Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 2562138

Browse files
committed
Bug 1291944 - Verify makensis binary is 32-bits; r=glandium
This required implementing a utility function to resolve the binary type. I used GetBinaryTypeW via ctypes because this seems the fastest. I arbitrarily limited the function to testing 32-bit and 64-bit Windows executables because hopefully those are the only executables we'll ever encounter. We can expand the binary detection later, if needed. This includes support for running on non-Windows platforms. MozReview-Commit-ID: CYwyDWQrePc --HG-- extra : rebase_source : 8fd7ca7f253d9e9e18d64784652a5ff934ad2272
1 parent 3dffde2 commit 2562138

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

build/moz.configure/util.configure

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ def normsep(path):
6262
return mozpath.normsep(path)
6363

6464

65+
@imports('ctypes')
66+
@imports(_from='ctypes', _import='wintypes')
67+
@imports(_from='mozbuild.configure.constants', _import='WindowsBinaryType')
68+
def windows_binary_type(path):
69+
"""Obtain the type of a binary on Windows.
70+
71+
Returns WindowsBinaryType constant.
72+
"""
73+
GetBinaryTypeW = ctypes.windll.kernel32.GetBinaryTypeW
74+
GetBinaryTypeW.argtypes = [wintypes.LPWSTR, wintypes.POINTER(wintypes.DWORD)]
75+
GetBinaryTypeW.restype = wintypes.BOOL
76+
77+
bin_type = wintypes.DWORD()
78+
res = GetBinaryTypeW(path, ctypes.byref(bin_type))
79+
if not res:
80+
die('could not obtain binary type of %s' % path)
81+
82+
if bin_type.value == 0:
83+
return WindowsBinaryType('win32')
84+
elif bin_type.value == 6:
85+
return WindowsBinaryType('win64')
86+
# If we see another binary type, something is likely horribly wrong.
87+
else:
88+
die('unsupported binary type on %s: %s' % (path, bin_type))
89+
90+
6591
@imports('ctypes')
6692
@imports(_from='ctypes', _import='wintypes')
6793
def get_GetShortPathNameW():

moz.configure

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ def nsis_version(nsis):
295295

296296
return ver
297297

298+
# And that makensis is 32-bit.
299+
@depends_if(nsis)
300+
@checking('for 32-bit NSIS')
301+
def nsis_binary_type(nsis):
302+
bin_type = windows_binary_type(nsis)
303+
if bin_type != 'win32':
304+
raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
305+
306+
return 'yes'
307+
298308

299309
# Fallthrough to autoconf-based configure
300310
include('build/moz.configure/old.configure')

python/mozbuild/mozbuild/configure/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
'little',
6464
)
6565

66+
WindowsBinaryType = EnumString.subclass(
67+
'win32',
68+
'win64',
69+
)
70+
6671
# The order of those checks matter
6772
CPU_preprocessor_checks = OrderedDict((
6873
('x86', '__i386__ || _M_IX86'),

0 commit comments

Comments
 (0)