public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* mudflap wrappers [patch]
@ 2003-04-25 12:47 Eyal Lebedinsky
  2003-04-25 13:21 ` Eyal Lebedinsky
  0 siblings, 1 reply; 7+ messages in thread
From: Eyal Lebedinsky @ 2003-04-25 12:47 UTC (permalink / raw)
  To: list, gcc, Eigler, Frank Ch.

It is time to show what I am doing with the wrappers in order
to attract some criticism. Attached is a patch for gcc/libmudflap
that adds a bunch of wrappers. This is a significant portion of
the ones I use in my system

Please note that this is work in progress, very lightly tested,
so do not install it on your heart-lung machine just yet...

Can someone who knows have a quick look and say what needs to be
changed so that the patch will be accepted when finished?

The code also shows that not all functions are easy to wrap. Look
at the *dir() functions and you will see that the 'DIR *' type is
never exposed, so checking it is problematic - what length should
one use (I used 4, is 1 safer?)?

Another issue is the treatment of alien addresses returned from
an external library. I defined
	MF_REGISTER_FOPEN
	MF_REGISTER_OPENDIR
	MF_REGISTER_READDIR
to indicate if these objects need to be registered. On my
Linux/i386 all were trapped by the malloc hook and did not need
to handle un/registration. This will be different on other
platform and I am not yet sure how to easily implement an
automatic way of detecting what to do (i.e. using autoconf).
It looks like a manual port will be necessary whenever these
wrappers are enabled on a new platform.

However, if I can assume that the GNU libc will always be used
with gcc then I can make some assumptions from the way it works.

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mudflap wrappers [patch]
  2003-04-25 12:47 mudflap wrappers [patch] Eyal Lebedinsky
@ 2003-04-25 13:21 ` Eyal Lebedinsky
  2003-04-25 14:25   ` Steven Bosscher
  0 siblings, 1 reply; 7+ messages in thread
From: Eyal Lebedinsky @ 2003-04-25 13:21 UTC (permalink / raw)
  To: list, gcc

Eyal Lebedinsky wrote:
> 
> It is time to show what I am doing with the wrappers in order
> to attract some criticism. Attached is a patch for gcc/libmudflap
> that adds a bunch of wrappers. This is a significant portion of
> the ones I use in my system

oops.

automake did not like something, you should replace the "HOOKOBJS +="
construct with a simple continuation of the "HOOKOBJS =" block in
Makefile.am.

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mudflap wrappers [patch]
  2003-04-25 13:21 ` Eyal Lebedinsky
@ 2003-04-25 14:25   ` Steven Bosscher
  2003-04-25 14:55     ` Eyal Lebedinsky
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Bosscher @ 2003-04-25 14:25 UTC (permalink / raw)
  To: Eyal Lebedinsky; +Cc: list, gcc

Op vr 25-04-2003, om 14:36 schreef Eyal Lebedinsky:
> Eyal Lebedinsky wrote:
> > 
> > It is time to show what I am doing with the wrappers in order
> > to attract some criticism. Attached is a patch for gcc/libmudflap
> > that adds a bunch of wrappers. This is a significant portion of
> > the ones I use in my system
> 
> oops.
> 
> automake did not like something, you should replace the "HOOKOBJS +="
> construct with a simple continuation of the "HOOKOBJS =" block in
> Makefile.am.

Another oops: Where's the patch :-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mudflap wrappers [patch]
  2003-04-25 14:25   ` Steven Bosscher
@ 2003-04-25 14:55     ` Eyal Lebedinsky
  0 siblings, 0 replies; 7+ messages in thread
From: Eyal Lebedinsky @ 2003-04-25 14:55 UTC (permalink / raw)
  Cc: list, gcc

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]

Steven Bosscher wrote:
> Another oops: Where's the patch :-)

Bugger, what happened to it?

Whatever, here it comes. And fixed too.

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

