Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2bda940
refactor(process): introduce shared memory limit policy
sgt57 Nov 7, 2026
0452c55
refactor(process): supervise Unix memory through shared limit policy
sgt57 Nov 7, 2026
86ab3f9
refactor(process): enforce Windows memory limits with execution jobs
sgt57 Nov 7, 2026
32f9f51
refactor(process): centralize exit outcomes and bound process cleanup
sgt57 Nov 7, 2026
52963a1
test(process): cover memory accounting and prelimit failures
sgt57 Nov 7, 2026
ce5bed6
style: format codes
actions-user Nov 7, 2026
c5178a6
fix(process): protect memory accounting from Windows max macro
sgt57 Nov 7, 2026
85d0d8c
style: format codes
actions-user Nov 7, 2026
d5fdeba
fix(ci): skip Qt deployment for memory limiter test
sgt57 Nov 7, 2026
24956a1
fix(tests): statically link MinGW sandbox helper runtime
sgt57 Nov 7, 2026
b4fc9c1
fix(tests): guard sandbox handle queries with SEH
sgt57 Nov 7, 2026
99756a4
fix(tests): address Codacy memory supervision findings
sgt57 Nov 7, 2026
414b7c0
style: format codes
actions-user Nov 7, 2026
ed2aea7
refactor(process): account memory by declared usage only
sgt57 Nov 7, 2026
a7a52b4
test(process): distinguish private commit from working set
sgt57 Nov 7, 2026
1886ec1
refactor(process): remove redundant execution outcome types
sgt57 Nov 8, 2026
921e716
refactor(process): replace unused interfaces with platform functions
sgt57 Nov 8, 2026
0592d8e
test(process): compare Unix memory reports with native counters
sgt57 Nov 8, 2026
b11229c
test(process): verify reported private commit at multiple sizes
sgt57 Nov 8, 2026
e2883c8
ci: fix macos ci
sgt57 Nov 8, 2026
586aa20
refactor(process): use event-driven monitoring on Linux and macOS
sgt57 Nov 8, 2026
dfbef21
style: format codes
actions-user Nov 8, 2026
adc09f0
refactor(process): use event-driven waits on Windows
sgt57 Nov 8, 2026
4eadf75
refactor(process): remove periodic sampling on Linux and Windows
sgt57 Nov 8, 2026
6ae31aa
style: format codes
actions-user Nov 8, 2026
c2dcfec
test(process): remove sampling delays from memory fixtures
sgt57 Nov 8, 2026
bf3a0c4
fix(process): expand stack on Linux when there is no memory limit
sgt57 Nov 8, 2026
b7de2d5
refactor(process): inline memory limit checks and localize Windows he…
sgt57 Nov 8, 2026
ffaa181
style: format codes
actions-user Nov 8, 2026
2921869
fix(process): wait for watcher exit after forced termination
sgt57 Nov 8, 2026
4ad1583
refactor: simplify code
sgt57 Nov 8, 2026
584b7b2
fix(ci): update macos ci target to 11.0
sgt57 Nov 8, 2026
ab0137a
fix(windows): reap suspended processes outside the job
sgt57 Nov 9, 2026
b1837f1
fix(windows): enforce memory limit before resuming the process
sgt57 Nov 9, 2026
bdd9e46
fix(linux): preserve stop and continue under ptrace
sgt57 Nov 9, 2026
68cab6c
fix(linux): retain VSS peaks across exec
sgt57 Nov 9, 2026
3bb9303
style: format codes
actions-user Nov 9, 2026
3c372b6
Merge branch 'master' into refactor/memory-limit
sgt57 Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .github/workflows/macos-qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest]
build_type: [Release, RelWithDebInfo, Debug]
arch: [x86_64, arm64]
qt_ver: [6.12.0]
qt_arch: [clang_64]
include:
- arch: x86_64
os: macos-26-intel
- arch: arm64
os: macos-latest
env:
targetName: lemon
steps:
Expand All @@ -50,22 +53,16 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DLEMON_BUILD_INFO="Build for macOS" \
-DLEMON_BUILD_EXTRA_INFO="Build on $(uname -sr)" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}"
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}"
cmake --build . --parallel $(sysctl -n hw.logicalcpu)
- name: Run tests
if: ${{ false }}
run: |
ctest --test-dir . --output-on-failure --timeout 120
# tag 打包
- name: package
env:
Qt6_DIR: ../Qt/${{matrix.qt_ver}}/${{matrix.qt_arch}}
run: |
# 拷贝依赖
#mv ${targetName} ${targetName}.app
export PATH=$Qt6_DIR/bin:$PATH
macdeployqt ${targetName}.app -qmldir=. -verbose=1 -dmg
macdeployqt "${targetName}.app" -qmldir=. -verbose=1 -dmg
mv "${targetName}.dmg" "${{ steps.artifact_name.outputs.name }}.dmg"
- name: Upload artifact
uses: actions/upload-artifact@v7
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/watcher_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Watcher for Linux Test
on:
push:
branches: ["master"]
paths: ["unix/**"]
paths: ["unix/**", "src/core/memoryunits.h"]
pull_request:
branches: ["master"]
paths: ["unix/**"]
paths: ["unix/**", "src/core/memoryunits.h"]
workflow_dispatch:

env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/watcher_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Watcher for MacOS Test
on:
push:
branches: ["master"]
paths: ["unix/**"]
paths: ["unix/**", "src/core/memoryunits.h"]
pull_request:
branches: ["master"]
paths: ["unix/**"]
paths: ["unix/**", "src/core/memoryunits.h"]
workflow_dispatch:

