From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Egger, Christoph" Subject: Re: [PATCH] tools/misc/xencov.c: Use MAP_WIRED on NetBSD Date: Thu, 13 Jun 2013 11:47:02 +0200 Message-ID: <51B99516.60001@amazon.de> References: <51A74A37.5070502@amazon.de> <1369999519.5199.99.camel@zakaz.uk.xensource.com> <1370958416.1654.3.camel@hamster.uk.xensource.com> <1371028899.24512.376.camel@zakaz.uk.xensource.com> <1371038547.26497.4.camel@hamster.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1371038547.26497.4.camel@hamster.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Frediano Ziglio Cc: Miguel Clara , Ian Campbell , Frediano Ziglio , xen-devel List-Id: xen-devel@lists.xenproject.org On 12.06.13 14:02, Frediano Ziglio wrote: > Subject: [PATCH] gcov: Do not use mmap directly but use xc_hypercall_buffer_alloc > > xencov.c did not compile on NetBSD so use xc_hypercall_buffer which is > more portable. > > Signed-off-by: Frediano Ziglio Acked-by: Christoph Egger > --- > tools/misc/xencov.c | 22 +++++++++------------- > 1 file changed, 9 insertions(+), 13 deletions(-) > > Here you are. It get tested on a x64 machine, if somebody could test it > with a NetBSD would be great. > > diff --git a/tools/misc/xencov.c b/tools/misc/xencov.c > index 6645a30..fb4b2ff 100644 > --- a/tools/misc/xencov.c > +++ b/tools/misc/xencov.c > @@ -24,7 +24,6 @@ > #include > #include > #include > -#include > > static xc_interface *gcov_xch = NULL; > > @@ -35,16 +34,17 @@ static void gcov_init(void) > err(1, "opening interface"); > } > > -int gcov_get_info(int op, struct xen_sysctl *sys, void *ptr) > +int gcov_get_info(int op, struct xen_sysctl *sys, struct xc_hypercall_buffer *ptr) > { > struct xen_sysctl_coverage_op *cov; > + DECLARE_HYPERCALL_BUFFER_ARGUMENT(ptr); > > memset(sys, 0, sizeof(*sys)); > sys->cmd = XEN_SYSCTL_coverage_op; > > cov = &sys->u.coverage_op; > cov->cmd = op; > - cov->u.raw_info.p = ptr; > + set_xen_guest_handle(cov->u.raw_info, ptr); > > return xc_sysctl(gcov_xch, sys); > } > @@ -52,10 +52,8 @@ int gcov_get_info(int op, struct xen_sysctl *sys, void *ptr) > static void gcov_read(const char *fn, int reset) > { > struct xen_sysctl sys; > - unsigned page_size = sysconf(_SC_PAGESIZE); > uint32_t total_len; > - uint8_t *p; > - size_t size; > + DECLARE_HYPERCALL_BUFFER(uint8_t, p); > FILE *f; > int op = reset ? XEN_SYSCTL_COVERAGE_read_and_reset : > XEN_SYSCTL_COVERAGE_read; > @@ -71,16 +69,13 @@ static void gcov_read(const char *fn, int reset) > errx(1, "coverage size too big %u bytes\n", total_len); > > /* allocate */ > - size = total_len + page_size; > - size -= (size % page_size); > - p = mmap(0, size, PROT_WRITE|PROT_READ, > - MAP_PRIVATE|MAP_ANON|MAP_LOCKED, -1, 0); > - if ( p == (uint8_t *) -1 ) > - err(1, "mapping memory for coverage"); > + p = xc_hypercall_buffer_alloc(gcov_xch, p, total_len); > + if ( p == NULL ) > + err(1, "allocating memory for coverage"); > > /* get data */ > memset(p, 0, total_len); > - if ( gcov_get_info(op, &sys, p) < 0 ) > + if ( gcov_get_info(op, &sys, HYPERCALL_BUFFER(p)) < 0 ) > err(1, "getting coverage information"); > > /* write to a file */ > @@ -94,6 +89,7 @@ static void gcov_read(const char *fn, int reset) > err(1, "writing coverage to file"); > if (f != stdout) > fclose(f); > + xc_hypercall_buffer_free(gcov_xch, p); > } > > static void gcov_reset(void) >