X86FuncNode* X86Compiler::newFunc(const FuncPrototype& p) { X86FuncNode* func = newNode<X86FuncNode>(); Error error; if (func == NULL) goto _NoMemory; // Create helper nodes. func->_entryNode = newLabelNode(); func->_exitNode = newLabelNode(); func->_end = newNode<HLSentinel>(); if (func->_entryNode == NULL || func->_exitNode == NULL || func->_end == NULL) goto _NoMemory; // Function prototype. if ((error = func->_x86Decl.setPrototype(p)) != kErrorOk) { setLastError(error); return NULL; } // Function arguments stack size. Since function requires _argStackSize to be // set, we have to copy it from X86FuncDecl. func->_argStackSize = func->_x86Decl.getArgStackSize(); func->_redZoneSize = static_cast<uint16_t>(func->_x86Decl.getRedZoneSize()); func->_spillZoneSize = static_cast<uint16_t>(func->_x86Decl.getSpillZoneSize()); // Expected/Required stack alignment. func->_expectedStackAlignment = getRuntime()->getStackAlignment(); func->_requiredStackAlignment = 0; // Allocate space for function arguments. func->_args = NULL; if (func->getNumArgs() != 0) { func->_args = _zoneAllocator.allocT<VarData*>(func->getNumArgs() * sizeof(VarData*)); if (func->_args == NULL) goto _NoMemory; ::memset(func->_args, 0, func->getNumArgs() * sizeof(VarData*)); } return func; _NoMemory: setLastError(kErrorNoHeapMemory); return NULL; }
void Instance::initializeAction(const std::string& action_name) { assert(m_object); assert(m_activity); const Action *old_action = m_activity->m_actioninfo ? m_activity->m_actioninfo->m_action : NULL; if (m_activity->m_actioninfo) { delete m_activity->m_actioninfo; m_activity->m_actioninfo = NULL; } m_activity->m_actioninfo = new ActionInfo(m_object->getPather(), m_location); m_activity->m_actioninfo->m_action = m_object->getAction(action_name); if (!m_activity->m_actioninfo->m_action) { delete m_activity->m_actioninfo; m_activity->m_actioninfo = NULL; throw NotFound(std::string("action ") + action_name + " not found"); } m_activity->m_actioninfo->m_prev_call_time = getRuntime(); if (m_activity->m_actioninfo->m_action != old_action) { m_activity->m_actioninfo->m_action_start_time = m_activity->m_actioninfo->m_prev_call_time; } }
CellAutomataAgent::CellAutomataAgent(Runtime& rt, const k_guid_t& guid) : Agent(rt, guid), _pGrouping(this), _pDisplayInfo(this, R_MATE), _pConsole(this), _pPixmap(this, PixmapOutputProtocol::BLACK_AND_WHITE, R_OUTPUT), _borderCond(false), _antLocation(2) { _pConsole.setServer(rt.getConsoleGuid()); _pConsole.subscribe(); _delay = 200; _problem = ANT; _stopFlag = false; _pConsole.setServer(getRuntime().getConsoleGuid()); _computeThread = new ComputeThread(*this); _neighbours = new ManagedArray<Partition>(); registerHandler((handler_t)&CellAutomataAgent::handleOpStart, OP_START); registerHandler((handler_t)&CellAutomataAgent::handleOpPartition, OP_PARTITION); registerHandler((handler_t)&CellAutomataAgent::handleOpBorder, OP_BORDER); registerHandler((handler_t)&CellAutomataAgent::handleOpSetDelay, OP_SET_DELAY); }
int main(int argc, char *argv[]) { int tdcount, tlimit, mlimit; char exename[1024], inputfile[1024]; struct rlimit r; if (argc < 6) { printf("Usage: [id] [probid] [input] [time limit] [memory limit]\n"); exit(RET_SE); } tlimit = atoi(argv[4]); mlimit = atoi(argv[5]); sprintf(exename, "./%s", argv[1]); strcpy(inputfile, argv[3]); if ((pid = fork()) == 0) { freopen("input.txt", "r", stdin); chdir("sandbox"); chroot("."); freopen("output.txt", "w", stdout); setregid(99, 99); setreuid(99, 99); ptrace(PTRACE_TRACEME, 0, NULL, NULL); execl(exename, exename, NULL); exit(0); } signal(SIGALRM, timer); alarm(1); int stat, tmpmem, sig; for (;;) { wait4(pid, &stat, 0, &rinfo); if (WIFEXITED(stat)) { puts("exited!\n"); break; } else if (WIFSTOPPED(stat)) { sig = WSTOPSIG(stat); if (sig == SIGTRAP) { if (checkSyscall() == RET_RF) { ptrace(PTRACE_KILL, pid, NULL, NULL); final_result(RET_RF); } } else if (sig == SIGUSR1) { } else printf("Stopped due to signal: %d\n", sig); } else if (WIFSIGNALED(stat)) { //Runtime Error printf("Runtime Error. Received signal: %d\n", WTERMSIG(stat)); final_result(RET_RE); break; } tmpmem = getMemory(); if (tmpmem > maxmem) maxmem = tmpmem; if (maxmem > mlimit) final_result(RET_MLE); if (getRuntime() > tlimit) { ptrace(PTRACE_KILL, pid, NULL, NULL); final_result(RET_TLE); } ptrace(PTRACE_SYSCALL, pid, NULL, NULL); } final_result(RET_AC); return 0; }
void final_result(int r) { printf("Runtime: %d MS\n", getRuntime()); printf("Memory: %d KB\n", maxmem); exit(r); }