env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
shell: pwsh
run: |
Get-ChildItem tests -Recurse -Filter *.exe |
Where-Object { $_.Name -ne 'sandbox-helper.exe' } |
Where-Object { $_.Name -notin @('sandbox-helper.exe', 'sandbox-static-memory-helper.exe') } |
ForEach-Object {
windeployqt $_.FullName
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(MINGW)
add_compile_definitions(__USE_MINGW_ANSI_STDIO=1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

cmake_policy(SET CMP0072 NEW)
Expand Down
1 change: 1 addition & 0 deletions src/core/casejudger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ void CaseJudger::judgeTraditionalTask() {
});

ProcessRunnerConfig cfg{
.stopToken = stopToken,
.executableFile = executableFile,
.arguments = arguments,
.workingDirectory = workingDirectory,
Expand Down
1 change: 1 addition & 0 deletions src/core/casejudger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CaseJudger {
public:
CaseJudger();
void setCancellation(QFuture<void>);
std::stop_token stopToken;
void setExtraTimeRatio(double);
void setEnvironment(const QProcessEnvironment &);
void setWorkingDirectory(const QString &);
Expand Down
4 changes: 3 additions & 1 deletion src/core/judgingcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ void JudgingController::stop() {
delete queuingTasks.dequeue().judger;
for (auto *watcher : runningTasks.keys()) {
// Preserve results that finished before the stop request reached the GUI.
if (! watcher->isFinished())
if (! watcher->isFinished()) {
watcher->cancel();
runningTasks.value(watcher).judger->requestStop();
}
}
}
22 changes: 22 additions & 0 deletions src/core/memoryunits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include <cstdint>
#include <limits>

namespace Lemon::Execution {
using Bytes = std::int64_t;
inline constexpr Bytes KiB = 1024;
inline constexpr Bytes MiB = KiB * 1024;

inline bool memoryBytes(std::int64_t mib, Bytes &bytes) {
if (mib < 0) {
bytes = -1;
return true;
}
if (mib > (std::numeric_limits<Bytes>::max)() / MiB)
return false;
bytes = mib * MiB;
return true;
}
} // namespace Lemon::Execution
2 changes: 2 additions & 0 deletions src/core/processrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
#include <QString>
#include <QtGlobal>
#include <memory>
#include <stop_token>

class WindowsSandboxSession;

struct ProcessRunnerConfig {
std::stop_token stopToken;
QString executableFile;
QString arguments;
QString workingDirectory;
Expand Down
28 changes: 18 additions & 10 deletions src/core/processrunner_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ ProcessRunnerResult UnixProcessRunner::run() {
argumentsList << config.outputFileName;
}

argumentsList << QString("%1").arg(extraTime);
if (! config.interpreterAsWatcher)
argumentsList << QString("%1").arg(extraTime);

qDebug() << argumentsList;

Expand Down Expand Up @@ -161,7 +162,8 @@ ProcessRunnerResult UnixProcessRunner::run() {
argumentsList << config.outputFileName;
}

argumentsList << QString("%1").arg(extraTime);
if (! config.interpreterAsWatcher)
argumentsList << QString("%1").arg(extraTime);

qDebug() << argumentsList;

Expand All @@ -171,7 +173,7 @@ ProcessRunnerResult UnixProcessRunner::run() {

#endif

if (! runner.waitForStarted(-1)) {
if (! runner.waitForStarted(5000)) {
res.score = 0;
res.result = CannotStartProgram;
res.message = "Start runner failed";
Expand All @@ -182,9 +184,10 @@ ProcessRunnerResult UnixProcessRunner::run() {
QElapsedTimer timer;
timer.start();

// The watcher itself enforces the wall clock (timeLimit + extraTime) and exits shortly
// after the timer fires; this loop only guards against a hung watcher, with 1s of slack.
long long killTimeLimit = 1LL * config.timeLimit + extraTime + 1000;
// Leave room for the watcher's explicit wall deadline and bounded reaping.
long long killTimeLimit = 1LL * config.timeLimit + extraTime + 5000LL;
if (config.interpreterAsWatcher)
killTimeLimit = qMax(2000LL, 3LL * config.timeLimit) + extraTime + 5000LL;
while (timer.elapsed() <= killTimeLimit) {
if (runner.waitForFinished(10)) {
isProgramFinishedInExtraTimeLimit = true;
Expand All @@ -193,15 +196,20 @@ ProcessRunnerResult UnixProcessRunner::run() {

if (cancellation.isCanceled()) {
runner.terminate();
runner.waitForFinished(-1);

if (! runner.waitForFinished(2500)) {
runner.kill();
runner.waitForFinished(-1);
}
return res;
}
}

if (! isProgramFinishedInExtraTimeLimit) {
runner.terminate();
runner.waitForFinished(-1);
if (! runner.waitForFinished(2500)) {
runner.kill();
runner.waitForFinished(2000);
}
res.score = 0;
res.timeUsed = res.memoryUsed = -1;
// Watcher usually needs to handle the situation of program timeout and kill it. Therefore, it is
Expand All @@ -227,7 +235,7 @@ ProcessRunnerResult UnixProcessRunner::run() {
RS_MLE = 4,
};

int code = runner.exitCode();
int code = runner.exitStatus() == QProcess::NormalExit ? runner.exitCode() : -1;

switch (code) {
case RS_RE:
Expand Down
Loading
Loading