|
@@ -1,42 +1,64 @@
|
1
|
|
-/* setjmp and longjmp. Use of these functions is deprecated. */
|
2
|
|
-
|
3
|
|
-FILE_LICENCE ( GPL2_OR_LATER )
|
|
1
|
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
4
|
2
|
|
5
|
3
|
.text
|
6
|
4
|
.arch i386
|
7
|
5
|
.code32
|
8
|
|
-
|
9
|
|
-/**************************************************************************
|
10
|
|
-SETJMP - Save stack context for non-local goto
|
11
|
|
-**************************************************************************/
|
|
6
|
+
|
|
7
|
+ /* Must match jmp_buf structure layout */
|
|
8
|
+ .struct 0
|
|
9
|
+env_retaddr: .long 0
|
|
10
|
+env_stack: .long 0
|
|
11
|
+env_ebx: .long 0
|
|
12
|
+env_esi: .long 0
|
|
13
|
+env_edi: .long 0
|
|
14
|
+env_ebp: .long 0
|
|
15
|
+ .previous
|
|
16
|
+
|
|
17
|
+/*
|
|
18
|
+ * Save stack context for non-local goto
|
|
19
|
+ */
|
12
|
20
|
.globl setjmp
|
13
|
21
|
setjmp:
|
14
|
|
- movl 4(%esp),%ecx /* jmpbuf */
|
15
|
|
- movl 0(%esp),%edx /* return address */
|
16
|
|
- movl %edx,0(%ecx)
|
17
|
|
- movl %ebx,4(%ecx)
|
18
|
|
- movl %esp,8(%ecx)
|
19
|
|
- movl %ebp,12(%ecx)
|
20
|
|
- movl %esi,16(%ecx)
|
21
|
|
- movl %edi,20(%ecx)
|
22
|
|
- movl $0,%eax
|
|
22
|
+ /* Get jmp_buf pointer in %edx */
|
|
23
|
+ movl 4(%esp),%edx
|
|
24
|
+ /* Save return address */
|
|
25
|
+ movl 0(%esp),%eax
|
|
26
|
+ movl %eax, env_retaddr(%edx)
|
|
27
|
+ /* Save stack pointer */
|
|
28
|
+ movl %esp, env_stack(%edx)
|
|
29
|
+ /* Save other registers */
|
|
30
|
+ movl %ebx, env_ebx(%edx)
|
|
31
|
+ movl %esi, env_esi(%edx)
|
|
32
|
+ movl %edi, env_edi(%edx)
|
|
33
|
+ movl %ebp, env_ebp(%edx)
|
|
34
|
+ /* Return 0 when returning as setjmp() */
|
|
35
|
+ xorl %eax, %eax
|
23
|
36
|
ret
|
|
37
|
+ .size setjmp, . - setjmp
|
24
|
38
|
|
25
|
|
-/**************************************************************************
|
26
|
|
-LONGJMP - Non-local jump to a saved stack context
|
27
|
|
-**************************************************************************/
|
|
39
|
+/*
|
|
40
|
+ * Non-local jump to a saved stack context
|
|
41
|
+ */
|
28
|
42
|
.globl longjmp
|
29
|
43
|
longjmp:
|
30
|
|
- movl 4(%esp),%edx /* jumpbuf */
|
31
|
|
- movl 8(%esp),%eax /* result */
|
32
|
|
- movl 0(%edx),%ecx
|
33
|
|
- movl 4(%edx),%ebx
|
34
|
|
- movl 8(%edx),%esp
|
35
|
|
- movl 12(%edx),%ebp
|
36
|
|
- movl 16(%edx),%esi
|
37
|
|
- movl 20(%edx),%edi
|
38
|
|
- cmpl $0,%eax
|
39
|
|
- jne 1f
|
40
|
|
- movl $1,%eax
|
41
|
|
-1: movl %ecx,0(%esp)
|
|
44
|
+ /* Get jmp_buf pointer in %edx */
|
|
45
|
+ movl 4(%esp),%edx
|
|
46
|
+ /* Get result in %eax */
|
|
47
|
+ movl 8(%esp),%eax
|
|
48
|
+ /* Force result to non-zero */
|
|
49
|
+ testl %eax, %eax
|
|
50
|
+ jnz 1f
|
|
51
|
+ incl %eax
|
|
52
|
+1: /* Restore stack pointer */
|
|
53
|
+ movl env_stack(%edx), %esp
|
|
54
|
+ /* Restore other registers */
|
|
55
|
+ movl env_ebx(%edx), %esp
|
|
56
|
+ movl env_esi(%edx), %esp
|
|
57
|
+ movl env_edi(%edx), %esp
|
|
58
|
+ movl env_ebp(%edx), %ebp
|
|
59
|
+ /* Replace return address on the new stack */
|
|
60
|
+ popl %ecx /* discard */
|
|
61
|
+ pushl env_retaddr(%edx)
|
|
62
|
+ /* Return to setjmp() caller */
|
42
|
63
|
ret
|
|
64
|
+ .size longjmp, . - longjmp
|