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

Does this structure packing size and alignment of WasiAddrinfo match the c++ host code's __wasi_addrinfo_t #83

Open
danielblignaut opened this issue Mar 17, 2023 · 0 comments

Comments

@danielblignaut
Copy link

Hi,

I'm comparing the sockets client code here:

pub enum AiFlags {

with the host functions in the engine here:
https://github.com/WasmEdge/WasmEdge/blob/0bbc4f7d28f8bdbd37175a174f15d4f9a61953f7/thirdparty/wasi/api.hpp#L1759

It looks like this mapping from the rust enum to the c++ bitflag is not correct?

The Rust enum AiFlags does not map directly to any specific C++ enum value because Rust's AiFlags::AiPassive has an explicit discriminant of 0, while in the C++ code, __WASI_AIFLAGS_AI_PASSIVE has an implicit discriminant of 1 (since it's defined as 1ULL << 0). In other words, the Rust enum AiFlags is zero-based, while the C++ enum __wasi_aiflags_t is one-based. Therefore, there is no direct mapping between them.

However, I'm guessing "this just works" for AiPassive because in the context of getaddrinfo, the AI_PASSIVE flag is defined to have a value of 0 in POSIX, so it's possible that AiFlags::AiPassive could be used to represent __WASI_AIFLAGS_AI_PASSIVE with a value of 0 in C++.

However, the other enum values will therefore map incorrectly as it currently stands... I'm not very good at either C++ or Rust, but can anyone validate that this is correct?
and in fact either the rust enum needs to change to be indexed starting from 1, not 0 or the bit flags should change to:
__WASI_AIFLAGS_AI_PASSIVE = 0 << 0
__WASI_AIFLAGS_AI_CANONNAME = 1 << 0

and so on.

If I look at the WasiAddrInfo struct overall, it has the following information: size = 40, align = 4 but the __wasi_addrinfo_t struct in C++ has size = 28, align = 4.

I would expect these to be the same? Should the rust code or host code be treated as correct?

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

No branches or pull requests

1 participant