1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#pragma once
|
|
|
16 |
|
|
|
17 |
#include <stdbool.h>
|
|
|
18 |
#include <sys/ucontext.h>
|
|
|
19 |
|
|
|
20 |
#if CLS_CPU_ARM
|
|
|
21 |
#define FIRCLSThreadStateCount ARM_THREAD_STATE_COUNT
|
|
|
22 |
#define FIRCLSThreadState ARM_THREAD_STATE
|
|
|
23 |
#elif CLS_CPU_ARM64
|
|
|
24 |
#define FIRCLSThreadStateCount ARM_THREAD_STATE64_COUNT
|
|
|
25 |
#define FIRCLSThreadState ARM_THREAD_STATE64
|
|
|
26 |
#elif CLS_CPU_I386
|
|
|
27 |
#define FIRCLSThreadStateCount x86_THREAD_STATE32_COUNT
|
|
|
28 |
#define FIRCLSThreadState x86_THREAD_STATE32
|
|
|
29 |
#elif CLS_CPU_X86_64
|
|
|
30 |
#define FIRCLSThreadStateCount x86_THREAD_STATE64_COUNT
|
|
|
31 |
#define FIRCLSThreadState x86_THREAD_STATE64
|
|
|
32 |
#endif
|
|
|
33 |
|
|
|
34 |
// _STRUCT_MCONTEXT was fixed to point to the right thing on ARM in the iOS 7.1 SDK
|
|
|
35 |
typedef _STRUCT_MCONTEXT FIRCLSThreadContext;
|
|
|
36 |
|
|
|
37 |
// I'm not entirely sure what happened when, but this appears to have disappeared from
|
|
|
38 |
// the SDKs...
|
|
|
39 |
#if !defined(_STRUCT_UCONTEXT64)
|
|
|
40 |
typedef _STRUCT_UCONTEXT _STRUCT_UCONTEXT64;
|
|
|
41 |
#endif
|
|
|
42 |
|
|
|
43 |
#pragma mark Register Access
|
|
|
44 |
|
|
|
45 |
uintptr_t FIRCLSThreadContextGetPC(FIRCLSThreadContext* registers);
|
|
|
46 |
uintptr_t FIRCLSThreadContextGetStackPointer(const FIRCLSThreadContext* registers);
|
|
|
47 |
uintptr_t FIRCLSThreadContextGetFramePointer(const FIRCLSThreadContext* registers);
|
|
|
48 |
|
|
|
49 |
bool FIRCLSThreadContextSetPC(FIRCLSThreadContext* registers, uintptr_t value);
|
|
|
50 |
bool FIRCLSThreadContextSetStackPointer(FIRCLSThreadContext* registers, uintptr_t value);
|
|
|
51 |
bool FIRCLSThreadContextSetFramePointer(FIRCLSThreadContext* registers, uintptr_t value);
|
|
|
52 |
|
|
|
53 |
// The link register only exists on ARM platforms.
|
|
|
54 |
#if CLS_CPU_ARM || CLS_CPU_ARM64
|
|
|
55 |
uintptr_t FIRCLSThreadContextGetLinkRegister(const FIRCLSThreadContext* registers);
|
|
|
56 |
bool FIRCLSThreadContextSetLinkRegister(FIRCLSThreadContext* registers, uintptr_t value);
|
|
|
57 |
#endif
|