1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef BERBERIS_GUEST_STATE_GUEST_STATE_ARCH_H_
18 #define BERBERIS_GUEST_STATE_GUEST_STATE_ARCH_H_
19 
20 #include <atomic>
21 
22 #include "berberis/guest_state/guest_addr.h"
23 #include "berberis/guest_state/guest_state_opaque.h"
24 #include "native_bridge_support/arm/guest_state/guest_state_cpu_state.h"
25 
26 namespace berberis {
27 
28 // Guest CPU state + interface to access guest memory.
29 struct ThreadState {
30   CPUState cpu;
31 
32   // Guest thread pointer.
33   GuestThread* thread;
34 
35   // Guest TLS pointer.
36   // It can be read using MRC instruction.
37   // Statically linked ARM executable initializes it by set_tls syscall.
38   // For PIC objects, InitThreadState sets it either to host TLS or to (stub) thread-id.
39   // TODO(b/36890513): guest should have its own TLS area for PIC objects too.
40   GuestAddr tls;
41 
42   // Keep pending signals status here for fast checking in generated code.
43   // TODO(b/28058920): move to GuestThread!
44   std::atomic_uint_least8_t pending_signals_status;
45 
46   GuestThreadResidence residence;
47 
48   // Arbitrary per-thread data added by instrumentation.
49   void* instrument_data;
50 
51   // Point to the guest thread memory start position.
52   void* thread_state_storage;
53 };
54 
55 }  // namespace berberis
56 
57 #endif  // BERBERIS_GUEST_STATE_GUEST_STATE_ARCH_H_
58