Skip to content

Commit 488e330

Browse files
committed
Add ubsan log dump support
1 parent 892f0c1 commit 488e330

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

Lilu/Headers/kern_util.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ extern proc_t kernproc;
7272
* @param cond precondition
7373
* @param str printf-like string
7474
*/
75-
#define SYSLOG_COND(cond, module, str, ...) \
76-
do { \
77-
if (cond) \
78-
LLLog( "%s%10s" str "\n", xStringify(PRODUCT_NAME) ": ", module " @ ", ## __VA_ARGS__); \
75+
#define SYSLOG_COND(cond, module, str, ...) \
76+
do { \
77+
if (cond) \
78+
lilu_os_log( "%s%10s" str "\n", xStringify(PRODUCT_NAME) ": ", module " @ ", ## __VA_ARGS__); \
7979
} while (0)
8080

8181
/**
@@ -240,7 +240,7 @@ extern proc_t kernproc;
240240
*
241241
* @param format formatted string
242242
*/
243-
EXPORT void LLLog(const char *format, ...);
243+
EXPORT extern "C" void lilu_os_log(const char *format, ...);
244244

245245
/**
246246
* Two-way substring search

Lilu/PrivateHeaders/kern_ubsan.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@
5353
#ifdef vprintf
5454
#undef vprintf
5555
#endif
56+
void lilu_os_log(const char *format, ...);
5657
#define vprintf(fmt, va) do { \
5758
char buf[1024]; \
5859
vsnprintf(buf, sizeof(buf), (fmt), (va)); \
5960
if (buf[0] == 'U' && buf[1] == 'B' && buf[2] == 'S' && buf[3] == 'a' && buf[4] == 'n' && buf[5] == ':') \
60-
IOLog("Lilu: ubsan @%s", &buf[6]); \
61+
lilu_os_log("Lilu: ubsan @%s", &buf[6]); \
6162
else \
62-
IOLog("Lilu: ubsan @ %s", buf); \
63+
lilu_os_log("Lilu: ubsan @ %s", buf); \
6364
} while (0)
6465

6566
// Bit manipulation is not present (aside an ugly BIT macro in IOFireWire header)

Lilu/Sources/kern_user.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
104104
for (maybe = 0; maybe < sz; maybe++) {
105105
if (lookup.c[i][maybe] == value) {
106106
// We have a possible match
107-
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "found a possible match for %lu of %llX\n", i, value);
107+
DBGLOG("user", "found a possible match for %lu of %llX\n", i, value);
108108
break;
109109
}
110110
}
111111
} else {
112112
if (lookup.c[i][maybe] != value) {
113113
// We failed
114-
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "failure not matching %lu of %llX to expected %llX\n", i, value, lookup.c[i][maybe]);
114+
DBGLOG("user", "failure not matching %lu of %llX to expected %llX\n", i, value, lookup.c[i][maybe]);
115115
maybe = sz;
116116
} else {
117-
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "found a possible match for %lu of %llX\n", i, value);
117+
DBGLOG("user", "found a possible match for %lu of %llX\n", i, value);
118118
}
119119
}
120120

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

134134

135-
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],
135+
DBGLOG("user", "found what we are looking for %X %X %X %X %X %X %X %X\n", rpatch.find[0],
136136
rpatch.size > 1 ? rpatch.find[1] : 0xff,
137137
rpatch.size > 2 ? rpatch.find[2] : 0xff,
138138
rpatch.size > 3 ? rpatch.find[3] : 0xff,
@@ -143,7 +143,7 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) {
143143
);
144144

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

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

169169
if (MachInfo::setKernelWriting(false, KernelPatcher::kernelWriteLock) == KERN_SUCCESS) {
170-
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "restored write permssions\n");
170+
DBGLOG("user", "restored write permssions\n");
171171
}
172172
} else {
173-
SYSLOG_COND(ml_get_interrupts_enabled(), "user", "failed to obtain write permssions for %lu\n", sz);
173+
SYSLOG("user", "failed to obtain write permssions for %lu\n", sz);
174174
}
175175
}
176176
} else {
177-
DBGLOG_COND(ml_get_interrupts_enabled(), "user", "failed to match a complete page with %lu\n", maybe);
177+
DBGLOG("user", "failed to match a complete page with %lu\n", maybe);
178178
}
179179
}
180180
}

Lilu/Sources/kern_util.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
bool ADDPR(debugEnabled) = false;
1717
uint32_t ADDPR(debugPrintDelay) = 0;
1818

19-
void LLLog(const char *format, ...) {
20-
char tmp[2048];
19+
void lilu_os_log(const char *format, ...) {
20+
char tmp[1024];
21+
tmp[0] = '\0';
2122
va_list va;
2223
va_start(va, format);
2324
vsnprintf(tmp, sizeof(tmp), format, va);
2425
va_end(va);
2526

26-
IOLog("%s", tmp);
27+
if (ml_get_interrupts_enabled())
28+
IOLog("%s", tmp);
2729

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

45-
if (ADDPR(debugPrintDelay) > 0)
47+
if (ml_get_interrupts_enabled() && ADDPR(debugPrintDelay) > 0)
4648
IOSleep(ADDPR(debugPrintDelay));
4749
}
4850

0 commit comments

Comments
 (0)