Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
[GAS] Dynamic memory allocation
  • GT3X
    Posts: 20
    In asm u can allocate the memory dynamc with the syscall mmap. With the following code a memoryrange gets allocated during the runtime. The startadress is in the %eax register. So nothing special


    .data
    .comm mmap_, 24
    .text
    .macro alloc length

    #prepare params for mmap
    movl $0, mmap_ # 0- Startadress gets selected from Kernel
    movl \length, mmap_+4 #size of Adressrange
    movl $3, mmap_+8 #PROT_WITE / PROT_READ 0x02, 0x01
    movl $34, mmap_+12 #map anonymously (0x20), map_private(0x20)
    movl $-1, mmap_+16 #fd -1 portability
    movl $0, mmap_+20 # offset ignored

    #allocate memory
    movl $90, %eax
    leal mmap_ , %ebx
    int $0x80
    .endm


    too release it


    .macro free address length
    movl $91, %eax
    movl \address, %ebx
    movl \length, %ecx
    int $0x80
    .endm
  • Xin
    Posts: 3,251
    Good job keep it up
    Xin