this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[mldr] Rework How "load" And "setup_stack" Are Handled

I didn't really like the idea of having a bunch of `#ifdefs`, so I decided to implement stub methods for "load" And "setup_stack" that abort if they are called (when they shouldn't be called).

+29 -24
+29 -24
src/startup/mldr/mldr.c
··· 64 64 // 65 65 // Additionally, mldr providers access to native platforms libdl.so APIs (ELF loader). 66 66 67 - #ifdef __x86_64__ 68 67 static void load64(int fd, bool expect_dylinker, struct load_results* lr); 68 + static void setup_stack64(const char* filepath, struct load_results* lr); 69 69 static void reexec32(char** argv); 70 - #endif 71 70 static void load32(int fd, bool expect_dylinker, struct load_results* lr); 71 + static void setup_stack32(const char* filepath, struct load_results* lr); 72 + 72 73 static void load_fat(int fd, cpu_type_t cpu, bool expect_dylinker, char** argv, struct load_results* lr); 73 74 static void load(const char* path, cpu_type_t cpu, bool expect_dylinker, char** argv, struct load_results* lr); 74 75 static int native_prot(int prot); ··· 77 78 static void start_thread(struct load_results* lr); 78 79 static bool is_kernel_at_least(int major, int minor); 79 80 static void* compatible_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); 80 - #ifdef __x86_64__ 81 - static void setup_stack64(const char* filepath, struct load_results* lr); 82 - #endif 83 - static void setup_stack32(const char* filepath, struct load_results* lr); 84 81 85 82 // this is called when argv[0] specifies an interpreter and we need to "unexpand" it (i.e. convert it from a Linux path to a vchrooted path) 86 83 static void vchroot_unexpand_interpreter(struct load_results* lr); ··· 246 243 if (mldr_load_results._32on64) 247 244 setup_stack32(filename, &mldr_load_results); 248 245 else 249 - #ifdef __x86_64__ 250 246 setup_stack64(filename, &mldr_load_results); 251 - #elif __aarch64__ 252 - #error TODO: aarch64 253 - #else 254 - abort(); 255 - #endif 256 247 257 248 int status = dserver_rpc_set_dyld_info(mldr_load_results.dyld_all_image_location, mldr_load_results.dyld_all_image_size); 258 249 if (status < 0) { ··· 298 289 299 290 if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) 300 291 { 301 - #ifdef __x86_64__ 302 292 lseek(fd, 0, SEEK_SET); 303 293 load64(fd, expect_dylinker, lr); 304 - #else 305 - abort(); 306 - #endif 307 294 } 308 295 else if (magic == MH_MAGIC || magic == MH_CIGAM) 309 296 { 310 - #if !__x86_64__ 297 + #if defined(__i386__) 311 298 lseek(fd, 0, SEEK_SET); 312 299 load32(fd, expect_dylinker, lr); 313 300 #else ··· 422 409 } 423 410 424 411 if (best_arch.cputype & CPU_ARCH_ABI64) { 425 - #ifdef __x86_64__ 426 412 load64(fd, expect_dylinker, lr); 427 - #elif __aarch64__ 428 - #error TODO: aarch64 429 - #else 430 - abort(); 431 - #endif 432 413 } else { 433 - #if !__x86_64__ 414 + #if defined(__i386__) 434 415 load32(fd, expect_dylinker, lr); 435 416 #else 436 417 // Re-run self as mldr32 ··· 444 425 #include "loader.c" 445 426 #include "stack.c" 446 427 #undef GEN_64BIT 428 + 429 + #else 430 + static void load64(int fd, bool expect_dylinker, struct load_results* lr) { 431 + perror("Unexpected entry to load64, aborting..."); 432 + abort(); 433 + } 434 + 435 + static void setup_stack64(const char* filepath, struct load_results* lr) { 436 + perror("Unexpected entry to setup_stack64, aborting..."); 437 + abort(); 438 + } 447 439 #endif 448 440 441 + #if defined(__i386__) 449 442 #define GEN_32BIT 450 443 #include "loader.c" 451 444 #include "stack.c" 452 445 #undef GEN_32BIT 446 + 447 + #else 448 + static void load32(int fd, bool expect_dylinker, struct load_results* lr) { 449 + perror("Unexpected entry to load32, aborting..."); 450 + abort(); 451 + } 452 + 453 + static void setup_stack32(const char* filepath, struct load_results* lr) { 454 + perror("Unexpected entry to setup_stack32, aborting..."); 455 + abort(); 456 + } 457 + #endif 453 458 454 459 int native_prot(int prot) 455 460 {