-
Notifications
You must be signed in to change notification settings - Fork 11
/
machapi.pas
3351 lines (2766 loc) · 112 KB
/
machapi.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
fpDebug - A debugger for the Free Pascal Compiler.
Copyright (c) 2012 by Graeme Geldenhuys.
See the file LICENSE.txt, included in this distribution,
for details about redistributing fpDebug.
Description:
.
}
unit machapi;
// mach_vm_size_t processor dependant!?
// Mach man pages
// http://www.opensource.apple.com/source/xnu/
// http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/
{$ifdef fpc}{$mode delphi}{$H+}{$endif}
interface
type
NDR_record_t = packed record
mig_vers : byte;
if_vers : byte;
reserved1 : byte;
mig_encoding : byte;
int_rep : byte;
char_rep : byte;
float_rep : byte;
reserved2 : byte;
end;
const
{ MIG supported protocols for Network Data Representation }
NDR_PROTOCOL_2_0 = 0;
{ NDR 2.0 format flag type definition and values. }
NDR_INT_BIG_ENDIAN = 0;
NDR_INT_LITTLE_ENDIAN = 1;
NDR_FLOAT_IEEE = 0;
NDR_FLOAT_VAX = 1;
NDR_FLOAT_CRAY = 2;
NDR_FLOAT_IBM = 3;
NDR_CHAR_ASCII = 0;
NDR_CHAR_EBCDIC = 1;
{* File: h/kern_return.h
* Author: Avadis Tevanian, Jr.
* Date: 1985
*
* Kernel return codes. *}
const
KERN_SUCCESS= 0;
KERN_INVALID_ADDRESS = 1; {* Specified address is not currently valid. *}
KERN_PROTECTION_FAILURE = 2; {* Specified memory is valid, but does not permit the required forms of access.*}
KERN_NO_SPACE = 3; {* The address range specified is already in use, or no address range of the size specified could be found. *}
KERN_INVALID_ARGUMENT = 4; {* The function requested was not applicable to this type of argument, or an argument is invalid *}
KERN_FAILURE = 5; {* The function could not be performed. A catch-all. *}
KERN_RESOURCE_SHORTAGE = 6; {* A system resource could not be allocated to fulfill this request. This failure may not be permanent. *}
KERN_NOT_RECEIVER = 7; {* The task in question does not hold receive rights for the port argument. *}
KERN_NO_ACCESS = 8; {* Bogus access restriction.*}
KERN_MEMORY_FAILURE = 9;
{* During a page fault, the target address refers to a
* memory object that has been destroyed. This
* failure is permanent. *}
KERN_MEMORY_ERROR = 10;
{* During a page fault, the memory object indicated
* that the data could not be returned. This failure
* may be temporary; future attempts to access this
* same data may succeed, as defined by the memory
* object. *}
KERN_ALREADY_IN_SET = 11; {* The receive right is already a member of the portset. *}
KERN_NOT_IN_SET = 12; {* The receive right is not a member of a port set. *}
KERN_NAME_EXISTS = 13; {* The name already denotes a right in the task. *}
KERN_ABORTED = 14; {* The operation was aborted. Ipc code will catch this and reflect it as a message error. *}
KERN_INVALID_NAME = 15; {* The name doesn't denote a right in the task. *}
KERN_INVALID_TASK = 16; {* Target task isn't an active task. *}
KERN_INVALID_RIGHT = 17; {* The name denotes a right, but not an appropriate right. *}
KERN_INVALID_VALUE = 18; {* A blatant range error. *}
KERN_UREFS_OVERFLOW = 19; {* Operation would overflow limit on user-references. *}
KERN_INVALID_CAPABILITY = 20; {* The supplied (port) capability is improper. *}
KERN_RIGHT_EXISTS = 21; {* The task already has send or receive rights for the port under another name. *}
KERN_INVALID_HOST = 22; {* Target host isn't actually a host. *}
KERN_MEMORY_PRESENT = 23; {* An attempt was made to supply "precious" data for memory that is already present in a memory object.*}
KERN_MEMORY_DATA_MOVED = 24;
{* A page was requested of a memory manager via
* memory_object_data_request for an object using
* a MEMORY_OBJECT_COPY_CALL strategy, with the
* VM_PROT_WANTS_COPY flag being used to specify
* that the page desired is for a copy of the
* object, and the memory manager has detected
* the page was pushed into a copy of the object
* while the kernel was walking the shadow chain
* from the copy to the object. This error code
* is delivered via memory_object_data_error
* and is handled by the kernel (it forces the
* kernel to restart the fault). It will not be
* seen by users.
*}
KERN_MEMORY_RESTART_COPY = 25; {* A strategic copy was attempted of an object *}
{* upon which a quicker copy is now possible. *}
{* The caller should retry the copy using *}
{* vm_object_copy_quickly. This error code *}
{* is seen only by the kernel. *}
KERN_INVALID_PROCESSOR_SET = 26; {* An argument applied to assert processor set privilege was not a processor set control port. *}
KERN_POLICY_LIMIT = 27; {* The specified scheduling attributes exceed the thread's limits. *}
KERN_INVALID_POLICY = 28; {* The specified scheduling policy is not currently enabled for the processor set. *}
KERN_INVALID_OBJECT = 29; {* The external memory manager failed to initialize the memory object. *}
KERN_ALREADY_WAITING = 30; {* A thread is attempting to wait for an event for which there is already a waiting thread. *}
KERN_DEFAULT_SET = 31; {* An attempt was made to destroy the default processor set. *}
KERN_EXCEPTION_PROTECTED = 32; {* An attempt was made to fetch an exception port that is protected, *}
{* or to abort a thread while processing a protected exception. *}
KERN_INVALID_LEDGER = 33; {* A ledger was required but not supplied. *}
KERN_INVALID_MEMORY_CONTROL = 34; {* The port was not a memory cache control port. *}
KERN_INVALID_SECURITY = 35; {* An argument supplied to assert security privilege was not a host security port. *}
KERN_NOT_DEPRESSED = 36; {* thread_depress_abort was called on a thread which was not currently depressed. *}
KERN_TERMINATED = 37; {* Object has been terminated and is no longer available *}
KERN_LOCK_SET_DESTROYED = 38; {* Lock set has been destroyed and is no longer available.*}
KERN_LOCK_UNSTABLE = 39; {* The thread holding the lock terminated before releasing the lock *}
KERN_LOCK_OWNED = 40; {* The lock is already owned by another thread *}
KERN_LOCK_OWNED_SELF = 41; {* The lock is already owned by the calling thread *}
KERN_SEMAPHORE_DESTROYED = 42; {* Semaphore has been destroyed and is no longer available. *}
KERN_RPC_SERVER_TERMINATED = 43; {* Return from RPC indicating the target server was terminated before it successfully replied *}
KERN_RPC_TERMINATE_ORPHAN = 44; {* Terminate an orphaned activation. *}
KERN_RPC_CONTINUE_ORPHAN = 45; {* Allow an orphaned activation to continue executing. *}
KERN_NOT_SUPPORTED = 46; {* Empty thread activation (No thread linked to it)*}
KERN_NODE_DOWN = 47; {* Remote node down or inaccessible. *}
KERN_NOT_WAITING = 48; {* A signalled thread was not actually waiting. *}
KERN_OPERATION_TIMED_OUT = 49; {* Some thread-oriented operation (semaphore_wait) timed out *}
KERN_RETURN_MAX = $100; {* Maximum return value allowable *}
type
// boolean_t = Integer;
boolean_t = LongBool;
// integer_t = Integer;
// natural_t = LongWord;
uint64_t = QWord;
int64_t = Int64;
{*
* Header file for basic, machine-dependent data types. i386 version.
*}
int16_t = SmallInt;
int32_t = Integer;
uint32_t = LongWord;
MACH_MSG_TYPE_REAL_32 = single;
MACH_MSG_TYPE_REAL_64 = double;
// from ISO/IEC 988:1999 spec *}
// 7.18.1.4 Integer types capable of hgolding object pointers *}
{*
* The [u]intptr_t types for the native
* integer type, e.g. 32 or 64 or.. whatever
* register size the machine has. They are
* used for entities that might be either
* [unsigned] integers or pointers, and for
* type-casting between the two.
*
* For instance, the IPC system represents
* a port in user space as an integer and
* in kernel space as a pointer.
*}
//#if defined(__LP64__)
//type uintptr_t = uint64_t;
//type intptr_t = int64_t;
//#else
//type uintptr_t = uint32_t;
//type intptr_t = int32_t;
//#endif
{*
* These are the legacy Mach types that are
* the [rough] equivalents of the standards above.
* They were defined in terms of int, not
* long int, so they remain separate.
*}
{if defined(__LP64__)
type register_t = int64_t;
#else
type register_t = int32_t;
#endif}
register_t = int32_t;
integer_t = int32_t;
natural_t = uint32_t;
pinteger_t = ^integer_t;
pnatural_t = ^natural_t;
{*
* These are the VM types that scale with the address
* space size of a given process.
*}
{if defined(__LP64__)
type vm_address_t = uint64_t;
type vm_offset_t = uint64_t;
type vm_size_t = uint64_t;
#else}
vm_address_t = natural_t;
vm_offset_t = natural_t;
vm_size_t = natural_t;
pvm_address_t = ^vm_address_t;
pvm_offset_t = ^vm_offset_t;
pvm_size_t = ^vm_size_t;
//endif
{*
* The mach_vm_xxx_t types are sized to hold the
* maximum pointer, offset, etc... supported on the
* platform.
*}
mach_vm_address_t = uint64_t;
pmach_vm_address_t = ^mach_vm_address_t;
mach_vm_offset_t = uint64_t;
mach_vm_size_t = uint64_t;
pmach_vm_size_t = ^mach_vm_size_t;
{ Time value returned by kernel.}
time_value = record
seconds : integer_t;
microseconds : integer_t;
end;
time_value_t = time_value;
// mach_types.h
type
kern_return_t = Integer;
mach_port_t = Integer;
pmach_port_t = ^mach_port_t;
task_t = mach_port_t;
task_name_t = mach_port_t;
thread_act_t = mach_port_t;
ipc_space_t = mach_port_t ;
thread_t = mach_port_t;
host_t = mach_port_t;
host_priv_t = mach_port_t;
host_security_t = mach_port_t;
processor_t = mach_port_t;
processor_set_t = mach_port_t;
processor_set_control_t = mach_port_t;
semaphore_t = mach_port_t;
lock_set_t = mach_port_t;
ledger_t = mach_port_t;
alarm_t = mach_port_t;
clock_serv_t = mach_port_t;
clock_ctrl_t = mach_port_t;
mach_msg_type_number_t = Integer;
Pmach_msg_type_number_t = ^mach_msg_type_number_t;
{ * Mig doesn't translate the components of an array.
* For example, Mig won't use the thread_t translations
* to translate a thread_array_t argument. So, these definitions
* are not completely accurate at the moment for other kernel
* components. }
//typedef task_t *task_array_t;
Ttask_array = array [word] of task_t;
Ptask_array = ^Ttask_array;
//task_array_t = ^task_t;
task_array_t = Ptask_array;
//todo:
thread_array_t = ^thread_t;
processor_set_array_t = ^processor_set_t;
processor_set_name_array_t = ^processor_set_t;
processor_array_t = ^processor_t;
Tthread_act_array_t = array [word] of thread_act_t;
Pthread_act_array_t = ^Tthread_act_array_t;
thread_act_array_t = Pthread_act_array_t;
//thread_act_array_t = ^thread_act_t;
ledger_array_t = ^ledger_t;
{* These aren't really unique types. They are just called
* out as unique types at one point in history. So we list
* them here for compatibility. }
processor_set_name_t = processor_set_t;
{ These types are just hard-coded as ports }
clock_reply_t = mach_port_t;
bootstrap_t = mach_port_t;
mem_entry_name_port_t = mach_port_t;
exception_handler_t = mach_port_t;
Texception_handler_array = array [word] of exception_handler_t;
Pexception_handler_array = ^Texception_handler_array;
exception_handler_array_t = Pexception_handler_array;
//exception_handler_array_t = ^exception_handler_t;
vm_task_entry_t = mach_port_t;
io_master_t = mach_port_t;
UNDServerRef = mach_port_t;
const
TASK_NULL = 0;
TASK_NAME_NULL = 0;
THREAD_NULL = 0;
THR_ACT_NULL = 0;
IPC_SPACE_NULL = 0;
HOST_NULL = 0;
HOST_PRIV_NULL = 0;
HOST_SECURITY_NULL = 0;
PROCESSOR_SET_NULL = 0;
PROCESSOR_NULL = 0;
SEMAPHORE_NULL = 0;
LOCK_SET_NULL = 0;
LEDGER_NULL = 0;
ALARM_NULL = 0;
CLOCK_NULL = 0;
UND_SERVER_NULL = 0;
type
ledger_item_t = natural_t;
Temulation_vector = array [word] of mach_vm_offset_t;
Pemulation_vector = ^Temulation_vector;
//emulation_vector_t = ^mach_vm_offset_t;
emulation_vector_t = Pemulation_vector;
user_subsystem_t = Pchar;
labelstr_t = Pchar;
{* File: mach/error.h
* Purpose:
* error module definitions *}
{* error number layout as follows:
*
* hi lo
* | system(6) | subsystem(12) | code(14) | *}
const
err_none = 0;
ERR_SUCCESS = 0;
ERR_ROUTINE_NIL = nil;
system_emask = $3f shr 26;
sub_emask = $fff shr 14;
code_emask = $3fff;
(* major error systems *)
const
//err_system(x) (((x)&0x3f)<<26) ((| and $3f) shr 26)
err_kern = (0 shr 26); // err_system(0x1) /* kernel */
err_us = (1 shr 26); // err_system(0x1) /* user space library */
err_server = (2 shr 26); // err_system(0x2) /* user space servers */
err_ipc = (3 shr 26); // err_system(0x3) /* old ipc errors */
err_mach_ipc = (4 shr 26); // err_system(0x4) /* mach-ipc errors */
err_dipc = (7 shr 26); // err_system(0x7) /* distributed ipc */
err_local = ($3e shr 26); // err_system(0x3e) /* user defined errors */
err_ipc_compat = ($ef shr 26); // err_system(0x3f) /* (compatibility) mach-ipc errors */
err_max_system = $3f;
type
mach_error_t = kern_return_t;
mach_error_fn_t = function : mach_error_t; cdecl;
// port.h
{*
* File: mach/port.h
*
* Definition of a Mach port
*
* Mach ports are the endpoints to Mach-implemented communications
* channels (usually uni-directional message queues, but other types
* also exist).
*
* Unique collections of these endpoints are maintained for each
* Mach task. Each Mach port in the task's collection is given a
* [task-local] name to identify it - and the the various "rights"
* held by the task for that specific endpoint.
*
* This header defines the types used to identify these Mach ports
* and the various rights associated with them. For more info see:
*
* <mach/mach_port.h> - manipulation of port rights in a given space
* <mach/message.h> - message queue [and port right passing] mechanism
*
*}
{*
* mach_port_name_t - the local identity for a Mach port
*
* The name is Mach port namespace specific. It is used to
* identify the rights held for that port by the task whose
* namespace is implied [or specifically provided].
*
* Use of this type usually implies just a name - no rights.
* See mach_port_t for a type that implies a "named right."
*
*}
type
mach_port_name_t = natural_t;
mach_port_name_array_t = ^mach_port_name_t;
pmach_port_name_t = ^mach_port_name_t;
pmach_port_name_array_t = ^mach_port_name_array_t;
{*
* mach_port_t - a named port right
*
* In user-space, "rights" are represented by the name of the
* right in the Mach port namespace. Even so, this type is
* presented as a unique one to more clearly denote the presence
* of a right coming along with the name.
*
* Often, various rights for a port held in a single name space
* will coalesce and are, therefore, be identified by a single name
* [this is the case for send and receive rights]. But not
* always [send-once rights currently get a unique name for
* each right].
*
*}
type
mach_port_array_t = ^mach_port_t;
{*
* MACH_PORT_NULL is a legal value that can be carried in messages.
* It indicates the absence of any port or port rights. (A port
* argument keeps the message from being "simple", even if the
* value is MACH_PORT_NULL.) The value MACH_PORT_DEAD is also a legal
* value that can be carried in messages. It indicates
* that a port right was present, but it died.
*}
const
MACH_PORT_NULL = 0; {* intentional loose typing *}
MACH_PORT_DEAD = mach_port_name_t($FFFFFFFF);
{ MACH_PORT_VALID(name) \
(((name) != MACH_PORT_NULL) && \
((name) != MACH_PORT_DEAD))}
{*
* These are the different rights a task may have for a port.
* The MACH_PORT_RIGHT_* definitions are used as arguments
* to mach_port_allocate, mach_port_get_refs, etc, to specify
* a particular right to act upon. The mach_port_names and
* mach_port_type calls return bitmasks using the MACH_PORT_TYPE_*
* definitions. This is because a single name may denote
* multiple rights.
*}
type
mach_port_right_t = natural_t;
const
MACH_PORT_RIGHT_SEND = 0;
MACH_PORT_RIGHT_RECEIVE = 1;
MACH_PORT_RIGHT_SEND_ONCE = 2;
MACH_PORT_RIGHT_PORT_SET = 3;
MACH_PORT_RIGHT_DEAD_NAME = 4;
MACH_PORT_RIGHT_LABELH = 5;
MACH_PORT_RIGHT_NUMBER = 6;
type
mach_port_type_t = natural_t;
mach_port_type_array_t = ^mach_port_type_t;
pmach_port_type_t = ^mach_port_type_t;
pmach_port_type_array_t = ^mach_port_type_array_t;
{#define MACH_PORT_TYPE(right) \
(
(mach_port_type_t)
( 1 << ((right) + (16)) }
const
MACH_PORT_TYPE_NONE = 0;
MACH_PORT_TYPE_SEND = 1 shl (MACH_PORT_RIGHT_SEND+16);
MACH_PORT_TYPE_RECEIVE = 1 shl (MACH_PORT_RIGHT_RECEIVE+16);
MACH_PORT_TYPE_SEND_ONCE = 1 shl (MACH_PORT_RIGHT_SEND_ONCE+16);
MACH_PORT_TYPE_PORT_SET = 1 shl (MACH_PORT_RIGHT_PORT_SET+16);
MACH_PORT_TYPE_DEAD_NAME = 1 shl (MACH_PORT_RIGHT_DEAD_NAME+16);
MACH_PORT_TYPE_LABELH = 1 shl (MACH_PORT_RIGHT_LABELH+16);
{ Convenient combinations. }
MACH_PORT_TYPE_SEND_RECEIVE = (MACH_PORT_TYPE_SEND or MACH_PORT_TYPE_RECEIVE);
MACH_PORT_TYPE_SEND_RIGHTS = (MACH_PORT_TYPE_SEND or MACH_PORT_TYPE_SEND_ONCE);
MACH_PORT_TYPE_PORT_RIGHTS = (MACH_PORT_TYPE_SEND_RIGHTS or MACH_PORT_TYPE_RECEIVE);
MACH_PORT_TYPE_PORT_OR_DEAD = (MACH_PORT_TYPE_PORT_RIGHTS or MACH_PORT_TYPE_DEAD_NAME);
MACH_PORT_TYPE_ALL_RIGHTS = (MACH_PORT_TYPE_PORT_OR_DEAD or MACH_PORT_TYPE_PORT_SET);
// Dummy type bits that mach_port_type/mach_port_names can return.
MACH_PORT_TYPE_DNREQUEST = $80000000;
// User-references for capabilities.
type
mach_port_urefs_t = natural_t;
mach_port_delta_t = integer_t; { change in urefs }
pmach_port_urefs_t = ^mach_port_urefs_t;
{ Attributes of ports. (See mach_port_get_receive_status.) }
mach_port_seqno_t = natural_t; { sequence number }
mach_port_mscount_t = natural_t; { make-send count }
mach_port_msgcount_t = natural_t; { number of msgs }
mach_port_rights_t = natural_t; { number of rights }
pmach_port_rights_t = ^mach_port_rights_t;
{*
* Are there outstanding send rights for a given port?
*}
const
MACH_PORT_SRIGHTS_NONE = 0; { no srights }
MACH_PORT_SRIGHTS_PRESENT = 1; { srights }
type
mach_port_srights_t = LongWord; { status of send rights }
type
mach_port_status = record
mps_pset : mach_port_rights_t; { count of containing port sets }
mps_seqno : mach_port_seqno_t ; { sequence number }
mps_mscount : mach_port_mscount_t; { make-send count }
mps_qlimit : mach_port_msgcount_t; { queue limit }
mps_msgcount : mach_port_msgcount_t; { number in the queue }
mps_sorights : mach_port_rights_t; { how many send-once rights }
mps_srights : boolean_t; { do send rights exist? }
mps_pdrequest : boolean_t; { port-deleted requested? }
mps_nsrequest : boolean_t; { no-senders requested? }
mps_flags : natural_t; { port flags }
end;
mach_port_status_t = mach_port_status;
{ System-wide values for setting queue limits on a port }
const
MACH_PORT_QLIMIT_ZERO = 0;
MACH_PORT_QLIMIT_BASIC = 5;
MACH_PORT_QLIMIT_SMALL = 16;
MACH_PORT_QLIMIT_LARGE = 1024;
MACH_PORT_QLIMIT_MIN = MACH_PORT_QLIMIT_ZERO;
MACH_PORT_QLIMIT_DEFAULT = MACH_PORT_QLIMIT_BASIC;
MACH_PORT_QLIMIT_MAX = MACH_PORT_QLIMIT_LARGE;
type
mach_port_limits = record
mpl_qlimit: mach_port_msgcount_t; { number of msgs }
end;
mach_port_limits_t = mach_port_limits;
mach_port_info_t = ^integer_t; { varying array of natural_t }
{ Flavors for mach_port_get/set_attributes() }
mach_port_flavor_t = integer;
const
MACH_PORT_LIMITS_INFO = 1; { uses mach_port_status_t }
MACH_PORT_RECEIVE_STATUS = 2; { uses mach_port_limits_t }
MACH_PORT_DNREQUESTS_SIZE = 3; { info is int }
MACH_PORT_LIMITS_INFO_COUNT = sizeof(mach_port_limits_t) div sizeof(natural_t);
MACH_PORT_RECEIVE_STATUS_COUNT = sizeof(mach_port_status_t) div sizeof(natural_t);
MACH_PORT_DNREQUESTS_SIZE_COUNT = 1;
{*
* Structure used to pass information about port allocation requests.
* Must be padded to 64-bits total length.
*}
type
mach_port_qos = record
//unsigned int name:1; {* name given *}
//unsigned int prealloc:1; {* prealloced message *}
//boolean_t pad1:30;
flags : LongWord;
len : natural_t;
end;
mach_port_qos_t = mach_port_qos;
pmach_port_qos_t = ^mach_port_qos_t;
//#if !__DARWIN_UNIX03 && !defined(_NO_PORT_T_FROM_MACH)
{*
* Mach 3.0 renamed everything to have mach_ in front of it.
* These types and macros are provided for backward compatibility
* but are deprecated.
*}
type
port_t = mach_port_t;
port_name_t = mach_port_name_t ;
port_name_array_t = ^mach_port_name_t;
const
PORT_NULL = 0;
PORT_DEAD = port_t($FFFFFFFF);
//#define PORT_VALID(name) \
// ((port_t)(name) != PORT_NULL && (port_t)(name) != PORT_DEAD)
{*******************************************************************************
* File: mach/message.h *
* *
* Mach IPC message and primitive function definitions. *
*******************************************************************************}
{*
* The timeout mechanism uses mach_msg_timeout_t values,
* passed by value. The timeout units are milliseconds.
* It is controlled with the MACH_SEND_TIMEOUT
* and MACH_RCV_TIMEOUT options.
*}
type
mach_msg_timeout_t = natural_t ;
{*
* The value to be used when there is no timeout.
* (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
*}
const
MACH_MSG_TIMEOUT_NONE = 0;
{*
* The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. It it isn't on, it
* assumes the body of the message doesn't contain port rights or OOL
* data. The field is set in received messages. A user task must
* use caution in interpreting the body of a message if the bit isn't
* on, because the mach_msg_type's in the body might "lie" about the
* contents. If the bit isn't on, but the mach_msg_types
* in the body specify rights or OOL data, the behavior is undefined.
* (Ie, an error may or may not be produced.)
*
* The value of MACH_MSGH_BITS_REMOTE determines the interpretation
* of the msgh_remote_port field. It is handled like a msgt_name.
*
* The value of MACH_MSGH_BITS_LOCAL determines the interpretation
* of the msgh_local_port field. It is handled like a msgt_name.
*
* MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
* and local fields, into a single value suitable for msgh_bits.
*
* MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally.
*
* The unused bits should be zero and are reserved for the kernel
* or for future interface expansion.
*}
const
MACH_MSGH_BITS_ZERO = $00000000;
MACH_MSGH_BITS_REMOTE_MASK = $000000ff;
MACH_MSGH_BITS_LOCAL_MASK = $0000ff00;
MACH_MSGH_BITS_COMPLEX = $80000000;
MACH_MSGH_BITS_USER = $8000ffff;
MACH_MSGH_BITS_CIRCULAR = $40000000; { internal use only }
MACH_MSGH_BITS_USED = $c000ffff;
MACH_MSGH_BITS_PORTS_MASK = (MACH_MSGH_BITS_REMOTE_MASK or MACH_MSGH_BITS_LOCAL_MASK);
{#define MACH_MSGH_BITS(remote, local) \
((remote) | ((local) << 8))
#define MACH_MSGH_BITS_REMOTE(bits) \
((bits) & MACH_MSGH_BITS_REMOTE_MASK)
#define MACH_MSGH_BITS_LOCAL(bits) \
(((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
#define MACH_MSGH_BITS_PORTS(bits) \
((bits) & MACH_MSGH_BITS_PORTS_MASK)
#define MACH_MSGH_BITS_OTHER(bits) \
((bits) &~ MACH_MSGH_BITS_PORTS_MASK)}
{*
* Every message starts with a message header.
* Following the message header are zero or more pairs of
* type descriptors (mach_msg_type_t/mach_msg_type_long_t) and
* data values. The size of the message must be specified in bytes,
* and includes the message header, type descriptors, inline
* data, and inline pointer for out-of-line data.
*
* The msgh_remote_port field specifies the destination of the message.
* It must specify a valid send or send-once right for a port.
*
* The msgh_local_port field specifies a "reply port". Normally,
* This field carries a send-once right that the receiver will use
* to reply to the message. It may carry the values MACH_PORT_NULL,
* MACH_PORT_DEAD, a send-once right, or a send right.
*
* The msgh_seqno field carries a sequence number associated with the
* received-from port. A port's sequence number is incremented every
* time a message is received from it. In sent messages, the field's
* value is ignored.
*
* The msgh_id field is uninterpreted by the message primitives.
* It normally carries information specifying the format
* or meaning of the message.
*}
type
mach_msg_bits_t = LongWord;
mach_msg_size_t = natural_t;
mach_msg_id_t = integer_t ;
const
MACH_MSG_SIZE_NULL = 0; // (mach_msg_size_t *) 0
type
mach_msg_type_name_t = LongWord;
pmach_msg_type_name_t = ^mach_msg_type_name_t;
const
MACH_MSG_TYPE_MOVE_RECEIVE = 16; { Must hold receive rights }
MACH_MSG_TYPE_MOVE_SEND = 17; { Must hold send rights }
MACH_MSG_TYPE_MOVE_SEND_ONCE = 18; { Must hold sendonce rights }
MACH_MSG_TYPE_COPY_SEND = 19; { Must hold send rights }
MACH_MSG_TYPE_MAKE_SEND = 20; { Must hold receive rights }
MACH_MSG_TYPE_MAKE_SEND_ONCE = 21; { Must hold receive rights }
MACH_MSG_TYPE_COPY_RECEIVE = 22; { Must hold receive rights }
type
mach_msg_copy_options_t = LongWord;
const
MACH_MSG_PHYSICAL_COPY = 0;
MACH_MSG_VIRTUAL_COPY = 1;
MACH_MSG_ALLOCATE = 2;
MACH_MSG_OVERWRITE_ = 3;
MACH_MSG_KALLOC_COPY_T = 4;
type
mach_msg_descriptor_type_t = LongWord;
const
MACH_MSG_PORT_DESCRIPTOR = 0;
MACH_MSG_OOL_DESCRIPTOR = 1;
MACH_MSG_OOL_PORTS_DESCRIPTOR = 2;
MACH_MSG_OOL_VOLATILE_DESCRIPTOR = 3;
//#pragma pack(4), not packed records?
type
mach_msg_type_descriptor_t = packed record
pad1 : natural_t;
pad2 : mach_msg_size_t;
pad3_type : LongWord
end;
mach_msg_port_descriptor_t = packed record
name : mach_port_t;
pad1 : mach_msg_size_t;
pad2 : word;
disposition : byte;
_type : byte;
end;
mach_msg_ool_descriptor32_t = packed record
address : uint32_t;
size : mach_msg_size_t;
deallocate : boolean;
copy : byte; // as mach_msg_copy_options_t
pad1 : byte;
_type : byte; // as mach_msg_descriptor_type_t
end;
mach_msg_ool_descriptor64_t = packed record
address : uint64_t;
deallocate : boolean;
copy : byte; // as mach_msg_copy_options_t
pad1 : byte;
_type : byte; // as mach_msg_descriptor_type_t
size : mach_msg_size_t;
end;
{$ifdef CPU64}
mach_msg_ool_descriptor_t = mach_msg_ool_descriptor64_t;
{$else}
mach_msg_ool_descriptor_t = mach_msg_ool_descriptor32_t;
{$endif}
mach_msg_ool_ports_descriptor32_t = packed record
address : uint32_t;
count : mach_msg_size_t;
deallocate : boolean;
copy : byte; // as mach_msg_copy_options_t
disposition : byte; // as mach_msg_type_name_t
_type : byte; // as mach_msg_descriptor_type_t
end;
mach_msg_ool_ports_descriptor64_t = packed record
address : uint64_t;
deallocate : boolean;
copy : byte; // as mach_msg_copy_options_t
disposition : byte; // as mach_msg_type_name_t
_type : byte; // as mach_msg_descriptor_type_t
count : mach_msg_size_t;
end;
{$ifdef CPU64}
mach_msg_ool_ports_descriptor_t=mach_msg_ool_ports_descriptor64_t;
{$else}
mach_msg_ool_ports_descriptor_t=mach_msg_ool_ports_descriptor32_t;
{$endif}
{*
* LP64support - This union definition is not really
* appropriate in LP64 mode because not all descriptors
* are of the same size in that environment.
*}
mach_msg_descriptor_t = packed record
case byte of
0: (port : mach_msg_port_descriptor_t);
1: (out_of_line : mach_msg_ool_descriptor_t);
2: (ool_ports : mach_msg_ool_ports_descriptor_t);
3: (_type : mach_msg_type_descriptor_t);
end;
mach_msg_body_t = packed record
msgh_descriptor_count : mach_msg_size_t;
end;
const
MACH_MSG_BODY_NULL = nil;
MACH_MSG_DESCRIPTOR_NULL = nil;
type
mach_msg_header_t = packed record
msgh_bits : mach_msg_bits_t;
msgh_size : mach_msg_size_t;
msgh_remote_port : mach_port_t;
msgh_local_port : mach_port_t;
msgh_reserved : mach_msg_size_t;
msgh_id : mach_msg_id_t;
end;
pmach_msg_header_t = ^mach_msg_header_t;
const
MACH_MSG_NULL = nil;
type
mach_msg_base_t = packed record
header : mach_msg_header_t;
body : mach_msg_body_t;
end;
pmach_msg_base_t = ^mach_msg_base_t;
mach_msg_trailer_type_t = LongWord;
const
MACH_MSG_TRAILER_FORMAT_0 = 0;
type
mach_msg_trailer_size_t = LongWord;
mach_msg_trailer_t = packed record
msgh_trailer_type : mach_msg_trailer_type_t;
msgh_trailer_size : mach_msg_trailer_size_t;
end;
mach_msg_seqno_trailer_t = packed record
msgh_trailer_type : mach_msg_trailer_type_t;
msgh_trailer_size : mach_msg_trailer_size_t;
msgh_seqno : mach_port_seqno_t;
end;
security_token_t = packed record
val : array [0..1] of LongWord;
end;
mach_msg_security_trailer_t = packed record
msgh_trailer_type : mach_msg_trailer_type_t;
msgh_trailer_size : mach_msg_trailer_size_t;
msgh_seqno : mach_port_seqno_t;
msgh_sender : security_token_t;
end;
{*
* The audit token is an opaque token which identifies
* Mach tasks and senders of Mach messages as subjects
* to the BSM audit system. Only the appropriate BSM
* library routines should be used to interpret the
* contents of the audit token as the representation
* of the subject identity within the token may change
* over time.
*}
audit_token_t = packed record
val : array [0..7] of LongWord;
end;
mach_msg_audit_trailer_t = packed record
msgh_trailer_type : mach_msg_trailer_type_t;
msgh_trailer_size : mach_msg_trailer_size_t;
msgh_seqno : mach_port_seqno_t;
msgh_sender : security_token_t;
msgh_audit : audit_token_t;
end;
msg_labels_t = packed record
sender : mach_port_name_t;
end;
{* Trailer type to pass MAC policy label info as a mach message trailer. *}
mach_msg_mac_trailer_t = packed record
msgh_trailer_type : mach_msg_trailer_type_t;
msgh_trailer_size : mach_msg_trailer_size_t;
msgh_seqno : mach_port_seqno_t;
msgh_sender : security_token_t;
msgh_audit : audit_token_t;
msgh_labels : msg_labels_t;
msgh_ad : integer;
end;
const
MACH_MSG_TRAILER_MINIMUM_SIZE = sizeof(mach_msg_trailer_t);
{*
* These values can change from release to release - but clearly
* code cannot request additional trailer elements one was not
* compiled to understand. Therefore, it is safe to use this
* constant when the same module specified the receive options.
* Otherwise, you run the risk that the options requested by
* another module may exceed the local modules notion of
* MAX_TRAILER_SIZE.
*}
type
mach_msg_max_trailer_t = mach_msg_mac_trailer_t;
const
MAX_TRAILER_SIZE = sizeof(mach_msg_max_trailer_t);
{*
* Legacy requirements keep us from ever updating these defines (even
* when the format_0 trailers gain new option data fields in the future).
* Therefore, they shouldn't be used going forward. Instead, the sizes
* should be compared against the specific element size requested using
* REQUESTED_TRAILER_SIZE.
*}
type
mach_msg_format_0_trailer_t = mach_msg_security_trailer_t;
{*typedef mach_msg_mac_trailer_t mach_msg_format_0_trailer_t; *}
const
MACH_MSG_TRAILER_FORMAT_0_SIZE = sizeof(mach_msg_format_0_trailer_t);
(*
#define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} }
extern security_token_t KERNEL_SECURITY_TOKEN;
#define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} }
extern audit_token_t KERNEL_AUDIT_TOKEN;
*)
type
mach_msg_options_t = integer_t;
mach_msg_empty_send_t = packed record
header : mach_msg_header_t;
end;
mach_msg_empty_rcv_t = packed record
header : mach_msg_header_t;
trailer : mach_msg_trailer_t;
end;
mach_msg_empty_t = packed record
case byte of
0: (send : mach_msg_empty_send_t);
1: (rcv: mach_msg_empty_rcv_t);
end;
//#pragma pack()
{* utility to round the message size - will become machine dependent *}
//#define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
// ~(sizeof (natural_t) - 1))
{*
* There is no fixed upper bound to the size of Mach messages.
*}
//#define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)