Files
vasilito 5851974b20 feat: build system transition to release fork + archive hardening
Release fork infrastructure:
- REDBEAR_RELEASE=0.1.1 with offline enforcement (fetch/distclean/unfetch blocked)
- 195 BLAKE3-verified source archives in standard format
- Atomic provisioning via provision-release.sh (staging + .complete sentry)
- 5-phase improvement plan: restore format auto-detection, source tree
  validation (validate-source-trees.py), archive-map.json, REPO_BINARY fallback

Archive normalization:
- Removed 87 duplicate/unversioned archives from shared pool
- Regenerated all archives in consistent format with source/ + recipe.toml
- BLAKE3SUMS and manifest.json generated from stable tarball set

Patch management:
- verify-patches.sh: pre-sync dry-run report (OK/REVERSED/CONFLICT)
- 121 upstream-absorbed patches moved to absorbed/ directories
- 43 active patches verified clean against rebased sources
- Stress test: base updated to upstream HEAD, relibc reset and patched

Compilation fixes:
- relibc: Vec imports in redox-rt (proc.rs, lib.rs, sys.rs)
- relibc: unsafe from_raw_parts in mod.rs (2024 edition)
- fetch.rs: rev comparison handles short/full hash prefixes
- kibi recipe: corrected rev mismatch

New scripts: restore-sources.sh, provision-release.sh, verify-sources-archived.sh,
check-upstream-releases.sh, validate-source-trees.py, verify-patches.sh,
repair-archive-format.sh, generate-manifest.py

Documentation: AGENTS.md, README.md, local/AGENTS.md updated for release fork model
2026-05-02 01:41:17 +01:00

183 lines
5.3 KiB
Diff

--- a/src/header/semaphore/mod.rs 2026-04-25 17:07:53.742796721 +0100
+++ b/src/header/semaphore/mod.rs 2026-04-25 17:08:54.527084219 +0100
@@ -2,12 +2,24 @@
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/semaphore.h.html>.
+use core::mem::size_of;
+
use crate::{
+ c_str::CStr,
header::{
bits_timespec::timespec,
+ errno::{EEXIST, EINVAL},
+ fcntl::{O_CREAT, O_EXCL, O_RDWR},
+ sys_mman::{
+ mmap, munmap, shm_open, shm_unlink, MAP_SHARED, MAP_FAILED, PROT_READ, PROT_WRITE,
+ },
time::{CLOCK_MONOTONIC, CLOCK_REALTIME},
+ unistd::{close, ftruncate},
+ },
+ platform::{
+ ERRNO,
+ types::{c_char, c_int, c_long, c_uint, clockid_t, c_void, mode_t, off_t, size_t},
},
- platform::types::{c_char, c_int, c_long, c_uint, clockid_t},
};
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/semaphore.h.html>.
@@ -18,12 +30,17 @@
pub size: [c_char; 4],
pub align: c_long,
}
+
+/// Pointer value returned by `sem_open` on failure.
+/// cbindgen:ignore
+pub const SEM_FAILED: *mut sem_t = usize::MAX as *mut sem_t;
+
pub type RlctSempahore = crate::sync::Semaphore;
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_close.html>.
-// #[unsafe(no_mangle)]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_close(sem: *mut sem_t) -> c_int {
- todo!("named semaphores")
+ unsafe { munmap(sem.cast::<c_void>(), size_of::<sem_t>()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_destroy.html>.
@@ -50,13 +67,105 @@
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_open.html>.
-// TODO: va_list
-// #[unsafe(no_mangle)]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_open(
name: *const c_char,
- oflag: c_int, /* (va_list) value: c_uint */
+ oflag: c_int,
+ mut __valist: ...
) -> *mut sem_t {
- todo!("named semaphores")
+ // Validate name: must start with '/', no embedded '/'.
+ if name.is_null() {
+ ERRNO.set(EINVAL);
+ return SEM_FAILED;
+ }
+
+ let name_c = unsafe { CStr::from_ptr(name) };
+ let name_bytes = name_c.to_bytes();
+ if name_bytes.is_empty() || name_bytes[0] != b'/' {
+ ERRNO.set(EINVAL);
+ return SEM_FAILED;
+ }
+ if name_bytes[1..].iter().any(|&b| b == b'/') {
+ ERRNO.set(EINVAL);
+ return SEM_FAILED;
+ }
+
+ let creat = oflag & O_CREAT == O_CREAT;
+ let excl = oflag & O_EXCL == O_EXCL;
+
+ let (mode, value): (mode_t, c_uint) = if creat {
+ (
+ unsafe { __valist.arg::<mode_t>() },
+ unsafe { __valist.arg::<c_uint>() },
+ )
+ } else {
+ (0, 0)
+ };
+
+ // Open or create the shared memory backing.
+ let (fd, created) = if creat && excl {
+ // O_CREAT | O_EXCL: must create exclusively.
+ let fd = unsafe { shm_open(name, O_CREAT | O_EXCL | O_RDWR, mode) };
+ if fd < 0 {
+ return SEM_FAILED;
+ }
+ (fd, true)
+ } else if creat {
+ // O_CREAT without O_EXCL: try exclusive first, fall back to open.
+ let fd = unsafe { shm_open(name, O_CREAT | O_EXCL | O_RDWR, mode) };
+ if fd >= 0 {
+ (fd, true)
+ } else if ERRNO.get() == EEXIST {
+ let fd = unsafe { shm_open(name, O_RDWR, 0) };
+ if fd < 0 {
+ return SEM_FAILED;
+ }
+ (fd, false)
+ } else {
+ return SEM_FAILED;
+ }
+ } else {
+ // No O_CREAT: open existing.
+ let fd = unsafe { shm_open(name, O_RDWR, 0) };
+ if fd < 0 {
+ return SEM_FAILED;
+ }
+ (fd, false)
+ };
+
+ // Set size if we created the backing.
+ if created {
+ if unsafe { ftruncate(fd, size_of::<sem_t>() as off_t) } < 0 {
+ let _ = unsafe { close(fd) };
+ return SEM_FAILED;
+ }
+ }
+
+ // Map the shared memory.
+ let ptr = unsafe {
+ mmap(
+ core::ptr::null_mut(),
+ size_of::<sem_t>(),
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ fd,
+ 0,
+ )
+ };
+ let _ = unsafe { close(fd) };
+
+ if ptr == MAP_FAILED {
+ return SEM_FAILED;
+ }
+
+ let sem_ptr = ptr.cast::<sem_t>();
+
+ // Initialize the semaphore value if we created the backing.
+ if created {
+ unsafe { sem_ptr.cast::<RlctSempahore>().write(RlctSempahore::new(value)) };
+ }
+
+ sem_ptr
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_post.html>.
@@ -76,10 +185,10 @@
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_unlink.html>.
-// #[unsafe(no_mangle)]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_unlink(name: *const c_char) -> c_int {
- todo!("named semaphores")
+ unsafe { shm_unlink(name) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>.
--- a/src/header/semaphore/cbindgen.toml 2026-04-25 17:07:53.743979154 +0100
+++ b/src/header/semaphore/cbindgen.toml 2026-04-25 17:09:18.310792692 +0100
@@ -3,6 +3,9 @@
after_includes = """
#include <bits/timespec.h> // for timespec
"""
+trailer = """
+#define SEM_FAILED ((sem_t *) -1)
+"""
language = "C"
style = "Type"
no_includes = true