tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] enforced immutability - proposed research project


From: Elijah Stone
Subject: Re: [Tinycc-devel] enforced immutability - proposed research project
Date: Mon, 18 Jan 2021 15:54:19 -0800 (PST)

On Mon, 18 Jan 2021, Michael Matz wrote:

Doing things at runtime also isn't super-easy: you either waste full pages for each allocation, no matter how small (in order to write-protect them at freeze), or you need to copy contents around (to write-controlled areas) invalidating addresses already pointing to it, or you need to do checked-writes for each memory write.

There's a much easier way I just realised, taking advantage of hardware protections. It's very performant, and even allows you to have both immutable and mutable references to the same memory.

You have to set up a shadow memory space; it's a distinct address space, but mapped to the same physical pages. But it has readonly permissions where the primary memory space has rw. To turn a regular reference into a const one, you add to it the offset between the regular memory space and the shadow space.

(You also have to make sure to compensate for addresses being in the shadow memory space, when comparing them. If you make the memory size a power of two, this gets easier, because you can just clear a high bit to 'disambiguate' addresses by forcing them out of the shadow space.)


The only problem is actually convincing the OS to map those addresses. On linux at least, MAP_FIXED seems to be mutually exclusive with MAP_SHARED. But I'm sure there's a way around that...

 -E



reply via email to

[Prev in Thread] Current Thread [Next in Thread]