void _start() { /* * Relocate the stack at the end of the last page inside the available memory * and jump to the main function to clear stack context. */ relocate_stack(AVAILABLE_MEMORY MEGABYTES); _cppstart(); }
int main(int argc, char**argv, char **envp) { int i; #ifdef __x86_64__ /* FIXME: this doesn't belong here. */ extern void set_fs(); set_fs(); #endif get_task_size(); /* Take a copy of our argc/argv and environment below we blow them away */ real_argc = argc; real_argv = (char**) xmalloc((sizeof(char*)*argc) + 1); for (i = 0; i < argc; i++) { real_argv[i] = (char*) xmalloc(strlen(argv[i]) + 1); memcpy(real_argv[i], argv[i], strlen(argv[i]) + 1); } real_argv[i] = (char*) xmalloc(sizeof('\0')); *real_argv[i] = '\0'; for(i = 0; envp[i]; i++); /* count environment variables */ real_environ = xmalloc((sizeof(char*)*i)+1); for(i = 0; envp[i]; i++) { *real_environ++ = strdup(envp[i]); #ifdef USE_GTK if (strncmp(envp[i], "DISPLAY=", 8) == 0) { strncpy(display_environ, envp[i]+8, sizeof(display_environ)-1); display_environ[sizeof(display_environ)-1] = '\0'; } else if (strncmp(envp[i], "XAUTHORITY=", 11) == 0) { strncpy(xauthority_environ, envp[i]+11, sizeof(xauthority_environ)-1); xauthority_environ[sizeof(xauthority_environ)-1] = '\0'; } #endif } *real_environ = '\0'; environ = real_environ; real_fd = open_self(); relocate_stack(); /* Now hope for the best! */ real_main(real_argc, real_argv); }