relibc: add missing POSIX/Linux headers and constants

New headers:
- include/sys/ioccom.h: Linux UAPI ioctl encoding macros (_IO/_IOR/_IOW/_IOWR)
- include/byteswap.h: bswap_16/32/64 inline functions
- src/header/sys_statfs/: struct statfs + statfs()/fstatfs() functions
  (delegates to fstatvfs, converts to Linux struct statfs format)

New constants:
- sys_socket: MSG_NOSIGNAL, MSG_PROBE, MSG_CONFIRM, MSG_MORE, MSG_FASTOPEN
- sys_mman: MAP_GROWSDOWN, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_LOCKED, MAP_NONBLOCK
- elf/cbindgen.toml: ELFMAG and SELFMAG #defines in after_includes

These headers eliminate the need for shim patches in libwayland (MSG_NOSIGNAL),
mesa (sys/ioccom.h), qtbase (sys/statfs.h, ELFMAG), pipewire/wireplumber
(byteswap.h, MAP_* flags).
This commit is contained in:
Red Bear OS
2026-07-10 14:15:18 +03:00
parent ee3107d873
commit 32df50c8fa
8 changed files with 169 additions and 0 deletions
+2
View File
@@ -1,4 +1,6 @@
after_includes = """
#define ELFMAG "\\177ELF"
#define SELFMAG 4
#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
#define ELF32_ST_TYPE(val) ((val) & 0xf)
#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
+1
View File
@@ -110,6 +110,7 @@ pub mod sys_select;
// TODO: sys/shm.h
pub mod sys_socket;
pub mod sys_stat;
pub mod sys_statfs;
pub mod sys_statvfs;
#[allow(non_upper_case_globals)]
pub mod sys_syscall;
+5
View File
@@ -34,6 +34,11 @@ pub const MAP_TYPE: c_int = 0x000F;
pub const MAP_ANON: c_int = 0x0020;
pub const MAP_ANONYMOUS: c_int = MAP_ANON;
pub const MAP_STACK: c_int = 0x20000;
pub const MAP_GROWSDOWN: c_int = 0x0100;
pub const MAP_DENYWRITE: c_int = 0x0800;
pub const MAP_EXECUTABLE: c_int = 0x01000;
pub const MAP_LOCKED: c_int = 0x2000;
pub const MAP_NONBLOCK: c_int = 0x10000;
/// cbindgen:ignore
pub const MAP_FAILED: *mut c_void = usize::wrapping_neg(1) as *mut c_void;
+5
View File
@@ -51,6 +51,11 @@ pub const MSG_TRUNC: c_int = 32;
pub const MSG_DONTWAIT: c_int = 64;
pub const MSG_WAITALL: c_int = 256;
pub const MSG_CMSG_CLOEXEC: c_int = 0x40000000;
pub const MSG_NOSIGNAL: c_int = 0x4000;
pub const MSG_PROBE: c_int = 0x10;
pub const MSG_CONFIRM: c_int = 0x800;
pub const MSG_MORE: c_int = 0x8000;
pub const MSG_FASTOPEN: c_int = 0x20000000;
pub const IP_ADD_SOURCE_MEMBERSHIP: c_int = 70;
pub const IP_DROP_SOURCE_MEMBERSHIP: c_int = 71;
+11
View File
@@ -0,0 +1,11 @@
sys_includes = ["sys/types.h"]
include_guard = "_SYS_STATFS_H"
language = "C"
style = "tag"
usize_is_size_t = true
[export]
include = ["statfs"]
[fn]
prefix = ""
+70
View File
@@ -0,0 +1,70 @@
use crate::{
c_str::CStr,
error::ResultExt,
header::fcntl::O_PATH,
out::Out,
platform::{
Pal, Sys,
types::{c_char, c_int, c_long},
},
};
#[repr(C)]
#[derive(Default)]
pub struct statfs {
pub f_type: c_long,
pub f_bsize: c_long,
pub f_blocks: c_long,
pub f_bfree: c_long,
pub f_bavail: c_long,
pub f_files: c_long,
pub f_ffree: c_long,
pub f_fsid: [c_int; 2],
pub f_namelen: c_long,
pub f_frsize: c_long,
pub f_flags: c_long,
pub f_spare: [c_long; 4],
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn statfs(path: *const c_char, buf: *mut statfs) -> c_int {
let path = unsafe { CStr::from_ptr(path) };
let buf = unsafe { Out::nonnull(buf) };
let fd = Sys::open(path, O_PATH, 0).or_minus_one_errno();
if fd < 0 {
return -1;
}
let res = unsafe { fill_statfs(fd, buf) };
if let Ok(()) = Sys::close(fd) {}
res
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int {
let buf = unsafe { Out::nonnull(buf) };
unsafe { fill_statfs(fd, buf) }
}
unsafe fn fill_statfs(fd: c_int, mut buf: Out<statfs>) -> c_int {
let mut sv = crate::header::sys_statvfs::statvfs::default();
let sv_out = Out::from_mut(&mut sv);
let res = Sys::fstatvfs(fd, sv_out);
if res.is_err() {
return res.map(|()| 0).or_minus_one_errno();
}
buf.write(statfs {
f_type: 0xEF53,
f_bsize: sv.f_bsize as c_long,
f_blocks: sv.f_blocks as c_long,
f_bfree: sv.f_bfree as c_long,
f_bavail: sv.f_bavail as c_long,
f_files: sv.f_files as c_long,
f_ffree: sv.f_ffree as c_long,
f_fsid: [sv.f_fsid as c_int, 0],
f_namelen: sv.f_namemax as c_long,
f_frsize: sv.f_frsize as c_long,
f_flags: sv.f_flag as c_long,
f_spare: [0; 4],
});
0
}