Use new u2mfn_fd for each ring_init call - each open fd to u2mfn is capable to
do only one u2mfn_alloc_kpage, so it can't be reused at the next ring_init.
In case of evtchn buffer overflow (received more than 1024 events between
libvchan_wait calls) further reads returns ERROR_IO_DEVICE. The only way to
recover from that is to reset the buffer. Because vchan code doesn't take care
of number of fired events - only the fact that some event was fired - lost
events here shouldn't break anything. Events reported _after_ libvchan_wait
call will be collected and reported correctly.
Some more comments in the code (here and in qrexec-agent in the next commit).
Windows evtchn driver can double fire on one event (details in
xenpci/evtchn_device_interface.c:EvtChn_EvtIoWrite). Less intrusive way of
fixing it is just remove all events from queue on libvchan_wait (to prevent
queue fill).
This won't hurt because we are interested in events only sent
after xc_evtchn_unmask call which is one line below.
This reverts commit f7ce10db8f76f752cf9d65b420de352e70bdb048.
This should be fixed by doing 0-length reads in qrexec main loop (instead of
real read of fired port number).
Use features macros (QREXEC_RING_V2 and ASYNC_INIT) instead of directly
depending on building environment. The macros are turned on (when required) in
libvchan.h based on target system.