mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 09:08:59 +00:00
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
10
bfd/bfdwin.c
10
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. */
|
||||
|
||||
10
bfd/cache.c
10
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 =
|
||||
|
||||
12
bfd/sysdep.h
12
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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user