Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 711