Skip to content

Commit 8efa3c9

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: eliminate setjmp_wrapper
setjmp_wrapper existed to provide setjmp to kernel code when UML used libc's setjmp and longjmp. Now that UML has its own implementation, this isn't needed and kernel code can invoke setjmp directly. do_buffer_op is massively cleaned up since it is no longer a callback from setjmp_wrapper and given a va_list from which it must extract its arguments. The actual setjmp is moved from buffer_op to do_op_one_page because the copy operation is inside an atomic section (kmap_atomic to kunmap_atomic) and it shouldn't be longjmp-ed out of. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0b4e273 commit 8efa3c9

3 files changed

Lines changed: 27 additions & 62 deletions

File tree

‎arch/um/include/os.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ extern void stack_protections(unsigned long address);
235235
extern int raw(int fd);
236236
extern void setup_machinename(char *machine_out);
237237
extern void setup_hostinfo(char *buf, int len);
238-
extern int setjmp_wrapper(void (*proc)(void *, void *), ...);
239238
extern void os_dump_core(void) __attribute__ ((noreturn));
240239

241240
/* time.c */

‎arch/um/kernel/skas/uaccess.c‎

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ static pte_t *maybe_map(unsigned long virt, int is_write)
5858
static int do_op_one_page(unsigned long addr, int len, int is_write,
5959
int (*op)(unsigned long addr, int len, void *arg), void *arg)
6060
{
61+
jmp_buf buf;
6162
struct page *page;
6263
pte_t *pte;
63-
int n;
64+
int n, faulted;
6465

6566
pte = maybe_map(addr, is_write);
6667
if (pte == NULL)
@@ -70,82 +71,62 @@ static int do_op_one_page(unsigned long addr, int len, int is_write,
7071
addr = (unsigned long) kmap_atomic(page, KM_UML_USERCOPY) +
7172
(addr & ~PAGE_MASK);
7273

73-
n = (*op)(addr, len, arg);
74+
current->thread.fault_catcher = &buf;
75+
76+
faulted = UML_SETJMP(&buf);
77+
if (faulted == 0)
78+
n = (*op)(addr, len, arg);
79+
else
80+
n = -1;
81+
82+
current->thread.fault_catcher = NULL;
7483

7584
kunmap_atomic(page, KM_UML_USERCOPY);
7685

7786
return n;
7887
}
7988

80-
static void do_buffer_op(void *jmpbuf, void *arg_ptr)
89+
static int buffer_op(unsigned long addr, int len, int is_write,
90+
int (*op)(unsigned long, int, void *), void *arg)
8191
{
82-
va_list args;
83-
unsigned long addr;
84-
int len, is_write, size, remain, n;
85-
int (*op)(unsigned long, int, void *);
86-
void *arg;
87-
int *res;
88-
89-
va_copy(args, *(va_list *)arg_ptr);
90-
addr = va_arg(args, unsigned long);
91-
len = va_arg(args, int);
92-
is_write = va_arg(args, int);
93-
op = va_arg(args, void *);
94-
arg = va_arg(args, void *);
95-
res = va_arg(args, int *);
96-
va_end(args);
92+
int size, remain, n;
93+
9794
size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len);
9895
remain = len;
9996

100-
current->thread.fault_catcher = jmpbuf;
10197
n = do_op_one_page(addr, size, is_write, op, arg);
10298
if (n != 0) {
103-
*res = (n < 0 ? remain : 0);
99+
remain = (n < 0 ? remain : 0);
104100
goto out;
105101
}
106102

107103
addr += size;
108104
remain -= size;
109-
if (remain == 0) {
110-
*res = 0;
105+
if (remain == 0)
111106
goto out;
112-
}
113107

114-
while(addr < ((addr + remain) & PAGE_MASK)) {
108+
while (addr < ((addr + remain) & PAGE_MASK)) {
115109
n = do_op_one_page(addr, PAGE_SIZE, is_write, op, arg);
116110
if (n != 0) {
117-
*res = (n < 0 ? remain : 0);
111+
remain = (n < 0 ? remain : 0);
118112
goto out;
119113
}
120114

121115
addr += PAGE_SIZE;
122116
remain -= PAGE_SIZE;
123117
}
124-
if (remain == 0) {
125-
*res = 0;
118+
if (remain == 0)
126119
goto out;
127-
}
128120

129121
n = do_op_one_page(addr, remain, is_write, op, arg);
130-
if (n != 0)
131-
*res = (n < 0 ? remain : 0);
132-
else *res = 0;
133-
out:
134-
current->thread.fault_catcher = NULL;
135-
}
136-
137-
static int buffer_op(unsigned long addr, int len, int is_write,
138-
int (*op)(unsigned long addr, int len, void *arg),
139-
void *arg)
140-
{
141-
int faulted, res;
142-
143-
faulted = setjmp_wrapper(do_buffer_op, addr, len, is_write, op, arg,
144-
&res);
145-
if (!faulted)
146-
return res;
122+
if (n != 0) {
123+
remain = (n < 0 ? remain : 0);
124+
goto out;
125+
}
147126

148-
return addr + len - (unsigned long) current->thread.fault_addr;
127+
return 0;
128+
out:
129+
return remain;
149130
}
150131

151132
static int copy_chunk_from_user(unsigned long from, int len, void *arg)

‎arch/um/os-Linux/util.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,6 @@ void setup_hostinfo(char *buf, int len)
8888
host.release, host.version, host.machine);
8989
}
9090

91-
int setjmp_wrapper(void (*proc)(void *, void *), ...)
92-
{
93-
va_list args;
94-
jmp_buf buf;
95-
int n;
96-
97-
n = UML_SETJMP(&buf);
98-
if(n == 0){
99-
va_start(args, proc);
100-
(*proc)(&buf, &args);
101-
}
102-
va_end(args);
103-
return n;
104-
}
105-
10691
void os_dump_core(void)
10792
{
10893
int pid;

0 commit comments

Comments
 (0)