2 /*--------------------------------------------------------------------*/
3 /*--- Private syscalls header for Darwin. priv_syswrap-darwin.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2005-2010 Apple Inc.
11 Greg Parker gparker@apple.com
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PRIV_SYSWRAP_DARWIN_H
32 #define __PRIV_SYSWRAP_DARWIN_H
34 /* requires #include "priv_types_n_macros.h" */
37 Addr allocstack ( ThreadId tid );
38 void find_stack_segment ( ThreadId tid, Addr sp );
39 void start_thread_NORETURN ( Word arg );
40 void assign_port_name(mach_port_t port, const char *name);
41 void record_named_port(ThreadId tid, mach_port_t port, mach_port_right_t right, const char *name);
43 extern const SyscallTableEntry ML_(mach_trap_table)[];
44 extern const SyscallTableEntry ML_(syscall_table)[];
45 extern const SyscallTableEntry ML_(mdep_trap_table)[];
47 extern const UInt ML_(syscall_table_size);
48 extern const UInt ML_(mach_trap_table_size);
49 extern const UInt ML_(mdep_trap_table_size);
51 void VG_(show_open_ports)(void);
53 void ML_(sync_mappings)(const HChar *when, const HChar *where, Int num);
56 // GEN = it uses the generic wrapper
57 // NYI = wrapper not yet implemented in Valgrind
58 // NOC = the non-"_nocancel" wrapper is used
59 // old = the syscall no longer exists in Darwin
60 DECL_TEMPLATE(darwin, exit); // 1
77 DECL_TEMPLATE(darwin, getfsstat); // 18
85 DECL_TEMPLATE(darwin, ptrace); // 26
86 DECL_TEMPLATE(darwin, recvmsg); // 27
87 DECL_TEMPLATE(darwin, sendmsg); // 28
88 DECL_TEMPLATE(darwin, recvfrom); // 29
89 DECL_TEMPLATE(darwin, accept); // 30
90 DECL_TEMPLATE(darwin, getpeername); // 31
91 DECL_TEMPLATE(darwin, getsockname); // 32
93 DECL_TEMPLATE(darwin, chflags); // 34
94 DECL_TEMPLATE(darwin, fchflags); // 35
101 DECL_TEMPLATE(darwin, pipe); // 42
105 DECL_TEMPLATE(darwin, sigaction); // 46
107 DECL_TEMPLATE(darwin, sigprocmask); // 48
108 DECL_TEMPLATE(darwin, getlogin); // 49
111 DECL_TEMPLATE(darwin, sigpending); // 52
112 // GEN sigaltstack 53
113 DECL_TEMPLATE(darwin, ioctl); // 54
122 // 63 used internally, reserved
123 // old getpagesize 64
148 DECL_TEMPLATE(darwin, getdtablesize); // 89
151 DECL_TEMPLATE(darwin, fcntl); // 92
155 // GEN setpriority 96
156 DECL_TEMPLATE(darwin, socket); // 97
157 DECL_TEMPLATE(darwin, connect); // 98
159 // GEN getpriority 100
163 DECL_TEMPLATE(darwin, bind); // 104
164 DECL_TEMPLATE(darwin, setsockopt); // 105
165 DECL_TEMPLATE(darwin, listen); // 106
170 DECL_TEMPLATE(darwin, sigsuspend); // 111
175 // GEN gettimeofday 116
177 DECL_TEMPLATE(darwin, getsockopt); // 118
181 // NYI settimeofday 122
192 DECL_TEMPLATE(darwin, sendto); // 133
193 DECL_TEMPLATE(darwin, shutdown); // 134
194 DECL_TEMPLATE(darwin, socketpair); // 135
198 DECL_TEMPLATE(darwin, futimes); // 139
201 DECL_TEMPLATE(darwin, gethostuuid); // 142
211 // NYI setprivexec 152
226 DECL_TEMPLATE(darwin, mount); // 167
228 DECL_TEMPLATE(darwin, csops); // 169
235 // NYI add_profil 176
239 DECL_TEMPLATE(darwin, kdebug_trace); // 180
241 DECL_TEMPLATE(darwin, setegid); // 182
242 DECL_TEMPLATE(darwin, seteuid); // 183
243 DECL_TEMPLATE(darwin, sigreturn); // 184
244 DECL_TEMPLATE(darwin, FAKE_SIGRETURN);
251 DECL_TEMPLATE(darwin, pathconf); // 191
252 DECL_TEMPLATE(darwin, fpathconf); // 192
256 DECL_TEMPLATE(darwin, getdirentries); // 196
257 DECL_TEMPLATE(darwin, mmap); // 197
259 DECL_TEMPLATE(darwin, lseek); // 199 (was UX64)
262 DECL_TEMPLATE(darwin, __sysctl); // 202
273 // 213 Reserved for AppleTalk
274 // NYI kqueue_from_portset_np 214
275 // NYI kqueue_portset_np 215
280 DECL_TEMPLATE(darwin, getattrlist); // 220
281 DECL_TEMPLATE(darwin, setattrlist); // 221
282 DECL_TEMPLATE(darwin, getdirentriesattr); // 222
283 DECL_TEMPLATE(darwin, exchangedata); // 223
284 // 224 checkuseraccess
291 DECL_TEMPLATE(darwin, watchevent); // 231
292 DECL_TEMPLATE(darwin, waitevent); // 232
293 DECL_TEMPLATE(darwin, modwatch); // 233
294 DECL_TEMPLATE(darwin, getxattr); // 234
295 DECL_TEMPLATE(darwin, fgetxattr); // 235
296 DECL_TEMPLATE(darwin, setxattr); // 236
297 DECL_TEMPLATE(darwin, fsetxattr); // 237
298 DECL_TEMPLATE(darwin, removexattr); // 238
299 DECL_TEMPLATE(darwin, fremovexattr); // 239
300 DECL_TEMPLATE(darwin, listxattr); // 240
301 DECL_TEMPLATE(darwin, flistxattr); // 241
302 DECL_TEMPLATE(darwin, fsctl); // 242
303 DECL_TEMPLATE(darwin, initgroups); // 243
304 DECL_TEMPLATE(darwin, posix_spawn); // 244
314 DECL_TEMPLATE(darwin, semctl); // 254
315 DECL_TEMPLATE(darwin, semget); // 255
316 DECL_TEMPLATE(darwin, semop); // 256
322 DECL_TEMPLATE(darwin, shmat); // 262
323 DECL_TEMPLATE(darwin, shmctl); // 263
324 DECL_TEMPLATE(darwin, shmdt); // 264
325 DECL_TEMPLATE(darwin, shmget); // 265
326 DECL_TEMPLATE(darwin, shm_open); // 266
327 // NYI shm_unlink 267
328 DECL_TEMPLATE(darwin, sem_open); // 268
329 DECL_TEMPLATE(darwin, sem_close); // 269
330 DECL_TEMPLATE(darwin, sem_unlink); // 270
331 DECL_TEMPLATE(darwin, sem_wait); // 271
332 DECL_TEMPLATE(darwin, sem_trywait); // 272
333 DECL_TEMPLATE(darwin, sem_post); // 273
334 // NYI sem_getvalue 274
335 DECL_TEMPLATE(darwin, sem_init); // 275
336 DECL_TEMPLATE(darwin, sem_destroy); // 276
337 DECL_TEMPLATE(darwin, open_extended) // 277
338 // NYI umask_extended 278
339 DECL_TEMPLATE(darwin, stat_extended); // 279
340 DECL_TEMPLATE(darwin, lstat_extended); // 280
341 DECL_TEMPLATE(darwin, fstat_extended); // 281
342 DECL_TEMPLATE(darwin, chmod_extended); // 282
343 DECL_TEMPLATE(darwin, fchmod_extended); // 283
344 DECL_TEMPLATE(darwin, access_extended); // 284
345 DECL_TEMPLATE(darwin, settid); // 285
347 // NYI setsgroups 287
348 // NYI getsgroups 288
349 // NYI setwgroups 289
350 // NYI getwgroups 290
351 // NYI mkfifo_extended 291
352 // NYI mkdir_extended 292
353 // NYI identitysvc 293
354 // NYI shared_region_check_np 294
355 // NYI shared_region_map_np 295
356 // old load_shared_file
357 // old reset_shared_file
358 // old new_system_shared_regions
359 // old shared_region_map_file_np
360 // old shared_region_make_private_np
361 // NYI __pthread_mutex_destroy 301
362 // NYI __pthread_mutex_init 302
363 // NYI __pthread_mutex_lock 303
364 // NYI __pthread_mutex_trylock 304
365 // NYI __pthread_mutex_unlock 305
366 // NYI __pthread_cond_init 306
367 // NYI __pthread_cond_destroy 307
368 // NYI __pthread_cond_broadcast 308
369 // NYI __pthread_cond_signal 309
371 // NYI settid_with_pid 311
372 // NYI __pthread_cond_timedwait 312
374 DECL_TEMPLATE(darwin, aio_return); // 314
375 DECL_TEMPLATE(darwin, aio_suspend); // 315
376 // NYI aio_cancel 316
377 DECL_TEMPLATE(darwin, aio_error); // 317
378 DECL_TEMPLATE(darwin, aio_read); // 318
379 DECL_TEMPLATE(darwin, aio_write); // 319
380 // NYI lio_listio 320
381 // NYI __pthread_cond_wait 321
382 // NYI iopolicysys 322
385 // NYI munlockall 325
387 DECL_TEMPLATE(darwin, issetugid); // 327
388 DECL_TEMPLATE(darwin, __pthread_kill); // 328
389 DECL_TEMPLATE(darwin, __pthread_sigmask); // 329
391 DECL_TEMPLATE(darwin, __disable_threadsignal); // 331
392 DECL_TEMPLATE(darwin, __pthread_markcancel); // 332
393 DECL_TEMPLATE(darwin, __pthread_canceled); // 333
394 DECL_TEMPLATE(darwin, __semwait_signal); // 334
396 #if DARWIN_VERS >= DARWIN_10_6
397 DECL_TEMPLATE(darwin, proc_info); // 336
399 DECL_TEMPLATE(darwin, sendfile); // 337
400 DECL_TEMPLATE(darwin, stat64); // 338
401 DECL_TEMPLATE(darwin, fstat64); // 339
402 DECL_TEMPLATE(darwin, lstat64); // 340
403 DECL_TEMPLATE(darwin, stat64_extended); // 341
404 DECL_TEMPLATE(darwin, lstat64_extended); // 342
405 DECL_TEMPLATE(darwin, fstat64_extended); // 343
406 DECL_TEMPLATE(darwin, getdirentries64); // 344
407 DECL_TEMPLATE(darwin, statfs64); // 345
408 DECL_TEMPLATE(darwin, fstatfs64); // 346
409 DECL_TEMPLATE(darwin, getfsstat64); // 347
410 // NYI __pthread_chdir 348
411 // NYI __pthread_fchdir 349
413 DECL_TEMPLATE(darwin, auditon); // 351
419 // NYI getaudit_addr 357
420 // NYI setaudit_addr 358
422 DECL_TEMPLATE(darwin, bsdthread_create); // 360
423 DECL_TEMPLATE(darwin, bsdthread_terminate); // 361
424 DECL_TEMPLATE(darwin, kqueue); // 362
425 DECL_TEMPLATE(darwin, kevent); // 363
427 // NYI stack_snapshot 365
428 DECL_TEMPLATE(darwin, bsdthread_register); // 366
429 DECL_TEMPLATE(darwin, workq_open); // 367
430 DECL_TEMPLATE(darwin, workq_ops); // 368
434 DECL_TEMPLATE(darwin, __thread_selfid); // 372
442 // NYI __mac_execve 380
443 DECL_TEMPLATE(darwin, __mac_syscall); // 381
444 // NYI __mac_get_file 382
445 // NYI __mac_set_file 383
446 // NYI __mac_get_link 384
447 // NYI __mac_set_link 385
448 // NYI __mac_get_proc 386
449 // NYI __mac_set_proc 387
450 // NYI __mac_get_fd 388
451 // NYI __mac_set_fd 389
452 // NYI __mac_get_pid 390
453 // NYI __mac_get_lcid 391
454 // NYI __mac_get_lctx 392
455 // NYI __mac_set_lctx 393
458 // GEN read_nocancel 396
459 // GEN write_nocancel 397
460 // GEN open_nocancel 398
461 // GEN close_nocancel 399
462 // GEN wait4_nocancel 400
463 // NOC recvmsg_nocancel 401
464 // NOC sendmsg_nocancel 402
465 // NOC recvfrom_nocancel 403
466 // NOC accept_nocancel 404
467 // GEN msync_nocancel 405
468 // NOC fcntl_nocancel 406
469 // GEN select_nocancel 407
470 // GEN fsync_nocancel 408
471 // NOC connect_nocancel 409
472 // NYI sigsuspend_nocancel 410
473 // GEN readv_nocancel 411
474 // GEN writev_nocancel 412
475 // NOC sendto_nocancel 413
476 // GEN pread_nocancel 414
477 // GEN pwrite_nocancel 415
478 // NYI waitid_nocancel 416
479 // GEN poll_nocancel 417
480 // NYI msgsnd_nocancel 418
481 // NYI msgrcv_nocancel 419
482 // NOC sem_wait_nocancel 420
483 // NYI aio_suspend_nocancel 421
484 // NYI __sigwait_nocancel 422
485 // NOC __semwait_signal_nocancel 423
486 // NYI __mac_mount 424
487 // NYI __mac_get_mount 425
488 // NYI __mac_getfsstat 426
489 DECL_TEMPLATE(darwin, fsgetpath); // 427
490 DECL_TEMPLATE(darwin, audit_session_self); // 428
491 // NYI audit_session_join 429
493 // Mach message helpers
494 DECL_TEMPLATE(darwin, host_info);
495 DECL_TEMPLATE(darwin, host_page_size);
496 DECL_TEMPLATE(darwin, host_get_io_master);
497 DECL_TEMPLATE(darwin, host_get_clock_service);
498 DECL_TEMPLATE(darwin, host_request_notification);
499 DECL_TEMPLATE(darwin, mach_port_type);
500 DECL_TEMPLATE(darwin, mach_port_extract_member);
501 DECL_TEMPLATE(darwin, mach_port_allocate);
502 DECL_TEMPLATE(darwin, mach_port_deallocate);
503 DECL_TEMPLATE(darwin, mach_port_get_refs);
504 DECL_TEMPLATE(darwin, mach_port_mod_refs);
505 DECL_TEMPLATE(darwin, mach_port_get_set_status);
506 DECL_TEMPLATE(darwin, mach_port_move_member);
507 DECL_TEMPLATE(darwin, mach_port_destroy);
508 DECL_TEMPLATE(darwin, mach_port_request_notification);
509 DECL_TEMPLATE(darwin, mach_port_insert_right);
510 DECL_TEMPLATE(darwin, mach_port_extract_right);
511 DECL_TEMPLATE(darwin, mach_port_get_attributes);
512 DECL_TEMPLATE(darwin, mach_port_set_attributes);
513 DECL_TEMPLATE(darwin, mach_port_insert_member);
514 DECL_TEMPLATE(darwin, task_get_special_port);
515 DECL_TEMPLATE(darwin, semaphore_create);
516 DECL_TEMPLATE(darwin, semaphore_destroy);
517 DECL_TEMPLATE(darwin, mach_ports_lookup);
518 DECL_TEMPLATE(darwin, task_threads);
519 DECL_TEMPLATE(darwin, task_suspend);
520 DECL_TEMPLATE(darwin, task_resume);
521 DECL_TEMPLATE(darwin, vm_allocate);
522 DECL_TEMPLATE(darwin, vm_deallocate);
523 DECL_TEMPLATE(darwin, vm_protect);
524 DECL_TEMPLATE(darwin, vm_inherit);
525 DECL_TEMPLATE(darwin, vm_read);
526 DECL_TEMPLATE(darwin, mach_vm_read);
527 DECL_TEMPLATE(darwin, vm_copy);
528 DECL_TEMPLATE(darwin, vm_read_overwrite);
529 DECL_TEMPLATE(darwin, vm_map);
530 DECL_TEMPLATE(darwin, vm_remap);
531 DECL_TEMPLATE(darwin, mach_make_memory_entry_64);
532 DECL_TEMPLATE(darwin, vm_purgable_control);
533 DECL_TEMPLATE(darwin, mach_vm_purgable_control);
534 DECL_TEMPLATE(darwin, mach_vm_allocate);
535 DECL_TEMPLATE(darwin, mach_vm_deallocate);
536 DECL_TEMPLATE(darwin, mach_vm_protect);
537 DECL_TEMPLATE(darwin, mach_vm_copy);
538 DECL_TEMPLATE(darwin, mach_vm_inherit);
539 DECL_TEMPLATE(darwin, mach_vm_map);
540 DECL_TEMPLATE(darwin, mach_vm_region_recurse);
541 DECL_TEMPLATE(darwin, thread_terminate);
542 DECL_TEMPLATE(darwin, thread_create);
543 DECL_TEMPLATE(darwin, thread_create_running);
544 DECL_TEMPLATE(darwin, thread_suspend);
545 DECL_TEMPLATE(darwin, thread_get_state);
546 DECL_TEMPLATE(darwin, thread_policy);
547 DECL_TEMPLATE(darwin, thread_policy_set);
548 DECL_TEMPLATE(darwin, thread_info);
549 DECL_TEMPLATE(darwin, bootstrap_register);
550 DECL_TEMPLATE(darwin, bootstrap_look_up);
551 DECL_TEMPLATE(darwin, mach_msg_receive);
552 DECL_TEMPLATE(darwin, mach_msg_bootstrap);
553 DECL_TEMPLATE(darwin, mach_msg_host);
554 DECL_TEMPLATE(darwin, mach_msg_task);
555 DECL_TEMPLATE(darwin, mach_msg_thread);
558 DECL_TEMPLATE(darwin, mach_msg_unhandled);
559 DECL_TEMPLATE(darwin, mach_msg);
560 DECL_TEMPLATE(darwin, mach_reply_port);
561 DECL_TEMPLATE(darwin, mach_thread_self);
562 DECL_TEMPLATE(darwin, mach_host_self);
563 DECL_TEMPLATE(darwin, mach_task_self);
564 DECL_TEMPLATE(darwin, syscall_thread_switch);
565 DECL_TEMPLATE(darwin, semaphore_signal);
566 DECL_TEMPLATE(darwin, semaphore_signal_all);
567 DECL_TEMPLATE(darwin, semaphore_signal_thread);
568 DECL_TEMPLATE(darwin, semaphore_wait);
569 DECL_TEMPLATE(darwin, semaphore_wait_signal);
570 DECL_TEMPLATE(darwin, semaphore_timedwait);
571 DECL_TEMPLATE(darwin, semaphore_timedwait_signal);
572 DECL_TEMPLATE(darwin, task_for_pid);
573 DECL_TEMPLATE(darwin, pid_for_task);
574 DECL_TEMPLATE(darwin, mach_timebase_info);
575 DECL_TEMPLATE(darwin, mach_wait_until);
576 DECL_TEMPLATE(darwin, mk_timer_create);
577 DECL_TEMPLATE(darwin, mk_timer_destroy);
578 DECL_TEMPLATE(darwin, mk_timer_arm);
579 DECL_TEMPLATE(darwin, mk_timer_cancel);
580 DECL_TEMPLATE(darwin, iokit_user_client_trap);
581 DECL_TEMPLATE(darwin, swtch);
582 DECL_TEMPLATE(darwin, swtch_pri);
584 // Machine-dependent traps
585 DECL_TEMPLATE(darwin, thread_fast_set_cthread_self);
587 // syswrap-<arch>-darwin.c
588 #include <mach/mach.h>
590 void thread_state_from_vex(thread_state_t mach_generic,
591 thread_state_flavor_t flavor,
592 mach_msg_type_number_t count,
593 VexGuestArchState *vex_generic);
595 void thread_state_to_vex(const thread_state_t mach_generic,
596 thread_state_flavor_t flavor,
597 mach_msg_type_number_t count,
598 VexGuestArchState *vex_generic);
600 ThreadState *build_thread(const thread_state_t state,
601 thread_state_flavor_t flavor,
602 mach_msg_type_number_t count);
604 void hijack_thread_state(thread_state_t mach_generic,
605 thread_state_flavor_t flavor,
606 mach_msg_type_number_t count,
609 __attribute__((noreturn))
610 void call_on_new_stack_0_1 ( Addr stack,
615 extern void pthread_hijack_asm(void);
616 extern void pthread_hijack(Addr self, Addr kport, Addr func, Addr func_arg,
617 Addr stacksize, Addr flags, Addr sp);
618 extern void wqthread_hijack_asm(void);
619 extern void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, Int reuse, Addr sp);
621 extern Addr pthread_starter;
622 extern Addr wqthread_starter;
623 extern SizeT pthread_structsize;
628 /*--------------------------------------------------------------------*/
630 /*--------------------------------------------------------------------*/