-
Notifications
You must be signed in to change notification settings - Fork 348
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
Project idea: strongly typed file descriptor integers and deduplication of various checks around them #3772
Comments
It would also be good to be able to write something like EDIT: Oh, that's what |
These constants (almost?) always have a corresponding ErrKind, so I think we can transform them to |
It seems silly to construct a Result if we hard-code the Err variant - at least we want a method that takes an io::Errror.
But I am not sure we can always construct an ErrorKind.
|
Separate idea: instead of hardcoding the io::Result to integer conversion logic, we add a new enum around |
Use Scalar consistently in foreign item emulation Step 0 of #3772 This just makes the code consistent. While we could also go for consistency the other way, that would only allow us to use integers in some cases where we use `Scalar` right now, because `Scalar` can also hold pointers where applicable. There's also no danger in messing up (even though we do lose some compile-time checks), as `Scalar` knows the size of the integer stored within, so it will check that against the destination when it is written. In fact, this makes the checks much stronger compared with `write_int`, which just checks that the integer fits into the destination size.
What's the status of this issue? A good chunk of this is taken care of - I could look into fixing any additional pieces. |
It seems like all steps other than step 0 are not implemented yet. |
I am not convinced that using We also have way fewer FD numbers floating around now, so a newtype seems less critical -- but could still be a bit of extra type safety. Or it might just be annoying overhead. Hard to say without trying it. :) |
This is less of a fundamental/large-in-behavior change and more a very bitrotty change with possibly not-really-deduplicating-that-much changes that hopefully still make the code more manageable.
Problem statement
Currently we represent file descriptors just as
i32
within miri. We mix them with various negative integer values for signalling errors, just like libc does. We also duplicate a lot of error handling logic likeand
Solution parts
Scalar
instead ofi32
as the return type of foreign function handlers (groundwork for the following, as we inconsistently usei32
andScalar
. Even usingScalar
wheni32
would definitely suffice, not just when it could be a pointer).i32
known-to-be-file-descriptors in a newtype struct together with some convenience functions for reading them and getting the integer back out (into a scalar)io::Result<FileDescriptionRef>
(or the reference versions) from the various getters, instead ofOption<FileDescriptionRef>
. Forward that where useful, avoiding explicit-1
returns paired withset_last_error
, instead handling it withtry_unwrap_io_result
get_mut
,get
, anddup
methods toFdTable
that returnio::Result
instead ofOption
, even though the only io error they ever return isNotFound
, allowing us to?
away their resultThe text was updated successfully, but these errors were encountered: