Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i386), sbrk example added (github.com/lpsantil)
49 points by oso2k on Oct 12, 2015 | hide | past | favorite | 10 comments



Original HN announcement/discussion [https://news.ycombinator.com/item?id=8974024]. CFLAGS additions produce smaller binaries. HelloWorld in 608 bytes (i386) and 792 bytes (x86_64). An example of sbrk/brk provided in the test folder.


What is sbrk even used for anymore? Surely most heap allocators use mmap/mprotect directly these days. There's no downside.

EDIT: Not trying to rain on anyone's parade, I think the syscall mentioned is beside the point of the post. :)


I agree that sbrk/brk are nearly deprecated. But not all allocators I studied use mprotect or mmap. Most reference material (old OS books & blogs) still refer to sbrk/brk and/or malloc when discussing reference counters or garbage collectors. And Linux has a nice gotcha (see the Linux notes here[1]) in its implementation of the sys_brk syscall. It matches neither of the interfaces described for sbrk or brk exactly that most people are familiar with.

For me, however, I have a personal goal to show how to implement the basic newlib porting requirements [2].

[1] http://linux.die.net/man/2/brk

[2] http://wiki.osdev.org/Porting_Newlib


Yea, sbrk makes sense in a flat address space. I don't think it makes as much sense with virtual memory.


A flat address space is the future. You don't need virtual memory when a flat address space can hold all memory addresses for all processes as it does now with 64-bit processors.


Virtual memory isn't just for giving each process enough space. It's for security reasons, too.


Could you explain how virtual memory makes a process more secure? My intuition is that it would be another source of contention to manage (like CPU, RAM, IO, etc).

Maybe you're considering non-sequential address space an improvement for security. That I could see. ASLR would be another, which, you can see the effect of by multiple runs of t/_end.exe in rt0.


sbrk competes with mmap, not mprotect.

And yes, I would expect mmap to be used in most modern systems. OS X, for instance, just emulates sbrk with a large static buffer, and it has no actual effect on the page tables.



Updated, sorry, they almost seem like the same API to me—I've never used one without the other. I have no idea whether that's actually the case.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: