Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/boot2/modules.h

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

Archive Download this file

Revision: 789