diff --git a/include/coreinit/context.h b/include/coreinit/context.h index 9960143..e74594d 100644 --- a/include/coreinit/context.h +++ b/include/coreinit/context.h @@ -16,7 +16,7 @@ typedef struct OSContext OSContext; #define OS_CONTEXT_TAG 0x4F53436F6E747874ull -struct OSContext +struct WUT_ALIGNAS(8) OSContext { //! Should always be set to the value OS_CONTEXT_TAG. uint64_t tag; diff --git a/include/coreinit/memblockheap.h b/include/coreinit/memblockheap.h index 6325b40..7df56cb 100644 --- a/include/coreinit/memblockheap.h +++ b/include/coreinit/memblockheap.h @@ -54,7 +54,7 @@ WUT_CHECK_OFFSET(MEMBlockHeapBlock, 0x0c, prev); WUT_CHECK_OFFSET(MEMBlockHeapBlock, 0x10, next); WUT_CHECK_SIZE(MEMBlockHeapBlock, 0x14); -struct MEMBlockHeap +struct WUT_PACKED MEMBlockHeap { MEMHeapHeader header; diff --git a/include/coreinit/memexpheap.h b/include/coreinit/memexpheap.h index 8bbacc9..11da2d2 100644 --- a/include/coreinit/memexpheap.h +++ b/include/coreinit/memexpheap.h @@ -56,7 +56,7 @@ WUT_CHECK_OFFSET(MEMExpHeapBlockList, 0x00, head); WUT_CHECK_OFFSET(MEMExpHeapBlockList, 0x04, tail); WUT_CHECK_SIZE(MEMExpHeapBlockList, 0x08); -struct MEMExpHeap +struct WUT_PACKED MEMExpHeap { MEMHeapHeader header; MEMExpHeapBlockList freeList; diff --git a/include/coreinit/memfrmheap.h b/include/coreinit/memfrmheap.h index e963890..7312860 100644 --- a/include/coreinit/memfrmheap.h +++ b/include/coreinit/memfrmheap.h @@ -35,7 +35,7 @@ WUT_CHECK_OFFSET(MEMFrmHeapState, 0x08, tail); WUT_CHECK_OFFSET(MEMFrmHeapState, 0x0C, previous); WUT_CHECK_SIZE(MEMFrmHeapState, 0x10); -struct MEMFrmHeap +struct WUT_PACKED MEMFrmHeap { MEMHeapHeader header; void *head; diff --git a/include/coreinit/memunitheap.h b/include/coreinit/memunitheap.h index 1623bed..c1df857 100644 --- a/include/coreinit/memunitheap.h +++ b/include/coreinit/memunitheap.h @@ -22,7 +22,7 @@ struct MEMUnitHeapFreeBlock WUT_CHECK_OFFSET(MEMUnitHeapFreeBlock, 0x00, next); WUT_CHECK_SIZE(MEMUnitHeapFreeBlock, 0x04); -struct MEMUnitHeap +struct WUT_PACKED MEMUnitHeap { MEMHeapHeader header; MEMUnitHeapFreeBlock *freeBlocks; diff --git a/include/coreinit/spinlock.h b/include/coreinit/spinlock.h index 64923d1..b24fa52 100644 --- a/include/coreinit/spinlock.h +++ b/include/coreinit/spinlock.h @@ -14,7 +14,7 @@ extern "C" { typedef struct OSSpinLock OSSpinLock; -struct OSSpinLock +struct WUT_ALIGNAS(16) OSSpinLock { uint32_t owner; WUT_UNKNOWN_BYTES(0x4); diff --git a/include/coreinit/thread.h b/include/coreinit/thread.h index fcd5db7..e83e86c 100644 --- a/include/coreinit/thread.h +++ b/include/coreinit/thread.h @@ -117,7 +117,7 @@ WUT_CHECK_SIZE(OSFastMutexQueue, 0x08); #define OS_THREAD_TAG 0x74487244u #pragma pack(push, 1) -struct OSThread +struct WUT_ALIGNAS(8) OSThread { OSContext context; diff --git a/include/wut_structsize.h b/include/wut_structsize.h index 99ef9c0..d28972e 100644 --- a/include/wut_structsize.h +++ b/include/wut_structsize.h @@ -31,3 +31,10 @@ // Marks a struct as packed #define WUT_PACKED __attribute__((__packed__)) + +// Sets alignment for a struct +#if defined(__alignas_is_defined) || defined(__cplusplus) +#define WUT_ALIGNAS(x) alignas(x) +#elif defined(__GNUC__) || defined(__clang__) +#define WUT_ALIGNAS(x) __attribute__((__aligned__(x))) +#endif