AcesNative+Usermode - libacessnative "works" (for some definitions)
authorJohn Hodge <[email protected]>
Tue, 26 Mar 2013 14:59:29 +0000 (22:59 +0800)
committerJohn Hodge <[email protected]>
Tue, 26 Mar 2013 14:59:29 +0000 (22:59 +0800)
- Uses system libc, and as such *printf goes to system stdout

23 files changed:
AcessNative/acesskernel_src/syscalls.c
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/request.c
AcessNative/ld-acess_src/syscalls.c
AcessNative/libacess-native.so_src/Makefile
AcessNative/libacess-native.so_src/exports.c
AcessNative/libacess-native.so_src/main.c
BuildConf/native/Makefile.cfg
KernelLand/Kernel/vfs/io.c
Usermode/Applications/Makefile.cfg
Usermode/Applications/Makefile.tpl
Usermode/Applications/axwin3_src/WM/main.c
Usermode/Applications/axwin3_src/WM/video.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/include/internal.h
Usermode/Libraries/Makefile.cfg
Usermode/Libraries/Makefile.tpl
Usermode/Libraries/ld-acess.so_src/include_exp/acess/_native_syscallmod.h [new file with mode: 0644]
Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h
Usermode/Libraries/libc.so_src/Makefile
Usermode/Libraries/libc.so_src/include_exp/errno.h
Usermode/Libraries/libc.so_src/signals.c
Usermode/Libraries/libc.so_src/stub.c
Usermode/Libraries/libposix.so_src/Makefile

index 4458846..f19fe69 100644 (file)
@@ -119,6 +119,7 @@ SYSCALL3(Syscall_Read, "iid", int, int, void *,
 );
 SYSCALL3(Syscall_Write, "iid", int, int, const void *,
        if( Sizes[2] < a1 ) {
+               Log_Warning("Syscalls", "Write - %i < %i", Sizes[2], a1);
                *Errno = EINVAL;
                return -1;
        }
index a5196b5..756feba 100644 (file)
@@ -199,7 +199,7 @@ int acess__SysUnloadBin(void *base)
 }
 
 // --- Timekeeping ---
-int64_t acess_SysTimestamp(void)
+int64_t acess__SysTimestamp(void)
 {
        // TODO: Better impl
 //     return now()*1000;
index 2fa481a..62e70e8 100644 (file)
@@ -243,6 +243,38 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize)
        if( recvbytes > expbytes ) {
                // TODO: Warning
        }
+       
+       #if DEBUG
+       {
+                int    i;
+               char    *data = (char*)&Request->Params[Request->NParams];
+               DEBUG_S(" Reply:");
+               for( i = 0; i < Request->NParams; i ++ )
+               {
+                       switch(Request->Params[i].Type)
+                       {
+                       case ARG_TYPE_INT32:
+                               DEBUG_S(" 0x%08x", *(uint32_t*)data);
+                               data += sizeof(uint32_t);
+                               break;
+                       case ARG_TYPE_INT64:
+                               DEBUG_S(" 0x%016"PRIx64"", *(uint64_t*)data);
+                               data += sizeof(uint64_t);
+                               break;
+                       case ARG_TYPE_STRING:
+                               DEBUG_S(" '%s'", (char*)data);
+                               data += Request->Params[i].Length;
+                               break;
+                       case ARG_TYPE_DATA:
+                               DEBUG_S(" %p:0x%x", (char*)data, Request->Params[i].Length);
+                               if( !(Request->Params[i].Flags & ARG_FLAG_ZEROED) )
+                                       data += Request->Params[i].Length;
+                               break;
+                       }
+               }
+               DEBUG_S("\n");
+       }
+       #endif
        return recvbytes;
 }
 
index c649f28..88db8c4 100644 (file)
@@ -249,7 +249,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...)
                exit(127);
        }
        
-       Debug("req->NParams = %i", req->NParams);
+       dataPtr = (void*)&req->Params[req->NParams];
        assert(req->NParams >= 2);
        // return
        assert(req->Params[0].Type == ARG_TYPE_INT64);
index 0b9bc20..0a074a6 100644 (file)
@@ -20,7 +20,7 @@ CFLAGS   += -Wall
 CFLAGS   += -Werror
 CFLAGS   += -g -shared -fPIC
 CPPFLAGS += -DARCHDIR_is_x86_64=1
