Flutter Engine
The Flutter Engine
platform.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_PLATFORM_H_
6#define RUNTIME_BIN_PLATFORM_H_
7
8#include "bin/builtin.h"
9
10#include "platform/atomic.h"
11#include "platform/globals.h"
12#include "platform/utils.h"
13
14#if defined(DART_HOST_OS_MACOS)
15#include "bin/platform_macos.h"
16#endif // defined(DART_HOST_OS_MACOS)
17
18namespace dart {
19namespace bin {
20
21class Platform {
22 public:
23 // Perform platform specific initialization.
24 static bool Initialize();
25
26 // Returns the number of processors on the machine.
27 static int NumberOfProcessors();
28
29 // Returns a string representing the operating system ("linux",
30 // "macos", "windows", or "android"). The returned string should not be
31 // deallocated by the caller.
32 static const char* OperatingSystem() { return kHostOperatingSystemName; }
33
34 // Returns a string representing the version of the operating system. The
35 // format of the string is determined by the platform. The returned string
36 // should not be deallocated by the caller.
37 static const char* OperatingSystemVersion();
38
39 // Returns the architecture name of the processor the VM is running on
40 // (ia32, x64, arm, or arm64).
41 static const char* HostArchitecture() { return kHostArchitectureName; }
42
43 static const char* LibraryPrefix();
44
45 // Returns a string representing the operating system's shared library
46 // extension (e.g. 'so', 'dll', ...). The returned string should not be
47 // deallocated by the caller.
48 static const char* LibraryExtension();
49
50 // Extracts the local hostname.
51 static bool LocalHostname(char* buffer, intptr_t buffer_length);
52
53 static const char* LocaleName();
54
55 // Extracts the environment variables for the current process. The array of
56 // strings is Dart_ScopeAllocated. The number of elements in the array is
57 // returned in the count argument.
58 static char** Environment(intptr_t* count);
59
60 static const char* ResolveExecutablePath();
61
62 // This has the same effect as calling ResolveExecutablePath except that
63 // Dart_ScopeAllocate is not called and that the result goes into the given
64 // parameters.
65 // WARNING: On Fuchsia it returns -1, i.e. doesn't work.
66 // Note that `result` should be pre-allocated with size `result_size`.
67 // The return-value is the length read into `result` or -1 on failure.
68 static intptr_t ResolveExecutablePathInto(char* result, size_t result_size);
69
70 // Stores the executable name.
71 static void SetExecutableName(const char* executable_name) {
72 executable_name_ = executable_name;
73 }
74 static const char* GetExecutableName();
75 static const char* GetResolvedExecutableName() {
76 if (resolved_executable_name_.load() == nullptr) {
77 // Try to resolve the executable path using platform specific APIs.
78 const char* resolved_name = Platform::ResolveExecutablePath();
79 if (resolved_name != nullptr) {
80 char* resolved_name_copy = Utils::StrDup(resolved_name);
81 const char* expect_old_is_null = nullptr;
82 if (!resolved_executable_name_.compare_exchange_strong(
83 expect_old_is_null, resolved_name_copy)) {
84 free(resolved_name_copy);
85 }
86 }
87 }
88 return resolved_executable_name_.load();
89 }
90
91 // Stores and gets the flags passed to the executable.
92 static void SetExecutableArguments(int script_index, char** argv) {
93 script_index_ = script_index;
94 argv_ = argv;
95 }
96 static int GetScriptIndex() { return script_index_; }
97 static char** GetArgv() { return argv_; }
98
99 static void SetProcessName(const char* name);
100
101 DART_NORETURN static void Exit(int exit_code);
102 DART_NORETURN static void _Exit(int exit_code);
103
105
106#if defined(DART_HOST_OS_FUCHSIA)
107 static zx_handle_t GetVMEXResource();
108#endif
109
110 private:
111 // The path to the executable.
112 static const char* executable_name_;
113
114 // The path to the resolved executable.
115 //
116 // We use require-release semantics to ensure initializing stores to the
117 // string are visible when the string becomes visible.
118 static AcqRelAtomic<const char*> resolved_executable_name_;
119
120 static int script_index_;
121 static char** argv_; // VM flags are argv_[1 ... script_index_ - 1]
122
123 DISALLOW_ALLOCATION();
124 DISALLOW_IMPLICIT_CONSTRUCTORS(Platform);
125};
126
127} // namespace bin
128} // namespace dart
129
130#endif // RUNTIME_BIN_PLATFORM_H_
int count
Definition: FontMgrTest.cpp:50
T load(std::memory_order order=std::memory_order_acquire) const
Definition: atomic.h:101
bool compare_exchange_strong(T &expected, T desired, std::memory_order success_order=std::memory_order_acq_rel, std::memory_order failure_order=std::memory_order_acquire)
Definition: atomic.h:129
static char * StrDup(const char *s)
static bool LocalHostname(char *buffer, intptr_t buffer_length)
static const char * GetExecutableName()
static const char * LibraryPrefix()
static const char * HostArchitecture()
Definition: platform.h:41
static void SetExecutableName(const char *executable_name)
Definition: platform.h:71
static DART_NORETURN void _Exit(int exit_code)
static int GetScriptIndex()
Definition: platform.h:96
static void SetProcessName(const char *name)
static const char * LocaleName()
static const char * OperatingSystem()
Definition: platform.h:32
static const char * GetResolvedExecutableName()
Definition: platform.h:75
static DART_NORETURN void Exit(int exit_code)
static bool Initialize()
static void SetExecutableArguments(int script_index, char **argv)
Definition: platform.h:92
static char ** Environment(intptr_t *count)
static const char * OperatingSystemVersion()
static intptr_t ResolveExecutablePathInto(char *result, size_t result_size)
static int NumberOfProcessors()
static const char * LibraryExtension()
static const char * ResolveExecutablePath()
static void SetCoreDumpResourceLimit(int value)
static char ** GetArgv()
Definition: platform.h:97
uint8_t value
GAsyncResult * result
char ** argv
Definition: library.h:9
Definition: dart_vm.cc:33
const char *const name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126