-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Conditionalize use of POSIX features missing on WASI/WebAssembly #92677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ static std::error_code getHostID(SmallVectorImpl<char> &HostID) { | |
| StringRef UUIDRef(UUIDStr); | ||
| HostID.append(UUIDRef.begin(), UUIDRef.end()); | ||
|
|
||
| #elif LLVM_ON_UNIX | ||
| #elif !defined(__wasi__) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're changing behavior for
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this is the cause of buildbot failures that I missed during my own review. |
||
| char HostName[256]; | ||
| HostName[255] = 0; | ||
| HostName[0] = 0; | ||
|
|
@@ -111,7 +111,7 @@ static std::error_code getHostID(SmallVectorImpl<char> &HostID) { | |
| } | ||
|
|
||
| bool LockFileManager::processStillExecuting(StringRef HostID, int PID) { | ||
| #if LLVM_ON_UNIX && !defined(__ANDROID__) | ||
| #if LLVM_ON_UNIX && !defined(__ANDROID__) && !defined(__wasi__) | ||
| SmallString<256> StoredHostID; | ||
| if (getHostID(StoredHostID)) | ||
| return true; // Conservatively assume it's executing on error. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,9 +273,19 @@ static bool printMarkupStackTrace(StringRef Argv0, void **StackTrace, int Depth, | |
| } | ||
|
|
||
| // Include the platform-specific parts of this class. | ||
| #ifdef LLVM_ON_UNIX | ||
| #if defined(__wasi__) | ||
| // WASI does not have signals. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these stubs to WASI/Signals.inc for consistency with the other platform support files. |
||
| void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr, | ||
| void *Cookie) {} | ||
| void llvm::sys::RunInterruptHandlers() {} | ||
| void sys::CleanupOnSignal(uintptr_t Context) {} | ||
| bool llvm::sys::RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg) { | ||
| return false; | ||
| } | ||
| void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) {} | ||
| void llvm::sys::DisableSystemDialogsOnCrash() {} | ||
| #elif defined(LLVM_ON_UNIX) | ||
| #include "Unix/Signals.inc" | ||
| #endif | ||
| #ifdef _WIN32 | ||
| #elif defined(_WIN32) | ||
| #include "Windows/Signals.inc" | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ | |
| #endif | ||
|
|
||
| #include <dirent.h> | ||
| #if !defined(__wasi__) | ||
| #include <pwd.h> | ||
| #endif | ||
| #include <sys/file.h> | ||
|
|
||
| #ifdef __APPLE__ | ||
|
|
@@ -126,10 +128,12 @@ namespace fs { | |
|
|
||
| const file_t kInvalidFile = -1; | ||
|
|
||
| #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ | ||
| defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) || \ | ||
| defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \ | ||
| (defined(__sun__) && defined(__svr4__) || defined(__HAIKU__)) | ||
| #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ | ||
| defined(__FreeBSD_kernel__) || defined(__linux__) || \ | ||
| defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || \ | ||
| defined(__GNU__) || \ | ||
| (defined(__sun__) && defined(__svr4__) || defined(__HAIKU__)) || \ | ||
| defined(__wasi__) | ||
| static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { | ||
| struct stat sb; | ||
| char fullpath[PATH_MAX]; | ||
|
|
@@ -283,7 +287,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { | |
| // Fall back to the classical detection. | ||
| if (getprogpath(exe_path, argv0)) | ||
| return exe_path; | ||
| #elif defined(__OpenBSD__) || defined(__HAIKU__) | ||
| #elif defined(__OpenBSD__) || defined(__HAIKU__) || defined(__wasi__) | ||
| char exe_path[PATH_MAX]; | ||
| // argv[0] only | ||
| if (getprogpath(exe_path, argv0) != NULL) | ||
|
|
@@ -508,6 +512,9 @@ static bool is_local_impl(struct STATVFS &Vfs) { | |
| #elif defined(__EMSCRIPTEN__) | ||
| // Emscripten doesn't currently support remote filesystem mounts. | ||
| return true; | ||
| #elif defined(__wasi__) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does emscripten no longer have asm.js mode? Last time I checked it did, but I'm not sure if it still does today...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't; C++ compilation only targets wasm. The emscripten driver still supports generating javascript, but only via invoking the binaryen "wasm2js" tool post-link -- which translates the wasm binary into javascript. |
||
| // WASI doesn't currently support remote filesystem mounts. | ||
| return true; | ||
| #elif defined(__HAIKU__) | ||
| // Haiku doesn't expose this information. | ||
| return false; | ||
|
|
@@ -673,6 +680,11 @@ static void expandTildeExpr(SmallVectorImpl<char> &Path) { | |
| return; | ||
| } | ||
|
|
||
| #if defined(__wasi__) | ||
| // No access to password database, return back the original path. | ||
| (void)Remainder; | ||
| return; | ||
| #else | ||
| // This is a string of the form ~username/, look up this user's entry in the | ||
| // password database. | ||
| std::unique_ptr<char[]> Buf; | ||
|
|
@@ -694,6 +706,7 @@ static void expandTildeExpr(SmallVectorImpl<char> &Path) { | |
| Path.clear(); | ||
| Path.append(Entry->pw_dir, Entry->pw_dir + strlen(Entry->pw_dir)); | ||
| llvm::sys::path::append(Path, Storage); | ||
| #endif | ||
| } | ||
|
|
||
| void expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) { | ||
|
|
@@ -770,11 +783,15 @@ std::error_code status(int FD, file_status &Result) { | |
| } | ||
|
|
||
| unsigned getUmask() { | ||
| #if defined(__wasi__) | ||
| return 0022; | ||
| #else | ||
| // Chose arbitary new mask and reset the umask to the old mask. | ||
| // umask(2) never fails so ignore the return of the second call. | ||
| unsigned Mask = ::umask(0); | ||
| (void)::umask(Mask); | ||
| return Mask; | ||
| #endif | ||
| } | ||
|
|
||
| std::error_code setPermissions(const Twine &Path, perms Permissions) { | ||
|
|
@@ -880,7 +897,7 @@ void mapped_file_region::dontNeedImpl() { | |
| assert(Mode == mapped_file_region::readonly); | ||
| if (!Mapping) | ||
| return; | ||
| #if defined(__MVS__) || defined(_AIX) | ||
| #if defined(__MVS__) || defined(_AIX) || defined(__wasi__) | ||
| // If we don't have madvise, or it isn't beneficial, treat this as a no-op. | ||
| #elif defined(POSIX_MADV_DONTNEED) | ||
| ::posix_madvise(Mapping, Size, POSIX_MADV_DONTNEED); | ||
|
|
@@ -1224,6 +1241,9 @@ Expected<size_t> readNativeFileSlice(file_t FD, MutableArrayRef<char> Buf, | |
| } | ||
|
|
||
| std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) { | ||
| #if defined(__wasi__) | ||
| return std::error_code(ENOSYS, std::generic_category()); | ||
| #else | ||
| auto Start = std::chrono::steady_clock::now(); | ||
| auto End = Start + Timeout; | ||
| do { | ||
|
|
@@ -1241,9 +1261,13 @@ std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) { | |
| usleep(1000); | ||
| } while (std::chrono::steady_clock::now() < End); | ||
| return make_error_code(errc::no_lock_available); | ||
| #endif | ||
| } | ||
|
|
||
| std::error_code lockFile(int FD) { | ||
| #if defined(__wasi__) | ||
| return std::error_code(ENOSYS, std::generic_category()); | ||
| #else | ||
| struct flock Lock; | ||
| memset(&Lock, 0, sizeof(Lock)); | ||
| Lock.l_type = F_WRLCK; | ||
|
|
@@ -1253,9 +1277,13 @@ std::error_code lockFile(int FD) { | |
| if (::fcntl(FD, F_SETLKW, &Lock) != -1) | ||
| return std::error_code(); | ||
| return errnoAsErrorCode(); | ||
| #endif | ||
| } | ||
|
|
||
| std::error_code unlockFile(int FD) { | ||
| #if defined(__wasi__) | ||
| return std::error_code(ENOSYS, std::generic_category()); | ||
| #else | ||
| struct flock Lock; | ||
| Lock.l_type = F_UNLCK; | ||
| Lock.l_whence = SEEK_SET; | ||
|
|
@@ -1264,6 +1292,7 @@ std::error_code unlockFile(int FD) { | |
| if (::fcntl(FD, F_SETLK, &Lock) != -1) | ||
| return std::error_code(); | ||
| return errnoAsErrorCode(); | ||
| #endif | ||
| } | ||
|
|
||
| std::error_code closeFile(file_t &F) { | ||
|
|
@@ -1335,11 +1364,15 @@ std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest, | |
| } | ||
|
|
||
| std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group) { | ||
| #if defined(__wasi__) | ||
| return std::error_code(ENOTSUP, std::generic_category()); | ||
| #else | ||
| auto FChown = [&]() { return ::fchown(FD, Owner, Group); }; | ||
| // Retry if fchown call fails due to interruption. | ||
| if ((sys::RetryAfterSignal(-1, FChown)) < 0) | ||
| return errnoAsErrorCode(); | ||
| return std::error_code(); | ||
| #endif | ||
| } | ||
|
|
||
| } // end namespace fs | ||
|
|
@@ -1349,6 +1382,7 @@ namespace path { | |
| bool home_directory(SmallVectorImpl<char> &result) { | ||
| std::unique_ptr<char[]> Buf; | ||
| char *RequestedDir = getenv("HOME"); | ||
| #if !defined(__wasi__) | ||
| if (!RequestedDir) { | ||
| long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX); | ||
| if (BufSize <= 0) | ||
|
|
@@ -1360,6 +1394,7 @@ bool home_directory(SmallVectorImpl<char> &result) { | |
| if (pw && pw->pw_dir) | ||
| RequestedDir = pw->pw_dir; | ||
| } | ||
| #endif | ||
| if (!RequestedDir) | ||
| return false; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be
__wasi__rather than__wasm__since the later is the architecture, which by itself doesn't mean we haveendian.havailable.