1 /**
2  * D header file for Darwin.
3  *
4  * Copyright: Copyright Sean Kelly 2008 - 2009.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Sean Kelly
7  */
8 
9 /*          Copyright Sean Kelly 2008 - 2009.
10  * Distributed under the Boost Software License, Version 1.0.
11  *    (See accompanying file LICENSE or copy at
12  *          http://www.boost.org/LICENSE_1_0.txt)
13  */
14 module core.sys.darwin.mach.thread_act;
15 
16 version (OSX)
17     version = Darwin;
18 else version (iOS)
19     version = Darwin;
20 else version (TVOS)
21     version = Darwin;
22 else version (WatchOS)
23     version = Darwin;
24 
25 version (Darwin):
26 extern (C):
27 nothrow:
28 @nogc:
29 
30 public import core.sys.darwin.mach.kern_return;
31 public import core.sys.darwin.mach.port;
32 
33 version (X86)
34     version = i386;
35 version (X86_64)
36     version = i386;
version(i386)37 version (i386)
38 {
39     alias mach_port_t thread_act_t;
40     alias void        thread_state_t;
41     alias int         thread_state_flavor_t;
42     alias natural_t   mach_msg_type_number_t;
43 
44     enum
45     {
46         x86_THREAD_STATE32      = 1,
47         x86_FLOAT_STATE32       = 2,
48         x86_EXCEPTION_STATE32   = 3,
49         x86_THREAD_STATE64      = 4,
50         x86_FLOAT_STATE64       = 5,
51         x86_EXCEPTION_STATE64   = 6,
52         x86_THREAD_STATE        = 7,
53         x86_FLOAT_STATE         = 8,
54         x86_EXCEPTION_STATE     = 9,
55         x86_DEBUG_STATE32       = 10,
56         x86_DEBUG_STATE64       = 11,
57         x86_DEBUG_STATE         = 12,
58         THREAD_STATE_NONE       = 13,
59     }
60 
61     struct x86_thread_state32_t
62     {
63         uint    eax;
64         uint    ebx;
65         uint    ecx;
66         uint    edx;
67         uint    edi;
68         uint    esi;
69         uint    ebp;
70         uint    esp;
71         uint    ss;
72         uint    eflags;
73         uint    eip;
74         uint    cs;
75         uint    ds;
76         uint    es;
77         uint    fs;
78         uint    gs;
79     }
80 
81     struct x86_thread_state64_t
82     {
83         ulong   rax;
84         ulong   rbx;
85         ulong   rcx;
86         ulong   rdx;
87         ulong   rdi;
88         ulong   rsi;
89         ulong   rbp;
90         ulong   rsp;
91         ulong   r8;
92         ulong   r9;
93         ulong   r10;
94         ulong   r11;
95         ulong   r12;
96         ulong   r13;
97         ulong   r14;
98         ulong   r15;
99         ulong   rip;
100         ulong   rflags;
101         ulong   cs;
102         ulong   fs;
103         ulong   gs;
104     }
105 
106     struct x86_state_hdr_t
107     {
108         int     flavor;
109         int     count;
110     }
111 
112     struct x86_thread_state_t
113     {
114         x86_state_hdr_t             tsh;
115         union _uts
116         {
117             x86_thread_state32_t    ts32;
118             x86_thread_state64_t    ts64;
119         }
120         _uts                        uts;
121     }
122 
123     enum : mach_msg_type_number_t
124     {
125         x86_THREAD_STATE32_COUNT = cast(mach_msg_type_number_t)( x86_thread_state32_t.sizeof / int.sizeof ),
126         x86_THREAD_STATE64_COUNT = cast(mach_msg_type_number_t)( x86_thread_state64_t.sizeof / int.sizeof ),
127         x86_THREAD_STATE_COUNT   = cast(mach_msg_type_number_t)( x86_thread_state_t.sizeof / int.sizeof ),
128     }
129 
130     alias x86_THREAD_STATE          MACHINE_THREAD_STATE;
131     alias x86_THREAD_STATE_COUNT    MACHINE_THREAD_STATE_COUNT;
132 
133     mach_port_t   mach_thread_self();
134     kern_return_t thread_suspend(thread_act_t);
135     kern_return_t thread_resume(thread_act_t);
136     kern_return_t thread_get_state(thread_act_t, thread_state_flavor_t, thread_state_t*, mach_msg_type_number_t*);
137 }
138