#include #include #include #include #include static int xce_handle = -1; static int src_port = -1; static int dst_port = -1; static int xc_handle = -1; int create_channel(int dom, int remote_dom) { //open the hypervisor interface if (-1 != (xc_handle=xc_interface_open())) { // printf("\n Accquired HYPERVISOR INTERFACE HANDLE: %d \n", xc_handle); } else { return -1; //HYPERVISOR_INTERFACE_OPEN_FAIL } //allocate a port on the remote domain if (-1 != (dst_port = xc_evtchn_alloc_unbound(xc_handle, remote_dom, dom))) { // printf("\n Allocated the DEST port %d \n", dst_port); } else { return -2; //UNBOUND_PORT_ALLOCATION_FAIL } //create a handle for event channel if (-1 != (xce_handle = xc_evtchn_open())) { // printf("\n Accquired HYPERVISOR INTERFACE EVTCHN HANDLE: %d\n", xce_handle); } else { return -3; //EVENT_CHANN //create the event channelEL_OPEN_FAIL } //bind src and dst ports if(-1 != (src_port = xc_evtchn_bind_interdomain(xce_handle, remote_dom, dst_port))) { // printf("\n Allocated the SRC port %d \n", src_port); } else { return -4; //BINDING_SRC_DST_PORTS_FAIL } return 0; } void close_channel(void){ //close hypervisor interface xc_interface_close(xc_handle); //close event channel xc_evtchn_close(xce_handle); } void wait_for_event(long ms){ sleep(ms); } int main(void){ int ret, dom, remote_dom; //initialize domains dom=0; remote_dom=2; //create the event channel ret = create_channel(dom, remote_dom); if (0 == ret) { printf("\n Event Channel established successfully \n"); } else { return -1; //EVENT_CHANNEL_CREATION_FAILED } //wait 20 seconds for an event to occur in DomU wait_for_event(20); //close the opened interfaces close_channel(); return 0; }