ReactOS 0.4.16-dev-106-g10b08aa
util.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS DC21x4 Driver
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Utility header file
5 * COPYRIGHT: Copyright 2023 Dmitry Borisov <di.sean@protonmail.com>
6 */
7
8#pragma once
9
10#include <pshpack1.h>
11typedef struct _ETH_HEADER
12{
17#include <poppack.h>
18
19#define ETH_IS_LOCALLY_ADMINISTERED(Address) \
20 ((BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x02)))
21
22#define ETH_IS_EMPTY(Address) \
23 ((BOOLEAN)((((PUCHAR)(Address))[0] | ((PUCHAR)(Address))[1] | ((PUCHAR)(Address))[2] | \
24 ((PUCHAR)(Address))[3] | ((PUCHAR)(Address))[4] | ((PUCHAR)(Address))[5]) == 0))
25
26#if defined(_M_IX86) || defined(_M_AMD64)
27/* Strict memory model, does not reorder Write-Write operations */
28#define DC_WRITE_BARRIER() KeMemoryBarrierWithoutFence()
29#else
30#define DC_WRITE_BARRIER() KeMemoryBarrier()
31#endif
32
33#if defined(_MSC_VER)
34/*
35 * Merge with PAGE, we don't need a new pageable section. For a small amount of data,
36 * there is additional size overhead if the actual data size is smaller than section alignment.
37 * GCC doesn't seem to appreciate this idea.
38 */
39#define DC_PG_DATA DATA_SEG("PAGE")
40#else
41#define DC_PG_DATA
42#endif
43
44/* Access to unaligned memory */
48 _In_ const VOID* Data)
49{
50#if defined(_M_IX86) || defined(_M_AMD64)
51 /* Supported by ISA */
52 return *(const UNALIGNED USHORT*)Data;
53#else
55
56 NdisMoveMemory(&Result, Data, sizeof(Result));
57 return Result;
58#endif
59}
60
61#if DBG
62#define DcPopEntryList PopEntryList
63#else
64/*
65 * This is an optimized version of the PopEntryList() function.
66 * We assume that the next entry has already been checked for nullability
67 * so we don't need to.
68 */
73{
74 PSINGLE_LIST_ENTRY FirstEntry;
75
76 FirstEntry = ListHead->Next;
77
78 ASSERT(FirstEntry);
79
80 ListHead->Next = FirstEntry->Next;
81
82 return FirstEntry;
83}
84#endif
#define UNALIGNED
Definition: crtdefs.h:144
FORCEINLINE USHORT DcRetrieveWord(_In_ const VOID *Data)
Definition: util.h:47
struct _ETH_HEADER ETH_HEADER
FORCEINLINE PSINGLE_LIST_ENTRY DcPopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: util.h:71
struct _ETH_HEADER * PETH_HEADER
#define ETH_LENGTH_OF_ADDRESS
Definition: efilter.h:16
#define ASSERT(a)
Definition: mode.c:44
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define NdisMoveMemory(Destination, Source, Length)
Definition: ndis.h:3896
unsigned short USHORT
Definition: pedump.c:61
UCHAR Destination[ETH_LENGTH_OF_ADDRESS]
Definition: util.h:13
UCHAR Source[ETH_LENGTH_OF_ADDRESS]
Definition: util.h:14
USHORT PayloadType
Definition: util.h:15
Definition: ntbasedef.h:628
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
#define FORCEINLINE
Definition: wdftypes.h:67
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181