Compare commits

..

75 commits

Author SHA1 Message Date
Jonas 'Sortie' Termansen
8210ac97d3 fixup! Add sig2str(3) and str2sig(3). 2024-06-23 20:34:40 +02:00
Jonas 'Sortie' Termansen
5c896e027a Add ESOCKTNOSUPPORT. 2024-06-23 19:56:50 +02:00
Jonas 'Sortie' Termansen
23bce072c0 Reject the obsolescent inet_addr and inet_ntoa. 2024-06-23 19:48:50 +02:00
Jonas 'Sortie' Termansen
16abe619e6 fixup! Implement dladdr(3). 2024-06-23 19:45:58 +02:00
Jonas 'Sortie' Termansen
535ee9649f Add sig2str(3) and str2sig(3). 2024-06-23 19:38:24 +02:00
Jonas 'Sortie' Termansen
230b816702 Delay implementing getresgid, getresuid, setresgid, setresuid. 2024-06-23 19:10:43 +02:00
Jonas 'Sortie' Termansen
64fc6b5f6d Add thread wait functions with clock support.
- pthread_cond_clockwait(2)
- pthread_mutex_clocklock(2)
- pthread_mutex_timedlock(2)
- pthread_rwlock_clockrdlock(2)
- pthread_rwlock_clockwrlock(2)
- pthread_rwlock_timedrdlock(2)
- pthread_rwlock_timedwrlock(2)
- sem_clockwait(2)
2024-06-23 19:05:04 +02:00
Jonas 'Sortie' Termansen
f460bb78aa fixup! Add memmem(3). 2024-06-23 19:01:51 +02:00
Jonas 'Sortie' Termansen
ae6b1ed45a Reject posix_getdents(2) for now. 2024-06-23 18:06:32 +02:00
Jonas 'Sortie' Termansen
95481db488 Reject posix_devctl(2). 2024-06-23 18:06:29 +02:00
Jonas 'Sortie' Termansen
752c9b8aa2 Reject posix_close(3). 2024-06-23 17:50:09 +02:00
Jonas 'Sortie' Termansen
0f5aaed789 Add memmem(3). 2024-06-23 17:28:53 +02:00
Jonas 'Sortie' Termansen
8f68ea49ce Add getlocalename_l(3). 2024-06-23 17:28:08 +02:00
Jonas 'Sortie' Termansen
8618c1adf5 Add GETENTROPY_MAX. 2024-06-23 13:50:27 +02:00
Jonas 'Sortie' Termansen
240d227be8 Implement dladdr(3). 2024-06-23 13:48:48 +02:00
Jonas 'Sortie' Termansen
c4a44531bf Add _Fork(2). 2024-06-23 13:40:39 +02:00
Jonas 'Sortie' Termansen
82fd2d4c92 Recognize and advertise POSIX 2024 support.
Update feature macros for interfaces added to POSIX 2024.

This commit begins the work of implementing POSIX 2024, which was
largely already implemented as extensions.
2024-06-23 13:33:55 +02:00
Jonas 'Sortie' Termansen
50792cb986 Remove unused alternative const safe sortix string functions. 2024-06-23 12:10:18 +02:00
Jonas 'Sortie' Termansen
442aa49070 Modernize process and thread member variable names. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
bfa2083ff0 Fix ppoll(2) EINTR handling. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
b46c25ea0c Add pstree(1) -is options. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
ed8bb024c5 Add chroot(8) -I option. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
49bf6298a7 Modernize chroot(8). 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
5d18d8be30 Prevent init(8) from using the tty when a daemon uses it. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
e90e2077e7 Run daemons in their own session. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
6e51c1ae51 Add init groups.
Every process now has an init process like it has a session, and each
session belong to an init. Orphaned processes are reparented to its init
process. All descendent processes are SIGKILL'd when an init process exits
and creating additional processes/threads fails.

Add setinit(2) for becoming the init process for your child processes and
add getinit(2) for locating your init process.

Add TIOCSCTTY force flag that releases a terminal from its current session
and makes it the controlling terminal for the current session. This ioctl
is essential to transferring the controlling terminal to a nested init,
which has its own session.

Add TIOCUCTTY that releases the terminal as the controlling terminal for
its current session.

Remove INIT_PID as it is replaced by getinit(2).
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
09ca6ea01e Add service(8). 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
2629d5bdcc Add checksum(1) --cache option. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
70dbd6952a Add php port. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
b90b063efe Revert "Update to perl-5.39.5."
This reverts commit 781ff8880f3e2d29e31460427bccf50cc1ec436e.

File/Spec was no longer being installed when --all-static, breaking
texinfo.
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
1f616954a5 Update to perl-5.39.5. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
f96d02415d Revert "Update to python-3.12.1."
This reverts commit 8ae8363167cc195f92803489e2f97391e2527c5f.

The libglib build broke due to no distutils module.
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
2e2def6288 Update to python-3.12.1. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
c258e9b68d Revert "Update to texinfo-7.1."
This reverts commit 9813bb1d13c625d48ecd950bfaafc274383ca049.

ffmpeg fails to build natively with the new makeinfo:

perl ./doc/texidep.pl . doc/ffmpeg-utils.texi doc/ffmpeg-utils.html >doc/ffmpeg-utils.html.d
makeinfo --html -I doc --no-split -D config-not-all --init-file=./doc/t2h.pm --output doc/ffmpeg-utils.html doc/ffmpeg-utils.texi
makeinfo: error parsing ./doc/t2h.pm: Undefined subroutine &Texinfo::Config::set_from_init_file called at ./doc/t2h.pm line 24.
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
abd57ad77c Update to texinfo-7.1. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
2639949a3b Revert "Update to dash-0.5.12."
This reverts commit 16bedfc9630779c01ebae5513fd307e969c329de.

Something is wrong with the case pattern matching, maybe fnmatch?
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
48e5fb31cd Update to dash-0.5.12. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
cfd607f35e Revert "Update to freetype-2.13.2."
This reverts commit 5ad1e5f6054dd1e44ecb955b9326c1198ef17ff0.

configure runs make and crashes on a stack overflow in make.
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
5abaee0b07 Update to freetype-2.13.2. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
5a40d167f5 Revert "Update to bison-3.8.2."
This reverts commit b82fae810b42c5426d21c4dc153b32f086dd7fde.
2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
9af68c9e79 Update to bison-3.8.2. 2024-06-22 18:25:49 +02:00
Jonas 'Sortie' Termansen
12ef28d590 Revert "Schedule interactive threads fairly under load."
This reverts commit 47731b91c37933943a73010c5a4494101cce52dc.

There is a rare freeze when the scheduler fails to run anything.
2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
a2b6b05838 Schedule interactive threads fairly under load.
Preempted threads are now removed from the runnable list until every
other thread has been preempted or the system goes idle. This ensures
threads that roundtrip to other threads get a full chance to perform
their work cooperatively without being starved by CPU intensive threads
whenever they yield.
2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
81947e4f3b Kinda fix pager(1) man bullet points. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
e142c64dc8 Fix ESP endian. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
7e1e5bc6ce Support booting with EFI. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
784481dab6 Add kernel(7) --firmware option. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
58bab55351 Add fatfs(8). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
cb5ccbec33 Add getty(8). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
c6f6aaa285 Add terminal and interrupt support to com(4). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
d1a05c28ab Add nyan(1). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
39072cbcff Work around pty deadlock. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
cd5b226201 Add cdrom mounting live environment. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
c9917c00a1 Revert "Parallelize driver initialization."
This reverts commit 0fef08bbc4.
2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
f0d03cdd57 Parallelize driver initialization. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
a8eba7e85f Speed up ata(4) 400 ns waits.
Waiting for any non-zero duration currently waits for at least one timer
cycle (10 ms), which is especially expensive during early boot.

