Skip to content

Commit 2b4bf35

Browse files
ZCubedscho
authored andcommitted
mingw: introduce code to detect whether we're inside a Windows container
This will come in handy in the next commit. Signed-off-by: JiSeop Moon <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b487ad1 commit 2b4bf35

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compat/mingw.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,3 +3666,35 @@ int uname(struct utsname *buf)
36663666
"%u", (v >> 16) & 0x7fff);
36673667
return 0;
36683668
}
3669+
3670+
/*
3671+
* Based on https://stackoverflow.com/questions/43002803
3672+
*
3673+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3674+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3675+
* "ErrorControl"=dword:00000001
3676+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3677+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3678+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3679+
* 65,00,00,00
3680+
* "Start"=dword:00000002
3681+
* "Type"=dword:00000010
3682+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3683+
* "ObjectName"="LocalSystem"
3684+
* "ServiceSidType"=dword:00000001
3685+
*/
3686+
int is_inside_windows_container(void)
3687+
{
3688+
static int inside_container = -1; /* -1 uninitialized */
3689+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3690+
HKEY handle = NULL;
3691+
3692+
if (inside_container != -1)
3693+
return inside_container;
3694+
3695+
inside_container = ERROR_SUCCESS ==
3696+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3697+
RegCloseKey(handle);
3698+
3699+
return inside_container;
3700+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,8 @@ void open_in_gdb(void);
703703
* Used by Pthread API implementation for Windows
704704
*/
705705
int err_win_to_posix(DWORD winerr);
706+
707+
/*
708+
* Check current process is inside Windows Container.
709+
*/
710+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)