From 86e425a0dc3c6087c52b4d46e2edb5c565397315 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 3 Jun 2019 10:56:50 +0000 Subject: [PATCH] Document TransitionLock semantics and RCU intent Rumor has it, NT is one of the few kernels that actually has RCU (alongside Linux and maybe some IBM things). So maybe if we ever learn how to use NT's RCU functionality, we'll be able to replace this with that. --- wintun.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wintun.c b/wintun.c index 6362f56..ab1c994 100644 --- a/wintun.c +++ b/wintun.c @@ -56,6 +56,10 @@ typedef enum _TUN_STATE { typedef struct _TUN_CTX { volatile TUN_STATE State; volatile NDIS_DEVICE_POWER_STATE PowerState; + + /* Used like RCU. When we're making use of queues, we take a shared lock. When we want to + * drain the queues and toggle the state, we take an exclusive lock before toggling the + * atomic and then releasing. It's similar to setting the atomic and then calling rcu_barrier(). */ EX_SPIN_LOCK TransitionLock; NDIS_HANDLE MiniportAdapterHandle;