sortix-mirror/libc/include/unistd.h

430 lines
12 KiB
C
Raw Normal View History

/*******************************************************************************
2011-08-05 12:25:00 +00:00
2014-01-04 21:25:42 +00:00
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
2011-08-05 12:25:00 +00:00
This file is part of the Sortix C Library.
2011-08-05 12:25:00 +00:00
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
2011-08-05 12:25:00 +00:00
The Sortix C Library 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 Lesser General Public
License for more details.
2011-08-05 12:25:00 +00:00
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
2011-08-05 12:25:00 +00:00
unistd.h
The <unistd.h> header defines miscellaneous symbolic constants and types,
and declares miscellaneous functions.
2011-08-05 12:25:00 +00:00
*******************************************************************************/
2011-08-05 12:25:00 +00:00
/* TODO: POSIX-1.2008 compliance is only partial */
#ifndef _UNISTD_H
#define _UNISTD_H 1
2011-08-05 12:25:00 +00:00
#include <sys/cdefs.h>
#include <sys/__/types.h>
2013-01-16 00:45:51 +00:00
#include <__/stdint.h>
#if defined(_SORTIX_SOURCE)
#include <stdarg.h>
2013-01-16 00:45:51 +00:00
#include <stdint.h>
#include <sortix/fork.h>
2013-05-11 23:24:42 +00:00
__BEGIN_DECLS
2013-12-27 00:44:03 +00:00
#ifndef __time_t_defined
#define __time_t_defined
typedef __time_t time_t;
#endif
2013-05-11 23:24:42 +00:00
__END_DECLS
#include <sortix/timespec.h>
#include <ioleast.h>
#endif
#include <sortix/seek.h>
2012-03-05 14:46:23 +00:00
#include <sortix/unistd.h>
2011-08-05 12:25:00 +00:00
#define _SORTIX_ALWAYS_SBRK
2011-08-05 12:25:00 +00:00
__BEGIN_DECLS
/* Currently just say we support the newest POSIX. */
/* TODO: Support the newest POSIX. */
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION 200809L
/* Currently just say we support the newest X/Open */
/* TODO: Support the newest X/Open */
#define _XOPEN_VERSION 700
/* TODO: _POSIX_*, _POSIX2_*, _XOPEN_* is missing here. */
/* TODO: _POSIX_*, _POSIX2_* is missing here. */
2013-12-27 00:44:03 +00:00
#ifndef NULL
#define __need_NULL
#include <stddef.h>
#endif
2011-08-05 12:25:00 +00:00
2013-04-16 09:44:29 +00:00
#define _CS_PATH 0
#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1
#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 2
#define _CS_POSIX_V7_ILP32_OFF32_LIBS 3
#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 4
#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 5
#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 6
#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 7
#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 8
#define _CS_POSIX_V7_LP64_OFF64_LIBS 9
#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 10
#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 11
#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 12
#define _CS_POSIX_V7_THREADS_CFLAGS 13
#define _CS_POSIX_V7_THREADS_LDFLAGS 14
#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 15
#define _CS_V7_ENV 16
#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 17 /* obsolescent */
#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 18 /* obsolescent */
#define _CS_POSIX_V6_ILP32_OFF32_LIBS 19 /* obsolescent */
#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 20 /* obsolescent */
#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 21 /* obsolescent */
#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 22 /* obsolescent */
#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 23 /* obsolescent */
#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 24 /* obsolescent */
#define _CS_POSIX_V6_LP64_OFF64_LIBS 25 /* obsolescent */
#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 26 /* obsolescent */
#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 27 /* obsolescent */
#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 28 /* obsolescent */
#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 29 /* obsolescent */
#define _CS_V6_ENV 30 /* obsolescent */
2011-08-05 12:25:00 +00:00
/* TODO: F_* is missing here. */
2013-03-22 12:58:43 +00:00
#define _PC_2_SYMLINKS 1
#define _PC_ALLOC_SIZE_MIN 2
#define _PC_ASYNC_IO 3
#define _PC_CHOWN_RESTRICTED 4
#define _PC_FILESIZEBITS 5
#define _PC_LINK_MAX 6
#define _PC_MAX_CANON 7
#define _PC_MAX_INPUT 8
#define _PC_NAME_MAX 9
#define _PC_NO_TRUNC 10
#define _PC_PATH_MAX 11
#define _PC_PIPE_BUF 12
#define _PC_PRIO_IO 13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE 15
#define _PC_REC_MIN_XFER_SIZE 16
#define _PC_REC_XFER_ALIGN 17
#define _PC_SYMLINK_MAX 18
#define _PC_SYNC_IO 19
#define _PC_TIMESTAMP_RESOLUTION 20
#define _PC_VDISABLE 21
2011-08-05 12:25:00 +00:00
2013-04-16 08:11:15 +00:00
#define _SC_AIO_LISTIO_MAX 0
#define _SC_AIO_MAX 1
#define _SC_AIO_PRIO_DELTA_MAX 2
#define _SC_ARG_MAX 3
#define _SC_ATEXIT_MAX 4
#define _SC_BC_BASE_MAX 5
#define _SC_BC_DIM_MAX 6
#define _SC_BC_SCALE_MAX 7
#define _SC_BC_STRING_MAX 8
#define _SC_CHILD_MAX 9
#define _SC_CLK_TCK 10
#define _SC_COLL_WEIGHTS_MAX 11
#define _SC_DELAYTIMER_MAX 12
#define _SC_EXPR_NEST_MAX 13
#define _SC_HOST_NAME_MAX 14
#define _SC_IOV_MAX 15
#define _SC_LINE_MAX 16
#define _SC_LOGIN_NAME_MAX 17
#define _SC_NGROUPS_MAX 18
#define _SC_GETGR_R_SIZE_MAX 19
#define _SC_GETPW_R_SIZE_MAX 20
#define _SC_MQ_OPEN_MAX 21
#define _SC_MQ_PRIO_MAX 22
#define _SC_OPEN_MAX 23
#define _SC_ADVISORY_INFO 24
#define _SC_BARRIERS 25
#define _SC_ASYNCHRONOUS_IO 26
#define _SC_CLOCK_SELECTION 27
#define _SC_CPUTIME 28
#define _SC_FSYNC 29
#define _SC_IPV6 30
#define _SC_JOB_CONTROL 31
#define _SC_MAPPED_FILES 32
#define _SC_MEMLOCK 33
#define _SC_MEMLOCK_RANGE 34
#define _SC_MEMORY_PROTECTION 35
#define _SC_MESSAGE_PASSING 36
#define _SC_MONOTONIC_CLOCK 37
#define _SC_PRIORITIZED_IO 38
#define _SC_PRIORITY_SCHEDULING 39
#define _SC_RAW_SOCKETS 40
#define _SC_READER_WRITER_LOCKS 41
#define _SC_REALTIME_SIGNALS 42
#define _SC_REGEXP 43
#define _SC_SAVED_IDS 44
#define _SC_SEMAPHORES 45
#define _SC_SHARED_MEMORY_OBJECTS 46
#define _SC_SHELL 47
#define _SC_SPAWN 48
#define _SC_SPIN_LOCKS 49
#define _SC_SPORADIC_SERVER 50
#define _SC_SS_REPL_MAX 51
#define _SC_SYNCHRONIZED_IO 52
#define _SC_THREAD_ATTR_STACKADDR 53
#define _SC_THREAD_ATTR_STACKSIZE 54
#define _SC_THREAD_CPUTIME 55
#define _SC_THREAD_PRIO_INHERIT 56
#define _SC_THREAD_PRIO_PROTECT 57
#define _SC_THREAD_PRIORITY_SCHEDULING 58
#define _SC_THREAD_PROCESS_SHARED 59
#define _SC_THREAD_ROBUST_PRIO_INHERIT 60
#define _SC_THREAD_ROBUST_PRIO_PROTECT 61
#define _SC_THREAD_SAFE_FUNCTIONS 62
#define _SC_THREAD_SPORADIC_SERVER 63
#define _SC_THREADS 64
#define _SC_TIMEOUTS 65
#define _SC_TIMERS 66
#define _SC_TRACE 67
#define _SC_TRACE_EVENT_FILTER 68
#define _SC_TRACE_EVENT_NAME_MAX 69
#define _SC_TRACE_INHERIT 70
#define _SC_TRACE_LOG 71
#define _SC_TRACE_NAME_MAX 72
#define _SC_TRACE_SYS_MAX 73
#define _SC_TRACE_USER_EVENT_MAX 74
#define _SC_TYPED_MEMORY_OBJECTS 75
#define _SC_VERSION 76
#define _SC_V7_ILP32_OFF32 77
#define _SC_V7_ILP32_OFFBIG 78
#define _SC_V7_LP64_OFF64 79
#define _SC_V7_LPBIG_OFFBIG 80
#define _SC_V6_ILP32_OFF32 81 /* obsolescent */
#define _SC_V6_ILP32_OFFBIG 82 /* obsolescent */
#define _SC_V6_LP64_OFF64 83 /* obsolescent */
#define _SC_V6_LPBIG_OFFBIG 84 /* obsolescent */
#define _SC_2_C_BIND 85
#define _SC_2_C_DEV 86
#define _SC_2_CHAR_TERM 87
#define _SC_2_FORT_DEV 88
#define _SC_2_FORT_RUN 89
#define _SC_2_LOCALEDEF 90
#define _SC_2_PBS 91
#define _SC_2_PBS_ACCOUNTING 92
#define _SC_2_PBS_CHECKPOINT 93
#define _SC_2_PBS_LOCATE 94
#define _SC_2_PBS_MESSAGE 95
#define _SC_2_PBS_TRACK 96
#define _SC_2_SW_DEV 97
#define _SC_2_UPE 98
#define _SC_2_VERSION 99
#define _SC_PAGE_SIZE 100
#define _SC_PAGESIZE 111
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 112
#define _SC_THREAD_KEYS_MAX 113
#define _SC_THREAD_STACK_MIN 114
#define _SC_THREAD_THREADS_MAX 115
#define _SC_RE_DUP_MAX 116
#define _SC_RTSIG_MAX 117
#define _SC_SEM_NSEMS_MAX 118
#define _SC_SEM_VALUE_MAX 119
#define _SC_SIGQUEUE_MAX 120
#define _SC_STREAM_MAX 121
#define _SC_SYMLOOP_MAX 122
#define _SC_TIMER_MAX 123
#define _SC_TTY_NAME_MAX 124
#define _SC_TZNAME_MAX 125
#define _SC_XOPEN_CRYPT 126
#define _SC_XOPEN_ENH_I18N 127
#define _SC_XOPEN_REALTIME 128
#define _SC_XOPEN_REALTIME_THREADS 129
#define _SC_XOPEN_SHM 130
#define _SC_XOPEN_STREAMS 131
#define _SC_XOPEN_UNIX 132
#define _SC_XOPEN_UUCP 133
#define _SC_XOPEN_VERSION 134
2011-08-05 12:25:00 +00:00
2013-04-16 08:19:25 +00:00
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
2011-08-05 12:25:00 +00:00
/* TODO: _POSIX_VDISABLE is missing here. */
2013-12-27 00:44:03 +00:00
#ifndef __size_t_defined
#define __size_t_defined
#define __need_size_t
#include <stddef.h>
#endif
#ifndef __ssize_t_defined
#define __ssize_t_defined
typedef __ssize_t ssize_t;
#endif
#ifndef __uid_t_defined
#define __uid_t_defined
typedef __uid_t uid_t;
#endif
#ifndef __gid_t_defined
#define __gid_t_defined
typedef __gid_t gid_t;
#endif
#ifndef __off_t_defined
#define __off_t_defined
typedef __off_t off_t;
#endif
#ifndef __pid_t_defined
#define __pid_t_defined
typedef __pid_t pid_t;
#endif
#ifndef __useconds_t_defined
#define __useconds_t_defined
typedef __useconds_t useconds_t;
#endif
2011-08-05 12:25:00 +00:00
#if defined(_WANT_ENVIRON)
extern char** environ;
#endif
2012-09-28 22:53:50 +00:00
/* TODO: These are not implemented in sortix libc yet. */
#if 0
2011-08-05 12:25:00 +00:00
char* crypt(const char*, const char*);
char* ctermid(char*);
void encrypt(char [64], int);
int fdatasync(int);
int fexecve(int, char* const [], char* const []);
long fpathconf(int, int);
int getgroups(int, gid_t []);
long gethostid(void);
2013-07-26 15:22:57 +00:00
2011-08-05 12:25:00 +00:00
pid_t getpgrp(void);
pid_t getsid(pid_t);
int lockf(int, int, off_t);
int nice(int);
int pause(void);
int setregid(gid_t, gid_t);
int setreuid(uid_t, uid_t);
pid_t setsid(void);
void swab(const void* __restrict, void* __restrict, ssize_t);
2011-08-05 12:25:00 +00:00
void sync(void);
#endif
2012-03-05 14:46:23 +00:00
int access(const char*, int);
2013-05-11 23:24:42 +00:00
unsigned alarm(unsigned);
int chdir(const char*);
2012-10-23 18:02:33 +00:00
int chown(const char*, uid_t, gid_t);
int chroot(const char*);
int close(int);
2013-04-16 09:44:29 +00:00
size_t confstr(int, char*, size_t);
2013-06-27 18:47:24 +00:00
int dup2(int, int);
2013-09-23 18:41:31 +00:00
int dup3(int, int, int);
2011-11-17 19:34:04 +00:00
int dup(int);
void _exit(int) __attribute__ ((noreturn));
int execl(const char*, const char*, ...);
int execle(const char*, const char*, ...);
int execlp(const char*, const char*, ...);
int execv(const char*, char* const []);
int execve(const char*, char* const [], char* const []);
int execvp(const char*, char* const []);
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
2011-09-21 18:52:29 +00:00
pid_t fork(void);
2012-10-23 21:55:33 +00:00
int faccessat(int, const char*, int, int);
2012-10-24 11:06:12 +00:00
int fchdir(int);
2013-05-29 12:03:53 +00:00
int fchdirat(int, const char*);
2012-10-24 17:52:28 +00:00
int fchown(int, uid_t, gid_t);
2012-10-24 17:43:11 +00:00
int fchownat(int, const char*, uid_t, gid_t, int);
int fchroot(int);
int fchrootat(int, const char*);
2013-03-20 12:16:12 +00:00
int fsync(int);
int ftruncate(int, off_t);
char* getcwd(char*, size_t);
char* get_current_dir_name(void);
2013-01-13 01:37:14 +00:00
gid_t getegid(void);
uid_t geteuid(void);
2013-04-12 22:42:13 +00:00
int gethostname(char*, size_t);
2013-04-15 22:08:33 +00:00
char* getlogin(void);
int getlogin_r(char*, size_t);
2013-06-11 23:02:01 +00:00
pid_t getpgid(pid_t);
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
2011-09-21 18:52:29 +00:00
pid_t getpid(void);
pid_t getppid(void);
2013-01-13 01:37:14 +00:00
uid_t getuid(void);
gid_t getgid(void);
int isatty(int);
2013-01-14 21:58:34 +00:00
int lchown(const char*, uid_t, gid_t);
2012-10-23 18:09:43 +00:00
int link(const char*, const char*);
2012-10-25 13:43:53 +00:00
int linkat(int, const char*, int, const char*, int);
2011-12-26 22:12:12 +00:00
off_t lseek(int, off_t, int);
2013-03-22 12:58:43 +00:00
long pathconf(const char*, int);
2011-11-16 07:37:29 +00:00
int pipe(int [2]);
2014-01-15 18:46:36 +00:00
int pipe2(int [2], int);
ssize_t pread(int, void*, size_t, off_t);
ssize_t pwrite(int, const void*, size_t, off_t);
ssize_t readlink(const char* __restrict, char* __restrict, size_t);
ssize_t readlinkat(int, const char* __restrict, char* __restrict, size_t);
2011-11-16 07:37:29 +00:00
ssize_t read(int, void*, size_t);
2012-01-14 15:25:28 +00:00
int rmdir(const char*);
2013-01-13 01:37:14 +00:00
int setegid(gid_t);
int seteuid(uid_t);
int setgid(gid_t);
2013-06-11 23:02:01 +00:00
int setpgid(pid_t, pid_t);
2013-01-13 01:37:14 +00:00
int setuid(uid_t);
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
2011-09-21 18:52:29 +00:00
unsigned sleep(unsigned);
2013-11-21 19:27:34 +00:00
int symlink(const char*, const char*);
int symlinkat(const char*, int, const char*);
2013-04-16 08:11:15 +00:00
long sysconf(int);
2013-06-12 00:18:07 +00:00
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
int truncate(const char*, off_t);
int truncateat(int dirfd, const char*, off_t);
2013-03-23 22:58:20 +00:00
char* ttyname(int);
2014-01-04 21:25:42 +00:00
int ttyname_r(int, char*, size_t);
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
2011-09-21 18:52:29 +00:00
int usleep(useconds_t useconds);
2012-10-23 11:50:33 +00:00
int unlinkat(int, const char*, int);
2011-11-21 17:49:55 +00:00
int unlink(const char*);
2011-11-16 07:37:29 +00:00
ssize_t write(int, const void*, size_t);
#if defined(_SORTIX_SOURCE)
2013-05-11 23:24:42 +00:00
int alarmns(const struct timespec* delay, struct timespec* odelay);
int execvpe(const char*, char* const [], char* const []);
size_t getpagesize(void);
int memstat(size_t* memused, size_t* memtotal);
2013-06-01 11:24:27 +00:00
int mkpartition(int fd, off_t start, off_t length);
pid_t sfork(int flags);
pid_t tfork(int flags, tforkregs_t* regs);
2012-03-24 14:34:30 +00:00
size_t writeall(int fd, const void* buf, size_t count);
size_t writeleast(int fd, const void* buf, size_t least, size_t max);
#endif
#if defined(_SORTIX_SOURCE) || defined(_SORTIX_ALWAYS_SBRK)
2013-01-16 00:45:51 +00:00
void* sbrk(__intptr_t increment);
2011-11-24 09:26:36 +00:00
#endif
Implemented the fork() system call and what it needed to work properly. This commit got completely out of control. Added the fork(), getpid(), getppid(), sleep(), usleep() system calls, and aliases in the Maxsi:: namespace. Fixed a bug where zero-byte allocation would fail. Worked on the DescriptorTable class which now works and can fork. Got rid of some massive print-registers statements and replaced them with the portable InterruptRegisters::LogRegisters() function. Removed the SysExecuteOld function and replaced it with Process::Execute(). Rewrote the boot sequence in kernel.cpp such that it now loads the system idle process 'idle' as PID 0, and the initization process 'init' as PID 1. Rewrote the SIGINT hack. Processes now maintain a family-tree structure and keep track of their threads. PIDs are now allocated using a simple hack. Virtual memory per-process can now be allocated using a simple hack. Processes can now be forked. Fixed the Process::Execute function such that it now resets the stack pointer to where the stack actually is - not just a magic value. Removed the old and ugly Process::_endcodesection hack. Rewrote the scheduler into a much cleaner and faster version. Debug code is now moved to designated functions. The noop kernel-thread has been replaced by a simple user-space infinite-loop program 'idle'. The Thread class has been seperated from the Scheduler except in Scheduler- related code. Thread::{Save,Load}Registers has been improved and has been moved to $(CPU)/thread.cpp. Threads can now be forked. A new CreateThread function creates threads properly and portably. Added a MicrosecondsSinceBoot() function. Fixed a crucial bug in MemoryManagement::Fork(). Added an 'idle' user-space program that is a noop infinite loop, which is used by the scheduler when there is nothing to do. Rewrote the 'init' program such that it now forks off a shell, instead of becoming the shell. Added the $$ (current PID) and $PPID (parent PPID) variables to the shell.
2011-09-21 18:52:29 +00:00
2013-07-26 15:22:57 +00:00
/* For compatibility with POSIX, declare getopt(3) here. */
#if !defined(_SORTIX_SOURCE)
/* These declarations are repeated in <getopt.h>. */
#ifndef __getopt_unistd_shared_declared
#define __getopt_unistd_shared_declared
extern char* optarg;
extern int opterr;
extern int optind;
extern int optopt;
int getopt(int, char* const*, const char*);
#endif
#endif
2011-08-05 12:25:00 +00:00
__END_DECLS
#endif