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

From: A M (alim1993_at_yahoo.com)
Date: 11/18/04

  • Next message: Daniel Drake: "[PATCH] Permit LOG_SENSE and LOG_SELECT in SG_IO command table"
    Date:	Thu, 18 Nov 2004 07:09:52 -0800 (PST)
    To: Valdis.Kletnieks@vt.edu
    
    

    Thank you for your reply, please see my answers
    embedded below:
    --- Valdis.Kletnieks@vt.edu wrote:

    > On Tue, 16 Nov 2004 13:20:15 PST, A M said:
    >
    > > Does anybody know how to access the address of the
    > > current executing instruction in C while the
    > program
    > > is executing?
    >
    > For what processor? x86, itanium, sparc, s390 all
    > do it differently.
    I am targeting an x86 machines.
    >
    > Also, the answer to "this *very* instruction" is
    > different from
    > "where this instruction was when we
    > trapped/kdbg/interrupt/whatever
    > it so we could look at the current
    > process/thread/worker state".
    >
    > 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>?"
    it is close to the second scenario ("Where in memory
    is...") the basic idea is to come up with a
    passive-software based data bus analyzer that can be
    used to monitor/sample instructions of a process (a
    section of a process) or a thread while executing.
    >
    > (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__;
    >
    > > 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...
    >
    > In kernel space, you'll have to be more specific as
    > to what you're
    > trying to do, but you're always welcome to write a
    > replacement for
    > fs/binfmt_elf.c :)
    >
    > > Can anybody think of a method to replace a thread
    > > image without replacing the whole process image?
    >
    > What are you trying to achieve here? It's unclear
    > what you're
    > hoping will happen....
    The ability to create threads and replace the
    functionality of one of the threads with a previously
    compiled program (a complete process).
    >

    > ATTACHMENT part 2 application/pgp-signature

                    
    __________________________________
    Do you Yahoo!?
    The all-new My Yahoo! - Get yours free!
    http://my.yahoo.com
     

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Daniel Drake: "[PATCH] Permit LOG_SENSE and LOG_SELECT in SG_IO command table"

    Relevant Pages

    • Re: unset($this) or maybe unset(&$this)
      ... which does not involve a jump is executed the next instruction to be executed will be the very next instruction in the same object method. ... The code may still exist in the class definition, but the object, which contains a copy of that code in memory, does not, so how can it continue executing any of that code? ... When you call something like obj.Func; in C++ (assuming obj is an instance of class Foo), the compiler actually translates that to something like: ...
      (comp.lang.php)
    • Re: Revise text section that has been loaded into virtual memory
      ... > the executable that has been loaded into memory. ... >between all processes executing the same code. ... >instruction and data caches and any write operation goes to the data cache ... >while any instruction fetch will be done through the instruction cache. ...
      (comp.os.linux.development.system)
    • Re: Cross-Modifying Code
      ... > There's an explicit warning that instruction fetch and page table accesses ... > don't honour xFENCE for prefetched code either. ... > then you don't know when to issue the CPUID. ... The Opteron manuals don't comment on the interaction between executing code ...
      (comp.lang.asm.x86)
    • Re: Question about Instruction Format (ModR/M)
      ... (the first three bytes, being prefixes, could be in any order) ... This is a 32-bit PM instruction executing in 16-bit RM/PM due to ... they have to push the extra byte back onto the disassembly stream. ...
      (alt.lang.asm)
    • Re: IF NOTs
      ... a" will will slower than "FALSE a". ... case (executing x) would be slower than the "TRUE b" case (also ... conditional jump instruction. ... zero as needed. ...
      (comp.lang.forth)

    Loading