From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Date: Fri Oct 9 10:02:37 2015 -0400
Subject: Tracepoint event: add "TP_code_post()"
Git-commit 265822ae7c567f883f17d89316b5540eb4447d6f
Signed-off-by: Tony Jones <tonyj@suse.de>

    Tracepoint event: add "TP_code_post()"
    
    Useful for probes that need to perform teardown after serialization,
    e.g. allocate temporary memory in TP_code_pre() and free it in
    TP_code_post(). Be careful to only use memory allocation from contexts
    allowing it.
    
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

diff --git a/instrumentation/events/lttng-module/arch/x86/kvm/trace.h b/instrumentation/events/lttng-module/arch/x86/kvm/trace.h
index 32c4743..c366267 100644
--- a/instrumentation/events/lttng-module/arch/x86/kvm/trace.h
+++ b/instrumentation/events/lttng-module/arch/x86/kvm/trace.h
@@ -122,7 +122,7 @@ LTTNG_TRACEPOINT_EVENT_CODE(kvm_exit,
 		u64 info1, info2;
 	),
 
-	TP_code(
+	TP_code_pre(
 		kvm_x86_ops->get_exit_info(vcpu, &tp_locvar->info1,
 				&tp_locvar->info2);
 	),
@@ -133,7 +133,9 @@ LTTNG_TRACEPOINT_EVENT_CODE(kvm_exit,
 		ctf_integer(u32, isa, isa)
 		ctf_integer(u64, info1, tp_locvar->info1)
 		ctf_integer(u64, info2, tp_locvar->info2)
-	)
+	),
+
+	TP_code_post()
 )
 
 /*
diff --git a/instrumentation/events/lttng-module/block.h b/instrumentation/events/lttng-module/block.h
index 3505df0..1a2ba6b 100644
--- a/instrumentation/events/lttng-module/block.h
+++ b/instrumentation/events/lttng-module/block.h
@@ -135,7 +135,7 @@ LTTNG_TRACEPOINT_EVENT_CLASS_CODE(block_rq_with_error,
 		size_t cmd_len;
 	),
 
-	TP_code(
+	TP_code_pre(
 		if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
 			tp_locvar->sector = 0;
 			tp_locvar->nr_sector = 0;
@@ -159,7 +159,9 @@ LTTNG_TRACEPOINT_EVENT_CLASS_CODE(block_rq_with_error,
 			rq->cmd_flags, blk_rq_bytes(rq))
 		ctf_sequence_hex(unsigned char, cmd,
 			tp_locvar->cmd, size_t, tp_locvar->cmd_len)
-	)
+	),
+
+	TP_code_post()
 )
 
 /**
@@ -227,7 +229,7 @@ LTTNG_TRACEPOINT_EVENT_CODE(block_rq_complete,
 		size_t cmd_len;
 	),
 
-	TP_code(
+	TP_code_pre(
 		if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
 			tp_locvar->cmd = rq->cmd;
 			tp_locvar->cmd_len = rq->cmd_len;
@@ -247,7 +249,9 @@ LTTNG_TRACEPOINT_EVENT_CODE(block_rq_complete,
 			rq->cmd_flags, nr_bytes)
 		ctf_sequence_hex(unsigned char, cmd,
 			tp_locvar->cmd, size_t, tp_locvar->cmd_len)
-	)
+	),
+
+	TP_code_post()
 )
 
 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
@@ -286,7 +290,7 @@ LTTNG_TRACEPOINT_EVENT_CLASS_CODE(block_rq,
 		size_t cmd_len;
 	),
 
-	TP_code(
+	TP_code_pre(
 		if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
 			tp_locvar->sector = 0;
 			tp_locvar->nr_sector = 0;
@@ -314,7 +318,9 @@ LTTNG_TRACEPOINT_EVENT_CLASS_CODE(block_rq,
 		ctf_sequence_hex(unsigned char, cmd,
 			tp_locvar->cmd, size_t, tp_locvar->cmd_len)
 		ctf_array_text(char, comm, current->comm, TASK_COMM_LEN)
-	)
+	),
+
+	TP_code_post()
 )
 
 /**
diff --git a/instrumentation/events/lttng-module/compaction.h b/instrumentation/events/lttng-module/compaction.h
index 2c25846..771da7d 100644
--- a/instrumentation/events/lttng-module/compaction.h
+++ b/instrumentation/events/lttng-module/compaction.h
@@ -114,7 +114,7 @@ LTTNG_TRACEPOINT_EVENT_CODE_MAP(mm_compaction_migratepages,
 		unsigned long nr_failed;
 	),
 
-	TP_code(
+	TP_code_pre(
 		tp_locvar->nr_failed = 0;
 
 		{
@@ -131,7 +131,9 @@ LTTNG_TRACEPOINT_EVENT_CODE_MAP(mm_compaction_migratepages,
 	TP_FIELDS(
 		ctf_integer(unsigned long, nr_migrated, nr_all - tp_locvar->nr_failed)
 		ctf_integer(unsigned long, nr_failed, tp_locvar->nr_failed)
-	)
+	),
+
+	TP_code_post()
 )
 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,16,0)) */
 LTTNG_TRACEPOINT_EVENT_MAP(mm_compaction_migratepages,
diff --git a/instrumentation/events/lttng-module/sched.h b/instrumentation/events/lttng-module/sched.h
index 2efff16..dc30398 100644
--- a/instrumentation/events/lttng-module/sched.h
+++ b/instrumentation/events/lttng-module/sched.h
@@ -349,7 +349,7 @@ LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork,
 		unsigned int ns_level;
 	),
 
-	TP_code(
+	TP_code_pre(
 		if (child) {
 			struct pid *child_pid;
 			unsigned int i;
@@ -403,7 +403,9 @@ LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork,
 				child_ns_inum;
 			}))
 #endif
-	)
+	),
+
+	TP_code_post()
 )
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
diff --git a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
index 702cfb5..837991a 100644
--- a/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
+++ b/instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h
@@ -11,7 +11,7 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(connect,
 		uint16_t v6addr[8];
 		unsigned int v4addr_len, v6addr_len;
 	),
-	TP_code(
+	TP_code_pre(
 		sc_in(
 			memset(tp_locvar, 0, sizeof(*tp_locvar));
 			if (addrlen < sizeof(struct sockaddr))
@@ -48,7 +48,8 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(connect,
 		sc_in(ctf_integer_network(uint16_t, dport, tp_locvar->dport))
 		sc_in(ctf_sequence_network(uint8_t, v4addr, &tp_locvar->v4addr, unsigned int, tp_locvar->v4addr_len))
 		sc_in(ctf_sequence_network(uint16_t, v6addr, &tp_locvar->v6addr, unsigned int, tp_locvar->v6addr_len))
-	)
+	),
+	TP_code_post()
 )
 
 #define OVERRIDE_64_accept
@@ -63,7 +64,7 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(accept,
 		int v4addr_len, v6addr_len;
 		int uaddr_len;
 	),
-	TP_code(
+	TP_code_pre(
 		sc_inout(
 			memset(tp_locvar, 0, sizeof(*tp_locvar));
 			(void) get_user(tp_locvar->uaddr_len, upeer_addrlen);
@@ -103,7 +104,8 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(accept,
 		sc_out(ctf_integer_network(uint16_t, sport, tp_locvar->sport))
 		sc_in(ctf_sequence_network(uint8_t, v4addr, &tp_locvar->v4addr, unsigned int, tp_locvar->v4addr_len))
 		sc_in(ctf_sequence_network(uint16_t, v6addr, &tp_locvar->v6addr, unsigned int, tp_locvar->v6addr_len))
-	)
+	),
+	TP_code_post()
 )
 
 #define OVERRIDE_64_pipe
diff --git a/lttng-syscalls.c b/lttng-syscalls.c
index 5fa6666..806485f 100644
--- a/lttng-syscalls.c
+++ b/lttng-syscalls.c
@@ -118,10 +118,10 @@ struct file_handle;
 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
 	LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
 		PARAMS(_fields))
-#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
-		PARAMS(_locvar), PARAMS(_code),					\
-		PARAMS(_fields))
+		PARAMS(_locvar), PARAMS(_code_pre),				\
+		PARAMS(_fields), PARAMS(_code_post))
 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)		\
@@ -150,9 +150,9 @@ struct file_handle;
 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
 	LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
 		PARAMS(_fields))
-#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
-		PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
+		PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)		\
@@ -194,9 +194,9 @@ struct file_handle;
 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
 	LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
 		PARAMS(_fields))
-#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
-		PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
+		PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) 		\
@@ -226,9 +226,9 @@ struct file_handle;
 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
 	LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
 		PARAMS(_fields))
-#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
-		PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
+		PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)		\
diff --git a/probes/define_trace.h b/probes/define_trace.h
index 4b67f5f..98bd9f8 100644
--- a/probes/define_trace.h
+++ b/probes/define_trace.h
@@ -56,10 +56,10 @@
 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields)
 
 #undef LTTNG_TRACEPOINT_EVENT_CODE
-#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields)
+#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post)
 
 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
-#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields)
+#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post)
 
 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args)
diff --git a/probes/lttng-events-reset.h b/probes/lttng-events-reset.h
index 1bc7782..8262d83 100644
--- a/probes/lttng-events-reset.h
+++ b/probes/lttng-events-reset.h
@@ -21,10 +21,10 @@
 /* Reset macros used within LTTNG_TRACEPOINT_EVENT to "nothing" */
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields)
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post)
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields)
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post)
 
 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args)
@@ -41,8 +41,11 @@
 #undef TP_locvar
 #define TP_locvar(...)
 
-#undef TP_code
-#define TP_code(...)
+#undef TP_code_pre
+#define TP_code_pre(...)
+
+#undef TP_code_post
+#define TP_code_post(...)
 
 #undef TP_FIELDS
 #define TP_FIELDS(args...)
diff --git a/probes/lttng-events.h b/probes/lttng-events.h
index 35d6f79..0e3b713 100644
--- a/probes/lttng-events.h
+++ b/probes/lttng-events.h
@@ -55,23 +55,25 @@
 	LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
 
 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
-#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
+#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map,				\
 			     PARAMS(proto),				\
 			     PARAMS(args),				\
 			     PARAMS(_locvar),				\
-			     PARAMS(_code),				\
-			     PARAMS(fields))				\
+			     PARAMS(_code_pre),				\
+			     PARAMS(fields),				\
+			     PARAMS(_code_post))			\
 	LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
 
 #undef LTTNG_TRACEPOINT_EVENT_CODE
-#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
+#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
 	LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name,			\
 			     PARAMS(proto),				\
 			     PARAMS(args),				\
 			     PARAMS(_locvar),				\
-			     PARAMS(_code),				\
-			     PARAMS(fields))
+			     PARAMS(_code_pre),				\
+			     PARAMS(fields),				\
+			     PARAMS(_code_post))
 
 /*
  * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
@@ -106,11 +108,11 @@
 #undef LTTNG_TRACEPOINT_EVENT_CLASS
 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
 	LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
-		PARAMS(_fields))
+		PARAMS(_fields), )
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
-	LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
+	LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
 
 
 /*
@@ -165,11 +167,11 @@ void __event_template_proto___##_template(_proto);
 void __event_template_proto___##_template(void);
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 void __event_template_proto___##_name(_proto);
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 void __event_template_proto___##_name(void);
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
@@ -302,14 +304,14 @@ void __event_template_proto___##_name(void);
 #define TP_FIELDS(...)	__VA_ARGS__	/* Only one used in this phase */
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 	static const struct lttng_event_field __event_fields___##_name[] = { \
 		_fields							     \
 	};
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
-	LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
+	LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
@@ -326,11 +328,11 @@ void __event_template_proto___##_name(void);
 #define TP_PROTO(...)	__VA_ARGS__
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 static void __event_probe__##_name(void *__data, _proto);
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 static void __event_probe__##_name(void *__data);
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
@@ -399,7 +401,7 @@ static void __event_probe__##_name(void *__data);
 #define TP_locvar(...)	__VA_ARGS__
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 static inline size_t __event_get_size__##_name(size_t *__dynamic_len,	      \
 		void *__tp_locvar, _proto)				      \
 {									      \
@@ -412,7 +414,7 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,	      \
 }
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 static inline size_t __event_get_size__##_name(size_t *__dynamic_len,	      \
 		void *__tp_locvar)					      \
 {									      \
@@ -575,7 +577,7 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,	      \
 #define TP_locvar(...)	__VA_ARGS__
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 static inline								      \
 void __event_prepare_filter_stack__##_name(char *__stack_data,		      \
 		void *__tp_locvar)					      \
@@ -586,7 +588,7 @@ void __event_prepare_filter_stack__##_name(char *__stack_data,		      \
 }
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 static inline								      \
 void __event_prepare_filter_stack__##_name(char *__stack_data,		      \
 		void *__tp_locvar, _proto)				      \
