Skip to content

Commit a89a729

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 31f6707 commit a89a729

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
@@ -3137,3 +3137,35 @@ int uname(struct utsname *buf)
31373137
"%u", (v >> 16) & 0x7fff);
31383138
return 0;
31393139
}
3140+
3141+
/*
3142+
* Based on https://stackoverflow.com/questions/43002803
3143+
*
3144+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3145+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3146+
* "ErrorControl"=dword:00000001
3147+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3148+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3149+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3150+
* 65,00,00,00
3151+
* "Start"=dword:00000002
3152+
* "Type"=dword:00000010
3153+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3154+
* "ObjectName"="LocalSystem"
3155+
* "ServiceSidType"=dword:00000001
3156+
*/
3157+
int is_inside_windows_container(void)
3158+
{
3159+
static int inside_container = -1; /* -1 uninitialized */
3160+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3161+
HKEY handle = NULL;
3162+
3163+
if (inside_container != -1)
3164+
return inside_container;
3165+
3166+
inside_container = ERROR_SUCCESS ==
3167+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3168+
RegCloseKey(handle);
3169+
3170+
return inside_container;
3171+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,8 @@ extern void open_in_gdb(void);
679679
* Used by Pthread API implementation for Windows
680680
*/
681681
int err_win_to_posix(DWORD winerr);
682+
683+
/*
684+
* Check current process is inside Windows Container.
685+
*/
686+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)