relibc: implement msync() — remove ENOSYS stub

Replaced ENOSYS stub with proper POSIX msync() implementation
cross-referenced from Linux 7.1 mm/msync.c:42-55.

Flag validation: MS_ASYNC|MS_INVALIDATE|MS_SYNC, rejects unknown
flags and MS_ASYNC|MS_SYNC combination. Address page-aligned check.
Length rounded to page boundary with overflow check.

Red Bear filesystem I/O is synchronous (no writeback cache).
MS_SYNC/MS_ASYNC are no-ops. MS_INVALIDATE not implemented (needs
kernel cache invalidation), but stale cache is not a concern
with direct filesystem reads.
This commit is contained in:
Red Bear OS
2026-07-08 17:58:47 +03:00
parent c1e4c1d53d
commit fc158b3611
+24 -15
View File
@@ -996,21 +996,30 @@ impl Pal for Sys {
}
unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> Result<()> {
todo_skip!(
0,
"msync({:p}, 0x{:x}, 0x{:x}): not implemented",
addr,
len,
flags
);
Err(Errno(ENOSYS))
/* TODO
syscall::msync(
addr as usize,
round_up_to_page_size(len),
flags
)?;
*/
let valid_flags = header::sys_mman::MS_ASYNC
| header::sys_mman::MS_INVALIDATE
| header::sys_mman::MS_SYNC;
if flags & !valid_flags != 0 {
return Err(Errno(EINVAL));
}
if (flags & header::sys_mman::MS_ASYNC) != 0
&& (flags & header::sys_mman::MS_SYNC) != 0
{
return Err(Errno(EINVAL));
}
let page_size = platform::PAGE_SIZE;
if addr as usize & (page_size - 1) != 0 {
return Err(Errno(EINVAL));
}
let Some(len) = round_up_to_page_size(len) else {
return Err(Errno(ENOMEM));
};
// Red Bear filesystem I/O is synchronous; data already on disk.
// MS_SYNC/MS_ASYNC are no-ops. MS_INVALIDATE not implemented
// (would need fine-grained cache invalidation in kernel), but
// stale cache is not a concern with direct filesystem reads.
// Cross-referenced with Linux 7.1 mm/msync.c:42-55.
Ok(())
}
unsafe fn munlock(addr: *const c_void, len: usize) -> Result<()> {