Plan 9 from Bell Labs’s /usr/web/sources/contrib/rminnich/trace/9.probe/pc/probe.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"probe.h"

void
probeinstall(Probe *p)
{
	u32int *fp;
	p->enabled = 1;
	fp = (u32int*)p->func;
	fp[0] = p->probe[0];
	fp[1] = p->probe[1];
}

void
probeuninstall(Probe *p)
{
	u32int *fp;
	p->enabled = 0;
	fp = (u32int*)p->func;
	fp[0] = p->orig[0];
	fp[1] = p->orig[1];
}

Probe *
mkprobe(void *func, void (*pentry)(Probe *), void (*pexit)(Probe *))
{
	Probe *p;
	u32int *fp;
	u32int rjmp;
	fp = (u32int*)func;
	p = mallocz(sizeof p[0], 1);
	p->entry = pentry;
	p->exit = pexit;
	p->func = func;
	p->orig[0] = fp[0];
	p->orig[1] = fp[1];
	/* 5 is the call instruction size */
	rjmp = (ulong)p->entrycode - (ulong)func - 5;
	p->probe[0] = 0xe8 | (rjmp << 8);
	p->probe[1] = (rjmp >> 24);
	memmove(p->entrycode, pentrytmpl, sizeof p->entrycode);
	memmove(p->exitcode, pexittmpl, sizeof p->exitcode);
	return p;
}

void
freeprobe(Probe *p)
{
	free(p);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.