News for hackers. Stuff that matters.
Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by duaneb on Monday October 12, 2015 @07:12PM (#10377419)
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. :)

Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by oso2k on Monday October 12, 2015 @07:30PM (#10377480)
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

Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by duaneb on Monday October 12, 2015 @08:22PM (#10377717)
Yea, sbrk makes sense in a flat address space. I don't think it makes as much sense with virtual memory.
Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by gull on Monday October 12, 2015 @08:56PM (#10377827)
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.
Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by duaneb on Monday October 12, 2015 @09:43PM (#10377986)
Virtual memory isn't just for giving each process enough space. It's for security reasons, too.
Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by oso2k on Tuesday October 13, 2015 @04:19PM (#10383181)
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.

Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by koenigdavidmj on Monday October 12, 2015 @07:32PM (#10377485)
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.

Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by oso2k on Monday October 12, 2015 @07:37PM (#10377509)
Re:Show HN: Tiny C runtime Linux (rt0), HelloWorld 0.6k (i38... by duaneb on Monday October 12, 2015 @08:16PM (#10377700)
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.