1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | /*␊ |
8 | * Copyright 2012 Cadet-petit Armel <armelcadetpetit@gmail.com>. All rights reserved.␊ |
9 | *␊ |
10 | * Cleaned, Added bundles support.␊ |
11 | *␊ |
12 | */␊ |
13 | ␊ |
14 | // There is a bug with the module system / rebasing / binding␊ |
15 | // that causes static variables to be incorrectly rebased or bound␊ |
16 | // Disable static variables for the moment␊ |
17 | // #define static␊ |
18 | ␊ |
19 | #ifndef __BOOT_MODULES_H␊ |
20 | #define __BOOT_MODULES_H␊ |
21 | ␊ |
22 | #include <mach-o/loader.h>␊ |
23 | #include <mach-o/nlist.h>␊ |
24 | #include "efi.h"␊ |
25 | ␊ |
26 | #define DEFAULT_BUNDLE_SPEC_SIZE 4096␊ |
27 | #define macho_64 0␊ |
28 | ␊ |
29 | extern unsigned long long textAddress;␊ |
30 | extern unsigned long long textSection;␊ |
31 | ␊ |
32 | typedef struct symbolList_t␊ |
33 | {␊ |
34 | char* module;␊ |
35 | ␉char* symbol;␊ |
36 | ␉unsigned int addr;␊ |
37 | ␉struct symbolList_t* next;␊ |
38 | } symbolList_t;␊ |
39 | ␊ |
40 | typedef struct callbackList_t␊ |
41 | {␊ |
42 | ␉void(*callback)(void*, void*, void*, void*, void*, void*);␊ |
43 | ␉struct callbackList_t* next;␊ |
44 | } callbackList_t;␊ |
45 | ␊ |
46 | typedef struct moduleHook_t␊ |
47 | {␊ |
48 | ␉const char* name;␊ |
49 | ␉callbackList_t* callbacks;␊ |
50 | ␉struct moduleHook_t* next;␊ |
51 | } moduleHook_t;␊ |
52 | ␊ |
53 | #define SYMBOLS_BUNDLE "Symbols"␊ |
54 | ␊ |
55 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
56 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
57 | #define STUB_ENTRY_SIZE␉6␊ |
58 | ␊ |
59 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
60 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
61 | ␊ |
62 | #define SYS_CLASS "SYMS"␊ |
63 | #define SYSLIB_CLASS "SYS_LIB"␊ |
64 | ␊ |
65 | /*␊ |
66 | * Modules Interface␊ |
67 | * execute_hook␊ |
68 | *␉␉Exexutes a registered hook. All callbaks are␊ |
69 | *␉␉called in the same order that they were added␊ |
70 | *␊ |
71 | * register_hook_callback␊ |
72 | *␉␉registers a void function to be executed when a␊ |
73 | *␉␉hook is executed.␊ |
74 | */␊ |
75 | EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*);␊ |
76 | VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));␊ |
77 | VOID register_one_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));␊ |
78 | ␊ |
79 | void rebase_location(UInt32* location, char* base, int type);␊ |
80 | void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
81 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
82 | EFI_STATUS bind_macho(char* module, void* base, char* bind_stream, UInt32 size);␊ |
83 | ␊ |
84 | #if macho_64␊ |
85 | long long add_symbol(char* module,char* symbol, long long addr, char is64);␊ |
86 | #else␊ |
87 | long long add_symbol(char* module,char* symbol, long long addr);␊ |
88 | #endif␊ |
89 | ␊ |
90 | #if macho_64␊ |
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 | #else␊ |
96 | unsigned int handle_symtable(char *module, UInt32 base,␊ |
97 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
98 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, char*, long long));␊ |
99 | #endif␊ |
100 | ␊ |
101 | unsigned int lookup_all_symbols(const char* module, const char* name);␊ |
102 | ␊ |
103 | EFI_STATUS replace_function(const char* module, const char* symbol, void* newAddress);␊ |
104 | EFI_STATUS replace_system_function(const char* symbol, void* newAddress);␊ |
105 | EFI_STATUS replace_function_any(const char* symbol, void* newAddress);␊ |
106 | ␊ |
107 | extern unsigned int (*lookup_symbol)(const char*, int(*strcmp_callback)(const char*, const char*));␊ |
108 | ␊ |
109 | ␊ |
110 | long InitBundleSupport(void);␊ |
111 | long FileLoadBundles(char *dirSpec, long plugin);␊ |
112 | long LoadBundlePList(char *dirSpec, char *name, long bundleType);␊ |
113 | long LoadMatchedBundles(void);␊ |
114 | long MatchBundlesLibraries(void);␊ |
115 | long LoadBundles( char * dirSpec );␊ |
116 | void * GetBundleDict( char * bundle_id );␊ |
117 | void * GetBundlePersonality( char * bundle_id );␊ |
118 | char * GetBundlePath( char * bundle_id );␊ |
119 | ␊ |
120 | #endif /* __BOOT_MODULES_H */ |