mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54898
41 lines
925 B
C
41 lines
925 B
C
/*-
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright 2026 The FreeBSD Foundation
|
|
*
|
|
* This software were developed by
|
|
* Konstantin Belousov <[email protected]> under sponsorship from
|
|
* the FreeBSD Foundation.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
|
|
pid_t
|
|
rfork_thread(int flags, void *stack_addr, int (*start_fn)(void *), void *arg)
|
|
{
|
|
pid_t res;
|
|
int ret;
|
|
|
|
/*
|
|
* Generic implementation cannot switch stacks. Only
|
|
* architecture-specific code knows how to do it. Require
|
|
* that caller knows that, and refuse to do operate if the
|
|
* stack was supplied.
|
|
*
|
|
* Note that implementations that do switch stack, would fault
|
|
* immediately if the passed stack is NULL. They do not need to
|
|
* specifically check for the NULL stack value.
|
|
*/
|
|
if (stack_addr != NULL) {
|
|
errno = EOPNOTSUPP;
|
|
return (-1);
|
|
}
|
|
res = rfork(flags);
|
|
if (res == 0) {
|
|
ret = start_fn(arg);
|
|
_exit(ret);
|
|
}
|
|
return (res);
|
|
}
|