| author | |
| committer | |
| log | 817cf6a82efa7ed274371a28621bbf88a723d9b7 |
| tree | 20bd7930448899b0db67294c208eca4442e17f09 |
| parent | d4adf4420071397d993bac629a9da27b33c67ca3 |
| signature |
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-Clause | 3 | // SPDX-License-Identifier: BSD-2-Clause |
| 4 | 4 | ||
| 5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
| 6 | #include <sys/types.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <fcntl.h> | ||
| 6 | 9 | ||
| 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 | ||
| 4 | 9 | ||
| 5 | uintptr_t __stack_chk_guard; | 10 | uintptr_t __stack_chk_guard; |
| 6 | 11 | ||
| ... | @@ -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 | #endif | 24 | #endif |
| 20 | 25 | ||
| 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 | } |
| 23 | 30 | ||
| 24 | void __stack_chk_fail(void) | 31 | void __stack_chk_fail(void) |
| ... | @@ -29,3 +36,14 @@ void __stack_chk_fail(void) | ... | @@ -29,3 +36,14 @@ void __stack_chk_fail(void) |
| 29 | hidden void __stack_chk_fail_local(void); | 36 | hidden void __stack_chk_fail_local(void); |
| 30 | 37 | ||
| 31 | weak_alias(__stack_chk_fail, __stack_chk_fail_local); | 38 | weak_alias(__stack_chk_fail, __stack_chk_fail_local); |
| 39 | |||
| 40 | #ifndef __wasilibc_unmodified_upstream | ||
| 41 | # include <wasi/api.h> | ||
| 42 | |||
| 43 | __attribute__((constructor(60))) | ||
| 44 | static 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 | } |
| 329 | 329 | ||
| 330 | pub fn supportsStackProtector(target: std.Target) bool { | 330 | pub fn supportsStackProtector(target: std.Target) bool { |
| 331 | // TODO: investigate whether stack-protector works on wasm | 331 | _ = target; |
| 332 | return !target.isWasm(); | 332 | return true; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | pub fn libcProvidesStackProtector(target: std.Target) bool { | 335 | pub 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", |