|
| 1 | +/* |
| 2 | + * Copyright (C) 2011 by Nelson Elhage |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | + * THE SOFTWARE. |
| 21 | + */ |
| 22 | +#include "x86_common.h" |
| 23 | + |
| 24 | +#define ARCH_HAVE_MULTIPLE_PERSONALITIES |
| 25 | + |
| 26 | +static struct ptrace_personality arch_personality[2] = { |
| 27 | + { |
| 28 | + offsetof(struct user, regs.rax), offsetof(struct user, regs.rdi), |
| 29 | + offsetof(struct user, regs.rsi), offsetof(struct user, regs.rdx), |
| 30 | + offsetof(struct user, regs.r10), offsetof(struct user, regs.r8), |
| 31 | + offsetof(struct user, regs.r9), offsetof(struct user, regs.rip), |
| 32 | + }, |
| 33 | + { |
| 34 | + offsetof(struct user, regs.rax), offsetof(struct user, regs.rbx), |
| 35 | + offsetof(struct user, regs.rcx), offsetof(struct user, regs.rdx), |
| 36 | + offsetof(struct user, regs.rsi), offsetof(struct user, regs.rdi), |
| 37 | + offsetof(struct user, regs.rbp), offsetof(struct user, regs.rip), |
| 38 | + }, |
| 39 | +}; |
| 40 | + |
| 41 | +struct x86_personality x86_personality[2] = { |
| 42 | + { |
| 43 | + offsetof(struct user, regs.orig_rax), offsetof(struct user, regs.rax), |
| 44 | + }, |
| 45 | + { |
| 46 | + offsetof(struct user, regs.orig_rax), offsetof(struct user, regs.rax), |
| 47 | + }, |
| 48 | +}; |
| 49 | + |
| 50 | +struct syscall_numbers arch_syscall_numbers[2] = { |
| 51 | +#include "default-syscalls.h" |
| 52 | + { |
| 53 | + /* |
| 54 | + * These don't seem to be available in any convenient header. We could |
| 55 | + * include unistd_32.h, but those definitions would conflict with the |
| 56 | + * standard ones. So, let's just hardcode the values for now. Probably |
| 57 | + * we should generate this from unistd_32.h during the build process or |
| 58 | + * soemthing. |
| 59 | + */ |
| 60 | + .nr_mmap = 90, |
| 61 | + .nr_mmap2 = 192, |
| 62 | + .nr_munmap = 91, |
| 63 | + .nr_getsid = 147, |
| 64 | + .nr_setsid = 66, |
| 65 | + .nr_setpgid = 57, |
| 66 | + .nr_fork = 2, |
| 67 | + .nr_wait4 = 114, |
| 68 | + .nr_signal = 48, |
| 69 | + .nr_rt_sigaction = 174, |
| 70 | + .nr_open = 5, |
| 71 | + .nr_close = 6, |
| 72 | + .nr_ioctl = 54, |
| 73 | + .nr_dup2 = 63, |
| 74 | + .nr_socketcall = 102, |
| 75 | + .nr_setns = 346, |
| 76 | + }}; |
| 77 | + |
| 78 | +static int |
| 79 | +arch_get_personality(struct ptrace_child *child) |
| 80 | +{ |
| 81 | + unsigned long cs; |
| 82 | + |
| 83 | + cs = ptrace_command(child, PTRACE_PEEKUSER, |
| 84 | + offsetof(struct user, regs.cs)); |
| 85 | + if (child->error) |
| 86 | + return -1; |
| 87 | + if (cs == 0x23) |
| 88 | + child->personality = 1; |
| 89 | + return 0; |
| 90 | +} |
0 commit comments