[Misc] Replaced const with constexpr where possible

This commit is contained in:
Xphalnos
2025-03-20 21:16:32 +01:00
committed by Radosław Gliński
parent d20620eb5e
commit 5f918ef28d
64 changed files with 191 additions and 190 deletions

View File

@@ -44,7 +44,7 @@ class KernelModule : public XModule {
std::string path_;
// Guest trampoline for GetProcAddress
static const uint32_t kTrampolineSize = 400 * 8;
static constexpr uint32_t kTrampolineSize = 400 * 8;
uint32_t guest_trampoline_ = 0;
uint32_t guest_trampoline_next_ = 0; // Next free entry to be generated.
uint32_t guest_trampoline_size_ = 0;

View File

@@ -221,7 +221,7 @@ dword_result_t XGetAVPack_entry() {
DECLARE_XAM_EXPORT1(XGetAVPack, kNone, kStub);
uint32_t xeXGetGameRegion() {
static uint32_t const table[] = {
static uint32_t constexpr table[] = {
0xFFFFu, 0x03FFu, 0x02FEu, 0x02FEu, 0x03FFu, 0x02FEu, 0x0201u, 0x03FFu,
0x02FEu, 0x02FEu, 0x03FFu, 0x03FFu, 0x03FFu, 0x03FFu, 0x02FEu, 0x03FFu,
0x00FFu, 0xFFFFu, 0x02FEu, 0x03FFu, 0x0102u, 0x03FFu, 0x03FFu, 0x02FEu,

View File

@@ -36,7 +36,7 @@ namespace xam {
// Table lookups.
uint8_t xeXamGetOnlineCountryFromLocale(uint8_t id) {
static uint8_t const table[] = {
static uint8_t constexpr table[] = {
2, 6, 5, 8, 13, 16, 19, 20, 21, 23, 25, 32, 34, 24, 37,
39, 42, 46, 44, 50, 53, 56, 71, 74, 76, 75, 82, 84, 91, 93,
109, 31, 90, 18, 101, 35, 103, 88, 236, 99, 4, 89, 45, 1,
@@ -120,7 +120,7 @@ const char16_t* xeXamGetLocaleString(uint8_t id) {
}
uint8_t xeXamGetLocaleFromOnlineCountry(uint8_t id) {
static uint8_t const table[] = {
static uint8_t constexpr table[] = {
0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, 0, 5, 0, 33,
6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, 0, 31, 11, 0, 12, 35, 0, 14,
0, 15, 0, 0, 16, 0, 18, 42, 17, 0, 0, 0, 19, 0, 0, 20, 0, 0, 21,
@@ -140,7 +140,7 @@ uint8_t xeXamGetLocaleFromOnlineCountry(uint8_t id) {
}
uint8_t xeXamGetLanguageFromOnlineLanguage(uint8_t id) {
static uint8_t const table[] = {
static uint8_t constexpr table[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 11, 12, 1, 1, 15, 16, 13, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -164,7 +164,7 @@ const char16_t* xeXamGetOnlineLanguageString(uint8_t id) {
}
uint8_t xeXamGetCountryFromOnlineCountry(uint8_t id) {
static uint8_t const table[] = {
static uint8_t constexpr table[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
@@ -186,7 +186,7 @@ uint8_t xeXamGetCountryFromOnlineCountry(uint8_t id) {
}
uint8_t xeXamGetLocaleFromCountry(uint8_t id) {
static uint8_t const table[] = {
static uint8_t constexpr table[] = {
0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, 0, 5, 0, 33,
6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, 0, 31, 11, 0, 12, 35, 0, 14,
0, 15, 0, 0, 16, 0, 18, 42, 17, 0, 0, 0, 19, 0, 0, 20, 0, 0, 21,

View File

@@ -23,7 +23,7 @@ namespace xam {
bool xeXamIsUIActive();
static const std::string kXamModuleLoaderDataFileName = "launch_data.bin";
static constexpr std::string kXamModuleLoaderDataFileName = "launch_data.bin";
class XamModule : public KernelModule {
public:

View File

@@ -451,25 +451,25 @@ DECLARE_XAM_EXPORT1(NetDll_WSASetEvent, kNetworking, kImplemented);
struct XnAddrStatus {
// Address acquisition is not yet complete
static const uint32_t XNET_GET_XNADDR_PENDING = 0x00000000;
static constexpr uint32_t XNET_GET_XNADDR_PENDING = 0x00000000;
// XNet is uninitialized or no debugger found
static const uint32_t XNET_GET_XNADDR_NONE = 0x00000001;
static constexpr uint32_t XNET_GET_XNADDR_NONE = 0x00000001;
// Host has ethernet address (no IP address)
static const uint32_t XNET_GET_XNADDR_ETHERNET = 0x00000002;
static constexpr uint32_t XNET_GET_XNADDR_ETHERNET = 0x00000002;
// Host has statically assigned IP address
static const uint32_t XNET_GET_XNADDR_STATIC = 0x00000004;
static constexpr uint32_t XNET_GET_XNADDR_STATIC = 0x00000004;
// Host has DHCP assigned IP address
static const uint32_t XNET_GET_XNADDR_DHCP = 0x00000008;
static constexpr uint32_t XNET_GET_XNADDR_DHCP = 0x00000008;
// Host has PPPoE assigned IP address
static const uint32_t XNET_GET_XNADDR_PPPOE = 0x00000010;
static constexpr uint32_t XNET_GET_XNADDR_PPPOE = 0x00000010;
// Host has one or more gateways configured
static const uint32_t XNET_GET_XNADDR_GATEWAY = 0x00000020;
static constexpr uint32_t XNET_GET_XNADDR_GATEWAY = 0x00000020;
// Host has one or more DNS servers configured
static const uint32_t XNET_GET_XNADDR_DNS = 0x00000040;
static constexpr uint32_t XNET_GET_XNADDR_DNS = 0x00000040;
// Host is currently connected to online service
static const uint32_t XNET_GET_XNADDR_ONLINE = 0x00000080;
static constexpr uint32_t XNET_GET_XNADDR_ONLINE = 0x00000080;
// Network configuration requires troubleshooting
static const uint32_t XNET_GET_XNADDR_TROUBLESHOOT = 0x00008000;
static constexpr uint32_t XNET_GET_XNADDR_TROUBLESHOOT = 0x00008000;
};
dword_result_t NetDll_XNetGetTitleXnAddr_entry(dword_t caller,

View File

@@ -778,8 +778,9 @@ DECLARE_XBOXKRNL_EXPORT1(XeCryptHmacSha, kNone, kImplemented);
// TODO: Array of keys we need
// Retail key 0x19
static const uint8_t key19[] = {0xE1, 0xBC, 0x15, 0x9C, 0x73, 0xB1, 0xEA, 0xE9,
0xAB, 0x31, 0x70, 0xF3, 0xAD, 0x47, 0xEB, 0xF3};
static constexpr uint8_t key19[] = {0xE1, 0xBC, 0x15, 0x9C, 0x73, 0xB1,
0xEA, 0xE9, 0xAB, 0x31, 0x70, 0xF3,
0xAD, 0x47, 0xEB, 0xF3};
dword_result_t XeKeysHmacSha_entry(dword_t key_num, lpvoid_t inp_1,
dword_t inp_1_size, lpvoid_t inp_2,

View File

@@ -30,7 +30,7 @@ struct error_lookup_table {
};
// TODO(gibbed): replace these with named error codes
const uint32_t error_table_0x00000103[] = {
constexpr uint32_t error_table_0x00000103[] = {
0x000003E5, // 0x00000103
0, //
0x000000EA, // 0x00000105
@@ -44,7 +44,7 @@ const uint32_t error_table_0x00000103[] = {
0x00000516, // 0x0000010D
};
const uint32_t error_table_0x40000002[] = {
constexpr uint32_t error_table_0x40000002[] = {
0x00000057, // 0x40000002
0, //
0, //
@@ -59,15 +59,15 @@ const uint32_t error_table_0x40000002[] = {
0x00000518, // 0x4000000D
};
const uint32_t error_table_0x40020056[] = {
constexpr uint32_t error_table_0x40020056[] = {
0x00000720, // 0x40020056
};
const uint32_t error_table_0x400200AF[] = {
constexpr uint32_t error_table_0x400200AF[] = {
0x00000779, // 0x400200AF
};
const uint32_t error_table_0x80000001[] = {
constexpr uint32_t error_table_0x80000001[] = {
0x80000001, // 0x80000001
0x000003E6, // 0x80000002
0x80000003, // 0x80000003
@@ -107,12 +107,12 @@ const uint32_t error_table_0x80000001[] = {
0x00000962, // 0x80000025
};
const uint32_t error_table_0x80000288[] = {
constexpr uint32_t error_table_0x80000288[] = {
0x0000048D, // 0x80000288
0x0000048E, // 0x80000289
};
const uint32_t error_table_0x80090300[] = {
constexpr uint32_t error_table_0x80090300[] = {
0x000005AA, // 0x80090300
0x00000006, // 0x80090301
0x00000001, // 0x80090302
@@ -165,7 +165,7 @@ const uint32_t error_table_0x80090300[] = {
0x00000001, // 0x80090331
};
const uint32_t error_table_0xC0000001[] = {
constexpr uint32_t error_table_0xC0000001[] = {
0x0000001F, // 0xC0000001
0x00000001, // 0xC0000002
0x00000057, // 0xC0000003
@@ -579,7 +579,7 @@ const uint32_t error_table_0xC0000001[] = {
0x00000712, // 0xC000019B
};
const uint32_t error_table_0xC0000202[] = {
constexpr uint32_t error_table_0xC0000202[] = {
0x00000572, // 0xC0000202
0x0000003B, // 0xC0000203
0x00000717, // 0xC0000204
@@ -815,7 +815,7 @@ const uint32_t error_table_0xC0000202[] = {
0x00000052, // 0xC00002EA
};
const uint32_t error_table_0xC0020001[] = {
constexpr uint32_t error_table_0xC0020001[] = {
0x000006A4, // 0xC0020001
0x000006A5, // 0xC0020002
0x00000006, // 0xC0020003
@@ -917,7 +917,7 @@ const uint32_t error_table_0xC0020001[] = {
0x0000077B, // 0xC0020063
};
const uint32_t error_table_0xC0030001[] = {
constexpr uint32_t error_table_0xC0030001[] = {
0x000006EC, // 0xC0030001
0x000006ED, // 0xC0030002
0x000006EE, // 0xC0030003
@@ -932,7 +932,7 @@ const uint32_t error_table_0xC0030001[] = {
0x000006F7, // 0xC003000C
};
const uint32_t error_table_0xC0030059[] = {
constexpr uint32_t error_table_0xC0030059[] = {
0x00000723, // 0xC0030059
0x00000724, // 0xC003005A
0x00000725, // 0xC003005B
@@ -944,12 +944,12 @@ const uint32_t error_table_0xC0030059[] = {
0x0000077E, // 0xC0030061
};
const uint32_t error_table_0xC0050003[] = {
constexpr uint32_t error_table_0xC0050003[] = {
0x0000045D, // 0xC0050003
0x00000456, // 0xC0050004
};
const uint32_t error_table_0xC0980001[] = {
constexpr uint32_t error_table_0xC0980001[] = {
0x00000037, // 0xC0980001
0x00000037, // 0xC0980002
0, //
@@ -961,7 +961,7 @@ const uint32_t error_table_0xC0980001[] = {
};
#define MAKE_ENTRY(x) {x, xe::countof(error_table_##x), error_table_##x}
const error_lookup_table error_tables[] = {
constexpr error_lookup_table error_tables[] = {
MAKE_ENTRY(0x00000103), MAKE_ENTRY(0x40000002), MAKE_ENTRY(0x40020056),
MAKE_ENTRY(0x400200AF), MAKE_ENTRY(0x80000001), MAKE_ENTRY(0x80000288),
MAKE_ENTRY(0x80090300), MAKE_ENTRY(0xC0000001), MAKE_ENTRY(0xC0000202),

View File

@@ -29,14 +29,14 @@ namespace xboxkrnl {
struct CreateOptions {
// https://processhacker.sourceforge.io/doc/ntioapi_8h.html
static const uint32_t FILE_DIRECTORY_FILE = 0x00000001;
static constexpr uint32_t FILE_DIRECTORY_FILE = 0x00000001;
// Optimization - files access will be sequential, not random.
static const uint32_t FILE_SEQUENTIAL_ONLY = 0x00000004;
static const uint32_t FILE_SYNCHRONOUS_IO_ALERT = 0x00000010;
static const uint32_t FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020;
static const uint32_t FILE_NON_DIRECTORY_FILE = 0x00000040;
static constexpr uint32_t FILE_SEQUENTIAL_ONLY = 0x00000004;
static constexpr uint32_t FILE_SYNCHRONOUS_IO_ALERT = 0x00000010;
static constexpr uint32_t FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020;
static constexpr uint32_t FILE_NON_DIRECTORY_FILE = 0x00000040;
// Optimization - file access will be random, not sequential.
static const uint32_t FILE_RANDOM_ACCESS = 0x00000800;
static constexpr uint32_t FILE_RANDOM_ACCESS = 0x00000800;
};
dword_result_t NtCreateFile_entry(lpdword_t handle_out, dword_t desired_access,
@@ -625,7 +625,7 @@ dword_result_t NtDeviceIoControlFile_entry(
// Called by XMountUtilityDrive cache-mounting code
// (checks if the returned values look valid, values below seem to pass the
// checks)
const uint32_t cache_size = 0xFF000;
constexpr uint32_t cache_size = 0xFF000;
if (io_control_code == X_IOCTL_DISK_GET_DRIVE_GEOMETRY) {
if (output_buffer_len < 0x8) {

View File

@@ -703,7 +703,7 @@ DECLARE_XBOXKRNL_EXPORT1(ExAllocatePoolWithTag, kMemory, kImplemented);
dword_result_t ExAllocatePool_entry(dword_t size,
const ppc_context_t& context) {
const uint32_t none = 0x656E6F4E; // 'None'
constexpr uint32_t none = 0x656E6F4E; // 'None'
return xeAllocatePoolTypeWithTag(context, size, none, 0);
}
DECLARE_XBOXKRNL_EXPORT1(ExAllocatePool, kMemory, kImplemented);

View File

@@ -52,9 +52,9 @@ struct XDPC {
};
struct XAPC {
static const uint32_t kSize = 40;
static const uint32_t kDummyKernelRoutine = 0xF00DFF00;
static const uint32_t kDummyRundownRoutine = 0xF00DFF01;
static constexpr uint32_t kSize = 40;
static constexpr uint32_t kDummyKernelRoutine = 0xF00DFF00;
static constexpr uint32_t kDummyRundownRoutine = 0xF00DFF01;
// KAPC is 0x28(40) bytes? (what's passed to ExAllocatePoolWithTag)
// This is 4b shorter than NT - looks like the reserved dword at +4 is gone.