mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-31 22:17:27 +00:00
Return error when shutdown() fails (#2801)
Fix issue reported in #2787.
This commit is contained in:
parent
1ba4acd1c7
commit
5f7079f0f5
|
@ -2877,18 +2877,15 @@ wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
||||||
{
|
{
|
||||||
struct fd_object *fo;
|
struct fd_object *fo;
|
||||||
__wasi_errno_t error;
|
__wasi_errno_t error;
|
||||||
int ret;
|
|
||||||
|
|
||||||
error = fd_object_get(curfds, &fo, sock, 0, 0);
|
error = fd_object_get(curfds, &fo, sock, 0, 0);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
ret = os_socket_shutdown(fo->file_handle);
|
error = os_socket_shutdown(fo->file_handle);
|
||||||
fd_object_release(exec_env, fo);
|
fd_object_release(exec_env, fo);
|
||||||
if (BHT_OK != ret)
|
|
||||||
return convert_errno(errno);
|
|
||||||
|
|
||||||
return __WASI_ESUCCESS;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
__wasi_errno_t
|
__wasi_errno_t
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR})
|
set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||||
|
|
||||||
file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c)
|
file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c)
|
||||||
|
@ -9,6 +9,7 @@ if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
|
||||||
list(REMOVE_ITEM source_all
|
list(REMOVE_ITEM source_all
|
||||||
${PLATFORM_COMMON_POSIX_DIR}/posix_file.c
|
${PLATFORM_COMMON_POSIX_DIR}/posix_file.c
|
||||||
${PLATFORM_COMMON_POSIX_DIR}/posix_clock.c
|
${PLATFORM_COMMON_POSIX_DIR}/posix_clock.c
|
||||||
|
${PLATFORM_COMMON_POSIX_DIR}/posix_socket.c
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
include (${CMAKE_CURRENT_LIST_DIR}/../libc-util/platform_common_libc_util.cmake)
|
include (${CMAKE_CURRENT_LIST_DIR}/../libc-util/platform_common_libc_util.cmake)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "platform_api_vmcore.h"
|
#include "platform_api_vmcore.h"
|
||||||
#include "platform_api_extension.h"
|
#include "platform_api_extension.h"
|
||||||
|
#include "libc_errno.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
@ -308,11 +309,13 @@ os_socket_close(bh_socket_t socket)
|
||||||
return BHT_OK;
|
return BHT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
__wasi_errno_t
|
||||||
os_socket_shutdown(bh_socket_t socket)
|
os_socket_shutdown(bh_socket_t socket)
|
||||||
{
|
{
|
||||||
shutdown(socket, O_RDWR);
|
if (shutdown(socket, O_RDWR) != 0) {
|
||||||
return BHT_OK;
|
return convert_errno(errno);
|
||||||
|
}
|
||||||
|
return __WASI_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "platform_api_vmcore.h"
|
#include "platform_api_vmcore.h"
|
||||||
#include "platform_api_extension.h"
|
#include "platform_api_extension.h"
|
||||||
|
#include "libc_errno.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
@ -167,11 +168,13 @@ os_socket_close(bh_socket_t socket)
|
||||||
return BHT_OK;
|
return BHT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
__wasi_errno_t
|
||||||
os_socket_shutdown(bh_socket_t socket)
|
os_socket_shutdown(bh_socket_t socket)
|
||||||
{
|
{
|
||||||
shutdown(socket, O_RDWR);
|
if (shutdown(socket, O_RDWR) != 0) {
|
||||||
return BHT_OK;
|
return convert_errno(errno);
|
||||||
|
}
|
||||||
|
return __WASI_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -573,9 +573,9 @@ os_socket_close(bh_socket_t socket);
|
||||||
*
|
*
|
||||||
* @param socket the socket to be shutdown
|
* @param socket the socket to be shutdown
|
||||||
*
|
*
|
||||||
* @return always return 0
|
* @return returns corresponding error code
|
||||||
*/
|
*/
|
||||||
int
|
__wasi_errno_t
|
||||||
os_socket_shutdown(bh_socket_t socket);
|
os_socket_shutdown(bh_socket_t socket);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "platform_api_vmcore.h"
|
#include "platform_api_vmcore.h"
|
||||||
#include "platform_api_extension.h"
|
#include "platform_api_extension.h"
|
||||||
|
#include "libc_errno.h"
|
||||||
|
|
||||||
#ifndef SGX_DISABLE_WASI
|
#ifndef SGX_DISABLE_WASI
|
||||||
|
|
||||||
|
@ -855,10 +856,13 @@ os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
__wasi_errno_t
|
||||||
os_socket_shutdown(bh_socket_t socket)
|
os_socket_shutdown(bh_socket_t socket)
|
||||||
{
|
{
|
||||||
return shutdown(socket, O_RDWR);
|
if (shutdown(socket, O_RDWR) != 0) {
|
||||||
|
return convert_errno(errno);
|
||||||
|
}
|
||||||
|
return __WASI_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -46,50 +46,6 @@
|
||||||
CHECK_VALID_FILE_HANDLE((win_dir_stream)->handle); \
|
CHECK_VALID_FILE_HANDLE((win_dir_stream)->handle); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static __wasi_errno_t
|
|
||||||
convert_winsock_error_code(int error_code)
|
|
||||||
{
|
|
||||||
switch (error_code) {
|
|
||||||
case WSASYSNOTREADY:
|
|
||||||
case WSAEWOULDBLOCK:
|
|
||||||
return __WASI_EAGAIN;
|
|
||||||
case WSAVERNOTSUPPORTED:
|
|
||||||
return __WASI_ENOTSUP;
|
|
||||||
case WSAEINPROGRESS:
|
|
||||||
return __WASI_EINPROGRESS;
|
|
||||||
case WSAEPROCLIM:
|
|
||||||
return __WASI_EBUSY;
|
|
||||||
case WSAEFAULT:
|
|
||||||
return __WASI_EFAULT;
|
|
||||||
case WSAENETDOWN:
|
|
||||||
return __WASI_ENETDOWN;
|
|
||||||
case WSAENOTSOCK:
|
|
||||||
return __WASI_ENOTSOCK;
|
|
||||||
case WSAEINTR:
|
|
||||||
return __WASI_EINTR;
|
|
||||||
case WSAEAFNOSUPPORT:
|
|
||||||
return __WASI_EAFNOSUPPORT;
|
|
||||||
case WSAEMFILE:
|
|
||||||
return __WASI_ENFILE;
|
|
||||||
case WSAEINVAL:
|
|
||||||
return __WASI_EINVAL;
|
|
||||||
case WSAENOBUFS:
|
|
||||||
return __WASI_ENOBUFS;
|
|
||||||
case WSAEPROTONOSUPPORT:
|
|
||||||
return __WASI_EPROTONOSUPPORT;
|
|
||||||
case WSAEPROTOTYPE:
|
|
||||||
return __WASI_EPROTOTYPE;
|
|
||||||
case WSAESOCKTNOSUPPORT:
|
|
||||||
return __WASI_ENOTSUP;
|
|
||||||
case WSAEINVALIDPROCTABLE:
|
|
||||||
case WSAEINVALIDPROVIDER:
|
|
||||||
case WSAEPROVIDERFAILEDINIT:
|
|
||||||
case WSANOTINITIALISED:
|
|
||||||
default:
|
|
||||||
return __WASI_EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static __wasi_filetype_t
|
static __wasi_filetype_t
|
||||||
get_disk_filetype(DWORD attribute)
|
get_disk_filetype(DWORD attribute)
|
||||||
{
|
{
|
||||||
|
@ -1488,4 +1444,4 @@ os_realpath(const char *path, char *resolved_path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return resolved_path;
|
return resolved_path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include "platform_api_vmcore.h"
|
#include "platform_api_vmcore.h"
|
||||||
#include "platform_api_extension.h"
|
#include "platform_api_extension.h"
|
||||||
|
#include "platform_wasi_types.h"
|
||||||
|
#include "win_util.h"
|
||||||
|
|
||||||
/* link with Ws2_32.lib */
|
/* link with Ws2_32.lib */
|
||||||
#pragma comment(lib, "ws2_32.lib")
|
#pragma comment(lib, "ws2_32.lib")
|
||||||
|
@ -238,13 +240,15 @@ os_socket_close(bh_socket_t socket)
|
||||||
return BHT_OK;
|
return BHT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
__wasi_errno_t
|
||||||
os_socket_shutdown(bh_socket_t socket)
|
os_socket_shutdown(bh_socket_t socket)
|
||||||
{
|
{
|
||||||
CHECK_VALID_SOCKET_HANDLE(socket);
|
CHECK_VALID_SOCKET_HANDLE(socket);
|
||||||
|
|
||||||
shutdown(socket->raw.socket, SD_BOTH);
|
if (shutdown(socket->raw.socket, SD_BOTH) != 0) {
|
||||||
return BHT_OK;
|
return convert_winsock_error_code(WSAGetLastError());
|
||||||
|
}
|
||||||
|
return __WASI_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -93,4 +93,54 @@ uwp_print_to_debugger(const char *format, va_list ap)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
__wasi_errno_t
|
||||||
|
convert_winsock_error_code(int error_code)
|
||||||
|
{
|
||||||
|
switch (error_code) {
|
||||||
|
case WSASYSNOTREADY:
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
return __WASI_EAGAIN;
|
||||||
|
case WSAVERNOTSUPPORTED:
|
||||||
|
return __WASI_ENOTSUP;
|
||||||
|
case WSAEINPROGRESS:
|
||||||
|
return __WASI_EINPROGRESS;
|
||||||
|
case WSAEPROCLIM:
|
||||||
|
return __WASI_EBUSY;
|
||||||
|
case WSAEFAULT:
|
||||||
|
return __WASI_EFAULT;
|
||||||
|
case WSAENETDOWN:
|
||||||
|
return __WASI_ENETDOWN;
|
||||||
|
case WSAENOTSOCK:
|
||||||
|
return __WASI_ENOTSOCK;
|
||||||
|
case WSAEINTR:
|
||||||
|
return __WASI_EINTR;
|
||||||
|
case WSAEAFNOSUPPORT:
|
||||||
|
return __WASI_EAFNOSUPPORT;
|
||||||
|
case WSAEMFILE:
|
||||||
|
return __WASI_ENFILE;
|
||||||
|
case WSAEINVAL:
|
||||||
|
return __WASI_EINVAL;
|
||||||
|
case WSAENOBUFS:
|
||||||
|
return __WASI_ENOBUFS;
|
||||||
|
case WSAEPROTONOSUPPORT:
|
||||||
|
return __WASI_EPROTONOSUPPORT;
|
||||||
|
case WSAEPROTOTYPE:
|
||||||
|
return __WASI_EPROTOTYPE;
|
||||||
|
case WSAESOCKTNOSUPPORT:
|
||||||
|
return __WASI_ENOTSUP;
|
||||||
|
case WSAECONNABORTED:
|
||||||
|
return __WASI_ECONNABORTED;
|
||||||
|
case WSAECONNRESET:
|
||||||
|
return __WASI_ECONNRESET;
|
||||||
|
case WSAENOTCONN:
|
||||||
|
return __WASI_ENOTCONN;
|
||||||
|
case WSAEINVALIDPROCTABLE:
|
||||||
|
case WSAEINVALIDPROVIDER:
|
||||||
|
case WSAEPROVIDERFAILEDINIT:
|
||||||
|
case WSANOTINITIALISED:
|
||||||
|
default:
|
||||||
|
return __WASI_EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -12,8 +12,12 @@
|
||||||
__wasi_timestamp_t
|
__wasi_timestamp_t
|
||||||
convert_filetime_to_wasi_timestamp(LPFILETIME filetime);
|
convert_filetime_to_wasi_timestamp(LPFILETIME filetime);
|
||||||
|
|
||||||
// Convert a Windows error code to a WASI error code
|
/* Convert a Windows error code to a WASI error code */
|
||||||
__wasi_errno_t
|
__wasi_errno_t
|
||||||
convert_windows_error_code(DWORD windows_error_code);
|
convert_windows_error_code(DWORD windows_error_code);
|
||||||
|
|
||||||
|
/* Convert a Winsock error code to a WASI error code */
|
||||||
|
__wasi_errno_t
|
||||||
|
convert_winsock_error_code(int error_code);
|
||||||
|
|
||||||
#endif /* end of _WIN_UTIL_H */
|
#endif /* end of _WIN_UTIL_H */
|
Loading…
Reference in New Issue
Block a user