diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 4dd6be4..bf190e2 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -25,11 +25,7 @@ } currentLayer = nextLayer; } - if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; - } else if (currentLayer[hash >> (BITS(uintptr_t) - 4)] != string) { - free(string); - } + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; return hash; } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 4dd6be4..bf190e2 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -25,11 +25,7 @@ } currentLayer = nextLayer; } - if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; - } else if (currentLayer[hash >> (BITS(uintptr_t) - 4)] != string) { - free(string); - } + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; return hash; } diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 6f0f2ce..44a32f5 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -14,8 +14,7 @@ 2); uintptr_t size = strlen(string); char *savedString = malloc(size + 1); - memcpy(string, savedString, size); - savedString[size] = 0; + memcpy(string, savedString, size + 1); call->returnValue = insertString(savedString); unmapPage(string); } @@ -31,8 +30,14 @@ void handleReadStringSyscall(Syscall *call) { uintptr_t stringId = call->parameters[0]; Service *callService = call->service; - void *buffer = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *buffer = kernelMapPhysicalCount( + getPhysicalAddress(callService->pagingInfo.pageDirectory, + PTR(call->parameters[1])), + 2); + if (!stringId) { + buffer[0] = 0; + return; + } char *string = retrieveString(stringId); if (string) { memcpy(string, buffer, strlen(string) + 1); diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 4dd6be4..bf190e2 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -25,11 +25,7 @@ } currentLayer = nextLayer; } - if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; - } else if (currentLayer[hash >> (BITS(uintptr_t) - 4)] != string) { - free(string); - } + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; return hash; } diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 6f0f2ce..44a32f5 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -14,8 +14,7 @@ 2); uintptr_t size = strlen(string); char *savedString = malloc(size + 1); - memcpy(string, savedString, size); - savedString[size] = 0; + memcpy(string, savedString, size + 1); call->returnValue = insertString(savedString); unmapPage(string); } @@ -31,8 +30,14 @@ void handleReadStringSyscall(Syscall *call) { uintptr_t stringId = call->parameters[0]; Service *callService = call->service; - void *buffer = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *buffer = kernelMapPhysicalCount( + getPhysicalAddress(callService->pagingInfo.pageDirectory, + PTR(call->parameters[1])), + 2); + if (!stringId) { + buffer[0] = 0; + return; + } char *string = retrieveString(stringId); if (string) { memcpy(string, buffer, strlen(string) + 1); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 4aa3547..85c14dd 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -123,6 +123,9 @@ uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { + // I have absolutely no idea why this line fixes an issue where the first + // printf operation consistently doesn't correctly insert its string + free(malloc(1)); uintptr_t size = 0; va_list valist; va_start(valist, format); @@ -148,6 +151,10 @@ va_end(valist); uintptr_t id = insertString(data); + if (!id) { + insertString(data); + id = hashString(data); + } request(ioManager, logFunction, id, 0); discardString(id); free(data); diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 4dd6be4..bf190e2 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -25,11 +25,7 @@ } currentLayer = nextLayer; } - if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; - } else if (currentLayer[hash >> (BITS(uintptr_t) - 4)] != string) { - free(string); - } + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; return hash; } diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 6f0f2ce..44a32f5 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -14,8 +14,7 @@ 2); uintptr_t size = strlen(string); char *savedString = malloc(size + 1); - memcpy(string, savedString, size); - savedString[size] = 0; + memcpy(string, savedString, size + 1); call->returnValue = insertString(savedString); unmapPage(string); } @@ -31,8 +30,14 @@ void handleReadStringSyscall(Syscall *call) { uintptr_t stringId = call->parameters[0]; Service *callService = call->service; - void *buffer = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *buffer = kernelMapPhysicalCount( + getPhysicalAddress(callService->pagingInfo.pageDirectory, + PTR(call->parameters[1])), + 2); + if (!stringId) { + buffer[0] = 0; + return; + } char *string = retrieveString(stringId); if (string) { memcpy(string, buffer, strlen(string) + 1); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 4aa3547..85c14dd 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -123,6 +123,9 @@ uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { + // I have absolutely no idea why this line fixes an issue where the first + // printf operation consistently doesn't correctly insert its string + free(malloc(1)); uintptr_t size = 0; va_list valist; va_start(valist, format); @@ -148,6 +151,10 @@ va_end(valist); uintptr_t id = insertString(data); + if (!id) { + insertString(data); + id = hashString(data); + } request(ioManager, logFunction, id, 0); discardString(id); free(data); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 24fb966..f5e4ab2 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -3,9 +3,6 @@ #include #include -bool lock = false; -char buffer[100]; - uint32_t mainService, mainOut, globalService, globalOut; uint32_t focusService, focusServiceKeyHandler; @@ -18,6 +15,8 @@ } void logMain(uint32_t stringId) { + static char buffer[100]; + static bool lock = false; while (lock) { syscall(-1, 0, 0, 0, 0); } @@ -35,6 +34,8 @@ logMain(stringId); return; } + static bool lock = false; + static char buffer[100]; while (lock) { syscall(-1, 0, 0, 0, 0); }