From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: Using Xen's hypercall interface? Date: Mon, 07 Jul 2014 00:26:02 +0100 Message-ID: <53B9DB0A.3090608@citrix.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4284317757879765741==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Rig Gel , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --===============4284317757879765741== Content-Type: multipart/alternative; boundary="------------070500070301040307040508" This is a multi-part message in MIME format. --------------070500070301040307040508 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 06/07/2014 23:23, Rig Gel wrote: > Hi all, > > - I'm sorry if this is a repost, I was informed that this is the > correct mailing list only after sending a msg to xen-users - > > I would like to compile a simple ELF which would make a simple a > hypercall from a guest in order to > learn a bit more about the Xen Hypercall interface. > I tried including the hypervisor.h and -I'ing the ./extras/mini-os/ > dir but it seems that I'm missing a few flags or paths in order ot > make it fully compile correctly > > Can anyone hint or explain a bit what is the appropriate way to link > against Xen's header files ? > I only need hypervisor.h in order to call some hypercalls > > Attached below a sample of my code - > > #include > > ... > snip > ... > > void test_xen_version(int vers) { > HYPERVISOR_xen_version(vers); > } > > ( using the xe_version hypercall is just a mere example, I would like > to just know how to link/compile correctly against the required header > files/libs ) It is not possible to make hypercalls from userspace directly. Allowing such would cause all kinds of security problems. Linux and other operating systems a kernel driver which allow hypercalls via ioctl()s on /dev/xen/privcmd. You are best starting with libxenctrl which is a thin userspace library including OS abstraction to make hypercalls. >>From memory, something like: #include #include int main(void) { xc_interface *xch = xc_interface_open(NULL, NULL, 0); int ver = xc_version(xch, XENVER_version, NULL); printf("Xen version %d.%d\n", ver >> 16, ver & 0xffff); xc_interface_close(xch); return 0; } and compiled with `gcc foo.c -o foo -I/path/to/xenctrl.h -L/path/to/libxenctrl.so -lxenctrl` ought to get you started. ~Andrew --------------070500070301040307040508 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 06/07/2014 23:23, Rig Gel wrote:
Hi all,

- I'm sorry if this is a repost, I was informed that this is the correct mailing list only after sending a msg to xen-users - 

I would like to compile a simple ELF which would make a simple a hypercall from a guest in order to
learn a bit more about the Xen Hypercall interface.
I tried including the hypervisor.h and -I'ing the ./extras/mini-os/ dir but it seems that I'm missing a few flags or paths in order ot make it fully compile correctly 

Can anyone hint or explain a bit what is the appropriate way to link against Xen's header files ? 
I only need hypervisor.h in order to call some hypercalls 

Attached below a sample of my code -

#include <hypervisor.h>

...
snip 
...

void test_xen_version(int vers) {
    HYPERVISOR_xen_version(vers);
}

( using the xe_version hypercall is just a mere example, I would like to just know how to link/compile correctly against the required header files/libs )

It is not possible to make hypercalls from userspace directly.  Allowing such would cause all kinds of security problems.  Linux and other operating systems a kernel driver which allow hypercalls via ioctl()s on /dev/xen/privcmd.

You are best starting with libxenctrl which is a thin userspace library including OS abstraction to make hypercalls.

From memory, something like:

#include <stdio.h>
#include <xenctrl.h>

int main(void)
{
    xc_interface *xch = xc_interface_open(NULL, NULL, 0);
    int ver = xc_version(xch, XENVER_version, NULL);

    printf("Xen version %d.%d\n", ver >> 16, ver & 0xffff);
    xc_interface_close(xch);
    return 0;
}

and compiled with `gcc foo.c -o foo -I/path/to/xenctrl.h -L/path/to/libxenctrl.so -lxenctrl`

ought to get you started.

~Andrew
--------------070500070301040307040508-- --===============4284317757879765741== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============4284317757879765741==--