From: John Hodge Date: Tue, 14 May 2013 04:14:19 +0000 (+0800) Subject: Usermode - POSIX and C conformance changes X-Git-Tag: rel0.15~487 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=e91f60e14b8857312238d729fa580d6ab44ba27a Usermode - POSIX and C conformance changes --- diff --git a/Tools/GCCProxy/gccproxy.sh b/Tools/GCCProxy/gccproxy.sh index 0dd68644..801a1f1b 100755 --- a/Tools/GCCProxy/gccproxy.sh +++ b/Tools/GCCProxy/gccproxy.sh @@ -73,7 +73,9 @@ while [[ $# -gt 0 ]]; do done run() { - #echo --- $* + if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then + echo --- $* + fi $* return $? } @@ -101,7 +103,7 @@ elif [[ $_compile -eq 1 ]]; then elif echo " $_miscargs" | grep '\.c' >/dev/null; then tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir` run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout - run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $LIBGCC_PATH $_libs + run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH _rv=$? rm $tmpout exit $_rv diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index 1a1fc7be..ced39440 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) // If no directory was passed (we want to use the mount list) // or we are not root (we need to use the mount list) // Check the mount list - if(sDir == NULL || getuid() != 0) + if(sDir == NULL || _SysGetUID() != 0) { // Check if it is defined in the mounts file // - At this point sDevice could be a device name or a mount point diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index a4346eb9..c3cb7b14 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -6,9 +6,9 @@ MAKEDEP = $(CC) -M ifeq ($(ARCHDIR),native) -ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 -LDFLAGS := -lacess-native -#CPPFLAGS := -D SoMain="__attribute__ ((constructor(101))) libacessnative_init" + ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 + LDFLAGS := -lacess-native + #CPPFLAGS := -D SoMain="__attribute__ ((constructor(101))) libacessnative_init" ifeq ($(PLATFORM),windows) else LDFLAGS += -Wl,-init,SoMain diff --git a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h index c7a7215c..8ed66842 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -11,9 +11,9 @@ SYSCALL1(_SysWaitEvent, SYS_WAITEVENT) SYSCALL2(_SysWaitTID, SYS_WAITTID) SYSCALL0(gettid, SYS_GETTID) -SYSCALL0(getpid, SYS_GETPID) -SYSCALL0(getuid, SYS_GETUID) -SYSCALL0(getgid, SYS_GETGID) +SYSCALL0(_SysGetPID, SYS_GETPID) +SYSCALL0(_SysGetUID, SYS_GETUID) +SYSCALL0(_SysGetGID, SYS_GETGID) SYSCALL1(setuid, SYS_SETUID) SYSCALL1(setgid, SYS_SETGID) @@ -43,6 +43,7 @@ SYSCALL2(_SysOpen, SYS_OPEN) // char*, int SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int SYSCALL3(_SysReopen, SYS_REOPEN) // int, char*, int SYSCALL2(_SysCopyFD, SYS_COPYFD) // int, int +SYSCALL3(_SysFDFlags, SYS_FDCTL) // int, int, int SYSCALL1(_SysClose, SYS_CLOSE) // int SYSCALL3(_SysRead, SYS_READ) // int, uint, void* SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void* diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h index 21e40ae0..d45ffb64 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h @@ -55,7 +55,7 @@ extern int _SysClone(int flags, void *stack); extern int _SysExecVE(const char *path, char **argv, char **envp); extern int _SysSpawn(const char *Path, const char **argv, const char **envp, int nFDs, int *FDs, struct s_sys_spawninfo *info); extern int gettid(void); -extern int getpid(void); +extern int _SysGetPID(void); extern int _SysSetFaultHandler(int (*Handler)(int)); extern void _SysSetName(const char *Name); extern int _SysGetName(char *NameDest); @@ -64,8 +64,8 @@ extern int _SysSetPri(int Priority); extern int64_t _SysTimestamp(void); // --- Permissions --- -extern int getuid(void); -extern int getgid(void); +extern int _SysGetUID(void); +extern int _SysGetGID(void); extern void setuid(int id); extern void setgid(int id); @@ -78,6 +78,7 @@ extern int _SysOpenChild(int fd, const char *name, int flags); extern int _SysOpenPipe(int *read, int *write, int flags); extern int _SysReopen(int fd, const char *path, int flags); extern int _SysCopyFD(int srcfd, int dstfd); +extern int _SysFDFlags(int fd, int mask, int newflags); extern size_t _SysRead(int fd, void *buffer, size_t length); extern int _SysClose(int fd); extern int _SysFDCtl(int fd, int option, ...); @@ -90,7 +91,7 @@ extern int _SysReadDir(int fd, char *dest); extern int _SysGetACL(int fd, t_sysACL *dest); extern int _SysMount(const char *Device, const char *Directory, const char *Type, const char *Options); extern int _SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *err, int64_t *timeout, unsigned int extraevents); -#define select(nfs, rdfds, wrfds, erfds, timeout) _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0) +//#define select(nfs, rdfds, wrfds, erfds, timeout) _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0) extern int _SysUnlink(const char *pathname); // --- IPC --- diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index be6e08aa..60b86cd2 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -12,7 +12,7 @@ INCFILES := stdio.h stdlib.h OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o rand.o OBJ += perror.o scanf.o signals.o strtoi.o strtof.o -OBJ += printf.o +OBJ += printf.o time.o OBJ += arch/$(ARCHDIR).ao # signals.o DEPFILES := $(OBJ:%.o=%.d) diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h index 67ca3519..1aeb879b 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h @@ -20,6 +20,7 @@ enum { ENODEV, // ??? EADDRNOTAVAIL, // ? EINPROGRESS, // ? + EROFS, EAGAIN, // Try again diff --git a/Usermode/Libraries/libc.so_src/include_exp/signal.h b/Usermode/Libraries/libc.so_src/include_exp/signal.h index da6d78fd..03816f32 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/signal.h +++ b/Usermode/Libraries/libc.so_src/include_exp/signal.h @@ -10,6 +10,7 @@ typedef void (*sighandler_t)(int); +#define SIG_IGN ((void*)1) #define SIG_DFL ((void*)0) #define SIG_ERR ((void*)-1) diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdio.h b/Usermode/Libraries/libc.so_src/include_exp/stdio.h index 70e71388..fed2e97a 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdio.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdio.h @@ -69,6 +69,7 @@ extern int fileno(FILE *stream); extern size_t fread(void *buf, size_t size, size_t n, FILE *fp); extern size_t fwrite(const void *buf, size_t size, size_t n, FILE *fp); extern int fgetc(FILE *fp); +#define getc(fp) fgetc(fp) extern char *fgets(char *s, int size, FILE *fp); extern int fputc(int ch, FILE *fp); extern int fputs(const char *s, FILE *fp); diff --git a/Usermode/Libraries/libc.so_src/include_exp/time.h b/Usermode/Libraries/libc.so_src/include_exp/time.h index 5d728cea..ce693267 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/time.h +++ b/Usermode/Libraries/libc.so_src/include_exp/time.h @@ -28,7 +28,9 @@ struct tm typedef signed long long clock_t; -extern clock_t clock(); +extern clock_t clock(void); + +extern time_t time(time_t *t); #endif diff --git a/Usermode/Libraries/libc.so_src/strtoi.c b/Usermode/Libraries/libc.so_src/strtoi.c index 9326fb8a..81af4601 100644 --- a/Usermode/Libraries/libc.so_src/strtoi.c +++ b/Usermode/Libraries/libc.so_src/strtoi.c @@ -132,3 +132,19 @@ int atoi(const char *str) } return tmp; } + +long atol(const char *str) +{ + long long tmp = strtoll(str, NULL, 0); + if( tmp > LONG_MAX || tmp < LONG_MIN ) { + errno = ERANGE; + return (tmp > LONG_MAX) ? LONG_MAX : LONG_MIN; + } + return tmp; +} + +long atoll(const char *str) +{ + long long tmp = strtoll(str, NULL, 0); + return tmp; +} diff --git a/Usermode/Libraries/libc.so_src/time.c b/Usermode/Libraries/libc.so_src/time.c new file mode 100644 index 00000000..aa4b2de8 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/time.c @@ -0,0 +1,22 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * time.c + * - POSIX/stdc time functions + */ +#include +#include + +clock_t clock(void) +{ + return _SysTimestamp(); +} + +time_t time(time_t *t) +{ + time_t ret = _SysTimestamp() / 1000; + if(t) + *t = ret; + return ret; +} diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index 628999c3..b1f02570 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -8,7 +8,8 @@ CFLAGS += -Werror -Wextra ASFLAGS += LDFLAGS += -soname libposix.so -Map map.txt -lc -OBJ = main.o unistd.o dirent.o stat.o +OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o +OBJ += pwd.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h index daababb4..bdb54226 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h @@ -9,22 +9,27 @@ #ifndef _FCNTL_H_ #define _FCNTL_H_ -//#include - -// Hacks to handle different behaviors in Acess - -// Open doesn't take a chmod -//#define open(_1,_2,...) open(_1, _2) - -// Close returns void -//#define close(_1) (close(_1),0) - -// Acess doesn't implement lseek -#define lseek(_1,_2,_3) (seek(_1,_2,_3),tell(_1)) +struct flock +{ + short l_type; + short l_whece; + off_t l_start; + off_t l_len; + pid_t l_pid; +}; enum e_fcntl_cmds { - F_SETFL + F_DUPFD, // (long) + //F_DUPFD_CLOEXEC, // (long) - Non POSIX + F_GETFD, // (void) + F_SETFD, // (long) + F_GETFL, // (void) + F_SETFL, // (long) + + F_SETLK, // (struct flock *) + F_SETLKW, // (struct flock *) + F_GETLK, // (struct flock *) }; static inline int fcntl(int fd __attribute__((unused)), int cmd __attribute__((unused)), ...) { return -1; } diff --git a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h index ae4bf077..9d2e2990 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h @@ -8,6 +8,7 @@ #ifndef _LIBPOSIX__PWD_H_ #define _LIBPOSIX__PWD_H_ +#include // size_t #include // gid_t/uid_t struct passwd diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h index 16cdd40a..e4807ec8 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h @@ -8,7 +8,7 @@ #ifndef _LIBPOSIX__IOCTL_H_ #define _LIBPOSIX__IOCTL_H_ - +extern int ioctl(int d, int request, ...); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h index cf2f1aaf..f31e583e 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h @@ -11,7 +11,7 @@ #include #include -extern int select(int nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout); +extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *execptfds, struct timeval *timeout); // TODO: pselect? #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h index c5749281..be5ceb34 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h @@ -55,5 +55,6 @@ struct stat extern int stat(const char *path, struct stat *buf); extern int lstat(const char *path, struct stat *buf); extern int fstat(int fd, struct stat *buf); +extern int mkdir(const char *pathname, mode_t mode); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h index 5cd28762..7a734a5a 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h @@ -8,6 +8,8 @@ #ifndef _LIBPOSIX__SYS__TIME_H_ #define _LIBPOSIX__SYS__TIME_H_ +#include + typedef unsigned long suseconds_t; struct timeval diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h index 03e24ddc..c6cdc020 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h @@ -11,6 +11,8 @@ typedef unsigned int u_int; typedef struct stat t_fstat; +typedef unsigned long uid_t; +typedef unsigned long gid_t; typedef unsigned int id_t; typedef unsigned long pid_t; typedef unsigned long tid_t; diff --git a/Usermode/Libraries/libposix.so_src/include_exp/termios.h b/Usermode/Libraries/libposix.so_src/include_exp/termios.h index a200f2c4..bb3cf884 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/termios.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/termios.h @@ -131,5 +131,27 @@ struct termios cc_t c_cc[NCCS]; }; +extern int tcgetattr(int fd, struct termios *termios_p); + +#define TCSANOW 0x01 +#define TCSADRAIN 0x02 +#define TCSAFLUSH 0x04 +extern int tcsetattr(int fd, int optional_actions, const struct termios *termios_p); + +// ioctl() calls for terminals +enum +{ + TIOCGWINSZ, + TIOCSWINSZ +}; + +struct winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; /* unused */ + unsigned short ws_ypixel; /* unused */ +}; + + #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h index ea107a9d..81124c4d 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -45,5 +45,34 @@ extern int execv(const char *b, char *v[]); extern int dup2(int oldfd, int newfd); +extern int chown(const char *path, uid_t owner, gid_t group); + +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00300 +#define S_IXUSR 00100 +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 +#define S_IRWXO 0007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 +extern int chmod(const char *path, mode_t mode); + +extern uid_t getuid(void); +extern uid_t geteuid(void); +extern pid_t getpid(void); + +// signal.h / sys/types.h +#define SIGWINCH 101 +#define SIGTSTP 102 +extern int kill(pid_t pid, int sig); + + #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h b/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h new file mode 100644 index 00000000..8593a994 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h @@ -0,0 +1,49 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * utmpx.h + * - User login records + */ +#ifndef _LIBPOSIX__UTMPX_H_ +#define _LIBPOSIX__UTMPX_H_ + +#include // struct timeval + +#define UTMPX_FILE "/Acess/var/utmpx" + +enum e_utmpx_type_vals +{ + EMPTY, //!< No information + BOOT_TIME, //!< Identifies time of system boot + OLD_TIME, //!< Old time when system time was changed + NEW_TIME, //!< New time when system time was changed + USER_PROCESS, //!< Any process + INIT_PROCESS, //!< Process spawned by init + LOGIN_PROCESS, //!< Session leader for a logged-in user + DEAD_PROCESS //!< Exited session leader +}; + +#define UT_USER_MAX 32 +#define UT_ID_MAX 8 +#define UT_LINE_MAX 32 + +struct utmpx +{ + char ut_user[UT_USER_MAX]; + char ut_id[UT_ID_MAX]; + char ut_line[UT_LINE_MAX]; + pid_t ut_pid; + short ut_type; + struct timeval ut_tv; +}; + +extern void endutxent(void); +extern struct utmpx *getutxent(void); +extern struct utmpx *getutxid(const struct utmpx *); +extern struct utmpx *getutxline(const struct utmpx *); +extern struct utmpx *pututxline(const struct utmpx *); +extern void setutxent(void); + +#endif + diff --git a/Usermode/Libraries/libposix.so_src/pwd.c b/Usermode/Libraries/libposix.so_src/pwd.c new file mode 100644 index 00000000..99c4f5d1 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/pwd.c @@ -0,0 +1,96 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * pwd.c + * - Password Structure + */ +#include +#include +#include + +// TODO: Parse something like '/Acess/Conf/Users' + +// === GLOBALS === +static const struct passwd gPwd_RootInfo = { + .pw_name = "root", + .pw_uid = 0, + .pw_gid = 0, + .pw_dir = "/Acess/Root", + .pw_shell = "/Acess/Bin/CLIShell", + .pw_passwd = "", +}; + +// === CODE === +struct passwd *getpwnam(const char *name) +{ + static struct passwd ret_struct; + static char ret_buf[64]; + struct passwd *ret_ptr; + errno = getpwnam_r(name, &ret_struct, ret_buf, sizeof(ret_buf), &ret_ptr); + return ret_ptr; +} + +struct passwd *getpwuid(uid_t uid) +{ + static struct passwd ret_struct; + static char ret_buf[64]; + struct passwd *ret_ptr; + errno = getpwuid_r(uid, &ret_struct, ret_buf, sizeof(ret_buf), &ret_ptr); + return ret_ptr; +} + +static int fill_pwd(const struct passwd *tpl, struct passwd *pwd, char *buf, size_t buflen) +{ + size_t ofs = 0; + #define _setstr(field) do { \ + if( ofs + strlen(tpl->field)+1 > buflen ) \ + return ERANGE; \ + pwd->field = buf + ofs; \ + strcpy(pwd->field, tpl->field); \ + } while(0) + _setstr(pw_name); + pwd->pw_uid = tpl->pw_uid; + pwd->pw_gid = tpl->pw_gid; + _setstr(pw_dir); + _setstr(pw_shell); + _setstr(pw_passwd); + return 0; +} + +int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) +{ + *result = NULL; + if( strcmp(name, "root") == 0 ) { + int ret = fill_pwd(&gPwd_RootInfo, pwd, buf, buflen); + if(ret) return ret; + *result = pwd; + } + return 0; +} + +int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) +{ + *result = NULL; + if( uid == 0 ) { + int ret = fill_pwd(&gPwd_RootInfo, pwd, buf, buflen); + if(ret) return ret; + *result = pwd; + } + return 0; +} + +void endpwent(void) +{ +} + +struct passwd *getpwent(void) +{ + return NULL; +} + +void setpwent(void) +{ + +} + diff --git a/Usermode/Libraries/libposix.so_src/termios.c b/Usermode/Libraries/libposix.so_src/termios.c new file mode 100644 index 00000000..0e8e3564 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/termios.c @@ -0,0 +1,43 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * termios.c + * - Terminal Control + */ +#include +#include +#include + +// === CODE === +int tcgetattr(int fd, struct termios *termios_p) +{ + if( fd == -1 ) { + errno = EBADF; + return -1; + } + // Double-check `fd` describes a terminal + + // Fill defaults + memset(termios_p, 0, sizeof(struct termios)); + + // Query kernel for other params + + return 0; +} + +int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) +{ + if( fd == -1 ) { + errno = EBADF; + return -1; + } + + if( !termios_p || (optional_actions & ~(7)) ) { + errno = EINVAL; + return -1; + } + + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 68c4e522..9234319e 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -8,6 +8,7 @@ #include #include #include +#include // === CODE === int unlink(const char *pathname) @@ -85,9 +86,56 @@ int execv(const char *b, char *v[]) return _SysExecVE(b, v, NULL); } +int dup(int oldfd) +{ + // NOTE: Acess's CopyFD doesn't cause offset sharing + // TODO: Check that -1 does cause a new allocation + return _SysCopyFD(oldfd, -1); +} + int dup2(int oldfd, int newfd) { // NOTE: Acess's CopyFD doesn't cause offset sharing return _SysCopyFD(oldfd, newfd); } +pid_t getpid(void) +{ + return _SysGetPID(); +} + +uid_t getuid(void) +{ + return _SysGetUID(); +} + +int kill(pid_t pid, int signal) +{ + // TODO: Need special handling? + return _SysKill(pid, signal); +} + +int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout) +{ + + if( timeout ) + { + long long int ltimeout = 0; + ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000; + int ret = _SysSelect(nfd, rfd, wfd, efd, <imeout, 0); + return ret; + } + else + { + return _SysSelect(nfd, rfd, wfd, efd, NULL, 0); + } +} + +int pipe(int pipefd[2]) +{ + pipefd[0] = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + pipefd[1] = _SysCopyFD(pipefd[0], -1); + _SysFDFlags(pipefd[1], OPENFLAG_READ|OPENFLAG_WRITE, OPENFLAG_WRITE); + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/utmpx.c b/Usermode/Libraries/libposix.so_src/utmpx.c new file mode 100644 index 00000000..ef63c921 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/utmpx.c @@ -0,0 +1,52 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * utmpx.c + * - User login records + */ +#include +#include + +/* + * Rewind UTMPX file pointer + */ +void setutxent(void) +{ +} + +/* + * Close UTMPX file + */ +void endutxent(void) +{ +} + +/* + * Read from current position in UTMPX file + */ +struct utmpx *getutxent(void) +{ + return NULL; +} + +/* + * Locate an entry in the UTMPX file for a given id + */ +struct utmpx *getutxid(const struct utmpx *utmpx __attribute__((unused))) +{ + return NULL; +} + +struct utmpx *getutxline(const struct utmpx *utmpx __attribute__((unused))) +{ + utmpx = NULL; + return NULL; +} + +struct utmpx *pututxline(const struct utmpx *utmpx __attribute__((unused))) +{ + utmpx = NULL; + return NULL; +} + diff --git a/Usermode/Libraries/libpsocket.so_src/socket.c b/Usermode/Libraries/libpsocket.so_src/socket.c index 613e82b7..e2521ad3 100644 --- a/Usermode/Libraries/libpsocket.so_src/socket.c +++ b/Usermode/Libraries/libpsocket.so_src/socket.c @@ -227,3 +227,24 @@ int send(int sockfd, void *buffer, size_t length, int flags) return _SysWrite(sockfd, buffer, length); } + +int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len) +{ + return 0; +} + +int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len) +{ + return 0; +} + +int getsockname(int socket, struct sockaddr *addr, socklen_t *addrlen) +{ + return 0; +} + +int getpeername(int socket, struct sockaddr *addr, socklen_t *addrlen) +{ + return 0; +} +