AcessNative - Working on libacess-native
authorJohn Hodge <[email protected]>
Wed, 6 Mar 2013 03:15:55 +0000 (11:15 +0800)
committerJohn Hodge <[email protected]>
Wed, 6 Mar 2013 03:15:55 +0000 (11:15 +0800)
14 files changed:
AcessNative/ld-acess.so_src/Makefile [deleted file]
AcessNative/ld-acess.so_src/exports.c [deleted file]
AcessNative/ld-acess.so_src/main.c [deleted file]
AcessNative/ld-acess.so_src/memory.c [deleted file]
AcessNative/ld-acess.so_src/request.c [deleted file]
AcessNative/ld-acess.so_src/syscalls.c [deleted file]
AcessNative/ld-acess_src/exports.c
AcessNative/libacess-native.so_src/Makefile [new file with mode: 0644]
AcessNative/libacess-native.so_src/exports.c [new file with mode: 0644]
AcessNative/libacess-native.so_src/main.c [new file with mode: 0644]
AcessNative/libacess-native.so_src/memory.c [new file with mode: 0644]
AcessNative/libacess-native.so_src/request.c [new file with mode: 0644]
AcessNative/libacess-native.so_src/syscalls.c [new file with mode: 0644]
AcessNative/symbol_renames.ld [new file with mode: 0644]

diff --git a/AcessNative/ld-acess.so_src/Makefile b/AcessNative/ld-acess.so_src/Makefile
deleted file mode 100644 (file)
index 661e674..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-#
-
-ifeq ($(PLATFORM),)
-       PLATFORM := lin
-endif
-
-OBJ := main.o syscalls.o request.o memory.o exports.o
-OBJ := $(addprefix obj-$(PLATFORM)/,$(OBJ))
-
-ifeq ($(PLATFORM),win)
-       BIN := ../ld-acess.dll
-       LDFLAGS += -lws2_32
-endif
-ifeq ($(PLATFORM),lin)
-       BIN := ../ld-acess.so
-endif
-
-CFLAGS   += -Wall
-CFLAGS   += -Werror
-CFLAGS   += -g -shared -fPIC
-CPPFLAGS += -DARCHDIR_is_x86_64=1
-LDFLAGS  += -g -shared -Wl,--no-undefined
-
-DEPFILES  = $(filter %.o,$(OBJ))
-DEPFILES := $(DEPFILES:%=%.dep)
-
-.PHONY: all clean
-
-all: $(BIN)
-
-clean:
-       $(RM) $(BIN) $(OBJ) $(DEPFILES)
-
-$(BIN): $(OBJ)
-       $(CC) -o $@ $(OBJ) $(LDFLAGS)
-       objdump -S $@ > [email protected]
-
-obj-$(PLATFORM)/%.o: %.c
-       @mkdir -p $(dir $@)
-       @echo [CC] -o $@
-       @$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
-       @$(CC) -M $(CPPFLAGS) -MT $@ -o [email protected] $<
-
--include $(DEPFILES)
-
diff --git a/AcessNative/ld-acess.so_src/exports.c b/AcessNative/ld-acess.so_src/exports.c
deleted file mode 100644 (file)
index cf38b5b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../ld-acess_src/exports.c"
diff --git a/AcessNative/ld-acess.so_src/main.c b/AcessNative/ld-acess.so_src/main.c
deleted file mode 100644 (file)
index 4bf908b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- */
-#include <stdarg.h>
-#include <stdio.h>
-
-#ifdef __WINDOWS__
-int DllMain(void)
-{
-       return 0;
-}
-
-#endif
-
-#ifdef __linux__
-int main(int argc, char *argv[], char **envp)
-{
-       return 0;
-}
-#endif
-
-
-void Debug(const char *format, ...)
-{
-       va_list args;
-       printf("Debug: ");
-       va_start(args, format);
-       vfprintf(stdout, format, args);
-       va_end(args);
-       printf("\n");
-}
-
-void Warning(const char *format, ...)
-{
-       va_list args;
-       printf("Warning: ");
-       va_start(args, format);
-       vfprintf(stdout, format, args);
-       va_end(args);
-       printf("\n");
-}
-
diff --git a/AcessNative/ld-acess.so_src/memory.c b/AcessNative/ld-acess.so_src/memory.c
deleted file mode 100644 (file)
index 3a9ef1a..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- */
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#if __WIN32__
-# include <windows.h>
-#else
-# include <sys/mman.h>
-# include <errno.h>
-#endif
-
-// === PROTOTYPES ===
- int   AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
-uintptr_t      FindFreeRange(size_t ByteCount, int MaxBits);
-
-// === CODE ===
-int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount)
-{
-       uintptr_t       base = (VirtAddr >> 12) << 12;
-       size_t  size = (VirtAddr & 0xFFF) + ByteCount;
-       void    *tmp;
-       #if __WIN32__
-       do
-       {
-               MEMORY_BASIC_INFORMATION        info;
-               VirtualQuery( (void*)base, &info, sizeof(info) );
-               if( info.State != MEM_FREE ) {
-                       printf("ERROR: Unable to allocate memory %p+0x%x, already allocated\n",
-                               (void*)base, size);
-                       base += 0x1000;
-                       if( size < 0x1000 )
-                               return 0;
-                       size -= 0x1000;
-               }
-               else
-                       break;
-       } while( size >= 0x1000 );
-       tmp = VirtualAlloc((void*)base, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-       if( tmp == NULL ) {
-               printf("ERROR: Unable to allocate memory %p+%x (0x%x)\n",
-                       (void*)base, size,
-                       (int)GetLastError());
-               return -1;
-       }
-       #else
-//     printf("AllocateMemory: mmap(%p, 0x%lx, ...)\n", (void*)base, ByteCount);
-       tmp = mmap((void*)base, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
-       if( tmp == MAP_FAILED ) {
-               printf("ERROR: Unable to allocate memory\n");
-               perror("AllocateMemory");
-               return -1;
-       }
-//     printf("AllocateMemory: RETURN 0\n");
-       #endif
-       return 0;
-}
-
-uintptr_t FindFreeRange(size_t ByteCount, int MaxBits)
-{
-       uintptr_t       base, ofs, size;
-       uintptr_t       end = -1;
-       static const int        PAGE_SIZE = 0x1000;
-       
-       size = (ByteCount + PAGE_SIZE - 1) / PAGE_SIZE;
-       size *= PAGE_SIZE;
-
-       end <<= (sizeof(intptr_t)*8-MaxBits);
-       end >>= (sizeof(intptr_t)*8-MaxBits);
-//     printf("end = %p\n", (void*)end);
-       
-//     for( base = 0; base < end - size; base -= PAGE_SIZE )
-       for( base = end - size + 1; base > 0; base -= PAGE_SIZE )
-       {
-               for( ofs = 0; ofs < size; ofs += PAGE_SIZE ) {
-                       #if __WIN32__
-                       MEMORY_BASIC_INFORMATION        info;
-                       VirtualQuery( (void*)(base + ofs), &info, sizeof(info) );
-                       if( info.State != MEM_FREE )
-                               break;
-                       #else
-                       if( msync( (void*)(base+ofs), 1, 0) == 0 )
-                               break;
-                       if( errno != ENOMEM )
-                               perror("FindFreeRange, msync");
-                       #endif
-               }
-               if( ofs >= size ) {
-                       return base;
-               }
-       }
-       return 0;
-}
diff --git a/AcessNative/ld-acess.so_src/request.c b/AcessNative/ld-acess.so_src/request.c
deleted file mode 100644 (file)
index b892d6c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../ld-acess_src/request.c"
diff --git a/AcessNative/ld-acess.so_src/syscalls.c b/AcessNative/ld-acess.so_src/syscalls.c
deleted file mode 100644 (file)
index 33c8950..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "../ld-acess_src/syscalls.c"
index dcfc526..a5196b5 100644 (file)
@@ -140,6 +140,11 @@ int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, int64
                events
                );
 }
