[RFC PATCH 0/2] Linux: Add futex_waitv syscall wrapper

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Aug 20 17:41:45 GMT 2026



On 18/08/26 14:57, Adhemerval Zanella Netto wrote:
> 
> 
> On 14/08/26 15:36, André Almeida wrote:
>> Hi folks,
>>
>> Based on a talk on last LPC by Carlos O'Donell[1], I'm sending this patch as a
>> starting point to add the futex_waitv() syscall wrapper. 
>>
>> I tried to base myself on the work done for others wrappers, but I see that
>> there are missing details in my implementation, so I'm seeking guidance on how
>> to approach this.
>>
>
> 
> I will try to create POC so we can check if it makes sense.
I create a POC on personal branch for a possible futex interface [1]. Some design
notes:

* Only the well-defined subset of futex(2) is exposed: wait, timed wait, wake,
  value-checked requeue, and futex_waitv. The racy unchecked FUTEX_REQUEUE, the
  removed FUTEX_FD, the error-prone FUTEX_WAKE_OP, bitset matching, and the PI
  operations are deliberately not exposed.

* Survey of real futex users (libgomp, libitm, libstdc++ C++11/C++20 tiers, libgo,
  libc++, OpenMP runtime, scudo, sanitizers) shows every usage in the wild is
  expressible with this set. The only caller-side adaptation anywhere is
  relative→absolute timeout conversion (libgo, libc++).

* For the futex_* interfaces I also added a 32-bit interface (which I suggested
  against). It seems that libstc++ does not use _TIME_BITS and issues the syscall
  directly (and it always use the 32 bit time_t futex one, which is different
  issue). It makes a possible integration easier and it also seems expected
  to follow suit other syscall that still have 32-bit time_t support.

* futex_waitv is only provided for 64-bit time_t.

* All of them uses the default -1/errno for error reporting, instead of the
  pthread like way I suggested. With the only exception of libgo from gcc, all
  other futexes usage are through 'syscall' and they handle errors through the
  usual errno mechanism.

* Flags follow the kernel convention: zero means process-shared, FUTEX_PRIVATE_FLAG 
  selects the private fast path. So the same value works across all five functions,
  including futex_waitv's per-waiter FUTEX2_PRIVATE.

* futex_timedwait takes an absolute timeout with an explicit clockid, implemented
  with FUTEX_WAIT_BITSET/FUTEX_BITSET_MATCH_ANY to avoid the relative-only
  CLOCK_MONOTONIC quirk of FUTEX_WAIT. Pre-epoch timeouts are reported as ETIMEDOUT
  instead of the kernel's EINVAL (as we do for other syscalls).

* The exported FUTEX2_* constants cover only what the syscall accepts today 
  (FUTEX2_SIZE_U32, FUTEX2_PRIVATE, FUTEX2_NUMA, FUTEX2_MPOL, FUTEX_NO_NODE). The
  unimplemented sizes are omitted.

[1] https://sourceware.org/git?p=glibc.git;a=shortlog;h=refs/heads/azanella/futex-wrappers


More information about the Libc-alpha mailing list