-LDFLAGS  += -g -shared -Wl,--no-undefined
+LDFLAGS  += -g -shared -Wl,--no-undefined -lc
 
 DEPFILES  = $(filter %.o,$(OBJ))
 DEPFILES := $(DEPFILES:%=%.dep)
index b761e61..0ab6361 100644 (file)
@@ -1,2 +1,11 @@
 
 #include "../ld-acess_src/exports.c"
+
+void   *_crt0_exit_handler;
+
+int *libc_geterrno(void)
+{
+       return &acess__errno;
+}
+
+
index 4bf908b..f072864 100644 (file)
@@ -1,19 +1,59 @@
 /*
  */
 #include <stdarg.h>
+#include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+
+extern int     giSyscall_ClientID;
+extern void    Request_Preinit(void);
+extern int     acess__SysOpen(const char *Path, unsigned int flags);
 
 #ifdef __WINDOWS__
 int DllMain(void)
 {
+       fprintf(stderr, "TODO: Windows libacessnative setup\n");
        return 0;
 }
 
 #endif
 
 #ifdef __linux__
-int main(int argc, char *argv[], char **envp)
+int __attribute__ ((constructor)) libacessnative_init(void);
+
+int libacessnative_init(void)
 {
+       Request_Preinit();
+
+       const char *preopens = getenv("AN_PREOPEN");
+       if( preopens )
+       {
+               while( *preopens )
+               {
+                       const char *splitter = strchr(preopens, ':');
+                       size_t  len;
+                       if( !splitter ) {
+                               len = strlen(preopens);
+                       }
+                       else {
+                               len = splitter - preopens;
+                       }
+                       char path[len+1];
+                       memcpy(path, preopens, len);
+                       path[len] = 0;
+                       int fd = acess__SysOpen(path, 6);       // WRITE,READ,no EXEC
+                       if( fd == -1 ) {
+                               fprintf(stderr, "Unable to preopen '%s'\n", path);
+                       }
+                       
+                       if( !splitter )
+                               break;
+                       preopens = splitter + 1;
+               }
+       }
+
+//     if( !getenv("ACESSNATIVE_ID")
+       
        return 0;
 }
 #endif
@@ -39,3 +79,11 @@ void Warning(const char *format, ...)
        printf("\n");
 }
 
+void __libc_csu_fini()
+{
+}
+
+void __libc_csu_init()
+{
+}
+
index aa4cd00..2bf14cc 100644 (file)
@@ -5,7 +5,8 @@
 
 ARCHDIR := native
 
-LD ?= $(CC) -print-prog-name=ld
+#LD ?= $(CC) -print-prog-name=ld
+LD = $(CC)
 AS = $(CC) -c
 ASSUFFIX = S
 
index 1df3403..24aa78b 100644 (file)
@@ -41,7 +41,8 @@ size_t VFS_Read(int FD, size_t Length, void *Buffer)
        }
 
        if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
-               Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
+               Log_Error("VFS", "Node type %p(%s) read method is junk %p",
+                       h->Node->Type, h->Node, h->Node->Type->TypeName,
                        h->Node->Type->Read);
                LEAVE_RET('i', -1);
        }
@@ -98,10 +99,19 @@ size_t VFS_Write(int FD, size_t Length, const void *Buffer)
        h = VFS_GetHandle(FD);
        if(!h)  return -1;
        
-       if( !(h->Mode & VFS_OPENFLAG_WRITE) )   return -1;
-       if( h->Node->Flags & VFS_FFLAG_DIRECTORY )      return -1;
+       if( !(h->Mode & VFS_OPENFLAG_WRITE) ) {
+               LOG("FD%i not opened for writing", FD);
+               return -1;
+       }
+       if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) {
+               LOG("FD%i is a director", FD);
+               return -1;
+       }
 
-       if( !h->Node->Type || !h->Node->Type->Write )   return 0;
+       if( !h->Node->Type || !h->Node->Type->Write ) {
+               LOG("FD%i has no write method", FD);
+               return 0;
+       }
 
        if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
                Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
index 6b80a5e..2dbcfc2 100644 (file)
@@ -9,18 +9,19 @@ ASFLAGS = -felf
 CPPFLAGS = -Wall
 CFLAGS = $(CPPFLAGS)
 LDFLAGS = -L $(OUTPUTDIR)Libs -lacess-native
