blob: df3b64b7c48e0aaef3c47737f7ad03ab327fbe7e [file] [log] [blame]
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +02001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _ARCH_MIPS_SYS_UCONTEXT_H_
29#define _ARCH_MIPS_SYS_UCONTEXT_H_
30
31#include <signal.h>
32#include <stdint.h>
33
34__BEGIN_DECLS
35
36/* Technical note:
37 *
38 * On MIPS, there are differences in the way GLibc and the Linux kernel declare
39 * ucontext_t:
40 *
41 * - The kernel implements 'uc_mcontext' with a 'struct sigcontext',
42 * while GLibc defines 'mcontext_t' in a binary-compatible way
43 * (same size, same binary layout), but with different field naming/access
44 * convention.
45 *
46 * The biggest difference is the naming of the fields. The kernel uses
47 * a 'sc_' prefix (e.g. "sc_gregs[]"), while GLibc does not ("gregs[]").
48 *
49 * For maximum portability of existing client code, this header follows
50 * the GLibc convention. Client code, and the C library, should never
51 * try to include <asm/ucontext.h>
52 *
53 * Apart from that, all floating point state is stored in uc_mcontext
54 * in the same way, which is much simpler than ARM and x86 schemes for it.
55 * As such, there is no _libc_fpstate.
56 *
57 * Reference source files:
58 * $KERNEL/arch/mips/include/asm/sigcontext.h
59 * $KERNEL/arch/mips/include/asm/ucontext.h
60 *
61 * $GLIBC/sysdeps/unix/sysv/linux/mips/getcontext.S
62 * $GLIBC/sysdeps/unix/sysv/linux/mips/setcontext.S
63 * $GLIBC/sysdeps/unix/sysv/linux/mips/sys/ucontext.h
64 */
65
66/* First, the kernel-compatible version, for reference. */
67typedef struct __kernel_ucontext {
68 unsigned long uc_flags;
69 struct __kernel_ucontext* uc_link;
70 stack_t uc_stack;
71 struct sigcontext uc_mcontext;
72 __kernel_sigset_t uc_sigmask;
73} __kernel_ucontext_t;
74
75/* Second, the GLibc-compatible version */
76
77__extension__ /* Required to build in ANSI C mode */
78typedef unsigned long long greg_t;
79
80#define NGREG 32
81#define NFPREG 32
82
83typedef greg_t gregset_t[NGREG];
84
85typedef struct fpregset {
86 union {
87 double fp_dregs[NFPREG];
88 struct {
89 float _fp_fregs;
90 unsigned _fp_pad;
91 } fp_fregs[NFPREG];
92 } fp_r;
93} fpregset_t;
94
95#ifndef _MIPS_SIM
96#error "_MIPS_SIM should be defined by your Android MIPS toolchain!"
97#endif
98
99#ifndef _OABI32
100#error "_OABI32 should be defined by your Android MIPS toolchain!"
101#endif
102
103#if _MIPS_SIM != _OABI32
104#error "Only _OABI32 is supported on Android MIPS!"
105#endif
106
107typedef struct {
108 unsigned regmask;
109 unsigned status;
110 greg_t pc;
111 gregset_t gregs;
112 fpregset_t fpregs;
113 unsigned fp_owned;
114 unsigned fpc_csr;
115 unsigned fpc_eir;
116 unsigned used_math;
117 unsigned dsp;
118 greg_t mdhi;
119 greg_t mdlo;
120 unsigned hi1;
121 unsigned lo1;
122 unsigned hi2;
123 unsigned lo2;
124 unsigned hi3;
125 unsigned lo3;
126} mcontext_t;
127
128typedef struct ucontext {
129 uint32_t uc_flags;
130 struct ucontext* uc_link;
131 stack_t uc_stack;
132 mcontext_t uc_mcontext;
133 /* Only expose the signals in Bionic's 32-bit sigset_t.
134 * The _unused field is required padding from the kernel. */
135 sigset_t uc_sigmask;
136 char _unused[sizeof(__kernel_sigset_t) - sizeof(sigset_t)];
137} ucontext_t;
138
139__END_DECLS
140
141#endif /* _ARCH_MIPS_SYS_UCONTEXT_H_ */