1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | // There is a bug with the module system / rebasing / binding␊ |
8 | // that causes static variables to be incorrectly rebased or bound␊ |
9 | // Disable static variables for the moment␊ |
10 | // #define static␊ |
11 | ␊ |
12 | #ifndef __BOOT_MODULES_H␊ |
13 | #define __BOOT_MODULES_H␊ |
14 | ␊ |
15 | #include <mach-o/loader.h>␊ |
16 | #include <mach-o/nlist.h>␊ |
17 | #include "efi.h"␊ |
18 | ␊ |
19 | extern unsigned long long textAddress;␊ |
20 | extern unsigned long long textSection;␊ |
21 | ␊ |
22 | typedef struct symbolList_t␊ |
23 | {␊ |
24 | char* module;␊ |
25 | ␉char* symbol;␊ |
26 | ␉unsigned int addr;␊ |
27 | ␉struct symbolList_t* next;␊ |
28 | } symbolList_t;␊ |
29 | ␊ |
30 | typedef struct moduleList_t␊ |
31 | {␊ |
32 | ␉char* module;␊ |
33 | ␉//struct moduleHook_t* hook_list;␊ |
34 | ␉struct moduleList_t* next;␊ |
35 | } moduleList_t;␊ |
36 | ␊ |
37 | typedef struct callbackList_t␊ |
38 | {␊ |
39 | ␉void(*callback)(void*, void*, void*, void*, void*, void*);␊ |
40 | ␉struct callbackList_t* next;␊ |
41 | } callbackList_t;␊ |
42 | ␊ |
43 | typedef struct moduleHook_t␊ |
44 | {␊ |
45 | ␉const char* name;␊ |
46 | ␉callbackList_t* callbacks;␊ |
47 | ␉struct moduleHook_t* next;␊ |
48 | } moduleHook_t;␊ |
49 | ␊ |
50 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
51 | ␊ |
52 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
53 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
54 | #define STUB_ENTRY_SIZE␉6␊ |
55 | ␊ |
56 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
57 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
58 | ␊ |
59 | EFI_STATUS init_module_system(void);␊ |
60 | VOID load_all_modules(void);␊ |
61 | ␊ |
62 | /*␊ |
63 | * Modules Interface␊ |
64 | * execute_hook␊ |
65 | *␉␉Exexutes a registered hook. All callbaks are␊ |
66 | *␉␉called in the same order that they were added␊ |
67 | *␊ |
68 | * register_hook_callback␊ |
69 | *␉␉registers a void function to be executed when a␊ |
70 | *␉␉hook is executed.␊ |
71 | */␊ |
72 | EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*);␊ |
73 | VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));␊ |
74 | ␊ |
75 | void rebase_location(UInt32* location, char* base, int type);␊ |
76 | void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
77 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
78 | EFI_STATUS bind_macho(char* module, void* base, char* bind_stream, UInt32 size);␊ |
79 | ␊ |
80 | EFI_STATUS load_module(char* module);␊ |
81 | EFI_STATUS load_bundle(const char* bundle);␊ |
82 | VOID load_all_bundles(void);␊ |
83 | ␊ |
84 | EFI_STATUS is_module_loaded(const char* name);␊ |
85 | VOID module_loaded(const char* name);␊ |
86 | ␊ |
87 | long long add_symbol(char* module,char* symbol, long long addr, char is64);␊ |
88 | ␊ |
89 | void* parse_mach(char *module, void* binary, EFI_STATUS(*dylib_loader)(char*), long long(*symbol_handler)(char*, char*, long long, char));␊ |
90 | ␊ |
91 | unsigned int handle_symtable(char *module, UInt32 base,␊ |
92 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
93 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, char*, long long, char),␊ |
94 | ␉␉␉␉␉␉␉ char is64);␊ |
95 | ␊ |
96 | unsigned int lookup_all_symbols(const char* module, const char* name);␊ |
97 | ␊ |
98 | EFI_STATUS replace_function(const char* module, const char* symbol, void* newAddress);␊ |
99 | EFI_STATUS replace_system_function(const char* symbol, void* newAddress);␊ |
100 | EFI_STATUS replace_function_any(const char* symbol, void* newAddress);␊ |
101 | ␊ |
102 | extern unsigned int (*lookup_symbol)(const char*, int(*strcmp_callback)(const char*, const char*));␊ |
103 | ␊ |
104 | #endif /* __BOOT_MODULES_H */ |