简体   繁体   中英

Unable to allocate memory with mmap in x86 Linux Assembly Language

I have successfully opened a file and have the file descriptor (7) stored in FILE, and I also have the size of the file (153kb) stored in SIZE. That being said, this mmap system call returns a -14. I'm not sure what I'm doing wrong

push    %esi            #Save non-general-purpose registers
push    %edi            #Save non-general-purpose registers     
push    %ebp            #Save non-general-purpose registers

movl    FILE, %edi      #Move file descriptor into edi
movl    $0, %ebp         #Offset to 0
movl    $0x2, %esi       #MAP_PRIVATE
movl    $0x3, %edx       #PROT_READ
movl    FSIZE, %ecx     #File length
movl    $0, %ebx         # *addr = NULL
movl    $90, %eax        #mmap Sys Call
int     $0x80            #Call kernel
test    %eax, %eax      #Error check
js  _error  

MMAP 90 = $5A

Example of MMAP the framebuffer device fb0 using NASM with Intel-Syntax

%define XRes 400h
%define YRes 300h
%define Mapsize (XRes*YRes*4)  ; 1024x768x32

section .text

          call MAP_FB          ; mmap

;----------- Subroutine----
MAP_FB:   mov      eax, 5      ; syscall nr: open
          xor      edx, edx
          mov      ebx, DEVICE ; pointer/offset auf File/Device-Name
          mov      ecx, 2      ; /usr/include/bits/fcntl.h = O_RDWR
          int 80h
          mov      [FD], eax   ; File discriptor
          mov      ebx, MMAP
          mov      eax, 5Ah    ; mmap(90)
          int 80h
          mov      esi, eax    ; pointer mmap-FRAMEBUFFER
          ret

section .data
DEVICE DB "/dev/fb0", 0, 0, 0, 0

MMAP:  DD 0       ; start - suggest memory address to allocate
       DD Mapsize ; length
       DD 3       ; prot (PROT_READ + PROT_WRITE)
       DD 1       ; flags (MAP_SHARED = 1)
FD:    DD 0       ; file discriptor(handle)
       DD 0       ; offset into file to start reading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM