done
run() {
- #echo --- $*
+ if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
+ echo --- $*
+ fi
$*
return $?
}
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
// 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
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
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)
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*
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);
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);
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, ...);
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 ---
\r
OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o rand.o\r
OBJ += perror.o scanf.o signals.o strtoi.o strtof.o\r
-OBJ += printf.o\r
+OBJ += printf.o time.o\r
OBJ += arch/$(ARCHDIR).ao\r
# signals.o\r
DEPFILES := $(OBJ:%.o=%.d)\r
ENODEV, // ???
EADDRNOTAVAIL, // ?
EINPROGRESS, // ?
+ EROFS,
EAGAIN, // Try again
typedef void (*sighandler_t)(int);
+#define SIG_IGN ((void*)1)
#define SIG_DFL ((void*)0)
#define SIG_ERR ((void*)-1)
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);
typedef signed long long clock_t;
-extern clock_t clock();
+extern clock_t clock(void);
+
+extern time_t time(time_t *t);
#endif
}
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;
+}
--- /dev/null
+/*
+ * Acess2 C Library
+ * - By John Hodge (thePowersGang)
+ *
+ * time.c
+ * - POSIX/stdc time functions
+ */
+#include <time.h>
+#include <acess/sys.h>
+
+clock_t clock(void)
+{
+ return _SysTimestamp();
+}
+
+time_t time(time_t *t)
+{
+ time_t ret = _SysTimestamp() / 1000;
+ if(t)
+ *t = ret;
+ return ret;
+}
ASFLAGS +=\r
LDFLAGS += -soname libposix.so -Map map.txt -lc\r
\r
-OBJ = main.o unistd.o dirent.o stat.o\r
+OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o\r
+OBJ += pwd.o\r
DEPFILES := $(OBJ:%.o=%.d)\r
BIN = libposix.so\r
\r
#ifndef _FCNTL_H_
#define _FCNTL_H_
-//#include <sys/sys.h>
-
-// 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; }
#ifndef _LIBPOSIX__PWD_H_
#define _LIBPOSIX__PWD_H_
+#include <stddef.h> // size_t
#include <sys/types.h> // gid_t/uid_t
struct passwd
#ifndef _LIBPOSIX__IOCTL_H_
#define _LIBPOSIX__IOCTL_H_
-
+extern int ioctl(int d, int request, ...);
#endif
#include <acess/fd_set.h>
#include <sys/time.h>
-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
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
#ifndef _LIBPOSIX__SYS__TIME_H_
#define _LIBPOSIX__SYS__TIME_H_
+#include <time.h>
+
typedef unsigned long suseconds_t;
struct timeval
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;
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
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
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * utmpx.h
+ * - User login records
+ */
+#ifndef _LIBPOSIX__UTMPX_H_
+#define _LIBPOSIX__UTMPX_H_
+
+#include <sys/time.h> // 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
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * pwd.c
+ * - Password Structure
+ */
+#include <pwd.h>
+#include <errno.h>
+#include <string.h>
+
+// 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)
+{
+
+}
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * termios.c
+ * - Terminal Control
+ */
+#include <termios.h>
+#include <errno.h>
+#include <string.h>
+
+// === 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;
+}
+
#include <unistd.h>
#include <acess/sys.h>
#include <stdarg.h>
+#include <sys/select.h>
// === CODE ===
int unlink(const char *pathname)
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;
+}
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * utmpx.c
+ * - User login records
+ */
+#include <stddef.h>
+#include <utmpx.h>
+
+/*
+ * 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;
+}
+
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;
+}
+