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"
|
2016-04-20 15:02:16 +00:00
|
|
|
#include "platform/globals.h"
|
2011-11-07 15:04:42 +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.
|
2011-11-07 15:04:42 +00:00
|
|
|
static const char* OperatingSystem();
|
|
|
|
|
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).
|
2016-04-20 15:02:16 +00:00
|
|
|
static const char* HostArchitecture() {
|
|
|
|
#if defined(HOST_ARCH_ARM)
|
|
|
|
return "arm";
|
|
|
|
#elif defined(HOST_ARCH_ARM64)
|
|
|
|
return "arm64";
|
|
|
|
#elif defined(HOST_ARCH_IA32)
|
|
|
|
return "ia32";
|
|
|
|
#elif defined(HOST_ARCH_X64)
|
|
|
|
return "x64";
|
|
|
|
#else
|
|
|
|
#error Architecture detection failed.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
if (resolved_executable_name_ == NULL) {
|
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();
|
|
|
|
if (resolved_name != NULL) {
|
|
|
|
resolved_executable_name_ = strdup(resolved_name);
|
|
|
|
}
|
2015-05-20 11:14:51 +00:00
|
|
|
}
|
2015-06-15 08:13:21 +00:00
|
|
|
return resolved_executable_name_;
|
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
|
|
|
|
2018-12-06 19:09:06 +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);
|
|
|
|
|
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_;
|
2015-06-15 08:13:21 +00:00
|
|
|
// The path to the resolved executable.
|
2016-03-18 15:34:23 +00:00
|
|
|
static 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_
|