1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Frank Ch. Eigler <fche@redhat.com>
4 and Graydon Hoare <graydon@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 #ifndef HAVE_SOCKLEN_T
39 /* These attempt to coax various unix flavours to declare all our
40 needed tidbits in the system headers. */
41 #if !defined(__FreeBSD__) && !defined(__APPLE__)
43 #endif /* Some BSDs break <sys/socket.h> if this is defined. */
47 #define __EXTENSIONS__
49 #define _LARGE_FILE_API
50 #define _XOPEN_SOURCE_EXTENDED 1
57 #include <sys/types.h>
64 #include "mf-runtime.h"
68 #error "Do not compile this file with -fmudflap!"
72 /* A bunch of independent stdlib/unistd hook functions, all
73 intercepted by mf-runtime.h macros. */
79 static inline size_t (strnlen
) (const char* str
, size_t n
)
83 for (s
= str
; n
&& *s
; ++s
, --n
)
92 WRAPPER2(void *, memcpy
, void *dest
, const void *src
, size_t n
)
94 TRACE ("%s\n", __PRETTY_FUNCTION__
);
95 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memcpy source");
96 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memcpy dest");
97 return memcpy (dest
, src
, n
);
103 WRAPPER2(void *, memmove
, void *dest
, const void *src
, size_t n
)
105 TRACE ("%s\n", __PRETTY_FUNCTION__
);
106 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memmove src");
107 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memmove dest");
108 return memmove (dest
, src
, n
);
113 WRAPPER2(void *, memset
, void *s
, int c
, size_t n
)
115 TRACE ("%s\n", __PRETTY_FUNCTION__
);
116 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "memset dest");
117 return memset (s
, c
, n
);
122 WRAPPER2(int, memcmp
, const void *s1
, const void *s2
, size_t n
)
124 TRACE ("%s\n", __PRETTY_FUNCTION__
);
125 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "memcmp 1st arg");
126 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "memcmp 2nd arg");
127 return memcmp (s1
, s2
, n
);
132 WRAPPER2(void *, memchr
, const void *s
, int c
, size_t n
)
134 TRACE ("%s\n", __PRETTY_FUNCTION__
);
135 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memchr region");
136 return memchr (s
, c
, n
);
141 WRAPPER2(void *, memrchr
, const void *s
, int c
, size_t n
)
143 TRACE ("%s\n", __PRETTY_FUNCTION__
);
144 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memrchr region");
145 return memrchr (s
, c
, n
);
150 WRAPPER2(char *, strcpy
, char *dest
, const char *src
)
152 /* nb: just because strlen(src) == n doesn't mean (src + n) or (src + n +
153 1) are valid pointers. the allocated object might have size < n.
156 size_t n
= strlen (src
);
157 TRACE ("%s\n", __PRETTY_FUNCTION__
);
158 MF_VALIDATE_EXTENT(src
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "strcpy src");
159 MF_VALIDATE_EXTENT(dest
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "strcpy dest");
160 return strcpy (dest
, src
);
165 WRAPPER2(char *, strncpy
, char *dest
, const char *src
, size_t n
)
167 size_t len
= strnlen (src
, n
);
168 TRACE ("%s\n", __PRETTY_FUNCTION__
);
169 MF_VALIDATE_EXTENT(src
, len
, __MF_CHECK_READ
, "strncpy src");
170 MF_VALIDATE_EXTENT(dest
, len
, __MF_CHECK_WRITE
, "strncpy dest"); /* nb: strNcpy */
171 return strncpy (dest
, src
, n
);
176 WRAPPER2(char *, strcat
, char *dest
, const char *src
)
180 TRACE ("%s\n", __PRETTY_FUNCTION__
);
181 dest_sz
= strlen (dest
);
182 src_sz
= strlen (src
);
183 MF_VALIDATE_EXTENT(src
, CLAMPADD(src_sz
, 1), __MF_CHECK_READ
, "strcat src");
184 MF_VALIDATE_EXTENT(dest
, CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1)),
185 __MF_CHECK_WRITE
, "strcat dest");
186 return strcat (dest
, src
);
191 WRAPPER2(char *, strncat
, char *dest
, const char *src
, size_t n
)
194 /* nb: validating the extents (s,n) might be a mistake for two reasons.
196 (1) the string s might be shorter than n chars, and n is just a
197 poor choice by the programmer. this is not a "true" error in the
198 sense that the call to strncat would still be ok.
200 (2) we could try to compensate for case (1) by calling strlen(s) and
201 using that as a bound for the extent to verify, but strlen might fall off
202 the end of a non-terminated string, leading to a false positive.
204 so we will call strnlen(s,n) and use that as a bound.
206 if strnlen returns a length beyond the end of the registered extent
207 associated with s, there is an error: the programmer's estimate for n is
208 too large _AND_ the string s is unterminated, in which case they'd be
209 about to touch memory they don't own while calling strncat.
211 this same logic applies to further uses of strnlen later down in this
216 TRACE ("%s\n", __PRETTY_FUNCTION__
);
217 src_sz
= strnlen (src
, n
);
218 dest_sz
= strnlen (dest
, n
);
219 MF_VALIDATE_EXTENT(src
, src_sz
, __MF_CHECK_READ
, "strncat src");
220 MF_VALIDATE_EXTENT(dest
, (CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1))),
221 __MF_CHECK_WRITE
, "strncat dest");
222 return strncat (dest
, src
, n
);
227 WRAPPER2(int, strcmp
, const char *s1
, const char *s2
)
231 TRACE ("%s\n", __PRETTY_FUNCTION__
);
234 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcmp 1st arg");
235 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_WRITE
, "strcmp 2nd arg");
236 return strcmp (s1
, s2
);
240 #ifdef WRAP_strcasecmp
241 WRAPPER2(int, strcasecmp
, const char *s1
, const char *s2
)
245 TRACE ("%s\n", __PRETTY_FUNCTION__
);
248 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcasecmp 1st arg");
249 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_READ
, "strcasecmp 2nd arg");
250 return strcasecmp (s1
, s2
);
255 WRAPPER2(int, strncmp
, const char *s1
, const char *s2
, size_t n
)
259 TRACE ("%s\n", __PRETTY_FUNCTION__
);
260 s1_sz
= strnlen (s1
, n
);
261 s2_sz
= strnlen (s2
, n
);
262 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncmp 1st arg");
263 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncmp 2nd arg");
264 return strncmp (s1
, s2
, n
);
268 #ifdef WRAP_strncasecmp
269 WRAPPER2(int, strncasecmp
, const char *s1
, const char *s2
, size_t n
)
273 TRACE ("%s\n", __PRETTY_FUNCTION__
);
274 s1_sz
= strnlen (s1
, n
);
275 s2_sz
= strnlen (s2
, n
);
276 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncasecmp 1st arg");
277 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncasecmp 2nd arg");
278 return strncasecmp (s1
, s2
, n
);
283 WRAPPER2(char *, strdup
, const char *s
)
285 DECLARE(void *, malloc
, size_t sz
);
287 size_t n
= strlen (s
);
288 TRACE ("%s\n", __PRETTY_FUNCTION__
);
289 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strdup region");
290 result
= (char *)CALL_REAL(malloc
,
291 CLAMPADD(CLAMPADD(n
,1),
292 CLAMPADD(__mf_opts
.crumple_zone
,
293 __mf_opts
.crumple_zone
)));
295 if (UNLIKELY(! result
)) return result
;
297 result
+= __mf_opts
.crumple_zone
;
298 memcpy (result
, s
, n
);
301 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strdup region");
307 WRAPPER2(char *, strndup
, const char *s
, size_t n
)
309 DECLARE(void *, malloc
, size_t sz
);
311 size_t sz
= strnlen (s
, n
);
312 TRACE ("%s\n", __PRETTY_FUNCTION__
);
313 MF_VALIDATE_EXTENT(s
, sz
, __MF_CHECK_READ
, "strndup region"); /* nb: strNdup */
315 /* note: strndup still adds a \0, even with the N limit! */
316 result
= (char *)CALL_REAL(malloc
,
317 CLAMPADD(CLAMPADD(n
,1),
318 CLAMPADD(__mf_opts
.crumple_zone
,
319 __mf_opts
.crumple_zone
)));
321 if (UNLIKELY(! result
)) return result
;
323 result
+= __mf_opts
.crumple_zone
;
324 memcpy (result
, s
, n
);
327 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strndup region");
333 WRAPPER2(char *, strchr
, const char *s
, int c
)
336 TRACE ("%s\n", __PRETTY_FUNCTION__
);
338 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strchr region");
339 return strchr (s
, c
);
344 WRAPPER2(char *, strrchr
, const char *s
, int c
)
347 TRACE ("%s\n", __PRETTY_FUNCTION__
);
349 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strrchr region");
350 return strrchr (s
, c
);
355 WRAPPER2(char *, strstr
, const char *haystack
, const char *needle
)
359 TRACE ("%s\n", __PRETTY_FUNCTION__
);
360 haystack_sz
= strlen (haystack
);
361 needle_sz
= strlen (needle
);
362 MF_VALIDATE_EXTENT(haystack
, CLAMPADD(haystack_sz
, 1), __MF_CHECK_READ
, "strstr haystack");
363 MF_VALIDATE_EXTENT(needle
, CLAMPADD(needle_sz
, 1), __MF_CHECK_READ
, "strstr needle");
364 return strstr (haystack
, needle
);
369 WRAPPER2(void *, memmem
,
370 const void *haystack
, size_t haystacklen
,
371 const void *needle
, size_t needlelen
)
373 TRACE ("%s\n", __PRETTY_FUNCTION__
);
374 MF_VALIDATE_EXTENT(haystack
, haystacklen
, __MF_CHECK_READ
, "memmem haystack");
375 MF_VALIDATE_EXTENT(needle
, needlelen
, __MF_CHECK_READ
, "memmem needle");
376 return memmem (haystack
, haystacklen
, needle
, needlelen
);
381 WRAPPER2(size_t, strlen
, const char *s
)
383 size_t result
= strlen (s
);
384 TRACE ("%s\n", __PRETTY_FUNCTION__
);
385 MF_VALIDATE_EXTENT(s
, CLAMPADD(result
, 1), __MF_CHECK_READ
, "strlen region");
391 WRAPPER2(size_t, strnlen
, const char *s
, size_t n
)
393 size_t result
= strnlen (s
, n
);
394 TRACE ("%s\n", __PRETTY_FUNCTION__
);
395 MF_VALIDATE_EXTENT(s
, result
, __MF_CHECK_READ
, "strnlen region");
401 WRAPPER2(void, bzero
, void *s
, size_t n
)
403 TRACE ("%s\n", __PRETTY_FUNCTION__
);
404 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "bzero region");
411 WRAPPER2(void, bcopy
, const void *src
, void *dest
, size_t n
)
413 TRACE ("%s\n", __PRETTY_FUNCTION__
);
414 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "bcopy src");
415 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "bcopy dest");
416 bcopy (src
, dest
, n
);
422 WRAPPER2(int, bcmp
, const void *s1
, const void *s2
, size_t n
)
424 TRACE ("%s\n", __PRETTY_FUNCTION__
);
425 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "bcmp 1st arg");
426 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "bcmp 2nd arg");
427 return bcmp (s1
, s2
, n
);
432 WRAPPER2(char *, index
, const char *s
, int c
)
434 size_t n
= strlen (s
);
435 TRACE ("%s\n", __PRETTY_FUNCTION__
);
436 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "index region");
442 WRAPPER2(char *, rindex
, const char *s
, int c
)
444 size_t n
= strlen (s
);
445 TRACE ("%s\n", __PRETTY_FUNCTION__
);
446 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "rindex region");
447 return rindex (s
, c
);
451 /* XXX: stpcpy, memccpy */
454 /* XXX: *printf,*scanf */
457 /* XXX: setjmp, longjmp */
460 WRAPPER2(char *, asctime
, struct tm
*tm
)
462 static char *reg_result
= NULL
;
464 TRACE ("%s\n", __PRETTY_FUNCTION__
);
465 MF_VALIDATE_EXTENT(tm
, sizeof (struct tm
), __MF_CHECK_READ
, "asctime tm");
466 result
= asctime (tm
);
467 if (reg_result
== NULL
)
469 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "asctime string");
477 WRAPPER2(char *, ctime
, const time_t *timep
)
479 static char *reg_result
= NULL
;
481 TRACE ("%s\n", __PRETTY_FUNCTION__
);
482 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "ctime time");
483 result
= ctime (timep
);
484 if (reg_result
== NULL
)
486 /* XXX: what if asctime and ctime return the same static ptr? */
487 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "ctime string");
495 #ifdef WRAP_localtime
496 WRAPPER2(struct tm
*, localtime
, const time_t *timep
)
498 static struct tm
*reg_result
= NULL
;
500 TRACE ("%s\n", __PRETTY_FUNCTION__
);
501 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "localtime time");
502 result
= localtime (timep
);
503 if (reg_result
== NULL
)
505 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "localtime tm");
513 WRAPPER2(struct tm
*, gmtime
, const time_t *timep
)
515 static struct tm
*reg_result
= NULL
;
517 TRACE ("%s\n", __PRETTY_FUNCTION__
);
518 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "gmtime time");
519 result
= gmtime (timep
);
520 if (reg_result
== NULL
)
522 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "gmtime tm");
533 /* The following indicate if the result of the corresponding function
534 * should be explicitly un/registered by the wrapper
536 #define MF_REGISTER_strerror __MF_TYPE_STATIC
537 #undef MF_REGISTER_fopen
538 #define MF_RESULT_SIZE_fopen (sizeof (FILE))
539 #undef MF_REGISTER_opendir
540 #define MF_RESULT_SIZE_opendir 0 /* (sizeof (DIR)) */
541 #undef MF_REGISTER_readdir
542 #define MF_REGISTER_gethostbyname __MF_TYPE_STATIC
543 #undef MF_REGISTER_gethostbyname_items
544 #undef MF_REGISTER_dlopen
545 #undef MF_REGISTER_dlerror
546 #undef MF_REGISTER_dlsym
547 #define MF_REGISTER_shmat __MF_TYPE_GUESS
552 WRAPPER2(time_t, time
, time_t *timep
)
554 TRACE ("%s\n", __PRETTY_FUNCTION__
);
556 MF_VALIDATE_EXTENT (timep
, sizeof (*timep
), __MF_CHECK_WRITE
,
563 WRAPPER2(char *, strerror
, int errnum
)
567 TRACE ("%s\n", __PRETTY_FUNCTION__
);
568 p
= strerror (errnum
);
572 #ifdef MF_REGISTER_strerror
573 __mf_register (p
, n
, MF_REGISTER_strerror
, "strerror result");
575 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "strerror result");
582 WRAPPER2(FILE *, fopen
, const char *path
, const char *mode
)
586 TRACE ("%s\n", __PRETTY_FUNCTION__
);
589 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen path");
592 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen mode");
594 p
= fopen (path
, mode
);
596 #ifdef MF_REGISTER_fopen
597 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen result");
599 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen result");
608 WRAPPER2(FILE *, fopen64
, const char *path
, const char *mode
)
612 TRACE ("%s\n", __PRETTY_FUNCTION__
);
615 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 path");
618 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 mode");
620 p
= fopen64 (path
, mode
);
622 #ifdef MF_REGISTER_fopen
623 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen64 result");
625 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen64 result");
634 WRAPPER2(int, fclose
, FILE *stream
)
637 TRACE ("%s\n", __PRETTY_FUNCTION__
);
638 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
640 resp
= fclose (stream
);
641 #ifdef MF_REGISTER_fopen
642 __mf_unregister (stream
, sizeof (*stream
));
650 WRAPPER2(size_t, fread
, void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
652 TRACE ("%s\n", __PRETTY_FUNCTION__
);
653 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
655 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_WRITE
, "fread buffer");
656 return fread (ptr
, size
, nmemb
, stream
);
661 WRAPPER2(size_t, fwrite
, const void *ptr
, size_t size
, size_t nmemb
,
664 TRACE ("%s\n", __PRETTY_FUNCTION__
);
665 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
667 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_READ
, "fwrite buffer");
668 return fwrite (ptr
, size
, nmemb
, stream
);
673 WRAPPER2(int, fgetc
, FILE *stream
)
675 TRACE ("%s\n", __PRETTY_FUNCTION__
);
676 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
678 return fgetc (stream
);
683 WRAPPER2(char *, fgets
, char *s
, int size
, FILE *stream
)
685 TRACE ("%s\n", __PRETTY_FUNCTION__
);
686 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
688 MF_VALIDATE_EXTENT (s
, size
, __MF_CHECK_WRITE
, "fgets buffer");
689 return fgets (s
, size
, stream
);
694 WRAPPER2(int, getc
, FILE *stream
)
696 TRACE ("%s\n", __PRETTY_FUNCTION__
);
697 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
699 return getc (stream
);
704 WRAPPER2(char *, gets
, char *s
)
706 TRACE ("%s\n", __PRETTY_FUNCTION__
);
707 MF_VALIDATE_EXTENT (s
, 1, __MF_CHECK_WRITE
, "gets buffer");
708 /* Avoid link-time warning... */
709 s
= fgets (s
, INT_MAX
, stdin
);
710 if (NULL
!= s
) { /* better late than never */
711 size_t n
= strlen (s
);
712 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "gets buffer");
719 WRAPPER2(int, ungetc
, int c
, FILE *stream
)
721 TRACE ("%s\n", __PRETTY_FUNCTION__
);
722 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
724 return ungetc (c
, stream
);
729 WRAPPER2(int, fputc
, int c
, FILE *stream
)
731 TRACE ("%s\n", __PRETTY_FUNCTION__
);
732 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
734 return fputc (c
, stream
);
739 WRAPPER2(int, fputs
, const char *s
, FILE *stream
)
742 TRACE ("%s\n", __PRETTY_FUNCTION__
);
744 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fputs buffer");
745 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
747 return fputs (s
, stream
);
752 WRAPPER2(int, putc
, int c
, FILE *stream
)
754 TRACE ("%s\n", __PRETTY_FUNCTION__
);
755 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
757 return putc (c
, stream
);
762 WRAPPER2(int, puts
, const char *s
)
765 TRACE ("%s\n", __PRETTY_FUNCTION__
);
767 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "puts buffer");
773 WRAPPER2(void, clearerr
, FILE *stream
)
775 TRACE ("%s\n", __PRETTY_FUNCTION__
);
776 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
783 WRAPPER2(int, feof
, FILE *stream
)
785 TRACE ("%s\n", __PRETTY_FUNCTION__
);
786 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
788 return feof (stream
);
793 WRAPPER2(int, ferror
, FILE *stream
)
795 TRACE ("%s\n", __PRETTY_FUNCTION__
);
796 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
798 return ferror (stream
);
804 WRAPPER2(int, fileno
, FILE *stream
)
806 TRACE ("%s\n", __PRETTY_FUNCTION__
);
807 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
809 return fileno (stream
);
816 WRAPPER2(int, printf
, const char *format
, ...)
821 TRACE ("%s\n", __PRETTY_FUNCTION__
);
823 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
825 va_start (ap
, format
);
826 result
= vprintf (format
, ap
);
835 WRAPPER2(int, fprintf
, FILE *stream
, const char *format
, ...)
840 TRACE ("%s\n", __PRETTY_FUNCTION__
);
841 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
844 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
846 va_start (ap
, format
);
847 result
= vfprintf (stream
, format
, ap
);
856 WRAPPER2(int, sprintf
, char *str
, const char *format
, ...)
861 TRACE ("%s\n", __PRETTY_FUNCTION__
);
862 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "sprintf str");
864 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
866 va_start (ap
, format
);
867 result
= vsprintf (str
, format
, ap
);
870 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "sprintf str");
878 WRAPPER2(int, snprintf
, char *str
, size_t size
, const char *format
, ...)
883 TRACE ("%s\n", __PRETTY_FUNCTION__
);
884 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "snprintf str");
886 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
888 va_start (ap
, format
);
889 result
= vsnprintf (str
, size
, format
, ap
);
898 WRAPPER2(int, vprintf
, const char *format
, va_list ap
)
901 TRACE ("%s\n", __PRETTY_FUNCTION__
);
903 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
905 return vprintf (format
, ap
);
912 WRAPPER2(int, vfprintf
, FILE *stream
, const char *format
, va_list ap
)
915 TRACE ("%s\n", __PRETTY_FUNCTION__
);
916 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
919 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
921 return vfprintf (stream
, format
, ap
);
928 WRAPPER2(int, vsprintf
, char *str
, const char *format
, va_list ap
)
932 TRACE ("%s\n", __PRETTY_FUNCTION__
);
933 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "vsprintf str");
935 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
937 result
= vsprintf (str
, format
, ap
);
939 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "vsprintf str");
944 #ifdef WRAP_vsnprintf
947 WRAPPER2(int, vsnprintf
, char *str
, size_t size
, const char *format
,
951 TRACE ("%s\n", __PRETTY_FUNCTION__
);
952 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "vsnprintf str");
954 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
956 return vsnprintf (str
, size
, format
, ap
);
961 WRAPPER2(int , access
, const char *path
, int mode
)
964 TRACE ("%s\n", __PRETTY_FUNCTION__
);
966 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "access path");
967 return access (path
, mode
);
972 WRAPPER2(int , remove
, const char *path
)
975 TRACE ("%s\n", __PRETTY_FUNCTION__
);
977 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "remove path");
978 return remove (path
);
983 WRAPPER2(int, fflush
, FILE *stream
)
985 TRACE ("%s\n", __PRETTY_FUNCTION__
);
986 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
988 return fflush (stream
);
993 WRAPPER2(int, fseek
, FILE *stream
, long offset
, int whence
)
995 TRACE ("%s\n", __PRETTY_FUNCTION__
);
996 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
998 return fseek (stream
, offset
, whence
);
1002 #ifdef HAVE_FSEEKO64
1003 #ifdef WRAP_fseeko64
1004 WRAPPER2(int, fseeko64
, FILE *stream
, off64_t offset
, int whence
)
1006 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1007 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1009 return fseeko64 (stream
, offset
, whence
);
1015 WRAPPER2(long, ftell
, FILE *stream
)
1017 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1018 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1020 return ftell (stream
);
1024 #ifdef HAVE_FTELLO64
1025 #ifdef WRAP_ftello64
1026 WRAPPER2(off64_t
, ftello64
, FILE *stream
)
1028 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1029 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1031 return ftello64 (stream
);
1037 WRAPPER2(void, rewind
, FILE *stream
)
1039 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1040 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1047 WRAPPER2(int, fgetpos
, FILE *stream
, fpos_t *pos
)
1049 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1050 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1052 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_WRITE
, "fgetpos pos");
1053 return fgetpos (stream
, pos
);
1058 WRAPPER2(int, fsetpos
, FILE *stream
, fpos_t *pos
)
1060 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1061 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1063 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_READ
, "fsetpos pos");
1064 return fsetpos (stream
, pos
);
1069 #include <sys/stat.h>
1070 WRAPPER2(int , stat
, const char *path
, struct stat
*buf
)
1073 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1075 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat path");
1076 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat buf");
1077 return stat (path
, buf
);
1083 #include <sys/stat.h>
1084 WRAPPER2(int , stat64
, const char *path
, struct stat64
*buf
)
1087 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1089 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat64 path");
1090 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat64 buf");
1091 return stat64 (path
, buf
);
1097 #include <sys/stat.h>
1098 WRAPPER2(int , fstat
, int filedes
, struct stat
*buf
)
1100 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1101 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "fstat buf");
1102 return fstat (filedes
, buf
);
1107 #include <sys/stat.h>
1108 WRAPPER2(int , lstat
, const char *path
, struct stat
*buf
)
1111 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1113 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "lstat path");
1114 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "lstat buf");
1115 return lstat (path
, buf
);
1120 #include <sys/stat.h>
1121 WRAPPER2(int , mkfifo
, const char *path
, mode_t mode
)
1124 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1126 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "mkfifo path");
1127 return mkfifo (path
, mode
);
1132 WRAPPER2(int, setvbuf
, FILE *stream
, char *buf
, int mode
, size_t size
)
1134 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1135 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1138 MF_VALIDATE_EXTENT (buf
, size
, __MF_CHECK_READ
, "setvbuf buf");
1139 return setvbuf (stream
, buf
, mode
, size
);
1144 WRAPPER2(void, setbuf
, FILE *stream
, char *buf
)
1146 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1147 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1150 MF_VALIDATE_EXTENT (buf
, BUFSIZ
, __MF_CHECK_READ
, "setbuf buf");
1151 setbuf (stream
, buf
);
1157 WRAPPER2(DIR *, opendir
, const char *path
)
1161 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1163 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "opendir path");
1167 #ifdef MF_REGISTER_opendir
1168 __mf_register (p
, MF_RESULT_SIZE_opendir
, MF_REGISTER_opendir
,
1171 MF_VALIDATE_EXTENT (p
, MF_RESULT_SIZE_opendir
, __MF_CHECK_WRITE
,
1178 #ifdef WRAP_closedir
1180 WRAPPER2(int, closedir
, DIR *dir
)
1182 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1183 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_WRITE
, "closedir dir");
1184 #ifdef MF_REGISTER_opendir
1185 __mf_unregister (dir
, MF_RESULT_SIZE_opendir
);
1187 return closedir (dir
);
1193 WRAPPER2(struct dirent
*, readdir
, DIR *dir
)
1196 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1197 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_READ
, "readdir dir");
1200 #ifdef MF_REGISTER_readdir
1201 __mf_register (p
, sizeof (*p
), MF_REGISTER_readdir
, "readdir result");
1203 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "readdir result");
1210 #include <sys/socket.h>
1211 WRAPPER2(int, recv
, int s
, void *buf
, size_t len
, int flags
)
1213 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1214 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recv buf");
1215 return recv (s
, buf
, len
, flags
);
1219 #ifdef WRAP_recvfrom
1220 #include <sys/socket.h>
1221 WRAPPER2(int, recvfrom
, int s
, void *buf
, size_t len
, int flags
,
1222 struct sockaddr
*from
, socklen_t
*fromlen
)
1224 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1225 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recvfrom buf");
1226 MF_VALIDATE_EXTENT (from
, (size_t)*fromlen
, __MF_CHECK_WRITE
,
1228 return recvfrom (s
, buf
, len
, flags
, from
, fromlen
);
1233 #include <sys/socket.h>
1234 WRAPPER2(int, recvmsg
, int s
, struct msghdr
*msg
, int flags
)
1236 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1237 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_WRITE
, "recvmsg msg");
1238 return recvmsg (s
, msg
, flags
);
1243 #include <sys/socket.h>
1244 WRAPPER2(int, send
, int s
, const void *msg
, size_t len
, int flags
)
1246 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1247 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "send msg");
1248 return send (s
, msg
, len
, flags
);
1253 #include <sys/socket.h>
1254 WRAPPER2(int, sendto
, int s
, const void *msg
, size_t len
, int flags
,
1255 const struct sockaddr
*to
, socklen_t tolen
)
1257 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1258 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "sendto msg");
1259 MF_VALIDATE_EXTENT (to
, (size_t)tolen
, __MF_CHECK_WRITE
, "sendto to");
1260 return sendto (s
, msg
, len
, flags
, to
, tolen
);
1265 #include <sys/socket.h>
1266 WRAPPER2(int, sendmsg
, int s
, const void *msg
, int flags
)
1268 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1269 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_READ
, "sendmsg msg");
1270 return sendmsg (s
, msg
, flags
);
1274 #ifdef WRAP_setsockopt
1275 #include <sys/socket.h>
1276 WRAPPER2(int, setsockopt
, int s
, int level
, int optname
, const void *optval
,
1279 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1280 MF_VALIDATE_EXTENT (optval
, (size_t)optlen
, __MF_CHECK_READ
,
1281 "setsockopt optval");
1282 return setsockopt (s
, level
, optname
, optval
, optlen
);
1286 #ifdef WRAP_getsockopt
1287 #include <sys/socket.h>
1288 WRAPPER2(int, getsockopt
, int s
, int level
, int optname
, void *optval
,
1291 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1292 MF_VALIDATE_EXTENT (optval
, (size_t)*optlen
, __MF_CHECK_WRITE
,
1293 "getsockopt optval");
1294 return getsockopt (s
, level
, optname
, optval
, optlen
);
1299 #include <sys/socket.h>
1300 WRAPPER2(int, accept
, int s
, struct sockaddr
*addr
, socklen_t
*addrlen
)
1302 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1303 MF_VALIDATE_EXTENT (addr
, (size_t)*addrlen
, __MF_CHECK_WRITE
, "accept addr");
1304 return accept (s
, addr
, addrlen
);
1309 #include <sys/socket.h>
1310 WRAPPER2(int, bind
, int sockfd
, struct sockaddr
*addr
, socklen_t addrlen
)
1312 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1313 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_WRITE
, "bind addr");
1314 return bind (sockfd
, addr
, addrlen
);
1319 #include <sys/socket.h>
1320 WRAPPER2(int, connect
, int sockfd
, const struct sockaddr
*addr
,
1323 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1324 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_READ
,
1326 return connect (sockfd
, addr
, addrlen
);
1330 #ifdef WRAP_gethostname
1331 WRAPPER2(int, gethostname
, char *name
, size_t len
)
1333 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1334 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_WRITE
, "gethostname name");
1335 return gethostname (name
, len
);
1339 #ifdef WRAP_sethostname
1340 WRAPPER2(int, sethostname
, const char *name
, size_t len
)
1342 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1343 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_READ
, "sethostname name");
1344 return sethostname (name
, len
);
1348 #ifdef WRAP_gethostbyname
1350 WRAPPER2(struct hostent
*, gethostbyname
, const char *name
)
1357 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1359 MF_VALIDATE_EXTENT (name
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1360 "gethostbyname name");
1361 p
= gethostbyname (name
);
1363 #ifdef MF_REGISTER_gethostbyname
1364 __mf_register (p
, sizeof (*p
), MF_REGISTER_gethostbyname
,
1365 "gethostbyname result");
1367 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
,
1368 "gethostbyname result");
1369 if (NULL
!= (s
= p
->h_name
)) {
1372 #ifdef MF_REGISTER_gethostbyname_items
1373 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1374 "gethostbyname result->h_name");
1376 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1377 "gethostbyname result->h_name");
1380 if (NULL
!= (ss
= p
->h_aliases
)) {
1381 for (nreg
= 1;; ++nreg
) {
1387 #ifdef MF_REGISTER_gethostbyname_items
1388 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1389 "gethostbyname result->h_aliases[]");
1391 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1392 "gethostbyname result->h_aliases[]");
1394 nreg
*= sizeof (*p
->h_aliases
);
1395 #ifdef MF_REGISTER_gethostbyname_items
1396 __mf_register (p
->h_aliases
, nreg
, MF_REGISTER_gethostbyname_items
,
1397 "gethostbyname result->h_aliases");
1399 MF_VALIDATE_EXTENT (p
->h_aliases
, nreg
, __MF_CHECK_WRITE
,
1400 "gethostbyname result->h_aliases");
1403 if (NULL
!= (ss
= p
->h_addr_list
)) {
1404 for (nreg
= 1;; ++nreg
) {
1408 #ifdef MF_REGISTER_gethostbyname_items
1409 __mf_register (s
, p
->h_length
, MF_REGISTER_gethostbyname_items
,
1410 "gethostbyname result->h_addr_list[]");
1412 MF_VALIDATE_EXTENT (s
, p
->h_length
, __MF_CHECK_WRITE
,
1413 "gethostbyname result->h_addr_list[]");
1415 nreg
*= sizeof (*p
->h_addr_list
);
1416 #ifdef MF_REGISTER_gethostbyname_items
1417 __mf_register (p
->h_addr_list
, nreg
, MF_REGISTER_gethostbyname_items
,
1418 "gethostbyname result->h_addr_list");
1420 MF_VALIDATE_EXTENT (p
->h_addr_list
, nreg
, __MF_CHECK_WRITE
,
1421 "gethostbyname result->h_addr_list");
1429 #include <sys/wait.h>
1430 WRAPPER2(pid_t
, wait
, int *status
)
1432 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1434 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1436 return wait (status
);
1441 #include <sys/wait.h>
1442 WRAPPER2(pid_t
, waitpid
, pid_t pid
, int *status
, int options
)
1444 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1446 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1448 return waitpid (pid
, status
, options
);
1453 WRAPPER2(FILE *, popen
, const char *command
, const char *mode
)
1457 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1459 n
= strlen (command
);
1460 MF_VALIDATE_EXTENT (command
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen path");
1463 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen mode");
1465 p
= popen (command
, mode
);
1467 #ifdef MF_REGISTER_fopen
1468 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "popen result");
1470 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "popen result");
1477 WRAPPER2(int, pclose
, FILE *stream
)
1480 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1481 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1483 resp
= pclose (stream
);
1484 #ifdef MF_REGISTER_fopen
1485 __mf_unregister (stream
, sizeof (*stream
));
1492 WRAPPER2(int, execve
, const char *path
, char *const argv
[],
1498 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1501 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve path");
1504 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *argv");
1509 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **argv");
1513 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *envp");
1518 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **envp");
1520 return execve (path
, argv
, envp
);
1525 WRAPPER2(int, execv
, const char *path
, char *const argv
[])
1530 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1533 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv path");
1536 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execv *argv");
1541 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv **argv");
1543 return execv (path
, argv
);
1548 WRAPPER2(int, execvp
, const char *path
, char *const argv
[])
1553 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1556 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp path");
1559 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execvp *argv");
1564 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp **argv");
1566 return execvp (path
, argv
);
1571 WRAPPER2(int, system
, const char *string
)
1574 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1575 n
= strlen (string
);
1576 MF_VALIDATE_EXTENT (string
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1578 return system (string
);
1583 WRAPPER2(void *, dlopen
, const char *path
, int flags
)
1587 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1589 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlopen path");
1590 p
= dlopen (path
, flags
);
1592 #ifdef MF_REGISTER_dlopen
1593 __mf_register (p
, 0, MF_REGISTER_dlopen
, "dlopen result");
1595 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlopen result");
1602 WRAPPER2(int, dlclose
, void *handle
)
1605 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1606 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlclose handle");
1607 resp
= dlclose (handle
);
1608 #ifdef MF_REGISTER_dlopen
1609 __mf_unregister (handle
, 0);
1616 WRAPPER2(char *, dlerror
)
1619 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1625 #ifdef MF_REGISTER_dlerror
1626 __mf_register (p
, n
, MF_REGISTER_dlerror
, "dlerror result");
1628 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "dlerror result");
1635 WRAPPER2(void *, dlsym
, void *handle
, char *symbol
)
1639 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1640 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlsym handle");
1641 n
= strlen (symbol
);
1642 MF_VALIDATE_EXTENT (symbol
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlsym symbol");
1643 p
= dlsym (handle
, symbol
);
1645 #ifdef MF_REGISTER_dlsym
1646 __mf_register (p
, 0, MF_REGISTER_dlsym
, "dlsym result");
1648 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlsym result");
1655 #include <sys/ipc.h>
1656 #include <sys/sem.h>
1657 WRAPPER2(int, semop
, int semid
, struct sembuf
*sops
, unsigned nsops
)
1659 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1660 MF_VALIDATE_EXTENT (sops
, sizeof (*sops
) * nsops
, __MF_CHECK_READ
,
1662 return semop (semid
, sops
, nsops
);
1667 #include <sys/ipc.h>
1668 #include <sys/sem.h>
1669 #ifndef HAVE_UNION_SEMUN
1671 int val
; /* value for SETVAL */
1672 struct semid_ds
*buf
; /* buffer for IPC_STAT, IPC_SET */
1673 unsigned short int *array
; /* array for GETALL, SETALL */
1674 struct seminfo
*__buf
; /* buffer for IPC_INFO */
1677 WRAPPER2(int, semctl
, int semid
, int semnum
, int cmd
, union semun arg
)
1679 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1682 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_WRITE
,
1686 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_READ
,
1690 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_WRITE
,
1693 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_READ
,
1697 /* FreeBSD 5.1 headers include IPC_INFO but not the __buf field. */
1698 #if !defined(__FreeBSD__)
1700 MF_VALIDATE_EXTENT (arg
.__buf
, sizeof (*arg
.__buf
), __MF_CHECK_WRITE
,
1708 return semctl (semid
, semnum
, cmd
, arg
);
1713 #include <sys/ipc.h>
1714 #include <sys/shm.h>
1715 WRAPPER2(int, shmctl
, int shmid
, int cmd
, struct shmid_ds
*buf
)
1717 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1720 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_WRITE
,
1724 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
,
1730 return shmctl (shmid
, cmd
, buf
);
1735 #include <sys/ipc.h>
1736 #include <sys/shm.h>
1737 WRAPPER2(void *, shmat
, int shmid
, const void *shmaddr
, int shmflg
)
1740 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1741 p
= shmat (shmid
, shmaddr
, shmflg
);
1742 #ifdef MF_REGISTER_shmat
1744 struct shmid_ds buf
;
1745 __mf_register (p
, shmctl (shmid
, IPC_STAT
, &buf
) ? 0 : buf
.shm_segsz
,
1746 MF_REGISTER_shmat
, "shmat result");
1754 #include <sys/ipc.h>
1755 #include <sys/shm.h>
1756 WRAPPER2(int, shmdt
, const void *shmaddr
)
1759 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1760 resp
= shmdt (shmaddr
);
1761 #ifdef MF_REGISTER_shmat
1762 __mf_unregister ((void *)shmaddr
, 0);