root/Whitix/trunk/include/module.h

Revision 1994, 2.4 KB (checked in by mwhitworth, 3 years ago)

Place thisModule inside of module code, add ModuleGetIcDir function.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#ifndef MODULE_H
20#define MODULE_H
21
22#define ModuleInit(func) \
23        int _ModuleInit(void) __attribute__((alias(#func)));
24
25#define MODULE_START    0xD8000000
26#define MODULE_END              0xE0000000
27
28#include <elf.h>
29#include <llist.h>
30#include <typedefs.h>
31#include <keobject.h>
32
33struct KernelSymbol;
34
35struct Module
36{
37        struct ListHead next;
38
39        struct KernelSymbol* keSymTab;
40        int keSymTabSize;
41
42        /* ELF specific information. */
43        DWORD loadAddr;
44        DWORD textAddr;
45        DWORD textLength;
46
47        struct ElfSectionHeader* sectionHeaders;
48
49        char* strTable;
50        int strTableSize;
51
52        struct ElfSymbol* symTable;
53        int symTableSize;
54       
55        struct KeObject object;
56};
57
58static inline struct KeFsEntry* ModuleGetIcDir(struct Module* module)
59{
60        return module->object.dir;
61}
62
63#ifndef MODULE /* Kernel-specific structures. */
64
65void ModuleSymbolPrint(DWORD address);
66int ModuleAdd(char* name, void* file, void* image, unsigned long length, int flags);
67
68#endif
69
70struct KernelSymbol
71{
72        unsigned long addr;
73        const char* name;
74};
75
76/* So drivers and stacks can access kernel functions, either through a trampoline
77 * or directly. */
78
79#define SYMBOL_EXPORT(sym) \
80        static const char _KeStrTab_##sym[] \
81        __attribute__((section(".symstrings"))) __attribute__((__used__)) \
82        = #sym; \
83        static const struct KernelSymbol _KeSymTab_##sym \
84        __attribute__((section(".symtable"))) __attribute__((__used__)) \
85        = { (unsigned long)&sym, _KeStrTab_##sym }
86       
87#ifdef MODULE
88
89/* Save us calling MemAlloc to allocate a Module structure by embedding each
90 * Module structure in the module itself. */
91 
92static struct Module thisModule __attribute__((section(".gnu.linkonce.thisModule"))) __attribute__((used));
93
94/* Defined for ease of reference. */
95#define THIS_MODULE &thisModule
96#endif
97
98#endif
Note: See TracBrowser for help on using the browser.