Commit Graph

398 Commits

Author SHA1 Message Date
Jason A. Donenfeld
53332cd078 installer: improve resource freeing flow
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-04 08:52:58 +00:00
Jason A. Donenfeld
736131960f msi-example: add instructions and sample code 2019-09-18 15:19:09 -06:00
Simon Rozman
af580a57af Stop timestamping test-signed binaries
WDK doesn't timestamp test-signed drivers. Neither should we.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-09-02 10:10:03 +02:00
Jason A. Donenfeld
c072f4f3c4 Explicitly opt-in to READ_ONCE/WRITE_ONCE semantics
We mark all atomic variables as volatile and have our atomic accessors
built around that. We probably, therefore, want Linux-style
READ/WRITE_ONCE semantics of implying memory barriers. /volatile:ms does
this automatically.

This was already the default on amd64 and x86 but not on ARM.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reported-by: Lev Stipakov <lstipakov@gmail.com>
2019-08-24 12:26:00 +00:00
Jason A. Donenfeld
e8e5a42e98 README: clarify spinning
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-22 11:27:57 +02:00
Simon Rozman
fa715c4863 Use WiX directly rather than via WiX's MSBuild
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-05 17:14:27 +02:00
Jason A. Donenfeld
03f356c492 Dynamically gather signtool full path
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-05 14:08:06 +02:00
Simon Rozman
810d2ac73a Unify XML empty-element spacing
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-05 09:45:52 +02:00
Jason A. Donenfeld
c9da443273 Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 15:29:48 +00:00
Jason A. Donenfeld
5b872e8cf9 Use performance counter for less spinning
Previously we had to spin for a minimum of 15ms because the tick
interval is 156250 on NT. On linux, usually trips to the high
performance timers are discouraged because if they don't hit the RDTSC
path (due to being unstable or the like), they hit more expensive
hardware. I assume that's probably the same on NT, but all of tcpip.sys
and ndis.sys uses the performance counters too, so what are we going to
do?

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 11:13:39 +00:00
Jason A. Donenfeld
85a8076d08 Spin less and more efficiently
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 07:06:50 +00:00
Jason A. Donenfeld
bc22e2dd25 GetCurrentProcessToken() is Win8+, so open our own token
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-03 08:46:21 +00:00
Jason A. Donenfeld
0e5c1a7a94 Shorten README
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 17:21:26 +02:00
Jason A. Donenfeld
fb68232f16 Free interface list when aborting in installer
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 13:24:21 +02:00
Jason A. Donenfeld
71afd84033 Document how to get file handle
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 13:22:35 +02:00
Simon Rozman
cd6fe285b4 Cleanup NBL reference counting
The Empty event state is now set according to
Ctx->Device.Receive.ActiveNbls.Head != NULL. But, we still have to clear
the Empty event inside the TransitionLock to prevent race with
TunPause().

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 12:25:22 +02:00
Simon Rozman
408665270f Skip packet on NBL allocation failure properly
Should NBL allocation persist to fail, the receive ring could eventually
fill up as there will be no TunReturnNetBufferLists() calls to advance
its head.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 12:04:02 +02:00
Jason A. Donenfeld
9d71da2d37 Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 11:57:30 +02:00
Jason A. Donenfeld
366aaf2820 Rearrange README and add additional MSM info
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 11:57:30 +02:00
Jason A. Donenfeld
47a2a980a8 Do not rebuild driver on installer library build
This commit is in many ways wrong, but when we're dealing with whql
imports, there's often a large gap in time, and it's useful to be able
to just restore everything exactly how it was prior and then build only
installer.dll and the msm.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Simon Rozman
799413a776 Use reference counter and KEVENT instead of remove locks
Driver verifier doesn't like re-initializing remove locks.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
9e9f1ac9b3 Rearrange comment to make clang-format happy
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
a2d46f3c00 Disable APC when taking rwlock
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Simon Rozman
ac3576a57e Unify driver input file list
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Simon Rozman
afdbc75bf9 Resolve SDV reported "defect"
NdisMGetDeviceProperty() should always return non-NULL
FunctionalDeviceObject according to _Outptr_opt_. An explicit
FunctionalDeviceObject NULL check has been added to keep the SDV happy
and not calling our driver "defective".

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Simon Rozman
b666f587d5 Add SDVView target
This invokes SDV GUI for easier review of SDV reported defects.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
28ba2d4600 Separate out atomic helpers
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
22e2da002d Rewrite installer logic in C
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
18cfd522aa Use explicit running boolean and use set instead of exchange
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-31 13:59:54 +00:00
Simon Rozman
999a6744db Assert that adapter is always running when client is registering rings
By attaching to NDIS device instead of creating our own device for I/O,
the adapter is always running before client is able to connect and
register rings. NDIS also won't allow adapter to pause with connected
clients.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:54 +00:00
Simon Rozman
7f49a66494 Cleanup TUN_FLAGS_PRESENT
With no PnP notifications and custom surprise removal code we do not
need the TUN_FLAGS_PRESENT any more. The traffic is stopped when handle
is closed or adapter is somehow paused. Though by reusing the NDIS device
for our I/O, the adapter will not be able to pause with a client
connected.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:54 +00:00
Jason A. Donenfeld
5239d53db0 Add handle closing ioctl
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-31 13:59:54 +00:00
Simon Rozman
0d9b9b925a Reinitialize active NBL remove lock to allow adapter reuse
Before the TunProcessReceiveData() thread terminates or adapter is
paused, we wait for all receive NBLs to be returned. Unfortunately,
IoReleaseRemoveLockAndWait() leaves the remove lock in non reusable
state.

