6#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
14#include <sys/resource.h>
15#if defined(DART_HOST_OS_ANDROID)
16#include <sys/system_properties.h>
18#include <sys/utsname.h>
27const char* Platform::executable_name_ =
nullptr;
28int Platform::script_index_ = 1;
29char** Platform::argv_ =
nullptr;
31static const char* strcode(
int si_signo,
int si_code) {
32#define CASE(signo, code) \
33 if (si_signo == signo && si_code == code) return #code;
35 CASE(SIGILL, ILL_ILLOPC);
36 CASE(SIGILL, ILL_ILLOPN);
37 CASE(SIGILL, ILL_ILLADR);
38 CASE(SIGILL, ILL_ILLTRP);
39 CASE(SIGILL, ILL_PRVOPC);
40 CASE(SIGILL, ILL_PRVREG);
41 CASE(SIGILL, ILL_COPROC);
42 CASE(SIGILL, ILL_BADSTK);
43 CASE(SIGSEGV, SEGV_MAPERR);
44 CASE(SIGSEGV, SEGV_ACCERR);
45 CASE(SIGBUS, BUS_ADRALN);
46 CASE(SIGBUS, BUS_ADRERR);
47 CASE(SIGBUS, BUS_OBJERR);
48 CASE(SIGBUS, BUS_MCEERR_AR);
49 CASE(SIGBUS, BUS_MCEERR_AO);
50 CASE(SIGTRAP, TRAP_BRKPT);
51 CASE(SIGTRAP, TRAP_TRACE);
56static void segv_handler(
int signal, siginfo_t* siginfo,
void* context) {
58 "\n===== CRASH =====\n"
59 "si_signo=%s(%d), si_code=%s(%d), si_addr=%p\n",
60 strsignal(siginfo->si_signo), siginfo->si_signo,
61 strcode(siginfo->si_signo, siginfo->si_code), siginfo->si_code,
72 struct sigaction act = {};
73 act.sa_handler = SIG_IGN;
74 if (sigaction(SIGPIPE, &act,
nullptr) != 0) {
75 perror(
"Setting signal handler failed");
83 sigemptyset(&signal_mask);
84 sigaddset(&signal_mask, SIGTTOU);
85 if (sigprocmask(SIG_BLOCK, &signal_mask,
nullptr) < 0) {
86 perror(
"Setting signal handler failed");
90 act.sa_flags = SA_SIGINFO;
91 act.sa_sigaction = &segv_handler;
92 if (sigemptyset(&act.sa_mask) != 0) {
93 perror(
"sigemptyset() failed.");
96 if (sigaddset(&act.sa_mask, SIGPROF) != 0) {
97 perror(
"sigaddset() failed");
100 if (sigaction(SIGSEGV, &act,
nullptr) != 0) {
101 perror(
"sigaction() failed.");
104 if (sigaction(SIGBUS, &act,
nullptr) != 0) {
105 perror(
"sigaction() failed.");
108 if (sigaction(SIGTRAP, &act,
nullptr) != 0) {
109 perror(
"sigaction() failed.");
112 if (sigaction(SIGILL, &act,
nullptr) != 0) {
113 perror(
"sigaction() failed.");
120 return sysconf(_SC_NPROCESSORS_ONLN);
124#if defined(DART_HOST_OS_ANDROID)
125 char os_version[PROP_VALUE_MAX + 1];
126 int os_version_length =
127 __system_property_get(
"ro.build.display.id", os_version);
128 if (os_version_length == 0) {
131 os_version[
Utils::Minimum(os_version_length, PROP_VALUE_MAX)] =
'\0';
135 int ret = uname(&
info);
154 if (lang ==
nullptr) {
161 return gethostname(
buffer, buffer_length) == 0;
168 char** tmp = environ;
169 while (*(tmp++) !=
nullptr) {
175 for (intptr_t current = 0; current < i; current++) {
176 result[current] = environ[current];
182 return executable_name_;
194 prctl(PR_SET_NAME,
reinterpret_cast<unsigned long>(
name), 0, 0, 0);
210 rlimit limit = {
static_cast<rlim_t
>(
value),
static_cast<rlim_t
>(value)};
211 setrlimit(RLIMIT_CORE, &limit);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static T Minimum(T x, T y)
static void RestoreConfig()
static char * ScopedCStringFormatted(const char *format,...) PRINTF_ATTRIBUTE(1
static char * ScopedCopyCString(const char *str)
static const char * ReadLink(const char *pathname)
static intptr_t ReadLinkInto(const char *pathname, char *result, size_t result_size)
static const uint8_t buffer[]
#define CASE(Arity, Mask, Name, Args, Result)
DART_EXPORT void Dart_PrepareToAbort()
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
DART_EXPORT void Dart_DumpNativeStackTrace(void *context)