From 6cca7994b0b4b232df98a7c3856197d6075bf1cc Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 26 Apr 2013 13:24:22 +0800 Subject: [PATCH] Usermode/libposix - More definitions on the way to dropbear --- .../libposix.so_src/include_exp/fcntl.h | 8 +- .../libposix.so_src/include_exp/pwd.h | 1 + .../libposix.so_src/include_exp/sys/ioctl.h | 14 +++ .../libposix.so_src/include_exp/sys/select.h | 1 + .../libposix.so_src/include_exp/sys/stat.h | 4 + .../libposix.so_src/include_exp/sys/wait.h | 2 + .../libposix.so_src/include_exp/termios.h | 97 ++++++++++++++++++- .../libposix.so_src/include_exp/unistd.h | 2 + Usermode/Libraries/libposix.so_src/unistd.c | 22 +++++ 9 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h diff --git a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h index ded9ba1e..daababb4 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h @@ -9,15 +9,15 @@ #ifndef _FCNTL_H_ #define _FCNTL_H_ -#include +//#include // Hacks to handle different behaviors in Acess // Open doesn't take a chmod -#define open(_1,_2,...) open(_1, _2) +//#define open(_1,_2,...) open(_1, _2) // Close returns void -#define close(_1) (close(_1),0) +//#define close(_1) (close(_1),0) // Acess doesn't implement lseek #define lseek(_1,_2,_3) (seek(_1,_2,_3),tell(_1)) @@ -27,7 +27,7 @@ enum e_fcntl_cmds F_SETFL }; -int fcntl(int fd, int cmd, ...) { return -1; } +static inline int fcntl(int fd __attribute__((unused)), int cmd __attribute__((unused)), ...) { return -1; } #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h index 66b157f9..ae4bf077 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h @@ -17,6 +17,7 @@ struct passwd gid_t pw_gid; char *pw_dir; char *pw_shell; + char *pw_passwd; }; extern struct passwd *getpwnam(const char *); diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h new file mode 100644 index 00000000..16cdd40a --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h @@ -0,0 +1,14 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * ioctl.h + * - IOCtl hacks + */ +#ifndef _LIBPOSIX__IOCTL_H_ +#define _LIBPOSIX__IOCTL_H_ + + + +#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 c33ccb13..cf2f1aaf 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h @@ -9,6 +9,7 @@ #define _SYS__SELECT_H_ #include +#include extern int select(int nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout); // TODO: pselect? 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 3e9f4303..c5749281 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h @@ -18,8 +18,12 @@ typedef uint64_t blkcnt_t; typedef unsigned int nlink_t; typedef uint32_t mode_t; +#ifndef uid_t typedef uint32_t uid_t; +#endif +#ifndef gid_t typedef uint32_t gid_t; +#endif #define S_IFMT 0170000 /* type of file */ #define S_IFDIR 0040000 /* directory */ diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/wait.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/wait.h index d37f5e5d..73e83f2a 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/wait.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/wait.h @@ -8,6 +8,8 @@ #ifndef _LIBPOSIX__SYS__WAIT_H_ #define _LIBPOSIX__SYS__WAIT_H_ +#include + // POSIX, waitpid() #define WNOHANG 0x01 #define WUNTRACED 0x02 diff --git a/Usermode/Libraries/libposix.so_src/include_exp/termios.h b/Usermode/Libraries/libposix.so_src/include_exp/termios.h index e29ff4cf..a200f2c4 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/termios.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/termios.h @@ -12,18 +12,113 @@ typedef unsigned char cc_t; typedef unsigned long speed_t; typedef unsigned short tcflag_t; -enum { +// c_iflag +#define IGNBRK (1 << 0) +#define BRKINT (1 << 1) +#define IGNPAR (1 << 2) // Ignore parity failures +#define PARMRK (1 << 3) // Mark parity failures with FFh 00h +#define INPCK (1 << 4) // Enable input parity checks +#define ISTRIP (1 << 5) // strip 8th bit +#define INLCR (1 << 6) // Translate input newline into CR +#define IGNCR (1 << 7) // Ignore input CR +#define ICRNL (1 << 8) // Translate input CR into NL +// (Linux) IUCLC // Map upper to lower case +#define IXON (1 <<10) // Enable input XON/XOFF +#define IXANY (1 <<11) // Any character will restart input +#define IXOFF IXON +// (Linux) IMAXBEL +// (Linux) IUTF8 + +// c_oflag +#define OPOST (1 << 0) // Output processing +// (Linux) OLCUC +#define ONLCR (1 << 2) // (XSI) NL->CR +#define OCRNL (1 << 3) // CR->NL +#define ONOCR (1 << 4) // Don't output CR at column 0 +#define ONLRET (1 << 5) // Don't output CR +#define OFILL (1 << 6) // Send fill chars for a delay, instead of timing +// (Linux) OFDEL +#define NLDLY (1 << 8) // Newline delay mask (NL0/NL1) +#define NL0 (0 << 8) +#define NL1 (1 << 8) +#define NCDLY (3 << 9) // Carriage return delay mask (CR0-CR3) +#define CR0 (0 << 9) +#define CR1 (1 << 9) +#define CR2 (2 << 9) +#define CR3 (3 << 9) +#define TABDLY (3 << 11) // Horizontal tab delay mask +#define TAB0 (0 << 11) +#define TAB1 (1 << 11) +#define TAB2 (2 << 11) +#define TAB3 (3 << 11) +#define BSDLY (1 << 13) // Backspace delay +#define BS0 (0 << 13) +#define BS1 (1 << 13) +#define VTDLY (1 << 14) // Vertical tab delay +#define VT0 (0 << 14) +#define VT1 (1 << 14) +#define FFDLY (1 << 15) // Form feed delay +#define FF0 (0 << 15) +#define VFF1 (1 << 15) + +// c_cflag +#define CBAUD (037 << 0) // Baud speed +#define CSIZE (3 << 5) // Character size mask +#define CS5 (0 << 5) +#define CS6 (1 << 5) +#define CS7 (2 << 5) +#define CS8 (3 << 5) +#define CSTOPB (1 << 7) // 1/2 stop bits +#define CREAD (1 << 8) // Enable receiver +#define PARENB (1 << 9) // Enable parity generation / checking +#define PARODD (1 << 10) // Odd parity +#define HUPCL (1 << 11) // Hang up on close +#define CLOCAL (1 << 12) // Ignore modem control lines +// LOBLK +// CIBAUD +// CMSPAR +// CRTSCTS + +// c_lflag +#define ISIG (1 << 0) // Generate signals for INTR, QUIT, SUSP and DSUSP +#define ICANON (1 << 1) // Input canonical mode +// XCASE +#define ECHO (1 << 3) // Echo input characters +#define ECHOE (1 << 4) // Enable ERASE and WERASE on echoed input [ICANON] +#define ECHOK (1 << 5) // Enable KILL char on echoed input [ICANON] +#define ECHONL (1 << 6) // Echo NL even if ECHO is unset [ICANON] +#define ECHOCTL (1 << 7) // (non-POSIX) If ECHO set specials are echoed as val+0x40 (BS=^H) +// ECHOPRT +#define ECHOKE (1 << 9) // (non-POSIX) KILL implimented by sequential erase [ICANON] +// DEFECHO +// FLUSHO +#define NOFLSH (1 << 11) // Disable flush of IO when generating INT, QUIT and SUSP +#define TOSTOP (1 << 12) // ? +// PENDIN +#define IEXTEN (1 << 14) + +// - Indexes for c_cc +enum +{ + VDISCARD, + VDSUSP, VEOF, VEOL, + VEOL2, VERASE, VINTR, VKILL, + VLNEXT, VMIN, VQUIT, + // VREPRINT, // (non-POSIX) VSTART, + // VSTATUS, // (non-POSIX) VSTOP, VSUSP, + // VSWITCH, // (non-POSIX) VTIME, + VWERASE, NCCS }; diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h index a2f397cc..ea107a9d 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -43,5 +43,7 @@ extern ssize_t read(int fd, void *buf, size_t count); extern int fork(void); extern int execv(const char *b, char *v[]); +extern int dup2(int oldfd, int newfd); + #endif diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index c1d4908d..68c4e522 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -10,6 +10,11 @@ #include // === CODE === +int unlink(const char *pathname) +{ + return _SysUnlink(pathname); +} + int open(const char *path, int openmode, ...) { mode_t create_mode = 0; @@ -60,6 +65,16 @@ ssize_t read(int fd, void *buf, size_t count) return _SysRead(fd, buf, count); } +int seek(int fd, int whence, off_t dest) +{ + return _SysSeek(fd, whence, dest); +} + +off_t tell(int fd) +{ + return _SysTell(fd); +} + int fork(void) { return _SysClone(CLONE_VM, 0); @@ -69,3 +84,10 @@ int execv(const char *b, char *v[]) { return _SysExecVE(b, v, NULL); } + +int dup2(int oldfd, int newfd) +{ + // NOTE: Acess's CopyFD doesn't cause offset sharing + return _SysCopyFD(oldfd, newfd); +} + -- 2.20.1