20#define IMPLEMENTING_LOG_FORMAT_FUNCTIONS
22#include "pedigree/kernel/Log.h"
23#include "pedigree/kernel/TargetInfo.h"
24#include "pedigree/kernel/utilities/spooky/SpookyV2.h"
25#include "pedigree/kernel/utilities/utility.h"
30 return reinterpret_cast<void*
>(
reinterpret_cast<uintptr_t
>(p) &
31 ~
static_cast<uintptr_t
>(TargetInfo::getPageOffsetMask()));
34const char* SDirectoryName(
const char* path,
char* buf,
size_t buflen) {
35 const char* last_slash = StringReverseFind(path,
'/');
36 if (last_slash ==
nullptr) {
40 size_t dirlength = last_slash - path;
42 size_t copylen = min(buflen, dirlength);
43 StringCopyN(buf, path, copylen);
49const char* SBaseName(
const char* path,
char* buf,
size_t buflen) {
50 size_t len = StringLength(path);
52 const char* last_slash = StringReverseFind(path,
'/');
53 if (last_slash ==
nullptr) {
54 StringCopyN(buf, path, buflen);
63 size_t baselength = len - (last_slash - path);
64 size_t copylen = min(buflen, baselength);
65 StringCopyN(buf, last_slash + 1, copylen);
71const char* DirectoryName(
const char* path) {
72 size_t len = StringLength(path);
73 char* buf =
new char[len + 1];
74 const char* result = SDirectoryName(path, buf, len + 1);
81const char* BaseName(
const char* path) {
82 size_t len = StringLength(path);
83 char* buf =
new char[len + 1];
84 const char* result = SBaseName(path, buf, len + 1);
91uint8_t checksum(
const uint8_t* pMemory,
size_t sMemory) {
93 for (
size_t i = 0; i < sMemory; i++)
98uint16_t checksum16(
const uint16_t* pMemory,
size_t sMemory) {
99 uint16_t sum1 = 0, sum2 = 0;
100 const uint8_t*
mem =
reinterpret_cast<const uint8_t*
>(pMemory);
102 for (
size_t i = 0; i < sMemory; ++i) {
103 sum1 = (sum1 +
mem[i]) % 255;
104 sum2 = (sum2 + sum1) % 255;
107 return (sum2 << 8) | sum1;
110uint32_t checksum32(
const uint32_t* pMemory,
size_t sMemory) {
111 uint32_t sum1 = 0, sum2 = 0;
112 const uint16_t*
mem =
reinterpret_cast<const uint16_t*
>(pMemory);
114 for (
size_t i = 0; i < sMemory / 2; ++i) {
115 sum1 = (sum1 +
mem[i]) % 65535;
116 sum2 = (sum2 + sum1) % 65535;
119 return (sum2 << 16) | sum1;
122uint32_t checksum32_naive(
const uint32_t* pMemory,
size_t sMemory) {
123 uint32_t sum1 = 0, sum2 = 0;
124 const uint16_t*
mem =
reinterpret_cast<const uint16_t*
>(pMemory);
126 for (
size_t i = 0; i < sMemory / 2; ++i) {
127 sum1 = (sum1 +
mem[i]) % 65535;
128 sum2 = (sum2 + sum1) % 65535;
131 return (sum2 << 16) | sum1;
134uint32_t checksumPage(uintptr_t address) {
139uint32_t elfHash(
const char* buffer,
size_t length) {
140 uint32_t h = 0, g = 0;
141 for (
size_t i = 0; i < length; ++i) {
142 h = (h << 4) + buffer[i];
151uint32_t jenkinsHash(
const char* buffer,
size_t length) {
153 for (
size_t i = 0; i < length; ++i) {
165uint32_t spookyHash(
const char* buffer,
size_t length) {
168 return h.Hash32(buffer, length, 0);
171uint64_t spookyHash64(
const char* buffer,
size_t length) {
174 return h.Hash64(buffer, length, 0);
177void spookyHash128(
const char* buffer,
size_t length, uint64_t* h1, uint64_t* h2) {
180 h.Hash128(buffer, length, h1, h2);
183#define LOG_FORMAT_COMMON \
188 i = VStringFormat(buf, fmt, ap); \
190 if (i && (buf[i - 1] == '\n')) \
193int Debugf(
const char* fmt, ...) {
196 DEBUG_LOG(
"debugf: " << buf);
201int Noticef(
const char* fmt, ...) {
204 NOTICE(
"noticef: " << buf);
209int Warningf(
const char* fmt, ...) {
212 WARNING(
"warningf: " << buf);
217int Errorf(
const char* fmt, ...) {
220 ERROR(
"errorf: " << buf);
225int Fatalf(
const char* fmt, ...) {
228 FATAL(
"fatalf: " << buf);
static constexpr size_t getPageSize() noexcept
void * page_align(void *p)