Giter VIP home page Giter VIP logo

lo-runner's Introduction

Loco program runner core

We use this python-c library to run program in a sandbox-like environment. With it, we can accurately known the resource using of the program and limit its resource using including system-call interrupt.

Usage

For run a program without tracing:

runcfg = {
    'args':['./m'],
    'fd_in':fin.fileno(),
    'fd_out':ftemp.fileno(),
    'timelimit':1000, #in MS
    'memorylimit':20000, #in KB
}

rst = lorun.run(runcfg)

For check one output:

ftemp = file('temp.out')
fout = file(out_path)
crst = lorun.check(fout.fileno(), ftemp.fileno())

trace

You can set runcfg['trace'] to True to ensure runner's security.

Here is a simple usage:

runcfg['trace'] = True
runcfg['calls'] = [1, 2, 3, 4] # system calls that could be used by testing programs
runcfg['files'] = {'/etc/ld.so.cache': 0} # open flag permitted (value is the flags of open)

lo-runner's People

Contributors

chestnutprog avatar dojiong avatar fybmain avatar skyzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lo-runner's Issues

在判java题时报错

系统版本 Ubuntu18.04.3
java版本:

openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)

runcfg:

{
	"args": ["java", "./judge/0561e20b5577d0affdeee205975d9279/Main"],
	"fd_in": 4,
	"fd_out": 5,
	"timelimit": 5000,
	"memorylimit": 20000
}

运行时出现错误:

Error: failed /usr/lib/jvm/java-11-openjdk-amd64/lib/server/libjvm.so, because libm.so.6: failed to map segment from shared object

直接使用 java ./judge/0561e20b5577d0affdeee205975d9279/Main是可以正常运行的
请问该如何处理才能运行出正确答案?

Presentation Error when using 'rU' open mode

Some code:

fin = open(inFile, 'rU')

inFile is data from MySQL Database, and this data is from PHP textarea input by user.
I use vim to see the inFile, and find ^M at the end of each line.
So I use 'rU' open mode instead of 'r'.
But when lo-runner compare between answer and user out file, it gives out Presentation Error.
Out file doesn't have ^M.

RLIMIT_DATA和 RLIMIT_AS的选择

我看你的项目使用的是 setrlimit(RLIMIT_DATA, &rl) 来限制内存的,而 hustoj 的判题端使用的是RLIMIT_AS,代码在 https://github.com/zhblue/hustoj/blob/master/trunk/core/judge_client/judge_client.cc#L1565

我的理解是RLIMIT_DATA就只能限制代码数据段的内存占用,比如代码中已经定义的数组,而RLIMIT_AS是限制了整个进程的虚拟地址空间,也能控制 malloc 或者 new 的内存了。

不知道我理解的对么,你选择 RLIMIT_DATA 的理由是什么呢?谢谢

想知道有木有trace功能的白名单

