blob: 7df4242c7bfa4ad06caa9cec45c4049ab21b71c6 [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/bss_relocs.h"
#include "vm/runtime_entry.h"
#include "vm/thread.h"
namespace dart {
static void InitializeBSSEntry(BSS::Relocation relocation,
uword function_address,
uword* bss_start) {
std::atomic<uword>* slot = reinterpret_cast<std::atomic<uword>*>(
&bss_start[BSS::RelocationIndex(relocation)]);
uword old_value = slot->load(std::memory_order_relaxed);
uword new_value = function_address;
if (!slot->compare_exchange_strong(old_value, new_value,
std::memory_order_relaxed)) {
RELEASE_ASSERT(old_value == new_value);
}
}
void BSS::Initialize(Thread* current, uword* bss_start) {
InitializeBSSEntry(BSS::Relocation::DRT_GetThreadForNativeCallback,
reinterpret_cast<uword>(DLRT_GetThreadForNativeCallback),
bss_start);
}
} // namespace dart