-LIBGCC_PATH = $(ACESSDIR)/AcessNative/symbol_renames.ld
+#LIBGCC_PATH = $(ACESSDIR)/AcessNative/symbol_renames.ld
 else
 ASFLAGS = -felf
 CPPFLAGS = -ffreestanding
 CFLAGS   = -fno-stack-protector -fno-builtin $(CPPFLAGS)
-LDFLAGS  = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o -lposix
+LDFLAGS  = -T $(OUTPUTDIR)Libs/acess.ld -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o -lposix
 LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name)
 
 endif
 
 CPPFLAGS += $(addprefix -I,$(wildcard $(ACESSUSERDIR)Libraries/*/include_exp/))
 CPPFLAGS += -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR)
+LDFLAGS += -rpath-link $(OUTPUTDIR)Libs
 
 # Extra-verbose errors!
 #CFLAGS += -Wall -Wextra -Wwrite-strings -Wshadow -Wswitch-default -Wswitch-enum -Wstrict-overflow=5 -Wfloat-equal -Wundef -Wmissing-declarations -Wlogical-op  -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wsync-nand -Wunused -Wstrict-overflow=5 -Wfloat-equal -Wundef -Wno-endif-labels -Wshadow -Wunsafe-loop-optimizations -Wbad-function-cast -Wc++-compat -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-declarations -Wnormalized=nfc -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wdisabled-optimization -Woverlength-strings
index f42e660..472349c 100644 (file)
@@ -6,6 +6,13 @@
 CFLAGS  += -g
 LDFLAGS += -g
 
+LDFLAGS += -Map $(_OBJPREFIX)Map.txt
+
+ifneq ($(lastword $(subst -, ,$(basename $(LD)))),ld)
+  LDFLAGS := $(subst -rpath-link ,-Wl$(comma)-rpath-link$(comma),$(LDFLAGS))
+  LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS))
+endif
+
 _BIN := $(OUTPUTDIR)$(DIR)/$(BIN)
 _OBJPREFIX := obj-$(ARCH)/
 
@@ -40,12 +47,7 @@ install: $(_BIN)
 $(_BIN): $(OUTPUTDIR)Libs/acess.ld $(OUTPUTDIR)Libs/crt0.o $(_LIBS) $(OBJ)
        @mkdir -p $(dir $(_BIN))
        @echo [LD] -o $@
-#ifeq ($(ARCHDIR),native)
-#      $V$(LD) -g -o [email protected] -r $(OBJ) $(LIBGCC_PATH)
-#      $V$(LD) -g $(LDFLAGS) -o $@ [email protected] -Map $(_OBJPREFIX)Map.txt
-#else
-       $V$(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map $(_OBJPREFIX)Map.txt $(LIBGCC_PATH)
-#endif
+       $V$(LD) -g $(LDFLAGS) -o $@ $(OBJ) $(LIBGCC_PATH)
        $V$(DISASM) $(_BIN) > $(_OBJPREFIX)$(BIN).dsm
 
 $(OBJ): $(_OBJPREFIX)%.o: %.c
index 1d83314..a9266b4 100644 (file)
@@ -39,6 +39,8 @@ const char    *gsMouseDevice = NULL;
 #define __INSTALL_ROOT "/Acess/Apps/AxWin/3.0"
 
 const char     *gsInstallRoot = __INSTALL_ROOT;
+const char     *gsInterfaceApp = __INSTALL_ROOT"/AxWinUI";
+ int   gbNoSpawnUI = 0;
 
 // === CODE ===
 /**
@@ -76,17 +78,17 @@ int main(int argc, char *argv[])
        WM_Hotkey_Register(2, keys, "Interface>TextEdit");
        
        // Spawn interface root
+       if( !gbNoSpawnUI )
        {
                int     server_tid = gettid();
                _SysDebug("server_tid = %i", server_tid);
-               static char csInterfaceApp[] = __INSTALL_ROOT"/AxWinUI";
                char    server_info[] = "AXWIN3_SERVER=00000";
                const char      *envp[] = {server_info, NULL};
-               const char      *argv[] = {csInterfaceApp, NULL};
+               const char      *argv[] = {gsInterfaceApp, NULL};
                _SysDebug("server_tid = %i, &server_tid = %p", server_tid, &server_tid);
                sprintf(server_info, "AXWIN3_SERVER=%i", server_tid);
                // TODO: Does the client need FDs?
-                int    rv = _SysSpawn(csInterfaceApp, argv, envp, 0, NULL, NULL);
+                int    rv = _SysSpawn(gsInterfaceApp, argv, envp, 0, NULL, NULL);
                if( rv < 0 ) {
                        _SysDebug("_SysSpawn chucked a sad, rv=%i, errno=%i", rv, _errno);
                }
@@ -116,8 +118,37 @@ int main(int argc, char *argv[])
        return 0;
 }
 
+void PrintUsage(void)
+{
+       fprintf(stderr, "Arguments:\n");
+       fprintf(stderr, "  --no-ui  : Don't spawn the UI process\n");
+}
+
 void ParseCommandline(int argc, char **argv)
 {
-       
+       for( int i = 1; i < argc; i ++ )
+       {
+               if( argv[i][0] != '-' ) {
+                       // Error?
+                       PrintUsage();
+                       exit(-1);
+               }
+               else if( argv[i][1] != '-' ) {
+                       // Short
+                       PrintUsage();
+                       exit(-1);
+               }
+               else {
+                       // Long
+                       if( strcmp(argv[i], "--no-ui") == 0 ) {
+                               gbNoSpawnUI = 1;
+                       }
+                       else {
+                               // Error.
+                               PrintUsage();
+                               exit(-1);
+                       }
+               }
+       }
 }
 
index 1b9ffab..a30dd37 100644 (file)
@@ -49,9 +49,10 @@ void Video_Setup(void)
        giTerminalFD_Input = 0;
        // Check that the console is a VT
        // - _SysIOCtl(..., 0, NULL) returns the type, which should be 2
-       if( _SysIOCtl(1, 0, NULL) != 2 )
+       tmpInt = _SysIOCtl(1, 0, NULL);
+       if( tmpInt != 2 )
        {
-               fprintf(stderr, "stdout is not an Acess VT, can't start");
+               fprintf(stderr, "stdout is not an Acess VT, can't start (2 exp, %i got)\n", tmpInt);
                _SysDebug("stdout is not an Acess VT, can't start");
                exit(-1);
        }
index 19ee8fd..ce00d85 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <stdint.h>
 
-extern void    _SysDebug(const char *Fmt, ...);
+#include <acess/sys.h> // _SysDebug
 
 struct sAxWin3_Window
 {
index 4aafe56..a9a0eef 100644 (file)
@@ -5,8 +5,22 @@
 
 MAKEDEP  = $(CC) -M
 
-ASFLAGS  += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1
-CPPFLAGS := -ffreestanding -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1
+ifeq ($(ARCHDIR),native)
+ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1
+LDFLAGS := -lacess-native
+ ifeq ($(PLATFORM),windows)
+ else
+  LDFLAGS += -Wl,-init,SoMain
+  CFLAGS += -fPIC
+ endif
+else
+CPPFLAGS := -ffreestanding
+CFLAGS   := -fno-stack-protector -fPIC
+LDFLAGS  := -I/Acess/Libs/ld-acess.so -lld-acess `$(CC) -print-libgcc-file-name`
+endif
+CPPFLAGS += -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1
 CPPFLAGS += $(addprefix -I,$(wildcard $(ACESSUSERDIR)Libraries/*/include_exp/))
