无法使用x86 Linux汇编语言中的mmap分配内存 [英] Unable to allocate memory with mmap in x86 Linux Assembly Language

查看:112
本文介绍了无法使用x86 Linux汇编语言中的mmap分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功打开一个文件并将文件描述符(7)存储在FILE中,并且我还将文件大小(153kb)存储在SIZE中.就是说,此mmap系统调用返回-14.我不确定自己在做什么错

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

MMAP 90 = $5A

使用具有Intel语法的NASM的MMAP帧缓冲设备fb0的示例

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

这篇关于无法使用x86 Linux汇编语言中的mmap分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