]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/bsd_kern.c
xnu-1228.7.58.tar.gz
[apple/xnu.git] / osfmk / kern / bsd_kern.c
index 1a7d3f2dd637cf047f93d5169fbf007630f0a1e9..d09e4ea6e882e716efb88e6961440601c7772318 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -57,9 +57,10 @@ boolean_t thread_should_abort(thread_t);
 boolean_t current_thread_aborted(void);
 void task_act_iterate_wth_args(task_t, void(*)(thread_t, void *), void *);
 void ipc_port_release(ipc_port_t);
-boolean_t is_thread_active(thread_t);
 kern_return_t get_signalact(task_t , thread_t *, int);
 int get_vmsubmap_entries(vm_map_t, vm_object_offset_t, vm_object_offset_t);
+void syscall_exit_funnelcheck(void);
+
 
 /*
  *
@@ -69,6 +70,14 @@ void  *get_bsdtask_info(task_t t)
        return(t->bsd_info);
 }
 
+/*
+ *
+ */
+void *get_bsdthreadtask_info(thread_t th)
+{
+       return(th->task != TASK_NULL ? th->task->bsd_info : NULL);
+}
+
 /*
  *
  */
@@ -123,15 +132,15 @@ get_signalact(
 
        for (inc  = (thread_t)queue_first(&task->threads);
                        !queue_end(&task->threads, (queue_entry_t)inc); ) {
-                thread_mtx_lock(inc);
-                if (inc->active  && 
-                           (inc->state & (TH_ABORT|TH_ABORT_SAFELY)) != TH_ABORT) {
-                    thread = inc;
-                                       break;
-                }
-                thread_mtx_unlock(inc);
-
-                               inc = (thread_t)queue_next(&inc->task_threads);
+               thread_mtx_lock(inc);
+               if (inc->active &&
+                               (inc->sched_mode & TH_MODE_ISABORTED) != TH_MODE_ABORT) {
+                       thread = inc;
+                       break;
+               }
+               thread_mtx_unlock(inc);
+
+               inc = (thread_t)queue_next(&inc->task_threads);
        }
 
        if (result_out) 
@@ -175,7 +184,7 @@ check_actforsig(
                        thread_mtx_lock(inc);
 
                        if (inc->active  && 
-                               (inc->state & (TH_ABORT|TH_ABORT_SAFELY)) != TH_ABORT) {
+                                       (inc->sched_mode & TH_MODE_ISABORTED) != TH_MODE_ABORT) {
                                result = KERN_SUCCESS;
                                break;
                        }
@@ -296,43 +305,6 @@ task_t     get_threadtask(thread_t th)
        return(th->task);
 }
 
-
-/*
- *
- */
-boolean_t is_thread_idle(thread_t th)
-{
-       return((th->state & TH_IDLE) == TH_IDLE);
-}
-
-/*
- *
- */
-boolean_t is_thread_running(thread_t th)
-{
-       return((th->state & TH_RUN) == TH_RUN);
-}
-
-/*
- *
- */
-thread_t
-getshuttle_thread(
-       thread_t        th)
-{
-       return(th);
-}
-
-/*
- *
- */
-thread_t
-getact_thread(
-       thread_t        th)
-{
-       return(th);
-}
-
 /*
  *
  */
@@ -450,7 +422,7 @@ boolean_t
 thread_should_abort(
        thread_t th)
 {
-       return ((th->state & (TH_ABORT|TH_ABORT_SAFELY)) == TH_ABORT);
+       return ((th->sched_mode & TH_MODE_ISABORTED) == TH_MODE_ABORT);
 }
 
 /*
@@ -468,14 +440,14 @@ current_thread_aborted (
        thread_t th = current_thread();
        spl_t s;
 
-       if ((th->state & (TH_ABORT|TH_ABORT_SAFELY)) == TH_ABORT &&
+       if ((th->sched_mode & TH_MODE_ISABORTED) == TH_MODE_ABORT &&
                        (th->options & TH_OPT_INTMASK) != THREAD_UNINT)
                return (TRUE);
-       if (th->state & TH_ABORT_SAFELY) {
+       if (th->sched_mode & TH_MODE_ABORTSAFELY) {
                s = splsched();
                thread_lock(th);
-               if (th->state & TH_ABORT_SAFELY)
-                       th->state &= ~(TH_ABORT|TH_ABORT_SAFELY);
+               if (th->sched_mode & TH_MODE_ABORTSAFELY)
+                       th->sched_mode &= ~TH_MODE_ISABORTED;
                thread_unlock(th);
                splx(s);
        }
@@ -511,13 +483,6 @@ ipc_port_release(
        ipc_object_release(&(port)->ip_object);
 }
 
-boolean_t
-is_thread_active(
-       thread_t th)
-{
-       return(th->active);
-}
-
 void
 astbsd_on(void)
 {
@@ -537,13 +502,14 @@ fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo)
        vm_map_t map;
        task_absolutetime_info_data_t   tinfo;
        thread_t thread;
-       int numrunning = 0;
+       int cswitch = 0, numrunning = 0;
        
        map = (task == kernel_task)? kernel_map: task->map;
 
        ptinfo->pti_virtual_size  = map->size;
-       ptinfo->pti_resident_size  = (mach_vm_size_t)(pmap_resident_count(map->pmap)
-                                  * PAGE_SIZE);
+       ptinfo->pti_resident_size =
+               (mach_vm_size_t)(pmap_resident_count(map->pmap))
+               * PAGE_SIZE_64;
 
        task_lock(task);
 
@@ -559,6 +525,7 @@ fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo)
 
                if ((thread->state & TH_RUN) == TH_RUN)
                        numrunning++;
+               cswitch += thread->c_switch;
                tval = timer_grab(&thread->user_timer);
                tinfo.threads_user += tval;
                tinfo.total_user += tval;
@@ -580,7 +547,7 @@ fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo)
        ptinfo->pti_messages_received = task->messages_received;
        ptinfo->pti_syscalls_mach = task->syscalls_mach;
        ptinfo->pti_syscalls_unix = task->syscalls_unix;
-       ptinfo->pti_csw = task->csw;
+       ptinfo->pti_csw = task->c_switch + cswitch;
        ptinfo->pti_threadnum = task->thread_count;
        ptinfo->pti_numrunning = numrunning;
        ptinfo->pti_priority = task->priority;
@@ -589,10 +556,11 @@ fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo)
 }
 
 int 
-fill_taskthreadinfo(task_t task, uint64_t thaddr, struct proc_threadinfo_internal * ptinfo)
+fill_taskthreadinfo(task_t task, uint64_t thaddr, struct proc_threadinfo_internal * ptinfo, void * vpp, int *vidp)
 {
        thread_t  thact;
-       int err=0, count;
+       int err=0;
+       mach_msg_type_number_t count;
        thread_basic_info_data_t basic_info;
        kern_return_t kret;
 
@@ -600,7 +568,7 @@ fill_taskthreadinfo(task_t task, uint64_t thaddr, struct proc_threadinfo_interna
 
        for (thact  = (thread_t)queue_first(&task->threads);
                        !queue_end(&task->threads, (queue_entry_t)thact); ) {
-#if defined(__ppc__)
+#if defined(__ppc__) || defined(__arm__)
                if (thact->machine.cthread_self == thaddr)
 #elif defined (__i386__)
                if (thact->machine.pcb->cthread_self == thaddr)
@@ -610,7 +578,7 @@ fill_taskthreadinfo(task_t task, uint64_t thaddr, struct proc_threadinfo_interna
                {
                
                        count = THREAD_BASIC_INFO_COUNT;
-                       if ((kret = thread_info_internal(thact, THREAD_BASIC_INFO, &basic_info, &count)) != KERN_SUCCESS) {
+                       if ((kret = thread_info_internal(thact, THREAD_BASIC_INFO, (thread_info_t)&basic_info, &count)) != KERN_SUCCESS) {
                                err = 1;
                                goto out;       
                        }
@@ -631,6 +599,8 @@ fill_taskthreadinfo(task_t task, uint64_t thaddr, struct proc_threadinfo_interna
                        ptinfo->pth_priority = thact->priority;
                        ptinfo->pth_maxpriority = thact->max_priority;
                        
+                       if ((vpp != NULL) && (thact->uthread != NULL)) 
+                               bsd_threadcdir(thact->uthread, vpp, vidp);
                        err = 0;
                        goto out; 
                }
@@ -657,7 +627,7 @@ fill_taskthreadlist(task_t task, void * buffer, int thcount)
 
        for (thact  = (thread_t)queue_first(&task->threads);
                        !queue_end(&task->threads, (queue_entry_t)thact); ) {
-#if defined(__ppc__)
+#if defined(__ppc__) || defined(__arm__)
                thaddr = thact->machine.cthread_self;
 #elif defined (__i386__)
                thaddr = thact->machine.pcb->cthread_self;
@@ -683,3 +653,13 @@ get_numthreads(task_t task)
        return(task->thread_count);
 }
 
+void 
+syscall_exit_funnelcheck(void)
+{
+        thread_t thread;
+
+       thread = current_thread();
+
+        if (thread->funnel_lock)
+               panic("syscall exit with funnel held\n");
+}