Skip to content

Commit 2ab4aa4

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: add auxiliary vector retrieval for i386
In the _start block we now iterate over envp to find the auxiliary vector after the NULL. The pointer is saved into an _auxv variable that is marked as weak so that it's accessible from multiple units. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 9e5bdc6 commit 2ab4aa4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/include/nolibc/arch-i386.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct sys_stat_struct {
179179
})
180180

181181
char **environ __attribute__((weak));
182+
const unsigned long *_auxv __attribute__((weak));
182183

183184
/* startup code */
184185
/*
@@ -195,6 +196,12 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
195196
"lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
196197
"mov %ecx, environ\n" // save environ
197198
"xor %ebp, %ebp\n" // zero the stack frame
199+
"mov %ecx, %edx\n" // search for auxv (follows NULL after last env)
200+
"0:\n"
201+
"add $4, %edx\n" // search for auxv using edx, it follows the
202+
"cmp -4(%edx), %ebp\n" // ... NULL after last env (ebp is zero here)
203+
"jnz 0b\n"
204+
"mov %edx, _auxv\n" // save it into _auxv
198205
"and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before
199206
"sub $4, %esp\n" // the call instruction (args are aligned)
200207
"push %ecx\n" // push all registers on the stack so that we

0 commit comments

Comments
 (0)