[-- Attachment #2: 20030425.patch --]
[-- Type: text/plain, Size: 17845 bytes --]

--- Makefile.am	Sat Apr 26 00:07:00 2003
+++ Makefile.am.new	Fri Apr 25 22:13:23 2003
@@ -8,7 +8,7 @@
 MAINT_CHARSET = latin1
 SUBDIRS = testsuite
 
-AM_CFLAGS = -ansi -Wall
+AM_CFLAGS = -Wall
 
 lib_LTLIBRARIES = libmudflap.la
 include_HEADERS = mf-runtime.h
@@ -51,8 +51,59 @@
  rindex-hook.lo \
  mmap-hook.lo \
  munmap-hook.lo \
- alloca-hook.lo
-
+ alloca-hook.lo \
+\
+ time-hook.lo \
+ ctime-hook.lo \
+ strerror-hook.lo \
+ fopen-hook.lo \
+ fclose-hook.lo \
+ fread-hook.lo \
+ fwrite-hook.lo \
+ fgetc-hook.lo \
+ fgets-hook.lo \
+ getc-hook.lo \
+ gets-hook.lo \
+ ungetc-hook.lo \
+ fputc-hook.lo \
+ fputs-hook.lo \
+ putc-hook.lo \
+ puts-hook.lo \
+ clearerr-hook.lo \
+ feof-hook.lo \
+ ferror-hook.lo \
+ fileno-hook.lo \
+ access-hook.lo \
+ remove-hook.lo \
+ fflush-hook.lo \
+ fseek-hook.lo \
+ ftell-hook.lo \
+ rewind-hook.lo \
+ fgetpos-hook.lo \
+ fsetpos-hook.lo \
+ stat-hook.lo \
+ fstat-hook.lo \
+ lstat-hook.lo \
+ mkfifo-hook.lo \
+ setvbuf-hook.lo \
+ setbuf-hook.lo \
+ opendir-hook.lo \
+ closedir-hook.lo \
+ readdir-hook.lo \
+ recv-hook.lo \
+ recvfrom-hook.lo \
+ recvmsg-hook.lo \
+ send-hook.lo \
+ sendto-hook.lo \
+ sendmsg-hook.lo \
+ setsockopt-hook.lo \
+ getsockopt-hook.lo \
+ accept-hook.lo \
+ bind-hook.lo \
+ connect-hook.lo \
+ gethostname-hook.lo \
+ sethostname-hook.lo \
+ gethostbyname-hook.lo
 #.NOTPARALLEL: # Otherwise the following loop will be executed in parallel!
 $(HOOKOBJS): mf-hooks.c mf-runtime.h mf-impl.h
 	hook=`basename $@ -hook.lo`; \
--- Makefile.in	Sat Apr 26 00:07:01 2003
+++ Makefile.in.new	Fri Apr 25 22:13:28 2003
@@ -92,7 +92,7 @@
 MAINT_CHARSET = latin1
 SUBDIRS = testsuite
 
-AM_CFLAGS = -ansi -Wall
+AM_CFLAGS = -Wall
 
 lib_LTLIBRARIES = libmudflap.la
 include_HEADERS = mf-runtime.h
@@ -136,7 +136,59 @@
  rindex-hook.lo \
  mmap-hook.lo \
  munmap-hook.lo \
- alloca-hook.lo
+ alloca-hook.lo \
+\
+ time-hook.lo \
+ ctime-hook.lo \
+ strerror-hook.lo \
+ fopen-hook.lo \
+ fclose-hook.lo \
+ fread-hook.lo \
+ fwrite-hook.lo \
+ fgetc-hook.lo \
+ fgets-hook.lo \
+ getc-hook.lo \
+ gets-hook.lo \
+ ungetc-hook.lo \
+ fputc-hook.lo \
+ fputs-hook.lo \
+ putc-hook.lo \
+ puts-hook.lo \
+ clearerr-hook.lo \
+ feof-hook.lo \
+ ferror-hook.lo \
+ fileno-hook.lo \
+ access-hook.lo \
+ remove-hook.lo \
+ fflush-hook.lo \
+ fseek-hook.lo \
+ ftell-hook.lo \
+ rewind-hook.lo \
+ fgetpos-hook.lo \
+ fsetpos-hook.lo \
+ stat-hook.lo \
+ fstat-hook.lo \
+ lstat-hook.lo \
+ mkfifo-hook.lo \
+ setvbuf-hook.lo \
+ setbuf-hook.lo \
+ opendir-hook.lo \
+ closedir-hook.lo \
+ readdir-hook.lo \
+ recv-hook.lo \
+ recvfrom-hook.lo \
+ recvmsg-hook.lo \
+ send-hook.lo \
+ sendto-hook.lo \
+ sendmsg-hook.lo \
+ setsockopt-hook.lo \
+ getsockopt-hook.lo \
+ accept-hook.lo \
+ bind-hook.lo \
+ connect-hook.lo \
+ gethostname-hook.lo \
+ sethostname-hook.lo \
+ gethostbyname-hook.lo
 
 
 libmudflap_la_LDFLAGS = 
--- mf-hooks.c	Sat Apr 26 00:07:01 2003
+++ mf-hooks.c.new	Fri Apr 25 22:34:39 2003
@@ -7,6 +7,7 @@
 XXX: libgcc license?
 */
 
+#define _GNU_SOURCE
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -810,6 +811,546 @@
 }
 #endif
 