The current workaround of simply reading the status 14 times seems really
suspicious although the osdev wiki documents it, but let's see how well it
works on real hardware, it's probably good enough.

Try to determine the initial selected drive to save one drive selection.
2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
61c6f65839 Decrease PS/2 timeouts. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
a9738417c7 Add uptime(1) -pr options. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
2100eb369d Add iso9660 filesystem implementation. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
fd58b62068 Add kernel virtual address space usage debug information. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
f636b310f6 Debug TCP socket state listing. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
eb1f28c738 Add kernel heap allocation tracing debug facility. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
23309f39b1 Trianglix 4. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
ab7cb1314f Add tix-check(8). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
1c3465260a Volatile release. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
cda3e2dce8 Add tix-upgrade(8). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
5236589d81 Add tix-repository(8).
Support renaming, splitting, and deleting ports via RENAMES.

Unify on RUNTIME_DEPS for runtime dependencies.
2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
4f2f3e720b Add signify port. 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
19c352b8c5 Add pty(1). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
54eedef518 Add getaddrinfo(1). 2024-06-22 18:25:48 +02:00
Jonas 'Sortie' Termansen
2a7a2ff76e Enable stack smash protection by default. 2024-06-22 18:25:47 +02:00
Jonas 'Sortie' Termansen
cb510e298f Enable undefined behavior sanitization by default. 2024-06-22 18:25:47 +02:00
Jonas 'Sortie' Termansen
d631aaafeb Handle SIGTERM in display(1).
Display a final frame with a message explaining what is happening that is
displayed while the system powers off, reboots, halts, when the user logs
out, or just exits the compositor.
2024-06-22 18:25:47 +02:00
Jonas 'Sortie' Termansen
65bc117891 Handle SIGTERM in login(8).
Display a final frame with a message explaining what is happening that is
displayed while the system powers off, reboots, or halts.
2024-06-22 18:25:47 +02:00
Jonas 'Sortie' Termansen
2bc6e40f1d Sync login framebuffer code to libui. 2024-06-22 18:25:47 +02:00
47 changed files with 900 additions and 330 deletions

View file

@ -6,7 +6,7 @@ if [ "$#" = 0 ]; then
set i686-sortix x86_64-sortix
fi
for target; do
for feature in "" "-D_POSIX_C_SOURCE=200809L" "-D_XOPEN_SOURCE=700" "-D_SORTIX_SOURCE"; do
for feature in "" "-D_POSIX_C_SOURCE=202405L" "-D_XOPEN_SOURCE=800" "-D_SORTIX_SOURCE"; do
for std in \
"-ansi -pedantic-errors" \
"-std=c89 -pedantic-errors" \

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, 2017 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2016, 2017, 2024 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
@ -28,4 +28,8 @@
#define IOV_MAX 1024
#endif
#if __USE_SORTIX || 202405L <= __USE_POSIX
#define GETENTROPY_MAX 256
#endif
#endif

View file

@ -679,7 +679,7 @@ Ref<Inode> Socket(int type, int protocol)
switch ( type )
{
case SOCK_STREAM: return Ref<Inode>(new StreamSocket(0, 0, 0600, manager));
default: return errno = EPROTOTYPE, Ref<Inode>(NULL);
default: return errno = ESOCKTNOSUPPORT, Ref<Inode>(NULL);
}
}

View file

