Commit Graph

390 Commits

Author SHA1 Message Date
Ryan Prichard
7c12d90086 Get the tests running inside the WOW64 environment on pre-Win7 OSs
Prior to Windows 7, the undocumented NtQuerySystemInformation API did
not return valid handle information when called by a WOW64 process.  To
work around this problem, the 32-bit test program connects to a 64-bit
worker and uses the existing RPC mechanism, issuing LookupKernelObject
commands, which call NtQuerySystemInformation in a native 64-bit
environment.

Even on Windows 7, the NtQuerySystemInformation API returns truncated
kernel object pointers, so, AFAIK, we still need to do this work. Maybe
not, though, if the lower 32 bits are guaranteed to be unique.

On Windows 10, there is a CompareObjectHandles API that works in WOW64
mode.
2015-10-27 13:19:42 -05:00
Ryan Prichard
72c5ea52fd Fixes and comments to Test_CreateProcess_Duplicate_PseudoHandleBug
It seems that this bug was fixed in WOW64 prior to its fixing in the
normal environment.

It makes no sense to run Test_CreateProcess_Duplicate_PseudoHandleBug_IL
on OS's that don't have inherit lists.
2015-10-26 18:42:06 -05:00
Ryan Prichard
b95da0a6d8 Document my theory for the CONOUT$ Win7 bug and add a safe-ish? testcase. 2015-10-26 17:39:04 -05:00
Ryan Prichard
116f3402ba Make the Windows 7 note a bit clearer. 2015-10-26 13:09:08 -05:00
Ryan Prichard
a7feca65a7 Consolidate InheritList tests, expand them, document the semantics.
Provide a way to test for UpdateProcThreadAttribute failures, because
trying to create an empty inherit list seems interesting to me.
2015-10-26 11:53:39 -05:00
Ryan Prichard
29b9ebbc2e Add Test_AttachConsole_AllocConsole_StdHandles trad + modern tests. 2015-10-26 01:14:23 -05:00
Ryan Prichard
4a67a2073e Suppress tests; XP doesn't have inherit lists 2015-10-25 23:38:51 -05:00
Ryan Prichard
37b467c2c5 Test with both CREATE_NEW_CONSOLE and CREATE_NO_WINDOW as the default.
Also fix a problem with a 0xdeadbeef handle.
2015-10-25 23:28:34 -05:00
Ryan Prichard
6f77ca472d CreateProcess can duplicate standard handles in another instance 2015-10-25 23:18:03 -05:00
Ryan Prichard
649bdad6e2 Documentation updates 2015-10-25 20:54:50 -05:00
Ryan Prichard
ff5be78af6 Rename the "default inheritance" concept to "duplicate". 2015-10-25 20:36:01 -05:00
Ryan Prichard
0b2e0c20ee Document DETACHED_PROCESS behavior and add a test for it. 2015-10-25 20:30:21 -05:00
Ryan Prichard
45a38be9e4 Add a simple test for the CreateProcess NewConsole standard handle case.
Simplify checkModernConsoleHandleInit usage; it isn't necessary to build
a list of potential console handles.  We can just scan for them.
2015-10-25 19:50:57 -05:00
Ryan Prichard
7ad3f28f48 Rewording in console-handles.md. 2015-10-25 19:35:30 -05:00
Ryan Prichard
ae8a725170 Refactor Test_CreateProcess_UseStdHandles to better follow spec. 2015-10-25 19:15:46 -05:00
Ryan Prichard
4b76f1e3a7 Rework standard handle setting in CreateProcess documentation.
I don't *think* this changes the semantics at all.

Also, move the INVALID_HANDLE_VALUE thing into a note at the bottom.

Improve intra-document bug linking.
2015-10-25 18:56:22 -05:00
Ryan Prichard
955b5c61c3 Fix CreateProcess_UseStdHandles on Win8 and fix the spec.
* The NULL-to-new-handle conversion only happens when creating a new
   console, not when attaching to the parent's console.

 * Also, Windows reports that the handle value 0x7 is value, presumably
   because it ignores the lowest 2 bits.  It's better to just remove those
   values from this test.
