@@ -50,25 +50,28 @@ pub fn validate_vcpu_signal_num(num: c_int) -> io::Result<c_int> {
50
50
}
51
51
}
52
52
53
- /// Registers `handler` as the vCPU's signal handler of signum `num `.
53
+ /// Registers `handler` as the vCPU's signal handler of `signum `.
54
54
///
55
55
/// This is considered unsafe because the given handler will be called asynchronously, interrupting
56
56
/// whatever the thread was doing and therefore must only do async-signal-safe operations.
57
- pub unsafe fn register_vcpu_signal_handler ( num : i32 , handler : SignalHandler ) -> io:: Result < ( ) > {
58
- let num = validate_vcpu_signal_num ( num) ?;
57
+ pub unsafe fn register_vcpu_signal_handler (
58
+ signum : c_int ,
59
+ handler : SignalHandler ,
60
+ ) -> io:: Result < ( ) > {
61
+ let num = validate_vcpu_signal_num ( signum) ?;
59
62
// Safe, because this is a POD struct.
60
63
let mut sigact: sigaction = mem:: zeroed ( ) ;
61
64
sigact. sa_flags = libc:: SA_SIGINFO ;
62
65
sigact. sa_sigaction = handler as usize ;
63
66
SyscallReturnCode ( sigaction ( num, & sigact, null_mut ( ) ) ) . into_empty_result ( )
64
67
}
65
68
66
- /// Registers the specified signal handler for `SIGSYS `.
67
- pub fn register_sigsys_handler ( sigsys_handler : SignalHandler ) -> Result < ( ) , io:: Error > {
69
+ /// Registers `handler` as the process' signal handler of `signum `.
70
+ pub fn register_signal_handler ( signum : c_int , handler : SignalHandler ) -> Result < ( ) , io:: Error > {
68
71
// Safe, because this is a POD struct.
69
72
let mut sigact: sigaction = unsafe { mem:: zeroed ( ) } ;
70
73
sigact. sa_flags = libc:: SA_SIGINFO ;
71
- sigact. sa_sigaction = sigsys_handler as usize ;
74
+ sigact. sa_sigaction = handler as usize ;
72
75
73
76
// We set all the bits of sa_mask, so all signals are blocked on the current thread while the
74
77
// SIGSYS handler is executing. Safe because the parameter is valid and we check the return
@@ -78,7 +81,7 @@ pub fn register_sigsys_handler(sigsys_handler: SignalHandler) -> Result<(), io::
78
81
}
79
82
80
83
// Safe because the parameters are valid and we check the return value.
81
- unsafe { SyscallReturnCode ( sigaction ( libc :: SIGSYS , & sigact, null_mut ( ) ) ) . into_empty_result ( ) }
84
+ unsafe { SyscallReturnCode ( sigaction ( signum , & sigact, null_mut ( ) ) ) . into_empty_result ( ) }
82
85
}
83
86
84
87
/// Trait for threads that can be signalled via `pthread_kill`.
@@ -116,6 +119,8 @@ mod tests {
116
119
use std:: thread;
117
120
use std:: time:: Duration ;
118
121
122
+ use libc:: SIGSYS ;
123
+
119
124
static mut SIGNAL_HANDLER_CALLED : bool = false ;
120
125
121
126
extern "C" fn handle_signal ( _: c_int , _: * mut siginfo_t , _: * mut c_void ) {
@@ -130,7 +135,7 @@ mod tests {
130
135
// testing bad value
131
136
assert ! ( register_vcpu_signal_handler( SIGRTMAX ( ) , handle_signal) . is_err( ) ) ;
132
137
assert ! ( register_vcpu_signal_handler( 0 , handle_signal) . is_ok( ) ) ;
133
- assert ! ( register_sigsys_handler ( handle_signal) . is_ok( ) ) ;
138
+ assert ! ( register_signal_handler ( SIGSYS , handle_signal) . is_ok( ) ) ;
134
139
}
135
140
}
136
141
0 commit comments