Author: kib
Date: Thu Dec 12 22:59:22 2019
New Revision: 355676
URL: https://svnweb.freebsd.org/changeset/base/355676

Log:
  rtld: make checks for mmap(2) failures compliant with documentation.
  
  On error, mmap(2) returns MAP_FAILED.  There is no need to use its
  definition or to cast.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week

Modified:
  head/libexec/rtld-elf/map_object.c

Modified: head/libexec/rtld-elf/map_object.c
==============================================================================
--- head/libexec/rtld-elf/map_object.c  Thu Dec 12 22:36:47 2019        
(r355675)
+++ head/libexec/rtld-elf/map_object.c  Thu Dec 12 22:59:22 2019        
(r355676)
@@ -209,7 +209,7 @@ map_object(int fd, const char *path, const struct stat
        base_flags |= MAP_FIXED | MAP_EXCL;
 
     mapbase = mmap(base_addr, mapsize, PROT_NONE, base_flags, -1, 0);
-    if (mapbase == (caddr_t) -1) {
+    if (mapbase == MAP_FAILED) {
        _rtld_error("%s: mmap of entire address space failed: %s",
          path, rtld_strerror(errno));
        goto error;
@@ -266,7 +266,7 @@ map_object(int fd, const char *path, const struct stat
            bss_addr = mapbase +  (bss_vaddr - base_vaddr);
            if (bss_vlimit > bss_vaddr) {       /* There is something to do */
                if (mmap(bss_addr, bss_vlimit - bss_vaddr, data_prot,
-                   data_flags | MAP_ANON, -1, 0) == (caddr_t)-1) {
+                   data_flags | MAP_ANON, -1, 0) == MAP_FAILED) {
                    _rtld_error("%s: mmap of bss failed: %s", path,
                        rtld_strerror(errno));
                    goto error1;
@@ -348,7 +348,7 @@ get_elf_header(int fd, const char *path, const struct 
 
        hdr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_PREFAULT_READ,
            fd, 0);
-       if (hdr == (Elf_Ehdr *)MAP_FAILED) {
+       if (hdr == MAP_FAILED) {
                _rtld_error("%s: read error: %s", path, rtld_strerror(errno));
                return (NULL);
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to