int mpl_read_model(MPL *mpl, char *file, int skip_data) { if (mpl->phase != 0) fault("mpl_read_model: invalid call sequence"); if (file == NULL) fault("mpl_read_model: no input filename specified"); /* set up error handler */ if (setjmp(mpl->jump)) goto done; /* translate model section */ mpl->phase = 1; print("Reading model section from %s...", file); open_input(mpl, file); model_section(mpl); if (mpl->model == NULL) error(mpl, "empty model section not allowed"); /* save name of the input text file containing model section for error diagnostics during the generation phase */ mpl->mod_file = ucalloc(strlen(file)+1, sizeof(char)); strcpy(mpl->mod_file, mpl->in_file); /* allocate content arrays for all model objects */ alloc_content(mpl); /* optional data section may begin with the keyword 'data' */ if (is_keyword(mpl, "data")) { if (skip_data) { warning(mpl, "data section ignored"); goto skip; } mpl->flag_d = 1; get_token(mpl /* data */); if (mpl->token != T_SEMICOLON) error(mpl, "semicolon missing where expected"); get_token(mpl /* ; */); /* translate data section */ mpl->phase = 2; print("Reading data section from %s...", file); data_section(mpl); } /* process end statement */ end_statement(mpl); skip: print("%d line%s were read", mpl->line, mpl->line == 1 ? "" : "s") ; close_input(mpl); done: /* return to the calling program */ return mpl->phase; }
static void faultamd64(Ureg* ureg, void* v) { Proc *up = externup(); uint64_t addr; int ftype, user, insyscall; char buf[ERRMAX]; addr = machp()->MMU.cr2; user = userureg(ureg); if(!user && mmukmapsync(addr)) return; /* * There must be a user context. * If not, the usual problem is causing a fault during * initialisation before the system is fully up. */ if(up == nil) { panic("fault with up == nil; pc %#llx addr %#llx\n", ureg->ip, addr); } ftype = (ureg->error&2) ? FT_WRITE : (ureg->error&16) ? FT_EXEC : FT_READ; /* if (read) hi("read fault\n"); else hi("write fault\n"); hi("addr "); put64(addr); hi("\n"); */ insyscall = up->insyscall; up->insyscall = 1; if (0)hi("call fault\n"); if(fault(addr, ureg->ip, ftype) < 0) { iprint("could not %s fault %p\n", faulttypes[ftype], addr); /* * It is possible to get here with !user if, for example, * a process was in a system call accessing a shared * segment but was preempted by another process which shrunk * or deallocated the shared segment; when the original * process resumes it may fault while in kernel mode. * No need to panic this case, post a note to the process * and unwind the error stack. There must be an error stack * (up->nerrlab != 0) if this is a system call, if not then * the game's a bogey. */ if(!user && (!insyscall || up->nerrlab == 0)) panic("fault: %#llx\n", addr); sprint(buf, "sys: trap: fault %s addr=%#llx", faulttypes[ftype], addr); postnote(up, 1, buf, NDebug); if(insyscall) error(buf); } up->insyscall = insyscall; }
int mpl_get_col_kind(MPL *mpl, int j) { int kind; if (mpl->phase != 3) fault("mpl_get_col_kind: invalid call sequence"); if (!(1 <= j && j <= mpl->n)) fault("mpl_get_col_kind: j = %d; column number out of range", j); switch (mpl->col[j]->var->type) { case A_NUMERIC: kind = MPL_NUM; break; case A_INTEGER: kind = MPL_INT; break; case A_BINARY: kind = MPL_BIN; break; default: insist(mpl != mpl); } return kind; }
void *MemoryProtocol::zalloc(size_t size) { void *mem = alloc(size); if(mem) memset(mem, 0, size); else fault(); return mem; }
char *mpl_get_row_name(MPL *mpl, int i) { char *name = mpl->mpl_buf, *t; int len; if (mpl->phase != 3) fault("mpl_get_row_name: invalid call sequence"); if (!(1 <= i && i <= mpl->m)) fault("mpl_get_row_name: i = %d; row number out of range", i); strcpy(name, mpl->row[i]->con->name); len = strlen(name); insist(len <= 255); t = format_tuple(mpl, '[', mpl->row[i]->memb->tuple); while (*t) { if (len == 255) break; name[len++] = *t++; } name[len] = '\0'; if (len == 255) strcpy(name+252, "..."); insist(strlen(name) <= 255); return name; }
void flash_page_erase(uintptr_t ptr){ if ((ptr & 0b11) != 0) fault("invalid ptr"); *((uint32_t *)(BASE_FLASH_REGISTER + OFFSET_FMA)) = ptr; if (!(*((uint32_t *)BASE_SYSCTL_REGISTER + OFFSET_BOOTCFG) & 0b10000)) *((uint32_t *)(BASE_FLASH_REGISTER + OFFSET_FMC)) |= ((0xA442 << 16) | 0b10); // wrkey now = 0xA442 (magic constant) and erase = 1 else *((uint32_t *)(BASE_FLASH_REGISTER + OFFSET_FMC)) |= ((0x71D5 << 16) | 0b10); // wrkey now = 0x71D5 (another magic constant) and erase = 1 while (*((uint32_t *)(BASE_FLASH_REGISTER + OFFSET_FMC)) & 0b10); // }
int CClp_status(CClp *lp, int *status) { /* CHECKS whether the current lp is infeasible or whether an optimal solution has been found. It returns an error if the LP has not not been optimized. - lp is the lp; - status returns 0 if the lp has an optimal solution and 1 if it is infeasible. */ insist(lp == lp); insist(status == status); fault("CClp_status: not implemented"); return 0; }
Arc::MCC_Status ARexService::ESRestartActivity(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out) { /* esmanag:RestartActivity estypes:ActivityID esmanag:RestartActivityResponse esmanag:RestartActivityResponseItem estypes:ActivityID . esmanag:EstimatedTime (xsd:unsignedLong) estypes:InternalBaseFault OperationNotPossibleFault OperationNotAllowedFault ActivityNotFoundFault AccessControlFault estypes:VectorLimitExceededFault estypes:AccessControlFault estypes:InternalBaseFault */ Arc::XMLNode id = in["ActivityID"]; unsigned int n = 0; for(;(bool)id;++id) { if((++n) > MAX_ACTIVITIES) { Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,""); ESVectorLimitExceededFault(fault,MAX_ACTIVITIES,"Too many ActivityID"); out.Destroy(); return Arc::MCC_Status(Arc::STATUS_OK); }; }; id = in["ActivityID"]; for(;(bool)id;++id) { std::string jobid = id; Arc::XMLNode item = out.NewChild("esmanag:RestartActivityResponseItem"); item.NewChild("estypes:ActivityID") = jobid; ARexJob job(jobid,config,logger_); if(!job) { // There is no such job logger_.msg(Arc::ERROR, "EMIES:RestartActivity: job %s - %s", jobid, job.Failure()); ESActivityNotFoundFault(item.NewChild("dummy"),job.Failure()); } else { if(!job.Resume()) { // Probably wrong current state logger_.msg(Arc::ERROR, "EMIES:RestartActivity: job %s - %s", jobid, job.Failure()); // TODO: check for real reason ESOperationNotAllowedFault(item.NewChild("dummy"),job.Failure()); } else { item.NewChild("esmanag:EstimatedTime") = Arc::tostring(config.GmConfig().WakeupPeriod()); }; }; }; return Arc::MCC_Status(Arc::STATUS_OK); }
char *mpl_get_col_name(MPL *mpl, int j) { char *name = mpl->mpl_buf, *t; int len; if (mpl->phase != 3) fault("mpl_get_col_name: invalid call sequence"); if (!(1 <= j && j <= mpl->n)) fault("mpl_get_col_name: j = %d; column number out of range", j); strcpy(name, mpl->col[j]->var->name); len = strlen(name); insist(len <= 255); t = format_tuple(mpl, '[', mpl->col[j]->memb->tuple); while (*t) { if (len == 255) break; name[len++] = *t++; } name[len] = '\0'; if (len == 255) strcpy(name+252, "..."); insist(strlen(name) <= 255); return name; }
void ejoy2d_win_init(int argc, char *argv[]) { G = create_game(); lua_State *L = ejoy2d_game_lua(G->game); int top = lua_gettop(L); luaL_requiref(L, "socket.c", luaopen_socket_c, 0); luaL_requiref(L, "socketbuffer.c", luaopen_socketbuffer_c, 0); luaL_requiref(L, "audio.c", luaopen_audio_c, 0); luaL_requiref(L, "png", luaopen_png, 0); lua_settop(L, top); lua_pushcfunction(L, traceback); int tb = lua_gettop(L); char buf[BUFSIZE]; const char *pathbuf = read_exepath(buf, BUFSIZE); if (pathbuf == NULL) fault("can't read exepath"); int err = luaL_loadstring(L, startscript); if (err) { const char *msg = lua_tostring(L,-1); fault("%s", msg); } lua_pushstring(L, pathbuf); int i; for (i=1;i<argc;i++) { lua_pushstring(L, argv[i]); } screen_init(WIDTH,HEIGHT,1.0f); err = lua_pcall(L, argc, 0, tb); if (err) { const char *msg = lua_tostring(L,-1); fault("%s", msg); } lua_pop(L,1); ejoy2d_game_start(G->game); }
void forth_swap() { if( datastack.size < 2 ) { fault( "data stack too short" ); } cell_t first = pop(); cell_t last = pop(); push( first ); push( last ); }
void forth_divmod() { cell_t first = pop(); cell_t last = pop(); if( last == 0 ) { fault( "division by zero" ); } push( (cell_t)(last / first) ); push( last % first ); }
void forth_cswap() { if( ctrlstack.size < 2 ) { fault( "ctrl stack too short" ); } cell_t first = cpop(); cell_t last = cpop(); cpush( first ); cpush( last ); }
int mpl_postsolve(MPL *mpl) { if (!(mpl->phase == 3 && !mpl->flag_p)) fault("mpl_postsolve: invalid call sequence"); /* set up error handler */ if (setjmp(mpl->jump)) goto done; /* perform postsolving */ postsolve_model(mpl); flush_output(mpl); /* postsolving phase has been finished */ print("Model has been successfully processed"); done: /* return to the calling program */ return mpl->phase; }
static void program_init(struct program * p, const char *FS, const char *VS) { // Create shader program. p->prog = glCreateProgram(); GLuint fs = compile(FS, GL_FRAGMENT_SHADER); if (fs == 0) { fault("Can't compile fragment shader"); } else { glAttachShader(p->prog, fs); } GLuint vs = compile(VS, GL_VERTEX_SHADER); if (vs == 0) { fault("Can't compile vertex shader"); } else { glAttachShader(p->prog, vs); } glBindAttribLocation(p->prog, ATTRIB_VERTEX, "position"); glBindAttribLocation(p->prog, ATTRIB_TEXTCOORD, "texcoord"); glBindAttribLocation(p->prog, ATTRIB_COLOR, "color"); glBindAttribLocation(p->prog, ATTRIB_ADDITIVE, "additive"); link(p); p->mask = glGetUniformLocation(p->prog, "mask"); p->arg_mask_x = 0.0f; p->arg_mask_y = 0.0f; if (p->mask != -1) { glUniform2f(p->mask, 0.0f, 0.0f); } p->st = glGetUniformLocation(p->prog, "st"); glDetachShader(p->prog, fs); glDeleteShader(fs); glDetachShader(p->prog, vs); glDeleteShader(vs); }
int paramList::getInt(unsigned int const paramNumber, int const minimum, int const maximum) const { if (paramNumber >= this->paramVector.size()) throw(fault("Not enough parameters", fault::CODE_TYPE)); if (this->paramVector[paramNumber].type() != value::TYPE_INT) throw(fault("Parameter that is supposed to be integer is not", fault::CODE_TYPE)); int const intvalue(static_cast<int>( value_int(this->paramVector[paramNumber]))); if (intvalue < minimum) throw(fault("Integer parameter too low", fault::CODE_TYPE)); if (intvalue > maximum) throw(fault("Integer parameter too high", fault::CODE_TYPE)); return intvalue; }
static void link(struct program *p) { GLint status; glLinkProgram(p->prog); glGetProgramiv(p->prog, GL_LINK_STATUS, &status); if (status == 0) { char buf[1024]; GLint len; glGetProgramInfoLog(p->prog, 1024, &len, buf); fault("link failed:%s\n", buf); } }
/* Pair for measuring fault -> fault handler path */ static void measure_fault_fn(int argc, char **argv) { assert(argc == N_FAULTER_ARGS); volatile ccnt_t * start = (volatile ccnt_t *) atol(argv[0]); seL4_CPtr done_ep = atol(argv[2]); for (int i = 0; i < N_RUNS + 1; i++) { /* record time */ SEL4BENCH_READ_CCNT(*start); fault(); } seL4_Signal(done_ep); }
void MaiaXmlRpcClient::httpRequestDone(int id, bool error) { QString response; if(!callmap.contains(id)) return; if(error) { MaiaFault fault(-32300, http.errorString()); response = fault.toString(); } else { response = QString::fromUtf8(http.readAll()); } callmap[id]->parseResponse(response); callmap.remove(id); }
xml::element* make_fault(const string& what) { xml::element* fault(new xml::element("env:Fault")); xml::element* faultCode(new xml::element("faultcode")); faultCode->content("env:Server"); fault->append(faultCode); xml::element* faultString(new xml::element("faultstring")); faultString->content(what); fault->append(faultString); return make_envelope(fault); }
int mpl_get_row_bnds(MPL *mpl, int i, double *_lb, double *_ub) { ELEMCON *con; int type; double lb, ub; if (mpl->phase != 3) fault("mpl_get_row_bnds: invalid call sequence"); if (!(1 <= i && i <= mpl->m)) fault("mpl_get_row_bnds: i = %d; row number out of range", i); con = mpl->row[i]; if (con->con->lbnd == NULL && con->con->ubnd == NULL) type = MPL_FR, lb = ub = 0.0; else if (con->con->ubnd == NULL) type = MPL_LO, lb = con->lbnd, ub = 0.0; else if (con->con->lbnd == NULL) type = MPL_UP, lb = 0.0, ub = con->ubnd; else if (con->con->lbnd != con->con->ubnd) type = MPL_DB, lb = con->lbnd, ub = con->ubnd; else type = MPL_FX, lb = ub = con->lbnd; if (_lb != NULL) *_lb = lb; if (_ub != NULL) *_ub = ub; return type; }
bool MappedMemory::copy(size_t offset, void *buffer, size_t bufsize) const { if(!map || (offset + bufsize > size)) { fault(); return false; } const void *member = (const void *)(map + offset); do { memcpy(buffer, member, bufsize); } while(memcmp(buffer, member, bufsize)); return true; }
static int call(lua_State *L, int n, int r) { int err = lua_pcall(L, n, r, TRACEBACK_FUNCTION); switch(err) { case LUA_OK: break; case LUA_ERRRUN: fault("LUA_ERRRUN : %s\n", lua_tostring(L,-1)); break; case LUA_ERRMEM: fault("LUA_ERRMEM : %s\n", lua_tostring(L,-1)); break; case LUA_ERRERR: fault("LUA_ERRERR : %s\n", lua_tostring(L,-1)); break; case LUA_ERRGCMM: fault("LUA_ERRGCMM : %s\n", lua_tostring(L,-1)); break; default: fault("Unknown Lua error: %d\n", err); break; } return err; }
/* * open a tcp socket and start listening for connections on it */ static int startlistening(unsigned short port) { int fd, on; struct sockaddr_in sin; if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) fault("socket"); on = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) syslog(LOG_WARNING, "setsockopt (SO_REUSEADDR): %m"); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons (port); sin.sin_addr.s_addr = INADDR_ANY; if (bind(fd, &sin, sizeof(sin)) < 0) fault("bind: %u: %s\n", port, strerror(errno)); if (listen(fd, 1) < 0) fault("listen: %s\n", strerror(errno)); return fd; }
int CClp_getweight(CClp *lp, int nrows, int *rmatbeg, int *rmatind, double *rmatval, double *weight) { /* COMPUTES the duals of the steepest edge norms for the n rows specified in rmatbeg, rmatind, and rmatval. - weight returns the array of weights; the array should be at least nrows long. */ insist(lp == lp); insist(nrows == nrows); insist(rmatbeg == rmatbeg); insist(rmatind == rmatind); insist(rmatval == rmatval); insist(weight == weight); fault("CClp_getweight: not implemented"); return 0; }
int luf_sparse(LUF *luf, int tr, int len, int ind[], double val[]) { if (!luf->valid) fault("luf_sparse: LU-factorization is not valid"); if (!tr) { /* A = F*V, therefore inv(A) = inv(V)*inv(F) */ len = luf_f_sparse(luf, len, ind, val); len = luf_v_sparse(luf, len, ind, val); } else { /* A' = V'*F', therefore inv(A') = inv(F')*inv(V') */ len = luf_vt_sparse(luf, len, ind, val); len = luf_ft_sparse(luf, len, ind, val); } return len; }
void MaiaObject::parseResponse(QString response) { QDomDocument doc; QVariant arg; if(!doc.setContent(response)) { emit fault(-32700, tr("parse error: response not well formed.")); delete this; return; } if(doc.documentElement().firstChild().toElement().tagName().toLower() == "params") { QDomNode paramNode = doc.documentElement().firstChild().firstChild(); if(!paramNode.isNull()) { arg = fromXml( paramNode.firstChild().toElement() ); } emit aresponse(arg); } else if(doc.documentElement().firstChild().toElement().tagName().toLower() == "fault") { const QVariant errorVariant = fromXml(doc.documentElement().firstChild().firstChild().toElement()); emit fault(errorVariant.toMap() [ "faultCode" ].toInt(), errorVariant.toMap() [ "faultString" ].toString()); } else { emit fault(-32600, tr("parse error: invalid xml-rpc. not conforming to spec.")); } delete this; return; }
int mpl_get_col_bnds(MPL *mpl, int j, double *_lb, double *_ub) { ELEMVAR *var; int type; double lb, ub; if (mpl->phase != 3) fault("mpl_get_col_bnds: invalid call sequence"); if (!(1 <= j && j <= mpl->n)) fault("mpl_get_col_bnds: j = %d; column number out of range", j); var = mpl->col[j]; if (var->var->lbnd == NULL && var->var->ubnd == NULL) type = MPL_FR, lb = ub = 0.0; else if (var->var->ubnd == NULL) type = MPL_LO, lb = var->lbnd, ub = 0.0; else if (var->var->lbnd == NULL) type = MPL_UP, lb = 0.0, ub = var->ubnd; else if (var->var->lbnd != var->var->ubnd) type = MPL_DB, lb = var->lbnd, ub = var->ubnd; else type = MPL_FX, lb = ub = var->lbnd; if (_lb != NULL) *_lb = lb; if (_ub != NULL) *_ub = ub; return type; }
static void faultarm(Ureg *ureg, ulong fsr, uintptr addr) { int user, insyscall, read; static char buf[ERRMAX]; char *err; read = (fsr & (1<<11)) == 0; user = userureg(ureg); if(!user){ if(addr >= USTKTOP || up == nil) _dumpstack(ureg); if(addr >= USTKTOP) panic("kernel fault: bad address pc=%#.8lux addr=%#.8lux fsr=%#.8lux", ureg->pc, addr, fsr); if(up == nil) panic("kernel fault: no user process pc=%#.8lux addr=%#.8lux fsr=%#.8lux", ureg->pc, addr, fsr); } if(up == nil) panic("user fault: up=nil pc=%#.8lux addr=%#.8lux fsr=%#.8lux", ureg->pc, addr, fsr); insyscall = up->insyscall; up->insyscall = 1; switch(fsr & 0x1F){ case 0x05: /* translation fault L1 */ case 0x07: /* translation fault L2 */ case 0x03: /* access flag fault L1 */ case 0x06: /* access flag fault L2 */ case 0x09: /* domain fault L1 */ case 0x0B: /* domain fault L2 */ case 0x0D: /* permission fault L1 */ case 0x0F: /* permission fault L2 */ if(fault(addr, read) == 0) break; /* wet floor */ default: err = faulterr[fsr & 0x1F]; if(err == nil) err = "fault"; if(!user){ dumpregs(ureg); _dumpstack(ureg); panic("kernel %s: pc=%#.8lux addr=%#.8lux fsr=%#.8lux", err, ureg->pc, addr, fsr); } sprint(buf, "sys: trap: %s %s addr=%#.8lux", err, read ? "read" : "write", addr); postnote(up, 1, buf, NDebug); } up->insyscall = insyscall; }
Arc::MCC_Status ARexService::ESResumeActivity(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out) { /* ResumeActivity estypes:ActivityID 1- ResumeActivityResponse ResumeActivityResponseItem 1- estypes:ActivityID . EstimatedTime 0-1 estypes:InternalBaseFault OperationNotPossibleFault OperationNotAllowedFault ActivityNotFoundFault AccessControlFault estypes:VectorLimitExceededFault estypes:AccessControlFault estypes:InternalBaseFault */ Arc::XMLNode id = in["ActivityID"]; unsigned int n = 0; for(;(bool)id;++id) { if((++n) > MAX_ACTIVITIES) { Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,""); ESVectorLimitExceededFault(fault,MAX_ACTIVITIES,"Too many ActivityID"); out.Destroy(); return Arc::MCC_Status(Arc::STATUS_OK); }; }; id = in["ActivityID"]; for(;(bool)id;++id) { std::string jobid = id; Arc::XMLNode item = out.NewChild("esmanag:ResumeActivityResponseItem"); item.NewChild("estypes:ActivityID") = jobid; ARexJob job(jobid,config,logger_); if(!job) { // There is no such job logger_.msg(Arc::ERROR, "EMIES:ResumeActivity: job %s - %s", jobid, job.Failure()); ESActivityNotFoundFault(item.NewChild("dummy"),job.Failure()); } else { // Pause not implemented hence job can't be resumed too logger_.msg(Arc::ERROR, "EMIES:ResumeActivity: job %s - %s", jobid, "pause not implemented"); ESOperationNotAllowedFault(item.NewChild("dummy"),"pause not implemented"); }; }; return Arc::MCC_Status(Arc::STATUS_OK); }