/*
- * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_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.
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
*
- * This 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.
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
*
- * @APPLE_LICENSE_HEADER_END@
+ * 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.
+ *
+ * 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, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
*/
/*-
* Copyright (c) 1982, 1986, 1989, 1993
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
-#include <sys/proc.h>
+#include <sys/proc_internal.h>
#include <sys/systm.h>
#include <bsm/audit_kernel.h>
int error = 0;
struct sysctl_oid *oid;
struct sysctl_oid_list *lsp = &sysctl__children, *lsp2;
- char buf[10];
+ char tempbuf[10];
while (namelen) {
if (!lsp) {
- snprintf(buf,sizeof(buf),"%d",*name);
+ snprintf(tempbuf,sizeof(tempbuf),"%d",*name);
if (req->oldidx)
error = SYSCTL_OUT(req, ".", 1);
if (!error)
- error = SYSCTL_OUT(req, buf, strlen(buf));
+ error = SYSCTL_OUT(req, tempbuf, strlen(tempbuf));
if (error)
return (error);
namelen--;
if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */
return (ENAMETOOLONG);
- p = _MALLOC(req->newlen+1, M_TEMP, M_WAITOK);
-
+ MALLOC(p, char *,req->newlen+1, M_TEMP, M_WAITOK);
if (!p)
return ENOMEM;
sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l)
{
size_t i = 0;
- int error = 0;
if (req->oldptr) {
i = l;
if (i > req->oldlen - req->oldidx)
i = req->oldlen - req->oldidx;
if (i > 0)
- bcopy((void*)p, (char *)req->oldptr + req->oldidx, i);
+ bcopy((void*)p, CAST_DOWN(char *, (req->oldptr + req->oldidx)), i);
}
req->oldidx += l;
if (req->oldptr && i != l)
return 0;
if (req->newlen - req->newidx < l)
return (EINVAL);
- bcopy((char *)req->newptr + req->newidx, p, l);
+ bcopy(CAST_DOWN(char *, (req->newptr + req->newidx)), p, l);
req->newidx += l;
return (0);
}
if (oldlenp)
req.oldlen = *oldlenp;
if (old)
- req.oldptr= old;
+ req.oldptr = CAST_USER_ADDR_T(old);
if (newlen) {
req.newlen = newlen;
- req.newptr = new;
+ req.newptr = CAST_USER_ADDR_T(new);
}
req.oldfunc = sysctl_old_kernel;
req.newfunc = sysctl_new_kernel;
/* unlock memory if required */
if (req.lock == 2)
- vsunlock(req.oldptr, req.oldlen, B_WRITE);
+ vsunlock(req.oldptr, (user_size_t)req.oldlen, B_WRITE);
memlock.sl_lock = 0;
if (i > req->oldlen - req->oldidx)
i = req->oldlen - req->oldidx;
if (i > 0)
- error = copyout((void*)p, (char *)req->oldptr + req->oldidx,
- i);
+ error = copyout((void*)p, (req->oldptr + req->oldidx), i);
}
req->oldidx += l;
if (error)
return 0;
if (req->newlen - req->newidx < l)
return (EINVAL);
- error = copyin((char *)req->newptr + req->newidx, p, l);
+ error = copyin((req->newptr + req->newidx), p, l);
req->newidx += l;
return (error);
}
return EINVAL;
}
- /*
- * Switch to the NETWORK funnel for CTL_NET and KERN_IPC sysctls
- */
-
- if (((name[0] == CTL_NET) || ((name[0] == CTL_KERN) &&
- (name[1] == KERN_IPC))))
- thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
i = (oid->oid_handler) (oid,
req);
}
- /*
- * Switch back to the KERNEL funnel, if necessary
- */
-
- if (((name[0] == CTL_NET) || ((name[0] == CTL_KERN) &&
- (name[1] == KERN_IPC))))
- thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
-
return (i);
}
if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
return (EINVAL);
- error = copyin(uap->name, &name, uap->namelen * sizeof(int));
+ error = copyin(CAST_USER_ADDR_T(uap->name), &name, uap->namelen * sizeof(int));
if (error)
return (error);
error = userland_sysctl(p, name, uap->namelen,
- uap->old, uap->oldlenp, 0,
- uap->new, uap->newlen, &j);
+ CAST_USER_ADDR_T(uap->old), uap->oldlenp, 0,
+ CAST_USER_ADDR_T(uap->new), uap->newlen, &j);
if (error && error != ENOMEM)
return (error);
if (uap->oldlenp) {
- i = copyout(&j, uap->oldlenp, sizeof(j));
+ i = copyout(&j, CAST_USER_ADDR_T(uap->oldlenp), sizeof(j));
if (i)
return (i);
}
* must be in kernel space.
*/
int
-userland_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval)
+userland_sysctl(struct proc *p, int *name, u_int namelen, user_addr_t oldp,
+ size_t *oldlenp, int inkernel, user_addr_t newp, size_t newlen,
+ size_t *retval)
{
int error = 0;
struct sysctl_req req, req2;
if (inkernel) {
req.oldlen = *oldlenp;
} else {
- error = copyin(oldlenp, &req.oldlen, sizeof(*oldlenp));
+ error = copyin(CAST_USER_ADDR_T(oldlenp), &req.oldlen, sizeof(*oldlenp));
if (error)
return (error);
}
}
- if (old) {
- req.oldptr= old;
+ if (oldp) {
+ req.oldptr = oldp;
}
if (newlen) {
req.newlen = newlen;
- req.newptr = new;
+ req.newptr = newp;
}
req.oldfunc = sysctl_old_user;