2012-04-05 21:00:47 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
This file is part of Sortix.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
sortix/fork.h
|
|
|
|
Declarations related to the fork family of system calls on Sortix.
|
2012-04-05 21:00:47 +00:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SORTIX_FORK_H
|
|
|
|
#define SORTIX_FORK_H
|
|
|
|
|
2013-10-13 11:04:27 +00:00
|
|
|
#include <sys/cdefs.h>
|
2013-09-23 14:37:33 +00:00
|
|
|
|
2012-04-05 21:00:47 +00:00
|
|
|
#include <sortix/x86/fork.h>
|
|
|
|
#include <sortix/x64/fork.h>
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
/* The sfork system call is much like the rfork system call found in Plan 9 and
|
|
|
|
BSD systems, however it works slightly differently and was renamed to avoid
|
|
|
|
conflicts with existing programs. In particular, it never forks an item
|
|
|
|
unless its bit is set, whereas rfork sometimes forks an item by default. If
|
|
|
|
you wish to fork certain items simply set the proper flags. Note that since
|
|
|
|
flags may be added from time to time, you should use various compound flags
|
|
|
|
defined below such as SFFORK and SFALL. It can be useful do combine these
|
2012-08-05 15:35:19 +00:00
|
|
|
compound flags with bit operations, for instance "I want traditional fork,
|
2012-04-05 21:00:47 +00:00
|
|
|
except share the working dir pointer" is sfork(SFFORK & ~SFCWD). */
|
2012-08-05 15:35:19 +00:00
|
|
|
#define SFPROC (1<<0) /* Creates child, otherwise affect current task. */
|
2012-04-05 21:00:47 +00:00
|
|
|
#define SFPID (1<<1) /* Allocates new PID. */
|
|
|
|
#define SFFD (1<<2) /* Fork file descriptor table. */
|
|
|
|
#define SFMEM (1<<3) /* Forks address space. */
|
|
|
|
#define SFCWD (1<<4) /* Forks current directory pointer. */
|
|
|
|
#define SFROOT (1<<5) /* Forks root directory pointer. */
|
|
|
|
#define SFNAME (1<<6) /* Forks namespace. */
|
|
|
|
#define SFSIG (1<<7) /* Forks signal table. */
|
|
|
|
#define SFCSIG (1<<8) /* Child will have no pending signals, like fork(2). */
|
|
|
|
|
|
|
|
/* Creates a new thread in this process. Beware that it will share the stack of
|
2012-08-05 15:35:19 +00:00
|
|
|
the parent thread and that various threading features may not have been set
|
|
|
|
up properly. You should use the standard threading API unless you know what
|
|
|
|
you are doing; remember that you can always sfork more stuff after the
|
|
|
|
standard threading API returns control to you. This is useful combined with
|
|
|
|
the tfork System call that lets you control the registers of the new task. */
|
2012-04-05 21:00:47 +00:00
|
|
|
#define SFTHREAD (SFPROC | SFCSIG)
|
|
|
|
|
|
|
|
/* Provides traditional fork(2) behavior; use this instead of the above values
|
|
|
|
if you want "as fork(2), but also fork foo", or "as fork(2), except bar". In
|
|
|
|
those cases it is better to sfork(SFFORK & ~SFFOO); or sfork(SFFORK | SFBAR);
|
|
|
|
as that would allow to add new flags to SFFORK if a new kernel feature is
|
|
|
|
added to the system that applications don't know about yet. */
|
|
|
|
#define SFFORK (SFPROC | SFPID | SFFD | SFMEM | SFCWD | SFROOT | SFCSIG)
|
|
|
|
|
|
|
|
/* This allows creating a process that is completely forked from the original
|
|
|
|
process, unlike SFFORK which does share a few things (such as the process
|
|
|
|
namespace). Note that there is a few unset high bits in this value, these
|
|
|
|
are reserved and must not be set. */
|
|
|
|
#define SFALL ((1<<20)-1)
|
|
|
|
|
2012-08-05 15:35:19 +00:00
|
|
|
/* This structure tells tfork the initial values of the registers in the new
|
|
|
|
task. It is ignored if no new task is created. sfork works by recording its
|
|
|
|
own state into such a structure and calling tfork. Note that this structure
|
|
|
|
is highly platform specific, portable code should use the standard threading
|
|
|
|
facilities combined with sfork if possible. */
|
2013-06-20 12:35:40 +00:00
|
|
|
#if defined(__i386__)
|
2012-08-05 15:35:19 +00:00
|
|
|
typedef struct tforkregs_x86 tforkregs_t;
|
2013-06-20 12:35:40 +00:00
|
|
|
#elif defined(__x86_64__)
|
2012-08-05 15:35:19 +00:00
|
|
|
typedef struct tforkregs_x64 tforkregs_t;
|
2012-04-05 21:00:47 +00:00
|
|
|
#else
|
2012-08-05 15:35:19 +00:00
|
|
|
#warning No tforkregs_cpu structure declared
|
2012-04-05 21:00:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|