I want to call a system call (prctl) in assembly inline and retrieve the result of the system call. But I cannot make it work.
This is the code I am using:
int install_filter(void) { long int res =-1; void *prg_ptr = NULL; struct sock_filter filter[] = { BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_TRAP), /* If a trap is not generate, the application is killed */ BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), }; struct sock_fprog prog = { .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), .filter = filter, }; prg_ptr = &prog; no_permis(); __asm__ ( "mov %1, %%rdx\n" "mov $0x2, %%rsi \n" "mov $0x16, %%rdi \n" "mov $0x9d, %%rax\n" "syscall\n" "mov %%rax, %0\n" : "=r"(res) : "r"(prg_ptr) : "%rdx", "%rsi", "%rdi", "%rax" ); if ( res < 0 ){ perror("prctl"); exit(EXIT_FAILURE); } return 0; } The address of the filter should be the input (prg_ptr) and I want to save the result in res.
Can you help me?