Re: Mem under Linux



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

.