debuggers.hg

changeset 21950:6a0dd2c29999

libxc: free thread specific hypercall buffer on xc_interface_close

The per-thread hypercall buffer is usually cleaned up on pthread_exit
by the destructor passed to pthread_key_create. However if the calling
application is not threaded then the destructor is never called.

This frees the data for the current thread only but that is OK since
any other threads will be cleaned up by the destructor.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Fri Jul 30 16:20:48 2010 +0100 (2010-07-30)
parents 9f49667fec71
children 6b9e44cf2651 624c5fdf0284
files tools/libxc/xc_private.c
line diff
     1.1 --- a/tools/libxc/xc_private.c	Fri Jul 30 15:22:39 2010 +0100
     1.2 +++ b/tools/libxc/xc_private.c	Fri Jul 30 16:20:48 2010 +0100
     1.3 @@ -57,6 +57,8 @@ xc_interface *xc_interface_open(xentooll
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +static void xc_clean_hcall_buf(void);
     1.8 +
     1.9  int xc_interface_close(xc_interface *xch)
    1.10  {
    1.11      int rc = 0;
    1.12 @@ -68,6 +70,9 @@ int xc_interface_close(xc_interface *xch
    1.13          rc = xc_interface_close_core(xch, xch->fd);
    1.14          if (rc) PERROR("Could not close hypervisor interface");
    1.15      }
    1.16 +
    1.17 +    xc_clean_hcall_buf();
    1.18 +
    1.19      free(xch);
    1.20      return rc;
    1.21  }
    1.22 @@ -180,6 +185,8 @@ void unlock_pages(void *addr, size_t len
    1.23  int hcall_buf_prep(void **addr, size_t len) { return 0; }
    1.24  void hcall_buf_release(void **addr, size_t len) { }
    1.25  
    1.26 +static void xc_clean_hcall_buf(void) { }
    1.27 +
    1.28  #else /* !__sun__ */
    1.29  
    1.30  int lock_pages(void *addr, size_t len)
    1.31 @@ -225,6 +232,14 @@ static void _xc_clean_hcall_buf(void *m)
    1.32      pthread_setspecific(hcall_buf_pkey, NULL);
    1.33  }
    1.34  
    1.35 +static void xc_clean_hcall_buf(void)
    1.36 +{
    1.37 +    void *hcall_buf = pthread_getspecific(hcall_buf_pkey);
    1.38 +
    1.39 +    if (hcall_buf)
    1.40 +        _xc_clean_hcall_buf(hcall_buf);
    1.41 +}
    1.42 +
    1.43  static void _xc_init_hcall_buf(void)
    1.44  {
    1.45      pthread_key_create(&hcall_buf_pkey, _xc_clean_hcall_buf);