sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A replacement for the standard libpthread.so. ---*/ |
| 4 | /*--- vg_libpthread.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an x86 protected-mode emulator |
| 9 | designed for debugging and profiling binaries on x86-Unixes. |
| 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file LICENSE. |
| 30 | */ |
| 31 | |
| 32 | /* ALL THIS CODE RUNS ON THE SIMULATED CPU. |
| 33 | |
| 34 | This is a replacement for the standard libpthread.so. It is loaded |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 35 | as part of the client's image (if required) and directs pthread |
| 36 | calls through to Valgrind's request mechanism. |
| 37 | |
| 38 | A couple of caveats. |
| 39 | |
| 40 | 1. Since it's a binary-compatible replacement for an existing library, |
| 41 | we must take care to used exactly the same data layouts, etc, as |
| 42 | the standard pthread.so does. |
| 43 | |
| 44 | 2. Since this runs as part of the client, there are no specific |
| 45 | restrictions on what headers etc we can include, so long as |
| 46 | this libpthread.so does not end up having dependencies on .so's |
| 47 | which the real one doesn't. |
| 48 | |
| 49 | Later ... it appears we cannot call file-related stuff in libc here, |
| 50 | perhaps fair enough. Be careful what you call from here. Even exit() |
| 51 | doesn't work (gives infinite recursion and then stack overflow); hence |
| 52 | myexit(). Also fprintf doesn't seem safe. |
| 53 | */ |
| 54 | |
| 55 | #include "valgrind.h" /* For the request-passing mechanism */ |
| 56 | #include "vg_include.h" /* For the VG_USERREQ__* constants */ |
| 57 | |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 58 | #define __USE_UNIX98 |
| 59 | #include <sys/types.h> |
| 60 | #include <pthread.h> |
| 61 | #undef __USE_UNIX98 |
| 62 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 63 | #include <unistd.h> |
| 64 | #include <string.h> |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 65 | #ifdef GLIBC_2_1 |
| 66 | #include <sys/time.h> |
| 67 | #endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 68 | |
sewardj | 705d3cb | 2002-05-23 13:13:12 +0000 | [diff] [blame] | 69 | |
| 70 | /* --------------------------------------------------------------------- |
| 71 | Forwardses. |
| 72 | ------------------------------------------------------------------ */ |
| 73 | |
| 74 | static void wait_for_fd_to_be_readable_or_erring ( int fd ); |
| 75 | |
| 76 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 77 | /* --------------------------------------------------------------------- |
| 78 | Helpers. We have to be pretty self-sufficient. |
| 79 | ------------------------------------------------------------------ */ |
| 80 | |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 81 | /* Number of times any given error message is printed. */ |
| 82 | #define N_MOANS 3 |
| 83 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 84 | /* Extract from Valgrind the value of VG_(clo_trace_pthread_level). |
| 85 | Returns 0 (none) if not running on Valgrind. */ |
| 86 | static |
| 87 | int get_pt_trace_level ( void ) |
| 88 | { |
| 89 | int res; |
| 90 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 91 | VG_USERREQ__GET_PTHREAD_TRACE_LEVEL, |
| 92 | 0, 0, 0, 0); |
| 93 | return res; |
| 94 | } |
| 95 | |
| 96 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 97 | static |
| 98 | void myexit ( int arg ) |
| 99 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 100 | int __res; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 101 | __asm__ volatile ("movl %%ecx, %%ebx ; int $0x80" |
| 102 | : "=a" (__res) |
| 103 | : "0" (__NR_exit), |
| 104 | "c" (arg) ); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 105 | /* We don't bother to mention the fact that this asm trashes %ebx, |
| 106 | since it won't return. If you ever do let it return ... fix |
| 107 | this! */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 111 | /* We need this guy -- it's in valgrind.so. */ |
| 112 | extern void VG_(startup) ( void ); |
| 113 | |
| 114 | |
| 115 | /* Just start up Valgrind if it's not already going. VG_(startup)() |
| 116 | detects and ignores second and subsequent calls. */ |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 117 | static __inline__ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 118 | void ensure_valgrind ( char* caller ) |
| 119 | { |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 120 | VG_(startup)(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 121 | } |
| 122 | |
sewardj | bea1caa | 2002-05-10 23:20:58 +0000 | [diff] [blame] | 123 | /* While we're at it ... hook our own startup function into this |
| 124 | game. */ |
| 125 | __asm__ ( |
| 126 | ".section .init\n" |
| 127 | "\tcall vgPlain_startup" |
| 128 | ); |
| 129 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 130 | |
| 131 | static |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 132 | __attribute__((noreturn)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 133 | void barf ( char* str ) |
| 134 | { |
| 135 | char buf[100]; |
| 136 | buf[0] = 0; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 137 | strcat(buf, "\nvalgrind's libpthread.so: "); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 138 | strcat(buf, str); |
| 139 | strcat(buf, "\n\n"); |
| 140 | write(2, buf, strlen(buf)); |
| 141 | myexit(1); |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 142 | /* We have to persuade gcc into believing this doesn't return. */ |
| 143 | while (1) { }; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 147 | static void ignored ( char* msg ) |
| 148 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 149 | if (get_pt_trace_level() >= 0) { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 150 | char* ig = "valgrind's libpthread.so: IGNORED call to: "; |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 151 | write(2, ig, strlen(ig)); |
| 152 | write(2, msg, strlen(msg)); |
| 153 | ig = "\n"; |
| 154 | write(2, ig, strlen(ig)); |
| 155 | } |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 156 | } |
| 157 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 158 | static void kludged ( char* msg ) |
| 159 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 160 | if (get_pt_trace_level() >= 0) { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 161 | char* ig = "valgrind's libpthread.so: KLUDGED call to: "; |
| 162 | write(2, ig, strlen(ig)); |
| 163 | write(2, msg, strlen(msg)); |
| 164 | ig = "\n"; |
| 165 | write(2, ig, strlen(ig)); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static void not_inside ( char* msg ) |
| 170 | { |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 171 | VG_(startup)(); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 172 | } |
| 173 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 174 | __attribute__((noreturn)) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 175 | void vgPlain_unimp ( char* what ) |
| 176 | { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 177 | char* ig = "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: "; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 178 | write(2, ig, strlen(ig)); |
| 179 | write(2, what, strlen(what)); |
| 180 | ig = "\n"; |
| 181 | write(2, ig, strlen(ig)); |
| 182 | barf("Please report this bug to me at: jseward@acm.org"); |
| 183 | } |
| 184 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 185 | |
| 186 | /* --------------------------------------------------------------------- |
| 187 | Pass pthread_ calls to Valgrind's request mechanism. |
| 188 | ------------------------------------------------------------------ */ |
| 189 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 190 | #include <stdio.h> |
| 191 | #include <errno.h> |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 192 | #include <assert.h> |
| 193 | #include <sys/time.h> /* gettimeofday */ |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 194 | |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 195 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 196 | /* --------------------------------------------------- |
| 197 | THREAD ATTRIBUTES |
| 198 | ------------------------------------------------ */ |
| 199 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 200 | int pthread_attr_init(pthread_attr_t *attr) |
| 201 | { |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 202 | /* Just initialise the fields which we might look at. */ |
| 203 | attr->__detachstate = PTHREAD_CREATE_JOINABLE; |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) |
| 208 | { |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 209 | if (detachstate != PTHREAD_CREATE_JOINABLE |
| 210 | && detachstate != PTHREAD_CREATE_DETACHED) |
| 211 | return EINVAL; |
| 212 | attr->__detachstate = detachstate; |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 216 | int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) |
| 217 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 218 | static int moans = N_MOANS; |
| 219 | if (moans-- > 0) |
| 220 | ignored("pthread_attr_setinheritsched"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 221 | return 0; |
| 222 | } |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 223 | |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 224 | __attribute__((weak)) |
| 225 | int pthread_attr_setstacksize (pthread_attr_t *__attr, |
| 226 | size_t __stacksize) |
| 227 | { |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 228 | size_t limit; |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 229 | ensure_valgrind("pthread_attr_setstacksize"); |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 230 | limit = VG_PTHREAD_STACK_SIZE - VG_AR_CLIENT_STACKBASE_REDZONE_SZB |
| 231 | - 1000; /* paranoia */ |
| 232 | if (__stacksize < limit) |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | barf("pthread_attr_setstacksize: " |
| 235 | "requested size >= VG_PTHREAD_STACK_SIZE\n " |
| 236 | "edit vg_include.h and rebuild."); |
| 237 | } |
| 238 | |
| 239 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 240 | /* This is completely bogus. */ |
| 241 | int pthread_attr_getschedparam(const pthread_attr_t *attr, |
| 242 | struct sched_param *param) |
| 243 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 244 | static int moans = N_MOANS; |
| 245 | if (moans-- > 0) |
| 246 | kludged("pthread_attr_getschedparam"); |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 247 | # ifdef GLIBC_2_1 |
| 248 | if (param) param->sched_priority = 0; /* who knows */ |
| 249 | # else |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 250 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 251 | # endif |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | int pthread_attr_setschedparam(pthread_attr_t *attr, |
| 256 | const struct sched_param *param) |
| 257 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 258 | static int moans = N_MOANS; |
| 259 | if (moans-- > 0) |
| 260 | ignored("pthread_attr_setschedparam"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int pthread_attr_destroy(pthread_attr_t *attr) |
| 265 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 266 | static int moans = N_MOANS; |
| 267 | if (moans-- > 0) |
| 268 | ignored("pthread_attr_destroy"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 269 | return 0; |
| 270 | } |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 271 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 272 | /* --------------------------------------------------- |
| 273 | Helper functions for running a thread |
| 274 | and for clearing up afterwards. |
| 275 | ------------------------------------------------ */ |
| 276 | |
| 277 | /* All exiting threads eventually pass through here, bearing the |
| 278 | return value, or PTHREAD_CANCELED, in ret_val. */ |
| 279 | static |
| 280 | __attribute__((noreturn)) |
| 281 | void thread_exit_wrapper ( void* ret_val ) |
| 282 | { |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 283 | int detached, res; |
| 284 | CleanupEntry cu; |
| 285 | pthread_key_t key; |
| 286 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 287 | /* Run this thread's cleanup handlers. */ |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 288 | while (1) { |
| 289 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 290 | VG_USERREQ__CLEANUP_POP, |
| 291 | &cu, 0, 0, 0); |
| 292 | if (res == -1) break; /* stack empty */ |
| 293 | assert(res == 0); |
| 294 | if (0) printf("running exit cleanup handler"); |
| 295 | cu.fn ( cu.arg ); |
| 296 | } |
| 297 | |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 298 | /* Run this thread's key finalizers. Really this should be run |
| 299 | PTHREAD_DESTRUCTOR_ITERATIONS times. */ |
| 300 | for (key = 0; key < VG_N_THREAD_KEYS; key++) { |
| 301 | VALGRIND_MAGIC_SEQUENCE(res, (-2) /* default */, |
| 302 | VG_USERREQ__GET_KEY_D_AND_S, |
| 303 | key, &cu, 0, 0 ); |
| 304 | if (res == 0) { |
| 305 | /* valid key */ |
| 306 | if (cu.fn && cu.arg) |
| 307 | cu.fn /* destructor for key */ |
| 308 | ( cu.arg /* specific for key for this thread */ ); |
| 309 | continue; |
| 310 | } |
| 311 | assert(res == -1); |
| 312 | } |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 313 | |
| 314 | /* Decide on my final disposition. */ |
| 315 | VALGRIND_MAGIC_SEQUENCE(detached, (-1) /* default */, |
| 316 | VG_USERREQ__SET_OR_GET_DETACH, |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 317 | 2 /* get */, pthread_self(), 0, 0); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 318 | assert(detached == 0 || detached == 1); |
| 319 | |
| 320 | if (detached) { |
| 321 | /* Detached; I just quit right now. */ |
| 322 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 323 | VG_USERREQ__QUIT, 0, 0, 0, 0); |
| 324 | } else { |
| 325 | /* Not detached; so I wait for a joiner. */ |
| 326 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 327 | VG_USERREQ__WAIT_JOINER, ret_val, 0, 0, 0); |
| 328 | } |
| 329 | /* NOTREACHED */ |
| 330 | barf("thread_exit_wrapper: still alive?!"); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /* This function is a wrapper function for running a thread. It runs |
| 335 | the root function specified in pthread_create, and then, should the |
| 336 | root function return a value, it arranges to run the thread's |
| 337 | cleanup handlers and exit correctly. */ |
| 338 | |
| 339 | /* Struct used to convey info from pthread_create to |
| 340 | thread_wrapper. */ |
| 341 | typedef |
| 342 | struct { |
| 343 | pthread_attr_t* attr; |
| 344 | void* (*root_fn) ( void* ); |
| 345 | void* arg; |
| 346 | } |
| 347 | NewThreadInfo; |
| 348 | |
| 349 | |
| 350 | /* This is passed to the VG_USERREQ__APPLY_IN_NEW_THREAD and so must |
| 351 | not return. Note that this runs in the new thread, not the |
| 352 | parent. */ |
| 353 | static |
| 354 | __attribute__((noreturn)) |
| 355 | void thread_wrapper ( NewThreadInfo* info ) |
| 356 | { |
| 357 | int res; |
| 358 | pthread_attr_t* attr; |
| 359 | void* (*root_fn) ( void* ); |
| 360 | void* arg; |
| 361 | void* ret_val; |
| 362 | |
| 363 | attr = info->attr; |
| 364 | root_fn = info->root_fn; |
| 365 | arg = info->arg; |
| 366 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 367 | /* Free up the arg block that pthread_create malloced. */ |
| 368 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 369 | VG_USERREQ__FREE, info, 0, 0, 0); |
| 370 | assert(res == 0); |
| 371 | |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 372 | /* Minimally observe the attributes supplied. */ |
| 373 | if (attr) { |
| 374 | assert(attr->__detachstate == PTHREAD_CREATE_DETACHED |
| 375 | || attr->__detachstate == PTHREAD_CREATE_JOINABLE); |
| 376 | if (attr->__detachstate == PTHREAD_CREATE_DETACHED) |
| 377 | pthread_detach(pthread_self()); |
| 378 | } |
| 379 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 380 | /* The root function might not return. But if it does we simply |
| 381 | move along to thread_exit_wrapper. All other ways out for the |
| 382 | thread (cancellation, or calling pthread_exit) lead there |
| 383 | too. */ |
| 384 | ret_val = root_fn(arg); |
| 385 | thread_exit_wrapper(ret_val); |
| 386 | /* NOTREACHED */ |
| 387 | } |
| 388 | |
| 389 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 390 | /* --------------------------------------------------- |
| 391 | THREADs |
| 392 | ------------------------------------------------ */ |
| 393 | |
sewardj | ff42d1d | 2002-05-22 13:17:31 +0000 | [diff] [blame] | 394 | __attribute__((weak)) |
| 395 | int pthread_yield ( void ) |
| 396 | { |
| 397 | int res; |
| 398 | ensure_valgrind("pthread_yield"); |
| 399 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 400 | VG_USERREQ__PTHREAD_YIELD, 0, 0, 0, 0); |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 405 | int pthread_equal(pthread_t thread1, pthread_t thread2) |
| 406 | { |
| 407 | return thread1 == thread2 ? 1 : 0; |
| 408 | } |
| 409 | |
| 410 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 411 | /* Bundle up the args into a malloc'd block and create a new thread |
| 412 | consisting of thread_wrapper() applied to said malloc'd block. */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 413 | int |
| 414 | pthread_create (pthread_t *__restrict __thread, |
| 415 | __const pthread_attr_t *__restrict __attr, |
| 416 | void *(*__start_routine) (void *), |
| 417 | void *__restrict __arg) |
| 418 | { |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 419 | int tid_child; |
| 420 | NewThreadInfo* info; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 421 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 422 | ensure_valgrind("pthread_create"); |
| 423 | |
| 424 | /* Allocate space for the arg block. thread_wrapper will free |
| 425 | it. */ |
| 426 | VALGRIND_MAGIC_SEQUENCE(info, NULL /* default */, |
| 427 | VG_USERREQ__MALLOC, |
| 428 | sizeof(NewThreadInfo), 0, 0, 0); |
| 429 | assert(info != NULL); |
| 430 | |
| 431 | info->attr = (pthread_attr_t*)__attr; |
| 432 | info->root_fn = __start_routine; |
| 433 | info->arg = __arg; |
| 434 | VALGRIND_MAGIC_SEQUENCE(tid_child, VG_INVALID_THREADID /* default */, |
| 435 | VG_USERREQ__APPLY_IN_NEW_THREAD, |
| 436 | &thread_wrapper, info, 0, 0); |
| 437 | assert(tid_child != VG_INVALID_THREADID); |
| 438 | |
| 439 | if (__thread) |
| 440 | *__thread = tid_child; |
| 441 | return 0; /* success */ |
| 442 | } |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 443 | |
| 444 | |
| 445 | int |
| 446 | pthread_join (pthread_t __th, void **__thread_return) |
| 447 | { |
| 448 | int res; |
| 449 | ensure_valgrind("pthread_join"); |
| 450 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 451 | VG_USERREQ__PTHREAD_JOIN, |
| 452 | __th, __thread_return, 0, 0); |
| 453 | return res; |
| 454 | } |
| 455 | |
| 456 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 457 | void pthread_exit(void *retval) |
| 458 | { |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 459 | ensure_valgrind("pthread_exit"); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 460 | /* Simple! */ |
| 461 | thread_exit_wrapper(retval); |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 462 | } |
| 463 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 464 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 465 | pthread_t pthread_self(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 466 | { |
| 467 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 468 | ensure_valgrind("pthread_self"); |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 469 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 470 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 471 | 0, 0, 0, 0); |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 472 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 473 | barf("pthread_self: invalid ThreadId"); |
| 474 | return tid; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 478 | int pthread_detach(pthread_t th) |
| 479 | { |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 480 | int res; |
| 481 | ensure_valgrind("pthread_detach"); |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 482 | /* First we enquire as to the current detach state. */ |
| 483 | VALGRIND_MAGIC_SEQUENCE(res, (-2) /* default */, |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 484 | VG_USERREQ__SET_OR_GET_DETACH, |
sewardj | 7989d0c | 2002-05-28 11:00:01 +0000 | [diff] [blame] | 485 | 2 /* get */, th, 0, 0); |
| 486 | if (res == -1) /* not found */ |
| 487 | return ESRCH; |
| 488 | if (res == 1) /* already detached */ |
| 489 | return EINVAL; |
| 490 | if (res == 0) { |
| 491 | VALGRIND_MAGIC_SEQUENCE(res, (-2) /* default */, |
| 492 | VG_USERREQ__SET_OR_GET_DETACH, |
| 493 | 1 /* set */, th, 0, 0); |
| 494 | assert(res == 0); |
| 495 | return 0; |
| 496 | } |
| 497 | barf("pthread_detach"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 501 | /* --------------------------------------------------- |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 502 | CLEANUP STACKS |
| 503 | ------------------------------------------------ */ |
| 504 | |
| 505 | void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, |
| 506 | void (*__routine) (void *), |
| 507 | void *__arg) |
| 508 | { |
| 509 | int res; |
| 510 | CleanupEntry cu; |
| 511 | ensure_valgrind("_pthread_cleanup_push"); |
| 512 | cu.fn = __routine; |
| 513 | cu.arg = __arg; |
| 514 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 515 | VG_USERREQ__CLEANUP_PUSH, |
| 516 | &cu, 0, 0, 0); |
| 517 | assert(res == 0); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer, |
| 522 | void (*__routine) (void *), |
| 523 | void *__arg) |
| 524 | { |
| 525 | /* As _pthread_cleanup_push, but first save the thread's original |
| 526 | cancellation type in __buffer and set it to Deferred. */ |
| 527 | int orig_ctype; |
| 528 | ensure_valgrind("_pthread_cleanup_push_defer"); |
| 529 | /* Set to Deferred, and put the old cancellation type in res. */ |
| 530 | assert(-1 != PTHREAD_CANCEL_DEFERRED); |
| 531 | assert(-1 != PTHREAD_CANCEL_ASYNCHRONOUS); |
| 532 | assert(sizeof(struct _pthread_cleanup_buffer) >= sizeof(int)); |
| 533 | VALGRIND_MAGIC_SEQUENCE(orig_ctype, (-1) /* default */, |
| 534 | VG_USERREQ__SET_CANCELTYPE, |
| 535 | PTHREAD_CANCEL_DEFERRED, 0, 0, 0); |
| 536 | assert(orig_ctype != -1); |
| 537 | *((int*)(__buffer)) = orig_ctype; |
| 538 | /* Now push the cleanup. */ |
| 539 | _pthread_cleanup_push(NULL, __routine, __arg); |
| 540 | } |
| 541 | |
| 542 | |
| 543 | void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer, |
| 544 | int __execute) |
| 545 | { |
| 546 | int res; |
| 547 | CleanupEntry cu; |
| 548 | ensure_valgrind("_pthread_cleanup_push"); |
| 549 | cu.fn = cu.arg = NULL; /* paranoia */ |
| 550 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 551 | VG_USERREQ__CLEANUP_POP, |
| 552 | &cu, 0, 0, 0); |
| 553 | if (res == 0) { |
| 554 | /* pop succeeded */ |
| 555 | if (__execute) { |
| 556 | cu.fn ( cu.arg ); |
| 557 | } |
| 558 | return; |
| 559 | } |
| 560 | if (res == -1) { |
| 561 | /* stack underflow */ |
| 562 | return; |
| 563 | } |
| 564 | barf("_pthread_cleanup_pop"); |
| 565 | } |
| 566 | |
| 567 | |
| 568 | void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer, |
| 569 | int __execute) |
| 570 | { |
| 571 | int orig_ctype, fake_ctype; |
| 572 | /* As _pthread_cleanup_pop, but after popping/running the handler, |
| 573 | restore the thread's original cancellation type from the first |
| 574 | word of __buffer. */ |
| 575 | _pthread_cleanup_pop(NULL, __execute); |
| 576 | orig_ctype = *((int*)(__buffer)); |
| 577 | assert(orig_ctype == PTHREAD_CANCEL_DEFERRED |
| 578 | || orig_ctype == PTHREAD_CANCEL_ASYNCHRONOUS); |
| 579 | assert(-1 != PTHREAD_CANCEL_DEFERRED); |
| 580 | assert(-1 != PTHREAD_CANCEL_ASYNCHRONOUS); |
| 581 | assert(sizeof(struct _pthread_cleanup_buffer) >= sizeof(int)); |
| 582 | VALGRIND_MAGIC_SEQUENCE(fake_ctype, (-1) /* default */, |
| 583 | VG_USERREQ__SET_CANCELTYPE, |
| 584 | orig_ctype, 0, 0, 0); |
| 585 | assert(fake_ctype == PTHREAD_CANCEL_DEFERRED); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 590 | MUTEX ATTRIBUTES |
| 591 | ------------------------------------------------ */ |
| 592 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 593 | int __pthread_mutexattr_init(pthread_mutexattr_t *attr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 594 | { |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 595 | attr->__mutexkind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 596 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 597 | } |
| 598 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 599 | int __pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 600 | { |
| 601 | switch (type) { |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 602 | # ifndef GLIBC_2_1 |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 603 | case PTHREAD_MUTEX_TIMED_NP: |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 604 | case PTHREAD_MUTEX_ADAPTIVE_NP: |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 605 | # endif |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 606 | # ifdef GLIBC_2_1 |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 607 | case PTHREAD_MUTEX_FAST_NP: |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 608 | # endif |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 609 | case PTHREAD_MUTEX_RECURSIVE_NP: |
| 610 | case PTHREAD_MUTEX_ERRORCHECK_NP: |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 611 | attr->__mutexkind = type; |
| 612 | return 0; |
| 613 | default: |
| 614 | return EINVAL; |
| 615 | } |
| 616 | } |
| 617 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 618 | int __pthread_mutexattr_destroy(pthread_mutexattr_t *attr) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 619 | { |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | |
| 624 | /* --------------------------------------------------- |
| 625 | MUTEXes |
| 626 | ------------------------------------------------ */ |
| 627 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 628 | int __pthread_mutex_init(pthread_mutex_t *mutex, |
| 629 | const pthread_mutexattr_t *mutexattr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 630 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 631 | mutex->__m_count = 0; |
| 632 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 633 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
| 634 | if (mutexattr) |
| 635 | mutex->__m_kind = mutexattr->__mutexkind; |
| 636 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 637 | } |
| 638 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 639 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 640 | int __pthread_mutex_lock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 641 | { |
| 642 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 643 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 644 | if (RUNNING_ON_VALGRIND) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 645 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 646 | VG_USERREQ__PTHREAD_MUTEX_LOCK, |
| 647 | mutex, 0, 0, 0); |
| 648 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 649 | } else { |
| 650 | if (moans-- > 0) |
| 651 | not_inside("pthread_mutex_lock"); |
| 652 | return 0; /* success */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 656 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 657 | int __pthread_mutex_trylock(pthread_mutex_t *mutex) |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 658 | { |
| 659 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 660 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 661 | if (RUNNING_ON_VALGRIND) { |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 662 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 663 | VG_USERREQ__PTHREAD_MUTEX_TRYLOCK, |
| 664 | mutex, 0, 0, 0); |
| 665 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 666 | } else { |
| 667 | if (moans-- > 0) |
| 668 | not_inside("pthread_mutex_trylock"); |
| 669 | return 0; |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 673 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 674 | int __pthread_mutex_unlock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 675 | { |
| 676 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 677 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 678 | if (RUNNING_ON_VALGRIND) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 679 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 680 | VG_USERREQ__PTHREAD_MUTEX_UNLOCK, |
| 681 | mutex, 0, 0, 0); |
| 682 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 683 | } else { |
| 684 | if (moans-- > 0) |
| 685 | not_inside("pthread_mutex_unlock"); |
| 686 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 690 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 691 | int __pthread_mutex_destroy(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 692 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 693 | /* Valgrind doesn't hold any resources on behalf of the mutex, so no |
| 694 | need to involve it. */ |
| 695 | if (mutex->__m_count > 0) |
| 696 | return EBUSY; |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 697 | mutex->__m_count = 0; |
| 698 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 699 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 700 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 704 | /* --------------------------------------------------- |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 705 | CONDITION VARIABLES |
| 706 | ------------------------------------------------ */ |
| 707 | |
| 708 | /* LinuxThreads supports no attributes for conditions. Hence ... */ |
| 709 | |
| 710 | int pthread_condattr_init(pthread_condattr_t *attr) |
| 711 | { |
| 712 | return 0; |
| 713 | } |
| 714 | |
sewardj | 0738a59 | 2002-04-20 13:59:33 +0000 | [diff] [blame] | 715 | int pthread_condattr_destroy(pthread_condattr_t *attr) |
| 716 | { |
| 717 | return 0; |
| 718 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 719 | |
| 720 | int pthread_cond_init( pthread_cond_t *cond, |
| 721 | const pthread_condattr_t *cond_attr) |
| 722 | { |
| 723 | cond->__c_waiting = (_pthread_descr)VG_INVALID_THREADID; |
| 724 | return 0; |
| 725 | } |
| 726 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 727 | int pthread_cond_destroy(pthread_cond_t *cond) |
| 728 | { |
| 729 | /* should check that no threads are waiting on this CV */ |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 730 | static int moans = N_MOANS; |
| 731 | if (moans-- > 0) |
| 732 | kludged("pthread_cond_destroy"); |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 733 | return 0; |
| 734 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 735 | |
| 736 | /* --------------------------------------------------- |
| 737 | SCHEDULING |
| 738 | ------------------------------------------------ */ |
| 739 | |
| 740 | /* This is completely bogus. */ |
| 741 | int pthread_getschedparam(pthread_t target_thread, |
| 742 | int *policy, |
| 743 | struct sched_param *param) |
| 744 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 745 | static int moans = N_MOANS; |
| 746 | if (moans-- > 0) |
| 747 | kludged("pthread_getschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 748 | if (policy) *policy = SCHED_OTHER; |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 749 | # ifdef GLIBC_2_1 |
| 750 | if (param) param->sched_priority = 0; /* who knows */ |
| 751 | # else |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 752 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 753 | # endif |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | int pthread_setschedparam(pthread_t target_thread, |
| 758 | int policy, |
| 759 | const struct sched_param *param) |
| 760 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 761 | static int moans = N_MOANS; |
| 762 | if (moans-- > 0) |
| 763 | ignored("pthread_setschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 764 | return 0; |
| 765 | } |
| 766 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 767 | int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 768 | { |
| 769 | int res; |
| 770 | ensure_valgrind("pthread_cond_wait"); |
| 771 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 772 | VG_USERREQ__PTHREAD_COND_WAIT, |
| 773 | cond, mutex, 0, 0); |
| 774 | return res; |
| 775 | } |
| 776 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 777 | int pthread_cond_timedwait ( pthread_cond_t *cond, |
| 778 | pthread_mutex_t *mutex, |
| 779 | const struct timespec *abstime ) |
| 780 | { |
| 781 | int res; |
| 782 | unsigned int ms_now, ms_end; |
| 783 | struct timeval timeval_now; |
| 784 | unsigned long long int ull_ms_now_after_1970; |
| 785 | unsigned long long int ull_ms_end_after_1970; |
| 786 | |
| 787 | ensure_valgrind("pthread_cond_timedwait"); |
| 788 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 789 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 790 | 0, 0, 0, 0); |
| 791 | assert(ms_now != 0xFFFFFFFF); |
| 792 | res = gettimeofday(&timeval_now, NULL); |
| 793 | assert(res == 0); |
| 794 | |
| 795 | ull_ms_now_after_1970 |
| 796 | = 1000ULL * ((unsigned long long int)(timeval_now.tv_sec)) |
| 797 | + ((unsigned long long int)(timeval_now.tv_usec / 1000000)); |
| 798 | ull_ms_end_after_1970 |
| 799 | = 1000ULL * ((unsigned long long int)(abstime->tv_sec)) |
| 800 | + ((unsigned long long int)(abstime->tv_nsec / 1000000)); |
sewardj | d8e919e | 2002-05-29 20:13:53 +0000 | [diff] [blame] | 801 | if (ull_ms_end_after_1970 < ull_ms_now_after_1970) |
| 802 | ull_ms_end_after_1970 = ull_ms_now_after_1970; |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 803 | ms_end |
| 804 | = ms_now + (unsigned int)(ull_ms_end_after_1970 - ull_ms_now_after_1970); |
| 805 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 806 | VG_USERREQ__PTHREAD_COND_TIMEDWAIT, |
| 807 | cond, mutex, ms_end, 0); |
| 808 | return res; |
| 809 | } |
| 810 | |
| 811 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 812 | int pthread_cond_signal(pthread_cond_t *cond) |
| 813 | { |
| 814 | int res; |
| 815 | ensure_valgrind("pthread_cond_signal"); |
| 816 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 817 | VG_USERREQ__PTHREAD_COND_SIGNAL, |
| 818 | cond, 0, 0, 0); |
| 819 | return res; |
| 820 | } |
| 821 | |
| 822 | int pthread_cond_broadcast(pthread_cond_t *cond) |
| 823 | { |
| 824 | int res; |
| 825 | ensure_valgrind("pthread_cond_broadcast"); |
| 826 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 827 | VG_USERREQ__PTHREAD_COND_BROADCAST, |
| 828 | cond, 0, 0, 0); |
| 829 | return res; |
| 830 | } |
| 831 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 832 | |
| 833 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 834 | CANCELLATION |
| 835 | ------------------------------------------------ */ |
| 836 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 837 | int pthread_setcancelstate(int state, int *oldstate) |
| 838 | { |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 839 | int res; |
| 840 | ensure_valgrind("pthread_setcancelstate"); |
| 841 | if (state != PTHREAD_CANCEL_ENABLE |
| 842 | && state != PTHREAD_CANCEL_DISABLE) |
| 843 | return EINVAL; |
| 844 | assert(-1 != PTHREAD_CANCEL_ENABLE); |
| 845 | assert(-1 != PTHREAD_CANCEL_DISABLE); |
| 846 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 847 | VG_USERREQ__SET_CANCELSTATE, |
| 848 | state, 0, 0, 0); |
| 849 | assert(res != -1); |
| 850 | if (oldstate) |
| 851 | *oldstate = res; |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 852 | return 0; |
| 853 | } |
| 854 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 855 | int pthread_setcanceltype(int type, int *oldtype) |
| 856 | { |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 857 | int res; |
| 858 | ensure_valgrind("pthread_setcanceltype"); |
| 859 | if (type != PTHREAD_CANCEL_DEFERRED |
| 860 | && type != PTHREAD_CANCEL_ASYNCHRONOUS) |
| 861 | return EINVAL; |
| 862 | assert(-1 != PTHREAD_CANCEL_DEFERRED); |
| 863 | assert(-1 != PTHREAD_CANCEL_ASYNCHRONOUS); |
| 864 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 865 | VG_USERREQ__SET_CANCELTYPE, |
| 866 | type, 0, 0, 0); |
| 867 | assert(res != -1); |
| 868 | if (oldtype) |
| 869 | *oldtype = res; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 873 | int pthread_cancel(pthread_t thread) |
| 874 | { |
| 875 | int res; |
| 876 | ensure_valgrind("pthread_cancel"); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 877 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 878 | VG_USERREQ__SET_CANCELPEND, |
| 879 | thread, &thread_exit_wrapper, 0, 0); |
| 880 | assert(res != -1); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 881 | return res; |
| 882 | } |
| 883 | |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 884 | static __inline__ |
| 885 | void __my_pthread_testcancel(void) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 886 | { |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 887 | int res; |
| 888 | VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */, |
| 889 | VG_USERREQ__TESTCANCEL, |
| 890 | 0, 0, 0, 0); |
| 891 | assert(res == 0); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 892 | } |
| 893 | |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 894 | void pthread_testcancel ( void ) |
| 895 | { |
| 896 | __my_pthread_testcancel(); |
| 897 | } |
| 898 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 899 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 900 | /*-------------------*/ |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 901 | /* If this is indeed used by LinuxThreads to implement thread nuking |
| 902 | post fork and pre exec, we should really nuke em, not do |
| 903 | pthread_cancel. */ |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 904 | static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER; |
| 905 | |
| 906 | void __pthread_kill_other_threads_np ( void ) |
| 907 | { |
sewardj | 9a66454 | 2002-05-29 20:22:17 +0000 | [diff] [blame] | 908 | /* If we need this, implement it properly! */ |
| 909 | vgPlain_unimp("__pthread_kill_other_threads_np"); |
| 910 | #if 0 |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 911 | int i, res, me; |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 912 | __pthread_mutex_lock(&massacre_mx); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 913 | me = pthread_self(); |
| 914 | for (i = 1; i < VG_N_THREADS; i++) { |
| 915 | if (i == me) continue; |
| 916 | res = pthread_cancel(i); |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 917 | if (0 && res == 0) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 918 | printf("----------- NUKED %d\n", i); |
| 919 | } |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 920 | __pthread_mutex_unlock(&massacre_mx); |
sewardj | 9a66454 | 2002-05-29 20:22:17 +0000 | [diff] [blame] | 921 | #endif |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 922 | } |
| 923 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 924 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 925 | /* --------------------------------------------------- |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 926 | SIGNALS |
| 927 | ------------------------------------------------ */ |
| 928 | |
| 929 | #include <signal.h> |
| 930 | |
| 931 | int pthread_sigmask(int how, const sigset_t *newmask, |
| 932 | sigset_t *oldmask) |
| 933 | { |
| 934 | int res; |
| 935 | |
| 936 | /* A bit subtle, because the scheduler expects newmask and oldmask |
| 937 | to be vki_sigset_t* rather than sigset_t*, and the two are |
| 938 | different. Fortunately the first 64 bits of a sigset_t are |
| 939 | exactly a vki_sigset_t, so we just pass the pointers through |
| 940 | unmodified. Haaaack! |
| 941 | |
| 942 | Also mash the how value so that the SIG_ constants from glibc |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 943 | constants to VKI_ constants, so that the former do not have to |
| 944 | be included into vg_scheduler.c. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 945 | |
| 946 | ensure_valgrind("pthread_sigmask"); |
| 947 | |
| 948 | switch (how) { |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 949 | case SIG_SETMASK: how = VKI_SIG_SETMASK; break; |
| 950 | case SIG_BLOCK: how = VKI_SIG_BLOCK; break; |
| 951 | case SIG_UNBLOCK: how = VKI_SIG_UNBLOCK; break; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 952 | default: return EINVAL; |
| 953 | } |
| 954 | |
| 955 | /* Crude check */ |
| 956 | if (newmask == NULL) |
| 957 | return EFAULT; |
| 958 | |
| 959 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 960 | VG_USERREQ__PTHREAD_SIGMASK, |
| 961 | how, newmask, oldmask, 0); |
| 962 | |
| 963 | /* The scheduler tells us of any memory violations. */ |
| 964 | return res == 0 ? 0 : EFAULT; |
| 965 | } |
| 966 | |
| 967 | |
| 968 | int sigwait ( const sigset_t* set, int* sig ) |
| 969 | { |
| 970 | int res; |
| 971 | ensure_valgrind("sigwait"); |
| 972 | /* As with pthread_sigmask we deliberately confuse sigset_t with |
| 973 | vki_ksigset_t. */ |
| 974 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 975 | VG_USERREQ__SIGWAIT, |
| 976 | set, sig, 0, 0); |
| 977 | return res; |
| 978 | } |
| 979 | |
| 980 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 981 | int pthread_kill(pthread_t thread, int signo) |
| 982 | { |
| 983 | int res; |
| 984 | ensure_valgrind("pthread_kill"); |
| 985 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 986 | VG_USERREQ__PTHREAD_KILL, |
| 987 | thread, signo, 0, 0); |
| 988 | return res; |
| 989 | } |
| 990 | |
| 991 | |
sewardj | 3665ded | 2002-05-16 16:57:25 +0000 | [diff] [blame] | 992 | /* Copied verbatim from Linuxthreads */ |
| 993 | /* Redefine raise() to send signal to calling thread only, |
| 994 | as per POSIX 1003.1c */ |
| 995 | int raise (int sig) |
| 996 | { |
| 997 | int retcode = pthread_kill(pthread_self(), sig); |
| 998 | if (retcode == 0) |
| 999 | return 0; |
| 1000 | else { |
| 1001 | errno = retcode; |
| 1002 | return -1; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 1007 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1008 | THREAD-SPECIFICs |
| 1009 | ------------------------------------------------ */ |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1010 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1011 | int __pthread_key_create(pthread_key_t *key, |
| 1012 | void (*destr_function) (void *)) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1013 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1014 | int res; |
| 1015 | ensure_valgrind("pthread_key_create"); |
| 1016 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 1017 | VG_USERREQ__PTHREAD_KEY_CREATE, |
| 1018 | key, destr_function, 0, 0); |
| 1019 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | int pthread_key_delete(pthread_key_t key) |
| 1023 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1024 | static int moans = N_MOANS; |
| 1025 | if (moans-- > 0) |
| 1026 | ignored("pthread_key_delete"); |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1030 | int __pthread_setspecific(pthread_key_t key, const void *pointer) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1031 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1032 | int res; |
| 1033 | ensure_valgrind("pthread_setspecific"); |
| 1034 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 1035 | VG_USERREQ__PTHREAD_SETSPECIFIC, |
| 1036 | key, pointer, 0, 0); |
| 1037 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1040 | void * __pthread_getspecific(pthread_key_t key) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1041 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1042 | int res; |
| 1043 | ensure_valgrind("pthread_getspecific"); |
| 1044 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 1045 | VG_USERREQ__PTHREAD_GETSPECIFIC, |
| 1046 | key, 0 , 0, 0); |
| 1047 | return (void*)res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1050 | |
| 1051 | /* --------------------------------------------------- |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1052 | ONCEry |
| 1053 | ------------------------------------------------ */ |
| 1054 | |
| 1055 | static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER; |
| 1056 | |
| 1057 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1058 | int __pthread_once ( pthread_once_t *once_control, |
| 1059 | void (*init_routine) (void) ) |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1060 | { |
| 1061 | int res; |
| 1062 | ensure_valgrind("pthread_once"); |
| 1063 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 1064 | res = __pthread_mutex_lock(&once_masterlock); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1065 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 1066 | if (res != 0) { |
| 1067 | printf("res = %d\n",res); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1068 | barf("pthread_once: Looks like your program's " |
| 1069 | "init routine calls back to pthread_once() ?!"); |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 1070 | } |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1071 | |
| 1072 | if (*once_control == 0) { |
| 1073 | *once_control = 1; |
| 1074 | init_routine(); |
| 1075 | } |
| 1076 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 1077 | __pthread_mutex_unlock(&once_masterlock); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | /* --------------------------------------------------- |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1084 | MISC |
| 1085 | ------------------------------------------------ */ |
| 1086 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1087 | int __pthread_atfork ( void (*prepare)(void), |
| 1088 | void (*parent)(void), |
| 1089 | void (*child)(void) ) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1090 | { |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 1091 | /* We have to do this properly or not at all; faking it isn't an |
| 1092 | option. */ |
| 1093 | vgPlain_unimp("__pthread_atfork"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | |
sewardj | bb99078 | 2002-05-08 02:01:14 +0000 | [diff] [blame] | 1097 | __attribute__((weak)) |
| 1098 | void __pthread_initialize ( void ) |
| 1099 | { |
sewardj | bea1caa | 2002-05-10 23:20:58 +0000 | [diff] [blame] | 1100 | ensure_valgrind("__pthread_initialize"); |
sewardj | bb99078 | 2002-05-08 02:01:14 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1104 | /* --------------------------------------------------- |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1105 | LIBRARY-PRIVATE THREAD SPECIFIC STATE |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1106 | ------------------------------------------------ */ |
| 1107 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1108 | #include <resolv.h> |
| 1109 | static int thread_specific_errno[VG_N_THREADS]; |
| 1110 | static int thread_specific_h_errno[VG_N_THREADS]; |
| 1111 | static struct __res_state |
| 1112 | thread_specific_res_state[VG_N_THREADS]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1113 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1114 | int* __errno_location ( void ) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1115 | { |
| 1116 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1117 | /* ensure_valgrind("__errno_location"); */ |
| 1118 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1119 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 1120 | 0, 0, 0, 0); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1121 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1122 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1123 | barf("__errno_location: invalid ThreadId"); |
| 1124 | return & thread_specific_errno[tid]; |
| 1125 | } |
| 1126 | |
| 1127 | int* __h_errno_location ( void ) |
| 1128 | { |
| 1129 | int tid; |
| 1130 | /* ensure_valgrind("__h_errno_location"); */ |
| 1131 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 1132 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 1133 | 0, 0, 0, 0); |
| 1134 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1135 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1136 | barf("__h_errno_location: invalid ThreadId"); |
| 1137 | return & thread_specific_h_errno[tid]; |
| 1138 | } |
| 1139 | |
| 1140 | struct __res_state* __res_state ( void ) |
| 1141 | { |
| 1142 | int tid; |
| 1143 | /* ensure_valgrind("__res_state"); */ |
| 1144 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 1145 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 1146 | 0, 0, 0, 0); |
| 1147 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1148 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1149 | barf("__res_state: invalid ThreadId"); |
| 1150 | return & thread_specific_res_state[tid]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1154 | /* --------------------------------------------------- |
| 1155 | LIBC-PRIVATE SPECIFIC DATA |
| 1156 | ------------------------------------------------ */ |
| 1157 | |
| 1158 | /* Relies on assumption that initial private data is NULL. This |
| 1159 | should be fixed somehow. */ |
| 1160 | |
| 1161 | /* The allowable keys (indices) (all 2 of them). |
| 1162 | From sysdeps/pthread/bits/libc-tsd.h |
| 1163 | */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1164 | #define N_LIBC_TSD_EXTRA_KEYS 1 |
| 1165 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1166 | enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, |
| 1167 | _LIBC_TSD_KEY_DL_ERROR, |
| 1168 | _LIBC_TSD_KEY_N }; |
| 1169 | |
| 1170 | /* Auto-initialising subsystem. libc_specifics_inited is set |
| 1171 | after initialisation. libc_specifics_inited_mx guards it. */ |
| 1172 | static int libc_specifics_inited = 0; |
| 1173 | static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; |
| 1174 | |
| 1175 | /* These are the keys we must initialise the first time. */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1176 | static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N |
| 1177 | + N_LIBC_TSD_EXTRA_KEYS]; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1178 | |
| 1179 | /* Initialise the keys, if they are not already initialise. */ |
| 1180 | static |
| 1181 | void init_libc_tsd_keys ( void ) |
| 1182 | { |
| 1183 | int res, i; |
| 1184 | pthread_key_t k; |
| 1185 | |
| 1186 | res = pthread_mutex_lock(&libc_specifics_inited_mx); |
| 1187 | if (res != 0) barf("init_libc_tsd_keys: lock"); |
| 1188 | |
| 1189 | if (libc_specifics_inited == 0) { |
| 1190 | /* printf("INIT libc specifics\n"); */ |
| 1191 | libc_specifics_inited = 1; |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1192 | for (i = 0; i < _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS; i++) { |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1193 | res = pthread_key_create(&k, NULL); |
| 1194 | if (res != 0) barf("init_libc_tsd_keys: create"); |
| 1195 | libc_specifics_keys[i] = k; |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | res = pthread_mutex_unlock(&libc_specifics_inited_mx); |
| 1200 | if (res != 0) barf("init_libc_tsd_keys: unlock"); |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | static int |
| 1205 | libc_internal_tsd_set ( enum __libc_tsd_key_t key, |
| 1206 | const void * pointer ) |
| 1207 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1208 | int res; |
| 1209 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1210 | /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1211 | if (key < _LIBC_TSD_KEY_MALLOC |
| 1212 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1213 | barf("libc_internal_tsd_set: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1214 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 1215 | fprintf(stderr, |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1216 | "valgrind's libpthread.so: libc_internal_tsd_set: " |
| 1217 | "dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1218 | init_libc_tsd_keys(); |
| 1219 | res = pthread_setspecific(libc_specifics_keys[key], pointer); |
| 1220 | if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); |
| 1221 | return 0; |
| 1222 | } |
| 1223 | |
| 1224 | static void * |
| 1225 | libc_internal_tsd_get ( enum __libc_tsd_key_t key ) |
| 1226 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1227 | void* v; |
| 1228 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1229 | /* printf("GET GET GET key %d\n", key); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1230 | if (key < _LIBC_TSD_KEY_MALLOC |
| 1231 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1232 | barf("libc_internal_tsd_get: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1233 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 1234 | fprintf(stderr, |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1235 | "valgrind's libpthread.so: libc_internal_tsd_get: " |
| 1236 | "dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1237 | init_libc_tsd_keys(); |
| 1238 | v = pthread_getspecific(libc_specifics_keys[key]); |
| 1239 | /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ |
| 1240 | return v; |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1246 | int (*__libc_internal_tsd_set) |
| 1247 | (enum __libc_tsd_key_t key, const void * pointer) |
| 1248 | = libc_internal_tsd_set; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1249 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 1250 | void* (*__libc_internal_tsd_get) |
| 1251 | (enum __libc_tsd_key_t key) |
| 1252 | = libc_internal_tsd_get; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1253 | |
| 1254 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1255 | /* --------------------------------------------------------------------- |
| 1256 | These are here (I think) because they are deemed cancellation |
| 1257 | points by POSIX. For the moment we'll simply pass the call along |
| 1258 | to the corresponding thread-unaware (?) libc routine. |
| 1259 | ------------------------------------------------------------------ */ |
| 1260 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1261 | #include <stdlib.h> |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1262 | #include <sys/types.h> |
| 1263 | #include <sys/socket.h> |
| 1264 | |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 1265 | #ifdef GLIBC_2_1 |
| 1266 | extern |
| 1267 | int __sigaction |
| 1268 | (int signum, |
| 1269 | const struct sigaction *act, |
| 1270 | struct sigaction *oldact); |
| 1271 | #else |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1272 | extern |
| 1273 | int __libc_sigaction |
| 1274 | (int signum, |
| 1275 | const struct sigaction *act, |
| 1276 | struct sigaction *oldact); |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 1277 | #endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1278 | int sigaction(int signum, |
| 1279 | const struct sigaction *act, |
| 1280 | struct sigaction *oldact) |
| 1281 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1282 | __my_pthread_testcancel(); |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 1283 | # ifdef GLIBC_2_1 |
| 1284 | return __sigaction(signum, act, oldact); |
| 1285 | # else |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1286 | return __libc_sigaction(signum, act, oldact); |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 1287 | # endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | extern |
| 1292 | int __libc_connect(int sockfd, |
| 1293 | const struct sockaddr *serv_addr, |
| 1294 | socklen_t addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1295 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1296 | int connect(int sockfd, |
| 1297 | const struct sockaddr *serv_addr, |
| 1298 | socklen_t addrlen) |
| 1299 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1300 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1301 | return __libc_connect(sockfd, serv_addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | extern |
| 1306 | int __libc_fcntl(int fd, int cmd, long arg); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1307 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1308 | int fcntl(int fd, int cmd, long arg) |
| 1309 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1310 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1311 | return __libc_fcntl(fd, cmd, arg); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | extern |
| 1316 | ssize_t __libc_write(int fd, const void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1317 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1318 | ssize_t write(int fd, const void *buf, size_t count) |
| 1319 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1320 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1321 | return __libc_write(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | extern |
| 1326 | ssize_t __libc_read(int fd, void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1327 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1328 | ssize_t read(int fd, void *buf, size_t count) |
| 1329 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1330 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1331 | return __libc_read(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1334 | |
| 1335 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1336 | int __libc_open64(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1337 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1338 | int open64(const char *pathname, int flags, mode_t mode) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1339 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1340 | __my_pthread_testcancel(); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1341 | return __libc_open64(pathname, flags, mode); |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1344 | |
| 1345 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1346 | int __libc_open(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1347 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1348 | int open(const char *pathname, int flags, mode_t mode) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1349 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1350 | __my_pthread_testcancel(); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1351 | return __libc_open(pathname, flags, mode); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | extern |
| 1356 | int __libc_close(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1357 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1358 | int close(int fd) |
| 1359 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1360 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1361 | return __libc_close(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | |
| 1365 | extern |
| 1366 | int __libc_accept(int s, struct sockaddr *addr, socklen_t *addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1367 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1368 | int accept(int s, struct sockaddr *addr, socklen_t *addrlen) |
| 1369 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1370 | __my_pthread_testcancel(); |
sewardj | 705d3cb | 2002-05-23 13:13:12 +0000 | [diff] [blame] | 1371 | wait_for_fd_to_be_readable_or_erring(s); |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1372 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1373 | return __libc_accept(s, addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | extern |
| 1378 | pid_t __libc_fork(void); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1379 | pid_t __fork(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1380 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1381 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1382 | return __libc_fork(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | extern |
| 1387 | pid_t __libc_waitpid(pid_t pid, int *status, int options); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1388 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1389 | pid_t waitpid(pid_t pid, int *status, int options) |
| 1390 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1391 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1392 | return __libc_waitpid(pid, status, options); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | extern |
| 1397 | int __libc_nanosleep(const struct timespec *req, struct timespec *rem); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1398 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1399 | int nanosleep(const struct timespec *req, struct timespec *rem) |
| 1400 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1401 | __my_pthread_testcancel(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1402 | return __libc_nanosleep(req, rem); |
| 1403 | } |
| 1404 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1405 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1406 | extern |
| 1407 | int __libc_fsync(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1408 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1409 | int fsync(int fd) |
| 1410 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1411 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1412 | return __libc_fsync(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1415 | |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1416 | extern |
| 1417 | off_t __libc_lseek(int fildes, off_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1418 | __attribute__((weak)) |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1419 | off_t lseek(int fildes, off_t offset, int whence) |
| 1420 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1421 | __my_pthread_testcancel(); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1422 | return __libc_lseek(fildes, offset, whence); |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1425 | |
| 1426 | extern |
| 1427 | __off64_t __libc_lseek64(int fildes, __off64_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1428 | __attribute__((weak)) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1429 | __off64_t lseek64(int fildes, __off64_t offset, int whence) |
| 1430 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1431 | __my_pthread_testcancel(); |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1432 | return __libc_lseek64(fildes, offset, whence); |
| 1433 | } |
| 1434 | |
| 1435 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1436 | extern |
| 1437 | ssize_t __libc_pread64 (int __fd, void *__buf, size_t __nbytes, |
| 1438 | __off64_t __offset); |
| 1439 | ssize_t __pread64 (int __fd, void *__buf, size_t __nbytes, |
| 1440 | __off64_t __offset) |
| 1441 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1442 | __my_pthread_testcancel(); |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1443 | return __libc_pread64(__fd, __buf, __nbytes, __offset); |
| 1444 | } |
| 1445 | |
| 1446 | |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 1447 | extern |
| 1448 | ssize_t __libc_pwrite64 (int __fd, const void *__buf, size_t __nbytes, |
| 1449 | __off64_t __offset); |
| 1450 | ssize_t __pwrite64 (int __fd, const void *__buf, size_t __nbytes, |
| 1451 | __off64_t __offset) |
| 1452 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1453 | __my_pthread_testcancel(); |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 1454 | return __libc_pwrite64(__fd, __buf, __nbytes, __offset); |
| 1455 | } |
| 1456 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1457 | |
sewardj | 39b93b1 | 2002-05-18 10:56:27 +0000 | [diff] [blame] | 1458 | extern |
| 1459 | ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset); |
| 1460 | __attribute__((weak)) |
| 1461 | ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) |
| 1462 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1463 | __my_pthread_testcancel(); |
sewardj | 39b93b1 | 2002-05-18 10:56:27 +0000 | [diff] [blame] | 1464 | return __libc_pwrite(fd, buf, count, offset); |
| 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | extern |
| 1469 | ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset); |
| 1470 | __attribute__((weak)) |
| 1471 | ssize_t pread(int fd, void *buf, size_t count, off_t offset) |
| 1472 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1473 | __my_pthread_testcancel(); |
sewardj | 39b93b1 | 2002-05-18 10:56:27 +0000 | [diff] [blame] | 1474 | return __libc_pread(fd, buf, count, offset); |
| 1475 | } |
| 1476 | |
| 1477 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1478 | extern |
| 1479 | void __libc_longjmp(jmp_buf env, int val) __attribute((noreturn)); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1480 | /* not weak: __attribute__((weak)) */ |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1481 | void longjmp(jmp_buf env, int val) |
| 1482 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1483 | __my_pthread_testcancel(); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1484 | __libc_longjmp(env, val); |
| 1485 | } |
| 1486 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1487 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1488 | extern |
| 1489 | int __libc_send(int s, const void *msg, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1490 | __attribute__((weak)) |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1491 | int send(int s, const void *msg, size_t len, int flags) |
| 1492 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1493 | __my_pthread_testcancel(); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1494 | return __libc_send(s, msg, len, flags); |
| 1495 | } |
| 1496 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1497 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1498 | extern |
| 1499 | int __libc_recv(int s, void *buf, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1500 | __attribute__((weak)) |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1501 | int recv(int s, void *buf, size_t len, int flags) |
| 1502 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1503 | __my_pthread_testcancel(); |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1504 | return __libc_recv(s, buf, len, flags); |
| 1505 | } |
| 1506 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1507 | |
sewardj | 3665ded | 2002-05-16 16:57:25 +0000 | [diff] [blame] | 1508 | extern |
| 1509 | int __libc_sendmsg(int s, const struct msghdr *msg, int flags); |
| 1510 | __attribute__((weak)) |
| 1511 | int sendmsg(int s, const struct msghdr *msg, int flags) |
| 1512 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1513 | __my_pthread_testcancel(); |
sewardj | 3665ded | 2002-05-16 16:57:25 +0000 | [diff] [blame] | 1514 | return __libc_sendmsg(s, msg, flags); |
| 1515 | } |
| 1516 | |
| 1517 | |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1518 | extern |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1519 | int __libc_recvfrom(int s, void *buf, size_t len, int flags, |
| 1520 | struct sockaddr *from, socklen_t *fromlen); |
| 1521 | __attribute__((weak)) |
| 1522 | int recvfrom(int s, void *buf, size_t len, int flags, |
| 1523 | struct sockaddr *from, socklen_t *fromlen) |
| 1524 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1525 | __my_pthread_testcancel(); |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1526 | return __libc_recvfrom(s, buf, len, flags, from, fromlen); |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | extern |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1531 | int __libc_sendto(int s, const void *msg, size_t len, int flags, |
| 1532 | const struct sockaddr *to, socklen_t tolen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1533 | __attribute__((weak)) |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1534 | int sendto(int s, const void *msg, size_t len, int flags, |
| 1535 | const struct sockaddr *to, socklen_t tolen) |
| 1536 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1537 | __my_pthread_testcancel(); |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1538 | return __libc_sendto(s, msg, len, flags, to, tolen); |
| 1539 | } |
| 1540 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1541 | |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1542 | extern |
| 1543 | int __libc_system(const char* str); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1544 | __attribute__((weak)) |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1545 | int system(const char* str) |
| 1546 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1547 | __my_pthread_testcancel(); |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1548 | return __libc_system(str); |
| 1549 | } |
| 1550 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1551 | |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1552 | extern |
| 1553 | pid_t __libc_wait(int *status); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1554 | __attribute__((weak)) |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1555 | pid_t wait(int *status) |
| 1556 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1557 | __my_pthread_testcancel(); |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1558 | return __libc_wait(status); |
| 1559 | } |
| 1560 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1561 | |
sewardj | 67f1d58 | 2002-05-24 02:11:32 +0000 | [diff] [blame] | 1562 | extern |
| 1563 | int __libc_msync(const void *start, size_t length, int flags); |
| 1564 | __attribute__((weak)) |
| 1565 | int msync(const void *start, size_t length, int flags) |
| 1566 | { |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1567 | __my_pthread_testcancel(); |
sewardj | 67f1d58 | 2002-05-24 02:11:32 +0000 | [diff] [blame] | 1568 | return __libc_msync(start, length, flags); |
| 1569 | } |
| 1570 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1571 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1572 | /* --------------------------------------------------------------------- |
| 1573 | Nonblocking implementations of select() and poll(). This stuff will |
| 1574 | surely rot your mind. |
| 1575 | ------------------------------------------------------------------ */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1576 | |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1577 | /*--------------------------------------------------*/ |
| 1578 | |
| 1579 | #include "vg_kerneliface.h" |
| 1580 | |
| 1581 | static |
| 1582 | __inline__ |
| 1583 | int is_kerror ( int res ) |
| 1584 | { |
| 1585 | if (res >= -4095 && res <= -1) |
| 1586 | return 1; |
| 1587 | else |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
| 1591 | |
| 1592 | static |
| 1593 | int my_do_syscall1 ( int syscallno, int arg1 ) |
| 1594 | { |
| 1595 | int __res; |
| 1596 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1597 | : "=a" (__res) |
| 1598 | : "0" (syscallno), |
| 1599 | "d" (arg1) ); |
| 1600 | return __res; |
| 1601 | } |
| 1602 | |
| 1603 | static |
| 1604 | int my_do_syscall2 ( int syscallno, |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1605 | int arg1, int arg2 ) |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1606 | { |
| 1607 | int __res; |
| 1608 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1609 | : "=a" (__res) |
| 1610 | : "0" (syscallno), |
| 1611 | "d" (arg1), |
| 1612 | "c" (arg2) ); |
| 1613 | return __res; |
| 1614 | } |
| 1615 | |
| 1616 | static |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1617 | int my_do_syscall3 ( int syscallno, |
| 1618 | int arg1, int arg2, int arg3 ) |
| 1619 | { |
| 1620 | int __res; |
| 1621 | __asm__ volatile ("pushl %%ebx; movl %%esi,%%ebx ; int $0x80 ; popl %%ebx" |
| 1622 | : "=a" (__res) |
| 1623 | : "0" (syscallno), |
| 1624 | "S" (arg1), |
| 1625 | "c" (arg2), |
| 1626 | "d" (arg3) ); |
| 1627 | return __res; |
| 1628 | } |
| 1629 | |
| 1630 | static |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1631 | int do_syscall_select( int n, |
| 1632 | vki_fd_set* readfds, |
| 1633 | vki_fd_set* writefds, |
| 1634 | vki_fd_set* exceptfds, |
| 1635 | struct vki_timeval * timeout ) |
| 1636 | { |
| 1637 | int res; |
| 1638 | int args[5]; |
| 1639 | args[0] = n; |
| 1640 | args[1] = (int)readfds; |
| 1641 | args[2] = (int)writefds; |
| 1642 | args[3] = (int)exceptfds; |
| 1643 | args[4] = (int)timeout; |
| 1644 | res = my_do_syscall1(__NR_select, (int)(&(args[0])) ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1645 | return res; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | |
| 1649 | /* This is a wrapper round select(), which makes it thread-safe, |
| 1650 | meaning that only this thread will block, rather than the entire |
| 1651 | process. This wrapper in turn depends on nanosleep() not to block |
| 1652 | the entire process, but I think (hope? suspect?) that POSIX |
| 1653 | pthreads guarantees that to be the case. |
| 1654 | |
| 1655 | Basic idea is: modify the timeout parameter to select so that it |
| 1656 | returns immediately. Poll like this until select returns non-zero, |
| 1657 | indicating something interesting happened, or until our time is up. |
| 1658 | Space out the polls with nanosleeps of say 20 milliseconds, which |
| 1659 | is required to be nonblocking; this allows other threads to run. |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1660 | |
| 1661 | Assumes: |
| 1662 | * (checked via assert) types fd_set and vki_fd_set are identical. |
| 1663 | * (checked via assert) types timeval and vki_timeval are identical. |
| 1664 | * (unchecked) libc error numbers (EINTR etc) are the negation of the |
| 1665 | kernel's error numbers (VKI_EINTR etc). |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1666 | */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1667 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1668 | /* __attribute__((weak)) */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1669 | int select ( int n, |
| 1670 | fd_set *rfds, |
| 1671 | fd_set *wfds, |
| 1672 | fd_set *xfds, |
| 1673 | struct timeval *timeout ) |
| 1674 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1675 | unsigned int ms_now, ms_end; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1676 | int res; |
| 1677 | fd_set rfds_copy; |
| 1678 | fd_set wfds_copy; |
| 1679 | fd_set xfds_copy; |
| 1680 | struct vki_timeval t_now; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1681 | struct vki_timeval zero_timeout; |
| 1682 | struct vki_timespec nanosleep_interval; |
| 1683 | |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1684 | __my_pthread_testcancel(); |
| 1685 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1686 | /* gcc's complains about ms_end being used uninitialised -- classic |
| 1687 | case it can't understand, where ms_end is both defined and used |
| 1688 | only if timeout != NULL. Hence ... */ |
| 1689 | ms_end = 0; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1690 | |
| 1691 | /* We assume that the kernel and libc data layouts are identical |
| 1692 | for the following types. These asserts provide a crude |
| 1693 | check. */ |
| 1694 | if (sizeof(fd_set) != sizeof(vki_fd_set) |
| 1695 | || sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1696 | barf("valgrind's hacky non-blocking select(): data sizes error"); |
| 1697 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1698 | /* Detect the current time and simultaneously find out if we are |
| 1699 | running on Valgrind. */ |
| 1700 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1701 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1702 | 0, 0, 0, 0); |
| 1703 | |
| 1704 | /* If a zero timeout specified, this call is harmless. Also go |
| 1705 | this route if we're not running on Valgrind, for whatever |
| 1706 | reason. */ |
| 1707 | if ( (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) |
| 1708 | || (ms_now == 0xFFFFFFFF) ) { |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1709 | res = do_syscall_select( n, (vki_fd_set*)rfds, |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1710 | (vki_fd_set*)wfds, |
| 1711 | (vki_fd_set*)xfds, |
| 1712 | (struct vki_timeval*)timeout); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1713 | if (is_kerror(res)) { |
| 1714 | * (__errno_location()) = -res; |
| 1715 | return -1; |
| 1716 | } else { |
| 1717 | return res; |
| 1718 | } |
| 1719 | } |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1720 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1721 | /* If a timeout was specified, set ms_end to be the end millisecond |
| 1722 | counter [wallclock] time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1723 | if (timeout) { |
| 1724 | res = my_do_syscall2(__NR_gettimeofday, (int)&t_now, (int)NULL); |
| 1725 | assert(res == 0); |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1726 | ms_end = ms_now; |
| 1727 | ms_end += (timeout->tv_usec / 1000); |
| 1728 | ms_end += (timeout->tv_sec * 1000); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1729 | /* Stay sane ... */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1730 | assert (ms_end >= ms_now); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | /* fprintf(stderr, "MY_SELECT: before loop\n"); */ |
| 1734 | |
| 1735 | /* Either timeout == NULL, meaning wait indefinitely, or timeout != |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1736 | NULL, in which case ms_end holds the end time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1737 | while (1) { |
| 1738 | if (timeout) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1739 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1740 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1741 | 0, 0, 0, 0); |
| 1742 | assert(ms_now != 0xFFFFFFFF); |
| 1743 | if (ms_now >= ms_end) { |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1744 | /* timeout; nothing interesting happened. */ |
| 1745 | if (rfds) FD_ZERO(rfds); |
| 1746 | if (wfds) FD_ZERO(wfds); |
| 1747 | if (xfds) FD_ZERO(xfds); |
| 1748 | return 0; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | /* These could be trashed each time round the loop, so restore |
| 1753 | them each time. */ |
| 1754 | if (rfds) rfds_copy = *rfds; |
| 1755 | if (wfds) wfds_copy = *wfds; |
| 1756 | if (xfds) xfds_copy = *xfds; |
| 1757 | |
| 1758 | zero_timeout.tv_sec = zero_timeout.tv_usec = 0; |
| 1759 | |
| 1760 | res = do_syscall_select( n, |
| 1761 | rfds ? (vki_fd_set*)(&rfds_copy) : NULL, |
| 1762 | wfds ? (vki_fd_set*)(&wfds_copy) : NULL, |
| 1763 | xfds ? (vki_fd_set*)(&xfds_copy) : NULL, |
| 1764 | & zero_timeout ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1765 | if (is_kerror(res)) { |
| 1766 | /* Some kind of error (including EINTR). Set errno and |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1767 | return. The sets are unspecified in this case. */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1768 | * (__errno_location()) = -res; |
| 1769 | return -1; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1770 | } |
| 1771 | if (res > 0) { |
| 1772 | /* one or more fds is ready. Copy out resulting sets and |
| 1773 | return. */ |
| 1774 | if (rfds) *rfds = rfds_copy; |
| 1775 | if (wfds) *wfds = wfds_copy; |
| 1776 | if (xfds) *xfds = xfds_copy; |
| 1777 | return res; |
| 1778 | } |
| 1779 | /* fprintf(stderr, "MY_SELECT: nanosleep\n"); */ |
| 1780 | /* nanosleep and go round again */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1781 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1782 | nanosleep_interval.tv_nsec = 50 * 1000 * 1000; /* 50 milliseconds */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1783 | /* It's critical here that valgrind's nanosleep implementation |
| 1784 | is nonblocking. */ |
| 1785 | (void)my_do_syscall2(__NR_nanosleep, |
| 1786 | (int)(&nanosleep_interval), (int)NULL); |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | #include <sys/poll.h> |
| 1794 | |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 1795 | #ifdef GLIBC_2_1 |
| 1796 | typedef unsigned long int nfds_t; |
| 1797 | #endif |
| 1798 | |
sewardj | 705d3cb | 2002-05-23 13:13:12 +0000 | [diff] [blame] | 1799 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1800 | /* __attribute__((weak)) */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1801 | int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) |
| 1802 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1803 | unsigned int ms_now, ms_end; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1804 | int res, i; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1805 | struct vki_timespec nanosleep_interval; |
| 1806 | |
sewardj | d140e44 | 2002-05-29 01:21:19 +0000 | [diff] [blame] | 1807 | __my_pthread_testcancel(); |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1808 | ensure_valgrind("poll"); |
| 1809 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1810 | /* Detect the current time and simultaneously find out if we are |
| 1811 | running on Valgrind. */ |
| 1812 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1813 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1814 | 0, 0, 0, 0); |
| 1815 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1816 | if (/* CHECK SIZES FOR struct pollfd */ |
| 1817 | sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1818 | barf("valgrind's hacky non-blocking poll(): data sizes error"); |
| 1819 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1820 | /* dummy initialisation to keep gcc -Wall happy */ |
| 1821 | ms_end = 0; |
| 1822 | |
| 1823 | /* If a zero timeout specified, this call is harmless. Also do |
| 1824 | this if not running on Valgrind. */ |
| 1825 | if (__timeout == 0 || ms_now == 0xFFFFFFFF) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1826 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, __timeout); |
| 1827 | if (is_kerror(res)) { |
| 1828 | * (__errno_location()) = -res; |
| 1829 | return -1; |
| 1830 | } else { |
| 1831 | return res; |
| 1832 | } |
| 1833 | } |
| 1834 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1835 | /* If a timeout was specified, set ms_end to be the end wallclock |
| 1836 | time. Easy considering that __timeout is in milliseconds. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1837 | if (__timeout > 0) { |
sewardj | 650ac00 | 2002-04-29 12:20:34 +0000 | [diff] [blame] | 1838 | ms_end = ms_now + (unsigned int)__timeout; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /* fprintf(stderr, "MY_POLL: before loop\n"); */ |
| 1842 | |
| 1843 | /* Either timeout < 0, meaning wait indefinitely, or timeout > 0, |
| 1844 | in which case t_end holds the end time. */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1845 | assert(__timeout != 0); |
| 1846 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1847 | while (1) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1848 | if (__timeout > 0) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1849 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1850 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1851 | 0, 0, 0, 0); |
| 1852 | assert(ms_now != 0xFFFFFFFF); |
| 1853 | if (ms_now >= ms_end) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1854 | /* timeout; nothing interesting happened. */ |
| 1855 | for (i = 0; i < __nfds; i++) |
| 1856 | __fds[i].revents = 0; |
| 1857 | return 0; |
| 1858 | } |
| 1859 | } |
| 1860 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1861 | /* Do a return-immediately poll. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1862 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 ); |
| 1863 | if (is_kerror(res)) { |
| 1864 | /* Some kind of error. Set errno and return. */ |
| 1865 | * (__errno_location()) = -res; |
| 1866 | return -1; |
| 1867 | } |
| 1868 | if (res > 0) { |
| 1869 | /* One or more fds is ready. Return now. */ |
| 1870 | return res; |
| 1871 | } |
| 1872 | /* fprintf(stderr, "MY_POLL: nanosleep\n"); */ |
| 1873 | /* nanosleep and go round again */ |
| 1874 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1875 | nanosleep_interval.tv_nsec = 51 * 1000 * 1000; /* 51 milliseconds */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1876 | /* It's critical here that valgrind's nanosleep implementation |
| 1877 | is nonblocking. */ |
| 1878 | (void)my_do_syscall2(__NR_nanosleep, |
| 1879 | (int)(&nanosleep_interval), (int)NULL); |
| 1880 | } |
| 1881 | } |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1882 | |
| 1883 | |
sewardj | 705d3cb | 2002-05-23 13:13:12 +0000 | [diff] [blame] | 1884 | /* Helper function used to make accept() non-blocking. Idea is to use |
| 1885 | the above nonblocking poll() to make this thread ONLY wait for the |
| 1886 | specified fd to become ready, and then return. */ |
| 1887 | static void wait_for_fd_to_be_readable_or_erring ( int fd ) |
| 1888 | { |
| 1889 | struct pollfd pfd; |
sewardj | 6e6cbaa | 2002-05-24 02:12:52 +0000 | [diff] [blame] | 1890 | /* fprintf(stderr, "wait_for_fd_to_be_readable_or_erring %d\n", fd); */ |
sewardj | 705d3cb | 2002-05-23 13:13:12 +0000 | [diff] [blame] | 1891 | pfd.fd = fd; |
| 1892 | pfd.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; |
| 1893 | /* ... but not POLLOUT, you may notice. */ |
| 1894 | pfd.revents = 0; |
| 1895 | (void)poll(&pfd, 1, -1 /* forever */); |
| 1896 | } |
| 1897 | |
| 1898 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1899 | /* --------------------------------------------------------------------- |
sewardj | 8f253ff | 2002-05-19 00:13:34 +0000 | [diff] [blame] | 1900 | Hacky implementation of semaphores. |
| 1901 | ------------------------------------------------------------------ */ |
| 1902 | |
| 1903 | #include <semaphore.h> |
| 1904 | |
| 1905 | /* This is a terrible way to do the remapping. Plan is to import an |
| 1906 | AVL tree at some point. */ |
sewardj | 8f253ff | 2002-05-19 00:13:34 +0000 | [diff] [blame] | 1907 | |
| 1908 | typedef |
| 1909 | struct { |
| 1910 | pthread_mutex_t se_mx; |
| 1911 | pthread_cond_t se_cv; |
| 1912 | int count; |
| 1913 | } |
| 1914 | vg_sem_t; |
| 1915 | |
| 1916 | static pthread_mutex_t se_remap_mx = PTHREAD_MUTEX_INITIALIZER; |
| 1917 | |
| 1918 | static int se_remap_used = 0; |
| 1919 | static sem_t* se_remap_orig[VG_N_SEMAPHORES]; |
| 1920 | static vg_sem_t se_remap_new[VG_N_SEMAPHORES]; |
| 1921 | |
| 1922 | static vg_sem_t* se_remap ( sem_t* orig ) |
| 1923 | { |
| 1924 | int res, i; |
| 1925 | res = __pthread_mutex_lock(&se_remap_mx); |
| 1926 | assert(res == 0); |
| 1927 | |
| 1928 | for (i = 0; i < se_remap_used; i++) { |
| 1929 | if (se_remap_orig[i] == orig) |
| 1930 | break; |
| 1931 | } |
| 1932 | if (i == se_remap_used) { |
| 1933 | if (se_remap_used == VG_N_SEMAPHORES) { |
| 1934 | res = pthread_mutex_unlock(&se_remap_mx); |
| 1935 | assert(res == 0); |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 1936 | barf("VG_N_SEMAPHORES is too low. Increase and recompile."); |
sewardj | 8f253ff | 2002-05-19 00:13:34 +0000 | [diff] [blame] | 1937 | } |
| 1938 | se_remap_used++; |
| 1939 | se_remap_orig[i] = orig; |
| 1940 | /* printf("allocated semaphore %d\n", i); */ |
| 1941 | } |
| 1942 | res = __pthread_mutex_unlock(&se_remap_mx); |
| 1943 | assert(res == 0); |
| 1944 | return &se_remap_new[i]; |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | int sem_init(sem_t *sem, int pshared, unsigned int value) |
| 1949 | { |
| 1950 | int res; |
| 1951 | vg_sem_t* vg_sem; |
| 1952 | ensure_valgrind("sem_init"); |
| 1953 | if (pshared != 0) { |
| 1954 | errno = ENOSYS; |
| 1955 | return -1; |
| 1956 | } |
| 1957 | vg_sem = se_remap(sem); |
| 1958 | res = pthread_mutex_init(&vg_sem->se_mx, NULL); |
| 1959 | assert(res == 0); |
| 1960 | res = pthread_cond_init(&vg_sem->se_cv, NULL); |
| 1961 | assert(res == 0); |
| 1962 | vg_sem->count = value; |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | int sem_wait ( sem_t* sem ) |
| 1968 | { |
| 1969 | int res; |
| 1970 | vg_sem_t* vg_sem; |
| 1971 | ensure_valgrind("sem_wait"); |
| 1972 | vg_sem = se_remap(sem); |
| 1973 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 1974 | assert(res == 0); |
| 1975 | while (vg_sem->count == 0) { |
| 1976 | res = pthread_cond_wait(&vg_sem->se_cv, &vg_sem->se_mx); |
| 1977 | assert(res == 0); |
| 1978 | } |
| 1979 | vg_sem->count--; |
| 1980 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 1981 | assert(res == 0); |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
| 1985 | int sem_post ( sem_t* sem ) |
| 1986 | { |
| 1987 | int res; |
| 1988 | vg_sem_t* vg_sem; |
| 1989 | ensure_valgrind("sem_post"); |
| 1990 | vg_sem = se_remap(sem); |
| 1991 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 1992 | assert(res == 0); |
| 1993 | if (vg_sem->count == 0) { |
| 1994 | vg_sem->count++; |
| 1995 | res = pthread_cond_broadcast(&vg_sem->se_cv); |
| 1996 | assert(res == 0); |
| 1997 | } else { |
| 1998 | vg_sem->count++; |
| 1999 | } |
| 2000 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 2001 | assert(res == 0); |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | int sem_trywait ( sem_t* sem ) |
| 2007 | { |
| 2008 | int ret, res; |
| 2009 | vg_sem_t* vg_sem; |
| 2010 | ensure_valgrind("sem_trywait"); |
| 2011 | vg_sem = se_remap(sem); |
| 2012 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 2013 | assert(res == 0); |
| 2014 | if (vg_sem->count > 0) { |
| 2015 | vg_sem->count--; |
| 2016 | ret = 0; |
| 2017 | } else { |
| 2018 | ret = -1; |
| 2019 | errno = EAGAIN; |
| 2020 | } |
| 2021 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 2022 | assert(res == 0); |
| 2023 | return ret; |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | int sem_getvalue(sem_t* sem, int * sval) |
| 2028 | { |
| 2029 | vg_sem_t* vg_sem; |
| 2030 | ensure_valgrind("sem_trywait"); |
| 2031 | vg_sem = se_remap(sem); |
| 2032 | *sval = vg_sem->count; |
| 2033 | return 0; |
| 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | int sem_destroy(sem_t * sem) |
| 2038 | { |
| 2039 | kludged("sem_destroy"); |
| 2040 | /* if someone waiting on this semaphore, errno = EBUSY, return -1 */ |
| 2041 | return 0; |
| 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | /* --------------------------------------------------------------------- |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 2046 | Hacky implementation of reader-writer locks. |
| 2047 | ------------------------------------------------------------------ */ |
| 2048 | |
| 2049 | /* |
| 2050 | Errata from 7th printing: |
| 2051 | |
| 2052 | Page 259, rwlock.c, line 27, the two "!=" should be ">", for |
| 2053 | consistency with other similar tests. (The values should never be |
| 2054 | negative; this isn't a fix, but an improvement to clarity and |
| 2055 | consistency.) |
| 2056 | |
| 2057 | [27] if (rwl->r_wait > 0 || rwl->w_wait > 0) { |
| 2058 | |
| 2059 | Page 259, rwlock.c, lines 39 and 40, in both lines, "==" should |
| 2060 | become "!=": |
| 2061 | |
| 2062 | [39] return (status != 0 ? status |
| 2063 | [40] : (status1 != 0 ? status1 : status2)); |
| 2064 | */ |
| 2065 | |
| 2066 | /* |
| 2067 | * rwlock.h |
| 2068 | * |
| 2069 | * This header file describes the "reader/writer lock" synchronization |
| 2070 | * construct. The type rwlock_t describes the full state of the lock |
| 2071 | * including the POSIX 1003.1c synchronization objects necessary. |
| 2072 | * |
| 2073 | * A reader/writer lock allows a thread to lock shared data either for shared |
| 2074 | * read access or exclusive write access. |
| 2075 | * |
| 2076 | * The rwl_init() and rwl_destroy() functions, respectively, allow you to |
| 2077 | * initialize/create and destroy/free the reader/writer lock. |
| 2078 | */ |
| 2079 | |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 2080 | /* |
| 2081 | * Structure describing a read-write lock. |
| 2082 | */ |
| 2083 | typedef struct { |
| 2084 | pthread_mutex_t mutex; |
| 2085 | pthread_cond_t read; /* wait for read */ |
| 2086 | pthread_cond_t write; /* wait for write */ |
| 2087 | int valid; /* set when valid */ |
| 2088 | int r_active; /* readers active */ |
| 2089 | int w_active; /* writer active */ |
| 2090 | int r_wait; /* readers waiting */ |
| 2091 | int w_wait; /* writers waiting */ |
| 2092 | int pref_writer; /* != 0 --> prefer writer */ |
| 2093 | } vg_rwlock_t; |
| 2094 | |
| 2095 | #define VG_RWLOCK_VALID 0xfacade |
| 2096 | |
| 2097 | |
| 2098 | /* |
| 2099 | * Support static initialization of barriers |
| 2100 | */ |
| 2101 | #define VG_RWL_INITIALIZER \ |
| 2102 | {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \ |
| 2103 | PTHREAD_COND_INITIALIZER, VG_RWLOCK_VALID, 0, 0, 0, 0, 1} |
| 2104 | |
| 2105 | |
| 2106 | static pthread_mutex_t rw_remap_mx = PTHREAD_MUTEX_INITIALIZER; |
| 2107 | |
| 2108 | static int rw_remap_used = 0; |
| 2109 | static pthread_rwlock_t* rw_remap_orig[VG_N_RWLOCKS]; |
| 2110 | static vg_rwlock_t rw_remap_new[VG_N_RWLOCKS]; |
| 2111 | |
| 2112 | /* Take the address of a LinuxThreads rwlock_t and return the shadow |
| 2113 | address of our version. Further, if the LinuxThreads version |
| 2114 | appears to have been statically initialised, do the same to the one |
| 2115 | we allocate here. The pthread_rwlock_t.__rw_readers field is set |
| 2116 | to zero by PTHREAD_RWLOCK_INITIALIZER, so we take zero as meaning |
| 2117 | uninitialised and non-zero meaning initialised. |
| 2118 | */ |
| 2119 | static vg_rwlock_t* rw_remap ( pthread_rwlock_t* orig ) |
| 2120 | { |
| 2121 | int res, i; |
| 2122 | vg_rwlock_t* vg_rwl; |
| 2123 | res = __pthread_mutex_lock(&rw_remap_mx); |
| 2124 | assert(res == 0); |
| 2125 | |
| 2126 | for (i = 0; i < rw_remap_used; i++) { |
| 2127 | if (rw_remap_orig[i] == orig) |
| 2128 | break; |
| 2129 | } |
| 2130 | if (i == rw_remap_used) { |
| 2131 | if (rw_remap_used == VG_N_RWLOCKS) { |
| 2132 | res = pthread_mutex_unlock(&rw_remap_mx); |
| 2133 | assert(res == 0); |
| 2134 | barf("VG_N_RWLOCKS is too low. Increase and recompile."); |
| 2135 | } |
| 2136 | rw_remap_used++; |
| 2137 | rw_remap_orig[i] = orig; |
| 2138 | if (0) printf("allocated rwlock %d\n", i); |
| 2139 | } |
| 2140 | res = __pthread_mutex_unlock(&rw_remap_mx); |
| 2141 | assert(res == 0); |
| 2142 | vg_rwl = &rw_remap_new[i]; |
| 2143 | |
| 2144 | /* Mimic static initialisation of the original. */ |
| 2145 | if (orig->__rw_readers == 0) { |
| 2146 | const vg_rwlock_t default_rwl = VG_RWL_INITIALIZER; |
| 2147 | orig->__rw_readers = 1; |
| 2148 | *vg_rwl = default_rwl; |
| 2149 | vg_rwl->pref_writer = 1; |
| 2150 | if (orig->__rw_kind == PTHREAD_RWLOCK_PREFER_READER_NP) |
| 2151 | vg_rwl->pref_writer = 0; |
| 2152 | } |
| 2153 | |
| 2154 | return vg_rwl; |
| 2155 | } |
| 2156 | |
| 2157 | |
| 2158 | /* |
| 2159 | * rwlock.c |
| 2160 | * |
| 2161 | * This file implements the "read-write lock" synchronization |
| 2162 | * construct. |
| 2163 | * |
| 2164 | * A read-write lock allows a thread to lock shared data either |
| 2165 | * for shared read access or exclusive write access. |
| 2166 | * |
| 2167 | * The rwl_init() and rwl_destroy() functions, respectively, |
| 2168 | * allow you to initialize/create and destroy/free the |
| 2169 | * read-write lock. |
| 2170 | * |
| 2171 | * The rwl_readlock() function locks a read-write lock for |
| 2172 | * shared read access, and rwl_readunlock() releases the |
| 2173 | * lock. rwl_readtrylock() attempts to lock a read-write lock |
| 2174 | * for read access, and returns EBUSY instead of blocking. |
| 2175 | * |
| 2176 | * The rwl_writelock() function locks a read-write lock for |
| 2177 | * exclusive write access, and rwl_writeunlock() releases the |
| 2178 | * lock. rwl_writetrylock() attempts to lock a read-write lock |
| 2179 | * for write access, and returns EBUSY instead of blocking. |
| 2180 | */ |
| 2181 | |
| 2182 | |
| 2183 | /* |
| 2184 | * Initialize a read-write lock |
| 2185 | */ |
| 2186 | static int rwl_init ( vg_rwlock_t *rwl ) |
| 2187 | { |
| 2188 | int status; |
| 2189 | |
| 2190 | rwl->r_active = 0; |
| 2191 | rwl->r_wait = rwl->w_wait = 0; |
| 2192 | rwl->w_active = 0; |
| 2193 | status = pthread_mutex_init (&rwl->mutex, NULL); |
| 2194 | if (status != 0) |
| 2195 | return status; |
| 2196 | status = pthread_cond_init (&rwl->read, NULL); |
| 2197 | if (status != 0) { |
| 2198 | /* if unable to create read CV, destroy mutex */ |
| 2199 | pthread_mutex_destroy (&rwl->mutex); |
| 2200 | return status; |
| 2201 | } |
| 2202 | status = pthread_cond_init (&rwl->write, NULL); |
| 2203 | if (status != 0) { |
| 2204 | /* if unable to create write CV, destroy read CV and mutex */ |
| 2205 | pthread_cond_destroy (&rwl->read); |
| 2206 | pthread_mutex_destroy (&rwl->mutex); |
| 2207 | return status; |
| 2208 | } |
| 2209 | rwl->valid = VG_RWLOCK_VALID; |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | /* |
| 2214 | * Destroy a read-write lock |
| 2215 | */ |
| 2216 | static int rwl_destroy (vg_rwlock_t *rwl) |
| 2217 | { |
| 2218 | int status, status1, status2; |
| 2219 | |
| 2220 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2221 | return EINVAL; |
| 2222 | status = pthread_mutex_lock (&rwl->mutex); |
| 2223 | if (status != 0) |
| 2224 | return status; |
| 2225 | |
| 2226 | /* |
| 2227 | * Check whether any threads own the lock; report "BUSY" if |
| 2228 | * so. |
| 2229 | */ |
| 2230 | if (rwl->r_active > 0 || rwl->w_active) { |
| 2231 | pthread_mutex_unlock (&rwl->mutex); |
| 2232 | return EBUSY; |
| 2233 | } |
| 2234 | |
| 2235 | /* |
| 2236 | * Check whether any threads are known to be waiting; report |
| 2237 | * EBUSY if so. |
| 2238 | */ |
| 2239 | if (rwl->r_wait > 0 || rwl->w_wait > 0) { |
| 2240 | pthread_mutex_unlock (&rwl->mutex); |
| 2241 | return EBUSY; |
| 2242 | } |
| 2243 | |
| 2244 | rwl->valid = 0; |
| 2245 | status = pthread_mutex_unlock (&rwl->mutex); |
| 2246 | if (status != 0) |
| 2247 | return status; |
| 2248 | status = pthread_mutex_destroy (&rwl->mutex); |
| 2249 | status1 = pthread_cond_destroy (&rwl->read); |
| 2250 | status2 = pthread_cond_destroy (&rwl->write); |
| 2251 | return (status != 0 ? status : (status1 != 0 ? status1 : status2)); |
| 2252 | } |
| 2253 | |
| 2254 | /* |
| 2255 | * Handle cleanup when the read lock condition variable |
| 2256 | * wait is cancelled. |
| 2257 | * |
| 2258 | * Simply record that the thread is no longer waiting, |
| 2259 | * and unlock the mutex. |
| 2260 | */ |
| 2261 | static void rwl_readcleanup (void *arg) |
| 2262 | { |
| 2263 | vg_rwlock_t *rwl = (vg_rwlock_t *)arg; |
| 2264 | |
| 2265 | rwl->r_wait--; |
| 2266 | pthread_mutex_unlock (&rwl->mutex); |
| 2267 | } |
| 2268 | |
| 2269 | /* |
| 2270 | * Lock a read-write lock for read access. |
| 2271 | */ |
| 2272 | static int rwl_readlock (vg_rwlock_t *rwl) |
| 2273 | { |
| 2274 | int status; |
| 2275 | |
| 2276 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2277 | return EINVAL; |
| 2278 | status = pthread_mutex_lock (&rwl->mutex); |
| 2279 | if (status != 0) |
| 2280 | return status; |
| 2281 | if (rwl->w_active) { |
| 2282 | rwl->r_wait++; |
| 2283 | pthread_cleanup_push (rwl_readcleanup, (void*)rwl); |
| 2284 | while (rwl->w_active) { |
| 2285 | status = pthread_cond_wait (&rwl->read, &rwl->mutex); |
| 2286 | if (status != 0) |
| 2287 | break; |
| 2288 | } |
| 2289 | pthread_cleanup_pop (0); |
| 2290 | rwl->r_wait--; |
| 2291 | } |
| 2292 | if (status == 0) |
| 2293 | rwl->r_active++; |
| 2294 | pthread_mutex_unlock (&rwl->mutex); |
| 2295 | return status; |
| 2296 | } |
| 2297 | |
| 2298 | /* |
| 2299 | * Attempt to lock a read-write lock for read access (don't |
| 2300 | * block if unavailable). |
| 2301 | */ |
| 2302 | static int rwl_readtrylock (vg_rwlock_t *rwl) |
| 2303 | { |
| 2304 | int status, status2; |
| 2305 | |
| 2306 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2307 | return EINVAL; |
| 2308 | status = pthread_mutex_lock (&rwl->mutex); |
| 2309 | if (status != 0) |
| 2310 | return status; |
| 2311 | if (rwl->w_active) |
| 2312 | status = EBUSY; |
| 2313 | else |
| 2314 | rwl->r_active++; |
| 2315 | status2 = pthread_mutex_unlock (&rwl->mutex); |
| 2316 | return (status2 != 0 ? status2 : status); |
| 2317 | } |
| 2318 | |
| 2319 | /* |
| 2320 | * Handle cleanup when the write lock condition variable |
| 2321 | * wait is cancelled. |
| 2322 | * |
| 2323 | * Simply record that the thread is no longer waiting, |
| 2324 | * and unlock the mutex. |
| 2325 | */ |
| 2326 | static void rwl_writecleanup (void *arg) |
| 2327 | { |
| 2328 | vg_rwlock_t *rwl = (vg_rwlock_t *)arg; |
| 2329 | |
| 2330 | rwl->w_wait--; |
| 2331 | pthread_mutex_unlock (&rwl->mutex); |
| 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * Lock a read-write lock for write access. |
| 2336 | */ |
| 2337 | static int rwl_writelock (vg_rwlock_t *rwl) |
| 2338 | { |
| 2339 | int status; |
| 2340 | |
| 2341 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2342 | return EINVAL; |
| 2343 | status = pthread_mutex_lock (&rwl->mutex); |
| 2344 | if (status != 0) |
| 2345 | return status; |
| 2346 | if (rwl->w_active || rwl->r_active > 0) { |
| 2347 | rwl->w_wait++; |
| 2348 | pthread_cleanup_push (rwl_writecleanup, (void*)rwl); |
| 2349 | while (rwl->w_active || rwl->r_active > 0) { |
| 2350 | status = pthread_cond_wait (&rwl->write, &rwl->mutex); |
| 2351 | if (status != 0) |
| 2352 | break; |
| 2353 | } |
| 2354 | pthread_cleanup_pop (0); |
| 2355 | rwl->w_wait--; |
| 2356 | } |
| 2357 | if (status == 0) |
| 2358 | rwl->w_active = 1; |
| 2359 | pthread_mutex_unlock (&rwl->mutex); |
| 2360 | return status; |
| 2361 | } |
| 2362 | |
| 2363 | /* |
| 2364 | * Attempt to lock a read-write lock for write access. Don't |
| 2365 | * block if unavailable. |
| 2366 | */ |
| 2367 | static int rwl_writetrylock (vg_rwlock_t *rwl) |
| 2368 | { |
| 2369 | int status, status2; |
| 2370 | |
| 2371 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2372 | return EINVAL; |
| 2373 | status = pthread_mutex_lock (&rwl->mutex); |
| 2374 | if (status != 0) |
| 2375 | return status; |
| 2376 | if (rwl->w_active || rwl->r_active > 0) |
| 2377 | status = EBUSY; |
| 2378 | else |
| 2379 | rwl->w_active = 1; |
| 2380 | status2 = pthread_mutex_unlock (&rwl->mutex); |
| 2381 | return (status != 0 ? status : status2); |
| 2382 | } |
| 2383 | |
| 2384 | /* |
| 2385 | * Unlock a read-write lock, using the r_active and w_active fields to |
| 2386 | * decide whether we're in a read or write lock. |
| 2387 | */ |
| 2388 | static int rwl_unlock (vg_rwlock_t *rwl) |
| 2389 | { |
| 2390 | int status, status2; |
| 2391 | |
| 2392 | if (rwl->valid != VG_RWLOCK_VALID) |
| 2393 | return EINVAL; |
| 2394 | status = pthread_mutex_lock (&rwl->mutex); |
| 2395 | if (status != 0) |
| 2396 | return status; |
| 2397 | |
| 2398 | if (rwl->r_active > 0) { |
| 2399 | |
| 2400 | /* READ case */ |
| 2401 | assert(!rwl->w_active); |
| 2402 | rwl->r_active--; |
| 2403 | if (rwl->r_active == 0 && rwl->w_wait > 0) |
| 2404 | status = pthread_cond_signal (&rwl->write); |
| 2405 | /* END READ case */ |
| 2406 | |
| 2407 | } else { |
| 2408 | |
| 2409 | /* WRITE case */ |
| 2410 | assert(rwl->w_active); |
| 2411 | assert(rwl->r_active == 0); |
| 2412 | rwl->w_active = 0; |
| 2413 | |
| 2414 | if (rwl->pref_writer) { |
| 2415 | /* Do writer-preference wakeups. */ |
| 2416 | if (rwl->w_wait > 0) { |
| 2417 | status = pthread_cond_signal (&rwl->write); |
| 2418 | if (status != 0) { |
| 2419 | pthread_mutex_unlock (&rwl->mutex); |
| 2420 | return status; |
| 2421 | } |
| 2422 | } else if (rwl->r_wait > 0) { |
| 2423 | status = pthread_cond_broadcast (&rwl->read); |
| 2424 | if (status != 0) { |
| 2425 | pthread_mutex_unlock (&rwl->mutex); |
| 2426 | return status; |
| 2427 | } |
| 2428 | } |
| 2429 | } else { |
| 2430 | /* Do reader-preference wakeups. */ |
| 2431 | if (rwl->r_wait > 0) { |
| 2432 | status = pthread_cond_broadcast (&rwl->read); |
| 2433 | if (status != 0) { |
| 2434 | pthread_mutex_unlock (&rwl->mutex); |
| 2435 | return status; |
| 2436 | } |
| 2437 | } else if (rwl->w_wait > 0) { |
| 2438 | status = pthread_cond_signal (&rwl->write); |
| 2439 | if (status != 0) { |
| 2440 | pthread_mutex_unlock (&rwl->mutex); |
| 2441 | return status; |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | /* END WRITE case */ |
| 2446 | |
| 2447 | } |
| 2448 | |
| 2449 | status2 = pthread_mutex_unlock (&rwl->mutex); |
| 2450 | return (status2 == 0 ? status : status2); |
| 2451 | } |
| 2452 | |
| 2453 | /* -------------------------------- */ |
| 2454 | |
| 2455 | int pthread_rwlock_init ( pthread_rwlock_t* orig, |
| 2456 | const pthread_rwlockattr_t* attr ) |
| 2457 | { |
| 2458 | int res; |
| 2459 | vg_rwlock_t* rwl; |
| 2460 | if (0) printf ("pthread_rwlock_init\n"); |
| 2461 | /* Force the remapper to initialise the shadow. */ |
| 2462 | orig->__rw_readers = 0; |
| 2463 | /* Install the lock preference; the remapper needs to know it. */ |
| 2464 | orig->__rw_kind = PTHREAD_RWLOCK_DEFAULT_NP; |
| 2465 | if (attr) |
| 2466 | orig->__rw_kind = attr->__lockkind; |
| 2467 | rwl = rw_remap ( orig ); |
| 2468 | res = rwl_init ( rwl ); |
| 2469 | return res; |
| 2470 | } |
| 2471 | |
| 2472 | int pthread_rwlock_destroy ( pthread_rwlock_t *orig ) |
| 2473 | { |
| 2474 | int res; |
| 2475 | vg_rwlock_t* rwl; |
| 2476 | if (0) printf ("pthread_rwlock_destroy\n"); |
| 2477 | rwl = rw_remap ( orig ); |
| 2478 | res = rwl_destroy ( rwl ); |
| 2479 | return res; |
| 2480 | } |
| 2481 | |
| 2482 | int pthread_rwlock_rdlock ( pthread_rwlock_t* orig ) |
| 2483 | { |
| 2484 | int res; |
| 2485 | vg_rwlock_t* rwl; |
| 2486 | if (0) printf ("pthread_rwlock_rdlock\n"); |
| 2487 | rwl = rw_remap ( orig ); |
| 2488 | res = rwl_readlock ( rwl ); |
| 2489 | return res; |
| 2490 | } |
| 2491 | |
| 2492 | int pthread_rwlock_tryrdlock ( pthread_rwlock_t* orig ) |
| 2493 | { |
| 2494 | int res; |
| 2495 | vg_rwlock_t* rwl; |
| 2496 | if (0) printf ("pthread_rwlock_tryrdlock\n"); |
| 2497 | rwl = rw_remap ( orig ); |
| 2498 | res = rwl_readtrylock ( rwl ); |
| 2499 | return res; |
| 2500 | } |
| 2501 | |
| 2502 | int pthread_rwlock_wrlock ( pthread_rwlock_t* orig ) |
| 2503 | { |
| 2504 | int res; |
| 2505 | vg_rwlock_t* rwl; |
| 2506 | if (0) printf ("pthread_rwlock_wrlock\n"); |
| 2507 | rwl = rw_remap ( orig ); |
| 2508 | res = rwl_writelock ( rwl ); |
| 2509 | return res; |
| 2510 | } |
| 2511 | |
| 2512 | int pthread_rwlock_trywrlock ( pthread_rwlock_t* orig ) |
| 2513 | { |
| 2514 | int res; |
| 2515 | vg_rwlock_t* rwl; |
| 2516 | if (0) printf ("pthread_rwlock_trywrlock\n"); |
| 2517 | rwl = rw_remap ( orig ); |
| 2518 | res = rwl_writetrylock ( rwl ); |
| 2519 | return res; |
| 2520 | } |
| 2521 | |
| 2522 | int pthread_rwlock_unlock ( pthread_rwlock_t* orig ) |
| 2523 | { |
| 2524 | int res; |
| 2525 | vg_rwlock_t* rwl; |
| 2526 | if (0) printf ("pthread_rwlock_unlock\n"); |
| 2527 | rwl = rw_remap ( orig ); |
| 2528 | res = rwl_unlock ( rwl ); |
| 2529 | return res; |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | /* --------------------------------------------------------------------- |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2534 | B'stard. |
| 2535 | ------------------------------------------------------------------ */ |
| 2536 | |
| 2537 | # define strong_alias(name, aliasname) \ |
| 2538 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); |
| 2539 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2540 | # define weak_alias(name, aliasname) \ |
| 2541 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2542 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2543 | strong_alias(__pthread_mutex_lock, pthread_mutex_lock) |
| 2544 | strong_alias(__pthread_mutex_trylock, pthread_mutex_trylock) |
| 2545 | strong_alias(__pthread_mutex_unlock, pthread_mutex_unlock) |
| 2546 | strong_alias(__pthread_mutexattr_init, pthread_mutexattr_init) |
| 2547 | weak_alias(__pthread_mutexattr_settype, pthread_mutexattr_settype) |
| 2548 | strong_alias(__pthread_mutex_init, pthread_mutex_init) |
| 2549 | strong_alias(__pthread_mutexattr_destroy, pthread_mutexattr_destroy) |
| 2550 | strong_alias(__pthread_mutex_destroy, pthread_mutex_destroy) |
| 2551 | strong_alias(__pthread_once, pthread_once) |
| 2552 | strong_alias(__pthread_atfork, pthread_atfork) |
| 2553 | strong_alias(__pthread_key_create, pthread_key_create) |
| 2554 | strong_alias(__pthread_getspecific, pthread_getspecific) |
| 2555 | strong_alias(__pthread_setspecific, pthread_setspecific) |
| 2556 | |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 2557 | #ifndef GLIBC_2_1 |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2558 | strong_alias(sigaction, __sigaction) |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 2559 | #endif |
| 2560 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2561 | strong_alias(close, __close) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2562 | strong_alias(fcntl, __fcntl) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2563 | strong_alias(lseek, __lseek) |
| 2564 | strong_alias(open, __open) |
| 2565 | strong_alias(open64, __open64) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2566 | strong_alias(read, __read) |
| 2567 | strong_alias(wait, __wait) |
| 2568 | strong_alias(write, __write) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2569 | strong_alias(connect, __connect) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2570 | strong_alias(send, __send) |
| 2571 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 2572 | weak_alias (__pread64, pread64) |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 2573 | weak_alias (__pwrite64, pwrite64) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2574 | weak_alias(__fork, fork) |
sewardj | 7f6456d | 2002-05-21 00:51:21 +0000 | [diff] [blame] | 2575 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2576 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2577 | |
| 2578 | /*--------------------------------------------------*/ |
| 2579 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2580 | weak_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2581 | weak_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) |
sewardj | 262b029 | 2002-05-01 00:03:16 +0000 | [diff] [blame] | 2582 | weak_alias(pthread_rwlock_wrlock, __pthread_rwlock_wrlock) |
sewardj | 060b04f | 2002-04-26 21:01:13 +0000 | [diff] [blame] | 2583 | |
sewardj | a1ac5cb | 2002-05-27 13:00:05 +0000 | [diff] [blame] | 2584 | weak_alias(pthread_rwlock_destroy, __pthread_rwlock_destroy) |
| 2585 | weak_alias(pthread_rwlock_init, __pthread_rwlock_init) |
| 2586 | weak_alias(pthread_rwlock_tryrdlock, __pthread_rwlock_tryrdlock) |
| 2587 | weak_alias(pthread_rwlock_trywrlock, __pthread_rwlock_trywrlock) |
| 2588 | |
sewardj | 060b04f | 2002-04-26 21:01:13 +0000 | [diff] [blame] | 2589 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2590 | /* I've no idea what these are, but they get called quite a lot. |
| 2591 | Anybody know? */ |
| 2592 | |
| 2593 | #undef _IO_flockfile |
| 2594 | void _IO_flockfile ( _IO_FILE * file ) |
| 2595 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 2596 | pthread_mutex_lock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2597 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2598 | weak_alias(_IO_flockfile, flockfile); |
| 2599 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2600 | |
| 2601 | #undef _IO_funlockfile |
| 2602 | void _IO_funlockfile ( _IO_FILE * file ) |
| 2603 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 2604 | pthread_mutex_unlock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2605 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 2606 | weak_alias(_IO_funlockfile, funlockfile); |
| 2607 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 2608 | |
sewardj | d4f2c71 | 2002-04-30 10:20:10 +0000 | [diff] [blame] | 2609 | /* This doesn't seem to be needed to simulate libpthread.so's external |
| 2610 | interface, but many people complain about its absence. */ |
| 2611 | |
| 2612 | strong_alias(__pthread_mutexattr_settype, __pthread_mutexattr_setkind_np) |
| 2613 | weak_alias(__pthread_mutexattr_setkind_np, pthread_mutexattr_setkind_np) |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 2614 | |
| 2615 | |
| 2616 | /*--------------------------------------------------------------------*/ |
| 2617 | /*--- end vg_libpthread.c ---*/ |
| 2618 | /*--------------------------------------------------------------------*/ |