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

Improve FFI safety w.r.t. alignment and sizing #36

Closed
briansmith opened this issue Oct 20, 2015 · 6 comments
Closed

Improve FFI safety w.r.t. alignment and sizing #36

briansmith opened this issue Oct 20, 2015 · 6 comments

Comments

@briansmith
Copy link
Owner

See the checked_struct branch, particularly, cd53d14.

That is incomplete in that it doesn't address alignment from the Rust side. In particular, we assume that the alignment of u64 is 8 bytes, but we don't assert that.

It is also incomplete because it doesn't do the FFI checking for ring::digest.

@briansmith
Copy link
Owner Author

Partially fixed with 377f611. The work mentioned above still needs to be done. More work on checking alignment and size of other primitive types, like pointer types, is also needed.

@briansmith
Copy link
Owner Author

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57271. On ARM we may need to align to 16 or even 32 bytes for any function that might use NEON instructions that access memory.

@briansmith
Copy link
Owner Author

@briansmith
Copy link
Owner Author

See also rust-lang/rfcs#325 and rust-lang/rust#26403. Without a fix for that issue, we probably have to work around the problem by padding all our FFI context buffers with 16 or 32 extra bytes, and calculate the aligned addresses ourselves.

@briansmith
Copy link
Owner Author

C99 section 7.20.3: "The order and contiguity of storage allocated by successive calls to the calloc, malloc, and realloc functions is unspecified. The pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object or an array of such objects in the space allocated"

@briansmith
Copy link
Owner Author

The situation for ring::digest was mostly fixed in 8cb362f.

@briansmith briansmith closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant