Re: Accessing program counter registers from within C or Aseembler.

From: Jan Engelhardt
Date: Thu Nov 18 2004 - 05:55:32 EST


>> Does anybody know how to access the address of the
>> current executing instruction in C while the program
>> is executing?
>
>In other words, are you trying to answer "Where in memory am *I*?"
>or "Where in memory is <that very recent code I want to look at>?"
>
>(Hint - for the former, you can probably get very good approximations
>by just looking at the entry point address for the function:
>
> (void *) where = &__FUNCTION__;

Well, that's only the function in which you are (i.e. it's an approximation to
EIP)

>> Also, is there a method to load a program image from
>> memory not a file (an exec that works with a memory
>> address)? Mainly I am looking for a method that brings
>> a program image into memory modify parts of it and
>> start the in-memory modified version.
>
>In user space, you probably want either mmap() or dlopen(), depending what it
>is you're trying to do, most likely...

Those pages will probably have NX set then, for archs which support it.




Jan Engelhardt
--
Gesellschaft fÃr Wissenschaftliche Datenverarbeitung
Am Fassberg, 37077 GÃttingen, www.gwdg.de
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/