Replies: 4 comments 3 replies
-
https://faultlore.com/blah/fix-rust-pointers/#aliasing
|
Beta Was this translation helpful? Give feedback.
-
I'm currently using UnsafeCell, which may be unsound, but mutable references to the io_uring struct are almost certainly unsound. |
Beta Was this translation helpful? Give feedback.
-
That's why I prefer using handles instead of structs. Handles are immutable because they are simply numbers, whereas structs are mutable and require consideration of aliasing and other issues. |
Beta Was this translation helpful? Give feedback.
-
In general, no, I wouldn't assume that you can safely apply For your Rust code, you should just stick with using the raw pointer, there's no need for You use Looking at how I did it in Rust last time, I had a helper C function: struct io_uring *rio_setup(unsigned int entries, unsigned int flags)
{
struct io_uring *ring = malloc(sizeof(*ring));
int errnum = io_uring_queue_init(entries, ring, flags);
if (0 != errnum)
{
return NULL;
}
return ring;
} . Re-examining this code, I'm actually not 100% sure this is correct but it worked fine for me with valgrind. I'd recommend just doing this from Rust as well. The reason for this is because you avoid needing the definition of the |
Beta Was this translation helpful? Give feedback.
-
Is the
io_uring
structure unaliased? In other words, if I allocate this structure, is my pointer the only pointer that points to this allocated memory?This is important because Rust's mutable references require them to be unaliased, otherwise UnsafeCell must be used.
Beta Was this translation helpful? Give feedback.
All reactions