njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 1 | |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 3 | /*--- Client-space code for the core. vg_preloaded.c ---*/ |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | c0ae705 | 2005-08-25 22:55:19 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 9 | |
sewardj | 9ebd6e0 | 2007-01-08 06:01:59 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2007 Julian Seward |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 11 | 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 | /* --------------------------------------------------------------------- |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 33 | 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. |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 43 | ------------------------------------------------------------------ */ |
| 44 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 45 | #include "pub_core_basics.h" |
njn | 93fe3b2 | 2005-12-21 20:22:52 +0000 | [diff] [blame] | 46 | #include "pub_core_clreq.h" |
njn | 24a6efb | 2005-06-20 03:36:51 +0000 | [diff] [blame] | 47 | #include "pub_core_debuginfo.h" // Needed for pub_core_redir.h |
| 48 | #include "pub_core_redir.h" // For VG_NOTIFY_ON_LOAD |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 49 | |
| 50 | /* --------------------------------------------------------------------- |
| 51 | Hook for running __libc_freeres once the program exits. |
| 52 | ------------------------------------------------------------------ */ |
| 53 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 54 | void VG_NOTIFY_ON_LOAD(freeres)( void ); |
| 55 | void VG_NOTIFY_ON_LOAD(freeres)( void ) |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 56 | { |
| 57 | int res; |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 58 | #if !defined(__UCLIBC__) && !defined(VGO_aix5) |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 59 | extern void __libc_freeres(void); |
| 60 | __libc_freeres(); |
| 61 | #endif |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 62 | VALGRIND_DO_CLIENT_REQUEST(res, 0 /* default */, |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 63 | VG_USERREQ__LIBC_FREERES_DONE, |
| 64 | 0, 0, 0, 0, 0); |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 65 | /*NOTREACHED*/ |
| 66 | *(int *)0 = 'x'; |
| 67 | } |
| 68 | |
sewardj | eb3603e | 2006-01-24 01:01:17 +0000 | [diff] [blame] | 69 | |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 70 | /*--------------------------------------------------------------------*/ |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 71 | /*--- end ---*/ |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 72 | /*--------------------------------------------------------------------*/ |
| 73 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 74 | #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 |
| 84 | PTH_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 |
| 100 | PTH_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 |
| 115 | PTH_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 |