/* * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) * Licensed under the GPL */ #include #include #include #include #include #include #include #include #include #include #include "kern_util.h" #include "as-layout.h" #include "mem_user.h" #include "irq_user.h" #include "user.h" #include "init.h" #include "mode.h" #include "choose-mode.h" #include "uml-config.h" #include "os.h" #include "um_malloc.h" /* Set in main, unchanged thereafter */ char *linux_prog; #define PGD_BOUND (4 * 1024 * 1024) #define STACKSIZE (8 * 1024 * 1024) #define THREAD_NAME_LEN (256) static void set_stklim(void) { struct rlimit lim; if(getrlimit(RLIMIT_STACK, &lim) < 0){ perror("getrlimit"); exit(1); } if((lim.rlim_cur == RLIM_INFINITY) || (lim.rlim_cur > STACKSIZE)){ lim.rlim_cur = STACKSIZE; if(setrlimit(RLIMIT_STACK, &lim) < 0){ perror("setrlimit"); exit(1); } } } static __init void do_uml_initcalls(void) { initcall_t *call; call = &__uml_initcall_start; while (call < &__uml_initcall_end){ (*call)(); call++; } } static void last_ditch_exit(int sig) { uml_cleanup(); exit(1); } static void install_fatal_handler(int sig) { struct sigaction action; /* All signals are enabled in this handler ... */ sigemptyset(&action.sa_mask); /* ... including the signal being handled, plus we want the * handler reset to the default behavior, so that if an exit * handler is hanging for some reason, the UML will just die * after this signal is sent a second time. */ action.sa_flags = SA_RESETHAND | SA_NODEFER; action.sa_restorer = NULL; action.sa_handler = last_ditch_exit; if(sigaction(sig, &action, NULL) < 0){ printf("failed to install handler for signal %d - errno = %d\n", errno); exit(1); } } #define UML_LIB_PATH ":/usr/lib/uml" static void setup_env_path(void) { char *new_path = NULL; char *old_path = NULL; int path_len = 0; old_path = getenv("PATH"); /* if no PATH variable is set or it has an empty value * just use the default + /usr/lib/uml */ if (!old_path || (path_len = strlen(old_path)) == 0) { putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH); return; } /* append /usr/lib/uml to the existing path */ path_len += strlen("PATH=" UML_LIB_PATH) + 1; new_path = malloc(path_len); if (!new_path) { perror("coudn't malloc to set a new PATH"); return; } snprintf(new_path, path_len, "PATH=%s" UML_LIB_PATH, old_path); putenv(new_path); } extern int uml_exitcode; extern void scan_elf_aux( char **envp); int main(int argc, char **argv, char **envp) { char **new_argv; int ret, i, err; #ifdef UML_CONFIG_CMDLINE_ON_HOST /* Allocate memory for thread command lines */ if(argc < 2 || strlen(argv[1]) < THREAD_NAME_LEN - 1){ char padding[THREAD_NAME_LEN] = { [ 0 ... THREAD_NAME_LEN - 2] = ' ', '\0' }; new_argv = malloc((argc + 2) * sizeof(char*)); if(!new_argv) { perror("Allocating extended argv"); exit(1); } new_argv[0] = argv[0]; new_argv[1] = padding; for(i = 2; i <= argc; i++) new_argv[i] = argv[i - 1]; new_argv[argc + 1] = NULL; execvp(new_argv[0], new_argv); perror("execing with extended args"); exit(1); } #endif linux_prog = argv[0]; set_stklim(); setup_env_path(); new_argv = malloc((argc + 1) * sizeof(char *)); if(new_argv == NULL){ perror("Mallocing argv"); exit(1); } for(i=0;i= uml_physmem) && (addr < high_physmem)){ if(CAN_KMALLOC()) kfree(ptr); } else if((addr >= start_vm) && (addr < end_vm)){ if(CAN_KMALLOC()) vfree(ptr); } else __real_free(ptr); }