]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/stubs.c
xnu-517.tar.gz
[apple/xnu.git] / bsd / dev / i386 / stubs.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
27 * Copyright (c) 1993 NeXT Computer, Inc.
28 *
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/buf.h>
34#include <sys/ioctl.h>
35#include <sys/tty.h>
36#include <sys/conf.h>
37#include <sys/proc.h>
38#include <sys/user.h>
39#include <kern/task.h>
40#include <kern/thread.h>
41#include <kern/thread_act.h>
42#include <vm/vm_map.h>
43
44
45/*
46 * copy a null terminated string from the kernel address space into
47 * the user address space.
48 * - if the user is denied write access, return EFAULT.
49 * - if the end of string isn't found before
50 * maxlen bytes are copied, return ENAMETOOLONG,
51 * indicating an incomplete copy.
52 * - otherwise, return 0, indicating success.
53 * the number of bytes copied is always returned in lencopied.
54 */
55int
56copyoutstr(from, to, maxlen, lencopied)
57 void * from, * to;
58 size_t maxlen, *lencopied;
59{
60 int slen,len,error=0;
61
62 slen = strlen(from) + 1;
55e303ae
A
63 if (slen > maxlen)
64 error = ENAMETOOLONG;
1c79356b
A
65
66 len = min(maxlen,slen);
67 if (copyout(from, to, len))
55e303ae 68 error = EFAULT;
1c79356b
A
69 *lencopied = len;
70
71 return error;
72}
73
74
75/*
76 * copy a null terminated string from one point to another in
77 * the kernel address space.
78 * - no access checks are performed.
79 * - if the end of string isn't found before
80 * maxlen bytes are copied, return ENAMETOOLONG,
81 * indicating an incomplete copy.
82 * - otherwise, return 0, indicating success.
83 * the number of bytes copied is always returned in lencopied.
84 */
85/* from ppc/fault_copy.c -Titan1T4 VERSION */
86int
87copystr(vfrom, vto, maxlen, lencopied)
88 register void * vfrom, *vto;
89 size_t maxlen, *lencopied;
90{
91 register unsigned l;
92 int error;
93caddr_t from, to;
94
95 from = vfrom;
96 to = vto;
97 for (l = 0; l < maxlen; l++)
98 if ((*to++ = *from++) == '\0') {
99 if (lencopied)
100 *lencopied = l + 1;
101 return 0;
102 }
103 if (lencopied)
104 *lencopied = maxlen;
105 return ENAMETOOLONG;
106}
107
108int copywithin(src, dst, count)
109void * src, *dst;
110size_t count;
111{
112 bcopy(src,dst,count);
113 return 0;
114}
115
1c79356b
A
116set_bsduthreadargs(thread_t th, void * pcb, void *ignored_arg)
117{
118struct uthread * ut;
119
120 ut = get_bsdthread_info(th);
121 ut->uu_ar0 = (int *)pcb;
122
123 return(1);
124}
125
126void *
127get_bsduthreadarg(thread_t th)
128{
129struct uthread *ut;
130 ut = get_bsdthread_info(th);
131 return((void *)(ut->uu_arg));
132}
133
134int *
135get_bsduthreadrval(thread_act_t th)
136{
137struct uthread *ut;
138 ut = get_bsdthread_info(th);
139 return(&ut->uu_rval[0]);
140}