]> git.saurik.com Git - apple/system_cmds.git/blob - KDBG/NurseryMachMsg.hpp
system_cmds-671.10.3.tar.gz
[apple/system_cmds.git] / KDBG / NurseryMachMsg.hpp
1 //
2 // NurseryMachMsg.hpp
3 // KDBG
4 //
5 // Created by James McIlree on 2/20/14.
6 // Copyright (c) 2014 Apple. All rights reserved.
7 //
8
9 #ifndef kernel_perf_cmds_NurseryMachMsg_hpp
10 #define kernel_perf_cmds_NurseryMachMsg_hpp
11
12 enum class kNurseryMachMsgState : std::uint32_t {
13 Uninitialized = 1,
14 Send,
15 Recv,
16 Free
17 };
18
19 template <typename SIZE>
20 class NurseryMachMsg {
21 protected:
22 AbsTime _send_time;
23 MachineVoucher<SIZE>* _send_voucher;
24
25 typename SIZE::ptr_t _send_tid;
26 typename SIZE::ptr_t _kmsg_addr;
27
28 uint32_t _id; // This is globally unique for EACH message.
29 uint32_t _send_msgh_id;
30 uint32_t _send_msgh_bits; // msgh_bits is modified between send/recv
31 kNurseryMachMsgState _state;
32
33 // These are intptr_t's so they can be set to -1, indicating "no index"
34 intptr_t _send_event_index;
35
36 public:
37 static uint32_t message_id();
38
39 NurseryMachMsg(typename SIZE::ptr_t kmsg_addr) :
40 _kmsg_addr(kmsg_addr),
41 _state(kNurseryMachMsgState::Uninitialized)
42 {
43 }
44
45 void send(uintptr_t index, AbsTime time, typename SIZE::ptr_t tid, typename SIZE::ptr_t kmsg_addr, uint32_t msgh_bits, uint32_t msgh_id, MachineVoucher<SIZE>* voucher);
46
47 kNurseryMachMsgState state() const { return _state; }
48 void set_state(kNurseryMachMsgState state) { _state = state; }
49
50 AbsTime send_time() const { return _send_time; }
51 typename SIZE::ptr_t send_tid() const { return _send_tid; }
52
53 typename SIZE::ptr_t kmsg_addr() const { return _kmsg_addr; }
54 MachineVoucher<SIZE>* send_voucher() const { return _send_voucher; }
55
56 uint32_t id() const { return _id; }
57 uint32_t send_msgh_id() const { return _send_msgh_id; }
58 uint32_t send_msgh_bits() const { return _send_msgh_bits; }
59
60 void set_send_event_index(intptr_t value) { _send_event_index = value; }
61 intptr_t send_event_index() const { return _send_event_index; }
62 };
63
64 template <typename SIZE>
65 uint32_t NurseryMachMsg<SIZE>::message_id() {
66 static uint32_t message_id = 1;
67 return OSAtomicIncrement32Barrier((volatile int32_t*)&message_id);
68 }
69
70 template <typename SIZE>
71 void NurseryMachMsg<SIZE>::send(uintptr_t index, AbsTime time, typename SIZE::ptr_t tid, typename SIZE::ptr_t kmsg_addr, uint32_t msgh_bits, uint32_t msgh_id, MachineVoucher<SIZE>* voucher) {
72 ASSERT(_state == kNurseryMachMsgState::Uninitialized || _state == kNurseryMachMsgState::Free, "Calling send when msg is not in Uninitialized/Free state");
73 ASSERT(kmsg_addr == _kmsg_addr, "Sanity");
74
75 ASSERT(tid, "Sanity");
76 ASSERT(msgh_bits, "Sanity");
77
78 _id = NurseryMachMsg::message_id();
79
80 _send_event_index = index;
81 _send_time = time;
82 _send_tid = tid;
83 // _kmsg_addr = kmsg_addr;
84 _send_msgh_bits = msgh_bits;
85 _send_msgh_id = msgh_id;
86 _send_voucher = voucher;
87 }
88
89 #endif