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