Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add waitid and related constants and types. #489

Merged
merged 7 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub type nl_item = ::c_int;
pub type id_t = ::c_uint;
pub type sem_t = ::c_int;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to avoid repeating this comment in all locations, we tend to not have a lot of comments in libc due to the large amount of duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the trouble is that there isn't an obvious "top" or "first" place to put it. I think I'll leave it in bsd/apple/mod.rs, which is alphabetically first, and remove it from the others; does that sound good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think it's safe to just elide the comment in general. All the relevant properties of the typedef are already checked against the C representation, so it's basically never going to change, so it's ok to omit the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

pub type idtype_t = ::c_uint;

pub enum timezone {}

s! {
Expand Down Expand Up @@ -1363,6 +1369,15 @@ pub const LIO_READ: ::c_int = 1;
pub const LIO_WAIT: ::c_int = 2;
pub const LIO_NOWAIT: ::c_int = 1;

pub const WEXITED: ::c_int = 0x00000004;
pub const WSTOPPED: ::c_int = 0x00000008;
pub const WCONTINUED: ::c_int = 0x00000010;
pub const WNOWAIT: ::c_int = 0x00000020;

pub const P_ALL: idtype_t = 0;
pub const P_PID: idtype_t = 1;
pub const P_PGID: idtype_t = 2;

f! {
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
status >> 8
Expand Down Expand Up @@ -1532,6 +1547,12 @@ extern {
flags: ::c_int) -> ::c_int;

pub fn initgroups(user: *const ::c_char, basegroup: ::c_int) -> ::c_int;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "waitid$UNIX2003")]
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;

}

