mmap在汇编器中不起作用

时间:2018-07-15 11:10:47

标签: c++ linux assembly mmap

我在asm和c ++中写了2个相同的代码。

ASM

         PROT_READ          equ     1    ; Page can be read.  */
         PROT_WRITE         equ     2    ; Page can be written.  */
         PROT_EXEC          equ     4    ; Page can be executed.  */
         PROT_NONE          equ     0    ; Page can not be accessed.  */

         MAP_SHARED         equ     1
         MAP_PRIVATE        equ     2
         MAP_FIXED          equ     10h
         MAP_TYPE           equ     0Fh
         MAP_FILE           equ     0
         MAP_ANON           equ     20h
         MAP_ANONYMOUS      equ     MAP_ANON
         MAP_32BIT          equ     40h
         MAP_NORESERVE      equ     4000h
         MAP_GROWSDOWN      equ     0100h
         MAP_DENYWRITE      equ     0800h
         MAP_EXECUTABLE     equ     1000h
         MAP_LOCKED         equ     2000h
         MAP_POPULATE       equ     8000h
         MAP_NONBLOCK       equ     10000h
         MAP_STACK          equ     20000h
         MAP_HUGETLB        equ     40000h

        .code

    _start:

        main proc

                 mov rdi, 0
                 mov rsi, 4095
                 mov rdx, PROT_WRITE or PROT_READ
                 mov rcx, MAP_ANONYMOUS or MAP_PRIVATE or MAP_GROWSDOWN
                 mov r8, -1
                 mov r9, 0

                 mov rax, 9 ; mmap
                 syscall

         main endp

    end

C ++

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/mman.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>

    int main()
    {

        int *map = mmap(0, 4096, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0);

        printf ("%x\n", map);

        return 0;
    }

相同。但只能在c ++中使用,asm返回0xfffffffffffffffff7错误。请告诉为什么为什么不能在asm中工作?

这将以等宽字体显示。前四个空格     将被删除,但所有其他空格将保留。

Markdown and HTML are turned off in code blocks:
<i>This is not italic</i>, and [this is not a link](https://example.com)

0 个答案:

没有答案