我正在尝试制作一个接受ptr和mmap参数的宏,然后相应地设置它。这是我到目前为止所拥有的:
#define MY_MMAP(PTR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \
({ \
int x = 90; \
asm ( \
"movl %1, %%eax \n" \
"movl %2, %%ebx \n" \
"movl %3, %%ecx \n" \
"movl %4, %%edx \n" \
"movl %5, %%esi \n" \
"movl %6, %%edi \n" \
"movl %7, %%ebp \n" \
"int $0x80 \n" \
"movl %%eax, %0" \
:"=r" (PTR) \
: "eax" (x) ,"ebx" (ARG1), "ecx" (ARG2), "edx" (ARG3), "esi" (ARG4), "edi" (ARG5), "ebp" (ARG6) \
: \
); \
})
但是,当我使用它时,此代码不起作用。有人可以帮我吗?
char * readBuffer;
MY_MMAP(readBuffer, 0, (sizeOfRead + 1), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1 ,0);
这是由 gcc 制作的汇编代码:
movl %eax, %eax
movl $0, %ebx
movl %ecx, %ecx
movl $3, %edx
movl $34, %esi
movl $-1, %edi
movl $0, %ebp
int $0x80
mov %eax, %ebx