}\r
#define AddLoaded(a,b) do{}while(0)\r
#define LoadLibrary(a,b,c) (Log_Debug("ELF", "Module requested lib '%s'",a),0)\r
-#define SysSetMemFlags(ad,f,m) do{}while(0)\r
+#define _SysSetMemFlags(ad,f,m) do{}while(0)\r
#include "../../../Usermode/Libraries/ld-acess.so_src/elf.c"\r
// ---- / ----\r
\r
#define SYS_SETGID 42 // Set current Group ID
#define SYS_OPEN 64 // Open a file
#define SYS_REOPEN 65 // Close a file and reuse its handle
-#define SYS_CLOSE 66 // Close a file
-#define SYS_READ 67 // Read from an open file
-#define SYS_WRITE 68 // Write to an open file
-#define SYS_IOCTL 69 // Perform an IOCtl Call
-#define SYS_SEEK 70 // Seek to a new position in the file
-#define SYS_READDIR 71 // Read from an open directory
-#define SYS_OPENCHILD 72 // Open a child entry in a directory
-#define SYS_GETACL 73 // Get an ACL Value
-#define SYS_SETACL 74 // Set an ACL Value
-#define SYS_FINFO 75 // Get file information
-#define SYS_MKDIR 76 // Create a new directory
-#define SYS_LINK 77 // Create a new link to a file
-#define SYS_SYMLINK 78 // Create a symbolic link
-#define SYS_UNLINK 79 // Delete a file
-#define SYS_TELL 80 // Return the current file position
-#define SYS_CHDIR 81 // Change current directory
-#define SYS_GETCWD 82 // Get current directory
-#define SYS_MOUNT 83 // Mount a filesystem
-#define SYS_SELECT 84 // Wait for file handles
+#define SYS_OPENCHILD 66 // Open a child entry in a directory
+#define SYS_OPENPIPE 67 // Open a FIFO pipe pair
+#define SYS_CLOSE 68 // Close a file
+#define SYS_COPYFD 69 // Create a copy of a file handle
+#define SYS_FDCTL 70 // Modify properties of a file descriptor
+#define SYS_READ 71 // Read from an open file
+#define SYS_WRITE 72 // Write to an open file
+#define SYS_IOCTL 73 // Perform an IOCtl Call
+#define SYS_SEEK 74 // Seek to a new position in the file
+#define SYS_READDIR 75 // Read from an open directory
+#define SYS_GETACL 76 // Get an ACL Value
+#define SYS_SETACL 77 // Set an ACL Value
+#define SYS_FINFO 78 // Get file information
+#define SYS_MKDIR 79 // Create a new directory
+#define SYS_LINK 80 // Create a new link to a file
+#define SYS_SYMLINK 81 // Create a symbolic link
+#define SYS_UNLINK 82 // Delete a file
+#define SYS_TELL 83 // Return the current file position
+#define SYS_CHDIR 84 // Change current directory
+#define SYS_GETCWD 85 // Get current directory
+#define SYS_MOUNT 86 // Mount a filesystem
+#define SYS_SELECT 87 // Wait for file handles
-#define NUM_SYSCALLS 85
+#define NUM_SYSCALLS 88
#define SYS_DEBUG 0x100
#ifndef __ASSEMBLER__
+#ifndef NO_SYSCALL_STRS
static const char *cSYSCALL_NAMES[] = {
"SYS_EXIT",
"SYS_CLONE",
"",
"SYS_OPEN",
"SYS_REOPEN",
+ "SYS_OPENCHILD",
+ "SYS_OPENPIPE",
"SYS_CLOSE",
+ "SYS_COPYFD",
+ "SYS_FDCTL",
"SYS_READ",
"SYS_WRITE",
"SYS_IOCTL",
"SYS_SEEK",
"SYS_READDIR",
- "SYS_OPENCHILD",
"SYS_GETACL",
"SYS_SETACL",
"SYS_FINFO",
""
};
#endif
+#endif
#endif
%define SYS_SETGID 42 ;Set current Group ID
%define SYS_OPEN 64 ;Open a file
%define SYS_REOPEN 65 ;Close a file and reuse its handle
-%define SYS_CLOSE 66 ;Close a file
-%define SYS_READ 67 ;Read from an open file
-%define SYS_WRITE 68 ;Write to an open file
-%define SYS_IOCTL 69 ;Perform an IOCtl Call
-%define SYS_SEEK 70 ;Seek to a new position in the file
-%define SYS_READDIR 71 ;Read from an open directory
-%define SYS_OPENCHILD 72 ;Open a child entry in a directory
-%define SYS_GETACL 73 ;Get an ACL Value
-%define SYS_SETACL 74 ;Set an ACL Value
-%define SYS_FINFO 75 ;Get file information
-%define SYS_MKDIR 76 ;Create a new directory
-%define SYS_LINK 77 ;Create a new link to a file
-%define SYS_SYMLINK 78 ;Create a symbolic link
-%define SYS_UNLINK 79 ;Delete a file
-%define SYS_TELL 80 ;Return the current file position
-%define SYS_CHDIR 81 ;Change current directory
-%define SYS_GETCWD 82 ;Get current directory
-%define SYS_MOUNT 83 ;Mount a filesystem
-%define SYS_SELECT 84 ;Wait for file handles
+%define SYS_OPENCHILD 66 ;Open a child entry in a directory
+%define SYS_OPENPIPE 67 ;Open a FIFO pipe pair
+%define SYS_CLOSE 68 ;Close a file
+%define SYS_COPYFD 69 ;Create a copy of a file handle
+%define SYS_FDCTL 70 ;Modify properties of a file descriptor
+%define SYS_READ 71 ;Read from an open file
+%define SYS_WRITE 72 ;Write to an open file
+%define SYS_IOCTL 73 ;Perform an IOCtl Call
+%define SYS_SEEK 74 ;Seek to a new position in the file
+%define SYS_READDIR 75 ;Read from an open directory
+%define SYS_GETACL 76 ;Get an ACL Value
+%define SYS_SETACL 77 ;Set an ACL Value
+%define SYS_FINFO 78 ;Get file information
+%define SYS_MKDIR 79 ;Create a new directory
+%define SYS_LINK 80 ;Create a new link to a file
+%define SYS_SYMLINK 81 ;Create a symbolic link
+%define SYS_UNLINK 82 ;Delete a file
+%define SYS_TELL 83 ;Return the current file position
+%define SYS_CHDIR 84 ;Change current directory
+%define SYS_GETCWD 85 ;Get current directory
+%define SYS_MOUNT 86 ;Mount a filesystem
+%define SYS_SELECT 87 ;Wait for file handles
64
SYS_OPEN Open a file
SYS_REOPEN Close a file and reuse its handle
+SYS_OPENCHILD Open a child entry in a directory
+SYS_OPENPIPE Open a FIFO pipe pair
SYS_CLOSE Close a file
+SYS_COPYFD Create a copy of a file handle
+SYS_FDCTL Modify properties of a file descriptor
SYS_READ Read from an open file
SYS_WRITE Write to an open file
SYS_IOCTL Perform an IOCtl Call
SYS_SEEK Seek to a new position in the file
SYS_READDIR Read from an open directory
-SYS_OPENCHILD Open a child entry in a directory
SYS_GETACL Get an ACL Value
SYS_SETACL Set an ACL Value
SYS_FINFO Get file information
}\r
\r
// Create new process\r
- pid = clone(CLONE_VM, 0);\r
- // Start Task\r
- if(pid == 0) {\r
- execve(sTmpBuffer, Args, gasEnvironment);\r
- printf("Execve returned, ... oops\n");\r
- exit(-1);\r
- }\r
+ int fds[] = {0, 1, 2};\r
+ pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL);\r
if(pid <= 0) {\r
printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message\r
}\r
else {\r
int status;\r
- waittid(pid, &status);\r
+ _SysWaitTID(pid, &status);\r
}\r
}\r
\r
size_t len;
int tid;
- while( (len = SysGetMessage(&tid, 0, NULL)) )
+ while( (len = _SysGetMessage(&tid, 0, NULL)) )
{
char data[len];
- SysGetMessage(NULL, len, data);
+ _SysGetMessage(NULL, len, data);
IPC_Handle(&gIPC_Type_SysMessage, &tid, len, (void*)data);
// _SysDebug("IPC_HandleSelect: Message handled");
void IPC_Type_Sys_Send(const void *Ident, size_t Length, const void *Data)
{
- SysSendMessage( *(const tid_t*)Ident, Length, Data );
+ _SysSendMessage( *(const tid_t*)Ident, Length, Data );
}
// --- Client -> Window Mappings
switch(giConnectionType)
{
case CONNTYPE_SENDMESSAGE:
- SysSendMessage(giConnectionNum, size, Msg);
+ _SysSendMessage(giConnectionNum, size, Msg);
break;
case CONNTYPE_UDP: {
// Create UDP header
_SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG);
// Clear out IPC messages
- while( (len = SysGetMessage(&tid, 0, NULL)) )
+ while( (len = _SysGetMessage(&tid, 0, NULL)) )
{
if( giConnectionType != CONNTYPE_SENDMESSAGE || tid != giConnectionNum )
{
if( gAxWin3_MessageCallback )
gAxWin3_MessageCallback(tid, len);
else
- SysGetMessage(NULL, 0, GETMSG_IGNORE);
+ _SysGetMessage(NULL, 0, GETMSG_IGNORE);
continue ;
}
ret = malloc(len);
if(ret == NULL) {
_SysDebug("malloc() failed, ignoring message");
- SysGetMessage(NULL, 0, GETMSG_IGNORE);
+ _SysGetMessage(NULL, 0, GETMSG_IGNORE);
return NULL;
}
- SysGetMessage(NULL, len, ret);
+ _SysGetMessage(NULL, len, ret);
break;
}
if( gbForkBomb )
{
- for(;;) clone(CLONE_VM, 0);
+ for(;;) _SysClone(CLONE_VM, 0);
}
else {
for(;;)
printf("Outta heap space!\n");
return 0;
}
- tid = clone(0, stack+stackSize-stackOffset);
+ tid = _SysClone(0, stack+stackSize-stackOffset);
//_SysDebug("tid = %i", tid);
if( tid == 0 )
{
STATE_PREINIT,
STATE_DISCOVER_SENT,
STATE_REQUEST_SENT,
- STATE_COMPLETE
+ STATE_COMPLETE,
};
// === STRUCTURES ===
char HWAddr[6];
int64_t Timeout;
+ int nTimeouts;
} tInterface;
// === PROTOTYPES ===
int Start_Interface(tInterface *Iface);
void Send_DHCPDISCOVER(tInterface *Iface);
void Send_DHCPREQUEST(tInterface *Iface, void *OfferBuffer, int TypeOffset);
-int Handle_Packet(tInterface *Iface);
-void Handle_Timeout(tInterface *Iface);
+ int Handle_Packet(tInterface *Iface);
+ int Handle_Timeout(tInterface *Iface);
void Update_State(tInterface *Iface, int newState);
void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router);
if( FD_ISSET(i->SocketFD, &fds) )
{
if( Handle_Packet( i ) )
- {
- _SysClose(i->SocketFD);
- _SysClose(i->IfaceFD);
- p->Next = i->Next;
- free(i);
- i = p;
- }
+ goto _remove;
}
if( _SysTimestamp() > i->Timeout )
{
- Handle_Timeout(i);
+ if( Handle_Timeout(i) )
+ {
+ fprintf(stderr, "%s timed out\n", i->Adapter);
+ goto _remove;
+ }
}
+ continue ;
+ _remove:
+ _SysClose(i->SocketFD);
+ _SysClose(i->IfaceFD);
+ p->Next = i->Next;
+ free(i);
+ i = p;
}
}
return 0;
return 0;
}
-void Handle_Timeout(tInterface *Iface)
+int Handle_Timeout(tInterface *Iface)
{
+ if( Iface->nTimeouts == 3 )
+ return 1;
switch(Iface->State)
{
case STATE_DISCOVER_SENT:
_SysDebug("Timeout with state = %i", Iface->State);
break;
}
+ return 0;
}
void Update_State(tInterface *Iface, int newState)
{
Iface->Timeout = _SysTimestamp() + 500;
Iface->State = newState;
+ Iface->nTimeouts = 0;
}
else
{
// TODO: Exponential backoff
Iface->Timeout = _SysTimestamp() + 3000;
+ Iface->nTimeouts ++;
_SysDebug("State %i repeated, timeout is 3000ms now", newState);
}
}
// - Start virtual terminals
for( i = 0; i < NUM_TERMS; i++ )
{
- tid = clone(CLONE_VM, 0);
+ tid = _SysClone(CLONE_VM, 0);
if(tid == 0)
{
termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i;
_SysOpen(termpath, OPENFLAG_READ); // Stdin
_SysOpen(termpath, OPENFLAG_WRITE); // Stdout
_SysOpen(termpath, OPENFLAG_WRITE); // Stderr
- execve(DEFAULT_SHELL, child_argv, NULL);
+ _SysExecVE(DEFAULT_SHELL, child_argv, NULL);
for(;;) ;
}
}
break;
}
printf("\n");
-
- // Create child process
- pid = clone(CLONE_VM, 0);
+
+ uinfo = GetUserInfo(uid);
+ struct s_sys_spawninfo spawninfo;
+ spawninfo.flags = 0;
+ spawninfo.gid = uinfo->GID;
+ spawninfo.uid = uinfo->UID;
+ const char *child_argv[2] = {"-", 0};
+ const char **child_envp = NULL;
+ int fds[] = {0, 1, 2};
+ pid = _SysSpawn(uinfo->Shell, child_argv, child_envp, 3, fds, &spawninfo);
// Error check
if(pid == -1) {
fprintf(stderr, "Unable to fork the login process!\n");
return -1;
}
- // Spawn shell in a child process
- if(pid == 0)
- {
- char *child_argv[2] = {NULL, 0};
- char **child_envp = NULL;
-
- // Get user information
- uinfo = GetUserInfo(uid);
-
- child_argv[0] = uinfo->Shell;
- // Set Environment
- setgid(uinfo->GID);
- //setuid(uid);
- setuid(uinfo->UID);
-
- execve(uinfo->Shell, child_argv, child_envp);
- exit(-1);
- }
-
// Wait for child to terminate
- waittid(pid, &status);
+ _SysWaitTID(pid, &status);
}
return 0;
INCFILES := sys/sys.h
CFLAGS = -g -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC
-CFLAGS += $(CPPFLAGS)
+CFLAGS += $(CPPFLAGS) -Werror
LDFLAGS = -g -T arch/$(ARCHDIR).ld -Map map.txt --export-dynamic
include ../Makefile.tpl
#define SYSCALL5(name,num) void name(void){}
#define SYSCALL6(name,num) void name(void){}
+#define NO_SYSCALL_STRS
#include "arch/syscalls.s.h"
// libgcc functions
// --- Process Control ---
SYSCALL1(_exit, SYS_EXIT)
-SYSCALL2(clone, SYS_CLONE)
-SYSCALL2(kill, SYS_KILL)
+SYSCALL2(_SysClone, SYS_CLONE)
+SYSCALL2(_SysKill, SYS_KILL)
//SYSCALL0(yield, SYS_YIELD)
//SYSCALL0(sleep, SYS_SLEEP)
SYSCALL1(_SysWaitEvent, SYS_WAITEVENT)
-SYSCALL2(waittid, SYS_WAITTID)
+SYSCALL2(_SysWaitTID, SYS_WAITTID)
SYSCALL0(gettid, SYS_GETTID)
SYSCALL0(getpid, SYS_GETPID)
SYSCALL1(setuid, SYS_SETUID)
SYSCALL1(setgid, SYS_SETGID)
-SYSCALL1(SysSetName, SYS_SETNAME)
-SYSCALL2(SysGetName, SYS_GETNAME)
+SYSCALL1(_SysSetName, SYS_SETNAME)
+SYSCALL2(_SysGetName, SYS_GETNAME)
SYSCALL0(_SysTimestamp, SYS_GETTIME)
-SYSCALL1(SysSetPri, SYS_SETPRI)
+SYSCALL1(_SysSetPri, SYS_SETPRI)
-SYSCALL3(SysSendMessage, SYS_SENDMSG)
-SYSCALL3(SysGetMessage, SYS_GETMSG)
+SYSCALL3(_SysSendMessage, SYS_SENDMSG)
+SYSCALL3(_SysGetMessage, SYS_GETMSG)
SYSCALL5(_SysSpawn, SYS_SPAWN)
-SYSCALL3(execve, SYS_EXECVE)
-SYSCALL2(SysLoadBin, SYS_LOADBIN)
-SYSCALL1(SysUnloadBin, SYS_UNLOADBIN)
+SYSCALL3(_SysExecVE, SYS_EXECVE)
+SYSCALL2(_SysLoadBin, SYS_LOADBIN)
+SYSCALL1(_SysUnloadBin, SYS_UNLOADBIN)
SYSCALL1(_SysSetFaultHandler, SYS_SETFAULTHANDLER)
SYSCALL6(_SysDebug, 0x100)
SYSCALL1(_SysGetPhys, SYS_GETPHYS) // uint64_t _SysGetPhys(uint addr)
SYSCALL1(_SysAllocate, SYS_ALLOCATE) // uint64_t _SysAllocate(uint addr)
-SYSCALL3(SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, uint flags, uint mask)
+SYSCALL3(_SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, uint flags, uint mask)
// VFS System calls
SYSCALL2(_SysOpen, SYS_OPEN) // char*, int
SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int
extern void *memcpy(void *dest, const void *src, size_t len);
// === System Calls ===
-extern void SysDebug(const char *fmt, ...); //!< Now implemented in main.c
-extern void SysDebugV(const char *fmt, ...);
-extern void *SysLoadBin(const char *path, void **entry);
-extern int SysUnloadBin(void *Base);
-extern void SysSetFaultHandler(int (*Hanlder)(int));
// === ELF Loader ===
extern void *ElfRelocate(void *Base, char **envp, const char *Filename);
uintptr_t addr = phtab[i].VAddr + iBaseDiff;
uintptr_t end = addr + phtab[i].MemSize;
for( ; addr < end; addr += PAGE_SIZE )
- SysSetMemFlags(addr, 0, 1); // Unset RO
+ _SysSetMemFlags(addr, 0, 1); // Unset RO
}
}
uintptr_t addr = phtab[i].VAddr + iBaseDiff;
uintptr_t end = addr + phtab[i].MemSize;
for( ; addr < end; addr += PAGE_SIZE )
- SysSetMemFlags(addr, 1, 1); // Unset RO
+ _SysSetMemFlags(addr, 1, 1); // Unset RO
}
}
+++ /dev/null
-/*
- */
-#ifndef _ACESS_INTDEFS_H_
-#define _ACESS_INTDEFS_H_
-
-#include <stdint.h>
-#include <limits.h>
-
-#if 0
-#define INT_MIN -0x80000000
-#define INT_MAX 0x7FFFFFFF
-
-typedef unsigned char __uint8_t;
-typedef unsigned short __uint16_t;
-typedef unsigned int __uint32_t;
-typedef unsigned long long __uint64_t;
-
-typedef signed char __int8_t;
-typedef signed short __int16_t;
-typedef signed int __int32_t;
-typedef signed long long __int64_t;
-
-#if defined(ARCHDIR_is_x86)
-typedef __int32_t __intptr_t;
-typedef __uint32_t __uintptr_t;
-#elif defined(ARCHDIR_is_x86_64)
-typedef __int64_t __intptr_t;
-typedef __uint64_t __uintptr_t;
-#elif defined(ARCHDIR_is_armv7) | defined(ARCHDIR_is_armv6)
-typedef __int32_t __intptr_t;
-typedef __uint32_t __uintptr_t;
-#else
-# error "Unknown pointer size"
-#endif
-
-#endif
-
-#endif
-
extern void _SysDebug(const char *format, ...);
// --- Proc ---
extern void _exit(int status) __attribute__((noreturn));
-//extern void sleep(void);
-//extern void yield(void);
-extern int kill(int pid, int sig);
-//extern void wait(int miliseconds);
+extern int _SysKill(int pid, int sig);
extern int _SysWaitEvent(int EventMask);
-extern int waittid(int id, int *status);
-extern int clone(int flags, void *stack);
-extern int execve(const char *path, char **argv, char **envp);
+extern int _SysWaitTID(int id, int *status);
+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 _SysSetFaultHandler(int (*Handler)(int));
-extern void SysSetName(const char *Name);
-extern int SysGetName(char *NameDest);
-extern int SysSetPri(int Priority);
+extern void _SysSetName(const char *Name);
+extern int _SysGetName(char *NameDest);
+extern int _SysSetPri(int Priority);
+// --- Timekeeping ---
extern int64_t _SysTimestamp(void);
// --- Permissions ---
// --- VFS ---
extern int _SysChdir(const char *dir);
-extern int _SysRoot(const char *dir);
+extern int _SysChroot(const char *dir);
extern int _SysOpen(const char *path, int flags, ...);
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 _SysClose(int fd);
extern size_t _SysRead(int fd, void *buffer, size_t length);
+extern int _SysClose(int fd);
+extern int _SysFDCtl(int fd, int option, ...);
extern size_t _SysWrite(int fd, const void *buffer, size_t length);
extern int _SysSeek(int fd, int64_t offset, int whence);
extern uint64_t _SysTell(int fd);
extern int _SysUnlink(const char *pathname);
// --- IPC ---
-extern int SysSendMessage(int dest, size_t length, const void *Data);
-extern int SysGetMessage(int *src, size_t buflen, void *Data);
+extern int _SysSendMessage(int dest, size_t length, const void *Data);
+extern int _SysGetMessage(int *src, size_t buflen, void *Data);
// --- MEMORY ---
-uint64_t _SysGetPhys(uintptr_t vaddr);
-uint64_t _SysAllocate(uintptr_t vaddr);
-uint32_t SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask);
+extern uint64_t _SysGetPhys(uintptr_t vaddr);
+extern uint64_t _SysAllocate(uintptr_t vaddr);
+extern uint32_t _SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask);
+extern void *_SysLoadBin(const char *path, void **entry);
+extern int _SysUnloadBin(void *base);
+extern void SysSetFaultHandler(int (*Hanlder)(int));
#endif
*/
#include "common.h"
#include <stdint.h>
+#include <acess/sys.h>
#define DEBUG 0
DEBUGS(" LoadLibrary: SysLoadBin()");
// Load Library
- base = SysLoadBin(filename, (void**)&fEntry);
+ base = _SysLoadBin(filename, (void**)&fEntry);
if(!base) {
DEBUGS("LoadLibrary: RETURN 0");
return 0;
if(id == MAX_LOADED_LIBRARIES) return;
// Unload Binary
- SysUnloadBin( Base );
+ _SysUnloadBin( Base );
// Save String Pointer
str = gLoadedLibraries[id].Name;
int fork(void)
{
- return clone(CLONE_VM, 0);
+ return _SysClone(CLONE_VM, 0);
}
int execv(const char *b, char *v[])
{
- return execve(b, v, NULL);
+ return _SysExecVE(b, v, NULL);
}