-#pragma pack()
-
-#define LCK_RW_ATTR_DEBUG 0x1
-#define LCK_RW_ATTR_DEBUGb 0
-#define LCK_RW_ATTR_STAT 0x2
-#define LCK_RW_ATTR_STATb 1
-#define LCK_RW_ATTR_READ_PRI 0x3
-#define LCK_RW_ATTR_READ_PRIb 2
-#define LCK_RW_ATTR_DIS_THREAD 0x40000000
-#define LCK_RW_ATTR_DIS_THREADb 30
-#define LCK_RW_ATTR_DIS_MYLOCK 0x10000000
-#define LCK_RW_ATTR_DIS_MYLOCKb 28
+#define LCK_RW_T_SIZE 16
+
+static_assert(sizeof(lck_rw_t) == LCK_RW_T_SIZE);
+
+#define LCK_RW_SHARED_SHIFT 0
+#define LCK_RW_INTERLOCK_BIT 16
+#define LCK_RW_PRIV_EXCL_BIT 24
+#define LCK_RW_WANT_UPGRADE_BIT 25
+#define LCK_RW_WANT_EXCL_BIT 26
+#define LCK_RW_R_WAITING_BIT 27
+#define LCK_RW_W_WAITING_BIT 28
+#define LCK_RW_CAN_SLEEP_BIT 29
+
+#define LCK_RW_INTERLOCK (1 << LCK_RW_INTERLOCK_BIT)
+#define LCK_RW_WANT_UPGRADE (1 << LCK_RW_WANT_UPGRADE_BIT)
+#define LCK_RW_WANT_EXCL (1 << LCK_RW_WANT_EXCL_BIT)
+#define LCK_RW_R_WAITING (1 << LCK_RW_R_WAITING_BIT)
+#define LCK_RW_W_WAITING (1 << LCK_RW_W_WAITING_BIT)
+#define LCK_RW_PRIV_EXCL (1 << LCK_RW_PRIV_EXCL_BIT)
+#define LCK_RW_TAG_VALID (1 << LCK_RW_TAG_VALID_BIT)
+#define LCK_RW_SHARED_MASK (0xffff << LCK_RW_SHARED_SHIFT)
+#define LCK_RW_SHARED_READER (1 << LCK_RW_SHARED_SHIFT)
+
+#define LCK_RW_WANT_WRITE LCK_RW_WANT_EXCL
+
+
+#define LCK_RW_ATTR_DEBUG 0x1
+#define LCK_RW_ATTR_DEBUGb 0
+#define LCK_RW_ATTR_STAT 0x2
+#define LCK_RW_ATTR_STATb 1
+#define LCK_RW_ATTR_READ_PRI 0x3
+#define LCK_RW_ATTR_READ_PRIb 2
+#define LCK_RW_ATTR_DIS_THREAD 0x40000000
+#define LCK_RW_ATTR_DIS_THREADb 30
+#define LCK_RW_ATTR_DIS_MYLOCK 0x10000000
+#define LCK_RW_ATTR_DIS_MYLOCKb 28
+
+#define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
+
+#define RW_LOCK_READER_EVENT(x) ((event_t) (((unsigned char*) (x)) + (offsetof(lck_rw_t, lck_rw_tag))))
+#define RW_LOCK_WRITER_EVENT(x) ((event_t) (((unsigned char*) (x)) + (offsetof(lck_rw_t, lck_rw_pad8))))
+#define READ_EVENT_TO_RWLOCK(x) ((lck_rw_t *)(((unsigned char*)(x) - (offsetof(lck_rw_t, lck_rw_tag)))))
+#define WRITE_EVENT_TO_RWLOCK(x) ((lck_rw_t *)(((unsigned char*)(x) - (offsetof(lck_rw_t, lck_rw_pad8)))))
+
+#if LOCK_PRIVATE
+
+#define disable_preemption_for_thread(t) ((cpu_data_t GS_RELATIVE *)0UL)->cpu_preemption_level++
+#define preemption_disabled_for_thread(t) (((cpu_data_t GS_RELATIVE *)0UL)->cpu_preemption_level > 0)
+
+#define LCK_MTX_THREAD_TO_STATE(t) ((uintptr_t)t)
+#define PLATFORM_LCK_ILOCK 0
+
+#define LOCK_SNOOP_SPINS 1000
+#define LOCK_PRETEST 1
+
+/* hw_lock_lock static panic deadline, in timebase units. hw_lock_to() uses
+ * LockTimeoutTSC computed at startup
+ */
+#define LOCK_PANIC_TIMEOUT 0xf000000 /* 251e6 TSC ticks */