Skip to content

custom socket-like file descriptors#111

Open
gkgoat1 wants to merge 18 commits intoturbolent:mainfrom
portal-co:custom_fds
Open

custom socket-like file descriptors#111
gkgoat1 wants to merge 18 commits intoturbolent:mainfrom
portal-co:custom_fds

Conversation

@gkgoat1
Copy link
Contributor

@gkgoat1 gkgoat1 commented Feb 6, 2025

This adds custom socket-like FDs to w2c2, which is useful for virtualization.

This code has been reformatted, but there was no clang-format file. In addition, I do not know if the code is still C89; Please comment if any of those issues come up.

@turbolent
Copy link
Owner

@gkgoat1 Thank you for this contribution! I like this idea 👍

The PR is currently really hard to review, because it's almost impossible to see what was actually changed. Could you please avoid /revert the irrelevant re-formatting?

@gkgoat1
Copy link
Contributor Author

gkgoat1 commented Feb 9, 2025

@gkgoat1 Thank you for this contribution! I like this idea 👍

The PR is currently really hard to review, because it's almost impossible to see what was actually changed. Could you please avoid /revert the irrelevant re-formatting?

Do you have a .clang-format file or similar I can use to restore the formatting?

@turbolent
Copy link
Owner

@gkgoat1 No, I don't use clang format, it might be worth investigating.

Thank you for removing the re-formatting, it's now clear what you're trying to add. I'll open a follow up PR to improve the API a bit and address some of the problems.

@gkgoat1
Copy link
Contributor Author

gkgoat1 commented Jun 14, 2025

Are you still looking at this PR? You mentioned a follow-up PR, so I assumed this would be merged.

Copy link
Owner

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look through all places where the descriptor's fd, path, and dir fields are accessed and it looks like the following functions still need to handle non-native descriptors:

  • wasiFdFdstatGet
  • wasiPathFilestatGet
  • wasiPathRename
  • wasiPathUnlinkFile
  • wasiPathRemoveDirectory
  • wasiPathCreateDirectory
  • wasiPathSymlink
  • wasiPathReadlink
  • wasiFDReaddir
  • wasiDirectorySet

What if there is no distinction between native and non-native descriptors, and the callback are only used if they are set (e.g. when reading, writing, etc.)?

wasi/wasi.c Outdated

bool
WARN_UNUSED_RESULT
wasiFileDescriptorAddStruct(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is duplicating the last part of wasiFileDescriptorsAdd, adding the descriptor to the descriptors.

Maybe refactor the existing code a bit more:

  • Rename this function to wasiFileDescriptorsAdd
  • Rename the existing wasiFileDescriptorsAdd to something that indicates it is adding a native descriptor. Maybe wasiFileDescriptorAddNative?
  • Rename this new function to something that indicates it is adding the non-native/callbacks descriptor

wasi/wasi.h Outdated
};
} WasiFileDescriptor;

#define wasiIsNative(d) d.fd != -2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the magic number -2 here? Is the idea that wasiFileDescriptorAddStruct is called with fd = -2 when the callbacks are set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a tag indicating the descriptor is non-native

@gkgoat1
Copy link
Contributor Author

gkgoat1 commented Aug 18, 2025

What if there is no distinction between native and non-native descriptors, and the callback are only used if they are set (e.g. when reading, writing, etc.)?

The goal of this PR is to create streaming file descriptors without a native file backing it, so either we distinguish native and non-native descriptors, or implement a complete VFS all in one PR--a hard-to-review almost-full refactor. That may be something we consider later on, but right now having this distinction would enforce the stream-like nature of non-native descriptors.

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

Successfully merging this pull request may close these issues.

2 participants