Debian Codegraph @

src/dex-ucontext-private.h

raw symbols SCIP
1 /* dex-ucontext-private.h
2 *
3 * Copyright 2022 Christian Hergert <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21 #pragma once
22
23 #include "config.h"
24
25 #include <signal.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 /* The following code is from libtask by Russ Cox to emulate the
31 * ucontext implementation in a fashion that doesn't necessarily
32 * require context switches for implementation.
33 */
34
35 /* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */
36
37 #if defined(__sun__)
38 # define __EXTENSIONS__ 1 /* SunOS */
39 # if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__)
40 /* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
41 # else
42 # define __MAKECONTEXT_V2_SOURCE 1
43 # endif
44 #endif
45
46 #define USE_UCONTEXT 1
47
48 #if defined(__linux__) && defined(__x86_64__)
49 # undef USE_UCONTEXT
50 # define USE_UCONTEXT 0
51 #endif
52
53 #if defined(__OpenBSD__) || defined(__mips__)
54 #include <stdint.h>
55 # undef USE_UCONTEXT
56 # define USE_UCONTEXT 0
57 #endif
58
59 #if defined(__APPLE__)
60 # ifndef _XOPEN_SOURCE
61 # define _XOPEN_SOURCE
62 # endif
63 #endif
64
65 #if USE_UCONTEXT
66 # include <ucontext.h>
67 #endif
68
69 #if defined(__FreeBSD__) && __FreeBSD__ < 5
70 extern int getmcontext(mcontext_t*);
71 extern void setmcontext(const mcontext_t*);
72 # define setcontext(u) setmcontext(&(u)->uc_mcontext)
73 # define getcontext(u) getmcontext(&(u)->uc_mcontext)
74 extern int swapcontext(ucontext_t*, const ucontext_t*);
75 extern void makecontext(ucontext_t*, void(*)(void), int, ...);
76 #endif
77
78 #if defined(__OpenBSD__)
79 # define mcontext libthread_mcontext
80 # define mcontext_t libthread_mcontext_t
81 # define ucontext libthread_ucontext
82 # define ucontext_t libthread_ucontext_t
83 # if defined __amd64__
84 # include "amd64-ucontext.h"
85 # elif defined __i386__
86 # include "386-ucontext.h"
87 # else
88 # include "power-ucontext.h"
89 # endif
90 #endif
91
92 #if defined(__linux__) && defined(__x86_64__)
93 # define mcontext libthread_mcontext
94 # define mcontext_t libthread_mcontext_t
95 # define ucontext libthread_ucontext
96 # define ucontext_t libthread_ucontext_t
97 # include "amd64-ucontext.h"
98 #endif
99
100 #if defined(__linux__) && defined(__mips__)
101 # if !defined(HAVE_UCONTEXT_H)
102 # include "mips-ucontext.h"
103 # endif
104 extern int getcontext (ucontext_t *ucp);
105 extern int setcontext(const ucontext_t *ucp);
106 extern int swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
107 /* glibc makecontext.S for mips specifies int return type, not void */
108 extern void makecontext(ucontext_t *ucp, void(*)(void), int, ...);
109 #endif