xref: /llvm-project-15.0.7/libc/spec/posix.td (revision 643dfd97)
1def SigSetType : NamedType<"sigset_t">;
2def SigSetPtrType : PtrType<SigSetType>;
3def ConstSigSetPtrType : ConstType<SigSetPtrType>;
4def RestrictedSigSetType : RestrictedPtrType<SigSetType>;
5def ConstRestrictedSigSetType : ConstType<RestrictedSigSetType>;
6
7def StructSigaction : NamedType<"struct sigaction">;
8def StructSigactionPtr : PtrType<StructSigaction>;
9def ConstStructSigactionPtr : ConstType<StructSigactionPtr>;
10def RestrictedStructSigactionPtr : RestrictedPtrType<StructSigaction>;
11def ConstRestrictedStructSigactionPtr : ConstType<RestrictedStructSigactionPtr>;
12
13def PThreadStartT : NamedType<"__pthread_start_t">;
14
15def POSIX : StandardSpec<"POSIX"> {
16  PtrType CharPtr = PtrType<CharType>;
17  RestrictedPtrType RestrictedCharPtr = RestrictedPtrType<CharType>;
18  RestrictedPtrType CharRestrictedDoublePtr = RestrictedPtrType<CharPtr>;
19  ConstType ConstCharPtr = ConstType<CharPtr>;
20  ConstType ConstRestrictedCharPtr = ConstType<RestrictedCharPtr>;
21
22  NamedType ModeTType = NamedType<"mode_t">;
23  NamedType OffTType = NamedType<"off_t">;
24  NamedType SSizeTType = NamedType<"ssize_t">;
25
26  NamedType PThreadAttrTType = NamedType<"pthread_attr_t">;
27  PtrType PThreadAttrTPtr = PtrType<PThreadAttrTType>;
28  RestrictedPtrType RestrictedPThreadAttrTPtr = RestrictedPtrType<PThreadAttrTType>;
29  ConstType ConstPThreadAttrTPtr = ConstType<PThreadAttrTPtr>;
30  ConstType ConstRestrictedPThreadAttrTPtr = ConstType<RestrictedPThreadAttrTPtr>;
31
32  NamedType PThreadMutexAttrTType = NamedType<"pthread_mutexattr_t">;
33  PtrType PThreadMutexAttrTPtr = PtrType<PThreadMutexAttrTType>;
34  RestrictedPtrType RestrictedPThreadMutexAttrTPtr = RestrictedPtrType<PThreadMutexAttrTType>;
35  ConstType ConstPThreadMutexAttrTPtr = ConstType<PThreadMutexAttrTPtr>;
36  ConstType ConstRestrictedPThreadMutexAttrTPtr = ConstType<RestrictedPThreadMutexAttrTPtr>;
37
38  NamedType PThreadMutexTType = NamedType<"pthread_mutex_t">;
39  PtrType PThreadMutexTPtr = PtrType<PThreadMutexTType>;
40  RestrictedPtrType RestrictedPThreadMutexTPtr = RestrictedPtrType<PThreadMutexTType>;
41  ConstType ConstPThreadMutexTPtr = ConstType<PThreadMutexTPtr>;
42  ConstType ConstRestrictedPThreadMutexTPtr = ConstType<RestrictedPThreadMutexTPtr>;
43
44  NamedType PThreadTType = NamedType<"pthread_t">;
45  PtrType PThreadTPtr = PtrType<PThreadTType>;
46  RestrictedPtrType RestrictedPThreadTPtr = RestrictedPtrType<PThreadTType>;
47
48  HeaderSpec Errno = HeaderSpec<
49      "errno.h",
50      [
51        Macro<"E2BIG">,
52        Macro<"EACCES">,
53        Macro<"EADDRINUSE">,
54        Macro<"EADDRNOTAVAIL">,
55        Macro<"EAFNOSUPPORT">,
56        Macro<"EAGAIN">,
57        Macro<"EALREADY">,
58        Macro<"EBADF">,
59        Macro<"EBADMSG">,
60        Macro<"EBUSY">,
61        Macro<"ECANCELED">,
62        Macro<"ECHILD">,
63        Macro<"ECONNABORTED">,
64        Macro<"ECONNREFUSED">,
65        Macro<"ECONNRESET">,
66        Macro<"EDEADLK">,
67        Macro<"EDESTADDRREQ">,
68        Macro<"EDQUOT">,
69        Macro<"EEXIST">,
70        Macro<"EFAULT">,
71        Macro<"EFBIG">,
72        Macro<"EHOSTUNREACH">,
73        Macro<"EIDRM">,
74        Macro<"EINPROGRESS">,
75        Macro<"EINTR">,
76        Macro<"EINVAL">,
77        Macro<"EIO">,
78        Macro<"EISCONN">,
79        Macro<"EISDIR">,
80        Macro<"ELOOP">,
81        Macro<"EMFILE">,
82        Macro<"EMLINK">,
83        Macro<"EMSGSIZE">,
84        Macro<"EMULTIHOP">,
85        Macro<"ENAMETOOLONG">,
86        Macro<"ENETDOWN">,
87        Macro<"ENETRESET">,
88        Macro<"ENETUNREACH">,
89        Macro<"ENFILE">,
90        Macro<"ENOBUFS">,
91        Macro<"ENODATA">,
92        Macro<"ENODEV">,
93        Macro<"ENOENT">,
94        Macro<"ENOEXEC">,
95        Macro<"ENOLCK">,
96        Macro<"ENOLINK">,
97        Macro<"ENOMEM">,
98        Macro<"ENOMSG">,
99        Macro<"ENOPROTOOPT">,
100        Macro<"ENOSPC">,
101        Macro<"ENOSR">,
102        Macro<"ENOSTR">,
103        Macro<"ENOSYS">,
104        Macro<"ENOTCONN">,
105        Macro<"ENOTDIR">,
106        Macro<"ENOTEMPTY">,
107        Macro<"ENOTRECOVERABLE">,
108        Macro<"ENOTSOCK">,
109        Macro<"ENOTSUP">,
110        Macro<"ENOTTY">,
111        Macro<"ENXIO">,
112        Macro<"EOPNOTSUPP">,
113        Macro<"EOVERFLOW">,
114        Macro<"EOWNERDEAD">,
115        Macro<"EPERM">,
116        Macro<"EPIPE">,
117        Macro<"EPROTO">,
118        Macro<"EPROTONOSUPPORT">,
119        Macro<"EPROTOTYPE">,
120        Macro<"EROFS">,
121        Macro<"ESPIPE">,
122        Macro<"ESRCH">,
123        Macro<"ESTALE">,
124        Macro<"ETIME">,
125        Macro<"ETIMEDOUT">,
126        Macro<"ETXTBSY">,
127        Macro<"EWOULDBLOCK">,
128        Macro<"EXDEV">,
129      ],
130      [], // Types
131      [], // Enumerations
132      []  // Functions
133  >;
134
135  HeaderSpec FCntl = HeaderSpec<
136    "fcntl.h",
137    [], // Macros
138    [ModeTType],
139    [], // Enumerations
140    [
141      FunctionSpec<
142          "creat",
143          RetValSpec<IntType>,
144          [ArgSpec<ConstCharPtr>, ArgSpec<ModeTType>]
145      >,
146      FunctionSpec<
147          "open",
148          RetValSpec<IntType>,
149          [ArgSpec<ConstCharPtr>, ArgSpec<IntType>, ArgSpec<VarArgType>]
150      >,
151      FunctionSpec<
152          "openat",
153          RetValSpec<IntType>,
154          [ArgSpec<IntType>, ArgSpec<ConstCharPtr>, ArgSpec<IntType>, ArgSpec<VarArgType>]
155      >,
156    ]
157  >;
158
159  HeaderSpec SysMMan = HeaderSpec<
160      "sys/mman.h",
161      [
162        // TODO: Add a facility to bunch macros into bitwise-or-able groups.
163        // POSIX requires it, so such thing should be captured in this spec.
164        Macro<"PROT_EXEC">,
165        Macro<"PROT_NONE">,
166        Macro<"PROT_READ">,
167        Macro<"PROT_WRITE">,
168
169        Macro<"MAP_FIXED">,
170        Macro<"MAP_PRIVATE">,
171        Macro<"MAP_SHARED">,
172
173        Macro<"MAP_FAILED">,
174      ],
175      [
176        SizeTType,
177        OffTType,
178      ],
179      [], // Enumerations
180      [
181        FunctionSpec<
182            "mmap",
183            RetValSpec<VoidPtr>,
184            [ArgSpec<VoidPtr>,
185             ArgSpec<SizeTType>,
186             ArgSpec<IntType>,
187             ArgSpec<IntType>,
188             ArgSpec<IntType>,
189             ArgSpec<OffTType>]
190        >,
191        FunctionSpec<
192            "munmap",
193            RetValSpec<IntType>,
194            [ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
195        >,
196      ]
197  >;
198
199  HeaderSpec Signal = HeaderSpec<
200      "signal.h",
201      [], // Macros
202      [
203        SigSetType,
204        StructSigaction,
205      ],
206      [], // Enumerations
207      [
208        FunctionSpec<
209          "sigaction",
210          RetValSpec<IntType>,
211          [ArgSpec<IntType>,
212           ArgSpec<ConstRestrictedStructSigactionPtr>,
213           ArgSpec<RestrictedStructSigactionPtr>]
214        >,
215        FunctionSpec<
216          "sigdelset",
217          RetValSpec<IntType>,
218          [ArgSpec<SigSetPtrType>,
219           ArgSpec<IntType>]
220        >,
221        FunctionSpec<
222          "sigprocmask",
223          RetValSpec<IntType>,
224          [ArgSpec<IntType>, ArgSpec<ConstRestrictedSigSetType>, ArgSpec<RestrictedSigSetType>]
225        >,
226        FunctionSpec<
227          "sigemptyset",
228          RetValSpec<IntType>,
229          [ArgSpec<SigSetPtrType>]
230        >,
231        FunctionSpec<
232          "sigaddset",
233          RetValSpec<IntType>,
234          [ArgSpec<SigSetPtrType>,
235           ArgSpec<IntType>]
236        >,
237        FunctionSpec<
238          "sigfillset",
239          RetValSpec<IntType>,
240          [ArgSpec<SigSetPtrType>]
241        >,
242      ]
243  >;
244
245  HeaderSpec UniStd = HeaderSpec<
246    "unistd.h",
247    [], // Macros
248    [
249      OffTType,
250      SSizeTType,
251      SizeTType,
252    ],
253    [], // Enumerations
254    [
255        FunctionSpec<
256          "close",
257          RetValSpec<IntType>,
258          [ArgSpec<IntType>]
259        >,
260        FunctionSpec<
261          "fsync",
262          RetValSpec<IntType>,
263          [ArgSpec<IntType>]
264        >,
265        FunctionSpec<
266          "lseek",
267          RetValSpec<OffTType>,
268          [ArgSpec<IntType>, ArgSpec<OffTType>, ArgSpec<IntType>]
269        >,
270        FunctionSpec<
271          "read",
272          RetValSpec<SSizeTType>,
273          [ArgSpec<IntType>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
274        >,
275        FunctionSpec<
276          "rmdir",
277          RetValSpec<IntType>,
278          [ArgSpec<ConstCharPtr>]
279        >,
280        FunctionSpec<
281          "unlink",
282          RetValSpec<IntType>,
283          [ArgSpec<ConstCharPtr>]
284        >,
285        FunctionSpec<
286          "unlinkat",
287          RetValSpec<IntType>,
288          [ArgSpec<IntType>, ArgSpec<ConstCharPtr>, ArgSpec<IntType>]
289        >,
290        FunctionSpec<
291          "write",
292          RetValSpec<SSizeTType>,
293          [ArgSpec<IntType>, ArgSpec<ConstVoidPtr>, ArgSpec<SizeTType>]
294        >,
295    ]
296  >;
297
298  HeaderSpec StdLib = HeaderSpec<
299    "stdlib.h",
300    [], // Macros
301    [], // Types
302    [], // Enumerations
303    [
304        FunctionSpec<
305          "getenv",
306          RetValSpec<CharPtr>,
307          [ArgSpec<ConstCharPtr>]
308        >,
309    ]
310  >;
311
312  HeaderSpec String = HeaderSpec<
313    "string.h",
314    [
315        Macro<"NULL">,
316    ],
317    [
318        SizeTType,
319    ],
320    [], // Enumerations
321    [
322        FunctionSpec<
323            "memccpy",
324            RetValSpec<VoidPtr>,
325            [ArgSpec<VoidRestrictedPtr>,
326             ArgSpec<ConstVoidRestrictedPtr>,
327             ArgSpec<IntType>,
328             ArgSpec<SizeTType>]
329        >,
330        FunctionSpec<
331            "mempcpy",
332            RetValSpec<VoidPtr>,
333            [ArgSpec<VoidRestrictedPtr>,
334             ArgSpec<ConstVoidRestrictedPtr>,
335             ArgSpec<SizeTType>]
336        >,
337        FunctionSpec<
338            "stpcpy",
339            RetValSpec<CharPtr>,
340            [ArgSpec<RestrictedCharPtr>,
341             ArgSpec<ConstRestrictedCharPtr>]
342        >,
343        FunctionSpec<
344            "stpncpy",
345            RetValSpec<CharPtr>,
346            [ArgSpec<RestrictedCharPtr>,
347             ArgSpec<ConstRestrictedCharPtr>,
348             ArgSpec<SizeTType>]
349        >,
350        FunctionSpec<
351            "strnlen",
352             RetValSpec<SizeTType>,
353             [ArgSpec<ConstCharPtr>, ArgSpec<SizeTType>]
354        >,
355        FunctionSpec<
356            "strtok_r",
357            RetValSpec<CharPtr>,
358            [ArgSpec<RestrictedCharPtr>,
359             ArgSpec<ConstRestrictedCharPtr>,
360             ArgSpec<CharRestrictedDoublePtr>]
361        >,
362    ]
363  >;
364
365  HeaderSpec CType = HeaderSpec<
366    "ctype.h",
367    [], // Macros
368    [], // Types
369    [], // Enumerations
370    [
371        FunctionSpec<
372            "isascii",
373            RetValSpec<IntType>,
374            [ArgSpec<IntType>]
375        >,
376    ]
377  >;
378
379  HeaderSpec SysStat = HeaderSpec<
380    "sys/stat.h",
381    [], // Macros
382    [ModeTType], // Types
383    [], // Enumerations
384    [
385        FunctionSpec<
386            "mkdir",
387            RetValSpec<IntType>,
388            [ArgSpec<ConstCharPtr>, ArgSpec<ModeTType>]
389        >,
390        FunctionSpec<
391            "mkdirat",
392            RetValSpec<IntType>,
393            [ArgSpec<IntType>, ArgSpec<ConstCharPtr>, ArgSpec<ModeTType>]
394        >,
395    ]
396  >;
397
398  HeaderSpec PThread = HeaderSpec<
399    "pthread.h",
400    [], // Macros
401    [PThreadAttrTType, PThreadMutexAttrTType, PThreadMutexTType, PThreadStartT, PThreadTType], // Types
402    [], // Enumerations
403    [
404      FunctionSpec<
405          "pthread_attr_init",
406          RetValSpec<IntType>,
407          [ArgSpec<PThreadAttrTPtr>]
408      >,
409      FunctionSpec<
410          "pthread_attr_destroy",
411          RetValSpec<IntType>,
412          [ArgSpec<PThreadAttrTPtr>]
413      >,
414      FunctionSpec<
415          "pthread_attr_getdetachstate",
416          RetValSpec<IntType>,
417          [ArgSpec<ConstPThreadAttrTPtr>, ArgSpec<IntPtr>]
418      >,
419      FunctionSpec<
420          "pthread_attr_setdetachstate",
421          RetValSpec<IntType>,
422          [ArgSpec<PThreadAttrTPtr>, ArgSpec<IntType>]
423      >,
424      FunctionSpec<
425          "pthread_attr_getguardsize",
426          RetValSpec<IntType>,
427          [ArgSpec<ConstRestrictedPThreadAttrTPtr>, ArgSpec<RestrictedSizeTPtr>]
428      >,
429      FunctionSpec<
430          "pthread_attr_setguardsize",
431          RetValSpec<IntType>,
432          [ArgSpec<PThreadAttrTPtr>, ArgSpec<SizeTType>]
433      >,
434      FunctionSpec<
435          "pthread_attr_getstacksize",
436          RetValSpec<IntType>,
437          [ArgSpec<ConstRestrictedPThreadAttrTPtr>, ArgSpec<RestrictedSizeTPtr>]
438      >,
439      FunctionSpec<
440          "pthread_attr_setstacksize",
441          RetValSpec<IntType>,
442          [ArgSpec<PThreadAttrTPtr>, ArgSpec<SizeTType>]
443      >,
444      FunctionSpec<
445          "pthread_attr_getstack",
446          RetValSpec<IntType>,
447          [ArgSpec<ConstRestrictedPThreadAttrTPtr>, ArgSpec<RestrictedVoidPtrPtr>, ArgSpec<RestrictedSizeTPtr>]
448      >,
449      FunctionSpec<
450          "pthread_attr_setstack",
451          RetValSpec<IntType>,
452          [ArgSpec<PThreadAttrTPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
453      >,
454      FunctionSpec<
455          "pthread_create",
456          RetValSpec<IntType>,
457          [ArgSpec<RestrictedPThreadTPtr>, ArgSpec<ConstRestrictedPThreadAttrTPtr>, ArgSpec<PThreadStartT>, ArgSpec<VoidPtr>]
458      >,
459      FunctionSpec<
460          "pthread_join",
461          RetValSpec<IntType>,
462          [ArgSpec<PThreadTType>, ArgSpec<VoidPtrPtr>]
463      >,
464      FunctionSpec<
465          "pthread_detach",
466          RetValSpec<IntType>,
467          [ArgSpec<PThreadTType>]
468      >,
469      FunctionSpec<
470          "pthread_self",
471          RetValSpec<PThreadTType>,
472          [ArgSpec<VoidType>]
473      >,
474      FunctionSpec<
475          "pthread_equal",
476          RetValSpec<IntType>,
477          [ArgSpec<PThreadTType>, ArgSpec<PThreadTType>]
478      >,
479      FunctionSpec<
480          "pthread_mutexattr_init",
481          RetValSpec<IntType>,
482          [ArgSpec<PThreadMutexAttrTPtr>]
483      >,
484      FunctionSpec<
485          "pthread_mutexattr_destroy",
486          RetValSpec<IntType>,
487          [ArgSpec<PThreadMutexAttrTPtr>]
488      >,
489      FunctionSpec<
490          "pthread_mutexattr_gettype",
491          RetValSpec<IntType>,
492          [ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>, ArgSpec<RestrictedIntPtr>]
493      >,
494      FunctionSpec<
495          "pthread_mutexattr_settype",
496          RetValSpec<IntType>,
497          [ArgSpec<RestrictedPThreadMutexAttrTPtr>, ArgSpec<IntType>]
498      >,
499      FunctionSpec<
500          "pthread_mutexattr_getrobust",
501          RetValSpec<IntType>,
502          [ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>, ArgSpec<RestrictedIntPtr>]
503      >,
504      FunctionSpec<
505          "pthread_mutexattr_setrobust",
506          RetValSpec<IntType>,
507          [ArgSpec<RestrictedPThreadMutexAttrTPtr>, ArgSpec<IntType>]
508      >,
509      FunctionSpec<
510          "pthread_mutexattr_getpshared",
511          RetValSpec<IntType>,
512          [ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>, ArgSpec<RestrictedIntPtr>]
513      >,
514      FunctionSpec<
515          "pthread_mutexattr_setpshared",
516          RetValSpec<IntType>,
517          [ArgSpec<RestrictedPThreadMutexAttrTPtr>, ArgSpec<IntType>]
518      >,
519      FunctionSpec<
520          "pthread_mutexattr_getprotocol",
521          RetValSpec<IntType>,
522          [ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>, ArgSpec<RestrictedIntPtr>]
523      >,
524      FunctionSpec<
525          "pthread_mutexattr_setprotocol",
526          RetValSpec<IntType>,
527          [ArgSpec<RestrictedPThreadMutexAttrTPtr>, ArgSpec<IntType>]
528      >,
529      FunctionSpec<
530          "pthread_mutexattr_getprioceiling",
531          RetValSpec<IntType>,
532          [ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>, ArgSpec<RestrictedIntPtr>]
533      >,
534      FunctionSpec<
535          "pthread_mutexattr_setprioceiling",
536          RetValSpec<IntType>,
537          [ArgSpec<RestrictedPThreadMutexAttrTPtr>, ArgSpec<IntType>]
538      >,
539      FunctionSpec<
540          "pthread_mutex_init",
541          RetValSpec<IntType>,
542          [ArgSpec<RestrictedPThreadMutexTPtr>, ArgSpec<ConstRestrictedPThreadMutexAttrTPtr>]
543      >,
544      FunctionSpec<
545          "pthread_mutex_destroy",
546          RetValSpec<IntType>,
547          [ArgSpec<PThreadMutexTPtr>]
548      >,
549      FunctionSpec<
550          "pthread_mutex_lock",
551          RetValSpec<IntType>,
552          [ArgSpec<PThreadMutexTPtr>]
553      >,
554      FunctionSpec<
555          "pthread_mutex_unlock",
556          RetValSpec<IntType>,
557          [ArgSpec<PThreadMutexTPtr>]
558      >,
559    ]
560  >;
561
562  HeaderSpec StdIO = HeaderSpec<
563      "stdio.h",
564      [], // Macros
565      [], // Types
566      [], // Enumerations
567      [
568          FunctionSpec<
569              "flockfile",
570              RetValSpec<VoidType>,
571              [ArgSpec<FILEPtr>]
572          >,
573          FunctionSpec<
574              "funlockfile",
575              RetValSpec<VoidType>,
576              [ArgSpec<FILEPtr>]
577          >,
578      ]
579  >;
580
581  let Headers = [
582    CType,
583    Errno,
584    FCntl,
585    PThread,
586    Signal,
587    StdIO,
588    StdLib,
589    SysMMan,
590    SysStat,
591    UniStd,
592    String
593  ];
594}
595