sync hh.org
[hh.org.git] / arch / um / kernel / tt / uaccess_user.c
blobed1abcf4d0576584e78e9df965f803ef5030c054
1 /*
2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
3 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
4 * Licensed under the GPL
5 */
7 #include <string.h>
8 #include "user_util.h"
9 #include "uml_uaccess.h"
10 #include "task.h"
11 #include "kern_util.h"
12 #include "os.h"
13 #include "longjmp.h"
15 int __do_copy_from_user(void *to, const void *from, int n,
16 void **fault_addr, void **fault_catcher)
18 struct tt_regs save = TASK_REGS(get_current())->tt;
19 unsigned long fault;
20 int faulted;
22 fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
23 __do_copy, &faulted);
24 TASK_REGS(get_current())->tt = save;
26 if(!faulted)
27 return 0;
28 else if (fault)
29 return n - (fault - (unsigned long) from);
30 else
31 /* In case of a general protection fault, we don't have the
32 * fault address, so NULL is used instead. Pretend we didn't
33 * copy anything. */
34 return n;
37 static void __do_strncpy(void *dst, const void *src, int count)
39 strncpy(dst, src, count);
42 int __do_strncpy_from_user(char *dst, const char *src, unsigned long count,
43 void **fault_addr, void **fault_catcher)
45 struct tt_regs save = TASK_REGS(get_current())->tt;
46 unsigned long fault;
47 int faulted;
49 fault = __do_user_copy(dst, src, count, fault_addr, fault_catcher,
50 __do_strncpy, &faulted);
51 TASK_REGS(get_current())->tt = save;
53 if(!faulted) return(strlen(dst));
54 else return(-1);
57 static void __do_clear(void *to, const void *from, int n)
59 memset(to, 0, n);
62 int __do_clear_user(void *mem, unsigned long len,
63 void **fault_addr, void **fault_catcher)
65 struct tt_regs save = TASK_REGS(get_current())->tt;
66 unsigned long fault;
67 int faulted;
69 fault = __do_user_copy(mem, NULL, len, fault_addr, fault_catcher,
70 __do_clear, &faulted);
71 TASK_REGS(get_current())->tt = save;
73 if(!faulted) return(0);
74 else return(len - (fault - (unsigned long) mem));
77 int __do_strnlen_user(const char *str, unsigned long n,
78 void **fault_addr, void **fault_catcher)
80 struct tt_regs save = TASK_REGS(get_current())->tt;
81 int ret;
82 unsigned long *faddrp = (unsigned long *)fault_addr;
83 jmp_buf jbuf;
85 *fault_catcher = &jbuf;
86 if(UML_SETJMP(&jbuf) == 0)
87 ret = strlen(str) + 1;
88 else ret = *faddrp - (unsigned long) str;
90 *fault_addr = NULL;
91 *fault_catcher = NULL;
93 TASK_REGS(get_current())->tt = save;
94 return ret;
98 * Overrides for Emacs so that we follow Linus's tabbing style.
99 * Emacs will notice this stuff at the end of the file and automatically
100 * adjust the settings for this buffer only. This must remain at the end
101 * of the file.
102 * ---------------------------------------------------------------------------
103 * Local variables:
104 * c-file-style: "linux"
105 * End: