Test kitchen doesn't retry when using reboot in Server 2012R2 - chef-recipe

My cookbook requires the guest to restart after installing WMF5 on Windows Server 2012R2.
reboot 'Reboot Windows' do
action :nothing
end
chocolatey 'DotNet4.5.1' do
version '4.5.1.20140606'
action :install
end
chocolatey 'Powershell' do
version '5.0.10586.20161027'
action :install
options ({ '-ignore-package-exit-codes' => '' })
end
powershell_script 'Reboot if PowerShell v4' do
notifies :reboot_now, 'reboot[Reboot Windows]', :immediately
only_if { reboot_pending? }
end
When the reboot occurs, test kitchen will then exit out without attempting to converge again. I am also unable to see an exit code.
D [WinRM] Waiting for output...
D [WinRM] Processing output
- execute the ruby block track-path-Powershell
* powershell_script[Reboot if PowerShell v4] action run
- execute "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20161212-936-452h54.ps1"
* reboot[Reboot Windows] action reboot_now[2016-12-12T15:44:04-05:00] WARN: Rebooting system immediately, requested by 'Reboot Windows'
Running handlers:
Running handlers complete
Chef Client finished, 54/140 resources updated in 02 minutes 46 seconds
[2016-12-12T15:44:04-05:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2016-12-12 15:44:04 -0500, :requested_by=>"Reboot Windows"}
D [WinRM] Waiting for output...
D [WinRM] Processing output
D [WinRM] cleaning up command_id: 737D4041-AE48-4403-ADEC-840D31B1FE0E on shell_id B4370D6D-AE03-46E3-9823-EFB3EF2EA14C
$$$$$$ DL is deprecated, please use Fiddle
D Cleaning up local sandbox in C:/Users/lsmit648/AppData/Local/Temp/default-windows2012r2min-sandbox-20161212-12432-rf5u0f
Finished converging <default-windows2012r2min> (3m19.06s).
-----> Kitchen is finished. (3m58.02s)
Here is my .kitchen.yaml file
---
driver:
name: vagrant
provider: virtualbox
gui: false
box_check_update: true
vm_hostname: false
communicator: winrm
guest: windows
customize:
natdnshostresolver1: 'on'
natdnsproxy1: 'on'
usb: 'off'
reset_command: "exit 0"
username: 'vagrant'
password: 'vagrant'
winrm:
boot_timeout: 600
max_tries: 500
# https://github.com/chef/chef-dk/issues/1009#issuecomment-246875683
transport:
name: winrm
username: 'vagrant'
password: 'vagrant'
elevated: true
provisioner:
name: chef_zero
retry_on_exit_code:
- [35, 1]
max_retries: 5
wait_for_retry: 60
client_rb:
exit_status: :enabled
verifier:
name: inspec
platforms:
- name: windows2012.r2.min
transport:
port: 5985
os_type: windows
shell_type: powershell
driver:
box: windows2012.r2.min
box_url: <%= ENV['VAGRANT_BOX_REPOSITORY'] %>/windows2012.r2min.json
port: 5985
winrm:
guest_port: 5985
network:
- ['forwarded_port', {guest: 3389, host: 9561, id: 'rdp', auto_correct: true}]
- ['forwarded_port', {guest: 5985, host: 9571, id: 'winrm', auto_correct: true}]
suites:
- name: default
run_list:
- recipe[chocolatey::default]
- recipe[wmf_5]
- recipe[roles_features]
How can I capture the exit code that reboot is using in order to have kitchen attempt to converge again?

Figured out the problem.
The chef client that was being installed by default was 12.8.1
I needed to have a min version of 12.11 for the exit codes to be returned correctly

Related

Commands not recognised in GitHub Action Mocha tests