2015-10-25 17:37:06 -05:00
Ryan Prichard
9260d0b54e If Test_CreateProcess_DefaultInherit fails, don't ASSERT-fail. 2015-10-25 16:56:45 -05:00
Ryan Prichard
f4a3bd1743 Fill out CreateProcess UseStdHandles testing.
There's just one test, and it iterates over these combinations:
 - CreationConsoleMode=NewConsole and CreationConsoleMode=Inherit
 - bInheritHandles=FALSE and bInheritHandles=TRUE

It takes several seconds to run, but that's OK.
2015-10-25 16:56:38 -05:00
Ryan Prichard
8ed8bac96b Add tests for CreateProcess UseStdHandles !InheritHandles 2015-10-25 14:14:28 -05:00
Ryan Prichard
5dc88b1a3e Refactor scanForConsoleHandles
* Fix a compiler warning about uint->HANDLE conversion on x64.

 * Use isModernConio
2015-10-25 12:04:31 -05:00
Ryan Prichard
28f11b7f9b Speed handle object comparison by reducing NtQuerySystemInformation calls 2015-10-25 11:51:28 -05:00
Ryan Prichard
ac238429fc Speed up compareObjectHandles by about 2x on pre-Windows10 2015-10-25 10:39:07 -05:00
Ryan Prichard
0483e2f870 Split off Test_CreateProcess_DefaultInherit_PseudoHandleBug 2015-10-25 02:35:04 -05:00
Ryan Prichard
11cccfa4ae Split off two CreateProcess tests.
* Add CreateProcess_DefaultInherit

 * Add CreateProcess_DefaultInherit_XPPipeBug
2015-10-25 02:09:59 -05:00
Ryan Prichard
a17fac4e5a Switch to individual test registration. 2015-10-25 01:45:24 -05:00
Ryan Prichard
7bdbce5e2c Reorganize the handle tests. 2015-10-25 01:30:32 -05:00
Ryan Prichard
84e6822635 Rename SpecialInherit to DefaultInherit and add another test case
* Improve documentation for default inheritance mode, esp. w.r.t.
   console handles.
2015-10-25 00:28:58 -05:00
Ryan Prichard
7dd8e67ea9 Split common CreateProcess tests into a separate file. 2015-10-24 23:34:50 -05:00
Ryan Prichard
7c5c22c007 Clarifications to console-handles.md. 2015-10-24 05:17:50 -05:00
Ryan Prichard
1c88b71ec0 For the XP bug, also demonstrate that the write end of the pipe works. 2015-10-24 04:21:09 -05:00
Ryan Prichard
5917ff60a7 On Win10, replace NtQuerySystemInformation with CompareObjectHandles
* CompareObjectHandles is a documented API, and presumably it could be
   faster.  The tests actually do run a little faster now on Win10,
   dropping from 6.5sec to 3.6sec or so.

 * Also make the NtQuerySystemInformation buffer static so we don't have to
   repeat the double-buffer-in-a-loop process on every ntHandlePointer
   call.
2015-10-24 04:14:25 -05:00
Ryan Prichard
9b4155eccc Add a test for what seems to be an obscure Windows XP bug.
* The read end of a pipe is translated to NULL by the special
   bInheritHandles=FALSE, no-STARTF_USESTDHANDLES inheritance mode.  The
   write end of the pipe works fine.

 * Passing bInheritHandles=TRUE with an inheritable pipe handle fixes it.
   Adding STARTF_USESTDHANDLES to this also works.
2015-10-24 04:06:46 -05:00
Ryan Prichard
51e84a50d4 Reword a comment. 2015-10-24 02:34:00 -05:00
Ryan Prichard
f635afacaf Windows 8.1 fixed the INVALID_HANDLE_VALUE --> process handle bug.
* To version detect 8.1, we need GetVersionEx to return something greater
   than Windows 8, which requires creating an app manifest.  For now at
   least, put the manifest XML next to the EXE.  It can be built into the
   EXE, but this is good enough (at least for now).
2015-10-24 02:31:46 -05:00
Ryan Prichard
18f23f38c0 Checkpoint work on traditional and common tests.
* Add Test_CreateProcess_SpecialInherit

 * Add traditional Test_HandleDuplication

 * Make handle.dup() use a GetCurrentProcess() target while
   handle.dup(handle.worker()) uses a non-pseudo handle.
