Skip to content

Commit a0b3449

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 c3643f0 commit a0b3449

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
@@ -3908,3 +3908,35 @@ int uname(struct utsname *buf)
39083908
"%u", (v >> 16) & 0x7fff);
39093909
return 0;
39103910
}
3911+
3912+
/*
3913+
* Based on https://stackoverflow.com/questions/43002803
3914+
*
3915+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3916+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3917+
* "ErrorControl"=dword:00000001
3918+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3919+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3920+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3921+
* 65,00,00,00
3922+
* "Start"=dword:00000002
3923+
* "Type"=dword:00000010
3924+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3925+
* "ObjectName"="LocalSystem"
3926+
* "ServiceSidType"=dword:00000001
3927+
*/
3928+
int is_inside_windows_container(void)
3929+
{
3930+
static int inside_container = -1; /* -1 uninitialized */
3931+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3932+
HKEY handle = NULL;
3933+
3934+
if (inside_container != -1)
3935+
return inside_container;
3936+
3937+
inside_container = ERROR_SUCCESS ==
3938+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3939+
RegCloseKey(handle);
3940+
3941+
return inside_container;
3942+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,8 @@ void open_in_gdb(void);
722722
* Used by Pthread API implementation for Windows
723723
*/
724724
int err_win_to_posix(DWORD winerr);
725+
726+
/*
727+
* Check current process is inside Windows Container.
728+
*/
729+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)