My unit tests pass when run locally. When executed by a GitHub Action when a branch is committed, this action
on:
push:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
- '!master' # excludes master
workflow_dispatch:
inputs:
build:
description: Unit tests
type: boolean
required: true
default: "true"
jobs:
build:
strategy:
matrix:
os: [windows-latest]
# os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Install Node.js
uses: actions/setup-node#v1
with:
node-version: 16.x
- run: npm install
- run: npm i gulp gulp-cli -g
if: runner.os == 'MacOS'
- run: gulp
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'
basically runs npm test.
When I do that locally, it works fine:
npm test
> vscode-print#0.9.25 test
> node ./out/test/runTest.js
Debugger listening on ws://127.0.0.1:63067/252bd7f9-c748-45b4-b9e6-8ba21e9fc909
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Found existing install in C:\Users\Peter\source\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1. Skipping download
[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.
[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.
[main 2022-07-03T14:02:28.455Z] update#ctor - updates are disabled by the environment
[main 2022-07-03T14:02:29.679Z] Starting extension host with pid 32 (fork() took 15 ms).
Loading development extension at c:\Users\Peter\source\vsc-print
Decryption failed
Print Extension Test Suite
✔ Check platform browser launch command on win32 (200ms)
✔ Check platform alternate browser launch command on win32 (112ms)
✔ Print active editor (304ms)
Could not find the language 'jsonc', did you forget to load/include a language module?
✔ Print folder (812ms)
4 passing (2s)
[main 2022-07-03T14:02:32.887Z] Extension host with pid 32 exited with code: 0, signal: null.
Exit code: 0
Done
Waiting for the debugger to disconnect...
When the Action runs it, this is the output.
Downloaded VS Code into D:\a\vsc-print\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1
[main 2022-07-03T13:06:32.496Z] update#ctor - updates are disabled by the environment
workbench#open()
[main 2022-07-03T13:06:37.868Z] Calling fork to start extension host...
[main 2022-07-03T13:06:37.879Z] Starting extension host with pid 776 (fork() took 11 ms).
IExtensionHostStarter.start() took 42 ms.
Loading development extension at d:\a\vsc-print\vsc-print
Print Extension Test Suite
1) Check platform browser launch command on win32
Error: 4 tests failed.
2) Check platform alternate browser launch command on win32
3) Print active editor
at d:\a\vsc-print\vsc-print\out\test\suite\index.js:25:27
4) Print folder
at done (d:\a\vsc-print\vsc-print\node_modules\mocha\lib\mocha.js:1009:7)
0 passing (518ms)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
4 failing
1) Print Extension Test Suite
Check platform browser launch command on win32:
Error: command 'extension.test.browserLaunchCommand' not found
at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
2) Print Extension Test Suite
Check platform alternate browser launch command on win32:
Error: command 'extension.test.browserLaunchCommand' not found
at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
3) Print Extension Test Suite
Print active editor:
Error: command 'extension.test.flags' not found
at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
4) Print Extension Test Suite
Print folder:
Error: command 'extension.test.flags' not found
at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
[main 2022-07-03T13:06:41.294Z] Waiting for extension host with pid 776 to exit.
[main 2022-07-03T13:06:41.330Z] Extension host with pid 776 exited with code: 1, signal: null.
Exit code: 1
Failed
Failed to run tests
Error: Process completed with exit code 1.
The unrecognised commands are registered near the start of the extension's activation event.
export function activate(context: vscode.ExtensionContext) {
let ecmPrint = vscode.workspace.getConfiguration("print", null).editorContextMenuItemPosition,
etmButton = vscode.workspace.getConfiguration("print", null).editorTitleMenuButton,
disposable: vscode.Disposable;
vscode.commands.executeCommand("setContext", "ecmPrint", ecmPrint);
vscode.commands.executeCommand("setContext", "etmButton", etmButton);
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(checkConfigurationChange));
context.subscriptions.push(vscode.commands.registerCommand("extension.print", printCommand));
context.subscriptions.push(vscode.commands.registerCommand("extension.printFolder", printFolderCommand));
context.subscriptions.push(vscode.commands.registerCommand("extension.test.flags", () => testFlags));
context.subscriptions.push(vscode.commands.registerCommand("extension.test.browserLaunchCommand", PrintSession.getLaunchBrowserCommand));
This suggests that the activation method hasn't been called. Is this something I must do explicitly?
I just noticed this up the top of extension.test.ts
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
That's not how my tests are written. They don't import the code and call it directly, they assume the extension is installed and active and they use registered commands. Some of these commands were added for no other reason than to allow fine grained unit tests.
The problem I describe in the question is due to the fact that the extension is not installed.
Discovering I can import from the extension doesn't solve all the problems. Some of my tests are strictly speaking integration tests. They need the extension to be installed and active.
To meet that requirement, gulp package rather than gulp build will also produce the VSIX. The only real trick is obtaining the VSIX name to install it in the test environment.
const vsixName = fs.readdirSync(extensionDevelopmentPath)
.filter(p => path.extname(p) === ".vsix")
.sort((a, b) => a < b ? 1 : a > b ? -1 : 0)[0];
const launchArgs = [
path.resolve(__dirname, '../../src/test/test-docs'),
"--install-extension",
vsixName
];
A hybrid approach is possible; some of the registered commands exist only for use by unit tests. These could be junked in favour of direct calls.

