3

So I'm using NASM on linux and I was curious how this is done. All the info I can find online uses functions from C like malloc(). Can this be done purely with assembly code? Perhaps via a system call?

Thanks.

Lonely Lad
  • 31
  • 2

1 Answers1

6

On Linux you can use the brk syscall to extend you data segment. First call brk(0) to find the break point and then extend your data segment every time you run out of memory. Another syscall to look into would be mmap, malloc uses both.

You can find a very nice explanation (and a simple memory manager written in assembly) in Chapter 9 of this book, though it might be a bit inaccessible since it uses x86 and AT&T syntax instead of x64 and NASM. But the general idea should still be applicable to x64 assembly.

Happy hacking :]

Knogger
  • 2,049
  • 3
  • 15