kubkon opened Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
kubkon assigned Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
kubkon assigned Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
kubkon labeled Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
kubkon labeled Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
kubkon labeled Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
sunfishcode commented on Issue #1308:
In an application which opens and closes many handles, we'll want to be able to reuse handle values. To support this, we'll need to move away from "add one to a handle" and toward "ask the context for a free handle", and have the context reuse closed handles.
alexcrichton commented on Issue #1308:
I'd imagine the same as @sunfishcode where it seems like the underlying code should best be changed to something that doesn't require this sort of addition. It sounds like an
FdSet
which has something like anallocate
anddeallocate
method which tracks all the indices is probably what's best here?
kubkon commented on Issue #1308:
I’m glad I run it past both of you! It makes perfect sense for the context to provide next available handle.
Since this is essentially required to swap
wig
forwiggle
, I’m gonna provide a draft PR of how I’d see this work and we can carry on our discussion there. Does that make sense to y’all?
sunfishcode commented on Issue #1308:
Makes sense!
kubkon commented on Issue #1308:
I’m gonna go ahead and close this one since we’ve solved the issue in #1329.
kubkon closed Issue #1308 (assigned to pchickey):
As in the title, pre-
wiggle
, we didn't really deal with a concept of WASI handle, and file descriptor was simply a type alias. Now, withwiggle
, we can and should handle "handles" properly.My question now is, how should we obtain a handle from another one in
wasi-common
? Until now (whenFd
was a simple type alias) we did:let new_fd = if let Some(fd) = old_fd.checked_add(1) { fd } else { Overflow }Since
Fd
is now a "supertype", it's no longer that obvious what to do. My initial thought was to provide an unsafe accessor to the underlying value inwiggle
, i.e., something like:pub struct Fd(u32); impl Fd { pub unsafe fn inner(&self) -> u32 { self.0 } }Then, we could re-use most of the code in
wasi-common
to obtain a new handle as follows:let new_fd = if let Some(raw) = unsafe { old_fd.inner() }.checked_add(1) { Fd::from(raw) } else { Overflow }I'm wondering though if you guys reckon there is a better, cleaner way of dealing with this? Perhaps a method on the handle type,
next() -> Self
say, that will return another valid handle. But then, I guess it won't necessarily possess a notion of valid means without having access to the current WASI context object, right?cc @alexcrichton I thought might be of interest for you as well.
Last updated: Nov 22 2024 at 17:03 UTC