Flutter Engine
The Flutter Engine
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
dart::bin::DartUtils Class Reference

#include <dartutils.h>

Public Types

enum  MagicNumber {
  kAppJITMagicNumber , kKernelMagicNumber , kKernelListMagicNumber , kGzipMagicNumber ,
  kAotELFMagicNumber , kAotMachO32MagicNumber , kAotMachO64MagicNumber , kAotMachO64Arm64MagicNumber ,
  kAotCoffARM32MagicNumber , kAotCoffARM64MagicNumber , kAotCoffRISCV32MagicNumber , kAotCoffRISCV64MagicNumber ,
  kUnknownMagicNumber
}
 

Static Public Member Functions

static int64_t GetIntegerValue (Dart_Handle value_obj)
 
static int64_t GetInt64ValueCheckRange (Dart_Handle value_obj, int64_t lower, int64_t upper)
 
static intptr_t GetIntptrValue (Dart_Handle value_obj)
 
static bool GetInt64Value (Dart_Handle value_obj, int64_t *value)
 
static const char * GetStringValue (Dart_Handle str_obj)
 
static bool GetBooleanValue (Dart_Handle bool_obj)
 
static bool GetNativeBooleanArgument (Dart_NativeArguments args, intptr_t index)
 
static int64_t GetNativeIntegerArgument (Dart_NativeArguments args, intptr_t index)
 
static intptr_t GetNativeIntptrArgument (Dart_NativeArguments args, intptr_t index)
 
static const char * GetNativeStringArgument (Dart_NativeArguments args, intptr_t index)
 
static const char * GetNativeTypedDataArgument (Dart_NativeArguments args, intptr_t index)
 
static Dart_Handle SetIntegerField (Dart_Handle handle, const char *name, int64_t val)
 
static Dart_Handle SetStringField (Dart_Handle handle, const char *name, const char *val)
 
static bool IsDartSchemeURL (const char *url_name)
 
static bool IsDartIOLibURL (const char *url_name)
 
static bool IsDartCLILibURL (const char *url_name)
 
static bool IsDartHttpLibURL (const char *url_name)
 
static bool IsDartBuiltinLibURL (const char *url_name)
 
static bool IsHttpSchemeURL (const char *url_name)
 
static const char * RemoveScheme (const char *url)
 
static char * DirName (const char *url)
 
static void * MapExecutable (const char *name, intptr_t *file_len)
 
static void * OpenFile (const char *name, bool write)
 
static void * OpenFileUri (const char *uri, bool write)
 
static void ReadFile (uint8_t **data, intptr_t *file_len, void *stream)
 
static void WriteFile (const void *buffer, intptr_t num_bytes, void *stream)
 
static void CloseFile (void *stream)
 
static bool EntropySource (uint8_t *buffer, intptr_t length)
 
static Dart_Handle ReadStringFromFile (const char *filename)
 
static Dart_Handle MakeUint8Array (const void *buffer, intptr_t length)
 
static Dart_Handle PrepareForScriptLoading (bool is_service_isolate, bool trace_loading)
 
static Dart_Handle SetupPackageConfig (const char *packages_file)
 
static Dart_Handle SetupIOLibrary (const char *namespc_path, const char *script_uri, bool disable_exit)
 
static bool PostNull (Dart_Port port_id)
 
static bool PostInt32 (Dart_Port port_id, int32_t value)
 
static bool PostInt64 (Dart_Port port_id, int64_t value)
 
static bool PostString (Dart_Port port_id, const char *value)
 
static Dart_Handle GetDartType (const char *library_url, const char *class_name)
 
static Dart_Handle NewDartOSError ()
 
static Dart_Handle NewDartOSError (OSError *os_error)
 
static Dart_Handle NewDartExceptionWithOSError (const char *library_url, const char *exception_name, const char *message, Dart_Handle os_error)
 
static Dart_Handle NewDartExceptionWithMessage (const char *library_url, const char *exception_name, const char *message)
 
static Dart_Handle NewDartArgumentError (const char *message)
 
static Dart_Handle NewDartFormatException (const char *message)
 
static Dart_Handle NewDartUnsupportedError (const char *message)
 
static Dart_Handle NewDartIOException (const char *exception_name, const char *message, Dart_Handle os_error)
 
static Dart_Handle NewString (const char *str)
 
static Dart_Handle NewStringFormatted (const char *format,...)
 
static char * ScopedCString (intptr_t length)
 
static char * ScopedCopyCString (const char *str)
 
