Merge ../linux-2.6-watchdog-mm
[linux-drm-fsl-dcu.git] / arch / um / kernel / tt / uaccess_user.c
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  */
6
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"
14
15 int __do_copy_from_user(void *to, const void *from, int n,
16                         void **fault_addr, void **fault_catcher)
17 {
18         struct tt_regs save = TASK_REGS(get_current())->tt;
19         unsigned long fault;
20         int faulted;
21
22         fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
23                                __do_copy, &faulted);
24         TASK_REGS(get_current())->tt = save;
25
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;
35 }
36
37 static void __do_strncpy(void *dst, const void *src, int count)
38 {
39         strncpy(dst, src, count);
40 }       
41
42 int __do_strncpy_from_user(char *dst, const char *src, unsigned long count,
43                            void **fault_addr, void **fault_catcher)
44 {
45         struct tt_regs save = TASK_REGS(get_current())->tt;
46         unsigned long fault;
47         int faulted;
48
49         fault = __do_user_copy(dst, src, count, fault_addr, fault_catcher,
50                                __do_strncpy, &faulted);
51         TASK_REGS(get_current())->tt = save;
52
53         if(!faulted) return(strlen(dst));
54         else return(-1);
55 }
56
57 static void __do_clear(void *to, const void *from, int n)
58 {
59         memset(to, 0, n);
60 }       
61
62 int __do_clear_user(void *mem, unsigned long len,
63                     void **fault_addr, void **fault_catcher)
64 {
65         struct tt_regs save = TASK_REGS(get_current())->tt;
66         unsigned long fault;
67         int faulted;
68
69         fault = __do_user_copy(mem, NULL, len, fault_addr, fault_catcher,
70                                __do_clear, &faulted);
71         TASK_REGS(get_current())->tt = save;
72
73         if(!faulted) return(0);
74         else return(len - (fault - (unsigned long) mem));
75 }
76
77 int __do_strnlen_user(const char *str, unsigned long n,
78                       void **fault_addr, void **fault_catcher)
79 {
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;
84
85         *fault_catcher = &jbuf;
86         if(UML_SETJMP(&jbuf) == 0)
87                 ret = strlen(str) + 1;
88         else ret = *faddrp - (unsigned long) str;
89
90         *fault_addr = NULL;
91         *fault_catcher = NULL;
92
93         TASK_REGS(get_current())->tt = save;
94         return ret;
95 }
96
97 /*
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:
106  */