Skip to content

Commit 7d8fa74

Browse files
committed
Revert "libc-wasi: Make rights of STDIN/STDOUT/STDERR fixed and overlook their access modes (bytecodealliance#3694)"
This reverts commit 67fa155. because it broke certain use cases while it isn't clear what it fixed. tested with: https://github.com/yamt/garbage/tree/master/wasm/httpd https://github.com/yamt/garbage/tree/master/wasm/tty cf. bytecodealliance#4447 bytecodealliance#3686 (comment)
1 parent eeff667 commit 7d8fa74

File tree

6 files changed

+19
-138
lines changed

6 files changed

+19
-138
lines changed

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,27 +459,8 @@ fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
459459
__wasi_rights_t *rights_inheriting)
460460
{
461461
struct __wasi_filestat_t buf;
462-
__wasi_errno_t error;
463-
464-
if (os_is_stdin_handle(fd)) {
465-
*rights_base = RIGHTS_STDIN;
466-
*rights_inheriting = RIGHTS_STDIN;
467-
return __WASI_ESUCCESS;
468-
}
469-
470-
if (os_is_stdout_handle(fd)) {
471-
*rights_base = RIGHTS_STDOUT;
472-
*rights_inheriting = RIGHTS_STDOUT;
473-
return __WASI_ESUCCESS;
474-
}
475-
476-
if (os_is_stderr_handle(fd)) {
477-
*rights_base = RIGHTS_STDERR;
478-
*rights_inheriting = RIGHTS_STDERR;
479-
return __WASI_ESUCCESS;
480-
}
462+
__wasi_errno_t error = os_fstat(fd, &buf);
481463

482-
error = os_fstat(fd, &buf);
483464
if (error != __WASI_ESUCCESS)
484465
return error;
485466

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@
4747
#define RIGHTS_CHARACTER_DEVICE_BASE RIGHTS_ALL
4848
#define RIGHTS_CHARACTER_DEVICE_INHERITING RIGHTS_ALL
4949

50-
#define RIGHTS_STDIN \
51-
(__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_FILESTAT_GET | \
52-
__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_WRITE | \
53-
__WASI_RIGHT_POLL_FD_READWRITE)
54-
55-
#define RIGHTS_STDOUT \
56-
(__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_DATASYNC | \
57-
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_SYNC | \
58-
__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_WRITE | \
59-
__WASI_RIGHT_POLL_FD_READWRITE)
60-
61-
#define RIGHTS_STDERR RIGHTS_STDOUT
62-
6350
// Only allow directory operations on directories. Directories can only
6451
// yield file descriptors to other directories and files.
6552
#define RIGHTS_DIRECTORY_BASE \

core/shared/platform/common/posix/posix_file.c

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@
5454
#define CONFIG_HAS_O_SYNC
5555
#endif
5656

57-
#ifndef STDIN_FILENO
58-
#define STDIN_FILENO 0
59-
#endif
60-
61-
#ifndef STDOUT_FILENO
62-
#define STDOUT_FILENO 1
63-
#endif
64-
65-
#ifndef STDERR_FILENO
66-
#define STDERR_FILENO 2
67-
#endif
68-
6957
// Converts a POSIX timespec to a WASI timestamp.
7058
static __wasi_timestamp_t
7159
convert_timespec(const struct timespec *ts)
@@ -870,39 +858,30 @@ os_isatty(os_file_handle handle)
870858
#endif
871859
}
872860

873-
bool
874-
os_is_stdin_handle(os_file_handle fd)
875-
{
876-
return fd == STDIN_FILENO;
877-
}
878-
879-
bool
880-
os_is_stdout_handle(os_file_handle fd)
881-
{
882-
return fd == STDOUT_FILENO;
883-
}
884-
885-
bool
886-
os_is_stderr_handle(os_file_handle fd)
887-
{
888-
return fd == STDERR_FILENO;
889-
}
890-
891861
os_file_handle
892862
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
893863
{
864+
#ifndef STDIN_FILENO
865+
#define STDIN_FILENO 0
866+
#endif
894867
return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO;
895868
}
896869

897870
os_file_handle
898871
os_convert_stdout_handle(os_raw_file_handle raw_stdout)
899872
{
873+
#ifndef STDOUT_FILENO
874+
#define STDOUT_FILENO 1
875+
#endif
900876
return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO;
901877
}
902878

