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// 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
19extern unsigned long long textAddress;
20extern unsigned long long textSection;
21
22typedef struct symbolList_t
23{
24char* symbol;
25unsigned int addr;
26struct symbolList_t* next;
27} symbolList_t;
28
29typedef struct moduleList_t
30{
31char* module;
32//struct moduleHook_t* hook_list;
33struct moduleList_t* next;
34} moduleList_t;
35
36typedef struct callbackList_t
37{
38void(*callback)(void*, void*, void*, void*, void*, void*);
39struct callbackList_t* next;
40} callbackList_t;
41
42typedef struct moduleHook_t
43{
44const char* name;
45callbackList_t* callbacks;
46struct 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_SIZE6
54
55#define SECT_NON_LAZY_SYMBOL_PTR"__nl_symbol_ptr"
56#define SECT_SYMBOL_STUBS"__symbol_stub"
57
58EFI_STATUS init_module_system();
59VOID 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 */
71EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*);
72VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));
73
74inline void rebase_location(UInt32* location, char* base, int type);
75inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);
76void rebase_macho(void* base, char* rebase_stream, UInt32 size);
77void bind_macho(void* base, char* bind_stream, UInt32 size);
78
79EFI_STATUS load_module(char* module);
80EFI_STATUS is_module_loaded(const char* name);
81VOID module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);
82
83long long add_symbol(char* symbol, long long addr, char is64);
84
85VOID* parse_mach(void* binary,
86 EFI_STATUS(*dylib_loader)(char*),
87 long long(*symbol_handler)(char*, long long, char)
88 );
89
90unsigned int handle_symtable(UInt32 base,
91 struct symtab_command* symtabCommand,
92 long long(*symbol_handler)(char*, long long, char),
93 char is64);
94
95unsigned int lookup_all_symbols(const char* name);
96
97EFI_STATUS replace_function(const char* symbol, void* newAddress);
98
99extern unsigned int (*lookup_symbol)(const char*);
100
101#endif /* __BOOT_MODULES_H */

Archive Download this file

Revision: 1119