From 77586e6561fef757c804499c0b2636a16ad1a30c Mon Sep 17 00:00:00 2001 From: nakst <> Date: Fri, 21 Jan 2022 10:37:02 +0000 Subject: [PATCH] bugfix in ThreadSetTemporaryAddressSpace: open 2 references instead of 1 --- desktop/api_tests.cpp | 8 +++++++- kernel/memory.cpp | 4 ---- kernel/scheduler.cpp | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/desktop/api_tests.cpp b/desktop/api_tests.cpp index 55f694a..829bccd 100644 --- a/desktop/api_tests.cpp +++ b/desktop/api_tests.cpp @@ -1206,6 +1206,12 @@ bool POSIXSubsystemTest() { EsFileWriteAll(EsLiteral("0:/test.sh"), EsLiteral("find . | grep Kernel.esx")); CHECK(POSIXSubsystemRunCommandAndCheckOutput(executeEnvironment, argv, executable, "./Essence/Kernel.esx\n")); + EsFileWriteAll(EsLiteral("0:/test.sh"), EsLiteral("exit")); + + for (uintptr_t i = 0; i < 1000; i++) { + CHECK(POSIXSubsystemRunCommandAndCheckOutput(executeEnvironment, argv, executable, "")); + } + return true; } @@ -1305,7 +1311,7 @@ const Test tests[] = { TEST(RangeSetTests, 60), TEST(UTF8Tests, 60), TEST(PipeTests, 60), - TEST(POSIXSubsystemTest, 60), + TEST(POSIXSubsystemTest, 120), TEST(RestartTest, 1200), TEST(ResizeFileTest, 600), }; diff --git a/kernel/memory.cpp b/kernel/memory.cpp index e6a8bc8..0f4e094 100644 --- a/kernel/memory.cpp +++ b/kernel/memory.cpp @@ -2176,10 +2176,6 @@ void MMSpaceOpenReference(MMSpace *space) { KernelPanic("MMSpaceOpenReference - Space %x has invalid reference count.\n", space); } - if (space->referenceCount >= K_MAX_PROCESSORS + 1) { - KernelPanic("MMSpaceOpenReference - Space %x has too many references (expected a maximum of %d).\n", K_MAX_PROCESSORS + 1); - } - __sync_fetch_and_add(&space->referenceCount, 1); } diff --git a/kernel/scheduler.cpp b/kernel/scheduler.cpp index 047d505..c04a1ff 100644 --- a/kernel/scheduler.cpp +++ b/kernel/scheduler.cpp @@ -934,10 +934,12 @@ void ThreadSetTemporaryAddressSpace(MMSpace *space) { MMSpace *oldSpace = thread->temporaryAddressSpace ?: kernelMMSpace; thread->temporaryAddressSpace = space; MMSpace *newSpace = space ?: kernelMMSpace; - MMSpaceOpenReference(newSpace); + MMSpaceOpenReference(newSpace); // Open our reference to the space. + MMSpaceOpenReference(newSpace); // This reference will be closed in PostContextSwitch, simulating the reference opened in Scheduler::Yield. ProcessorSetAddressSpace(&newSpace->data); KSpinlockRelease(&scheduler.dispatchSpinlock); - MMSpaceCloseReference(oldSpace); + MMSpaceCloseReference(oldSpace); // Close our reference to the space. + MMSpaceCloseReference(oldSpace); // This reference was opened by Scheduler::Yield, and would have been closed in PostContextSwitch. } void AsyncTaskThread() {