Skip to content

Commit 8fb2bc9

Browse files
authored
extend stack size to 64M (#10)
* extend stack size to 64M * update version * sync predetect with generateCaseResult
1 parent 1686cd0 commit 8fb2bc9

File tree

9 files changed

+56
-6
lines changed

9 files changed

+56
-6
lines changed

config.example.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ SecrectKey = "0xffffffff"
55
[self]
66
judgeCapability = 4
77
name = "TestJudger"
8-
version = "0.0.1"
98
[nsjail]
109
path = "/usr/bin/nsjail"
1110
configFile = "./jailConfig.cfg"

src/Config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ export class SelfConfig {
8383
@IsNotEmpty()
8484
name!: string;
8585
@IsString()
86-
@IsNotEmpty()
87-
version!: string;
88-
@IsString()
8986
@IsOptional()
9087
software?: string;
9188
}

src/SelfTest/BOMB/STACK.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { JudgeResultKind } from "heng-protocol";
2+
import { generateNormalSelfTest } from "../util";
3+
4+
const input = `
5+
`;
6+
const output = `67108864
7+
67108864
8+
`;
9+
const usrCode = `
10+
#include <stdio.h>
11+
#include <sys/resource.h>
12+
int main(void)
13+
{
14+
struct rlimit r;
15+
if (getrlimit(RLIMIT_STACK, &r) < 0)
16+
{
17+
fprintf(stderr, "getrlimit error\\n");
18+
return 1;
19+
}
20+
printf("%d\\n", r.rlim_cur);
21+
printf("%d\\n", r.rlim_max);
22+
23+
return 0;
24+
}
25+
`;
26+
27+
export const BOOMSTACK = generateNormalSelfTest("BOOMSTACK", "c", usrCode, {}, [
28+
{
29+
type: "direct",
30+
input,
31+
output,
32+
expectResultType: JudgeResultKind.Accepted,
33+
count: false,
34+
},
35+
]);

src/SelfTest/BOMB/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { BOMBCTLE } from "./CTLE";
66
import { BOMBFORKBOMB } from "./FORKBOMB";
77
import { KILLTIMER } from "./KILLTIMER";
88
import { BOMBSPJTLE } from "./SPJTLE";
9+
import { BOOMSTACK } from "./STACK";
910

1011
export const BOMB = [
1112
BOMBCOLE,
@@ -16,4 +17,5 @@ export const BOMB = [
1617
BOMBSPJTLE,
1718
BOMBBULL,
1819
KILLTIMER,
20+
BOOMSTACK,
1921
];

src/Spawn/Jail.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface JailSpawnOption {
3939
rlimitCPU?: number | RlimitString; // s default 600s
4040
rlimitAS?: number | RlimitString; // M default 4096MB
4141
rlimitFSIZE?: number | RlimitString; // M default 1MB
42+
rlimitSTACK?: number | RlimitString; // M default soft
4243

4344
cwd?: string;
4445
env?: { [key: string]: string };
@@ -154,6 +155,17 @@ export function useJail(
154155
}
155156
}
156157

158+
if (jailOption.rlimitSTACK !== undefined) {
159+
if (typeof jailOption.rlimitSTACK === "number") {
160+
jailArgs.push(
161+
"--rlimit_stack",
162+
Math.ceil(jailOption.rlimitSTACK).toString()
163+
);
164+
} else {
165+
jailArgs.push("--rlimit_stack", jailOption.rlimitSTACK);
166+
}
167+
}
168+
157169
if (jailOption.cwd) {
158170
jailArgs.push("--cwd", path.resolve(jailOption.cwd));
159171
}

src/Spawn/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function hengSpawn(
9090
if (options.fileLimit) {
9191
jailOption.rlimitFSIZE = Math.ceil(options.fileLimit / 1024 / 1024);
9292
}
93+
jailOption.rlimitSTACK = 64;
9394

9495
jailOption.cwd = options.cwd;
9596

src/Utilities/Judge.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ export abstract class JudgeAgent {
255255
userResult: MeterResult,
256256
userExec: Executable
257257
): JudgeResultKind | undefined {
258+
const userRunSumTime = userResult.time.usr + userResult.time.sys;
258259
if (userResult.signal === 25) {
259260
return JudgeResultKind.OutpuLimitExceeded;
260261
} else if (
261-
userResult.time.usr > userExec.limit.runtime.cpuTime ||
262+
userRunSumTime > userExec.limit.runtime.cpuTime ||
262263
(userResult.time.real > userExec.limit.runtime.cpuTime &&
263264
userResult.returnCode === -1 &&
264265
userResult.signal === 9)

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ExecTypeArray } from "./Spawn/Language/decl";
1212
import { chownR } from "./Utilities/File";
1313
import { ExitArgs } from "heng-protocol/internal-protocol/ws";
1414
import { stat } from "./Utilities/Statistics";
15+
import version from "./version";
1516

1617
async function wait(ms: number) {
1718
return new Promise((resolve) => setTimeout(() => resolve(null), ms));
@@ -29,6 +30,7 @@ async function main() {
2930
});
3031
const logger = getLogger("main");
3132
logger.info("Lunched");
33+
logger.info(version);
3234
try {
3335
getConfig();
3436
} catch (e) {
@@ -136,7 +138,7 @@ async function main() {
136138
config.judgeCapability,
137139
os.cpus().length,
138140
config.name,
139-
config.version
141+
version
140142
);
141143
logger.info(`Token is ${token.token}`);
142144
await controller.connectWs(token.token);

src/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "0.1.1";

0 commit comments

Comments
 (0)