diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 262a6f3..9ee8c6f 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -19,3 +19,13 @@ char *string = retrieveString(stringId, &size); call->returnValue = size; } + +void handleReadStringSyscall(Syscall *call) { + uintptr_t size, stringId = call->parameters[0]; + Service *callService = call->service; + void *buffer = kernelMapPhysical(getPhysicalAddress( + callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *string = retrieveString(stringId, &size); + memcpy(string, buffer, size + 1); + unmapPage(buffer); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 262a6f3..9ee8c6f 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -19,3 +19,13 @@ char *string = retrieveString(stringId, &size); call->returnValue = size; } + +void handleReadStringSyscall(Syscall *call) { + uintptr_t size, stringId = call->parameters[0]; + Service *callService = call->service; + void *buffer = kernelMapPhysical(getPhysicalAddress( + callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *string = retrieveString(stringId, &size); + memcpy(string, buffer, size + 1); + unmapPage(buffer); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index e00c358..f1cb269 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -56,7 +56,8 @@ extern uintptr_t handleCreateEventSyscall, handleGetEventSyscall, handleFireEventSyscall, handleSubscribeEventSyscall; extern uintptr_t handleSubscribeInterruptSyscall; -extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall; +extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, + handleReadStringSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -75,6 +76,7 @@ (void *)&handleGetServiceIdSyscall, (void *)&handleInsertStringSyscall, (void *)&handleReadStringLengthSyscall, + (void *)&handleReadStringSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 262a6f3..9ee8c6f 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -19,3 +19,13 @@ char *string = retrieveString(stringId, &size); call->returnValue = size; } + +void handleReadStringSyscall(Syscall *call) { + uintptr_t size, stringId = call->parameters[0]; + Service *callService = call->service; + void *buffer = kernelMapPhysical(getPhysicalAddress( + callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *string = retrieveString(stringId, &size); + memcpy(string, buffer, size + 1); + unmapPage(buffer); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index e00c358..f1cb269 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -56,7 +56,8 @@ extern uintptr_t handleCreateEventSyscall, handleGetEventSyscall, handleFireEventSyscall, handleSubscribeEventSyscall; extern uintptr_t handleSubscribeInterruptSyscall; -extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall; +extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, + handleReadStringSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -75,6 +76,7 @@ (void *)&handleGetServiceIdSyscall, (void *)&handleInsertStringSyscall, (void *)&handleReadStringLengthSyscall, + (void *)&handleReadStringSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f2344c1..07251c3 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -21,6 +21,7 @@ SYS_GET_SERVICE_ID = 13, SYS_INSERT_STRING = 14, SYS_GET_STRING_LENGTH = 15, + SYS_READ_STRING = 16, } SyscallIds; #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 262a6f3..9ee8c6f 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -19,3 +19,13 @@ char *string = retrieveString(stringId, &size); call->returnValue = size; } + +void handleReadStringSyscall(Syscall *call) { + uintptr_t size, stringId = call->parameters[0]; + Service *callService = call->service; + void *buffer = kernelMapPhysical(getPhysicalAddress( + callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *string = retrieveString(stringId, &size); + memcpy(string, buffer, size + 1); + unmapPage(buffer); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index e00c358..f1cb269 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -56,7 +56,8 @@ extern uintptr_t handleCreateEventSyscall, handleGetEventSyscall, handleFireEventSyscall, handleSubscribeEventSyscall; extern uintptr_t handleSubscribeInterruptSyscall; -extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall; +extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, + handleReadStringSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -75,6 +76,7 @@ (void *)&handleGetServiceIdSyscall, (void *)&handleInsertStringSyscall, (void *)&handleReadStringLengthSyscall, + (void *)&handleReadStringSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f2344c1..07251c3 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -21,6 +21,7 @@ SYS_GET_SERVICE_ID = 13, SYS_INSERT_STRING = 14, SYS_GET_STRING_LENGTH = 15, + SYS_READ_STRING = 16, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 6e9f93f..6734cdc 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -90,3 +90,7 @@ uintptr_t getStringLength(uintptr_t stringId) { return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); } + +void readString(uintptr_t stringId, void *buffer) { + syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index fed57d9..1e94acb 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -31,5 +31,6 @@ extern uint32_t getServiceId(); extern uintptr_t insertString(char *string, uintptr_t size); extern uintptr_t getStringLength(uintptr_t stringId); +extern void readString(uintptr_t stringId, void *buffer); #endif diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 262a6f3..9ee8c6f 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -19,3 +19,13 @@ char *string = retrieveString(stringId, &size); call->returnValue = size; } + +void handleReadStringSyscall(Syscall *call) { + uintptr_t size, stringId = call->parameters[0]; + Service *callService = call->service; + void *buffer = kernelMapPhysical(getPhysicalAddress( + callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *string = retrieveString(stringId, &size); + memcpy(string, buffer, size + 1); + unmapPage(buffer); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index e00c358..f1cb269 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -56,7 +56,8 @@ extern uintptr_t handleCreateEventSyscall, handleGetEventSyscall, handleFireEventSyscall, handleSubscribeEventSyscall; extern uintptr_t handleSubscribeInterruptSyscall; -extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall; +extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, + handleReadStringSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -75,6 +76,7 @@ (void *)&handleGetServiceIdSyscall, (void *)&handleInsertStringSyscall, (void *)&handleReadStringLengthSyscall, + (void *)&handleReadStringSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f2344c1..07251c3 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -21,6 +21,7 @@ SYS_GET_SERVICE_ID = 13, SYS_INSERT_STRING = 14, SYS_GET_STRING_LENGTH = 15, + SYS_READ_STRING = 16, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 6e9f93f..6734cdc 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -90,3 +90,7 @@ uintptr_t getStringLength(uintptr_t stringId) { return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); } + +void readString(uintptr_t stringId, void *buffer) { + syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 075f44e..54e9a72 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ char *testString = "hello world"; char *lengthString = "0"; +char readBuffer[20]; int32_t main() { loadFromInitrd("log"); @@ -16,5 +17,7 @@ uintptr_t length = getStringLength(id); lengthString[0] += length; log(lengthString); + readString(id, readBuffer); + log(readBuffer); return 0; }