Skip to content

Commit

Permalink
Add ubsan log dump support
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Sep 9, 2018
1 parent 892f0c1 commit 488e330
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Lilu/Headers/kern_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ extern proc_t kernproc;
* @param cond precondition
* @param str printf-like string
*/
#define SYSLOG_COND(cond, module, str, ...) \
do { \
if (cond) \
LLLog( "%s%10s" str "\n", xStringify(PRODUCT_NAME) ": ", module " @ ", ## __VA_ARGS__); \
#define SYSLOG_COND(cond, module, str, ...) \
do { \
if (cond) \
lilu_os_log( "%s%10s" str "\n", xStringify(PRODUCT_NAME) ": ", module " @ ", ## __VA_ARGS__); \
} while (0)

/**
Expand Down Expand Up @@ -240,7 +240,7 @@ extern proc_t kernproc;
*
* @param format formatted string
*/
EXPORT void LLLog(const char *format, ...);
EXPORT extern "C" void lilu_os_log(const char *format, ...);

/**
* Two-way substring search
Expand Down
5 changes: 3 additions & 2 deletions Lilu/PrivateHeaders/kern_ubsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@
#ifdef vprintf
#undef vprintf
#endif
void lilu_os_log(const char *format, ...);
#define vprintf(fmt, va) do { \
char buf[1024]; \
vsnprintf(buf, sizeof(buf), (fmt), (va)); \
if (buf[0] == 'U' && buf[1] == 'B' && buf[2] == 'S' && buf[3] == 'a' && buf[4] == 'n' && buf[5] == ':') \
IOLog("Lilu: ubsan @%s", &buf[6]); \
lilu_os_log("Lilu: ubsan @%s", &buf[6]); \
else \
IOLog("Lilu: ubsan @ %s", buf); \
lilu_os_log("Lilu: ubsan @ %s", buf); \
} while (0)

// Bit manipulation is not present (aside an ugly BIT macro in IOFireWire header)
Expand Down
16 changes: 8 additions & 8 deletions Lilu/Sources/kern_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
for (maybe = 0; maybe < sz; maybe++) {
if (lookup.c[i][maybe] == value) {
// We have a possible match
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "found a possible match for %lu of %llX\n", i, value);
DBGLOG("user", "found a possible match for %lu of %llX\n", i, value);
break;
}
}
} else {
if (lookup.c[i][maybe] != value) {
// We failed
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "failure not matching %lu of %llX to expected %llX\n", i, value, lookup.c[i][maybe]);
DBGLOG("user", "failure not matching %lu of %llX to expected %llX\n", i, value, lookup.c[i][maybe]);
maybe = sz;
} else {
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "found a possible match for %lu of %llX\n", i, value);
DBGLOG("user", "found a possible match for %lu of %llX\n", i, value);
}
}

Expand All @@ -132,7 +132,7 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
sz = ref->pageOffs.size();


DBGLOG_COND(ml_get_interrupts_enabled(), "user", "found what we are looking for %X %X %X %X %X %X %X %X\n", rpatch.find[0],
DBGLOG("user", "found what we are looking for %X %X %X %X %X %X %X %X\n", rpatch.find[0],
rpatch.size > 1 ? rpatch.find[1] : 0xff,
rpatch.size > 2 ? rpatch.find[2] : 0xff,
rpatch.size > 3 ? rpatch.find[3] : 0xff,
Expand All @@ -143,7 +143,7 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
);

if (sz > 0 && MachInfo::setKernelWriting(true, KernelPatcher::kernelWriteLock) == KERN_SUCCESS) {
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "obtained write permssions\n");
DBGLOG("user", "obtained write permssions\n");

for (size_t i = 0; i < sz; i++) {
uint8_t *patch = const_cast<uint8_t *>(ptr + ref->pageOffs[i]);
Expand All @@ -167,14 +167,14 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
}

if (MachInfo::setKernelWriting(false, KernelPatcher::kernelWriteLock) == KERN_SUCCESS) {
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "restored write permssions\n");
DBGLOG("user", "restored write permssions\n");
}
} else {
SYSLOG_COND(ml_get_interrupts_enabled(), "user", "failed to obtain write permssions for %lu\n", sz);
SYSLOG("user", "failed to obtain write permssions for %lu\n", sz);
}
}
} else {
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "failed to match a complete page with %lu\n", maybe);
DBGLOG("user", "failed to match a complete page with %lu\n", maybe);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions Lilu/Sources/kern_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
bool ADDPR(debugEnabled) = false;
uint32_t ADDPR(debugPrintDelay) = 0;

void LLLog(const char *format, ...) {
char tmp[2048];
void lilu_os_log(const char *format, ...) {
char tmp[1024];
tmp[0] = '\0';
va_list va;
va_start(va, format);
vsnprintf(tmp, sizeof(tmp), format, va);
va_end(va);

IOLog("%s", tmp);
if (ml_get_interrupts_enabled())
IOLog("%s", tmp);

#ifdef DEBUG
if (ADDPR(config).debugLock && ADDPR(config).debugBuffer) {
Expand All @@ -42,7 +44,7 @@ void LLLog(const char *format, ...) {
}
#endif

if (ADDPR(debugPrintDelay) > 0)
if (ml_get_interrupts_enabled() && ADDPR(debugPrintDelay) > 0)
IOSleep(ADDPR(debugPrintDelay));
}

Expand Down

0 comments on commit 488e330

Please sign in to comment.