1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SANDBOX_LINUX_SYSTEM_HEADERS_X86_64_LINUX_UCONTEXT_H_
6#define SANDBOX_LINUX_SYSTEM_HEADERS_X86_64_LINUX_UCONTEXT_H_
7
8#include <stdint.h>
9
10// We do something compatible with glibc. Hopefully, at some point Android will
11// provide that for us, and __BIONIC_HAVE_UCONTEXT_T should be defined.
12// Spec:
13// http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-AMD64/LSB-Core-AMD64/libc-ddefs.html#AEN5668
14
15#if !defined(__BIONIC_HAVE_UCONTEXT_T)
16#include <asm/sigcontext.h>
17
18struct _libc_fpxreg {
19  unsigned short significand[4];
20  unsigned short exponent;
21  unsigned short padding[3];
22};
23
24struct _libc_xmmreg {
25  uint32_t element[4];
26};
27
28struct _libc_fpstate {
29  uint16_t cwd;
30  uint16_t swd;
31  uint16_t twd;
32  uint16_t fop;
33  uint64_t rip;
34  uint64_t rdp;
35  uint32_t mxcsr;
36  uint32_t mxcsr_mask;
37  struct _libc_fpxreg _st[8];
38  struct _libc_xmmreg _xmm[16];
39  uint32_t padding[24];
40};
41
42typedef uint64_t greg_t;
43
44typedef struct {
45  greg_t gregs[23];
46  struct _libc_fpstate* fpregs;
47  unsigned long __reserved1[8];
48} mcontext_t;
49
50enum {
51  REG_R8 = 0,
52  REG_R9,
53  REG_R10,
54  REG_R11,
55  REG_R12,
56  REG_R13,
57  REG_R14,
58  REG_R15,
59  REG_RDI,
60  REG_RSI,
61  REG_RBP,
62  REG_RBX,
63  REG_RDX,
64  REG_RAX,
65  REG_RCX,
66  REG_RSP,
67  REG_RIP,
68  REG_EFL,
69  REG_CSGSFS,
70  REG_ERR,
71  REG_TRAPNO,
72  REG_OLDMASK,
73  REG_CR2,
74  NGREG,
75};
76
77typedef struct ucontext {
78  unsigned long uc_flags;
79  struct ucontext* uc_link;
80  stack_t uc_stack;
81  mcontext_t uc_mcontext;
82  sigset_t uc_sigmask;
83  struct _libc_fpstate __fpregs_mem;
84} ucontext_t;
85
86#else
87#include <sys/ucontext.h>
88#endif  // __BIONIC_HAVE_UCONTEXT_T
89
90#endif  // SANDBOX_LINUX_SYSTEM_HEADERS_X86_64_LINUX_UCONTEXT_H_
91