+/* mf-hooks.c.el start */
+
+#define MF_VALIDATE_FP(stream, title) \
+do { \
+  FILE *p = (stream); \
+  if (stdin  != p && stdout != p && stderr != p) { \
+    MF_VALIDATE_EXTENT(p, sizeof (*p), __MF_CHECK_WRITE, title); \
+  } \
+} while (0)
+
+#ifdef WRAP_time
+#include <time.h>
+WRAPPER2(time_t, time, time_t *timep)
+{
+  if (NULL != timep)
+    MF_VALIDATE_EXTENT(timep, sizeof (*timep), __MF_CHECK_WRITE, "time timep");
+  return time (timep);
+}
+#endif
+
+#ifdef WRAP_ctime
+#include <time.h>
+WRAPPER2(char *, ctime, time_t *timep)
+{
+  char *p;
+  int n;
+  MF_VALIDATE_EXTENT(timep, sizeof (*timep), __MF_CHECK_READ, "ctime timep");
+  p = ctime (timep);
+  if (NULL != p) {
+    n = strlen (p);
+    __mf_register (p, CLAMPADD(n, 1), __MF_TYPE_STATIC, "ctime area");
+  }
+  return p;
+}
+#endif
+
+#ifdef WRAP_strerror
+WRAPPER2(char *, strerror, int errnum)
+{
+  char *p;
+  int n;
+  p = strerror (errnum);
+  if (NULL != p) {
+    n = strlen (p);
+    __mf_register (p, CLAMPADD(n, 1), __MF_TYPE_STATIC, "strerror area");
+  }
+  return p;
+}
+#endif
+
+#undef MF_REGISTER_FOPEN
+
+#ifdef WRAP_fopen
+WRAPPER2(FILE *, fopen, const char *path, const char *mode)
+{
+  size_t n;
+  FILE *p;
+
+  n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "fopen path");
+
+  n = strlen (mode);
+  MF_VALIDATE_EXTENT(mode, CLAMPADD(n, 1), __MF_CHECK_READ, "fopen mode");
+
+  p = fopen (path, mode);
+#ifdef MF_REGISTER_FOPEN
+  if (NULL != p)
+    __mf_register (p, sizeof (*p), __MF_TYPE_STATIC, "fopen result");
+#endif
+
+  return p;
+}
+#endif
+
+#ifdef WRAP_fclose
+WRAPPER2(int, fclose, FILE *stream)
+{
+  int resp;
+  MF_VALIDATE_FP (stream, "fclose stream");
+  resp = fclose (stream);
+#ifdef MF_REGISTER_FOPEN
+  __mf_unregister (stream, sizeof (*stream));
+#endif
+
+  return resp;
+}
+#endif
+
+#ifdef WRAP_fread
+WRAPPER2(size_t, fread, void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fread stream");
+  MF_VALIDATE_EXTENT(ptr, size * nmemb, __MF_CHECK_WRITE, "fread buffer");
+  return fread (ptr, size, nmemb, stream);
+}
+#endif
+
+#ifdef WRAP_fwrite
+WRAPPER2(size_t, fwrite, const void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fwrite stream");
+  MF_VALIDATE_EXTENT(ptr, size * nmemb, __MF_CHECK_READ, "fwrite buffer");
+  return fwrite (ptr, size, nmemb, stream);
+}
+#endif
+
+#ifdef WRAP_fgetc
+WRAPPER2(int, fgetc, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fgetc stream");
+  return fgetc (stream);
+}
+#endif
+
+#ifdef WRAP_fgets
+WRAPPER2(char *, fgets, char *s, int size, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fgets stream");
+  MF_VALIDATE_EXTENT(s, size, __MF_CHECK_WRITE, "fgets buffer");
+  return fgets (s, size, stream);
+}
+#endif
+
+#ifdef WRAP_getc
+WRAPPER2(int, getc, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "getc stream");
+  return getc (stream);
+}
+#endif
+
+#ifdef WRAP_gets
+WRAPPER2(char *, gets, char *s)
+{
+  MF_VALIDATE_EXTENT(s, 1, __MF_CHECK_WRITE, "gets buffer");
+  s = gets (s);
+  if (NULL != s) {	/* better late than never */
+    int n = strlen (s);
+    MF_VALIDATE_EXTENT(s, CLAMPADD(n, 1), __MF_CHECK_WRITE, "gets buffer");
+  }
+  return s;
+}
+#endif
+
+#ifdef WRAP_ungetc
+WRAPPER2(int, ungetc, int c, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "ungetc stream");
+  return ungetc (c, stream);
+}
+#endif
+
+#ifdef WRAP_fputc
+WRAPPER2(int, fputc, int c, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fputc stream");
+  return fputc (c, stream);
+}
+#endif
+
+#ifdef WRAP_fputs
+WRAPPER2(int, fputs, const char *s, FILE *stream)
+{
+  int n = strlen (s);
+  MF_VALIDATE_EXTENT(s, CLAMPADD(n, 1), __MF_CHECK_READ, "fputs buffer");
+  MF_VALIDATE_FP (stream, "fputs stream");
+  return fputs (s, stream);
+}
+#endif
+
+#ifdef WRAP_putc
+WRAPPER2(int, putc, int c, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "putc stream");
+  return putc (c, stream);
+}
+#endif
+
+#ifdef WRAP_puts
+WRAPPER2(int, puts, const char *s)
+{
+  int n = strlen (s);
+  MF_VALIDATE_EXTENT(s, CLAMPADD(n, 1), __MF_CHECK_READ, "puts buffer");
+  return puts (s);
+}
+#endif
+
+#ifdef WRAP_clearerr
+WRAPPER2(void, clearerr, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "clearerr stream");
+  clearerr (stream);
+}
+#endif
+
+#ifdef WRAP_feof
+WRAPPER2(int, feof, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "feof stream");
+  return feof (stream);
+}
+#endif
+
+#ifdef WRAP_ferror
+WRAPPER2(int, ferror, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "ferror stream");
+  return ferror (stream);
+}
+#endif
+
+#ifdef WRAP_fileno
+#include <stdio.h>
+WRAPPER2(int, fileno, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fileno stream");
+  return fileno (stream);
+}
+#endif
+
+#ifdef WRAP_access
+WRAPPER2(int , access, const char *path, int mode)
+{
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "access path");
+
+  return access (path, mode);
+}
+#endif
+
+#ifdef WRAP_remove
+WRAPPER2(int , remove, const char *path)
+{
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "remove path");
+
+  return remove (path);
+}
+#endif
+
+#ifdef WRAP_fflush
+WRAPPER2(int, fflush, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "fflush stream");
+  return fflush (stream);
+}
+#endif
+
+#ifdef WRAP_fseek
+WRAPPER2(int, fseek, FILE *stream, long offset, int whence)
+{
+  MF_VALIDATE_FP (stream, "fseek stream");
+  return fseek (stream, offset, whence);
+}
+#endif
+
+#ifdef WRAP_ftell
+WRAPPER2(long, ftell, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "ftell stream");
+  return ftell (stream);
+}
+#endif
+
+#ifdef WRAP_rewind
+WRAPPER2(void, rewind, FILE *stream)
+{
+  MF_VALIDATE_FP (stream, "rewind stream");
+  rewind (stream);
+}
+#endif
+
+#ifdef WRAP_fgetpos
+WRAPPER2(int, fgetpos, FILE *stream, fpos_t *pos)
+{
+  MF_VALIDATE_FP (stream, "fgetpos stream");
+  MF_VALIDATE_EXTENT(pos, sizeof (*pos), __MF_CHECK_WRITE, "fgetpos pos");
+  return fgetpos (stream, pos);
+}
+#endif
+
+#ifdef WRAP_fsetpos
+WRAPPER2(int, fsetpos, FILE *stream, fpos_t *pos)
+{
+  MF_VALIDATE_FP (stream, "fsetpos stream");
+  MF_VALIDATE_EXTENT(pos, sizeof (*pos), __MF_CHECK_READ, "fsetpos pos");
+  return fsetpos (stream, pos);
+}
+#endif
+
+#ifdef WRAP_stat
+#include <sys/stat.h>
+WRAPPER2(int , stat, const char *path, struct stat *buf)
+{
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "stat path");
+  MF_VALIDATE_EXTENT(buf, sizeof (*buf), __MF_CHECK_READ, "stat buf");
+
+  return stat (path, buf);
+}
+#endif
+
+#ifdef WRAP_fstat
+#include <sys/stat.h>
+WRAPPER2(int , fstat, int filedes, struct stat *buf)
+{
+  MF_VALIDATE_EXTENT(buf, sizeof (*buf), __MF_CHECK_READ, "fstat buf");
+
+  return fstat (filedes, buf);
+}
+#endif
+
+#ifdef WRAP_lstat
+#include <sys/stat.h>
+WRAPPER2(int , lstat, const char *path, struct stat *buf)
+{
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "lstat path");
+  MF_VALIDATE_EXTENT(buf, sizeof (*buf), __MF_CHECK_READ, "lstat buf");
+
+  return lstat (path, buf);
+}
+#endif
+
+#ifdef WRAP_mkfifo
+#include <sys/stat.h>
+WRAPPER2(int , mkfifo, const char *path, mode_t mode)
+{
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "mkfifo path");
+
+  return mkfifo (path, mode);
+}
+#endif
+
+#ifdef WRAP_setvbuf
+WRAPPER2(int, setvbuf, FILE *stream, char *buf, int mode , size_t size)
+{
+  MF_VALIDATE_FP (stream, "setvbuf stream");
+  if (NULL != buf)
+    MF_VALIDATE_EXTENT(buf, size, __MF_CHECK_READ, "setvbuf buf");
+  return setvbuf (stream, buf, mode, size);
+}
+#endif
+
+#ifdef WRAP_setbuf
+WRAPPER2(void, setbuf, FILE *stream, char *buf)
+{
+  MF_VALIDATE_FP (stream, "setbuf stream");
+  if (NULL != buf)
+    MF_VALIDATE_EXTENT(buf, BUFSIZ, __MF_CHECK_READ, "setbuf buf");
+  setbuf (stream, buf);
+}
+#endif
+
+#undef MF_REGISTER_OPENDIR
+
+#ifdef WRAP_opendir
+#include <dirent.h>
+WRAPPER2(DIR *, opendir, const char *path)
+{
+  DIR *p;
+  size_t n = strlen (path);
+  MF_VALIDATE_EXTENT(path, CLAMPADD(n, 1), __MF_CHECK_READ, "opendir path");
+
+  p = opendir (path);
+#ifdef MF_REGISTER_OPENDIR
+  if (NULL != p)
+    __mf_register (p, 4 /*sizeof (*p)*/, __MF_TYPE_STATIC, "opendir result");
+#endif
+  return p;
+}
+#endif
+
+#ifdef WRAP_closedir
+#include <dirent.h>
+WRAPPER2(int, closedir, DIR *dir)
+{
+#ifdef MF_REGISTER_OPENDIR
+  if (NULL != dir)
+    __mf_unregister (dir, 4 /*sizeof (*dir)*/);
+#endif
+  return closedir (dir);
+}
+#endif
+
+#undef MF_REGISTER_READDIR
+
+#ifdef WRAP_readdir
+#include <dirent.h>
+WRAPPER2(struct dirent *, readdir, DIR *dir)
+{
+  struct dirent *p;
+  MF_VALIDATE_EXTENT(dir, 4 /*sizeof (*dir)*/, __MF_CHECK_READ, "readdir dir");
+  p = readdir (dir);
+#ifdef MF_REGISTER_READDIR
+  if (NULL != p)
+    __mf_register (p, sizeof (*p), __MF_TYPE_STATIC, "readdir result");
+#endif
+  return p;
+}
+#endif
+
+#ifdef WRAP_recv
+#include <sys/socket.h>
+WRAPPER2(int, recv, int s, void *buf, size_t len, int flags)
+{
+  MF_VALIDATE_EXTENT(buf, len, __MF_CHECK_WRITE, "recv buf");
+  return recv (s, buf, len, flags);
+}
+#endif
+
+#ifdef WRAP_recvfrom
+#include <sys/socket.h>
+WRAPPER2(int, recvfrom, int s, void *buf, size_t len, int flags,
+		struct sockaddr *from, socklen_t *fromlen)
+{
+  MF_VALIDATE_EXTENT(buf, len, __MF_CHECK_WRITE, "recvfrom buf");
+  MF_VALIDATE_EXTENT(from, (size_t)*fromlen, __MF_CHECK_WRITE, "recvfrom from");
+  return recvfrom (s, buf, len, flags, from, fromlen);
+}
+#endif
+
+#ifdef WRAP_recvmsg
+#include <sys/socket.h>
+WRAPPER2(int, recvmsg, int s, struct msghdr *msg, int flags)
+{
+  MF_VALIDATE_EXTENT(msg, sizeof (*msg), __MF_CHECK_WRITE, "recvmsg msg");
+  return recvmsg (s, msg, flags);
+}
+#endif
+
+#ifdef WRAP_send
+#include <sys/socket.h>
+WRAPPER2(int, send, int s, const void *msg, size_t len, int flags)
+{
+  MF_VALIDATE_EXTENT(msg, len, __MF_CHECK_READ, "send msg");
+  return send (s, msg, len, flags);
+}
+#endif
+
+#ifdef WRAP_sendto
+#include <sys/socket.h>
+WRAPPER2(int, sendto, int s, const void *msg, size_t len, int flags,
+		const struct sockaddr *to, socklen_t tolen)
+{
+  MF_VALIDATE_EXTENT(msg, len, __MF_CHECK_READ, "sendto msg");
+  MF_VALIDATE_EXTENT(to, (size_t)tolen, __MF_CHECK_WRITE, "sendto to");
+  return sendto (s, msg, len, flags, to, tolen);
+}
+#endif
+
+#ifdef WRAP_sendmsg
+#include <sys/socket.h>
+WRAPPER2(int, sendmsg, int s, const void *msg, int flags)
+{
+  MF_VALIDATE_EXTENT(msg, sizeof (*msg), __MF_CHECK_READ, "sendmsg msg");
+  return sendmsg (s, msg, flags);
+}
+#endif
+
+#ifdef WRAP_setsockopt
+#include <sys/socket.h>
+WRAPPER2(int, setsockopt, int s, int level, int optname, const void *optval,
+	socklen_t optlen)
+{
+  MF_VALIDATE_EXTENT(optval, (size_t)optlen, __MF_CHECK_READ,
+    "setsockopt optval");
+  return setsockopt (s, level, optname, optval, optlen);
+}
+#endif
+
+#ifdef WRAP_getsockopt
+#include <sys/socket.h>
+WRAPPER2(int, getsockopt, int s, int level, int optname, void *optval,
+		socklen_t *optlen)
+{
+  MF_VALIDATE_EXTENT(optval, (size_t)*optlen, __MF_CHECK_WRITE,
+    "getsockopt optval");
+  return getsockopt (s, level, optname, optval, optlen);
+}
+#endif
+
+#ifdef WRAP_accept
+#include <sys/socket.h>
+WRAPPER2(int, accept, int s, struct  sockaddr *addr, socklen_t *addrlen)
+{
+  MF_VALIDATE_EXTENT(addr, (size_t)*addrlen, __MF_CHECK_WRITE, "accept addr");
+  return accept (s, addr, addrlen);
+}
+#endif
+
+#ifdef WRAP_bind
+#include <sys/socket.h>
+WRAPPER2(int, bind, int sockfd, struct  sockaddr *addr, socklen_t addrlen)
+{
+  MF_VALIDATE_EXTENT(addr, (size_t)addrlen, __MF_CHECK_WRITE, "bind addr");
+  return bind (sockfd, addr, addrlen);
+}
+#endif
+
+#ifdef WRAP_connect
+#include <sys/socket.h>
+WRAPPER2(int, connect, int sockfd, const struct sockaddr  *addr,
+	socklen_t addrlen)
+{
+  MF_VALIDATE_EXTENT(addr, (size_t)addrlen, __MF_CHECK_READ,
+		 "connect addr");
+  return connect (sockfd, addr, addrlen);
+}
+#endif
+
+#ifdef WRAP_gethostname
+WRAPPER2(int, gethostname, char *name, size_t len)
+{
+  MF_VALIDATE_EXTENT(name, len, __MF_CHECK_WRITE, "gethostname name");
+  return gethostname (name, len);
+}
+#endif
+
+#ifdef WRAP_sethostname
+WRAPPER2(int, sethostname, const char *name, size_t len)
+{
+  MF_VALIDATE_EXTENT(name, len, __MF_CHECK_READ, "sethostname name");
+  return sethostname (name, len);
+}
+#endif
+
+#ifdef WRAP_gethostbyname
+#include <netdb.h>
+WRAPPER2(struct hostent *, gethostbyname, const char *name)
+{
+  size_t n = strlen (name);
+  MF_VALIDATE_EXTENT(name, CLAMPADD(n, 1), __MF_CHECK_READ,
+    "gethostbyname name");
+  return gethostbyname (name);
+}
+#endif
+
+/* mf-hooks.c.el end */
 /* XXX:  stpcpy, memccpy */
 
 
