@@ -128,28 +128,28 @@ static i64 LoadElfLoadSegment(struct Machine *m, const char *path, void *image,
128128 }
129129 if (offset > imagesize ) {
130130 ERRF ("bad phdr offset" );
131- exit (127 );
131+ exit (EXIT_FAILURE_EXEC_FAILED );
132132 }
133133 if (filesz > imagesize ) {
134134 ERRF ("bad phdr filesz" );
135- exit (127 );
135+ exit (EXIT_FAILURE_EXEC_FAILED );
136136 }
137137 if (filesz && offset + filesz > imagesize ) {
138138 ERRF ("corrupt elf program header" );
139- exit (127 );
139+ exit (EXIT_FAILURE_EXEC_FAILED );
140140 }
141141 if (end < last_end ) {
142142 ERRF ("program headers aren't ordered, expected %" PRIx64 " >= %" PRIx64 ,
143143 end , last_end );
144- exit (127 );
144+ exit (EXIT_FAILURE_EXEC_FAILED );
145145 }
146146 if (skew != (offset & (pagesize - 1 ))) {
147147 WriteErrorString (
148148 "p_vaddr p_offset skew unequal w.r.t. page size; try either "
149149 "(1) rebuilding your program using the linker flags: -static "
150150 "-Wl,-z,common-page-size=65536,-z,max-page-size=65536 or (2) "
151151 "using `blink -m` to disable the linear memory optimization\n" );
152- exit (127 );
152+ exit (EXIT_FAILURE_EXEC_FAILED );
153153 }
154154
155155 // on systems with a page size greater than the elf executable (e.g.
@@ -210,7 +210,7 @@ static i64 LoadElfLoadSegment(struct Machine *m, const char *path, void *image,
210210 start + bulk , offset , offset + bulk );
211211 if (ReserveVirtual (s , start , bulk , key , fd , offset , 0 , 0 ) == -1 ) {
212212 ERRF ("failed to map elf program header file data" );
213- exit (127 );
213+ exit (EXIT_FAILURE_EXEC_FAILED );
214214 }
215215 if ((amt = bulk - filesz )) {
216216 ELF_LOGF ("note: next copy is actually bzero() kludge" );
@@ -225,7 +225,7 @@ static i64 LoadElfLoadSegment(struct Machine *m, const char *path, void *image,
225225 ELF_LOGF ("alloc %" PRIx64 "-%" PRIx64 , start , end );
226226 if (ReserveVirtual (s , start , end - start , key , -1 , 0 , 0 , 0 ) == -1 ) {
227227 ERRF ("failed to allocate program header bss" );
228- exit (127 );
228+ exit (EXIT_FAILURE_EXEC_FAILED );
229229 }
230230 }
231231 }
@@ -378,7 +378,7 @@ static i64 ChooseAslr(const Elf64_Ehdr_ *ehdr, size_t size, i64 dflt,
378378 i64 aslr ;
379379 if (GetElfMemorySize (ehdr , size , base ) <= 0 ) {
380380 ERRF ("couldn't determine boundaries of loaded executable" );
381- exit (127 );
381+ exit (EXIT_FAILURE_EXEC_FAILED );
382382 }
383383 if (Read16 (ehdr -> type ) == ET_DYN_ && !* base ) {
384384 aslr = dflt ;
@@ -390,7 +390,7 @@ static i64 ChooseAslr(const Elf64_Ehdr_ *ehdr, size_t size, i64 dflt,
390390 * base += aslr ;
391391 if (!(* base & ~(FLAG_pagesize - 1 ))) {
392392 ERRF ("won't load program to null base address" );
393- exit (127 );
393+ exit (EXIT_FAILURE_EXEC_FAILED );
394394 }
395395 return aslr ;
396396}
@@ -427,7 +427,7 @@ static bool LoadElf(struct Machine *m, //
427427 elf -> interpreter = (char * )ehdr + Read64 (phdr -> offset );
428428 if (elf -> interpreter [Read64 (phdr -> filesz ) - 1 ]) {
429429 ELF_LOGF ("elf interpreter not nul terminated" );
430- exit (127 );
430+ exit (EXIT_FAILURE_EXEC_FAILED );
431431 }
432432 break ;
433433 default :
@@ -455,7 +455,7 @@ static bool LoadElf(struct Machine *m, //
455455 FormatInt64 (ibuf , errno );
456456 WriteErrorString (ibuf );
457457 WriteErrorString (")\n" );
458- exit (127 );
458+ exit (EXIT_FAILURE_EXEC_FAILED );
459459 }
460460 aslr = ChooseAslr (
461461 ehdri , st .st_size ,
@@ -717,7 +717,7 @@ void LoadProgram(struct Machine *m, char *execfn, char *prog, char **args,
717717 FormatInt64 (tmp , errno );
718718 WriteErrorString (tmp );
719719 WriteErrorString (")\n" );
720- exit (127 );
720+ exit (EXIT_FAILURE_EXEC_FAILED );
721721 }
722722 status = CanEmulateData (m , & prog , & args , isfirst , (char * )map , mapsize );
723723 if (!status ) {
@@ -727,7 +727,7 @@ error: unsupported executable; we need:\n\
727727- flat executables (.bin files)\n\
728728- actually portable executables (MZqFpD/jartsr)\n\
729729- scripts with #!shebang meeting above criteria\n" );
730- exit (127 );
730+ exit (EXIT_FAILURE_EXEC_FAILED );
731731 } else if (status == 1 ) {
732732 break ; // file is a real executable
733733 } else if (status == 2 ) {
@@ -739,7 +739,7 @@ error: unsupported executable; we need:\n\
739739 isfirst = false;
740740 } else {
741741 LOGF ("shell scripts can't interpret shell scripts" );
742- exit (127 );
742+ exit (EXIT_FAILURE_EXEC_FAILED );
743743 }
744744 } else {
745745 __builtin_unreachable ();
@@ -780,7 +780,7 @@ error: unsupported executable; we need:\n\
780780 // Cosmopolitan programs pretty much require at least 47-bit virtual
781781 // addresses; if the host lacks these, then emulate them w/ software
782782 if (FLAG_vabits < 47 ) FLAG_nolinear = true;
783- if (GetElfHeader (tmp , prog , (const char * )map ) == -1 ) exit (127 );
783+ if (GetElfHeader (tmp , prog , (const char * )map ) == -1 ) exit (EXIT_FAILURE_EXEC_FAILED );
784784 memcpy (map , tmp , 64 );
785785 execstack = LoadElf (m , elf , (Elf64_Ehdr_ * )map , mapsize , fd );
786786 } else {
@@ -797,7 +797,7 @@ error: unsupported executable; we need:\n\
797797 Put64 (m -> sp , stack + kStackSize );
798798 } else {
799799 LOGF ("failed to reserve stack memory" );
800- exit (127 );
800+ exit (EXIT_FAILURE_EXEC_FAILED );
801801 }
802802 m -> system -> loaded = true; // in case rwx stack is smc write-protected :'(
803803 LoadArgv (m , execfn , prog , args , vars , elf -> rng );
0 commit comments