- kern_return_t result;
- task_t new_task;
- vm_map_t old_map;
-
- /*
- * Create the task.
- */
- result = task_create_local(parent_task, FALSE, TRUE, &new_task);
- if (result != KERN_SUCCESS)
- return (result);
-
- /*
- * Task_create_local creates the task with a user-space map.
- * We attempt to replace the map and free it afterwards; else
- * task_deallocate will free it (can NOT set map to null before
- * task_deallocate, this impersonates a norma placeholder task).
- * _Mark the memory as pageable_ -- this is what we
- * want for images (like servers) loaded into the kernel.
- */
- if (map_size == 0) {
- vm_map_deallocate(new_task->map);
- new_task->map = kernel_map;
- *child_task = new_task;
- } else {
- old_map = new_task->map;
- if ((result = kmem_suballoc(kernel_map, &map_base,
- map_size, TRUE, FALSE,
- &new_task->map)) != KERN_SUCCESS) {
- /*
- * New task created with ref count of 2 -- decrement by
- * one to force task deletion.
- */
- printf("kmem_suballoc(%x,%x,%x,1,0,&new) Fails\n",
- kernel_map, map_base, map_size);
- --new_task->ref_count;
- task_deallocate(new_task);
- return (result);
- }
- vm_map_deallocate(old_map);
- *child_task = new_task;
- }
- return (KERN_SUCCESS);