libposix: deep refactor; add sys/posixly command
With these changes, libposix (and newlib) can run MirBSD Korn Shell.
This commit is contained in:
@ -30,12 +30,18 @@
|
||||
* #include <u.h>
|
||||
* #include <posix.h>
|
||||
*
|
||||
* Defining _LIBPOSIX_H before the include allow you to just get dirent
|
||||
* definition.
|
||||
* Defining _LIBPOSIX_H before the include allow you to just get
|
||||
* data structure definition.
|
||||
*/
|
||||
|
||||
#ifndef _LIBPOSIX_DIRENT
|
||||
#define _LIBPOSIX_DIRENT
|
||||
#ifndef _LIBPOSIX_DEF
|
||||
#define _LIBPOSIX_DEF
|
||||
|
||||
struct timespec
|
||||
{
|
||||
long tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
|
||||
/* dirent alias of stat(5) message.
|
||||
* We (ab)use the fact that both 9P and Jehanne are little endian.
|
||||
@ -75,13 +81,7 @@ struct __attribute__((__packed__)) dirent
|
||||
#define DT_SOCK 12
|
||||
#define DT_WHT 14
|
||||
|
||||
#endif /* _LIBPOSIX_DIRENT */
|
||||
|
||||
#ifndef _LIBPOSIX_H
|
||||
#define _LIBPOSIX_H
|
||||
|
||||
typedef unsigned long clock_t;
|
||||
|
||||
/* getrusage who */
|
||||
typedef enum PosixRUsages
|
||||
{
|
||||
PosixRUsageSelf = 0,
|
||||
@ -90,10 +90,170 @@ typedef enum PosixRUsages
|
||||
PosixRUsageUnknown = -1
|
||||
} PosixRUsages;
|
||||
|
||||
/* errno values */
|
||||
#define _ERRNO_H // skip the Posix part, we just need the enum
|
||||
#include <apw/errno.h>
|
||||
|
||||
/* signals */
|
||||
typedef unsigned long PosixSignalMask;
|
||||
|
||||
|
||||
typedef enum PosixSigProcMaskAction
|
||||
{
|
||||
PosixSPMSetMask = 0,
|
||||
PosixSPMBlock = 1,
|
||||
PosixSPMUnblock = 2
|
||||
} PosixSigProcMaskAction;
|
||||
|
||||
#define PosixNumberOfSignals (sizeof(PosixSignalMask)*7)
|
||||
typedef enum PosixSignals
|
||||
{
|
||||
PosixSIGABRT = 1,
|
||||
PosixSIGALRM,
|
||||
PosixSIGBUS,
|
||||
PosixSIGCHLD,
|
||||
PosixSIGCONT,
|
||||
PosixSIGFPE,
|
||||
PosixSIGHUP,
|
||||
PosixSIGILL,
|
||||
PosixSIGINT,
|
||||
PosixSIGKILL,
|
||||
PosixSIGPIPE,
|
||||
PosixSIGQUIT,
|
||||
PosixSIGSEGV,
|
||||
PosixSIGSTOP,
|
||||
PosixSIGTERM,
|
||||
PosixSIGTSTP,
|
||||
PosixSIGTTIN,
|
||||
PosixSIGTTOU,
|
||||
PosixSIGUSR1,
|
||||
PosixSIGUSR2,
|
||||
PosixSIGPOLL,
|
||||
PosixSIGPROF,
|
||||
PosixSIGSYS,
|
||||
PosixSIGTRAP,
|
||||
PosixSIGURG,
|
||||
PosixSIGVTALRM,
|
||||
PosixSIGXCPU,
|
||||
PosixSIGXFSZ,
|
||||
|
||||
/* Optional Signals */
|
||||
PosixSIGIOT,
|
||||
PosixSIGEMT,
|
||||
PosixSIGSTKFLT,
|
||||
PosixSIGIO,
|
||||
PosixSIGPWR,
|
||||
PosixSIGINFO,
|
||||
PosixSIGLOST,
|
||||
PosixSIGWINCH,
|
||||
PosixSIGUNUSED,
|
||||
|
||||
PosixSIGRTMIN,
|
||||
PosixSIGRTMAX = PosixNumberOfSignals
|
||||
} PosixSignals;
|
||||
|
||||
typedef enum PosixSigActionFlags
|
||||
{
|
||||
/* supported flags */
|
||||
PosixSAFSigInfo = 1<<0,
|
||||
PosixSAFRestart = 1<<1,
|
||||
PosixSAFNoChildrenStop = 1<<2,
|
||||
PosixSAFResetHandler = 1<<3,
|
||||
PosixSAFNoChildrenWait = 1<<4,
|
||||
|
||||
/* ignored flags */
|
||||
PosixSAFNoDefer = 1<<16, /* notes are not reentrant */
|
||||
PosixSAFOnStack = 1<<17,
|
||||
PosixSAFDisable = 1<<18
|
||||
} PosixSigActionFlags;
|
||||
|
||||
typedef enum PosixSigInfoCodes
|
||||
{
|
||||
PosixSIUser = 1,
|
||||
PosixSIQueue,
|
||||
PosixSITimer,
|
||||
PosixSIAsyncIO,
|
||||
PosixSIMsgQueued,
|
||||
|
||||
PosixSIFaultMapError,
|
||||
PosixSIFaultAccessError,
|
||||
|
||||
PosixSIChildExited,
|
||||
PosixSIChildKilled,
|
||||
PosixSIChildDumped,
|
||||
PosixSIChildTrapped,
|
||||
PosixSIChildStopped,
|
||||
PosixSIChildContinued
|
||||
} PosixSigInfoCodes;
|
||||
|
||||
union sigval {
|
||||
int sival_int; /* Integer signal value */
|
||||
void* sival_ptr; /* Pointer signal value */
|
||||
void* _si_addr; /* Address of faulting address */
|
||||
int _si_status; /* Child exit status */
|
||||
uintptr_t _sival_raw; /* Raw value */
|
||||
};
|
||||
|
||||
struct sigevent {
|
||||
int sigev_notify; /* Notification type */
|
||||
int sigev_signo; /* Signal number */
|
||||
union sigval sigev_value; /* Signal value */
|
||||
void (*sigev_notify_function)( union sigval );
|
||||
/* Notification function */
|
||||
long *sigev_notify_attributes; /* Notification Attributes */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int si_signo; /* Signal number */
|
||||
int si_code; /* Cause of the signal */
|
||||
int si_errno;
|
||||
int si_pid; /* Pid of sender */
|
||||
int si_uid; /* Uid of sender */
|
||||
union sigval si_value; /* Signal value */
|
||||
} PosixSignalInfo;
|
||||
|
||||
#define si_addr si_value._si_addr
|
||||
#define si_status si_value._si_status
|
||||
|
||||
typedef void (*PosixSigHandler)(int);
|
||||
typedef void (*PosixSigAction)(int, PosixSignalInfo *, void * );
|
||||
|
||||
struct sigaction {
|
||||
int sa_flags; /* Special flags to affect behavior of signal */
|
||||
PosixSignalMask sa_mask; /* Additional set of signals to be blocked */
|
||||
/* during execution of signal-catching */
|
||||
/* function. */
|
||||
union {
|
||||
PosixSigHandler _handler; /* SIG_DFL, SIG_IGN, or pointer to a function */
|
||||
PosixSigAction _sigaction;
|
||||
} _signal_handlers;
|
||||
};
|
||||
|
||||
#define sa_handler _signal_handlers._handler
|
||||
#define sa_sigaction _signal_handlers._sigaction
|
||||
|
||||
typedef enum PosixFDCmds
|
||||
{
|
||||
PosixFDCDupFD = 1,
|
||||
PosixFDCDupFDCloseOnExec,
|
||||
PosixFDCGetFD,
|
||||
PosixFDCSetFD,
|
||||
PosixFDCGetFL,
|
||||
PosixFDCSetFL
|
||||
} PosixFDCmds;
|
||||
|
||||
#endif /* _LIBPOSIX_DEF */
|
||||
|
||||
#ifndef _LIBPOSIX_H
|
||||
#define _LIBPOSIX_H
|
||||
|
||||
typedef unsigned long clock_t;
|
||||
|
||||
#define __POSIX_EXIT_PREFIX "posix error "
|
||||
#define __POSIX_EXIT_SIGNAL_PREFIX "terminated by posix signal "
|
||||
#define __POSIX_SIGNAL_PREFIX "posix: "
|
||||
|
||||
extern unsigned int POSIX_alarm(int *errnop, unsigned int seconds);
|
||||
extern int POSIX_access(int *errnop, const char *path, int amode);
|
||||
extern int POSIX_dup(int *errnop, int fildes);
|
||||
extern int POSIX_dup2(int *errnop, int fildes, int fildes2);
|
||||
@ -134,6 +294,8 @@ extern int POSIX_waitpid(int *errnop, int pid, int *status, int options);
|
||||
extern long POSIX_write(int *errnop, int fd, const void *buf, size_t len);
|
||||
extern int POSIX_gettimeofday(int *errnop, void *timeval, void *timezone);
|
||||
extern char* POSIX_getenv(int *errnop, const char *name);
|
||||
extern int POSIX_setenv(int *errno, const char *name, const char *value, int overwrite);
|
||||
extern int POSIX_unsetenv(int *errnop, const char *name);
|
||||
extern void *POSIX_sbrk(int *errnop, ptrdiff_t incr);
|
||||
extern void * POSIX_malloc(int *errnop, size_t size);
|
||||
extern void *POSIX_realloc(int *errnop, void *ptr, size_t size);
|
||||
@ -142,6 +304,19 @@ extern void POSIX_free(void *ptr);
|
||||
extern unsigned int POSIX_sleep(unsigned int seconds);
|
||||
extern int POSIX_pipe(int *errnop, int fildes[2]);
|
||||
extern int POSIX_umask(int *errnop, int mask);
|
||||
extern int POSIX_fcntl(int *errnop, int fd, PosixFDCmds cmd, uintptr_t arg);
|
||||
|
||||
extern int POSIX_sigaddset(int *errnop, PosixSignalMask *set, int signo);
|
||||
extern int POSIX_sigdelset(int *errnop, PosixSignalMask *set, int signo);
|
||||
extern int POSIX_sigismember(int *errnop, const PosixSignalMask *set, int signo);
|
||||
extern int POSIX_sigfillset(int *errnop, PosixSignalMask *set);
|
||||
extern int POSIX_sigemptyset(int *errnop, PosixSignalMask *set);
|
||||
extern int POSIX_sigprocmask(int *errnop, PosixSigProcMaskAction how, const PosixSignalMask *set, PosixSignalMask *oset);
|
||||
extern int POSIX_sigpending(int *errnop, PosixSignalMask *set);
|
||||
extern int POSIX_sigsuspend(int *errnop, const PosixSignalMask *mask);
|
||||
extern int POSIX_sigaction(int *errnop, int signo, const struct sigaction *act, struct sigaction *old);
|
||||
extern int POSIX_sigtimedwait(int *errnop, const PosixSignalMask *set, PosixSignalInfo *info, const struct timespec *timeout);
|
||||
extern int POSIX_sigqueue(int *errnop, int pid, int signo, const union sigval value);
|
||||
|
||||
extern int POSIX_getuid(int *errnop);
|
||||
extern int POSIX_geteuid(int *errnop);
|
||||
@ -159,72 +334,26 @@ extern int POSIX_setpgid(int *errnop, int pid, int pgid);
|
||||
extern int POSIX_getsid(int *errnop, int pid);
|
||||
extern int POSIX_setsid(int *errnop);
|
||||
|
||||
extern int POSIX_tcgetpgrp(int *errnop, int fd);
|
||||
extern int POSIX_tcsetpgrp(int *errnop, int fd, int pgrp);
|
||||
|
||||
extern int libposix_getdents(int *errnop, int fd, char *buf, int buf_bytes);
|
||||
extern PosixError libposix_translate_kernel_errors(const char *msg);
|
||||
|
||||
/* Library initialization
|
||||
*/
|
||||
#define _ERRNO_H // skip the Posix part, we just need the enum
|
||||
#include <apw/errno.h>
|
||||
|
||||
typedef enum PosixSignals
|
||||
{
|
||||
PosixSIGABRT = 1,
|
||||
PosixSIGALRM,
|
||||
PosixSIGBUS,
|
||||
PosixSIGCHLD,
|
||||
PosixSIGCONT,
|
||||
PosixSIGFPE,
|
||||
PosixSIGHUP,
|
||||
PosixSIGILL,
|
||||
PosixSIGINT,
|
||||
PosixSIGKILL,
|
||||
PosixSIGPIPE,
|
||||
PosixSIGQUIT,
|
||||
PosixSIGSEGV,
|
||||
PosixSIGSTOP,
|
||||
PosixSIGTERM,
|
||||
PosixSIGTSTP,
|
||||
PosixSIGTTIN,
|
||||
PosixSIGTTOU,
|
||||
PosixSIGUSR1,
|
||||
PosixSIGUSR2,
|
||||
PosixSIGPOLL,
|
||||
PosixSIGPROF,
|
||||
PosixSIGSYS,
|
||||
PosixSIGTRAP,
|
||||
PosixSIGURG,
|
||||
PosixSIGVTALRM,
|
||||
PosixSIGXCPU,
|
||||
PosixSIGXFSZ,
|
||||
|
||||
/* Optional Signals */
|
||||
PosixSIGIOT,
|
||||
PosixSIGEMT,
|
||||
PosixSIGSTKFLT,
|
||||
PosixSIGIO,
|
||||
PosixSIGCLD,
|
||||
PosixSIGPWR,
|
||||
PosixSIGINFO,
|
||||
PosixSIGLOST,
|
||||
PosixSIGWINCH,
|
||||
PosixSIGUNUSED,
|
||||
|
||||
PosixNumberOfSignals
|
||||
} PosixSignals;
|
||||
|
||||
/* Initialize libposix. Should call
|
||||
*
|
||||
* libposix_define_errno to set the value of each PosixError
|
||||
* libposix_define_signal to set the value of each PosixSignal
|
||||
* libposix_define_at_fdcwd to set the value of AT_FDCWD (for fchmodat)
|
||||
* libposix_translate_error to translate error strings to PosixError
|
||||
* libposix_set_signal_trampoline to dispatch signal received as notes
|
||||
* libposix_set_stat_reader
|
||||
* libposix_set_tms_reader
|
||||
* libposix_set_timeval_reader
|
||||
* libposix_set_timezone_reader
|
||||
*/
|
||||
typedef void (*PosixInit)(void);
|
||||
typedef void (*PosixInit)(int argc, char *argv[]);
|
||||
extern void libposix_init(int argc, char *argv[], PosixInit init) __attribute__((noreturn));
|
||||
|
||||
/* Translate an error string to a PosixError, in the context of the
|
||||
@ -327,23 +456,11 @@ typedef char* (*PosixExitStatusTranslator)(int status);
|
||||
|
||||
extern int libposix_translate_exit_status(PosixExitStatusTranslator translator);
|
||||
|
||||
/* Dispatch the signal to the registered handlers.
|
||||
/* Execute process disposition (executed when main returns)
|
||||
*/
|
||||
typedef enum PosixSignalAction
|
||||
{
|
||||
SignalCatched = 1,
|
||||
SignalIgnored,
|
||||
SignalError,
|
||||
SignalDefault
|
||||
} PosixSignalAction;
|
||||
typedef PosixSignalAction (*PosixSignalTrampoline)(int signal);
|
||||
|
||||
extern int libposix_set_signal_trampoline(PosixSignalTrampoline trampoline);
|
||||
|
||||
extern int libposix_define_signal(PosixSignals signal, int code);
|
||||
|
||||
extern int libposix_define_realtime_signals(int sigrtmin, int sigrtmax);
|
||||
typedef void (*PosixProcessDisposer)(int status);
|
||||
|
||||
extern int libposix_on_process_disposition(PosixProcessDisposer dispose);
|
||||
|
||||
/* Enable SIGCHLD emulation
|
||||
*/
|
||||
|
Reference in New Issue
Block a user