2 * Copyright (C) 2009 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; version 2.1 of
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <lttng/ust.h>
35 static pid_t (*plibc_func
)(void) = NULL
;
39 if (plibc_func
== NULL
) {
40 plibc_func
= dlsym(RTLD_NEXT
, "fork");
41 if (plibc_func
== NULL
) {
42 fprintf(stderr
, "libustfork: unable to find \"fork\" symbol\n");
47 ust_before_fork(&sigset
);
48 /* Do the real fork */
49 retval
= plibc_func();
52 ust_after_fork_child(&sigset
);
54 ust_after_fork_parent(&sigset
);
59 struct ustfork_clone_info
{
65 static int clone_fn(void *arg
)
67 struct ustfork_clone_info
*info
= (struct ustfork_clone_info
*) arg
;
69 /* clone is now done and we are in child */
70 ust_after_fork_child(&info
->sigset
);
71 return info
->fn(info
->arg
);
74 int clone(int (*fn
)(void *), void *child_stack
, int flags
, void *arg
, ...)
76 static int (*plibc_func
)(int (*fn
)(void *), void *child_stack
,
77 int flags
, void *arg
, pid_t
*ptid
,
78 struct user_desc
*tls
, pid_t
*ctid
) = NULL
;
81 struct user_desc
*tls
;
88 ptid
= va_arg(ap
, pid_t
*);
89 tls
= va_arg(ap
, struct user_desc
*);
90 ctid
= va_arg(ap
, pid_t
*);
93 if (plibc_func
== NULL
) {
94 plibc_func
= dlsym(RTLD_NEXT
, "clone");
95 if (plibc_func
== NULL
) {
96 fprintf(stderr
, "libustfork: unable to find \"clone\" symbol.\n");
101 if (flags
& CLONE_VM
) {
103 * Creating a thread, no need to intervene, just pass on
106 retval
= plibc_func(fn
, child_stack
, flags
, arg
, ptid
,
109 /* Creating a real process, we need to intervene. */
110 struct ustfork_clone_info info
= { fn
: fn
, arg
: arg
};
112 ust_before_fork(&info
.sigset
);
113 retval
= plibc_func(clone_fn
, child_stack
, flags
, &info
,
115 /* The child doesn't get here. */
116 ust_after_fork_parent(&info
.sigset
);
This page took 0.032331 seconds and 4 git commands to generate.