2012-04-17 16:20:28 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-11-07 15:04:42 +00:00
|
|
|
// 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.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_BIN_PLATFORM_H_
|
|
|
|
#define RUNTIME_BIN_PLATFORM_H_
|
2011-11-07 15:04:42 +00:00
|
|
|
|
|
|
|
#include "bin/builtin.h"
|
2021-07-15 15:26:55 +00:00
|
|
|
|
|
|
|
#include "platform/atomic.h"
|
2016-04-20 15:02:16 +00:00
|
|
|
#include "platform/globals.h"
|
2020-06-25 03:36:41 +00:00
|
|
|
#include "platform/utils.h"
|
2011-11-07 15:04:42 +00:00
|
|
|
|
2021-07-02 19:06:45 +00:00
|
|
|
#if defined(DART_HOST_OS_MACOS)
|
2020-07-07 21:07:55 +00:00
|
|
|
#include "bin/platform_macos.h"
|
2021-07-02 19:06:45 +00:00
|
|
|
#endif // defined(DART_HOST_OS_MACOS)
|
2020-07-07 21:07:55 +00:00
|
|
|
|
2013-04-25 14:22:30 +00:00
|
|
|
namespace dart {
|
|
|
|
namespace bin {
|
|
|
|
|
2011-11-07 15:04:42 +00:00
|
|
|
class Platform {
|
|
|
|
public:
|
2019-09-24 20:43:20 +00:00
|
|
|
// Perform platform specific initialization.
|
|
|
|
static bool Initialize();
|
2011-11-23 14:49:18 +00:00
|
|
|
|
2011-11-09 11:22:33 +00:00
|
|
|
// Returns the number of processors on the machine.
|
2011-11-07 15:04:42 +00:00
|
|
|
static int NumberOfProcessors();
|
2011-11-09 11:22:33 +00:00
|
|
|
|
|
|
|
// Returns a string representing the operating system ("linux",
|
2016-04-20 15:02:16 +00:00
|
|
|
// "macos", "windows", or "android"). The returned string should not be
|
2011-11-09 11:22:33 +00:00
|
|
|
// deallocated by the caller.
|
[vm] Add OS and architecture to non-symbolic stack traces.
Examples of the new line added to non-symbolic stack traces:
os: linux arch: x64 comp: yes sim: no
(Running on linux-x64c)
os: macos arch: arm64 comp: no sim: yes
(Running on mac-simarm64)
This CL also abstracts out the separate hardcoded strings across
the codebase for host and target OS and architecture into
definitions in platform/globals.h to ensure that they stay
in sync across different uses.
TEST=vm/dart{,_2}/use_dwarf_stack_traces_flag
Issue: https://github.com/flutter/flutter/pull/101586
Change-Id: Ifdfea5138dd1003f561da0174e89aebc165bf9b0
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253283
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-08-05 11:53:37 +00:00
|
|
|
static const char* OperatingSystem() { return kHostOperatingSystemName; }
|
2011-11-07 15:04:42 +00:00
|
|
|
|
2017-09-02 05:08:45 +00:00
|
|
|
// Returns a string representing the version of the operating system. The
|
|
|
|
// format of the string is determined by the platform. The returned string
|
|
|
|
// should not be deallocated by the caller.
|
|
|
|
static const char* OperatingSystemVersion();
|
|
|
|
|
2016-04-20 15:02:16 +00:00
|
|
|
// Returns the architecture name of the processor the VM is running on
|
2017-06-22 15:49:19 +00:00
|
|
|
// (ia32, x64, arm, or arm64).
|
[vm] Add OS and architecture to non-symbolic stack traces.
Examples of the new line added to non-symbolic stack traces:
os: linux arch: x64 comp: yes sim: no
(Running on linux-x64c)
os: macos arch: arm64 comp: no sim: yes
(Running on mac-simarm64)
This CL also abstracts out the separate hardcoded strings across
the codebase for host and target OS and architecture into
definitions in platform/globals.h to ensure that they stay
in sync across different uses.
TEST=vm/dart{,_2}/use_dwarf_stack_traces_flag
Issue: https://github.com/flutter/flutter/pull/101586
Change-Id: Ifdfea5138dd1003f561da0174e89aebc165bf9b0
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253283
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-08-05 11:53:37 +00:00
|
|
|
static const char* HostArchitecture() { return kHostArchitectureName; }
|
2016-04-20 15:02:16 +00:00
|
|
|
|
|
|
|
static const char* LibraryPrefix();
|
|
|
|
|
2015-01-29 18:31:27 +00:00
|
|
|
// Returns a string representing the operating system's shared library
|
|
|
|
// extension (e.g. 'so', 'dll', ...). The returned string should not be
|
|
|
|
// deallocated by the caller.
|
|
|
|
static const char* LibraryExtension();
|
|
|
|
|
2012-04-11 12:27:55 +00:00
|
|
|
// Extracts the local hostname.
|
2012-04-17 16:20:28 +00:00
|
|
|
static bool LocalHostname(char* buffer, intptr_t buffer_length);
|
|
|
|
|
2017-03-30 20:51:44 +00:00
|
|
|
static const char* LocaleName();
|
|
|
|
|
2016-03-14 18:08:52 +00:00
|
|
|
// Extracts the environment variables for the current process. The array of
|
|
|
|
// strings is Dart_ScopeAllocated. The number of elements in the array is
|
|
|
|
// returned in the count argument.
|
2012-04-17 16:20:28 +00:00
|
|
|
static char** Environment(intptr_t* count);
|
2012-04-11 12:27:55 +00:00
|
|
|
|
2016-03-14 18:08:52 +00:00
|
|
|
static const char* ResolveExecutablePath();
|
2015-05-20 11:14:51 +00:00
|
|
|
|
2019-10-18 10:30:48 +00:00
|
|
|
// This has the same effect as calling ResolveExecutablePath except that
|
|
|
|
// Dart_ScopeAllocate is not called and that the result goes into the given
|
|
|
|
// parameters.
|
|
|
|
// WARNING: On Fuchsia it returns -1, i.e. doesn't work.
|
2019-09-17 07:25:38 +00:00
|
|
|
// Note that `result` should be pre-allocated with size `result_size`.
|
|
|
|
// The return-value is the length read into `result` or -1 on failure.
|
|
|
|
static intptr_t ResolveExecutablePathInto(char* result, size_t result_size);
|
|
|
|
|
2015-05-20 11:14:51 +00:00
|
|
|
// Stores the executable name.
|
2013-08-08 07:19:21 +00:00
|
|
|
static void SetExecutableName(const char* executable_name) {
|
|
|
|
executable_name_ = executable_name;
|
|
|
|
}
|
2017-06-15 16:05:51 +00:00
|
|
|
static const char* GetExecutableName();
|
2015-06-15 08:13:21 +00:00
|
|
|
static const char* GetResolvedExecutableName() {
|
2021-07-15 15:26:55 +00:00
|
|
|
if (resolved_executable_name_.load() == nullptr) {
|
2015-05-20 11:14:51 +00:00
|
|
|
// Try to resolve the executable path using platform specific APIs.
|
2016-05-06 21:29:53 +00:00
|
|
|
const char* resolved_name = Platform::ResolveExecutablePath();
|
2021-07-15 15:26:55 +00:00
|
|
|
if (resolved_name != nullptr) {
|
|
|
|
char* resolved_name_copy = Utils::StrDup(resolved_name);
|
|
|
|
const char* expect_old_is_null = nullptr;
|
|
|
|
if (!resolved_executable_name_.compare_exchange_strong(
|
|
|
|
expect_old_is_null, resolved_name_copy)) {
|
|
|
|
free(resolved_name_copy);
|
|
|
|
}
|
2016-05-06 21:29:53 +00:00
|
|
|
}
|
2015-05-20 11:14:51 +00:00
|
|
|
}
|
2021-07-15 15:26:55 +00:00
|
|
|
return resolved_executable_name_.load();
|
2013-08-08 07:19:21 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 15:21:55 +00:00
|
|
|
// Stores and gets the flags passed to the executable.
|
|
|
|
static void SetExecutableArguments(int script_index, char** argv) {
|
|
|
|
script_index_ = script_index;
|
|
|
|
argv_ = argv;
|
|
|
|
}
|
2016-11-04 19:30:56 +00:00
|
|
|
static int GetScriptIndex() { return script_index_; }
|
|
|
|
static char** GetArgv() { return argv_; }
|
2013-08-21 15:21:55 +00:00
|
|
|
|
2021-08-31 19:33:10 +00:00
|
|
|
static void SetProcessName(const char* name);
|
|
|
|
|
2018-12-06 19:09:06 +00:00
|
|
|
DART_NORETURN static void Exit(int exit_code);
|
2023-09-05 22:15:58 +00:00
|
|
|
DART_NORETURN static void _Exit(int exit_code);
|
2015-10-30 06:35:46 +00:00
|
|
|
|
2018-11-30 11:15:06 +00:00
|
|
|
static void SetCoreDumpResourceLimit(int value);
|
|
|
|
|
2023-06-20 19:28:18 +00:00
|
|
|
#if defined(DART_HOST_OS_FUCHSIA)
|
|
|
|
static zx_handle_t GetVMEXResource();
|
|
|
|
#endif
|
|
|
|
|
2011-11-07 15:04:42 +00:00
|
|
|
private:
|
2015-05-20 11:14:51 +00:00
|
|
|
// The path to the executable.
|
2013-08-08 07:19:21 +00:00
|
|
|
static const char* executable_name_;
|
2021-07-15 15:26:55 +00:00
|
|
|
|
2015-06-15 08:13:21 +00:00
|
|
|
// The path to the resolved executable.
|
2021-07-15 15:26:55 +00:00
|
|
|
//
|
|
|
|
// We use require-release semantics to ensure initializing stores to the
|
|
|
|
// string are visible when the string becomes visible.
|
|
|
|
static AcqRelAtomic<const char*> resolved_executable_name_;
|
2015-05-20 11:14:51 +00:00
|
|
|
|
2013-08-21 15:21:55 +00:00
|
|
|
static int script_index_;
|
|
|
|
static char** argv_; // VM flags are argv_[1 ... script_index_ - 1]
|
2013-08-08 07:19:21 +00:00
|
|
|
|
2011-11-07 15:04:42 +00:00
|
|
|
DISALLOW_ALLOCATION();
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Platform);
|
|
|
|
};
|
|
|
|
|
2013-04-25 14:22:30 +00:00
|
|
|
} // namespace bin
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_BIN_PLATFORM_H_
|