Hacker News new | past | comments | ask | show | jobs | submit login
Restricting program memory (reduct.ru)
27 points by dzeban on Nov 25, 2014 | hide | past | favorite | 6 comments



Link at the correct address so there's 1MB between the end of the application image and the bottom of the stack. Allow the linker to load the shared libraries (or just link statically) and then use mmap to fill the rest of the virtual address space. You can implement this in multiple ways.

It's a bit of a weird exercise, you'd generally just calculate the maximum space used by the algorithm, maybe account for stack frame size if recursion is used.


There are problems on many accounts: you can forget all the dance around the heap, — malloc can (it sometimes will) just use mmap; catching malloc is not enough, you can directly mmap, or, and there's perfectly a fine stack you can utilize for 1M; you cannot restrict memory space because necessary libraries take considerate to 1M amount.

TL;DR: 1M is too small to do it.


1M is too small for what? For sorting? Dunno, will see next time when try to implement external merge sort :-). Too small for the whole program? Of course, it won't load runtime - I've shown it in container and qemu parts.


1M is sometimes all the memory that you have, on the embedded systems. And sometimes it is less. For example, it could be 68 bytes.

PIC 16F84A - 1K Program Memory, 68 bytes Data Memory, 64 bytes EEPROM


Where did the addresses used in the linker (.text and data) script come from? I work mostly in bare-metal embedded world and I use linker scripts but in my world the micro architecture defines where FLASH and RAM are located. How does it work when the application runs inside an OS?


It's virtual addressing, the loader maps the image at whatever address is specified (with some restrictions).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: