MemeAssembly icon indicating copy to clipboard operation
MemeAssembly copied to clipboard

[Command suggestion] `it's free real estate [number/register]`

Open kammt opened this issue 3 years ago • 4 comments

Command Syntax: (e.g. stonks [register]) it's free real estate [register/number]

Command Description: Allocates the provided number of Bytes on the Heap and returns a pointer to the starting address. If the allocation failed, 0 is returned. The memory block cannot be freed - because who does that anyway? (hides)

Which x86_64 Assembly instruction(s) would be used to translate this command? For a possible implementation, see https://github.com/xarantolus/memeasm/blob/main/malloc/malloc.memeasm

What could this command be useful for? Well.. heap allocation

What Meme is your command based on? (You can also provide a link to e.g. its KnowYourMeme page) https://knowyourmeme.com/memes/its-free-real-estate

kammt avatar Jun 19 '22 10:06 kammt

There's also an x86-64 implementation here, the MemeAssembly version was translated from it.

One thing to note is error handling: the implementation detects if we didn't get any more memory at all (old break == new break), but it doesn't check if we got enough memory (not sure if the kernel would ever return less than we expected instead of the old break, indicating error). Maybe one should do that for a better implementation, or we just follow the MemeAseembly standard in that case

xarantolus avatar Jun 19 '22 10:06 xarantolus

When using a libc (which we do, the programs start at main), using brk is extremely likely to break things. Why not just call... malloc? Otherwise, mmap could be used for memory allocation.

aengelke avatar Jun 20 '22 07:06 aengelke

using brk is extremely likely to break things

Ah, that's why the syscall is called brk :flushy:

kammt avatar Jun 20 '22 11:06 kammt

brk is literally the abbreviation for "break" ^^

aengelke avatar Jun 20 '22 12:06 aengelke