--- Gnu-Mach/kern/task.c 2020/09/02 04:47:38 1.1.1.4 +++ Gnu-Mach/kern/task.c 2020/09/02 04:54:07 1.1.1.7 @@ -63,7 +63,7 @@ ipc_port_t new_task_notification = NULL; void task_init(void) { kmem_cache_init(&task_cache, "task", sizeof(struct task), 0, - NULL, NULL, NULL, 0); + NULL, 0); eml_init(); machine_task_module_init (); @@ -75,6 +75,7 @@ void task_init(void) */ (void) task_create(TASK_NULL, FALSE, &kernel_task); (void) task_set_name(kernel_task, "gnumach"); + vm_map_set_name(kernel_map, kernel_task->name); } kern_return_t task_create( @@ -89,9 +90,8 @@ kern_return_t task_create( #endif new_task = (task_t) kmem_cache_alloc(&task_cache); - if (new_task == TASK_NULL) { - panic("task_create: no memory for task structure"); - } + if (new_task == TASK_NULL) + return KERN_RESOURCE_SHORTAGE; /* one ref for just being alive; one for our caller */ new_task->ref_count = 2; @@ -101,10 +101,23 @@ kern_return_t task_create( } else if (inherit_memory) { new_task->map = vm_map_fork(parent_task->map); } else { - new_task->map = vm_map_create(pmap_create(0), + pmap_t new_pmap = pmap_create((vm_size_t) 0); + if (new_pmap == PMAP_NULL) + new_task->map = VM_MAP_NULL; + else { + new_task->map = vm_map_create(new_pmap, round_page(VM_MIN_ADDRESS), - trunc_page(VM_MAX_ADDRESS), TRUE); + trunc_page(VM_MAX_ADDRESS)); + if (new_task->map == VM_MAP_NULL) + pmap_destroy(new_pmap); + } + } + if (new_task->map == VM_MAP_NULL) { + kmem_cache_free(&task_cache, (vm_address_t) new_task); + return KERN_RESOURCE_SHORTAGE; } + if (child_task != &kernel_task) + vm_map_set_name(new_task->map, new_task->name); simple_lock_init(&new_task->lock); queue_init(&new_task->thread_list); @@ -378,7 +391,7 @@ kern_return_t task_terminate( task_unlock(task); thread_force_terminate(thread); thread_deallocate(thread); - thread_block((void (*)()) 0); + thread_block(thread_no_continuation); task_lock(task); } task_unlock(task); @@ -566,7 +579,7 @@ kern_return_t task_threads( unsigned int actual; /* this many threads */ thread_t thread; thread_t *threads; - int i; + unsigned i; vm_size_t size, size_needed; vm_offset_t addr; @@ -784,7 +797,8 @@ kern_return_t task_info( = task->total_system_time.seconds; basic_info->system_time.microseconds = task->total_system_time.microseconds; - basic_info->creation_time = task->creation_time; + read_time_stamp(&task->creation_time, + &basic_info->creation_time); task_unlock(task); if (*task_info_count > TASK_BASIC_INFO_COUNT) @@ -893,7 +907,7 @@ task_assign( task->assign_active = TRUE; assert_wait((event_t)&task->assign_active, TRUE); task_unlock(task); - thread_block((void (*)()) 0); + thread_block(thread_no_continuation); task_lock(task); } @@ -1064,6 +1078,9 @@ kern_return_t task_get_assignment( task_t task, processor_set_t *pset) { + if (task == TASK_NULL) + return KERN_INVALID_ARGUMENT; + if (!task->active) return KERN_FAILURE;