[qfcc] add pointer validity check function to test-harness

This commit is contained in:
Bill Currie 2024-02-17 19:43:58 +09:00
parent 192eb11235
commit 3a22091455
2 changed files with 19 additions and 6 deletions

View file

@ -96,6 +96,17 @@ bi_remove (progs_t *pr, void *data)
ED_Free (pr, ed); ED_Free (pr, ed);
} }
static void
bi_ptr_valid (progs_t *pr, void *data)
{
pr_ptr_t ptr = P_POINTER (pr, 0);
R_INT (pr) = 1;
// check for null pointers (or nearly null)
R_INT (pr) &= !(ptr < pr->null_size);
// pointer is too large
R_INT (pr) &= !(ptr >= pr->globals_size);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}} #define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
#define p(type) PR_PARAM(type) #define p(type) PR_PARAM(type)
static builtin_t builtins[] = { static builtin_t builtins[] = {
@ -105,6 +116,7 @@ static builtin_t builtins[] = {
bi(exit, 1, p(int)), bi(exit, 1, p(int)),
bi(spawn, 0), bi(spawn, 0),
bi(remove, 1, p(entity)), bi(remove, 1, p(entity)),
bi(ptr_valid, 1, p(ptr)),
{0} {0}
}; };

View file

@ -7,5 +7,6 @@ void traceon (void) = #0;
void traceoff (void) = #0; void traceoff (void) = #0;
entity spawn (void) = #0; entity spawn (void) = #0;
void remove (entity e) = #0; void remove (entity e) = #0;
int ptr_valid (void *ptr) = #0;
id obj_msgSend (id receiver, SEL op, ...) = #0; id obj_msgSend (id receiver, SEL op, ...) = #0;
void __obj_exec_class (struct obj_module *msg) = #0; void __obj_exec_class (struct obj_module *msg) = #0;