File tree Expand file tree Collapse file tree 11 files changed +389
-178
lines changed Expand file tree Collapse file tree 11 files changed +389
-178
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,18 @@ doctest = false
19
19
test = false
20
20
21
21
[dependencies ]
22
- cfg-if = " 0.1"
23
- libc = " 0.2"
22
+ cfg-if = " 0.1.6"
23
+ libc = " 0.2.45"
24
+
25
+ [target .'cfg(windows)' .dependencies .winapi ]
26
+ version = " 0.3.6"
27
+ features = [
28
+ ' memoryapi' ,
29
+ ' winbase' ,
30
+ ' fibersapi' ,
31
+ ' processthreadsapi' ,
32
+ ' minwindef' ,
33
+ ]
24
34
25
35
[build-dependencies ]
26
36
cc = " 1.0"
Original file line number Diff line number Diff line change 7
7
8
8
A stack-growth library for Rust. Enables annotating fixed points in programs
9
9
where the stack may want to grow larger. Spills over to the heap if the stack
10
- has it its limit.
10
+ has hit its limit.
11
11
12
12
This library is intended on helping implement recursive algorithms.
13
13
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ fn main() {
14
14
cfg. define ( "APPLE" , None ) ;
15
15
} else if target. contains ( "windows" ) {
16
16
cfg. define ( "WINDOWS" , None ) ;
17
+ cfg. file ( "src/arch/windows.c" ) ;
17
18
} else {
18
19
panic ! ( "\n \n using currently unsupported target triple with \
19
20
stacker: {}\n \n ", target) ;
Original file line number Diff line number Diff line change 2
2
3
3
.text
4
4
5
- GLOBAL(__stacker_black_box):
6
- ret
7
-
8
5
GLOBAL(__stacker_stack_pointer):
9
6
mov %esp , %eax
10
7
ret
11
8
12
- #if defined(WINDOWS)
13
- GLOBAL(__stacker_get_tib_32):
14
- mov %fs :0x18 , %eax
15
- ret
16
- #endif
17
-
18
9
GLOBAL(__stacker_switch_stacks):
10
+ // CFI instructions tells the unwinder how to unwind this function
11
+ // This enables unwinding through our extended stacks and also
12
+ // backtrackes
13
+ .cfi_startproc
19
14
push %ebp
15
+ .cfi_def_cfa_offset 8 // restore esp by adding 8
16
+ .cfi_offset ebp, -8 // restore ebp from the stack
20
17
mov %esp , %ebp
21
- mov 8 (%ebp ), %esp // switch to our new stack
18
+ .cfi_def_cfa_register ebp // restore esp from ebp
19
+ mov 16 (%ebp ), %esp // switch to our new stack
22
20
mov 12 (%ebp ), %eax // load function we're going to call
23
- push 16 (%ebp ) // push argument to first function
21
+ push 8 (%ebp ) // push argument to first function
24
22
call *%eax // call our function pointer
25
23
mov %ebp , %esp // restore the old stack pointer
26
24
pop %ebp
27
25
ret
26
+ .cfi_endproc
Original file line number Diff line number Diff line change 2
2
.MODEL FL AT , C
3
3
.CODE
4
4
5
- __stacker_black_box PROC
6
- RET
7
- __stacker_black_box ENDP
8
-
9
5
__stacker_stack_pointer PROC
10
6
MOV EAX , ESP
11
7
RET
12
8
__stacker_stack_pointer ENDP
13
9
14
- __stacker_get_tib_32 PROC
15
- ASSUME FS :NOTHING
16
- MOV EAX , FS : [ 24 ]
17
- ASSUME FS :ERROR
18
- RET
19
- __stacker_get_tib_32 ENDP
20
-
21
- __stacker_switch_stacks PROC
22
- PUSH EBP
23
- MOV EBP , ESP
24
- MOV ESP , [ EBP + 8 ] ; switch stacks
25
- MOV EAX , [ EBP + 12 ] ; load the function we're going to call
26
- PUSH [ EBP + 16 ] ; push the argument to this function
27
- CALL EAX ; call the next function
28
- MOV ESP , EBP ; restore the old stack pointer
29
- POP EBP
30
- RET
31
- __stacker_switch_stacks ENDP
32
-
33
10
END
Original file line number Diff line number Diff line change
1
+ #include <windows.h>
2
+
3
+ PVOID __stacker_get_current_fiber () {
4
+ return GetCurrentFiber ();
5
+ }
Original file line number Diff line number Diff line change 2
2
3
3
.text
4
4
5
- GLOBAL(__stacker_black_box):
6
- ret
7
-
8
5
GLOBAL(__stacker_stack_pointer):
9
6
movq %rsp , %rax
10
7
ret
11
8
12
- #if defined(WINDOWS)
13
- #define ARG1 %rcx
14
- #define ARG2 %rdx
15
- #define ARG3 %r8
16
- #else
17
- #define ARG1 %rdi
18
- #define ARG2 %rsi
19
- #define ARG3 %rdx
20
- #endif
21
-
22
- #if defined(WINDOWS)
23
- GLOBAL(__stacker_get_tib_64):
24
- mov %gs :0x30 , %rax
25
- ret
26
- #endif
27
-
28
9
GLOBAL(__stacker_switch_stacks):
10
+ // CFI instructions tells the unwinder how to unwind this function
11
+ // This enables unwinding through our extended stacks and also
12
+ // backtrackes
13
+ .cfi_startproc
29
14
push %rbp
15
+ .cfi_def_cfa_offset 16 // restore rsp by adding 16
16
+ .cfi_offset rbp, -16 // restore rbp from the stack
30
17
mov %rsp , %rbp
31
- mov ARG1, %rsp // switch to our new stack
32
- mov ARG3, ARG1 // move the data pointer to the first argument
33
- call *ARG2 // call our function pointer
18
+ .cfi_def_cfa_register rbp // restore rsp from rbp
19
+ mov %rdx , %rsp // switch to our new stack
20
+ call *%rsi // call our function pointer, data argument in %rdi
34
21
mov %rbp , %rsp // restore the old stack pointer
35
22
pop %rbp
36
23
ret
24
+ .cfi_endproc
Original file line number Diff line number Diff line change 1
1
_text SEGMENT
2
2
3
- __stacker_black_box PROC
4
- RET
5
- __stacker_black_box ENDP
6
-
7
3
__stacker_stack_pointer PROC
8
4
MOV RAX , RSP
9
5
RET
10
6
__stacker_stack_pointer ENDP
11
7
12
- __stacker_switch_stacks PROC
13
- PUSH RBP
14
- MOV RBP , RSP
15
- MOV RSP , RCX ; switch to our new stack
16
- MOV RCX , R8 ; move the data pointer to the first argument
17
- CALL RDX ; call our function pointer
18
- MOV RSP , RBP ; restore the old stack pointer
19
- POP RBP
20
- RET
21
- __stacker_switch_stacks ENDP
22
-
23
- END
8
+ END
You can’t perform that action at this time.
0 commit comments