tizen 2.3 release
[framework/system/swap-probe.git] / helper / daforkexec.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Vitaliy Cherepanov <v.cherepanov@samsung.com>
9  *
10  * This library is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the
12  * Free Software Foundation; either version 2.1 of the License, or (at your option)
13  * any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation, Inc., 51
22  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  * Contributors:
25  * - Samsung RnD Institute Russia
26  *
27  */
28 #ifndef __DAFORKEXEC_H_
29 #define __DAFORKEXEC_H_
30
31 #define INIT_FUNC_EXEC(FUNCNAME)                                        \
32         if(!FUNCNAME##_p) {                                             \
33                 void *tmpPtr = dlsym(RTLD_NEXT , #FUNCNAME);    \
34                 if (tmpPtr == NULL || dlerror() != NULL) {              \
35                         perror("dlsym failed : " #FUNCNAME);            \
36                         exit(0);                                        \
37                 }                                                       \
38                 memcpy(&FUNCNAME##_p, &tmpPtr, sizeof(tmpPtr));         \
39         }
40
41 #define DECLARE(RET, FUNCTION, ...)                     \
42         typedef RET (* FUNCTION ## _p_t)(__VA_ARGS__);  \
43         static FUNCTION ## _p_t FUNCTION ## _p = 0
44
45 void init_exec_fork();
46
47 #endif /* __DAFORKEXEC_H_ */