@ -445,7 +445,7 @@ Ref<Inode> Socket(int type, int protocol)
if ( protocol == 0 || protocol == IPPROTO_TCP )
return TCP::Socket(AF_INET);
return errno = EPROTONOSUPPORT, Ref<Inode>(NULL);
default: return errno = EPROTOTYPE, Ref<Inode>(NULL);
default: return errno = ESOCKTNOSUPPORT, Ref<Inode>(NULL);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, 2016 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015, 2016, 2024 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
@ -24,6 +24,7 @@
#include <string.h>
#include <sortix/clock.h>
#include <sortix/limits.h>
#include <sortix/kernel/addralloc.h>
#include <sortix/kernel/copy.h>
@ -162,7 +163,7 @@ namespace Sortix {
int sys_getentropy(void* user_buffer, size_t size)
{
unsigned char buffer[256];
unsigned char buffer[GETENTROPY_MAX];
if ( sizeof(buffer) < size )
return errno = EIO, -1;
arc4random_buf(buffer, size);

View file

@ -60,6 +60,7 @@ malloc/__heap_verify.o \
netinet/if_ether/etheraddr_broadcast.o \
netinet/in/in6addr_any.o \
netinet/in/in6addr_loopback.o \
signal/sig2str.o \
signal/sigaddset.o \
signal/sigandset.o \
signal/sigdelset.o \
@ -69,6 +70,7 @@ signal/sigisemptyset.o \
signal/sigismember.o \
signal/signotset.o \
signal/sigorset.o \
signal/str2sig.o \
ssp/__stack_chk_fail.o \
stdio/asprintf.o \
stdio/cbprintf.o \
@ -179,6 +181,7 @@ string/memccpy.o \
string/memchr.o \
string/memcmp.o \
string/memcpy.o \
string/memmem.o \
string/memmove.o \
string/memrchr.o \
string/memset.o \
@ -394,6 +397,7 @@ ioleast/writeall.o \
ioleast/writeleast.o \
langinfo/nl_langinfo_l.o \
langinfo/nl_langinfo.o \
locale/getlocalename_l.o \
locale/localeconv.o \
locale/setlocale.o \
memusage/memusage.o \
@ -436,6 +440,7 @@ pthread/pthread_condattr_getclock.o \
pthread/pthread_condattr_init.o \
pthread/pthread_condattr_setclock.o \
pthread/pthread_cond_broadcast.o \
pthread/pthread_cond_clockwait.o \
pthread/pthread_cond_destroy.o \
pthread/pthread_cond_init.o \
pthread/pthread_cond_signal.o \
@ -454,15 +459,21 @@ pthread/pthread_mutexattr_destroy.o \
pthread/pthread_mutexattr_gettype.o \
pthread/pthread_mutexattr_init.o \
pthread/pthread_mutexattr_settype.o \
pthread/pthread_mutex_clocklock.o \
pthread/pthread_mutex_destroy.o \
pthread/pthread_mutex_init.o \
pthread/pthread_mutex_lock.o \
pthread/pthread_mutex_timedlock.o \
pthread/pthread_mutex_trylock.o \
pthread/pthread_mutex_unlock.o \
pthread/pthread_once.o \
pthread/pthread_rwlock_clockrdlock.o \
pthread/pthread_rwlock_clockwrlock.o \
pthread/pthread_rwlock_destroy.o \
pthread/pthread_rwlock_init.o \
pthread/pthread_rwlock_rdlock.o \
pthread/pthread_rwlock_timedrdlock.o \
pthread/pthread_rwlock_timedwrlock.o \
pthread/pthread_rwlock_tryrdlock.o \
pthread/pthread_rwlock_trywrlock.o \
pthread/pthread_rwlock_unlock.o \
@ -486,6 +497,7 @@ pwd/setpwent.o \
sched/sched_yield.o \
pty/openpty.o \
scram/scram.o \
semaphore/sem_clockwait.o \
semaphore/sem_destroy.o \
semaphore/sem_getvalue.o \
semaphore/sem_init.o \
@ -702,6 +714,7 @@ unistd/fchownat.o \
unistd/fchown.o \
unistd/fchrootat.o \
unistd/fchroot.o \
unistd/_Fork.o \
unistd/fork.o \
unistd/fpathconf.o \
unistd/fsync.o \

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2013, 2024 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
@ -22,6 +22,13 @@
static const char* dlerrormsg = NULL;
int dladdr(const void* restrict addr, Dl_info_t* restrict dlip)
{
(void) addr;
(void) dlip;
return 0;
}
void* dlopen(const char* filename, int mode)
{
(void) filename;

View file

@ -34,12 +34,6 @@ const char* inet_ntop(int, const void* __restrict, char* __restrict, socklen_t);
int inet_pton(int, const char* __restrict, void* __restrict);
#endif
/* Functions copied from elsewhere. */
#if __USE_SORTIX
/* TODO: int inet_aton(const char*, struct in_addr*); */
/* TODO: char* inet_neta(in_addr_t, char*, size_t); */
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2024 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
@ -22,19 +22,32 @@
#include <sys/cdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RTLD_LAZY (1<<0)
#define RTLD_NOW (1<<1)
#define RTLD_GLOBAL (1<<8)
#define RTLD_LOCAL 0 /* Bit 8 is not set. */
int dlclose(void* handle);
#if __USE_SORTIX || 202405L <= __USE_POSIX
typedef struct
{
const char* dli_fname;
void* dli_fbase;
const char* dli_sname;
void* dli_saddr;
} Dl_info_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if __USE_SORTIX || 202405L <= __USE_POSIX
int dladdr(const void* restrict, Dl_info_t* __restrict);
#endif
int dlclose(void*);
char* dlerror(void);
void* dlopen(const char* filename, int mode);
void* dlsym(void* handle, const char* name);
void* dlopen(const char*, int);
void* dlsym(void*, const char*);
#ifdef __cplusplus
} /* extern "C" */

View file

@ -109,6 +109,7 @@
#define ENOMOUNT 99
#define ENOMEDIUM 100
#define EHOSTDOWN 101
#define ESOCKTNOSUPPORT 102
#define EOPNOTSUPP ENOTSUP
#define EWOULDBLOCK EAGAIN

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
* Copyright (c) 2011, 2012, 2013, 2014, 2024 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
@ -62,14 +62,13 @@
#define _C11_SOURCE
#endif
#if !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200809L
#define _POSIX_C_SOURCE 202405L
#endif
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 700
#endif
#if !defined(_SORTIX_SOURCE)
#define _SORTIX_SOURCE 1
#define __IMPLICIT_SORTIX_SOURCE
#endif
#endif
@ -90,12 +89,14 @@
/* Use the Sortix API if the default API was requested. */
#if defined(_DEFAULT_SOURCE) && !defined(_SORTIX_SOURCE)
#define _SORTIX_SOURCE 1
#define __IMPLICIT_SORTIX_SOURCE
#endif
/* Particular XSI revisions imply certain POSIX revisions. */
#if defined(_XOPEN_SOURCE)
#if 700 <= _XOPEN_SOURCE - 0
#if 800 <= _XOPEN_SOURCE - 0
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 202405L
#elif 700 <= _XOPEN_SOURCE - 0
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#elif 600 <= _XOPEN_SOURCE - 0
@ -157,7 +158,9 @@
/* Determine which revision of POSIX is used. */
#ifdef _POSIX_C_SOURCE
#if 200809L <= _POSIX_C_SOURCE - 0
#if 202405L <= _POSIX_C_SOURCE - 0
#define __USE_POSIX 202405L
#elif 200809L <= _POSIX_C_SOURCE - 0
#define __USE_POSIX 200809L
#elif 200112L <= _POSIX_C_SOURCE - 0
#define __USE_POSIX 200112L
@ -192,15 +195,6 @@
#define __USE_SORTIX 0
#endif
/* Whether to override some "standard" functions with Sortix alternatives. */
#if !defined(__SORTIX_STDLIB_REDIRECTS)
#if __USE_SORTIX && !defined(__IMPLICIT_SORTIX_SOURCE)
#define __SORTIX_STDLIB_REDIRECTS 1
#else
#define __SORTIX_STDLIB_REDIRECTS 0
#endif
#endif
/* Provide the restrict keyword when building system components. */
#if defined(__is_sortix_system_component) && !defined(__want_restrict)
#define __want_restrict 1

View file

@ -64,12 +64,29 @@ struct lconv
#define LC_ALL 6
#define LC_NUM_CATEGORIES LC_ALL
#if __USE_SORTIX || __USE_POSIX
#define LC_GLOBAL_LOCALE ((locale_t) -1)
#endif
#if __USE_SORTIX || __USE_POSIX
#ifndef __locale_t_defined
#define __locale_t_defined
/* TODO: figure out what this does and typedef it properly. This is just a
temporary assignment. */
typedef int __locale_t;
typedef __locale_t locale_t;
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
char* setlocale(int category, const char* locale);
struct lconv* localeconv(void);
#if __USE_SORTIX || 202405L <= __USE_POSIX
const char* getlocalename_l(int, locale_t);
#endif
#ifdef __cplusplus
} /* extern "C" */

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2024 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
@ -24,28 +24,23 @@
#include <sys/__/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __time_t_defined
#define __time_t_defined
typedef __time_t time_t;
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#include <sortix/poll.h>
#if __USE_SORTIX || 202405L <= __USE_POSIX
#include <sortix/sigset.h>
#include <sortix/timespec.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
int poll(struct pollfd* fds, nfds_t nfds, int timeout);
#if __USE_SORTIX || 202405L <= __USE_POSIX
int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* timeout,
const sigset_t* sigmask);
#endif
#ifdef __cplusplus
} /* extern "C" */

View file

