diff options
author | Adam Edwards <adamed@opscode.com> | 2014-06-08 08:07:44 -0700 |
---|---|---|
committer | adamedx <adamed@getchef.com> | 2014-06-20 22:00:27 -0700 |
commit | 3bec9c5be2ddce5857166c7d9b0d58762b7dfa09 (patch) | |
tree | ddc7e2b0281e00c36a80fab5db248fc9ef571b4e /lib/chef/mixin | |
parent | f6730f41b46fb9f3ffa5c6fea71d90b5964e779b (diff) | |
download | chef-3bec9c5be2ddce5857166c7d9b0d58762b7dfa09.tar.gz |
CHEF-5287: Use IsWow64Process instead of ENV hash to determine 32-bit process on 64-bit OS
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/windows_architecture_helper.rb | 22 |
1 files changed, 18 insertions, 4 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 ) |