-CFLAGS   := -g -Wall -fPIC -fno-stack-protector -O3
-LDFLAGS  := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -lld-acess -e SoMain -x -L$(OUTPUTDIR)Libs/ --no-undefined `$(CC) -print-libgcc-file-name`
+CFLAGS += -Wall -g
+LDFLAGS += -g -nostdlib -shared -eSoMain -x --no-undefined -L$(OUTPUTDIR)Libs/
+
+# vim: ft=make
index 7749521..652d5a2 100644 (file)
@@ -2,6 +2,14 @@
 # - Library Common Makefile
 #
 
+comma=,
+
+ifneq ($(lastword $(subst -, ,$(basename $(LD)))),ld)
+  LDFLAGS := $(subst -soname ,-Wl$(comma)-soname$(comma),$(LDFLAGS))
+  LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS))
+  LDFLAGS := $(LDFLAGS:-x=-Wl,-x)
+  LDFLAGS := $(LDFLAGS:--%=-Wl,--%)
+endif
 
 _BIN := $(addprefix $(OUTPUTDIR)Libs/,$(BIN))
 _XBIN := $(addprefix $(OUTPUTDIR)Libs/,$(EXTRABIN))
diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/_native_syscallmod.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/_native_syscallmod.h
new file mode 100644 (file)
index 0000000..c368a29
--- /dev/null
@@ -0,0 +1,45 @@
+
+#define _exit  acess__exit
+#define _SysClone      acess__SysClone
+#define _SysKill       acess__SysKill
+#define _SysWaitEvent  acess__SysWaitEvent
+#define _SysWaitTID    acess__SysWaitTID
+#define gettid acess_gettid
+#define getpid acess_getpid
+#define getuid acess_getuid
+#define getgid acess_getgid
+#define setuid acess_setuid
+#define setgid acess_setgid
+#define _SysSetName    acess__SysSetName
+#define _SysGetName    acess__SysGetName
+#define _SysTimestamp  acess__SysTimestamp
+#define _SysSetPri     acess__SysSetPri
+#define _SysSendMessage        acess__SysSendMessage
+#define _SysGetMessage acess__SysGetMessage
+#define _SysSpawn      acess__SysSpawn
+#define _SysExecVE     acess__SysExecVE
+#define SysLoadBin     acess_SysLoadBin
+#define _SysUnloadBin  acess__SysUnloadBin
+#define _SysSetFaultHandler    acess__SysSetFaultHandler
+#define _SysDebug      acess__SysDebug
+#define _SysGetPhys    acess__SysGetPhys
+#define _SysAllocate   acess__SysAllocate
+#define _SysSetMemFlags        acess__SysSetMemFlags
+#define _SysOpen       acess__SysOpen
+#define _SysOpenChild  acess__SysOpenChild
+#define _SysReopen     acess__SysReopen
+#define _SysClose      acess__SysClose
+#define _SysRead       acess__SysRead
+#define _SysWrite      acess__SysWrite
+#define _SysSeek       acess__SysSeek
+#define _SysTell       acess__SysTell
+#define _SysFInfo      acess__SysFInfo
+#define _SysReadDir    acess__SysReadDir
+#define _SysGetACL     acess__SysGetACL
+#define _SysChdir      acess__SysChdir
+#define _SysIOCtl      acess__SysIOCtl
+#define _SysMount      acess__SysMount
+#define _SysSelect     acess__SysSelect
+#define _SysUnlink     acess__SysUnlink
+
+#define _errno acess__errno
index d9d3173..21e40ae 100644 (file)
@@ -35,6 +35,9 @@
 #define FILEFLAG_SYMLINK       0x20
 #define CLONE_VM       0x10
 
