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
10 #include "uml_uaccess.h"
12 #include "kern_util.h"
14 int __do_copy_from_user(void *to, const void *from, int n,
15 void **fault_addr, void **fault_catcher)
17 struct tt_regs save = TASK_REGS(get_current())->tt;
21 fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
23 TASK_REGS(get_current())->tt = save;
28 return n - (fault - (unsigned long) from);
30 /* In case of a general protection fault, we don't have the
31 * fault address, so NULL is used instead. Pretend we didn't
36 static void __do_strncpy(void *dst, const void *src, int count)
38 strncpy(dst, src, count);
41 int __do_strncpy_from_user(char *dst, const char *src, unsigned long count,
42 void **fault_addr, void **fault_catcher)
44 struct tt_regs save = TASK_REGS(get_current())->tt;
48 fault = __do_user_copy(dst, src, count, fault_addr, fault_catcher,
49 __do_strncpy, &faulted);
50 TASK_REGS(get_current())->tt = save;
52 if(!faulted) return(strlen(dst));
56 static void __do_clear(void *to, const void *from, int n)
61 int __do_clear_user(void *mem, unsigned long len,
62 void **fault_addr, void **fault_catcher)
64 struct tt_regs save = TASK_REGS(get_current())->tt;
68 fault = __do_user_copy(mem, NULL, len, fault_addr, fault_catcher,
69 __do_clear, &faulted);
70 TASK_REGS(get_current())->tt = save;
72 if(!faulted) return(0);
73 else return(len - (fault - (unsigned long) mem));
76 int __do_strnlen_user(const char *str, unsigned long n,
77 void **fault_addr, void **fault_catcher)
79 struct tt_regs save = TASK_REGS(get_current())->tt;
81 unsigned long *faddrp = (unsigned long *)fault_addr;
84 *fault_catcher = &jbuf;
85 if(sigsetjmp(jbuf, 1) == 0)
86 ret = strlen(str) + 1;
87 else ret = *faddrp - (unsigned long) str;
90 *fault_catcher = NULL;
92 TASK_REGS(get_current())->tt = save;
97 * Overrides for Emacs so that we follow Linus's tabbing style.
98 * Emacs will notice this stuff at the end of the file and automatically
99 * adjust the settings for this buffer only. This must remain at the end
101 * ---------------------------------------------------------------------------
103 * c-file-style: "linux"