What about passing the handle of the entity pointer into the function?
I'm not 100% sure, but wouldn't it be possible to use the my-pointer inside the function ( + proc_mode = PROC_GLOBAL; )?
Something like that:
void runWhileEntity(ENTITY* inLight)
{
proc_mode = PROC_GLOBAL;
my = inLight;
while (my) {
...
}
...
}
The my-pointer is restored correctly, isn't it?