--- mf-runtime.h.in	Sat Apr 26 00:07:01 2003
+++ mf-runtime.h.in.new	Fri Apr 25 21:12:44 2003
@@ -88,6 +88,59 @@
 #define index __mfwrap_index 
 #define rindex __mfwrap_rindex
 
+/* mf-runtime.h.in.el start */
+#define time __mfwrap_time
+#define ctime __mfwrap_ctime
+#define strerror __mfwrap_strerror
+#define fopen __mfwrap_fopen
+#define fclose __mfwrap_fclose
+#define fread __mfwrap_fread
+#define fwrite __mfwrap_fwrite
+#define fgetc __mfwrap_fgetc
+#define fgets __mfwrap_fgets
+#define getc __mfwrap_getc
+#define gets __mfwrap_gets
+#define ungetc __mfwrap_ungetc
+#define fputc __mfwrap_fputc
+#define fputs __mfwrap_fputs
+#define putc __mfwrap_putc
+#define puts __mfwrap_puts
+#define clearerr __mfwrap_clearerr
+#define feof __mfwrap_feof
+#define ferror __mfwrap_ferror
+#define fileno __mfwrap_fileno
+#define access __mfwrap_access
+#define remove __mfwrap_remove
+#define fflush __mfwrap_fflush
+#define fseek __mfwrap_fseek
+#define ftell __mfwrap_ftell
+#define rewind __mfwrap_rewind
+#define fgetpos __mfwrap_fgetpos
+#define fsetpos __mfwrap_fsetpos
+#define stat __mfwrap_stat
+#define fstat __mfwrap_fstat
+#define lstat __mfwrap_lstat
+#define mkfifo __mfwrap_mkfifo
+#define setvbuf __mfwrap_setvbuf
+#define setbuf __mfwrap_setbuf
+#define opendir __mfwrap_opendir
+#define closedir __mfwrap_closedir
+#define readdir __mfwrap_readdir
+#define recv __mfwrap_recv
+#define recvfrom __mfwrap_recvfrom
+#define recvmsg __mfwrap_recvmsg
+#define send __mfwrap_send
+#define sendto __mfwrap_sendto
+#define sendmsg __mfwrap_sendmsg
+#define setsockopt __mfwrap_setsockopt
+#define getsockopt __mfwrap_getsockopt
+#define accept __mfwrap_accept
+#define bind __mfwrap_bind
+#define connect __mfwrap_connect
+#define gethostname __mfwrap_gethostname
+#define sethostname __mfwrap_sethostname
+#define gethostbyname __mfwrap_gethostbyname
+/* mf-runtime.h.in.el end */
 /* Disable glibc macros.  */
 #define __NO_STRING_INLINES
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mudflap wrappers [patch]
  2003-04-28 19:53 ` Frank Ch. Eigler
@ 2003-04-29  2:40   ` Eyal Lebedinsky
  0 siblings, 0 replies; 7+ messages in thread
