ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / kernel / tt / include / uaccess.h
1 /* 
2  * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #ifndef __TT_UACCESS_H
7 #define __TT_UACCESS_H
8
9 #include "linux/string.h"
10 #include "linux/sched.h"
11 #include "asm/processor.h"
12 #include "asm/errno.h"
13 #include "asm/current.h"
14 #include "asm/a.out.h"
15 #include "uml_uaccess.h"
16
17 #define ABOVE_KMEM (16 * 1024 * 1024)
18
19 extern unsigned long end_vm;
20 extern unsigned long uml_physmem;
21
22 #define under_task_size(addr, size) \
23         (((unsigned long) (addr) < TASK_SIZE) && \
24          (((unsigned long) (addr) + (size)) < TASK_SIZE))
25
26 #define is_stack(addr, size) \
27         (((unsigned long) (addr) < STACK_TOP) && \
28          ((unsigned long) (addr) >= STACK_TOP - ABOVE_KMEM) && \
29          (((unsigned long) (addr) + (size)) <= STACK_TOP))
30
31 #define access_ok_tt(type, addr, size) \
32         ((type == VERIFY_READ) || (segment_eq(get_fs(), KERNEL_DS)) || \
33          (((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) && \
34           (under_task_size(addr, size) || is_stack(addr, size))))
35
36 static inline int verify_area_tt(int type, const void * addr, 
37                                  unsigned long size)
38 {
39         return(access_ok_tt(type, addr, size) ? 0 : -EFAULT);
40 }
41
42 extern unsigned long get_fault_addr(void);
43
44 extern int __do_copy_from_user(void *to, const void *from, int n,
45                                void **fault_addr, void **fault_catcher);
46
47 static inline int copy_from_user_tt(void *to, const void *from, int n)
48 {
49         return(access_ok_tt(VERIFY_READ, from, n) ?
50                __do_copy_from_user(to, from, n, 
51                                    &current->thread.fault_addr,
52                                    &current->thread.fault_catcher) : n);
53 }
54
55 static inline int copy_to_user_tt(void *to, const void *from, int n)
56 {
57         return(access_ok_tt(VERIFY_WRITE, to, n) ?
58                __do_copy_to_user(to, from, n, 
59                                    &current->thread.fault_addr,
60                                    &current->thread.fault_catcher) : n);
61 }
62
63 extern int __do_strncpy_from_user(char *dst, const char *src, size_t n,
64                                   void **fault_addr, void **fault_catcher);
65
66 static inline int strncpy_from_user_tt(char *dst, const char *src, int count)
67 {
68         int n;
69
70         if(!access_ok_tt(VERIFY_READ, src, 1)) return(-EFAULT);
71         n = __do_strncpy_from_user(dst, src, count, 
72                                    &current->thread.fault_addr,
73                                    &current->thread.fault_catcher);
74         if(n < 0) return(-EFAULT);
75         return(n);
76 }
77
78 extern int __do_clear_user(void *mem, size_t len, void **fault_addr,
79                            void **fault_catcher);
80
81 static inline int __clear_user_tt(void *mem, int len)
82 {
83         return(__do_clear_user(mem, len,
84                                &current->thread.fault_addr,
85                                &current->thread.fault_catcher));
86 }
87
88 static inline int clear_user_tt(void *mem, int len)
89 {
90         return(access_ok_tt(VERIFY_WRITE, mem, len) ? 
91                __do_clear_user(mem, len, 
92                                &current->thread.fault_addr,
93                                &current->thread.fault_catcher) : len);
94 }
95
96 extern int __do_strnlen_user(const char *str, unsigned long n,
97                              void **fault_addr, void **fault_catcher);
98
99 static inline int strnlen_user_tt(const void *str, int len)
100 {
101         return(__do_strnlen_user(str, len,
102                                  &current->thread.fault_addr,
103                                  &current->thread.fault_catcher));
104 }
105
106 #endif
107
108 /*
109  * Overrides for Emacs so that we follow Linus's tabbing style.
110  * Emacs will notice this stuff at the end of the file and automatically
111  * adjust the settings for this buffer only.  This must remain at the end
112  * of the file.
113  * ---------------------------------------------------------------------------
114  * Local variables:
115  * c-file-style: "linux"
116  * End:
117  */