2 * GINGE - GINGE Is Not Gp2x Emulator
5 * This work is licensed under the MAME license, see COPYING file for details.
17 static void next_line(FILE *f)
22 } while (c != EOF && c != '\n');
25 __attribute__((constructor))
26 static void ginge_init(void)
28 void *lowest_segments[2] = { NULL, NULL };
29 unsigned int start, end;
33 for (i = 0; i < ARRAY_SIZE(real_funcs_np); i++) {
34 *real_funcs_np[i].func_ptr = dlsym(RTLD_NEXT, real_funcs_np[i].name);
35 if (*real_funcs_np[i].func_ptr == NULL) {
36 fprintf(stderr, "dlsym %s: %s\n", real_funcs_np[i].name, dlerror());
39 // dbg("%p %s\n", *real_funcs_np[i].func_ptr, real_funcs_np[i].name);
42 f = fopen("/proc/self/maps", "r");
44 perror("open /proc/self/maps");
48 ret = fscanf(f, "%x-%x ", &start, &end);
53 lowest_segments[0] = (void *)start;
58 ret = fscanf(f, "%x-%*s %*s %*s %*s %*s %*s\n", &start);
62 if (lowest_segments[0] == NULL || (void *)start < lowest_segments[0])
63 lowest_segments[0] = (void *)start;
64 else if (lowest_segments[1] == NULL
65 && (char *)start - (char *)lowest_segments[0] > 0x800000)
67 // an offset is needed because ld-linux also
68 // tends to put stuff here
69 lowest_segments[1] = (void *)(start - 0x20000);
76 while (fgets(buff, sizeof(buff), f))
81 // remove self from preload, further commands (from system() and such)
82 // will be handled by ginge_prep.
83 unsetenv("LD_PRELOAD");
84 unsetenv("LD_LIBRARY_PATH");
86 emu_init(lowest_segments, 1);
89 // vim:shiftwidth=2:expandtab