20 #define IMPLEMENTING_LOG_FORMAT_FUNCTIONS 22 #include "pedigree/kernel/utilities/utility.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 25 #include "pedigree/kernel/utilities/spooky/SpookyV2.h" 30 return reinterpret_cast<void *
>(
31 reinterpret_cast<uintptr_t
>(p) &
35 const char *SDirectoryName(
const char *path,
char *buf,
size_t buflen)
37 const char *last_slash = StringReverseFind(path,
'/');
38 if (last_slash ==
nullptr)
43 size_t dirlength = last_slash - path;
45 size_t copylen = min(buflen, dirlength);
46 StringCopyN(buf, path, copylen);
52 const char *SBaseName(
const char *path,
char *buf,
size_t buflen)
54 size_t len = StringLength(path);
56 const char *last_slash = StringReverseFind(path,
'/');
57 if (last_slash ==
nullptr)
59 StringCopyN(buf, path, buflen);
69 size_t baselength = len - (last_slash - path);
70 size_t copylen = min(buflen, baselength);
71 StringCopyN(buf, last_slash + 1, copylen);
77 const char *DirectoryName(
const char *path)
79 size_t len = StringLength(path);
80 char *buf =
new char[len + 1];
81 const char *result = SDirectoryName(path, buf, len + 1);
89 const char *BaseName(
const char *path)
91 size_t len = StringLength(path);
92 char *buf =
new char[len + 1];
93 const char *result = SBaseName(path, buf, len + 1);
101 uint8_t checksum(
const uint8_t *pMemory,
size_t sMemory)
104 for (
size_t i = 0; i < sMemory; i++)
109 uint16_t checksum16(
const uint8_t *pMemory,
size_t sMemory)
111 uint16_t sum1 = 0, sum2 = 0;
113 for (
size_t i = 0; i < sMemory; ++i)
115 sum1 = (sum1 + pMemory[i]) % 255;
116 sum2 = (sum2 + sum1) % 255;
119 return (sum2 << 8) | sum1;
122 uint32_t checksum32(
const uint8_t *pMemory,
size_t sMemory)
124 uint32_t sum1 = 0, sum2 = 0;
125 const uint16_t *
mem =
reinterpret_cast<const uint16_t *
>(pMemory);
127 for (
size_t i = 0; i < sMemory / 2; ++i)
129 sum1 = (sum1 + mem[i]) % 65535;
130 sum2 = (sum2 + sum1) % 65535;
133 return (sum2 << 16) | sum1;
136 uint32_t checksum32_naive(
const uint8_t *pMemory,
size_t sMemory)
138 uint32_t sum1 = 0, sum2 = 0;
139 const uint16_t *
mem =
reinterpret_cast<const uint16_t *
>(pMemory);
141 for (
size_t i = 0; i < sMemory / 2; ++i)
143 sum1 = (sum1 + mem[i]) % 65535;
144 sum2 = (sum2 + sum1) % 65535;
147 return (sum2 << 16) | sum1;
150 uint32_t checksumPage(uintptr_t address)
154 reinterpret_cast<const uint8_t *>(address),
158 uint32_t elfHash(
const char *buffer,
size_t length)
160 uint32_t h = 0, g = 0;
161 for (
size_t i = 0; i < length; ++i)
163 h = (h << 4) + buffer[i];
172 uint32_t jenkinsHash(
const char *buffer,
size_t length)
175 for (
size_t i = 0; i < length; ++i)
188 uint32_t spookyHash(
const char *buffer,
size_t length)
192 return h.Hash32(buffer, length, 0);
195 uint64_t spookyHash64(
const char *buffer,
size_t length)
199 return h.Hash64(buffer, length, 0);
202 void spookyHash128(
const char *buffer,
size_t length, uint64_t *h1, uint64_t *h2)
206 h.Hash128(buffer, length, h1, h2);
209 #define LOG_FORMAT_COMMON \ 214 i = VStringFormat(buf, fmt, ap); \ 216 if (i && (buf[i - 1] == '\n')) \ 219 int Debugf(
const char *fmt, ...)
228 int Noticef(
const char *fmt, ...)
232 NOTICE(
"noticef: " << buf);
237 int Warningf(
const char *fmt, ...)
246 int Errorf(
const char *fmt, ...)
250 ERROR(
"errorf: " << buf);
255 int Fatalf(
const char *fmt, ...)
259 FATAL(
"fatalf: " << buf);
static size_t getPageSize() PURE
void * page_align(void *p)