-/* 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,
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
/* 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. */
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;
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);
}
}
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;
}
}
/* 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,
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);
}
}
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;
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);