On Mon, 10 Sep 2001, Jonathan Lemon wrote:

> One thing you might want to try doing is to write your own read()
> function and link against that.  Your modified version could then
> replace the nbytes value with something smaller, for debugging purposes.

Infact, when I saw this thread I whipped up a simple .so to override the
syscalls to test a network program of my own, and it helpfully found a
obscure bug where I wasn't correctly using the return value from read()..

The main problem with the below code is that it unconditionally reads X
bytes at a time.  You might want to override socket/close (and maybe dup
too, if the code does things like that) so you're only restricting syscalls
on sockets.  Or make a is_socket() function that does some runtime test I
can't think of to figure out what to do...

(compile using something like:
 gcc -fPIC -shared -O2 -g test.c -o test.so;
 use with something like:
 LD_PRELOAD=/path/to/test.so /your/program/bin/blah)

#define NBYTES 1

ssize_t read(int d, void *buf, size_t nbytes)
{
  return syscall(SYS_read, d, buf, ((nbytes<NBYTES) ? nbytes : NBYTES));
}

ssize_t write(int d, const void *buf, size_t nbytes)
{
  return syscall(SYS_write, d, buf, ((nbytes<NBYTES) ? nbytes : NBYTES));
}

-- 
David Taylor
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to