From 6bc73bfc97e5d78e2c5ba85a70ebd7f54aee554a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 9 Aug 2023 17:17:47 -0300 Subject: [PATCH 1/4] isapnp: Small macro cleanup --- src/device/isapnp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/isapnp.c b/src/device/isapnp.c index 22b22dfcc..b3500027c 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -35,7 +35,7 @@ } #define CHECK_CURRENT_CARD() \ - if (1) { \ + do { \ card = dev->first_card; \ while (card) { \ if (card->enable && (card->state == PNP_STATE_CONFIG)) \ @@ -46,7 +46,7 @@ isapnp_log("ISAPnP: No card in CONFIG state\n"); \ break; \ } \ - } + } while (0); static const uint8_t pnp_init_key[32] = { 0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE, 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61, From b539105b23fa42ae2f1eb25965393512288ddd72 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 9 Aug 2023 17:19:50 -0300 Subject: [PATCH 2/4] VISO: Proper pointer format strings --- src/cdrom/cdrom_image_viso.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index 45182481d..7a4507b5b 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -429,7 +429,7 @@ viso_fill_time(uint8_t *data, time_t time, int format, int longform) or way too far into 64-bit space (Linux). Fall back to epoch. */ time_t epoch = 0; time_s = localtime(&epoch); - if (!time_s) + if (UNLIKELY(!time_s)) fatal("VISO: localtime(0) = NULL\n"); /* Force year clamping if the timestamp is known to be outside the supported ranges. */ @@ -636,12 +636,8 @@ pad_susp: break; } - if ((p - data) > 255) -#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) - fatal("VISO: Directory record overflow (%d) on entry %016" PRIX64 "\n", (uint32_t) (uintptr_t) (p - data), (uint64_t) (uintptr_t) entry); -#else - fatal("VISO: Directory record overflow (%d) on entry %08X\n", (uint32_t) (uintptr_t) (p - data), (uint32_t) (uintptr_t) entry); -#endif + if (UNLIKELY((p - data) > 255)) + fatal("VISO: Directory record overflow (%" PRIuPTR ") on entry %08" PRIXPTR "\n", (uintptr_t) (p - data), (uintptr_t) entry); data[0] = p - data; /* length */ return data[0]; From 481e48a9174fa77466ce756710f97cd0f14cadb2 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 9 Aug 2023 17:21:48 -0300 Subject: [PATCH 3/4] gdbstub: Proper size_t format string --- src/gdbstub.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gdbstub.c b/src/gdbstub.c index 4fafb545e..97bf82fc9 100644 --- a/src/gdbstub.c +++ b/src/gdbstub.c @@ -1015,13 +1015,8 @@ e14: /* Add our supported features to the end. */ if (client->response_pos < (sizeof(client->response) - 1)) -#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) client->response_pos += snprintf(&client->response[client->response_pos], sizeof(client->response) - client->response_pos, - "PacketSize=%lX;swbreak+;hwbreak+;qXfer:features:read+", sizeof(client->packet) - 1); -#else - client->response_pos += snprintf(&client->response[client->response_pos], sizeof(client->response) - client->response_pos, - "PacketSize=%X;swbreak+;hwbreak+;qXfer:features:read+", sizeof(client->packet) - 1); -#endif + "PacketSize=%X;swbreak+;hwbreak+;qXfer:features:read+", (int) (sizeof(client->packet) - 1)); break; } else if (!strcmp(client->response, "Xfer")) { /* Read the transfer object. */ From 15013e1edeb9ba39c04ed70c6a413bb6a29cf4b1 Mon Sep 17 00:00:00 2001 From: cold-brewed <47337035+cold-brewed@users.noreply.github.com> Date: Wed, 9 Aug 2023 17:12:27 -0400 Subject: [PATCH 4/4] Added new platform function to get cpu string (#3533) Co-authored-by: cold-brewed --- src/include/86box/plat.h | 1 + src/qt/qt_platform.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ src/unix/unix.c | 6 ++++ src/win/win.c | 6 ++++ 4 files changed, 80 insertions(+) diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 2b0809c2e..a936b4ea0 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -137,6 +137,7 @@ extern void plat_vidapi_reload(void); extern void plat_vid_reload_options(void); extern uint32_t plat_language_code(char *langcode); extern void plat_language_code_r(uint32_t lcid, char *outbuf, int len); +extern void plat_get_cpu_string(char *outbuf, uint8_t len); /* Resource management. */ extern void set_language(uint32_t id); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 0274bc44a..cd43c6730 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -660,3 +661,69 @@ plat_init_rom_paths() #endif } } + +void +plat_get_cpu_string(char *outbuf, uint8_t len) { + auto cpu_string = QString("Unknown"); + /* Write the default string now in case we have to exit early from an error */ + qstrncpy(outbuf, cpu_string.toUtf8().constData(), len); + +#if defined(Q_OS_MACOS) + auto *process = new QProcess(nullptr); + QStringList arguments; + QString program = "/usr/sbin/sysctl"; + arguments << "machdep.cpu.brand_string"; + process->start(program, arguments); + if (!process->waitForStarted()) { + return; + } + if (!process->waitForFinished()) { + return; + } + QByteArray result = process->readAll(); + auto command_result = QString(result).split(": ").last(); + if(!command_result.isEmpty()) { + cpu_string = command_result; + } +#elif defined(Q_OS_WINDOWS) + const LPCSTR keyName = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"; + const LPCSTR valueName = "ProcessorNameString"; + unsigned char buf[32768]; + DWORD bufSize; + HKEY hKey; + bufSize = 32768; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, 1, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueExA(hKey, valueName, NULL, NULL, buf, &bufSize) == ERROR_SUCCESS) { + cpu_string = reinterpret_cast(buf); + } + RegCloseKey(hKey); + } +#elif defined(Q_OS_LINUX) + auto cpuinfo = QString("/proc/cpuinfo"); + auto cpuinfo_fi = QFileInfo(cpuinfo); + if(!cpuinfo_fi.isReadable()) { + return; + } + QFile file(cpuinfo); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream textStream(&file); + while(true) { + QString line = textStream.readLine(); + if (line.isNull()) { + break; + } + if(line.contains(QRegExp("model name.*:"))) { + auto list = line.split(": "); + if(!list.last().isEmpty()) { + cpu_string = list.last(); + break; + } + } + + } + } +#endif + + qstrncpy(outbuf, cpu_string.toUtf8().constData(), len); + +} \ No newline at end of file diff --git a/src/unix/unix.c b/src/unix/unix.c index 513f3b259..c389c9c45 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -1309,6 +1309,12 @@ plat_language_code(char *langcode) return 0; } +void +plat_get_cpu_string(char *outbuf, uint8_t len) { + char cpu_string[] = "Unknown"; + strncpy(outbuf, cpu_string, len); +} + /* Converts back the language code to LCID */ void plat_language_code_r(uint32_t lcid, char *outbuf, int len) diff --git a/src/win/win.c b/src/win/win.c index f166d559d..83135cd68 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -1250,6 +1250,12 @@ plat_language_code_r(uint32_t lcid, char *outbuf, int len) c16stombs(outbuf, buffer, len); } +void +plat_get_cpu_string(char *outbuf, uint8_t len) { + char cpu_string[] = "Unknown"; + strncpy(outbuf, cpu_string, len); +} + void take_screenshot(void) {