-// NEED to reset startst after calling this!
+extern cvar_t prvm_garbagecollection_enable;
+// NEED to reset startst after calling this! startst may or may not be clobbered!
#define ADVANCE_PROFILE_BEFORE_JUMP() \
- prog->xfunction->profile += (st - startst)
+ prog->xfunction->profile += (st - startst); \
+ if (prvm_statementprofiling.integer || (prvm_coverage.integer & 4)) { \
+ /* All statements from startst+1 to st have been hit. */ \
+ while (++startst <= st) { \
+ if (prog->statement_profile[startst - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) \
+ PRVM_StatementCoverageEvent(prog, prog->xfunction, startst - cached_statements); \
+ } \
+ /* Observe: startst now is clobbered (now at st+1)! */ \
+ }
#ifdef PRVMTIMEPROFILING
#define PRE_ERROR() \
{
if (prog->watch_global_type != ev_void)
{
- prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
+ prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
prog->xstatement = st + 1 - cached_statements;
- PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
+ PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, g);
}
if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
{
- prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
+ prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
prog->xstatement = st + 1 - cached_statements;
- PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
+ PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, g);
}
}
#endif
#if PRVMSLOWINTERPRETER
if (prog->trace)
PRVM_PrintStatement(prog, st);
- if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4))
- PRVM_StatementCoverageEvent(prog, prog->xfunction, st - cached_statements);
if (prog->break_statement >= 0)
if ((st - cached_statements) == prog->break_statement)
{
HANDLE_OPCODE(OP_STORE_F):
HANDLE_OPCODE(OP_STORE_ENT):
HANDLE_OPCODE(OP_STORE_FLD): // integers
- HANDLE_OPCODE(OP_STORE_S):
HANDLE_OPCODE(OP_STORE_FNC): // pointers
OPB->_int = OPA->_int;
DISPATCH_OPCODE();
+ HANDLE_OPCODE(OP_STORE_S):
+ // refresh the garbage collection on the string - this guards
+ // against a certain sort of repeated migration to earlier
+ // points in the scan that could otherwise result in the string
+ // being freed for being unused
+ if(prvm_garbagecollection_enable.integer)
+ PRVM_GetString(prog, OPA->_int);
+ OPB->_int = OPA->_int;
+ DISPATCH_OPCODE();
HANDLE_OPCODE(OP_STORE_V):
OPB->ivector[0] = OPA->ivector[0];
OPB->ivector[1] = OPA->ivector[1];
HANDLE_OPCODE(OP_STOREP_F):
HANDLE_OPCODE(OP_STOREP_ENT):
HANDLE_OPCODE(OP_STOREP_FLD): // integers
- HANDLE_OPCODE(OP_STOREP_S):
HANDLE_OPCODE(OP_STOREP_FNC): // pointers
if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
{
ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
ptr->_int = OPA->_int;
DISPATCH_OPCODE();
+ HANDLE_OPCODE(OP_STOREP_S):
+ if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
+ {
+ if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
+ {
+ PRE_ERROR();
+ prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
+ goto cleanup;
+ }
+ if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
+ {
+ PRE_ERROR();
+ VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
+ }
+ }
+ // refresh the garbage collection on the string - this guards
+ // against a certain sort of repeated migration to earlier
+ // points in the scan that could otherwise result in the string
+ // being freed for being unused
+ if(prvm_garbagecollection_enable.integer)
+ PRVM_GetString(prog, OPA->_int);
+ ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
+ ptr->_int = OPA->_int;
+ DISPATCH_OPCODE();
HANDLE_OPCODE(OP_STOREP_V):
if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
{
HANDLE_OPCODE(OP_LOAD_F):
HANDLE_OPCODE(OP_LOAD_FLD):
HANDLE_OPCODE(OP_LOAD_ENT):
- HANDLE_OPCODE(OP_LOAD_S):
HANDLE_OPCODE(OP_LOAD_FNC):
if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
{
ed = PRVM_PROG_TO_EDICT(OPA->edict);
OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
DISPATCH_OPCODE();
+ HANDLE_OPCODE(OP_LOAD_S):
+ if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
+ {
+ PRE_ERROR();
+ prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
+ goto cleanup;
+ }
+ if ((prvm_uint_t)OPB->_int >= cached_entityfields)
+ {
+ PRE_ERROR();
+ prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
+ goto cleanup;
+ }
+ ed = PRVM_PROG_TO_EDICT(OPA->edict);
+ OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
+ // refresh the garbage collection on the string - this guards
+ // against a certain sort of repeated migration to earlier
+ // points in the scan that could otherwise result in the string
+ // being freed for being unused
+ PRVM_GetString(prog, OPC->_int);
+ DISPATCH_OPCODE();
HANDLE_OPCODE(OP_LOAD_V):
if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
goto cleanup;
}
- newf = &prog->functions[OPA->function];
- if (newf->callcount++ == 0 && (prvm_coverage.integer & 1))
- PRVM_FunctionCoverageEvent(prog, newf);
+ enterfunc = &prog->functions[OPA->function];
+ if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
+ PRVM_FunctionCoverageEvent(prog, enterfunc);
- if (newf->first_statement < 0)
+ if (enterfunc->first_statement < 0)
{
// negative first_statement values are built in functions
- int builtinnumber = -newf->first_statement;
+ int builtinnumber = -enterfunc->first_statement;
prog->xfunction->builtinsprofile++;
if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
{
prog->builtins[builtinnumber](prog);
#ifdef PRVMTIMEPROFILING
tm = Sys_DirtyTime();
- newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
+ enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
starttm = tm;
#endif
// builtins may cause ED_Alloc() to be called, update cached variables
- cached_edictsfields = prog->edictsfields;
+ cached_edictsfields = prog->edictsfields.fp;
cached_entityfields = prog->entityfields;
cached_entityfields_3 = prog->entityfields - 3;
cached_entityfieldsarea = prog->entityfieldsarea;
prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
}
else
- st = cached_statements + PRVM_EnterFunction(prog, newf);
+ st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
startst = st;
DISPATCH_OPCODE();
}
DISPATCH_OPCODE();
-// LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
+// LadyHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
/*
HANDLE_OPCODE(OP_ADD_I):
OPC->_int = OPA->_int + OPB->_int;
{
if (prog->watch_global_type != ev_void)
{
- prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
+ prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
prog->xstatement = st - cached_statements;
- PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
+ PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
}
if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
{
- prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
+ prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
prog->xstatement = st - cached_statements;
- PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);
+ PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
}
}
#endif