tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Tests requiring MD hooks



On Sun, Jul 10, 2011 at 09:38:13PM -0700, Matt Thomas wrote:
> 
> On Jul 10, 2011, at 7:58 PM, Valeriy E. Ushakov wrote:
> 
> > 
> >> That seems to be a bit tricky to write in a portable way: testing --x
> >> right in memory pages requires to put/copy some payload in a page and
> >> call it.
> > 
> > dlopen something, find a function with dlsym, disable exec on that
> > page and call the function.  Catch SIGSEGV, check siginfo.  mprotect
> > it back and call the function again.
> 
> doesn't work when the target uses function descriptors.

I'm confused (not difficult these days!).
dlsym() returns 'void *', there is no separate dlsym_function_ptr() that
can return a 'fat' function pointer, or is the symbol attached to
something more akin to an x86 'call gate descriptor' - which is used
as the target of the call instruction?

This gives the inverse problem - if (as suggested in another path of
this thread) you try to allocate the function code on an array,
you'll need to generate the function descriptor as well as the code
itself - this could be somewhat tricky!
Of course, the compiler could be doing horrid things when casting
function pointers to/from void *.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index