1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
2 Copyright (C) 2002, 2003, 2004 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 _LARGEFILE64_SOURCE
51 #define _XOPEN_SOURCE_EXTENDED 1
60 #include <sys/types.h>
68 #ifdef HAVE_SYS_SOCKET_H
69 #include <sys/socket.h>
74 #ifdef HAVE_SYS_WAIT_H
88 #include "mf-runtime.h"
92 #error "Do not compile this file with -fmudflap!"
96 /* A bunch of independent stdlib/unistd hook functions, all
97 intercepted by mf-runtime.h macros. */
100 static inline size_t (strnlen
) (const char* str
, size_t n
)
104 for (s
= str
; n
&& *s
; ++s
, --n
)
113 WRAPPER2(void *, memcpy
, void *dest
, const void *src
, size_t n
)
115 TRACE ("%s\n", __PRETTY_FUNCTION__
);
116 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memcpy source");
117 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memcpy dest");
118 return memcpy (dest
, src
, n
);
122 WRAPPER2(void *, memmove
, void *dest
, const void *src
, size_t n
)
124 TRACE ("%s\n", __PRETTY_FUNCTION__
);
125 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memmove src");
126 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memmove dest");
127 return memmove (dest
, src
, n
);
131 WRAPPER2(void *, memset
, void *s
, int c
, size_t n
)
133 TRACE ("%s\n", __PRETTY_FUNCTION__
);
134 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "memset dest");
135 return memset (s
, c
, n
);
139 WRAPPER2(int, memcmp
, const void *s1
, const void *s2
, size_t n
)
141 TRACE ("%s\n", __PRETTY_FUNCTION__
);
142 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "memcmp 1st arg");
143 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "memcmp 2nd arg");
144 return memcmp (s1
, s2
, n
);
148 WRAPPER2(void *, memchr
, const void *s
, int c
, size_t n
)
150 TRACE ("%s\n", __PRETTY_FUNCTION__
);
151 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memchr region");
152 return memchr (s
, c
, n
);
157 WRAPPER2(void *, memrchr
, const void *s
, int c
, size_t n
)
159 TRACE ("%s\n", __PRETTY_FUNCTION__
);
160 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memrchr region");
161 return memrchr (s
, c
, n
);
166 WRAPPER2(char *, strcpy
, char *dest
, const char *src
)
168 /* nb: just because strlen(src) == n doesn't mean (src + n) or (src + n +
169 1) are valid pointers. the allocated object might have size < n.
172 size_t n
= strlen (src
);
173 TRACE ("%s\n", __PRETTY_FUNCTION__
);
174 MF_VALIDATE_EXTENT(src
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "strcpy src");
175 MF_VALIDATE_EXTENT(dest
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "strcpy dest");
176 return strcpy (dest
, src
);
181 WRAPPER2(char *, strncpy
, char *dest
, const char *src
, size_t n
)
183 size_t len
= strnlen (src
, n
);
184 TRACE ("%s\n", __PRETTY_FUNCTION__
);
185 MF_VALIDATE_EXTENT(src
, len
, __MF_CHECK_READ
, "strncpy src");
186 MF_VALIDATE_EXTENT(dest
, len
, __MF_CHECK_WRITE
, "strncpy dest"); /* nb: strNcpy */
187 return strncpy (dest
, src
, n
);
192 WRAPPER2(char *, strcat
, char *dest
, const char *src
)
196 TRACE ("%s\n", __PRETTY_FUNCTION__
);
197 dest_sz
= strlen (dest
);
198 src_sz
= strlen (src
);
199 MF_VALIDATE_EXTENT(src
, CLAMPADD(src_sz
, 1), __MF_CHECK_READ
, "strcat src");
200 MF_VALIDATE_EXTENT(dest
, CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1)),
201 __MF_CHECK_WRITE
, "strcat dest");
202 return strcat (dest
, src
);
206 WRAPPER2(char *, strncat
, char *dest
, const char *src
, size_t n
)
209 /* nb: validating the extents (s,n) might be a mistake for two reasons.
211 (1) the string s might be shorter than n chars, and n is just a
212 poor choice by the programmer. this is not a "true" error in the
213 sense that the call to strncat would still be ok.
215 (2) we could try to compensate for case (1) by calling strlen(s) and
216 using that as a bound for the extent to verify, but strlen might fall off
217 the end of a non-terminated string, leading to a false positive.
219 so we will call strnlen(s,n) and use that as a bound.
221 if strnlen returns a length beyond the end of the registered extent
222 associated with s, there is an error: the programmer's estimate for n is
223 too large _AND_ the string s is unterminated, in which case they'd be
224 about to touch memory they don't own while calling strncat.
226 this same logic applies to further uses of strnlen later down in this
231 TRACE ("%s\n", __PRETTY_FUNCTION__
);
232 src_sz
= strnlen (src
, n
);
233 dest_sz
= strnlen (dest
, n
);
234 MF_VALIDATE_EXTENT(src
, src_sz
, __MF_CHECK_READ
, "strncat src");
235 MF_VALIDATE_EXTENT(dest
, (CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1))),
236 __MF_CHECK_WRITE
, "strncat dest");
237 return strncat (dest
, src
, n
);
241 WRAPPER2(int, strcmp
, const char *s1
, const char *s2
)
245 TRACE ("%s\n", __PRETTY_FUNCTION__
);
248 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcmp 1st arg");
249 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_WRITE
, "strcmp 2nd arg");
250 return strcmp (s1
, s2
);
254 WRAPPER2(int, strcasecmp
, const char *s1
, const char *s2
)
258 TRACE ("%s\n", __PRETTY_FUNCTION__
);
261 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcasecmp 1st arg");
262 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_READ
, "strcasecmp 2nd arg");
263 return strcasecmp (s1
, s2
);
267 WRAPPER2(int, strncmp
, const char *s1
, const char *s2
, size_t n
)
271 TRACE ("%s\n", __PRETTY_FUNCTION__
);
272 s1_sz
= strnlen (s1
, n
);
273 s2_sz
= strnlen (s2
, n
);
274 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncmp 1st arg");
275 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncmp 2nd arg");
276 return strncmp (s1
, s2
, n
);
280 WRAPPER2(int, strncasecmp
, const char *s1
, const char *s2
, size_t n
)
284 TRACE ("%s\n", __PRETTY_FUNCTION__
);
285 s1_sz
= strnlen (s1
, n
);
286 s2_sz
= strnlen (s2
, n
);
287 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncasecmp 1st arg");
288 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncasecmp 2nd arg");
289 return strncasecmp (s1
, s2
, n
);
293 WRAPPER2(char *, strdup
, const char *s
)
295 DECLARE(void *, malloc
, size_t sz
);
297 size_t n
= strlen (s
);
298 TRACE ("%s\n", __PRETTY_FUNCTION__
);
299 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strdup region");
300 result
= (char *)CALL_REAL(malloc
,
301 CLAMPADD(CLAMPADD(n
,1),
302 CLAMPADD(__mf_opts
.crumple_zone
,
303 __mf_opts
.crumple_zone
)));
305 if (UNLIKELY(! result
)) return result
;
307 result
+= __mf_opts
.crumple_zone
;
308 memcpy (result
, s
, n
);
311 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strdup region");
316 WRAPPER2(char *, strndup
, const char *s
, size_t n
)
318 DECLARE(void *, malloc
, size_t sz
);
320 size_t sz
= strnlen (s
, n
);
321 TRACE ("%s\n", __PRETTY_FUNCTION__
);
322 MF_VALIDATE_EXTENT(s
, sz
, __MF_CHECK_READ
, "strndup region"); /* nb: strNdup */
324 /* note: strndup still adds a \0, even with the N limit! */
325 result
= (char *)CALL_REAL(malloc
,
326 CLAMPADD(CLAMPADD(n
,1),
327 CLAMPADD(__mf_opts
.crumple_zone
,
328 __mf_opts
.crumple_zone
)));
330 if (UNLIKELY(! result
)) return result
;
332 result
+= __mf_opts
.crumple_zone
;
333 memcpy (result
, s
, n
);
336 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strndup region");
341 WRAPPER2(char *, strchr
, const char *s
, int c
)
344 TRACE ("%s\n", __PRETTY_FUNCTION__
);
346 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strchr region");
347 return strchr (s
, c
);
351 WRAPPER2(char *, strrchr
, const char *s
, int c
)
354 TRACE ("%s\n", __PRETTY_FUNCTION__
);
356 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strrchr region");
357 return strrchr (s
, c
);
361 WRAPPER2(char *, strstr
, const char *haystack
, const char *needle
)
365 TRACE ("%s\n", __PRETTY_FUNCTION__
);
366 haystack_sz
= strlen (haystack
);
367 needle_sz
= strlen (needle
);
368 MF_VALIDATE_EXTENT(haystack
, CLAMPADD(haystack_sz
, 1), __MF_CHECK_READ
, "strstr haystack");
369 MF_VALIDATE_EXTENT(needle
, CLAMPADD(needle_sz
, 1), __MF_CHECK_READ
, "strstr needle");
370 return strstr (haystack
, needle
);
375 WRAPPER2(void *, memmem
,
376 const void *haystack
, size_t haystacklen
,
377 const void *needle
, size_t needlelen
)
379 TRACE ("%s\n", __PRETTY_FUNCTION__
);
380 MF_VALIDATE_EXTENT(haystack
, haystacklen
, __MF_CHECK_READ
, "memmem haystack");
381 MF_VALIDATE_EXTENT(needle
, needlelen
, __MF_CHECK_READ
, "memmem needle");
382 return memmem (haystack
, haystacklen
, needle
, needlelen
);
387 WRAPPER2(size_t, strlen
, const char *s
)
389 size_t result
= strlen (s
);
390 TRACE ("%s\n", __PRETTY_FUNCTION__
);
391 MF_VALIDATE_EXTENT(s
, CLAMPADD(result
, 1), __MF_CHECK_READ
, "strlen region");
396 WRAPPER2(size_t, strnlen
, const char *s
, size_t n
)
398 size_t result
= strnlen (s
, n
);
399 TRACE ("%s\n", __PRETTY_FUNCTION__
);
400 MF_VALIDATE_EXTENT(s
, result
, __MF_CHECK_READ
, "strnlen region");
405 WRAPPER2(void, bzero
, void *s
, size_t n
)
407 TRACE ("%s\n", __PRETTY_FUNCTION__
);
408 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "bzero region");
414 WRAPPER2(void, bcopy
, const void *src
, void *dest
, size_t n
)
416 TRACE ("%s\n", __PRETTY_FUNCTION__
);
417 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "bcopy src");
418 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "bcopy dest");
419 bcopy (src
, dest
, n
);
424 WRAPPER2(int, bcmp
, const void *s1
, const void *s2
, size_t n
)
426 TRACE ("%s\n", __PRETTY_FUNCTION__
);
427 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "bcmp 1st arg");
428 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "bcmp 2nd arg");
429 return bcmp (s1
, s2
, n
);
433 WRAPPER2(char *, index
, const char *s
, int c
)
435 size_t n
= strlen (s
);
436 TRACE ("%s\n", __PRETTY_FUNCTION__
);
437 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
);
450 /* XXX: stpcpy, memccpy */
452 /* XXX: *printf,*scanf */
454 /* XXX: setjmp, longjmp */
456 WRAPPER2(char *, asctime
, struct tm
*tm
)
458 static char *reg_result
= NULL
;
460 TRACE ("%s\n", __PRETTY_FUNCTION__
);
461 MF_VALIDATE_EXTENT(tm
, sizeof (struct tm
), __MF_CHECK_READ
, "asctime tm");
462 result
= asctime (tm
);
463 if (reg_result
== NULL
)
465 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "asctime string");
472 WRAPPER2(char *, ctime
, const time_t *timep
)
474 static char *reg_result
= NULL
;
476 TRACE ("%s\n", __PRETTY_FUNCTION__
);
477 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "ctime time");
478 result
= ctime (timep
);
479 if (reg_result
== NULL
)
481 /* XXX: what if asctime and ctime return the same static ptr? */
482 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "ctime string");
489 WRAPPER2(struct tm
*, localtime
, const time_t *timep
)
491 static struct tm
*reg_result
= NULL
;
493 TRACE ("%s\n", __PRETTY_FUNCTION__
);
494 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "localtime time");
495 result
= localtime (timep
);
496 if (reg_result
== NULL
)
498 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "localtime tm");
505 WRAPPER2(struct tm
*, gmtime
, const time_t *timep
)
507 static struct tm
*reg_result
= NULL
;
509 TRACE ("%s\n", __PRETTY_FUNCTION__
);
510 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "gmtime time");
511 result
= gmtime (timep
);
512 if (reg_result
== NULL
)
514 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "gmtime tm");
523 /* The following indicate if the result of the corresponding function
524 * should be explicitly un/registered by the wrapper
526 #define MF_REGISTER_strerror __MF_TYPE_STATIC
527 #undef MF_REGISTER_fopen
528 #define MF_RESULT_SIZE_fopen (sizeof (FILE))
529 #undef MF_REGISTER_opendir
530 #define MF_RESULT_SIZE_opendir 0 /* (sizeof (DIR)) */
531 #undef MF_REGISTER_readdir
532 #define MF_REGISTER_gethostbyname __MF_TYPE_STATIC
533 #undef MF_REGISTER_gethostbyname_items
534 #undef MF_REGISTER_dlopen
535 #undef MF_REGISTER_dlerror
536 #undef MF_REGISTER_dlsym
537 #define MF_REGISTER_shmat __MF_TYPE_GUESS
541 WRAPPER2(time_t, time
, time_t *timep
)
543 TRACE ("%s\n", __PRETTY_FUNCTION__
);
545 MF_VALIDATE_EXTENT (timep
, sizeof (*timep
), __MF_CHECK_WRITE
,
551 WRAPPER2(char *, strerror
, int errnum
)
555 TRACE ("%s\n", __PRETTY_FUNCTION__
);
556 p
= strerror (errnum
);
560 #ifdef MF_REGISTER_strerror
561 __mf_register (p
, n
, MF_REGISTER_strerror
, "strerror result");
563 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "strerror result");
569 WRAPPER2(FILE *, fopen
, const char *path
, const char *mode
)
573 TRACE ("%s\n", __PRETTY_FUNCTION__
);
576 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen path");
579 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen mode");
581 p
= fopen (path
, mode
);
583 #ifdef MF_REGISTER_fopen
584 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen result");
586 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen result");
594 WRAPPER2(FILE *, fopen64
, const char *path
, const char *mode
)
598 TRACE ("%s\n", __PRETTY_FUNCTION__
);
601 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 path");
604 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 mode");
606 p
= fopen64 (path
, mode
);
608 #ifdef MF_REGISTER_fopen
609 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen64 result");
611 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen64 result");
619 WRAPPER2(int, fclose
, FILE *stream
)
622 TRACE ("%s\n", __PRETTY_FUNCTION__
);
623 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
625 resp
= fclose (stream
);
626 #ifdef MF_REGISTER_fopen
627 __mf_unregister (stream
, sizeof (*stream
));
634 WRAPPER2(size_t, fread
, void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
636 TRACE ("%s\n", __PRETTY_FUNCTION__
);
637 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
639 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_WRITE
, "fread buffer");
640 return fread (ptr
, size
, nmemb
, stream
);
644 WRAPPER2(size_t, fwrite
, const void *ptr
, size_t size
, size_t nmemb
,
647 TRACE ("%s\n", __PRETTY_FUNCTION__
);
648 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
650 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_READ
, "fwrite buffer");
651 return fwrite (ptr
, size
, nmemb
, stream
);
655 WRAPPER2(int, fgetc
, FILE *stream
)
657 TRACE ("%s\n", __PRETTY_FUNCTION__
);
658 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
660 return fgetc (stream
);
664 WRAPPER2(char *, fgets
, char *s
, int size
, FILE *stream
)
666 TRACE ("%s\n", __PRETTY_FUNCTION__
);
667 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
669 MF_VALIDATE_EXTENT (s
, size
, __MF_CHECK_WRITE
, "fgets buffer");
670 return fgets (s
, size
, stream
);
674 WRAPPER2(int, getc
, FILE *stream
)
676 TRACE ("%s\n", __PRETTY_FUNCTION__
);
677 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
679 return getc (stream
);
683 WRAPPER2(char *, gets
, char *s
)
685 TRACE ("%s\n", __PRETTY_FUNCTION__
);
686 MF_VALIDATE_EXTENT (s
, 1, __MF_CHECK_WRITE
, "gets buffer");
687 /* Avoid link-time warning... */
688 s
= fgets (s
, INT_MAX
, stdin
);
689 if (NULL
!= s
) { /* better late than never */
690 size_t n
= strlen (s
);
691 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "gets buffer");
697 WRAPPER2(int, ungetc
, int c
, FILE *stream
)
699 TRACE ("%s\n", __PRETTY_FUNCTION__
);
700 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
702 return ungetc (c
, stream
);
706 WRAPPER2(int, fputc
, int c
, FILE *stream
)
708 TRACE ("%s\n", __PRETTY_FUNCTION__
);
709 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
711 return fputc (c
, stream
);
715 WRAPPER2(int, fputs
, const char *s
, FILE *stream
)
718 TRACE ("%s\n", __PRETTY_FUNCTION__
);
720 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fputs buffer");
721 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
723 return fputs (s
, stream
);
727 WRAPPER2(int, putc
, int c
, FILE *stream
)
729 TRACE ("%s\n", __PRETTY_FUNCTION__
);
730 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
732 return putc (c
, stream
);
736 WRAPPER2(int, puts
, const char *s
)
739 TRACE ("%s\n", __PRETTY_FUNCTION__
);
741 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "puts buffer");
746 WRAPPER2(void, clearerr
, FILE *stream
)
748 TRACE ("%s\n", __PRETTY_FUNCTION__
);
749 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
755 WRAPPER2(int, feof
, FILE *stream
)
757 TRACE ("%s\n", __PRETTY_FUNCTION__
);
758 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
760 return feof (stream
);
764 WRAPPER2(int, ferror
, FILE *stream
)
766 TRACE ("%s\n", __PRETTY_FUNCTION__
);
767 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
769 return ferror (stream
);
773 WRAPPER2(int, fileno
, FILE *stream
)
775 TRACE ("%s\n", __PRETTY_FUNCTION__
);
776 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
778 return fileno (stream
);
782 WRAPPER2(int, printf
, const char *format
, ...)
787 TRACE ("%s\n", __PRETTY_FUNCTION__
);
789 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
791 va_start (ap
, format
);
792 result
= vprintf (format
, ap
);
798 WRAPPER2(int, fprintf
, FILE *stream
, const char *format
, ...)
803 TRACE ("%s\n", __PRETTY_FUNCTION__
);
804 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
807 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
809 va_start (ap
, format
);
810 result
= vfprintf (stream
, format
, ap
);
816 WRAPPER2(int, sprintf
, char *str
, const char *format
, ...)
821 TRACE ("%s\n", __PRETTY_FUNCTION__
);
822 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "sprintf str");
824 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
826 va_start (ap
, format
);
827 result
= vsprintf (str
, format
, ap
);
830 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "sprintf str");
835 WRAPPER2(int, snprintf
, char *str
, size_t size
, const char *format
, ...)
840 TRACE ("%s\n", __PRETTY_FUNCTION__
);
841 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "snprintf str");
843 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
845 va_start (ap
, format
);
846 result
= vsnprintf (str
, size
, format
, ap
);
852 WRAPPER2(int, vprintf
, const char *format
, va_list ap
)
855 TRACE ("%s\n", __PRETTY_FUNCTION__
);
857 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
859 return vprintf (format
, ap
);
863 WRAPPER2(int, vfprintf
, FILE *stream
, const char *format
, va_list ap
)
866 TRACE ("%s\n", __PRETTY_FUNCTION__
);
867 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
870 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
872 return vfprintf (stream
, format
, ap
);
876 WRAPPER2(int, vsprintf
, char *str
, const char *format
, va_list ap
)
880 TRACE ("%s\n", __PRETTY_FUNCTION__
);
881 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "vsprintf str");
883 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
885 result
= vsprintf (str
, format
, ap
);
887 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "vsprintf str");
892 WRAPPER2(int, vsnprintf
, char *str
, size_t size
, const char *format
,
896 TRACE ("%s\n", __PRETTY_FUNCTION__
);
897 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "vsnprintf str");
899 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
901 return vsnprintf (str
, size
, format
, ap
);
905 WRAPPER2(int , access
, const char *path
, int mode
)
908 TRACE ("%s\n", __PRETTY_FUNCTION__
);
910 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "access path");
911 return access (path
, mode
);
915 WRAPPER2(int , remove
, const char *path
)
918 TRACE ("%s\n", __PRETTY_FUNCTION__
);
920 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "remove path");
921 return remove (path
);
925 WRAPPER2(int, fflush
, FILE *stream
)
927 TRACE ("%s\n", __PRETTY_FUNCTION__
);
928 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
930 return fflush (stream
);
934 WRAPPER2(int, fseek
, FILE *stream
, long offset
, int whence
)
936 TRACE ("%s\n", __PRETTY_FUNCTION__
);
937 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
939 return fseek (stream
, offset
, whence
);
944 WRAPPER2(int, fseeko64
, FILE *stream
, off64_t offset
, int whence
)
946 TRACE ("%s\n", __PRETTY_FUNCTION__
);
947 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
949 return fseeko64 (stream
, offset
, whence
);
954 WRAPPER2(long, ftell
, FILE *stream
)
956 TRACE ("%s\n", __PRETTY_FUNCTION__
);
957 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
959 return ftell (stream
);
964 WRAPPER2(off64_t
, ftello64
, FILE *stream
)
966 TRACE ("%s\n", __PRETTY_FUNCTION__
);
967 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
969 return ftello64 (stream
);
974 WRAPPER2(void, rewind
, FILE *stream
)
976 TRACE ("%s\n", __PRETTY_FUNCTION__
);
977 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
983 WRAPPER2(int, fgetpos
, FILE *stream
, fpos_t *pos
)
985 TRACE ("%s\n", __PRETTY_FUNCTION__
);
986 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
988 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_WRITE
, "fgetpos pos");
989 return fgetpos (stream
, pos
);
993 WRAPPER2(int, fsetpos
, FILE *stream
, fpos_t *pos
)
995 TRACE ("%s\n", __PRETTY_FUNCTION__
);
996 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
998 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_READ
, "fsetpos pos");
999 return fsetpos (stream
, pos
);
1003 WRAPPER2(int , stat
, const char *path
, struct stat
*buf
)
1006 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1008 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat path");
1009 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat buf");
1010 return stat (path
, buf
);
1015 WRAPPER2(int , stat64
, const char *path
, struct stat64
*buf
)
1018 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1020 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat64 path");
1021 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat64 buf");
1022 return stat64 (path
, buf
);
1027 WRAPPER2(int , fstat
, int filedes
, struct stat
*buf
)
1029 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1030 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "fstat buf");
1031 return fstat (filedes
, buf
);
1035 WRAPPER2(int , lstat
, const char *path
, struct stat
*buf
)
1038 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1040 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "lstat path");
1041 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "lstat buf");
1042 return lstat (path
, buf
);
1046 WRAPPER2(int , mkfifo
, const char *path
, mode_t mode
)
1049 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1051 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "mkfifo path");
1052 return mkfifo (path
, mode
);
1056 WRAPPER2(int, setvbuf
, FILE *stream
, char *buf
, int mode
, size_t size
)
1058 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1059 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1062 MF_VALIDATE_EXTENT (buf
, size
, __MF_CHECK_READ
, "setvbuf buf");
1063 return setvbuf (stream
, buf
, mode
, size
);
1067 WRAPPER2(void, setbuf
, FILE *stream
, char *buf
)
1069 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1070 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1073 MF_VALIDATE_EXTENT (buf
, BUFSIZ
, __MF_CHECK_READ
, "setbuf buf");
1074 setbuf (stream
, buf
);
1078 WRAPPER2(DIR *, opendir
, const char *path
)
1082 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1084 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "opendir path");
1088 #ifdef MF_REGISTER_opendir
1089 __mf_register (p
, MF_RESULT_SIZE_opendir
, MF_REGISTER_opendir
,
1092 MF_VALIDATE_EXTENT (p
, MF_RESULT_SIZE_opendir
, __MF_CHECK_WRITE
,
1099 WRAPPER2(int, closedir
, DIR *dir
)
1101 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1102 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_WRITE
, "closedir dir");
1103 #ifdef MF_REGISTER_opendir
1104 __mf_unregister (dir
, MF_RESULT_SIZE_opendir
);
1106 return closedir (dir
);
1110 WRAPPER2(struct dirent
*, readdir
, DIR *dir
)
1113 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1114 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_READ
, "readdir dir");
1117 #ifdef MF_REGISTER_readdir
1118 __mf_register (p
, sizeof (*p
), MF_REGISTER_readdir
, "readdir result");
1120 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "readdir result");
1126 #ifdef HAVE_SYS_SOCKET_H
1128 WRAPPER2(int, recv
, int s
, void *buf
, size_t len
, int flags
)
1130 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1131 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recv buf");
1132 return recv (s
, buf
, len
, flags
);
1136 WRAPPER2(int, recvfrom
, int s
, void *buf
, size_t len
, int flags
,
1137 struct sockaddr
*from
, socklen_t
*fromlen
)
1139 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1140 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recvfrom buf");
1141 MF_VALIDATE_EXTENT (from
, (size_t)*fromlen
, __MF_CHECK_WRITE
,
1143 return recvfrom (s
, buf
, len
, flags
, from
, fromlen
);
1147 WRAPPER2(int, recvmsg
, int s
, struct msghdr
*msg
, int flags
)
1149 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1150 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_WRITE
, "recvmsg msg");
1151 return recvmsg (s
, msg
, flags
);
1155 WRAPPER2(int, send
, int s
, const void *msg
, size_t len
, int flags
)
1157 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1158 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "send msg");
1159 return send (s
, msg
, len
, flags
);
1163 WRAPPER2(int, sendto
, int s
, const void *msg
, size_t len
, int flags
,
1164 const struct sockaddr
*to
, socklen_t tolen
)
1166 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1167 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "sendto msg");
1168 MF_VALIDATE_EXTENT (to
, (size_t)tolen
, __MF_CHECK_WRITE
, "sendto to");
1169 return sendto (s
, msg
, len
, flags
, to
, tolen
);
1173 WRAPPER2(int, sendmsg
, int s
, const void *msg
, int flags
)
1175 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1176 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_READ
, "sendmsg msg");
1177 return sendmsg (s
, msg
, flags
);
1181 WRAPPER2(int, setsockopt
, int s
, int level
, int optname
, const void *optval
,
1184 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1185 MF_VALIDATE_EXTENT (optval
, (size_t)optlen
, __MF_CHECK_READ
,
1186 "setsockopt optval");
1187 return setsockopt (s
, level
, optname
, optval
, optlen
);
1191 WRAPPER2(int, getsockopt
, int s
, int level
, int optname
, void *optval
,
1194 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1195 MF_VALIDATE_EXTENT (optval
, (size_t)*optlen
, __MF_CHECK_WRITE
,
1196 "getsockopt optval");
1197 return getsockopt (s
, level
, optname
, optval
, optlen
);
1201 WRAPPER2(int, accept
, int s
, struct sockaddr
*addr
, socklen_t
*addrlen
)
1203 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1204 MF_VALIDATE_EXTENT (addr
, (size_t)*addrlen
, __MF_CHECK_WRITE
, "accept addr");
1205 return accept (s
, addr
, addrlen
);
1209 WRAPPER2(int, bind
, int sockfd
, struct sockaddr
*addr
, socklen_t addrlen
)
1211 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1212 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_WRITE
, "bind addr");
1213 return bind (sockfd
, addr
, addrlen
);
1217 WRAPPER2(int, connect
, int sockfd
, const struct sockaddr
*addr
,
1220 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1221 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_READ
,
1223 return connect (sockfd
, addr
, addrlen
);
1226 #endif /* HAVE_SYS_SOCKET_H */
1229 WRAPPER2(int, gethostname
, char *name
, size_t len
)
1231 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1232 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_WRITE
, "gethostname name");
1233 return gethostname (name
, len
);
1237 #ifdef HAVE_SETHOSTNAME
1238 WRAPPER2(int, sethostname
, const char *name
, size_t len
)
1240 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1241 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_READ
, "sethostname name");
1242 return sethostname (name
, len
);
1249 WRAPPER2(struct hostent
*, gethostbyname
, const char *name
)
1256 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1258 MF_VALIDATE_EXTENT (name
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1259 "gethostbyname name");
1260 p
= gethostbyname (name
);
1262 #ifdef MF_REGISTER_gethostbyname
1263 __mf_register (p
, sizeof (*p
), MF_REGISTER_gethostbyname
,
1264 "gethostbyname result");
1266 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
,
1267 "gethostbyname result");
1268 if (NULL
!= (s
= p
->h_name
)) {
1271 #ifdef MF_REGISTER_gethostbyname_items
1272 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1273 "gethostbyname result->h_name");
1275 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1276 "gethostbyname result->h_name");
1279 if (NULL
!= (ss
= p
->h_aliases
)) {
1280 for (nreg
= 1;; ++nreg
) {
1286 #ifdef MF_REGISTER_gethostbyname_items
1287 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1288 "gethostbyname result->h_aliases[]");
1290 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1291 "gethostbyname result->h_aliases[]");
1293 nreg
*= sizeof (*p
->h_aliases
);
1294 #ifdef MF_REGISTER_gethostbyname_items
1295 __mf_register (p
->h_aliases
, nreg
, MF_REGISTER_gethostbyname_items
,
1296 "gethostbyname result->h_aliases");
1298 MF_VALIDATE_EXTENT (p
->h_aliases
, nreg
, __MF_CHECK_WRITE
,
1299 "gethostbyname result->h_aliases");
1302 if (NULL
!= (ss
= p
->h_addr_list
)) {
1303 for (nreg
= 1;; ++nreg
) {
1307 #ifdef MF_REGISTER_gethostbyname_items
1308 __mf_register (s
, p
->h_length
, MF_REGISTER_gethostbyname_items
,
1309 "gethostbyname result->h_addr_list[]");
1311 MF_VALIDATE_EXTENT (s
, p
->h_length
, __MF_CHECK_WRITE
,
1312 "gethostbyname result->h_addr_list[]");
1314 nreg
*= sizeof (*p
->h_addr_list
);
1315 #ifdef MF_REGISTER_gethostbyname_items
1316 __mf_register (p
->h_addr_list
, nreg
, MF_REGISTER_gethostbyname_items
,
1317 "gethostbyname result->h_addr_list");
1319 MF_VALIDATE_EXTENT (p
->h_addr_list
, nreg
, __MF_CHECK_WRITE
,
1320 "gethostbyname result->h_addr_list");
1326 #endif /* HAVE_NETDB_H */
1329 #ifdef HAVE_SYS_WAIT_H
1331 WRAPPER2(pid_t
, wait
, int *status
)
1333 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1335 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1337 return wait (status
);
1341 WRAPPER2(pid_t
, waitpid
, pid_t pid
, int *status
, int options
)
1343 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1345 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1347 return waitpid (pid
, status
, options
);
1350 #endif /* HAVE_SYS_WAIT_H */
1353 WRAPPER2(FILE *, popen
, const char *command
, const char *mode
)
1357 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1359 n
= strlen (command
);
1360 MF_VALIDATE_EXTENT (command
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen path");
1363 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen mode");
1365 p
= popen (command
, mode
);
1367 #ifdef MF_REGISTER_fopen
1368 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "popen result");
1370 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "popen result");
1376 WRAPPER2(int, pclose
, FILE *stream
)
1379 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1380 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1382 resp
= pclose (stream
);
1383 #ifdef MF_REGISTER_fopen
1384 __mf_unregister (stream
, sizeof (*stream
));
1390 WRAPPER2(int, execve
, const char *path
, char *const argv
[],
1396 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1399 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve path");
1402 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *argv");
1407 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **argv");
1411 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *envp");
1416 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **envp");
1418 return execve (path
, argv
, envp
);
1422 WRAPPER2(int, execv
, const char *path
, char *const argv
[])
1427 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1430 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv path");
1433 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execv *argv");
1438 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv **argv");
1440 return execv (path
, argv
);
1444 WRAPPER2(int, execvp
, const char *path
, char *const argv
[])
1449 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1452 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp path");
1455 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execvp *argv");
1460 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp **argv");
1462 return execvp (path
, argv
);
1466 WRAPPER2(int, system
, const char *string
)
1469 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1470 n
= strlen (string
);
1471 MF_VALIDATE_EXTENT (string
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1473 return system (string
);
1477 WRAPPER2(void *, dlopen
, const char *path
, int flags
)
1481 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1483 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlopen path");
1484 p
= dlopen (path
, flags
);
1486 #ifdef MF_REGISTER_dlopen
1487 __mf_register (p
, 0, MF_REGISTER_dlopen
, "dlopen result");
1489 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlopen result");
1495 WRAPPER2(int, dlclose
, void *handle
)
1498 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1499 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlclose handle");
1500 resp
= dlclose (handle
);
1501 #ifdef MF_REGISTER_dlopen
1502 __mf_unregister (handle
, 0);
1508 WRAPPER2(char *, dlerror
)
1511 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1517 #ifdef MF_REGISTER_dlerror
1518 __mf_register (p
, n
, MF_REGISTER_dlerror
, "dlerror result");
1520 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "dlerror result");
1526 WRAPPER2(void *, dlsym
, void *handle
, char *symbol
)
1530 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1531 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlsym handle");
1532 n
= strlen (symbol
);
1533 MF_VALIDATE_EXTENT (symbol
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlsym symbol");
1534 p
= dlsym (handle
, symbol
);
1536 #ifdef MF_REGISTER_dlsym
1537 __mf_register (p
, 0, MF_REGISTER_dlsym
, "dlsym result");
1539 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlsym result");
1545 #if defined (HAVE_SYS_IPC_H) && defined (HAVE_SYS_SEM_H) && defined (HAVE_SYS_SHM_H)
1547 WRAPPER2(int, semop
, int semid
, struct sembuf
*sops
, unsigned nsops
)
1549 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1550 MF_VALIDATE_EXTENT (sops
, sizeof (*sops
) * nsops
, __MF_CHECK_READ
,
1552 return semop (semid
, sops
, nsops
);
1556 #ifndef HAVE_UNION_SEMUN
1558 int val
; /* value for SETVAL */
1559 struct semid_ds
*buf
; /* buffer for IPC_STAT, IPC_SET */
1560 unsigned short int *array
; /* array for GETALL, SETALL */
1561 struct seminfo
*__buf
; /* buffer for IPC_INFO */
1564 WRAPPER2(int, semctl
, int semid
, int semnum
, int cmd
, union semun arg
)
1566 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1569 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_WRITE
,
1573 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_READ
,
1577 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_WRITE
,
1580 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_READ
,
1584 /* FreeBSD 5.1 And Cygwin headers include IPC_INFO but not the __buf field. */
1585 #if !defined(__FreeBSD__) && !defined(__CYGWIN__)
1587 MF_VALIDATE_EXTENT (arg
.__buf
, sizeof (*arg
.__buf
), __MF_CHECK_WRITE
,
1595 return semctl (semid
, semnum
, cmd
, arg
);
1599 WRAPPER2(int, shmctl
, int shmid
, int cmd
, struct shmid_ds
*buf
)
1601 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1604 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_WRITE
,
1608 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
,
1614 return shmctl (shmid
, cmd
, buf
);
1618 WRAPPER2(void *, shmat
, int shmid
, const void *shmaddr
, int shmflg
)
1621 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1622 p
= shmat (shmid
, shmaddr
, shmflg
);
1623 #ifdef MF_REGISTER_shmat
1625 struct shmid_ds buf
;
1626 __mf_register (p
, shmctl (shmid
, IPC_STAT
, &buf
) ? 0 : buf
.shm_segsz
,
1627 MF_REGISTER_shmat
, "shmat result");
1634 WRAPPER2(int, shmdt
, const void *shmaddr
)
1637 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1638 resp
= shmdt (shmaddr
);
1639 #ifdef MF_REGISTER_shmat
1640 __mf_unregister ((void *)shmaddr
, 0);
1646 #endif /* HAVE_SYS_IPC/SEM/SHM_H */
1650 /* ctype stuff. This is host-specific by necessity, as the arrays
1651 that is used by most is*()/to*() macros are implementation-defined. */
1654 #ifdef HAVE___CTYPE_B_LOC
1655 WRAPPER2(unsigned short **, __ctype_b_loc
, void)
1657 static unsigned short * last_buf
= (void *) 0;
1658 static unsigned short ** last_ptr
= (void *) 0;
1659 unsigned short ** ptr
= (unsigned short **) __ctype_b_loc ();
1660 unsigned short * buf
= * ptr
;
1661 if (ptr
!= last_ptr
)
1663 /* XXX: unregister last_ptr? */
1665 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_b_loc **");
1667 if (buf
!= last_buf
)
1670 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(unsigned short), __MF_TYPE_STATIC
,
1677 #ifdef HAVE___CTYPE_TOUPPER_LOC
1678 WRAPPER2(int **, __ctype_toupper_loc
, void)
1680 static int * last_buf
= (void *) 0;
1681 static int ** last_ptr
= (void *) 0;
1682 int ** ptr
= (int **) __ctype_toupper_loc ();
1684 if (ptr
!= last_ptr
)
1686 /* XXX: unregister last_ptr? */
1688 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_toupper_loc **");
1690 if (buf
!= last_buf
)
1693 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(int), __MF_TYPE_STATIC
,
1694 "ctype_toupper_loc []");
1700 #ifdef HAVE___CTYPE_TOLOWER_LOC
1701 WRAPPER2(int **, __ctype_tolower_loc
, void)
1703 static int * last_buf
= (void *) 0;
1704 static int ** last_ptr
= (void *) 0;
1705 int ** ptr
= (int **) __ctype_tolower_loc ();
1707 if (ptr
!= last_ptr
)
1709 /* XXX: unregister last_ptr? */
1711 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_tolower_loc **");
1713 if (buf
!= last_buf
)
1716 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(int), __MF_TYPE_STATIC
,
1717 "ctype_tolower_loc []");