我正在尝试创建一个接受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
答案 0 :(得分:0)
您正在将指针作为参数传递给系统调用,在执行int 0x80之前,它应该是ema中的mmaps系统调用号。