static char * ScopedCStringFormatted (const char *format,...) PRINTF_ATTRIBUTE(1
 
static char static char * ScopedCStringVFormatted (const char *format, va_list args)
 
static Dart_Handle NewError (const char *format,...)
 
static Dart_Handle NewInternalError (const char *message)
 
static Dart_Handle LookupBuiltinLib ()
 
static bool SetOriginalWorkingDirectory ()
 
static Dart_Handle ResolveScript (Dart_Handle url)
 
static bool IsAotMagicNumber (MagicNumber number)
 
static MagicNumber SniffForMagicNumber (const char *filename)
 
static MagicNumber SniffForMagicNumber (const uint8_t *text_buffer, intptr_t buffer_len)
 
static void SetEnvironment (dart::SimpleHashMap *environment)
 
static Dart_Handle EnvironmentCallback (Dart_Handle name)
 

Static Public Attributes

static constexpr int64_t kMaxMagicNumberSize = 8
 
static const char * original_working_directory = nullptr
 
static constexpr const char * kDartScheme = "dart:"
 
static constexpr const char * kAsyncLibURL = "dart:async"
 
static constexpr const char * kBuiltinLibURL = "dart:_builtin"
 
static constexpr const char * kCoreLibURL = "dart:core"
 
static constexpr const char * kInternalLibURL = "dart:_internal"
 
static constexpr const char * kIsolateLibURL = "dart:isolate"
 
static constexpr const char * kHttpLibURL = "dart:_http"
 
static constexpr const char * kIOLibURL = "dart:io"
 
static constexpr const char * kIOLibPatchURL = "dart:io-patch"
 
static constexpr const char * kCLILibURL = "dart:cli"
 
static constexpr const char * kCLILibPatchURL = "dart:cli-patch"
 
static constexpr const char * kUriLibURL = "dart:uri"
 
static constexpr const char * kHttpScheme = "http:"
 
static constexpr const char * kVMServiceLibURL = "dart:vmservice"
 

Detailed Description

Definition at line 108 of file dartutils.h.

Member Enumeration Documentation

◆ MagicNumber

Enumerator
kAppJITMagicNumber 
kKernelMagicNumber 
kKernelListMagicNumber 
kGzipMagicNumber 
kAotELFMagicNumber 
kAotMachO32MagicNumber 
kAotMachO64MagicNumber 
kAotMachO64Arm64MagicNumber 
kAotCoffARM32MagicNumber 
kAotCoffARM64MagicNumber 
kAotCoffRISCV32MagicNumber 
kAotCoffRISCV64MagicNumber 
kUnknownMagicNumber 

Definition at line 256 of file dartutils.h.

256 {
270 };

Member Function Documentation

◆ CloseFile()

void dart::bin::DartUtils::CloseFile ( void *  stream)
static

Definition at line 303 of file dartutils.cc.

303 {
304 File* file = reinterpret_cast<File*>(stream);
305 file->Release();
306}

◆ DirName()

char * dart::bin::DartUtils::DirName ( const char *  url)
static

Definition at line 252 of file dartutils.cc.

252 {
253 const char* slash = strrchr(url, File::PathSeparator()[0]);
254 if (slash == nullptr) {
255 return Utils::StrDup(url);
256 } else {
257 return Utils::StrNDup(url, slash - url + 1);
258 }
259}
static char * StrDup(const char *s)
static char * StrNDup(const char *s, intptr_t n)
static const char * PathSeparator()

◆ EntropySource()

bool dart::bin::DartUtils::EntropySource ( uint8_t *  buffer,
intptr_t  length 
)
static

Definition at line 308 of file dartutils.cc.

308 {
310}
static bool GetRandomBytes(intptr_t count, uint8_t *buffer)
size_t length
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

◆ EnvironmentCallback()

Dart_Handle dart::bin::DartUtils::EnvironmentCallback ( Dart_Handle  name)
static

Definition at line 835 of file dartutils.cc.

835 {
836 uint8_t* utf8_array;
837 intptr_t utf8_len;
839 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len);
840 if (Dart_IsError(handle)) {
841 handle = Dart_ThrowException(
843 } else {
844 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1));
845 memmove(name_chars, utf8_array, utf8_len);
846 name_chars[utf8_len] = '\0';
847 const char* value = nullptr;
848 if (environment_ != nullptr) {
849 SimpleHashMap::Entry* entry =
850 environment_->Lookup(GetHashmapKeyFromString(name_chars),
851 SimpleHashMap::StringHash(name_chars), false);
852 if (entry != nullptr) {
853 value = reinterpret_cast<char*>(entry->value);
854 }
855 }
856 if (value != nullptr) {
857 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value),
858 strlen(value));
859 if (Dart_IsError(result)) {
860 result = Dart_Null();
861 }
862 }
863 free(name_chars);
864 }
865 return result;
866}
Entry * Lookup(void *key, uint32_t hash, bool insert)
Definition: hashmap.cc:20
static uint32_t StringHash(const char *key)
Definition: hashmap.h:26
static Dart_Handle NewDartArgumentError(const char *message)
Definition: dartutils.cc:746
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
uint8_t value
GAsyncResult * result
static void * GetHashmapKeyFromString(char *key)
Definition: dartutils.h:38
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, uint8_t **utf8_array, intptr_t *length)
const char *const name
void * malloc(size_t size)
Definition: allocation.cc:19
DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t *utf8_array, intptr_t length)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT Dart_Handle Dart_Null()

◆ GetBooleanValue()

bool dart::bin::DartUtils::GetBooleanValue ( Dart_Handle  bool_obj)
static

Definition at line 137 of file dartutils.cc.

137 {
138 bool value = false;
140 if (Dart_IsError(result)) {
142 }
143 return value;
144}
DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, bool *value)
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)

◆ GetDartType()

Dart_Handle dart::bin::DartUtils::GetDartType ( const char *  library_url,
const char *  class_name 
)
static

Definition at line 696 of file dartutils.cc.

697 {
699 NewString(class_name), 0, nullptr);
700}
static Dart_Handle NewString(const char *str)
Definition: dartutils.h:214
const char *const class_name
DART_EXPORT Dart_Handle Dart_GetNonNullableType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle *type_arguments)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)

◆ GetInt64Value()

bool dart::bin::DartUtils::GetInt64Value ( Dart_Handle  value_obj,
int64_t *  value 
)
static

Definition at line 112 of file dartutils.cc.

112 {
113 bool valid = Dart_IsInteger(value_obj);
114 if (valid) {
115 Dart_Handle result = Dart_IntegerFitsIntoInt64(value_obj, &valid);
116 if (Dart_IsError(result)) {
118 }
119 }
120 if (!valid) return false;
122 if (Dart_IsError(result)) {
124 }
125 return true;
126}
DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, bool *fits)
DART_EXPORT bool Dart_IsInteger(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)

◆ GetInt64ValueCheckRange()

