Skip to content

Commit 01c0608

Browse files
ZCubevdye
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 98a16e8 commit 01c0608

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
@@ -3776,3 +3776,35 @@ int uname(struct utsname *buf)
37763776
"%u", (v >> 16) & 0x7fff);
37773777
return 0;
37783778
}
3779+
3780+
/*
3781+
* Based on https://stackoverflow.com/questions/43002803
3782+
*
3783+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3784+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3785+
* "ErrorControl"=dword:00000001
3786+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3787+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3788+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3789+
* 65,00,00,00
3790+
* "Start"=dword:00000002
3791+
* "Type"=dword:00000010
3792+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3793+
* "ObjectName"="LocalSystem"
3794+
* "ServiceSidType"=dword:00000001
3795+
*/
3796+
int is_inside_windows_container(void)
3797+
{
3798+
static int inside_container = -1; /* -1 uninitialized */
3799+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3800+
HKEY handle = NULL;
3801+
3802+
if (inside_container != -1)
3803+
return inside_container;
3804+
3805+
inside_container = ERROR_SUCCESS ==
3806+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3807+
RegCloseKey(handle);
3808+
3809+
return inside_container;
3810+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,8 @@ void open_in_gdb(void);
717717
* Used by Pthread API implementation for Windows
718718
*/
719719
int err_win_to_posix(DWORD winerr);
720+
721+
/*
722+
* Check current process is inside Windows Container.
723+
*/
724+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)