1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
3 ;;; --- Foreign type definitions for *NIX systems.
6 (in-package :iolib.syscalls
)
8 ;;; FIXME: Find a way to use pkg-config to get these flags
9 ;;; instead of hard-coding them
12 (define "_GNU_SOURCE")
13 (define "_LARGEFILE_SOURCE")
14 (define "_LARGEFILE64_SOURCE")
15 (define "_FILE_OFFSET_BITS" 64))
19 (include "sys/poll.h" ;; FIXME: add poll() to LFP
20 "sys/ioctl.h" "sys/utsname.h"
24 (include "sys/epoll.h" "sys/syscall.h")
27 (include "sys/event.h" "sys/time.h") ; for kqueue
31 ;;;-------------------------------------------------------------------------
32 ;;; Simple POSIX types
33 ;;;-------------------------------------------------------------------------
36 (ctype size-t
"size_t")
37 (ctype ssize-t
"ssize_t")
38 (ctype intptr-t
"intptr_t")
39 (ctype uintptr-t
"uintptr_t")
44 (ctype mode-t
"mode_t")
45 (ctype time-t
"time_t")
46 (ctype useconds-t
"useconds_t")
47 (ctype suseconds-t
"suseconds_t")
50 (ctype nlink-t
"nlink_t")
51 (ctype blksize-t
"blksize_t")
52 (ctype blkcnt-t
"blkcnt_t")
53 (ctype nfds-t
"nfds_t")
54 (ctype rlim-t
"rlim_t")
56 (ctype clockid-t
"clockid_t")
59 ;;;-------------------------------------------------------------------------
60 ;;; Structs, slots and C constants
61 ;;;-------------------------------------------------------------------------
65 (constantenum (errno-values :define-constants t
)
68 (:eaddrinuse
"EADDRINUSE")
69 (:eaddrnotavail
"EADDRNOTAVAIL")
70 (:eafnosupport
"EAFNOSUPPORT")
71 (:ealready
"EALREADY")
75 (:ecanceled
"ECANCELED")
77 (:econnaborted
"ECONNABORTED")
78 (:econnrefused
"ECONNREFUSED")
79 (:econnreset
"ECONNRESET")
81 (:edestaddrreq
"EDESTADDRREQ")
87 (:ehostdown
"EHOSTDOWN")
88 (:ehostunreach
"EHOSTUNREACH")
91 (:einprogress
"EINPROGRESS")
100 (:emsgsize
"EMSGSIZE")
101 (:emultihop
"EMULTIHOP")
102 (:enametoolong
"ENAMETOOLONG")
103 (:enetdown
"ENETDOWN")
104 (:enetreset
"ENETRESET")
105 (:enetunreach
"ENETUNREACH")
116 (:enonet
"ENONET" :optional t
)
117 (:enoprotoopt
"ENOPROTOOPT")
122 (:enotconn
"ENOTCONN")
124 (:enotempty
"ENOTEMPTY")
125 (:enotsock
"ENOTSOCK")
129 (:eopnotsupp
"EOPNOTSUPP")
130 (:eoverflow
"EOVERFLOW")
134 (:eprotonosupport
"EPROTONOSUPPORT")
135 (:eprototype
"EPROTOTYPE")
138 (:eshutdown
"ESHUTDOWN")
143 (:etimedout
"ETIMEDOUT")
145 (:ewouldblock
"EWOULDBLOCK")
154 (constant (o-rdonly "O_RDONLY"))
155 (constant (o-wronly "O_WRONLY"))
156 (constant (o-rdwr "O_RDWR"))
157 (constant (o-creat "O_CREAT"))
158 (constant (o-excl "O_EXCL"))
159 (constant (o-trunc "O_TRUNC"))
160 (constant (o-append "O_APPEND"))
162 (constant (o-noctty "O_NOCTTY"))
163 (constant (o-nonblock "O_NONBLOCK"))
164 (constant (o-ndelay "O_NDELAY"))
165 (constant (o-sync "O_SYNC"))
166 (constant (o-nofollow "O_NOFOLLOW"))
167 (constant (o-async "O_ASYNC"))
168 (constant (o-cloexec "O_CLOEXEC"))
172 (constant (f-dupfd "F_DUPFD"))
173 (constant (f-getfd "F_GETFD"))
174 (constant (f-setfd "F_SETFD"))
175 (constant (f-getfl "F_GETFL"))
176 (constant (f-setfl "F_SETFL"))
177 (constant (f-getlk "F_GETLK"))
178 (constant (f-setlk "F_SETLK"))
179 (constant (f-setlkw "F_SETLKW"))
180 (constant (f-getown "F_GETOWN"))
181 (constant (f-setown "F_SETOWN"))
182 (constant (f-rdlck "F_RDLCK"))
183 (constant (f-wrlck "F_WRLCK"))
184 (constant (f-unlck "F_UNLCK"))
187 (constant (f-getsig "F_GETSIG"))
188 (constant (f-setsig "F_SETSIG"))
189 (constant (f-setlease "F_SETLEASE"))
190 (constant (f-getlease "F_GETLEASE")))
197 (constant (seek-set "SEEK_SET"))
198 (constant (seek-cur "SEEK_CUR"))
199 (constant (seek-end "SEEK_END"))
203 (constant (r-ok "R_OK"))
204 (constant (w-ok "W_OK"))
205 (constant (x-ok "X_OK"))
206 (constant (f-ok "F_OK"))
211 (constant (clock-realtime "CLOCK_REALTIME"))
212 (constant (clock-monotonic "CLOCK_MONOTONIC"))
214 (cstruct timespec
"struct timespec"
215 "UNIX time specification in seconds and nanoseconds."
216 (sec "tv_sec" :type time-t
)
217 (nsec "tv_nsec" :type
:long
))
222 (constant (path-max "PATH_MAX" "MAXPATHLEN"))
224 (cstruct stat
"struct stat"
225 (dev "st_dev" :type dev-t
)
226 (ino "st_ino" :type ino-t
)
227 (mode "st_mode" :type mode-t
)
228 (nlink "st_nlink" :type nlink-t
)
229 (uid "st_uid" :type uid-t
)
230 (gid "st_gid" :type gid-t
)
231 (rdev "st_rdev" :type dev-t
)
232 (size "st_size" :type off-t
)
233 (blksize "st_blksize" :type blkcnt-t
)
234 (blocks "st_blocks" :type blksize-t
)
235 (atime "st_atime" :type time-t
)
236 (mtime "st_mtime" :type time-t
)
237 (ctime "st_ctime" :type time-t
))
239 (constant (s-irwxu "S_IRWXU"))
240 (constant (s-irusr "S_IRUSR"))
241 (constant (s-iwusr "S_IWUSR"))
242 (constant (s-ixusr "S_IXUSR"))
243 (constant (s-ifmt "S_IFMT"))
244 (constant (s-ififo "S_IFIFO"))
245 (constant (s-ifchr "S_IFCHR"))
246 (constant (s-ifdir "S_IFDIR"))
247 (constant (s-ifblk "S_IFBLK"))
248 (constant (s-ifreg "S_IFREG"))
249 (constant (s-ifwht "S_IFWHT") :optional t
)
250 (constant (s-iread "S_IREAD"))
251 (constant (s-iwrite "S_IWRITE"))
252 (constant (s-iexec "S_IEXEC"))
254 (constant (s-irwxg "S_IRWXG"))
255 (constant (s-irgrp "S_IRGRP"))
256 (constant (s-iwgrp "S_IWGRP"))
257 (constant (s-ixgrp "S_IXGRP"))
258 (constant (s-irwxo "S_IRWXO"))
259 (constant (s-iroth "S_IROTH"))
260 (constant (s-iwoth "S_IWOTH"))
261 (constant (s-ixoth "S_IXOTH"))
262 (constant (s-isuid "S_ISUID"))
263 (constant (s-isgid "S_ISGID"))
264 (constant (s-isvtx "S_ISVTX"))
265 (constant (s-iflnk "S_IFLNK"))
266 (constant (s-ifsock "S_IFSOCK"))
273 (constant (fionbio "FIONBIO"))
274 (constant (fionread "FIONREAD"))
279 (constant (wnohang "WNOHANG"))
280 (constant (wuntraced "WUNTRACED"))
281 (constant (wcontinued "WCONTINUED"))
284 ;;;-------------------------------------------------------------------------
286 ;;;-------------------------------------------------------------------------
289 (constantenum (signal :define-constants t
)
311 (:sigpoll
"SIGPOLL" :optional t
)
316 (:sigvtalrm
"SIGVTALRM")
320 (:sigemt
"SIGEMT" :optional t
)
322 (:sigcld
"SIGCLD" :optional t
)
323 (:sigpwr
"SIGPWR" :optional t
)
324 (:siginfo
"SIGINFO" :optional t
)
325 (:siglost
"SIGLOST" :optional t
)
326 (:sigwinch
"SIGWINCH"))
328 (constant (sig-ign "SIG_IGN"))
329 (constant (sig-dfl "SIG_DFL"))
331 (cstruct sigaction
"struct sigaction"
332 (handler "sa_handler" :type
:pointer
)
333 (sigaction "sa_sigaction" :type
:pointer
)
334 ;; actual type can be structure or array...
335 (mask "sa_mask" :type
:unsigned-long
)
336 (flags "sa_flags" :type
:int
))
338 (constant (sa-nocldstop "SA_NOCLDSTOP"))
339 (constant (sa-nocldwait "SA_NOCLDWAIT"))
340 (constant (sa-nodefer "SA_NODEFER"))
341 (constant (sa-onstack "SA_ONSTACK"))
342 (constant (sa-resethand "SA_RESETHAND"))
343 (constant (sa-restart "SA_RESTART"))
344 (constant (sa-siginfo "SA_SIGINFO"))
351 (constant (prot-none "PROT_NONE"))
352 (constant (prot-read "PROT_READ"))
353 (constant (prot-write "PROT_WRITE"))
354 (constant (prot-exec "PROT_EXEC"))
355 (constant (map-shared "MAP_SHARED"))
356 (constant (map-private "MAP_PRIVATE"))
357 (constant (map-fixed "MAP_FIXED"))
358 (constant (map-failed "MAP_FAILED"))
363 (cstruct fd-set
"fd_set")
364 (constant (fd-setsize "FD_SETSIZE"))
366 (cstruct timeval
"struct timeval"
367 "UNIX time specification in seconds and microseconds."
368 (sec "tv_sec" :type time-t
)
369 (usec "tv_usec" :type suseconds-t
))
376 (cstruct pollfd
"struct pollfd"
377 "Poll file descriptor activity specification structure."
379 (events "events" :type
:short
)
380 (revents "revents" :type
:short
))
382 (constant (pollin "POLLIN"))
383 (constant (pollrdnorm "POLLRDNORM"))
384 (constant (pollrdband "POLLRDBAND"))
385 (constant (pollpri "POLLPRI"))
386 (constant (pollout "POLLOUT"))
387 (constant (pollwrnorm "POLLWRNORM"))
388 (constant (pollwrband "POLLWRBAND"))
389 (constant (pollerr "POLLERR"))
390 #+linux
(constant (pollrdhup "POLLRDHUP"))
391 (constant (pollhup "POLLHUP"))
392 (constant (pollnval "POLLNVAL"))
397 ;; Apparently POSIX 1003.1-2001 (according to linux manpages) only
398 ;; requires d_name. Sigh. I guess we should assemble some decent
399 ;; wrapper functions. No, struct members can't be optional at this
401 (cstruct dirent
"struct dirent"
402 ;; POSIX actually requires this to be d_ino
403 (fileno "d_fileno" :type
#-freebsd ino-t
#+freebsd
:uint32
)
404 (type "d_type" :type
:uint8
)
405 (name "d_name" :type
:uint8
:count
:auto
))
407 ;;; filetypes set in d_type slot of struct dirent
408 (constant (dt-unknown "DT_UNKNOWN"))
409 (constant (dt-fifo "DT_FIFO"))
410 (constant (dt-chr "DT_CHR"))
411 (constant (dt-dir "DT_DIR"))
412 (constant (dt-blk "DT_BLK"))
413 (constant (dt-reg "DT_REG"))
414 (constant (dt-lnk "DT_LNK"))
415 (constant (dt-sock "DT_SOCK"))
416 (constant (dt-wht "DT_WHT"))
419 ;;;-------------------------------------------------------------------------
421 ;;;-------------------------------------------------------------------------
423 (cstruct rlimit
"struct rlimit"
424 (cur "rlim_cur" :type rlim-t
)
425 (max "rlim_max" :type rlim-t
))
427 (cstruct rusage
"struct rusage"
428 (utime "ru_utime" :type timeval
)
429 (stime "ru_stime" :type timeval
)
430 (maxrss "ru_maxrss" :type
:long
)
431 (ixrss "ru_ixrss" :type
:long
)
432 (idrss "ru_idrss" :type
:long
)
433 (isrss "ru_isrss" :type
:long
)
434 (minflt "ru_minflt" :type
:long
)
435 (majflt "ru_majflt" :type
:long
)
436 (nswap "ru_nswap" :type
:long
)
437 (inblock "ru_inblock" :type
:long
)
438 (oublock "ru_oublock" :type
:long
)
439 (msgsnd "ru_msgsnd" :type
:long
)
440 (msgrcv "ru_msgrcv" :type
:long
)
441 (nsignals "ru_nsignals" :type
:long
)
442 (nvcsw "ru_nvcsw" :type
:long
)
443 (nivcsw "ru_nivcsw" :type
:long
))
445 (constant (prio-process "PRIO_PROCESS"))
446 (constant (prio-pgrp "PRIO_PGRP"))
447 (constant (prio-user "PRIO_USER"))
448 (constant (rlim-infinity "RLIM_INFINITY"))
449 (constant (rusage-self "RUSAGE_SELF"))
450 (constant (rusage-children "RUSAGE_CHILDREN"))
451 (constant (rlimit-as "RLIMIT_AS"))
452 (constant (rlimit-core "RLIMIT_CORE"))
453 (constant (rlimit-cpu "RLIMIT_CPU"))
454 (constant (rlimit-data "RLIMIT_DATA"))
455 (constant (rlimit-fsize "RLIMIT_FSIZE"))
456 (constant (rlimit-memlock "RLIMIT_MEMLOCK"))
457 (constant (rlimit-nofile "RLIMIT_NOFILE"))
458 (constant (rlimit-nproc "RLIMIT_NPROC"))
459 (constant (rlimit-rss "RLIMIT_RSS"))
460 (constant (rlimit-stack "RLIMIT_STACK"))
464 (constant (rlim-saved-max "RLIM_SAVED_MAX"))
465 (constant (rlim-saved-cur "RLIM_SAVED_CUR"))
466 (constant (rlimit-locks "RLIMIT_LOCKS"))
467 (constant (rlimit-msgqueue "RLIMIT_MSGQUEUE"))
468 (constant (rlimit-nlimits "RLIMIT_NLIMITS"))
469 (constant (rlimit-nice "RLIMIT_NICE"))
470 (constant (rlimit-rtprio "RLIMIT_RTPRIO"))
471 (constant (rlimit-sigpending "RLIMIT_SIGPENDING")))
474 (constant (rlimit-sbsize "RLIMIT_SBSIZE"))
477 ;;;-------------------------------------------------------------------------
479 ;;;-------------------------------------------------------------------------
481 (cstruct utsname
"struct utsname"
482 (sysname "sysname" :type
:char
)
483 (nodename "nodename" :type
:char
)
484 (release "release" :type
:char
)
485 (version "version" :type
:char
)
486 (machine "machine" :type
:char
))
489 ;;;-------------------------------------------------------------------------
491 ;;;-------------------------------------------------------------------------
493 (cstruct passwd
"struct passwd"
494 (name "pw_name" :type
:string
)
495 (passwd "pw_passwd" :type
:string
)
496 (uid "pw_uid" :type uid-t
)
497 (gid "pw_gid" :type gid-t
)
498 (gecos "pw_gecos" :type
:string
)
499 (dir "pw_dir" :type
:string
)
500 (shell "pw_shell" :type
:string
))
503 ;;;-------------------------------------------------------------------------
505 ;;;-------------------------------------------------------------------------
507 (cstruct group
"struct group"
508 (name "gr_name" :type
:string
)
509 (passwd "gr_passwd" :type
:string
)
510 (gid "gr_gid" :type gid-t
)
511 (mem "gr_mem" :type
:pointer
))
514 ;;;-------------------------------------------------------------------------
516 ;;;-------------------------------------------------------------------------
518 #+linux
(constant (sys-gettid "SYS_gettid"))
521 ;;;-------------------------------------------------------------------------
523 ;;;-------------------------------------------------------------------------
527 (cunion epoll-data
"epoll_data_t"
528 (ptr "ptr" :type
:pointer
)
530 (u32 "u32" :type
:uint32
)
531 (u64 "u64" :type
:uint64
))
533 (cstruct epoll-event
"struct epoll_event"
534 (events "events" :type
:uint32
)
535 (data "data" :type epoll-data
))
537 (constant (epoll-ctl-add "EPOLL_CTL_ADD"))
538 (constant (epoll-ctl-del "EPOLL_CTL_DEL"))
539 (constant (epoll-ctl-mod "EPOLL_CTL_MOD"))
541 (constant (epollin "EPOLLIN"))
542 (constant (epollrdnorm "EPOLLRDNORM"))
543 (constant (epollrdband "EPOLLRDBAND"))
544 (constant (epollpri "EPOLLPRI"))
545 (constant (epollout "EPOLLOUT"))
546 (constant (epollwrnorm "EPOLLWRNORM"))
547 (constant (epollwrband "EPOLLWRBAND"))
548 (constant (epollerr "EPOLLERR"))
549 (constant (epollhup "EPOLLHUP"))
550 (constant (epollmsg "EPOLLMSG"))
551 (constant (epolloneshot "EPOLLONESHOT"))
552 (constant (epollet "EPOLLET")))
555 ;;;-------------------------------------------------------------------------
557 ;;;-------------------------------------------------------------------------
561 (cstruct kevent
"struct kevent"
562 (ident "ident" :type uintptr-t
)
563 (filter "filter" :type
#-netbsd
:short
565 (flags "flags" :type
#-netbsd
:unsigned-short
567 (fflags "fflags" :type
#-netbsd
:unsigned-int
569 (data "data" :type
#-netbsd intptr-t
571 (udata "udata" :type
:pointer
))
574 (constant (ev-add "EV_ADD"))
575 (constant (ev-enable "EV_ENABLE"))
576 (constant (ev-disable "EV_DISABLE"))
577 (constant (ev-delete "EV_DELETE"))
578 (constant (ev-oneshot "EV_ONESHOT"))
579 (constant (ev-clear "EV_CLEAR"))
580 (constant (ev-eof "EV_EOF"))
581 (constant (ev-error "EV_ERROR"))
583 ;; kevent() filter flags
584 (constant (evfilt-read "EVFILT_READ"))
585 (constant (evfilt-write "EVFILT_WRITE"))
586 (constant (evfilt-aio "EVFILT_AIO"))
587 (constant (evfilt-vnode "EVFILT_VNODE"))
588 (constant (evfilt-proc "EVFILT_PROC"))
589 (constant (evfilt-signal "EVFILT_SIGNAL"))
590 (constant (evfilt-timer "EVFILT_TIMER"))
591 #-darwin
(constant (evfilt-netdev "EVFILT_NETDEV"))
593 ;; EVFILT_VNODE options
594 (constant (note-delete "NOTE_DELETE"))
595 (constant (note-write "NOTE_WRITE"))
596 (constant (note-extend "NOTE_EXTEND"))
597 (constant (note-attrib "NOTE_ATTRIB"))
598 (constant (note-link "NOTE_LINK"))
599 (constant (note-rename "NOTE_RENAME"))
600 (constant (note-revoke "NOTE_REVOKE"))
602 ;; EVFILT_PROC options
603 (constant (note-exit "NOTE_EXIT"))
604 (constant (note-fork "NOTE_FORK"))
605 (constant (note-exec "NOTE_EXEC"))
606 (constant (note-track "NOTE_TRACK"))
607 (constant (note-trackerr "NOTE_TRACKERR"))
609 ;; EVFILT_NETDEV options
612 (constant (note-linkup "NOTE_LINKUP"))
613 (constant (note-linkdown "NOTE_LINKDOWN"))
614 (constant (note-linkinv "NOTE_LINKINV"))))
617 ;;;-------------------------------------------------------------------------
619 ;;;-------------------------------------------------------------------------
621 ;; Option flags for openlog.
622 (constant (log-pid "LOG_PID")
623 :documentation
"log the pid with each message")
624 (constant (log-cons "LOG_CONS")
625 :documentation
"log on the console if errors in sending")
626 (constant (log-odelay "LOG_ODELAY")
627 :documentation
"delay open until first syslog() (default)")
628 (constant (log-ndelay "LOG_NDELAY")
629 :documentation
"don't delay open")
630 (constant (log-nowait "LOG_NOWAIT")
631 :documentation
"don't wait for console forks: DEPRECATED")
632 (constant (log-perror "LOG_PERROR")
633 :documentation
"log to stderr as well")
636 (constant (log-kern "LOG_KERN")
637 :documentation
"kernel messages")
638 (constant (log-user "LOG_USER")
639 :documentation
"random user-level messages")
640 (constant (log-mail "LOG_MAIL")
641 :documentation
"mail system")
642 (constant (log-daemon "LOG_DAEMON")
643 :documentation
"system daemons")
644 (constant (log-auth "LOG_AUTH")
645 :documentation
"security/authorization messages")
646 (constant (log-syslog "LOG_SYSLOG")
647 :documentation
"messages generated internally by syslogd")
648 (constant (log-lpr "LOG_LPR")
649 :documentation
"line printer subsystem")
650 (constant (log-news "LOG_NEWS")
651 :documentation
"network news subsystem")
652 (constant (log-uucp "LOG_UUCP")
653 :documentation
"UUCP subsystem")
654 (constant (log-cron "LOG_CRON")
655 :documentation
"clock daemon")
656 (constant (log-authpriv "LOG_AUTHPRIV")
657 :documentation
"security/authorization messages (private")
658 (constant (log-ftp "LOG_FTP")
659 :documentation
"ftp daemon")
661 (constant (log-security "LOG_SECURITY")
662 :documentation
"security subsystems")
664 ;; other codes through 15 reserved for system use
665 (constant (log-local0 "LOG_LOCAL0"))
666 (constant (log-local1 "LOG_LOCAL1"))
667 (constant (log-local2 "LOG_LOCAL2"))
668 (constant (log-local3 "LOG_LOCAL3"))
669 (constant (log-local4 "LOG_LOCAL4"))
670 (constant (log-local5 "LOG_LOCAL5"))
671 (constant (log-local6 "LOG_LOCAL6"))
672 (constant (log-local7 "LOG_LOCAL7"))
674 ;; priorities (these are ordered)
675 (constant (log-emerg "LOG_EMERG")
676 :documentation
"system is unusable")
677 (constant (log-alert "LOG_ALERT")
678 :documentation
"action must be taken immediately")
679 (constant (log-crit "LOG_CRIT")
680 :documentation
"critical conditions")
681 (constant (log-err "LOG_ERR")
682 :documentation
"error conditions")
683 (constant (log-warning "LOG_WARNING")
684 :documentation
"warning conditions")
685 (constant (log-notice "LOG_NOTICE")
686 :documentation
"normal but significant condition")
687 (constant (log-info "LOG_INFO")
688 :documentation
"informational")
689 (constant (log-debug "LOG_DEBUG")
690 :documentation
"debug-level messages")