1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/libc/include/unistd.h

578 lines
19 KiB
C
Raw Normal View History

/*
* Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* unistd.h
* Standard symbolic constants and types.
*/
2011-08-05 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
#ifndef INCLUDE_UNISTD_H
#define INCLUDE_UNISTD_H
2011-08-05 08:25:00 -04:00
#include <sys/cdefs.h>
#include <sys/__/types.h>
2013-01-15 19:45:51 -05:00
#include <__/stdint.h>
2014-04-05 18:16:59 -04:00
#include <sortix/seek.h>
#include <sortix/unistd.h>
#if __USE_SORTIX
2013-08-31 13:35:17 -04:00
#include <sortix/exit.h>
#include <sortix/fork.h>
2013-05-11 19:24:42 -04:00
#include <sortix/timespec.h>
#endif
2011-08-05 08:25:00 -04:00
2015-05-13 12:11:02 -04:00
#ifdef __cplusplus
extern "C" {
#endif
2011-08-05 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
/* If a POSIX revision was already decided by feature macros. */
#if __USE_POSIX
#define _POSIX_VERSION __USE_POSIX /* C bindings */
#define _POSIX2_VERSION __USE_POSIX /* Shell utilities. */
/* The native API is based on POSIX 2008. */
#elif __USE_SORTIX
#define _POSIX_VERSION 200809L /* C bindings */
#define _POSIX2_VERSION 200809L /* Shell utilities. */
/* That's odd. This is a POSIX header, but the POSIX API is not visible. The
best option is probably to just say we are the 1990 POSIX standard, since it
is not protected by feature macros in this header. */
#else
#define _POSIX_VERSION 199009L /* C bindings */
#define _POSIX2_VERSION 199209L /* Shell utilities. */
#endif
2011-08-05 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
/* If an X/OPEN revision was already decided by feature macros.
TODO: Sortix refuses to implement stupid parts of the POSIX; the XSI option
is usually a great clue something is stupid. */
#if 600 < __USE_XOPEN
#define _XOPEN_VERSION __USE_XOPEN
#elif 500 <= __USE_XOPEN
#define _XOPEN_VERSION 500
#else
#define _XOPEN_VERSION 4
#endif
2011-08-05 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
/* #define _POSIX_ADVISORY_INFO 200809L
TODO: Uncomment when posix_fadvise(), posix_fallocate(), posix_madvise(),
posix_memalign() has been added. */
#define _POSIX_ASYNCHRONOUS_IO 200809L
#define _POSIX_BARRIERS 200809L
/* TODO: _POSIX_CHOWN_RESTRICTED - Decide when security policies are implemented. */
#define _POSIX_CLOCK_SELECTION 200809L
#define _POSIX_CPUTIME 200809L
#define _POSIX_FSYNC 200809L
#define _POSIX_IPV6 200809L
#define _POSIX_JOB_CONTROL
/*TODO: _POSIX_MEMLOCK - Research what this is. */
/*TODO: _POSIX_MEMLOCK_RANGE - Research what this is. */
#define _POSIX_MEMORY_PROTECTION 200809L
/*TODO: _POSIX_MESSAGE_PASSING - Research what this is. */
#define _POSIX_MONOTONIC_CLOCK 200809L
#define _POSIX_NO_TRUNC 1
/*TODO: _POSIX_PRIORITIZED_IO - Research what this is. */
/*TODO: _POSIX_PRIORITY_SCHEDULING - Research what this is. */
/*TODO: _POSIX_RAW_SOCKETS - Research what this is. */
#define _POSIX_READER_WRITER_LOCKS 200809L
#define _POSIX_REALTIME_SIGNALS 200809L
/* #define _POSIX_REGEXP 1
TODO: Uncomment when regular expressions are implemented. */
/* #define _POSIX_SAVED_IDS 1
TODO: Uncomment when saved ids are implemented. I forgot if they already are. */
2014-08-02 11:33:14 -04:00
#define _POSIX_SEMAPHORES 200809L
2014-04-05 18:16:59 -04:00
/*TODO: _POSIX_SHARED_MEMORY_OBJECTS - Research what this is. */
#define _POSIX_SHELL 1
/*TODO: _POSIX_SPAWN - Research what this is. */
#define _POSIX_SPIN_LOCKS 200809L
/*TODO: _POSIX_SPORADIC_SERVER - Research what this is. */
/*TODO: _POSIX_SYNCHRONIZED_IO - Research what this is. */
/*TODO: _POSIX_THREAD_ATTR_STACKADDR - Research what this is. */
/*TODO: _POSIX_THREAD_ATTR_STACKSIZE - Research what this is. */
2014-04-05 18:16:59 -04:00
#define _POSIX_THREAD_CPUTIME 200809L
/*TODO: _POSIX_THREAD_PRIO_INHERIT - Research what this is. */
/*TODO: _POSIX_THREAD_PRIO_PROTECT - Research what this is. */
/*TODO: _POSIX_THREAD_PRIORITY_SCHEDULING - Research what this is. */
/*TODO: _POSIX_THREAD_PROCESS_SHARED - Research what this is. */
/*TODO: _POSIX_THREAD_ROBUST_PRIO_INHERIT - Research what this is. */
/*TODO: _POSIX_THREAD_ROBUST_PRIO_PROTECT - Research what this is. */
2014-04-05 18:16:59 -04:00
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is. */
2014-04-05 18:16:59 -04:00
#define _POSIX_THREADS 200809L
#define _POSIX_TIMEOUTS 200809L
#define _POSIX_TIMERS 200809L
/* TODO: _POSIX_TRACE (Obsolescent) - Research what this is. */
/* TODO: _POSIX_TRACE_EVENT_FILTER (Obsolescent) - Research what this is. */
/* TODO: _POSIX_TRACE_INHERIT (Obsolescent) - Research what this is. */
/* TODO: _POSIX_TRACE_LOG (Obsolescent) - Research what this is. */
/* TODO: TYPED_MEMORY_OBJECTS - Research what this is. */
/* TODO: _POSIX_V6_ILP32_OFF32 (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V6_ILP32_OFFBIG (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V6_LP64_OFF64 (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V6_LPBIG_OFFBIG (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V7_ILP32_OFF32 - Research what this is. */
/* TODO: _POSIX_V7_ILP32_OFFBIG - Research what this is. */
/* TODO: _POSIX_V7_LP64_OFF64 - Research what this is. */
/* TODO: _POSIX_V7_LPBIG_OFFBIG - Research what this is. */
#define _POSIX2_C_BIND _POSIX2_VERSION
#define _POSIX2_C_DEV _POSIX2_VERSION
#define _POSIX2_CHAR_TERM 1
/* TODO: _POSIX2_FORT_RUN - When fortran becomes supported. */
/* #define _POSIX2_LOCALEDEF __POSIX2_THIS_VERSION
TODO: Uncomment when locales are implemented. */
/* TODO: _POSIX2_PBS (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_PBS_ACCOUNTING (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_PBS_CHECKPOINT (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_PBS_LOCATE (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_PBS_MESSAGE (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_PBS_TRACK (Obsolescent) - Research what this is. */
/* TODO: _POSIX2_SW_DEV - Research what this is. (Define to _POSIX2_VERSION) */
/* #define _POSIX2_UPE 200809L
TODO: Uncomment when bg, ex, fc, fg, jobs, more, talk, vi are implemented. */
/* TODO: _XOPEN_CRYPT - Research what this is. */
#define _XOPEN_ENH_I18N 1
#define _XOPEN_REALTIME 1
#define _XOPEN_REALTIME 1
/* TODO: _XOPEN_STREAMS (Obsolescent) - Probably don't want to support this. */
/* TODO: _XOPEN_UNIX - Decide whether we actually support this (probably not),
but also whether this header should lie. */
/* TODO: _XOPEN_UUCP - Research what this is. */
/* TODO: _POSIX_ASYNC_IO - Research what exactly this is. */
/* TODO: _POSIX_PRIO_IO - Research what exactly this is. */
/* TODO: _POSIX_SYNC_IO - Research what exactly this is. */
/* TODO: _POSIX_TIMESTAMP_RESOLUTION - Research what exactly this is. */
/* TODO: _POSIX2_SYMLINKS - Research what exactly this is. */
2011-08-05 08:25:00 -04:00
2013-12-26 19:44:03 -05:00
#ifndef NULL
#define __need_NULL
#include <stddef.h>
#endif
2011-08-05 08:25:00 -04:00
2013-04-16 05:44:29 -04: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 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
/* Sortix will not support POSIX advisory locks and doesn't declare:
F_LOCK
F_TEST
F_TLOCK
F_UNLOCK */
2011-08-05 08:25:00 -04:00
2013-03-22 08:58:43 -04: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 08:25:00 -04:00
2013-04-16 04:11:15 -04: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 08:25:00 -04:00
2013-04-16 04:19:25 -04:00
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
2011-08-05 08:25:00 -04:00
2014-04-05 18:16:59 -04:00
#define _POSIX_VDISABLE '\0'
2011-08-05 08:25:00 -04:00
2013-12-26 19:44:03 -05: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
2014-04-05 18:16:59 -04:00
/* TODO: intptr_t is not declared because <stdint.h> doesn't allow other headers
to define some, but not all, of the fixed width types. Additionally,
intptr_t was only added for the sake of sbrk(), but that was removed in
POSIX 2001. */
2014-04-05 18:16:59 -04:00
/* Somehow programs are required to declare environ themselves according to
the POSIX specification. */
#if __USE_SORTIX
extern char** environ;
#if defined(__is_sortix_libc)
extern char** __environ_malloced;
extern size_t __environ_used;
extern size_t __environ_length;
#endif
2011-08-05 08:25:00 -04:00
#endif
2012-03-05 09:46:23 -05:00
int access(const char*, int);
2013-05-11 19:24:42 -04:00
unsigned alarm(unsigned);
int chdir(const char*);
2012-10-23 14:02:33 -04:00
int chown(const char*, uid_t, gid_t);
int close(int);
2011-11-17 14:34:04 -05:00
int dup(int);
2014-04-05 18:16:59 -04:00
int dup2(int, 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 14:52:29 -04:00
pid_t fork(void);
2014-06-27 17:00:55 -04:00
long fpathconf(int, int);
2013-03-20 08:16:12 -04:00
int fsync(int);
char* getcwd(char*, size_t);
2013-01-12 20:37:14 -05:00
gid_t getegid(void);
uid_t geteuid(void);
2014-04-05 18:16:59 -04:00
gid_t getgid(void);
/* TODO: int getgroups(int, gid_t []); */
2013-04-15 18:08:33 -04:00
char* getlogin(void);
2013-06-11 19:02:01 -04:00
pid_t getpgid(pid_t);
2014-04-05 18:16:59 -04:00
/* TODO: pid_t getpgrp(void); */
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 14:52:29 -04:00
pid_t getpid(void);
pid_t getppid(void);
2013-01-12 20:37:14 -05:00
uid_t getuid(void);
int isatty(int);
2012-10-23 14:09:43 -04:00
int link(const char*, const char*);
2014-04-05 18:16:59 -04:00
/* lockf will not be implemented. */
2011-12-26 17:12:12 -05:00
off_t lseek(int, off_t, int);
2013-03-22 08:58:43 -04:00
long pathconf(const char*, int);
2014-04-05 18:16:59 -04:00
/* TODO: int pause(void); */
2011-11-16 02:37:29 -05:00
int pipe(int [2]);
ssize_t read(int, void*, size_t);
2012-01-14 10:25:28 -05:00
int rmdir(const char*);
2013-01-12 20:37:14 -05:00
int setgid(gid_t);
2013-06-11 19:02:01 -04:00
int setpgid(pid_t, pid_t);
2014-04-05 18:16:59 -04:00
/* TODO: pid_t setsid(void); */
2013-01-12 20:37:14 -05: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 14:52:29 -04:00
unsigned sleep(unsigned);
2013-04-16 04:11:15 -04:00
long sysconf(int);
2013-06-11 20:18:07 -04:00
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
2013-03-23 18:58:20 -04:00
char* ttyname(int);
2014-01-04 16:25:42 -05:00
int ttyname_r(int, char*, size_t);
2011-11-21 12:49:55 -05:00
int unlink(const char*);
2011-11-16 02:37:29 -05:00
ssize_t write(int, const void*, size_t);
2014-04-05 18:16:59 -04:00
#if __USE_SORTIX || 199209L <= __USE_POSIX
size_t confstr(int, char*, size_t);
2013-07-26 11:22:57 -04:00
/* For compatibility with POSIX, declare getopt(3) here. */
/* 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
2014-04-05 18:16:59 -04:00
#if __USE_XOPEN
/* TODO: char* crypt(const char*, const char*); */
/* TODO: void encrypt(char [64], int); */
/* gethostid will not be implemented */
/* TODO: int nice(int); */
/* setpgrp will not be implemented. */
/* TODO: void swab(const void* __restrict, void* __restrict, ssize_t); */
/* TODO: void sync(void); */
#endif
#if __USE_SORTIX || 420 <= __USE_XOPEN
/* TODO: int setregid(gid_t, gid_t); (XSI option) */
/* TODO: int setreuid(uid_t, uid_t); (XSI option) */
#endif
#if __USE_SORTIX || 199309L <= __USE_POSIX || 420 <= __USE_XOPEN
int getlogin_r(char*, size_t);
#endif
#if __USE_SORTIX || 200112L <= __USE_POSIX || 420 <= __USE_XOPEN
int ftruncate(int, off_t);
ssize_t readlink(const char* __restrict, char* __restrict, size_t);
int symlink(const char*, const char*);
#endif
#if __USE_SORTIX || 200809L <= __USE_POSIX || 420 <= __USE_XOPEN
int fchdir(int);
int fchown(int, uid_t, gid_t);
/* TODO: pid_t getsid(void); */
int lchown(const char*, uid_t, gid_t);
int truncate(const char*, off_t);
#endif
/* TODO: This feature macro seems wrong, verify historically. */
#if __USE_SORTIX || 199309L <= __USE_POSIX || 500 <= __USE_XOPEN
/* TODO: fdatasync (SIO option) */
#endif
/* Functions from POSIX 1995. */
#if __USE_SORTIX || 199506L <= __USE_POSIX
int getlogin_r(char*, size_t);
#endif
#if __USE_SORTIX || 200112L <= __USE_POSIX || 500 <= __USE_XOPEN
int gethostname(char*, size_t);
#endif
#if __USE_SORTIX || 200809L <= __USE_POSIX || 500 <= __USE_XOPEN
ssize_t pread(int, void*, size_t, off_t);
ssize_t pwrite(int, const void*, size_t, off_t);
#endif
/* Functions from POSIX 2001. */
#if __USE_SORTIX || 200112L <= __USE_POSIX
int setegid(gid_t);
int seteuid(uid_t);
#endif
/* Functions from POSIX 2008. */
#if __USE_SORTIX || 200809L <= __USE_POSIX
int faccessat(int, const char*, int, int);
int fchownat(int, const char*, uid_t, gid_t, int);
/* TODO: int fexecve(int, char* const [], char* const []); */
int linkat(int, const char*, int, const char*, int);
ssize_t readlinkat(int, const char* __restrict, char* __restrict, size_t);
int symlinkat(const char*, int, const char*);
int unlinkat(int, const char*, int);
#endif
#if __USE_SORTIX || !(200112L <= __USE_POSIX || 600 <= __USE_XOPEN)
size_t getpagesize(void);
#endif
/* Functions copied from elsewhere. */
#if __USE_SORTIX
int chroot(const char*);
2015-05-13 11:48:53 -04:00
int closefrom(int);
int crypt_checkpass(const char*, const char*);
int crypt_newhash(const char*, const char*, char*, size_t);
2014-04-05 18:16:59 -04:00
int dup3(int, int, int);
int execvpe(const char*, char* const [], char* const []);
char* get_current_dir_name(void);
int getdomainname(char*, size_t);
2014-07-14 17:24:43 -04:00
int getentropy(void*, size_t);
2014-04-05 18:16:59 -04:00
int pipe2(int [2], int);
2014-10-05 09:02:50 -04:00
int sethostname(const char*, size_t);
typedef unsigned int useconds_t;
2014-04-05 18:16:59 -04:00
int usleep(useconds_t useconds);
#endif
/* Functions that are Sortix extensions. */
#if __USE_SORTIX
int alarmns(const struct timespec* delay, struct timespec* odelay);
int exit_thread(int, int, const struct exit_thread*);
int fchdirat(int, const char*);
int fchroot(int);
int fchrootat(int, const char*);
int memstat(size_t* memused, size_t* memtotal);
int mkpartition(int fd, off_t start, off_t length);
pid_t sfork(int flags);
pid_t tfork(int flags, struct tfork* regs);
int truncateat(int dirfd, const char*, off_t);
#endif
2015-05-13 12:11:02 -04:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2011-08-05 08:25:00 -04:00
#endif