int64_t dart::bin::DartUtils::GetInt64ValueCheckRange ( Dart_Handle  value_obj,
int64_t  lower,
int64_t  upper 
)
static

Definition at line 90 of file dartutils.cc.

92 {
93 int64_t value = DartUtils::GetIntegerValue(value_obj);
94 if (value < lower || upper < value) {
95 Dart_PropagateError(Dart_NewApiError("Value outside expected range"));
96 }
97 return value;
98}
static int64_t GetIntegerValue(Dart_Handle value_obj)
Definition: dartutils.cc:81
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)

◆ GetIntegerValue()

int64_t dart::bin::DartUtils::GetIntegerValue ( Dart_Handle  value_obj)
static

Definition at line 81 of file dartutils.cc.

81 {
82 int64_t value = 0;
84 if (Dart_IsError(result)) {
86 }
87 return value;
88}

◆ GetIntptrValue()

intptr_t dart::bin::DartUtils::GetIntptrValue ( Dart_Handle  value_obj)
static

Definition at line 100 of file dartutils.cc.

100 {
101 int64_t value = 0;
103 if (Dart_IsError(result)) {
105 }
106 if (value < kIntptrMin || kIntptrMax < value) {
107 Dart_PropagateError(Dart_NewApiError("Value outside intptr_t range"));
108 }
109 return static_cast<intptr_t>(value);
110}
constexpr intptr_t kIntptrMin
Definition: globals.h:556
constexpr intptr_t kIntptrMax
Definition: globals.h:557

◆ GetNativeBooleanArgument()

bool dart::bin::DartUtils::GetNativeBooleanArgument ( Dart_NativeArguments  args,
intptr_t  index 
)
static

Definition at line 146 of file dartutils.cc.

147 {
148 bool value = false;
150 if (Dart_IsError(result)) {
152 }
153 return value;
154}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, int index, bool *value)

◆ GetNativeIntegerArgument()

int64_t dart::bin::DartUtils::GetNativeIntegerArgument ( Dart_NativeArguments  args,
intptr_t  index 
)
static

Definition at line 156 of file dartutils.cc.

157 {
158 int64_t value = 0;
160 if (Dart_IsError(result)) {
162 }
163 return value;
164}
DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, int index, int64_t *value)

◆ GetNativeIntptrArgument()

intptr_t dart::bin::DartUtils::GetNativeIntptrArgument ( Dart_NativeArguments  args,
intptr_t  index 
)
static

Definition at line 166 of file dartutils.cc.

167 {
168 int64_t value = GetNativeIntegerArgument(args, index);
169 if (value < kIntptrMin || kIntptrMax < value) {
170 Dart_PropagateError(Dart_NewApiError("Value outside intptr_t range"));
171 }
172 return static_cast<intptr_t>(value);
173}
static int64_t GetNativeIntegerArgument(Dart_NativeArguments args, intptr_t index)
Definition: dartutils.cc:156

◆ GetNativeStringArgument()

const char * dart::bin::DartUtils::GetNativeStringArgument ( Dart_NativeArguments  args,
intptr_t  index 
)
static

Definition at line 175 of file dartutils.cc.

176 {
177 char* tmp = nullptr;
179 Dart_GetNativeStringArgument(args, index, reinterpret_cast<void**>(&tmp));
180 if (Dart_IsError(result)) {
182 }
183 if (tmp != nullptr) {
184 return tmp;
185 }
186 const char* cstring = nullptr;
188 if (Dart_IsError(result)) {
190 }
191 ASSERT(cstring != nullptr);
192 return cstring;
193}
#define ASSERT(E)
DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, int arg_index, void **peer)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, const char **cstr)

◆ GetNativeTypedDataArgument()

const char * dart::bin::DartUtils::GetNativeTypedDataArgument ( Dart_NativeArguments  args,
intptr_t  index 
)
static

Definition at line 195 of file dartutils.cc.

196 {
197 Dart_Handle handle = Dart_GetNativeArgument(args, index);
198 TypedDataScope data(handle);
200 return data.GetScopedCString();
201}
@ Dart_TypedData_kUint8
Definition: dart_api.h:2615
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
static int8_t data[kExtLength]

◆ GetStringValue()

const char * dart::bin::DartUtils::GetStringValue ( Dart_Handle  str_obj)
static

Definition at line 128 of file dartutils.cc.

128 {
129 const char* cstring = nullptr;
130 Dart_Handle result = Dart_StringToCString(str_obj, &cstring);
131 if (Dart_IsError(result)) {
133 }
134 return cstring;
135}

◆ IsAotMagicNumber()

static bool dart::bin::DartUtils::IsAotMagicNumber ( MagicNumber  number)
inlinestatic

Definition at line 275 of file dartutils.h.

275 {
276 return (number >= DartUtils::kAotELFMagicNumber) &&
278 }

◆ IsDartBuiltinLibURL()

bool dart::bin::DartUtils::IsDartBuiltinLibURL ( const char *  url_name)
static

Definition at line 239 of file dartutils.cc.

239 {
240 return (strcmp(url_name, kBuiltinLibURL) == 0);
241}
static constexpr const char * kBuiltinLibURL
Definition: dartutils.h:292

◆ IsDartCLILibURL()

bool dart::bin::DartUtils::IsDartCLILibURL ( const char *  url_name)
static

Definition at line 231 of file dartutils.cc.

231 {
232 return (strcmp(url_name, kCLILibURL) == 0);
233}
static constexpr const char * kCLILibURL
Definition: dartutils.h:299

◆ IsDartHttpLibURL()

bool dart::bin::DartUtils::IsDartHttpLibURL ( const char *  url_name)
static

Definition at line 235 of file dartutils.cc.

