2012-04-05 21:00:47 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-08-04 18:24:59 +00:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2014.
|
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
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2013-08-04 18:24:59 +00:00
|
|
|
#ifndef INCLUDE_SORTIX_FORK_H
|
|
|
|
#define INCLUDE_SORTIX_FORK_H
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2013-10-13 11:04:27 +00:00
|
|
|
#include <sys/cdefs.h>
|
2013-09-23 14:37:33 +00:00
|
|
|
|
2013-08-04 18:24:59 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <sortix/sigset.h>
|
|
|
|
#include <sortix/stack.h>
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2015-05-13 16:11:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2012-04-05 21:00:47 +00:00
|
|
|
|
|
|
|
/* 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-08-04 18:24:59 +00:00
|
|
|
struct tfork
|
|
|
|
{
|
2013-06-20 12:35:40 +00:00
|
|
|
#if defined(__i386__)
|
2013-08-04 18:24:59 +00:00
|
|
|
uint32_t eip;
|
|
|
|
uint32_t eax;
|
|
|
|
uint32_t ebx;
|
|
|
|
uint32_t ecx;
|
|
|
|
uint32_t edx;
|
|
|
|
uint32_t edi;
|
|
|
|
uint32_t esi;
|
|
|
|
uint32_t esp;
|
|
|
|
uint32_t ebp;
|
|
|
|
uint32_t eflags;
|
|
|
|
uint32_t fsbase;
|
|
|
|
uint32_t gsbase;
|
2013-06-20 12:35:40 +00:00
|
|
|
#elif defined(__x86_64__)
|
2013-08-04 18:24:59 +00:00
|
|
|
uint64_t rip;
|
|
|
|
uint64_t rax;
|
|
|
|
uint64_t rbx;
|
|
|
|
uint64_t rcx;
|
|
|
|
uint64_t rdx;
|
|
|
|
uint64_t rdi;
|
|
|
|
uint64_t rsi;
|
|
|
|
uint64_t rsp;
|
|
|
|
uint64_t rbp;
|
|
|
|
uint64_t r8;
|
|
|
|
uint64_t r9;
|
|
|
|
uint64_t r10;
|
|
|
|
uint64_t r11;
|
|
|
|
uint64_t r12;
|
|
|
|
uint64_t r13;
|
|
|
|
uint64_t r14;
|
|
|
|
uint64_t r15;
|
|
|
|
uint64_t rflags;
|
|
|
|
uint64_t fsbase;
|
|
|
|
uint64_t gsbase;
|
2012-04-05 21:00:47 +00:00
|
|
|
#else
|
2013-08-04 18:24:59 +00:00
|
|
|
#error "You need to add a struct tfork for your platform"
|
2012-04-05 21:00:47 +00:00
|
|
|
#endif
|
2013-08-04 18:24:59 +00:00
|
|
|
sigset_t sigmask;
|
|
|
|
stack_t altstack;
|
|
|
|
};
|
2012-04-05 21:00:47 +00:00
|
|
|
|
2015-05-13 16:11:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
2012-04-05 21:00:47 +00:00
|
|
|
|
|
|
|
#endif
|