debuggers.hg

changeset 22070:aa078b53ff62

tools/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.

Changed since v1:
* Ensure hcall_buf_pkey is initialised before use. Thanks to
Christoph Egger for his help diagnosing this issue on NetBSD.
* Remove redundant if (hcall_buf) from xc_clean_hcall_buf since
_xc_clean_hcall_buf includes the same check.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Wed Aug 18 17:09:25 2010 +0100 (2010-08-18)
parents af6799abc6e9
children 9a4acc688e9f
files tools/libxc/xc_private.c
line diff
     1.1 --- a/tools/libxc/xc_private.c	Wed Aug 18 16:48:25 2010 +0100
     1.2 +++ b/tools/libxc/xc_private.c	Wed Aug 18 17:09:25 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 @@ -230,6 +237,13 @@ static void _xc_init_hcall_buf(void)
    1.32      pthread_key_create(&hcall_buf_pkey, _xc_clean_hcall_buf);
    1.33  }
    1.34  
    1.35 +static void xc_clean_hcall_buf(void)
    1.36 +{
    1.37 +    pthread_once(&hcall_buf_pkey_once, _xc_init_hcall_buf);
    1.38 +
    1.39 +    _xc_clean_hcall_buf(pthread_getspecific(hcall_buf_pkey));
    1.40 +}
    1.41 +
    1.42  int hcall_buf_prep(void **addr, size_t len)
    1.43  {
    1.44      struct hcall_buf *hcall_buf;