- thread_act_t thr_act;
- int rc;
- vm_map_t map;
-
- if (first_act) {
- thr_act = &pageout_act;
- first_act = FALSE;
- } else
- thr_act = (thread_act_t)zalloc(thr_act_zone);
- if (thr_act == 0)
- return(KERN_RESOURCE_SHORTAGE);
-
-#if MACH_ASSERT
- if (watchacts & WA_ACT_LNK)
- printf("act_create(task=%x,thr_act@%x=%x)\n",
- task, new_act, thr_act);
-#endif /* MACH_ASSERT */
-
- /* Start by zeroing everything; then init non-zero items only */
- bzero((char *)thr_act, sizeof(*thr_act));
-
- if (thr_act == &pageout_act)
- thr_act->thread = &pageout_thread;
-
-#ifdef MACH_BSD
- {
- /*
- * Take care of the uthread allocation
- * do it early in order to make KERN_RESOURCE_SHORTAGE
- * handling trivial
- * uthread_alloc() will bzero the storage allocated.
- */
- extern void *uthread_alloc(task_t, thread_act_t);
-
- thr_act->uthread = uthread_alloc(task, thr_act);
- if(thr_act->uthread == 0) {
- /* Put the thr_act back on the thr_act zone */
- zfree(thr_act_zone, (vm_offset_t)thr_act);
- return(KERN_RESOURCE_SHORTAGE);
- }
- }
-#endif /* MACH_BSD */
-
- /*
- * Start with one reference for the caller and one for the
- * act being alive.
- */
- act_lock_init(thr_act);
- thr_act->ref_count = 2;
-
- /* Latch onto the task. */
- thr_act->task = task;
- task_reference(task);
-
- /* special_handler will always be last on the returnhandlers list. */
- thr_act->special_handler.next = 0;
- thr_act->special_handler.handler = special_handler;
-
-#if MACH_PROF
- thr_act->act_profiled = FALSE;
- thr_act->act_profiled_own = FALSE;
- thr_act->profil_buffer = NULLPROFDATA;
-#endif
-
- /* Initialize the held_ulocks queue as empty */
- queue_init(&thr_act->held_ulocks);