feat(ipc/sem): add semaphore support for dragonOS - #2172
Draft
mistcoversmyeyes wants to merge 3 commits into
Draft
feat(ipc/sem): add semaphore support for dragonOS#2172mistcoversmyeyes wants to merge 3 commits into
mistcoversmyeyes wants to merge 3 commits into
Conversation
Move PosixIpcPerm and the permission checks (ipc_permission, check_control_permission, check_lock_permission, uid/gid mapping) out of shm.rs into a new ipc_perm.rs, exposed through the IpcPermView trait. Shm keeps its KernIpcPerm (which mixes state bits into mode) and only adapts to the shared helpers; observable behavior is unchanged. Prepares the shared permission machinery for the SysV semaphore implementation.
Implement semget/semctl/semop/semtimedop for x86_64, tracking Linux 6.6 ipc/sem.c observable behavior: - SemManager with IpcIdAllocator, per-namespace set table, and semmns accounting (SEMMNI/SEMMSL/SEMOPM/SEMVMX limits) - Atomic multi-op requests: full feasibility scan then apply; a blocked op leaves no partial modification - Blocking with per-set waiter queue (Increase/Zero classes), timeout via Timer, signal interruption (EINTR), and EIDRM on removal - semctl covers IPC_STAT/SET/RMID/INFO, GETVAL/PID/NCNT/ZCNT/ALL, SETVAL/SETALL, SEM_STAT/SEM_STAT_ANY/SEM_INFO with the x86_64 UAPI command values and the 104-byte semid64_ds layout (otime/ctime high fields) - SEM_UNDO is explicitly rejected with ENOSYS Wake-up uses broadcast-and-recheck instead of Linux's exact queue scan: correctness-equivalent under the manager lock, at the cost of spurious wakeups.
35 cases covering creation/lookup semantics, all semctl commands, atomic multi-op rollback, blocking wakeup (increment and wait-for-zero), IPC_NOWAIT, semtimedop timeout, signal interruption, EIDRM on removal, invalid arguments, and multi-process concurrency.
fslongjin
reviewed
Aug 9, 2026
Comment on lines
+17
to
+30
| /// # SYS_SEMOP 系统调用:原子执行一组信号量操作(无限等待) | ||
| /// | ||
| /// 与 SYS_SEMTIMEDOP 共享实现,timeout 为 NULL。 | ||
| /// | ||
| /// ## 参数 | ||
| /// | ||
| /// - `semid`: 信号量集合 id | ||
| /// - `sops`: 用户态 sembuf 数组指针 | ||
| /// - `nsops`: 操作数 | ||
| /// | ||
| /// ## 返回值 | ||
| /// | ||
| /// 成功:0 | ||
| /// 失败:错误码 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to