DF-4069 / probe.c
/* DF-4069..4074 struct-layout probe: exact array capacities and overflow math * for vegam_smumgr.c DPM walks. Pure C, no GPU required. */ #include <sys/types.h> #include <stdio.h> #include <stddef.h> #include "smu75_discrete.h" #define PP_ATOMCTRL_MAX_VOLTAGE_ENTRIES 32 int main(void) { printf("sizeof(SMU75_Discrete_GraphicsLevel)=%zu\n", sizeof(SMU75_Discrete_GraphicsLevel)); printf("sizeof(SMU75_Discrete_MemoryLevel)=%zu\n", sizeof(SMU75_Discrete_MemoryLevel)); printf("sizeof(SMU75_Discrete_LinkLevel)=%zu\n", sizeof(SMU75_Discrete_LinkLevel)); printf("sizeof(SMU75_Discrete_MCArbDramTimingTableEntry)=%zu\n", sizeof(SMU75_Discrete_MCArbDramTimingTableEntry)); printf("sizeof(SMU75_Discrete_MCArbDramTimingTable)=%zu\n", sizeof(SMU75_Discrete_MCArbDramTimingTable)); printf("sizeof(SMU75_Discrete_DpmTable)=%zu\n", sizeof(SMU75_Discrete_DpmTable)); printf("MAX_LEVELS GRAPHICS=%d MEMORY=%d LINK=%d SMIO=%d\n", SMU75_MAX_LEVELS_GRAPHICS, SMU75_MAX_LEVELS_MEMORY, SMU75_MAX_LEVELS_LINK, SMU75_MAX_ENTRIES_SMIO); printf("SMU__NUM_SCLK_DPM_STATE x SMU__NUM_MCLK_DPM_LEVELS = %d x %d\n", SMU__NUM_SCLK_DPM_STATE, SMU__NUM_MCLK_DPM_LEVELS); printf("offsetof: GraphicsLevel=%zu MemoryLevel=%zu LinkLevel=%zu\n", offsetof(SMU75_Discrete_DpmTable, GraphicsLevel), offsetof(SMU75_Discrete_DpmTable, MemoryLevel), offsetof(SMU75_Discrete_DpmTable, LinkLevel)); /* worst-case walks (count straight from VBIOS u8 ucNumEntries, <=255) */ printf("GraphicsLevel walk: count=255 writes up to byte %zu of array (capacity %zu)\n", (size_t)255 * sizeof(SMU75_Discrete_GraphicsLevel), (size_t)SMU75_MAX_LEVELS_GRAPHICS * sizeof(SMU75_Discrete_GraphicsLevel)); printf("MemoryLevel walk: count=255 writes up to byte %zu of array (capacity %zu)\n", (size_t)255 * sizeof(SMU75_Discrete_MemoryLevel), (size_t)SMU75_MAX_LEVELS_MEMORY * sizeof(SMU75_Discrete_MemoryLevel)); printf("MemoryLevel walk: count=5 writes up to byte %zu (capacity %zu) -> already OOB\n", (size_t)5 * sizeof(SMU75_Discrete_MemoryLevel), (size_t)SMU75_MAX_LEVELS_MEMORY * sizeof(SMU75_Discrete_MemoryLevel)); printf("MC-arb walk: sclk=9,mclk=5 writes entry offset %zu bytes (table=%zu)\n", ((size_t)9 * SMU__NUM_MCLK_DPM_LEVELS + 5) * sizeof(SMU75_Discrete_MCArbDramTimingTableEntry), sizeof(SMU75_Discrete_MCArbDramTimingTable)); printf("MC-arb walk: sclk=255,mclk=4 writes entry offset %zu bytes (table=%zu)\n", ((size_t)255 * SMU__NUM_MCLK_DPM_LEVELS) * sizeof(SMU75_Discrete_MCArbDramTimingTableEntry), sizeof(SMU75_Discrete_MCArbDramTimingTable)); } |