2014-04-07 64 views
0

我已經成功地打開了一個文件,並且在FILE中存儲了文件描述符(7),並且我還有SIZE中存儲的文件大小(153kb)。這就是說,這個mmap系統調用返回一個-14。我不知道我在做什麼MMAP的錯誤無法在x86 Linux中使用mmap分配內存Linux彙編語言

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 
+0

你嘗試過它在C?如果你這樣做,你有比較生成的代碼嗎? –

+0

嘗試「strace」你的程序。 –

+0

我看到sys_mmap(= 90)將一個指針指向'ebx'中的「args」結構。可能的sys_map2(= 192)在'ebp'中使用一個參數? –

回答

1

MMAP 90 = $ 5A

實例幀緩衝設備使用FB0 NASM與Intel的語法

%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