1 year ago

#376875

test-img

Mike

mmap() system call linux 32-bit x86 NASM(i386)

I am trying to use mmap for my code but I dont have a clue to choose the values to store in the registers in pre interrupt processing. I picked up below part of code from somewhere. I am trying to print the return value (ig this will be stored in eax) after the interrupt but the value is negative(-14) which means the process is unsucessfull what should I change here?

mov     ebx,0                ;address

mov     edx,0x1              ;protection

mov     esi,0x2              ;flags

mov     edi,[file_descriptor];file descriptor

mov     ecx,4096             ;size

mov     ebp,0                ;offset is 0

mov     eax,192              ;mmap instruction code(90)

int     0x80                 ;For mmap

PutLInt eax                  ;printing the returned value after the system-call

I am getting strace output as:

        strace ./a
execve("./a", ["./a"], 0x7ffcdf6517c0 /* 49 vars */) = 0
strace: [ Process PID=20342 runs in 32 bit mode. ]
read(0, 3
"3\n", 256)                     = 2
creat("input.txt", 0700)                = 3
read(0, 4
"4\n", 20)                      = 2
write(3, "4\n", 2)                      = 2
read(0, 5
"5\n", 20)                      = 2
write(3, "5\n", 2)                      = 2
read(0, 6
"6\n", 20)                      = 2
write(3, "6\n", 2)                      = 2
write(1, "\n", 1
)                       = 1
write(1, "3", 13)                        = 1
write(1, "\n", 1
)                       = 1
write(1, "3", 13)                        = 1
write(1, "\n", 1
)                       = 1
mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0) = -1 EACCES (Permission denied)
write(1, "-", 1-)                        = 1
write(1, "1", 11)                        = 1
write(1, "3", 13)                        = 1
exit(0)                                 = ?
+++ exited with 0 +++

linux

assembly

x86

system-calls

mmap

0 Answers

Your Answer

Accepted video resources