flat assembler
Message board for the users of flat assembler.

Index > Linux > How to allocate memory in Linux dynamically (like malloc)

Author
Thread Post new topic Reply to topic
Ton



Joined: 06 Jan 2005
Posts: 22
Ton
Dear all,

In fasm I can allocate memory with e.g.
a0 rd 1024h

But how can I do this dynamically using system calls. Basically I need a
malloc(3), and free(3). I couldn't find the clue in the system call list, there is
no *alloc* there.

Best Regards,
Ton
Post 10 Feb 2005, 08:30
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
You have an excellent example: Take a look into the source of fasm. You will find it.
Post 10 Feb 2005, 12:11
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
It's syscall 45, called sys_brk, which resizes the memory block allocated for your program (the program resides on the bottom of this block, and with sys_brk you just move the top of it).
Post 10 Feb 2005, 12:18
View user's profile Send private message Visit poster's website Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
sys_brk is old style. Now it's preffered sys_mmap with anon mapping.

_________________
There's one more bug... Smile
Image
Post 10 Feb 2005, 16:11
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
However brk syscall is common for the Linux and all BSD systems (I'm not sure about BeOS), so I preferred it.
Post 10 Feb 2005, 16:21
View user's profile Send private message Visit poster's website Reply with quote
Ton



Joined: 06 Jan 2005
Posts: 22
Ton
Thanks for the pointers. Iĺl give it a try.

--
Ton
Post 10 Feb 2005, 16:52
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
there's also malloc and free in linux Smile
try: man 3 malloc
Post 11 Feb 2005, 12:48
View user's profile Send private message Visit poster's website Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
scientica wrote:
there's also malloc and free in linux Smile
try: man 3 malloc

But then he need link with libc...

_________________
There's one more bug... Smile
Image
Post 11 Feb 2005, 22:08
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.