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

#include <ffi_callback_metadata.h>

Classes

class  Metadata
 

Public Types

enum class  TrampolineType : uint8_t { kSync = 0 , kSyncStackDelta4 = 1 , kAsync = 2 }
 
enum  RuntimeFunctions { kGetFfiCallbackMetadata , kExitTemporaryIsolate , kNumRuntimeFunctions }
 
using Trampoline = uword
 

Public Member Functions

Trampoline CreateAsyncFfiCallback (Isolate *isolate, Zone *zone, const Function &function, Dart_Port send_port, Metadata **list_head)
 
Trampoline CreateIsolateLocalFfiCallback (Isolate *isolate, Zone *zone, const Function &function, const Closure &closure, Metadata **list_head)
 
void DeleteCallback (Trampoline trampoline, Metadata **list_head)
 
void DeleteAllCallbacks (Metadata **list_head)
 
Metadata LookupMetadataForTrampoline (Trampoline trampoline) const
 
Mutexlock ()
 
MetadataMetadataOfTrampoline (Trampoline trampoline) const
 
Trampoline TrampolineOfMetadata (Metadata *metadata) const
 

Static Public Member Functions

static void Init ()
 
static void Cleanup ()
 
static FfiCallbackMetadataInstance ()
 
static constexpr intptr_t NumCallbackTrampolinesPerPage ()
 
static constexpr intptr_t RXMappingSize ()
 
static constexpr intptr_t RWMappingSize ()
 
static constexpr intptr_t MappingSize ()
 
static constexpr intptr_t MappingAlignment ()
 
static constexpr intptr_t MappingStart (uword address)
 
static constexpr uword RuntimeFunctionOffset (uword function_index)
 
static constexpr intptr_t MetadataOffset ()
 

Static Public Attributes

static constexpr intptr_t kPageSize = 4 * KB
 
static constexpr intptr_t kPageMask = ~(kPageSize - 1)
 

Detailed Description

Definition at line 33 of file ffi_callback_metadata.h.

Member Typedef Documentation

◆ Trampoline

Definition at line 38 of file ffi_callback_metadata.h.

Member Enumeration Documentation

◆ RuntimeFunctions

Enumerator
kGetFfiCallbackMetadata 
kExitTemporaryIsolate 
kNumRuntimeFunctions 

Definition at line 46 of file ffi_callback_metadata.h.

◆ TrampolineType

enum class dart::FfiCallbackMetadata::TrampolineType : uint8_t
strong
Enumerator
kSync 
kSyncStackDelta4 
kAsync 

Definition at line 40 of file ffi_callback_metadata.h.

40 : uint8_t {
41 kSync = 0,
42 kSyncStackDelta4 = 1, // Only used by TARGET_ARCH_IA32
43 kAsync = 2,
44 };

Member Function Documentation

◆ Cleanup()

void dart::FfiCallbackMetadata::Cleanup ( )
static

Definition at line 75 of file ffi_callback_metadata.cc.

75 {
76 ASSERT(singleton_ != nullptr);
77 delete singleton_;
78 singleton_ = nullptr;
79}
#define ASSERT(E)

◆ CreateAsyncFfiCallback()

FfiCallbackMetadata::Trampoline dart::FfiCallbackMetadata::CreateAsyncFfiCallback ( Isolate isolate,
Zone zone,
const Function function,
Dart_Port  send_port,
Metadata **  list_head 
)

Definition at line 316 of file ffi_callback_metadata.cc.

321 {
322 ASSERT(send_function.GetFfiCallbackKind() == FfiCallbackKind::kAsyncCallback);
323 return CreateMetadataEntry(isolate, TrampolineType::kAsync,
324 GetEntryPoint(zone, send_function),
325 static_cast<uint64_t>(send_port), list_head);
326}

◆ CreateIsolateLocalFfiCallback()

FfiCallbackMetadata::Trampoline dart::FfiCallbackMetadata::CreateIsolateLocalFfiCallback ( Isolate isolate,
Zone zone,
const Function function,
const Closure closure,
Metadata **  list_head 
)

Definition at line 270 of file ffi_callback_metadata.cc.

