[libc-commits] [libc] [libc][sys/sem] Add sys v sem headers and syscall wrapper implementation (PR #185914)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Thu Mar 12 07:47:28 PDT 2026


================
@@ -0,0 +1,86 @@
+//===-- Linux implementation of semctl ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/sem/semctl.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/sys_ipc_macros.h"
+#include "hdr/sys_sem_macros.h"
+#include "hdr/types/struct_semid_ds.h"
+#include "hdr/types/struct_seminfo.h"
+#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include <stdarg.h>
+#include <sys/syscall.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, semctl, (int semid, int semnum, int cmd, ...)) {
----------------
SchrodingerZhu wrote:

Sth like (my summary may not be exactly precise):

- IPC_RMID, GETVAL, GETPID, GETNCNT, GETZCNT do not consume a 4th user argument in our wrapper, so cmd_arg remains 0.
- SETVAL consumes an integer value from va_arg.
- IPC_SET, IPC_STAT, SEM_STAT, SEM_STAT_ANY consume a struct semid_ds *.
- GETALL, SETALL consume an unsigned short *.
- IPC_INFO, SEM_INFO consume a struct seminfo *.
- default rejects unsupported commands with EINVAL.

https://github.com/llvm/llvm-project/pull/185914


More information about the libc-commits mailing list