235 {
236 return (strcmp(url_name, kHttpLibURL) == 0);
237}
static constexpr const char * kHttpLibURL
Definition: dartutils.h:296

◆ IsDartIOLibURL()

bool dart::bin::DartUtils::IsDartIOLibURL ( const char *  url_name)
static

Definition at line 227 of file dartutils.cc.

227 {
228 return (strcmp(url_name, kIOLibURL) == 0);
229}
static constexpr const char * kIOLibURL
Definition: dartutils.h:297

◆ IsDartSchemeURL()

bool dart::bin::DartUtils::IsDartSchemeURL ( const char *  url_name)
static

Definition at line 215 of file dartutils.cc.

215 {
216 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
217 // If the URL starts with "dart:" then it is considered as a special
218 // library URL which is handled differently from other URLs.
219 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0);
220}
static constexpr const char * kDartScheme
Definition: dartutils.h:290

◆ IsHttpSchemeURL()

bool dart::bin::DartUtils::IsHttpSchemeURL ( const char *  url_name)
static

Definition at line 222 of file dartutils.cc.

222 {
223 static const intptr_t kHttpSchemeLen = strlen(kHttpScheme);
224 return (strncmp(url_name, kHttpScheme, kHttpSchemeLen) == 0);
225}
static constexpr const char * kHttpScheme
Definition: dartutils.h:302

◆ LookupBuiltinLib()

static Dart_Handle dart::bin::DartUtils::LookupBuiltinLib ( )
inlinestatic

Definition at line 248 of file dartutils.h.

248 {
250 }

◆ MakeUint8Array()

Dart_Handle dart::bin::DartUtils::MakeUint8Array ( const void *  buffer,
intptr_t  length 
)
static

Definition at line 360 of file dartutils.cc.

360 {
362 RETURN_IF_ERROR(array);
363 {
364 Dart_TypedData_Type td_type;
365 void* td_data;
366 intptr_t td_len;
368 Dart_TypedDataAcquireData(array, &td_type, &td_data, &td_len);
370 ASSERT(td_type == Dart_TypedData_kUint8);
371 ASSERT(td_len == len);
372 ASSERT(td_data != nullptr);
373 memmove(td_data, buffer, td_len);
376 }
377 return array;
378}
Dart_TypedData_Type
Definition: dart_api.h:2612
#define RETURN_IF_ERROR(handle)
Definition: dartutils.cc:20
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)

◆ MapExecutable()

static void * dart::bin::DartUtils::MapExecutable ( const char *  name,
intptr_t *  file_len 
)
static

◆ NewDartArgumentError()

Dart_Handle dart::bin::DartUtils::NewDartArgumentError ( const char *  message)
static

Definition at line 746 of file dartutils.cc.

746 {
747 return NewDartExceptionWithMessage(kCoreLibURL, "ArgumentError", message);
748}
static Dart_Handle NewDartExceptionWithMessage(const char *library_url, const char *exception_name, const char *message)
Definition: dartutils.cc:731
static constexpr const char * kCoreLibURL
Definition: dartutils.h:293
Win32Message message

◆ NewDartExceptionWithMessage()

Dart_Handle dart::bin::DartUtils::NewDartExceptionWithMessage ( const char *  library_url,
const char *  exception_name,
const char *  message 
)
static

Definition at line 731 of file dartutils.cc.

733 {
734 // Create a Dart Exception object with a message.
735 Dart_Handle type = GetDartType(library_url, exception_name);
737 if (message != nullptr) {
738 Dart_Handle args[1];
739 args[0] = NewString(message);
740 return Dart_New(type, Dart_Null(), 1, args);
741 } else {
742 return Dart_New(type, Dart_Null(), 0, nullptr);
743 }
744}
GLenum type
static Dart_Handle GetDartType(const char *library_url, const char *class_name)
Definition: dartutils.cc:696
DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, Dart_Handle constructor_name, int number_of_arguments, Dart_Handle *arguments)

◆ NewDartExceptionWithOSError()

Dart_Handle dart::bin::DartUtils::NewDartExceptionWithOSError ( const char *  library_url,
const char *  exception_name,
const char *  message,
Dart_Handle  os_error 
)
static

Definition at line 718 of file dartutils.cc.

721 {
722 // Create a Dart Exception object with a message and an OSError.
723 Dart_Handle type = GetDartType(library_url, exception_name);
725 Dart_Handle args[2];
726 args[0] = NewString(message);
727 args[1] = os_error;
728 return Dart_New(type, Dart_Null(), 2, args);
729}

◆ NewDartFormatException()

Dart_Handle dart::bin::DartUtils::NewDartFormatException ( const char *  message)
static

Definition at line 750 of file dartutils.cc.

750 {
751 return NewDartExceptionWithMessage(kCoreLibURL, "FormatException", message);
752}

◆ NewDartIOException()

Dart_Handle dart::bin::DartUtils::NewDartIOException ( const char *  exception_name,
const char *  message,
Dart_Handle  os_error 
)
static

Definition at line 758 of file dartutils.cc.

760 {
761 // Create a dart:io exception object of the given type.
762 return NewDartExceptionWithOSError(kIOLibURL, exception_name, message,
763 os_error);
764}
static Dart_Handle NewDartExceptionWithOSError(const char *library_url, const char *exception_name, const char *message, Dart_Handle os_error)
Definition: dartutils.cc:718

◆ NewDartOSError() [1/2]

Dart_Handle dart::bin::DartUtils::NewDartOSError ( )
static

Definition at line 702 of file dartutils.cc.

702 {
703 // Extract the current OS error.
704 OSError os_error;
705 return NewDartOSError(&os_error);
706}
static Dart_Handle NewDartOSError()
Definition: dartutils.cc:702