@@ -646,7 +648,7 @@ void __event_prepare_filter_stack__##_name(char *__stack_data,		      \
 #define TP_locvar(...)	__VA_ARGS__
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto)    \
 {									      \
 	size_t __event_align = 1;					      \
@@ -657,7 +659,7 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto)    \
 }
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 static inline size_t __event_get_align__##_name(void *__tp_locvar)	      \
 {									      \
 	size_t __event_align = 1;					      \
@@ -871,8 +873,11 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar)	      \
 #undef TP_locvar
 #define TP_locvar(...)	__VA_ARGS__
 
-#undef TP_code
-#define TP_code(...)	__VA_ARGS__
+#undef TP_code_pre
+#define TP_code_pre(...)	__VA_ARGS__
+
+#undef TP_code_post
+#define TP_code_post(...)	__VA_ARGS__
 
 /*
  * For state dump, check that "session" argument (mandatory) matches the
@@ -893,7 +898,7 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar)	      \
  * Perform UNION (||) of filter runtime list.
  */
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
 static void __event_probe__##_name(void *__data, _proto)		      \
 {									      \
 	struct probe_local_vars { _locvar };				      \
@@ -924,7 +929,7 @@ static void __event_probe__##_name(void *__data, _proto)		      \
 	__lpf = lttng_rcu_dereference(__session->pid_tracker);		      \
 	if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid)))  \
 		return;							      \
-	_code								      \
+	_code_pre							      \
 	if (unlikely(!list_empty(&__event->bytecode_runtime_head))) {	      \
 		struct lttng_bytecode_runtime *bc_runtime;		      \
 		int __filter_record = __event->has_enablers_without_bytecode; \
@@ -937,7 +942,7 @@ static void __event_probe__##_name(void *__data, _proto)		      \
 				__filter_record = 1;			      \
 		}							      \
 		if (likely(!__filter_record))				      \
-			return;						      \
+			goto __post;					      \
 	}								      \
 	__event_len = __event_get_size__##_name(__stackvar.__dynamic_len,     \
 				tp_locvar, _args);			      \
@@ -946,13 +951,16 @@ static void __event_probe__##_name(void *__data, _proto)		      \
 				 __event_align, -1);			      \
 	__ret = __chan->ops->event_reserve(&__ctx, __event->id);	      \
 	if (__ret < 0)							      \
-		return;							      \
+		goto __post;						      \
 	_fields								      \
 	__chan->ops->event_commit(&__ctx);				      \
+__post:									      \
+	_code_post							      \
+	return;								      \
 }
 
 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
 static void __event_probe__##_name(void *__data)			      \
 {									      \
 	struct probe_local_vars { _locvar };				      \
@@ -983,7 +991,7 @@ static void __event_probe__##_name(void *__data)			      \
 	__lpf = lttng_rcu_dereference(__session->pid_tracker);		      \
 	if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid)))  \
 		return;							      \
-	_code								      \
+	_code_pre							      \
 	if (unlikely(!list_empty(&__event->bytecode_runtime_head))) {	      \
 		struct lttng_bytecode_runtime *bc_runtime;		      \
 		int __filter_record = __event->has_enablers_without_bytecode; \
@@ -996,7 +1004,7 @@ static void __event_probe__##_name(void *__data)			      \
 				__filter_record = 1;			      \
 		}							      \
 		if (likely(!__filter_record))				      \
-			return;						      \
+			goto __post;					      \
 	}								      \
 	__event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
 	__event_align = __event_get_align__##_name(tp_locvar);		      \
@@ -1004,9 +1012,12 @@ static void __event_probe__##_name(void *__data)			      \
 				 __event_align, -1);			      \
 	__ret = __chan->ops->event_reserve(&__ctx, __event->id);	      \
 	if (__ret < 0)							      \
-		return;							      \
+		goto __post;						      \
 	_fields								      \
 	__chan->ops->event_commit(&__ctx);				      \
+__post:									      \
+	_code_post							      \
+	return;								      \
 }
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
diff --git a/probes/lttng-tracepoint-event.h b/probes/lttng-tracepoint-event.h
index 39c0f37..fc3417c 100644
--- a/probes/lttng-tracepoint-event.h
+++ b/probes/lttng-tracepoint-event.h
@@ -37,9 +37,9 @@
 
 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)))
-#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
+#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)))
-#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
+#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)))
 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)))
@@ -47,8 +47,8 @@
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE_NOARGS(name))
 
 #define LTTNG_TRACEPOINT_EVENT_CLASS(name, proto, args, fields)
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields)
-#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields)
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post)
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post)
 
 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
 	_LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)))