写了个vj想要添加一个插件支持,变成 vj && oj 双混合模式,基本差不多但是不知道哪些system calls该放行,看了hustoj的源码[大雾,Ubuntu Server 15.10 32位 0.0

So 来请求帮助了 😂

emmm...小白有个安装问题

用python setup.py instll 安装后 在python里import lorun 的时候报错找不到.lorun_ext模块是为什么呢。。?求教..谢谢

MAC 上无法编译成功,好像是因为 sys/user.h文件和linux不一样

(oj) ➜ Lo-runner git:(master) ✗ python setup.py install
running install
running build
running build_py
running build_ext
building 'lorun/_lorun_ext' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include/python3.6m -c lorun/cext/lorun.c -o build/temp.macosx-10.7-x86_64-3.6/lorun/cext/lorun.o
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include/python3.6m -c lorun/cext/convert.c -o build/temp.macosx-10.7-x86_64-3.6/lorun/cext/convert.o
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include -arch x86_64 -I/Users/menduo/anaconda3/envs/oj/include/python3.6m -c lorun/cext/access.c -o build/temp.macosx-10.7-x86_64-3.6/lorun/cext/access.o
In file included from lorun/cext/access.c:19:
lorun/cext/access.h:39:56: warning: declaration of 'struct user_regs_struct' will not be visible outside of this function [-Wvisibility]
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs);
^
lorun/cext/access.c:20:2: error: invalid preprocessing directive
#includegc <sys/syscall.h>
^
lorun/cext/access.c:45:56: warning: declaration of 'struct user_regs_struct' will not be visible outside of this function [-Wvisibility]
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs) {
^
lorun/cext/access.c:45:5: error: conflicting types for 'checkAccess'
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs) {
^
lorun/cext/access.h:39:5: note: previous declaration is here
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs);
^
lorun/cext/access.c:46:27: error: incomplete definition of type 'struct user_regs_struct'
if (!runobj->inttable[REG_SYS_CALL(regs)])
^~~~~~~~~~~~~~~~~~
lorun/cext/access.h:30:33: note: expanded from macro 'REG_SYS_CALL'
#define REG_SYS_CALL(x) ((x)->orig_rax)
~~~^
lorun/cext/access.c:45:56: note: forward declaration of 'struct user_regs_struct'
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs) {
^
lorun/cext/access.c:49:13: error: incomplete definition of type 'struct user_regs_struct'
switch (REG_SYS_CALL(regs)) {
^~~~~~~~~~~~~~~~~~
lorun/cext/access.h:30:33: note: expanded from macro 'REG_SYS_CALL'
#define REG_SYS_CALL(x) ((x)->orig_rax)
~~~^
lorun/cext/access.c:45:56: note: forward declaration of 'struct user_regs_struct'
int checkAccess(struct Runobj *runobj, int pid, struct user_regs_struct *regs) {
^
2 warnings and 4 errors generated.
error: command 'gcc' failed with exit status 1

---------------报错信息----------------

sys/user.h文件

#ifndef SYS_USER_H
#define SYS_USER_H

#include <sys/appleapiopts.h>
struct waitq_set;
/* stuff that used to be included by user.h, or is now needed /
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ucred.h>
#include <sys/uio.h>
#include <sys/vm.h> /
XXX */
#include <sys/sysctl.h>

/*

  • Per process structure containing data that isn't needed in core
  • when the process isn't running (esp. when swapped out).
  • This structure may or may not be at the same kernel address
  • in all processes.
    */

struct user {
/* NOT USED ANYMORE */
};

#endif /* !SYS_USER_H */

安装时出错了呀

C:\Users\Dell\Desktop\Lo-runner-master>python C:\Users\Dell\Desktop\Lo-runner-master\setup.py install
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\lorun
copying lorun_init_.py -> build\lib.win-amd64-3.6\lorun
running build_ext
building 'lorun/_lorun_ext' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\lorun
creating build\temp.win-amd64-3.6\Release\lorun\cext
D:\Program Files\Microsoft Visual Studio\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-ID:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include" "-ID:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include" "-ID:\Program Files\Microsoft Visual Studio\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-ID:\Windows Kits\10\include\10.0.17763.0\ucrt" "-ID:\Windows Kits\10\include\10.0.17763.0\shared" "-ID:\Windows Kits\10\include\10.0.17763.0\um" "-ID:\Windows Kits\10\include\10.0.17763.0\winrt" "-ID:\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tclorun/cext/lorun.c /Fobuild\temp.win-amd64-3.6\Release\lorun/cext/lorun.obj
lorun.c
c:\users\dell\desktop\lo-runner-master\lorun\cext\lorun.h(50): error C2061: 语法错误: 标识符“u_char”
c:\users\dell\desktop\lo-runner-master\lorun\cext\lorun.h(57): error C2059: 语法错误:“}”
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2146: 语法错误: 缺少“)”(在标识符“calls”的前面)
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2081: “u_char”: 形参表中的名称非法
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2061: 语法错误: 标识符“calls”
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2059: 语法错误:“;”
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2059: 语法错误:“[”
c:\users\dell\desktop\lo-runner-master\lorun\cext\convert.h(24): error C2059: 语法错误:“)”
lorun/cext/lorun.c(37): error C2037: “args”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(40): error C2037: “fd_in”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(41): error C2037: “fd_in”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(43): error C2037: “fd_out”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(44): error C2037: “fd_out”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(46): error C2037: “fd_err”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(47): error C2037: “fd_err”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(51): error C2037: “time_limit”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(55): error C2037: “memory_limit”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(58): error C2037: “runner”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(60): error C2037: “runner”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(64): error C2037: “trace”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(70): warning C4013: “initCalls”未定义;假设外部返回 int
lorun/cext/lorun.c(70): error C2037: “inttable”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(72): error C2037: “files”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(74): error C2037: “files”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(76): error C2037: “trace”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(77): error C2037: “trace”的左侧部分指定未定义的结构/联合“Runobj”
lorun/cext/lorun.c(84): error C2079: “runobj”使用未定义的 struct“Runobj”
lorun/cext/lorun.c(88): warning C4133: “函数”: 从“int *”到“Runobj *”的类型不兼容
lorun/cext/lorun.c(89): error C2224: “.args”的左侧必须具有结构/联合类型
lorun/cext/lorun.c(90): error C2224: “.args”的左侧必须具有结构/联合类型
lorun/cext/lorun.c(90): error C2198: “free”: 用于调用的参数太少
lorun/cext/lorun.c(94): warning C4133: “函数”: 从“int *”到“Runobj *”的类型不兼容
lorun/cext/lorun.c(96): error C2224: “.args”的左侧必须具有结构/联合类型
lorun/cext/lorun.c(97): error C2224: “.args”的左侧必须具有结构/联合类型
lorun/cext/lorun.c(97): error C2198: “free”: 用于调用的参数太少
error: command 'D:\Program Files\Microsoft Visual Studio\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2

沙盒中(python)调用其他库

请问,我在沙盒中使用python的import numpy的时候发现会调用失败。
好像所有的import操作都会失败。目前找了好久也没找到原因。
所以想问一下作者,我想在执行的程序里面import其他库应该怎么做?
出错信息:
ImportError: liblapack.so.3: failed to map segment from shared object

Install Problem On Linux

Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lorun
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/srv/Lo-runner/lorun/__init__.py", line 1, in <module>
    from ._lorun_ext import run, check
ImportError: No module named 'lorun._lorun_ext'

64位Ubuntu下内存读不准

lorun在32位系统下表现很好,然而在64位Ubuntu下(我测试了12.04和14.04两个LTS版本),都会出现内存读不准的问题,请问有什么方法可以解决么?

怎么设置files参数?

我在设置中这样设置,
runcfg['trace'] = True
runcfg['calls'] = [0,1,2,3,5,9,10,11,12,21,59,158,231]
runcfg['files'] = {'/etc/ld.so.cache': 0}
然而运行时返回的结果是RE,具体如下
{'re_file': '/etc/ld.so.cache', 'memoryused': 156, 'result': 5, 'timeused': 0, 're_file_flag': 524288}
求问这个files参数是什么意思?应该怎么设置?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.