2015-10-24 01:58:16 -05:00
Ryan Prichard
7de7c6f76b Clarify document a bit. 2015-10-23 23:41:24 -05:00
Ryan Prichard
43db1ac585 Fix a couple of typos, reword a test comment, add a TODO comment. 2015-10-23 23:27:02 -05:00
Ryan Prichard
7e7b992cd6 Checkpoint a lot of work on the console-handles.md document. 2015-10-23 23:27:00 -05:00
Ryan Prichard
f22f856205 For brevity, add a special SpawnParams ctor for STARTF_USEHANDLES. 2015-10-23 23:27:00 -05:00
Ryan Prichard
2bb1ca205d Improve RemoteWorker and Event ctors.
* Allow creating a RemoteWorker object without spawning a new worker.
   It can be used like so:

   {
       Worker w(Worker::DoNotSpawn);
       if (...) {
           w = ...;
       } else {
           w = ...;
       }
   }

 * Remove the weird RemoteWorker(std::string) ctor.  The computation of the
   worker name should be inside the ctor.

 * It now becomes possible to initialize a RemoteWorker using syntax like:
      Worker w({ true, 0 });
   However, these are still ambiguous:
      Worker w({})  // could be move-init from a default-init Worker
      Worker w({1}) // could be move-init from a Worker(SpawnParams{1})

 * Make the Event ctor explicit.  The SpawnParams ctor needs to be
   non-explicit so it can be used with the braced initializer list.
2015-10-23 23:26:59 -05:00
Ryan Prichard
bbbea127e9 Remove a check from Test_InheritNothing so it works with CREATE_NO_WINDOW
* With this change, RemoteWorker can default to CREATE_NO_WINDOW instead
   of CREATE_NEW_CONSOLE, and the tests all still pass.
2015-10-23 23:26:58 -05:00
Ryan Prichard
2b146e9173 Expand common tests and refactor some code.
* Add Test_Active_ScreenBuffer_Order

 * Add Test_GetStdHandle_SetStdHandle

 * Also test a STARTF_USESTDHANDLES process in
   Test_Detach_Does_Not_Change_Standard_Handles.
2015-10-23 23:24:48 -05:00
Ryan Prichard
8e4b78c40b Test bInheritHandles=FALSE and PROC_THREAD_ATTRIBUTE_HANDLE_LIST combo.
* The API call fails.

 * Also refactor the PROC_THREAD_ATTRIBUTE_HANDLE_LIST tests a little.
2015-10-23 04:32:10 -05:00
Ryan Prichard
aec5e552b6 Expand common tests:
* Test combos of CREATE_NEW_CONSOLE, DETACHED_PROCESS, CREATE_NO_WINDOW.

 * Test use of PROC_THREAD_ATTRIBUTE_HANDLE_LIST.  It cannot be used with
   GetCurrentProcess(), but it also can't be used with traditional
   console handles.

 * Prefer nullptr over INVALID_HANDLE_VALUE.  Change ntHandlePointer.
2015-10-23 03:44:27 -05:00
Ryan Prichard
b3e95cd7de Start reorganizing the TestHandleInheritance test 2015-10-23 02:00:16 -05:00
Ryan Prichard
83c5e6de18 Propagate spawn GetLastError() so it can checked; print nice error messages 2015-10-23 00:00:37 -05:00
Ryan Prichard
1b71ef07cc Support PROC_THREAD_ATTRIBUTE_HANDLE_LIST and testing for spawn failure
* Also add a public Worker::exit() for killing workers more conveniently.

 * Previously, a Worker was either:
     (1) fully initialized and running (m_valid==true), or
     (2) moved out of (m_valid==false)
   Now RemoteWorker::trySpawn() can return an invalid RemoteWorker object.
2015-10-23 00:00:36 -05:00
Ryan Prichard
5ef3aa3a0b Remove an unnecessary line from the Vista BSOD test case. 2015-10-23 00:00:35 -05:00
Ryan Prichard
af9e06a71d Log the pipe handles in newPipe, and close the pipes in the host process 2015-10-23 00:00:34 -05:00