Skip to content

Commit 527beaa

Browse files
authored
Provide _NSIG, kernel_sigset_t, and kernel_sigaction (#51)
See the comments in gen/modules/general.h for details, but in short, the definitions of `NSIG`, `sigset_t`, and `sigaction` provided by the Linux headers don't match what's used by the `rt_sigaction` system call, so define versions that do.
1 parent 8bafff2 commit 527beaa

15 files changed

Lines changed: 209 additions & 0 deletions

File tree

gen/modules/general.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,25 @@ struct mmsghdr {
357357
#define MNT_EXPIRE 0x4
358358
#define UMOUNT_NOFOLLOW 0x8
359359
#define UMOUNT_UNUSED 0x80000000
360+
361+
// Linux's public headers provide public `NSIG`, `sigset_t` and `sigaction`
362+
// definitions which "cater to libcs that poke about in kernel headers", but
363+
// they're not usable in libcs because, for example, `SYS_rt_sigaction` insists
364+
// that its fourth argument be the size of the kernel's internal `sigset_t`
365+
// type. So we define our own.
366+
367+
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__)
368+
#define _NSIG 64
369+
#endif
370+
371+
typedef struct {
372+
unsigned long sig[_NSIG / (sizeof(unsigned long) * __CHAR_BIT__)];
373+
} kernel_sigset_t;
374+
375+
struct kernel_sigaction {
376+
// Some platforms make `sa_handler` a macro, so use a different name.
377+
__kernel_sighandler_t sa_handler_kernel;
378+
unsigned long sa_flags;
379+
__sigrestore_t sa_restorer;
380+
kernel_sigset_t sa_mask;
381+
};

src/aarch64/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5254,3 +5254,16 @@ pub struct mmsghdr {
52545254
pub msg_hdr: msghdr,
52555255
pub msg_len: crate::ctypes::c_uint,
52565256
}
5257+
#[repr(C)]
5258+
#[derive(Debug, Copy, Clone)]
5259+
pub struct kernel_sigset_t {
5260+
pub sig: [crate::ctypes::c_ulong; 1usize],
5261+
}
5262+
#[repr(C)]
5263+
#[derive(Debug, Copy, Clone)]
5264+
pub struct kernel_sigaction {
5265+
pub sa_handler_kernel: __kernel_sighandler_t,
5266+
pub sa_flags: crate::ctypes::c_ulong,
5267+
pub sa_restorer: __sigrestore_t,
5268+
pub sa_mask: kernel_sigset_t,
5269+
}

src/arm/general.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ pub const MNT_DETACH: u32 = 2;
26142614
pub const MNT_EXPIRE: u32 = 4;
26152615
pub const UMOUNT_NOFOLLOW: u32 = 8;
26162616
pub const UMOUNT_UNUSED: u32 = 2147483648;
2617+
pub const _NSIG: u32 = 64;
26172618
pub type size_t = crate::ctypes::c_uint;
26182619
pub type ssize_t = crate::ctypes::c_int;
26192620
pub type __s8 = crate::ctypes::c_schar;
@@ -5377,3 +5378,16 @@ pub struct mmsghdr {
53775378
pub msg_hdr: msghdr,
53785379
pub msg_len: crate::ctypes::c_uint,
53795380
}
5381+
#[repr(C)]
5382+
#[derive(Debug, Copy, Clone)]
5383+
pub struct kernel_sigset_t {
5384+
pub sig: [crate::ctypes::c_ulong; 2usize],
5385+
}
5386+
#[repr(C)]
5387+
#[derive(Debug, Copy, Clone)]
5388+
pub struct kernel_sigaction {
5389+
pub sa_handler_kernel: __kernel_sighandler_t,
5390+
pub sa_flags: crate::ctypes::c_ulong,
5391+
pub sa_restorer: __sigrestore_t,
5392+
pub sa_mask: kernel_sigset_t,
5393+
}

src/mips/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5542,3 +5542,16 @@ pub struct mmsghdr {
55425542
pub msg_hdr: msghdr,
55435543
pub msg_len: crate::ctypes::c_uint,
55445544
}
5545+
#[repr(C)]
5546+
#[derive(Debug, Copy, Clone)]
5547+
pub struct kernel_sigset_t {
5548+
pub sig: [crate::ctypes::c_ulong; 4usize],
5549+
}
5550+
#[repr(C)]
5551+
#[derive(Debug, Copy, Clone)]
5552+
pub struct kernel_sigaction {
5553+
pub sa_handler_kernel: __kernel_sighandler_t,
5554+
pub sa_flags: crate::ctypes::c_ulong,
5555+
pub sa_restorer: __sigrestore_t,
5556+
pub sa_mask: kernel_sigset_t,
5557+
}

src/mips64/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5467,3 +5467,16 @@ pub struct mmsghdr {
54675467
pub msg_hdr: msghdr,
54685468
pub msg_len: crate::ctypes::c_uint,
54695469
}
5470+
#[repr(C)]
5471+
#[derive(Debug, Copy, Clone)]
5472+
pub struct kernel_sigset_t {
5473+
pub sig: [crate::ctypes::c_ulong; 2usize],
5474+
}
5475+
#[repr(C)]
5476+
#[derive(Debug, Copy, Clone)]
5477+
pub struct kernel_sigaction {
5478+
pub sa_handler_kernel: __kernel_sighandler_t,
5479+
pub sa_flags: crate::ctypes::c_ulong,
5480+
pub sa_restorer: __sigrestore_t,
5481+
pub sa_mask: kernel_sigset_t,
5482+
}

src/powerpc/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,3 +5463,16 @@ pub struct mmsghdr {
54635463
pub msg_hdr: msghdr,
54645464
pub msg_len: crate::ctypes::c_uint,
54655465
}
5466+
#[repr(C)]
5467+
#[derive(Debug, Copy, Clone)]
5468+
pub struct kernel_sigset_t {
5469+
pub sig: [crate::ctypes::c_ulong; 2usize],
5470+
}
5471+
#[repr(C)]
5472+
#[derive(Debug, Copy, Clone)]
5473+
pub struct kernel_sigaction {
5474+
pub sa_handler_kernel: __kernel_sighandler_t,
5475+
pub sa_flags: crate::ctypes::c_ulong,
5476+
pub sa_restorer: __sigrestore_t,
5477+
pub sa_mask: kernel_sigset_t,
5478+
}

src/powerpc64/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,3 +5418,16 @@ pub struct mmsghdr {
54185418
pub msg_hdr: msghdr,
54195419
pub msg_len: crate::ctypes::c_uint,
54205420
}
5421+
#[repr(C)]
5422+
#[derive(Debug, Copy, Clone)]
5423+
pub struct kernel_sigset_t {
5424+
pub sig: [crate::ctypes::c_ulong; 1usize],
5425+
}
5426+
#[repr(C)]
5427+
#[derive(Debug, Copy, Clone)]
5428+
pub struct kernel_sigaction {
5429+
pub sa_handler_kernel: __kernel_sighandler_t,
5430+
pub sa_flags: crate::ctypes::c_ulong,
5431+
pub sa_restorer: __sigrestore_t,
5432+
pub sa_mask: kernel_sigset_t,
5433+
}

src/riscv32/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,3 +5262,16 @@ pub struct mmsghdr {
52625262
pub msg_hdr: msghdr,
52635263
pub msg_len: crate::ctypes::c_uint,
52645264
}
5265+
#[repr(C)]
5266+
#[derive(Debug, Copy, Clone)]
5267+
pub struct kernel_sigset_t {
5268+
pub sig: [crate::ctypes::c_ulong; 2usize],
5269+
}
5270+
#[repr(C)]
5271+
#[derive(Debug, Copy, Clone)]
5272+
pub struct kernel_sigaction {
5273+
pub sa_handler_kernel: __kernel_sighandler_t,
5274+
pub sa_flags: crate::ctypes::c_ulong,
5275+
pub sa_restorer: __sigrestore_t,
5276+
pub sa_mask: kernel_sigset_t,
5277+
}

src/riscv64/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,3 +5255,16 @@ pub struct mmsghdr {
52555255
pub msg_hdr: msghdr,
52565256
pub msg_len: crate::ctypes::c_uint,
52575257
}
5258+
#[repr(C)]
5259+
#[derive(Debug, Copy, Clone)]
5260+
pub struct kernel_sigset_t {
5261+
pub sig: [crate::ctypes::c_ulong; 1usize],
5262+
}
5263+
#[repr(C)]
5264+
#[derive(Debug, Copy, Clone)]
5265+
pub struct kernel_sigaction {
5266+
pub sa_handler_kernel: __kernel_sighandler_t,
5267+
pub sa_flags: crate::ctypes::c_ulong,
5268+
pub sa_restorer: __sigrestore_t,
5269+
pub sa_mask: kernel_sigset_t,
5270+
}

src/s390x/general.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,7 @@ pub const MNT_DETACH: u32 = 2;
25722572
pub const MNT_EXPIRE: u32 = 4;
25732573
pub const UMOUNT_NOFOLLOW: u32 = 8;
25742574
pub const UMOUNT_UNUSED: u32 = 2147483648;
2575+
pub const _NSIG: u32 = 64;
25752576
pub type size_t = crate::ctypes::c_ulong;
25762577
pub type ssize_t = crate::ctypes::c_long;
25772578
pub type __s8 = crate::ctypes::c_schar;
@@ -5295,3 +5296,16 @@ pub struct mmsghdr {
52955296
pub msg_hdr: msghdr,
52965297
pub msg_len: crate::ctypes::c_uint,
52975298
}
5299+
#[repr(C)]
5300+
#[derive(Debug, Copy, Clone)]
5301+
pub struct kernel_sigset_t {
5302+
pub sig: [crate::ctypes::c_ulong; 1usize],
5303+
}
5304+
#[repr(C)]
5305+
#[derive(Debug, Copy, Clone)]
5306+
pub struct kernel_sigaction {
5307+
pub sa_handler_kernel: __kernel_sighandler_t,
5308+
pub sa_flags: crate::ctypes::c_ulong,
5309+
pub sa_restorer: __sigrestore_t,
5310+
pub sa_mask: kernel_sigset_t,
5311+
}

0 commit comments

Comments
 (0)