◆ NewDartOSError() [2/2]

Dart_Handle dart::bin::DartUtils::NewDartOSError ( OSError os_error)
static

Definition at line 708 of file dartutils.cc.

708 {
709 // Create a dart:io OSError object with the information retrieved from the OS.
712 Dart_Handle args[2];
713 args[0] = NewString(os_error->message());
714 args[1] = Dart_NewInteger(os_error->code());
715 return Dart_New(type, Dart_Null(), 2, args);
716}
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)

◆ NewDartUnsupportedError()

Dart_Handle dart::bin::DartUtils::NewDartUnsupportedError ( const char *  message)
static

Definition at line 754 of file dartutils.cc.

754 {
755 return NewDartExceptionWithMessage(kCoreLibURL, "UnsupportedError", message);
756}

◆ NewError()

Dart_Handle dart::bin::DartUtils::NewError ( const char *  format,
  ... 
)
static

Definition at line 766 of file dartutils.cc.

766 {
767 va_list measure_args;
768 va_start(measure_args, format);
769 intptr_t len = Utils::VSNPrint(nullptr, 0, format, measure_args);
770 va_end(measure_args);
771
772 char* buffer = reinterpret_cast<char*>(Dart_ScopeAllocate(len + 1));
773 va_list print_args;
774 va_start(print_args, format);
775 Utils::VSNPrint(buffer, (len + 1), format, print_args);
776 va_end(print_args);
777
778 return Dart_NewApiError(buffer);
779}
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
uint32_t uint32_t * format
va_start(args, format)
va_end(args)
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)

◆ NewInternalError()

Dart_Handle dart::bin::DartUtils::NewInternalError ( const char *  message)
static

Definition at line 781 of file dartutils.cc.

781 {
782 return NewDartExceptionWithMessage(kCoreLibURL, "_InternalError", message);
783}

◆ NewString()

static Dart_Handle dart::bin::DartUtils::NewString ( const char *  str)
inlinestatic

Definition at line 214 of file dartutils.h.

214 {
215 ASSERT(str != nullptr);
216 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str),
217 strlen(str));
218 }

◆ NewStringFormatted()

Dart_Handle dart::bin::DartUtils::NewStringFormatted ( const char *  format,
  ... 
)
static

Definition at line 785 of file dartutils.cc.

785 {
786 va_list args;
789 va_end(args);
790 return NewString(result);
791}
static char static char * ScopedCStringVFormatted(const char *format, va_list args)
Definition: dartutils.cc:793

◆ OpenFile()

void * dart::bin::DartUtils::OpenFile ( const char *  name,
bool  write 
)
static

Definition at line 261 of file dartutils.cc.

261 {
262 File* file =
264 return reinterpret_cast<void*>(file);
265}
static File * Open(Namespace *namespc, const char *path, FileOpenMode mode)
@ kWriteTruncate
Definition: file.h:60
void write(SkWStream *wStream, const T &text)
Definition: skqp.cpp:188

◆ OpenFileUri()

void * dart::bin::DartUtils::OpenFileUri ( const char *  uri,
bool  write 
)
static

Definition at line 267 of file dartutils.cc.

267 {
268 File* file =
270 return reinterpret_cast<void*>(file);
271}
static File * OpenUri(Namespace *namespc, const char *uri, FileOpenMode mode)

◆ PostInt32()

bool dart::bin::DartUtils::PostInt32 ( Dart_Port  port_id,
int32_t  value 
)
static

Definition at line 672 of file dartutils.cc.

672 {
673 // Post a message with the integer value.
674 int32_t min = 0xc0000000; // -1073741824
675 int32_t max = 0x3fffffff; // 1073741823
676 ASSERT(min <= value && value < max);
677 Dart_CObject object;
678 object.type = Dart_CObject_kInt32;
679 object.value.as_int32 = value;
680 return Dart_PostCObject(port_id, &object);
681}
@ Dart_CObject_kInt32
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
Dart_CObject_Type type

◆ PostInt64()

bool dart::bin::DartUtils::PostInt64 ( Dart_Port  port_id,
int64_t  value 
)
static

Definition at line 683 of file dartutils.cc.

683 {
684 // Post a message with the integer value.
685 Dart_CObject object;
686 object.type = Dart_CObject_kInt64;
687 object.value.as_int64 = value;
688 return Dart_PostCObject(port_id, &object);
689}
@ Dart_CObject_kInt64

◆ PostNull()

bool dart::bin::DartUtils::PostNull ( Dart_Port  port_id)
static

Definition at line 667 of file dartutils.cc.

667 {
668 // Post a message with just the null object.
669 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject());
670}
static CObject * Null()
Definition: dartutils.cc:879

◆ PostString()

bool dart::bin::DartUtils::PostString ( Dart_Port  port_id,
const char *  value 
)
static

Definition at line 691 of file dartutils.cc.

691 {
693 return Dart_PostCObject(port_id, object);
694}
static Dart_CObject * NewString(const char *str)
Definition: dartutils.cc:927

◆ PrepareForScriptLoading()

Dart_Handle dart::bin::DartUtils::PrepareForScriptLoading ( bool  is_service_isolate,
bool  trace_loading 
)
static

Definition at line 570 of file dartutils.cc.

571 {
572 // First ensure all required libraries are available.
574 RETURN_IF_ERROR(url);
575 Dart_Handle core_lib = Dart_LookupLibrary(url);
576 RETURN_IF_ERROR(core_lib);
577 url = NewString(kAsyncLibURL);
578 RETURN_IF_ERROR(url);
579 Dart_Handle async_lib = Dart_LookupLibrary(url);
580 RETURN_IF_ERROR(async_lib);
582 RETURN_IF_ERROR(url);
583 Dart_Handle isolate_lib = Dart_LookupLibrary(url);
584 RETURN_IF_ERROR(isolate_lib);
586 RETURN_IF_ERROR(url);
587 Dart_Handle internal_lib = Dart_LookupLibrary(url);
588 RETURN_IF_ERROR(internal_lib);
589 Dart_Handle builtin_lib =
591 RETURN_IF_ERROR(builtin_lib);
594 RETURN_IF_ERROR(io_lib);
597 RETURN_IF_ERROR(cli_lib);
599
600 // We need to ensure that all the scripts loaded so far are finalized
601 // as we are about to invoke some Dart code below to setup closures.
604
605 result = PrepareBuiltinLibrary(builtin_lib, internal_lib, is_service_isolate,
606 trace_loading);
608
609 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib));
610 RETURN_IF_ERROR(PrepareCoreLibrary(core_lib, io_lib, is_service_isolate));
611 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib));
612 RETURN_IF_ERROR(PrepareIOLibrary(io_lib));
613 RETURN_IF_ERROR(PrepareCLILibrary(cli_lib));
614 return result;
615}
static Dart_Handle LoadAndCheckLibrary(BuiltinLibraryId id)
Definition: builtin.cc:43
static void SetNativeResolver(BuiltinLibraryId id)
Definition: builtin.cc:28
static constexpr const char * kAsyncLibURL
Definition: dartutils.h:291
static constexpr const char * kIsolateLibURL
Definition: dartutils.h:295
static constexpr const char * kInternalLibURL
Definition: dartutils.h:294
DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures)

◆ ReadFile()

void dart::bin::DartUtils::ReadFile ( uint8_t **  data,
intptr_t *  file_len,
void *  stream 
)
static

Definition at line 273 of file dartutils.cc.

273 {
274 ASSERT(data != nullptr);
275 ASSERT(len != nullptr);
276 ASSERT(stream != nullptr);
277 File* file_stream = reinterpret_cast<File*>(stream);
278 int64_t file_len = file_stream->Length();
279 if ((file_len < 0) || (file_len > kIntptrMax)) {
280 *data = nullptr;
281 *len = -1; // Indicates read was not successful.
282 return;
283 }
284 *len = static_cast<intptr_t>(file_len);
285 *data = reinterpret_cast<uint8_t*>(malloc(*len));
286 if (!file_stream->ReadFully(*data, *len)) {
287 free(*data);
288 *data = nullptr;
289 *len = -1; // Indicates read was not successful.
290 return;
291 }
292}

◆ ReadStringFromFile()

Dart_Handle dart::bin::DartUtils::ReadStringFromFile ( const char *  filename)
static

Definition at line 348 of file dartutils.cc.

348 {
349 const char* error_msg = nullptr;
350 intptr_t len;
351 uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg);
352 if (text_buffer == nullptr) {
353 return Dart_NewApiError(error_msg);
354 }
355 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len);
356 free(text_buffer);
357 return str;
358}
static uint8_t * ReadFileFully(const char *filename, intptr_t *file_len, const char **error_msg)
Definition: dartutils.cc:329

◆ RemoveScheme()

const char * dart::bin::DartUtils::RemoveScheme ( const char *  url)
static

Definition at line 243 of file dartutils.cc.

243 {
244 const char* colon = strchr(url, ':');
245 if (colon == nullptr) {
246 return url;
247 } else {
248 return colon + 1;
249 }
250}

◆ ResolveScript()

Dart_Handle dart::bin::DartUtils::ResolveScript ( Dart_Handle  url)
static

Definition at line 386 of file dartutils.cc.

386 {
387 const int kNumArgs = 1;
388 Dart_Handle dart_args[kNumArgs];
389 dart_args[0] = url;
391 NewString("_resolveScriptUri"), kNumArgs, dart_args);
392}
static Dart_Handle LookupBuiltinLib()
Definition: dartutils.h:248
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)

◆ ScopedCopyCString()

static char * dart::bin::DartUtils::ScopedCopyCString ( const char *  str)
inlinestatic

Definition at line 232 of file dartutils.h.

232 {
233 size_t str_len = strlen(str);
234 char* result = ScopedCString(str_len + 1);
235 memmove(result, str, str_len);
236 result[str_len] = '\0';
237 return result;
238 }
static char * ScopedCString(intptr_t length)
Definition: dartutils.h:224

◆ ScopedCString()

static char * dart::bin::DartUtils::ScopedCString ( intptr_t  length)
inlinestatic

Definition at line 224 of file dartutils.h.

224 {
225 char* result = nullptr;
226 result =
227 reinterpret_cast<char*>(Dart_ScopeAllocate(length * sizeof(*result)));
228 return result;
229 }

◆ ScopedCStringFormatted()

char * dart::bin::DartUtils::ScopedCStringFormatted ( const char *  format,
  ... 
)
static

Definition at line 813 of file dartutils.cc.

813 {
814 va_list args;
817 va_end(args);
818 return result;
819}

◆ ScopedCStringVFormatted()

char * dart::bin::DartUtils::ScopedCStringVFormatted ( const char *  format,
va_list  args 
)
static

Definition at line 793 of file dartutils.cc.

793 {
794 va_list measure_args;
795 va_copy(measure_args, args);
796 intptr_t len = Utils::VSNPrint(nullptr, 0, format, measure_args);
797 if (len < 0) {
798 return nullptr;
799 }
800 va_end(measure_args);
801
802 char* buffer = ScopedCString(len + 1);
803 va_list print_args;
804 va_copy(print_args, args);
805 len = Utils::VSNPrint(buffer, (len + 1), format, print_args);
806 if (len < 0) {
807 return nullptr;
808 }
809 va_end(print_args);
810 return buffer;
811}

