Date: Sat, 21 Dec 2002 04:22:33 +0100 From: Pawel Jakub Dawidek <nick@garage.freebsd.pl> To: freebsd-hackers@freebsd.org Subject: Re: Syscall number. Message-ID: <20021221032233.GG11475@garage.freebsd.pl> In-Reply-To: <20021220184337.GD11475@garage.freebsd.pl> References: <20021220184337.GD11475@garage.freebsd.pl>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Fri, Dec 20, 2002 at 07:43:37PM +0100, Pawel Jakub Dawidek wrote:
+> Simple example (from kld module):
+>
+> sysent[SYS_chmod].sy_call = myfunction;
+> sysent[SYS_open].sy_call = myfunction;
+> sysent[SYS_execve].sy_call = myfunction;
+>
+> int
+> myfunction(register struct proc *p, register void *uap)
+> {
+> int syscallno;
+>
+> syscallno = ?
+>
+> return (0);
+> }
+>
+> How to get syscall number inside myfunction()?
+>
+> I've always use method used in spy from Andrzej Bialecki:
+>
+> syscallno = p->p_md.md_regs->tf_eax;
+>
+> for i386 arch.
+> But when I catch many syscalls I got false numbers.
+> Hmm, not false numbers, one false numer: SYS___syscall (and I don't catch it).
Ok, I've found solution (ripped from trap.c, ehh).
int
myfunction(register struct proc *p, register void *uap)
{
int scno;
caddr_t params;
scno = p->p_md.md_regs->tf_eax;
params = (caddr_t)p->p_md.md_regs->tf_esp + sizeof(int);
if (scno == SYS_syscall) {
scno = fuword(params);
params += sizeof(int);
} else if (scno == SYS___syscall) {
scno = fuword(params);
params += sizeof(quad_t);
}
/* Now we got correct syscall number in 'scno'. */
[...]
return (0);
}
--
Pawel Jakub Dawidek
UNIX Systems Administrator
http://garage.freebsd.pl
Am I Evil? Yes, I Am.
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (FreeBSD)
iQCVAwUBPgPeeT/PhmMH/Mf1AQF/6QP+KrmHDMSXMQOPHg21PjDWarnkIJOSiOJv
tUgVkuU46ThQ99lxl5BXfqnleayPOzLH5TQZz2LMLrqxh3dZQG1FrTalR8/Ua3Gy
Q+06UnWJpk13tU0esaVt7Jw7Q/YDvodwjVd5ySYlvCZybGKdvrdbMfAeRA3vtPC6
V3khK8o6Bjs=
=zKOC
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021221032233.GG11475>
