Index: mod/kcore/boot.rt.c ================================================================== --- mod/kcore/boot.rt.c +++ mod/kcore/boot.rt.c @@ -9,15 +9,10 @@ const char** argv, /* arguments */ char** envp /* environment */ ) { _k_internal_binary_name = argv[0]; - envp ++; /* envp seems to point at a leading null; - this is probably a sign of breakage but - i don't know what else to do about it for - the moment. */ - char** ep; /* advance ep until it points at the last element */ for (ep = envp; *ep != 0; ++ep); /* allocate space for each environment variable */ Index: mod/kcore/boot.rt.x86.lin.64.s ================================================================== --- mod/kcore/boot.rt.x86.lin.64.s +++ mod/kcore/boot.rt.x86.lin.64.s @@ -21,27 +21,35 @@ ; this is a 32-bit signed(??) integer ; that is equal to the number of ; elements in argv (see below). it is ; not strictly necessary, because argv ; is per spec always null-terminated, - ; but we pass it just in case. + ; but we pass it just in case. it is + ; also used for finding the environment + ; below. lea rsi, [rsp + 8] ; &arguments ; 2nd argument to _boot(): ptr to argv ; this points to an array of strings ; containing the program's command line ; arguments. _boot() does not need to ; parse this, but it does need to store ; it in the structure passed to main() + ; this exists on the stack, right above + ; argc - lea rdx, [rsp + 16] ; &environment + lea rdx, [rsp + rdi * 8 + 16] ; &environment ; third argument to _boot(): ptr to envp ; this points to the list of environment ; variables for the running program. it ; is the responsibility of _boot to parse ; this list and arrange it into a set of - ; legible and useful C arrays. + ; legible and useful C arrays. it exists + ; above the argument list, the math is + ; stack pointer + argc*pointers(8 bytes) + ; + 16 bytes (argc itself and the + ; terminating null from argv) mov rax, 0 ; zero out %rax ; this is required by the C ABI, and is ; reputedly necessary for compatibility ; with icc, intel's own proprietary C