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-2013 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 #include "pub_core_basics.h" // ThreadId
35 #include "priv_types_n_macros.h" // DECL_TEMPLATE
38 Addr allocstack ( ThreadId tid );
39 void find_stack_segment ( ThreadId tid, Addr sp );
40 void start_thread_NORETURN ( Word arg );
41 void assign_port_name(mach_port_t port, const char *name);
42 void record_named_port(ThreadId tid, mach_port_t port, mach_port_right_t right, const char *name);
44 extern const SyscallTableEntry ML_(mach_trap_table)[];
45 extern const SyscallTableEntry ML_(syscall_table)[];
46 extern const SyscallTableEntry ML_(mdep_trap_table)[];
48 extern const UInt ML_(syscall_table_size);
49 extern const UInt ML_(mach_trap_table_size);
50 extern const UInt ML_(mdep_trap_table_size);
52 void VG_(show_open_ports)(void);
54 void ML_(sync_mappings)(const HChar *when, const HChar *where, Int num);
57 // GEN = it uses the generic wrapper
58 // NYI = wrapper not yet implemented in Valgrind
59 // NOC = the non-"_nocancel" wrapper is used
60 // old = the syscall no longer exists in Darwin
61 DECL_TEMPLATE(darwin, exit); // 1
78 DECL_TEMPLATE(darwin, getfsstat); // 18
86 DECL_TEMPLATE(darwin, ptrace); // 26
87 DECL_TEMPLATE(darwin, recvmsg); // 27
88 DECL_TEMPLATE(darwin, sendmsg); // 28
89 DECL_TEMPLATE(darwin, recvfrom); // 29
90 DECL_TEMPLATE(darwin, accept); // 30
91 DECL_TEMPLATE(darwin, getpeername); // 31
92 DECL_TEMPLATE(darwin, getsockname); // 32
94 DECL_TEMPLATE(darwin, chflags); // 34
95 DECL_TEMPLATE(darwin, fchflags); // 35
102 DECL_TEMPLATE(darwin, pipe); // 42
106 DECL_TEMPLATE(darwin, sigaction); // 46
108 DECL_TEMPLATE(darwin, sigprocmask); // 48
109 DECL_TEMPLATE(darwin, getlogin); // 49
112 DECL_TEMPLATE(darwin, sigpending); // 52
113 // GEN sigaltstack 53
114 DECL_TEMPLATE(darwin, ioctl); // 54
123 // 63 used internally, reserved
124 // old getpagesize 64
149 DECL_TEMPLATE(darwin, getdtablesize); // 89
152 DECL_TEMPLATE(darwin, fcntl); // 92
156 // GEN setpriority 96
157 DECL_TEMPLATE(darwin, socket); // 97
158 DECL_TEMPLATE(darwin, connect); // 98
160 // GEN getpriority 100
164 DECL_TEMPLATE(darwin, bind); // 104
165 DECL_TEMPLATE(darwin, setsockopt); // 105
166 DECL_TEMPLATE(darwin, listen); // 106
171 DECL_TEMPLATE(darwin, sigsuspend); // 111
176 // GEN gettimeofday 116
178 DECL_TEMPLATE(darwin, getsockopt); // 118
182 // NYI settimeofday 122
193 DECL_TEMPLATE(darwin, sendto); // 133
194 DECL_TEMPLATE(darwin, shutdown); // 134
195 DECL_TEMPLATE(darwin, socketpair); // 135
199 DECL_TEMPLATE(darwin, futimes); // 139
202 DECL_TEMPLATE(darwin, gethostuuid); // 142
212 // NYI setprivexec 152
227 DECL_TEMPLATE(darwin, mount); // 167
229 DECL_TEMPLATE(darwin, csops); // 169
236 // NYI add_profil 176
240 DECL_TEMPLATE(darwin, kdebug_trace); // 180
242 DECL_TEMPLATE(darwin, setegid); // 182
243 DECL_TEMPLATE(darwin, seteuid); // 183
244 DECL_TEMPLATE(darwin, sigreturn); // 184
245 DECL_TEMPLATE(darwin, FAKE_SIGRETURN);
252 DECL_TEMPLATE(darwin, pathconf); // 191
253 DECL_TEMPLATE(darwin, fpathconf); // 192
257 DECL_TEMPLATE(darwin, getdirentries); // 196
258 DECL_TEMPLATE(darwin, mmap); // 197
260 DECL_TEMPLATE(darwin, lseek); // 199 (was UX64)
263 DECL_TEMPLATE(darwin, __sysctl); // 202
274 // 213 Reserved for AppleTalk
275 // NYI kqueue_from_portset_np 214
276 // NYI kqueue_portset_np 215
281 DECL_TEMPLATE(darwin, getattrlist); // 220
282 DECL_TEMPLATE(darwin, setattrlist); // 221
283 DECL_TEMPLATE(darwin, getdirentriesattr); // 222
284 DECL_TEMPLATE(darwin, exchangedata); // 223
285 // 224 checkuseraccess
292 DECL_TEMPLATE(darwin, watchevent); // 231
293 DECL_TEMPLATE(darwin, waitevent); // 232
294 DECL_TEMPLATE(darwin, modwatch); // 233
295 DECL_TEMPLATE(darwin, getxattr); // 234
296 DECL_TEMPLATE(darwin, fgetxattr); // 235
297 DECL_TEMPLATE(darwin, setxattr); // 236
298 DECL_TEMPLATE(darwin, fsetxattr); // 237
299 DECL_TEMPLATE(darwin, removexattr); // 238
300 DECL_TEMPLATE(darwin, fremovexattr); // 239
301 DECL_TEMPLATE(darwin, listxattr); // 240
302 DECL_TEMPLATE(darwin, flistxattr); // 241
303 DECL_TEMPLATE(darwin, fsctl); // 242
304 DECL_TEMPLATE(darwin, initgroups); // 243
305 DECL_TEMPLATE(darwin, posix_spawn); // 244
315 DECL_TEMPLATE(darwin, semctl); // 254
316 DECL_TEMPLATE(darwin, semget); // 255
317 DECL_TEMPLATE(darwin, semop); // 256
323 DECL_TEMPLATE(darwin, shmat); // 262
324 DECL_TEMPLATE(darwin, shmctl); // 263
325 DECL_TEMPLATE(darwin, shmdt); // 264
326 DECL_TEMPLATE(darwin, shmget); // 265
327 DECL_TEMPLATE(darwin, shm_open); // 266
328 DECL_TEMPLATE(darwin, shm_unlink); // 267
329 DECL_TEMPLATE(darwin, sem_open); // 268
330 DECL_TEMPLATE(darwin, sem_close); // 269
331 DECL_TEMPLATE(darwin, sem_unlink); // 270
332 DECL_TEMPLATE(darwin, sem_wait); // 271
333 DECL_TEMPLATE(darwin, sem_trywait); // 272
334 DECL_TEMPLATE(darwin, sem_post); // 273
335 // NYI sem_getvalue 274
336 DECL_TEMPLATE(darwin, sem_init); // 275
337 DECL_TEMPLATE(darwin, sem_destroy); // 276
338 DECL_TEMPLATE(darwin, open_extended) // 277
339 // NYI umask_extended 278
340 DECL_TEMPLATE(darwin, stat_extended); // 279
341 DECL_TEMPLATE(darwin, lstat_extended); // 280
342 DECL_TEMPLATE(darwin, fstat_extended); // 281
343 DECL_TEMPLATE(darwin, chmod_extended); // 282
344 DECL_TEMPLATE(darwin, fchmod_extended); // 283
345 DECL_TEMPLATE(darwin, access_extended); // 284
346 DECL_TEMPLATE(darwin, settid); // 285
348 // NYI setsgroups 287
349 // NYI getsgroups 288
350 // NYI setwgroups 289
351 // NYI getwgroups 290
352 // NYI mkfifo_extended 291
353 // NYI mkdir_extended 292
354 // NYI identitysvc 293
355 // NYI shared_region_check_np 294
356 // NYI shared_region_map_np 295
357 // old load_shared_file
358 // old reset_shared_file
359 // old new_system_shared_regions
360 // old shared_region_map_file_np
361 // old shared_region_make_private_np
362 DECL_TEMPLATE(darwin, psynch_mutexwait); // 301 // new in 10.7 ?
363 DECL_TEMPLATE(darwin, psynch_mutexdrop); // 302 // new in 10.7 ?
364 DECL_TEMPLATE(darwin, psynch_cvbroad); // 303 // new in 10.7 ?
365 DECL_TEMPLATE(darwin, psynch_cvsignal); // 304 // new in 10.7 ?
366 DECL_TEMPLATE(darwin, psynch_cvwait); // 305 // new in 10.7 ?
367 DECL_TEMPLATE(darwin, psynch_rw_rdlock); // 306 // new in 10.7 ?
368 DECL_TEMPLATE(darwin, psynch_rw_wrlock); // 307 // new in 10.7 ?
369 DECL_TEMPLATE(darwin, psynch_rw_unlock); // 308 // new in 10.7 ?
370 // NYI __pthread_cond_signal 309
372 // NYI settid_with_pid 311
373 DECL_TEMPLATE(darwin, psynch_cvclrprepost); // 312 // new in 10.7 ?
375 DECL_TEMPLATE(darwin, aio_return); // 314
376 DECL_TEMPLATE(darwin, aio_suspend); // 315
377 // NYI aio_cancel 316
378 DECL_TEMPLATE(darwin, aio_error); // 317
379 DECL_TEMPLATE(darwin, aio_read); // 318
380 DECL_TEMPLATE(darwin, aio_write); // 319
381 // NYI lio_listio 320
382 // NYI __pthread_cond_wait 321
383 // NYI iopolicysys 322
386 // NYI munlockall 325
388 DECL_TEMPLATE(darwin, issetugid); // 327
389 DECL_TEMPLATE(darwin, __pthread_kill); // 328
390 DECL_TEMPLATE(darwin, __pthread_sigmask); // 329
392 DECL_TEMPLATE(darwin, __disable_threadsignal); // 331
393 DECL_TEMPLATE(darwin, __pthread_markcancel); // 332
394 DECL_TEMPLATE(darwin, __pthread_canceled); // 333
395 DECL_TEMPLATE(darwin, __semwait_signal); // 334
397 #if DARWIN_VERS >= DARWIN_10_6
398 DECL_TEMPLATE(darwin, proc_info); // 336
400 DECL_TEMPLATE(darwin, sendfile); // 337
401 DECL_TEMPLATE(darwin, stat64); // 338
402 DECL_TEMPLATE(darwin, fstat64); // 339
403 DECL_TEMPLATE(darwin, lstat64); // 340
404 DECL_TEMPLATE(darwin, stat64_extended); // 341
405 DECL_TEMPLATE(darwin, lstat64_extended); // 342
406 DECL_TEMPLATE(darwin, fstat64_extended); // 343
407 DECL_TEMPLATE(darwin, getdirentries64); // 344
408 DECL_TEMPLATE(darwin, statfs64); // 345
409 DECL_TEMPLATE(darwin, fstatfs64); // 346
410 DECL_TEMPLATE(darwin, getfsstat64); // 347
411 // NYI __pthread_chdir 348
412 // NYI __pthread_fchdir 349
414 DECL_TEMPLATE(darwin, auditon); // 351
420 #if DARWIN_VERS >= DARWIN_10_7
421 DECL_TEMPLATE(darwin, getaudit_addr) // 357
423 // NYI setaudit_addr 358
425 DECL_TEMPLATE(darwin, bsdthread_create); // 360
426 DECL_TEMPLATE(darwin, bsdthread_terminate); // 361
427 DECL_TEMPLATE(darwin, kqueue); // 362
428 DECL_TEMPLATE(darwin, kevent); // 363
430 // NYI stack_snapshot 365
431 DECL_TEMPLATE(darwin, bsdthread_register); // 366
432 DECL_TEMPLATE(darwin, workq_open); // 367
433 DECL_TEMPLATE(darwin, workq_ops); // 368
437 DECL_TEMPLATE(darwin, __thread_selfid); // 372
445 // NYI __mac_execve 380
446 DECL_TEMPLATE(darwin, __mac_syscall); // 381
447 // NYI __mac_get_file 382
448 // NYI __mac_set_file 383
449 // NYI __mac_get_link 384
450 // NYI __mac_set_link 385
451 // NYI __mac_get_proc 386
452 // NYI __mac_set_proc 387
453 // NYI __mac_get_fd 388
454 // NYI __mac_set_fd 389
455 // NYI __mac_get_pid 390
456 // NYI __mac_get_lcid 391
457 // NYI __mac_get_lctx 392
458 // NYI __mac_set_lctx 393
461 // GEN read_nocancel 396
462 // GEN write_nocancel 397
463 // GEN open_nocancel 398
464 // GEN close_nocancel 399
465 // GEN wait4_nocancel 400
466 // NOC recvmsg_nocancel 401
467 // NOC sendmsg_nocancel 402
468 // NOC recvfrom_nocancel 403
469 // NOC accept_nocancel 404
470 // GEN msync_nocancel 405
471 // NOC fcntl_nocancel 406
472 // GEN select_nocancel 407
473 // GEN fsync_nocancel 408
474 // NOC connect_nocancel 409
475 // NYI sigsuspend_nocancel 410
476 // GEN readv_nocancel 411
477 // GEN writev_nocancel 412
478 // NOC sendto_nocancel 413
479 // GEN pread_nocancel 414
480 // GEN pwrite_nocancel 415
481 // NYI waitid_nocancel 416
482 // GEN poll_nocancel 417
483 // NYI msgsnd_nocancel 418
484 // NYI msgrcv_nocancel 419
485 // NOC sem_wait_nocancel 420
486 // NYI aio_suspend_nocancel 421
487 // NYI __sigwait_nocancel 422
488 // NOC __semwait_signal_nocancel 423
489 // NYI __mac_mount 424
490 // NYI __mac_get_mount 425
491 // NYI __mac_getfsstat 426
492 DECL_TEMPLATE(darwin, fsgetpath); // 427
493 DECL_TEMPLATE(darwin, audit_session_self); // 428
494 // NYI audit_session_join 429
496 // Mach message helpers
497 DECL_TEMPLATE(darwin, mach_port_set_context);
498 DECL_TEMPLATE(darwin, host_info);
499 DECL_TEMPLATE(darwin, host_page_size);
500 DECL_TEMPLATE(darwin, host_get_io_master);
501 DECL_TEMPLATE(darwin, host_get_clock_service);
502 DECL_TEMPLATE(darwin, host_request_notification);
503 DECL_TEMPLATE(darwin, mach_port_type);
504 DECL_TEMPLATE(darwin, mach_port_extract_member);
505 DECL_TEMPLATE(darwin, mach_port_allocate);
506 DECL_TEMPLATE(darwin, mach_port_deallocate);
507 DECL_TEMPLATE(darwin, mach_port_get_refs);
508 DECL_TEMPLATE(darwin, mach_port_mod_refs);
509 DECL_TEMPLATE(darwin, mach_port_get_set_status);
510 DECL_TEMPLATE(darwin, mach_port_move_member);
511 DECL_TEMPLATE(darwin, mach_port_destroy);
512 DECL_TEMPLATE(darwin, mach_port_request_notification);
513 DECL_TEMPLATE(darwin, mach_port_insert_right);
514 DECL_TEMPLATE(darwin, mach_port_extract_right);
515 DECL_TEMPLATE(darwin, mach_port_get_attributes);
516 DECL_TEMPLATE(darwin, mach_port_set_attributes);
517 DECL_TEMPLATE(darwin, mach_port_insert_member);
518 DECL_TEMPLATE(darwin, task_get_special_port);
519 DECL_TEMPLATE(darwin, task_get_exception_ports);
520 DECL_TEMPLATE(darwin, semaphore_create);
521 DECL_TEMPLATE(darwin, semaphore_destroy);
522 DECL_TEMPLATE(darwin, mach_ports_lookup);
523 DECL_TEMPLATE(darwin, task_threads);
524 DECL_TEMPLATE(darwin, task_suspend);
525 DECL_TEMPLATE(darwin, task_resume);
526 DECL_TEMPLATE(darwin, vm_allocate);
527 DECL_TEMPLATE(darwin, vm_deallocate);
528 DECL_TEMPLATE(darwin, vm_protect);
529 DECL_TEMPLATE(darwin, vm_inherit);
530 DECL_TEMPLATE(darwin, vm_read);
531 DECL_TEMPLATE(darwin, mach_vm_read);
532 DECL_TEMPLATE(darwin, vm_copy);
533 DECL_TEMPLATE(darwin, vm_read_overwrite);
534 DECL_TEMPLATE(darwin, vm_map);
535 DECL_TEMPLATE(darwin, vm_remap);
536 DECL_TEMPLATE(darwin, mach_make_memory_entry_64);
537 DECL_TEMPLATE(darwin, vm_purgable_control);
538 DECL_TEMPLATE(darwin, mach_vm_purgable_control);
539 DECL_TEMPLATE(darwin, mach_vm_allocate);
540 DECL_TEMPLATE(darwin, mach_vm_deallocate);
541 DECL_TEMPLATE(darwin, mach_vm_protect);
542 DECL_TEMPLATE(darwin, mach_vm_copy);
543 DECL_TEMPLATE(darwin, mach_vm_inherit);
544 DECL_TEMPLATE(darwin, mach_vm_map);
545 DECL_TEMPLATE(darwin, mach_vm_region_recurse);
546 DECL_TEMPLATE(darwin, thread_terminate);
547 DECL_TEMPLATE(darwin, thread_create);
548 DECL_TEMPLATE(darwin, thread_create_running);
549 DECL_TEMPLATE(darwin, thread_suspend);
550 DECL_TEMPLATE(darwin, thread_get_state);
551 DECL_TEMPLATE(darwin, thread_policy);
552 DECL_TEMPLATE(darwin, thread_policy_set);
553 DECL_TEMPLATE(darwin, thread_info);
554 DECL_TEMPLATE(darwin, bootstrap_register);
555 DECL_TEMPLATE(darwin, bootstrap_look_up);
556 DECL_TEMPLATE(darwin, mach_msg_receive);
557 DECL_TEMPLATE(darwin, mach_msg_bootstrap);
558 DECL_TEMPLATE(darwin, mach_msg_host);
559 DECL_TEMPLATE(darwin, mach_msg_task);
560 DECL_TEMPLATE(darwin, mach_msg_thread);
563 #if DARWIN_VERS == DARWIN_10_8
564 DECL_TEMPLATE(darwin, mach__10);
565 DECL_TEMPLATE(darwin, mach__12);
566 DECL_TEMPLATE(darwin, mach__14);
567 DECL_TEMPLATE(darwin, mach__16);
568 DECL_TEMPLATE(darwin, mach__18);
569 DECL_TEMPLATE(darwin, mach__19);
570 DECL_TEMPLATE(darwin, mach__20);
571 DECL_TEMPLATE(darwin, mach__21);
572 #endif /* DARWIN_VERS == DARWIN_10_8 */
573 DECL_TEMPLATE(darwin, mach_msg_unhandled);
574 DECL_TEMPLATE(darwin, mach_msg);
575 DECL_TEMPLATE(darwin, mach_reply_port);
576 DECL_TEMPLATE(darwin, mach_thread_self);
577 DECL_TEMPLATE(darwin, mach_host_self);
578 DECL_TEMPLATE(darwin, mach_task_self);
579 DECL_TEMPLATE(darwin, syscall_thread_switch);
580 DECL_TEMPLATE(darwin, semaphore_signal);
581 DECL_TEMPLATE(darwin, semaphore_signal_all);
582 DECL_TEMPLATE(darwin, semaphore_signal_thread);
583 DECL_TEMPLATE(darwin, semaphore_wait);
584 DECL_TEMPLATE(darwin, semaphore_wait_signal);
585 DECL_TEMPLATE(darwin, semaphore_timedwait);
586 DECL_TEMPLATE(darwin, semaphore_timedwait_signal);
587 DECL_TEMPLATE(darwin, task_for_pid);
588 DECL_TEMPLATE(darwin, pid_for_task);
589 DECL_TEMPLATE(darwin, mach_timebase_info);
590 DECL_TEMPLATE(darwin, mach_wait_until);
591 DECL_TEMPLATE(darwin, mk_timer_create);
592 DECL_TEMPLATE(darwin, mk_timer_destroy);
593 DECL_TEMPLATE(darwin, mk_timer_arm);
594 DECL_TEMPLATE(darwin, mk_timer_cancel);
595 DECL_TEMPLATE(darwin, iokit_user_client_trap);
596 DECL_TEMPLATE(darwin, swtch);
597 DECL_TEMPLATE(darwin, swtch_pri);
599 // Machine-dependent traps
600 DECL_TEMPLATE(darwin, thread_fast_set_cthread_self);
602 // syswrap-<arch>-darwin.c
603 #include <mach/mach.h>
605 void thread_state_from_vex(thread_state_t mach_generic,
606 thread_state_flavor_t flavor,
607 mach_msg_type_number_t count,
608 VexGuestArchState *vex_generic);
610 void thread_state_to_vex(const thread_state_t mach_generic,
611 thread_state_flavor_t flavor,
612 mach_msg_type_number_t count,
613 VexGuestArchState *vex_generic);
615 ThreadState *build_thread(const thread_state_t state,
616 thread_state_flavor_t flavor,
617 mach_msg_type_number_t count);
619 void hijack_thread_state(thread_state_t mach_generic,
620 thread_state_flavor_t flavor,
621 mach_msg_type_number_t count,
624 __attribute__((noreturn))
625 void call_on_new_stack_0_1 ( Addr stack,
630 extern void pthread_hijack_asm(void);
631 extern void pthread_hijack(Addr self, Addr kport, Addr func, Addr func_arg,
632 Addr stacksize, Addr flags, Addr sp);
633 extern void wqthread_hijack_asm(void);
634 extern void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, Int reuse, Addr sp);
636 extern Addr pthread_starter;
637 extern Addr wqthread_starter;
638 extern SizeT pthread_structsize;
643 /*--------------------------------------------------------------------*/
645 /*--------------------------------------------------------------------*/