◆ SetEnvironment()

void dart::bin::DartUtils::SetEnvironment ( dart::SimpleHashMap environment)
static

Definition at line 831 of file dartutils.cc.

831 {
832 environment_ = environment;
833}
static dart::SimpleHashMap * environment
Definition: gen_snapshot.cc:59

◆ SetIntegerField()

Dart_Handle dart::bin::DartUtils::SetIntegerField ( Dart_Handle  handle,
const char *  name,
int64_t  val 
)
static

Definition at line 203 of file dartutils.cc.

205 {
206 return Dart_SetField(handle, NewString(name), Dart_NewInteger(val));
207}
DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)

◆ SetOriginalWorkingDirectory()

bool dart::bin::DartUtils::SetOriginalWorkingDirectory ( )
static

Definition at line 821 of file dartutils.cc.

821 {
822 // If we happen to re-initialize the Dart VM multiple times, make sure to free
823 // the old string (allocated by getcwd()) before setting a new one.
824 if (original_working_directory != nullptr) {
825 free(const_cast<char*>(original_working_directory));
826 }
828 return original_working_directory != nullptr;
829}
static const char * original_working_directory
Definition: dartutils.h:288
static char * CurrentNoScope()

◆ SetStringField()

Dart_Handle dart::bin::DartUtils::SetStringField ( Dart_Handle  handle,
const char *  name,
const char *  val 
)
static

Definition at line 209 of file dartutils.cc.

211 {
212 return Dart_SetField(handle, NewString(name), NewString(val));
213}

◆ SetupIOLibrary()

Dart_Handle dart::bin::DartUtils::SetupIOLibrary ( const char *  namespc_path,
const char *  script_uri,
bool  disable_exit 
)
static

Definition at line 617 of file dartutils.cc.

619 {
620 Dart_Handle io_lib_url = NewString(kIOLibURL);
621 RETURN_IF_ERROR(io_lib_url);
622 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
623 RETURN_IF_ERROR(io_lib);
624
625 if (namespc_path != nullptr) {
626 Dart_Handle namespc_type = GetDartType(DartUtils::kIOLibURL, "_Namespace");
627 RETURN_IF_ERROR(namespc_type);
628 Dart_Handle args[1];
629 args[0] = NewString(namespc_path);
632 Dart_Invoke(namespc_type, NewString("_setupNamespace"), 1, args);
634 }
635
636 if (disable_exit) {
637 Dart_Handle embedder_config_type =
638 GetDartType(DartUtils::kIOLibURL, "_EmbedderConfig");
639 RETURN_IF_ERROR(embedder_config_type);
640 Dart_Handle result = Dart_SetField(embedder_config_type,
641 NewString("_mayExit"), Dart_False());
643 }
644
645 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform");
646 RETURN_IF_ERROR(platform_type);
647 Dart_Handle script_name = NewString("_nativeScript");
648 RETURN_IF_ERROR(script_name);
649 Dart_Handle dart_script = NewString(script_uri);
650 RETURN_IF_ERROR(dart_script);
651 Dart_Handle set_script_name =
652 Dart_SetField(platform_type, script_name, dart_script);
653 RETURN_IF_ERROR(set_script_name);
654
655#if !defined(PRODUCT)
656 Dart_Handle network_profiling_type =
657 GetDartType(DartUtils::kIOLibURL, "_NetworkProfiling");
658 RETURN_IF_ERROR(network_profiling_type);
660 Dart_Invoke(network_profiling_type,
661 NewString("_registerServiceExtension"), 0, nullptr);
663#endif // !defined(PRODUCT)
664 return Dart_Null();
665}
DART_EXPORT Dart_Handle Dart_False()

◆ SetupPackageConfig()

Dart_Handle dart::bin::DartUtils::SetupPackageConfig ( const char *  packages_file)
static

Definition at line 555 of file dartutils.cc.

555 {
557
558 if (packages_config != nullptr) {
559 result = NewString(packages_config);
561 const int kNumArgs = 1;
562 Dart_Handle dart_args[kNumArgs];
563 dart_args[0] = result;
565 NewString("_setPackagesMap"), kNumArgs, dart_args);
566 }
567 return result;
568}

◆ SniffForMagicNumber() [1/2]

DartUtils::MagicNumber dart::bin::DartUtils::SniffForMagicNumber ( const char *  filename)
static

Definition at line 403 of file dartutils.cc.

403 {
417 if (File::GetType(nullptr, filename, true) == File::kIsFile) {
418 File* file = File::Open(nullptr, filename, File::kRead);
419 if (file != nullptr) {
420 RefCntReleaseScope<File> rs(file);
422 if (file->ReadFully(&header, kMaxMagicNumberSize)) {
423 magic_number = DartUtils::SniffForMagicNumber(header, sizeof(header));
424 }
425 }
426 }
427 return magic_number;
428}
static MagicNumber SniffForMagicNumber(const char *filename)
Definition: dartutils.cc:403
static constexpr int64_t kMaxMagicNumberSize
Definition: dartutils.h:271
static Type GetType(Namespace *namespc, const char *path, bool follow_links)
MagicNumberData gzip_magic_number
Definition: dartutils.cc:48
MagicNumberData aotcoff_riscv32_magic_number
Definition: dartutils.cc:42
MagicNumberData appjit_magic_number
Definition: dartutils.cc:35
MagicNumberData aotmacho32_magic_number
Definition: dartutils.cc:37
MagicNumberData aotmacho64_magic_number
Definition: dartutils.cc:38
MagicNumberData kernel_list_magic_number
Definition: dartutils.cc:45
MagicNumberData aotelf_magic_number
Definition: dartutils.cc:36
MagicNumberData aotcoff_riscv64_magic_number
Definition: dartutils.cc:43
MagicNumberData kernel_magic_number
Definition: dartutils.cc:44
MagicNumberData aotcoff_arm64_magic_number
Definition: dartutils.cc:41
MagicNumberData aotcoff_arm32_magic_number
Definition: dartutils.cc:40
MagicNumberData aotmacho64_arm64_magic_number
Definition: dartutils.cc:39
static const char header[]
Definition: skpbench.cpp:88

