Skip to content

Commit 27c3161

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 ad843f0 commit 27c3161

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
@@ -3689,3 +3689,35 @@ int uname(struct utsname *buf)
36893689
"%u", (v >> 16) & 0x7fff);
36903690
return 0;
36913691
}
3692+
3693+
/*
3694+
* Based on https://stackoverflow.com/questions/43002803
3695+
*
3696+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3697+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3698+
* "ErrorControl"=dword:00000001
3699+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3700+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3701+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3702+
* 65,00,00,00
3703+
* "Start"=dword:00000002
3704+
* "Type"=dword:00000010
3705+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3706+
* "ObjectName"="LocalSystem"
3707+
* "ServiceSidType"=dword:00000001
3708+
*/
3709+
int is_inside_windows_container(void)
3710+
{
3711+
static int inside_container = -1; /* -1 uninitialized */
3712+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3713+
HKEY handle = NULL;
3714+
3715+
if (inside_container != -1)
3716+
return inside_container;
3717+
3718+
inside_container = ERROR_SUCCESS ==
3719+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3720+
RegCloseKey(handle);
3721+
3722+
return inside_container;
3723+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,8 @@ void open_in_gdb(void);
710710
* Used by Pthread API implementation for Windows
711711
*/
712712
int err_win_to_posix(DWORD winerr);
713+
714+
/*
715+
* Check current process is inside Windows Container.
716+
*/
717+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)