]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libbacktrace/mmapio.c
Update copyright years.
[thirdparty/gcc.git] / libbacktrace / mmapio.c
index 8b46f63919630b7a09fd0c534f2a35e7984c0b47..b780c3d07dff4d7603e66f2cbfb75363bde26426 100644 (file)
@@ -1,5 +1,5 @@
 /* mmapio.c -- File views using mmap.
-   Copyright (C) 2012 Free Software Foundation, Inc.
+   Copyright (C) 2012-2024 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Google.
 
 Redistribution and use in source and binary forms, with or without
@@ -7,13 +7,13 @@ modification, are permitted provided that the following conditions are
 met:
 
     (1) Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer. 
+    notice, this list of conditions and the following disclaimer.
 
     (2) Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
-    distribution.  
-    
+    distribution.
+
     (3) The name of the author may not be used to
     endorse or promote products derived from this software without
     specific prior written permission.
@@ -30,8 +30,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.  */
 
-#define _GNU_SOURCE
-
 #include "config.h"
 
 #include <errno.h>
@@ -42,6 +40,14 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include "backtrace.h"
 #include "internal.h"
 
+#ifndef HAVE_DECL_GETPAGESIZE
+extern int getpagesize (void);
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
 /* This file implements file views and memory allocation when mmap is
    available.  */
 
@@ -49,7 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 int
 backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
-                   int descriptor, off_t offset, size_t size,
+                   int descriptor, off_t offset, uint64_t size,
                    backtrace_error_callback error_callback,
                    void *data, struct backtrace_view *view)
 {
@@ -58,6 +64,12 @@ backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
   off_t pageoff;
   void *map;
 
+  if ((uint64_t) (size_t) size != size)
+    {
+      error_callback (data, "file size too large", 0);
+      return 0;
+    }
+
   pagesize = getpagesize ();
   inpage = offset % pagesize;
   pageoff = offset - inpage;