Pregunta algo nueva sobre Assy y el montón.

Ultimately I am just trying to figure out how to dynamically allocate heap memory from within assembly.

If I call Linux sbrk() from assembly code, can I use the address returned as I would use an address of a statically (ie in the .data section of my program listing) declared chunk of memory?

I know Linux uses the hardware MMU if present, so I am not sure if what sbrk returns is a 'raw' pointer to real RAM, or is it a cooked pointer to RAM that may be modified by Linux's VM system?

Leo esto: ¿Cómo se implementan sbrk / brk en Linux?. I suspect I can not use the return value from sbrk() without worry: the MMU fault on access-non-allocated-address must cause the VM to alter the real location in RAM being addressed. Thus assy, not linked against libc or what-have-you, would not know the address has changed.

Does this make sense, or am I out to lunch?

preguntado el 09 de enero de 11 a las 03:01

Is there still a true sbrk syscall? I thought it had been deprecated (in favour of mmap) ages ago. E.g. FreeBSD doesn't have one anymore. Could be that the linux flavour is x86 specific. -

x86 Linux (OpenSuSE 11.3) still has a man page for sbrk(2) & brk(2). But it does say this: "CONFORMING TO 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001." So not sure. I only started considering calling something lower level than malloc() yesterday, if I find sbrk/brk is not used I'll try to post back here. -

Hmm, it also says: Avoid using brk() and sbrk(): the malloc(3) memory allocation package is the portable and comfortable way of allocating memory. Various systems use various types for the argument of sbrk(). Common are int, ssize_t, ptrdiff_t, intptr_t. -

1 Respuestas

Unix user processes live in memoria virtual, no matter if written in assembler of Fortran, and should not care about physical addresses. That's kernel's business - kernel sets up and manages the MMU. You don't have to worry about it. Fallos de página are handled automatically and transparently.

sbrk(2) devuelve un dirección virtual specific to the process, if that's what you were asking.

Respondido el 09 de enero de 11 a las 06:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.