xref: /xnu-12377.81.4/bsd/dev/arm/stubs.c (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3  */
4 /*
5  * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
6  * Copyright (c) 1993 NeXT Computer, Inc.
7  *
8  */
9 
10 #include <sys/cdefs.h>
11 #include <sys/param.h>
12 #include <sys/systm.h>
13 #include <sys/ioctl.h>
14 #include <sys/tty.h>
15 #include <sys/conf.h>
16 #include <sys/kauth.h>
17 #include <sys/ucred.h>
18 #include <sys/proc_internal.h>
19 #include <sys/sysproto.h>
20 #include <sys/user.h>
21 #include <kern/task.h>
22 #include <kern/thread.h>
23 #include <vm/vm_map.h>
24 #include <arm/machine_routines.h>
25 
26 
27 /*
28  * copy a null terminated string from the kernel address space into the user
29  * address space. - if the user is denied write access, return EFAULT. - if
30  * the end of string isn't found before maxlen bytes are copied,  return
31  * ENAMETOOLONG, indicating an incomplete copy. - otherwise, return 0,
32  * indicating success. the number of bytes copied is always returned in
33  * lencopied.
34  */
35 int
copyoutstr(const void * from,user_addr_t to,size_t maxlen,size_t * lencopied)36 copyoutstr(const void *from, user_addr_t to, size_t maxlen, size_t * lencopied)
37 {
38 	size_t          slen;
39 	size_t          len;
40 	int             error = copyoutstr_prevalidate(from, to, maxlen);
41 
42 	if (__improbable(error)) {
43 		return error;
44 	}
45 
46 	slen = strlen(from) + 1;
47 	if (slen > maxlen) {
48 		error = ENAMETOOLONG;
49 	}
50 
51 	len = MIN(maxlen, slen);
52 	if (copyout(from, to, len)) {
53 		error = EFAULT;
54 	}
55 	*lencopied = len;
56 
57 	return error;
58 }
59 
60 
61 /*
62  * copy a null terminated string from one point to another in the kernel
63  * address space. - no access checks are performed. - if the end of string
64  * isn't found before maxlen bytes are copied,  return ENAMETOOLONG,
65  * indicating an incomplete copy. - otherwise, return 0, indicating success.
66  * the number of bytes copied is always returned in lencopied.
67  */
68 /* from ppc/fault_copy.c -Titan1T4 VERSION  */
69 int
copystr(const void * vfrom,void * vto,size_t maxlen,size_t * lencopied)70 copystr(const void *vfrom, void *vto, size_t maxlen, size_t * lencopied)
71 {
72 	size_t          l;
73 	char const     *from = (char const *) vfrom;
74 	char           *to = (char *) vto;
75 
76 	for (l = 0; l < maxlen; l++) {
77 		if ((*to++ = *from++) == '\0') {
78 			if (lencopied) {
79 				*lencopied = l + 1;
80 			}
81 			return 0;
82 		}
83 	}
84 	if (lencopied) {
85 		*lencopied = maxlen;
86 	}
87 	return ENAMETOOLONG;
88 }
89 
90 int
copywithin(void * src,void * dst,size_t count)91 copywithin(void *src, void *dst, size_t count)
92 {
93 	bcopy(src, dst, count);
94 	return 0;
95 }
96 
97 
98 int
objc_bp_assist_cfg_np(__unused struct proc * p,__unused struct objc_bp_assist_cfg_np_args * uap,__unused int * retvalp)99 objc_bp_assist_cfg_np(
100 	__unused struct proc                        *p,
101 	__unused struct objc_bp_assist_cfg_np_args  *uap,
102 	__unused int                                *retvalp)
103 {
104 	int ret = KERN_FAILURE;
105 
106 
107 	return ret;
108 }
109