[FEATURE] add evas_gl_ probes
[platform/core/system/swap-probe.git] / probe_memory / libdamemmanage.c
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * Anastasia Lyupa <a.lyupa@samsung.com>
12  *
13  * This library is free software; you can redistribute it and/or modify it under
14  * the terms of the GNU Lesser General Public License as published by the
15  * Free Software Foundation; either version 2.1 of the License, or (at your option)
16  * any later version.
17  *
18  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21  * License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this library; if not, write to the Free Software Foundation, Inc., 51
25  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  * Contributors:
28  * - S-Core Co., Ltd
29  * - Samsung RnD Institute Russia
30  *
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <dlfcn.h>
37 #include <stdbool.h>
38 #include <memory.h>
39 #include <errno.h>
40 #include "daprobe.h"
41 #include "probeinfo.h"
42 #include "dautil.h"
43 #include "da_memory.h"
44 #include "binproto.h"
45 #include "common_probe_init.h"
46
47 static enum DaOptions _sopt = OPT_ALLOC;
48
49 void *memset(void *memblock, int c, size_t n)
50 {
51         static void *(*memsetp)(void *,int,size_t);
52         DECLARE_VARIABLE_STANDARD;
53         void *pret;
54
55         GET_REAL_FUNC_RTLD_NEXT(memset);
56
57         PRE_PROBEBLOCK();
58
59         pret = memsetp(memblock, c, n);
60
61         POST_PACK_PROBEBLOCK_BEGIN();
62
63         PREPARE_LOCAL_BUF();
64         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
65                           API_ID_memset,
66                           "pdx", voidp_to_uint64(memblock), c,
67                           (uint64_t)(n));
68         PACK_COMMON_END('p', pret, newerrno, blockresult);
69         PACK_MEMORY(n, MEMORY_API_MANAGE, pret);
70         FLUSH_LOCAL_BUF();
71
72         POST_PACK_PROBEBLOCK_END();
73
74         return pret;
75 }
76
77 int memcmp(const void * ptr1, const void * ptr2, size_t num)
78 {
79         static int(*memcmpp)(const void *,const void *,size_t);
80         DECLARE_VARIABLE_STANDARD;
81
82         GET_REAL_FUNC_RTLD_NEXT(memcmp);
83
84         PRE_PROBEBLOCK();
85
86         ret = memcmpp(ptr1, ptr2, num);
87
88         POST_PACK_PROBEBLOCK_BEGIN();
89
90         PREPARE_LOCAL_BUF();
91         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
92                           API_ID_memcmp,
93                           "ppx", voidp_to_uint64(ptr1), voidp_to_uint64(ptr2),
94                           (uint64_t)(num));
95         PACK_COMMON_END('d', ret, newerrno, blockresult);
96         PACK_MEMORY(num, MEMORY_API_MANAGE, ret);
97         FLUSH_LOCAL_BUF();
98
99         POST_PACK_PROBEBLOCK_END();
100
101         return ret;
102 }
103
104 void *memcpy(void * destination, const void * source, size_t num )
105 {
106         static void *(*memcpyp)(void *,const void *,size_t);
107         DECLARE_VARIABLE_STANDARD;
108         void *pret;
109
110         GET_REAL_FUNC_RTLD_NEXT(memcpy);
111
112         PRE_PROBEBLOCK();
113
114         pret = memcpyp(destination, source, num);
115
116         POST_PACK_PROBEBLOCK_BEGIN();
117
118         PREPARE_LOCAL_BUF();
119         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
120                           API_ID_memcpy,
121                           "ppx", voidp_to_uint64(destination),
122                           voidp_to_uint64(source),
123                           (uint64_t)(num));
124         PACK_COMMON_END('p', pret, newerrno, blockresult);
125         PACK_MEMORY(num, MEMORY_API_MANAGE, pret);
126         FLUSH_LOCAL_BUF();
127
128         POST_PACK_PROBEBLOCK_END();
129
130         return pret;
131 }
132