hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

platformstart+libc.ha (750B)


      1 // License: MPL-2.0
      2 // (c) 2021-2022 Alexey Yerin <yyp@disroot.org>
      3 
      4 export fn start_linux() void = {
      5 	// Here we use a cool strategy of re-constructing argv and argc without
      6 	// knowing their original values. Since environ is placed just after
      7 	// them, it's possible to traverse backwards calculating how many
      8 	// entries were processed and comparing that value to the one at
      9 	// current position.
     10 	let argv_ptr = c_environ: uintptr - size(*u8): uintptr * 2;
     11 	let i = 0z;
     12 	for (*(argv_ptr: **u8): uintptr: size != i; i += 1) {
     13 		argv_ptr -= size(*u8): uintptr;
     14 	};
     15 
     16 	argc = i;
     17 	argv = (argv_ptr + size(*u8): uintptr): *[*]*u8;
     18 	envp = c_environ;
     19 };
     20 
     21 @init fn start_linux() void = start_linux();
     22 
     23 let @symbol("environ") c_environ: *[*]nullable *u8;