mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:27:35 +00:00
Loader: Add dynamic loader program
The dynamic loader exists as /usr/lib/Loader.so and is loaded by the kernel when ET_DYN programs are executed. The dynamic loader is responsible for loading the dependencies of the main program, allocating TLS storage, preparing all loaded objects for execution and finally jumping to the entry of the main program.
This commit is contained in:
parent
781aa424a9
commit
07b4957361
18 changed files with 962 additions and 104 deletions
22
Userland/DynamicLoader/CMakeLists.txt
Normal file
22
Userland/DynamicLoader/CMakeLists.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
set(LOADER_SOURCES
|
||||
main.cpp
|
||||
math.cpp
|
||||
misc.cpp
|
||||
)
|
||||
|
||||
file(GLOB AK_SOURCES "../../AK/*.cpp")
|
||||
file(GLOB ELF_SOURCES "../../Libraries/LibELF/*.cpp")
|
||||
set(ELF_SOURCES ${ELF_SOURCES} ../../Libraries/LibELF/Arch/i386/plt_trampoline.S)
|
||||
file(GLOB LIBC_SOURCES1 "../../Libraries/LibC/*.cpp")
|
||||
file(GLOB LIBC_SOURCES2 "../../Libraries/LibC/*/*.cpp")
|
||||
file(GLOB LIBC_SOURCES3 "../../Libraries/LibC/*.S")
|
||||
|
||||
list(FILTER LIBC_SOURCES1 EXCLUDE REGEX ".+crt0.cpp")
|
||||
list(FILTER LIBC_SOURCES1 EXCLUDE REGEX ".+crt0.+.cpp")
|
||||
|
||||
set(SOURCES ${LOADER_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${LIBC_SOURCES1} ${LIBC_SOURCES2} ${LIBC_SOURCES3})
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -pie -fpic -DNO_TLS")
|
||||
|
||||
add_executable(Loader.so ${SOURCES})
|
||||
install(TARGETS Loader.so RUNTIME DESTINATION usr/lib/)
|
252
Userland/DynamicLoader/main.cpp
Normal file
252
Userland/DynamicLoader/main.cpp
Normal file
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <LibC/mman.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/sys/internals.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibELF/AuxiliaryVector.h>
|
||||
#include <LibELF/DynamicLoader.h>
|
||||
#include <LibELF/DynamicObject.h>
|
||||
#include <LibELF/Image.h>
|
||||
#include <LibELF/Loader.h>
|
||||
#include <LibELF/exec_elf.h>
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// #define DYNAMIC_LOAD_VERBOSE
|
||||
|
||||
#ifdef DYNAMIC_LOAD_VERBOSE
|
||||
# define VERBOSE(fmt, ...) dbgprintf(fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
# define VERBOSE(fmt, ...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif
|
||||
#define TLS_VERBOSE(fmt, ...) dbgprintf(fmt, ##__VA_ARGS__)
|
||||
|
||||
char* __static_environ[] = { nullptr }; // We don't get the environment without some libc workarounds..
|
||||
|
||||
static HashMap<String, NonnullRefPtr<ELF::DynamicLoader>> g_loaders;
|
||||
static HashMap<String, NonnullRefPtr<ELF::DynamicObject>> g_loaded_objects;
|
||||
|
||||
static size_t g_current_tls_offset = 0;
|
||||
static size_t g_total_tls_size = 0;
|
||||
|
||||
static void init_libc()
|
||||
{
|
||||
environ = __static_environ;
|
||||
__environ_is_malloced = false;
|
||||
__stdio_is_initialized = false;
|
||||
__malloc_init();
|
||||
}
|
||||
|
||||
static void perform_self_relocations()
|
||||
{
|
||||
// We need to relocate ourselves.
|
||||
// (these relocations seem to be generated because of our vtables)
|
||||
|
||||
// TODO: Pass this address in the Auxiliary Vector
|
||||
u32 base = 0x08000000;
|
||||
Elf32_Ehdr* header = (Elf32_Ehdr*)(base);
|
||||
Elf32_Phdr* pheader = (Elf32_Phdr*)(base + header->e_phoff);
|
||||
u32 dynamic_section_addr = 0;
|
||||
for (size_t i = 0; i < (size_t)header->e_phnum; ++i, ++pheader) {
|
||||
if (pheader->p_type != PT_DYNAMIC)
|
||||
continue;
|
||||
dynamic_section_addr = pheader->p_vaddr + base;
|
||||
}
|
||||
if (!dynamic_section_addr)
|
||||
exit(1);
|
||||
|
||||
auto dynamic_object = ELF::DynamicObject::construct((VirtualAddress(base)), (VirtualAddress(dynamic_section_addr)));
|
||||
|
||||
dynamic_object->relocation_section().for_each_relocation([base](auto& reloc) {
|
||||
if (reloc.type() != R_386_RELATIVE)
|
||||
return IterationDecision::Continue;
|
||||
*(u32*)reloc.address().as_ptr() += base;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
static ELF::DynamicObject::SymbolLookupResult global_symbol_lookup(const char* symbol_name)
|
||||
{
|
||||
VERBOSE("global symbol lookup: %s\n", symbol_name);
|
||||
for (auto& lib : g_loaded_objects) {
|
||||
VERBOSE("looking up in object: %s\n", lib.key.characters());
|
||||
auto res = lib.value->lookup_symbol(symbol_name);
|
||||
if (!res.has_value())
|
||||
continue;
|
||||
return res.value();
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
return {};
|
||||
}
|
||||
|
||||
static void map_library(const String& name, int fd)
|
||||
{
|
||||
struct stat lib_stat;
|
||||
int rc = fstat(fd, &lib_stat);
|
||||
ASSERT(!rc);
|
||||
|
||||
auto loader = ELF::DynamicLoader::construct(name.characters(), fd, lib_stat.st_size);
|
||||
loader->set_tls_offset(g_current_tls_offset);
|
||||
loader->m_global_symbol_lookup_func = global_symbol_lookup;
|
||||
|
||||
g_loaders.set(name, loader);
|
||||
|
||||
g_current_tls_offset += loader->tls_size();
|
||||
}
|
||||
|
||||
static void map_library(const String& name)
|
||||
{
|
||||
// TODO: Do we want to also look for libs in other paths too?
|
||||
String path = String::format("/usr/lib/%s", name.characters());
|
||||
int fd = open(path.characters(), O_RDONLY);
|
||||
ASSERT(fd >= 0);
|
||||
map_library(name, fd);
|
||||
}
|
||||
|
||||
static String get_library_name(const StringView& path)
|
||||
{
|
||||
return LexicalPath(path).basename();
|
||||
}
|
||||
|
||||
static void map_dependencies(const String& name)
|
||||
{
|
||||
dbg() << "mapping dependencies for: " << name;
|
||||
auto lib = g_loaders.get(name).value();
|
||||
lib->for_each_needed_library([](auto needed_name) {
|
||||
dbg() << "needed library: " << needed_name;
|
||||
String library_name = get_library_name(needed_name);
|
||||
|
||||
if (!g_loaders.contains(library_name)) {
|
||||
map_library(library_name);
|
||||
map_dependencies(library_name);
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
static void allocate_tls()
|
||||
{
|
||||
size_t total_tls_size = 0;
|
||||
for (const auto& data : g_loaders) {
|
||||
total_tls_size += data.value->tls_size();
|
||||
}
|
||||
if (total_tls_size) {
|
||||
void* tls_address = allocate_tls(total_tls_size);
|
||||
dbg() << "from userspace, tls_address: " << tls_address;
|
||||
}
|
||||
g_total_tls_size = total_tls_size;
|
||||
}
|
||||
|
||||
static void load_elf(const String& name)
|
||||
{
|
||||
dbg() << "load_elf: " << name;
|
||||
auto loader = g_loaders.get(name).value();
|
||||
loader->for_each_needed_library([](auto needed_name) {
|
||||
dbg() << "needed library: " << needed_name;
|
||||
String library_name = get_library_name(needed_name);
|
||||
if (!g_loaded_objects.contains(library_name)) {
|
||||
load_elf(library_name);
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
auto dynamic_object = loader->load_from_image(RTLD_GLOBAL, g_total_tls_size);
|
||||
ASSERT(!dynamic_object.is_null());
|
||||
g_loaded_objects.set(name, dynamic_object.release_nonnull());
|
||||
}
|
||||
|
||||
static FlatPtr loader_main(auxv_t* auxvp)
|
||||
{
|
||||
int main_program_fd = -1;
|
||||
for (; auxvp->a_type != AT_NULL; ++auxvp) {
|
||||
if (auxvp->a_type == AuxiliaryValue::ExecFileDescriptor) {
|
||||
main_program_fd = auxvp->a_un.a_val;
|
||||
}
|
||||
}
|
||||
ASSERT(main_program_fd >= 0);
|
||||
|
||||
// TODO: Pass this in the auxiliary vector
|
||||
const String main_program_name = "MainProgram";
|
||||
map_library(main_program_name, main_program_fd);
|
||||
map_dependencies(main_program_name);
|
||||
|
||||
dbg() << "loaded all dependencies";
|
||||
for (auto& lib : g_loaders) {
|
||||
dbg() << lib.key << "- tls size: " << lib.value->tls_size() << ", tls offset: " << lib.value->tls_offset();
|
||||
}
|
||||
|
||||
allocate_tls();
|
||||
|
||||
load_elf(main_program_name);
|
||||
|
||||
auto main_program_lib = g_loaders.get(main_program_name).value();
|
||||
FlatPtr entry_point = reinterpret_cast<FlatPtr>(main_program_lib->image().entry().as_ptr() + (FlatPtr)main_program_lib->text_segment_load_address().as_ptr());
|
||||
dbg() << "entry point: " << (void*)entry_point;
|
||||
|
||||
// This will unmap the temporary memory maps we had for loading the libraries
|
||||
g_loaders.clear();
|
||||
|
||||
return entry_point;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
// The compiler expects a previous declaration
|
||||
void _start(int, char**, char**);
|
||||
|
||||
using MainFunction = int (*)(int, char**, char**);
|
||||
|
||||
void _start(int argc, char** argv, char** envp)
|
||||
{
|
||||
perform_self_relocations();
|
||||
init_libc();
|
||||
|
||||
char** env;
|
||||
for (env = envp; *env; ++env) {
|
||||
}
|
||||
|
||||
auxv_t* auxvp = (auxv_t*)++env;
|
||||
FlatPtr entry = loader_main(auxvp);
|
||||
MainFunction main_function = (MainFunction)(entry);
|
||||
dbg() << "jumping to main program entry point: " << (void*)main_function;
|
||||
int rc = main_function(argc, argv, envp);
|
||||
dbg() << "rc: " << rc;
|
||||
sleep(100);
|
||||
_exit(rc);
|
||||
}
|
||||
}
|
190
Userland/DynamicLoader/math.cpp
Normal file
190
Userland/DynamicLoader/math.cpp
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// TODO: Is there a compiler flag we can use to still get these math functions? (and compile with -nostdlib)
|
||||
// FIXME: What do we do with this regarding copyright stuff?
|
||||
// code for math functions taken from here:
|
||||
// https://gitlab.incom.co/CM-Shield/u-boot/commit/aa7839b39c2ee77f9ab8c393c56b8d812507dbb7
|
||||
// https://github.com/zayac/qemu-arm/blob/master/qemu/roms/ipxe/src/libgcc/__udivmoddi4.c
|
||||
// https://code.woboq.org/llvm/compiler-rt/lib/builtins/divdi3.c.html
|
||||
|
||||
#include "math.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
union overlay64 {
|
||||
u64 longw;
|
||||
struct {
|
||||
u32 lower;
|
||||
u32 higher;
|
||||
} words;
|
||||
};
|
||||
|
||||
u64 __ashldi3(u64 num, unsigned int shift)
|
||||
{
|
||||
union overlay64 output;
|
||||
|
||||
output.longw = num;
|
||||
if (shift >= 32) {
|
||||
output.words.higher = output.words.lower << (shift - 32);
|
||||
output.words.lower = 0;
|
||||
} else {
|
||||
if (!shift)
|
||||
return num;
|
||||
output.words.higher = (output.words.higher << shift) | (output.words.lower >> (32 - shift));
|
||||
output.words.lower = output.words.lower << shift;
|
||||
}
|
||||
return output.longw;
|
||||
}
|
||||
|
||||
u64 __lshrdi3(u64 num, unsigned int shift)
|
||||
{
|
||||
union overlay64 output;
|
||||
|
||||
output.longw = num;
|
||||
if (shift >= 32) {
|
||||
output.words.lower = output.words.higher >> (shift - 32);
|
||||
output.words.higher = 0;
|
||||
} else {
|
||||
if (!shift)
|
||||
return num;
|
||||
output.words.lower = output.words.lower >> shift | (output.words.higher << (32 - shift));
|
||||
output.words.higher = output.words.higher >> shift;
|
||||
}
|
||||
return output.longw;
|
||||
}
|
||||
|
||||
#define MAX_32BIT_UINT ((((u64)1) << 32) - 1)
|
||||
|
||||
static u64 _64bit_divide(u64 dividend, u64 divider, u64* rem_p)
|
||||
{
|
||||
u64 result = 0;
|
||||
|
||||
/*
|
||||
* If divider is zero - let the rest of the system care about the
|
||||
* exception.
|
||||
*/
|
||||
if (!divider)
|
||||
return 1 / (u32)divider;
|
||||
|
||||
/* As an optimization, let's not use 64 bit division unless we must. */
|
||||
if (dividend <= MAX_32BIT_UINT) {
|
||||
if (divider > MAX_32BIT_UINT) {
|
||||
result = 0;
|
||||
if (rem_p)
|
||||
*rem_p = divider;
|
||||
} else {
|
||||
result = (u32)dividend / (u32)divider;
|
||||
if (rem_p)
|
||||
*rem_p = (u32)dividend % (u32)divider;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
while (divider <= dividend) {
|
||||
u64 locald = divider;
|
||||
u64 limit = __lshrdi3(dividend, 1);
|
||||
int shifts = 0;
|
||||
|
||||
while (locald <= limit) {
|
||||
shifts++;
|
||||
locald = locald + locald;
|
||||
}
|
||||
result |= __ashldi3(1, shifts);
|
||||
dividend -= locald;
|
||||
}
|
||||
|
||||
if (rem_p)
|
||||
*rem_p = dividend;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
u64 __udivdi3(u64 num, u64 den)
|
||||
{
|
||||
return _64bit_divide(num, den, nullptr);
|
||||
}
|
||||
|
||||
u64 __umoddi3(u64 num, u64 den)
|
||||
{
|
||||
u64 v = 0;
|
||||
|
||||
_64bit_divide(num, den, &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t* rem_p)
|
||||
{
|
||||
uint64_t quot = 0, qbit = 1;
|
||||
|
||||
if (den == 0) {
|
||||
return 1 / ((unsigned)den); /* Intentional divide by zero, without
|
||||
triggering a compiler warning which
|
||||
would abort the build */
|
||||
}
|
||||
|
||||
/* Left-justify denominator and count shift */
|
||||
while ((int64_t)den >= 0) {
|
||||
den <<= 1;
|
||||
qbit <<= 1;
|
||||
}
|
||||
|
||||
while (qbit) {
|
||||
if (den <= num) {
|
||||
num -= den;
|
||||
quot += qbit;
|
||||
}
|
||||
den >>= 1;
|
||||
qbit >>= 1;
|
||||
}
|
||||
|
||||
if (rem_p)
|
||||
*rem_p = num;
|
||||
|
||||
return quot;
|
||||
}
|
||||
int64_t __divdi3(int64_t a, int64_t b)
|
||||
{
|
||||
const int bits_in_dword_m1 = (int)(sizeof(int64_t) * 8) - 1;
|
||||
int64_t s_a = a >> bits_in_dword_m1; // s_a = a < 0 ? -1 : 0
|
||||
int64_t s_b = b >> bits_in_dword_m1; // s_b = b < 0 ? -1 : 0
|
||||
a = (a ^ s_a) - s_a; // negate if s_a == -1
|
||||
b = (b ^ s_b) - s_b; // negate if s_b == -1
|
||||
s_a ^= s_b; // sign of quotient
|
||||
return (__udivmoddi4(a, b, (uint64_t*)0) ^ s_a) - s_a; // negate if s_a == -1
|
||||
}
|
||||
int64_t __moddi3(int64_t a, int64_t b)
|
||||
{
|
||||
const int bits_in_dword_m1 = (int)(sizeof(int64_t) * 8) - 1;
|
||||
int64_t s = b >> bits_in_dword_m1; // s = b < 0 ? -1 : 0
|
||||
b = (b ^ s) - s; // negate if s == -1
|
||||
s = a >> bits_in_dword_m1; // s = a < 0 ? -1 : 0
|
||||
a = (a ^ s) - s; // negate if s == -1
|
||||
uint64_t r;
|
||||
__udivmoddi4(a, b, &r);
|
||||
return ((int64_t)r ^ s) - s; // negate if s == -1
|
||||
}
|
||||
}
|
46
Userland/DynamicLoader/math.h
Normal file
46
Userland/DynamicLoader/math.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
u64 __ashldi3(u64 num, unsigned int shift);
|
||||
|
||||
u64 __lshrdi3(u64 num, unsigned int shift);
|
||||
|
||||
u64 __udivdi3(u64 num, u64 den);
|
||||
|
||||
u64 __umoddi3(u64 num, u64 den);
|
||||
|
||||
uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t* rem_p);
|
||||
|
||||
int64_t __divdi3(int64_t a, int64_t b);
|
||||
|
||||
int64_t __moddi3(int64_t a, int64_t b);
|
||||
}
|
39
Userland/DynamicLoader/misc.cpp
Normal file
39
Userland/DynamicLoader/misc.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "misc.h"
|
||||
#include "AK/LogStream.h"
|
||||
|
||||
extern "C" {
|
||||
const char* __cxa_demangle(const char*, void*, void*, int*)
|
||||
{
|
||||
dbg() << "WARNING: __cxa_demangle not supported";
|
||||
return "";
|
||||
}
|
||||
|
||||
// FIXME: Is this correct?
|
||||
void* __dso_handle = nullptr;
|
||||
}
|
33
Userland/DynamicLoader/misc.h
Normal file
33
Userland/DynamicLoader/misc.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
const char* __cxa_demangle(const char*, void*, void*, int*);
|
||||
|
||||
extern void* __dso_handle;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue