[libc-commits] [libc] [libc] Implement CPU_ALLOC and CPU_FREE (PR #202349)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Thu Jun 11 05:56:13 PDT 2026


================
@@ -0,0 +1,32 @@
+//===-- Implementation of sched_cpualloc ----------------------------------===//
+//
+// 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/sched/sched_cpualloc.h"
+#include "hdr/errno_macros.h"
+#include "hdr/sched_macros.h"
+#include "hdr/stdint_proxy.h"
+#include "hdr/types/cpu_set_t.h"
+#include "src/__support/CPP/new.h"
+#include "src/__support/alloc-checker.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(cpu_set_t *, __sched_cpualloc, (int count)) {
----------------
labath wrote:

size_t sounds much better. Let's follow the implementation since this API is their invention anyway.

I also spent probably longer than I should on trying to fix the CPU_ALLOC_SIZE overflow on values close to SIZE_MAX, but I didn't find anything better than what we have now. A non-overflowing way of computing the result requires evaluating the macro argument more than once. That can be avoided with a statement expression, but then the macro cannot be used at the top level (e.g. to initialize a global variable). And a static inline constexpr function is not compatible with C (plus we also ban static inline functions).

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


More information about the libc-commits mailing list