mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
Add stack limit settings to request
This commit is contained in:
parent
d06968e152
commit
238ba879e1
@ -204,6 +204,7 @@ interface Cmd {
|
||||
cpuLimit?: number; // ns
|
||||
realCpuLimit?: number; // ns
|
||||
memoryLimit?: number; // byte
|
||||
stackLimit?: number; // byte (N/A on windows, macOS cannot set over 32M)
|
||||
procLimit?: number;
|
||||
|
||||
// copy the correspond file to the container dst path
|
||||
@ -247,8 +248,9 @@ interface Request {
|
||||
interface Result {
|
||||
status: Status;
|
||||
error?: string; // potential system error message
|
||||
time: number; // ns
|
||||
time: number; // ns (cgroup recorded time)
|
||||
memory: number; // byte
|
||||
runTime: number; // ns (wall clock time)
|
||||
// copyFile name -> content
|
||||
files?: {[name:string]:string};
|
||||
// copyFileCached name -> fileId
|
||||
|
||||
@ -170,6 +170,7 @@ func convertPBCmd(c *pb.Request_CmdType) (cm worker.Cmd, streamIn []*fileStreamI
|
||||
CPULimit: c.GetCPULimit(),
|
||||
RealCPULimit: c.GetRealCPULimit(),
|
||||
MemoryLimit: c.GetMemoryLimit(),
|
||||
StackLimit: c.GetStackLimit(),
|
||||
ProcLimit: c.GetProcLimit(),
|
||||
CopyOut: c.GetCopyOut(),
|
||||
CopyOutCached: c.GetCopyOutCached(),
|
||||
|
||||
@ -25,6 +25,7 @@ type Cmd struct {
|
||||
CPULimit uint64 `json:"cpuLimit"`
|
||||
RealCPULimit uint64 `json:"realCpuLimit"`
|
||||
MemoryLimit uint64 `json:"memoryLimit"`
|
||||
StackLimit uint64 `json:"stackLimit"`
|
||||
ProcLimit uint64 `json:"procLimit"`
|
||||
|
||||
CopyIn map[string]CmdFile `json:"copyIn"`
|
||||
@ -155,6 +156,7 @@ func convertCmd(c Cmd) (worker.Cmd, error) {
|
||||
CPULimit: c.CPULimit,
|
||||
RealCPULimit: c.RealCPULimit,
|
||||
MemoryLimit: c.MemoryLimit,
|
||||
StackLimit: c.StackLimit,
|
||||
ProcLimit: c.ProcLimit,
|
||||
CopyOut: c.CopyOut,
|
||||
CopyOutCached: c.CopyOutCached,
|
||||
|
||||
@ -1045,6 +1045,7 @@ type Request_CmdType struct {
|
||||
CPULimit uint64 `protobuf:"varint,4,opt,name=CPULimit,proto3" json:"CPULimit,omitempty"`
|
||||
RealCPULimit uint64 `protobuf:"varint,5,opt,name=realCPULimit,proto3" json:"realCPULimit,omitempty"`
|
||||
MemoryLimit uint64 `protobuf:"varint,6,opt,name=memoryLimit,proto3" json:"memoryLimit,omitempty"`
|
||||
StackLimit uint64 `protobuf:"varint,12,opt,name=stackLimit,proto3" json:"stackLimit,omitempty"`
|
||||
ProcLimit uint64 `protobuf:"varint,7,opt,name=procLimit,proto3" json:"procLimit,omitempty"`
|
||||
CopyIn map[string]*Request_File `protobuf:"bytes,8,rep,name=copyIn,proto3" json:"copyIn,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
CopyOut []string `protobuf:"bytes,9,rep,name=copyOut,proto3" json:"copyOut,omitempty"`
|
||||
@ -1126,6 +1127,13 @@ func (x *Request_CmdType) GetMemoryLimit() uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Request_CmdType) GetStackLimit() uint64 {
|
||||
if x != nil {
|
||||
return x.StackLimit
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Request_CmdType) GetProcLimit() uint64 {
|
||||
if x != nil {
|
||||
return x.ProcLimit
|
||||
@ -1576,7 +1584,7 @@ var file_judge_proto_rawDesc = []byte{
|
||||
0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x28, 0x0a, 0x0c, 0x46, 0x69, 0x6c,
|
||||
0x65, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x49, 0x44, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x65,
|
||||
0x49, 0x44, 0x73, 0x22, 0xa7, 0x0a, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x49, 0x44, 0x73, 0x22, 0xc7, 0x0a, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x1c, 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x25, 0x0a,
|
||||
0x03, 0x63, 0x6d, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x62, 0x2e,
|
||||
@ -1620,7 +1628,7 @@ var file_judge_proto_rawDesc = []byte{
|
||||
0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x18, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x53, 0x74, 0x72,
|
||||
0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x48, 0x00, 0x52, 0x09, 0x73, 0x74, 0x72,
|
||||
0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x1a, 0xbd,
|
||||
0x65, 0x61, 0x6d, 0x4f, 0x75, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x1a, 0xdd,
|
||||
0x03, 0x0a, 0x07, 0x43, 0x6d, 0x64, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72,
|
||||
0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x65, 0x6e, 0x76, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x76,
|
||||
@ -1632,7 +1640,9 @@ var file_judge_proto_rawDesc = []byte{
|
||||
0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x72, 0x65, 0x61, 0x6c,
|
||||
0x43, 0x50, 0x55, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x65, 0x6d, 0x6f,
|
||||
0x72, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d,
|
||||
0x65, 0x6d, 0x6f, 0x72, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72,
|
||||
0x65, 0x6d, 0x6f, 0x72, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74,
|
||||
0x61, 0x63, 0x6b, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a,
|
||||
0x73, 0x74, 0x61, 0x63, 0x6b, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72,
|
||||
0x6f, 0x63, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x70,
|
||||
0x72, 0x6f, 0x63, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x37, 0x0a, 0x06, 0x63, 0x6f, 0x70, 0x79,
|
||||
0x49, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x65,
|
||||
|
||||
@ -81,6 +81,7 @@ message Request {
|
||||
uint64 CPULimit = 4;
|
||||
uint64 realCPULimit = 5;
|
||||
uint64 memoryLimit = 6;
|
||||
uint64 stackLimit = 12;
|
||||
uint64 procLimit = 7;
|
||||
|
||||
map<string, File> copyIn = 8;
|
||||
|
||||
@ -23,7 +23,8 @@ type Cmd struct {
|
||||
|
||||
// resource limits
|
||||
TimeLimit time.Duration
|
||||
MemoryLimit runner.Size // in bytes
|
||||
MemoryLimit runner.Size
|
||||
StackLimit runner.Size
|
||||
ProcLimit uint64
|
||||
|
||||
// file contents to copyin before exec
|
||||
|
||||
@ -19,6 +19,16 @@ func runSingle(pc context.Context, m Environment, c *Cmd, fds []*os.File, ptc []
|
||||
}
|
||||
}
|
||||
|
||||
memoryLimit := c.MemoryLimit + runner.Size(memoryLimitExtra)
|
||||
|
||||
var stackLimit runner.Size
|
||||
if c.StackLimit > 0 {
|
||||
stackLimit = c.StackLimit + runner.Size(memoryLimitExtra)
|
||||
}
|
||||
if stackLimit > memoryLimit {
|
||||
stackLimit = memoryLimit
|
||||
}
|
||||
|
||||
// set running parameters
|
||||
execParam := ExecveParam{
|
||||
Args: c.Args,
|
||||
@ -26,8 +36,9 @@ func runSingle(pc context.Context, m Environment, c *Cmd, fds []*os.File, ptc []
|
||||
Files: getFdArray(fds),
|
||||
Limit: Limit{
|
||||
Time: c.TimeLimit,
|
||||
Memory: c.MemoryLimit + runner.Size(memoryLimitExtra),
|
||||
Memory: memoryLimit,
|
||||
Proc: c.ProcLimit,
|
||||
Stack: stackLimit,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ type Cmd struct {
|
||||
CPULimit uint64
|
||||
RealCPULimit uint64
|
||||
MemoryLimit uint64
|
||||
StackLimit uint64
|
||||
ProcLimit uint64
|
||||
|
||||
CopyIn map[string]CmdFile
|
||||
|
||||
@ -259,6 +259,7 @@ func (w *Worker) prepareCmd(rc Cmd) (*envexec.Cmd, map[string]bool, error) {
|
||||
Files: files,
|
||||
TimeLimit: timeLimit,
|
||||
MemoryLimit: runner.Size(rc.MemoryLimit),
|
||||
StackLimit: runner.Size(rc.StackLimit),
|
||||
ProcLimit: rc.ProcLimit,
|
||||
CopyIn: copyIn,
|
||||
CopyOut: copyOut,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user