blob: 087ed74ffca55081ab7052d51d74103f34d3c7f5 [file] [log] [blame]
Gennady Sharapovbb578422005-11-07 00:58:50 -08001/*
2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
Jeff Dike5134d8f2008-02-08 04:22:08 -08003 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Gennady Sharapovbb578422005-11-07 00:58:50 -08004 * Licensed under the GPL
5 */
6
Jeff Dike13c06be2006-09-25 23:32:59 -07007#include <stddef.h>
Jeff Dike1d7173b2006-01-18 17:42:49 -08008#include "longjmp.h"
Gennady Sharapovbb578422005-11-07 00:58:50 -08009
10unsigned long __do_user_copy(void *to, const void *from, int n,
Jeff Dikefab95c52007-10-16 01:27:05 -070011 void **fault_addr, jmp_buf **fault_catcher,
Gennady Sharapovbb578422005-11-07 00:58:50 -080012 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 Dikead28e022006-04-18 22:21:41 -070017 jmp_buf jbuf;
Gennady Sharapovbb578422005-11-07 00:58:50 -080018 *fault_catcher = &jbuf;
Jeff Dike5134d8f2008-02-08 04:22:08 -080019 if (UML_SETJMP(&jbuf) == 0) {
Gennady Sharapovbb578422005-11-07 00:58:50 -080020 (*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