Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 649