Skip to content

Instantly share code, notes, and snippets.

@moonpolysoft
Created March 22, 2010 21:39
Show Gist options
  • Save moonpolysoft/340558 to your computer and use it in GitHub Desktop.
Save moonpolysoft/340558 to your computer and use it in GitHub Desktop.
/*
** Everything ok, patch the beam code with op_call_nif
*/
mod->nif = lib;
for (i=0; i < entry->num_of_funcs; i++)
{
Uint* code_ptr;
erts_atom_get(entry->funcs[i].name, sys_strlen(entry->funcs[i].name), &f_atom);
code_ptr = *get_func_pp(mod->code, f_atom, entry->funcs[i].arity);
if (code_ptr[1] == 0) {
code_ptr[5+0] = (Uint) BeamOp(op_call_nif);
}
else { /* Function traced, patch the original instruction word */
BpData* bp = (BpData*) code_ptr[1];
bp->orig_instr = (Uint) BeamOp(op_call_nif);
}
code_ptr[5+1] = (Uint) entry->funcs[i].fptr;
code_ptr[5+2] = (Uint) lib;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment