Root/
Source at commit 658 created 13 years 5 months ago. By meklort, Makeful update (again). Added a ugly hack so that only c++ modules will link agains the uClibc++ module. Removed the possibility for modules to link agains themselfs. Added laxydylib1.c so that if you try to compile a module with -lazy_library instead of -weak_library, the build will not fail | |
---|---|
1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #include <mach-o/loader.h>␊ |
8 | #include <mach-o/nlist.h>␊ |
9 | ␊ |
10 | ␊ |
11 | // There is a bug with the module system / rebasing / binding␊ |
12 | // that causes static variables to be incorrectly rebased or bound␊ |
13 | // Disable static variables for the moment␊ |
14 | // #define static␊ |
15 | ␊ |
16 | #ifndef __BOOT_MODULES_H␊ |
17 | #define __BOOT_MODULES_H␊ |
18 | ␊ |
19 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
20 | ␊ |
21 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
22 | #define STUB_ENTRY_SIZE␉6␊ |
23 | ␊ |
24 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
25 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
26 | ␊ |
27 | ␊ |
28 | #define VALID_FUNCTION(__x__)␉(__x__ && (void*)__x__ != (void*)0xFFFFFFFF)␊ |
29 | ␊ |
30 | extern unsigned long long textAddress;␊ |
31 | extern unsigned long long textSection;␊ |
32 | ␊ |
33 | ␊ |
34 | typedef struct symbolList_t␊ |
35 | {␊ |
36 | ␉char* symbol;␊ |
37 | ␉unsigned int addr;␊ |
38 | ␉struct symbolList_t* next;␊ |
39 | } symbolList_t;␊ |
40 | ␊ |
41 | typedef struct moduleList_t␊ |
42 | {␊ |
43 | ␉char* module;␊ |
44 | ␉unsigned int version;␊ |
45 | ␉unsigned int compat;␊ |
46 | ␉struct moduleList_t* next;␊ |
47 | } moduleList_t;␊ |
48 | ␊ |
49 | typedef struct callbackList_t␊ |
50 | {␊ |
51 | ␉void(*callback)(void*, void*, void*, void*);␊ |
52 | ␉struct callbackList_t* next;␊ |
53 | } callbackList_t;␊ |
54 | ␊ |
55 | typedef struct moduleHook_t␊ |
56 | {␊ |
57 | ␉const char* name;␊ |
58 | ␉callbackList_t* callbacks;␊ |
59 | ␉struct moduleHook_t* next;␊ |
60 | } moduleHook_t;␊ |
61 | ␊ |
62 | ␊ |
63 | ␊ |
64 | int init_module_system();␊ |
65 | void load_all_modules();␊ |
66 | ␊ |
67 | /*␊ |
68 | * Modules Interface␊ |
69 | * execute_hook␊ |
70 | *␉␉Exexutes a registered hook. All callbaks are␊ |
71 | *␉␉called in the same order that they were added␊ |
72 | *␊ |
73 | * register_hook_callback␊ |
74 | *␉␉registers a void function to be executed when a␊ |
75 | *␉␉hook is executed.␊ |
76 | */␊ |
77 | int execute_hook(const char* name, void*, void*, void*, void*);␊ |
78 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
79 | ␊ |
80 | inline void rebase_location(UInt32* location, char* base, int type);␊ |
81 | inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
82 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
83 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
84 | ␊ |
85 | int load_module(char* module);␊ |
86 | int is_module_loaded(const char* name);␊ |
87 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
88 | ␊ |
89 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
90 | ␊ |
91 | void* parse_mach(void* binary, ␊ |
92 | ␉␉␉␉ int(*dylib_loader)(char*),␊ |
93 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
94 | ␉␉␉␉ );␊ |
95 | ␊ |
96 | unsigned int handle_symtable(UInt32 base,␊ |
97 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
98 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
99 | ␉␉␉␉␉␉␉ char is64);␊ |
100 | ␉␉␉␉␉␉␉ ␊ |
101 | unsigned int lookup_all_symbols(const char* name);␊ |
102 | ␊ |
103 | int replace_function(const char* symbol, void* newAddress);␊ |
104 | ␊ |
105 | //extern unsigned int (*lookup_symbol)(const char*);␊ |
106 | ␊ |
107 | #endif /* __BOOT_MODULES_H */ |