Welcome to mirror list, hosted at ThFree Co, Russian Federation.

os_is64bit.c « host « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2969811d9e2a8aece5d034ff56e27210e81e63f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * \file   os_is64bit.c
 * \brief  Native code-side checking for a 64-bit architecture.
 * \author Copyright (c) 2011 Jason Perkins and the Premake project
 */

#include "premake.h"

#if PLATFORM_WINDOWS
typedef BOOL(WINAPI* WowFuncSig)(HANDLE, PBOOL);
#endif

int os_is64bit(lua_State* L)
{
#if PLATFORM_WINDOWS
	HMODULE hKrnl32 = GetModuleHandle(TEXT("kernel32"));
#endif
	if (sizeof(void*) == 8) // our premake build is 64-bit, so the runtime environment must be also (at least) 64-bit ...
	{
		lua_pushboolean(L, 1);
		return 1;
	}
	// If this code returns true, then the platform is 64-bit. If it
	// returns false, the platform might still be 64-bit, but more 
	// checking will need to be done on the Lua side of things.
#if PLATFORM_WINDOWS
	if (hKrnl32)
	{
		WowFuncSig func = (WowFuncSig)GetProcAddress(hKrnl32, "IsWow64Process");
		if (func)
		{
			BOOL isWow = FALSE;
			if (func(GetCurrentProcess(), &isWow))
			{
				lua_pushboolean(L, isWow);
				return 1;
			}
		}
	}
#endif

	lua_pushboolean(L, 0);
	return 1;
}