The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=2d555ec85a716e016be587b2a1606ca69267f870

commit 2d555ec85a716e016be587b2a1606ca69267f870
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-01-08 03:49:33 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-01-25 15:54:08 +0000

    lib/libsys, lib/libc: export pdwait
    
    Make pdwait(2) cancellable, same as all other wait*(2) syscalls wrappers.
    
    Reviewed by:    asomers, markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D54592
---
 lib/libc/include/libc_private.h  |  1 +
 lib/libc/sys/Symbol.map          |  4 ++++
 lib/libc/sys/pdwait.c            | 20 ++++++++++++++++++++
 lib/libsys/Makefile.sys          |  1 +
 lib/libsys/interposing_table.c   |  1 +
 lib/libthr/thread/thr_syscalls.c | 15 +++++++++++++++
 sys/sys/procdesc.h               |  4 ++++
 7 files changed, 46 insertions(+)

diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index db4cbc32be35..299629fce2ad 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -252,6 +252,7 @@ enum {
        INTERPOS__reserved0, /* was distribute_static_tls */
        INTERPOS_pdfork,
        INTERPOS_uexterr_gettext,
+       INTERPOS_pdwait,
        INTERPOS_MAX
 };
 
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index 32b1b0ecee05..8acffcfd714e 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -71,3 +71,7 @@ FBSD_1.6 {
 FBSD_1.7 {
        _Fork;
 };
+
+FBSD_1.9 {
+       pdwait;
+};
diff --git a/lib/libc/sys/pdwait.c b/lib/libc/sys/pdwait.c
new file mode 100644
index 000000000000..89d43b7fca2e
--- /dev/null
+++ b/lib/libc/sys/pdwait.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2026 The FreeBSD Foundation.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * This software was developed by Konstantin Belousov <[email protected]>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#include <sys/types.h>
+#include <sys/procdesc.h>
+#include "libc_private.h"
+
+#pragma weak pdwait
+int
+pdwait(int fd, int *status, int options, struct __wrusage *ru,
+    struct __siginfo *infop)
+{
+       return (INTERPOS_SYS(pdwait, fd, status, options, ru, infop));
+}
diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys
index 5f149170b974..4e70faec1167 100644
--- a/lib/libsys/Makefile.sys
+++ b/lib/libsys/Makefile.sys
@@ -73,6 +73,7 @@ INTERPOSED = \
        open \
        openat \
        pdfork \
+       pdwait \
        poll \
        ppoll \
        pselect \
diff --git a/lib/libsys/interposing_table.c b/lib/libsys/interposing_table.c
index 31cdb1511ab8..0151364f89d2 100644
--- a/lib/libsys/interposing_table.c
+++ b/lib/libsys/interposing_table.c
@@ -72,6 +72,7 @@ static interpos_func_t __libsys_interposing[INTERPOS_MAX] = {
        SLOT(fdatasync, __sys_fdatasync),
        SLOT(clock_nanosleep, __sys_clock_nanosleep),
        SLOT(pdfork, __sys_pdfork),
+       SLOT(pdwait, __sys_pdwait),
 };
 #undef SLOT
 
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index 188374a30070..bff2d0624aee 100644
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -584,6 +584,20 @@ __thr_wait6(idtype_t idtype, id_t id, int *status, int 
options,
        return (ret);
 }
 
+static pid_t
+__thr_pdwait(int fd, int *status, int options, struct __wrusage *ru,
+    siginfo_t *infop)
+{
+       struct pthread *curthread;
+       pid_t ret;
+
+       curthread = _get_curthread();
+       _thr_cancel_enter(curthread);
+       ret = __sys_pdwait(fd, status, options, ru, infop);
+       _thr_cancel_leave(curthread, ret == -1);
+       return (ret);
+}
+
 /*
  * Cancellation behavior:
  *   Thread may be canceled at start, but if the thread wrote some data,
@@ -685,6 +699,7 @@ __thr_interpose_libc(void)
        SLOT(clock_nanosleep);
        SLOT(pdfork);
        SLOT(uexterr_gettext);
+       SLOT(pdwait);
 #undef SLOT
        *(__libc_interposing_slot(
            INTERPOS__pthread_mutex_init_calloc_cb)) =
diff --git a/sys/sys/procdesc.h b/sys/sys/procdesc.h
index 6ce6c9f81de1..6a9168b04a68 100644
--- a/sys/sys/procdesc.h
+++ b/sys/sys/procdesc.h
@@ -122,10 +122,14 @@ struct rusage;
  * Process descriptor system calls.
  */
 __BEGIN_DECLS
+struct __wrusage;
+struct __siginfo;
+
 pid_t   pdfork(int *, int);
 pid_t   pdrfork(int *, int, int);
 int     pdkill(int, int);
 int     pdgetpid(int, pid_t *);
+int     pdwait(int, int *, int, struct __wrusage *, struct __siginfo *);
 __END_DECLS
 
 #endif /* _KERNEL */

Reply via email to