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 @@
33// SPDX-License-Identifier: BSD-2-Clause
44
55#include <sys/stat.h>
6#include <sys/types.h>
7#include <unistd.h>
8#include <fcntl.h>
69
710#include <assert.h>
811#include <wasi/api.h>
......@@ -77,10 +80,36 @@ struct dirent *readdir(DIR *dirp) {
7780 GROW(dirp->dirent, dirp->dirent_size,
7881 offsetof(struct dirent, d_name) + entry.d_namlen + 1);
7982 struct dirent *dirent = dirp->dirent;
80 dirent->d_ino = entry.d_ino;
8183 dirent->d_type = entry.d_type;
8284 memcpy(dirent->d_name, name, entry.d_namlen);
8385 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
84113 dirp->cookie = entry.d_next;
85114 dirp->buffer_processed += entry_size;
86115 return dirent;
lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c+18
......@@ -1,6 +1,11 @@
11#include <string.h>
22#include <stdint.h>
3#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
34#include "pthread_impl.h"
5#else
6// In non-_REENTRANT, include it for `a_crash`
7# include "atomic.h"
8#endif
49
510uintptr_t __stack_chk_guard;
611
......@@ -18,7 +23,9 @@ void __init_ssp(void *entropy)
1823 ((char *)&__stack_chk_guard)[1] = 0;
1924#endif
2025
26#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
2127 __pthread_self()->canary = __stack_chk_guard;
28#endif
2229}
2330
2431void __stack_chk_fail(void)
......@@ -29,3 +36,14 @@ void __stack_chk_fail(void)
2936hidden void __stack_chk_fail_local(void);
3037
3138weak_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 {
328328}
329329
330330pub fn supportsStackProtector(target: std.Target) bool {
331 // TODO: investigate whether stack-protector works on wasm
332 return !target.isWasm();
331 _ = target;
332 return true;
333333}
334334
335335pub fn libcProvidesStackProtector(target: std.Target) bool {
src/wasi_libc.zig+1
......@@ -551,6 +551,7 @@ const libc_top_half_src_files = [_][]const u8{
551551 "wasi/libc-top-half/musl/src/fcntl/creat.c",
552552 "wasi/libc-top-half/musl/src/dirent/alphasort.c",
553553 "wasi/libc-top-half/musl/src/dirent/versionsort.c",
554 "wasi/libc-top-half/musl/src/env/__stack_chk_fail.c",
554555 "wasi/libc-top-half/musl/src/env/clearenv.c",
555556 "wasi/libc-top-half/musl/src/env/getenv.c",
556557 "wasi/libc-top-half/musl/src/env/putenv.c",