diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index cc4619e..3ae6e27 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -130,6 +130,9 @@ for (uint32_t i = 0; i < size; i++) { mapPage(kernelVirtualPages, ADDRESS(physicalPageStart + i), ADDRESS(virtualPageStart + i), false, false); + uint32_t pageId = virtualPageStart + i; + kernelVirtualPages->isPageConnectedToNext[pageId / 32] |= + 1 << (pageId % 32); } return ADDRESS(virtualPageStart) + PAGE_OFFSET(address); } @@ -233,6 +236,7 @@ fineBit = 1 << fine; markPageFree(info, coarse, fine, fineBit); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } @@ -254,6 +258,7 @@ markPageFree(kernelPhysicalPages, physicalPageId / 32, physicalFine, 1 << physicalFine); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index cc4619e..3ae6e27 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -130,6 +130,9 @@ for (uint32_t i = 0; i < size; i++) { mapPage(kernelVirtualPages, ADDRESS(physicalPageStart + i), ADDRESS(virtualPageStart + i), false, false); + uint32_t pageId = virtualPageStart + i; + kernelVirtualPages->isPageConnectedToNext[pageId / 32] |= + 1 << (pageId % 32); } return ADDRESS(virtualPageStart) + PAGE_OFFSET(address); } @@ -233,6 +236,7 @@ fineBit = 1 << fine; markPageFree(info, coarse, fine, fineBit); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } @@ -254,6 +258,7 @@ markPageFree(kernelPhysicalPages, physicalPageId / 32, physicalFine, 1 << physicalFine); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 2ff5281..598f95e 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -53,10 +53,9 @@ if (hlib && programHeader->virtualAddress >= 0xF0000000) { goto end; } - for (uint32_t page = 0; page < programHeader->segmentMemorySize; + for (uint32_t page = 0; page < programHeader->segmentFileSize; page += 0x1000) { void *data = malloc(0x1000); - memset(data, 0, 0x1000); memcpy(elfStart + programHeader->dataOffset + page, data, MIN(0x1000, programHeader->segmentFileSize - page)); sharePage(&service->pagingInfo, data, diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index cc4619e..3ae6e27 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -130,6 +130,9 @@ for (uint32_t i = 0; i < size; i++) { mapPage(kernelVirtualPages, ADDRESS(physicalPageStart + i), ADDRESS(virtualPageStart + i), false, false); + uint32_t pageId = virtualPageStart + i; + kernelVirtualPages->isPageConnectedToNext[pageId / 32] |= + 1 << (pageId % 32); } return ADDRESS(virtualPageStart) + PAGE_OFFSET(address); } @@ -233,6 +236,7 @@ fineBit = 1 << fine; markPageFree(info, coarse, fine, fineBit); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } @@ -254,6 +258,7 @@ markPageFree(kernelPhysicalPages, physicalPageId / 32, physicalFine, 1 << physicalFine); unmapSinglePageFrom(info, ADDRESS(pageId)); + pageId++; } while (info->isPageConnectedToNext[coarse] & fineBit); } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 2ff5281..598f95e 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -53,10 +53,9 @@ if (hlib && programHeader->virtualAddress >= 0xF0000000) { goto end; } - for (uint32_t page = 0; page < programHeader->segmentMemorySize; + for (uint32_t page = 0; page < programHeader->segmentFileSize; page += 0x1000) { void *data = malloc(0x1000); - memset(data, 0, 0x1000); memcpy(elfStart + programHeader->dataOffset + page, data, MIN(0x1000, programHeader->segmentFileSize - page)); sharePage(&service->pagingInfo, data, diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 2e1ff3d..6f0f2ce 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -4,8 +4,14 @@ void handleInsertStringSyscall(Syscall *call) { Service *callService = call->service; - void *string = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[0]))); + if (!call->parameters[0]) { + return; + } + // need to make sure the whole string is allocated + void *string = kernelMapPhysicalCount( + getPhysicalAddress(callService->pagingInfo.pageDirectory, + PTR(call->parameters[0])), + 2); uintptr_t size = strlen(string); char *savedString = malloc(size + 1); memcpy(string, savedString, size);