Skip to content

Commit 027d483

Browse files
committed
Auto merge of #1176 - xmclark:add-signal-and-raise-windows, r=alexcrichton
add signal and raise bindings for windows This PR adds `signal` and `raise` bindings for windows. I don't know these functions or linux very well, so I leaned on other overrides of signal in the linux bindings, and the [cppreference page](https://en.cppreference.com/w/cpp/header/csignal) for adding the bindings. I added some constants that were shown on the [microsoft signal page](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2017) and used the default values I found spelunking through my own copy of `signal.h` that came along with visual studio. The automated tests pass and my toy apps use the `signal` and `raise` as expected. Let me know if there is anything else I need to do, or any extra tests to write. EDIT: currently working on getting a nice isolated msys2 environment I can use to dev against. - [x] msys2 env setup and building
2 parents 8b63b1c + af19934 commit 027d483

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

libc-test/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn main() {
7676
cfg.header("windows.h");
7777
cfg.header("process.h");
7878
cfg.header("ws2ipdef.h");
79+
cfg.header("signal.h");
7980

8081
if target.contains("gnu") {
8182
cfg.header("ws2tcpip.h");
@@ -372,7 +373,9 @@ fn main() {
372373
// Fixup a few types on windows that don't actually exist.
373374
"time64_t" if windows => "__time64_t".to_string(),
374375
"ssize_t" if windows => "SSIZE_T".to_string(),
375-
376+
// windows
377+
"sighandler_t" if windows && !mingw => "_crt_signal_t".to_string(),
378+
"sighandler_t" if windows && mingw => "__p_sig_fn_t".to_string(),
376379
// OSX calls this something else
377380
"sighandler_t" if bsdlike => "sig_t".to_string(),
378381

@@ -507,6 +510,7 @@ fn main() {
507510
n if n.starts_with("P") => true,
508511
n if n.starts_with("H") => true,
509512
n if n.starts_with("LP") => true,
513+
"__p_sig_fn_t" if mingw => true,
510514
_ => false,
511515
}
512516
});

src/windows/gnu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ pub const TMP_MAX: ::c_uint = 0x7fff;
44
extern {
55
pub fn strcasecmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int;
66
pub fn strncasecmp(s1: *const ::c_char, s2: *const ::c_char,
7-
n: ::size_t) -> ::c_int;
7+
n: ::size_t) -> ::c_int;
88
}

src/windows/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub type ptrdiff_t = isize;
2727
pub type intptr_t = isize;
2828
pub type uintptr_t = usize;
2929
pub type ssize_t = isize;
30+
pub type sighandler_t = usize;
3031

3132
pub type c_char = i8;
3233
pub type c_long = i32;
@@ -177,6 +178,16 @@ pub const ENOTEMPTY: ::c_int = 41;
177178
pub const EILSEQ: ::c_int = 42;
178179
pub const STRUNCATE: ::c_int = 80;
179180

181+
// signal codes
182+
pub const SIGINT: ::c_int = 2;
183+
pub const SIGILL: ::c_int = 4;
184+
pub const SIGFPE: ::c_int = 8;
185+
pub const SIGSEGV: ::c_int = 11;
186+
pub const SIGTERM: ::c_int = 15;
187+
pub const SIGABRT: ::c_int = 22;
188+
pub const NSIG: ::c_int = 23;
189+
pub const SIG_ERR: ::c_int = -1;
190+
180191
// inline comment below appeases style checker
181192
#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if "
182193
#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
@@ -287,6 +298,9 @@ extern {
287298
pub fn rand() -> c_int;
288299
pub fn srand(seed: c_uint);
289300

301+
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
302+
pub fn raise(signum: c_int) -> c_int;
303+
290304
#[link_name = "_chmod"]
291305
pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int;
292306
#[link_name = "_wchmod"]

src/windows/msvc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ extern {
77
#[link_name = "_strnicmp"]
88
pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char,
99
n: ::size_t) -> ::c_int;
10-
}
10+
}

0 commit comments

Comments
 (0)