To be able to start receiving packets on existing adapter again, we
(re)initialize the remove lock on ring registration or adapter resume.
The former addresses TunProcessReceiveData()'s
IoReleaseRemoveLockAndWait() call, the later addresses the TunPause()'s.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:46 +00:00
Jason A. Donenfeld
f48b0b2883 Compile on 32-bit and arm64
No popcnt intrinsic on arm, no PopulationCount64 function on 32bit.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-19 10:28:02 +00:00
Jason A. Donenfeld
970e22d8e4 Use more specific IOCTL code
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-19 06:31:26 +00:00
Jason A. Donenfeld
6ebdbf77d2 Require the usual SDDL_DEVOBJ_SYS_ALL permissions
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 19:35:41 +00:00
Simon Rozman
14e5532dc8 Make receiving NBLs asynchronous
This commit moves NBL post-processing (moving ring head, releasing NBL)
to MINIPORT_RETURN_NET_BUFFER_LISTS handler.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18 15:27:18 +02:00
Simon Rozman
f5eadb50c4 Minimize TransitionLock when receiving packets
We do not need to share-lock the TransitionLock for the whole life of
receiver thread.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18 14:53:38 +02:00
Jason A. Donenfeld
9bf25d873b Fix insane coding style
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 12:49:32 +00:00
Jason A. Donenfeld
cdf0d0bf9a Fix awkward comment style
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 12:45:34 +00:00
Jason A. Donenfeld
5502b77218 Do not hijack PNP notifier
We no longer pend send-side NBLs, so we don't have a real use for this.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 12:41:04 +00:00
Jason A. Donenfeld
aac642e3dc Switch to paged dispatch handlers
We're not totally sure this is kosher, unfortunately.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 11:28:25 +00:00
Simon Rozman
043abc0a8e Minimize TransitionLock when sending packets
We do not need to share-lock the TransitionLock for complete NBL chain.
This commit should improve better state transition response, thou until
NDIS is sending a single NBL per MINIPORT_SEND_NET_BUFFER_LISTS call,
this should not have a considerable effect.

Since the skibNbl: call of NdisMSendNetBufferListsComplete() is made
inside the TransactionLock at dispatch IRQL, a dispatch IRQL hint was
added to the NdisMSendNetBufferListsComplete() call.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18 13:52:16 +02:00
Jason A. Donenfeld
58ce3c5000 Piggy-back on top of NDIS' device object instead of adding our own
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 10:34:38 +00:00
Jason A. Donenfeld
bf51c91e3e README: clarify ring usage
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-17 21:13:39 +00:00
Simon Rozman
82ede2f96d Replace TUN_FLAGS_CONNECTED by an event
On client closing the handle there is a potential race if somebody
resets the TailMoved event of receive ring at the right time. Rather
than rely on TailMoved event, we introduce our own Disconnected
notification event and have the receive thread wait on both. The
Disconnected  event is also usable as TUN_FLAGS_CONNECTED substitute.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-17 14:53:09 +02:00
Simon Rozman
e7fad38a07 Improve lock retention when sending
NDIS may call MINIPORT_SEND_NET_BUFFER_LISTS from parallel threads to
queue as many packets as fast as possible. Initial implementation of
ring buffers used a spin lock to completely serialize sending packets
making it sub-optimal and burning large amount of CPU.

This commit uses locked section to allocate space for packet(s) in the
ring. It copies the packets unlocked, then it locks again to adjust the
ring tail.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-17 12:22:48 +02:00
Jason A. Donenfeld
1914547ab3 Spin for a bit before falling back to event object
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-17 10:17:46 +00:00
Simon Rozman
66e51bd08f Switch to ring buffers for exchanging packets
This demonstrates the use of ring buffers in its simplest, purest form.
No performance optimizations were made.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-16 20:06:54 +00:00
Jason A. Donenfeld
830df36cd3 README: correct path of device
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reported-by: Shay Sharon <Shay.Sharon@audiocodes.com>
2019-07-09 11:10:17 +02:00