mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: add address space limit to language config (#682)
This commit is contained in:
1 parent
6276627ee1
commit
ee4fc2b732
8 files changed
+26
-1
No files matched your search
@@ -14,6 +14,7 @@ const logger = new Logger('judge/default');
|
|||||||
|
|
||||||
function judgeCase(c: NormalizedCase) {
|
function judgeCase(c: NormalizedCase) {
|
||||||
return async (ctx: Context, ctxSubtask: ContextSubTask, runner?: Function) => {
|
return async (ctx: Context, ctxSubtask: ContextSubTask, runner?: Function) => {
|
||||||
|
const { address_space_limit, process_limit } = ctx.session.getLang(ctx.lang);
|
||||||
const res = await runQueued(
|
const res = await runQueued(
|
||||||
ctx.execute.execute,
|
ctx.execute.execute,
|
||||||
{
|
{
|
||||||
@@ -23,6 +24,8 @@ function judgeCase(c: NormalizedCase) {
|
|||||||
time: c.time,
|
time: c.time,
|
||||||
memory: c.memory,
|
memory: c.memory,
|
||||||
cacheStdoutAndStderr: true,
|
cacheStdoutAndStderr: true,
|
||||||
|
addressSpaceLimit: address_space_limit,
|
||||||
|
processLimit: process_limit,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export async function judge(ctx: Context) {
|
|||||||
const message = `${validateResult.stdout || ''}\n${validateResult.stderr || ''}`.trim();
|
const message = `${validateResult.stdout || ''}\n${validateResult.stderr || ''}`.trim();
|
||||||
return ctx.end({ status: STATUS.STATUS_FORMAT_ERROR, message });
|
return ctx.end({ status: STATUS.STATUS_FORMAT_ERROR, message });
|
||||||
}
|
}
|
||||||
|
const { address_space_limit, process_limit } = ctx.session.getLang(ctx.lang);
|
||||||
const res = await runQueued(
|
const res = await runQueued(
|
||||||
execute.execute,
|
execute.execute,
|
||||||
{
|
{
|
||||||
@@ -49,6 +50,8 @@ export async function judge(ctx: Context) {
|
|||||||
time: parseTimeMS(ctx.config.time || '1s'),
|
time: parseTimeMS(ctx.config.time || '1s'),
|
||||||
memory: parseMemoryMB(ctx.config.memory || '256m'),
|
memory: parseMemoryMB(ctx.config.memory || '256m'),
|
||||||
cacheStdoutAndStderr: true,
|
cacheStdoutAndStderr: true,
|
||||||
|
addressSpaceLimit: address_space_limit,
|
||||||
|
processLimit: process_limit,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ function judgeCase(c: NormalizedCase) {
|
|||||||
return async (ctx: Context, ctxSubtask: ContextSubTask) => {
|
return async (ctx: Context, ctxSubtask: ContextSubTask) => {
|
||||||
ctx.executeInteractor.copyIn.in = c.input ? { src: c.input } : { content: '' };
|
ctx.executeInteractor.copyIn.in = c.input ? { src: c.input } : { content: '' };
|
||||||
ctx.executeInteractor.copyIn.out = c.output ? { src: c.output } : { content: '' };
|
ctx.executeInteractor.copyIn.out = c.output ? { src: c.output } : { content: '' };
|
||||||
|
const { address_space_limit, process_limit } = ctx.session.getLang(ctx.lang);
|
||||||
const [{
|
const [{
|
||||||
code, signalled, time, memory,
|
code, signalled, time, memory,
|
||||||
}, resInteractor] = await runPiped(
|
}, resInteractor] = await runPiped(
|
||||||
@@ -21,6 +22,8 @@ function judgeCase(c: NormalizedCase) {
|
|||||||
copyIn: ctx.executeUser.copyIn,
|
copyIn: ctx.executeUser.copyIn,
|
||||||
time: c.time,
|
time: c.time,
|
||||||
memory: c.memory,
|
memory: c.memory,
|
||||||
|
addressSpaceLimit: address_space_limit,
|
||||||
|
processLimit: process_limit,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
execute: `${ctx.executeInteractor.execute} /w/in /w/tout /w/out`,
|
execute: `${ctx.executeInteractor.execute} /w/in /w/tout /w/out`,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export const judge = async (ctx: Context) => {
|
|||||||
}
|
}
|
||||||
ctx.clean.push(ctx.execute.clean);
|
ctx.clean.push(ctx.execute.clean);
|
||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
|
const { address_space_limit, process_limit } = ctx.session.getLang(ctx.lang);
|
||||||
const res = await runQueued(
|
const res = await runQueued(
|
||||||
ctx.execute.execute,
|
ctx.execute.execute,
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,8 @@ export const judge = async (ctx: Context) => {
|
|||||||
// Allow 2x limits for better debugging
|
// Allow 2x limits for better debugging
|
||||||
time: parseTimeMS(ctx.config.time || '1s') * 2,
|
time: parseTimeMS(ctx.config.time || '1s') * 2,
|
||||||
memory: parseMemoryMB(ctx.config.memory || '128m'),
|
memory: parseMemoryMB(ctx.config.memory || '128m'),
|
||||||
|
addressSpaceLimit: address_space_limit,
|
||||||
|
processLimit: process_limit,
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ interface Parameter {
|
|||||||
execute?: string;
|
execute?: string;
|
||||||
memory?: number;
|
memory?: number;
|
||||||
processLimit?: number;
|
processLimit?: number;
|
||||||
|
addressSpaceLimit?: boolean;
|
||||||
copyIn?: CopyIn;
|
copyIn?: CopyIn;
|
||||||
copyOut?: string[];
|
copyOut?: string[];
|
||||||
copyOutCached?: string[];
|
copyOutCached?: string[];
|
||||||
@@ -101,6 +102,7 @@ function proc(params: Parameter): Cmd {
|
|||||||
clockLimit: 3 * cpuLimit,
|
clockLimit: 3 * cpuLimit,
|
||||||
memoryLimit: Math.floor(memory * 1024 * 1024),
|
memoryLimit: Math.floor(memory * 1024 * 1024),
|
||||||
strictMemoryLimit: getConfig('strict_memory'),
|
strictMemoryLimit: getConfig('strict_memory'),
|
||||||
|
addressSpaceLimit: params.addressSpaceLimit,
|
||||||
stackLimit: getConfig('strict_memory') ? Math.floor(memory * 1024 * 1024) : 0,
|
stackLimit: getConfig('strict_memory') ? Math.floor(memory * 1024 * 1024) : 0,
|
||||||
procLimit: params.processLimit || getConfig('processLimit'),
|
procLimit: params.processLimit || getConfig('processLimit'),
|
||||||
copyOutMax: Math.floor(1024 * 1024 * stdioLimit * 3),
|
copyOutMax: Math.floor(1024 * 1024 * stdioLimit * 3),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface SandboxVersion {
|
|||||||
os: string;
|
os: string;
|
||||||
copyOutOptional?: boolean;
|
copyOutOptional?: boolean;
|
||||||
pipeProxy?: boolean;
|
pipeProxy?: boolean;
|
||||||
|
addressSpaceLimit?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LocalFile {
|
export interface LocalFile {
|
||||||
@@ -50,8 +51,12 @@ export interface Cmd {
|
|||||||
cpuRateLimit?: number;
|
cpuRateLimit?: number;
|
||||||
/** cpuSetLimit defines cpu set limit if enabled in sandbox server */
|
/** cpuSetLimit defines cpu set limit if enabled in sandbox server */
|
||||||
cpuSetLimit?: string;
|
cpuSetLimit?: string;
|
||||||
/** strictMemoryLimit set rlimit_data limit for memoryLimit */
|
/** @deprecated use dataSegmentLimit instead, keep compatibility for old versions */
|
||||||
strictMemoryLimit?: boolean;
|
strictMemoryLimit?: boolean;
|
||||||
|
/** dataSegmentLimit set rlimit_data limit for memoryLimit */
|
||||||
|
dataSegmentLimit?: boolean;
|
||||||
|
/** addressSpaceLimit set rlimit_address_space limit for memoryLimit */
|
||||||
|
addressSpaceLimit?: boolean;
|
||||||
|
|
||||||
/** files to be copied into sandbox before execution */
|
/** files to be copied into sandbox before execution */
|
||||||
copyIn?: Record<string, CopyInFile>;
|
copyIn?: Record<string, CopyInFile>;
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ langs:
|
|||||||
target?: Compiler output file, defaults to `foo`
|
target?: Compiler output file, defaults to `foo`
|
||||||
display: Display name
|
display: Display name
|
||||||
compile_time_limit?: Compile time limit, in milliseconds
|
compile_time_limit?: Compile time limit, in milliseconds
|
||||||
|
address_space_limit?: Enable address space memory limit as CCF did
|
||||||
|
process_limit?: Limit the number of thread
|
||||||
bash:
|
bash:
|
||||||
display: Bash
|
display: Bash
|
||||||
code_file: foo.sh
|
code_file: foo.sh
|
||||||
@@ -58,6 +60,8 @@ langs:
|
|||||||
highlight: cpp
|
highlight: cpp
|
||||||
monaco: cpp
|
monaco: cpp
|
||||||
display: C++
|
display: C++
|
||||||
|
address_space_limit: true
|
||||||
|
process_limit: 1
|
||||||
cc.cc98:
|
cc.cc98:
|
||||||
compile: /usr/bin/g++ -Wall -std=c++98 -o foo foo.cc -lm -I/include
|
compile: /usr/bin/g++ -Wall -std=c++98 -o foo foo.cc -lm -I/include
|
||||||
display: C++98
|
display: C++98
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export interface LangConfig {
|
|||||||
monaco: string;
|
monaco: string;
|
||||||
time_limit_rate: number;
|
time_limit_rate: number;
|
||||||
memory_limit_rate: number;
|
memory_limit_rate: number;
|
||||||
|
address_space_limit?: boolean;
|
||||||
|
process_limit?: number;
|
||||||
display: string;
|
display: string;
|
||||||
target?: string;
|
target?: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
|||||||
Reference in new issue
Block a user