Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk) |
Jeff Dike | 5134d8f | 2008-02-08 04:22:08 -0800 | [diff] [blame] | 3 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 4 | * Licensed under the GPL |
| 5 | */ |
| 6 | |
Jeff Dike | 13c06be | 2006-09-25 23:32:59 -0700 | [diff] [blame] | 7 | #include <stddef.h> |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 8 | #include "longjmp.h" |
Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 9 | |
| 10 | unsigned long __do_user_copy(void *to, const void *from, int n, |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 11 | void **fault_addr, jmp_buf **fault_catcher, |
Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 12 | void (*op)(void *to, const void *from, |
| 13 | int n), int *faulted_out) |
| 14 | { |
| 15 | unsigned long *faddrp = (unsigned long *) fault_addr, ret; |
| 16 | |
Jeff Dike | ad28e02 | 2006-04-18 22:21:41 -0700 | [diff] [blame] | 17 | jmp_buf jbuf; |
Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 18 | *fault_catcher = &jbuf; |
Jeff Dike | 5134d8f | 2008-02-08 04:22:08 -0800 | [diff] [blame] | 19 | if (UML_SETJMP(&jbuf) == 0) { |
Gennady Sharapov | bb57842 | 2005-11-07 00:58:50 -0800 | [diff] [blame] | 20 | (*op)(to, from, n); |
| 21 | ret = 0; |
| 22 | *faulted_out = 0; |
| 23 | } |
| 24 | else { |
| 25 | ret = *faddrp; |
| 26 | *faulted_out = 1; |
| 27 | } |
| 28 | *fault_addr = NULL; |
| 29 | *fault_catcher = NULL; |
| 30 | return ret; |
| 31 | } |
| 32 | |