diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-12-04 07:02:49 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-12-04 07:02:49 +0000 |
commit | 88de8df0dca10d6c7f8bca833f09b324216ac318 (patch) | |
tree | a11729432982b668d2128e8e973e87cb03fa36e1 /tools/libxl/libxl_internal.c | |
parent | 78eed7d0445b3d8d16beb526128544b12e928343 (diff) | |
download | xen-88de8df0dca10d6c7f8bca833f09b324216ac318.tar.gz xen-88de8df0dca10d6c7f8bca833f09b324216ac318.tar.bz2 xen-88de8df0dca10d6c7f8bca833f09b324216ac318.zip |
libxenlight: fix GC when cloning contexts
Provide a function to clone a context. This is necessary
because simply copying the structs will eventually
corrup the GC: maxsize is updated in the cloned context
but not in the originating, yet they have the same array
of referenced pointers alloc_ptrs.
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.com>
Diffstat (limited to 'tools/libxl/libxl_internal.c')
-rw-r--r-- | tools/libxl/libxl_internal.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index a04ac8ddf7..eeadbfd71f 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -28,6 +28,28 @@ int libxl_error_set(struct libxl_ctx *ctx, int code) return 0; } +int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to) +{ + /* We could just copy the structs, but since + * maxsize is not a pointer we need to take care + * of our own GC. */ + *to = *from; + to->alloc_ptrs = NULL; + to->alloc_maxsize = 256; + to->alloc_ptrs = calloc(to->alloc_maxsize, sizeof(void *)); + if (!to->alloc_ptrs) + return ERROR_NOMEM; + return 0; +} + +void libxl_discard_cloned_context(struct libxl_ctx *ctx) +{ + /* We only need to worry about GC-related fields */ + (void)libxl_ctx_free(ctx); + if (ctx->alloc_ptrs) + free(ctx->alloc_ptrs); +} + int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr) { int i; |