1
- #![ cfg( not( test) ) ]
2
-
3
1
#[ cfg( not( target_arch = "wasm32" ) ) ]
4
2
use core:: arch:: asm;
5
3
6
- use crate :: solution;
7
- use basm:: platform;
8
- use basm:: platform:: allocator;
4
+ use crate :: platform;
9
5
#[ cfg( not( target_arch = "wasm32" ) ) ]
10
- use basm:: platform:: loader;
11
-
12
- #[ global_allocator]
13
- static ALLOC : allocator:: Allocator = allocator:: Allocator ;
6
+ use crate :: platform:: loader;
14
7
15
8
/* We need to support multiple scenarios.
16
9
* 1) Architectures: x86, x86-64
@@ -28,9 +21,9 @@ static ALLOC: allocator::Allocator = allocator::Allocator;
28
21
* For 4), we build the binary to run without the loader.
29
22
* When running without the loader, the binary will fabricate a dummy
30
23
* SERVICE_FUNCTIONS and PLATFORM_DATA table at the beginning of the
31
- * EntryPoint (_start ).
24
+ * EntryPoint (_basm_start ).
32
25
* When running with the loader, the loader patches the beginning of
33
- * the EntryPoint (_start ) to override the platform configuration data.
26
+ * the EntryPoint (_basm_start ) to override the platform configuration data.
34
27
*
35
28
* When running without the loader, the relocations are handled differently.
36
29
* For Windows, the Windows kernel will handle relocations for us,
@@ -54,7 +47,7 @@ compile_error!("The target architecture is not supported.");
54
47
#[ cfg( all( target_arch = "x86_64" , not( target_os = "windows" ) ) ) ]
55
48
#[ no_mangle]
56
49
#[ naked]
57
- unsafe extern "win64" fn _start ( ) -> ! {
50
+ pub unsafe extern "win64" fn _basm_start ( ) -> ! {
58
51
// AMD64 System V ABI requires RSP to be aligned
59
52
// on the 16-byte boundary BEFORE `call` instruction.
60
53
// However, when called as the entrypoint by the Linux OS,
@@ -103,7 +96,7 @@ unsafe extern "sysv64" fn get_kernel32() -> usize {
103
96
#[ cfg( all( target_arch = "x86_64" , target_os = "windows" ) ) ]
104
97
#[ no_mangle]
105
98
#[ naked]
106
- unsafe extern "win64" fn _start ( ) -> ! {
99
+ pub unsafe extern "win64" fn _basm_start ( ) -> ! {
107
100
// Microsoft x64 ABI requires RSP to be aligned
108
101
// on the 16-byte boundary BEFORE `call` instruction.
109
102
// Also, when called as the entrypoint by the Windows OS,
@@ -162,7 +155,7 @@ unsafe extern "win64" fn _start() -> ! {
162
155
#[ link_section = ".data" ]
163
156
unsafe extern "cdecl" fn _get_start_offset ( ) -> ! {
164
157
asm ! (
165
- "lea eax, [_start ]" ,
158
+ "lea eax, [_basm_start ]" ,
166
159
"ret" ,
167
160
options( noreturn)
168
161
) ;
@@ -183,7 +176,7 @@ unsafe extern "cdecl" fn _get_dynamic_section_offset() -> ! {
183
176
#[ cfg( target_arch = "x86" ) ]
184
177
#[ no_mangle]
185
178
#[ naked]
186
- unsafe extern "cdecl" fn _start ( ) -> ! {
179
+ pub unsafe extern "cdecl" fn _basm_start ( ) -> ! {
187
180
// i386 System V ABI requires ESP to be aligned
188
181
// on the 16-byte boundary BEFORE `call` instruction
189
182
asm ! (
@@ -205,9 +198,9 @@ unsafe extern "cdecl" fn _start() -> ! {
205
198
"2:" ,
206
199
"call 3f" ,
207
200
"3:" ,
208
- "pop ecx" , // ecx = _start + 36 (obtained by counting the opcode size in bytes)
201
+ "pop ecx" , // ecx = _basm_start + 36 (obtained by counting the opcode size in bytes)
209
202
"push edx" , // [esp + 0] = PLATFORM_DATA table
210
- "call {2}" , // eax = offset of _start from the image base
203
+ "call {2}" , // eax = offset of _basm_start from the image base
211
204
"sub ecx, eax" ,
212
205
"sub ecx, 36" , // ecx = the in-memory image base (i.e., __ehdr_start)
213
206
"call {3}" , // eax = offset of _DYNAMIC table from the image base
@@ -231,7 +224,7 @@ unsafe extern "cdecl" fn _start() -> ! {
231
224
232
225
#[ cfg( target_arch = "wasm32" ) ]
233
226
#[ no_mangle]
234
- extern "C" fn _start ( ) {
227
+ pub extern "C" fn _basm_start ( ) {
235
228
let mut pd = platform:: services:: PlatformData {
236
229
env_id : platform:: services:: ENV_ID_WASM ,
237
230
.. Default :: default ( )
@@ -246,7 +239,10 @@ extern "C" fn _start() {
246
239
*/
247
240
#[ cfg_attr( not( feature = "short" ) , inline( never) ) ]
248
241
fn _call_main ( ) {
249
- solution:: main ( ) ;
242
+ extern "C" {
243
+ fn _basm_main ( ) ;
244
+ }
245
+ unsafe { _basm_main ( ) }
250
246
}
251
247
fn _start_rust ( platform_data : usize ) -> i32 {
252
248
platform:: init ( platform_data) ;
@@ -259,7 +255,7 @@ fn _start_rust(platform_data: usize) -> i32 {
259
255
#[ naked]
260
256
#[ repr( align( 4 ) ) ]
261
257
#[ cfg( all( target_arch = "x86_64" , target_os = "windows" ) ) ]
262
- unsafe extern "win64" fn __chkstk ( ) -> ! {
258
+ pub unsafe extern "win64" fn __chkstk ( ) -> ! {
263
259
asm ! (
264
260
"push rcx" ,
265
261
"push rax" ,
@@ -280,30 +276,4 @@ unsafe extern "win64" fn __chkstk() -> ! {
280
276
"ret" ,
281
277
options( noreturn)
282
278
) ;
283
- }
284
-
285
- #[ no_mangle]
286
- #[ cfg( target_os = "windows" ) ]
287
- static mut _fltused: i32 = 0 ;
288
-
289
- #[ no_mangle]
290
- #[ cfg( target_os = "windows" ) ]
291
- extern "win64" fn __CxxFrameHandler3 ( ) -> ! {
292
- unsafe { core:: hint:: unreachable_unchecked ( ) }
293
- }
294
-
295
- #[ alloc_error_handler]
296
- fn alloc_fail ( _: core:: alloc:: Layout ) -> ! {
297
- unsafe { core:: hint:: unreachable_unchecked ( ) }
298
- }
299
-
300
- #[ no_mangle]
301
- #[ allow( non_snake_case) ]
302
- pub fn _Unwind_Resume ( ) {
303
- unsafe { core:: hint:: unreachable_unchecked ( ) }
304
- }
305
-
306
- #[ no_mangle]
307
- pub fn rust_eh_personality ( ) {
308
- unsafe { core:: hint:: unreachable_unchecked ( ) }
309
- }
279
+ }
0 commit comments