Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262731AbUKRKsL (ORCPT ); Thu, 18 Nov 2004 05:48:11 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262727AbUKRK3L (ORCPT ); Thu, 18 Nov 2004 05:29:11 -0500 Received: from linux01.gwdg.de ([134.76.13.21]:48256 "EHLO linux01.gwdg.de") by vger.kernel.org with ESMTP id S262725AbUKRK2p (ORCPT ); Thu, 18 Nov 2004 05:28:45 -0500 Date: Thu, 18 Nov 2004 11:28:41 +0100 (MET) From: Jan Engelhardt To: Valdis.Kletnieks@vt.edu cc: A M , linux-kernel@vger.kernel.org Subject: Re: Accessing program counter registers from within C or Aseembler. In-Reply-To: <200411162133.iAGLXn7v018578@turing-police.cc.vt.edu> Message-ID: References: <20041116212015.32217.qmail@web51901.mail.yahoo.com> <200411162133.iAGLXn7v018578@turing-police.cc.vt.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1344 Lines: 38 >> 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 ?" > >(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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/