);
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;
}
}
// --- Timekeeping ---
-int64_t acess_SysTimestamp(void)
+int64_t acess__SysTimestamp(void)
{
// TODO: Better impl
// return now()*1000;
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;
}
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);
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)
#include "../ld-acess_src/exports.c"
+
+void *_crt0_exit_handler;
+
+int *libc_geterrno(void)
+{
+ return &acess__errno;
+}
+
+
/*
*/
#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
printf("\n");
}
+void __libc_csu_fini()
+{
+}
+
+void __libc_csu_init()
+{
+}
+
ARCHDIR := native
-LD ?= $(CC) -print-prog-name=ld
+#LD ?= $(CC) -print-prog-name=ld
+LD = $(CC)
AS = $(CC) -c
ASSUFFIX = S
}
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);
}
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,
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
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)/
$(_BIN): $(OUTPUTDIR)Libs/acess.ld $(OUTPUTDIR)Libs/crt0.o $(_LIBS) $(OBJ)
@mkdir -p $(dir $(_BIN))
@echo [LD] -o $@
-#ifeq ($(ARCHDIR),native)
-#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
#define __INSTALL_ROOT "/Acess/Apps/AxWin/3.0"
const char *gsInstallRoot = __INSTALL_ROOT;
+const char *gsInterfaceApp = __INSTALL_ROOT"/AxWinUI";
+ int gbNoSpawnUI = 0;
// === CODE ===
/**
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);
}
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);
+ }
+ }
+ }
}
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);
}
#include <stdint.h>
-extern void _SysDebug(const char *Fmt, ...);
+#include <acess/sys.h> // _SysDebug
struct sAxWin3_Window
{
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
# - 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))
--- /dev/null
+
+#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
#define FILEFLAG_SYMLINK 0x20
#define CLONE_VM 0x10
+#ifdef ARCHDIR_is_native
+# include "_native_syscallmod.h"
+#endif
// === TYPES ===
# 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
// 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"
* AcessOS Basic C Library
* signals.c
*/
-//#include <acess/sys.h>
+#include <acess/sys.h>
#include <stdlib.h>
#include <signal.h>
#include "lib.h"
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
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