aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-10-30 16:58:50 +0100
committerSimon Rozman <simon@rozman.si>2020-10-31 19:11:50 +0100
commitf947205cee76a1ae9ddf555d7e2a45675fe333fd (patch)
tree2d70011349690078863efeedf066f26600603179 /api
parentapi: rework pool hashing (diff)
downloadwintun-f947205cee76a1ae9ddf555d7e2a45675fe333fd.tar.xz
wintun-f947205cee76a1ae9ddf555d7e2a45675fe333fd.zip
api: use proper iso atomic semantics
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api')
-rw-r--r--api/api.vcxproj2
-rw-r--r--api/api.vcxproj.filters3
-rw-r--r--api/atomic.h26
-rw-r--r--api/pch.h1
-rw-r--r--api/session.c10
5 files changed, 6 insertions, 36 deletions
diff --git a/api/api.vcxproj b/api/api.vcxproj
index 12ae6ca..cea689d 100644
--- a/api/api.vcxproj
+++ b/api/api.vcxproj
@@ -146,6 +146,7 @@
<PreprocessorDefinitions Condition="Exists('$(OutDir)whql\')">HAVE_WHQL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+ <AdditionalOptions>/volatile:iso %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>..\$(Configuration)\$(WintunPlatform);..\$(Configuration);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -194,7 +195,6 @@
<ItemGroup>
<ClInclude Include="api.h" />
<ClInclude Include="adapter.h" />
- <ClInclude Include="atomic.h" />
<ClInclude Include="elevate.h" />
<ClInclude Include="logger.h" />
<ClInclude Include="namespace.h" />
diff --git a/api/api.vcxproj.filters b/api/api.vcxproj.filters
index 090a1ef..c585527 100644
--- a/api/api.vcxproj.filters
+++ b/api/api.vcxproj.filters
@@ -52,9 +52,6 @@
<ClInclude Include="wintun.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="atomic.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="elevate.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/api/atomic.h b/api/atomic.h
deleted file mode 100644
index 011e53b..0000000
--- a/api/atomic.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0
- *
- * Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
- */
-
-#pragma once
-
-#include <Windows.h>
-
-static __forceinline VOID
-InterlockedSetU(_Inout_ _Interlocked_operand_ ULONG volatile *Target, _In_ ULONG Value)
-{
- *Target = Value;
-}
-
-static __forceinline LONG
-InterlockedGet(_In_ _Interlocked_operand_ LONG volatile *Value)
-{
- return *Value;
-}
-
-static __forceinline ULONG
-InterlockedGetU(_In_ _Interlocked_operand_ ULONG volatile *Value)
-{
- return *Value;
-}
diff --git a/api/pch.h b/api/pch.h
index bb5b3a1..45bf3b1 100644
--- a/api/pch.h
+++ b/api/pch.h
@@ -6,7 +6,6 @@
#pragma once
#include "adapter.h"
-#include "atomic.h"
#include "api.h"
#include "elevate.h"
#include "logger.h"
diff --git a/api/session.c b/api/session.c
index 71849c3..e39f21b 100644
--- a/api/session.c
+++ b/api/session.c
@@ -172,7 +172,7 @@ WintunReceivePacket(_In_ TUN_SESSION *Session, _Out_bytecapcount_(*PacketSize) B
Result = ERROR_HANDLE_EOF;
goto cleanup;
}
- const ULONG BuffTail = InterlockedGetU(&Session->Descriptor.Send.Ring->Tail);
+ const ULONG BuffTail = ReadULongAcquire(&Session->Descriptor.Send.Ring->Tail);
if (BuffTail >= Session->Capacity)
{
Result = ERROR_HANDLE_EOF;
@@ -226,7 +226,7 @@ WintunReceiveRelease(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet)
Session->Send.HeadRelease = TUN_RING_WRAP(Session->Send.HeadRelease + AlignedPacketSize, Session->Capacity);
Session->Send.PacketsToRelease--;
}
- InterlockedSetU(&Session->Descriptor.Send.Ring->Head, Session->Send.HeadRelease);
+ WriteULongRelease(&Session->Descriptor.Send.Ring->Head, Session->Send.HeadRelease);
LeaveCriticalSection(&Session->Send.Lock);
}
@@ -241,7 +241,7 @@ WintunAllocateSendPacket(_In_ TUN_SESSION *Session, _In_ DWORD PacketSize, _Out_
goto cleanup;
}
const ULONG AlignedPacketSize = TUN_ALIGN(sizeof(TUN_PACKET) + PacketSize);
- const ULONG BuffHead = InterlockedGetU(&Session->Descriptor.Receive.Ring->Head);
+ const ULONG BuffHead = ReadULongAcquire(&Session->Descriptor.Receive.Ring->Head);
if (BuffHead >= Session->Capacity)
{
Result = ERROR_HANDLE_EOF;
@@ -281,8 +281,8 @@ WintunSendPacket(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet)
TUN_RING_WRAP(Session->Receive.TailRelease + AlignedPacketSize, Session->Capacity);
Session->Receive.PacketsToRelease--;
}
- InterlockedSetU(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
- if (InterlockedGet(&Session->Descriptor.Receive.Ring->Alertable))
+ WriteULongRelease(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
+ if (ReadAcquire(&Session->Descriptor.Receive.Ring->Alertable))
SetEvent(Session->Descriptor.Receive.TailMoved);
LeaveCriticalSection(&Session->Receive.Lock);
}