Fix: ensure power of 2 check handles 64-bit size_t entirely
[lttng-modules.git] / lttng-context-ppid.c
CommitLineData
b64bc438
MD
1/*
2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * LTTng PPID context.
6 *
7 * Dual LGPL v2.1/GPL v2 license.
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
13#include <linux/syscalls.h>
a90917c3 14#include "lttng-events.h"
b64bc438
MD
15#include "wrapper/ringbuffer/frontend_types.h"
16#include "wrapper/vmalloc.h"
a90917c3 17#include "lttng-tracer.h"
b64bc438
MD
18
19static
20size_t ppid_get_size(size_t offset)
21{
22 size_t size = 0;
23
a90917c3 24 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
25 size += sizeof(pid_t);
26 return size;
27}
28
29static
30void ppid_record(struct lttng_ctx_field *field,
31 struct lib_ring_buffer_ctx *ctx,
a90917c3 32 struct lttng_channel *chan)
b64bc438
MD
33{
34 pid_t ppid;
35
36 rcu_read_lock();
37 ppid = task_tgid_nr(current->real_parent);
38 rcu_read_unlock();
a90917c3 39 lib_ring_buffer_align_ctx(ctx, lttng_alignof(ppid));
b64bc438
MD
40 chan->ops->event_write(ctx, &ppid, sizeof(ppid));
41}
42
43int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx)
44{
45 struct lttng_ctx_field *field;
b64bc438
MD
46
47 field = lttng_append_context(ctx);
48 if (!field)
09fec6b4 49 return -ENOMEM;
44252f0f
MD
50 if (lttng_find_context(*ctx, "ppid")) {
51 lttng_remove_context_field(ctx, field);
52 return -EEXIST;
53 }
b64bc438
MD
54 field->event_field.name = "ppid";
55 field->event_field.type.atype = atype_integer;
56 field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
a90917c3 57 field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
b64bc438
MD
58 field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
59 field->event_field.type.u.basic.integer.reverse_byte_order = 0;
60 field->event_field.type.u.basic.integer.base = 10;
61 field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
62 field->get_size = ppid_get_size;
63 field->record = ppid_record;
64 wrapper_vmalloc_sync_all();
65 return 0;
66}
67EXPORT_SYMBOL_GPL(lttng_add_ppid_to_ctx);
68
69MODULE_LICENSE("GPL and additional rights");
70MODULE_AUTHOR("Mathieu Desnoyers");
71MODULE_DESCRIPTION("Linux Trace Toolkit PPID Context");
This page took 0.039238 seconds and 4 git commands to generate.