13 #include <asm/unistd.h>
20 #include <ptrace_user.h>
21 #include <registers.h>
23 #include <skas_ptrace.h>
28 return pid == getpgrp();
31 static int ptrace_dump_regs(
int pid)
50 #define STUB_SIG_MASK ((1 << SIGVTALRM) | (1 << SIGWINCH))
53 #define STUB_DONE_MASK (1 << SIGTRAP)
61 if ((n < 0) || !WIFSTOPPED(status))
70 "errno = %d\n",
errno);
79 err = ptrace_dump_regs(pid);
82 "errno = %d\n", -err);
84 "pid = %d, n = %d, errno = %d, status = 0x%x\n", pid, n,
errno,
91 static void get_skas_faultinfo(
int pid,
struct faultinfo *fi)
99 "PTRACE_FAULTINFO failed, errno = %d\n", errno);
121 "errno = %d\n", pid, errno);
141 static void handle_segv(
int pid,
struct uml_pt_regs * regs)
143 get_skas_faultinfo(pid, ®s->
faultinfo);
151 static void handle_trap(
int pid,
struct uml_pt_regs *regs,
152 int local_using_sysemu)
162 if (!local_using_sysemu)
168 "failed, errno = %d\n", errno);
175 "syscall failed, errno = %d\n", errno);
180 if ((err < 0) || !WIFSTOPPED(status) ||
181 (WSTOPSIG(status) !=
SIGTRAP + 0x80)) {
182 err = ptrace_dump_regs(pid);
185 "from process, errno = %d\n", -err);
187 "end of syscall, errno = %d, status = %d\n",
198 static int userspace_tramp(
void *
stack)
210 "errno = %d\n", err);
220 unsigned long long offset;
221 fd =
phys_mapping(to_phys(&__syscall_stub_start), &offset);
222 addr = mmap64((
void *)
STUB_CODE, UM_KERN_PAGE_SIZE,
224 if (addr == MAP_FAILED) {
235 if (addr == MAP_FAILED) {
237 "at 0x%lx failed, errno = %d\n",
248 (
unsigned long) &__syscall_stub_start;
251 sigemptyset(&
sa.sa_mask);
253 sa.sa_sigaction = (
void *) v;
257 "handler failed - errno = %d\n", errno);
277 stack = mmap(
NULL, UM_KERN_PAGE_SIZE,
280 if (stack == MAP_FAILED) {
283 "errno = %d\n",
errno);
287 sp = (
unsigned long) stack + UM_KERN_PAGE_SIZE -
sizeof(
void *);
295 pid = clone(userspace_tramp, (
void *) sp, flags, (
void *) stub_stack);
299 "errno = %d\n",
errno);
308 "errno = %d\n",
errno);
311 }
while (WIFSTOPPED(status) && (WSTOPSIG(status) ==
SIGVTALRM));
313 if (!WIFSTOPPED(status) || (WSTOPSIG(status) !=
SIGSTOP)) {
316 "status = %d\n", status);
324 "failed, errno = %d\n",
errno);
328 if (munmap(stack, UM_KERN_PAGE_SIZE) < 0) {
331 "errno = %d\n",
errno);
345 unsigned long long nsecs, now;
348 int local_using_sysemu;
356 nsecs = timer.
it_value.tv_sec * UM_NSEC_PER_SEC +
357 timer.
it_value.tv_usec * UM_NSEC_PER_USEC;
381 if (ptrace(op, pid, 0, 0)) {
383 "failed, op = %d, errno = %d\n", op,
errno);
390 "errno = %d\n",
errno);
397 "errno = %d\n",
errno);
403 "errno = %d\n",
errno);
409 if (WIFSTOPPED(status)) {
410 int sig = WSTOPSIG(status);
418 get_skas_faultinfo(pid,
423 else handle_segv(pid, regs);
426 handle_trap(pid, regs, local_using_sysemu);
455 "with signal %d\n", sig);
458 pid = userspace_pid[0];
469 static unsigned long thread_fp_regs[
FP_SIZE];
471 static int __init init_thread_regs(
void)
477 (
unsigned long) &__syscall_stub_start;
480 #ifdef __SIGNAL_FRAMESIZE
490 struct timeval tv = { .
tv_sec = 0, .tv_usec = UM_USEC_PER_SEC / UM_HZ };
495 unsigned long long new_offset;
496 int new_fd =
phys_mapping(to_phys((
void *)new_stack), &new_offset);
506 .it_interval = tv }) });
512 "failed, pid = %d, errno = %d\n", pid, -err);
519 "failed, pid = %d, err = %d\n", pid, err);
524 child_data->
err = 12345678;
534 "errno = %d\n", pid,
errno);
554 "error %ld\n", child_data->
err);
555 err = child_data->
err;
563 "failed, errno = %d\n",
errno);
584 unsigned long long code_offset;
585 int code_fd =
phys_mapping(to_phys((
void *) &__syscall_stub_start),
592 .len = UM_KERN_PAGE_SIZE,
596 .offset = code_offset
599 if (n !=
sizeof(mmop)) {
602 "offset = %llx\n", code, code_fd,
603 (
unsigned long long) code_offset);
605 "failed, err = %d\n", n);
610 unsigned long long map_offset;
611 int map_fd =
phys_mapping(to_phys((
void *)stack), &map_offset);
617 .len = UM_KERN_PAGE_SIZE,
624 if (n !=
sizeof(mmop)) {
627 "data failed, err = %d\n", n);
638 (*buf)[0].JB_SP = (
unsigned long) stack + UM_THREAD_SIZE -
642 #define INIT_JMP_NEW_THREAD 0
643 #define INIT_JMP_CALLBACK 1
644 #define INIT_JMP_HALT 2
645 #define INIT_JMP_REBOOT 3
656 static void (*cb_proc)(
void *
arg);
674 n =
setjmp(initial_jmpbuf);
678 (*switch_buf)[0].JB_SP = (
unsigned long) stack +
679 UM_THREAD_SIZE -
sizeof(
void *);
693 "start_idle_thread - %d\n", n);
739 "failed, errno = %d\n",
errno);
743 else userspace_pid[0] = mm_idp->
u.
pid;