Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions core/shared/platform/include/platform_wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,6 @@ assert_wasi_layout(offsetof(__wasi_subscription_t, userdata) == 0, "witx calcula
assert_wasi_layout(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset");

/* keep syncing with wasi_socket_ext.h */
typedef enum {
/* Used only for sock_addr_resolve hints */
SOCKET_ANY = -1,
SOCKET_DGRAM = 0,
SOCKET_STREAM,
} __wasi_sock_type_t;

typedef uint16_t __wasi_ip_port_t;

Expand Down Expand Up @@ -589,20 +583,36 @@ typedef struct __wasi_addr_t {
} addr;
} __wasi_addr_t;

typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t;
/* Force 32-bit wire width for cross-boundary fields */
typedef int32_t __wasi_sock_type_t;
enum { SOCKET_ANY = -1, SOCKET_DGRAM = 0, SOCKET_STREAM = 1 };
Copy link
Collaborator

Choose a reason for hiding this comment

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

i agree it isn't appropriate to use enums to define an ABI.

it's better to retire all enums in this file.
ie.

#define SOCKET_DGRAM 0

it's even better to stop using too generic names.

typedef int32_t __wamr_socket_ext_sock_type_t;
#define WAMR_SOCKET_EXT_SOCK_TYPE_DGRAM 0

note that SOCKET_DGRAM is NOT wasi SOCK_DGRAM.

Copy link
Contributor

@srberard srberard Nov 12, 2025

Choose a reason for hiding this comment

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

Hi @yamt,
Are you suggesting that we replace all of the enums with #defines? For example:

enum { IPv4 = 0, IPv6 };

with this:

#define IPv4   0
#define IPv6   1

I'm happy to update the PR and make this change. The current PR continues to use enums but fixes the typedef to use fixed sizes (following the pattern used for __wasi_addr_type_t).

I also agree with changing things like SOCKET_DGRAM to something like WAMR_SOCKET_EXT_SOCK_TYPE_DGRAM as it is very confusing, particularly when having to debug. The only reservation I have is that will likely break existing code that uses the SOCKET_* values.


typedef int32_t __wasi_address_family_t;
enum { INET4 = 0, INET6 = 1, INET_UNSPEC = 2 };

typedef struct __wasi_addr_info_t {
__wasi_addr_t addr;
__wasi_addr_t addr;
__wasi_sock_type_t type;
} __wasi_addr_info_t;

typedef struct __wasi_addr_info_hints_t {
__wasi_sock_type_t type;
__wasi_address_family_t family;
// this is to workaround lack of optional parameters
uint8_t hints_enabled;
__wasi_sock_type_t type; // 4 bytes
__wasi_address_family_t family; // 4 bytes
uint8_t hints_enabled; // 1 byte
uint8_t _pad[3]; // enforce layout
} __wasi_addr_info_hints_t;

assert_wasi_layout(sizeof(__wasi_sock_type_t) == 4, "sock_type must be 4 bytes");
assert_wasi_layout(sizeof(__wasi_address_family_t) == 4, "addr_family must be 4 bytes");

assert_wasi_layout(sizeof(__wasi_addr_info_hints_t) == 12, "hints_t must be 12 bytes");
assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, type) == 0, "hints.type@0");
assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, family) == 4, "hints.family@4");
assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, hints_enabled) == 8, "hints.enabled@8");

assert_wasi_layout(offsetof(__wasi_addr_info_t, type) == sizeof(__wasi_addr_t),
"addr_info.type follows addr");

#undef assert_wasi_layout

/* clang-format on */
Expand Down
Loading