Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory safety approach using standard libraries? #17

Open
maxxoccupancy opened this issue Feb 29, 2024 · 0 comments
Open

Memory safety approach using standard libraries? #17

maxxoccupancy opened this issue Feb 29, 2024 · 0 comments

Comments

@maxxoccupancy
Copy link

Sorry, total newb here. For memory safe code, would it be possible to borrow a trick from Rust and do the following with Zig:
i. All hand rolled, custom code must be provably safe, following memory management rules, or the code does not compile.
ii. Standard libraries, which have been examined in detail and thoroughly tested by thousands of software devs, could use heap allocation, arenas, reallocation, etc, that would not be directly available to custom code.

Using whiteboard:

struct bibliography:
    name = "Unknown title"
    author = "Unknown author"
    uint_fast8_t numPages, numPics, numChapters

bibliography* Moby = { "Moby Dick", "Dick Moby", 250, 11}    //object added to heap with ptr Moby, numChapters is initialized to 0

The compiler recognizes bibliography* as a unique pointer so that the memory space gets freed automagically (unless that space is immediately reallocated when Moby is slain). For your custom code, the compiler then allows this since it's using smart pointers.

However, if the program uses the standard library, the library writers would be free to come up with all sorts of fast, clever memory management, arenas, etc, since that code is peer-reviewed up the yin yang. That is to say that the code is carefully analyzed BEFORE the latest update to the compiler, which can therefore depend on its memory safety and ruggedness.

Most of the security problems with C/C++ are the result of programmers not following those strict memory management rules, so C#, Java, Python, etc, just use a garbage collector with lots of overhead and unacceptable stalls at runtime. Rust prevents code from compiling if the strict rules are not followed.

Using these two tools, no memory unsafe code would end up in production code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant