News for hackers. Stuff that matters.
Re:Linear Address Spaces: Unsafe at any speed by jasonhansel on Wednesday June 29, 2022 @09:33PM (#31927799)
Well, unless you're implementing malloc using e.g. sbrk().
Re:Linear Address Spaces: Unsafe at any speed by kllrnohj on Wednesday June 29, 2022 @10:22PM (#31928115)
Although you shouldn't be on a modern system, you'd instead be implementing malloc on top of mmap. So remove sbrk, and make mmap the "object allocator", and tada! You don't really need linear virtual address spaces anymore.
Re:Linear Address Spaces: Unsafe at any speed by gary_0 on Wednesday June 29, 2022 @10:56PM (#31928300)
Newer allocators like mimalloc[0] don't even support sbrk (I think jemalloc still does). Mimalloc seems to have some interesting features.

[0] https://github.com/microsoft/mimalloc

Re:Linear Address Spaces: Unsafe at any speed by hiker on Thursday June 30, 2022 @04:04AM (#31929864)
It still supports sbrk since it's available on WebAssembly but mmap is not.

https://webassembly.org/docs/faq/#what-about-mmap

Re:Linear Address Spaces: Unsafe at any speed by trasz on Thursday June 30, 2022 @09:53AM (#31932360)
Newer kernels like arm64 FreeBSD don't even support sbrk(2).
Re:Linear Address Spaces: Unsafe at any speed by astrange on Wednesday June 29, 2022 @11:28PM (#31928459)
Yes, this is why malloc() can't actually be implemented in C. Actual implementations of it exist because of special compiler dispensation, or mostly that the callers and implementations are in separate libraries so the implementation isn't visible to the caller.
Re:Linear Address Spaces: Unsafe at any speed by kazinator on Thursday June 30, 2022 @02:49PM (#31936818)
malloc perhaps can't be implemented in the abstract dialect called ISO C. It can be impemented in GNU C, and others.
Re:Linear Address Spaces: Unsafe at any speed by astrange on Thursday June 30, 2022 @07:51PM (#31940261)
It can't. GNU C adds a malloc attribute:

> Attribute malloc indicates that a function is malloc-like, i.e., that the pointer P returned by the function cannot alias any other pointer valid when the function returns, and moreover no pointers to valid objects occur in any storage addressed by P. In addition, the GCC predicts that a function with the attribute returns non-null in most cases.

But it doesn't provide any operations to do the things in this paragraph (create new pointers). The operation that does this is malloc itself.

This will typically not cause problems, but it would if LTO got so good you could include libc in it.