diff options
-rw-r--r-- | lib/chef/mixin/windows_architecture_helper.rb | 22 | ||||
-rw-r--r-- | lib/chef/provider/windows_script.rb | 2 | ||||
-rw-r--r-- | lib/chef/win32/api/process.rb | 1 |
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/chef/mixin/windows_architecture_helper.rb b/lib/chef/mixin/windows_architecture_helper.rb index c13278693f..3d9f2bd2d1 100644 --- a/lib/chef/mixin/windows_architecture_helper.rb +++ b/lib/chef/mixin/windows_architecture_helper.rb @@ -19,19 +19,24 @@ require 'chef/exceptions' require 'win32/api' if Chef::Platform.windows? +require 'chef/win32/api/process' if Chef::Platform.windows? +require 'chef/win32/api/error' if Chef::Platform.windows? class Chef module Mixin module WindowsArchitectureHelper + include Chef::ReservedNames::Win32::API::Process + include Chef::ReservedNames::Win32::API::Error + def node_windows_architecture(node) node[:kernel][:machine].to_sym end def wow64_architecture_override_required?(node, desired_architecture) - is_i386_windows_process? && + desired_architecture == :x86_64 && node_windows_architecture(node) == :x86_64 && - desired_architecture == :x86_64 + is_i386_process_on_x86_64_windows? end def node_supports_windows_architecture?(node, desired_architecture) @@ -51,8 +56,17 @@ class Chef end end - def is_i386_windows_process? - Chef::Platform.windows? && 'X86'.casecmp(ENV['PROCESSOR_ARCHITECTURE']) == 0 + def is_i386_process_on_x86_64_windows? + is_64_bit_process_result = FFI::MemoryPointer.new(:int) + + # The return value of IsWow64Process is nonzero value if the API call succeeds. + # The result data are returned in the last parameter, not the return value. + call_succeeded = IsWow64Process(GetCurrentProcess(), is_64_bit_process_result) + + # The result is nonzero if IsWow64Process's calling process, in the case here + # this process, is running under WOW64, i.e. the result is nonzero if this + # process is 32-bit (aka :i386). + result = (call_succeeded != 0) && (is_64_bit_process_result.get_int(0) != 0) end def disable_wow64_file_redirection( node ) diff --git a/lib/chef/provider/windows_script.rb b/lib/chef/provider/windows_script.rb index 08a2ea74df..04f9f9d023 100644 --- a/lib/chef/provider/windows_script.rb +++ b/lib/chef/provider/windows_script.rb @@ -36,7 +36,7 @@ class Chef @is_wow64 = wow64_architecture_override_required?(run_context.node, target_architecture) - if ( target_architecture == :i386 ) && ! is_i386_windows_process? + if ( target_architecture == :i386 ) && ! is_i386_process_on_x86_64_windows? raise Chef::Exceptions::Win32ArchitectureIncorrect, "Support for the i386 architecture from a 64-bit Ruby runtime is not yet implemented" end diff --git a/lib/chef/win32/api/process.rb b/lib/chef/win32/api/process.rb index 0aca992ed5..217880b737 100644 --- a/lib/chef/win32/api/process.rb +++ b/lib/chef/win32/api/process.rb @@ -34,6 +34,7 @@ class Chef safe_attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL safe_attach_function :GetProcessId, [ :HANDLE ], :DWORD safe_attach_function :CloseHandle, [ :HANDLE ], :BOOL + safe_attach_function :IsWow64Process, [ :HANDLE, :PBOOL ], :BOOL end end |