Skip to content

Instantly share code, notes, and snippets.

@totem3
Last active August 29, 2015 14:07
Show Gist options
  • Save totem3/438a5cf79b121978064b to your computer and use it in GitHub Desktop.
Save totem3/438a5cf79b121978064b to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf("Hello World!\n");
return 0;
}
#define INLINE_SYSCALL(name, nr, args...) \
({ \
unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
{ \
__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
resultvar = 0xffffffff; \
} \
(int) resultvar; })
# define INTERNAL_SYSCALL(name, err, nr, args...) \
({ \
register unsigned int resultvar; \
EXTRAVAR_##nr \
asm volatile ( \
LOADARGS_##nr \
"movl %1, %%eax\n\t" \
"int $0x80\n\t" \
RESTOREARGS_##nr \
: "=a" (resultvar) \
: "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
(int) resultvar; })
/*
* # define LOADARGS_3 \
* "xchgl %%ebx, %%edi\n\t"
*
* # define RESTOREARGS_3 \
* "xchgl %%edi, %%ebx\n\t"
*
* __NR_execve = 11 (unistd.h)
*
* # define ASMFMT_3(arg1, arg2, arg3) \
* , "b" (arg1), "c" (arg2), "d" (arg3)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment