From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: [PATCH 2 of 3] [xen-detect] Return 0 if no Xen detected; 1 if running in PV context; and 2 if in HVM context Date: Tue, 22 Dec 2009 16:48:57 -0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com, keir.fraser@eu.citrix.com Cc: konrad.wilk@oracle.com List-Id: xen-devel@lists.xenproject.org # HG changeset patch # User konrad@phenom.dumpdata.com # Date 1261438342 18000 # Node ID fc27db3a2ddb3f0843841748684547f6e2ed1f02 # Parent 402aa73665eddb3f7b3ede0a8894acd24397218d [xen-detect] Return 0 if no Xen detected; 1 if running in PV context; and 2 if in HVM context. On top of printing whether we are in HVM or PV context (or none at all), also return a value. diff -r 402aa73665ed -r fc27db3a2ddb tools/misc/xen-detect.c --- a/tools/misc/xen-detect.c Mon Dec 21 17:50:08 2009 -0500 +++ b/tools/misc/xen-detect.c Mon Dec 21 18:32:22 2009 -0500 @@ -68,7 +68,8 @@ cpuid(base + 1, &eax, &ebx, &ecx, &edx, pv_context); printf("Running in %s context on Xen v%d.%d.\n", pv_context ? "PV" : "HVM", (uint16_t)(eax >> 16), (uint16_t)eax); - return 1; + + return pv_context ? 1 : 2; } static jmp_buf sigill_jmp; @@ -79,9 +80,12 @@ int main(void) { + /* 0 - no Xen, 1 - PV Xen, 2 - HVM Xen */ + int rc = 0; + /* Check for execution in HVM context. */ - if ( check_for_xen(0) ) - return 0; + if ( (rc = check_for_xen(0)) ) + return rc; /* * Set up a signal handler to test the paravirtualised CPUID instruction. @@ -90,8 +94,8 @@ */ if ( !setjmp(sigill_jmp) && (signal(SIGILL, sigill_handler) != SIG_ERR) - && check_for_xen(1) ) - return 0; + && (rc = check_for_xen(1)) ) + return rc; printf("Not running on Xen.\n"); return 0;