From: Eyal Lebedinsky @ 2003-04-29  2:40 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: list, gcc

"Frank Ch. Eigler" wrote:
> > shmdt() does not supply the size of the object, which is needed
> >       for the check and the unreg. Again I use zero size, can
> >       I do better?
> 
> Sure - you could use the same shmctl() trick you use in shmat().

I do not see how. shmat() had the 'shmid', shmdt() has only the
address. I was thinking that maybe I can look the object up (in
mf) and get the size that I registered before.

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mudflap wrappers [patch]
  2003-04-26 14:27 Eyal Lebedinsky
@ 2003-04-28 19:53 ` Frank Ch. Eigler
  2003-04-29  2:40   ` Eyal Lebedinsky
  0 siblings, 1 reply; 7+ messages in thread
From: Frank Ch. Eigler @ 2003-04-28 19:53 UTC (permalink / raw)
  To: Eyal Lebedinsky; +Cc: list, gcc

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

Hi -


On Sat, Apr 26, 2003 at 07:43:18PM +1000, Eyal Lebedinsky wrote:
> [...]
> opendir() and friends use 'DIR *' which is never a completed
> 	type, so how should I check this pointer? I use a size
> 	of zero - is this "The Right Way"?

I suspect the right approach will be a combination of autoconf
(detecting whether the DIR object's size might be yanked out
of system headers, then stick with that), and a conservative
backup (using size 1).