Can't run stock SF Container out of the box on local cluster

I created a stock out of the box VS2019 Azure Service Fabric Container app. It and every other Service Fabric app won't run on the local cluster. I get this:
1>------ Build started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
2>------ Publish started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
2>Started executing script 'GetApplicationExistence'.
2>Finished executing script 'GetApplicationExistence'.
2>Time elapsed: 00:00:00.5863836
-------- Package started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
ServiceFabricContainer -> C:\dev\ServiceFabricContainer\pkg\Debug
-------- Package: Project: ServiceFabricContainer succeeded, Time elapsed: 00:00:00.2741254 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>powershell -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command ". 'C:\dev\ServiceFabricContainer\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\dev\ServiceFabricContainer\pkg\Debug' -PublishProfileFile 'C:\dev\ServiceFabricContainer\PublishProfiles\Local.1Node.xml' -DeployOnly:$false -ApplicationParameter:#{} -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'SameAppTypeAndVersion' -SkipPackageValidation:$false -ErrorAction Stop"
2>Copying application to image store...
2>Upload to Image Store succeeded
2>Registering application type...
2>Register application type started. Use Get-ServiceFabricApplicationType to query for status.
2>Running Image Builder process ...
2>Application package is registered.
2>Removing application package from image store...
2>Remove application package succeeded
2>Creating application...
2>New-ServiceFabricApplication : Repository Credentials for Account Name:sgentile cannot have a blank password if you
2>have PasswordEncrypted set to True or Type set to Encrypted/SecretsStoreRef.
2>At C:\Program Files\Microsoft SDKs\Service
2>Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:358 char:9
2>+ New-ServiceFabricApplication -ApplicationName $ApplicationNam ...
2>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2> + CategoryInfo : InvalidOperation: (Microsoft.Servi...usterConnection:ClusterConnection) [New-ServiceFabr
2> icApplication], FabricException
2> + FullyQualifiedErrorId : CreateApplicationInstanceErrorId,Microsoft.ServiceFabric.Powershell.NewApplication
2>
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:09.7611521
2>The PowerShell script failed to execute.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
Help please!
The answer is right in the error information. I just needed to have a non blank password. It works now.

Running PowerShell terminal in 2.0 mode

