ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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 <setjmp.h>
8 #include <string.h>
9 #include "user_util.h"
10 #include "uml_uaccess.h"
11
12 int __do_copy_from_user(void *to, const void *from, int n,
13                         void **fault_addr, void **fault_catcher)
14 {
15         unsigned long fault;
16         int faulted;
17
18         fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
19                                __do_copy, &faulted);
20         if(!faulted) return(0);
21         else return(n - (fault - (unsigned long) from));
22 }
23
24 static void __do_strncpy(void *dst, const void *src, int count)
25 {
26         strncpy(dst, src, count);
27 }       
28
29 int __do_strncpy_from_user(char *dst, const char *src, unsigned long count,
30                            void **fault_addr, void **fault_catcher)
31 {
32         unsigned long fault;
33         int faulted;
34
35         fault = __do_user_copy(dst, src, count, fault_addr, fault_catcher,
36                                __do_strncpy, &faulted);
37         if(!faulted) return(strlen(dst));
38         else return(-1);
39 }
40
41 static void __do_clear(void *to, const void *from, int n)
42 {
43         memset(to, 0, n);
44 }       
45
46 int __do_clear_user(void *mem, unsigned long len,
47                     void **fault_addr, void **fault_catcher)
48 {
49         unsigned long fault;
50         int faulted;
51
52         fault = __do_user_copy(mem, NULL, len, fault_addr, fault_catcher,
53                                __do_clear, &faulted);
54         if(!faulted) return(0);
55         else return(len - (fault - (unsigned long) mem));
56 }
57
58 int __do_strnlen_user(const char *str, unsigned long n,
59                       void **fault_addr, void **fault_catcher)
60 {
61         int ret;
62         unsigned long *faddrp = (unsigned long *)fault_addr;
63         jmp_buf jbuf;
64
65         *fault_catcher = &jbuf;
66         if(setjmp(jbuf) == 0){
67                 ret = strlen(str) + 1;
68         } 
69         else {
70                 ret = *faddrp - (unsigned long) str;
71         }
72         *fault_addr = NULL;
73         *fault_catcher = NULL;
74         return ret;
75 }
76
77 /*
78  * Overrides for Emacs so that we follow Linus's tabbing style.
79  * Emacs will notice this stuff at the end of the file and automatically
80  * adjust the settings for this buffer only.  This must remain at the end
81  * of the file.
82  * ---------------------------------------------------------------------------
83  * Local variables:
84  * c-file-style: "linux"
85  * End:
86  */