4 * Copyright 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Woojin Jung <woojin2.jung@samsung.com>
9 * Jaewon Lim <jaewon81.lim@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
11 * Anastasia Lyupa <a.lyupa@samsung.com>
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)
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.
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
29 * - Samsung RnD Institute Russia
37 #include "probeinfo.h"
42 #include "real_functions.h"
44 static enum DaOptions _sopt = OPT_THREAD;
46 int pthread_mutex_init(pthread_mutex_t *mutex,
47 const pthread_mutexattr_t *attr) {
48 static int (*pthread_mutex_initp)(pthread_mutex_t *mutex,
49 const pthread_mutexattr_t *attr);
51 BEFORE_ORIGINAL_SYNC(pthread_mutex_init, LIBPTHREAD);
53 ret = pthread_mutex_initp(mutex, attr);
55 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutex_init,
56 'd', ret, mutex, SYNC_PTHREAD_MUTEX,
58 voidp_to_uint64(mutex), voidp_to_uint64(attr));
63 int pthread_mutex_destroy(pthread_mutex_t *mutex) {
64 static int (*pthread_mutex_destroyp)(pthread_mutex_t *mutex);
66 BEFORE_ORIGINAL_SYNC(pthread_mutex_destroy, LIBPTHREAD);
68 ret = pthread_mutex_destroyp(mutex);
70 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutex_destroy,
71 'd', ret, mutex, SYNC_PTHREAD_MUTEX,
72 SYNC_API_OTHER, "p", voidp_to_uint64(mutex));
77 int real_pthread_mutex_lock(pthread_mutex_t *mutex) {
78 static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
80 GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
82 return pthread_mutex_lockp(mutex);
85 int pthread_mutex_lock(pthread_mutex_t *mutex) {
86 static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
88 DECLARE_VARIABLE_STANDARD;
89 GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
91 PRE_PROBEBLOCK_BEGIN();
94 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
95 API_ID_pthread_mutex_lock,
96 "p", voidp_to_uint64(mutex));
97 PACK_COMMON_END('d', 0, 0, blockresult);
98 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
101 PRE_PROBEBLOCK_END();
103 ret = pthread_mutex_lockp(mutex);
107 if(postBlockBegin(blockresult)) {
108 setProbePoint(&probeInfo);
111 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
112 API_ID_pthread_mutex_lock,
113 "p", voidp_to_uint64(mutex));
114 PACK_COMMON_END('d', ret, errno, blockresult);
115 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
120 errno = (newerrno != 0) ? newerrno : olderrno;
125 int pthread_mutex_timedlock(pthread_mutex_t *mutex,
126 const struct timespec *abs_timeout) {
127 static int (*pthread_mutex_timedlockp)(pthread_mutex_t *mutex,
128 const struct timespec *abs_timeout);
130 DECLARE_VARIABLE_STANDARD;
131 GET_REAL_FUNC(pthread_mutex_timedlock, LIBPTHREAD);
133 PRE_PROBEBLOCK_BEGIN();
136 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
137 API_ID_pthread_mutex_timedlock,
138 "pp", voidp_to_uint64(mutex),
139 voidp_to_uint64(abs_timeout));
140 PACK_COMMON_END('d', 0, 0, blockresult);
141 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
144 PRE_PROBEBLOCK_END();
146 ret = pthread_mutex_timedlockp(mutex, abs_timeout);
150 if(postBlockBegin(blockresult)) {
151 setProbePoint(&probeInfo);
154 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
155 API_ID_pthread_mutex_timedlock,
156 "pp", voidp_to_uint64(mutex),
157 voidp_to_uint64(abs_timeout));
158 PACK_COMMON_END('d', ret, errno, blockresult);
159 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
165 errno = (newerrno != 0) ? newerrno : olderrno;
170 int pthread_mutex_trylock(pthread_mutex_t *mutex) {
171 static int (*pthread_mutex_trylockp)(pthread_mutex_t *mutex);
173 BEFORE_ORIGINAL_SYNC(pthread_mutex_trylock, LIBPTHREAD);
175 ret = pthread_mutex_trylockp(mutex);
177 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutex_trylock,
178 'd', ret, mutex, SYNC_PTHREAD_MUTEX,
179 SYNC_API_TRY_ACQUIRE, "p",
180 voidp_to_uint64(mutex));
185 int real_pthread_mutex_unlock(pthread_mutex_t *mutex) {
186 static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
188 GET_REAL_FUNC(pthread_mutex_unlock, LIBPTHREAD);
190 return pthread_mutex_unlockp(mutex);
193 int pthread_mutex_unlock(pthread_mutex_t *mutex) {
194 static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
196 BEFORE_ORIGINAL_SYNC(pthread_mutex_unlock, LIBPTHREAD);
198 ret = pthread_mutex_unlockp(mutex);
200 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutex_unlock,
201 'd', ret, mutex, SYNC_PTHREAD_MUTEX,
202 SYNC_API_RELEASE, "p",
203 voidp_to_uint64(mutex));
208 int pthread_mutexattr_init(pthread_mutexattr_t *attr) {
209 static int (*pthread_mutexattr_initp)(pthread_mutexattr_t *attr);
211 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_init, LIBPTHREAD);
213 ret = pthread_mutexattr_initp(attr);
215 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_init,
216 'd', ret, 0, SYNC_PTHREAD_MUTEX,
218 voidp_to_uint64(attr));
223 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) {
224 static int (*pthread_mutexattr_destroyp)(pthread_mutexattr_t *attr);
226 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_destroy, LIBPTHREAD);
228 ret = pthread_mutexattr_destroyp(attr);
230 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_destroy,
231 'd', ret, 0, SYNC_PTHREAD_MUTEX,
233 voidp_to_uint64(attr));
238 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr,
240 static int (*pthread_mutexattr_getprioceilingp)(
241 const pthread_mutexattr_t *attr, int *prioceiling);
243 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprioceiling, LIBPTHREAD);
245 ret = pthread_mutexattr_getprioceilingp(attr, prioceiling);
247 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_getprioceiling,
248 'd', ret, 0, SYNC_PTHREAD_MUTEX,
249 SYNC_API_OTHER, "pp",
250 voidp_to_uint64(attr),
251 voidp_to_uint64(prioceiling));
256 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
258 static int (*pthread_mutexattr_setprioceilingp)(
259 pthread_mutexattr_t *attr, int prioceiling);
261 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprioceiling, LIBPTHREAD);
263 ret = pthread_mutexattr_setprioceilingp(attr, prioceiling);
265 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_setprioceiling,
266 'd', ret, 0, SYNC_PTHREAD_MUTEX,
267 SYNC_API_OTHER, "pd", voidp_to_uint64(attr),
273 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
275 static int (*pthread_mutexattr_getprotocolp)(
276 const pthread_mutexattr_t *attr, int *protocol);
278 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprotocol, LIBPTHREAD);
280 ret = pthread_mutexattr_getprotocolp(attr, protocol);
282 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_getprotocol,
283 'd', ret, 0, SYNC_PTHREAD_MUTEX,
284 SYNC_API_OTHER, "pp",
285 voidp_to_uint64(attr),
286 voidp_to_uint64(protocol));
291 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
293 static int (*pthread_mutexattr_setprotocolp)(
294 pthread_mutexattr_t *attr, int protocol);
296 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprotocol, LIBPTHREAD);
298 ret = pthread_mutexattr_setprotocolp(attr, protocol);
300 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_setprotocol,
301 'd', ret, 0, SYNC_PTHREAD_MUTEX,
302 SYNC_API_OTHER, "pd", voidp_to_uint64(attr),
308 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
310 static int (*pthread_mutexattr_getpsharedp)(
311 const pthread_mutexattr_t *attr, int *pshared);
313 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getpshared, LIBPTHREAD);
315 ret = pthread_mutexattr_getpsharedp(attr, pshared);
317 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_getpshared,
318 'd', ret, 0, SYNC_PTHREAD_MUTEX,
319 SYNC_API_OTHER, "pp",
320 voidp_to_uint64(attr),
321 voidp_to_uint64(pshared));
326 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
328 static int (*pthread_mutexattr_setpsharedp)(
329 pthread_mutexattr_t *attr, int pshared);
331 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setpshared, LIBPTHREAD);
333 ret = pthread_mutexattr_setpsharedp(attr, pshared);
335 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_setpshared,
336 'd', ret, 0, SYNC_PTHREAD_MUTEX,
337 SYNC_API_OTHER, "pd", voidp_to_uint64(attr),
343 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) {
344 static int (*pthread_mutexattr_gettypep)(
345 const pthread_mutexattr_t *attr, int *type);
347 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_gettype, LIBPTHREAD);
349 ret = pthread_mutexattr_gettypep(attr, type);
351 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_gettype,
352 'd', ret, 0, SYNC_PTHREAD_MUTEX,
353 SYNC_API_OTHER, "pp",
354 voidp_to_uint64(attr),
355 voidp_to_uint64(type));
360 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) {
361 static int (*pthread_mutexattr_settypep)(
362 pthread_mutexattr_t *attr, int type);
364 BEFORE_ORIGINAL_SYNC(pthread_mutexattr_settype, LIBPTHREAD);
366 ret = pthread_mutexattr_settypep(attr, type);
368 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_mutexattr_settype,
369 'd', ret, 0, SYNC_PTHREAD_MUTEX,
370 SYNC_API_OTHER, "pd",
371 voidp_to_uint64(attr),
378 int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
380 int pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
381 int prioceiling, int *old_ceiling);
384 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) {
385 static int (*pthread_cond_initp)(pthread_cond_t *cond,
386 const pthread_condattr_t *attr);
388 BEFORE_ORIGINAL_SYNC(pthread_cond_init, LIBPTHREAD);
390 ret = pthread_cond_initp(cond, attr);
392 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_cond_init,
393 'd', ret, cond, SYNC_PTHREAD_COND_VARIABLE,
394 SYNC_API_OTHER, "pp",
395 voidp_to_uint64(cond),
396 voidp_to_uint64(attr));
401 int pthread_cond_destroy(pthread_cond_t *cond) {
402 static int (*pthread_cond_destroyp)(pthread_cond_t *cond);
404 BEFORE_ORIGINAL_SYNC(pthread_cond_destroy, LIBPTHREAD);
406 ret = pthread_cond_destroyp(cond);
408 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_cond_destroy,
409 'd', ret, cond, SYNC_PTHREAD_COND_VARIABLE,
411 voidp_to_uint64(cond));
416 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
417 static int (*pthread_cond_waitp)(pthread_cond_t *cond,
418 pthread_mutex_t *mutex);
420 DECLARE_VARIABLE_STANDARD;
421 GET_REAL_FUNC(pthread_cond_wait, LIBPTHREAD);
423 PRE_PROBEBLOCK_BEGIN();
424 // send WAIT_START log
427 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
428 API_ID_pthread_cond_wait,
430 voidp_to_uint64(cond),
431 voidp_to_uint64(mutex));
432 PACK_COMMON_END('d', 0, 0, blockresult);
433 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
436 PRE_PROBEBLOCK_END();
438 ret = pthread_cond_waitp(cond, mutex);
442 if(postBlockBegin(blockresult)) {
443 setProbePoint(&probeInfo);
446 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
447 API_ID_pthread_cond_wait,
449 voidp_to_uint64(cond),
450 voidp_to_uint64(mutex));
451 PACK_COMMON_END('d', ret, errno, blockresult);
452 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
457 errno = (newerrno != 0) ? newerrno : olderrno;
462 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
463 const struct timespec *abstime) {
464 static int (*pthread_cond_timedwaitp)(pthread_cond_t *cond,
465 pthread_mutex_t *mutex, const struct timespec *abstime);
467 DECLARE_VARIABLE_STANDARD;
468 GET_REAL_FUNC(pthread_cond_timedwait, LIBPTHREAD);
470 PRE_PROBEBLOCK_BEGIN();
471 // send WAIT_START log
474 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
475 API_ID_pthread_cond_timedwait,
477 voidp_to_uint64(cond),
478 voidp_to_uint64(mutex),
479 voidp_to_uint64(abstime));
480 PACK_COMMON_END('d', 0, 0, blockresult);
481 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
484 PRE_PROBEBLOCK_END();
486 ret = pthread_cond_timedwaitp(cond, mutex, abstime);
490 if(postBlockBegin(blockresult)) {
491 setProbePoint(&probeInfo);
494 PACK_COMMON_BEGIN(MSG_PROBE_SYNC,
495 API_ID_pthread_cond_timedwait,
497 voidp_to_uint64(cond),
498 voidp_to_uint64(mutex),
499 voidp_to_uint64(abstime));
500 PACK_COMMON_END('d', ret, errno, blockresult);
501 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
507 errno = (newerrno != 0) ? newerrno : olderrno;
512 int pthread_cond_signal(pthread_cond_t *cond) {
513 static int (*pthread_cond_signalp)(pthread_cond_t *cond);
515 BEFORE_ORIGINAL_SYNC(pthread_cond_signal, LIBPTHREAD);
517 ret = pthread_cond_signalp(cond);
519 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_cond_signal,
520 'd', ret, cond, SYNC_PTHREAD_COND_VARIABLE,
521 SYNC_API_NOTIFY, "p", voidp_to_uint64(cond));
526 int pthread_cond_broadcast(pthread_cond_t *cond) {
527 static int (*pthread_cond_broadcastp)(pthread_cond_t *cond);
529 BEFORE_ORIGINAL_SYNC(pthread_cond_broadcast, LIBPTHREAD);
531 ret = pthread_cond_broadcastp(cond);
533 AFTER_PACK_ORIGINAL_SYNC(API_ID_pthread_cond_broadcast,
534 'd', ret, cond, SYNC_PTHREAD_COND_VARIABLE,
535 SYNC_API_NOTIFY_ALL, "p", voidp_to_uint64(cond));