News for hackers. Stuff that matters.
Re:Linear Address Spaces: Unsafe at any speed by e63f67dd-065b on Wednesday June 29, 2022 @09:11PM (#31927651)
Oh boy, welcome to the exciting world of C pointer provenance :) What you just described is what compiler people call pointer provenance, where each pointer has, in addition to the address, a second piece of info attached to it that describes all the places to which the pointer can point.

This is an extremely simplified and probably incorrect view of https://open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1434r0.... This is complicated because nobody agrees on what the correct behaviour should be, and we have mountains of legacy codebases that all rely on something slightly different when pointers get converted to ints and back.

Re:Linear Address Spaces: Unsafe at any speed by gary_0 on Wednesday June 29, 2022 @09:22PM (#31927722)
That's what makes C programming fun: doing what the compiler/language people say you shouldn't be doing and seeing if it works anyways. At least, it works on my machine...
Re:Linear Address Spaces: Unsafe at any speed by pjmlp on Thursday June 30, 2022 @01:47AM (#31929038)
Until the compiler gets upgraded....
Re:Linear Address Spaces: Unsafe at any speed by adrianN on Thursday June 30, 2022 @03:21AM (#31929592)
Until changes in seemingly far away code change the optimization decisions the compiler makes...
Re:Linear Address Spaces: Unsafe at any speed by phkamp on Thursday June 30, 2022 @03:51AM (#31929780)
That is actually the R1000's raison d'etre:

Rational built a truly semantic IDE, and the result of that is that if you change a line of source-code somewhere in a huge complicated project, it will know precisely what the consequences of that change are.

Ultimately, this allows it often just recompile that single line.

Re:Linear Address Spaces: Unsafe at any speed by verdagon on Wednesday June 29, 2022 @10:29PM (#31928158)
That sounds like the "generation" tag in Vale's generational references [0] or like how memory tagging works on ARM CPUs [1].

I love the approach, it's a way to get a lot more memory safety while not giving up a program's flexibility, especially in C's case.

Some languages are opting to disallow pointer arithmetic and conversion between integers and pointers. We'll see how it works out!

[0] https://verdagon.dev/blog/generational-references

[1] https://developer.arm.com/-/media/Arm%20Developer%20Communit...

Re:Linear Address Spaces: Unsafe at any speed by anonymoushn on Thursday June 30, 2022 @04:28AM (#31929993)
The part of this that I most enjoy is that you cannot even obtain some memory from your own allocator implemented on top of mmap or on top of malloc, store ints in it, return it to the allocator, ask the allocator for memory again and receive the same memory back, and store doubles in it.
Re:Linear Address Spaces: Unsafe at any speed by gpderetta on Thursday June 30, 2022 @05:28AM (#31930305)
Yes, notoriously you can't implement malloc in portable C.

In C++, I think they added enough magic in that you should now be able to do it (placement new, std::launder and numerous other hacks).

Re:Linear Address Spaces: Unsafe at any speed by rkangel on Thursday June 30, 2022 @11:15AM (#31933563)
I've implemented a pools allocator for embedded devices a couple of times. Allocating memory for callers out of a block of static memory. I thought it was portable C. Which detail of the standard did I not realise I was running into?
Re:Linear Address Spaces: Unsafe at any speed by gpderetta on Thursday June 30, 2022 @02:23PM (#31936457)
I assume the block of static memory was a large static char array.

My understanding that reusing the storage would violate the aliasing rules[1] and the rules against overlapping object lifetimes.

[1] while char ptrs can be used to access everything, the reverse is not allowed.

Re:Linear Address Spaces: Unsafe at any speed by teddyh on Thursday June 30, 2022 @09:29AM (#31932101)
Reportedly you can implement malloc in C, using mmap().
Re:Linear Address Spaces: Unsafe at any speed by gpderetta on Thursday June 30, 2022 @09:35AM (#31932165)
well mmap is posix, not standard portable C.
Re:Linear Address Spaces: Unsafe at any speed by raverbashing on Thursday June 30, 2022 @04:24AM (#31929976)
So instead of giving that metadata to the programmer the C language says F U and tells me only knowing where to put it is enough, right?

"hey you allocated it you should know about it right?" right yeah

Re:Linear Address Spaces: Unsafe at any speed by simiones on Thursday June 30, 2022 @09:09AM (#31931897)
To be clear, that metadata only (generally) exists in principle - it is not actually materialized and stored anywhere, even at compile time (definitely not at runtime). There may be cases where the compiler actually tracks it, but most often it is only tracked "best effort" - the compiler only needs to prove that two pointers can't be aliased based on any possible value of that metadata, not actually compute that metadata and use it.