!122 Support ARK Previewer on Windows

Merge pull request !122 from huangyu/support_win_previewer
This commit is contained in:
openharmony_ci
2022-04-24 14:02:54 +00:00
committed by Gitee
78 changed files with 962 additions and 423 deletions
+3
View File
@@ -69,6 +69,9 @@ ohos_shared_library("libarkassembler") {
relative_install_dir = "ark"
}
output_extension = "so"
if (is_mingw) {
output_extension = "dll"
}
subsystem_name = "ark"
part_name = "ark"
}
+3
View File
@@ -56,6 +56,9 @@ ohos_shared_library("arkdisassembler") {
relative_install_dir = "ark"
}
output_extension = "so"
if (is_mingw) {
output_extension = "dll"
}
subsystem_name = "ark"
part_name = "ark"
}
+7 -7
View File
@@ -30,7 +30,7 @@
#include "generated/daemon_options.h"
namespace panda::dprof {
bool CheckVersion(const os::unix::UniqueFd &sock)
bool CheckVersion(const os::unique_fd::UniqueFd &sock)
{
// Get version
ipc::Message msg;
@@ -54,7 +54,7 @@ bool CheckVersion(const os::unix::UniqueFd &sock)
return true;
}
static std::unique_ptr<AppData> ProcessingConnect(const os::unix::UniqueFd &sock)
static std::unique_ptr<AppData> ProcessingConnect(const os::unique_fd::UniqueFd &sock)
{
if (!CheckVersion(sock)) {
return nullptr;
@@ -106,7 +106,7 @@ static std::unique_ptr<AppData> ProcessingConnect(const os::unix::UniqueFd &sock
class Worker {
public:
void EnqueueClientSocket(os::unix::UniqueFd clientSock)
void EnqueueClientSocket(os::unique_fd::UniqueFd clientSock)
{
os::memory::LockHolder lock(queue_lock_);
queue_.push(std::move(clientSock));
@@ -130,7 +130,7 @@ public:
void DoRun(AppDataStorage *storage)
{
while (!done_) {
os::unix::UniqueFd clientSock;
os::unique_fd::UniqueFd clientSock;
{
os::memory::LockHolder lock(queue_lock_);
while (queue_.empty() && !done_) {
@@ -157,7 +157,7 @@ public:
private:
std::thread thread_;
os::memory::Mutex queue_lock_;
std::queue<os::unix::UniqueFd> queue_;
std::queue<os::unique_fd::UniqueFd> queue_;
os::memory::ConditionVariable cond_ GUARDED_BY(queue_lock_);
bool done_ = false;
};
@@ -245,7 +245,7 @@ static int Main(panda::Span<const char *> args)
}
// Create server socket
os::unix::UniqueFd sock(ipc::CreateUnixServerSocket(MAX_PENDING_CONNECTIONS_QUEUE));
os::unique_fd::UniqueFd sock(ipc::CreateUnixServerSocket(MAX_PENDING_CONNECTIONS_QUEUE));
if (!sock.IsValid()) {
LOG(FATAL, DPROF) << "Cannot create socket";
return -1;
@@ -257,7 +257,7 @@ static int Main(panda::Span<const char *> args)
LOG(INFO, DPROF) << "Daemon is ready for connections";
// Main loop
while (!g_done) {
os::unix::UniqueFd clientSock(::accept4(sock.Get(), nullptr, nullptr, SOCK_CLOEXEC));
os::unique_fd::UniqueFd clientSock(::accept4(sock.Get(), nullptr, nullptr, SOCK_CLOEXEC));
if (!clientSock.IsValid()) {
if (errno == EINTR) {
continue;
+10 -10
View File
@@ -15,7 +15,7 @@
#include "ipc_unix_socket.h"
#include "os/unix/failure_retry.h"
#include "os/failure_retry.h"
#include "utils/logger.h"
#include "securec.h"
@@ -29,14 +29,14 @@ namespace panda::dprof::ipc {
constexpr char SOCKET_NAME[] = "\0dprof.socket"; // NOLINT(modernize-avoid-c-arrays)
static_assert(sizeof(SOCKET_NAME) <= sizeof(static_cast<sockaddr_un *>(nullptr)->sun_path), "Socket name too large");
os::unix::UniqueFd CreateUnixServerSocket(int backlog)
os::unique_fd::UniqueFd CreateUnixServerSocket(int backlog)
{
os::unix::UniqueFd sock(PANDA_FAILURE_RETRY(::socket(AF_UNIX, SOCK_STREAM, 0)));
os::unique_fd::UniqueFd sock(PANDA_FAILURE_RETRY(::socket(AF_UNIX, SOCK_STREAM, 0)));
int opt = 1;
if (PANDA_FAILURE_RETRY(::setsockopt(sock.Get(), SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) == -1) {
PLOG(ERROR, DPROF) << "setsockopt() failed";
return os::unix::UniqueFd();
return os::unique_fd::UniqueFd();
}
struct sockaddr_un serverAddr {
@@ -53,23 +53,23 @@ os::unix::UniqueFd CreateUnixServerSocket(int backlog)
if (PANDA_FAILURE_RETRY(::bind(sock.Get(), reinterpret_cast<struct sockaddr *>(&serverAddr), sizeof(serverAddr))) ==
-1) {
PLOG(ERROR, DPROF) << "bind() failed";
return os::unix::UniqueFd();
return os::unique_fd::UniqueFd();
}
if (::listen(sock.Get(), backlog) == -1) {
PLOG(ERROR, DPROF) << "listen() failed";
return os::unix::UniqueFd();
return os::unique_fd::UniqueFd();
}
return sock;
}
os::unix::UniqueFd CreateUnixClientSocket()
os::unique_fd::UniqueFd CreateUnixClientSocket()
{
os::unix::UniqueFd sock(PANDA_FAILURE_RETRY(::socket(AF_UNIX, SOCK_STREAM, 0)));
os::unique_fd::UniqueFd sock(PANDA_FAILURE_RETRY(::socket(AF_UNIX, SOCK_STREAM, 0)));
if (!sock.IsValid()) {
PLOG(ERROR, DPROF) << "socket() failed";
return os::unix::UniqueFd();
return os::unique_fd::UniqueFd();
}
struct sockaddr_un serverAddr {
@@ -86,7 +86,7 @@ os::unix::UniqueFd CreateUnixClientSocket()
if (PANDA_FAILURE_RETRY(
::connect(sock.Get(), reinterpret_cast<struct sockaddr *>(&serverAddr), sizeof(serverAddr))) == -1) {
PLOG(ERROR, DPROF) << "connect() failed";
return os::unix::UniqueFd();
return os::unique_fd::UniqueFd();
}
return sock;
+3 -3
View File
@@ -16,11 +16,11 @@
#ifndef PANDA_DPROF_LIBDPROF_DPROF_IPC_IPC_UNIX_SOCKET_H_
#define PANDA_DPROF_LIBDPROF_DPROF_IPC_IPC_UNIX_SOCKET_H_
#include "os/unix/unique_fd.h"
#include "os/unique_fd.h"
namespace panda::dprof::ipc {
os::unix::UniqueFd CreateUnixServerSocket(int backlog);
os::unix::UniqueFd CreateUnixClientSocket();
os::unique_fd::UniqueFd CreateUnixServerSocket(int backlog);
os::unique_fd::UniqueFd CreateUnixClientSocket();
bool WaitDataTimeout(int fd, int timeoutMs);
bool SendAll(int fd, const void *buf, int len);
+1 -1
View File
@@ -35,7 +35,7 @@ bool ProfilingData::SetFeatureDate(const std::string &featureName, std::vector<u
bool ProfilingData::DumpAndResetFeatures()
{
os::unix::UniqueFd sock(ipc::CreateUnixClientSocket());
os::unique_fd::UniqueFd sock(ipc::CreateUnixClientSocket());
if (!sock.IsValid()) {
LOG(ERROR, DPROF) << "Cannot create client socket";
return false;
+14 -4
View File
@@ -40,21 +40,28 @@ if (is_mingw) {
"$ark_root/libpandabase/mem/arena.cpp",
"$ark_root/libpandabase/mem/arena_allocator.cpp",
"$ark_root/libpandabase/mem/base_mem_stats.cpp",
"$ark_root/libpandabase/mem/code_allocator.cpp",
"$ark_root/libpandabase/mem/mem_config.cpp",
"$ark_root/libpandabase/mem/pool_manager.cpp",
"$ark_root/libpandabase/mem/pool_map.cpp",
"$ark_root/libpandabase/os/dfx_option.cpp",
"$ark_root/libpandabase/os/filesystem.cpp",
"$ark_root/libpandabase/os/mutex.cpp",
"$ark_root/libpandabase/os/native_stack.cpp",
"$ark_root/libpandabase/os/stacktrace_stub.cpp",
"$ark_root/libpandabase/os/unix/mutex.cpp",
"$ark_root/libpandabase/os/time.cpp",
"$ark_root/libpandabase/os/windows/error.cpp",
"$ark_root/libpandabase/os/windows/file.cpp",
"$ark_root/libpandabase/os/windows/library_loader.cpp",
"$ark_root/libpandabase/os/windows/mem.cpp",
"$ark_root/libpandabase/os/windows/mem_hooks.cpp",
"$ark_root/libpandabase/os/windows/thread.cpp",
"$ark_root/libpandabase/trace/windows/trace.cpp",
"$ark_root/libpandabase/utils/dfx.cpp",
"$ark_root/libpandabase/utils/json_parser.cpp",
"$ark_root/libpandabase/utils/logger.cpp",
"$ark_root/libpandabase/utils/time.cpp",
"$ark_root/libpandabase/utils/type_converter.cpp",
"$ark_root/libpandabase/utils/utf.cpp",
]
} else {
@@ -78,10 +85,10 @@ if (is_mingw) {
"$ark_root/libpandabase/os/unix/filesystem.cpp",
"$ark_root/libpandabase/os/unix/library_loader.cpp",
"$ark_root/libpandabase/os/unix/mem.cpp",
"$ark_root/libpandabase/os/unix/mem_hooks.cpp",
"$ark_root/libpandabase/os/unix/native_stack.cpp",
"$ark_root/libpandabase/os/unix/property.cpp",
"$ark_root/libpandabase/os/unix/thread.cpp",
"$ark_root/libpandabase/os/unix/time_unix.cpp",
"$ark_root/libpandabase/trace/trace.cpp",
"$ark_root/libpandabase/trace/unix/trace.cpp",
"$ark_root/libpandabase/utils/dfx.cpp",
@@ -99,10 +106,10 @@ if (is_mingw) {
"$ark_root/libpandabase/os/unix/exec.cpp",
"$ark_root/libpandabase/os/unix/futex/mutex.cpp",
"$ark_root/libpandabase/os/unix/pipe.cpp",
"$ark_root/libpandabase/os/unix/sighooklib/sighook.cpp",
"$ark_root/libpandabase/os/unix/sighook.cpp",
]
} else {
libarkbase_sources += [ "$ark_root/libpandabase/os/unix/mutex.cpp" ]
libarkbase_sources += [ "$ark_root/libpandabase/os/mutex.cpp" ]
}
}
@@ -130,6 +137,9 @@ ohos_shared_library("libarkbase") {
deps = libarkbase_deps
output_extension = "so"
if (is_mingw) {
output_extension = "dll"
}
if (!is_standard_system) {
relative_install_dir = "ark"
}
+47 -35
View File
@@ -46,13 +46,13 @@ set(UNIX_SOURCES_COMMON
${PANDA_ROOT}/libpandabase/os/unix/thread.cpp
${PANDA_ROOT}/libpandabase/os/unix/native_stack.cpp
${PANDA_ROOT}/libpandabase/os/unix/property.cpp
${PANDA_ROOT}/libpandabase/os/unix/time_unix.cpp
${PANDA_ROOT}/libpandabase/os/unix/file.cpp
${PANDA_ROOT}/libpandabase/os/unix/filesystem.cpp
${PANDA_ROOT}/libpandabase/os/unix/library_loader.cpp
${PANDA_ROOT}/libpandabase/os/unix/mem.cpp
${PANDA_ROOT}/libpandabase/os/unix/mem_hooks.cpp
${PANDA_ROOT}/libpandabase/trace/unix/trace.cpp
${PANDA_ROOT}/libpandabase/os/unix/sighooklib/sighook.cpp
${PANDA_ROOT}/libpandabase/os/unix/sighook.cpp
)
# Handle pthread and futex mutexes
if(PANDA_USE_FUTEX)
@@ -61,7 +61,7 @@ if(PANDA_USE_FUTEX)
)
else()
set(UNIX_SOURCES_COMMON ${UNIX_SOURCES_COMMON}
${PANDA_ROOT}/libpandabase/os/unix/mutex.cpp
${PANDA_ROOT}/libpandabase/os/mutex.cpp
)
endif()
@@ -71,18 +71,26 @@ set(WINDOWS_SOURCES
${PANDA_ROOT}/libpandabase/utils/dfx.cpp
${PANDA_ROOT}/libpandabase/utils/utf.cpp
${PANDA_ROOT}/libpandabase/utils/json_parser.cpp
${PANDA_ROOT}/libpandabase/utils/time.cpp
${PANDA_ROOT}/libpandabase/utils/type_converter.cpp
${PANDA_ROOT}/libpandabase/os/windows/error.cpp
${PANDA_ROOT}/libpandabase/os/windows/file.cpp
${PANDA_ROOT}/libpandabase/os/windows/mem.cpp
${PANDA_ROOT}/libpandabase/os/windows/thread.cpp
${PANDA_ROOT}/libpandabase/os/windows/library_loader.cpp
${PANDA_ROOT}/libpandabase/os/windows/mem_hooks.cpp
${PANDA_ROOT}/libpandabase/trace/windows/trace.cpp
${PANDA_ROOT}/libpandabase/os/dfx_option.cpp
${PANDA_ROOT}/libpandabase/os/filesystem.cpp
${PANDA_ROOT}/libpandabase/os/unix/mutex.cpp
${PANDA_ROOT}/libpandabase/os/mutex.cpp
${PANDA_ROOT}/libpandabase/os/time.cpp
${PANDA_ROOT}/libpandabase/mem/alloc_tracker.cpp
${PANDA_ROOT}/libpandabase/mem/arena.cpp
${PANDA_ROOT}/libpandabase/mem/arena_allocator.cpp
${PANDA_ROOT}/libpandabase/mem/pool_manager.cpp
${PANDA_ROOT}/libpandabase/mem/pool_map.cpp
${PANDA_ROOT}/libpandabase/mem/base_mem_stats.cpp
${PANDA_ROOT}/libpandabase/mem/code_allocator.cpp
${PANDA_ROOT}/libpandabase/mem/mem_config.cpp
)
@@ -186,41 +194,45 @@ target_include_directories(arkbase
PUBLIC ${INCLUDE_DIRECTORIES}
)
set(ARKBASE_TESTS_SOURCES
tests/list_test.cpp
tests/bit_helpers_test.cpp
tests/bit_memory_region_test.cpp
tests/bit_table_test.cpp
tests/bit_utils_test.cpp
tests/bit_vector_test.cpp
tests/string_helpers_test.cpp
tests/type_converter_tests.cpp
tests/logger_test.cpp
tests/dfx_test.cpp
tests/leb128_test.cpp
tests/utf_test.cpp
tests/arena_test.cpp
tests/arena_allocator_test.cpp
tests/expected_test.cpp
tests/code_allocator_test.cpp
tests/small_vector_test.cpp
tests/span_test.cpp
tests/pandargs_test.cpp
tests/pool_map_test.cpp
tests/hash_test.cpp
tests/math_helpers_test.cpp
tests/serializer_test.cpp
tests/base_mem_stats_test.cpp
tests/unique_fd_test.cpp
tests/mem_range_test.cpp
tests/mmap_fixed_test.cpp
tests/mmap_mem_pool_test.cpp
tests/native_bytes_from_mallinfo_test.cpp
tests/json_parser_test.cpp
tests/alloc_tracker_test.cpp
)
panda_add_gtest(
NO_CORES
NAME arkbase_tests
SOURCES
tests/list_test.cpp
tests/bit_helpers_test.cpp
tests/bit_memory_region_test.cpp
tests/bit_table_test.cpp
tests/bit_utils_test.cpp
tests/bit_vector_test.cpp
tests/string_helpers_test.cpp
tests/type_converter_tests.cpp
tests/logger_test.cpp
tests/dfx_test.cpp
tests/leb128_test.cpp
tests/utf_test.cpp
tests/arena_test.cpp
tests/arena_allocator_test.cpp
tests/expected_test.cpp
tests/code_allocator_test.cpp
tests/small_vector_test.cpp
tests/span_test.cpp
tests/pandargs_test.cpp
tests/pool_map_test.cpp
tests/hash_test.cpp
tests/math_helpers_test.cpp
tests/serializer_test.cpp
tests/base_mem_stats_test.cpp
tests/unique_fd_test.cpp
tests/mem_range_test.cpp
tests/mmap_fixed_test.cpp
tests/mmap_mem_pool_test.cpp
tests/native_bytes_from_mallinfo_test.cpp
tests/json_parser_test.cpp
tests/alloc_tracker_test.cpp
${ARKBASE_TESTS_SOURCES}
LIBRARIES
arkbase
SANITIZERS
+4
View File
@@ -47,8 +47,12 @@
#define FIELD_UNUSED
#endif
#ifndef PANDA_TARGET_WINDOWS
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define PANDA_PUBLIC_API __attribute__((visibility ("default")))
#else
#define PANDA_PUBLIC_API __declspec(dllexport)
#endif
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define MEMBER_OFFSET(T, F) offsetof(T, F)
+1 -7
View File
@@ -66,13 +66,7 @@ inline void MallocMemPool::FreeArenaImpl(ArenaT *arena)
LOG_MALLOC_MEM_POOL(DEBUG) << "Try to free arena with size " << std::dec << arena->GetSize()
<< " at addr = " << std::hex << arena;
arena->~Arena();
#ifdef PANDA_TARGET_WINDOWS
// std::free can not work with _aligned_malloc. it will lead to some weird crash
_aligned_free(arena);
#else
std::free(arena); // NOLINT(cppcoreguidelines-no-malloc)
#endif
os::mem::AlignedFree(arena);
LOG_MALLOC_MEM_POOL(DEBUG) << "Free arena call finished";
}
+4 -3
View File
@@ -41,8 +41,9 @@ namespace panda::os::dfx_option {
DFX_OPTION_ELEM(D, END_FLAG, "end-flag")
#else
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DFX_OPTION_LIST(D) \
DFX_OPTION_ELEM(D, DFXLOG, "dfx-log") \
#define DFX_OPTION_LIST(D) \
DFX_OPTION_ELEM(D, REFERENCE_DUMP, "reference-dump") \
DFX_OPTION_ELEM(D, DFXLOG, "dfx-log") \
DFX_OPTION_ELEM(D, END_FLAG, "end-flag")
#endif // PANDA_TARGET_UNIX
@@ -51,7 +52,6 @@ public:
enum DfxOptionId : uint8_t {
#ifdef PANDA_TARGET_UNIX
COMPILER_NULLCHECK_ID,
REFERENCE_DUMP_ID,
SIGNAL_CATCHER_ID,
SIGNAL_HANDLER_ID,
ARK_SIGQUIT_ID,
@@ -59,6 +59,7 @@ public:
ARK_SIGUSR2_ID,
MOBILE_LOG_ID,
#endif // PANDA_TARGET_UNIX
REFERENCE_DUMP_ID,
DFXLOG_ID,
END_FLAG_ID,
};
@@ -16,8 +16,10 @@
#ifndef PANDA_LIBPANDABASE_OS_UNIX_FAILURE_RETRY_H_
#define PANDA_LIBPANDABASE_OS_UNIX_FAILURE_RETRY_H_
#ifdef PANDA_TARGET_UNIX
// Mac Os' libc doesn't have this macro
#ifndef TEMP_FAILURE_RETRY
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TEMP_FAILURE_RETRY(exp) \
(__extension__({ \
decltype(exp) _result; \
@@ -30,5 +32,11 @@
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define PANDA_FAILURE_RETRY(exp) (__extension__ TEMP_FAILURE_RETRY(exp))
#elif PANDA_TARGET_WINDOWS
// Windows Os does not support TEMP_FAILURE_RETRY macro
#define PANDA_FAILURE_RETRY(exp) (exp)
#else
#error "Unsupported platform"
#endif // PANDA_TARGET_UNIX
#endif // PANDA_LIBPANDABASE_OS_UNIX_FAILURE_RETRY_H_
+3
View File
@@ -19,6 +19,9 @@
defined PANDA_TARGET_ARM64
#include <sys/stat.h>
#endif
#if defined(PANDA_TARGET_WINDOWS)
#include <fileapi.h>
#endif
namespace panda::os {
-1
View File
@@ -20,7 +20,6 @@
#include <string>
#if defined(PANDA_TARGET_WINDOWS)
#include <fileapi.h>
#ifndef NAME_MAX
constexpr size_t NAME_MAX = 255;
#endif // NAME_MAX
+2 -7
View File
@@ -18,6 +18,8 @@
#ifdef PANDA_TARGET_UNIX
#include "os/unix/library_loader.h"
#elif PANDA_TARGET_WINDOWS
#include "os/windows/library_loader.h"
#else
#error "Unsupported platform"
#endif
@@ -28,15 +30,8 @@
#include <string_view>
namespace panda::os::library_loader {
#ifdef PANDA_TARGET_UNIX
using LibraryHandle = panda::os::unix::library_loader::LibraryHandle;
#endif
Expected<LibraryHandle, Error> Load(std::string_view filename);
Expected<void *, Error> ResolveSymbol(const LibraryHandle &handle, std::string_view name);
} // namespace panda::os::library_loader
#endif // PANDA_LIBPANDABASE_OS_LIBRARY_LOADER_H_
+18 -1
View File
@@ -40,6 +40,15 @@ namespace panda::os::mem {
void MmapDeleter(std::byte *ptr, size_t size) noexcept;
/**
* \brief Make memory region \param mem with size \param size with protection flags \param prot
* @param mem Pointer to memory region (should be aligned to page size)
* @param size Size of memory region
* @param prot Memory protection flags, a combination of MMAP_PROT_XXX values
* @return Error object if any errors occur
*/
std::optional<Error> MakeMemWithProtFlag(void *mem, size_t size, int prot);
/**
* \brief Make memory region \param mem with size \param size readable and executable
* @param mem Pointer to memory region (should be aligned to page size)
@@ -72,12 +81,20 @@ std::optional<Error> MakeMemReadOnly(void *mem, size_t size);
uintptr_t AlignDownToPageSize(uintptr_t addr);
/**
* \brief Allocated aligned memory with alignment \param alignment_in_bytes and
* with size \param size. Use AlignedFree to free this memory.
* @param alignment_in_bytes - alignment in bytes
* @param size - min required size in bytes
* @return
*/
void *AlignedAlloc(size_t alignment_in_bytes, size_t size);
/**
* \brief Free memory, allocated by AlignedAlloc.
* @param mem - Pointer to memory, allocated by AlignedAlloc
*/
void AlignedFree(void *mem);
template <class T>
class MapRange {
public:
@@ -348,7 +365,7 @@ inline void ReleasePages([[maybe_unused]] uintptr_t pages_start, [[maybe_unused]
#ifdef PANDA_TARGET_UNIX
madvise(ToVoidPtr(pages_start), pages_end - pages_start, MADV_DONTNEED);
#else
UNREACHABLE();
// On Windows system we can do nothing
#endif
}
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_MEM_HOOKS_H_
#define PANDA_LIBPANDABASE_OS_MEM_HOOKS_H_
#ifdef PANDA_TARGET_UNIX
#include "os/unix/mem_hooks.h"
#elif PANDA_TARGET_WINDOWS
#include "os/windows/mem_hooks.h"
#else
#error "Unsupported platform"
#endif // PANDA_TARGET_UNIX
#endif // PANDA_LIBPANDABASE_OS_MEM_HOOKS_H_
@@ -14,15 +14,12 @@
*/
#include "mutex.h"
#include "utils/logger.h"
#include <cstring>
#include <ctime>
namespace panda::os::unix::memory {
const int64_t MILLISECONDS_PER_SEC = 1000;
const int64_t NANOSECONDS_PER_MILLISEC = 1000000;
const int64_t NANOSECONDS_PER_SEC = 1000000000;
@@ -199,5 +196,4 @@ bool ConditionVariable::TimedWait(Mutex *mutex, uint64_t ms, uint64_t ns, bool i
FatalIfError("pthread_cond_timedwait", rc);
return false;
}
} // namespace panda::os::unix::memory
+3 -1
View File
@@ -16,17 +16,19 @@
#ifndef PANDA_LIBPANDABASE_OS_NATIVE_STACK_H_
#define PANDA_LIBPANDABASE_OS_NATIVE_STACK_H_
#include "os/thread.h"
#if defined(PANDA_TARGET_UNIX)
#include "os/unix/native_stack.h"
#endif // PANDA_TARGET_UNIX
#include <string>
#include <set>
#include <signal.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
namespace panda::os::native_stack {
const auto g_PandaThreadSigmask = pthread_sigmask; // NOLINT(readability-identifier-naming)
#if defined(PANDA_TARGET_UNIX)
const auto g_PandaThreadSigmask = pthread_sigmask; // NOLINT(readability-identifier-naming)
using DumpUnattachedThread = panda::os::unix::native_stack::DumpUnattachedThread;
const auto DumpKernelStack = panda::os::unix::native_stack::DumpKernelStack; // NOLINT(readability-identifier-naming)
const auto GetNativeThreadNameForFile = // NOLINT(readability-identifier-naming)
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_SIGHOOK_H_
#define PANDA_LIBPANDABASE_OS_SIGHOOK_H_
#ifdef PANDA_TARGET_UNIX
#include "os/unix/sighook.h"
#else
#error "Unsupported platform"
#endif // PANDA_TARGET_UNIX
#endif // PANDA_LIBPANDABASE_OS_SIGHOOK_H_
+9
View File
@@ -22,6 +22,7 @@
#include <cstdint>
#include <memory>
#include <thread>
#include <pthread.h>
namespace panda::os::thread {
@@ -108,7 +109,11 @@ static void *ProxyFunc(void *args)
template <typename Func, typename... Args>
native_handle_type ThreadStart(Func *func, Args... args)
{
#ifdef PANDA_TARGET_UNIX
native_handle_type tid;
#else
pthread_t tid;
#endif
auto args_tuple = std::make_tuple(func, std::move(args)...);
internal::SharedPtrStruct<decltype(args_tuple)> *ptr = nullptr;
{
@@ -124,7 +129,11 @@ native_handle_type ThreadStart(Func *func, Args... args)
pthread_create(&tid, nullptr,
&internal::ProxyFunc<Func, decltype(args_tuple), std::tuple_size<decltype(args_tuple)>::value>,
static_cast<void *>(ptr));
#ifdef PANDA_TARGET_UNIX
return tid;
#else
return reinterpret_cast<native_handle_type>(tid);
#endif
}
} // namespace panda::os::thread
+12 -5
View File
@@ -16,20 +16,27 @@
#include "os/time.h"
namespace panda::os::time {
#if !defined(PANDA_TARGET_UNIX)
/**
* Return current time in nanoseconds
*/
uint64_t GetClockTimeInMicro()
{
return 0;
return GetClockTime<std::chrono::microseconds>(CLOCK_MONOTONIC);
}
/**
* Return current time in milliseconds
*/
uint64_t GetClockTimeInMilli()
{
return 0;
return GetClockTime<std::chrono::milliseconds>(CLOCK_MONOTONIC);
}
/**
* Return thread CPU time in nanoseconds
*/
uint64_t GetClockTimeInThreadCpuTime()
{
return 0;
return GetClockTime<std::chrono::nanoseconds>(CLOCK_THREAD_CPUTIME_ID);
}
#endif // PANDA_TARGET_UNIX
} // namespace panda::os::time
+7 -10
View File
@@ -16,23 +16,20 @@
#ifndef PANDA_LIBPANDABASE_OS_TIME_H_
#define PANDA_LIBPANDABASE_OS_TIME_H_
#if defined(PANDA_TARGET_UNIX)
#include "os/unix/time_unix.h"
#ifdef PANDA_TARGET_UNIX
#include "os/unix/time.h"
#elif PANDA_TARGET_WINDOWS
#include "os/windows/time.h"
#else
#error "Unsupported platform"
#endif // PANDA_TARGET_UNIX
#include <cstdint>
namespace panda::os::time {
#if defined(PANDA_TARGET_UNIX)
const auto GetClockTimeInMicro = panda::os::unix::time::GetClockTimeInMicro; // NOLINT(readability-identifier-naming)
const auto GetClockTimeInMilli = panda::os::unix::time::GetClockTimeInMilli; // NOLINT(readability-identifier-naming)
const auto GetClockTimeInThreadCpuTime = // NOLINT(readability-identifier-naming)
panda::os::unix::time::GetClockTimeInThreadCpuTime;
#else
uint64_t GetClockTimeInMicro();
uint64_t GetClockTimeInMilli();
uint64_t GetClockTimeInThreadCpuTime();
#endif // PANDA_TARGET_UNIX
} // namespace panda::os::time
#endif // PANDA_LIBPANDABASE_OS_TIME_H_
+95
View File
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_UNIQUE_FD_H_
#define PANDA_LIBPANDABASE_OS_UNIQUE_FD_H_
#ifdef PANDA_TARGET_UNIX
#include "os/unix/unique_fd.h"
#elif PANDA_TARGET_WINDOWS
#include "os/windows/unique_fd.h"
#else
#error "Unsupported platform"
#endif // PANDA_TARGET_UNIX
#include "os/failure_retry.h"
#include "utils/logger.h"
#include <unistd.h>
namespace panda::os::unique_fd {
class UniqueFd {
public:
explicit UniqueFd(int fd = -1) noexcept
{
Reset(fd);
}
UniqueFd(const UniqueFd &other_fd) = delete;
UniqueFd &operator=(const UniqueFd &other_fd) = delete;
UniqueFd(UniqueFd &&other_fd) noexcept
{
Reset(other_fd.Release());
}
UniqueFd &operator=(UniqueFd &&other_fd) noexcept
{
Reset(other_fd.Release());
return *this;
}
~UniqueFd()
{
Reset();
}
int Release() noexcept
{
int fd = fd_;
fd_ = -1;
return fd;
}
void Reset(int new_fd = -1)
{
if (fd_ != -1) {
ASSERT(new_fd != fd_);
DefaultCloser(fd_);
}
fd_ = new_fd;
}
int Get() const noexcept
{
return fd_;
}
bool IsValid() const noexcept
{
return fd_ != -1;
}
private:
static void DefaultCloser(int fd)
{
LOG_IF(PANDA_FAILURE_RETRY(::close(fd)) != 0, FATAL, COMMON) << "Incorrect fd: " << fd;
}
int fd_ = -1;
};
} // namespace panda::os::unique_fd
#endif // PANDA_LIBPANDABASE_OS_UNIQUE_FD_H_
+1 -1
View File
@@ -17,7 +17,7 @@
#include <cstring>
#include <unistd.h>
#include "os/unix/failure_retry.h"
#include "os/failure_retry.h"
#include "sys/wait.h"
namespace panda::os::exec {
+4
View File
@@ -64,4 +64,8 @@ private:
} // namespace panda::os::unix::library_loader
namespace panda::os::library_loader {
using LibraryHandle = panda::os::unix::library_loader::LibraryHandle;
} // namespace panda::os::library_loader
#endif // PANDA_LIBPANDABASE_OS_UNIX_LIBRARY_LOADER_H_
+16 -16
View File
@@ -65,36 +65,30 @@ BytePtr MapExecuted(size_t size)
return BytePtr(static_cast<std::byte *>(result), (result == nullptr) ? 0 : size, MmapDeleter);
}
std::optional<Error> MakeMemReadExec(void *mem, size_t size)
std::optional<Error> MakeMemWithProtFlag(void *mem, size_t size, int prot)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
int r = mprotect(mem, size, PROT_EXEC | PROT_READ);
int r = mprotect(mem, size, prot);
if (r != 0) {
return Error(errno);
}
return {};
}
std::optional<Error> MakeMemReadExec(void *mem, size_t size)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
return MakeMemWithProtFlag(mem, size, PROT_EXEC | PROT_READ);
}
std::optional<Error> MakeMemReadWrite(void *mem, size_t size)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
int r = mprotect(mem, size, PROT_WRITE | PROT_READ);
if (r != 0) {
return Error(errno);
}
return {};
return MakeMemWithProtFlag(mem, size, PROT_WRITE | PROT_READ);
}
std::optional<Error> MakeMemReadOnly(void *mem, size_t size)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
int r = mprotect(mem, size, PROT_READ);
if (r != 0) {
return Error(errno);
}
return {};
return MakeMemWithProtFlag(mem, size, PROT_READ);
}
uintptr_t AlignDownToPageSize(uintptr_t addr)
@@ -121,6 +115,12 @@ void *AlignedAlloc(size_t alignment_in_bytes, size_t size)
return ret;
}
void AlignedFree(void *mem)
{
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
std::free(mem);
}
static uint32_t GetPageSizeFromOs()
{
// NOLINTNEXTLINE(google-runtime-int)
@@ -19,8 +19,7 @@
#include "mem_hooks.h"
namespace panda::mem {
namespace panda::os::unix::mem_hooks {
size_t PandaHooks::alloc_via_standard = 0;
void *(*volatile PandaHooks::old_malloc_hook)(size_t, const void *) = nullptr;
void *(*volatile PandaHooks::old_memalign_hook)(size_t, size_t, const void *) = nullptr;
@@ -113,5 +112,4 @@ void PandaHooks::Disable()
__free_hook = old_free_hook;
#endif // __MUSL__
}
} // namespace panda::mem
} // namespace panda::os::unix::mem_hooks
@@ -13,13 +13,12 @@
* limitations under the License.
*/
#ifndef PANDA_RUNTIME_MEM_MEM_HOOKS_H_
#define PANDA_RUNTIME_MEM_MEM_HOOKS_H_
#ifndef PANDA_LIBPANDABASE_OS_UNIX_MEM_HOOKS_H_
#define PANDA_LIBPANDABASE_OS_UNIX_MEM_HOOKS_H_
#include "libpandabase/mem/mem.h"
namespace panda::mem {
namespace panda::os::unix::mem_hooks {
class PandaHooks {
public:
static void Enable();
@@ -48,7 +47,10 @@ private:
static size_t alloc_via_standard;
};
} // namespace panda::os::unix::mem_hooks
} // namespace panda::mem
namespace panda::os::mem_hooks {
using PandaHooks = panda::os::unix::mem_hooks::PandaHooks;
} // namespace panda::os::mem_hooks
#endif // PANDA_RUNTIME_MEM_MEM_HOOKS_H_
#endif // PANDA_LIBPANDABASE_OS_UNIX_MEM_HOOKS_H_
+1 -1
View File
@@ -15,7 +15,7 @@
#include "pipe.h"
#include "failure_retry.h"
#include "os/failure_retry.h"
#include <vector>
#include <array>
+3 -1
View File
@@ -16,15 +16,17 @@
#ifndef PANDA_LIBPANDABASE_OS_UNIX_PIPE_H_
#define PANDA_LIBPANDABASE_OS_UNIX_PIPE_H_
#include "unique_fd.h"
#include "utils/expected.h"
#include "os/error.h"
#include "os/unique_fd.h"
#include <utility>
#include <optional>
namespace panda::os::unix {
using UniqueFd = panda::os::unique_fd::UniqueFd;
std::pair<UniqueFd, UniqueFd> CreatePipe();
int SetFdNonblocking(const UniqueFd &fd);
@@ -13,9 +13,6 @@
* limitations under the License.
*/
#include "sighook.h"
#include "utils/logger.h"
#include <dlfcn.h>
#include <errno.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
#include <signal.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
@@ -24,6 +21,9 @@
#include <string.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
#include <array>
#include "utils/logger.h"
#include "os/sighook.h"
#include <algorithm>
#include <initializer_list>
#include <os/mutex.h>
@@ -35,7 +35,6 @@
#include <ucontext.h>
namespace panda {
static decltype(&sigaction) real_sigaction;
static decltype(&sigprocmask) real_sigprocmask;
static bool g_is_init_really {false};
@@ -495,5 +494,4 @@ void ClearSignalHooksHandlersArray()
signal_hooks[i].ClearHookActionHandlers();
}
}
} // namespace panda
@@ -13,14 +13,13 @@
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_
#define PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_
#ifndef PANDA_LIBPANDABASE_OS_UNIX_SIGHOOK_H_
#define PANDA_LIBPANDABASE_OS_UNIX_SIGHOOK_H_
#include <signal.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
#include <stdint.h> // NOLINTNEXTLINE(modernize-deprecated-headers)
namespace panda {
#if PANDA_TARGET_MACOS && !defined _NSIG
#define _NSIG NSIG
#endif
@@ -49,7 +48,6 @@ struct SigchainAction {
extern "C" void AddSpecialSignalHandlerFn(int signal, SigchainAction *sa);
extern "C" void RemoveSpecialSignalHandlerFn(int signal, bool (*fn)(int, siginfo_t *, void *));
extern "C" void EnsureFrontOfChain(int signal);
} // namespace panda
#endif // PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_
#endif // PANDA_LIBPANDABASE_OS_UNIX_SIGHOOK_H_
+2 -40
View File
@@ -23,7 +23,6 @@
#include <unistd.h>
namespace panda::os::thread {
ThreadId GetCurrentThreadId()
{
#if defined(HAVE_GETTID)
@@ -33,30 +32,20 @@ ThreadId GetCurrentThreadId()
uint64_t tid64;
pthread_threadid_np(NULL, &tid64);
return static_cast<ThreadId>(tid64);
#elif defined(PANDA_TARGET_UNIX)
#else
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
return static_cast<ThreadId>(syscall(SYS_gettid));
#else
#error "Unsupported platform"
#endif
}
int SetPriority(int thread_id, int prio)
{
#if defined(PANDA_TARGET_UNIX)
return setpriority(PRIO_PROCESS, thread_id, prio);
#else
#error "Unsupported platform"
#endif
}
int GetPriority(int thread_id)
{
#if defined(PANDA_TARGET_UNIX)
return getpriority(PRIO_PROCESS, thread_id);
#else
#error "Unsupported platform"
#endif
}
int SetThreadName(native_handle_type pthread_id, const char *name)
@@ -64,65 +53,38 @@ int SetThreadName(native_handle_type pthread_id, const char *name)
ASSERT(pthread_id != 0);
#if defined(PANDA_TARGET_MACOS)
return pthread_setname_np(name);
#elif defined(PANDA_TARGET_UNIX)
return pthread_setname_np(pthread_id, name);
#else
#error "Unsupported platform"
return pthread_setname_np(pthread_id, name);
#endif
}
native_handle_type GetNativeHandle()
{
#if defined(PANDA_TARGET_UNIX)
return pthread_self();
#else
#error "Unsupported platform"
#endif
}
void Yield()
{
#if defined(PANDA_TARGET_UNIX)
std::this_thread::yield();
#else
#error "Unsupported platform"
#endif
}
void NativeSleep(unsigned int ms)
{
#if defined(PANDA_TARGET_UNIX)
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
#else
#error "Unsupported platform"
#endif
}
void ThreadDetach(native_handle_type pthread_id)
{
#if defined(PANDA_TARGET_UNIX)
pthread_detach(pthread_id);
#else
#error "Unsupported platform"
#endif
}
void ThreadExit(void *retval)
{
#if defined(PANDA_TARGET_UNIX)
pthread_exit(retval);
#else
#error "Unsupported platform"
#endif
}
void ThreadJoin(native_handle_type pthread_id, void **retval)
{
#if defined(PANDA_TARGET_UNIX)
pthread_join(pthread_id, retval);
#else
#error "Unsupported platform"
#endif
}
} // namespace panda::os::thread
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include "time.h" // NOLINTNEXTLINE(modernize-deprecated-headers, hicpp-deprecated-headers)
#ifndef PANDA_LIBPANDABASE_OS_UNIX_TIME_H_
#define PANDA_LIBPANDABASE_OS_UNIX_TIME_H_
#include <chrono>
namespace panda::os::unix::time {
namespace panda::os::time {
template <class T>
static uint64_t GetClockTime(clockid_t clock)
{
@@ -28,29 +29,6 @@ static uint64_t GetClockTime(clockid_t clock)
}
return 0;
}
} // namespace panda::os::time
/**
* Return current time in nanoseconds
*/
uint64_t GetClockTimeInMicro()
{
return GetClockTime<std::chrono::microseconds>(CLOCK_MONOTONIC);
}
/**
* Return current time in milliseconds
*/
uint64_t GetClockTimeInMilli()
{
return GetClockTime<std::chrono::milliseconds>(CLOCK_MONOTONIC);
}
/**
* Return thread CPU time in nanoseconds
*/
uint64_t GetClockTimeInThreadCpuTime()
{
return GetClockTime<std::chrono::nanoseconds>(CLOCK_THREAD_CPUTIME_ID);
}
} // namespace panda::os::unix::time
#endif // PANDA_LIBPANDABASE_OS_UNIX_TIME_H_
+3 -69
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -16,79 +16,13 @@
#ifndef PANDA_LIBPANDABASE_OS_UNIX_UNIQUE_FD_H_
#define PANDA_LIBPANDABASE_OS_UNIX_UNIQUE_FD_H_
#include <unistd.h>
#include <fcntl.h>
#include "utils/logger.h"
#include "os/unix/failure_retry.h"
namespace panda::os::unix {
class UniqueFd {
public:
explicit UniqueFd(int fd = -1) noexcept
{
Reset(fd);
}
UniqueFd(const UniqueFd &other_fd) = delete;
UniqueFd &operator=(const UniqueFd &other_fd) = delete;
UniqueFd(UniqueFd &&other_fd) noexcept
{
Reset(other_fd.Release());
}
UniqueFd &operator=(UniqueFd &&other_fd) noexcept
{
Reset(other_fd.Release());
return *this;
}
~UniqueFd()
{
Reset();
}
int Release() noexcept
{
int fd = fd_;
fd_ = -1;
return fd;
}
void Reset(int new_fd = -1)
{
if (fd_ != -1) {
ASSERT(new_fd != fd_);
DefaultCloser(fd_);
}
fd_ = new_fd;
}
int Get() const noexcept
{
return fd_;
}
bool IsValid() const noexcept
{
return fd_ != -1;
}
private:
static void DefaultCloser(int fd)
{
LOG_IF(PANDA_FAILURE_RETRY(::close(fd)) != 0, FATAL, COMMON) << "Incorrect fd: " << fd;
}
int fd_ = -1;
};
namespace panda::os::unique_fd {
inline int DupCloexec(int fd)
{
return fcntl(fd, F_DUPFD_CLOEXEC, 0);
}
} // namespace panda::os::unix
} // namespace panda::os::unique_fd
#endif // PANDA_LIBPANDABASE_OS_UNIX_UNIQUE_FD_H_
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "os/library_loader.h"
#include <windows.h>
namespace panda::os::library_loader {
Expected<LibraryHandle, Error> Load(std::string_view filename)
{
HMODULE module = LoadLibrary(filename.data());
void *handle = reinterpret_cast<void *>(module);
if (handle != nullptr) {
return LibraryHandle(handle);
}
return Unexpected(Error(std::string("Failed to load library ") + filename.data() + std::string(", error code ") +
std::to_string(GetLastError())));
}
Expected<void *, Error> ResolveSymbol(const LibraryHandle &handle, std::string_view name)
{
HMODULE module = reinterpret_cast<HMODULE>(handle.GetNativeHandle());
void *p = reinterpret_cast<void *>(GetProcAddress(module, name.data()));
if (p != nullptr) {
return p;
}
return Unexpected(Error(std::string("Failed to resolve symbol ") + name.data() + std::string(", error code ") +
std::to_string(GetLastError())));
}
} // namespace panda::os::library_loader
namespace panda::os::windows::library_loader {
LibraryHandle::~LibraryHandle()
{
if (handle_ != nullptr) {
FreeLibrary(reinterpret_cast<HMODULE>(handle_));
}
}
} // namespace panda::os::windows::library_loader
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_WINDOWS_LIBRARY_LOADER_H_
#define PANDA_LIBPANDABASE_OS_WINDOWS_LIBRARY_LOADER_H_
#include "macros.h"
namespace panda::os::windows::library_loader {
class LibraryHandle {
public:
explicit LibraryHandle(void *handle) : handle_(handle) {}
LibraryHandle(LibraryHandle &&handle) noexcept
{
handle_ = handle.handle_;
handle.handle_ = nullptr;
}
LibraryHandle &operator=(LibraryHandle &&handle) noexcept
{
handle_ = handle.handle_;
handle.handle_ = nullptr;
return *this;
}
bool IsValid() const
{
return handle_ != nullptr;
}
void *GetNativeHandle() const
{
return handle_;
}
~LibraryHandle();
private:
void *handle_;
NO_COPY_SEMANTIC(LibraryHandle);
};
} // namespace panda::os::windows::library_loader
namespace panda::os::library_loader {
using LibraryHandle = panda::os::windows::library_loader::LibraryHandle;
} // namespace panda::os::library_loader
#endif // PANDA_LIBPANDABASE_OS_WINDOWS_LIBRARY_LOADER_H_
+71 -13
View File
@@ -14,7 +14,6 @@
*/
#include "os/mem.h"
#include "windows_mem.h"
#include "utils/type_helpers.h"
#include "utils/asan_interface.h"
@@ -24,6 +23,7 @@
#include <errno.h>
#include <io.h>
#include <sysinfoapi.h>
#include <type_traits>
#define MAP_FAILED (reinterpret_cast<void *>(-1))
@@ -51,7 +51,7 @@ static DWORD mem_protection_flags_for_page(const int prot)
return flags;
}
static DWORD mem_protection_flags_for_file(const int prot)
static DWORD mem_protection_flags_for_file(const int prot, const uint32_t map_flags)
{
DWORD flags = 0;
@@ -59,6 +59,15 @@ static DWORD mem_protection_flags_for_file(const int prot)
return flags;
}
/* Notice that only single FILE_MAP_COPY flag can ensure a copy-on-write mapping which
* MMAP_FLAG_PRIVATE needs. It can't be bitwise OR'ed with FILE_MAP_ALL_ACCESS, FILE_MAP_READ
* or FILE_MAP_WRITE. Or else it will be converted to PAGE_READONLY or PAGE_READWRITE, and make
* the changes synced back to the original file.
*/
if ((map_flags & MMAP_FLAG_PRIVATE) != 0) {
return FILE_MAP_COPY;
}
if ((static_cast<unsigned>(prot) & MMAP_PROT_READ) != 0) {
flags |= FILE_MAP_READ;
}
@@ -115,7 +124,7 @@ void *mmap([[maybe_unused]] void *addr, size_t len, int prot, uint32_t flags, in
return MAP_FAILED;
}
const auto prot_file = mem_protection_flags_for_file(prot);
const auto prot_file = mem_protection_flags_for_file(prot, flags);
const auto file_off_low = mem_select_lower_bound(off);
const auto file_off_high = mem_select_upper_bound(off);
void *map = MapViewOfFile(fm, prot_file, file_off_high, file_off_low, len);
@@ -158,6 +167,46 @@ BytePtr MapFile(file::File file, uint32_t prot, uint32_t flags, size_t size, siz
return BytePtr(static_cast<std::byte *>(result) + offset, size, MmapDeleter);
}
BytePtr MapExecuted(size_t size)
{
// By design caller should pass valid size, so don't do any additional checks except ones that
// mmap do itself
// NOLINTNEXTLINE(hicpp-signed-bitwise)
void *result = mmap(nullptr, size, MMAP_PROT_EXEC | MMAP_PROT_WRITE, MMAP_FLAG_SHARED | MMAP_FLAG_ANONYMOUS, -1, 0);
if (result == reinterpret_cast<void *>(-1)) {
result = nullptr;
}
return BytePtr(static_cast<std::byte *>(result), (result == nullptr) ? 0 : size, MmapDeleter);
}
std::optional<Error> MakeMemWithProtFlag(void *mem, size_t size, int prot)
{
PDWORD old = nullptr;
int r = VirtualProtect(mem, size, prot, old);
if (r != 0) {
return Error(GetLastError());
}
return {};
}
std::optional<Error> MakeMemReadExec(void *mem, size_t size)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
return MakeMemWithProtFlag(mem, size, MMAP_PROT_EXEC | MMAP_PROT_READ);
}
std::optional<Error> MakeMemReadWrite(void *mem, size_t size)
{
// NOLINTNEXTLINE(hicpp-signed-bitwise)
return MakeMemWithProtFlag(mem, size, MMAP_PROT_WRITE | MMAP_PROT_READ);
}
std::optional<Error> MakeMemReadOnly(void *mem, size_t size)
{
return MakeMemWithProtFlag(mem, size, MMAP_PROT_READ);
}
uint32_t GetPageSize()
{
constexpr size_t PAGE_SIZE = 4096;
@@ -194,19 +243,18 @@ void *MapRWAnonymousWithAlignmentRaw(size_t size, size_t aligment_in_bytes, bool
uintptr_t aligned_mem = (allocated_mem & ~(aligment_in_bytes - 1U)) +
((allocated_mem % aligment_in_bytes) != 0U ? aligment_in_bytes : 0U);
ASSERT(aligned_mem >= allocated_mem);
size_t unused_in_start = aligned_mem - allocated_mem;
ASSERT(unused_in_start <= aligment_in_bytes);
size_t unused_in_end = aligment_in_bytes - unused_in_start;
if (unused_in_start != 0) {
UnmapRaw(result, unused_in_start);
}
if (unused_in_end != 0) {
auto end_part = reinterpret_cast<void *>(aligned_mem + size);
UnmapRaw(end_part, unused_in_end);
}
return reinterpret_cast<void *>(aligned_mem);
}
uintptr_t AlignDownToPageSize(uintptr_t addr)
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
const size_t SYS_PAGE_SIZE = sysInfo.dwPageSize;
addr &= ~(SYS_PAGE_SIZE - 1);
return addr;
}
void *AlignedAlloc(size_t alignment_in_bytes, size_t size)
{
size_t aligned_size = (size + alignment_in_bytes - 1) & ~(alignment_in_bytes - 1);
@@ -217,6 +265,11 @@ void *AlignedAlloc(size_t alignment_in_bytes, size_t size)
return ret;
}
void AlignedFree(void *mem)
{
_aligned_free(mem);
}
std::optional<Error> UnmapRaw(void *mem, size_t size)
{
ASAN_UNPOISON_MEMORY_REGION(mem, size);
@@ -234,4 +287,9 @@ std::optional<Error> TagAnonymousMemory([[maybe_unused]] const void *mem, [[mayb
return {};
}
size_t GetNativeBytesFromMallinfo()
{
return DEFAULT_NATIVE_BYTES_FROM_MALLINFO;
}
} // namespace panda::os::mem
+113
View File
@@ -0,0 +1,113 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "os/mem_hooks.h"
#include <iostream>
#include <iomanip>
namespace panda::os::windows::mem_hooks {
volatile bool enable = false;
static bool first = true;
static const char *GetAllocTypeName(int at)
{
switch (at) {
case _HOOK_ALLOC:
return "_HOOK_ALLOC";
case _HOOK_REALLOC:
return "_HOOK_REALLOC";
case _HOOK_FREE:
return "_HOOK_FREE";
default:
return "unknown AllocType";
}
}
static const char *GetBlockTypeName(int bt)
{
switch (bt) {
case _CRT_BLOCK:
return "_CRT_BLOCK";
case _NORMAL_BLOCK:
return "_NORMAL_BLOCK";
case _FREE_BLOCK:
return "_FREE_BLOCK";
default:
return "unknown BlockType";
}
}
int PandaHooks::PandaAllocHook(int alloctype, [[maybe_unused]] void *data, std::size_t size, int blocktype,
[[maybe_unused]] long request, const unsigned char *filename, int linenumber)
{
if (!enable) {
return true;
}
/* Ignoring internal allocations made by C run-time library functions,
* or else it may trap the program in an endless loop.
*/
if (blocktype == _CRT_BLOCK) {
return true;
}
constexpr int ALIGN_SIZE = 32;
if (first) {
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << "alloc type";
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << "block type";
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << "size";
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << "filename";
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << "linenumber" << std::endl;
first = false;
}
const char* alloctype_name = GetAllocTypeName(alloctype);
const char* blocktype_name = GetBlockTypeName(blocktype);
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << alloctype_name;
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << blocktype_name;
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << (int)size;
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << filename;
std::cout << std::left << std::setfill(' ') << std::setw(ALIGN_SIZE) << linenumber << std::endl;
return true;
}
/* static */
void PandaHooks::Enable()
{
enable = true;
_CrtSetAllocHook(PandaAllocHook);
_CrtMemCheckpoint(&begin);
_CrtMemDumpAllObjectsSince(&begin);
}
/* static */
void PandaHooks::Disable()
{
enable = false;
_CrtMemCheckpoint(&end);
_CrtMemDumpAllObjectsSince(&end);
if (_CrtMemDifference(&out, &begin, &end)) {
std::cerr << "Memory leak detected:" << std::endl;
_CrtDumpMemoryLeaks();
}
}
} // namespace panda::os::windows::mem_hooks
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_WINDOWS_MEM_HOOKS_H_
#define PANDA_LIBPANDABASE_OS_WINDOWS_MEM_HOOKS_H_
#include <crtdbg.h>
#include <iostream>
namespace panda::os::windows::mem_hooks {
class PandaHooks {
public:
static void Enable();
static void Disable();
private:
/*
* "PandaAllocHook" is an allocation hook function, following a prototype described in
* https://docs.microsoft.com/en-us/visualstudio/debugger/allocation-hook-functions.
* Installed it using "_CrtSetAllocHook", then it will be called every time memory is
* allocated, reallocated, or freed.
*/
static int PandaAllocHook(int alloctype, void *data, std::size_t size, int blocktype, long request,
const unsigned char *filename, int linenumber);
static _CrtMemState begin, end, out;
};
} // namespace panda::os::windows::mem_hooks
namespace panda::os::mem_hooks {
using PandaHooks = panda::os::windows::mem_hooks::PandaHooks;
} // namespace panda::os::mem_hooks
#endif // PANDA_LIBPANDABASE_OS_WINDOWS_MEM_HOOKS_H_
+32
View File
@@ -16,6 +16,7 @@
#include "os/thread.h"
#include <thread>
#include <processthreadsapi.h>
namespace panda::os::thread {
@@ -24,4 +25,35 @@ ThreadId GetCurrentThreadId()
return static_cast<ThreadId>(std::hash<std::thread::id>()(std::this_thread::get_id()));
}
int SetPriority([[maybe_unused]] int thread_id, int prio)
{
return SetThreadPriority(GetCurrentThread(), prio);
}
int GetPriority([[maybe_unused]] int thread_id)
{
return GetThreadPriority(GetCurrentThread());
}
int SetThreadName([[maybe_unused]] native_handle_type pthread_id, const char *name)
{
ASSERT(pthread_id != 0);
return pthread_setname_np(pthread_self(), name);
}
void Yield()
{
std::this_thread::yield();
}
void NativeSleep(unsigned int ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
void ThreadJoin(native_handle_type pthread_id, void **retval)
{
pthread_join(reinterpret_cast<pthread_t>(pthread_id), retval);
}
} // namespace panda::os::thread
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_
#define PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_
#include <chrono>
#include <sys/time.h>
namespace panda::os::time {
template <class T>
static uint64_t GetClockTime([[maybe_unused]] clockid_t clock)
{
struct timeval time = {0, 0};
if (gettimeofday(&time, nullptr) != -1) {
auto duration = std::chrono::seconds {time.tv_sec} + std::chrono::microseconds {time.tv_usec};
return std::chrono::duration_cast<T>(duration).count();
}
return 0;
}
} // namespace panda::os::time
#endif // PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -13,27 +13,17 @@
* limitations under the License.
*/
#ifndef PANDA_LIBPANDABASE_OS_UNIX_TIME_UNIX_H_
#define PANDA_LIBPANDABASE_OS_UNIX_TIME_UNIX_H_
#ifndef PANDA_LIBPANDABASE_OS_WINDOWS_UNIQUE_FD_H_
#define PANDA_LIBPANDABASE_OS_WINDOWS_UNIQUE_FD_H_
#include <cstdint>
#include "libpandabase/macros.h"
namespace panda::os::unix::time {
namespace panda::os::unique_fd {
inline int DupCloexec([[maybe_unused]] int fd)
{
// Unsupported on windows platform
UNREACHABLE();
}
} // namespace panda::os::unique_fd
/**
* Return current time in nanoseconds
*/
uint64_t GetClockTimeInMicro();
/**
* Return current time in milliseconds
*/
uint64_t GetClockTimeInMilli();
/**
* Thread Cpu Time in nanoseconds
*/
uint64_t GetClockTimeInThreadCpuTime();
} // namespace panda::os::unix::time
#endif // PANDA_LIBPANDABASE_OS_UNIX_TIME_UNIX_H_
#endif // PANDA_LIBPANDABASE_OS_WINDOWS_UNIQUE_FD_H_
+5
View File
@@ -23,10 +23,15 @@ static constexpr uint32_t MMAP_PROT_READ = 1;
static constexpr uint32_t MMAP_PROT_WRITE = 2;
static constexpr uint32_t MMAP_PROT_EXEC = 4;
static constexpr uint32_t MMAP_FLAG_SHARED = 1;
static constexpr uint32_t MMAP_FLAG_PRIVATE = 2;
static constexpr uint32_t MMAP_FLAG_FIXED = 0x10;
static constexpr uint32_t MMAP_FLAG_ANONYMOUS = 0x20;
void *mmap([[maybe_unused]] void *addr, size_t len, int prot, uint32_t flags, int fildes, off_t off);
int munmap(void *addr, [[maybe_unused]] size_t len);
} // namespace panda::os::mem
#endif // PANDA_LIBPANDABASE_OS_WINDOWS_WINDOWS_MEM_H_
+42 -34
View File
@@ -22,6 +22,43 @@
namespace panda::test {
void MapDfxOption(std::map<DfxOptionHandler::DfxOption, uint8_t> &option_map, DfxOptionHandler::DfxOption option)
{
switch (option) {
#ifdef PANDA_TARGET_UNIX
case DfxOptionHandler::COMPILER_NULLCHECK:
option_map[DfxOptionHandler::COMPILER_NULLCHECK] = 1;
break;
case DfxOptionHandler::SIGNAL_CATCHER:
option_map[DfxOptionHandler::SIGNAL_CATCHER] = 1;
break;
case DfxOptionHandler::SIGNAL_HANDLER:
option_map[DfxOptionHandler::SIGNAL_HANDLER] = 1;
break;
case DfxOptionHandler::ARK_SIGQUIT:
option_map[DfxOptionHandler::ARK_SIGQUIT] = 1;
break;
case DfxOptionHandler::ARK_SIGUSR1:
option_map[DfxOptionHandler::ARK_SIGUSR1] = 1;
break;
case DfxOptionHandler::ARK_SIGUSR2:
option_map[DfxOptionHandler::ARK_SIGUSR2] = 1;
break;
case DfxOptionHandler::MOBILE_LOG:
option_map[DfxOptionHandler::MOBILE_LOG] = 1;
break;
#endif // PANDA_TARGET_UNIX
case DfxOptionHandler::REFERENCE_DUMP:
option_map[DfxOptionHandler::REFERENCE_DUMP] = 1;
break;
case DfxOptionHandler::DFXLOG:
option_map[DfxOptionHandler::DFXLOG] = 0;
break;
default:
break;
}
}
TEST(DfxController, Initialization)
{
if (DfxController::IsInitialized()) {
@@ -37,38 +74,8 @@ TEST(DfxController, Initialization)
std::map<DfxOptionHandler::DfxOption, uint8_t> option_map;
for (auto option = DfxOptionHandler::DfxOption(0); option < DfxOptionHandler::END_FLAG;
option = DfxOptionHandler::DfxOption(option + 1)) {
switch (option) {
case DfxOptionHandler::COMPILER_NULLCHECK:
option_map[DfxOptionHandler::COMPILER_NULLCHECK] = 1;
break;
case DfxOptionHandler::REFERENCE_DUMP:
option_map[DfxOptionHandler::REFERENCE_DUMP] = 1;
break;
case DfxOptionHandler::SIGNAL_CATCHER:
option_map[DfxOptionHandler::SIGNAL_CATCHER] = 1;
break;
case DfxOptionHandler::SIGNAL_HANDLER:
option_map[DfxOptionHandler::SIGNAL_HANDLER] = 1;
break;
case DfxOptionHandler::ARK_SIGQUIT:
option_map[DfxOptionHandler::ARK_SIGQUIT] = 1;
break;
case DfxOptionHandler::ARK_SIGUSR1:
option_map[DfxOptionHandler::ARK_SIGUSR1] = 1;
break;
case DfxOptionHandler::ARK_SIGUSR2:
option_map[DfxOptionHandler::ARK_SIGUSR2] = 1;
break;
case DfxOptionHandler::MOBILE_LOG:
option_map[DfxOptionHandler::MOBILE_LOG] = 1;
break;
case DfxOptionHandler::DFXLOG:
option_map[DfxOptionHandler::DFXLOG] = 0;
break;
default:
break;
}
option = DfxOptionHandler::DfxOption(option + 1)) {
MapDfxOption(option_map, option);
}
DfxController::Initialize(option_map);
@@ -117,17 +124,18 @@ TEST(DfxController, TestPrintDfxOptionValues)
#ifdef PANDA_TARGET_UNIX
std::string res = helpers::string::Format(
"[TID %06x] E/dfx: DFX option: compiler-nullcheck, option values: 1\n"
"[TID %06x] E/dfx: DFX option: reference-dump, option values: 1\n"
"[TID %06x] E/dfx: DFX option: signal-catcher, option values: 1\n"
"[TID %06x] E/dfx: DFX option: signal-handler, option values: 1\n"
"[TID %06x] E/dfx: DFX option: sigquit, option values: 1\n"
"[TID %06x] E/dfx: DFX option: sigusr1, option values: 1\n"
"[TID %06x] E/dfx: DFX option: sigusr2, option values: 1\n"
"[TID %06x] E/dfx: DFX option: mobile-log, option values: 1\n"
"[TID %06x] E/dfx: DFX option: reference-dump, option values: 1\n"
"[TID %06x] E/dfx: DFX option: dfx-log, option values: 0\n",
tid, tid, tid, tid, tid, tid, tid, tid, tid, tid);
#else
std::string res = helpers::string::Format("[TID %06x] E/dfx: DFX option: dfx-log, option values: 0\n", tid, tid);
std::string res = helpers::string::Format(
"[TID %06x] E/dfx: DFX option: dfx-log, option values: 0\n", tid, tid);
#endif
EXPECT_EQ(err, res);
+2 -2
View File
@@ -21,7 +21,6 @@
#include "mem/mem.h"
#include "os/mem.h"
#include "utils/asan_interface.h"
#include <sys/mman.h>
namespace panda {
@@ -120,7 +119,8 @@ void HashTest::EndOfPageStringHashTest() const
constexpr size_t ALLOC_SIZE = PAGE_SIZE * 2;
void *mem = panda::os::mem::MapRWAnonymousRaw(ALLOC_SIZE);
ASAN_UNPOISON_MEMORY_REGION(mem, ALLOC_SIZE);
mprotect(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(mem) + PAGE_SIZE), PAGE_SIZE, PROT_NONE);
panda::os::mem::MakeMemWithProtFlag(
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(mem) + PAGE_SIZE), PAGE_SIZE, PROT_NONE);
char *string =
reinterpret_cast<char *>((reinterpret_cast<uintptr_t>(mem) + PAGE_SIZE) - sizeof(char) * string_size);
string[0] = 'O';
+5 -5
View File
@@ -26,8 +26,8 @@ namespace panda::test::mem_range {
constexpr uintptr_t MAX_PTR = std::numeric_limits<uintptr_t>::max();
constexpr uint NUM_RANDOM_TESTS = 100;
constexpr uint NUM_ITER_PER_TEST = 1000;
constexpr uint64_t NUM_RANDOM_TESTS = 100;
constexpr uint64_t NUM_ITER_PER_TEST = 1000;
constexpr uintptr_t RANDOM_AREA_SIZE = 100000;
std::default_random_engine g_generator;
@@ -133,13 +133,13 @@ TEST(MemRangeTest, IntersectTest)
}
// function to conduct num_iter random tests with addresses in given bounds
static void randomTestInBounds(uintptr_t from, uintptr_t to, uint num_iter = NUM_ITER_PER_TEST)
static void randomTestInBounds(uintptr_t from, uintptr_t to, uint64_t num_iter = NUM_ITER_PER_TEST)
{
ASSERT(from < to);
panda::mem::MemRange mem_range_1(0, 1), mem_range_2(0, 1);
// check intersection via cycle
for (uint iter = 0; iter < num_iter; iter++) {
for (uint64_t iter = 0; iter < num_iter; iter++) {
mem_range_1 = randomMemRange(from, to);
mem_range_2 = randomMemRange(from, to);
@@ -196,7 +196,7 @@ TEST(MemRangeTest, RandomIntersectTest)
// tests in random ranges
uintptr_t position;
for (uint i = 0; i < NUM_RANDOM_TESTS; i++) {
for (uint64_t i = 0; i < NUM_RANDOM_TESTS; i++) {
position = random_uintptr();
if (position > RANDOM_AREA_SIZE) {
randomTestInBounds(position - RANDOM_AREA_SIZE, position);
+4 -5
View File
@@ -14,12 +14,11 @@
*/
#include "os/mem.h"
#include "mem/mem.h"
#include <sys/mman.h>
#include "utils/asan_interface.h"
#include "gtest/gtest.h"
namespace panda {
namespace panda::os::mem {
class MMapFixedTest : public testing::Test {
protected:
@@ -45,8 +44,8 @@ TEST_F(MMapFixedTest, MMapAsanTest)
uintptr_t end_addr = panda::os::mem::MMAP_FIXED_MAGIC_ADDR_FOR_ASAN;
end_addr = AlignUp(end_addr, sizeof(uint64_t));
void *result = // NOLINTNEXTLINE(hicpp-signed-bitwise)
mmap(ToVoidPtr(cur_addr), MMAP_ALLOC_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1,
0);
mmap(ToVoidPtr(cur_addr), MMAP_ALLOC_SIZE, MMAP_PROT_READ | MMAP_PROT_WRITE,
MMAP_FLAG_PRIVATE | MMAP_FLAG_ANONYMOUS | MMAP_FLAG_FIXED, -1, 0);
ASSERT_TRUE(result != nullptr);
ASSERT_TRUE(ToUintPtr(result) == cur_addr);
while (cur_addr < end_addr) {
@@ -63,4 +62,4 @@ TEST_F(MMapFixedTest, MMapAsanTest)
munmap(result, MMAP_ALLOC_SIZE);
}
} // namespace panda
} // namespace panda::os::mem
@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include "mem/mem.h"
#include <sys/mman.h>
#include "mem/mmap_mem_pool-inl.h"
#include "gtest/gtest.h"
+3 -3
View File
@@ -13,13 +13,13 @@
* limitations under the License.
*/
#include "os/unix/unique_fd.h"
#include "os/unique_fd.h"
#include <gtest/gtest.h>
#include <utility>
#include <unistd.h>
namespace panda::os::unix {
namespace panda::os::unique_fd {
enum testValue { DEFAULT_VALUE = -1, STDIN_VALUE, STDOUT_VALUE, STDERR_VALUE };
@@ -132,4 +132,4 @@ TEST(UniqueFd, Reset)
EXPECT_EQ(fd_d.Get(), dupDF.stferrValue);
}
} // namespace panda::os::unix
} // namespace panda::os::unique_fd
+3
View File
@@ -79,6 +79,9 @@ ohos_shared_library("libarkfile") {
relative_install_dir = "ark"
}
output_extension = "so"
if (is_mingw) {
output_extension = "dll"
}
subsystem_name = "ark"
part_name = "ark"
}
+26 -3
View File
@@ -26,9 +26,7 @@
#include "utils/span.h"
#include "zip_archive.h"
#include "trace/trace.h"
#if !PANDA_TARGET_WINDOWS
#include "securec.h"
#endif
#include <cerrno>
#include <cstring>
@@ -56,6 +54,30 @@ const std::array<uint8_t, File::MAGIC_SIZE> File::MAGIC {'P', 'A', 'N', 'D', 'A'
// NOLINTNEXTLINE(readability-identifier-naming, modernize-avoid-c-arrays)
const char *ANONMAPNAME_PERFIX = "panda-";
os::file::Mode GetMode(panda_file::File::OpenMode open_mode)
{
switch (open_mode) {
case File::READ_ONLY: {
return os::file::Mode::READONLY;
}
case File::READ_WRITE: {
#ifdef PANDA_TARGET_WINDOWS
return os::file::Mode::READWRITE;
#else
return os::file::Mode::READONLY;
#endif
}
case File::WRITE_ONLY: {
return os::file::Mode::WRITEONLY;
}
default: {
break;
}
}
UNREACHABLE();
}
static uint32_t GetProt(panda_file::File::OpenMode mode)
{
uint32_t prot = os::mem::MMAP_PROT_READ;
@@ -417,7 +439,8 @@ inline std::string VersionToString(const std::array<uint8_t, File::VERSION_SIZE>
std::unique_ptr<const File> File::Open(std::string_view filename, OpenMode open_mode)
{
trace::ScopedTrace scoped_trace("Open panda file " + std::string(filename));
os::file::File file = os::file::Open(filename, os::file::Mode::READONLY);
os::file::Mode mode = GetMode(open_mode);
os::file::File file = os::file::Open(filename, mode);
if (!file.IsValid()) {
PLOG(ERROR, PANDAFILE) << "Failed to open panda file '" << filename << "'";
+1 -1
View File
@@ -121,7 +121,7 @@ public:
uint32_t offset_ {0};
};
enum OpenMode { READ_ONLY, READ_WRITE };
enum OpenMode { READ_ONLY, READ_WRITE, WRITE_ONLY };
StringData GetStringData(EntityId id) const;
EntityId GetLiteralArraysId() const;
-2
View File
@@ -20,9 +20,7 @@
#include "utils/span.h"
#include "utils/type_helpers.h"
#include "utils/leb128.h"
#if !PANDA_TARGET_WINDOWS
#include "securec.h"
#endif
#include <cstdint>
#include <cerrno>
+28 -7
View File
@@ -77,8 +77,10 @@ public:
return panda::helpers::math::PowerOfTwoTableSlot(id.GetOffset(), CLASS_CACHE_SIZE);
}
inline Method *GetMethodFromCache(File::EntityId id) const
inline Method *GetMethodFromCache([[maybe_unused]] File::EntityId id) const
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
uint32_t index = GetMethodIndex(id);
auto *pair_ptr =
reinterpret_cast<std::atomic<MethodCachePair> *>(reinterpret_cast<uintptr_t>(&(method_cache_[index])));
@@ -87,11 +89,14 @@ public:
if (pair.id_ == id) {
return pair.ptr_;
}
#endif
return nullptr;
}
inline void SetMethodCache(File::EntityId id, Method *method)
inline void SetMethodCache([[maybe_unused]] File::EntityId id, [[maybe_unused]] Method *method)
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
MethodCachePair pair;
pair.id_ = id;
pair.ptr_ = method;
@@ -100,10 +105,13 @@ public:
reinterpret_cast<std::atomic<MethodCachePair> *>(reinterpret_cast<uintptr_t>(&(method_cache_[index])));
TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr);
pair_ptr->store(pair, std::memory_order_release);
#endif
}
inline Field *GetFieldFromCache(File::EntityId id) const
inline Field *GetFieldFromCache([[maybe_unused]] File::EntityId id) const
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
uint32_t index = GetFieldIndex(id);
auto *pair_ptr =
reinterpret_cast<std::atomic<FieldCachePair> *>(reinterpret_cast<uintptr_t>(&(field_cache_[index])));
@@ -112,11 +120,14 @@ public:
if (pair.id_ == id) {
return pair.ptr_;
}
#endif
return nullptr;
}
inline void SetFieldCache(File::EntityId id, Field *field)
inline void SetFieldCache([[maybe_unused]] File::EntityId id, [[maybe_unused]] Field *field)
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
uint32_t index = GetFieldIndex(id);
auto *pair_ptr =
reinterpret_cast<std::atomic<FieldCachePair> *>(reinterpret_cast<uintptr_t>(&(field_cache_[index])));
@@ -125,10 +136,13 @@ public:
pair.ptr_ = field;
TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr);
pair_ptr->store(pair, std::memory_order_release);
#endif
}
inline Class *GetClassFromCache(File::EntityId id) const
inline Class *GetClassFromCache([[maybe_unused]] File::EntityId id) const
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
uint32_t index = GetClassIndex(id);
auto *pair_ptr =
reinterpret_cast<std::atomic<ClassCachePair> *>(reinterpret_cast<uintptr_t>(&(class_cache_[index])));
@@ -137,11 +151,14 @@ public:
if (pair.id_ == id) {
return pair.ptr_;
}
#endif
return nullptr;
}
inline void SetClassCache(File::EntityId id, Class *clazz)
inline void SetClassCache([[maybe_unused]] File::EntityId id, [[maybe_unused]] Class *clazz)
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
ClassCachePair pair;
pair.id_ = id;
pair.ptr_ = clazz;
@@ -150,11 +167,14 @@ public:
reinterpret_cast<std::atomic<ClassCachePair> *>(reinterpret_cast<uintptr_t>(&(class_cache_[index])));
TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr);
pair_ptr->store(pair, std::memory_order_release);
#endif
}
template <class Callback>
bool EnumerateCachedClasses(const Callback &cb)
bool EnumerateCachedClasses([[maybe_unused]] const Callback &cb)
{
// The os platform macro should be removed when "atomic" symbol is provided in mingw(issue #154FCK)
#ifndef PANDA_TARGET_WINDOWS
for (uint32_t i = 0; i < CLASS_CACHE_SIZE; i++) {
auto *pair_ptr =
reinterpret_cast<std::atomic<ClassCachePair> *>(reinterpret_cast<uintptr_t>(&(class_cache_[i])));
@@ -166,6 +186,7 @@ public:
}
}
}
#endif
return true;
}
+3
View File
@@ -53,6 +53,9 @@ ohos_shared_library("libarkziparchive") {
relative_install_dir = "ark"
}
output_extension = "so"
if (is_mingw) {
output_extension = "dll"
}
subsystem_name = "ark"
part_name = "ark"
}
+10 -4
View File
@@ -76,7 +76,6 @@ ohos_static_library("libarkruntime_static") {
"class_linker_extension.cpp",
"coretypes/array.cpp",
"coretypes/string.cpp",
"dprofiler/dprofiler.cpp",
"dyn_class_linker_extension.cpp",
"entrypoints/entrypoints.cpp",
"exceptions.cpp",
@@ -118,7 +117,6 @@ ohos_static_library("libarkruntime_static") {
"mem/heap_manager.cpp",
"mem/heap_verifier.cpp",
"mem/internal_allocator.cpp",
"mem/mem_hooks.cpp",
"mem/mem_stats.cpp",
"mem/mem_stats_additional_info.cpp",
"mem/mem_stats_default.cpp",
@@ -141,7 +139,6 @@ ohos_static_library("libarkruntime_static") {
"panda_vm.cpp",
"runtime.cpp",
"runtime_helpers.cpp",
"signal_handler.cpp",
"stack_walker.cpp",
"string_table.cpp",
"thread.cpp",
@@ -157,6 +154,12 @@ ohos_static_library("libarkruntime_static") {
"tooling/pt_thread.cpp",
"vtable_builder.cpp",
]
if (!is_mingw) {
sources += [
"dprofiler/dprofiler.cpp",
"signal_handler.cpp",
]
}
if (current_cpu == "arm") {
sources += [
"arch/arm/interpreter_support.S",
@@ -228,7 +231,6 @@ ohos_static_library("libarkruntime_static") {
deps = [
":arkruntime_header_deps",
":arkruntime_interpreter_impl",
"$ark_root/dprof:libdprof",
"$ark_root/libpandabase:libarkbase",
"$ark_root/libpandafile:libarkfile",
"$ark_root/libpandafile:libarkfile_type_gen_h",
@@ -237,6 +239,10 @@ ohos_static_library("libarkruntime_static") {
sdk_libc_secshared_dep,
]
if (!is_mingw) {
deps += [ "$ark_root/dprof:libdprof" ]
}
if (is_standard_system) {
cflags_cc = [ "-fvisibility=hidden" ]
}
-1
View File
@@ -107,7 +107,6 @@ set(SOURCES
mem/mem_stats.cpp
mem/internal_allocator.cpp
mem/panda_string.cpp
mem/mem_hooks.cpp
mem/memory_manager.cpp
mark_word.cpp
method.cpp
+2
View File
@@ -13,7 +13,9 @@
* limitations under the License.
*/
#ifndef PANDA_TARGET_WINDOWS
.type ExecuteImplStub, @function
#endif
.global ExecuteImplStub
.balign 16
ExecuteImplStub:
+1 -1
View File
@@ -38,7 +38,7 @@ static_assert(FRAME_SLOT_OFFSET == 80U);
static_assert(FRAME_TAG_OFFSET == 88U);
#endif
extern "C" ManagedThread *GetCurrentThread()
extern "C" ManagedThread *GetCurrentManagedThread()
{
return ManagedThread::GetCurrent();
}
+7
View File
@@ -37,6 +37,13 @@
// clang-format off
#ifndef PANDA_TARGET_WINDOWS
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TYPE_FUNCTION(name) .type name, %function
#else
#define TYPE_FUNCTION(name)
#endif
#ifndef NDEBUG
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
@@ -30,7 +30,7 @@
.extern IncrementHotnessCounter
.global CompiledCodeToInterpreterBridge
.type CompiledCodeToInterpreterBridge, %function
TYPE_FUNCTION(CompiledCodeToInterpreterBridge)
CompiledCodeToInterpreterBridge:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -29,7 +29,7 @@
// CompiledCodeToInterpreterBridgeDyn(Method* method, uint32_t num_args, int64_t func_obj, int64_t func_tag, int64_t arg_i, int64_t tag_i, ...)
.global CompiledCodeToInterpreterBridgeDyn
.type CompiledCodeToInterpreterBridgeDyn, %function
TYPE_FUNCTION(CompiledCodeToInterpreterBridgeDyn)
CompiledCodeToInterpreterBridgeDyn:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -17,7 +17,7 @@
.macro ENTRYPOINT name, entry, paramsnum
.global \name
.type \name, %function
TYPE_FUNCTION(\name)
\name:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -65,7 +65,7 @@
#include "entrypoints_bridge_asm_macro.inl"
.global AbstractMethodStub
.type AbstractMethodStub, %function
TYPE_FUNCTION(AbstractMethodStub)
AbstractMethodStub:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -261,7 +261,7 @@
// void InterpreterToCompiledCodeBridge(const BytecodeInstruction* insn, const Frame *iframe, const Method *method, ManagedThread* thread)
.global InterpreterToCompiledCodeBridge
.type InterpreterToCompiledCodeBridge, %function
TYPE_FUNCTION(InterpreterToCompiledCodeBridge)
InterpreterToCompiledCodeBridge:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -450,7 +450,7 @@ InterpreterToCompiledCodeBridge:
// DecodedTaggedValue InvokeCompiledCodeWithArguments(const int64_t* args, const Frame *iframe, const Method *method, ManagedThread* thread)
.global InvokeCompiledCodeWithArgArray
.type InvokeCompiledCodeWithArgArray, %function
TYPE_FUNCTION(InvokeCompiledCodeWithArgArray)
InvokeCompiledCodeWithArgArray:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -21,7 +21,7 @@
// const Method*, %rdx
// ManagedThread* thread) %rcx
.global InterpreterToCompiledCodeBridgeDyn
.type InterpreterToCompiledCodeBridgeDyn, %function
TYPE_FUNCTION(InterpreterToCompiledCodeBridgeDyn)
InterpreterToCompiledCodeBridgeDyn:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
@@ -125,7 +125,7 @@ InterpreterToCompiledCodeBridgeDyn:
// const Method*, %rcx
// ManagedThread* thread) %r8
.global InvokeCompiledCodeWithArgArrayDyn
.type InvokeCompiledCodeWithArgArrayDyn, %function
TYPE_FUNCTION(InvokeCompiledCodeWithArgArrayDyn)
InvokeCompiledCodeWithArgArrayDyn:
CFI_STARTPROC
CFI_DEF_CFA(rsp, 8)
+8
View File
@@ -38,7 +38,15 @@ class RuntimeListener;
*/
class DProfiler final {
public:
#ifdef PANDA_TARGET_UNIX
DProfiler(std::string_view app_name, Runtime *runtime);
#else
DProfiler([[maybe_unused]] std::string_view app_name, [[maybe_unused]] Runtime *runtime)
{
// Unsupported on windows platform
UNREACHABLE();
}
#endif // PANDA_TARGET_UNIX
~DProfiler() = default;
/**
+7 -3
View File
@@ -24,7 +24,6 @@
#include "libpandabase/mem/arena_allocator.h"
#include "libpandabase/os/mutex.h"
#include "libpandabase/os/library_loader.h"
#include "libpandabase/utils/expected.h"
#include "libpandabase/utils/dfx.h"
#include "libpandafile/file_items.h"
@@ -34,7 +33,9 @@
#include "runtime/include/runtime_options.h"
#include "runtime/include/gc_task.h"
#include "runtime/include/tooling/debug_interface.h"
#ifndef PANDA_TARGET_WINDOWS
#include "runtime/signal_handler.h"
#endif
#include "runtime/mem/allocator_adapter.h"
#include "runtime/mem/gc/gc.h"
#include "runtime/mem/gc/gc_trigger.h"
@@ -43,6 +44,7 @@
#include "runtime/string_table.h"
#include "runtime/thread_manager.h"
#include "verification/verification_options.h"
#include "libpandabase/os/library_loader.h"
namespace panda {
@@ -307,12 +309,12 @@ public:
return is_stacktrace_;
}
#ifndef PANDA_TARGET_WINDOWS
SignalManager *GetSignalManager()
{
return signal_manager_;
}
Trace *CreateTrace(LanguageContext ctx, PandaUniquePtr<os::unix::file::File> trace_file, size_t buffer_size);
#endif
void SetPtLangExt(tooling::PtLangExt *pt_lang_ext);
@@ -377,7 +379,9 @@ private:
PandaVM *panda_vm_ = nullptr;
#ifndef PANDA_TARGET_WINDOWS
SignalManager *signal_manager_ {nullptr};
#endif
// Language context
static constexpr size_t LANG_EXTENSIONS_COUNT = static_cast<size_t>(panda_file::SourceLang::LAST) + 1;
-1
View File
@@ -58,7 +58,6 @@
#include "runtime/interpreter/vregister_iterator.h"
#include "runtime/jit/profiling_data.h"
#include "runtime/mem/vm_handle.h"
#include "runtime/object_accessor-impl.cpp"
#include "runtime/handle_base-inl.h"
// ALWAYS_INLINE is mandatory attribute for handlers. There are cases which will be failed without it.
+2 -11
View File
@@ -16,10 +16,7 @@
#ifndef PANDA_RUNTIME_MEM_GC_BITMAP_H_
#define PANDA_RUNTIME_MEM_GC_BITMAP_H_
// clash with mingw
#ifndef PANDA_TARGET_WINDOWS
#include <securec.h>
#endif
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -46,9 +43,7 @@ public:
void ClearAllBits()
{
#ifndef PANDA_TARGET_WINDOWS
(void)memset_s(bitmap_.Data(), bitmap_.SizeBytes(), 0, bitmap_.SizeBytes());
#endif
}
Span<BitmapWordType> GetBitMap()
@@ -242,13 +237,11 @@ protected:
void SetWords([[maybe_unused]] size_t word_begin, [[maybe_unused]] size_t word_end)
{
ASSERT(word_begin <= word_end);
#ifndef PANDA_TARGET_WINDOWS
if (UNLIKELY(word_begin == word_end)) {
return;
}
(void)memset_s(&bitmap_[word_begin], (word_end - word_begin) * sizeof(BitmapWordType),
~static_cast<unsigned char>(0), (word_end - word_begin) * sizeof(BitmapWordType));
#endif
}
/**
@@ -259,13 +252,11 @@ protected:
void ClearWords([[maybe_unused]] size_t word_begin, [[maybe_unused]] size_t word_end)
{
ASSERT(word_begin <= word_end);
#ifndef PANDA_TARGET_WINDOWS
if (UNLIKELY(word_begin == word_end)) {
return;
}
(void)memset_s(&bitmap_[word_begin], (word_end - word_begin) * sizeof(BitmapWordType),
static_cast<unsigned char>(0), (word_end - word_begin) * sizeof(BitmapWordType));
#endif
}
explicit Bitmap(BitmapWordType *bitmap, size_t bitsize)
@@ -299,7 +290,7 @@ private:
size_t GetBitIdxWithinWord(size_t bit_offset) const
{
CheckBitOffset(bit_offset);
constexpr auto BIT_INDEX_MASK = static_cast<size_t>((1UL << LOG_BITSPERWORD) - 1);
constexpr auto BIT_INDEX_MASK = static_cast<size_t>((1ULL << LOG_BITSPERWORD) - 1);
return bit_offset & BIT_INDEX_MASK;
}
@@ -310,7 +301,7 @@ private:
*/
BitmapWordType GetBitMask(size_t bit_offset) const
{
return 1UL << GetBitIdxWithinWord(bit_offset);
return 1ULL << GetBitIdxWithinWord(bit_offset);
}
/**
+2 -3
View File
@@ -47,8 +47,7 @@ void *MallocProxyAllocator<AllocConfigT>::Alloc(size_t size, Alignment align)
lock_.Lock();
}
size_t alignment_in_bytes = GetAlignmentInBytes(align);
size_t aligned_size = (size + alignment_in_bytes - 1) & ~(alignment_in_bytes - 1);
void *ret = aligned_alloc(alignment_in_bytes, aligned_size);
void *ret = os::mem::AlignedAlloc(alignment_in_bytes, size);
// NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon)
if constexpr (!DUMMY_ALLOC_CONFIG) {
ASSERT(allocated_memory_.find(ret) == allocated_memory_.end());
@@ -72,7 +71,7 @@ void MallocProxyAllocator<AllocConfigT>::Free(void *mem)
if constexpr (!DUMMY_ALLOC_CONFIG) {
lock_.Lock();
}
std::free(mem); // NOLINT(cppcoreguidelines-no-malloc)
os::mem::AlignedFree(mem);
// NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon)
if constexpr (!DUMMY_ALLOC_CONFIG) {
auto iterator = allocated_memory_.find(mem);
+1 -1
View File
@@ -120,7 +120,7 @@ private:
duration min_pause_ = duration(0);
duration max_pause_ = duration(0);
duration sum_pause_ = duration(0);
uint pause_count_ = 0;
uint64_t pause_count_ = 0;
// make groups of different parts of the VM (JIT, interpreter, etc)
std::atomic_uint64_t objects_allocated_ = 0;
+1 -1
View File
@@ -65,7 +65,7 @@ void MemStatsAdditionalInfo::RecordGCPhaseEnd()
os::memory::LockHolder lk(phase_lock_);
ASSERT(current_phase_ != GCPhase::GC_PHASE_LAST);
uint phase_index = ToIndex(current_phase_);
uint64_t phase_index = ToIndex(current_phase_);
duration phase_time = clock::now() - phase_start_time_;
if (phase_count_[phase_index] != 0) {
min_phase_time_[phase_index] = std::min(min_phase_time_[phase_index], phase_time);
+1 -1
View File
@@ -57,7 +57,7 @@ private:
std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> min_phase_time_ = {};
std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> max_phase_time_ = {};
std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> sum_phase_time_ = {};
std::array<uint, ToIndex(GCPhase::GC_PHASE_LAST)> phase_count_ = {};
std::array<uint64_t, ToIndex(GCPhase::GC_PHASE_LAST)> phase_count_ = {};
os::memory::Mutex phase_lock_;
};
+7 -11
View File
@@ -26,7 +26,7 @@
#include "libpandabase/events/events.h"
#include "libpandabase/mem/mem_config.h"
#include "libpandabase/mem/pool_manager.h"
#include "libpandabase/os/library_loader.h"
#include "libpandabase/os/mem_hooks.h"
#include "libpandabase/os/native_stack.h"
#include "libpandabase/os/thread.h"
#include "libpandabase/utils/arena_containers.h"
@@ -53,7 +53,6 @@
#include "runtime/mem/gc/stw-gc/stw-gc.h"
#include "runtime/mem/gc/crossing_map_singleton.h"
#include "runtime/mem/heap_manager.h"
#include "runtime/mem/mem_hooks.h"
#include "runtime/mem/memory_manager.h"
#include "runtime/mem/internal_allocator-inl.h"
#include "runtime/core/core_class_linker_extension.h"
@@ -407,14 +406,16 @@ Runtime::Runtime(const RuntimeOptions &options, mem::InternalAllocatorPtr intern
// CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER)
class_linker_ = new ClassLinker(internal_allocator_, std::move(extensions));
#ifndef PANDA_TARGET_WINDOWS
// CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER)
signal_manager_ = new SignalManager(internal_allocator_);
#endif
if (IsEnableMemoryHooks()) {
// libbfd (which is used to get debug info from elf files) does a lot of allocations.
// Don't track allocations in this case.
if (!options_.IsSafepointBacktrace()) {
mem::PandaHooks::Enable();
panda::os::mem_hooks::PandaHooks::Enable();
}
}
@@ -432,12 +433,14 @@ Runtime::~Runtime()
panda::verifier::debug::DebugContext::Destroy();
if (IsEnableMemoryHooks()) {
mem::PandaHooks::Disable();
panda::os::mem_hooks::PandaHooks::Disable();
}
trace::ScopedTrace scoped_trace("Delete state");
#ifndef PANDA_TARGET_WINDOWS
signal_manager_->DeleteHandlersArray();
delete signal_manager_;
#endif
delete class_linker_;
if (dprofiler_ != nullptr) {
internal_allocator_->Delete(dprofiler_);
@@ -1174,11 +1177,4 @@ bool Runtime::SaveProfileInfo() const
return save_profiling_info_;
}
Trace *Runtime::CreateTrace([[maybe_unused]] LanguageContext ctx,
[[maybe_unused]] PandaUniquePtr<os::unix::file::File> trace_file,
[[maybe_unused]] size_t buffer_size)
{
LOG(FATAL, RUNTIME) << "Method tracing isn't supported at the moment!";
return nullptr;
}
} // namespace panda
-3
View File
@@ -22,9 +22,6 @@
#include "include/panda_vm.h"
#include "include/thread.h"
#include "include/stack_walker.h"
#if defined(PANDA_TARGET_UNIX)
#include "libpandabase/os/unix/sighooklib/sighook.h"
#endif // PANDA_TARGET_UNIX
namespace panda {
+1
View File
@@ -22,6 +22,7 @@
#include <vector>
#include <libpandabase/macros.h>
#include "runtime/include/mem/panda_containers.h"
#include "libpandabase/os/sighook.h"
namespace panda {