xref: /freebsd/lib/libsys/pdrfork_thread_gen.c (revision c1be185e3fb9afd6743683a8f5a43b9c364ab529)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright 2026 The FreeBSD Foundation
5  *
6  * This software were developed by
7  * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
8  * the FreeBSD Foundation.
9  */
10 
11 #include <sys/types.h>
12 #include <sys/procdesc.h>
13 #include <errno.h>
14 #include <unistd.h>
15 
16 pid_t
pdrfork_thread(int * fdp,int pdflags,int rfflags,void * stack_addr,int (* start_fn)(void *),void * arg)17 pdrfork_thread(int *fdp, int pdflags, int rfflags, void *stack_addr,
18     int (*start_fn)(void *), void *arg)
19 {
20 	pid_t res;
21 	int ret;
22 
23 	/* See comment in rfork_thread_gen.c. */
24 	if (stack_addr != NULL) {
25 		errno = EOPNOTSUPP;
26 		return (-1);
27 	}
28 	res = pdrfork(fdp, pdflags, rfflags);
29 	if (res == 0) {
30 		ret = start_fn(arg);
31 		_exit(ret);
32 	}
33 	return (res);
34 }
35