88#include "box64context.h"
99#include "box64cpu_util.h"
1010#include "elfloader.h"
11+ #include "elfs/elfloader_private.h"
1112#include "debug.h"
1213#include "emu/x64emu_private.h"
1314#include "auxval.h"
@@ -117,10 +118,12 @@ void SetupInitialStack(x64emu_t *emu)
117118 31 0x7ffd5074efea
118119 33 0x7ffd507e6000
119120 */
121+ elfheader_t * main = my_context -> elfs [0 ];
120122 Push64 (emu , 0 ); Push64 (emu , 0 ); //AT_NULL(0)=0
121- //Push64(emu, ); Push64(emu, 3); //AT_PHDR(3)=address of the PH of the executable
122- //Push64(emu, ); Push64(emu, 4); //AT_PHENT(4)=size of PH entry
123- //Push64(emu, ); Push64(emu, 5); //AT_PHNUM(5)=number of elf headers
123+ Push64 (emu , main -> fileno ); Push64 (emu , 2 ); //AT_EXECFD=file desciptor of program
124+ Push64 (emu , (uintptr_t )main -> PHEntries ._64 ); Push64 (emu , 3 ); //AT_PHDR(3)=address of the PH of the executable
125+ Push64 (emu , sizeof (Elf64_Phdr )); Push64 (emu , 4 ); //AT_PHENT(4)=size of PH entry
126+ Push64 (emu , main -> numPHEntries ); Push64 (emu , 5 ); //AT_PHNUM(5)=number of elf headers
124127 Push64 (emu , box64_pagesize ); Push64 (emu , 6 ); //AT_PAGESZ(6)
125128 //Push64(emu, real_getauxval(7)); Push64(emu, 7); //AT_BASE(7)=ld-2.27.so start (in memory)
126129 Push64 (emu , 0 ); Push64 (emu , 8 ); //AT_FLAGS(8)=0
@@ -145,15 +148,16 @@ void SetupInitialStack(x64emu_t *emu)
145148 | 1 <<30 // ia64
146149 );
147150 Push64 (emu , 16 ); //AT_HWCAP(16)=...
148- // Push64(emu, sysconf(_SC_CLK_TCK )); Push64(emu, 17); //AT_CLKTCK(17)=times() frequency
151+ Push64 (emu , real_getauxval ( 17 )); Push64 (emu , 17 ); //AT_CLKTCK(17)=times() frequency
149152 Push64 (emu , real_getauxval (23 )); Push64 (emu , 23 ); //AT_SECURE(23)
150153 Push64 (emu , p_random ); Push64 (emu , 25 ); //AT_RANDOM(25)=p_random
151154 Push64 (emu , 0
152155 | 1 <<1 // FSGSBASE
153156 ); Push64 (emu , 26 ); //AT_HWCAP2(26)=...
154157 Push64 (emu , p_arg0 ); Push64 (emu , 31 ); //AT_EXECFN(31)=p_arg0
155- Push64 (emu , emu -> context -> vsyscall ); Push64 (emu , 32 ); //AT_SYSINFO(32)=vsyscall
156- //Push64(emu, 0); Push64(emu, 33); //AT_SYSINFO_EHDR(33)=address of vDSO
158+ Push64 (emu , 0 ); Push64 (emu , 32 ); //AT_SYSINFO(32) not available in 64bits
159+ //Push64(emu, (uintptr_t)CreatevDSO64()); Push64(emu, 33); //AT_SYSINFO_EHDR(33)=address of vDSO
160+
157161 if (!emu -> context -> auxval_start ) // store auxval start if needed
158162 emu -> context -> auxval_start = (uintptr_t * )R_RSP ;
159163
0 commit comments