|
13 | 13 | #include <sys/wait.h> |
14 | 14 | #include <sys/mman.h> |
15 | 15 | #include <sys/user.h> |
| 16 | +#include <sys/time.h> |
16 | 17 | #include <asm/unistd.h> |
17 | 18 | #include <asm/types.h> |
18 | 19 | #include "user.h" |
|
22 | 23 | #include "user_util.h" |
23 | 24 | #include "kern_util.h" |
24 | 25 | #include "skas.h" |
| 26 | +#include "stub-data.h" |
25 | 27 | #include "mm_id.h" |
26 | 28 | #include "sysdep/sigcontext.h" |
27 | 29 | #include "sysdep/stub.h" |
@@ -296,6 +298,67 @@ void userspace(union uml_pt_regs *regs) |
296 | 298 | #define INIT_JMP_HALT 3 |
297 | 299 | #define INIT_JMP_REBOOT 4 |
298 | 300 |
|
| 301 | + |
| 302 | +int copy_context_skas0(unsigned long new_stack, int pid) |
| 303 | +{ |
| 304 | + int err; |
| 305 | + unsigned long regs[MAX_REG_NR]; |
| 306 | + unsigned long current_stack = current_stub_stack(); |
| 307 | + struct stub_data *data = (struct stub_data *) current_stack; |
| 308 | + struct stub_data *child_data = (struct stub_data *) new_stack; |
| 309 | + __u64 new_offset; |
| 310 | + int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset); |
| 311 | + |
| 312 | + /* prepare offset and fd of child's stack as argument for parent's |
| 313 | + * and child's mmap2 calls |
| 314 | + */ |
| 315 | + *data = ((struct stub_data) { .offset = MMAP_OFFSET(new_offset), |
| 316 | + .fd = new_fd, |
| 317 | + .timer = ((struct itimerval) |
| 318 | + { { 0, 1000000 / hz() }, |
| 319 | + { 0, 1000000 / hz() }})}); |
| 320 | + get_safe_registers(regs); |
| 321 | + |
| 322 | + /* Set parent's instruction pointer to start of clone-stub */ |
| 323 | + regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + |
| 324 | + (unsigned long) stub_clone_handler - |
| 325 | + (unsigned long) &__syscall_stub_start; |
| 326 | + regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA + PAGE_SIZE - |
| 327 | + sizeof(void *); |
| 328 | + err = ptrace_setregs(pid, regs); |
| 329 | + if(err < 0) |
| 330 | + panic("copy_context_skas0 : PTRACE_SETREGS failed, " |
| 331 | + "pid = %d, errno = %d\n", pid, errno); |
| 332 | + |
| 333 | + /* set a well known return code for detection of child write failure */ |
| 334 | + child_data->err = 12345678; |
| 335 | + |
| 336 | + /* Wait, until parent has finished its work: read child's pid from |
| 337 | + * parent's stack, and check, if bad result. |
| 338 | + */ |
| 339 | + wait_stub_done(pid, 0, "copy_context_skas0"); |
| 340 | + |
| 341 | + pid = data->err; |
| 342 | + if(pid < 0) |
| 343 | + panic("copy_context_skas0 - stub-parent reports error %d\n", |
| 344 | + pid); |
| 345 | + |
| 346 | + /* Wait, until child has finished too: read child's result from |
| 347 | + * child's stack and check it. |
| 348 | + */ |
| 349 | + wait_stub_done(pid, -1, "copy_context_skas0"); |
| 350 | + if (child_data->err != UML_CONFIG_STUB_DATA) |
| 351 | + panic("copy_context_skas0 - stub-child reports error %d\n", |
| 352 | + child_data->err); |
| 353 | + |
| 354 | + if (ptrace(PTRACE_OLDSETOPTIONS, pid, NULL, |
| 355 | + (void *)PTRACE_O_TRACESYSGOOD) < 0) |
| 356 | + panic("copy_context_skas0 : PTRACE_SETOPTIONS failed, " |
| 357 | + "errno = %d\n", errno); |
| 358 | + |
| 359 | + return pid; |
| 360 | +} |
| 361 | + |
299 | 362 | void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr, |
300 | 363 | void (*handler)(int)) |
301 | 364 | { |
|
0 commit comments