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