cfg_if! {
Expand Down
20 changes: 20 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub type sem_t = _sem;
pub type fsblkcnt_t = ::uint64_t;
pub type fsfilcnt_t = ::uint64_t;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
pub type idtype_t = ::c_uint;

s! {
pub struct utmpx {
pub ut_type: ::c_short,
Expand Down Expand Up @@ -356,6 +362,18 @@ pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
| LC_NUMERIC_MASK
| LC_TIME_MASK;

pub const WSTOPPED: ::c_int = 2; // same as WUNTRACED
pub const WCONTINUED: ::c_int = 4;
pub const WNOWAIT: ::c_int = 8;
pub const WEXITED: ::c_int = 16;
pub const WTRAPPED: ::c_int = 32;

// FreeBSD defines a great many more of these, we only expose the
// standardized ones.
pub const P_PID: idtype_t = 0;
pub const P_PGID: idtype_t = 2;
pub const P_ALL: idtype_t = 7;

extern {
pub fn __error() -> *mut ::c_int;

Expand All @@ -382,6 +400,8 @@ extern {
timeout: *mut ::timespec) -> ::ssize_t;

pub fn freelocale(loc: ::locale_t) -> ::c_int;
pub fn waitid(idtype: idtype_t, id: ::id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down
20 changes: 20 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ pub type blksize_t = ::int32_t;
pub type fsblkcnt_t = ::uint64_t;
pub type fsfilcnt_t = ::uint64_t;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
pub type idtype_t = ::c_int;

s! {
pub struct aiocb {
pub aio_offset: ::off_t,
Expand Down Expand Up @@ -583,6 +589,15 @@ pub const SIGEV_NONE: ::c_int = 0;
pub const SIGEV_SIGNAL: ::c_int = 1;
pub const SIGEV_THREAD: ::c_int = 2;

pub const WSTOPPED: ::c_int = 0x00000002; // same as WUNTRACED
pub const WCONTINUED: ::c_int = 0x00000010;
pub const WEXITED: ::c_int = 0x000000020;
pub const WNOWAIT: ::c_int = 0x00010000;

pub const P_ALL: idtype_t = 0;
pub const P_PID: idtype_t = 1;
pub const P_PGID: idtype_t = 4;

extern {
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;
pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int;
Expand Down Expand Up @@ -658,6 +673,11 @@ extern {
pub fn newlocale(mask: ::c_int,
locale: *const ::c_char,
base: ::locale_t) -> ::locale_t;

// This should work, but it causes the netbsd CI build to fail with an
// intra-libc.a undefined reference to `wait6`.
//pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
// options: ::c_int) -> ::c_int;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may just need a #[link_name] of some form, but otherwise it's ok to just delete this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OK. To be clear, though, I'm pretty sure this is a bug within (possibly just the rumprun version of) NetBSD libc. The actual error is

/usr/local/rumprun-x86_64/lib/libc.a(waitid.o): In function `_waitid':
/build/rumprun/src-netbsd/lib/libc/gen/waitid.c:52: undefined reference to `wait6'

I don't think there's any way to work around that from within our code.

}

mod other;
Expand Down
20 changes: 20 additions & 0 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ pub type fsblkcnt_t = i64;
pub type fsfilcnt_t = i64;
pub type pthread_attr_t = *mut ::c_void;
pub type nl_item = ::c_int;
pub type id_t = i32;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
pub type idtype_t = ::c_uint;

pub enum timezone {}

Expand Down Expand Up @@ -670,6 +677,17 @@ pub const SO_PEERCRED: ::c_int = 0x4000000b;

pub const NI_MAXHOST: ::size_t = 1025;

pub const WNOHANG: ::c_int = 0x01;
pub const WUNTRACED: ::c_int = 0x02;
pub const WCONTINUED: ::c_int = 0x04;
pub const WEXITED: ::c_int = 0x08;
pub const WSTOPPED: ::c_int = 0x10;
pub const WNOWAIT: ::c_int = 0x20;

pub const P_ALL: idtype_t = 0;
pub const P_PID: idtype_t = 1;
pub const P_PGID: idtype_t = 2;

f! {
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
Expand Down Expand Up @@ -742,6 +760,8 @@ extern {
flags: ::c_int) -> ::c_int;
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
abstime: *const ::timespec) -> ::c_int;
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down
18 changes: 18 additions & 0 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ pub type clockid_t = ::c_int;
pub type key_t = ::c_int;
pub type id_t = ::c_uint;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
cfg_if! {
if #[cfg(target_os = "android")] {
pub type idtype_t = ::c_int;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be pushed into the two lower modules as well to avoid the cfg_if!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

} else {
pub type idtype_t = ::c_uint;
}
}

pub enum timezone {}

s! {
Expand Down Expand Up @@ -624,6 +636,10 @@ pub const SIGEV_SIGNAL: ::c_int = 0;
pub const SIGEV_NONE: ::c_int = 1;
pub const SIGEV_THREAD: ::c_int = 2;

pub const P_ALL: idtype_t = 0;
pub const P_PID: idtype_t = 1;
pub const P_PGID: idtype_t = 2;

f! {
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
Expand Down Expand Up @@ -851,6 +867,8 @@ extern {
buf: *mut ::c_char,
buflen: ::size_t) -> ::c_int;
pub fn clearenv() -> ::c_int;
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down
21 changes: 21 additions & 0 deletions src/unix/solaris/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ pub type pthread_key_t = ::c_uint;
pub type blksize_t = u32;
pub type fflags_t = u32;
pub type nl_item = ::c_int;
pub type id_t = ::c_int;

// idtype_t is specified as a C enum:
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
// However, FFI doesn't currently know how to ABI-match a C enum
// (rust#28925, rust#34641).
pub type idtype_t = ::c_uint;

pub enum timezone {}

Expand Down Expand Up @@ -550,6 +557,18 @@ pub const SIGXFSZ: ::c_int = 31;
pub const WNOHANG: ::c_int = 0x40;
pub const WUNTRACED: ::c_int = 0x04;

pub const WEXITED: ::c_int = 0x01;
pub const WTRAPPED: ::c_int = 0x02;
pub const WSTOPPED: ::c_int = WUNTRACED;
pub const WCONTINUED: ::c_int = 0x08;
pub const WNOWAIT: ::c_int = 0x80;

// Solaris defines a great many more of these; we only expose the
// standardized ones.
pub const P_PID: idtype_t = 0;
pub const P_PGID: idtype_t = 2;
pub const P_ALL: idtype_t = 7;

pub const PROT_NONE: ::c_int = 0;
pub const PROT_READ: ::c_int = 1;
pub const PROT_WRITE: ::c_int = 2;
Expand Down Expand Up @@ -1056,4 +1075,6 @@ extern {
abstime: *const ::timespec) -> ::c_int;
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
abstime: *const ::timespec) -> ::c_int;
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;
}