diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-07-11 08:48:37 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-07-11 08:51:12 +0200 |
commit | 71e27ae1766e0090fa989aad7ee930152a1921de (patch) | |
tree | 5f07a7c63e9b03543d077f90a214bd8fbb09edb7 /funcjmp_simple_x86.c | |
parent | c8bc99eb8027a57570183e64e52fcb8fbc4c1e3d (diff) |
improved Makefile, check for supported arch
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'funcjmp_simple_x86.c')
-rw-r--r-- | funcjmp_simple_x86.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/funcjmp_simple_x86.c b/funcjmp_simple_x86.c new file mode 100644 index 0000000..5291788 --- /dev/null +++ b/funcjmp_simple_x86.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> + +#ifndef __i386 +#error "Unsupported Architecture" +#endif + +#define INTEL_ASM(_asm_str) asm volatile(".intel_syntax noprefix"); \ + asm volatile(_asm_str); \ + asm volatile(".att_syntax prefix"); +#define JUMPABLE_FUNC(fname) int fname(void) +#define JMP_FUNC_DECL(func) void *fptr = (void *)( &func ); +#define JMP_TO_FUNC \ + INTEL_ASM(" \ + call getip; \ + jmp short donext; \ + cfunc: \ + mov eax,[fptr]; \ + add eax,0x0; \ + jmp eax; \ + ret; \ + getip: \ + nop; \ + jmp short cfunc; \ + donext: \ + "); + +JUMPABLE_FUNC(testfkt); +JMP_FUNC_DECL(testfkt); + +JUMPABLE_FUNC(testfkt) +{ + int var0 = 0x1, var1 = 0x2, var2 = 0x3; + var0 += var1 + var2; + printf("Subroutine: %d = %d + %d\n", var0, var1, var2); + return 0; +} + +int main(int argc, char **argv) +{ + JMP_TO_FUNC; + return 66; +} |