Cleanup: reuse code in accept() and accept4() instrumentation
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 29 Aug 2016 20:02:10 +0000 (16:02 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Aug 2016 20:27:57 +0000 (16:27 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
instrumentation/syscalls/headers/x86-64-syscalls-3.10.0-rc7_pointers_override.h

index 6c59790a58e296d8cce5f2cad36ce4a76d77841e..22c328ac397e7205a1d09a73dc2f96ea7d1a8a9d 100644 (file)
@@ -52,48 +52,54 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(connect,
        TP_code_post()
 )
 
+#define LTTNG_SYSCALL_ACCEPT_locvar                    \
+       __typeof__(upeer_sockaddr->sa_family) sa_family;\
+       uint16_t sport;                                 \
+       uint32_t v4addr;                                \
+       uint16_t v6addr[8];                             \
+       int v4addr_len, v6addr_len;                     \
+       int uaddr_len;
+
+#define LTTNG_SYSCALL_ACCEPT_code_pre                                                                                  \
+       sc_inout(                                                                                                       \
+               memset(tp_locvar, 0, sizeof(*tp_locvar));                                                               \
+               (void) get_user(tp_locvar->uaddr_len, upeer_addrlen);                                                   \
+       )                                                                                                               \
+       sc_out(                                                                                                         \
+               if (tp_locvar->uaddr_len < sizeof(struct sockaddr))                                                     \
+                       goto skip_code;                                                                                 \
+               (void) get_user(tp_locvar->sa_family, &upeer_sockaddr->sa_family);                                      \
+               switch (tp_locvar->sa_family) {                                                                         \
+               case AF_INET:                                                                                           \
+                       if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in))                                          \
+                               goto skip_code;                                                                         \
+                       (void) get_user(tp_locvar->sport, &((struct sockaddr_in *) upeer_sockaddr)->sin_port);          \
+                       (void) get_user(tp_locvar->v4addr, &((struct sockaddr_in *) upeer_sockaddr)->sin_addr.s_addr);  \
+                       tp_locvar->v4addr_len = 4;                                                                      \
+                       break;                                                                                          \
+               case AF_INET6:                                                                                          \
+                       if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in6))                                         \
+                               goto skip_code;                                                                         \
+                       (void) get_user(tp_locvar->sport, &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_port);        \
+                       if (copy_from_user(tp_locvar->v6addr,                                                           \
+                                       &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_addr.in6_u.u6_addr8,            \
+                                       sizeof(tp_locvar->v6addr)))                                                     \
+                               memset(tp_locvar->v6addr, 0, sizeof(tp_locvar->v6addr));                                \
+                       tp_locvar->v6addr_len = 8;                                                                      \
+                       break;                                                                                          \
+               }                                                                                                       \
+       skip_code:                                                                                                      \
+       )
+
 #define OVERRIDE_64_accept
 SC_LTTNG_TRACEPOINT_EVENT_CODE(accept,
        TP_PROTO(sc_exit(long ret,) int fd, struct sockaddr * upeer_sockaddr, int * upeer_addrlen),
        TP_ARGS(sc_exit(ret,) fd, upeer_sockaddr, upeer_addrlen),
        TP_locvar(
-               __typeof__(upeer_sockaddr->sa_family) sa_family;
-               uint16_t sport;
-               uint32_t v4addr;
-               uint16_t v6addr[8];
-               int v4addr_len, v6addr_len;
-               int uaddr_len;
+               LTTNG_SYSCALL_ACCEPT_locvar
        ),
        TP_code_pre(
-               sc_inout(
-                       memset(tp_locvar, 0, sizeof(*tp_locvar));
-                       (void) get_user(tp_locvar->uaddr_len, upeer_addrlen);
-               )
-               sc_out(
-                       if (tp_locvar->uaddr_len < sizeof(struct sockaddr))
-                               goto skip_code;
-                       (void) get_user(tp_locvar->sa_family, &upeer_sockaddr->sa_family);
-                       switch (tp_locvar->sa_family) {
-                       case AF_INET:
-                               if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in))
-                                       goto skip_code;
-                               (void) get_user(tp_locvar->sport, &((struct sockaddr_in *) upeer_sockaddr)->sin_port);
-                               (void) get_user(tp_locvar->v4addr, &((struct sockaddr_in *) upeer_sockaddr)->sin_addr.s_addr);
-                               tp_locvar->v4addr_len = 4;
-                               break;
-                       case AF_INET6:
-                               if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in6))
-                                       goto skip_code;
-                               (void) get_user(tp_locvar->sport, &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_port);
-                               if (copy_from_user(tp_locvar->v6addr,
-                                               &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_addr.in6_u.u6_addr8,
-                                               sizeof(tp_locvar->v6addr)))
-                                       memset(tp_locvar->v6addr, 0, sizeof(tp_locvar->v6addr));
-                               tp_locvar->v6addr_len = 8;
-                               break;
-                       }
-               skip_code:
-               )
+               LTTNG_SYSCALL_ACCEPT_code_pre
        ),
        TP_FIELDS(
                sc_exit(ctf_integer(long, ret, ret))
@@ -113,43 +119,10 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(accept4,
        TP_PROTO(sc_exit(long ret,) int fd, struct sockaddr * upeer_sockaddr, int * upeer_addrlen, int flags),
        TP_ARGS(sc_exit(ret,) fd, upeer_sockaddr, upeer_addrlen, flags),
        TP_locvar(
-               __typeof__(upeer_sockaddr->sa_family) sa_family;
-               uint16_t sport;
-               uint32_t v4addr;
-               uint16_t v6addr[8];
-               int v4addr_len, v6addr_len;
-               int uaddr_len;
+               LTTNG_SYSCALL_ACCEPT_locvar
        ),
        TP_code_pre(
-               sc_inout(
-                       memset(tp_locvar, 0, sizeof(*tp_locvar));
-                       (void) get_user(tp_locvar->uaddr_len, upeer_addrlen);
-               )
-               sc_out(
-                       if (tp_locvar->uaddr_len < sizeof(struct sockaddr))
-                               goto skip_code;
-                       (void) get_user(tp_locvar->sa_family, &upeer_sockaddr->sa_family);
-                       switch (tp_locvar->sa_family) {
-                       case AF_INET:
-                               if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in))
-                                       goto skip_code;
-                               (void) get_user(tp_locvar->sport, &((struct sockaddr_in *) upeer_sockaddr)->sin_port);
-                               (void) get_user(tp_locvar->v4addr, &((struct sockaddr_in *) upeer_sockaddr)->sin_addr.s_addr);
-                               tp_locvar->v4addr_len = 4;
-                               break;
-                       case AF_INET6:
-                               if (tp_locvar->uaddr_len < sizeof(struct sockaddr_in6))
-                                       goto skip_code;
-                               (void) get_user(tp_locvar->sport, &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_port);
-                               if (copy_from_user(tp_locvar->v6addr,
-                                               &((struct sockaddr_in6 *) upeer_sockaddr)->sin6_addr.in6_u.u6_addr8,
-                                               sizeof(tp_locvar->v6addr)))
-                                       memset(tp_locvar->v6addr, 0, sizeof(tp_locvar->v6addr));
-                               tp_locvar->v6addr_len = 8;
-                               break;
-                       }
-               skip_code:
-               )
+               LTTNG_SYSCALL_ACCEPT_code_pre
        ),
        TP_FIELDS(
                sc_exit(ctf_integer(long, ret, ret))
This page took 0.027596 seconds and 4 git commands to generate.