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* symbol;␊ |
25 | ␉unsigned int addr;␊ |
26 | ␉struct symbolList_t* next;␊ |
27 | } symbolList_t;␊ |
28 | ␊ |
29 | typedef struct moduleList_t␊ |
30 | {␊ |
31 | ␉char* module;␊ |
32 | ␉//struct moduleHook_t* hook_list;␊ |
33 | ␉struct moduleList_t* next;␊ |
34 | } moduleList_t;␊ |
35 | ␊ |
36 | typedef struct callbackList_t␊ |
37 | {␊ |
38 | ␉void(*callback)(void*, void*, void*, void*, void*, void*);␊ |
39 | ␉struct callbackList_t* next;␊ |
40 | } callbackList_t;␊ |
41 | ␊ |
42 | typedef struct moduleHook_t␊ |
43 | {␊ |
44 | ␉const char* name;␊ |
45 | ␉callbackList_t* callbacks;␊ |
46 | ␉struct moduleHook_t* next;␊ |
47 | } moduleHook_t;␊ |
48 | ␊ |
49 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
50 | ␊ |
51 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
52 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
53 | #define STUB_ENTRY_SIZE␉6␊ |
54 | ␊ |
55 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
56 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
57 | ␊ |
58 | EFI_STATUS init_module_system();␊ |
59 | VOID load_all_modules();␊ |
60 | ␊ |
61 | /*␊ |
62 | * Modules Interface␊ |
63 | * execute_hook␊ |
64 | *␉␉Exexutes a registered hook. All callbaks are␊ |
65 | *␉␉called in the same order that they were added␊ |
66 | *␊ |
67 | * register_hook_callback␊ |
68 | *␉␉registers a void function to be executed when a␊ |
69 | *␉␉hook is executed.␊ |
70 | */␊ |
71 | EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*);␊ |
72 | VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));␊ |
73 | ␊ |
74 | inline void rebase_location(UInt32* location, char* base, int type);␊ |
75 | inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
76 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
77 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
78 | ␊ |
79 | EFI_STATUS load_module(char* module);␊ |
80 | EFI_STATUS is_module_loaded(const char* name);␊ |
81 | VOID module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
82 | ␊ |
83 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
84 | ␊ |
85 | VOID* parse_mach(void* binary, ␊ |
86 | ␉␉␉␉ EFI_STATUS(*dylib_loader)(char*),␊ |
87 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
88 | ␉␉␉␉ );␊ |
89 | ␊ |
90 | unsigned int handle_symtable(UInt32 base,␊ |
91 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
92 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
93 | ␉␉␉␉␉␉␉ char is64);␊ |
94 | ␉␉␉␉␉␉␉ ␊ |
95 | unsigned int lookup_all_symbols(const char* name);␊ |
96 | ␊ |
97 | EFI_STATUS replace_function(const char* symbol, void* newAddress);␊ |
98 | ␊ |
99 | extern unsigned int (*lookup_symbol)(const char*);␊ |
100 | ␊ |
101 | #endif /* __BOOT_MODULES_H */ |