VSCode Version: 1.16.1
OS Version: Windows Server 2012 R2 Standard
Is it possible to run the PowerShell terminal using PowerShell v2.0? I have an older SharePoint farm that requires earlier version of PowerShell and would like to run that version instead of more current versions. When I open VS Code on my server the PowerShell terminal crashes.
Here is the log of the crash.
9/18/2017 10:09:24 AM [NORMAL] - Visual Studio Code v1.16.1 64-bit
9/18/2017 10:09:24 AM [NORMAL] - PowerShell Extension v1.4.3
9/18/2017 10:09:24 AM [NORMAL] - Operating System: Windows 64-bit
9/18/2017 10:09:24 AM [NORMAL] - Language server starting --
9/18/2017 10:09:24 AM [NORMAL] - exe: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
9/18/2017 10:09:24 AM [NORMAL] - args: C:\Users\me\.vscode\extensions\ms-vscode.powershell-1.4.3\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.4.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.4.3' -AdditionalModules #('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\me\.vscode\extensions\ms-vscode.powershell-1.4.3\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\me\.vscode\extensions\ms-vscode.powershell-1.4.3\logs\1505754564-f1d3cfae-50af-4f74-9503-061208469b8d1505754561535\EditorServices.log' -SessionDetailsPath 'C:\Users\me\.vscode\extensions\ms-vscode.powershell-1.4.3\sessions\PSES-VSCode-10764-479503' -FeatureFlags #()
9/18/2017 10:09:25 AM [NORMAL] - powershell.exe started, pid: 6412
9/18/2017 10:09:25 AM [NORMAL] - powershell.exe terminated or terminal UI was closed
9/18/2017 10:10:25 AM [NORMAL] - Language server startup failed.
9/18/2017 10:10:25 AM [ERROR] - The language service could not be started:
9/18/2017 10:10:25 AM [ERROR] - Timed out waiting for session file to appear.
I experienced the same symptoms after updating VS Code (1.25.1) and PowerShell extension (1.8.2). Discovered that C:\Users\USERNAME.vscode\extensions\ms-vscode.powershell-1.8.2\modules\PowerShellEditorServices\Start-EditorServices.ps1 was failing to launch by looking at the logs and trying to launch it manually from a separate PowerShell instance with the same arguments. It returned the following prompt: Do you want to run software from this untrusted publisher? [V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D"): indicating that the digital signature was not trusted.
To remedy this I performed the following:
Browse to the file noted in the error message above. (ex. C:\Users\USERNAME.vscode\extensions\ms-vscode.powershell-1.8.2\modules\PowerShellEditorServices\Start-EditorServices.ps1)
Right click on the file and choose Properties | Digital Signatures
Select the signature and click Details | View Certificate
Choose the Details tab and click Copy to File...
Save the file with a .CER extension.
Using the Certificates MMC Snapin, import this file into the Trusted Publishers Certificate Store on the Local Machine.
(original solution post in https://github.com/PowerShell/vscode-powershell/issues/1360 )

Concourse CI Windows Worker

I'm trying to setup a Concourse CI environment with a Windows 7 worker.
I have one machine under Ubuntu Server (16.04) hosting my TSA server and one worker (for the support of git resources), and a second one under Windows 7 hosting a worker.
Everything seems to work fine as:
I can login into the web ui
the fly -t my_concourseci workers command returns :
name containers platform tags team state version
ubuntu 1 linux none none running 1.1
windows7 0 windows none none running 1.1
the fly -t my_concourseci execute -c test.yml command returns:
executing build 146
initializing
running echo Hello World!
Hello World!
with the following content in test.yml file:
platform: windows
run:
path: echo
args: [ "Hello World!" ]
Nevertheless when I add an input to my task:
platform: windows
> inputs:
> - name: concourse
run:
path: echo
args: [ "Hello World!" ]
I get the following error:
executing build 148
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5698k 0 5698k 0 0 1948k 0 --:--:-- 0:00:02 --:--:-- 1949k
initializing
failed to stream in to volume
errored
If I look at the windows worker log I got this error that comes up:
{"timestamp":"1500642862.643555164",
"source":"baggageclaim",
"message":"baggageclaim.api.volume-server.stream-in.bad-stream-payload",
"log_level":1,
"data":{"error":"tar extract failed (exit status 2). output: \"\\ngzip: stdin: not in gzip format\\n/usr/bin/tar: Child returned status 1\\n/usr/bin/tar: Error is not recoverable: exiting now\\n\"",
"session":"2.1.8730",
"volume":"15bf1fc6-0727-4962-6c84-18446e54ab96"}
}
Any ideas about what can cause a not in gzip format error ? Knowing that if I run the exact same task on a linux platform every works fine.
platform: linux
image_resource:
type: docker-image
source: {repository: busybox}
inputs:
- name: concourse
run:
path: echo
args: [ "Hello World!" ]
----- STDOUT
executing build 149
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5699k 0 5699k 0 0 1917k 0 --:--:-- 0:00:02 --:--:-- 1918k
initializing
Pulling busybox#sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4...
sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4: Pulling from library/busybox
9e87eff13613: Pulling fs layer
9e87eff13613: Verifying Checksum
9e87eff13613: Download complete
9e87eff13613: Pull complete
Digest: sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4
Status: Downloaded newer image for busybox#sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4
Successfully pulled busybox#sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4.
running echo Hello World!
succeeded
Thanks.
Launch powershell as Administrator, and run the concourse_worker.exe from there. That worked for me.
I am running a Windows Server 2016 Base on AWS based on this AMI ami-e1876a98
Thanks for your answers, it helps me solve my problem.
I were starting my concourse worker within a MSYS 1.0 environment. The thing is that MSYS contains tar and gunzip binaries within the $PATH. When I started concourse worker inside a Power Shell or cmd.exe without any MSYS unix-like binaries in the $PATH it worked like a charm !
Note: Be sure to have no MSYS binaries in the $PATH Windows environment variable for this to work, especially check that Git-Bash environment tools are not added to your windows $PATH environment variable.
Thanks again.

0xC0000022 before RtlUserThreadStart

I'm injecting some code to hook apis in processes but I have some issues in some applications like chrome.exe
My test app launches a suspended process, do injection and api hooking and then resumes it.
CreateProcessW is hooked in order to be able to hook child processes. If CreateProcessW is called, it is forced to be created suspended, hook the child and resume it.
The injected code only depends on ntdll api's so, although hooked processes are not fully initialized yet, ntdll.dll is always present.
Code is injected using a helper thread using CreateRemoteThread or NtCreateThreadEx with the CREATE_SUSPENDED flag. (No matter which one, the issue still there)
After this intro, the problem is that in some processes like some chrome childs, CreateRemoteThread returns TRUE but when I resume the injector thread, it exits with code 0xC0000022 and the process exits too.
If I attach WinDbg to a chrome.exe child process that is suspended, before I do anything, it fails too and chrome.exe ends with the same behavior.
Seems O.S. code executed before RtlUserThreadStart, generates the error but I don't know how to debug it.
How can I debug code that runs before RtlUserThreadStart? Is there a debugger or a windbg option that allows me to do that?
EDIT:
Following the last post from here, I could retrieve this info:
0a88:0814 # 02688302 - LdrpInitializeProcess - INFO: Beginning execution of chrome.exe (c:\Program Files (x86)\Google\Chrome\Application\chrome.exe)
Current directory: C:\Windows
Search path: C:\Windows\SYSTEM32 0a88:0814 # 02688318 - LdrpInitializeProcess - ERROR: Initializing the current directory to "C:\Windows" failed with status 0xc0000022
0a88:0814 # 02688334 - LdrLoadDll - ENTER: DLL name: C:\Windows\SYSTEM32\wow64.dll DLL path: NULL 0a88:0814 # 02688349 - LdrpLoadDll - ENTER: DLL name: C:\Windows\SYSTEM32\wow64.dll DLL path: C:\Windows\SYSTEM32
0a88:0814 # 02688365 - LdrpLoadDll - INFO: Loading DLL C:\Windows\SYSTEM32\wow64.dll from path C:\Windows\SYSTEM32 0a88:0814 # 02688380 - LdrpFindOrMapDll - ENTER: DLL name: C:\Windows\SYSTEM32\wow64.dll DLL path: C:\Windows\SYSTEM32
0a88:0814 # 02688396 - LdrpSearchPath - ENTER: DLL name: C:\Windows\SYSTEM32\wow64.dll DLL path: C:\Windows\SYSTEM32
0a88:0814 # 02688412 - LdrpResolveFileName - ENTER: DLL name: C:\Windows\SYSTEM32\wow64.dll
0a88:0814 # 02688427 - LdrpResolveFileName - RETURN: Status: 0xc0000022
0a88:0814 # 02688443 - LdrpSearchPath - RETURN: Status: 0xc0000022
0a88:0814 # 02688458 - LdrpFindOrMapDll - RETURN: Status: 0xc0000022
0a88:0814 # 02688474 - LdrpLoadDll - RETURN: Status: 0xc0000022
0a88:0814 # 02688490 - LdrLoadDll - RETURN: Status: 0xc0000022
0a88:0814 # 02688505 - LdrpInitializeProcess - ERROR: Loading WOW64 image management DLL "C:\Windows\SYSTEM32\wow64.dll" failed with status 0xc0000022
0a88:0814 # 02688521 - _LdrpInitialize - ERROR: Process initialization failed with status 0xc0000022
0a88:0814 # 02688536 - LdrpInitializationFailure - ERROR: Process initialization failed with status 0xc0000022
The process is created with a restricted token, the main thread inherits it but my injector thread isn't restricted because it is created by my app.
I can assume ntdll's apis are not hooked yet by chrome (in this case) because injection takes place before CreateProcess returns to chrome.
May the non-restricted token in my thread conflicts with process token in some way?
Take a look at Debugging WinLogon in the windbg help (debugger.chm). Simply substitute "chrome.exe" for "winlogon.exe". This technique controls a user mode debugger (ntsd) from the kernel mode debugger. I believe this will allow you debug chrome.exe's process initialization much earlier than using a user mode debugger alone.
The issue in chrome was the following:
Chrome launches child processes with very limited privileges (because of the sandbox) but before resuming the main thread it impersonates the main thread with a token with more privileges in order to let the process initialize.
My injector thread was not impersonating so the limited process token raised the 0xC0000022 exit code when the LdrpInitializeProcess routine was executed.