r/ProgrammingLanguages • • Oct 14 '26

Improved article about memory safety

Thank you to everyone who gave feedback on my article about memory safety.

I used the input to vastly improve the article (see "Achieving memory safety").

Please take a look and share your thoughts again and consider starring the Seed7 project on GitHub.

13 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/ThomasMertes Oct 14 '26 edited Oct 14 '26

Does Seed7 restrict IO operations in any way?

Depending on how you opened a file reading or writing might not be allowed and attempting to do so will trigger the exception FILE_ERROR. Beyond this, there are no restrictions.

On many operating systems, if you can do IO, you can read arbitrary memory through various mechanisms (on Linux, via the /proc filesystem). This is the case for most memory-safe languages and is usually not considered a major problem, but it means you need to be very precise about what exactly Seed7 guarantees.

This wasn't on my radar. I expected that operating system privileges would handle that, but this seems not to be the case. I asked Google AI and got:

Under Linux, no special or elevated privileges (like root or capabilities) are needed to read the memory of your own process via the /proc file system.

I need to consider that.

There are languages in which functions absolutely cannot do this, but they tend to be languages that require you to be explicit about IO in the type system.

How is this done?

I can imagine that the functions that open a file, look at the path and fail if the memory of the own process is requested. But this is operating system specific and it might not be easy to make it 100% correct.

Maybe it is possible to tell the OS that accessing the own memory should not be allowed for the current process. I saw that on Linux there is prctl() and seccomp(). Maybe these can be used.

How does Seed7 deal with circular references and the risk of memory leaks?

Contrary to languages with pointers, Seed7 was not designed to support implementing low-level data structures such as linked lists. So instead of using pointers to create e.g. linked lists Seed7 proposes using container types like array and hash to build complicated data structures.

That said, circular references could lead to memory leaks. BTW., neither the Seed7 example programs nor the Seed7 run-time libraries contain any circular reference.

Usually the formal proof is the first step, and only very rarely is the actual implementation proven correct as well.

When using a programming language the memory safety of the actual implementation is what counts. It does not help if a language is formally proven to be memory safe if it is not in practice.