--- /dev/null
+Provides Acess Kernel services\r
+- UDP Server listening on 127.0.0.1:2766 (0XACE)\r
+ > See ld-acess.so_src/syscalls for the spec\r
+- Starts acess applications\r
+ > Provides kernel loader services and loads libacess\r
+- Provides "vterms" / control panel\r
+- Cross platform (GTK?/SDL)
\ No newline at end of file
--- /dev/null
+# AcessNative Server\r
+# Makefile\r
+\r
+ifeq ($(PLATFORM),)\r
+ PLATFORM := lin\r
+endif\r
+\r
+KERNEL_SRC = ../../Kernel/\r
+\r
+KERNEL_OBJ := logging.o adt.o\r
+KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o vfs/nodecache.o vfs/mount.o\r
+KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
+KERNEL_OBJ += drv/vterm.o drv/fifo.o\r
+\r
+OBJ := main.o video.o keyboard.o mouse.o nativefs.o vfs_handle.o\r
+OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ))\r
+\r
+OBJ := $(addsuffix .$(PLATFORM),$(OBJ))\r
+\r
+CPPFLAGS += -I include/ -I $(KERNEL_SRC)include/\r
+CFLAGS += -Wall\r
+LDFLAGS += -lSDL -lSDLmain\r
+\r
+ifeq ($(PLATFORM),win)\r
+ BIN := ../AcessKernel.exe\r
+endif\r
+ifeq ($(PLATFORM),lin)\r
+ BIN := ../AcessKernel\r
+ CFLAGS +=\r
+endif\r
+\r
+.PHONY: all clean\r
+\r
+all: $(BIN)\r
+\r
+clean:\r
+ $(RM) $(BIN) $(OBJ)\r
+\r
+$(BIN): $(OBJ)\r
+ $(CC) $(LDFLAGS) -o $@ $(OBJ)\r
+\r
+%.o.$(PLATFORM): %.c\r
+ $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)\r
--- /dev/null
+/**
+ */
+#ifndef _ARCH_H_
+#define _ARCH_H_
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#define _MODULE_NAME_ "NativeKernel"
+
+#define BITS (sizeof(intptr_t)*8)
+
+typedef uint8_t Uint8;
+typedef uint16_t Uint16;
+typedef uint32_t Uint32;
+typedef uint64_t Uint64;
+
+typedef int8_t Sint8;
+typedef int16_t Sint16;
+typedef int32_t Sint32;
+typedef int64_t Sint64;
+
+typedef intptr_t Uint;
+
+typedef intptr_t tVAddr;
+typedef intptr_t tPAddr;
+
+struct sShortSpinlock
+{
+ int Lock;
+};
+
+#define SHORTLOCK(...)
+#define SHORTREL(...)
+
+#endif
+
--- /dev/null
+/**
+ */
+#ifndef _HEAP_H_
+#define _HEAP_H_
+
+// NOP (stdlib.h defines the heap functions)
+
+#endif
--- /dev/null
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * Kernel Main
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL/SDL.h>
+
+int main(int argc, char *argv[])
+{
+ return 0;
+}
+
+void LogF(const char *Fmt, ...)
+{
+ va_list args;
+ va_start(args, Fmt);
+ vprintf(Fmt, args);
+ va_end(args);
+}
+
+void Log(const char *Fmt, ...)
+{
+ va_list args;
+ printf("Log: ");
+ va_start(args, Fmt);
+ vprintf(Fmt, args);
+ va_end(args);
+ printf("\n");
+}
+
+void Warning(const char *Fmt, ...)
+{
+ va_list args;
+ printf("Warning: ");
+ va_start(args, Fmt);
+ vprintf(Fmt, args);
+ va_end(args);
+ printf("\n");
+}
+
+int CheckMem(void *Mem, int Count)
+{
+ return 1;
+}
+
+int CheckString(const char *String)
+{
+ return 1;
+}
--- /dev/null
+/*\r
+ * Acess2 Native Kernel\r
+ * - Acess kernel emulation on another OS using SDL and UDP\r
+ *\r
+ * nativefs.c\r
+ * - Host filesystem access\r
+ */\r
+#include <acess.h>\r
+#include <vfs.h>\r
+\r
+// === GLOBALS ===\r
+\r
+// === CODE ===\r
+tVFS_Node *Native_Mount(const char *Device, const char **Arguments)\r
+{\r
+ return NULL;\r
+}\r
--- /dev/null
+/*
+ * Acess2 VFS
+ * - AllocHandle, GetHandle
+ */
+#define DEBUG 0
+#include <acess.h>
+#include "vfs.h"
+#include "vfs_int.h"
+#include "vfs_ext.h"
+
+// === CONSTANTS ===
+#define MAX_KERNEL_FILES 128
+#define MAX_USER_FILES 64
+
+// === PROTOTYPES ===
+tVFS_Handle *VFS_GetHandle(int FD);
+ int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
+
+typedef struct sUserHandles
+{
+ struct sUserHandles *Next;
+ int PID;
+ tVFS_Handle Handles[MAX_USER_FILES];
+} tUserHandles;
+
+// === GLOBALS ===
+tUserHandles *gpUserHandles = NULL;
+tVFS_Handle gaKernelHandles[MAX_KERNEL_FILES];
+
+// === CODE ===
+/**
+ * \fn tVFS_Handle *VFS_GetHandle(int FD)
+ * \brief Gets a pointer to the handle information structure
+ */
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+ tVFS_Handle *h;
+
+ //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+
+ if(FD < 0) return NULL;
+
+ if(FD & VFS_KERNEL_FLAG) {
+ FD &= (VFS_KERNEL_FLAG - 1);
+ if(FD >= MAX_KERNEL_FILES) return NULL;
+ h = &gaKernelHandles[ FD ];
+ }
+ else {
+ tUserHandles *ent;
+ int pid = Threads_GetPID();
+ for( ent = gpUserHandles; ent; ent = ent->Next ) {
+ if( ent->PID == pid ) break;
+ if( ent->PID > pid ) {
+ Log_Error("VFS", "PID %i does not have a handle list", pid);
+ return NULL;
+ }
+ }
+ if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
+ h = &ent->Handles[ FD ];
+ }
+
+ if(h->Node == NULL) return NULL;
+ //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
+ return h;
+}
+
+int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
+{
+ int i;
+
+ // Check for a user open
+ if(bIsUser)
+ {
+ tUserHandles *ent, *prev;
+ int pid = Threads_GetPID();
+ for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) {
+ if( ent->PID == pid ) break;
+ if( ent->PID > pid ) break;
+ }
+ if( ent->PID > pid ) {
+ ent = calloc( 1, sizeof(tUserHandles) );
+ if( prev ) {
+ ent->Next = prev->Next;
+ prev->Next = ent;
+ }
+ else {
+ ent->Next = gpUserHandles;
+ gpUserHandles = ent;
+ }
+ }
+ // Get a handle
+ for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
+ {
+ if(ent->Handles[i].Node) continue;
+ ent->Handles[i].Node = Node;
+ ent->Handles[i].Position = 0;
+ ent->Handles[i].Mode = Mode;
+ return i;
+ }
+ }
+ else
+ {
+ // Get a handle
+ for(i=0;i<MAX_KERNEL_FILES;i++)
+ {
+ if(gaKernelHandles[i].Node) continue;
+ gaKernelHandles[i].Node = Node;
+ gaKernelHandles[i].Position = 0;
+ gaKernelHandles[i].Mode = Mode;
+ return i|VFS_KERNEL_FLAG;
+ }
+ }
+
+ return -1;
+}
--- /dev/null
+#
+#
+
+ifeq ($(PLATFORM),)
+ PLATFORM := lin
+endif
+
+OBJ := syscalls.$(PLATFORM).o request.$(PLATFORM).o
+
+ifeq ($(PLATFORM),win)
+ BIN := ../libacess.dll
+endif
+ifeq ($(PLATFORM),lin)
+ BIN := ../libacess.so
+ CFLAGS += -fPIC
+endif
+
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+ $(RM) $(BIN) $(OBJ)
+
+$(BIN): $(OBJ)
+ $(CC) -shared -o $@ $<
+
+%.$(PLATFORM).o: %.c
+ $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+
--- /dev/null
+/*
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <winsock.h>
+
+#define SERVER_PORT 0xACE
+
+// === GLOBALS ===
+#ifdef __WIN32__
+WSADATA gWinsock;
+SOCKET gSocket;
+#endif
+
+// === CODE ===
+int _InitSyscalls()
+{
+ struct sockaddr_in server;
+ struct sockaddr_in client;
+
+ #ifdef __WIN32__
+ /* Open windows connection */
+ if (WSAStartup(0x0101, &gWinsock) != 0)
+ {
+ fprintf(stderr, "Could not open Windows connection.\n");
+ exit(0);
+ }
+ #endif
+
+ // Open UDP Connection
+ gSocket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (gSocket == INVALID_SOCKET)
+ {
+ fprintf(stderr, "Could not create socket.\n");
+ WSACleanup();
+ exit(0);
+ }
+
+ // Set server address
+ memset((void *)&server, '\0', sizeof(struct sockaddr_in));
+ server.sin_family = AF_INET;
+ server.sin_port = htons(SERVER_PORT);
+ server.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127;
+ server.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0;
+ server.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0;
+ server.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1;
+
+ // Set client address
+ memset((void *)&client, '\0', sizeof(struct sockaddr_in));
+ client.sin_family = AF_INET;
+ client.sin_port = htons(0);
+ client.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127;
+ client.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0;
+ client.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0;
+ client.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1;
+
+ // Bind
+ if( bind(gSocket, (struct sockaddr *)&client, sizeof(struct sockaddr_in)) == -1 )
+ {
+ fprintf(stderr, "Cannot bind address to socket.\n");
+ closesocket(gSocket);
+ WSACleanup();
+ exit(0);
+ }
+}
+
+int _Syscall(const char *ArgTypes, ...)
+{
+ return 0;
+}
--- /dev/null
+/*
+ */
+//#include <acess/sys.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+// === IMPORTS ===
+/**
+ * \param ArgTypes
+ *
+ * Whitespace is ignored
+ * >i: Input Integer
+ * >I: Input Long Integer (64-bits)
+ * >s: Input String
+ * >d: Input Buffer (Preceded by valid size)
+ * <I: Output long integer
+ * <d: Output Buffer (Preceded by valid size)
+ */
+int _Syscall(const char *ArgTypes, ...)
+{
+ int outBufSize = 0;
+ va_list args;
+
+ va_start(args, ArgTypes);
+ va_end(args);
+
+}
+
+int open(const char *Path, int Flags) {
+ return _Syscall(">s >i", Path, Flags);
+}
+
+void close(int FD) {
+ _Syscall(">i", FD);
+}
+
+size_t read(int FD, size_t Bytes, void *Dest) {
+ return _Syscall(">i >i <d", FD, Bytes, Bytes, Dest);
+}
+
+size_t write(int FD, size_t Bytes, void *Src) {
+ return _Syscall(">i >i >d", FD, Bytes, Bytes, Src);
+}
+
+uint64_t tell(int FD) {
+ uint64_t ret;
+ _Syscall("<I >i", &ret, FD);
+ return ret;
+}
+
+int seek(int FD, uint64_t Ofs, int Dir) {
+ return _Syscall(">i >I >i", FD, Ofs, Dir);
+}
+
OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS)))
OBJ += drv/kb.o drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/vga.o
OBJ += binary.o bin/elf.o bin/pe.o
-OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o
+OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o vfs/handle.o
OBJ += vfs/fs/root.o vfs/fs/devfs.o
OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
OBJ := $(addsuffix .$(ARCH), $(OBJ))
*/
typedef struct sKernelSymbol {
char *Name;
- Uint Value;
+ tVAddr Value;
} tKernelSymbol;
-#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_name}
-#define EXPORTV(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)&_name}
-#define EXPORTAS(_sym,_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_sym}
+#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name}
+#define EXPORTV(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)&_name}
+#define EXPORTAS(_sym,_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_sym}
/**
* \}
*/
*/
extern int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
extern int sprintf(char *__s, const char *__format, ...);
-extern Uint strlen(const char *Str);
+extern size_t strlen(const char *Str);
extern char *strcpy(char *__dest, const char *__src);
extern char *strncpy(char *__dest, const char *__src, size_t max);
extern int strcmp(const char *__str1, const char *__str2);
* \}
*/
-extern Uint rand(void);
+extern int rand(void);
extern int CallWithArgArray(void *Function, int NArgs, Uint *Args);
// --- Heap ---
extern tGID Threads_GetGID(void);
extern int SpawnTask(tThreadFunction Function, void *Arg);
extern Uint *Threads_GetCfgPtr(int Id);
-extern int Threads_SetName(char *NewName);
+extern int Threads_SetName(const char *NewName);
extern void Mutex_Acquire(tMutex *Mutex);
extern void Mutex_Release(tMutex *Mutex);
extern int Mutex_IsLocked(tMutex *Mutex);
extern int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer);
extern int Proc_Execve(char *File, char **ArgV, char **EnvP);
extern Uint Binary_Load(char *file, Uint *entryPoint);
-extern int Threads_SetName(char *NewName);
extern int Threads_SetUID(Uint *errno, tUID ID);
extern int Threads_SetGID(Uint *errno, tGID ID);
extern int Threads_SetFaultHandler(Uint Handler);
extern tThread *Proc_GetCurThread(void);
extern int Proc_Clone(Uint *Err, Uint Flags);
extern void Proc_CallFaultHandler(tThread *Thread);
+extern int GetCPUNum(void);
// === PROTOTYPES ===
void Threads_Init(void);
- int Threads_SetName(char *NewName);
+ int Threads_SetName(const char *NewName);
char *Threads_GetName(int ID);
void Threads_SetPriority(tThread *Thread, int Pri);
tThread *Threads_CloneTCB(Uint *Err, Uint Flags);
}
/**
- * \fn void Threads_SetName(char *NewName)
+ * \fn void Threads_SetName(const char *NewName)
* \brief Sets the current thread's name
* \param NewName New name for the thread
* \return Boolean Failure
*/
-int Threads_SetName(char *NewName)
+int Threads_SetName(const char *NewName)
{
tThread *cur = Proc_GetCurThread();
char *oldname = cur->ThreadName;
{
SHORTLOCK( &glThreadListLock );
+ if( Thread->Status == THREAD_STAT_ACTIVE ) {
+ tThread *cur = Proc_GetCurThread();
+ Warning("WTF, CPU%i %p (%i %s) is adding %p (%i %s) when it is active",
+ GetCPUNum(), cur, cur->TID, cur->ThreadName, Thread, Thread->TID, Thread->ThreadName);
+ }
+
// Set state
Thread->Status = THREAD_STAT_ACTIVE;
Thread->CurCPU = -1;
#if SCHEDULER_TYPE == SCHED_LOTTERY
giFreeTickets += caiTICKET_COUNTS[ Thread->Priority ];
# if DEBUG_TRACE_TICKETS
- Log("Threads_AddActive: %p %i (%s) added, new giFreeTickets = %i",
- Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
+ Log("Threads_AddActive: CPU%i %p %i (%s) added, new giFreeTickets = %i",
+ GetCPUNum(), Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
# endif
#endif
// no need to decrement tickets, scheduler did it for us
#if SCHEDULER_TYPE == SCHED_LOTTERY && DEBUG_TRACE_TICKETS
- Log("Threads_RemActive: %p %i (%s) removed, giFreeTickets = %i",
- ret, ret->TID, ret->ThreadName, giFreeTickets);
+ Log("Threads_RemActive: CPU%i %p %i (%s) removed, giFreeTickets = %i",
+ GetCPUNum(), ret, ret->TID, ret->ThreadName, giFreeTickets);
#endif
SHORTREL( &glThreadListLock );
for(thread=gActiveThreads;thread;thread=thread->Next)
#endif
{
- Log(" %i (%i) - %s (CPU %i)",
- thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+ Log(" %p %i (%i) - %s (CPU %i)",
+ thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
if(thread->Status != THREAD_STAT_ACTIVE)
Log(" ERROR State (%i) != THREAD_STAT_ACTIVE (%i)", thread->Status, THREAD_STAT_ACTIVE);
Log(" Priority %i, Quantum %i", thread->Priority, thread->Quantum);
Log("All Threads:");
for(thread=gAllThreads;thread;thread=thread->GlobalNext)
{
- Log(" %i (%i) - %s (CPU %i)",
- thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+ Log(" %p %i (%i) - %s (CPU %i)",
+ thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
Log(" State %i (%s)", thread->Status, casTHREAD_STAT[thread->Status]);
switch(thread->Status)
{
--- /dev/null
+/*
+ * Acess2 VFS
+ * - AllocHandle, GetHandle
+ */
+#define DEBUG 0
+#include <acess.h>
+#include <mm_virt.h>
+#include "vfs.h"
+#include "vfs_int.h"
+#include "vfs_ext.h"
+
+// === CONSTANTS ===
+#define MAX_KERNEL_FILES 128
+
+// === PROTOTYPES ===
+tVFS_Handle *VFS_GetHandle(int FD);
+ int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
+
+// === GLOBALS ===
+tVFS_Handle *gaUserHandles = (void*)MM_PPD_VFS;
+tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS;
+
+// === CODE ===
+/**
+ * \fn tVFS_Handle *VFS_GetHandle(int FD)
+ * \brief Gets a pointer to the handle information structure
+ */
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+ tVFS_Handle *h;
+
+ //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+
+ if(FD < 0) return NULL;
+
+ if(FD & VFS_KERNEL_FLAG) {
+ FD &= (VFS_KERNEL_FLAG - 1);
+ if(FD >= MAX_KERNEL_FILES) return NULL;
+ h = &gaKernelHandles[ FD ];
+ } else {
+ if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
+ h = &gaUserHandles[ FD ];
+ }
+
+ if(h->Node == NULL) return NULL;
+ //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
+ return h;
+}
+
+int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
+{
+ int i;
+
+ // Check for a user open
+ if(bIsUser)
+ {
+ // Allocate Buffer
+ if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
+ {
+ Uint addr, size;
+ size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
+ for(addr = 0; addr < size; addr += 0x1000)
+ MM_Allocate( (Uint)gaUserHandles + addr );
+ memset( gaUserHandles, 0, size );
+ }
+ // Get a handle
+ for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
+ {
+ if(gaUserHandles[i].Node) continue;
+ gaUserHandles[i].Node = node;
+ gaUserHandles[i].Position = 0;
+ gaUserHandles[i].Mode = Mode;
+ return i;
+ }
+ }
+ else
+ {
+ // Allocate space if not already
+ if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
+ {
+ Uint addr, size;
+ size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
+ for(addr = 0; addr < size; addr += 0x1000)
+ MM_Allocate( (Uint)gaKernelHandles + addr );
+ memset( gaKernelHandles, 0, size );
+ }
+ // Get a handle
+ for(i=0;i<MAX_KERNEL_FILES;i++)
+ {
+ if(gaKernelHandles[i].Node) continue;
+ gaKernelHandles[i].Node = node;
+ gaKernelHandles[i].Position = 0;
+ gaKernelHandles[i].Mode = Mode;
+ return i|VFS_KERNEL_FLAG;
+ }
+ }
+
+ return -1;
+}
void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
{
Dest[0] = '$';
- itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
+ itoa( &Dest[1], (tVAddr)Base, 16, BITS/4, '0' );
Dest[BITS/4+1] = ':';
itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
Dest[BITS/2+2] = '\0';
*/
#define DEBUG 0
#include <acess.h>
-#include <mm_virt.h>
#include "vfs.h"
#include "vfs_int.h"
#include "vfs_ext.h"
// === CONSTANTS ===
#define OPEN_MOUNT_ROOT 1
-#define MAX_KERNEL_FILES 128
#define MAX_PATH_SLASHES 256
// === IMPORTS ===
extern tVFS_Node gVFS_MemRoot;
extern tVFS_Mount *gVFS_RootMount;
-// === GLOBALS ===
-tVFS_Handle *gaUserHandles = (void*)MM_PPD_VFS;
-tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS;
+extern tVFS_Handle *VFS_GetHandle(int FD);
+extern int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
// === CODE ===
/**
return -1;
}
- // Check for a user open
- if(Mode & VFS_OPENFLAG_USER)
- {
- // Allocate Buffer
- if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
- {
- Uint addr, size;
- size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
- for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaUserHandles + addr );
- memset( gaUserHandles, 0, size );
- }
- // Get a handle
- for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
- {
- if(gaUserHandles[i].Node) continue;
- gaUserHandles[i].Node = node;
- gaUserHandles[i].Position = 0;
- gaUserHandles[i].Mode = Mode;
- LEAVE('i', i);
- return i;
- }
- }
- else
- {
- // Allocate space if not already
- if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
- {
- Uint addr, size;
- size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
- for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaKernelHandles + addr );
- memset( gaKernelHandles, 0, size );
- }
- // Get a handle
- for(i=0;i<MAX_KERNEL_FILES;i++)
- {
- if(gaKernelHandles[i].Node) continue;
- gaKernelHandles[i].Node = node;
- gaKernelHandles[i].Position = 0;
- gaKernelHandles[i].Mode = Mode;
- LEAVE('x', i|VFS_KERNEL_FLAG);
- return i|VFS_KERNEL_FLAG;
- }
+ i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
+ if( i > 0 ) {
+ LEAVE('x', i);
+ return i;
}
Log("VFS_Open: Out of handles");
return -1;
}
- // Check for a user open
- if(Mode & VFS_OPENFLAG_USER)
- {
- // Allocate Buffer
- if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
- {
- Uint addr, size;
- size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
- for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaUserHandles + addr );
- memset( gaUserHandles, 0, size );
- }
- // Get a handle
- for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
- {
- if(gaUserHandles[i].Node) continue;
- gaUserHandles[i].Node = node;
- gaUserHandles[i].Position = 0;
- gaUserHandles[i].Mode = Mode;
- LEAVE('i', i);
- return i;
- }
- }
- else
- {
- // Allocate space if not already
- if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
- {
- Uint addr, size;
- size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
- for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaKernelHandles + addr );
- memset( gaKernelHandles, 0, size );
- }
- // Get a handle
- for(i=0;i<MAX_KERNEL_FILES;i++)
- {
- if(gaKernelHandles[i].Node) continue;
- gaKernelHandles[i].Node = node;
- gaKernelHandles[i].Position = 0;
- gaKernelHandles[i].Mode = Mode;
- LEAVE('x', i|VFS_KERNEL_FLAG);
- return i|VFS_KERNEL_FLAG;
- }
+ i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
+ if( i > 0 ) {
+ LEAVE('x', i);
+ return i;
}
Log_Error("VFS", "VFS_OpenChild - Out of handles");
return 1;
}
-/**
- * \fn tVFS_Handle *VFS_GetHandle(int FD)
- * \brief Gets a pointer to the handle information structure
- */
-tVFS_Handle *VFS_GetHandle(int FD)
-{
- tVFS_Handle *h;
-
- //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
-
- if(FD < 0) return NULL;
-
- if(FD & VFS_KERNEL_FLAG) {
- FD &= (VFS_KERNEL_FLAG - 1);
- if(FD >= MAX_KERNEL_FILES) return NULL;
- h = &gaKernelHandles[ FD ];
- } else {
- if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
- h = &gaUserHandles[ FD ];
- }
-
- if(h->Node == NULL) return NULL;
- //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
- return h;
-}
-
// === EXPORTS ===
EXPORT(VFS_Open);
EXPORT(VFS_Close);
if( !gbLink_CRCTableGenerated )
Link_InitCRC();
+ Threads_SetName(Adapter->Device);
+ Log_Log("NET", "Thread %i watching '%s'", Threads_GetTID(), Adapter->Device);
+
// Child Thread
while(Adapter->DeviceFD != -1)
{