--- /dev/null
+#!/bin/sh
+trap '' 2
+./AcessKernel --rootapp /Acess/SBin/login
+trap 2
+killall ld-acess
* - Host filesystem access\r
*/\r
#define DEBUG 1\r
+#define off_t _acess_off_t\r
#include <acess.h> // Acess\r
#include <vfs.h> // Acess\r
+#undef off_t\r
#include <dirent.h> // Posix\r
#include <sys/stat.h> // Posix\r
#include <stdio.h> // Posix\r
// Get the response
retHeader = SyscallRecieve(Client->CurrentRequest, &retSize);
- Log_Debug("AcessSrv", "Client %i request %i",
- Client->ClientID, Client->CurrentRequest->CallID);
+ {
+ int callid = Client->CurrentRequest->CallID;
+ Log_Debug("AcessSrv", "Client %i request %i %s",
+ Client->ClientID, callid,
+ callid < N_SYSCALLS ? casSYSCALL_NAMES[callid] : "UNK"
+ );
+ }
if( !retHeader ) {
retHeader->ClientID = Client->ClientID;
// Mark the thread as ready for another job
+ free(Client->CurrentRequest);
Client->CurrentRequest = 0;
- Log_Debug("AcessSrv", "Sending %i to %x:%i (Client %i)",
- retSize, ntohl(Client->ClientAddr.sin_addr.s_addr),
- ntohs(Client->ClientAddr.sin_port),
- Client->ClientID
- );
+// Log_Debug("AcessSrv", "Sending %i to %x:%i (Client %i)",
+// retSize, ntohl(Client->ClientAddr.sin_addr.s_addr),
+// ntohs(Client->ClientAddr.sin_port),
+// Client->ClientID
+// );
// Return the data
sentSize = sendto(gSocket, retHeader, retSize, 0,
// Hand off to a worker thread
// - TODO: Actually have worker threads
- printf("%i bytes from %x:%i\n", length,
- ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
+// Log_Debug("Server", "%i bytes from %x:%i", length,
+// ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
client = Server_GetClient(req->ClientID);
// NOTE: Hack - Should check if all zero
Log_Debug("AcessSrv", "Message from Client %i (%p)",
client->ClientID, client);
-
+
+ // Make a copy of the request data
+ req = malloc(length);
+ memcpy(req, data, length);
client->CurrentRequest = req;
SDL_CondSignal(client->WaitFlag);
#endif
return Threads_SetGID(a0);
);
-SYSCALL1(Syscall_Fork, "d", int *,
+SYSCALL1(Syscall_AN_Fork, "d", int *,
if(Sizes[0] < sizeof(int))
return -1;
*a0 = Threads_Fork();
Syscall_SetGID,
Syscall_Sleep,
- Syscall_Fork,
+ Syscall_AN_Fork,
NULL,
NULL,
#define _SIGNAL_H_ // Stop the acess signal.h being used
#define _HEAP_H_ // Stop heap.h being imported (collides with stdlib heap)
#define _VFS_EXT_H // Stop vfs_ext.h being imported (collides with fd_set)
-#undef CLONE_VM // Such a hack
+
+#define off_t _acess_off_t
#include <arch.h>
#undef NULL // Remove acess definition
#include <acess.h>
#include <mutex.h>
#include <semaphore.h>
+#include <events.h>
+
+#undef CLONE_VM // Such a hack
+#undef off_t
+
+// - Native headers
#include <unistd.h>
#include <sys/types.h>
#include <stdint.h>
#include "/usr/include/signal.h"
#include <SDL/SDL.h>
+#define THREAD_EVENT_WAKEUP 0x80000000
+
// === IMPORTS ===
void VFS_CloneHandleList(int PID);
ret->TID = giThreads_NextThreadID ++;
ret->ThreadName = strdup(TemplateThread->ThreadName);
+ ret->EventSem = SDL_CreateSemaphore(0);
ret->WaitingThreads = NULL;
ret->WaitingThreadsEnd = NULL;
tTID Threads_GetTID() { return gpCurrentThread->TID; }
tPID Threads_GetPID() { return gpCurrentThread->PID; }
-int Threads_SetUID(int *Errno, tUID NewUID)
+int Threads_SetUID(tUID NewUID)
{
if(Threads_GetUID() != 0) {
- if(Errno) *Errno = -EACCES;
+ errno = EACCES;
return -1;
}
return 0;
}
-int Threads_SetGID(int *Errno, tGID NewGID)
+int Threads_SetGID(tGID NewGID)
{
if(Threads_GetUID() != 0) {
- if(Errno) *Errno = -EACCES;
+ errno = -EACCES;
return -1;
}
char **Threads_GetChroot(void) { return &gpCurrentThread->Process->Chroot; }
int *Threads_GetMaxFD(void) { return &gpCurrentThread->Process->MaxFD; };
-int Threads_WaitTID(int TID, int *Status)
+tTID Threads_WaitTID(int TID, int *Status)
{
// Any Child
if(TID == -1) {
thread->WaitingThreadsEnd = us;
}
- while(thread->State != 0)
- {
- pause();
- Log_Debug("Threads", "Huh?... state = %i", thread->State);
- }
+ Threads_WaitEvents( THREAD_EVENT_WAKEUP );
if(Status) *Status = thread->ExitStatus;
thread->WaitingThreads = thread->WaitingThreads->Next;
int Threads_Wake(tThread *Thread)
{
Thread->State = 0;
- kill( Thread->KernelTID, SIGUSR1 );
+ Threads_PostEvent(Thread, THREAD_EVENT_WAKEUP);
return 0;
}
Uint32 Threads_WaitEvents(Uint32 Mask)
{
Uint32 rv;
+
+ Log_Debug("Threads", "Mask = %x, ->Events = %x", Mask, gpCurrentThread->Events);
+
gpCurrentThread->WaitMask = Mask;
if( !(gpCurrentThread->Events & Mask) )
+ {
SDL_SemWait( gpCurrentThread->EventSem );
+ }
rv = gpCurrentThread->Events & Mask;
gpCurrentThread->Events &= ~Mask;
gpCurrentThread->WaitMask = -1;
+
return rv;
}
void Threads_PostEvent(tThread *Thread, Uint32 Events)
{
Thread->Events |= Events;
+ Log_Debug("Threads", "Trigger event %x (->Events = %p)", Events, Thread->Events);
- if( Thread->WaitMask & Events )
- SDL_SemPost( gpCurrentThread->EventSem );
+ if( Thread->WaitMask & Events ) {
+ SDL_SemPost( Thread->EventSem );
+// Log_Debug("Threads", "Waking %p(%i %s)", Thread, Thread->TID, Thread->ThreadName);
+ }
}
// Set up video
SDL_Init(SDL_INIT_VIDEO);
printf("UI attempting %ix%i %ibpp\n", giUI_Width, giUI_Height, 32);
- gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0);
+ gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, SDL_DOUBLEBUF);
if( !gScreen ) {
fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError());
SDL_Quit();
gUI_KeyboardCallback(KEY_ACTION_RELEASE|acess_sym);
}
break;
-
+
+ case SDL_USEREVENT:
+ SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);
+ SDL_Flip(gScreen);
+ break;
+
default:
break;
}
void UI_Redraw(void)
{
// TODO: Keep track of changed rectangle
- SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);
+// SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);
+ SDL_Event e;
+
+ e.type = SDL_USEREVENT;
+ e.user.code = 0;
+ e.user.data1 = 0;
+ e.user.data2 = 0;
+
+ SDL_PushEvent( &e );
}
/*
* AcessNative
*/
+#define DEBUG 1
#include "common.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#define LIBRARY_PATH "$$$$../Usermode/Output/x86/Libs"
+#define LIBRARY_PATH "$$$$../Usermode/Output/x86_64/Libs"
// === TYPES ===
typedef struct sBinary {
}
#if DEBUG
- printf("fmt->Load(%i)...\n", fd);
+ printf("fmt->Load(0x%x)...\n", fd);
#endif
ret = fmt->Load(fd);
acess_close(fd);
#if DEBUG
- printf("fmt->Load(%p): %p\n", fd, ret);
+ printf("fmt->Load(0x%x): %p\n", fd, ret);
#endif
if( !ret ) {
return NULL;
extern int vprintf(const char *, va_list);
extern int strncmp(const char *, const char *, size_t);
+extern int gSocket;
extern int giSyscall_ClientID; // Needed for execve
+extern void _InitSyscalls(void);
+extern void _CloseSyscalls(void);
+
extern void Debug(const char *Format, ...);
extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
extern int fork(void);
if(flags & CLONE_VM) {
int ret, newID, kernel_tid=0;
- printf("fork()");
+ printf("USERSIDE fork()\n");
- newID = _Syscall(SYS_FORK, "<d", sizeof(int), &kernel_tid);
+ newID = _Syscall(SYS_AN_FORK, "<d", sizeof(int), &kernel_tid);
ret = fork();
- if(ret < 0) return ret;
+ if(ret < 0) {
+ return ret;
+ }
if(ret == 0)
{
+ _CloseSyscalls();
+ _InitSyscalls();
giSyscall_ClientID = newID;
return 0;
}
// Get argument count
for( argc = 0; argv[argc]; argc ++ ) ;
DEBUG(" acess_execve: argc = %i", argc);
-
- char *new_argv[5+argc+1];
- char key[11];
- sprintf(key, "%i", giSyscall_ClientID);
+
+ char *new_argv[7+argc+1];
+ char client_id_str[11];
+ char socket_fd_str[11];
+ sprintf(client_id_str, "%i", giSyscall_ClientID);
+ sprintf(socket_fd_str, "%i", gSocket);
new_argv[0] = "ld-acess"; // TODO: Get path to ld-acess executable
- new_argv[1] = "--key"; // Set socket/client ID for Request.c
- new_argv[2] = key;
- new_argv[3] = "--binary"; // Set the binary path (instead of using argv[0])
- new_argv[4] = path;
- for( i = 0; i < argc; i ++ ) new_argv[5+i] = argv[i];
- new_argv[5+i] = NULL;
+ new_argv[1] = "--key"; // Set client ID for Request.c
+ new_argv[2] = client_id_str;
+ new_argv[3] = "--socket"; // Socket
+ new_argv[4] = socket_fd_str;
+ new_argv[5] = "--binary"; // Set the binary path (instead of using argv[0])
+ new_argv[6] = path;
+ for( i = 0; i < argc; i ++ ) new_argv[7+i] = argv[i];
+ new_argv[7+i] = NULL;
#if 1
- argc += 5;
+ argc += 7;
for( i = 0; i < argc; i ++ )
printf("\"%s\" ", new_argv[i]);
printf("\n");
#include <string.h>
// === IMPORTS ===
+extern int gSocket;
extern int giSyscall_ClientID;
extern void acess__exit(int Status);
+extern void Request_Preinit(void);
// === PROTOTYPES ===
void CallUser(void *Entry, int argc, char *argv[], char **envp) __attribute__((noreturn));
void *base;
int rv;
+ Request_Preinit();
+
// int syscall_handle = -1;
for( i = 1; i < argc; i ++ )
giSyscall_ClientID = atoi(argv[++i]);
continue ;
}
+
+ if(strcmp(argv[i], "--socket") == 0) {
+ gSocket = atoi(argv[++i]);
+ continue ;
+ }
if(strcmp(argv[i], "--binary") == 0) {
appPath = argv[++i];
struct sockaddr_in gSyscall_ServerAddr;
// === CODE ===
-int _InitSyscalls()
+void Request_Preinit(void)
+{
+ // Set server address
+ memset((void *)&gSyscall_ServerAddr, '\0', sizeof(struct sockaddr_in));
+ gSyscall_ServerAddr.sin_family = AF_INET;
+ gSyscall_ServerAddr.sin_port = htons(SERVER_PORT);
+}
+
+int _InitSyscalls(void)
{
-
#ifdef __WIN32__
/* Open windows connection */
if (WSAStartup(0x0101, &gWinsock) != 0)
exit(0);
}
- // Set server address
- memset((void *)&gSyscall_ServerAddr, '\0', sizeof(struct sockaddr_in));
- gSyscall_ServerAddr.sin_family = AF_INET;
- gSyscall_ServerAddr.sin_port = htons(SERVER_PORT);
- gSyscall_ServerAddr.sin_addr.s_addr = htonl(0x7F000001);
-
#if 0
// Set client address
memset((void *)&client, '\0', sizeof(struct sockaddr_in));
#endif
exit(0);
}
- giSyscall_ClientID = gSocket; // A bit of a hack really :(
#endif
#if 0
return 0;
}
+/**
+ * \brief Close the syscall socket
+ * \note Used in acess_fork to get a different port number
+ */
+void _CloseSyscalls(void)
+{
+ #if __WIN32__
+ closesocket(gSocket);
+ WSACleanup();
+ #else
+ close(gSocket);
+ #endif
+}
+
int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize)
{
if( gSocket == INVALID_SOCKET )
// IPC
SYS_SLEEP,
- SYS_FORK,
+ SYS_AN_FORK,
SYS_SENDMSG,
SYS_GETMSG,
SYS_SELECT,
"SYS_GETACL",
"SYS_MOUNT",
"SYS_REOPEN",
+ "SYS_CHDIR",
+
+ "SYS_WAITTID",
+ "SYS_SETUID",
+ "SYS_SETGID",
// IPC
- "SYS_SLEEP"
+ "SYS_SLEEP",
+ "SYS_AN_FORK",
+ "SYS_SENDMSG",
+ "SYS_GETMSG",
+ "SYS_SELECT"
};
#endif