903879
os_file_handle
904880
os_convert_stderr_handle(os_raw_file_handle raw_stderr)
905881
{
882+
#ifndef STDERR_FILENO
883+
#define STDERR_FILENO 2
884+
#endif
906885
return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO;
907886
}
908887

core/shared/platform/esp-idf/espidf_file.c

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@
5454
#define CONFIG_HAS_O_SYNC
5555
#endif
5656

57-
#ifndef STDIN_FILENO
58-
#define STDIN_FILENO 0
59-
#endif
60-
61-
#ifndef STDOUT_FILENO
62-
#define STDOUT_FILENO 1
63-
#endif
64-
65-
#ifndef STDERR_FILENO
66-
#define STDERR_FILENO 2
67-
#endif
68-
6957
// Converts a POSIX timespec to a WASI timestamp.
7058
static __wasi_timestamp_t
7159
convert_timespec(const struct timespec *ts)
@@ -870,39 +858,30 @@ os_isatty(os_file_handle handle)
870858
#endif
871859
}
872860

873-
bool
874-
os_is_stdin_handle(os_file_handle fd)
875-
{
876-
return fd == STDIN_FILENO;
877-
}
878-
879-
bool
880-
os_is_stdout_handle(os_file_handle fd)
881-
{
882-
return fd == STDOUT_FILENO;
883-
}
884-
885-
bool
886-
os_is_stderr_handle(os_file_handle fd)
887-
{
888-
return fd == STDERR_FILENO;
889-
}
890-
891861
os_file_handle
892862
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
893863
{
864+
#ifndef STDIN_FILENO
865+
#define STDIN_FILENO 0
866+
#endif
894867
return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO;
895868
}
896869

897870
os_file_handle
898871
os_convert_stdout_handle(os_raw_file_handle raw_stdout)
899872
{
873+
#ifndef STDOUT_FILENO
874+
#define STDOUT_FILENO 1
875+
#endif
900876
return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO;
901877
}
902878

903879
os_file_handle
904880
os_convert_stderr_handle(os_raw_file_handle raw_stderr)
905881
{
882+
#ifndef STDERR_FILENO
883+
#define STDERR_FILENO 2
884+
#endif
906885
return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO;
907886
}
908887

core/shared/platform/include/platform_api_extension.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,33 +1503,6 @@ os_convert_stdout_handle(os_raw_file_handle raw_stdout);
15031503
os_file_handle
15041504
os_convert_stderr_handle(os_raw_file_handle raw_stderr);
15051505

1506-
/**
1507-
*
1508-
* @param fd a file handle
1509-
*
1510-
* @return true if it is stdin
1511-
*/
1512-
bool
1513-
os_is_stdin_handle(os_file_handle fd);
1514-
1515-
/**
1516-
*
1517-
* @param fd a file handle
1518-
*
1519-
* @return true if it is stdout
1520-
*/
1521-
bool
1522-
os_is_stdout_handle(os_file_handle fd);
1523-
1524-
/**
1525-
*
1526-
* @param fd a file handle
1527-
*
1528-
* @return true if it is stderr
1529-
*/
1530-
bool
1531-
os_is_stderr_handle(os_file_handle fd);
1532-
15331506
/**
15341507
* Open a directory stream for the provided directory handle. The returned
15351508
* directory stream will be positioned at the first entry in the directory.

core/shared/platform/windows/win_file.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,24 +1540,6 @@ create_stdio_handle(HANDLE raw_stdio_handle, DWORD stdio)
15401540
return stdio_handle;
15411541
}
15421542

1543-
bool
1544-
os_is_stdin_handle(os_file_handle fd)
1545-
{
1546-
return fd->raw.handle == GetStdHandle(STD_INPUT_HANDLE);
1547-
}
1548-
1549-
bool
1550-
os_is_stdout_handle(os_file_handle fd)
1551-
{
1552-
return fd->raw.handle == GetStdHandle(STD_OUTPUT_HANDLE);
1553-
}
1554-
1555-
bool
1556-
os_is_stderr_handle(os_file_handle fd)
1557-
{
1558-
return fd->raw.handle == GetStdHandle(STD_ERROR_HANDLE);
1559-
}
1560-
15611543
os_file_handle
15621544
os_convert_stdin_handle(os_raw_file_handle raw_stdin)
15631545
{

0 commit comments

Comments
 (0)