+#ifdef ARCHDIR_is_native
+# include "_native_syscallmod.h"
+#endif
 
 // === TYPES ===
 
index 0fd1e5b..f95e086 100644 (file)
@@ -17,6 +17,9 @@ OBJ += arch/$(ARCHDIR).ao
 # signals.o\r
 DEPFILES := $(OBJ:%.o=%.d)\r
 BIN = libc.so\r
+ifeq ($(ARCHDIR),native)\r
+ BIN = libc_acess.so\r
+endif\r
 \r
 include ../Makefile.tpl\r
 \r
index cbe8749..c7f5b49 100644 (file)
@@ -3,8 +3,8 @@
 
 // TODO: Fully implement errno.h, make sure it matches the kernel one
 
-extern int     _errno;
-#define        errno   _errno
+extern int     *libc_geterrno();
+#define        errno   (*libc_geterrno())
 
 #define strerror(_x)   "Unimplemented"
 
index f8b71d3..c33019e 100644 (file)
@@ -2,7 +2,7 @@
  * AcessOS Basic C Library
  * signals.c
 */
-//#include <acess/sys.h>
+#include <acess/sys.h>
 #include <stdlib.h>
 #include <signal.h>
 #include "lib.h"
index 6b64fb6..7e535a7 100644 (file)
@@ -100,6 +100,11 @@ int ErrorHandler(int Fault)
        return -1;\r
 }\r
 \r
+EXPORT int *libc_geterrno()\r
+{\r
+       return &_errno;\r
+}\r
+\r
 #if USE_CPUID\r
 /**\r
  * \brief Call the CPUID opcode\r
index 737e4d6..628999c 100644 (file)
@@ -6,7 +6,7 @@
 CPPFLAGS += \r
 CFLAGS   += -Werror -Wextra\r
 ASFLAGS  +=\r
-LDFLAGS  += -soname libposix.so -Map map.txt\r
+LDFLAGS  += -soname libposix.so -Map map.txt -lc\r
 \r
 OBJ  = main.o unistd.o dirent.o stat.o\r
 DEPFILES := $(OBJ:%.o=%.d)\r

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