blob: efee1544f350ae12a478108fe22b00bfa5c61056 [file] [log] [blame]
njn16eeb4e2005-06-16 03:56:58 +00001
sewardjcbdddcf2005-03-10 23:23:45 +00002/*--------------------------------------------------------------------*/
njn16eeb4e2005-06-16 03:56:58 +00003/*--- Client-space code for the core. vg_preloaded.c ---*/
sewardjcbdddcf2005-03-10 23:23:45 +00004/*--------------------------------------------------------------------*/
5
6/*
njnc0ae7052005-08-25 22:55:19 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardjcbdddcf2005-03-10 23:23:45 +00009
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 Julian Seward
sewardjcbdddcf2005-03-10 23:23:45 +000011 jseward@acm.org
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31
32/* ---------------------------------------------------------------------
njn16eeb4e2005-06-16 03:56:58 +000033 ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU.
34
35 These functions are not called directly - they're the targets of code
36 redirection or load notifications (see pub_core_redir.h for info).
37 They're named weirdly so that the intercept code can find them when the
38 shared object is initially loaded.
39
40 Note that this filename has the "vg_" prefix because it can appear
41 in stack traces, and the "vg_" makes it a little clearer that it
42 originates from Valgrind.
sewardjcbdddcf2005-03-10 23:23:45 +000043 ------------------------------------------------------------------ */
44
njnc7561b92005-06-19 01:24:32 +000045#include "pub_core_basics.h"
njn93fe3b22005-12-21 20:22:52 +000046#include "pub_core_clreq.h"
njn24a6efb2005-06-20 03:36:51 +000047#include "pub_core_debuginfo.h" // Needed for pub_core_redir.h
48#include "pub_core_redir.h" // For VG_NOTIFY_ON_LOAD
sewardjcbdddcf2005-03-10 23:23:45 +000049
50/* ---------------------------------------------------------------------
51 Hook for running __libc_freeres once the program exits.
52 ------------------------------------------------------------------ */
53
njn16eeb4e2005-06-16 03:56:58 +000054void VG_NOTIFY_ON_LOAD(freeres)( void );
55void VG_NOTIFY_ON_LOAD(freeres)( void )
sewardjcbdddcf2005-03-10 23:23:45 +000056{
57 int res;
sewardj745fc452006-10-17 02:03:11 +000058#if !defined(__UCLIBC__) && !defined(VGO_aix5)
sewardjcbdddcf2005-03-10 23:23:45 +000059 extern void __libc_freeres(void);
60 __libc_freeres();
61#endif
sewardj0ec07f32006-01-12 12:32:32 +000062 VALGRIND_DO_CLIENT_REQUEST(res, 0 /* default */,
sewardj9af10a12006-02-01 14:59:42 +000063 VG_USERREQ__LIBC_FREERES_DONE,
64 0, 0, 0, 0, 0);
sewardjcbdddcf2005-03-10 23:23:45 +000065 /*NOTREACHED*/
66 *(int *)0 = 'x';
67}
68
sewardjeb3603e2006-01-24 01:01:17 +000069
sewardjcbdddcf2005-03-10 23:23:45 +000070/*--------------------------------------------------------------------*/
njn16eeb4e2005-06-16 03:56:58 +000071/*--- end ---*/
sewardjcbdddcf2005-03-10 23:23:45 +000072/*--------------------------------------------------------------------*/
73
sewardj0ec07f32006-01-12 12:32:32 +000074#if 0
75
76#define PTH_FUNC(ret_ty, f, args...) \
77 ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args); \
78 ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args)
79
80#include <stdio.h>
81#include <pthread.h>
82
83// pthread_create
84PTH_FUNC(int, pthreadZucreateZAZa, // pthread_create@*
85 pthread_t *thread, const pthread_attr_t *attr,
86 void *(*start) (void *), void *arg)
87{
88 int ret;
89 void* fn;
90 VALGRIND_GET_NRADDR(fn);
91 fprintf(stderr, "<< pthread_create wrapper"); fflush(stderr);
92
93 CALL_FN_W_WWWW(ret, fn, thread,attr,start,arg);
94
95 fprintf(stderr, " -> %d >>\n", ret);
96 return ret;
97}
98
99// pthread_mutex_lock
100PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
101 pthread_mutex_t *mutex)
102{
103 int ret;
104 void* fn;
105 VALGRIND_GET_ORIG_FN(fn);
106 fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr);
107
108 CALL_FN_W_W(ret, fn, mutex);
109
110 fprintf(stderr, " -> %d >>\n", ret);
111 return ret;
112}
113
114// pthread_mutex_unlock
115PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
116 pthread_mutex_t *mutex)
117{
118 int ret;
119 void* fn;
120 VALGRIND_GET_ORIG_FN(fn);
121
122 fprintf(stderr, "<< pthread_mxunlk %p", mutex); fflush(stderr);
123
124 CALL_FN_W_W(ret, fn, mutex);
125
126 fprintf(stderr, " -> %d >>\n", ret);
127 return ret;
128}
129
130#endif