]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/arm/stubs.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / dev / arm / stubs.c
CommitLineData
5ba3f43e
A
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
cb323159 10#include <sys/cdefs.h>
5ba3f43e
A
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/user.h>
20#include <kern/task.h>
21#include <kern/thread.h>
22#include <vm/vm_map.h>
23
24/*
25 * copy a null terminated string from the kernel address space into the user
26 * address space. - if the user is denied write access, return EFAULT. - if
27 * the end of string isn't found before maxlen bytes are copied, return
28 * ENAMETOOLONG, indicating an incomplete copy. - otherwise, return 0,
29 * indicating success. the number of bytes copied is always returned in
30 * lencopied.
31 */
32int
33copyoutstr(const void *from, user_addr_t to, size_t maxlen, size_t * lencopied)
34{
35 size_t slen;
36 size_t len;
cb323159
A
37 int error = copyoutstr_prevalidate(from, to, maxlen);
38
39 if (__improbable(error)) {
40 return error;
41 }
5ba3f43e
A
42
43 slen = strlen(from) + 1;
0a7de745 44 if (slen > maxlen) {
5ba3f43e 45 error = ENAMETOOLONG;
0a7de745 46 }
5ba3f43e 47
f427ee49 48 len = MIN(maxlen, slen);
0a7de745 49 if (copyout(from, to, len)) {
5ba3f43e 50 error = EFAULT;
0a7de745 51 }
5ba3f43e
A
52 *lencopied = len;
53
54 return error;
55}
56
57
58/*
59 * copy a null terminated string from one point to another in the kernel
60 * address space. - no access checks are performed. - if the end of string
61 * isn't found before maxlen bytes are copied, return ENAMETOOLONG,
62 * indicating an incomplete copy. - otherwise, return 0, indicating success.
63 * the number of bytes copied is always returned in lencopied.
64 */
65/* from ppc/fault_copy.c -Titan1T4 VERSION */
66int
67copystr(const void *vfrom, void *vto, size_t maxlen, size_t * lencopied)
68{
69 size_t l;
70 char const *from = (char const *) vfrom;
71 char *to = (char *) vto;
72
73 for (l = 0; l < maxlen; l++) {
74 if ((*to++ = *from++) == '\0') {
0a7de745 75 if (lencopied) {
5ba3f43e 76 *lencopied = l + 1;
0a7de745 77 }
5ba3f43e
A
78 return 0;
79 }
80 }
0a7de745 81 if (lencopied) {
5ba3f43e 82 *lencopied = maxlen;
0a7de745 83 }
5ba3f43e
A
84 return ENAMETOOLONG;
85}
86
87int
88copywithin(void *src, void *dst, size_t count)
89{
90 bcopy(src, dst, count);
91 return 0;
92}