authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-12-06 23:48:35+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-06 22:48:35+00:00
log817cf6a82efa7ed274371a28621bbf88a723d9b7
tree20bd7930448899b0db67294c208eca4442e17f09
parentd4adf4420071397d993bac629a9da27b33c67ca3
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Update wasi-libc to 8b7148f69ae241a2749b3defe4606da8143b72e0 (#13793)


4 files changed, 51 insertions(+), 3 deletions(-)

lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c+30-1
...@@ -3,6 +3,9 @@...@@ -3,6 +3,9 @@
3// SPDX-License-Identifier: BSD-2-Clause3// SPDX-License-Identifier: BSD-2-Clause
44
5#include <sys/stat.h>5#include <sys/stat.h>
6#include <sys/types.h>
7#include <unistd.h>
8#include <fcntl.h>
69
7#include <assert.h>10#include <assert.h>
8#include <wasi/api.h>11#include <wasi/api.h>
...@@ -77,10 +80,36 @@ struct dirent *readdir(DIR *dirp) {...@@ -77,10 +80,36 @@ struct dirent *readdir(DIR *dirp) {
77 GROW(dirp->dirent, dirp->dirent_size,80 GROW(dirp->dirent, dirp->dirent_size,
78 offsetof(struct dirent, d_name) + entry.d_namlen + 1);81 offsetof(struct dirent, d_name) + entry.d_namlen + 1);
79 struct dirent *dirent = dirp->dirent;82 struct dirent *dirent = dirp->dirent;
80 dirent->d_ino = entry.d_ino;
81 dirent->d_type = entry.d_type;83 dirent->d_type = entry.d_type;
82 memcpy(dirent->d_name, name, entry.d_namlen);84 memcpy(dirent->d_name, name, entry.d_namlen);
83 dirent->d_name[entry.d_namlen] = '\0';85 dirent->d_name[entry.d_namlen] = '\0';
86
87 // `fd_readdir` implementations may set the inode field to zero if the
88 // the inode number is unknown. In that case, do an `fstatat` to get the
89 // inode number.
90 off_t d_ino = entry.d_ino;
91 unsigned char d_type = entry.d_type;
92 if (d_ino == 0 && strcmp(dirent->d_name, "..") != 0) {
93 struct stat statbuf;
94 if (fstatat(dirp->fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) {
95 if (errno == ENOENT) {
96 // The file disappeared before we could read it, so skip it.
97 dirp->buffer_processed += entry_size;
98 continue;
99 }
100 return NULL;
101 }
102
103 // Fill in the inode.
104 d_ino = statbuf.st_ino;
105
106 // In case someone raced with us and replaced the object with this name
107 // with another of a different type, update the type too.
108 d_type = __wasilibc_iftodt(statbuf.st_mode & S_IFMT);
109 }
110 dirent->d_ino = d_ino;
111 dirent->d_type = d_type;
112
84 dirp->cookie = entry.d_next;113 dirp->cookie = entry.d_next;
85 dirp->buffer_processed += entry_size;114 dirp->buffer_processed += entry_size;
86 return dirent;115 return dirent;
lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c+18
...@@ -1,6 +1,11 @@...@@ -1,6 +1,11 @@
1#include <string.h>1#include <string.h>
2#include <stdint.h>2#include <stdint.h>
3#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
3#include "pthread_impl.h"4#include "pthread_impl.h"
5#else
6// In non-_REENTRANT, include it for `a_crash`
7# include "atomic.h"
8#endif
49
5uintptr_t __stack_chk_guard;10uintptr_t __stack_chk_guard;
611
...@@ -18,7 +23,9 @@ void __init_ssp(void *entropy)...@@ -18,7 +23,9 @@ void __init_ssp(void *entropy)
18 ((char *)&__stack_chk_guard)[1] = 0;23 ((char *)&__stack_chk_guard)[1] = 0;
19#endif24#endif
2025
26#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
21 __pthread_self()->canary = __stack_chk_guard;27 __pthread_self()->canary = __stack_chk_guard;
28#endif
22}29}
2330
24void __stack_chk_fail(void)31void __stack_chk_fail(void)
...@@ -29,3 +36,14 @@ void __stack_chk_fail(void)...@@ -29,3 +36,14 @@ void __stack_chk_fail(void)
29hidden void __stack_chk_fail_local(void);36hidden void __stack_chk_fail_local(void);
3037
31weak_alias(__stack_chk_fail, __stack_chk_fail_local);38weak_alias(__stack_chk_fail, __stack_chk_fail_local);
39
40#ifndef __wasilibc_unmodified_upstream
41# include <wasi/api.h>
42
43__attribute__((constructor(60)))
44static void __wasilibc_init_ssp(void) {
45 uintptr_t entropy;
46 int r = __wasi_random_get((uint8_t *)&entropy, sizeof(uintptr_t));
47 __init_ssp(r ? NULL : &entropy);
48}
49#endif
src/target.zig+2-2
...@@ -328,8 +328,8 @@ pub fn supportsStackProbing(target: std.Target) bool {...@@ -328,8 +328,8 @@ pub fn supportsStackProbing(target: std.Target) bool {
328}328}
329329
330pub fn supportsStackProtector(target: std.Target) bool {330pub fn supportsStackProtector(target: std.Target) bool {
331 // TODO: investigate whether stack-protector works on wasm331 _ = target;
332 return !target.isWasm();332 return true;
333}333}
334334
335pub fn libcProvidesStackProtector(target: std.Target) bool {335pub fn libcProvidesStackProtector(target: std.Target) bool {
src/wasi_libc.zig+1
...@@ -551,6 +551,7 @@ const libc_top_half_src_files = [_][]const u8{...@@ -551,6 +551,7 @@ const libc_top_half_src_files = [_][]const u8{
551 "wasi/libc-top-half/musl/src/fcntl/creat.c",551 "wasi/libc-top-half/musl/src/fcntl/creat.c",
552 "wasi/libc-top-half/musl/src/dirent/alphasort.c",552 "wasi/libc-top-half/musl/src/dirent/alphasort.c",
553 "wasi/libc-top-half/musl/src/dirent/versionsort.c",553 "wasi/libc-top-half/musl/src/dirent/versionsort.c",
554 "wasi/libc-top-half/musl/src/env/__stack_chk_fail.c",
554 "wasi/libc-top-half/musl/src/env/clearenv.c",555 "wasi/libc-top-half/musl/src/env/clearenv.c",
555 "wasi/libc-top-half/musl/src/env/getenv.c",556 "wasi/libc-top-half/musl/src/env/getenv.c",
556 "wasi/libc-top-half/musl/src/env/putenv.c",557 "wasi/libc-top-half/musl/src/env/putenv.c",