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

[wasm] Add more errno support in WASILibc overlay #5509

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
121 changes: 92 additions & 29 deletions stdlib/public/Platform/WASILibc.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,98 @@ public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude

public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1)

// wasi-libc's error.h uses a macro that Swift can't import.
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EACCES'.")
public let EACCES: Int32 = 2
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EDQUOT'.")
public let EDQUOT: Int32 = 19
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EEXIST'.")
public let EEXIST: Int32 = 20
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EFBIG'.")
public let EFBIG: Int32 = 22
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINTR'.")
public let EINTR: Int32 = 27
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINVAL'.")
public let EINVAL: Int32 = 28
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENAMETOOLONG'.")
public let ENAMETOOLONG: Int32 = 37
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOENT'.")
public let ENOENT: Int32 = 44
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOSPC'.")
public let ENOSPC: Int32 = 51
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EPERM'.")
public let EPERM: Int32 = 63
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EROFS'.")
public let EROFS: Int32 = 69


// wasi-libc's _seek.h uses a macro that Swift can't import.
// https://developer.apple.com/documentation/swift/using-imported-c-macros-in-swift
// https://github.com/apple/swift/blob/c55b9cc87925c5d63a21d383ad23dff056d36607/lib/ClangImporter/ImportName.cpp#L2115-L2117
// https://github.com/WebAssembly/wasi-libc/pull/148
// TODO: wasi-libc's error.h defines these macros as function-like macros, which
// Swift can't import for now.
%{
posix_error_codes = [
"E2BIG",
"EACCES",
"EADDRINUSE",
"EADDRNOTAVAIL",
"EAFNOSUPPORT",
"EAGAIN",
"EALREADY",
"EBADF",
"EBADMSG",
"EBUSY",
"ECANCELED",
"ECHILD",
"ECONNABORTED",
"ECONNREFUSED",
"ECONNRESET",
"EDEADLK",
"EDESTADDRREQ",
"EDOM",
"EDQUOT",
"EEXIST",
"EFAULT",
"EFBIG",
"EHOSTUNREACH",
"EIDRM",
"EILSEQ",
"EINPROGRESS",
"EINTR",
"EINVAL",
"EIO",
"EISCONN",
"EISDIR",
"ELOOP",
"EMFILE",
"EMLINK",
"EMSGSIZE",
"EMULTIHOP",
"ENAMETOOLONG",
"ENETDOWN",
"ENETRESET",
"ENETUNREACH",
"ENFILE",
"ENOBUFS",
"ENODEV",
"ENOENT",
"ENOEXEC",
"ENOLCK",
"ENOLINK",
"ENOMEM",
"ENOMSG",
"ENOPROTOOPT",
"ENOSPC",
"ENOSYS",
"ENOTCONN",
"ENOTDIR",
"ENOTEMPTY",
"ENOTRECOVERABLE",
"ENOTSOCK",
"ENOTSUP",
"ENOTTY",
"ENXIO",
"EOVERFLOW",
"EOWNERDEAD",
"EPERM",
"EPIPE",
"EPROTO",
"EPROTONOSUPPORT",
"EPROTOTYPE",
"ERANGE",
"EROFS",
"ESPIPE",
"ESRCH",
"ESTALE",
"ETIMEDOUT",
"ETXTBSY",
"EXDEV",
"ENOTCAPABLE",
]
}%

%for ecode in posix_error_codes:

@available(*, deprecated, message: "Please use 'POSIXErrorCode.${ecode}'.")
public let ${ecode} = POSIXErrorCode.${ecode}.rawValue

%end

// TODO: wasi-libc's _seek.h defines these macros as function-like macros, which
// Swift can't import for now.
public let SEEK_SET: Int32 = 0
public let SEEK_CUR: Int32 = 1
public let SEEK_END: Int32 = 2