To get the changes on tree please make a pull request, I can mantain and update them from there if needed.
The ports to slibc are located in [source/ports], there, each port targets both
an architecture and OS, for example, aarch64-linux
. This target can be chosen
for compilation with the TARGET
Makefile variable.
There, in the chosen folder under [source/ports] a few items must be defined.
Given that we are trying to port to X-Y
, this are the items needed for a port
and their locations:
crt0.S
undersource/ports/X-Y/crt0.S
, which sets up arguments to call the__slibc_init
symbol, with the signaturevoid __slibc_init(int argc, char *argv[], char *envp[])
.- A series of C files implementing all the required functions, which are:
- POSIX-compatible
fcntl
. - POSIX-compatible
open
. - POSIX-compatible
close
. - POSIX-compatible
read
. - POSIX-compatible
write
. - POSIX-compatible
rmdir
. - POSIX-compatible
unlink
. - POSIX-compatible
getcwd
. - POSIX-compatible
fork
. - POSIX-compatible
_exit
. - POSIX-compatible
lseek
. - POSIX-compatible
sbrk
. - POSIX-compatible
stat
. - POSIX-compatible
fstat
. - POSIX-compatible
clock_gettime
. - POSIX-compatible
sched_yield
. - POSIX-compatible
access
. - POSIX-compatible
pipe
. - POSIX-compatible
getpid
. - POSIX-compatible
getppid
. - POSIX-compatible
getpgrp
. - POSIX-compatible
getgid
. - POSIX-compatible
setgid
. - POSIX-compatible
getegid
. - POSIX-compatible
getuid
. - POSIX-compatible
setuid
. - POSIX-compatible
geteuid
. - POSIX-compatible
execve
. - POSIX-compatible
nanosleep
. - POSIX-compatible
ttyname_r
. - POSIX-compatible
alarm
. - POSIX-compatible
kill
. - POSIX-compatible
ioctl
. - POSIX-compatible
tcgetattr
. - POSIX-compatible
tcsetattr
. - POSIX-compatible
tcflow
. - POSIX-compatible
fchmod
. - POSIX-compatible
times
. - All the desired optional functions.
- POSIX-compatible
- A declaration of
sys_siglist
andsys_nsig
.
The functions being syscalls or not does not matter as long as they express POSIX behaviour, this could be used to emulate POSIX behaviour on a non-POSIX syscall interface, for example.
- A
sys
directory undersource/ports/X-Y/sys
, which will be installed verbatim with the final instalation undersys
, containing:- The definition of the
errnoval.h
,fcntlval.h
,timeval.h
,statval.h
signalval.h
,termiosval.h
,timesval.h
andioctlval.h
headers, which define values taken by several functions that are by nature OS dependent. - The
types
header, since the types and values are part of the OS ABI. - Any desired optional headers. for optional declarations or values.
- The definition of the
For a more practical example, the x86_64-linux
is a complete documented
port that can be used as reference.
A few conditions are expected by the libc for its inner workings:
- File descriptors
0
,1
and2
must be already opened as they will serve asstdin
,stdout
andstderr
respectively.