Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 20 | #ifdef HAVE_ANDROID_OS |
| 21 | #include <android/log.h> |
| 22 | #else |
| 23 | #include <stdarg.h> |
| 24 | #include <iostream> |
| 25 | #endif |
| 26 | |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 27 | #include "sigchain.h" |
| 28 | |
Andreas Gampe | 9d9cfa8 | 2014-11-03 20:25:24 -0800 | [diff] [blame] | 29 | #define ATTRIBUTE_UNUSED __attribute__((__unused__)) |
| 30 | |
Andreas Gampe | ba1ff84 | 2015-04-06 14:33:54 -0700 | [diff] [blame] | 31 | // We cannot annotate the declarations, as they are not no-return in the non-dummy version. |
| 32 | #pragma GCC diagnostic push |
| 33 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" |
| 34 | #pragma GCC diagnostic ignored "-Wmissing-noreturn" |
| 35 | |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 36 | static void log(const char* format, ...) { |
| 37 | char buf[256]; |
| 38 | va_list ap; |
| 39 | va_start(ap, format); |
| 40 | vsnprintf(buf, sizeof(buf), format, ap); |
| 41 | #ifdef HAVE_ANDROID_OS |
| 42 | __android_log_write(ANDROID_LOG_ERROR, "libsigchain", buf); |
| 43 | #else |
| 44 | std::cout << buf << "\n"; |
| 45 | #endif |
| 46 | va_end(ap); |
| 47 | } |
| 48 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 49 | namespace art { |
| 50 | |
| 51 | |
Andreas Gampe | 9d9cfa8 | 2014-11-03 20:25:24 -0800 | [diff] [blame] | 52 | extern "C" void ClaimSignalChain(int signal ATTRIBUTE_UNUSED, |
| 53 | struct sigaction* oldaction ATTRIBUTE_UNUSED) { |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 54 | log("ClaimSignalChain is not exported by the main executable."); |
| 55 | abort(); |
| 56 | } |
| 57 | |
Andreas Gampe | 9d9cfa8 | 2014-11-03 20:25:24 -0800 | [diff] [blame] | 58 | extern "C" void UnclaimSignalChain(int signal ATTRIBUTE_UNUSED) { |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 59 | log("UnclaimSignalChain is not exported by the main executable."); |
| 60 | abort(); |
| 61 | } |
| 62 | |
Andreas Gampe | 9d9cfa8 | 2014-11-03 20:25:24 -0800 | [diff] [blame] | 63 | extern "C" void InvokeUserSignalHandler(int sig ATTRIBUTE_UNUSED, |
| 64 | siginfo_t* info ATTRIBUTE_UNUSED, |
| 65 | void* context ATTRIBUTE_UNUSED) { |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 66 | log("InvokeUserSignalHandler is not exported by the main executable."); |
| 67 | abort(); |
| 68 | } |
| 69 | |
| 70 | extern "C" void InitializeSignalChain() { |
| 71 | log("InitializeSignalChain is not exported by the main executable."); |
| 72 | abort(); |
| 73 | } |
Mathieu Chartier | d000480 | 2014-10-15 16:59:47 -0700 | [diff] [blame] | 74 | |
Andreas Gampe | 9d9cfa8 | 2014-11-03 20:25:24 -0800 | [diff] [blame] | 75 | extern "C" void EnsureFrontOfChain(int signal ATTRIBUTE_UNUSED, |
| 76 | struct sigaction* expected_action ATTRIBUTE_UNUSED) { |
Mathieu Chartier | d000480 | 2014-10-15 16:59:47 -0700 | [diff] [blame] | 77 | log("EnsureFrontOfChain is not exported by the main executable."); |
| 78 | abort(); |
| 79 | } |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 80 | |
Andreas Gampe | ba1ff84 | 2015-04-06 14:33:54 -0700 | [diff] [blame] | 81 | #pragma GCC diagnostic pop |
| 82 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 83 | } // namespace art |