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
59 #include <sys/types.h>
69 #ifdef HAVE_SYS_SOCKET_H
70 #include <sys/socket.h>
75 #ifdef HAVE_SYS_WAIT_H
89 #include "mf-runtime.h"
93 #error "Do not compile this file with -fmudflap!"
97 /* A bunch of independent stdlib/unistd hook functions, all
98 intercepted by mf-runtime.h macros. */
101 static inline size_t (strnlen
) (const char* str
, size_t n
)
105 for (s
= str
; n
&& *s
; ++s
, --n
)
114 WRAPPER2(void *, memcpy
, void *dest
, const void *src
, size_t n
)
116 TRACE ("%s\n", __PRETTY_FUNCTION__
);
117 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memcpy source");
118 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memcpy dest");
119 return memcpy (dest
, src
, n
);
123 WRAPPER2(void *, memmove
, void *dest
, const void *src
, size_t n
)
125 TRACE ("%s\n", __PRETTY_FUNCTION__
);
126 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "memmove src");
127 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "memmove dest");
128 return memmove (dest
, src
, n
);
132 WRAPPER2(void *, memset
, void *s
, int c
, size_t n
)
134 TRACE ("%s\n", __PRETTY_FUNCTION__
);
135 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "memset dest");
136 return memset (s
, c
, n
);
140 WRAPPER2(int, memcmp
, const void *s1
, const void *s2
, size_t n
)
142 TRACE ("%s\n", __PRETTY_FUNCTION__
);
143 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "memcmp 1st arg");
144 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "memcmp 2nd arg");
145 return memcmp (s1
, s2
, n
);
149 WRAPPER2(void *, memchr
, const void *s
, int c
, size_t n
)
151 TRACE ("%s\n", __PRETTY_FUNCTION__
);
152 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memchr region");
153 return memchr (s
, c
, n
);
158 WRAPPER2(void *, memrchr
, const void *s
, int c
, size_t n
)
160 TRACE ("%s\n", __PRETTY_FUNCTION__
);
161 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_READ
, "memrchr region");
162 return memrchr (s
, c
, n
);
167 WRAPPER2(char *, strcpy
, char *dest
, const char *src
)
169 /* nb: just because strlen(src) == n doesn't mean (src + n) or (src + n +
170 1) are valid pointers. the allocated object might have size < n.
173 size_t n
= strlen (src
);
174 TRACE ("%s\n", __PRETTY_FUNCTION__
);
175 MF_VALIDATE_EXTENT(src
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "strcpy src");
176 MF_VALIDATE_EXTENT(dest
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "strcpy dest");
177 return strcpy (dest
, src
);
182 WRAPPER2(char *, strncpy
, char *dest
, const char *src
, size_t n
)
184 size_t len
= strnlen (src
, n
);
185 TRACE ("%s\n", __PRETTY_FUNCTION__
);
186 MF_VALIDATE_EXTENT(src
, len
, __MF_CHECK_READ
, "strncpy src");
187 MF_VALIDATE_EXTENT(dest
, len
, __MF_CHECK_WRITE
, "strncpy dest"); /* nb: strNcpy */
188 return strncpy (dest
, src
, n
);
193 WRAPPER2(char *, strcat
, char *dest
, const char *src
)
197 TRACE ("%s\n", __PRETTY_FUNCTION__
);
198 dest_sz
= strlen (dest
);
199 src_sz
= strlen (src
);
200 MF_VALIDATE_EXTENT(src
, CLAMPADD(src_sz
, 1), __MF_CHECK_READ
, "strcat src");
201 MF_VALIDATE_EXTENT(dest
, CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1)),
202 __MF_CHECK_WRITE
, "strcat dest");
203 return strcat (dest
, src
);
207 WRAPPER2(char *, strncat
, char *dest
, const char *src
, size_t n
)
210 /* nb: validating the extents (s,n) might be a mistake for two reasons.
212 (1) the string s might be shorter than n chars, and n is just a
213 poor choice by the programmer. this is not a "true" error in the
214 sense that the call to strncat would still be ok.
216 (2) we could try to compensate for case (1) by calling strlen(s) and
217 using that as a bound for the extent to verify, but strlen might fall off
218 the end of a non-terminated string, leading to a false positive.
220 so we will call strnlen(s,n) and use that as a bound.
222 if strnlen returns a length beyond the end of the registered extent
223 associated with s, there is an error: the programmer's estimate for n is
224 too large _AND_ the string s is unterminated, in which case they'd be
225 about to touch memory they don't own while calling strncat.
227 this same logic applies to further uses of strnlen later down in this
232 TRACE ("%s\n", __PRETTY_FUNCTION__
);
233 src_sz
= strnlen (src
, n
);
234 dest_sz
= strnlen (dest
, n
);
235 MF_VALIDATE_EXTENT(src
, src_sz
, __MF_CHECK_READ
, "strncat src");
236 MF_VALIDATE_EXTENT(dest
, (CLAMPADD(dest_sz
, CLAMPADD(src_sz
, 1))),
237 __MF_CHECK_WRITE
, "strncat dest");
238 return strncat (dest
, src
, n
);
242 WRAPPER2(int, strcmp
, const char *s1
, const char *s2
)
246 TRACE ("%s\n", __PRETTY_FUNCTION__
);
249 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcmp 1st arg");
250 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_WRITE
, "strcmp 2nd arg");
251 return strcmp (s1
, s2
);
255 WRAPPER2(int, strcasecmp
, const char *s1
, const char *s2
)
259 TRACE ("%s\n", __PRETTY_FUNCTION__
);
262 MF_VALIDATE_EXTENT(s1
, CLAMPADD(s1_sz
, 1), __MF_CHECK_READ
, "strcasecmp 1st arg");
263 MF_VALIDATE_EXTENT(s2
, CLAMPADD(s2_sz
, 1), __MF_CHECK_READ
, "strcasecmp 2nd arg");
264 return strcasecmp (s1
, s2
);
268 WRAPPER2(int, strncmp
, const char *s1
, const char *s2
, size_t n
)
272 TRACE ("%s\n", __PRETTY_FUNCTION__
);
273 s1_sz
= strnlen (s1
, n
);
274 s2_sz
= strnlen (s2
, n
);
275 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncmp 1st arg");
276 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncmp 2nd arg");
277 return strncmp (s1
, s2
, n
);
281 WRAPPER2(int, strncasecmp
, const char *s1
, const char *s2
, size_t n
)
285 TRACE ("%s\n", __PRETTY_FUNCTION__
);
286 s1_sz
= strnlen (s1
, n
);
287 s2_sz
= strnlen (s2
, n
);
288 MF_VALIDATE_EXTENT(s1
, s1_sz
, __MF_CHECK_READ
, "strncasecmp 1st arg");
289 MF_VALIDATE_EXTENT(s2
, s2_sz
, __MF_CHECK_READ
, "strncasecmp 2nd arg");
290 return strncasecmp (s1
, s2
, n
);
294 WRAPPER2(char *, strdup
, const char *s
)
296 DECLARE(void *, malloc
, size_t sz
);
298 size_t n
= strlen (s
);
299 TRACE ("%s\n", __PRETTY_FUNCTION__
);
300 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strdup region");
301 result
= (char *)CALL_REAL(malloc
,
302 CLAMPADD(CLAMPADD(n
,1),
303 CLAMPADD(__mf_opts
.crumple_zone
,
304 __mf_opts
.crumple_zone
)));
306 if (UNLIKELY(! result
)) return result
;
308 result
+= __mf_opts
.crumple_zone
;
309 memcpy (result
, s
, n
);
312 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strdup region");
317 WRAPPER2(char *, strndup
, const char *s
, size_t n
)
319 DECLARE(void *, malloc
, size_t sz
);
321 size_t sz
= strnlen (s
, n
);
322 TRACE ("%s\n", __PRETTY_FUNCTION__
);
323 MF_VALIDATE_EXTENT(s
, sz
, __MF_CHECK_READ
, "strndup region"); /* nb: strNdup */
325 /* note: strndup still adds a \0, even with the N limit! */
326 result
= (char *)CALL_REAL(malloc
,
327 CLAMPADD(CLAMPADD(n
,1),
328 CLAMPADD(__mf_opts
.crumple_zone
,
329 __mf_opts
.crumple_zone
)));
331 if (UNLIKELY(! result
)) return result
;
333 result
+= __mf_opts
.crumple_zone
;
334 memcpy (result
, s
, n
);
337 __mf_register (result
, CLAMPADD(n
,1), __MF_TYPE_HEAP_I
, "strndup region");
342 WRAPPER2(char *, strchr
, const char *s
, int c
)
345 TRACE ("%s\n", __PRETTY_FUNCTION__
);
347 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strchr region");
348 return strchr (s
, c
);
352 WRAPPER2(char *, strrchr
, const char *s
, int c
)
355 TRACE ("%s\n", __PRETTY_FUNCTION__
);
357 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
,1), __MF_CHECK_READ
, "strrchr region");
358 return strrchr (s
, c
);
362 WRAPPER2(char *, strstr
, const char *haystack
, const char *needle
)
366 TRACE ("%s\n", __PRETTY_FUNCTION__
);
367 haystack_sz
= strlen (haystack
);
368 needle_sz
= strlen (needle
);
369 MF_VALIDATE_EXTENT(haystack
, CLAMPADD(haystack_sz
, 1), __MF_CHECK_READ
, "strstr haystack");
370 MF_VALIDATE_EXTENT(needle
, CLAMPADD(needle_sz
, 1), __MF_CHECK_READ
, "strstr needle");
371 return strstr (haystack
, needle
);
376 WRAPPER2(void *, memmem
,
377 const void *haystack
, size_t haystacklen
,
378 const void *needle
, size_t needlelen
)
380 TRACE ("%s\n", __PRETTY_FUNCTION__
);
381 MF_VALIDATE_EXTENT(haystack
, haystacklen
, __MF_CHECK_READ
, "memmem haystack");
382 MF_VALIDATE_EXTENT(needle
, needlelen
, __MF_CHECK_READ
, "memmem needle");
383 return memmem (haystack
, haystacklen
, needle
, needlelen
);
388 WRAPPER2(size_t, strlen
, const char *s
)
390 size_t result
= strlen (s
);
391 TRACE ("%s\n", __PRETTY_FUNCTION__
);
392 MF_VALIDATE_EXTENT(s
, CLAMPADD(result
, 1), __MF_CHECK_READ
, "strlen region");
397 WRAPPER2(size_t, strnlen
, const char *s
, size_t n
)
399 size_t result
= strnlen (s
, n
);
400 TRACE ("%s\n", __PRETTY_FUNCTION__
);
401 MF_VALIDATE_EXTENT(s
, result
, __MF_CHECK_READ
, "strnlen region");
406 WRAPPER2(void, bzero
, void *s
, size_t n
)
408 TRACE ("%s\n", __PRETTY_FUNCTION__
);
409 MF_VALIDATE_EXTENT(s
, n
, __MF_CHECK_WRITE
, "bzero region");
415 WRAPPER2(void, bcopy
, const void *src
, void *dest
, size_t n
)
417 TRACE ("%s\n", __PRETTY_FUNCTION__
);
418 MF_VALIDATE_EXTENT(src
, n
, __MF_CHECK_READ
, "bcopy src");
419 MF_VALIDATE_EXTENT(dest
, n
, __MF_CHECK_WRITE
, "bcopy dest");
420 bcopy (src
, dest
, n
);
425 WRAPPER2(int, bcmp
, const void *s1
, const void *s2
, size_t n
)
427 TRACE ("%s\n", __PRETTY_FUNCTION__
);
428 MF_VALIDATE_EXTENT(s1
, n
, __MF_CHECK_READ
, "bcmp 1st arg");
429 MF_VALIDATE_EXTENT(s2
, n
, __MF_CHECK_READ
, "bcmp 2nd arg");
430 return bcmp (s1
, s2
, n
);
434 WRAPPER2(char *, index
, const char *s
, int c
)
436 size_t n
= strlen (s
);
437 TRACE ("%s\n", __PRETTY_FUNCTION__
);
438 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "index region");
443 WRAPPER2(char *, rindex
, const char *s
, int c
)
445 size_t n
= strlen (s
);
446 TRACE ("%s\n", __PRETTY_FUNCTION__
);
447 MF_VALIDATE_EXTENT(s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "rindex region");
448 return rindex (s
, c
);
451 /* XXX: stpcpy, memccpy */
453 /* XXX: *printf,*scanf */
455 /* XXX: setjmp, longjmp */
457 WRAPPER2(char *, asctime
, struct tm
*tm
)
459 static char *reg_result
= NULL
;
461 TRACE ("%s\n", __PRETTY_FUNCTION__
);
462 MF_VALIDATE_EXTENT(tm
, sizeof (struct tm
), __MF_CHECK_READ
, "asctime tm");
463 result
= asctime (tm
);
464 if (reg_result
== NULL
)
466 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "asctime string");
473 WRAPPER2(char *, ctime
, const time_t *timep
)
475 static char *reg_result
= NULL
;
477 TRACE ("%s\n", __PRETTY_FUNCTION__
);
478 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "ctime time");
479 result
= ctime (timep
);
480 if (reg_result
== NULL
)
482 /* XXX: what if asctime and ctime return the same static ptr? */
483 __mf_register (result
, strlen (result
)+1, __MF_TYPE_STATIC
, "ctime string");
490 WRAPPER2(struct tm
*, localtime
, const time_t *timep
)
492 static struct tm
*reg_result
= NULL
;
494 TRACE ("%s\n", __PRETTY_FUNCTION__
);
495 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "localtime time");
496 result
= localtime (timep
);
497 if (reg_result
== NULL
)
499 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "localtime tm");
506 WRAPPER2(struct tm
*, gmtime
, const time_t *timep
)
508 static struct tm
*reg_result
= NULL
;
510 TRACE ("%s\n", __PRETTY_FUNCTION__
);
511 MF_VALIDATE_EXTENT(timep
, sizeof (time_t), __MF_CHECK_READ
, "gmtime time");
512 result
= gmtime (timep
);
513 if (reg_result
== NULL
)
515 __mf_register (result
, sizeof (struct tm
), __MF_TYPE_STATIC
, "gmtime tm");
524 /* The following indicate if the result of the corresponding function
525 * should be explicitly un/registered by the wrapper
527 #define MF_REGISTER_strerror __MF_TYPE_STATIC
528 #undef MF_REGISTER_fopen
529 #define MF_RESULT_SIZE_fopen (sizeof (FILE))
530 #undef MF_REGISTER_opendir
531 #define MF_RESULT_SIZE_opendir 0 /* (sizeof (DIR)) */
532 #undef MF_REGISTER_readdir
533 #define MF_REGISTER_gethostbyname __MF_TYPE_STATIC
534 #undef MF_REGISTER_gethostbyname_items
535 #undef MF_REGISTER_dlopen
536 #undef MF_REGISTER_dlerror
537 #undef MF_REGISTER_dlsym
538 #define MF_REGISTER_shmat __MF_TYPE_GUESS
542 WRAPPER2(time_t, time
, time_t *timep
)
544 TRACE ("%s\n", __PRETTY_FUNCTION__
);
546 MF_VALIDATE_EXTENT (timep
, sizeof (*timep
), __MF_CHECK_WRITE
,
552 WRAPPER2(char *, strerror
, int errnum
)
556 TRACE ("%s\n", __PRETTY_FUNCTION__
);
557 p
= strerror (errnum
);
561 #ifdef MF_REGISTER_strerror
562 __mf_register (p
, n
, MF_REGISTER_strerror
, "strerror result");
564 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "strerror result");
570 WRAPPER2(FILE *, fopen
, const char *path
, const char *mode
)
574 TRACE ("%s\n", __PRETTY_FUNCTION__
);
577 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen path");
580 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen mode");
582 p
= fopen (path
, mode
);
584 #ifdef MF_REGISTER_fopen
585 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen result");
587 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen result");
595 WRAPPER2(FILE *, fopen64
, const char *path
, const char *mode
)
599 TRACE ("%s\n", __PRETTY_FUNCTION__
);
602 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 path");
605 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fopen64 mode");
607 p
= fopen64 (path
, mode
);
609 #ifdef MF_REGISTER_fopen
610 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "fopen64 result");
612 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "fopen64 result");
620 WRAPPER2(int, fclose
, FILE *stream
)
623 TRACE ("%s\n", __PRETTY_FUNCTION__
);
624 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
626 resp
= fclose (stream
);
627 #ifdef MF_REGISTER_fopen
628 __mf_unregister (stream
, sizeof (*stream
), MF_REGISTER_fopen
);
635 WRAPPER2(size_t, fread
, void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
637 TRACE ("%s\n", __PRETTY_FUNCTION__
);
638 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
640 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_WRITE
, "fread buffer");
641 return fread (ptr
, size
, nmemb
, stream
);
645 WRAPPER2(size_t, fwrite
, const void *ptr
, size_t size
, size_t nmemb
,
648 TRACE ("%s\n", __PRETTY_FUNCTION__
);
649 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
651 MF_VALIDATE_EXTENT (ptr
, size
* nmemb
, __MF_CHECK_READ
, "fwrite buffer");
652 return fwrite (ptr
, size
, nmemb
, stream
);
656 WRAPPER2(int, fgetc
, FILE *stream
)
658 TRACE ("%s\n", __PRETTY_FUNCTION__
);
659 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
661 return fgetc (stream
);
665 WRAPPER2(char *, fgets
, char *s
, int size
, FILE *stream
)
667 TRACE ("%s\n", __PRETTY_FUNCTION__
);
668 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
670 MF_VALIDATE_EXTENT (s
, size
, __MF_CHECK_WRITE
, "fgets buffer");
671 return fgets (s
, size
, stream
);
675 WRAPPER2(int, getc
, FILE *stream
)
677 TRACE ("%s\n", __PRETTY_FUNCTION__
);
678 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
680 return getc (stream
);
684 WRAPPER2(char *, gets
, char *s
)
686 TRACE ("%s\n", __PRETTY_FUNCTION__
);
687 MF_VALIDATE_EXTENT (s
, 1, __MF_CHECK_WRITE
, "gets buffer");
688 /* Avoid link-time warning... */
689 s
= fgets (s
, INT_MAX
, stdin
);
690 if (NULL
!= s
) { /* better late than never */
691 size_t n
= strlen (s
);
692 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "gets buffer");
698 WRAPPER2(int, ungetc
, int c
, FILE *stream
)
700 TRACE ("%s\n", __PRETTY_FUNCTION__
);
701 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
703 return ungetc (c
, stream
);
707 WRAPPER2(int, fputc
, int c
, FILE *stream
)
709 TRACE ("%s\n", __PRETTY_FUNCTION__
);
710 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
712 return fputc (c
, stream
);
716 WRAPPER2(int, fputs
, const char *s
, FILE *stream
)
719 TRACE ("%s\n", __PRETTY_FUNCTION__
);
721 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "fputs buffer");
722 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
724 return fputs (s
, stream
);
728 WRAPPER2(int, putc
, int c
, FILE *stream
)
730 TRACE ("%s\n", __PRETTY_FUNCTION__
);
731 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
733 return putc (c
, stream
);
737 WRAPPER2(int, puts
, const char *s
)
740 TRACE ("%s\n", __PRETTY_FUNCTION__
);
742 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "puts buffer");
747 WRAPPER2(void, clearerr
, FILE *stream
)
749 TRACE ("%s\n", __PRETTY_FUNCTION__
);
750 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
756 WRAPPER2(int, feof
, FILE *stream
)
758 TRACE ("%s\n", __PRETTY_FUNCTION__
);
759 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
761 return feof (stream
);
765 WRAPPER2(int, ferror
, FILE *stream
)
767 TRACE ("%s\n", __PRETTY_FUNCTION__
);
768 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
770 return ferror (stream
);
774 WRAPPER2(int, fileno
, FILE *stream
)
776 TRACE ("%s\n", __PRETTY_FUNCTION__
);
777 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
779 return fileno (stream
);
783 WRAPPER2(int, printf
, const char *format
, ...)
788 TRACE ("%s\n", __PRETTY_FUNCTION__
);
790 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
792 va_start (ap
, format
);
793 result
= vprintf (format
, ap
);
799 WRAPPER2(int, fprintf
, FILE *stream
, const char *format
, ...)
804 TRACE ("%s\n", __PRETTY_FUNCTION__
);
805 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
808 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
810 va_start (ap
, format
);
811 result
= vfprintf (stream
, format
, ap
);
817 WRAPPER2(int, sprintf
, char *str
, const char *format
, ...)
822 TRACE ("%s\n", __PRETTY_FUNCTION__
);
823 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "sprintf str");
825 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
827 va_start (ap
, format
);
828 result
= vsprintf (str
, format
, ap
);
831 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "sprintf str");
836 WRAPPER2(int, snprintf
, char *str
, size_t size
, const char *format
, ...)
841 TRACE ("%s\n", __PRETTY_FUNCTION__
);
842 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "snprintf str");
844 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
846 va_start (ap
, format
);
847 result
= vsnprintf (str
, size
, format
, ap
);
853 WRAPPER2(int, vprintf
, const char *format
, va_list ap
)
856 TRACE ("%s\n", __PRETTY_FUNCTION__
);
858 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
860 return vprintf (format
, ap
);
864 WRAPPER2(int, vfprintf
, FILE *stream
, const char *format
, va_list ap
)
867 TRACE ("%s\n", __PRETTY_FUNCTION__
);
868 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
871 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
873 return vfprintf (stream
, format
, ap
);
877 WRAPPER2(int, vsprintf
, char *str
, const char *format
, va_list ap
)
881 TRACE ("%s\n", __PRETTY_FUNCTION__
);
882 MF_VALIDATE_EXTENT (str
, 1, __MF_CHECK_WRITE
, "vsprintf str");
884 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
886 result
= vsprintf (str
, format
, ap
);
888 MF_VALIDATE_EXTENT (str
, CLAMPADD(n
, 1), __MF_CHECK_WRITE
, "vsprintf str");
893 WRAPPER2(int, vsnprintf
, char *str
, size_t size
, const char *format
,
897 TRACE ("%s\n", __PRETTY_FUNCTION__
);
898 MF_VALIDATE_EXTENT (str
, size
, __MF_CHECK_WRITE
, "vsnprintf str");
900 MF_VALIDATE_EXTENT (format
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
902 return vsnprintf (str
, size
, format
, ap
);
906 WRAPPER2(int , access
, const char *path
, int mode
)
909 TRACE ("%s\n", __PRETTY_FUNCTION__
);
911 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "access path");
912 return access (path
, mode
);
916 WRAPPER2(int , remove
, const char *path
)
919 TRACE ("%s\n", __PRETTY_FUNCTION__
);
921 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "remove path");
922 return remove (path
);
926 WRAPPER2(int, fflush
, FILE *stream
)
928 TRACE ("%s\n", __PRETTY_FUNCTION__
);
929 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
931 return fflush (stream
);
935 WRAPPER2(int, fseek
, FILE *stream
, long offset
, int whence
)
937 TRACE ("%s\n", __PRETTY_FUNCTION__
);
938 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
940 return fseek (stream
, offset
, whence
);
945 WRAPPER2(int, fseeko64
, FILE *stream
, off64_t offset
, int whence
)
947 TRACE ("%s\n", __PRETTY_FUNCTION__
);
948 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
950 return fseeko64 (stream
, offset
, whence
);
955 WRAPPER2(long, ftell
, FILE *stream
)
957 TRACE ("%s\n", __PRETTY_FUNCTION__
);
958 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
960 return ftell (stream
);
965 WRAPPER2(off64_t
, ftello64
, FILE *stream
)
967 TRACE ("%s\n", __PRETTY_FUNCTION__
);
968 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
970 return ftello64 (stream
);
975 WRAPPER2(void, rewind
, FILE *stream
)
977 TRACE ("%s\n", __PRETTY_FUNCTION__
);
978 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
984 WRAPPER2(int, fgetpos
, FILE *stream
, fpos_t *pos
)
986 TRACE ("%s\n", __PRETTY_FUNCTION__
);
987 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
989 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_WRITE
, "fgetpos pos");
990 return fgetpos (stream
, pos
);
994 WRAPPER2(int, fsetpos
, FILE *stream
, fpos_t *pos
)
996 TRACE ("%s\n", __PRETTY_FUNCTION__
);
997 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
999 MF_VALIDATE_EXTENT (pos
, sizeof (*pos
), __MF_CHECK_READ
, "fsetpos pos");
1000 return fsetpos (stream
, pos
);
1004 WRAPPER2(int , stat
, const char *path
, struct stat
*buf
)
1007 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1009 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat path");
1010 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat buf");
1011 return stat (path
, buf
);
1016 WRAPPER2(int , stat64
, const char *path
, struct stat64
*buf
)
1019 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1021 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "stat64 path");
1022 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "stat64 buf");
1023 return stat64 (path
, buf
);
1028 WRAPPER2(int , fstat
, int filedes
, struct stat
*buf
)
1030 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1031 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "fstat buf");
1032 return fstat (filedes
, buf
);
1036 WRAPPER2(int , lstat
, const char *path
, struct stat
*buf
)
1039 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1041 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "lstat path");
1042 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
, "lstat buf");
1043 return lstat (path
, buf
);
1047 WRAPPER2(int , mkfifo
, const char *path
, mode_t mode
)
1050 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1052 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "mkfifo path");
1053 return mkfifo (path
, mode
);
1057 WRAPPER2(int, setvbuf
, FILE *stream
, char *buf
, int mode
, size_t size
)
1059 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1060 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1063 MF_VALIDATE_EXTENT (buf
, size
, __MF_CHECK_READ
, "setvbuf buf");
1064 return setvbuf (stream
, buf
, mode
, size
);
1068 WRAPPER2(void, setbuf
, FILE *stream
, char *buf
)
1070 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1071 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1074 MF_VALIDATE_EXTENT (buf
, BUFSIZ
, __MF_CHECK_READ
, "setbuf buf");
1075 setbuf (stream
, buf
);
1079 #ifdef HAVE_DIRENT_H
1080 WRAPPER2(DIR *, opendir
, const char *path
)
1084 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1086 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "opendir path");
1090 #ifdef MF_REGISTER_opendir
1091 __mf_register (p
, MF_RESULT_SIZE_opendir
, MF_REGISTER_opendir
,
1094 MF_VALIDATE_EXTENT (p
, MF_RESULT_SIZE_opendir
, __MF_CHECK_WRITE
,
1101 WRAPPER2(int, closedir
, DIR *dir
)
1103 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1104 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_WRITE
, "closedir dir");
1105 #ifdef MF_REGISTER_opendir
1106 __mf_unregister (dir
, MF_RESULT_SIZE_opendir
, MF_REGISTER_opendir
);
1108 return closedir (dir
);
1112 WRAPPER2(struct dirent
*, readdir
, DIR *dir
)
1115 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1116 MF_VALIDATE_EXTENT (dir
, 0, __MF_CHECK_READ
, "readdir dir");
1119 #ifdef MF_REGISTER_readdir
1120 __mf_register (p
, sizeof (*p
), MF_REGISTER_readdir
, "readdir result");
1122 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "readdir result");
1129 #ifdef HAVE_SYS_SOCKET_H
1131 WRAPPER2(int, recv
, int s
, void *buf
, size_t len
, int flags
)
1133 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1134 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recv buf");
1135 return recv (s
, buf
, len
, flags
);
1139 WRAPPER2(int, recvfrom
, int s
, void *buf
, size_t len
, int flags
,
1140 struct sockaddr
*from
, socklen_t
*fromlen
)
1142 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1143 MF_VALIDATE_EXTENT (buf
, len
, __MF_CHECK_WRITE
, "recvfrom buf");
1144 MF_VALIDATE_EXTENT (from
, (size_t)*fromlen
, __MF_CHECK_WRITE
,
1146 return recvfrom (s
, buf
, len
, flags
, from
, fromlen
);
1150 WRAPPER2(int, recvmsg
, int s
, struct msghdr
*msg
, int flags
)
1152 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1153 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_WRITE
, "recvmsg msg");
1154 return recvmsg (s
, msg
, flags
);
1158 WRAPPER2(int, send
, int s
, const void *msg
, size_t len
, int flags
)
1160 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1161 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "send msg");
1162 return send (s
, msg
, len
, flags
);
1166 WRAPPER2(int, sendto
, int s
, const void *msg
, size_t len
, int flags
,
1167 const struct sockaddr
*to
, socklen_t tolen
)
1169 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1170 MF_VALIDATE_EXTENT (msg
, len
, __MF_CHECK_READ
, "sendto msg");
1171 MF_VALIDATE_EXTENT (to
, (size_t)tolen
, __MF_CHECK_WRITE
, "sendto to");
1172 return sendto (s
, msg
, len
, flags
, to
, tolen
);
1176 WRAPPER2(int, sendmsg
, int s
, const void *msg
, int flags
)
1178 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1179 MF_VALIDATE_EXTENT (msg
, sizeof (*msg
), __MF_CHECK_READ
, "sendmsg msg");
1180 return sendmsg (s
, msg
, flags
);
1184 WRAPPER2(int, setsockopt
, int s
, int level
, int optname
, const void *optval
,
1187 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1188 MF_VALIDATE_EXTENT (optval
, (size_t)optlen
, __MF_CHECK_READ
,
1189 "setsockopt optval");
1190 return setsockopt (s
, level
, optname
, optval
, optlen
);
1194 WRAPPER2(int, getsockopt
, int s
, int level
, int optname
, void *optval
,
1197 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1198 MF_VALIDATE_EXTENT (optval
, (size_t)*optlen
, __MF_CHECK_WRITE
,
1199 "getsockopt optval");
1200 return getsockopt (s
, level
, optname
, optval
, optlen
);
1204 WRAPPER2(int, accept
, int s
, struct sockaddr
*addr
, socklen_t
*addrlen
)
1206 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1207 MF_VALIDATE_EXTENT (addr
, (size_t)*addrlen
, __MF_CHECK_WRITE
, "accept addr");
1208 return accept (s
, addr
, addrlen
);
1212 WRAPPER2(int, bind
, int sockfd
, struct sockaddr
*addr
, socklen_t addrlen
)
1214 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1215 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_WRITE
, "bind addr");
1216 return bind (sockfd
, addr
, addrlen
);
1220 WRAPPER2(int, connect
, int sockfd
, const struct sockaddr
*addr
,
1223 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1224 MF_VALIDATE_EXTENT (addr
, (size_t)addrlen
, __MF_CHECK_READ
,
1226 return connect (sockfd
, addr
, addrlen
);
1229 #endif /* HAVE_SYS_SOCKET_H */
1232 WRAPPER2(int, gethostname
, char *name
, size_t len
)
1234 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1235 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_WRITE
, "gethostname name");
1236 return gethostname (name
, len
);
1240 #ifdef HAVE_SETHOSTNAME
1241 WRAPPER2(int, sethostname
, const char *name
, size_t len
)
1243 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1244 MF_VALIDATE_EXTENT (name
, len
, __MF_CHECK_READ
, "sethostname name");
1245 return sethostname (name
, len
);
1252 WRAPPER2(struct hostent
*, gethostbyname
, const char *name
)
1259 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1261 MF_VALIDATE_EXTENT (name
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1262 "gethostbyname name");
1263 p
= gethostbyname (name
);
1265 #ifdef MF_REGISTER_gethostbyname
1266 __mf_register (p
, sizeof (*p
), MF_REGISTER_gethostbyname
,
1267 "gethostbyname result");
1269 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
,
1270 "gethostbyname result");
1271 if (NULL
!= (s
= p
->h_name
)) {
1274 #ifdef MF_REGISTER_gethostbyname_items
1275 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1276 "gethostbyname result->h_name");
1278 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1279 "gethostbyname result->h_name");
1282 if (NULL
!= (ss
= p
->h_aliases
)) {
1283 for (nreg
= 1;; ++nreg
) {
1289 #ifdef MF_REGISTER_gethostbyname_items
1290 __mf_register (s
, n
, MF_REGISTER_gethostbyname_items
,
1291 "gethostbyname result->h_aliases[]");
1293 MF_VALIDATE_EXTENT (s
, n
, __MF_CHECK_WRITE
,
1294 "gethostbyname result->h_aliases[]");
1296 nreg
*= sizeof (*p
->h_aliases
);
1297 #ifdef MF_REGISTER_gethostbyname_items
1298 __mf_register (p
->h_aliases
, nreg
, MF_REGISTER_gethostbyname_items
,
1299 "gethostbyname result->h_aliases");
1301 MF_VALIDATE_EXTENT (p
->h_aliases
, nreg
, __MF_CHECK_WRITE
,
1302 "gethostbyname result->h_aliases");
1305 if (NULL
!= (ss
= p
->h_addr_list
)) {
1306 for (nreg
= 1;; ++nreg
) {
1310 #ifdef MF_REGISTER_gethostbyname_items
1311 __mf_register (s
, p
->h_length
, MF_REGISTER_gethostbyname_items
,
1312 "gethostbyname result->h_addr_list[]");
1314 MF_VALIDATE_EXTENT (s
, p
->h_length
, __MF_CHECK_WRITE
,
1315 "gethostbyname result->h_addr_list[]");
1317 nreg
*= sizeof (*p
->h_addr_list
);
1318 #ifdef MF_REGISTER_gethostbyname_items
1319 __mf_register (p
->h_addr_list
, nreg
, MF_REGISTER_gethostbyname_items
,
1320 "gethostbyname result->h_addr_list");
1322 MF_VALIDATE_EXTENT (p
->h_addr_list
, nreg
, __MF_CHECK_WRITE
,
1323 "gethostbyname result->h_addr_list");
1329 #endif /* HAVE_NETDB_H */
1332 #ifdef HAVE_SYS_WAIT_H
1334 WRAPPER2(pid_t
, wait
, int *status
)
1336 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1338 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1340 return wait (status
);
1344 WRAPPER2(pid_t
, waitpid
, pid_t pid
, int *status
, int options
)
1346 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1348 MF_VALIDATE_EXTENT (status
, sizeof (*status
), __MF_CHECK_WRITE
,
1350 return waitpid (pid
, status
, options
);
1353 #endif /* HAVE_SYS_WAIT_H */
1356 WRAPPER2(FILE *, popen
, const char *command
, const char *mode
)
1360 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1362 n
= strlen (command
);
1363 MF_VALIDATE_EXTENT (command
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen path");
1366 MF_VALIDATE_EXTENT (mode
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "popen mode");
1368 p
= popen (command
, mode
);
1370 #ifdef MF_REGISTER_fopen
1371 __mf_register (p
, sizeof (*p
), MF_REGISTER_fopen
, "popen result");
1373 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_WRITE
, "popen result");
1379 WRAPPER2(int, pclose
, FILE *stream
)
1382 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1383 MF_VALIDATE_EXTENT (stream
, sizeof (*stream
), __MF_CHECK_WRITE
,
1385 resp
= pclose (stream
);
1386 #ifdef MF_REGISTER_fopen
1387 __mf_unregister (stream
, sizeof (*stream
), MF_REGISTER_fopen
);
1393 WRAPPER2(int, execve
, const char *path
, char *const argv
[],
1399 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1402 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve path");
1405 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *argv");
1410 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **argv");
1414 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execve *envp");
1419 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execve **envp");
1421 return execve (path
, argv
, envp
);
1425 WRAPPER2(int, execv
, const char *path
, char *const argv
[])
1430 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1433 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv path");
1436 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execv *argv");
1441 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execv **argv");
1443 return execv (path
, argv
);
1447 WRAPPER2(int, execvp
, const char *path
, char *const argv
[])
1452 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1455 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp path");
1458 MF_VALIDATE_EXTENT (p
, sizeof (*p
), __MF_CHECK_READ
, "execvp *argv");
1463 MF_VALIDATE_EXTENT (s
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "execvp **argv");
1465 return execvp (path
, argv
);
1469 WRAPPER2(int, system
, const char *string
)
1472 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1473 n
= strlen (string
);
1474 MF_VALIDATE_EXTENT (string
, CLAMPADD(n
, 1), __MF_CHECK_READ
,
1476 return system (string
);
1480 WRAPPER2(void *, dlopen
, const char *path
, int flags
)
1484 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1486 MF_VALIDATE_EXTENT (path
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlopen path");
1487 p
= dlopen (path
, flags
);
1489 #ifdef MF_REGISTER_dlopen
1490 __mf_register (p
, 0, MF_REGISTER_dlopen
, "dlopen result");
1492 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlopen result");
1498 WRAPPER2(int, dlclose
, void *handle
)
1501 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1502 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlclose handle");
1503 resp
= dlclose (handle
);
1504 #ifdef MF_REGISTER_dlopen
1505 __mf_unregister (handle
, 0, MF_REGISTER_dlopen
);
1511 WRAPPER2(char *, dlerror
)
1514 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1520 #ifdef MF_REGISTER_dlerror
1521 __mf_register (p
, n
, MF_REGISTER_dlerror
, "dlerror result");
1523 MF_VALIDATE_EXTENT (p
, n
, __MF_CHECK_WRITE
, "dlerror result");
1529 WRAPPER2(void *, dlsym
, void *handle
, char *symbol
)
1533 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1534 MF_VALIDATE_EXTENT (handle
, 0, __MF_CHECK_READ
, "dlsym handle");
1535 n
= strlen (symbol
);
1536 MF_VALIDATE_EXTENT (symbol
, CLAMPADD(n
, 1), __MF_CHECK_READ
, "dlsym symbol");
1537 p
= dlsym (handle
, symbol
);
1539 #ifdef MF_REGISTER_dlsym
1540 __mf_register (p
, 0, MF_REGISTER_dlsym
, "dlsym result");
1542 MF_VALIDATE_EXTENT (p
, 0, __MF_CHECK_WRITE
, "dlsym result");
1548 #if defined (HAVE_SYS_IPC_H) && defined (HAVE_SYS_SEM_H) && defined (HAVE_SYS_SHM_H)
1550 WRAPPER2(int, semop
, int semid
, struct sembuf
*sops
, unsigned nsops
)
1552 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1553 MF_VALIDATE_EXTENT (sops
, sizeof (*sops
) * nsops
, __MF_CHECK_READ
,
1555 return semop (semid
, sops
, nsops
);
1559 #ifndef HAVE_UNION_SEMUN
1561 int val
; /* value for SETVAL */
1562 struct semid_ds
*buf
; /* buffer for IPC_STAT, IPC_SET */
1563 unsigned short int *array
; /* array for GETALL, SETALL */
1564 struct seminfo
*__buf
; /* buffer for IPC_INFO */
1567 WRAPPER2(int, semctl
, int semid
, int semnum
, int cmd
, union semun arg
)
1569 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1572 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_WRITE
,
1576 MF_VALIDATE_EXTENT (arg
.buf
, sizeof (*arg
.buf
), __MF_CHECK_READ
,
1580 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_WRITE
,
1583 MF_VALIDATE_EXTENT (arg
.array
, sizeof (*arg
.array
), __MF_CHECK_READ
,
1587 /* FreeBSD 5.1 And Cygwin headers include IPC_INFO but not the __buf field. */
1588 #if !defined(__FreeBSD__) && !defined(__CYGWIN__)
1590 MF_VALIDATE_EXTENT (arg
.__buf
, sizeof (*arg
.__buf
), __MF_CHECK_WRITE
,
1598 return semctl (semid
, semnum
, cmd
, arg
);
1602 WRAPPER2(int, shmctl
, int shmid
, int cmd
, struct shmid_ds
*buf
)
1604 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1607 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_WRITE
,
1611 MF_VALIDATE_EXTENT (buf
, sizeof (*buf
), __MF_CHECK_READ
,
1617 return shmctl (shmid
, cmd
, buf
);
1621 WRAPPER2(void *, shmat
, int shmid
, const void *shmaddr
, int shmflg
)
1624 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1625 p
= shmat (shmid
, shmaddr
, shmflg
);
1626 #ifdef MF_REGISTER_shmat
1628 struct shmid_ds buf
;
1629 __mf_register (p
, shmctl (shmid
, IPC_STAT
, &buf
) ? 0 : buf
.shm_segsz
,
1630 MF_REGISTER_shmat
, "shmat result");
1637 WRAPPER2(int, shmdt
, const void *shmaddr
)
1640 TRACE ("%s\n", __PRETTY_FUNCTION__
);
1641 resp
= shmdt (shmaddr
);
1642 #ifdef MF_REGISTER_shmat
1643 __mf_unregister ((void *)shmaddr
, 0, MF_REGISTER_shmat
);
1649 #endif /* HAVE_SYS_IPC/SEM/SHM_H */
1653 /* ctype stuff. This is host-specific by necessity, as the arrays
1654 that is used by most is*()/to*() macros are implementation-defined. */
1657 #ifdef HAVE___CTYPE_B_LOC
1658 WRAPPER2(unsigned short **, __ctype_b_loc
, void)
1660 static unsigned short * last_buf
= (void *) 0;
1661 static unsigned short ** last_ptr
= (void *) 0;
1662 unsigned short ** ptr
= (unsigned short **) __ctype_b_loc ();
1663 unsigned short * buf
= * ptr
;
1664 if (ptr
!= last_ptr
)
1666 /* XXX: unregister last_ptr? */
1668 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_b_loc **");
1670 if (buf
!= last_buf
)
1673 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(unsigned short), __MF_TYPE_STATIC
,
1680 #ifdef HAVE___CTYPE_TOUPPER_LOC
1681 WRAPPER2(int **, __ctype_toupper_loc
, void)
1683 static int * last_buf
= (void *) 0;
1684 static int ** last_ptr
= (void *) 0;
1685 int ** ptr
= (int **) __ctype_toupper_loc ();
1687 if (ptr
!= last_ptr
)
1689 /* XXX: unregister last_ptr? */
1691 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_toupper_loc **");
1693 if (buf
!= last_buf
)
1696 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(int), __MF_TYPE_STATIC
,
1697 "ctype_toupper_loc []");
1703 #ifdef HAVE___CTYPE_TOLOWER_LOC
1704 WRAPPER2(int **, __ctype_tolower_loc
, void)
1706 static int * last_buf
= (void *) 0;
1707 static int ** last_ptr
= (void *) 0;
1708 int ** ptr
= (int **) __ctype_tolower_loc ();
1710 if (ptr
!= last_ptr
)
1712 /* XXX: unregister last_ptr? */
1714 __mf_register (last_ptr
, sizeof(last_ptr
), __MF_TYPE_STATIC
, "ctype_tolower_loc **");
1716 if (buf
!= last_buf
)
1719 __mf_register ((void *) (last_buf
- 128), 384 * sizeof(int), __MF_TYPE_STATIC
,
1720 "ctype_tolower_loc []");