Follow recent Solaris development with respect to

SUNWDTRACE program header. Newer Solaris no longer utilizes
this program header as a scratchspace for DTrace fasttrap
provider, before libc is loaded.
For the time being, it serves as a space for initial thread
pointer.
n-i-bz


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15936
This commit is contained in:
Ivo Raisr 2016-08-12 22:28:50 +00:00
parent 5ee5496e04
commit 6260274e4e
4 changed files with 65 additions and 5 deletions

View File

@ -3649,6 +3649,29 @@ AC_DEFINE([SOLARIS_SCHEDCTL_PAGE_EXEC], 1,
[Define to 1 if you have the schedctl page executable.])
])
# Solaris-specific check determining if PT_SUNWDTRACE program header provides
# scratch space for DTrace fasttrap provider (illumos, older Solaris) or just
# an initial thread pointer for libc (newer Solaris).
#
# C-level symbol: SOLARIS_PT_SUNDWTRACE_THRP
# Automake-level symbol: none
#
AC_MSG_CHECKING([if PT_SUNWDTRACE serves for initial thread pointer (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/fasttrap_isa.h>
]], [[
return !FT_SCRATCHSIZE;
]])], [
solaris_pt_sunwdtrace_thrp=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_PT_SUNDWTRACE_THRP], 1,
[Define to 1 if PT_SUNWDTRACE program header provides just an initial thread pointer for libc.])
], [
solaris_pt_sunwdtrace_thrp=no
AC_MSG_RESULT([no])
])
else
AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)

View File

@ -1594,6 +1594,10 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
XArray* /* of RangeAndBias */ svma_ranges = NULL;
# if defined(SOLARIS_PT_SUNDWTRACE_THRP)
Addr dtrace_data_vaddr = 0;
# endif
vg_assert(di);
vg_assert(di->fsm.have_rx_map == True);
vg_assert(di->fsm.have_rw_map == True);
@ -1815,6 +1819,16 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
}
}
if (!loaded) {
# if defined(SOLARIS_PT_SUNDWTRACE_THRP)
if ((a_phdr.p_memsz == VKI_PT_SUNWDTRACE_SIZE)
&& ((a_phdr.p_flags & (PF_R | PF_W | PF_X)) == PF_R)) {
TRACE_SYMTAB("PT_LOAD[%ld]: ignore dtrace_data program "
"header\n", i);
dtrace_data_vaddr = a_phdr.p_vaddr;
continue;
}
# endif /* SOLARIS_PT_SUNDWTRACE_THRP */
ML_(symerr)(di, False,
"ELF section outside all mapped regions");
/* This problem might be solved by further memory mappings.
@ -2020,6 +2034,12 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
/* Accept .data where mapped as rw (data), even if zero-sized */
if (0 == VG_(strcmp)(name, ".data")) {
# if defined(SOLARIS_PT_SUNDWTRACE_THRP)
if ((size == VKI_PT_SUNWDTRACE_SIZE) && (svma == dtrace_data_vaddr)) {
TRACE_SYMTAB("ignoring .data section for dtrace_data "
"%#lx .. %#lx\n", svma, svma + size - 1);
} else
# endif /* SOLARIS_PT_SUNDWTRACE_THRP */
if (inrw && !di->data_present) {
di->data_present = True;
di->data_svma = svma;

View File

@ -55,6 +55,11 @@
#include <elf.h>
#if defined(VGO_solaris)
# include <sys/fasttrap.h> // PT_SUNWDTRACE_SIZE
# if defined(SOLARIS_PT_SUNDWTRACE_THRP)
# define PT_SUNWDTRACE_PROTECTION (PF_R)
# else
# define PT_SUNWDTRACE_PROTECTION (PF_R | PF_W | PF_X)
# endif
#endif
/* --- !!! --- EXTERNAL HEADERS end --- !!! --- */
@ -617,11 +622,15 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info)
# if defined(VGO_solaris)
case PT_SUNWDTRACE:
if (ph->p_memsz < PT_SUNWDTRACE_SIZE ||
(ph->p_flags & (PF_R | PF_W | PF_X)) != (PF_R | PF_W | PF_X)) {
if (ph->p_memsz < PT_SUNWDTRACE_SIZE) {
VG_(printf)("valgrind: m_ume.c: too small SUNWDTRACE size\n");
return VKI_ENOEXEC;
}
if ((ph->p_flags & PT_SUNWDTRACE_PROTECTION)
!= PT_SUNWDTRACE_PROTECTION) {
VG_(printf)("valgrind: m_ume.c: SUNWDTRACE protection mismatch\n");
return VKI_ENOEXEC;
}
info->init_thrptr = ph->p_vaddr + ebase;
break;
@ -657,12 +666,16 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info)
# if defined(VGO_solaris)
if (iph->p_type == PT_SUNWDTRACE) {
if (iph->p_memsz < PT_SUNWDTRACE_SIZE ||
(iph->p_flags & (PF_R | PF_W | PF_X))
!= (PF_R | PF_W | PF_X)) {
if (iph->p_memsz < PT_SUNWDTRACE_SIZE) {
VG_(printf)("valgrind: m_ume.c: too small SUNWDTRACE size\n");
return VKI_ENOEXEC;
}
if ((iph->p_flags & PT_SUNWDTRACE_PROTECTION)
!= PT_SUNWDTRACE_PROTECTION) {
VG_(printf)("valgrind: m_ume.c: SUNWDTRACE protection "
"mismatch\n");
return VKI_ENOEXEC;
}
/* Store the thrptr value into a temporary because we do not
know yet where the interpreter is mapped. */

View File

@ -483,6 +483,10 @@ typedef struct vki_kcf_door_arg_s {
#endif /* SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS */
#include <sys/fasttrap.h>
#define VKI_PT_SUNWDTRACE_SIZE PT_SUNWDTRACE_SIZE
#include <sys/fcntl.h>
#define VKI_O_RDONLY O_RDONLY
#define VKI_O_WRONLY O_WRONLY