blob: aeefa011b5c2988bb54ed2f89b55937940a16ed2 [file] [log] [blame]
Atneya Nairf5b68512022-05-23 20:02:49 -04001/*
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 Naircce14202022-09-05 20:17:50 -070019#if defined(__linux__)
20#include <signal.h>
Atneya Nairf5b68512022-05-23 20:02:49 -040021#include <sys/syscall.h>
22#include <unistd.h>
Atneya Naircce14202022-09-05 20:17:50 -070023#endif
Atneya Nairf5b68512022-05-23 20:02:49 -040024
25namespace 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.
29inline pid_t getThreadIdWrapper() {
30#if defined(__BIONIC__)
31 return ::gettid();
32#else
33 return syscall(SYS_gettid);
34#endif
35}
36
Atneya Naircce14202022-09-05 20:17:50 -070037// Send an abort signal to a (linux) thread id.
38inline 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 Nairf5b68512022-05-23 20:02:49 -040053}