--- Gnu-Mach/kern/thread.c 2020/09/02 04:49:59 1.1.1.6 +++ Gnu-Mach/kern/thread.c 2020/09/02 04:54:10 1.1.1.8 @@ -70,6 +70,7 @@ thread_t active_threads[NCPUS]; vm_offset_t active_stacks[NCPUS]; struct kmem_cache thread_cache; +struct kmem_cache thread_stack_cache; queue_head_t reaper_queue; decl_simple_lock_data(, reaper_lock) @@ -195,16 +196,8 @@ kern_return_t stack_alloc( (void) splx(s); if (stack == 0) { - kern_return_t kr; - /* - * Kernel stacks should be naturally aligned, - * so that it is easy to find the starting/ending - * addresses of a stack given an address in the middle. - */ - kr = kmem_alloc_aligned(kmem_map, &stack, KERNEL_STACK_SIZE); - if (kr != KERN_SUCCESS) - return kr; - + stack = kmem_cache_alloc(&thread_stack_cache); + assert(stack != 0); #if MACH_DEBUG stack_init(stack); #endif /* MACH_DEBUG */ @@ -265,7 +258,7 @@ void stack_collect(void) #if MACH_DEBUG stack_finalize(stack); #endif /* MACH_DEBUG */ - kmem_free(kmem_map, stack, KERNEL_STACK_SIZE); + kmem_cache_free(&thread_stack_cache, stack); s = splsched(); stack_lock(); @@ -298,7 +291,15 @@ void stack_privilege( void thread_init(void) { kmem_cache_init(&thread_cache, "thread", sizeof(struct thread), 0, - NULL, NULL, NULL, 0); + NULL, 0); + /* + * Kernel stacks should be naturally aligned, + * so that it is easy to find the starting/ending + * addresses of a stack given an address in the middle. + */ + kmem_cache_init(&thread_stack_cache, "thread_stack", + KERNEL_STACK_SIZE, KERNEL_STACK_SIZE, + NULL, 0); /* * Fill in a template thread for fast initialization. @@ -341,7 +342,7 @@ void thread_init(void) /* thread_template.sched_stamp (later) */ thread_template.recover = (vm_offset_t) 0; - thread_template.vm_privilege = FALSE; + thread_template.vm_privilege = 0; thread_template.user_stop_count = 1; @@ -430,7 +431,7 @@ kern_return_t thread_create( * Create a pcb. The kernel stack is created later, * when the thread is swapped-in. */ - pcb_init(new_thread); + pcb_init(parent_task, new_thread); ipc_thread_init(new_thread); @@ -1424,6 +1425,12 @@ kern_return_t thread_get_state( { kern_return_t ret; +#if defined(__i386__) || defined(__x86_64__) + if (flavor == i386_DEBUG_STATE && thread == current_thread()) + /* This state can be obtained directly for the curren thread. */ + return thread_getstatus(thread, flavor, old_state, old_state_count); +#endif + if (thread == THREAD_NULL || thread == current_thread()) { return KERN_INVALID_ARGUMENT; } @@ -1448,6 +1455,12 @@ kern_return_t thread_set_state( { kern_return_t ret; +#if defined(__i386__) || defined(__x86_64__) + if (flavor == i386_DEBUG_STATE && thread == current_thread()) + /* This state can be set directly for the curren thread. */ + return thread_setstatus(thread, flavor, new_state, new_state_count); +#endif + if (thread == THREAD_NULL || thread == current_thread()) { return KERN_INVALID_ARGUMENT; } @@ -2220,11 +2233,11 @@ thread_wire( thread_lock(thread); if (wired) { - thread->vm_privilege = TRUE; + thread->vm_privilege = 1; stack_privilege(thread); } else { - thread->vm_privilege = FALSE; + thread->vm_privilege = 0; /*XXX stack_unprivilege(thread); */ thread->stack_privilege = 0; } @@ -2331,7 +2344,7 @@ void consider_thread_collect(void) vm_size_t stack_usage( vm_offset_t stack) { - int i; + unsigned i; for (i = 0; i < KERNEL_STACK_SIZE/sizeof(unsigned int); i++) if (((unsigned int *)stack)[i] != STACK_MARKER) @@ -2349,7 +2362,7 @@ void stack_init( vm_offset_t stack) { if (stack_check_usage) { - int i; + unsigned i; for (i = 0; i < KERNEL_STACK_SIZE/sizeof(unsigned int); i++) ((unsigned int *)stack)[i] = STACK_MARKER;