github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/constants/executor.go (about)

     1  package constants
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  	"os"
     7  )
     8  
     9  const (
    10  	JudgeFlagAC  = 0 // 0 Accepted
    11  	JudgeFlagPE  = 1 // 1 Presentation Error
    12  	JudgeFlagTLE = 2 // 2 Time Limit Exceeded
    13  	JudgeFlagMLE = 3 // 3 Memory Limit Exceeded
    14  	JudgeFlagWA  = 4 // 4 Wrong Answer
    15  	JudgeFlagRE  = 5 // 5 Runtime Error
    16  	JudgeFlagOLE = 6 // 6 Output Limit Exceeded
    17  	JudgeFlagCE  = 7 // 7 Compile Error
    18  	JudgeFlagSE  = 8 // 8 System Error
    19  
    20  	JudgeFlagSpecialJudgeTimeout        = 10 // 10 Special Judge Checker Time OUT
    21  	JudgeFlagSpecialJudgeError          = 11 // 11 Special Judge Checker ERROR
    22  	JudgeFlagSpecialJudgeRequireChecker = 12 // 12 Special Judge Checker Finish, Need Standard Checkup
    23  )
    24  
    25  const (
    26  	SpecialJudgeModeDisabled    = 0
    27  	SpecialJudgeModeChecker     = 1
    28  	SpecialJudgeModeInteractive = 2
    29  
    30  	SpecialJudgeTimeLimit   = 1 * 1000   // Unit: ms
    31  	SpecialJudgeMemoryLimit = 256 * 1024 // Unit: kb
    32  )
    33  
    34  var SignalNumberMap = map[int][]string{
    35  	1: {"SIGHUP", "Hangup (POSIX)."},
    36  	2: {"SIGINT", "Interrupt (ANSI)."},
    37  	3: {"SIGQUIT", "Quit (POSIX)."},
    38  	4: {"SIGILL", "Illegal instruction (ANSI)."},
    39  	5: {"SIGTRAP", "Trace trap (POSIX)."},
    40  	6: {"SIGABRT", "Abort (ANSI)."},
    41  	//6:  []string{"SIGIOT", "IOT trap (4.2 BSD)."},
    42  	7:  {"SIGBUS", "BUS error (4.2 BSD)."},
    43  	8:  {"SIGFPE", "Floating-point exception (ANSI)."},
    44  	9:  {"SIGKILL", "Kill, unblockable (POSIX)."},
    45  	10: {"SIGUSR1", "User-defined signal 1 (POSIX)."},
    46  	11: {"SIGSEGV", "Segmentation violation (ANSI)."},
    47  	12: {"SIGUSR2", "User-defined signal 2 (POSIX)."},
    48  	13: {"SIGPIPE", "Broken pipe (POSIX)."},
    49  	14: {"SIGALRM", "Alarm clock (POSIX)."},
    50  	15: {"SIGTERM", "Termination (ANSI)."},
    51  	16: {"SIGSTKFLT", "Stack fault."},
    52  	17: {"SIGCHLD", "Child status has changed (POSIX)."},
    53  	18: {"SIGCONT", "Continue (POSIX)."},
    54  	19: {"SIGSTOP", "Stop, unblockable (POSIX)."},
    55  	20: {"SIGTSTP", "Keyboard stop (POSIX)."},
    56  	21: {"SIGTTIN", "Background read from tty (POSIX)."},
    57  	22: {"SIGTTOU", "Background write to tty (POSIX)."},
    58  	23: {"SIGURG", "Urgent condition on socket (4.2 BSD)."},
    59  	24: {"SIGXCPU", "CPU limit exceeded (4.2 BSD)."},
    60  	25: {"SIGXFSZ", "File size limit exceeded (4.2 BSD)."},
    61  	26: {"SIGVTALRM", "Virtual alarm clock (4.2 BSD)."},
    62  	27: {"SIGPROF", "Profiling alarm clock (4.2 BSD)."},
    63  	28: {"SIGWINCH", "Window size change (4.3 BSD, Sun)."},
    64  	29: {"SIGIO", "I/O now possible (4.2 BSD)."},
    65  	30: {"SIGPWR", "Power failure restart (System V)."},
    66  	31: {"SIGSYS", "Bad system call."},
    67  }
    68  
    69  var FlagMeansMap = map[int]string{
    70  	0:  "Accepted",
    71  	1:  "Presentation Error",
    72  	2:  "Time Limit Exceeded",
    73  	3:  "Memory Limit Exceeded",
    74  	4:  "Wrong Answer",
    75  	5:  "Runtime Error",
    76  	6:  "Output Limit Exceeded",
    77  	7:  "Compile Error",
    78  	8:  "System Error",
    79  	9:  "Special Judge Checker Time OUT",
    80  	10: "Special Judge Checker ERROR",
    81  	11: "Special Judge Checker Finish, Need Standard Checkup",
    82  }
    83  
    84  // 给动态语言、带虚拟机的语言设定虚拟机自身的初始内存大小
    85  var MemorySizeForJIT = map[string]int{
    86  	"gcc":     0,
    87  	"g++":     0,
    88  	"java":    393216, // java
    89  	"python2": 65536,  // py2
    90  	"python3": 65536,  // py3
    91  	"nodejs":  262144, // js
    92  	"golang":  0,
    93  	"php":     131072, // php
    94  	"ruby":    65536,  // ruby
    95  	"rust":    0,
    96  }
    97  
    98  func PlaceMemorySizeForJIT(configFile string) error {
    99  	if configFile != "" {
   100  		_, err := os.Stat(configFile)
   101  		// ignore
   102  		if os.IsNotExist(err) {
   103  			return nil
   104  		}
   105  		cbody, err := ioutil.ReadFile(configFile)
   106  		if err != nil {
   107  			return err
   108  		}
   109  		err = json.Unmarshal(cbody, &MemorySizeForJIT)
   110  		if err != nil {
   111  			return err
   112  		}
   113  	}
   114  	return nil
   115  }