Correct wasi linking

This commit is contained in:
gingerBill
2021-10-31 13:04:28 +00:00
parent 2a5b8f53fe
commit 906c7ef0fc
+83 -63
View File
@@ -1,7 +1,7 @@
//+build wasm32 //+build wasm32
package sys_wasi package sys_wasi
foreign import wasi "env" foreign import wasi "wasi_unstable"
DIRCOOKIE_START :: u64(0) DIRCOOKIE_START :: u64(0)
size_t :: uint size_t :: uint
@@ -970,7 +970,7 @@ prestat_t :: struct {
}, },
} }
@(link_prefix="__wasi_") @(default_calling_convention="c")
foreign wasi { foreign wasi {
/** /**
* Read command-line argument data. * Read command-line argument data.
@@ -1303,8 +1303,8 @@ foreign wasi {
* Returns the number of arguments and the size of the argument string * Returns the number of arguments and the size of the argument string
* data, or an error. * data, or an error.
*/ */
args_sizes_get :: proc() -> (num_args, size_of_args: size_t, err: errno_t) { args_sizes_get :: proc "c" () -> (num_args, size_of_args: size_t, err: errno_t) {
err = __wasi_args_sizes_get(&num_args, &size_of_args) err = wasi_args_sizes_get(&num_args, &size_of_args)
return return
} }
/** /**
@@ -1313,8 +1313,8 @@ args_sizes_get :: proc() -> (num_args, size_of_args: size_t, err: errno_t) {
* Returns the number of environment variable arguments and the size of the * Returns the number of environment variable arguments and the size of the
* environment variable data. * environment variable data.
*/ */
environ_sizes_get :: proc() -> (num_envs, size_of_envs: size_t, err: errno_t) { environ_sizes_get :: proc "c" () -> (num_envs, size_of_envs: size_t, err: errno_t) {
err = __wasi_environ_sizes_get(&num_envs, &size_of_envs) err = wasi_environ_sizes_get(&num_envs, &size_of_envs)
return return
} }
/** /**
@@ -1325,13 +1325,13 @@ environ_sizes_get :: proc() -> (num_envs, size_of_envs: size_t, err: errno_t) {
* @return * @return
* The resolution of the clock, or an error if one happened. * The resolution of the clock, or an error if one happened.
*/ */
clock_res_get :: proc( clock_res_get :: proc "c" (
/** /**
* The clock for which to return the resolution. * The clock for which to return the resolution.
*/ */
id: clockid_t, id: clockid_t,
) -> (ts: timestamp_t, err: errno_t) { ) -> (ts: timestamp_t, err: errno_t) {
err = __wasi_clock_res_get(id, &ts) err = wasi_clock_res_get(id, &ts)
return return
} }
/** /**
@@ -1340,7 +1340,7 @@ clock_res_get :: proc(
* @return * @return
* The time value of the clock. * The time value of the clock.
*/ */
clock_time_get :: proc( clock_time_get :: proc "c" (
/** /**
* The clock for which to return the time. * The clock for which to return the time.
*/ */
@@ -1350,7 +1350,7 @@ clock_time_get :: proc(
*/ */
precision: timestamp_t, precision: timestamp_t,
) -> (ts: timestamp_t, err: errno_t) { ) -> (ts: timestamp_t, err: errno_t) {
err = __wasi_clock_time_get(id, precision, &ts) err = wasi_clock_time_get(id, precision, &ts)
return return
} }
/** /**
@@ -1359,10 +1359,10 @@ clock_time_get :: proc(
* @return * @return
* The buffer where the file descriptor's attributes are stored. * The buffer where the file descriptor's attributes are stored.
*/ */
fd_fdstat_get :: proc( fd_fdstat_get :: proc "c" (
fd: fd_t, fd: fd_t,
) -> (stat: fdstat_t, err: errno_t) { ) -> (stat: fdstat_t, err: errno_t) {
err = __wasi_fd_fdstat_get(fd, &stat) err = wasi_fd_fdstat_get(fd, &stat)
return return
} }
/** /**
@@ -1370,10 +1370,10 @@ fd_fdstat_get :: proc(
* @return * @return
* The buffer where the file's attributes are stored. * The buffer where the file's attributes are stored.
*/ */
fd_filestat_get :: proc( fd_filestat_get :: proc "c" (
fd: fd_t, fd: fd_t,
) -> (stat: filestat_t, err: errno_t) { ) -> (stat: filestat_t, err: errno_t) {
err = __wasi_fd_filestat_get(fd, &stat) err = wasi_fd_filestat_get(fd, &stat)
return return
} }
@@ -1386,7 +1386,7 @@ fd_filestat_get :: proc(
* @return * @return
* The number of bytes read. * The number of bytes read.
*/ */
fd_pread :: proc( fd_pread :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors in which to store data. * List of scatter/gather vectors in which to store data.
@@ -1401,7 +1401,7 @@ fd_pread :: proc(
*/ */
offset: filesize_t, offset: filesize_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_fd_pread(fd, iovs, iovs_len, offset, &n) err = wasi_fd_pread(fd, iovs, iovs_len, offset, &n)
return return
} }
/** /**
@@ -1409,10 +1409,10 @@ fd_pread :: proc(
* @return * @return
* The buffer where the description is stored. * The buffer where the description is stored.
*/ */
fd_prestat_get :: proc( fd_prestat_get :: proc "c" (
fd: fd_t, fd: fd_t,
) -> (desc: prestat_t, err: errno_t) { ) -> (desc: prestat_t, err: errno_t) {
err = __wasi_fd_prestat_get(fd, &desc) err = wasi_fd_prestat_get(fd, &desc)
return return
} }
/** /**
@@ -1421,7 +1421,7 @@ fd_prestat_get :: proc(
* @return * @return
* The number of bytes written. * The number of bytes written.
*/ */
fd_pwrite :: proc( fd_pwrite :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors from which to retrieve data. * List of scatter/gather vectors from which to retrieve data.
@@ -1436,7 +1436,7 @@ fd_pwrite :: proc(
*/ */
offset: filesize_t, offset: filesize_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_fd_pwrite(fd, iovs, iovs_len, offset, &n) err = wasi_fd_pwrite(fd, iovs, iovs_len, offset, &n)
return return
} }
/** /**
@@ -1445,7 +1445,7 @@ fd_pwrite :: proc(
* @return * @return
* The number of bytes read. * The number of bytes read.
*/ */
fd_read :: proc( fd_read :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors to which to store data. * List of scatter/gather vectors to which to store data.
@@ -1456,7 +1456,7 @@ fd_read :: proc(
*/ */
iovs_len: size_t, iovs_len: size_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_fd_read(fd, iovs, iovs_len, &n) err = wasi_fd_read(fd, iovs, iovs_len, &n)
return return
} }
/** /**
@@ -1472,7 +1472,7 @@ fd_read :: proc(
* @return * @return
* The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
*/ */
fd_readdir :: proc( fd_readdir :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* The buffer where directory entries are stored * The buffer where directory entries are stored
@@ -1484,7 +1484,7 @@ fd_readdir :: proc(
*/ */
cookie: dircookie_t, cookie: dircookie_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_fd_readdir(fd, buf, buf_len, cookie, &n) err = wasi_fd_readdir(fd, buf, buf_len, cookie, &n)
return return
} }
/** /**
@@ -1493,7 +1493,7 @@ fd_readdir :: proc(
* @return * @return
* The new offset of the file descriptor, relative to the start of the file. * The new offset of the file descriptor, relative to the start of the file.
*/ */
fd_seek :: proc( fd_seek :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* The number of bytes to move. * The number of bytes to move.
@@ -1504,7 +1504,7 @@ fd_seek :: proc(
*/ */
whence: whence_t, whence: whence_t,
) -> (new_offset: filesize_t, err: errno_t) { ) -> (new_offset: filesize_t, err: errno_t) {
err = __wasi_fd_seek(fd, offset, whence, &new_offset) err = wasi_fd_seek(fd, offset, whence, &new_offset)
return return
} }
/** /**
@@ -1513,17 +1513,17 @@ fd_seek :: proc(
* @return * @return
* The current offset of the file descriptor, relative to the start of the file. * The current offset of the file descriptor, relative to the start of the file.
*/ */
fd_tell :: proc( fd_tell :: proc "c" (
fd: fd_t, fd: fd_t,
) -> (offset: filesize_t, err: errno_t) { ) -> (offset: filesize_t, err: errno_t) {
err = __wasi_fd_tell(fd, &offset) err = wasi_fd_tell(fd, &offset)
return return
} }
/** /**
* Write to a file descriptor. * Write to a file descriptor.
* Note: This is similar to `writev` in POSIX. * Note: This is similar to `writev` in POSIX.
*/ */
fd_write :: proc( fd_write :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors from which to retrieve data. * List of scatter/gather vectors from which to retrieve data.
@@ -1534,7 +1534,7 @@ fd_write :: proc(
*/ */
iovs_len: size_t, iovs_len: size_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_fd_write(fd, iovs, iovs_len, &n) err = wasi_fd_write(fd, iovs, iovs_len, &n)
return return
} }
/** /**
@@ -1543,7 +1543,7 @@ fd_write :: proc(
* @return * @return
* The buffer where the file's attributes are stored. * The buffer where the file's attributes are stored.
*/ */
path_filestat_get :: proc( path_filestat_get :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* Flags determining the method of how the path is resolved. * Flags determining the method of how the path is resolved.
@@ -1554,7 +1554,7 @@ path_filestat_get :: proc(
*/ */
path: cstring, path: cstring,
) -> (offset: filestat_t, err: errno_t) { ) -> (offset: filestat_t, err: errno_t) {
err = __wasi_path_filestat_get(fd, flags, path, &offset) err = wasi_path_filestat_get(fd, flags, path, &offset)
return return
} }
/** /**
@@ -1568,7 +1568,7 @@ path_filestat_get :: proc(
* @return * @return
* The file descriptor of the file that has been opened. * The file descriptor of the file that has been opened.
*/ */
path_open :: proc( path_open :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* Flags determining the method of how the path is resolved. * Flags determining the method of how the path is resolved.
@@ -1596,7 +1596,7 @@ path_open :: proc(
fs_rights_inheriting: rights_t, fs_rights_inheriting: rights_t,
fdflags: fdflags_t, fdflags: fdflags_t,
) -> (file: fd_t, err: errno_t) { ) -> (file: fd_t, err: errno_t) {
err = __wasi_path_open(fd, dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fdflags, &file) err = wasi_path_open(fd, dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fdflags, &file)
return return
} }
/** /**
@@ -1605,7 +1605,7 @@ path_open :: proc(
* @return * @return
* The number of bytes placed in the buffer. * The number of bytes placed in the buffer.
*/ */
path_readlink :: proc( path_readlink :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* The path of the symbolic link from which to read. * The path of the symbolic link from which to read.
@@ -1617,7 +1617,7 @@ path_readlink :: proc(
buf: [^]u8, buf: [^]u8,
buf_len: size_t, buf_len: size_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_path_readlink(fd, path, buf, buf_len, &n) err = wasi_path_readlink(fd, path, buf, buf_len, &n)
return return
} }
/** /**
@@ -1625,7 +1625,7 @@ path_readlink :: proc(
* @return * @return
* The number of events stored. * The number of events stored.
*/ */
poll_oneoff :: proc( poll_oneoff :: proc "c" (
/** /**
* The events to which to subscribe. * The events to which to subscribe.
*/ */
@@ -1639,7 +1639,7 @@ poll_oneoff :: proc(
*/ */
nsubscriptions: size_t, nsubscriptions: size_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_poll_oneoff(subscription_in, event_out, nsubscriptions, &n) err = wasi_poll_oneoff(subscription_in, event_out, nsubscriptions, &n)
return return
} }
/** /**
@@ -1649,7 +1649,7 @@ poll_oneoff :: proc(
* @return * @return
* Number of bytes stored in ri_data and message flags. * Number of bytes stored in ri_data and message flags.
*/ */
sock_recv :: proc( sock_recv :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors to which to store data. * List of scatter/gather vectors to which to store data.
@@ -1664,7 +1664,7 @@ sock_recv :: proc(
*/ */
ri_flags: riflags_t, ri_flags: riflags_t,
) -> (n: size_t, flags: roflags_t, err: errno_t) { ) -> (n: size_t, flags: roflags_t, err: errno_t) {
err = __wasi_sock_recv(fd, ri_data, ri_data_len, ri_flags, &n, &flags) err = wasi_sock_recv(fd, ri_data, ri_data_len, ri_flags, &n, &flags)
return return
} }
/** /**
@@ -1674,7 +1674,7 @@ sock_recv :: proc(
* @return * @return
* Number of bytes transmitted. * Number of bytes transmitted.
*/ */
sock_send :: proc( sock_send :: proc "c" (
fd: fd_t, fd: fd_t,
/** /**
* List of scatter/gather vectors to which to retrieve data * List of scatter/gather vectors to which to retrieve data
@@ -1689,85 +1689,100 @@ sock_send :: proc(
*/ */
si_flags: siflags_t, si_flags: siflags_t,
) -> (n: size_t, err: errno_t) { ) -> (n: size_t, err: errno_t) {
err = __wasi_sock_send(fd, si_data, si_data_len, si_flags, &n) err = wasi_sock_send(fd, si_data, si_data_len, si_flags, &n)
return return
} }
@(default_calling_convention="c")
foreign wasi { foreign wasi {
__wasi_args_sizes_get :: proc( @(link_name="args_sizes_get")
wasi_args_sizes_get :: proc(
retptr0: ^size_t, retptr0: ^size_t,
retptr1: ^size_t, retptr1: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_environ_sizes_get :: proc( @(link_name="environ_sizes_get")
wasi_environ_sizes_get :: proc(
retptr0: ^size_t, retptr0: ^size_t,
retptr1: ^size_t, retptr1: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_clock_res_get :: proc( @(link_name="clock_res_get")
wasi_clock_res_get :: proc(
id: clockid_t, id: clockid_t,
retptr0: ^timestamp_t, retptr0: ^timestamp_t,
) -> errno_t --- ) -> errno_t ---
__wasi_clock_time_get :: proc( @(link_name="clock_time_get")
wasi_clock_time_get :: proc(
id: clockid_t, id: clockid_t,
precision: timestamp_t, precision: timestamp_t,
retptr0: ^timestamp_t, retptr0: ^timestamp_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_fdstat_get :: proc( @(link_name="fd_fdstat_get")
wasi_fd_fdstat_get :: proc(
fd: fd_t, fd: fd_t,
retptr0: ^fdstat_t, retptr0: ^fdstat_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_filestat_get :: proc( @(link_name="fd_filestat_get")
wasi_fd_filestat_get :: proc(
fd: fd_t, fd: fd_t,
retptr0: ^filestat_t, retptr0: ^filestat_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_pread :: proc( @(link_name="fd_pread")
wasi_fd_pread :: proc(
fd: fd_t, fd: fd_t,
iovs: [^]iovec_t, iovs: [^]iovec_t,
iovs_len: size_t, iovs_len: size_t,
offset: filesize_t, offset: filesize_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_prestat_get :: proc( @(link_name="fd_prestat_get")
wasi_fd_prestat_get :: proc(
fd: fd_t, fd: fd_t,
retptr0: ^prestat_t, retptr0: ^prestat_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_pwrite :: proc( @(link_name="fd_pwrite")
wasi_fd_pwrite :: proc(
fd: fd_t, fd: fd_t,
iovs: [^]ciovec_t, iovs: [^]ciovec_t,
iovs_len: size_t, iovs_len: size_t,
offset: filesize_t, offset: filesize_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_read :: proc( @(link_name="fd_read")
wasi_fd_read :: proc(
fd: fd_t, fd: fd_t,
iovs: [^]iovec_t, iovs: [^]iovec_t,
iovs_len: size_t, iovs_len: size_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_readdir :: proc( @(link_name="fd_readdir")
wasi_fd_readdir :: proc(
fd: fd_t, fd: fd_t,
buf: [^]u8, buf: [^]u8,
buf_len: size_t, buf_len: size_t,
cookie: dircookie_t, cookie: dircookie_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_seek :: proc( @(link_name="fd_seek")
wasi_fd_seek :: proc(
fd: fd_t, fd: fd_t,
offset: filedelta_t, offset: filedelta_t,
whence: whence_t, whence: whence_t,
retptr0: ^filesize_t, retptr0: ^filesize_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_tell :: proc( @(link_name="fd_tell")
wasi_fd_tell :: proc(
fd: fd_t, fd: fd_t,
retptr0: ^filesize_t, retptr0: ^filesize_t,
) -> errno_t --- ) -> errno_t ---
__wasi_fd_write :: proc( @(link_name="fd_write")
wasi_fd_write :: proc(
fd: fd_t, fd: fd_t,
iovs: [^]ciovec_t, iovs: [^]ciovec_t,
iovs_len: size_t, iovs_len: size_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_path_filestat_get :: proc( @(link_name="path_filestat_get")
wasi_path_filestat_get :: proc(
fd: fd_t, fd: fd_t,
flags: lookupflags_t, flags: lookupflags_t,
/** /**
@@ -1776,7 +1791,8 @@ foreign wasi {
path: cstring, path: cstring,
retptr0: ^filestat_t, retptr0: ^filestat_t,
) -> errno_t --- ) -> errno_t ---
__wasi_path_open :: proc( @(link_name="path_open")
wasi_path_open :: proc(
fd: fd_t, fd: fd_t,
dirflags: lookupflags_t, dirflags: lookupflags_t,
path: cstring, path: cstring,
@@ -1786,20 +1802,23 @@ foreign wasi {
fdflags: fdflags_t, fdflags: fdflags_t,
retptr: ^fd_t, retptr: ^fd_t,
) -> errno_t --- ) -> errno_t ---
__wasi_path_readlink :: proc( @(link_name="path_readlink")
wasi_path_readlink :: proc(
fd: fd_t, fd: fd_t,
path: cstring, path: cstring,
buf: [^]u8, buf: [^]u8,
buf_len: size_t, buf_len: size_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_poll_oneoff :: proc( @(link_name="poll_oneoff")
wasi_poll_oneoff :: proc(
subscription_in: ^subscription_t, subscription_in: ^subscription_t,
event_out: ^event_t, event_out: ^event_t,
nsubscriptions: size_t, nsubscriptions: size_t,
retptr0: ^size_t, retptr0: ^size_t,
) -> errno_t --- ) -> errno_t ---
__wasi_sock_recv :: proc( @(link_name="sock_recv")
wasi_sock_recv :: proc(
fd: fd_t, fd: fd_t,
ri_data: [^]iovec_t, ri_data: [^]iovec_t,
ri_data_len: size_t, ri_data_len: size_t,
@@ -1807,7 +1826,8 @@ foreign wasi {
retptr0: ^size_t, retptr0: ^size_t,
retptr1: ^roflags_t, retptr1: ^roflags_t,
) -> errno_t --- ) -> errno_t ---
__wasi_sock_send :: proc( @(link_name="sock_send")
wasi_sock_send :: proc(
fd: fd_t, fd: fd_t,
si_data: [^]ciovec_t, si_data: [^]ciovec_t,
si_data_len: size_t, si_data_len: size_t,