@ -252,7 +252,8 @@ int pthread_mutex_init(pthread_mutex_t* __restrict,
const pthread_mutexattr_t* __restrict);
int pthread_mutex_lock(pthread_mutex_t*);
/* TODO: pthread_mutex_setprioceiling */
/* TODO: pthread_mutex_timedlock */
int pthread_mutex_timedlock(pthread_mutex_t* __restrict,
const struct timespec* __restrict);
int pthread_mutex_trylock(pthread_mutex_t*);
int pthread_mutex_unlock(pthread_mutex_t*);
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
@ -272,8 +273,10 @@ int pthread_rwlock_destroy(pthread_rwlock_t*);
int pthread_rwlock_init(pthread_rwlock_t* __restrict,
const pthread_rwlockattr_t* __restrict);
int pthread_rwlock_rdlock(pthread_rwlock_t*);
/* TODO: pthread_rwlock_timedrdlock */
/* TODO: pthread_rwlock_timedwrlock */
int pthread_rwlock_timedrdlock(pthread_rwlock_t* __restrict,
const struct timespec* __restrict);
int pthread_rwlock_timedwrlock(pthread_rwlock_t* __restrict,
const struct timespec* __restrict);
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
int pthread_rwlock_unlock(pthread_rwlock_t*);
@ -296,6 +299,18 @@ int pthread_setspecific(pthread_key_t, const void*);
/* TODO: pthread_spin_unlock */
/* TODO: pthread_testcancel */
#if __USE_SORTIX || 202405L <= __USE_POSIX
int pthread_cond_clockwait(pthread_cond_t* __restrict,
pthread_mutex_t* __restrict, clockid_t,
const struct timespec* __restrict);
int pthread_mutex_clocklock(pthread_mutex_t* __restrict, clockid_t,
const struct timespec* __restrict);
int pthread_rwlock_clockrdlock(pthread_rwlock_t* __restrict, clockid_t,
const struct timespec* __restrict);
int pthread_rwlock_clockwrlock(pthread_rwlock_t* __restrict, clockid_t,
const struct timespec* __restrict);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -22,7 +22,7 @@
#include <sys/cdefs.h>
#include <sortix/timespec.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
@ -52,6 +52,11 @@ int sem_trywait(sem_t*);
/*int sem_unlink(const char*);*/
int sem_wait(sem_t*);
#if __USE_SORTIX || 202405L <= __USE_POSIX
int sem_clockwait(sem_t* __restrict, clockid_t clock,
const struct timespec* __restrict);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -87,6 +87,10 @@ typedef int sig_atomic_t;
#define MINSIGSTKSZ 2048
#define SIGSTKSZ 8192
#if __USE_SORTIX || 202405L <= __USE_POSIX
#define SIG2STR_MAX 16
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -122,6 +126,11 @@ int sigsuspend(const sigset_t*);
/* TODO: int sigwaitinfo(const sigset_t* __restrict, siginfo_t* __restrict); */
#endif
#if __USE_SORTIX || 202405L <= __USE_POSIX
int sig2str(int, char*);
int str2sig(const char* __restrict, int* __restrict);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2017, 2022 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2017, 2022, 2024 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
@ -121,7 +121,6 @@ int mkstemp(char*);
int mkstemps(char*, int);
int on_exit(void (*function)(int, void*), void* arg);
void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*);
#if !defined(__is_sortix_libc) /* not a warning inside libc */
__attribute__((__warning__("rand() isn't random, use arc4random()")))
#endif
@ -156,6 +155,17 @@ unsigned long long strtoull(const char* __restrict, char** __restrict, int);
long long strtoll(const char* __restrict, char** __restrict, int);
#endif
/* Functions from POSIX 2024. */
#if __USE_SORTIX || 202405L <= __USE_POSIX
void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*);
#ifdef __TRACE_ALLOCATION_SITES
void* reallocarray_trace(struct __allocation_site*, void*, size_t, size_t);
#define reallocarray(a, b, c) reallocarray_trace(ALLOCATION_SITE, (a), (b), (c))
#else
void* reallocarray(void*, size_t, size_t);
#endif
#endif
#if defined(__is_sortix_libc)
struct exit_handler
{
@ -204,12 +214,6 @@ int posix_openpt(int);
uint32_t arc4random(void);
void arc4random_buf(void*, size_t);
uint32_t arc4random_uniform(uint32_t);
#ifdef __TRACE_ALLOCATION_SITES
void* reallocarray_trace(struct __allocation_site*, void*, size_t, size_t);
#define reallocarray(a, b, c) reallocarray_trace(ALLOCATION_SITE, (a), (b), (c))
#else
void* reallocarray(void*, size_t, size_t);
#endif
int ptsname_r(int, char*, size_t);
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013, 2014, 2017, 2022 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2014, 2017, 2022, 2024 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
@ -62,11 +62,7 @@ int strcmp(const char*, const char*);
int strcoll(const char*, const char*);
char* strcpy(char* __restrict, const char* __restrict);
size_t strcspn(const char*, const char*);
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
const char* strerror(int errnum) __asm__ ("sortix_strerror");
#else
char* strerror(int errnum);
#endif
size_t strlen(const char*);
char* strncat(char* __restrict, const char* __restrict, size_t);
int strncmp(const char*, const char*, size_t);
@ -102,11 +98,7 @@ char* strdup(const char*);
/* Functions from POSIX 2001. */
#if __USE_SORTIX || 200112L <= __USE_POSIX
int ffs(int);
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
const char* strerror_l(int, locale_t) __asm__ ("sortix_strerror_l");
#else
char* strerror_l(int, locale_t);
#endif
int strerror_r(int, char*, size_t);
char* strtok_r(char* __restrict, const char* __restrict, char** __restrict);
#endif
@ -123,14 +115,17 @@ char* strndup_trace(struct __allocation_site*, const char*, size_t);
char* strndup(const char*, size_t);
#endif
size_t strnlen(const char*, size_t);
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
const char* strsignal(int signum) __asm__ ("sortix_strsignal");
#else
char* strsignal(int signum);
#endif
size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
#endif
/* Functions from POSIX 2024. */
#if __USE_SORTIX || 202405L <= __USE_POSIX
void* memmem(const void*, size_t, const void*, size_t);
size_t strlcat(char* __restrict, const char* __restrict, size_t);
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
#endif
/* Functions copied from elsewhere. */
#if __USE_SORTIX
void explicit_bzero(void*, size_t);
@ -139,8 +134,6 @@ void* memrchr(const void*, int, size_t);
/* TODO: strcasecmp_l */
char* strchrnul(const char* str, int c);
char* stresep(char**, const char*, int);
size_t strlcat(char* __restrict, const char* __restrict, size_t);
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
/* TODO: strncasecmp_l */
char* strsep(char**, const char*);
int strverscmp(const char*, const char*);
@ -150,9 +143,6 @@ int timingsafe_memcmp(const void*, const void*, size_t);
/* Functions that are Sortix extensions. */
#if __USE_SORTIX
int ffsll(long long int);
const char* sortix_strerror(int errnum);
const char* sortix_strerror_l(int, locale_t);
const char* sortix_strsignal(int signum);
#endif
#if __USE_SORTIX

View file

@ -43,10 +43,10 @@ extern "C" {
#define _POSIX_VERSION __USE_POSIX /* C bindings */
#define _POSIX2_VERSION __USE_POSIX /* Shell utilities. */
/* The native API is based on POSIX 2008. */
/* The native API is based on POSIX 2024. */
#elif __USE_SORTIX
#define _POSIX_VERSION 200809L /* C bindings */
#define _POSIX2_VERSION 200809L /* Shell utilities. */
#define _POSIX_VERSION 202405L /* C bindings */
#define _POSIX2_VERSION 202405L /* 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
@ -67,95 +67,86 @@ extern "C" {
#define _XOPEN_VERSION 4
#endif
/* #define _POSIX_ADVISORY_INFO 200809L
/* #define _POSIX_ADVISORY_INFO 202405L
TODO: Uncomment when posix_fadvise(), posix_fallocate(), posix_madvise(),
posix_memalign() has been added. */
#define _POSIX_ASYNCHRONOUS_IO 200809L
#define _POSIX_BARRIERS 200809L
#define _POSIX_ASYNCHRONOUS_IO 202405L
#define _POSIX_BARRIERS 202405L
/* 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
#define _POSIX_CLOCK_SELECTION 202405L
#define _POSIX_CPUTIME 202405L
/* #undef _POSIX_DEVICE_CONTROL - posix_devctl won't be implemented */
#define _POSIX_FSYNC 202405L
#define _POSIX_IPV6 202405L
#define _POSIX_JOB_CONTROL 1
/*TODO: _POSIX_MAPPED_FILES - Needs to be implemented */
/*TODO: _POSIX_MEMLOCK - Research what this is. */
/*TODO: _POSIX_MEMLOCK_RANGE - Research what this is. */
#define _POSIX_MEMORY_PROTECTION 200809L
#define _POSIX_MEMORY_PROTECTION 202405L
/*TODO: _POSIX_MESSAGE_PASSING - Research what this is. */
#define _POSIX_MONOTONIC_CLOCK 200809L
#define _POSIX_MONOTONIC_CLOCK 202405L
#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_READER_WRITER_LOCKS 202405L
#define _POSIX_REALTIME_SIGNALS 202405L
#define _POSIX_REGEXP 1
/* #define _POSIX_SAVED_IDS 1
TODO: Uncomment when saved ids are implemented. I forgot if they already are. */
#define _POSIX_SEMAPHORES 200809L
#define _POSIX_SEMAPHORES 202405L
/*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
#define _POSIX_SPIN_LOCKS 202405L
/*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. */
#define _POSIX_THREAD_CPUTIME 200809L
#define _POSIX_THREAD_ATTR_STACKSIZE 202405L
#define _POSIX_THREAD_CPUTIME 202405L
/*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. */
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
#define _POSIX_THREAD_SAFE_FUNCTIONS 202405L
/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is. */
#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 _POSIX_THREADS 202405L
#define _POSIX_TIMEOUTS 202405L
#define _POSIX_TIMERS 202405L
/* TODO: _POSIX_TYPED_MEMORY_OBJECTS - Research what this is. */
/* TODO: _POSIX_V7_ILP32_OFF32 (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V7_ILP32_OFFBIG (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V7_LP64_OFF64 (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V7_LPBIG_OFFBIG (Obsolescent) - Research what this is. */
/* TODO: _POSIX_V8_ILP32_OFF32 - Research what this is. */
/* TODO: _POSIX_V8_ILP32_OFFBIG - Research what this is. */
/* TODO: _POSIX_V8_LP64_OFF64 - Research what this is. */
/* TODO: _POSIX_V8_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
/* #define _POSIX2_LOCALEDEF 202405L
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: _POSIX2_SW_DEV - Research what this is. */
/* #define _POSIX2_UPE 202405L
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. */
#define _XOPEN_REALTIME_THREADS 1
/* 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_FALLOC - 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. */
#define _POSIX_TIMESTAMP_RESOLUTION 1
#define _POSIX2_SYMLINKS 1
#ifndef NULL
#define __need_NULL
@ -163,35 +154,35 @@ extern "C" {
#endif
#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_POSIX_V8_ILP32_OFF32_CFLAGS 1
#define _CS_POSIX_V8_ILP32_OFF32_LDFLAGS 2
#define _CS_POSIX_V8_ILP32_OFF32_LIBS 3
#define _CS_POSIX_V8_ILP32_OFFBIG_CFLAGS 4
#define _CS_POSIX_V8_ILP32_OFFBIG_LDFLAGS 5
#define _CS_POSIX_V8_ILP32_OFFBIG_LIBS 6
#define _CS_POSIX_V8_LP64_OFF64_CFLAGS 7
#define _CS_POSIX_V8_LP64_OFF64_LDFLAGS 8
#define _CS_POSIX_V8_LP64_OFF64_LIBS 9
#define _CS_POSIX_V8_LPBIG_OFFBIG_CFLAGS 10
#define _CS_POSIX_V8_LPBIG_OFFBIG_LDFLAGS 11
#define _CS_POSIX_V8_LPBIG_OFFBIG_LIBS 12
#define _CS_POSIX_V8_THREADS_CFLAGS 13
#define _CS_POSIX_V8_THREADS_LDFLAGS 14
#define _CS_POSIX_V8_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_POSIX_V7_ILP32_OFF32_CFLAGS 17 /* obsolescent */
#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 18 /* obsolescent */
#define _CS_POSIX_V7_ILP32_OFF32_LIBS 19 /* obsolescent */
#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 20 /* obsolescent */
#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 21 /* obsolescent */
#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 22 /* obsolescent */
#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 23 /* obsolescent */
#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 24 /* obsolescent */
#define _CS_POSIX_V7_LP64_OFF64_LIBS 25 /* obsolescent */
#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 26 /* obsolescent */
#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 27 /* obsolescent */
#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 28 /* obsolescent */
#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 29 /* obsolescent */
#define _CS_V6_ENV 30 /* obsolescent */
/* Sortix will not support POSIX advisory locks and doesn't declare:
@ -221,6 +212,8 @@ extern "C" {
#define _PC_SYNC_IO 19
#define _PC_TIMESTAMP_RESOLUTION 20
#define _PC_VDISABLE 21
#define _PC_FALLOC 22
#define _PC_TEXTDOMAIN_MAX 23
#define _SC_AIO_LISTIO_MAX 0
#define _SC_AIO_MAX 1
@ -347,6 +340,9 @@ extern "C" {
#define _SC_XOPEN_UNIX 132
#define _SC_XOPEN_UUCP 133
#define _SC_XOPEN_VERSION 134
#define _SC_NPROCESSORS_CONF 135
#define _SC_NPROCESSORS_ONLN 136
#define _SC_NSIG 137
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
@ -535,6 +531,14 @@ int symlinkat(const char*, int, const char*);
int unlinkat(int, const char*, int);
#endif
/* Functions from POSIX 2024. */
#if __USE_SORTIX || 202405L <= __USE_POSIX
pid_t _Fork(void);
int dup3(int, int, int);
int getentropy(void*, size_t);
int pipe2(int [2], int);
#endif
#if __USE_SORTIX || !(200112L <= __USE_POSIX || 600 <= __USE_XOPEN)
size_t getpagesize(void);
#endif
@ -545,11 +549,8 @@ int chroot(const char*);
int closefrom(int);
int crypt_checkpass(const char*, const char*);
int crypt_newhash(const char*, const char*, char*, size_t);
int dup3(int, int, int);
int execvpe(const char*, char* const [], char* const []);
char* get_current_dir_name(void);
int getentropy(void*, size_t);
int pipe2(int [2], int);
int sethostname(const char*, size_t);
typedef unsigned int useconds_t;
int usleep(useconds_t useconds);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2024 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
@ -207,6 +207,12 @@ size_t wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t,
/* TODO: size_t wcsxfrm_l(wchar_t* __restrict, const wchar_t* __restrict, size_t, locale_t); */
#endif
/* Functions from POSIX 2024. */
#if __USE_SORTIX || 202405L <= __USE_POSIX
size_t wcslcat(wchar_t* __restrict, const wchar_t* __restrict, size_t);
size_t wcslcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t);
#endif
/* Functions copied from elsewhere. */
#if __USE_SORTIX
/* TODO: getwc_unlocked */
@ -219,8 +225,6 @@ size_t wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t,
/* TODO: fputws_unlocked */
wchar_t* wcschrnul(const wchar_t*, wchar_t);
/* TODO: wcsftime_l */
size_t wcslcat(wchar_t* __restrict, const wchar_t* __restrict, size_t);
size_t wcslcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t);
/* TODO: wchar_t* wmempcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t); */
/* TODO: wcstod_l? */
/* TODO: wcstof_l? */

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 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.
*
* locale/getlocalename_l.c
* Get locale name.
*/
#include <assert.h>
#include <locale.h>
extern char* __current_locales[LC_NUM_CATEGORIES];
const char* getlocalename_l(int cat, locale_t locale)
{
assert(locale == LC_GLOBAL_LOCALE);
return __current_locales[cat] ? __current_locales[cat] : (char*) "C";
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2014, 2015, 2024 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
@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
char* __current_locales[LC_NUM_CATEGORIES] = { NULL };
char* setlocale(int category, const char* locale)
{
@ -32,7 +32,7 @@ char* setlocale(int category, const char* locale)
int from = category != LC_ALL ? category : 0;
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
if ( !locale )
return current_locales[to] ? current_locales[to] : (char*) "C";
return __current_locales[to] ? __current_locales[to] : (char*) "C";
for ( int i = from; i <= to; i++ )
{
if ( !(new_strings[i] = strdup(locale)) )
@ -44,8 +44,8 @@ char* setlocale(int category, const char* locale)
}
for ( int i = from; i <= to; i++ )
{
free(current_locales[i]);
current_locales[i] = new_strings[i];
free(__current_locales[i]);
__current_locales[i] = new_strings[i];
}
return (char*) locale;
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2014, 2021, 2024 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.
*
* pthread/pthread_cond_clockwait.c
* Waits on a condition or until a timeout happens.
*/
#include <sys/futex.h>
#include <errno.h>
#include <pthread.h>
int pthread_cond_clockwait(pthread_cond_t* restrict cond,
pthread_mutex_t* restrict mutex,
clockid_t clock,
const struct timespec* restrict abstime)
{
struct pthread_cond_elem elem;
pthread_mutex_lock(&cond->lock);
elem.next = NULL;
elem.prev = cond->last;
elem.woken = 0;
if ( cond->last )
cond->last->next = &elem;
if ( !cond->first )
cond->first = &elem;
cond->last = &elem;
pthread_mutex_unlock(&cond->lock);
pthread_mutex_unlock(mutex);
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
int result = 0;
while ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) &&
futex(&elem.woken, op, 0, abstime) < 0 )
{
if ( errno == EINTR )
continue;
if ( errno != EAGAIN )
result = errno;
break;
}
pthread_mutex_lock(mutex);
pthread_mutex_lock(&cond->lock);
if ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) )
{
if ( elem.next )
elem.next->prev = elem.prev;
else
cond->last = elem.prev;
if ( elem.prev )
elem.prev->next = elem.next;
else
cond->first = elem.next;
}
pthread_mutex_unlock(&cond->lock);
return result;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2021, 2024 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
@ -17,51 +17,11 @@
* Waits on a condition or until a timeout happens.
*/
#include <sys/futex.h>
#include <errno.h>
#include <pthread.h>
int pthread_cond_timedwait(pthread_cond_t* restrict cond,
pthread_mutex_t* restrict mutex,
const struct timespec* restrict abstime)
{
struct pthread_cond_elem elem;
pthread_mutex_lock(&cond->lock);
elem.next = NULL;
elem.prev = cond->last;
elem.woken = 0;
if ( cond->last )
cond->last->next = &elem;
if ( !cond->first )
cond->first = &elem;
cond->last = &elem;
pthread_mutex_unlock(&cond->lock);
pthread_mutex_unlock(mutex);
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(cond->clock);
int result = 0;
while ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) &&
futex(&elem.woken, op, 0, abstime) < 0 )
{
if ( errno == EINTR )
continue;
if ( errno != EAGAIN )
result = errno;
break;
}
pthread_mutex_lock(mutex);
pthread_mutex_lock(&cond->lock);
if ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) )
{
if ( elem.next )
elem.next->prev = elem.prev;
else
cond->last = elem.prev;
if ( elem.prev )
elem.prev->next = elem.next;
else
cond->first = elem.next;
}
pthread_mutex_unlock(&cond->lock);
return result;
return pthread_cond_clockwait(cond, mutex, cond->clock, abstime);
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2013, 2014, 2021, 2024 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.
*
* pthread/pthread_mutex_clocklock.c
* Locks a mutex or waits for a timeout.
*/
#include <sys/futex.h>
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#include <stdbool.h>
static const int UNLOCKED = 0;
static const int LOCKED = 1;
static const int CONTENDED = 2;
int pthread_mutex_clocklock(pthread_mutex_t* mutex,
clockid_t clock,
const struct timespec* abstime)
{
int state = UNLOCKED;
int desired = LOCKED;
while ( !__atomic_compare_exchange_n(&mutex->lock, &state, desired, false,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) )
{
if ( mutex->type == PTHREAD_MUTEX_RECURSIVE &&
(pthread_t) mutex->owner == pthread_self() )
{
if ( mutex->recursion == ULONG_MAX )
return errno = EAGAIN;
mutex->recursion++;
return 0;
}
if ( state == LOCKED &&
!__atomic_compare_exchange_n(&mutex->lock, &state, CONTENDED,
false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST) )
{
state = UNLOCKED;
continue;
}
desired = CONTENDED;
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
if ( futex(&mutex->lock, op, CONTENDED, abstime) < 0 &&
errno != EAGAIN && errno != EINTR )
return errno;
state = UNLOCKED;
}
mutex->owner = (unsigned long) pthread_self();
mutex->recursion = 0;
return 0;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2014, 2021, 2024 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
@ -17,47 +17,9 @@
* Locks a mutex.
*/
#include <sys/futex.h>
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#include <stdbool.h>
static const int UNLOCKED = 0;
static const int LOCKED = 1;
static const int CONTENDED = 2;
int pthread_mutex_lock(pthread_mutex_t* mutex)
{
int state = UNLOCKED;
int desired = LOCKED;
while ( !__atomic_compare_exchange_n(&mutex->lock, &state, desired, false,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) )
{
if ( mutex->type == PTHREAD_MUTEX_RECURSIVE &&
(pthread_t) mutex->owner == pthread_self() )
{
if ( mutex->recursion == ULONG_MAX )
return errno = EAGAIN;
mutex->recursion++;
return 0;
}
if ( state == LOCKED &&
!__atomic_compare_exchange_n(&mutex->lock, &state, CONTENDED,
false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST) )
{
state = UNLOCKED;
continue;
}
desired = CONTENDED;
if ( futex(&mutex->lock, FUTEX_WAIT, CONTENDED, NULL) < 0 &&
errno != EAGAIN && errno != EINTR )
return errno;
state = UNLOCKED;
}
mutex->owner = (unsigned long) pthread_self();
mutex->recursion = 0;
return 0;
return pthread_mutex_timedlock(mutex, NULL);
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2013, 2014, 2021, 2024 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.
*
* pthread/pthread_mutex_timedlock.c
* Locks a mutex or waits for a timeout.
*/
#include <pthread.h>
int pthread_mutex_timedlock(pthread_mutex_t* mutex,
const struct timespec* abstime)
{
return pthread_mutex_clocklock(mutex, CLOCK_REALTIME, abstime);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2013, 2024 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.
*
* pthread/pthread_rwlock_clockrdlock.c
* Acquires read access to a read-write lock or waits for a timeout.
*/
#include <pthread.h>
int pthread_rwlock_clockrdlock(pthread_rwlock_t* rwlock, clockid_t clock,
const struct timespec* abstime)
{
pthread_mutex_lock(&rwlock->request_mutex);
rwlock->pending_readers++;
int ret = 0;
while ( !ret && (!rwlock->num_writers || rwlock->pending_writers) )
ret = pthread_cond_clockwait(&rwlock->reader_condition,
&rwlock->request_mutex, clock, abstime);
rwlock->pending_readers--;
if ( !ret )
rwlock->num_readers++;
pthread_mutex_unlock(&rwlock->request_mutex);
return ret;
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2013, 2024 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.
*
* pthread/pthread_rwlock_clockwrlock.c
* Acquires write access to a read-write lock or waits for a timeout.
*/
#include <pthread.h>
int pthread_rwlock_clocklock(pthread_rwlock_t* rwlock, clockid_t clock,
const struct timespec* abstime)
{
pthread_mutex_lock(&rwlock->request_mutex);
rwlock->pending_writers++;
int ret = 0;
while ( !ret && (rwlock->num_readers || rwlock->num_writers) )
ret = pthread_cond_clockwait(&rwlock->writer_condition,
&rwlock->request_mutex, clock, abstime);
rwlock->pending_writers--;
if ( !ret )
rwlock->num_writers = 1;
pthread_mutex_unlock(&rwlock->request_mutex);
return ret;
}

View file

@ -21,12 +21,5 @@
int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock)
{
pthread_mutex_lock(&rwlock->request_mutex);
rwlock->pending_readers++;
while ( rwlock->num_writers || rwlock->pending_writers )
pthread_cond_wait(&rwlock->reader_condition, &rwlock->request_mutex);
rwlock->pending_readers--;
rwlock->num_readers++;
pthread_mutex_unlock(&rwlock->request_mutex);
return 0;
return pthread_rwlock_timedrdlock(rwlock, NULL);
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2013, 2024 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.
*
* pthread/pthread_rwlock_timedrdlock.c
* Acquires read access to a read-write lock or waits for a timeout.
*/
#include <pthread.h>
int pthread_rwlock_timedrdlock(pthread_rwlock_t* rwlock,
const struct timespec* abstime)
{
return pthread_rwlock_clockrdlock(rwlock, CLOCK_REALTIME, abstime);
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2013, 2024 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.
*
* pthread/pthread_rwlock_timedwrlock.c
* Acquires write access to a read-write lock or waits for a timeout.
*/
#include <pthread.h>
int pthread_rwlock_timedrwlock(pthread_rwlock_t* rwlock,
const struct timespec* abstime)
{
return pthread_rwlock_clockwrlock(rwlock, CLOCK_REALTIME, abstime);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2024 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
@ -21,12 +21,5 @@
int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock)
{
pthread_mutex_lock(&rwlock->request_mutex);
rwlock->pending_writers++;
while ( rwlock->num_readers || rwlock->num_writers )
pthread_cond_wait(&rwlock->writer_condition, &rwlock->request_mutex);
rwlock->pending_writers--;
rwlock->num_writers = 1;
pthread_mutex_unlock(&rwlock->request_mutex);
return 0;
return pthread_rwlock_timedwrlock(rwlock, NULL);
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2014, 2021, 2024 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.
*
* semaphore/sem_clockwait.c
* Lock a semaphore with a timeout.
*/
#include <sys/futex.h>
#include <errno.h>
#include <semaphore.h>
#include <stdbool.h>
#include <time.h>
int sem_clockwait(sem_t* restrict sem, clockid_t clock,
const struct timespec* restrict abstime)
{
while ( true )
{
int old = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST);
int new = old != -1 ? old - 1 : -1;
bool waiting = new == -1;
if ( waiting )
__atomic_add_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
if ( old != new &&
!__atomic_compare_exchange_n(&sem->value, &old, new, false,
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED) )
{
if ( waiting )
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
continue;
}
if ( !waiting )
return 0;
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
int ret = futex(&sem->value, op, -1, abstime);
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
if ( ret < 0 && errno != EAGAIN )
return -1;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2021, 2024 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
@ -17,36 +17,9 @@
* Lock a semaphore with a timeout.
*/
#include <sys/futex.h>
#include <errno.h>
#include <semaphore.h>
#include <stdbool.h>
#include <time.h>
int sem_timedwait(sem_t* restrict sem, const struct timespec* restrict abstime)
{
while ( true )
{
int old = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST);
int new = old != -1 ? old - 1 : -1;
bool waiting = new == -1;
if ( waiting )
__atomic_add_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
if ( old != new &&
!__atomic_compare_exchange_n(&sem->value, &old, new, false,
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED) )
{
if ( waiting )
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
continue;
}
if ( !waiting )
return 0;
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(CLOCK_REALTIME);
int ret = futex(&sem->value, op, -1, abstime);
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
if ( ret < 0 && errno != EAGAIN )
return -1;
}
return sem_clockwait(sem, CLOCK_REALTIME, abstime);
}

68
libc/signal/sig2str.c Normal file
View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 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.
*
* signal/sig2str.c
* Get signal name.
*/
#include <signal.h>
#include <stdio.h>
#include <string.h>
int sig2str(int signum, char* str)
{
if ( SIGRTMIN < signum || signum < SIGRTMAX )
{
snprintf(str, SIG2STR_MAX, "RTMIN+%i", signum - SIGRTMIN);
return 0;
}
const char* name;
switch ( signum )
{
case SIGHUP: name = "HUP"; break;
case SIGINT: name = "INT"; break;
case SIGQUIT: name = "QUIT"; break;
case SIGILL: name = "ILL"; break;
case SIGTRAP: name = "TRAP"; break;
case SIGABRT: name = "ABRT"; break;
case SIGBUS: name = "BUS"; break;
case SIGFPE: name = "FPE"; break;
case SIGKILL: name = "KILL"; break;
case SIGUSR1: name = "USR1"; break;
case SIGSEGV: name = "SEGV"; break;
case SIGUSR2: name = "USR2"; break;
case SIGPIPE: name = "PIPE"; break;
case SIGALRM: name = "ALRM"; break;
case SIGTERM: name = "TERM"; break;
case SIGSYS: name = "SYS"; break;
case SIGCHLD: name = "CHLD"; break;
case SIGCONT: name = "CONT"; break;
case SIGSTOP: name = "STOP"; break;
case SIGTSTP: name = "TSTP"; break;
case SIGTTIN: name = "TTIN"; break;
case SIGTTOU: name = "TTOU"; break;
case SIGURG: name = "URG"; break;
case SIGXCPU: name = "XCPU"; break;
case SIGXFSZ: name = "XFSZ"; break;
case SIGVTALRM: name = "VTALRM"; break;
case SIGPWR: name = "PWR"; break;
case SIGWINCH: name = "WINCH"; break;
case SIGRTMIN: name = "RTMIN"; break;
case SIGRTMAX: name = "RTMAX"; break;
default: return -1;
}
strlcpy(str, name, SIG2STR_MAX);
return 0;
}

67
libc/signal/str2sig.c Normal file
View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2024 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.
*
* signal/str2sig.c
* Lookup signal by name.
*/
#include <signal.h>
#include <stdlib.h>
#include <string.h>
int str2sig(const char* signame, int* signum)
{
int ret;
if ( !strncmp(signame, "RTMIN+", strlen("RTMIN+")) ||
!strncmp(signame, "RTMAX-", strlen("RTMAX-")) )
{
// TODO: Stricter check.
int off = atoi(signame + 6);
if ( off < 1 || SIGRTMAX - SIGRTMIN <= off )
return -1;
ret = signame[5] == '+' ? SIGRTMIN + off : SIGRTMAX - off;
}
else if ( !strcmp(signame, "HUP") ) ret = SIGHUP;
else if ( !strcmp(signame, "INT") ) ret = SIGINT;
else if ( !strcmp(signame, "QUIT") ) ret = SIGQUIT;
else if ( !strcmp(signame, "ILL") ) ret = SIGILL;
else if ( !strcmp(signame, "TRAP") ) ret = SIGTRAP;
else if ( !strcmp(signame, "ABRT") ) ret = SIGABRT;
else if ( !strcmp(signame, "BUS") ) ret = SIGBUS;
else if ( !strcmp(signame, "FPE") ) ret = SIGFPE;
else if ( !strcmp(signame, "KILL") ) ret = SIGKILL;
else if ( !strcmp(signame, "USR1") ) ret = SIGUSR1;
else if ( !strcmp(signame, "SEGV") ) ret = SIGSEGV;
else if ( !strcmp(signame, "USR2") ) ret = SIGUSR2;
else if ( !strcmp(signame, "PIPE") ) ret = SIGPIPE;
else if ( !strcmp(signame, "ALRM") ) ret = SIGALRM;
else if ( !strcmp(signame, "TERM") ) ret = SIGTERM;
else if ( !strcmp(signame, "SYS") ) ret = SIGSYS;
else if ( !strcmp(signame, "CHLD") ) ret = SIGCHLD;
else if ( !strcmp(signame, "CONT") ) ret = SIGCONT;
else if ( !strcmp(signame, "STOP") ) ret = SIGSTOP;
else if ( !strcmp(signame, "TSTP") ) ret = SIGTSTP;
else if ( !strcmp(signame, "TTIN") ) ret = SIGTTIN;
else if ( !strcmp(signame, "TTOU") ) ret = SIGTTOU;
else if ( !strcmp(signame, "URG") ) ret = SIGURG;
else if ( !strcmp(signame, "XCPU") ) ret = SIGXCPU;
else if ( !strcmp(signame, "XFSZ") ) ret = SIGXFSZ;
else if ( !strcmp(signame, "VTALRM") ) ret = SIGVTALRM;
else if ( !strcmp(signame, "PWR") ) ret = SIGPWR;
else if ( !strcmp(signame, "WINCH") ) ret = SIGWINCH;
else return -1;
*signum = ret;
return 0;
}

41
libc/string/memmem.c Normal file
View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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.
*
* string/memmem.c
* Locate a subsequence.
*/
#include <string.h>
// TODO: Remember the fast algorithm and implemented it here and in strstr.
void* memmem(const void* haystack, size_t haystack_size,
const void* needle, size_t needle_size)
{
if ( !needle_size )
return (void*) haystack;
if ( haystack_size < needle_size )
return NULL;
for ( size_t i = 0; i < haystack_size - needle_size; i++ )
{
for ( size_t n = 0; n < needle_size; n++ )
{
if ( ((char*) haystack)[i + n] != ((char*) needle)[n] )
break;
if ( n + 1 == needle_size )
return (char*) haystack + i;
}
}
return NULL;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2016, 2020-2022 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2016, 2020-2022, 2024 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
@ -17,11 +17,10 @@
* Convert error code to a string.
*/
#define __SORTIX_STDLIB_REDIRECTS 0
#include <errno.h>
#include <string.h>
const char* sortix_strerror(int errnum)
char* strerror(int errnum)
{
switch ( errnum )
{
@ -112,11 +111,7 @@ const char* sortix_strerror(int errnum)
case ENOMOUNT: return "No such mountpoint";
case ENOMEDIUM: return "No medium found";
case EHOSTDOWN: return "Host is down";
case ESOCKTNOSUPPORT: "Socket type is not supported";
default: return "Unknown error condition";
}
}
char* strerror(int errnum)
{
return (char*) sortix_strerror(errnum);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2024 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
@ -17,16 +17,10 @@
* Convert error code to a string.
*/
#define __SORTIX_STDLIB_REDIRECTS 0
#include <string.h>
const char* sortix_strerror_l(int errnum, locale_t locale)
{
(void) locale;
return sortix_strerror(errnum);
}
char* strerror_l(int errnum, locale_t locale)
{
return (char*) sortix_strerror_l(errnum, locale);
(void) locale;
return (char*) strerror(errnum);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
* Copyright (c) 2011, 2012, 2013, 2014, 2024 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
@ -22,7 +22,7 @@
int strerror_r(int errnum, char* dest, size_t dest_len)
{
const char* msg = sortix_strerror(errnum);
const char* msg = strerror(errnum);
if ( !msg )
return -1;
if ( dest_len < strlen(msg) + 1 )

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2014, 2024 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
@ -17,11 +17,10 @@
* Convert signal number to a string.
*/
#define __SORTIX_STDLIB_REDIRECTS 0
#include <signal.h>
#include <string.h>
const char* sortix_strsignal(int signum)
char* strsignal(int signum)
{
switch ( signum )
{
@ -61,8 +60,3 @@ const char* sortix_strsignal(int signum)
return "Unknown signal value";
}
char* strsignal(int signum)
{
return (char*) sortix_strsignal(signum);
}

25
libc/unistd/_Fork.c Normal file
View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2011, 2012, 2024 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/_Fork.c
* Create a new task inheriting some properties from the current task.
*/
#include <unistd.h>
pid_t _Fork(void)
{
return sfork(SFFORK);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012 Jonas 'Sortie' Termansen.
* Copyright (c) 2011, 2012, 2024 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
@ -21,5 +21,5 @@
pid_t fork(void)
{
return sfork(SFFORK);
return _Fork();
}

View file

@ -773,8 +773,7 @@ static void think(struct glogin* state)
state->warning = strerror(errno);
}
}
// TODO: Find a method to detect what init is trying to do so we can display
// the appropriate message to the user.
if ( got_sigterm )
{
int exit_code = get_init_exit_plan();

View file

@ -259,6 +259,10 @@ bool login(const char* username, const char* session)
return free(login_shell), close(pipe_fds[0]), close(pipe_fds[1]), false;
if ( child_pid == 0 )
{
sigset_t sigterm;
sigemptyset(&sigterm);
sigaddset(&sigterm, SIGTERM);
sigprocmask(SIG_UNBLOCK, &sigterm, NULL);
sigdelset(&oldset, SIGINT);
sigdelset(&oldset, SIGQUIT);
sigdelset(&oldset, SIGTERM);
@ -285,7 +289,6 @@ bool login(const char* username, const char* session)
open("/dev/tty", O_WRONLY) != 2 ||
setcloexecfrom(3) < 0 ||
tcsetpgrp(0, getpgid(0)) ||
// TODO: Do this immediately? At least unblock SIGTERM.
sigprocmask(SIG_SETMASK, &oldset, NULL) < 0 ||
settermmode(0, TERMMODE_NORMAL) < 0 ||
(session ?
@ -311,7 +314,6 @@ bool login(const char* username, const char* session)
sigaction(SIGTERM, &sa, &old_sa);
sigprocmask(SIG_UNBLOCK, &sigterm, NULL);
// TODO: What happens if EINTR happens here? waitpid might block.
int errnum;
if ( readall(pipe_fds[0], &errnum, sizeof(errnum)) < (ssize_t) sizeof(errnum) )
errnum = 0;

View file

@ -91,6 +91,22 @@ and
.Xr setpgid 3
are the standard portable replacements without disagreement on the function
signatures.
.Ss getresgid, getresuid, setresgid, setresuid
These are not implemented yet as multi-user security is not yet implemented
in this operating system.
The kernel does not have a saved uid and saved gid concept at this time.
The
.Xr getuid 2 ,
.Xr getgid 2 ,
.Xr geteuid 2 ,
.Xr getegid 2 ,
.Xr setuid 2 ,
.Xr setgid 2 ,
.Xr seteuid 2 ,
and
.Xr setegid 2
system calls can be used to retrieve and manipulate the implemented concepts as
a workaround.
.Ss gettimeofday
.Xr gettimeofday 2
is implemented but the second parameter is defunct and is typed
@ -166,6 +182,61 @@ is implemented in
per POSIX, however some operating systems have a
.In sys/poll.h
alias which is not implemented.
.Ss posix_close
.Xr close 2
should be used instead.
POSIX 2024 defined this replacement interface because some broken legacy
operating systems could fail with
.Ev EINTR
in
.Xr close 2
on slow devices,
instead of returning 0 and either completing the operating in the background
or aborting it.
However, this means most programs need to be updated to use the more
complicated alternative function instead for no practical gain, which isn't
going to happen.
The standard has added a lot of complexity where none needs to exist, which
is rejected in this operating system.
.Xr close 2
never fails with
.Ev EINTR on this operating system.
.Ss posix_devctl
.Xr ioctl 2
should be used instead.
POSIX 2024 defined this optional function as a replacement for
.Xr ioctl 2
but never defined any way for portable applications to actually use it.
The
.Fa dev_info_ptr
parameter is especially useless as its semantics are not defined, and often
the desired output does not necessarily fit in an int type.
The
.Xr ioctl 2
interface is fine and this alternative function is rejected in this operating
system as it is optional in POSIX 2024.
.Ss posix_getdents
.Xr readdir 3
should be used instead.
.Xr readdirents 2
is a similar Sortix-specific system call that will likely be replaced with
something else in the future.
This new
.Ft posix_getdents
function is due to a mess of diverent
.Fn getdents
functions.
It is unfortunate they used
.Vt struct posix_dent
instead of
.Vt struct dirent
as they did not want to mandate the addition of the common
.Vt d_type
field in
.Vt struct dirent .
However,
.Vt posix_getdents
is decent and may be implemented in the future.
.Ss printf
.Xr printf 3
is implemented, however floating point formatting is not currently implemented