tizen 2.3 release
[framework/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 #include "real_functions.h"
47
48 static enum DaOptions _sopt = OPT_ALLOC;
49
50 void *memset(void *memblock, int c, size_t n)
51 {
52         static void *(*memsetp)(void *,int,size_t);
53         DECLARE_VARIABLE_STANDARD;
54         void *pret;
55
56         GET_REAL_FUNC_RTLD_NEXT(memset);
57
58         PRE_PROBEBLOCK();
59
60         pret = memsetp(memblock, c, n);
61
62         POST_PACK_PROBEBLOCK_BEGIN();
63
64         PREPARE_LOCAL_BUF();
65         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
66                           API_ID_memset,
67                           "pdx", voidp_to_uint64(memblock), c,
68                           (uint64_t)(n));
69         PACK_COMMON_END('p', pret, newerrno, blockresult);
70         PACK_MEMORY(n, MEMORY_API_MANAGE, pret);
71         FLUSH_LOCAL_BUF();
72
73         POST_PACK_PROBEBLOCK_END();
74
75         return pret;
76 }
77
78 int memcmp(const void * ptr1, const void * ptr2, size_t num)
79 {
80         static int(*memcmpp)(const void *,const void *,size_t);
81         DECLARE_VARIABLE_STANDARD;
82
83         GET_REAL_FUNC_RTLD_NEXT(memcmp);
84
85         PRE_PROBEBLOCK();
86
87         ret = memcmpp(ptr1, ptr2, num);
88
89         POST_PACK_PROBEBLOCK_BEGIN();
90
91         PREPARE_LOCAL_BUF();
92         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
93                           API_ID_memcmp,
94                           "ppx", voidp_to_uint64(ptr1), voidp_to_uint64(ptr2),
95                           (uint64_t)(num));
96         PACK_COMMON_END('d', ret, newerrno, blockresult);
97         PACK_MEMORY(num, MEMORY_API_MANAGE, ret);
98         FLUSH_LOCAL_BUF();
99
100         POST_PACK_PROBEBLOCK_END();
101
102         return ret;
103 }
104
105 void *memcpy(void * destination, const void * source, size_t num )
106 {
107         static void *(*memcpyp)(void *,const void *,size_t);
108         DECLARE_VARIABLE_STANDARD;
109         void *pret;
110
111         GET_REAL_FUNC_RTLD_NEXT(memcpy);
112
113         PRE_PROBEBLOCK();
114
115         pret = memcpyp(destination, source, num);
116
117         POST_PACK_PROBEBLOCK_BEGIN();
118
119         PREPARE_LOCAL_BUF();
120         PACK_COMMON_BEGIN(MSG_PROBE_MEMORY,
121                           API_ID_memcpy,
122                           "ppx", voidp_to_uint64(destination),
123                           voidp_to_uint64(source),
124                           (uint64_t)(num));
125         PACK_COMMON_END('p', pret, newerrno, blockresult);
126         PACK_MEMORY(num, MEMORY_API_MANAGE, pret);
127         FLUSH_LOCAL_BUF();
128
129         POST_PACK_PROBEBLOCK_END();
130
131         return pret;
132 }
133