Rev 6767 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5195 | clevermous | 1 | format PE DLL GUI 0.8 at 7FF00000h |
2 | entry start |
||
3 | include '../../struct.inc' |
||
4 | include '../../proc32.inc' |
||
5 | include 'fpo.inc' |
||
6 | include 'export.inc' |
||
7 | include 'pe.inc' |
||
8 | section '.text' code readable executable |
||
9 | |||
10 | FS_STACK_MAX equ dword [fs:4] |
||
11 | FS_STACK_MIN equ dword [fs:8] |
||
12 | FS_SELF_PTR equ dword [fs:0x18] |
||
13 | FS_PROCESS_DATA equ dword [fs:0x30] |
||
14 | FS_ERRNO equ dword [fs:0x34] |
||
15 | FS_SYSCALL_PTR equ dword [fs:0xC0] |
||
16 | |||
17 | ENOMEM = 12 |
||
18 | |||
19 | DLL_PROCESS_DETACH = 0 |
||
20 | DLL_PROCESS_ATTACH = 1 |
||
21 | DLL_THREAD_ATTACH = 2 |
||
22 | DLL_THREAD_DETACH = 3 |
||
23 | |||
24 | SYSCALL_METHOD_I40 = 1 |
||
25 | SYSCALL_METHOD_SYSENTER = 2 |
||
26 | SYSCALL_METHOD_SYSCALL = 3 |
||
27 | |||
28 | ; Pointer to this structure is passed as the third argument |
||
29 | ; to 'start' procedure by the kernel. |
||
30 | struct kernel_init_data |
||
31 | version dw ? |
||
32 | flags dw ? |
||
33 | syscall_method dd ? |
||
34 | ; either one of SYSCALL_METHOD_xxx or pointer to procedure |
||
35 | exe_base dd ? |
||
36 | stack_base dd ? |
||
37 | stack_size dd ? |
||
38 | exe_path dd ? |
||
39 | command_line dd ? |
||
40 | ends |
||
41 | |||
42 | include 'malloc.inc' |
||
43 | |||
44 | proc syscall_int40 |
||
45 | int 0x40 |
||
46 | ret |
||
47 | endp |
||
48 | |||
49 | proc kercall |
||
50 | jmp FS_SYSCALL_PTR |
||
51 | endp |
||
52 | |||
53 | prologue@proc equ fpo_prologue |
||
54 | epilogue@proc equ fpo_epilogue |
||
55 | |||
56 | proc start stdcall, dll_base, reason, reserved |
||
57 | ; 1. Do nothing unless called by the kernel for DLL_PROCESS_ATTACH. |
||
58 | cmp [reason], DLL_PROCESS_ATTACH |
||
59 | jnz .nothing |
||
60 | ; 2. Validate version of the init struct. |
||
61 | ; If not known, say a debug message and die. |
||
62 | mov ebp, [reserved] |
||
63 | cmp [ebp+kernel_init_data.version], 1 |
||
64 | jnz .version_mismatch |
||
65 | ; 3. Setup common data based on the init struct. |
||
66 | mov eax, [ebp+kernel_init_data.stack_base] |
||
67 | mov FS_STACK_MIN, eax |
||
68 | add eax, [ebp+kernel_init_data.stack_size] |
||
69 | mov FS_STACK_MAX, eax |
||
70 | mov eax, [ebp+kernel_init_data.syscall_method] |
||
71 | cmp eax, 0x10000 |
||
72 | jae @f |
||
73 | mov eax, syscall_int40 |
||
74 | @@: |
||
75 | mov FS_SYSCALL_PTR, eax |
||
76 | ; 4. Initialize the process heap. |
||
77 | mov eax, [ebp+kernel_init_data.exe_base] |
||
78 | mov edx, [eax+STRIPPED_PE_HEADER.SizeOfHeapReserve] |
||
79 | cmp word [eax], 'MZ' |
||
80 | jnz @f |
||
81 | add eax, [eax+IMAGE_DOS_HEADER.e_lfanew] |
||
82 | mov edx, [eax+IMAGE_NT_HEADERS.OptionalHeader.SizeOfHeapReserve] |
||
83 | @@: |
||
84 | malloc_init |
||
85 | ; ...TBD... |
||
86 | ; Call exe entry point. |
||
87 | mov eax, [ebp+kernel_init_data.exe_base] |
||
88 | mov edx, [eax+STRIPPED_PE_HEADER.AddressOfEntryPoint] |
||
89 | cmp word [eax], 'MZ' |
||
90 | jnz @f |
||
91 | mov ecx, [eax+IMAGE_DOS_HEADER.e_lfanew] |
||
92 | add ecx, eax |
||
93 | mov edx, [ecx+IMAGE_NT_HEADERS.OptionalHeader.AddressOfEntryPoint] |
||
94 | @@: |
||
95 | add edx, eax |
||
96 | call edx |
||
97 | ; If exe entry point has returned control, die. |
||
98 | mov eax, -1 |
||
99 | call FS_SYSCALL_PTR |
||
100 | .version_mismatch: |
||
101 | mov esi, version_mismatch_msg |
||
102 | mov eax, 63 |
||
103 | mov ebx, 1 |
||
104 | @@: |
||
105 | mov cl, [esi] |
||
106 | test cl, cl |
||
107 | jz @f |
||
108 | int 0x40 ; can't use FS_SYSCALL_PTR here, it has not yet been set |
||
109 | inc esi |
||
110 | jmp @b |
||
111 | @@: |
||
112 | mov eax, -1 |
||
113 | int 0x40 |
||
114 | .nothing: |
||
115 | ret |
||
116 | endp |
||
117 | |||
118 | align 4 |
||
119 | data export |
||
120 | export 'kolibri.dll' \ |
||
121 | , kercall, 'kercall' \ |
||
122 | , malloc, 'malloc' \ |
||
123 | , free, 'free' \ |
||
124 | , calloc, 'calloc' \ |
||
125 | , realloc, 'realloc' \ |
||
126 | , realloc_in_place, 'realloc_in_place' \ |
||
127 | , memalign, 'memalign' \ |
||
128 | , create_mspace, 'create_mspace' \ |
||
129 | , destroy_mspace, 'destroy_mspace' \ |
||
130 | , mspace_malloc, 'mspace_malloc' \ |
||
131 | , mspace_free, 'mspace_free' \ |
||
132 | , mspace_calloc, 'mspace_calloc' \ |
||
133 | , mspace_realloc, 'mspace_realloc' \ |
||
134 | , mspace_realloc_in_place, 'mspace_realloc_in_place' \ |
||
135 | , mspace_memalign, 'mspace_memalign' \ |
||
136 | |||
137 | end data |
||
138 | |||
139 | version_mismatch_msg db 'Version mismatch between kernel and kolibri.dll',13,10,0 |
||
140 | |||
141 | if FOOTERS |
||
142 | section '.data' data readable writable |
||
143 | malloc_magic dd ? |
||
144 | end if |