digitalmars.D - How to mov EAX, &func?
- Mehrdad (10/10) May 15 2012 How do get the address of a function in naked assembly code?
- Gor Gyolchanyan (14/24) May 15 2012 I think I had that one before. Try this one:
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (16/41) May 15 2012 That's not naked inline asm, though.
- deadalnix (4/14) May 15 2012 As it is naked,
- ponce (15/17) May 15 2012 I think this is illegal in assembly, try to call a label in your
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (7/23) May 15 2012 I suspect he wanted a solution where he could load an arbitrary
- Walter Bright (5/15) May 16 2012 I know, but also be aware that even if it did work, it would not work in...
- Mehrdad (5/22) May 16 2012 Yeah I know, but currently shared libraries are the least of my
- Mehrdad (3/5) May 16 2012 Or position-independent code for that matter, although I'd be
- Walter Bright (2/3) May 16 2012 Just insert an asm call to a function that returns the address of foo.
- Mehrdad (6/11) May 16 2012 Hmmm... interesting idea.
How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...
May 15 2012
I think I had that one before. Try this one: void foo() { void* foopt = cast(void*)&foo; asm { naked; mov EAX fooptr; } } On Tue, May 15, 2012 at 11:33 PM, Mehrdad <wfunction hotmail.com> wrote:How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...-- Bye, Gor Gyolchanyan.
May 15 2012
On 15-05-2012 22:51, Gor Gyolchanyan wrote:I think I had that one before. Try this one: void foo() { void* foopt = cast(void*)&foo; asm { naked; mov EAX fooptr; } } On Tue, May 15, 2012 at 11:33 PM, Mehrdad <wfunction hotmail.com <mailto:wfunction hotmail.com>> wrote: How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work... -- Bye, Gor Gyolchanyan.That's not naked inline asm, though. Something like this might work: void foo() { asm { naked; mox EAX, dword ptr foo; /* whatever... */ } } -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 15 2012
Le 15/05/2012 21:33, Mehrdad a écrit :How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...As it is naked, mov EAX, EIP; is enough.
May 15 2012
Le 15/05/2012 23:27, deadalnix a écrit :mov EAX, EIP; is enough.I think this is illegal in assembly, try to call a label in your function then pop. void* selfAddress() // actually tested { asm { naked; call my_label; my_label: pop EAX; sub EAX, 5; ret; } }
May 15 2012
On 15-05-2012 23:27, deadalnix wrote:Le 15/05/2012 21:33, Mehrdad a écrit :I suspect he wanted a solution where he could load an arbitrary function's address. -- Alex Rønne Petersen alex lycus.org http://lycus.orgHow do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...As it is naked, mov EAX, EIP; is enough.
May 15 2012
Le 15/05/2012 23:58, Alex Rønne Petersen a écrit :I suspect he wanted a solution where he could load an arbitrary function's address.I'm also searching for a way to get a label address from inline assembly. This would be useful for hard-coded jumptables.
May 15 2012
On Tuesday, 15 May 2012 at 21:58:56 UTC, Alex Rønne Petersen wrote:On 15-05-2012 23:27, deadalnix wrote:indeedLe 15/05/2012 21:33, Mehrdad a écrit :I suspect he wanted a solution where he could load an arbitrary function's address.How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...As it is naked, mov EAX, EIP; is enough.
May 15 2012
On 5/15/2012 12:33 PM, Mehrdad wrote:How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...I know, but also be aware that even if it did work, it would not work in the presence of PIC code and shared libraries. It's best if you stick to using D code to get the address of a function, which accounts for all these variations and wierdness.
May 16 2012
On Wednesday, 16 May 2012 at 07:05:10 UTC, Walter Bright wrote:On 5/15/2012 12:33 PM, Mehrdad wrote:Yeah I know, but currently shared libraries are the least of my worries. The trouble with 'sticking to D code' is that, well, I can't... it's naked...How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work...I know, but also be aware that even if it did work, it would not work in the presence of PIC code and shared libraries. It's best if you stick to using D code to get the address of a function, which accounts for all these variations and wierdness.
May 16 2012
On Wednesday, 16 May 2012 at 09:40:08 UTC, Mehrdad wrote:Yeah I know, but currently shared libraries are the least of my worries.Or position-independent code for that matter, although I'd be more concerned with this than the former.
May 16 2012
On 5/16/2012 2:40 AM, Mehrdad wrote:The trouble with 'sticking to D code' is that, well, I can't... it's naked...Just insert an asm call to a function that returns the address of foo.
May 16 2012
On Wednesday, 16 May 2012 at 18:17:50 UTC, Walter Bright wrote:On 5/16/2012 2:40 AM, Mehrdad wrote:Hmmm... interesting idea. Not a real fan of this solution, since it's extra code, and it involves a function call (and I was trying to avoid function calls in this code, since it's going to be in a boot-sector-like thing). But I think it'll work, thanks...The trouble with 'sticking to D code' is that, well, I can't... it's naked...Just insert an asm call to a function that returns the address of foo.
May 16 2012