274 {
275 if (closure.IsNull()) {
276 // If the closure is null, it means the target is a static function, so is
277 // baked into the trampoline and is an ordinary sync callback.
278 ASSERT(function.GetFfiCallbackKind() ==
280 return CreateSyncFfiCallbackImpl(isolate, zone, function, nullptr,
281 list_head);
282 } else {
283 ASSERT(function.GetFfiCallbackKind() ==
285 return CreateSyncFfiCallbackImpl(isolate, zone, function,
286 CreatePersistentHandle(isolate, closure),
287 list_head);
288 }
289}
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void()> closure
Definition: closure.h:14

◆ DeleteAllCallbacks()

void dart::FfiCallbackMetadata::DeleteAllCallbacks ( Metadata **  list_head)

Definition at line 222 of file ffi_callback_metadata.cc.

222 {
223 MutexLocker locker(&lock_);
224 for (Metadata* entry = *list_head; entry != nullptr;) {
225 Metadata* next = entry->list_next();
226 DeleteCallbackLocked(entry);
227 entry = next;
228 }
229 *list_head = nullptr;
230}
static float next(float f)

◆ DeleteCallback()

void dart::FfiCallbackMetadata::DeleteCallback ( Trampoline  trampoline,
Metadata **  list_head 
)

Definition at line 232 of file ffi_callback_metadata.cc.

233 {
234 MutexLocker locker(&lock_);
235 auto* entry = MetadataOfTrampoline(trampoline);
236 ASSERT(entry->IsLive());
237 auto* prev = entry->list_prev_;
238 auto* next = entry->list_next_;
239 if (prev != nullptr) {
240 prev->list_next_ = next;
241 } else {
242 ASSERT(*list_head == entry);
243 *list_head = next;
244 }
245 if (next != nullptr) {
246 next->list_prev_ = prev;
247 }
248 DeleteCallbackLocked(entry);
249}
static float prev(float f)
Metadata * MetadataOfTrampoline(Trampoline trampoline) const

◆ Init()

void dart::FfiCallbackMetadata::Init ( )
static

Definition at line 70 of file ffi_callback_metadata.cc.

70 {
71 ASSERT(singleton_ == nullptr);
72 singleton_ = new FfiCallbackMetadata();
73}

◆ Instance()

FfiCallbackMetadata * dart::FfiCallbackMetadata::Instance ( )
static

Definition at line 81 of file ffi_callback_metadata.cc.

81 {
82 ASSERT(singleton_ != nullptr);
83 return singleton_;
84}

◆ lock()

Mutex * dart::FfiCallbackMetadata::lock ( )
inline

Definition at line 190 of file ffi_callback_metadata.h.

190{ return &lock_; }

◆ LookupMetadataForTrampoline()

FfiCallbackMetadata::Metadata dart::FfiCallbackMetadata::LookupMetadataForTrampoline ( Trampoline  trampoline) const

Definition at line 367 of file ffi_callback_metadata.cc.

368 {
369 return *MetadataOfTrampoline(trampoline);
370}

◆ MappingAlignment()

static constexpr intptr_t dart::FfiCallbackMetadata::MappingAlignment ( )
inlinestaticconstexpr

Definition at line 235 of file ffi_callback_metadata.h.

235 {
237 }
static constexpr intptr_t MappingSize()
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
Definition: utils.h:135

◆ MappingSize()

static constexpr intptr_t dart::FfiCallbackMetadata::MappingSize ( )
inlinestaticconstexpr

Definition at line 232 of file ffi_callback_metadata.h.

232 {
233 return RXMappingSize() + RWMappingSize();
234 }
static constexpr intptr_t RXMappingSize()
static constexpr intptr_t RWMappingSize()

◆ MappingStart()

static constexpr intptr_t dart::FfiCallbackMetadata::MappingStart ( uword  address)
inlinestaticconstexpr

Definition at line 238 of file ffi_callback_metadata.h.

238 {
239 const uword mask = MappingAlignment() - 1;
240 return address & ~mask;
241 }
static constexpr intptr_t MappingAlignment()
uintptr_t uword
Definition: globals.h:501

◆ MetadataOffset()

static constexpr intptr_t dart::FfiCallbackMetadata::MetadataOffset ( )
inlinestaticconstexpr

Definition at line 245 of file ffi_callback_metadata.h.

245 {
247 }
static constexpr uword RuntimeFunctionOffset(uword function_index)

◆ MetadataOfTrampoline()

FfiCallbackMetadata::Metadata * dart::FfiCallbackMetadata::MetadataOfTrampoline ( Trampoline  trampoline) const

Definition at line 342 of file ffi_callback_metadata.cc.

343 {
344#if defined(DART_TARGET_OS_FUCHSIA)
345 // On Fuchsia the metadata page is separate to the trampoline page.
346 // TODO(https://dartbug.com/52579): Remove.
347 const uword page_start =
348 Utils::RoundDown(trampoline - offset_of_first_trampoline_in_page_,
350 const uword index =
351 (trampoline - offset_of_first_trampoline_in_page_ - page_start) /
352 kNativeCallbackTrampolineSize;
354 Metadata* metadata_table = reinterpret_cast<Metadata*>(
355 fuchsia_metadata_page_->start() + MetadataOffset());
356 return metadata_table + index;
357#else
358 const uword start = MappingStart(trampoline);
359 Metadata* metadatas = reinterpret_cast<Metadata*>(start + MetadataOffset());
360 const uword index =
361 (trampoline - start - offset_of_first_trampoline_in_page_) /
362 kNativeCallbackTrampolineSize;
363 return &metadatas[index];
364#endif
365}
static constexpr intptr_t NumCallbackTrampolinesPerPage()
static constexpr intptr_t MappingStart(uword address)
static constexpr intptr_t MetadataOffset()
static constexpr T RoundDown(T x, intptr_t alignment)
Definition: utils.h:108
static intptr_t PageSize()

◆ NumCallbackTrampolinesPerPage()

static constexpr intptr_t dart::FfiCallbackMetadata::NumCallbackTrampolinesPerPage ( )
inlinestaticconstexpr

Definition at line 193 of file ffi_callback_metadata.h.

193 {
194 return (kPageSize - kNativeCallbackSharedStubSize) /
195 kNativeCallbackTrampolineSize;
196 }
static constexpr intptr_t kPageSize

◆ RuntimeFunctionOffset()

static constexpr uword dart::FfiCallbackMetadata::RuntimeFunctionOffset ( uword  function_index)
inlinestaticconstexpr

Definition at line 242 of file ffi_callback_metadata.h.

242 {
243 return RXMappingSize() + function_index * compiler::target::kWordSize;
244 }
static constexpr intptr_t kWordSize
Definition: runtime_api.h:274

◆ RWMappingSize()

static constexpr intptr_t dart::FfiCallbackMetadata::RWMappingSize ( )
inlinestaticconstexpr

Definition at line 226 of file ffi_callback_metadata.h.

226 {
227 return Utils::RoundUp(
229 sizeof(Metadata) * NumCallbackTrampolinesPerPage(),
230 kPageSize);
231 }
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition: utils.h:120

◆ RXMappingSize()

static constexpr intptr_t dart::FfiCallbackMetadata::RXMappingSize ( )
inlinestaticconstexpr

Definition at line 225 of file ffi_callback_metadata.h.

225{ return 2 * kPageSize; }

◆ TrampolineOfMetadata()

FfiCallbackMetadata::Trampoline dart::FfiCallbackMetadata::TrampolineOfMetadata ( Metadata metadata) const

Definition at line 328 of file ffi_callback_metadata.cc.

329 {
330 const uword start = MappingStart(reinterpret_cast<uword>(metadata));
331 Metadata* metadatas = reinterpret_cast<Metadata*>(start + MetadataOffset());
332 const uword index = metadata - metadatas;
333#if defined(DART_TARGET_OS_FUCHSIA)
334 return StubCode::FfiCallbackTrampoline().EntryPoint() +
335 index * kNativeCallbackTrampolineSize;
336#else
337 return start + offset_of_first_trampoline_in_page_ +
338 index * kNativeCallbackTrampolineSize;
339#endif
340}

Member Data Documentation

◆ kPageMask

constexpr intptr_t dart::FfiCallbackMetadata::kPageMask = ~(kPageSize - 1)
staticconstexpr

Definition at line 216 of file ffi_callback_metadata.h.

◆ kPageSize

constexpr intptr_t dart::FfiCallbackMetadata::kPageSize = 4 * KB
staticconstexpr

Definition at line 214 of file ffi_callback_metadata.h.


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