symbol-processor/data/out.h

56 lines
1.2 KiB
C
Raw Normal View History

2024-07-14 09:03:18 +00:00
#pragma once
// Check Architecture
#ifndef __arm__
#error "Symbols Are ARM-Only"
#endif
// Headers
2024-07-17 07:47:32 +00:00
#include "{{ data }}/function.h"
2024-07-14 09:03:18 +00:00
#include <cstddef>
#include <string>
#include <vector>
#include <map>
#include <type_traits>
#include <cstring>
// Shortcuts
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
// Duplicate VTable
#define RTTI_SIZE 4
template <typename T>
T *dup_vtable(T *vtable) {
// Check
2024-07-17 07:47:32 +00:00
static_assert(std::is_constructible_v<T>, "Unable To Construct VTable");
2024-07-14 09:03:18 +00:00
// Get Size
2024-07-17 07:47:32 +00:00
const uchar *real_vtable = (uchar *) vtable;
2024-07-14 09:03:18 +00:00
real_vtable -= RTTI_SIZE;
2024-07-17 07:47:32 +00:00
const size_t real_vtable_size = sizeof(T) + RTTI_SIZE;
2024-07-14 09:03:18 +00:00
// Allocate
uchar *new_vtable = (uchar *) ::operator new(real_vtable_size);
// Copy
2024-07-17 07:47:32 +00:00
memcpy(new_vtable, real_vtable, real_vtable_size);
2024-07-14 09:03:18 +00:00
// Return
new_vtable += RTTI_SIZE;
return (T *) new_vtable;
}
2024-07-16 17:46:20 +00:00
#undef RTTI_SIZE
2024-07-14 09:03:18 +00:00
// Forward Declarations
{{ forwardDeclarations }}
// Extra Headers
{{ extraHeaders }}
// Warnings
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#pragma GCC diagnostic ignored "-Wshadow"
{{ main }}
// Cleanup Warnings
#pragma GCC diagnostic pop