Skip to content

Tag: assembly

get a char passed as parameter

I would like to write a function in NASM System V ABI x86-64 (Intel Syntax) that I could use in a C program. Here is the prototype of the function: I therefore retrieve the parameters in order (const char *s = rdi, int c = rsi) First, I get the character stored in the register rsi and put it in

assembly, how to use mprotect?

I am trying to make self modifying code in Linux. I thought it would works but didn’t. I used nasm on ubuntu 18.04. INT 0x80 return value is -22 0xffffffea I don’t know what is wrong. Answer Run your program under strace, like strace ./a.out to decode system call args and return values. Probably your base address isn’t page-aligned, or

Clang 11 and GCC 8 O2 Breaks Inline Assembly

I have a short snippet of code, with some inline assembly that prints argv[0] properly in O0, but does not print anything in O2 (when using Clang. GCC, on the other hand, prints the string stored in envp[0] when printing argv[0]). This problem is also restricted to only argv (the other two function parameters can be used as expected with

Why does the Linux Kernel copy implementation use the AC flag?

The implementation of copy_user_enhanced_fast_string in the Linux Kernel copy routine uses stac/clac in the epilog and prolog. perf annotate shows the following code: AC is “Alignment check (or access control) flag”. What is the reason stac/clac are used in the routine? What would be the consequences if we simply remove them? Answer Normally all page access checks are disabled in