diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-03-13 06:31:28 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-03-13 06:55:44 -0700 |
commit | 2e384d4f44f15e560b2a068e0ed866438aaa7cd7 (patch) | |
tree | 57e59d6af7e7a76acfd3879885e399b509b78951 | |
parent | 32235d90951b4b7c2976c61a28c30d82cb7a7588 (diff) | |
download | gdb-2e384d4f44f15e560b2a068e0ed866438aaa7cd7.zip gdb-2e384d4f44f15e560b2a068e0ed866438aaa7cd7.tar.gz gdb-2e384d4f44f15e560b2a068e0ed866438aaa7cd7.tar.bz2 |
bfd: Use MAP_FAILED for mmap failure
Use MAP_FAILED, instead of ((void *) -1), for mmap failure and use
((void *) -1) only if MAP_FAILED is undefined.
* bfdio.c (bfd_mmap): Replace (void *) -1 with MAP_FAILED for
mmap failure.
* bfdwin.c: Don't include <sys/mman.h>.
(MAP_FILE): Removed.
(bfd_get_file_window): Replace (void *) -1 with MAP_FAILED for
mmap failure.
* cache.c: Don't include <sys/mman.h>.
(cache_bmmap): Replace (void *) -1 with MAP_FAILED for mmap
failure.
* opncls.c (opncls_bmmap): Likewise.
* sysdep.h: Include <sys/mman.h> if HAVE_MMAP is define.
(MAP_FILE): New. Defined as 0 if undefined.
(MAP_FAILED): New. Defined as ((void *) -1) if undefined.
-rw-r--r-- | bfd/bfdio.c | 2 | ||||
-rw-r--r-- | bfd/bfdwin.c | 10 | ||||
-rw-r--r-- | bfd/cache.c | 10 | ||||
-rw-r--r-- | bfd/opncls.c | 2 | ||||
-rw-r--r-- | bfd/sysdep.h | 12 | ||||
-rw-r--r-- | bfd/vms-lib.c | 2 |
6 files changed, 19 insertions, 19 deletions
diff --git a/bfd/bfdio.c b/bfd/bfdio.c index ab3e28e..1572de0 100644 --- a/bfd/bfdio.c +++ b/bfd/bfdio.c @@ -666,7 +666,7 @@ bfd_mmap (bfd *abfd, void *addr, bfd_size_type len, if (abfd->iovec == NULL) { bfd_set_error (bfd_error_invalid_operation); - return (void *) -1; + return MAP_FAILED; } return abfd->iovec->bmmap (abfd, addr, len, prot, flags, offset, diff --git a/bfd/bfdwin.c b/bfd/bfdwin.c index beb1739..2919c71 100644 --- a/bfd/bfdwin.c +++ b/bfd/bfdwin.c @@ -31,14 +31,6 @@ #undef HAVE_MPROTECT /* code's not tested yet */ -#if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE -#include <sys/mman.h> -#endif - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif - static int debug_windows; /* The idea behind the next and refcount fields is that one mapped @@ -234,7 +226,7 @@ bfd_get_file_window (bfd *abfd, ? MAP_FILE | MAP_PRIVATE : MAP_FILE | MAP_SHARED), fd, file_offset); - if (i->data == (void *) -1) + if (i->data == MAP_FAILED) { /* An error happened. Report it, or try using malloc, or something. */ diff --git a/bfd/cache.c b/bfd/cache.c index 4c00c00..3bc2afc 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -45,10 +45,6 @@ SUBSECTION #include "libbfd.h" #include "libiberty.h" -#ifdef HAVE_MMAP -#include <sys/mman.h> -#endif - static FILE *_bfd_open_file_unlocked (bfd *abfd); /* In some cases we can optimize cache operation when reopening files. @@ -489,7 +485,7 @@ cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, void **map_addr ATTRIBUTE_UNUSED, bfd_size_type *map_len ATTRIBUTE_UNUSED) { - void *ret = (void *) -1; + void *ret = MAP_FAILED; if (!bfd_lock ()) return ret; @@ -518,7 +514,7 @@ cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, pg_len = (len + (offset - pg_offset) + pagesize_m1) & ~pagesize_m1; ret = mmap (addr, pg_len, prot, flags, fileno (f), pg_offset); - if (ret == (void *) -1) + if (ret == MAP_FAILED) bfd_set_error (bfd_error_system_call); else { @@ -530,7 +526,7 @@ cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, #endif if (!bfd_unlock ()) - return (void *) -1; + return MAP_FAILED; return ret; } diff --git a/bfd/opncls.c b/bfd/opncls.c index a0a5c40..0966724 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -675,7 +675,7 @@ opncls_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, void **map_addr ATTRIBUTE_UNUSED, bfd_size_type *map_len ATTRIBUTE_UNUSED) { - return (void *) -1; + return MAP_FAILED; } static const struct bfd_iovec opncls_iovec = diff --git a/bfd/sysdep.h b/bfd/sysdep.h index a576665..b907bc2 100644 --- a/bfd/sysdep.h +++ b/bfd/sysdep.h @@ -86,6 +86,18 @@ #define SEEK_CUR 1 #endif +#ifdef HAVE_MMAP +#include <sys/mman.h> +#endif + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *) -1) +#endif + #include "filenames.h" #if !HAVE_DECL_FFS diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c index b0ca990..592a57f 100644 --- a/bfd/vms-lib.c +++ b/bfd/vms-lib.c @@ -1277,7 +1277,7 @@ vms_lib_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, void **map_addr ATTRIBUTE_UNUSED, bfd_size_type *map_len ATTRIBUTE_UNUSED) { - return (void *) -1; + return MAP_FAILED; } static const struct bfd_iovec vms_lib_iovec = { |