by Animats · 1w ago · 0 comments
Where this is likely to bite today is on machines where some memory is shared between processors, and some isn't. That's non-uniform memory access.
That takes us back to banked memory. We see this most commonly when GPU memory is exposed to the CPU, but there are Intel processors which support multiprocessor mixed shared and non-shared access. Linux apparently supports this. Pointer arithmetic between pointers from different banks is not meaningful.
The general safe rule is that, at some level, something allocates memory, and it returns something for which arithmetic is valid only on a part. There may be suballocators, as with Vulkan. Vulkan has an allocator for big blocks, and applications then need an allocator which subdivides those big blocks.
This leads to slices. If a slice is safe, a subslice is also safe. If all operations are on slices, you're good. That's the Rust philosophy.
Historically, slices came very late. If someone had thought of slices in the 1970s, they probably would have been in C, which would have eliminated most of the need for pointer arithmetic. Slices are just bounded pointer arithmetic, really. That C lacks slices is the underlying cause of many headaches.
Yes and this went all the way to the point where even foreign device memory is now mapped into that address space. The address space is linear but its backing memory is not.
Linear address spaces are perfectly logical on the machine level because it is just an arrangement of bits which is easy for silicon to process.
The actual problem that we are hitting is that this linear address space is carved up into (possibly nested) bounded regions and you are not allowed to go outside the region for a given pointer. This is what CHERI, etc do, they add the region information back on the machine level which clears up the confusion.