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
9 #include "uml_uaccess.h"
11 #include "kern_util.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
;
22 fault
= __do_user_copy(to
, from
, n
, fault_addr
, fault_catcher
,
24 TASK_REGS(get_current())->tt
= save
;
29 return n
- (fault
- (unsigned long) from
);
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
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
;
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
));
57 static void __do_clear(void *to
, const void *from
, int 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
;
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
;
82 unsigned long *faddrp
= (unsigned long *)fault_addr
;
85 *fault_catcher
= &jbuf
;
86 if(UML_SETJMP(&jbuf
) == 0)
87 ret
= strlen(str
) + 1;
88 else ret
= *faddrp
- (unsigned long) str
;
91 *fault_catcher
= NULL
;
93 TASK_REGS(get_current())->tt
= save
;
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
102 * ---------------------------------------------------------------------------
104 * c-file-style: "linux"