Fix syscall tracing argument input
[lttng-modules.git] / ltt-context.c
1 /*
2 * ltt-context.c
3 *
4 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng trace/channel/event context management.
7 */
8
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/slab.h>
13 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
14 #include "ltt-events.h"
15 #include "ltt-tracer.h"
16
17 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p)
18 {
19 struct lttng_ctx_field *field;
20 struct lttng_ctx *ctx;
21
22 if (!*ctx_p) {
23 *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
24 if (!*ctx_p)
25 return NULL;
26 }
27 ctx = *ctx_p;
28 if (ctx->nr_fields + 1 > ctx->allocated_fields) {
29 struct lttng_ctx_field *new_fields;
30
31 ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields);
32 new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
33 if (!new_fields)
34 return NULL;
35 if (ctx->fields)
36 memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields);
37 kfree(ctx->fields);
38 ctx->fields = new_fields;
39 }
40 field = &ctx->fields[ctx->nr_fields];
41 ctx->nr_fields++;
42 return field;
43 }
44 EXPORT_SYMBOL_GPL(lttng_append_context);
45
46 void lttng_destroy_context(struct lttng_ctx *ctx)
47 {
48 int i;
49
50 if (!ctx)
51 return;
52 for (i = 0; i < ctx->nr_fields; i++) {
53 if (ctx->fields[i].destroy)
54 ctx->fields[i].destroy(&ctx->fields[i]);
55 }
56 kfree(ctx->fields);
57 kfree(ctx);
58 }
This page took 0.031058 seconds and 5 git commands to generate.