libc-wasi: Make rights of STDIN/STDOUT/STDERR fixed and overlook their access modes (#3694)
When determining the file descriptor rights in the function fd_determine_type_rights(), we assign fixed and unchangeable rights to STDIN, STDOUT and STDERR. ps. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3686
This commit is contained in:
@ -54,6 +54,18 @@
|
||||
#define CONFIG_HAS_O_SYNC
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
// Converts a POSIX timespec to a WASI timestamp.
|
||||
static __wasi_timestamp_t
|
||||
convert_timespec(const struct timespec *ts)
|
||||
@ -858,30 +870,39 @@ os_isatty(os_file_handle handle)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdin_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDIN_FILENO;
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdout_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDOUT_FILENO;
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stderr_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDERR_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
|
||||
{
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stdout_handle(os_raw_file_handle raw_stdout)
|
||||
{
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stderr_handle(os_raw_file_handle raw_stderr)
|
||||
{
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO;
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,18 @@
|
||||
#define CONFIG_HAS_O_SYNC
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
// Converts a POSIX timespec to a WASI timestamp.
|
||||
static __wasi_timestamp_t
|
||||
convert_timespec(const struct timespec *ts)
|
||||
@ -858,30 +870,39 @@ os_isatty(os_file_handle handle)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdin_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDIN_FILENO;
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdout_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDOUT_FILENO;
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stderr_handle(os_file_handle fd)
|
||||
{
|
||||
return fd == STDERR_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
|
||||
{
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stdout_handle(os_raw_file_handle raw_stdout)
|
||||
{
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO;
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stderr_handle(os_raw_file_handle raw_stderr)
|
||||
{
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO;
|
||||
}
|
||||
|
||||
|
||||
@ -1502,6 +1502,33 @@ os_convert_stdout_handle(os_raw_file_handle raw_stdout);
|
||||
os_file_handle
|
||||
os_convert_stderr_handle(os_raw_file_handle raw_stderr);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fd a file handle
|
||||
*
|
||||
* @return true if it is stdin
|
||||
*/
|
||||
bool
|
||||
os_is_stdin_handle(os_file_handle fd);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fd a file handle
|
||||
*
|
||||
* @return true if it is stdout
|
||||
*/
|
||||
bool
|
||||
os_is_stdout_handle(os_file_handle fd);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fd a file handle
|
||||
*
|
||||
* @return true if it is stderr
|
||||
*/
|
||||
bool
|
||||
os_is_stderr_handle(os_file_handle fd);
|
||||
|
||||
/**
|
||||
* Open a directory stream for the provided directory handle. The returned
|
||||
* directory stream will be positioned at the first entry in the directory.
|
||||
|
||||
@ -1540,6 +1540,24 @@ create_stdio_handle(HANDLE raw_stdio_handle, DWORD stdio)
|
||||
return stdio_handle;
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdin_handle(os_file_handle fd)
|
||||
{
|
||||
return fd->raw.handle == GetStdHandle(STD_INPUT_HANDLE);
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stdout_handle(os_file_handle fd)
|
||||
{
|
||||
return fd->raw.handle == GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
}
|
||||
|
||||
bool
|
||||
os_is_stderr_handle(os_file_handle fd)
|
||||
{
|
||||
return fd->raw.handle == GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
|
||||
os_file_handle
|
||||
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user