> shmdt() does not supply the size of the object, which is needed
> 	for the check and the unreg. Again I use zero size, can
> 	I do better?

Sure - you could use the same shmctl() trick you use in shmat().


> In general, when a new object shows up I check it with WRITE mode
> to ensure mf knows it was written to. Any problem with this?  [...]

For opaque system objects like FILE, DIR, I wouldn't bother with
such artificial check calls.  If no directly instrumented read/write
pointers operations are made on them, it doesn't matter whether
libmudflap knows their written-ness.


- FChE

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* mudflap wrappers [patch]
@ 2003-04-26 14:27 Eyal Lebedinsky
  2003-04-28 19:53 ` Frank Ch. Eigler
  0 siblings, 1 reply; 7+ messages in thread
From: Eyal Lebedinsky @ 2003-04-26 14:27 UTC (permalink / raw)
  To: list, gcc, Eigler, Frank Ch.

This time the patch is here, I will update it from time to time:
	http://users.bigpond.net.au/eyal/

I finished adding the wrappers that my applications use, except for
the pthreads suit. It is still only minimally tested, many wrappers
were not yet used even once.

It is rather evident that there are some issues:

opendir() and friends use 'DIR *' which is never a completed
	type, so how should I check this pointer? I use a size
	of zero - is this "The Right Way"?

shmdt() does not supply the size of the object, which is needed
	for the check and the unreg. Again I use zero size, can
	I do better?

In general, when a new object shows up I check it with WRITE mode
to ensure mf knows it was written to. Any problem with this? Is
there a better way?

I am registering stdin/out/err at init time, I think this is OK.
I am not unreg'ing it just yet.


Also - I will run the copyright story by my employer, I do not
expect any drama.


Finally, in case I failed to make it absolutely clear, if anyone
can get pthreads working, or explain how to do it...

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-04-28 23:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-25 12:47 mudflap wrappers [patch] Eyal Lebedinsky
2003-04-25 13:21 ` Eyal Lebedinsky
2003-04-25 14:25   ` Steven Bosscher
2003-04-25 14:55     ` Eyal Lebedinsky
2003-04-26 14:27 Eyal Lebedinsky
2003-04-28 19:53 ` Frank Ch. Eigler
2003-04-29  2:40   ` Eyal Lebedinsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).