Christopher Ferris | 862fe02 | 2015-06-02 14:52:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <errno.h> |
| 18 | #include <signal.h> |
| 19 | #include <stdarg.h> |
| 20 | #include <sys/ptrace.h> |
| 21 | |
| 22 | #include <string> |
| 23 | |
| 24 | #include "ptrace_fake.h" |
| 25 | |
| 26 | siginfo_t g_fake_si = {.si_signo = 0}; |
| 27 | |
| 28 | void ptrace_set_fake_getsiginfo(const siginfo_t& si) { |
| 29 | g_fake_si = si; |
| 30 | } |
| 31 | |
| 32 | #if !defined(__BIONIC__) |
| 33 | extern "C" long ptrace_fake(enum __ptrace_request request, ...) { |
| 34 | #else |
| 35 | extern "C" long ptrace_fake(int request, ...) { |
| 36 | #endif |
| 37 | if (request == PTRACE_GETSIGINFO) { |
| 38 | if (g_fake_si.si_signo == 0) { |
| 39 | errno = EFAULT; |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | va_list ap; |
| 44 | va_start(ap, request); |
| 45 | va_arg(ap, int); |
| 46 | va_arg(ap, int); |
| 47 | siginfo_t* si = va_arg(ap, siginfo*); |
| 48 | va_end(ap); |
| 49 | *si = g_fake_si; |
| 50 | return 0; |
| 51 | } |
| 52 | return -1; |
| 53 | } |