Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
206daeab
Commit
206daeab
authored
Jun 24, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added access to thread state info from the signal handler
SVN=124404
parent
2987c843
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
15 deletions
+105
-15
rt1_amd64_darwin.c
src/runtime/rt1_amd64_darwin.c
+105
-15
No files found.
src/runtime/rt1_amd64_darwin.c
View file @
206daeab
...
...
@@ -5,6 +5,99 @@
#include "runtime.h"
#include "signals.h"
typedef
uint64
__uint64_t
;
// From /usr/include/mach/i386/_structs.h
#define _STRUCT_X86_THREAD_STATE64 struct __darwin_x86_thread_state64
_STRUCT_X86_THREAD_STATE64
{
__uint64_t
__rax
;
__uint64_t
__rbx
;
__uint64_t
__rcx
;
__uint64_t
__rdx
;
__uint64_t
__rdi
;
__uint64_t
__rsi
;
__uint64_t
__rbp
;
__uint64_t
__rsp
;
__uint64_t
__r8
;
__uint64_t
__r9
;
__uint64_t
__r10
;
__uint64_t
__r11
;
__uint64_t
__r12
;
__uint64_t
__r13
;
__uint64_t
__r14
;
__uint64_t
__r15
;
__uint64_t
__rip
;
__uint64_t
__rflags
;
__uint64_t
__cs
;
__uint64_t
__fs
;
__uint64_t
__gs
;
};
void
print_thread_state
(
_STRUCT_X86_THREAD_STATE64
*
ss
)
{
prints
(
"
\n
rax 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rax
);
prints
(
"
\n
rbx 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rbx
);
prints
(
"
\n
rcx 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rcx
);
prints
(
"
\n
rdx 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rdx
);
prints
(
"
\n
rdi 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rdi
);
prints
(
"
\n
rsi 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rsi
);
prints
(
"
\n
rbp 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rbp
);
prints
(
"
\n
rsp 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rsp
);
prints
(
"
\n
r8 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r8
);
prints
(
"
\n
r9 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r9
);
prints
(
"
\n
r10 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r10
);
prints
(
"
\n
r11 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r11
);
prints
(
"
\n
r12 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r12
);
prints
(
"
\n
r13 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r13
);
prints
(
"
\n
r14 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r14
);
prints
(
"
\n
r15 0x"
);
sys_printpointer
((
void
*
)
ss
->
__r15
);
prints
(
"
\n
rip 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rip
);
prints
(
"
\n
rflags 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rflags
);
prints
(
"
\n
cs 0x"
);
sys_printpointer
((
void
*
)
ss
->
__cs
);
prints
(
"
\n
fs 0x"
);
sys_printpointer
((
void
*
)
ss
->
__fs
);
prints
(
"
\n
gs 0x"
);
sys_printpointer
((
void
*
)
ss
->
__gs
);
prints
(
"
\n
"
);
}
/* Code generated via: g++ -m64 signals.cc && a.out */
static
void
*
adr_at
(
void
*
ptr
,
int32
offs
)
{
return
(
void
*
)((
uint8
*
)
ptr
+
offs
);
}
static
void
*
ptr_at
(
void
*
ptr
,
int32
offs
)
{
return
*
(
void
**
)((
uint8
*
)
ptr
+
offs
);
}
typedef
void
ucontext_t
;
typedef
void
_STRUCT_MCONTEXT64
;
typedef
void
_STRUCT_X86_EXCEPTION_STATE64
;
typedef
void
_STRUCT_X86_FLOAT_STATE64
;
static
_STRUCT_MCONTEXT64
*
get_uc_mcontext
(
ucontext_t
*
ptr
)
{
return
(
_STRUCT_MCONTEXT64
*
)
ptr_at
(
ptr
,
48
);
}
static
_STRUCT_X86_EXCEPTION_STATE64
*
get___es
(
_STRUCT_MCONTEXT64
*
ptr
)
{
return
(
_STRUCT_X86_EXCEPTION_STATE64
*
)
adr_at
(
ptr
,
0
);
}
static
_STRUCT_X86_THREAD_STATE64
*
get___ss
(
_STRUCT_MCONTEXT64
*
ptr
)
{
return
(
_STRUCT_X86_THREAD_STATE64
*
)
adr_at
(
ptr
,
16
);
}
static
_STRUCT_X86_FLOAT_STATE64
*
get___fs
(
_STRUCT_MCONTEXT64
*
ptr
)
{
return
(
_STRUCT_X86_FLOAT_STATE64
*
)
adr_at
(
ptr
,
184
);
}
/* End of generated code */
/*
* This assembler routine takes the args from registers, puts them on the stack,
* and calls sighandler().
...
...
@@ -37,10 +130,8 @@ typedef struct sigaction {
}
sigaction
;
void
sighandler
(
int32
sig
,
siginfo
*
info
,
void
**
context
)
{
int32
i
;
void
*
pc
,
*
sp
;
sighandler
(
int32
sig
,
siginfo
*
info
,
void
*
context
)
{
if
(
sig
<
0
||
sig
>=
NSIG
){
prints
(
"Signal "
);
sys_printint
(
sig
);
...
...
@@ -48,17 +139,16 @@ sighandler(int32 sig, siginfo* info, void** context) {
prints
(
sigtab
[
sig
].
name
);
}
prints
(
"
\n
Faulting address: 0x"
);
sys_printpointer
(
info
->
si_addr
);
prints
(
"
\n
PC: 0x"
);
pc
=
((
void
**
)((
&
sig
)
+
1
))[
22
];
sys_printpointer
(
pc
);
prints
(
"
\n
SP: 0x"
);
sp
=
((
void
**
)((
&
sig
)
+
1
))[
13
];
sys_printpointer
(
sp
);
prints
(
"
\n
"
);
if
(
pc
!=
0
&&
sp
!=
0
)
traceback
(
pc
,
sp
);
/* empirically discovered locations */
_STRUCT_MCONTEXT64
*
uc_mcontext
=
get_uc_mcontext
(
context
);
_STRUCT_X86_THREAD_STATE64
*
ss
=
get___ss
(
uc_mcontext
);
prints
(
"
\n
Faulting address: 0x"
);
sys_printpointer
(
info
->
si_addr
);
prints
(
"
\n
pc: 0x"
);
sys_printpointer
((
void
*
)
ss
->
__rip
);
prints
(
"
\n\n
"
);
traceback
((
void
*
)
ss
->
__rip
,
(
void
*
)
ss
->
__rsp
);
print_thread_state
(
ss
);
sys_exit
(
2
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment