mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[VM] Copies Dart_CodeObserver in Init to prevent use-after-free.
Dart_CodeObserver is a struct (in dart_api.h) with two pointers: void* data; void (*Dart_OnNewCodeCallback)(...) on_new_code; Change-Id: I556b73e0e3488a10f9fd162af24e36ad4f240fa1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111723 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Clement Skau <cskau@google.com>
This commit is contained in:
parent
d3f3b46b87
commit
844626c4e6
|
@ -17,7 +17,7 @@ CodeObserver** CodeObservers::observers_ = NULL;
|
|||
|
||||
class ExternalCodeObserverAdapter : public CodeObserver {
|
||||
public:
|
||||
explicit ExternalCodeObserverAdapter(Dart_CodeObserver* delegate)
|
||||
explicit ExternalCodeObserverAdapter(Dart_CodeObserver delegate)
|
||||
: delegate_(delegate) {}
|
||||
|
||||
virtual bool IsActive() const { return true; }
|
||||
|
@ -28,15 +28,15 @@ class ExternalCodeObserverAdapter : public CodeObserver {
|
|||
uword size,
|
||||
bool optimized,
|
||||
const CodeComments* comments) {
|
||||
return delegate_->on_new_code(delegate_, name, base, size);
|
||||
return delegate_.on_new_code(&delegate_, name, base, size);
|
||||
}
|
||||
|
||||
private:
|
||||
Dart_CodeObserver* delegate_;
|
||||
Dart_CodeObserver delegate_;
|
||||
};
|
||||
|
||||
void CodeObservers::RegisterExternal(Dart_CodeObserver* observer) {
|
||||
if (observer != nullptr) Register(new ExternalCodeObserverAdapter(observer));
|
||||
void CodeObservers::RegisterExternal(Dart_CodeObserver observer) {
|
||||
Register(new ExternalCodeObserverAdapter(observer));
|
||||
}
|
||||
|
||||
void CodeObservers::Register(CodeObserver* observer) {
|
||||
|
|
|
@ -57,7 +57,7 @@ class CodeObservers : public AllStatic {
|
|||
public:
|
||||
static void Init();
|
||||
|
||||
static void RegisterExternal(Dart_CodeObserver* observer);
|
||||
static void RegisterExternal(Dart_CodeObserver observer);
|
||||
|
||||
static void Register(CodeObserver* observer);
|
||||
|
||||
|
|
|
@ -200,7 +200,9 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
|
|||
set_entropy_source_callback(entropy_source);
|
||||
OS::Init();
|
||||
NOT_IN_PRODUCT(CodeObservers::Init());
|
||||
NOT_IN_PRODUCT(CodeObservers::RegisterExternal(observer));
|
||||
if (observer != nullptr) {
|
||||
NOT_IN_PRODUCT(CodeObservers::RegisterExternal(*observer));
|
||||
}
|
||||
start_time_micros_ = OS::GetCurrentMonotonicMicros();
|
||||
VirtualMemory::Init();
|
||||
OSThread::Init();
|
||||
|
|
Loading…
Reference in a new issue