From f9bd5682db3e40f0dd05adcd23bc71ec00cd3408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Sep 2026 10:39:06 -0600 Subject: [PATCH] libkirk: let C++ callers include its headers directly kirk_engine.h and amctrl.h guard their declarations, but AES.h and SHA1.h never did, and kirk_engine.h includes them from outside its own guard. So the AES_* and SHA1* functions got C++ linkage in any C++ file that reached them through there, and only linked for callers that happened to wrap the whole header in an extern "C" of their own. Nothing had called AES_* from C++ before, so it stayed hidden until something did. Guarding the two headers instead lets every caller include them plainly, and the wrappers scattered around the tree come out. Both are pure declarations over kirk_common.h's typedefs with no system headers behind them, so there's nothing in there that shouldn't be wrapped. kirk_engine.h also uses size_t without including anything that defines it, which only held together because its includers happened to have it already. Co-Authored-By: Claude Opus 5 --- Core/ELF/PrxDecrypter.cpp | 3 --- Core/FileSystems/BlockDevices.cpp | 3 --- Core/HLE/sceIo.cpp | 2 -- Core/HLE/sceKernelSemaphore.h | 3 --- Core/HLE/scePspNpDrm_user.cpp | 7 +------ Core/Util/PSARUnpack.cpp | 2 -- Core/Util/PkgUnpack.cpp | 2 -- ext/libkirk/AES.h | 8 ++++++++ ext/libkirk/SHA1.h | 8 ++++++++ ext/libkirk/kirk_engine.h | 5 +++++ 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Core/ELF/PrxDecrypter.cpp b/Core/ELF/PrxDecrypter.cpp index cf0e980e37..a3b8fe46c4 100644 --- a/Core/ELF/PrxDecrypter.cpp +++ b/Core/ELF/PrxDecrypter.cpp @@ -2,11 +2,8 @@ #include #include -extern "C" -{ #include "ext/libkirk/kirk_engine.h" #include "ext/libkirk/SHA1.h" -} #include "Common/Common.h" #include "Common/Log.h" #include "Common/Swap.h" diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index e6eb46554a..d74639a56c 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -35,12 +35,9 @@ #include "Core/Util/PathUtil.h" #include "libchdr/chd.h" -extern "C" -{ #include "zlib.h" #include "ext/libkirk/amctrl.h" #include "ext/libkirk/kirk_engine.h" -}; static u16 ReadLE16(const u8 *ptr) { return ptr[0] | (ptr[1] << 8); diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 293b388ca0..bb275b111a 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -58,9 +58,7 @@ #include "Core/FileSystems/ISOFileSystem.h" #include "Core/FileSystems/DirectoryFileSystem.h" -extern "C" { #include "ext/libkirk/amctrl.h" -}; #include "Core/HLE/sceIo.h" #include "Core/HLE/sceRtc.h" diff --git a/Core/HLE/sceKernelSemaphore.h b/Core/HLE/sceKernelSemaphore.h index 74002ff9d6..410fbe2f17 100644 --- a/Core/HLE/sceKernelSemaphore.h +++ b/Core/HLE/sceKernelSemaphore.h @@ -80,7 +80,4 @@ void __KernelSemaInit(); void __KernelSemaDoState(PointerWrap &p); KernelObject *__KernelSemaphoreObject(); -extern "C" -{ #include "ext/libkirk/kirk_engine.h" -} diff --git a/Core/HLE/scePspNpDrm_user.cpp b/Core/HLE/scePspNpDrm_user.cpp index 37c35b9386..6ef44d4ebf 100644 --- a/Core/HLE/scePspNpDrm_user.cpp +++ b/Core/HLE/scePspNpDrm_user.cpp @@ -1,10 +1,5 @@ -// kirk_engine.h includes AES.h from outside its own extern "C" block, so whoever pulls it in first -// decides the linkage the AES_* functions get. Do it here, the way PrxDecrypter.cpp does, or they -// come through sceChnnlsv.h below with C++ linkage and fail to link. -extern "C" { -#include "ext/libkirk/kirk_engine.h" +#include "ext/libkirk/AES.h" #include "ext/libkirk/amctrl.h" -} #include "Core/HLE/scePspNpDrm_user.h" #include "Core/MemMapHelpers.h" diff --git a/Core/Util/PSARUnpack.cpp b/Core/Util/PSARUnpack.cpp index e7aff71097..a0880bc6fa 100644 --- a/Core/Util/PSARUnpack.cpp +++ b/Core/Util/PSARUnpack.cpp @@ -37,9 +37,7 @@ #include "Core/System.h" #include "Core/Util/PSARUnpack.h" -extern "C" { #include "ext/libkirk/kirk_engine.h" -} // A PSAR record is [header][entry], where the header is 0x150 bytes of PRX-style encryption // metadata and the entry is 0x110 bytes describing one file. Pre-decrypted archives (rare, and diff --git a/Core/Util/PkgUnpack.cpp b/Core/Util/PkgUnpack.cpp index 105d52f4e6..48d03a9a66 100644 --- a/Core/Util/PkgUnpack.cpp +++ b/Core/Util/PkgUnpack.cpp @@ -31,9 +31,7 @@ #include "Core/System.h" #include "Core/Util/PkgUnpack.h" -extern "C" { #include "ext/libkirk/AES.h" -} // See docs/pkg_notes.md. Field offsets in the 0xC0-byte header: static const u32 PKG_MAGIC = 0x7F504B47; // "\x7FPKG" diff --git a/ext/libkirk/AES.h b/ext/libkirk/AES.h index ee61f46490..08e2260c99 100644 --- a/ext/libkirk/AES.h +++ b/ext/libkirk/AES.h @@ -3,6 +3,10 @@ #include "kirk_common.h" +#ifdef __cplusplus +extern "C" { +#endif + #define AES_KEY_LEN_128 (128) #define AES_KEY_LEN_192 (192) #define AES_KEY_LEN_256 (256) @@ -48,4 +52,8 @@ int rijndaelKeySetupEnc(u32 [], const u8 [], int); int rijndaelKeySetupDec(u32 [], const u8 [], int); void rijndaelEncrypt(const u32 [], int, const u8 pt[16], u8 ct[16]); +#ifdef __cplusplus +} +#endif + #endif /* __RIJNDAEL_H */ diff --git a/ext/libkirk/SHA1.h b/ext/libkirk/SHA1.h index 43493e3319..2735c3faf2 100644 --- a/ext/libkirk/SHA1.h +++ b/ext/libkirk/SHA1.h @@ -2,6 +2,10 @@ #include "kirk_common.h" +#ifdef __cplusplus +extern "C" { +#endif + /* POINTER defines a generic pointer type */ typedef unsigned char *POINTER; typedef const unsigned char *CONST_POINTER; @@ -34,3 +38,7 @@ void SHAUpdate(SHA_CTX *, const BYTE *buffer, int count); void SHAFinal(BYTE *output, SHA_CTX *); void endianTest(int *endianness); + +#ifdef __cplusplus +} +#endif diff --git a/ext/libkirk/kirk_engine.h b/ext/libkirk/kirk_engine.h index de90c4d48e..153e8c0b34 100644 --- a/ext/libkirk/kirk_engine.h +++ b/ext/libkirk/kirk_engine.h @@ -26,6 +26,11 @@ #pragma once +// kirk4()/kirk7() below take a size_t, and nothing here provided it - the header only ever +// compiled because whatever included it had pulled in a definition first. Core/HLE/scePspNpDrm_user.cpp +// includes libkirk before anything else, so it doesn't. +#include + #include "kirk_common.h" #include "SHA1.h" #include "AES.h"