Ucontext.h revision d226a5140989f509a0ed3e2723f05d5fc93ce8df
1/* 2 * Copyright (C) 2016 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 29#ifndef _LIBUNWINDSTACK_UCONTEXT_H 30#define _LIBUNWINDSTACK_UCONTEXT_H 31 32#include <stdint.h> 33 34namespace unwindstack { 35 36//------------------------------------------------------------------- 37// ARM ucontext structures 38//------------------------------------------------------------------- 39struct arm_stack_t { 40 uint32_t ss_sp; // void __user* 41 int32_t ss_flags; // int 42 uint32_t ss_size; // size_t 43}; 44 45struct arm_mcontext_t { 46 uint32_t trap_no; // unsigned long 47 uint32_t error_code; // unsigned long 48 uint32_t oldmask; // unsigned long 49 uint32_t regs[ARM_REG_LAST]; // unsigned long 50 uint32_t cpsr; // unsigned long 51 uint32_t fault_address; // unsigned long 52}; 53 54struct arm_ucontext_t { 55 uint32_t uc_flags; // unsigned long 56 uint32_t uc_link; // struct ucontext* 57 arm_stack_t uc_stack; 58 arm_mcontext_t uc_mcontext; 59 // Nothing else is used, so don't define it. 60}; 61//------------------------------------------------------------------- 62 63//------------------------------------------------------------------- 64// ARM64 ucontext structures 65//------------------------------------------------------------------- 66struct arm64_stack_t { 67 uint64_t ss_sp; // void __user* 68 int32_t ss_flags; // int 69 uint64_t ss_size; // size_t 70}; 71 72struct arm64_sigset_t { 73 uint64_t sig; // unsigned long 74}; 75 76struct arm64_mcontext_t { 77 uint64_t fault_address; // __u64 78 uint64_t regs[ARM64_REG_LAST]; // __u64 79 uint64_t pstate; // __u64 80 // Nothing else is used, so don't define it. 81}; 82 83struct arm64_ucontext_t { 84 uint64_t uc_flags; // unsigned long 85 uint64_t uc_link; // struct ucontext* 86 arm64_stack_t uc_stack; 87 arm64_sigset_t uc_sigmask; 88 // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. 89 char __padding[128 - sizeof(arm64_sigset_t)]; 90 // The full structure requires 16 byte alignment, but our partial structure 91 // doesn't, so force the alignment. 92 arm64_mcontext_t uc_mcontext __attribute__((aligned(16))); 93}; 94//------------------------------------------------------------------- 95 96//------------------------------------------------------------------- 97// X86 ucontext structures 98//------------------------------------------------------------------- 99struct x86_stack_t { 100 uint32_t ss_sp; // void __user* 101 int32_t ss_flags; // int 102 uint32_t ss_size; // size_t 103}; 104 105struct x86_mcontext_t { 106 uint32_t gs; 107 uint32_t fs; 108 uint32_t es; 109 uint32_t ds; 110 uint32_t edi; 111 uint32_t esi; 112 uint32_t ebp; 113 uint32_t esp; 114 uint32_t ebx; 115 uint32_t edx; 116 uint32_t ecx; 117 uint32_t eax; 118 uint32_t trapno; 119 uint32_t err; 120 uint32_t eip; 121 uint32_t cs; 122 uint32_t efl; 123 uint32_t uesp; 124 uint32_t ss; 125 // Only care about the registers, skip everything else. 126}; 127 128struct x86_ucontext_t { 129 uint32_t uc_flags; // unsigned long 130 uint32_t uc_link; // struct ucontext* 131 x86_stack_t uc_stack; 132 x86_mcontext_t uc_mcontext; 133 // Nothing else is used, so don't define it. 134}; 135//------------------------------------------------------------------- 136 137//------------------------------------------------------------------- 138// X86_64 ucontext structures 139//------------------------------------------------------------------- 140struct x86_64_stack_t { 141 uint64_t ss_sp; // void __user* 142 int32_t ss_flags; // int 143 uint64_t ss_size; // size_t 144}; 145 146struct x86_64_mcontext_t { 147 uint64_t r8; 148 uint64_t r9; 149 uint64_t r10; 150 uint64_t r11; 151 uint64_t r12; 152 uint64_t r13; 153 uint64_t r14; 154 uint64_t r15; 155 uint64_t rdi; 156 uint64_t rsi; 157 uint64_t rbp; 158 uint64_t rbx; 159 uint64_t rdx; 160 uint64_t rax; 161 uint64_t rcx; 162 uint64_t rsp; 163 uint64_t rip; 164 uint64_t efl; 165 uint64_t csgsfs; 166 uint64_t err; 167 uint64_t trapno; 168 uint64_t oldmask; 169 uint64_t cr2; 170 // Only care about the registers, skip everything else. 171}; 172 173typedef struct x86_64_ucontext { 174 uint64_t uc_flags; // unsigned long 175 uint64_t uc_link; // struct ucontext* 176 x86_64_stack_t uc_stack; 177 x86_64_mcontext_t uc_mcontext; 178 // Nothing else is used, so don't define it. 179} x86_64_ucontext_t; 180//------------------------------------------------------------------- 181 182} // namespace unwindstack 183 184#endif // _LIBUNWINDSTACK_UCONTEXT_H 185