diff --git a/src/kernel/core/arch/x86/arch_thread.c b/src/kernel/core/arch/x86/arch_thread.c index d4afdff4d6..78401b06f8 100755 --- a/src/kernel/core/arch/x86/arch_thread.c +++ b/src/kernel/core/arch/x86/arch_thread.c @@ -222,7 +222,7 @@ arch_thread_dump_info(void *info) void arch_thread_enter_uspace(struct thread *t, addr_t entry, void *args1, void *args2) { - addr_t ustack_top = t->user_stack_base + STACK_SIZE; + addr_t ustack_top = t->user_stack_base + t->user_stack_size; TRACE(("arch_thread_enter_uspace: entry 0x%lx, args %p %p, ustack_top 0x%lx\n", entry, args1, args2, ustack_top)); diff --git a/src/kernel/core/team.c b/src/kernel/core/team.c index 88e985edbb..810dbdfb3e 100644 --- a/src/kernel/core/team.c +++ b/src/kernel/core/team.c @@ -510,12 +510,13 @@ team_create_team2(void *args) // create an initial primary stack region - // ToDo: make ENV_SIZE variable? + // ToDo: make ENV_SIZE variable and put it on the heap? // ToDo: we could reserve the whole USER_STACK_REGION upfront... totalSize = PAGE_ALIGN(MAIN_THREAD_STACK_SIZE + TLS_SIZE + ENV_SIZE + get_arguments_data_size(teamArgs->args, teamArgs->argc)); t->user_stack_base = USER_STACK_REGION + USER_STACK_REGION_SIZE - totalSize; + t->user_stack_size = MAIN_THREAD_STACK_SIZE; // the exact location at the end of the user stack region sprintf(ustack_name, "%s_main_stack", team->name); @@ -542,7 +543,7 @@ team_create_team2(void *args) } uargs[arg_cnt] = NULL; - team->user_env_base = t->user_stack_base + STACK_SIZE + TLS_SIZE; + team->user_env_base = t->user_stack_base + t->user_stack_size + TLS_SIZE; uenv = (char **)team->user_env_base; udest = (char *)team->user_env_base + ENV_SIZE - 1; @@ -954,7 +955,7 @@ sys_setenv(const char *name, const char *value, int overwrite) RELEASE_TEAM_LOCK(); restore_interrupts(state); - + return rc; } @@ -970,7 +971,7 @@ sys_getenv(const char *name, char **value) int rc = -1; // ToDo: please put me out of the kernel into libroot.so! - + state = disable_interrupts(); GRAB_TEAM_LOCK(); @@ -985,7 +986,7 @@ sys_getenv(const char *name, char **value) } } } - + RELEASE_TEAM_LOCK(); restore_interrupts(state); diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index ffdcbc72fb..0653c5021f 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -351,11 +351,12 @@ create_thread(const char *name, team_id teamID, thread_entry_func entry, // the stack will be between USER_STACK_REGION and the main thread stack area // (the user stack of the main thread is created in team_create_team()) t->user_stack_base = USER_STACK_REGION; + t->user_stack_size = STACK_SIZE; snprintf(stack_name, B_OS_NAME_LENGTH, "%s_%lx_stack", name, t->id); t->user_stack_region_id = create_area_etc(team, stack_name, (void **)&t->user_stack_base, B_BASE_ADDRESS, - STACK_SIZE + TLS_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + t->user_stack_size + TLS_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (t->user_stack_region_id < 0) { // great, we have a fully running thread without a stack dprintf("create_thread: unable to create user stack!\n"); @@ -735,7 +736,7 @@ thread_exit(void) // Cancel previously installed alarm timer, if any cancel_timer(&t->alarm); - + // delete the user stack region first if (team->_aspace_id >= 0 && t->user_stack_region_id >= 0) { region_id rid = t->user_stack_region_id; @@ -815,7 +816,7 @@ static void thread_kthread_exit(void) { struct thread *t = thread_get_current_thread(); - + t->return_flags = THREAD_RETURN_EXIT; thread_exit(); }