dart-sdk/runtime/platform/utils_linux.cc
Vyacheslav Egorov aaca6ce34a [vm] Fix running under WSL 1
On WSL 1 trying to allocate memory close to the binary
by supplying a hint fails with ENOMEM for unclear reason.
Some reports suggest that this might be related to the
alignment of the hint but aligning it by 64Kb does not
make the issue go away in our experiments. Instead
just retry without any hint.

Fixes https://github.com/dart-lang/sdk/issues/54587

TEST=manually under WSL 1

Change-Id: I0adf997fbf76e470a57da00f5ce7a26bb50706f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345802
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-01-11 22:24:44 +00:00

70 lines
1.6 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "platform/globals.h"
#if defined(DART_HOST_OS_LINUX)
#include <sys/utsname.h>
#include "platform/utils.h"
#include "platform/utils_linux.h"
namespace dart {
char* Utils::StrNDup(const char* s, intptr_t n) {
return strndup(s, n);
}
char* Utils::StrDup(const char* s) {
return strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
return strnlen(s, n);
}
int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
va_list args;
va_start(args, format);
int retval = VSNPrint(str, size, format, args);
va_end(args);
return retval;
}
int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
MSAN_UNPOISON(str, size);
int retval = vsnprintf(str, size, format, args);
if (retval < 0) {
FATAL("Fatal error in Utils::VSNPrint with format '%s'", format);
}
return retval;
}
int Utils::Close(int fildes) {
return close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return unlink(path);
}
bool Utils::IsWindowsSubsystemForLinux() {
struct utsname info;
if (uname(&info) != 0) {
return false; // Not sure.
}
// If info.release contains either Microsoft or microsoft then we are
// most likely running under WSL.
return strstr(info.release, "icrosoft") != nullptr;
}
} // namespace dart
#endif // defined(DART_HOST_OS_LINUX)