Skip to content

Commit

Permalink
extend stack size to 64M (#10)
Browse files Browse the repository at this point in the history
* extend stack size to 64M

* update version

* sync predetect with generateCaseResult
  • Loading branch information
Handgrip authored Dec 23, 2021
1 parent 1686cd0 commit 8fb2bc9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 6 deletions.
1 change: 0 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SecrectKey = "0xffffffff"
[self]
judgeCapability = 4
name = "TestJudger"
version = "0.0.1"
[nsjail]
path = "/usr/bin/nsjail"
configFile = "./jailConfig.cfg"
Expand Down
3 changes: 0 additions & 3 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ export class SelfConfig {
@IsNotEmpty()
name!: string;
@IsString()
@IsNotEmpty()
version!: string;
@IsString()
@IsOptional()
software?: string;
}
Expand Down
35 changes: 35 additions & 0 deletions src/SelfTest/BOMB/STACK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { JudgeResultKind } from "heng-protocol";
import { generateNormalSelfTest } from "../util";

const input = `
`;
const output = `67108864
67108864
`;
const usrCode = `
#include <stdio.h>
#include <sys/resource.h>
int main(void)
{
struct rlimit r;
if (getrlimit(RLIMIT_STACK, &r) < 0)
{
fprintf(stderr, "getrlimit error\\n");
return 1;
}
printf("%d\\n", r.rlim_cur);
printf("%d\\n", r.rlim_max);
return 0;
}
`;

export const BOOMSTACK = generateNormalSelfTest("BOOMSTACK", "c", usrCode, {}, [
{
type: "direct",
input,
output,
expectResultType: JudgeResultKind.Accepted,
count: false,
},
]);
2 changes: 2 additions & 0 deletions src/SelfTest/BOMB/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BOMBCTLE } from "./CTLE";
import { BOMBFORKBOMB } from "./FORKBOMB";
import { KILLTIMER } from "./KILLTIMER";
import { BOMBSPJTLE } from "./SPJTLE";
import { BOOMSTACK } from "./STACK";

export const BOMB = [
BOMBCOLE,
Expand All @@ -16,4 +17,5 @@ export const BOMB = [
BOMBSPJTLE,
BOMBBULL,
KILLTIMER,
BOOMSTACK,
];
12 changes: 12 additions & 0 deletions src/Spawn/Jail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface JailSpawnOption {
rlimitCPU?: number | RlimitString; // s default 600s
rlimitAS?: number | RlimitString; // M default 4096MB
rlimitFSIZE?: number | RlimitString; // M default 1MB
rlimitSTACK?: number | RlimitString; // M default soft

cwd?: string;
env?: { [key: string]: string };
Expand Down Expand Up @@ -154,6 +155,17 @@ export function useJail(
}
}

if (jailOption.rlimitSTACK !== undefined) {
if (typeof jailOption.rlimitSTACK === "number") {
jailArgs.push(
"--rlimit_stack",
Math.ceil(jailOption.rlimitSTACK).toString()
);
} else {
jailArgs.push("--rlimit_stack", jailOption.rlimitSTACK);
}
}

if (jailOption.cwd) {
jailArgs.push("--cwd", path.resolve(jailOption.cwd));
}
Expand Down
1 change: 1 addition & 0 deletions src/Spawn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function hengSpawn(
if (options.fileLimit) {
jailOption.rlimitFSIZE = Math.ceil(options.fileLimit / 1024 / 1024);
}
jailOption.rlimitSTACK = 64;

jailOption.cwd = options.cwd;

Expand Down
3 changes: 2 additions & 1 deletion src/Utilities/Judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ export abstract class JudgeAgent {
userResult: MeterResult,
userExec: Executable
): JudgeResultKind | undefined {
const userRunSumTime = userResult.time.usr + userResult.time.sys;
if (userResult.signal === 25) {
return JudgeResultKind.OutpuLimitExceeded;
} else if (
userResult.time.usr > userExec.limit.runtime.cpuTime ||
userRunSumTime > userExec.limit.runtime.cpuTime ||
(userResult.time.real > userExec.limit.runtime.cpuTime &&
userResult.returnCode === -1 &&
userResult.signal === 9)
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ExecTypeArray } from "./Spawn/Language/decl";
import { chownR } from "./Utilities/File";
import { ExitArgs } from "heng-protocol/internal-protocol/ws";
import { stat } from "./Utilities/Statistics";
import version from "./version";

async function wait(ms: number) {
return new Promise((resolve) => setTimeout(() => resolve(null), ms));
Expand All @@ -29,6 +30,7 @@ async function main() {
});
const logger = getLogger("main");
logger.info("Lunched");
logger.info(version);
try {
getConfig();
} catch (e) {
Expand Down Expand Up @@ -136,7 +138,7 @@ async function main() {
config.judgeCapability,
os.cpus().length,
config.name,
config.version
version
);
logger.info(`Token is ${token.token}`);
await controller.connectWs(token.token);
Expand Down
1 change: 1 addition & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "0.1.1";

0 comments on commit 8fb2bc9

Please sign in to comment.