◆ SniffForMagicNumber() [2/2]

DartUtils::MagicNumber dart::bin::DartUtils::SniffForMagicNumber ( const uint8_t *  text_buffer,
intptr_t  buffer_len 
)
static

Definition at line 430 of file dartutils.cc.

431 {
432 if (CheckMagicNumber(buffer, buffer_length, appjit_magic_number)) {
433 return kAppJITMagicNumber;
434 }
435
436 if (CheckMagicNumber(buffer, buffer_length, kernel_magic_number)) {
437 return kKernelMagicNumber;
438 }
439
440 if (CheckMagicNumber(buffer, buffer_length, kernel_list_magic_number)) {
442 }
443
444 if (CheckMagicNumber(buffer, buffer_length, gzip_magic_number)) {
445 return kGzipMagicNumber;
446 }
447
448 if (CheckMagicNumber(buffer, buffer_length, gzip_magic_number)) {
449 return kGzipMagicNumber;
450 }
451
452 if (CheckMagicNumber(buffer, buffer_length, aotelf_magic_number)) {
453 return kAotELFMagicNumber;
454 }
455
456 if (CheckMagicNumber(buffer, buffer_length, aotmacho32_magic_number)) {
458 }
459
460 if (CheckMagicNumber(buffer, buffer_length, aotmacho64_magic_number)) {
462 }
463
466 }
467
470 }
471
474 }
475
478 }
479
482 }
483
484 return kUnknownMagicNumber;
485}
static bool CheckMagicNumber(const uint8_t *buffer, intptr_t buffer_length, const MagicNumberData &magic_number)
Definition: dartutils.cc:394

◆ WriteFile()

void dart::bin::DartUtils::WriteFile ( const void *  buffer,
intptr_t  num_bytes,
void *  stream 
)
static

Definition at line 294 of file dartutils.cc.

296 {
297 ASSERT(stream != nullptr);
298 File* file_stream = reinterpret_cast<File*>(stream);
299 bool bytes_written = file_stream->WriteFully(buffer, num_bytes);
300 ASSERT(bytes_written);
301}

Member Data Documentation

◆ kAsyncLibURL

constexpr const char* dart::bin::DartUtils::kAsyncLibURL = "dart:async"
staticconstexpr

Definition at line 291 of file dartutils.h.

◆ kBuiltinLibURL

constexpr const char* dart::bin::DartUtils::kBuiltinLibURL = "dart:_builtin"
staticconstexpr

Definition at line 292 of file dartutils.h.

◆ kCLILibPatchURL

constexpr const char* dart::bin::DartUtils::kCLILibPatchURL = "dart:cli-patch"
staticconstexpr

Definition at line 300 of file dartutils.h.

◆ kCLILibURL

constexpr const char* dart::bin::DartUtils::kCLILibURL = "dart:cli"
staticconstexpr

Definition at line 299 of file dartutils.h.

◆ kCoreLibURL

constexpr const char* dart::bin::DartUtils::kCoreLibURL = "dart:core"
staticconstexpr

Definition at line 293 of file dartutils.h.

◆ kDartScheme

constexpr const char* dart::bin::DartUtils::kDartScheme = "dart:"
staticconstexpr

Definition at line 290 of file dartutils.h.

◆ kHttpLibURL

constexpr const char* dart::bin::DartUtils::kHttpLibURL = "dart:_http"
staticconstexpr

Definition at line 296 of file dartutils.h.

◆ kHttpScheme

constexpr const char* dart::bin::DartUtils::kHttpScheme = "http:"
staticconstexpr

Definition at line 302 of file dartutils.h.

◆ kInternalLibURL

constexpr const char* dart::bin::DartUtils::kInternalLibURL = "dart:_internal"
staticconstexpr

Definition at line 294 of file dartutils.h.

◆ kIOLibPatchURL

constexpr const char* dart::bin::DartUtils::kIOLibPatchURL = "dart:io-patch"
staticconstexpr

Definition at line 298 of file dartutils.h.

◆ kIOLibURL

constexpr const char* dart::bin::DartUtils::kIOLibURL = "dart:io"
staticconstexpr

Definition at line 297 of file dartutils.h.

◆ kIsolateLibURL

constexpr const char* dart::bin::DartUtils::kIsolateLibURL = "dart:isolate"
staticconstexpr

Definition at line 295 of file dartutils.h.

◆ kMaxMagicNumberSize

constexpr int64_t dart::bin::DartUtils::kMaxMagicNumberSize = 8
staticconstexpr

Definition at line 271 of file dartutils.h.

◆ kUriLibURL

constexpr const char* dart::bin::DartUtils::kUriLibURL = "dart:uri"
staticconstexpr

Definition at line 301 of file dartutils.h.

◆ kVMServiceLibURL

constexpr const char* dart::bin::DartUtils::kVMServiceLibURL = "dart:vmservice"
staticconstexpr

Definition at line 303 of file dartutils.h.

◆ original_working_directory

const char * dart::bin::DartUtils::original_working_directory = nullptr
static

Definition at line 288 of file dartutils.h.


The documentation for this class was generated from the following files: