compiler: set varargs correctly for type of method expression
[gcc.git] / libvtv / vtv_rts.cc
index f5344a00687c3a7fe3e012f2f76bd699faf463cb..fd7cd9331f81ab98f703cef6897cee41dae7e881 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 2012-2013
- Free Software Foundation
+/* Copyright (C) 2012-2020 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
@@ -201,14 +212,15 @@ unsigned long long verify_vtable_cycles = 0;
    debugging/tracing will not be ON on production environments */
 
 static const bool debug_hash = HASHTABLE_STATS;
-static const int debug_functions = 0;
-static const int debug_init = 0;
-static const int debug_verify_vtable = 0;
 
 #ifdef VTV_DEBUG
 static const int debug_functions = 1;
 static const int debug_init = 1;
 static const int debug_verify_vtable = 1;
+#else
+static const int debug_functions = 0;
+static const int debug_init = 0;
+static const int debug_verify_vtable = 0;
 #endif
 
 /* Global file descriptor variables for logging, tracing and debugging.  */
@@ -573,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.  */
@@ -663,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;
@@ -784,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);
@@ -804,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;
                 }
             }
@@ -853,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,
@@ -896,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);
@@ -916,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;
@@ -1054,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);