Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #pragma once |
| 18 | |
Atneya Nair | cce1420 | 2022-09-05 20:17:50 -0700 | [diff] [blame^] | 19 | #if defined(__linux__) |
| 20 | #include <signal.h> |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 21 | #include <sys/syscall.h> |
| 22 | #include <unistd.h> |
Atneya Nair | cce1420 | 2022-09-05 20:17:50 -0700 | [diff] [blame^] | 23 | #endif |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 24 | |
| 25 | namespace android::mediautils { |
| 26 | |
| 27 | // The library wrapper for gettid is only available on bionic. If we don't link |
| 28 | // against it, we syscall directly. |
| 29 | inline pid_t getThreadIdWrapper() { |
| 30 | #if defined(__BIONIC__) |
| 31 | return ::gettid(); |
| 32 | #else |
| 33 | return syscall(SYS_gettid); |
| 34 | #endif |
| 35 | } |
| 36 | |
Atneya Nair | cce1420 | 2022-09-05 20:17:50 -0700 | [diff] [blame^] | 37 | // Send an abort signal to a (linux) thread id. |
| 38 | inline int abortTid(int tid) { |
| 39 | #if defined(__linux__) |
| 40 | const pid_t pid = getpid(); |
| 41 | siginfo_t siginfo = { |
| 42 | .si_code = SI_QUEUE, |
| 43 | .si_pid = pid, |
| 44 | .si_uid = getuid(), |
| 45 | }; |
| 46 | return syscall(SYS_rt_tgsigqueueinfo, pid, tid, SIGABRT, &siginfo); |
| 47 | #else |
| 48 | errno = ENODEV; |
| 49 | return -1; |
| 50 | #endif |
| 51 | } |
| 52 | |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 53 | } |