|
@@ -37,6 +37,25 @@ section .data
|
37
|
37
|
%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
|
38
|
38
|
%endmacro
|
39
|
39
|
|
|
40
|
+ STRUC SIGACTION_STRUC
|
|
41
|
+ .sa_handler: resq 1
|
|
42
|
+ .sa_flags: resq 1
|
|
43
|
+ .sa_restorer: resq 1
|
|
44
|
+ .sa_mask: resb 128
|
|
45
|
+ ENDSTRUC
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+ sigaction: ISTRUC SIGACTION_STRUC
|
|
49
|
+ at SIGACTION_STRUC.sa_handler, dq 0
|
|
50
|
+ at SIGACTION_STRUC.sa_flags, dq 0
|
|
51
|
+ at SIGACTION_STRUC.sa_restorer, dq 0
|
|
52
|
+ at SIGACTION_STRUC.sa_mask, times 128 db 0
|
|
53
|
+ IEND
|
|
54
|
+ %define sigaction.sa_handler sigaction+SIGACTION_STRUC.sa_handler
|
|
55
|
+ %define sigaction.sa_flags sigaction+SIGACTION_STRUC.sa_flags
|
|
56
|
+ %define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
|
|
57
|
+ %define sigaction.sa_mask sigaction+SIGACTION_STRUC.sa_mask
|
|
58
|
+
|
40
|
59
|
TIMESPEC ts_start
|
41
|
60
|
TIMESPEC ts_cur
|
42
|
61
|
|
|
@@ -44,7 +63,6 @@ section .data
|
44
|
63
|
tv_sleep_s dd 0,0
|
45
|
64
|
tv_sleep_us dd 10000000,0
|
46
|
65
|
|
47
|
|
-
|
48
|
66
|
;; 1/2s sleep
|
49
|
67
|
;ts_sleep:
|
50
|
68
|
; tv_sleep_s dq 0
|
|
@@ -64,11 +82,10 @@ section .data
|
64
|
82
|
nl: db 0x0A
|
65
|
83
|
buf: db 0
|
66
|
84
|
|
67
|
|
-
|
|
85
|
+ dbgmsg: db "SigINT", 0xa
|
68
|
86
|
|
69
|
87
|
section .text
|
70
|
88
|
global _start
|
71
|
|
-
|
72
|
89
|
_start:
|
73
|
90
|
|
74
|
91
|
; set stdin non blocking
|
|
@@ -86,6 +103,24 @@ syscall
|
86
|
103
|
cmp rax, 0
|
87
|
104
|
jne fault
|
88
|
105
|
|
|
106
|
+; preparing SIGINT catch
|
|
107
|
+mov rax, lap_handler
|
|
108
|
+mov qword [sigaction.sa_handler], rax
|
|
109
|
+mov eax, 0x10000000 ; SA_RESTART
|
|
110
|
+or eax, 0x04000000 ; SA_RESTORER
|
|
111
|
+mov dword [sigaction.sa_flags], eax
|
|
112
|
+mov rax, sig_restorer
|
|
113
|
+mov qword [sigaction.sa_restorer], rax
|
|
114
|
+
|
|
115
|
+mov rax, 13 ; sys_rt_sigaction
|
|
116
|
+mov rdi, 2 ; SIGINT
|
|
117
|
+mov rsi, sigaction
|
|
118
|
+mov rdx, 0 ; NULL
|
|
119
|
+mov r10, 8 ; sig_size
|
|
120
|
+syscall
|
|
121
|
+cmp rax, 0
|
|
122
|
+jne fault
|
|
123
|
+
|
89
|
124
|
mov rax, 228 ; clock_gettime
|
90
|
125
|
mov rdi, 0 ; CLOCK_REALTIME
|
91
|
126
|
mov rsi, ts_start
|
|
@@ -257,4 +292,21 @@ newline_exit:
|
257
|
292
|
syscall
|
258
|
293
|
jmp exit
|
259
|
294
|
|
|
295
|
+lap_handler:
|
|
296
|
+ pop r8
|
|
297
|
+
|
|
298
|
+ mov rax, 1
|
|
299
|
+ mov rdi, 1
|
|
300
|
+ mov rsi, dbgmsg
|
|
301
|
+ mov rdx, 7
|
|
302
|
+ syscall
|
|
303
|
+
|
|
304
|
+ push r8 ; push back ret addr
|
|
305
|
+ ret
|
|
306
|
+
|
|
307
|
+sig_restorer:
|
|
308
|
+ mov rax, 15 ; sys_rt_sigreturn
|
|
309
|
+ xor rdi, rdi
|
|
310
|
+ syscall
|
|
311
|
+
|
260
|
312
|
.end:
|