mirror of https://gitlab.com/nakst/essence
cleanup
This commit is contained in:
parent
56b55da549
commit
d1aa62b26d
|
@ -858,9 +858,6 @@ private enum EsSyscallType {
|
|||
ES_SYSCALL_PIPE_CREATE
|
||||
ES_SYSCALL_PIPE_WRITE
|
||||
ES_SYSCALL_PIPE_READ
|
||||
ES_SYSCALL_MAILSLOT_CREATE
|
||||
ES_SYSCALL_MAILSLOT_SEND
|
||||
ES_SYSCALL_MAILSLOT_RESPOND
|
||||
|
||||
// Misc.
|
||||
|
||||
|
|
|
@ -189,7 +189,6 @@ enum KernelObjectType : uint32_t {
|
|||
KERNEL_OBJECT_NODE = 0x00000010, // A file system node (file or directory).
|
||||
KERNEL_OBJECT_EVENT = 0x00000020, // A synchronisation event.
|
||||
KERNEL_OBJECT_CONSTANT_BUFFER = 0x00000040, // A buffer of unmodifiable data stored in the kernel's address space.
|
||||
KERNEL_OBJECT_MAILSLOT = 0x00000080, // A mailslot into a process's message queue. Can only send messages synchronously.
|
||||
#ifdef ENABLE_POSIX_SUBSYSTEM
|
||||
KERNEL_OBJECT_POSIX_FD = 0x00000100, // A POSIX file descriptor, used in the POSIX subsystem.
|
||||
#endif
|
||||
|
|
|
@ -53,15 +53,6 @@ struct MessageQueue {
|
|||
KEvent notEmpty;
|
||||
};
|
||||
|
||||
struct Mailslot {
|
||||
#define MAILSLOT_RECEIVER (1 << 0)
|
||||
struct Process *target; // Owns a handle.
|
||||
KEvent responseReceivedEvent;
|
||||
KEvent available;
|
||||
volatile size_t handles;
|
||||
volatile uintptr_t response;
|
||||
};
|
||||
|
||||
size_t totalHandleCount;
|
||||
|
||||
struct HandleTableL2 {
|
||||
|
@ -371,7 +362,7 @@ void CloseHandleToObject(void *object, KernelObjectType type, uint32_t flags) {
|
|||
|
||||
uintptr_t HandleShare(Handle share, Process *process, uint32_t mode, EsHandle at = ES_INVALID_HANDLE) {
|
||||
#define HANDLE_SHARE_TYPE_MASK ((KernelObjectType) (KERNEL_OBJECT_SHMEM | KERNEL_OBJECT_CONSTANT_BUFFER | KERNEL_OBJECT_PROCESS \
|
||||
| KERNEL_OBJECT_DEVICE | KERNEL_OBJECT_NODE | KERNEL_OBJECT_EVENT | KERNEL_OBJECT_PIPE | KERNEL_OBJECT_MAILSLOT))
|
||||
| KERNEL_OBJECT_DEVICE | KERNEL_OBJECT_NODE | KERNEL_OBJECT_EVENT | KERNEL_OBJECT_PIPE))
|
||||
|
||||
if ((share.type & HANDLE_SHARE_TYPE_MASK) == 0) {
|
||||
KernelPanic("HandleShare - Invalid object type %x; allowed types are %x.\n", share.type, HANDLE_SHARE_TYPE_MASK);
|
||||
|
@ -387,8 +378,6 @@ uintptr_t HandleShare(Handle share, Process *process, uint32_t mode, EsHandle at
|
|||
sharedFlags = (mode & 1) && (share.flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) ? ES_FILE_READ_SHARED : share.flags;
|
||||
if (mode & 2) sharedFlags &= ~_ES_NODE_DIRECTORY_WRITE;
|
||||
} else if (share.type == KERNEL_OBJECT_PIPE) {
|
||||
} else if (share.type == KERNEL_OBJECT_MAILSLOT) {
|
||||
sharedFlags = (mode & 1) ? share.flags : 0;
|
||||
}
|
||||
|
||||
if (!OpenHandleToObject(share.object, share.type, sharedFlags)) {
|
||||
|
|
|
@ -1433,14 +1433,18 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_PIPE_CREATE) {
|
|||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_PIPE_READ) {
|
||||
if (!argument2) SYSCALL_RETURN(ES_SUCCESS, false);
|
||||
SYSCALL_HANDLE(argument0, KERNEL_OBJECT_PIPE, pipe, Pipe);
|
||||
SYSCALL_HANDLE_2(argument0, KERNEL_OBJECT_PIPE, _pipe);
|
||||
Pipe *pipe = (Pipe *) _pipe.object;
|
||||
if ((~_pipe.flags & PIPE_READER)) SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_FILE_ACCESS, true);
|
||||
SYSCALL_BUFFER(argument1, argument2, 2, false);
|
||||
SYSCALL_RETURN(pipe->Access((void *) argument1, argument2, false, true), false);
|
||||
}
|
||||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_PIPE_WRITE) {
|
||||
if (!argument2) SYSCALL_RETURN(ES_SUCCESS, false);
|
||||
SYSCALL_HANDLE(argument0, KERNEL_OBJECT_PIPE, pipe, Pipe);
|
||||
SYSCALL_HANDLE_2(argument0, KERNEL_OBJECT_PIPE, _pipe);
|
||||
Pipe *pipe = (Pipe *) _pipe.object;
|
||||
if ((~_pipe.flags & PIPE_WRITER)) SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_FILE_ACCESS, true);
|
||||
SYSCALL_BUFFER(argument1, argument2, 2, true /* write */);
|
||||
SYSCALL_RETURN(pipe->Access((void *) argument1, argument2, true, true), false);
|
||||
}
|
||||
|
@ -1619,65 +1623,6 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_DEVICE_CONTROL) {
|
|||
SYSCALL_RETURN(ES_SUCCESS, false);
|
||||
}
|
||||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_MAILSLOT_CREATE) {
|
||||
if (!OpenHandleToObject(currentProcess, KERNEL_OBJECT_PROCESS, ES_FLAGS_DEFAULT)) {
|
||||
SYSCALL_RETURN(ES_ERROR_INSUFFICIENT_RESOURCES, false);
|
||||
}
|
||||
|
||||
Mailslot *mailslot = (Mailslot *) EsHeapAllocate(sizeof(Mailslot), true, K_PAGED);
|
||||
|
||||
if (mailslot) {
|
||||
mailslot->target = currentProcess;
|
||||
mailslot->responseReceivedEvent.autoReset = true;
|
||||
mailslot->available.autoReset = true;
|
||||
mailslot->handles = 1;
|
||||
KEventSet(&mailslot->available);
|
||||
|
||||
EsHandle handle = currentProcess->handleTable.OpenHandle(mailslot, MAILSLOT_RECEIVER, KERNEL_OBJECT_MAILSLOT);
|
||||
SYSCALL_RETURN(handle, false);
|
||||
} else {
|
||||
SYSCALL_RETURN(ES_ERROR_INSUFFICIENT_RESOURCES, false);
|
||||
}
|
||||
}
|
||||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_MAILSLOT_RESPOND) {
|
||||
SYSCALL_HANDLE_2(argument0, KERNEL_OBJECT_MAILSLOT, _mailslot);
|
||||
if (~_mailslot.flags & MAILSLOT_RECEIVER) SYSCALL_RETURN(ES_FATAL_ERROR_INSUFFICIENT_PERMISSIONS, true);
|
||||
Mailslot *mailslot = (Mailslot *) _mailslot.object;
|
||||
mailslot->response = argument1;
|
||||
__sync_synchronize();
|
||||
KEventSet(&mailslot->responseReceivedEvent, true /* maybe already set */);
|
||||
SYSCALL_RETURN(ES_SUCCESS, false);
|
||||
}
|
||||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_MAILSLOT_SEND) {
|
||||
SYSCALL_HANDLE(argument0, KERNEL_OBJECT_MAILSLOT, mailslot, Mailslot);
|
||||
|
||||
_EsMessageWithObject message;
|
||||
SYSCALL_READ(&message.message, argument2, sizeof(EsMessage));
|
||||
message.object = (void *) argument3;
|
||||
|
||||
currentThread->terminatableState = THREAD_USER_BLOCK_REQUEST;
|
||||
bool success = KEventWait(&mailslot->available);
|
||||
currentThread->terminatableState = THREAD_IN_SYSCALL;
|
||||
|
||||
if (success) {
|
||||
mailslot->target->messageQueue.SendMessage(&message);
|
||||
|
||||
currentThread->terminatableState = THREAD_USER_BLOCK_REQUEST;
|
||||
success = KEventWait(&mailslot->responseReceivedEvent);
|
||||
currentThread->terminatableState = THREAD_IN_SYSCALL;
|
||||
|
||||
if (success) {
|
||||
SYSCALL_WRITE(argument1, &mailslot->response, sizeof(mailslot->response));
|
||||
}
|
||||
|
||||
KEventSet(&mailslot->available);
|
||||
}
|
||||
|
||||
SYSCALL_RETURN(success ? ES_SUCCESS : ES_ERROR_TIMEOUT_REACHED, false);
|
||||
}
|
||||
|
||||
SYSCALL_IMPLEMENT(ES_SYSCALL_DEBUG_COMMAND) {
|
||||
SYSCALL_PERMISSION(ES_PERMISSION_TAKE_SYSTEM_SNAPSHOT);
|
||||
|
||||
|
|
Loading…
Reference in New Issue