]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libvtv/vtv_rts.cc
PR c++/87554 - ICE with extern template and reference member.
[thirdparty/gcc.git] / libvtv / vtv_rts.cc
index 7bde2f46e4f308fee5f6130c0c93daa6cfc4b305..bd3cda1749e322cc24f2e87c0e08d944c1d4f298 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 2012-2013
- Free Software Foundation
+/* Copyright (C) 2012-2019 Free Software Foundation, Inc.
 
  This file is part of GCC.
 
 
 #include "vtv-change-permission.h"
 
-#if defined (__CYGWIN__) || defined (__MINGW32__)
-// porting: fix link error to libc
-void __fortify_fail (const char * msg){
-    OutputDebugString(msg);
-    abort();
-}
-#else
+#ifdef HAVE_GETEXECNAME
+const char *program_invocation_name;
+#endif
+
+#ifdef HAVE___FORTIFY_FAIL
 extern "C" {
 
   /* __fortify_fail is a function in glibc that calls __libc_message,
@@ -174,6 +171,20 @@ extern "C" {
   extern void __fortify_fail (const char *) __attribute__((noreturn));
 
 } /* extern "C" */
+#else
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+// porting: fix link error to libc
+void __fortify_fail (const char * msg){
+    OutputDebugString(msg);
+    abort();
+}
+#else
+// FIXME: Provide backtrace via libbacktrace?
+void __fortify_fail (const char *msg) {
+    write (2, msg, strlen (msg));
+    abort ();
+}
+#endif
 #endif
 
 /* The following variables are used only for debugging and performance
@@ -574,6 +585,9 @@ read_section_offset_and_length (struct dl_phdr_info *info,
   /* Get the name of the main executable.  This may or may not include
      arguments passed to the program.  Find the first space, assume it
      is the start of the argument list, and change it to a '\0'. */
+#ifdef HAVE_GETEXECNAME
+  program_invocation_name = getexecname ();
+#endif
   snprintf (program_name, sizeof (program_name), program_invocation_name);
 
   /* Check to see if we already have the data for this file.  */
@@ -664,7 +678,10 @@ read_section_offset_and_length (struct dl_phdr_info *info,
                      size.  */
                   *sect_offset = sect_hdr.sh_addr;
                  if (!is_libvtv)
-                   *sect_len = sect_hdr.sh_size - VTV_PAGE_SIZE;
+                   {
+                     VTV_ASSERT (sect_hdr.sh_size - VTV_PAGE_SIZE >= 0);
+                     *sect_len = sect_hdr.sh_size - VTV_PAGE_SIZE;
+                   }
                  else
                    *sect_len = sect_hdr.sh_size;
                   found = true;
@@ -785,7 +802,7 @@ iterate_modules (void *data)
                       if (debug_functions)
                         {
                           snprintf (buffer, sizeof (buffer),
-                                    "Failed called to mprotect for %s error: ",
+                                    "Failed call to mprotect for %s error: ",
                                     (*mprotect_flags & PROT_WRITE) ?
                                     "READ/WRITE" : "READ-ONLY");
                           log_memory_protection_data (buffer);
@@ -805,9 +822,8 @@ iterate_modules (void *data)
                         }
                     }
                   increment_num_calls (&num_calls_to_mprotect);
-                  /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) 
-                                            / VTV_PAGE_SIZE; */
-                  num_pages_protected += (map_sect_len + 4096 - 1) / 4096;
+                  num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) 
+                   / VTV_PAGE_SIZE;
                   continue;
                 }
             }
@@ -854,6 +870,9 @@ dl_iterate_phdr_callback (struct dl_phdr_info *info, size_t, void *data)
   /* Get the name of the main executable.  This may or may not include
      arguments passed to the program.  Find the first space, assume it
      is the start of the argument list, and change it to a '\0'. */
+#ifdef HAVE_GETEXECNAME
+  program_invocation_name = getexecname ();
+#endif
   snprintf (program_name, sizeof (program_name), program_invocation_name);
 
   read_section_offset_and_length (info, map_sect_name, *mprotect_flags,
@@ -897,7 +916,7 @@ dl_iterate_phdr_callback (struct dl_phdr_info *info, size_t, void *data)
           if (debug_functions)
             {
               snprintf (buffer, sizeof (buffer),
-                        "Failed called to mprotect for %s error: ",
+                        "Failed call to mprotect for %s error: ",
                         (*mprotect_flags & PROT_WRITE) ?
                         "READ/WRITE" : "READ-ONLY");
               log_memory_protection_data (buffer);
@@ -917,8 +936,7 @@ dl_iterate_phdr_callback (struct dl_phdr_info *info, size_t, void *data)
             }
         }
       increment_num_calls (&num_calls_to_mprotect);
-      /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) / VTV_PAGE_SIZE; */
-      num_pages_protected += (map_sect_len + 4096 - 1) / 4096;
+      num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) / VTV_PAGE_SIZE;
     }
 
   return 0;
@@ -1055,9 +1073,9 @@ __VLTChangePermission (int perm)
   if (debug_functions)
     {
       if (perm == __VLTP_READ_WRITE)
-       fprintf (stdout, "Changing VLT permisisons to Read-Write.\n");
+       fprintf (stdout, "Changing VLT permissions to Read-Write.\n");
       else if (perm == __VLTP_READ_ONLY)
-       fprintf (stdout, "Changing VLT permissions to Read-only.\n");
+       fprintf (stdout, "Changing VLT permissions to Read-Only.\n");
 
       else
        fprintf (stdout, "Unrecognized permissions value: %d\n", perm);