Skip to content

feat(ipc/sem): add semaphore support for dragonOS - #2172

Draft
mistcoversmyeyes wants to merge 3 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/ipc-sem-2142
Draft

feat(ipc/sem): add semaphore support for dragonOS#2172
mistcoversmyeyes wants to merge 3 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/ipc-sem-2142

Conversation

@mistcoversmyeyes

@mistcoversmyeyes mistcoversmyeyes commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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.
@github-actions github-actions Bot added the enhancement New feature or request label Aug 8, 2026
Comment on lines +17 to +30
/// # SYS_SEMOP 系统调用:原子执行一组信号量操作(无限等待)
///
/// 与 SYS_SEMTIMEDOP 共享实现,timeout 为 NULL。
///
/// ## 参数
///
/// - `semid`: 信号量集合 id
/// - `sops`: 用户态 sembuf 数组指针
/// - `nsops`: 操作数
///
/// ## 返回值
///
/// 成功:0
/// 失败:错误码

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use English

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants