Re: Mem under Linux
- From: Charles Crayne <ccrayne@xxxxxxxxxx>
- Date: Sun, 30 Dec 2007 01:23:51 -0800
On 30 Dec 2007 07:27:43 GMT
Thomas Jensen <tj@xxxxxxxx> wrote:
Can someone help me with a link to a tutorial or a book, where I can
learn about memory in Linux, so I can make dynamic allocations with
syscalls, without malloc.
Here is some working code, in FASM format. Feel free to ask questions.
;allocate and initialize heap
initheap:
pusha
mov eax,__NR_brk ;brk
xor ebx,ebx ;get current end
int 80h ;query kernel
mov [faqehd],eax ;start of new allocation
mov ebx,eax ;previous end of data
add eax,8 ;first faqe
mov [bfrhd],eax ;start of heap
add ebx,40000h ;allocate 256k bytes
mov eax,__NR_brk ;brk
int 80h ;kernel call
mov [bfrtl],eax ;end of allocated area
or eax,eax ;test return
jns initheapok ;good return
err 205h ;allocation failed
jmp initheapexit ;done
initheapok:
mov esi,[bfrhd] ;start of heap
mov eax,[bfrtl] ;end of heap
sub eax,esi ;length of allocation
call inibuf ;intialize heap
initheapexit:
popa
ret
.
- References:
- Mem under Linux
- From: Thomas Jensen
- Mem under Linux
- Prev by Date: Mem under Linux
- Next by Date: NASM page
- Previous by thread: Mem under Linux
- Next by thread: Re: Mem under Linux
- Index(es):