+int acess__SysUnlink(const char *pathname)
+{
+       // TODO:
+       return 0;
+}
 
 int acess__SysOpenChild(int fd, char *name, int flags) {
        DEBUG("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags);
@@ -163,7 +168,51 @@ int acess__SysSetFaultHandler(int (*Handler)(int)) {
        return 0;
 }
 
+void acess__SysSetName(const char *Name)
+{
+       // TODO:
+}
+
+int acess__SysGetName(char *NameDest)
+{
+       // TODO: 
+       return 0;
+}
+
+int acess__SysSetPri(int Priority)
+{
+       // TODO:
+       return 0;
+}
+
+// --- Binaries? ---
+void *acess_SysLoadBin(const char *path, void **entry)
+{
+       // ERROR!
+       return NULL;
+}
+
+int acess__SysUnloadBin(void *base)
+{
+       // ERROR!
+       return -1;
+}
+
+// --- Timekeeping ---
+int64_t acess_SysTimestamp(void)
+{
+       // TODO: Better impl
+//     return now()*1000;
+       return 0;
+}
+
 // --- Memory Management ---
+uint64_t acess__SysGetPhys(uintptr_t vaddr)
+{
+       // TODO:
+       return 0;
+}
+
 uint64_t acess__SysAllocate(uintptr_t vaddr)
 {
        if( AllocateMemory(vaddr, 0x1000) == -1 )       // Allocate a page
@@ -209,6 +258,12 @@ int acess__SysClone(int flags, void *stack)
        #endif
 }
 
+int acess__SysKill(int pid, int sig)
+{
+       // TODO: Impliment SysKill
+       return -1;
+}
+
 int acess__SysExecVE(char *path, char **argv, const char **envp)
 {
         int    i, argc;
@@ -355,7 +410,9 @@ uint32_t acess__SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask)
 
 
 // === Symbol List ===
-#define DEFSYM(name)   {#name, &acess_##name}
+#ifndef DEFSYM
+# define DEFSYM(name)  {#name, &acess_##name}
+#endif
 const tSym     caBuiltinSymbols[] = {
        DEFSYM(_exit),
        
diff --git a/AcessNative/libacess-native.so_src/Makefile b/AcessNative/libacess-native.so_src/Makefile
new file mode 100644 (file)
index 0000000..0b9bc20
--- /dev/null
@@ -0,0 +1,46 @@
+#
+#
+
+ifeq ($(PLATFORM),)
+       PLATFORM := lin
+endif
+
+OBJ := main.o syscalls.o request.o memory.o exports.o
+OBJ := $(addprefix obj-$(PLATFORM)/,$(OBJ))
+
+ifeq ($(PLATFORM),win)
+       BIN := ../libacess-native.dll
+       LDFLAGS += -lws2_32
+endif
+ifeq ($(PLATFORM),lin)
+       BIN := ../libacess-native.so
+endif
+
+CFLAGS   += -Wall
+CFLAGS   += -Werror
+CFLAGS   += -g -shared -fPIC
+CPPFLAGS += -DARCHDIR_is_x86_64=1
+LDFLAGS  += -g -shared -Wl,--no-undefined
+
+DEPFILES  = $(filter %.o,$(OBJ))
+DEPFILES := $(DEPFILES:%=%.dep)
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+       $(RM) $(BIN) $(OBJ) $(DEPFILES)
+
+$(BIN): $(OBJ)
+       $(CC) -o $@ $(OBJ) $(LDFLAGS)
+       objdump -S $@ > [email protected]
+
+obj-$(PLATFORM)/%.o: %.c
+       @mkdir -p $(dir $@)
+       @echo [CC] -o $@
+       @$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+       @$(CC) -M $(CPPFLAGS) -MT $@ -o [email protected] $<
+
+-include $(DEPFILES)
+
diff --git a/AcessNative/libacess-native.so_src/exports.c b/AcessNative/libacess-native.so_src/exports.c
new file mode 100644 (file)
index 0000000..b761e61
--- /dev/null
@@ -0,0 +1,2 @@
+
+#include "../ld-acess_src/exports.c"
diff --git a/AcessNative/libacess-native.so_src/main.c b/AcessNative/libacess-native.so_src/main.c
new file mode 100644 (file)
index 0000000..4bf908b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ */
+#include <stdarg.h>
+#include <stdio.h>
+
+#ifdef __WINDOWS__
+int DllMain(void)
+{
+       return 0;
+}
+
+#endif
+
+#ifdef __linux__
+int main(int argc, char *argv[], char **envp)
+{
+       return 0;
+}
+#endif
+
+
+void Debug(const char *format, ...)
+{
+       va_list args;
+       printf("Debug: ");
+       va_start(args, format);
+       vfprintf(stdout, format, args);
+       va_end(args);
+       printf("\n");
+}
+
+void Warning(const char *format, ...)
+{
+       va_list args;
+       printf("Warning: ");
+       va_start(args, format);
+       vfprintf(stdout, format, args);
+       va_end(args);
+       printf("\n");
+}
+
diff --git a/AcessNative/libacess-native.so_src/memory.c b/AcessNative/libacess-native.so_src/memory.c
new file mode 100644 (file)
index 0000000..3a9ef1a
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#if __WIN32__
+# include <windows.h>
+#else
+# include <sys/mman.h>
+# include <errno.h>
+#endif
+
+// === PROTOTYPES ===
+ int   AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
+uintptr_t      FindFreeRange(size_t ByteCount, int MaxBits);
+
+// === CODE ===
+int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount)
+{
+       uintptr_t       base = (VirtAddr >> 12) << 12;
+       size_t  size = (VirtAddr & 0xFFF) + ByteCount;
+       void    *tmp;
+       #if __WIN32__
+       do
+       {
+               MEMORY_BASIC_INFORMATION        info;
+               VirtualQuery( (void*)base, &info, sizeof(info) );
+               if( info.State != MEM_FREE ) {
+                       printf("ERROR: Unable to allocate memory %p+0x%x, already allocated\n",
+                               (void*)base, size);
+                       base += 0x1000;
+                       if( size < 0x1000 )
+                               return 0;
+                       size -= 0x1000;
+               }
+               else
+                       break;
+       } while( size >= 0x1000 );
+       tmp = VirtualAlloc((void*)base, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+       if( tmp == NULL ) {
+               printf("ERROR: Unable to allocate memory %p+%x (0x%x)\n",
+                       (void*)base, size,
+                       (int)GetLastError());
+               return -1;
+       }
+       #else
+//     printf("AllocateMemory: mmap(%p, 0x%lx, ...)\n", (void*)base, ByteCount);
+       tmp = mmap((void*)base, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
+       if( tmp == MAP_FAILED ) {
+               printf("ERROR: Unable to allocate memory\n");
+               perror("AllocateMemory");
+               return -1;
+       }
+//     printf("AllocateMemory: RETURN 0\n");
+       #endif
+       return 0;
+}
+
+uintptr_t FindFreeRange(size_t ByteCount, int MaxBits)
+{
+       uintptr_t       base, ofs, size;
+       uintptr_t       end = -1;
+       static const int        PAGE_SIZE = 0x1000;
+       
+       size = (ByteCount + PAGE_SIZE - 1) / PAGE_SIZE;
+       size *= PAGE_SIZE;
+
+       end <<= (sizeof(intptr_t)*8-MaxBits);
+       end >>= (sizeof(intptr_t)*8-MaxBits);
+//     printf("end = %p\n", (void*)end);
+       
+//     for( base = 0; base < end - size; base -= PAGE_SIZE )
+       for( base = end - size + 1; base > 0; base -= PAGE_SIZE )
+       {
+               for( ofs = 0; ofs < size; ofs += PAGE_SIZE ) {
+                       #if __WIN32__
+                       MEMORY_BASIC_INFORMATION        info;
+                       VirtualQuery( (void*)(base + ofs), &info, sizeof(info) );
+                       if( info.State != MEM_FREE )
+                               break;
+                       #else
+                       if( msync( (void*)(base+ofs), 1, 0) == 0 )
+                               break;
+                       if( errno != ENOMEM )
+                               perror("FindFreeRange, msync");
+                       #endif
+               }
+               if( ofs >= size ) {
+                       return base;
+               }
+       }
+       return 0;
+}
diff --git a/AcessNative/libacess-native.so_src/request.c b/AcessNative/libacess-native.so_src/request.c
new file mode 100644 (file)
index 0000000..b892d6c
--- /dev/null
@@ -0,0 +1 @@
+#include "../ld-acess_src/request.c"
diff --git a/AcessNative/libacess-native.so_src/syscalls.c b/AcessNative/libacess-native.so_src/syscalls.c
new file mode 100644 (file)
index 0000000..33c8950
--- /dev/null
@@ -0,0 +1 @@
+#include "../ld-acess_src/syscalls.c"
diff --git a/AcessNative/symbol_renames.ld b/AcessNative/symbol_renames.ld
new file mode 100644 (file)
index 0000000..eb7377d
--- /dev/null
@@ -0,0 +1,42 @@
+_exit = acess__exit;
+_SysClone = acess__SysClone;
+_SysKill = acess__SysKill;
+_SysWaitEvent = acess__SysWaitEvent;
+_SysWaitTID = acess__SysWaitTID;
+gettid = acess_gettid;
+getpid = acess_getpid;
+getuid = acess_getuid;
+getgid = acess_getgid;
+setuid = acess_setuid;
+setgid = acess_setgid;
+_SysSetName = acess__SysSetName;
+_SysGetName = acess__SysGetName;
+SysTimestamp = acess_SysTimestamp;
+_SysSetPri = acess__SysSetPri;
+_SysSendMessage = acess__SysSendMessage;
+_SysGetMessage = acess__SysGetMessage;
+_SysSpawn = acess__SysSpawn;
+_SysExecVE = acess__SysExecVE;
+SysLoadBin = acess_SysLoadBin;
+_SysUnloadBin = acess__SysUnloadBin;
+_SysSetFaultHandler = acess__SysSetFaultHandler;
+_SysDebug = acess__SysDebug;
+_SysGetPhys = acess__SysGetPhys;
+_SysAllocate = acess__SysAllocate;
+_SysSetMemFlags = acess__SysSetMemFlags;
+_SysOpen = acess__SysOpen;
+_SysOpenChild = acess__SysOpenChild;
+_SysReopen = acess__SysReopen;
+_SysClose = acess__SysClose;
+_SysRead = acess__SysRead;
+_SysWrite = acess__SysWrite;
+_SysSeek = acess__SysSeek;
+_SysTell = acess__SysTell;
+_SysFInfo = acess__SysFInfo;
+_SysReadDir = acess__SysReadDir;
+_SysGetACL = acess__SysGetACL;
+_SysChdir = acess__SysChdir;
+_SysIOCtl = acess__SysIOCtl;
+_SysMount = acess__SysMount;
+_SysSelect = acess__SysSelect;
+_SysUnlink = acess__SysUnlink;

UCC git Repository :: git.ucc.asn.au