diff options
author | Toomas Soome <tsoome@me.com> | 2022-01-25 19:41:47 +0200 |
---|---|---|
committer | Toomas Soome <tsoome@me.com> | 2022-01-28 18:38:20 +0200 |
commit | 8c65387009c4cfaa0924c78065b46a4d4a178d41 (patch) | |
tree | 46734cd1bc48d0c15b4c3b9044762c2ecc0f8912 /usr/src/common | |
parent | 5a469116729183a46e77dc0620955bbde58d93f7 (diff) | |
download | illumos-joyent-8c65387009c4cfaa0924c78065b46a4d4a178d41.tar.gz |
14451 loader: want mechanism to test if we are virtualized
Reviewed by: Andy Fiddaman <andy@omnios.org>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>
Diffstat (limited to 'usr/src/common')
-rw-r--r-- | usr/src/common/ficl/loader.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/usr/src/common/ficl/loader.c b/usr/src/common/ficl/loader.c index c1f5c5d0eb..515330f849 100644 --- a/usr/src/common/ficl/loader.c +++ b/usr/src/common/ficl/loader.c @@ -430,6 +430,35 @@ ficlFindfile(ficlVm *pVM) ficlStackPushPointer(ficlVmGetDataStack(pVM), fp); } +/* + * isvirtualized? - Return whether the loader runs under a + * hypervisor. + * + * isvirtualized? ( -- addr len flag | flag ) + */ +static void +ficlIsvirtualizedQ(ficlVm *pVM) +{ + const char *hv; + + FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 3); + +#ifdef _STANDALONE + hv = (archsw.arch_hypervisor != NULL) + ? (*archsw.arch_hypervisor)() + : NULL; +#else + hv = NULL; +#endif + if (hv != NULL) { + ficlStackPushPointer(ficlVmGetDataStack(pVM), (void *)hv); + ficlStackPushInteger(ficlVmGetDataStack(pVM), strlen(hv)); + ficlStackPushInteger(ficlVmGetDataStack(pVM), FICL_TRUE); + } else { + ficlStackPushInteger(ficlVmGetDataStack(pVM), FICL_FALSE); + } +} + void ficlCcall(ficlVm *pVM) { @@ -1087,6 +1116,8 @@ ficlSystemCompilePlatform(ficlSystem *pSys) FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dp, "findfile", ficlFindfile, FICL_WORD_DEFAULT); + (void) ficlDictionarySetPrimitive(dp, "isvirtualized?", + ficlIsvirtualizedQ, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dp, "ccall", ficlCcall, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dp, "uuid-from-string", |