api: use proper iso atomic semantics
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b4a1494fb2
commit
f947205cee
@ -146,6 +146,7 @@
|
|||||||
<PreprocessorDefinitions Condition="Exists('$(OutDir)whql\')">HAVE_WHQL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions Condition="Exists('$(OutDir)whql\')">HAVE_WHQL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<AdditionalOptions>/volatile:iso %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ResourceCompile>
|
<ResourceCompile>
|
||||||
<AdditionalIncludeDirectories>..\$(Configuration)\$(WintunPlatform);..\$(Configuration);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\$(Configuration)\$(WintunPlatform);..\$(Configuration);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
@ -194,7 +195,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="api.h" />
|
<ClInclude Include="api.h" />
|
||||||
<ClInclude Include="adapter.h" />
|
<ClInclude Include="adapter.h" />
|
||||||
<ClInclude Include="atomic.h" />
|
|
||||||
<ClInclude Include="elevate.h" />
|
<ClInclude Include="elevate.h" />
|
||||||
<ClInclude Include="logger.h" />
|
<ClInclude Include="logger.h" />
|
||||||
<ClInclude Include="namespace.h" />
|
<ClInclude Include="namespace.h" />
|
||||||
|
@ -52,9 +52,6 @@
|
|||||||
<ClInclude Include="wintun.h">
|
<ClInclude Include="wintun.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="atomic.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="elevate.h">
|
<ClInclude Include="elevate.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
26
api/atomic.h
26
api/atomic.h
@ -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;
|
|
||||||
}
|
|
@ -6,7 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "adapter.h"
|
#include "adapter.h"
|
||||||
#include "atomic.h"
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
#include "elevate.h"
|
#include "elevate.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
@ -172,7 +172,7 @@ WintunReceivePacket(_In_ TUN_SESSION *Session, _Out_bytecapcount_(*PacketSize) B
|
|||||||
Result = ERROR_HANDLE_EOF;
|
Result = ERROR_HANDLE_EOF;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
const ULONG BuffTail = InterlockedGetU(&Session->Descriptor.Send.Ring->Tail);
|
const ULONG BuffTail = ReadULongAcquire(&Session->Descriptor.Send.Ring->Tail);
|
||||||
if (BuffTail >= Session->Capacity)
|
if (BuffTail >= Session->Capacity)
|
||||||
{
|
{
|
||||||
Result = ERROR_HANDLE_EOF;
|
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.HeadRelease = TUN_RING_WRAP(Session->Send.HeadRelease + AlignedPacketSize, Session->Capacity);
|
||||||
Session->Send.PacketsToRelease--;
|
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);
|
LeaveCriticalSection(&Session->Send.Lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ WintunAllocateSendPacket(_In_ TUN_SESSION *Session, _In_ DWORD PacketSize, _Out_
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
const ULONG AlignedPacketSize = TUN_ALIGN(sizeof(TUN_PACKET) + PacketSize);
|
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)
|
if (BuffHead >= Session->Capacity)
|
||||||
{
|
{
|
||||||
Result = ERROR_HANDLE_EOF;
|
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);
|
TUN_RING_WRAP(Session->Receive.TailRelease + AlignedPacketSize, Session->Capacity);
|
||||||
Session->Receive.PacketsToRelease--;
|
Session->Receive.PacketsToRelease--;
|
||||||
}
|
}
|
||||||
InterlockedSetU(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
|
WriteULongRelease(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
|
||||||
if (InterlockedGet(&Session->Descriptor.Receive.Ring->Alertable))
|
if (ReadAcquire(&Session->Descriptor.Receive.Ring->Alertable))
|
||||||
SetEvent(Session->Descriptor.Receive.TailMoved);
|
SetEvent(Session->Descriptor.Receive.TailMoved);
|
||||||
LeaveCriticalSection(&Session->Receive.Lock);
|
LeaveCriticalSection(&Session->Receive.Lock);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user