]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_control.c
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / kern / kern_control.c
index 95c9cbe2eb5f0697ba2b96f2373cc6c96809b28a..e742a0debe7aefa9a4fa1f886602a6fc8c20f333 100644 (file)
@@ -1,23 +1,29 @@
 /*
  * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 /*
@@ -68,45 +74,6 @@ static lck_attr_t            *ctl_lck_attr = 0;
 static lck_grp_t               *ctl_lck_grp = 0;
 static lck_mtx_t               *ctl_mtx;
 
-/*
- * internal structure maintained for each register controller 
- */
-
-struct ctl_cb;
-
-struct kctl
-{
-       TAILQ_ENTRY(kctl)       next;           /* controller chain */
-       
-       /* controller information provided when registering */
-       char                            name[MAX_KCTL_NAME]; /* unique nke identifier, provided by DTS */
-       u_int32_t                       id;
-       u_int32_t                       reg_unit;
-       
-       /* misc communication information */
-       u_int32_t       flags;                  /* support flags */
-       u_int32_t       recvbufsize;            /* request more than the default buffer size */
-       u_int32_t       sendbufsize;            /* request more than the default buffer size */
-       
-       /* Dispatch functions */
-       ctl_connect_func        connect;        /* Make contact */
-       ctl_disconnect_func     disconnect;     /* Break contact */
-       ctl_send_func           send;           /* Send data to nke */
-       ctl_setopt_func         setopt;         /* set kctl configuration */
-       ctl_getopt_func         getopt;         /* get kctl configuration */
-       
-       TAILQ_HEAD(, ctl_cb)    kcb_head;
-       u_int32_t                               lastunit;
-};
-
-struct ctl_cb {
-       TAILQ_ENTRY(ctl_cb)     next;           /* controller chain */
-       lck_mtx_t                               *mtx;
-       struct socket                   *so;            /* controlling socket */
-       struct kctl                             *kctl;          /* back pointer to controller */
-       u_int32_t                               unit;
-       void                                    *userdata;
-};
 
 /* all the controllers are chained */
 TAILQ_HEAD(, kctl)     ctl_head;
@@ -179,7 +146,6 @@ kern_control_init(void)
                        error = ENOMEM;
                        goto done;
        }
-       lck_grp_attr_setdefault(ctl_lck_grp_attr);
                        
        ctl_lck_grp = lck_grp_alloc_init("Kernel Control Protocol", ctl_lck_grp_attr);
        if (ctl_lck_grp == 0) {
@@ -194,7 +160,6 @@ kern_control_init(void)
                        error = ENOMEM;
                        goto done;
        }
-       lck_attr_setdefault(ctl_lck_attr);
        
        ctl_mtx = lck_mtx_alloc_init(ctl_lck_grp, ctl_lck_attr);
        if (ctl_mtx == 0) {
@@ -920,12 +885,9 @@ static int
 ctl_lock(struct socket *so, int refcount, int lr)
  {
        int lr_saved;
-#ifdef __ppc__
-       if (lr == 0) {
-                       __asm__ volatile("mflr %0" : "=r" (lr_saved));
-       }
+       if (lr == 0) 
+               lr_saved = (unsigned int) __builtin_return_address(0);
        else lr_saved = lr;
-#endif
        
        if (so->so_pcb) {
                lck_mtx_lock(((struct ctl_cb *)so->so_pcb)->mtx);
@@ -940,7 +902,9 @@ ctl_lock(struct socket *so, int refcount, int lr)
        
        if (refcount)
                so->so_usecount++;
-       so->reserved3 = (void *)lr_saved;
+
+       so->lock_lr[so->next_lock_lr] = (void *)lr_saved;
+       so->next_lock_lr = (so->next_lock_lr+1) % SO_LCKDBG_MAX;
        return (0);
 }
 
@@ -950,12 +914,9 @@ ctl_unlock(struct socket *so, int refcount, int lr)
        int lr_saved;
        lck_mtx_t * mutex_held;
        
-#ifdef __ppc__
-       if (lr == 0) {
-               __asm__ volatile("mflr %0" : "=r" (lr_saved));
-       }
+       if (lr == 0) 
+               lr_saved = (unsigned int) __builtin_return_address(0);
        else lr_saved = lr;
-#endif
        
 #ifdef MORE_KCTLLOCK_DEBUG
        printf("ctl_unlock: so=%x sopcb=%x lock=%x ref=%x lr=%x\n",
@@ -973,8 +934,9 @@ ctl_unlock(struct socket *so, int refcount, int lr)
                mutex_held = ((struct ctl_cb *)so->so_pcb)->mtx;
        }
        lck_mtx_assert(mutex_held, LCK_MTX_ASSERT_OWNED);
+       so->unlock_lr[so->next_unlock_lr] = (void *)lr_saved;
+       so->next_unlock_lr = (so->next_unlock_lr+1) % SO_LCKDBG_MAX;
        lck_mtx_unlock(mutex_held);
-       so->reserved4 = (void *)lr_saved;
        
        if (so->so_usecount == 0)
                ctl_sofreelastref(so);