]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/stubs.c
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / dev / i386 / stubs.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
8f6c56a5 11 *
6601e61a
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22/*
23 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
24 * Copyright (c) 1993 NeXT Computer, Inc.
25 *
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
1c79356b
A
30#include <sys/ioctl.h>
31#include <sys/tty.h>
32#include <sys/conf.h>
91447636
A
33#include <sys/kauth.h>
34#include <sys/ucred.h>
35#include <sys/proc_internal.h>
1c79356b
A
36#include <sys/user.h>
37#include <kern/task.h>
38#include <kern/thread.h>
1c79356b
A
39#include <vm/vm_map.h>
40
91447636 41/* XXX should be elsewhere (cpeak) */
6601e61a 42extern int set_bsduthreadargs(thread_t, void *, void *);
91447636
A
43extern void *get_bsduthreadarg(thread_t);
44extern int *get_bsduthreadrval(thread_t);
6601e61a 45extern int *get_bsduthreadlowpridelay(thread_t);
1c79356b
A
46
47/*
48 * copy a null terminated string from the kernel address space into
49 * the user address space.
50 * - if the user is denied write access, return EFAULT.
51 * - if the end of string isn't found before
52 * maxlen bytes are copied, return ENAMETOOLONG,
53 * indicating an incomplete copy.
54 * - otherwise, return 0, indicating success.
55 * the number of bytes copied is always returned in lencopied.
56 */
57int
91447636 58copyoutstr(const void *from, user_addr_t to, size_t maxlen, size_t *lencopied)
1c79356b 59{
91447636
A
60 size_t slen;
61 size_t len;
62 int error = 0;
1c79356b
A
63
64 slen = strlen(from) + 1;
55e303ae
A
65 if (slen > maxlen)
66 error = ENAMETOOLONG;
1c79356b
A
67
68 len = min(maxlen,slen);
69 if (copyout(from, to, len))
55e303ae 70 error = EFAULT;
1c79356b
A
71 *lencopied = len;
72
73 return error;
74}
75
76
77/*
78 * copy a null terminated string from one point to another in
79 * the kernel address space.
80 * - no access checks are performed.
81 * - if the end of string isn't found before
82 * maxlen bytes are copied, return ENAMETOOLONG,
83 * indicating an incomplete copy.
84 * - otherwise, return 0, indicating success.
85 * the number of bytes copied is always returned in lencopied.
86 */
87/* from ppc/fault_copy.c -Titan1T4 VERSION */
88int
91447636 89copystr(const void *vfrom, void *vto, size_t maxlen, size_t *lencopied)
1c79356b 90{
91447636
A
91 size_t l;
92 char const *from = (char const *) vfrom;
93 char *to = (char *) vto;
94
95 for (l = 0; l < maxlen; l++) {
96 if ((*to++ = *from++) == '\0') {
97 if (lencopied)
98 *lencopied = l + 1;
99 return 0;
100 }
101 }
102 if (lencopied)
103 *lencopied = maxlen;
104 return ENAMETOOLONG;
1c79356b
A
105}
106
91447636
A
107int
108copywithin(void *src, void *dst, size_t count)
1c79356b
A
109{
110 bcopy(src,dst,count);
111 return 0;
112}
113
6601e61a
A
114int
115set_bsduthreadargs(thread_t th, void * pcb, __unused void *ignored_arg)
116{
91447636 117 struct uthread * ut;
6601e61a 118 struct proc *p = current_proc();
89b3af67 119
6601e61a
A
120 ut = get_bsdthread_info(th);
121 ut->uu_ar0 = (int *)pcb;
122
123 /*
124 * Delayed binding of thread credential to process credential.
125 *
126 * XXX This doesn't really belong here, but the i386 code has a
127 * XXX number of seemingly gratuitous structural differences that
128 * XXX make this the most appropriate place to do the work.
129 */
130 if (ut->uu_ucred != p->p_ucred &&
131 (ut->uu_flag & UT_SETUID) == 0) {
132 kauth_cred_t old = ut->uu_ucred;
133 proc_lock(p);
134 ut->uu_ucred = p->p_ucred;
135 kauth_cred_ref(ut->uu_ucred);
136 proc_unlock(p);
137 if (old != NOCRED)
138 kauth_cred_rele(old);
139 }
4452a7af 140
6601e61a 141 return(1);
1c79356b
A
142}
143
144void *
145get_bsduthreadarg(thread_t th)
146{
6601e61a 147struct uthread *ut;
1c79356b 148 ut = get_bsdthread_info(th);
6601e61a 149 return((void *)(ut->uu_arg));
1c79356b
A
150}
151
152int *
91447636 153get_bsduthreadrval(thread_t th)
1c79356b 154{
6601e61a 155struct uthread *ut;
21362eb3 156 ut = get_bsdthread_info(th);
4452a7af 157 return(&ut->uu_rval[0]);
21362eb3 158}
6601e61a
A
159
160int *
161get_bsduthreadlowpridelay(thread_t th)
162{
163struct uthread *ut;
164 ut = get_bsdthread_info(th);
165 return(&ut->uu_lowpri_delay);
166}