#pragma once
#include <stddef.h>
#include <stdint.h>
#include <executorch/runtime/platform/compiler.h>
#include <executorch/runtime/platform/types.h>
#ifndef ET_INTERNAL_PLATFORM_WEAKNESS
#define ET_INTERNAL_PLATFORM_WEAKNESS
#endif
extern "C" {
typedef struct {
uint64_t numerator;
uint64_t denominator;
} et_tick_ratio_t;
void et_pal_init(void) ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_init_method = void (*)();
ET_NORETURN void et_pal_abort(void) ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_abort_method = void (*)();
et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS;
typedef et_timestamp_t (*et_pal_current_ticks_t)(void);
using pal_current_ticks_method = et_timestamp_t (*)();
et_tick_ratio_t et_pal_ticks_to_ns_multiplier(void)
ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_ticks_to_ns_multiplier_method = et_tick_ratio_t (*)();
typedef enum {
kDebug = 'D',
kInfo = 'I',
kError = 'E',
kFatal = 'F',
kUnknown = '?', } et_pal_log_level_t;
void et_pal_emit_log_message(
et_timestamp_t timestamp,
et_pal_log_level_t level,
const char* filename,
const char* function,
size_t line,
const char* message,
size_t length) ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_emit_log_message_method = void (*)(
et_timestamp_t timestamp,
et_pal_log_level_t level,
const char* filename,
const char* function,
size_t line,
const char* message,
size_t length);
void* et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_allocate_method = void* (*)(size_t size);
void et_pal_free(void* ptr) ET_INTERNAL_PLATFORM_WEAKNESS;
using pal_free_method = void (*)(void* ptr);
}
namespace executorch::runtime {
struct PalImpl {
static PalImpl create(
pal_emit_log_message_method emit_log_message,
const char* source_filename);
static PalImpl create(
pal_init_method init,
pal_abort_method abort,
pal_current_ticks_method current_ticks,
pal_ticks_to_ns_multiplier_method ticks_to_ns_multiplier,
pal_emit_log_message_method emit_log_message,
pal_allocate_method allocate,
pal_free_method free,
const char* source_filename);
pal_init_method init = nullptr;
pal_abort_method abort = nullptr;
pal_current_ticks_method current_ticks = nullptr;
pal_ticks_to_ns_multiplier_method ticks_to_ns_multiplier = nullptr;
pal_emit_log_message_method emit_log_message = nullptr;
pal_allocate_method allocate = nullptr;
pal_free_method free = nullptr;
const char* source_filename;
};
bool register_pal(PalImpl impl);
const PalImpl* get_pal_impl();
void pal_init();
ET_NORETURN void pal_abort();
et_timestamp_t pal_current_ticks();
et_tick_ratio_t pal_ticks_to_ns_multiplier();
void pal_emit_log_message(
et_timestamp_t timestamp,
et_pal_log_level_t level,
const char* filename,
const char* function,
size_t line,
const char* message,
size_t length);
void* pal_allocate(size_t size);
void pal_free(void* ptr);
}