From 8581b70b5d8d66341e123f939c32aba6f7d81644 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 22 Mar 2021 00:20:36 -0700 Subject: [PATCH 1/5] freebsd: add arch agnostic lib files --- lib/libc/include/any-freebsd-any/_ctype.h | 189 + lib/libc/include/any-freebsd-any/a.out.h | 47 + lib/libc/include/any-freebsd-any/ar.h | 69 + lib/libc/include/any-freebsd-any/arpa/ftp.h | 109 + lib/libc/include/any-freebsd-any/arpa/inet.h | 180 + .../include/any-freebsd-any/arpa/nameser.h | 682 ++++ .../any-freebsd-any/arpa/nameser_compat.h | 203 ++ .../include/any-freebsd-any/arpa/telnet.h | 345 ++ lib/libc/include/any-freebsd-any/arpa/tftp.h | 83 + lib/libc/include/any-freebsd-any/assert.h | 80 + lib/libc/include/any-freebsd-any/bitstring.h | 39 + lib/libc/include/any-freebsd-any/complex.h | 138 + lib/libc/include/any-freebsd-any/cpio.h | 57 + lib/libc/include/any-freebsd-any/ctype.h | 137 + lib/libc/include/any-freebsd-any/db.h | 219 ++ lib/libc/include/any-freebsd-any/dirent.h | 143 + lib/libc/include/any-freebsd-any/dlfcn.h | 141 + lib/libc/include/any-freebsd-any/elf-hints.h | 52 + lib/libc/include/any-freebsd-any/elf.h | 43 + lib/libc/include/any-freebsd-any/err.h | 69 + lib/libc/include/any-freebsd-any/fmtmsg.h | 75 + lib/libc/include/any-freebsd-any/fnmatch.h | 61 + lib/libc/include/any-freebsd-any/fstab.h | 80 + lib/libc/include/any-freebsd-any/fts.h | 138 + lib/libc/include/any-freebsd-any/ftw.h | 64 + lib/libc/include/any-freebsd-any/getopt.h | 80 + lib/libc/include/any-freebsd-any/glob.h | 108 + lib/libc/include/any-freebsd-any/grp.h | 94 + lib/libc/include/any-freebsd-any/gssapi.h | 5 + .../include/any-freebsd-any/gssapi/gssapi.h | 876 +++++ lib/libc/include/any-freebsd-any/hesiod.h | 93 + lib/libc/include/any-freebsd-any/iconv.h | 135 + lib/libc/include/any-freebsd-any/ieeefp.h | 15 + lib/libc/include/any-freebsd-any/ifaddrs.h | 67 + lib/libc/include/any-freebsd-any/inttypes.h | 64 + lib/libc/include/any-freebsd-any/iso646.h | 50 + lib/libc/include/any-freebsd-any/kenv.h | 41 + lib/libc/include/any-freebsd-any/langinfo.h | 141 + lib/libc/include/any-freebsd-any/libgen.h | 65 + lib/libc/include/any-freebsd-any/limits.h | 149 + lib/libc/include/any-freebsd-any/link.h | 35 + lib/libc/include/any-freebsd-any/locale.h | 89 + lib/libc/include/any-freebsd-any/malloc.h | 6 + lib/libc/include/any-freebsd-any/malloc_np.h | 132 + lib/libc/include/any-freebsd-any/memory.h | 36 + .../include/any-freebsd-any/mk-osreldate.sh | 54 + lib/libc/include/any-freebsd-any/monetary.h | 54 + lib/libc/include/any-freebsd-any/mpool.h | 111 + lib/libc/include/any-freebsd-any/mqueue.h | 60 + lib/libc/include/any-freebsd-any/ndbm.h | 82 + lib/libc/include/any-freebsd-any/netconfig.h | 126 + lib/libc/include/any-freebsd-any/netdb.h | 306 ++ lib/libc/include/any-freebsd-any/nl_types.h | 99 + lib/libc/include/any-freebsd-any/nlist.h | 51 + lib/libc/include/any-freebsd-any/nss.h | 59 + lib/libc/include/any-freebsd-any/nsswitch.h | 246 ++ lib/libc/include/any-freebsd-any/osreldate.h | 34 + lib/libc/include/any-freebsd-any/paths.h | 148 + lib/libc/include/any-freebsd-any/printf.h | 166 + .../include/any-freebsd-any/proc_service.h | 72 + .../any-freebsd-any/protocols/dumprestore.h | 144 + .../any-freebsd-any/protocols/routed.h | 174 + .../include/any-freebsd-any/protocols/rwhod.h | 70 + .../include/any-freebsd-any/protocols/talkd.h | 114 + .../include/any-freebsd-any/protocols/timed.h | 104 + lib/libc/include/any-freebsd-any/pthread.h | 354 ++ lib/libc/include/any-freebsd-any/pthread_np.h | 77 + lib/libc/include/any-freebsd-any/pwd.h | 177 + lib/libc/include/any-freebsd-any/ranlib.h | 50 + .../include/any-freebsd-any/readpassphrase.h | 49 + lib/libc/include/any-freebsd-any/regex.h | 118 + lib/libc/include/any-freebsd-any/res_update.h | 77 + lib/libc/include/any-freebsd-any/resolv.h | 505 +++ lib/libc/include/any-freebsd-any/rpc/auth.h | 370 ++ .../include/any-freebsd-any/rpc/auth_des.h | 127 + .../include/any-freebsd-any/rpc/auth_kerb.h | 142 + .../include/any-freebsd-any/rpc/auth_unix.h | 85 + lib/libc/include/any-freebsd-any/rpc/clnt.h | 538 +++ .../include/any-freebsd-any/rpc/clnt_soc.h | 107 + .../include/any-freebsd-any/rpc/clnt_stat.h | 83 + lib/libc/include/any-freebsd-any/rpc/des.h | 84 + .../include/any-freebsd-any/rpc/des_crypt.h | 107 + .../include/any-freebsd-any/rpc/nettype.h | 65 + .../include/any-freebsd-any/rpc/pmap_clnt.h | 87 + .../include/any-freebsd-any/rpc/pmap_prot.h | 108 + .../include/any-freebsd-any/rpc/pmap_rmt.h | 66 + lib/libc/include/any-freebsd-any/rpc/raw.h | 59 + lib/libc/include/any-freebsd-any/rpc/rpc.h | 109 + .../include/any-freebsd-any/rpc/rpc_com.h | 84 + .../include/any-freebsd-any/rpc/rpc_msg.h | 215 ++ .../include/any-freebsd-any/rpc/rpcb_clnt.h | 86 + .../include/any-freebsd-any/rpc/rpcb_prot.x | 553 +++ lib/libc/include/any-freebsd-any/rpc/rpcent.h | 68 + .../include/any-freebsd-any/rpc/rpcsec_gss.h | 181 + lib/libc/include/any-freebsd-any/rpc/svc.h | 476 +++ .../include/any-freebsd-any/rpc/svc_auth.h | 58 + lib/libc/include/any-freebsd-any/rpc/svc_dg.h | 52 + .../include/any-freebsd-any/rpc/svc_soc.h | 117 + lib/libc/include/any-freebsd-any/rpc/xdr.h | 366 ++ .../any-freebsd-any/rpcsvc/bootparam_prot.x | 104 + .../include/any-freebsd-any/rpcsvc/crypt.x | 87 + .../include/any-freebsd-any/rpcsvc/key_prot.x | 287 ++ .../include/any-freebsd-any/rpcsvc/klm_prot.x | 141 + .../include/any-freebsd-any/rpcsvc/mount.x | 259 ++ .../include/any-freebsd-any/rpcsvc/nfs_prot.x | 1268 +++++++ lib/libc/include/any-freebsd-any/rpcsvc/nis.x | 460 +++ .../any-freebsd-any/rpcsvc/nis_cache.x | 85 + .../any-freebsd-any/rpcsvc/nis_callback.x | 75 + .../include/any-freebsd-any/rpcsvc/nis_db.h | 135 + .../any-freebsd-any/rpcsvc/nis_object.x | 319 ++ .../include/any-freebsd-any/rpcsvc/nis_tags.h | 142 + .../include/any-freebsd-any/rpcsvc/nislib.h | 188 + .../include/any-freebsd-any/rpcsvc/nlm_prot.x | 327 ++ .../any-freebsd-any/rpcsvc/pmap_prot.x | 279 ++ lib/libc/include/any-freebsd-any/rpcsvc/rex.x | 237 ++ .../include/any-freebsd-any/rpcsvc/rnusers.x | 125 + .../include/any-freebsd-any/rpcsvc/rquota.x | 144 + .../include/any-freebsd-any/rpcsvc/rstat.x | 160 + .../include/any-freebsd-any/rpcsvc/rwall.x | 57 + .../include/any-freebsd-any/rpcsvc/sm_inter.x | 127 + .../include/any-freebsd-any/rpcsvc/spray.x | 92 + lib/libc/include/any-freebsd-any/rpcsvc/yp.x | 379 ++ .../include/any-freebsd-any/rpcsvc/yp_prot.h | 331 ++ .../include/any-freebsd-any/rpcsvc/ypclnt.h | 95 + .../include/any-freebsd-any/rpcsvc/yppasswd.x | 77 + .../any-freebsd-any/rpcsvc/ypupdate_prot.x | 86 + .../include/any-freebsd-any/rpcsvc/ypxfrd.x | 169 + lib/libc/include/any-freebsd-any/runetype.h | 106 + lib/libc/include/any-freebsd-any/search.h | 85 + lib/libc/include/any-freebsd-any/semaphore.h | 73 + lib/libc/include/any-freebsd-any/setjmp.h | 64 + lib/libc/include/any-freebsd-any/signal.h | 137 + lib/libc/include/any-freebsd-any/spawn.h | 120 + lib/libc/include/any-freebsd-any/stab.h | 72 + lib/libc/include/any-freebsd-any/stdalign.h | 49 + lib/libc/include/any-freebsd-any/stdbool.h | 45 + lib/libc/include/any-freebsd-any/stddef.h | 85 + lib/libc/include/any-freebsd-any/stdio.h | 535 +++ lib/libc/include/any-freebsd-any/stdlib.h | 347 ++ .../include/any-freebsd-any/stdnoreturn.h | 40 + lib/libc/include/any-freebsd-any/string.h | 164 + lib/libc/include/any-freebsd-any/stringlist.h | 54 + lib/libc/include/any-freebsd-any/strings.h | 73 + .../include/any-freebsd-any/sys/_bitset.h | 66 + .../include/any-freebsd-any/sys/_bus_dma.h | 65 + .../include/any-freebsd-any/sys/_callout.h | 69 + .../include/any-freebsd-any/sys/_cpuset.h | 52 + .../include/any-freebsd-any/sys/_domainset.h | 60 + .../include/any-freebsd-any/sys/_ffcounter.h | 44 + lib/libc/include/any-freebsd-any/sys/_iovec.h | 50 + .../any-freebsd-any/sys/_kstack_cache.h | 49 + lib/libc/include/any-freebsd-any/sys/_lock.h | 43 + .../include/any-freebsd-any/sys/_lockmgr.h | 51 + lib/libc/include/any-freebsd-any/sys/_mutex.h | 66 + lib/libc/include/any-freebsd-any/sys/_null.h | 49 + .../include/any-freebsd-any/sys/_pctrie.h | 43 + .../any-freebsd-any/sys/_pthreadtypes.h | 100 + .../include/any-freebsd-any/sys/_rangeset.h | 51 + .../include/any-freebsd-any/sys/_rmlock.h | 71 + .../include/any-freebsd-any/sys/_rwlock.h | 64 + .../include/any-freebsd-any/sys/_semaphore.h | 58 + .../include/any-freebsd-any/sys/_sigset.h | 61 + .../any-freebsd-any/sys/_sockaddr_storage.h | 56 + lib/libc/include/any-freebsd-any/sys/_stack.h | 41 + .../include/any-freebsd-any/sys/_stdarg.h | 55 + .../include/any-freebsd-any/sys/_stdint.h | 92 + lib/libc/include/any-freebsd-any/sys/_sx.h | 44 + lib/libc/include/any-freebsd-any/sys/_task.h | 76 + .../include/any-freebsd-any/sys/_termios.h | 230 ++ .../include/any-freebsd-any/sys/_timespec.h | 51 + .../include/any-freebsd-any/sys/_timeval.h | 54 + lib/libc/include/any-freebsd-any/sys/_types.h | 150 + .../include/any-freebsd-any/sys/_ucontext.h | 54 + lib/libc/include/any-freebsd-any/sys/_uio.h | 52 + lib/libc/include/any-freebsd-any/sys/_umtx.h | 81 + .../include/any-freebsd-any/sys/_unrhdr.h | 53 + .../include/any-freebsd-any/sys/aac_ioctl.h | 218 ++ .../include/any-freebsd-any/sys/abi_compat.h | 77 + lib/libc/include/any-freebsd-any/sys/acct.h | 149 + lib/libc/include/any-freebsd-any/sys/acl.h | 419 +++ lib/libc/include/any-freebsd-any/sys/agpio.h | 152 + lib/libc/include/any-freebsd-any/sys/aio.h | 266 ++ lib/libc/include/any-freebsd-any/sys/alq.h | 146 + lib/libc/include/any-freebsd-any/sys/apm.h | 5 + lib/libc/include/any-freebsd-any/sys/assym.h | 61 + lib/libc/include/any-freebsd-any/sys/ata.h | 1060 ++++++ .../any-freebsd-any/sys/atomic_common.h | 73 + lib/libc/include/any-freebsd-any/sys/auxv.h | 41 + lib/libc/include/any-freebsd-any/sys/bio.h | 184 + lib/libc/include/any-freebsd-any/sys/bitset.h | 255 ++ .../include/any-freebsd-any/sys/bitstring.h | 422 +++ lib/libc/include/any-freebsd-any/sys/blist.h | 106 + lib/libc/include/any-freebsd-any/sys/boot.h | 44 + lib/libc/include/any-freebsd-any/sys/buf.h | 586 ++++ .../include/any-freebsd-any/sys/buf_ring.h | 372 ++ lib/libc/include/any-freebsd-any/sys/bufobj.h | 140 + lib/libc/include/any-freebsd-any/sys/bus.h | 971 ++++++ .../include/any-freebsd-any/sys/bus_dma.h | 310 ++ .../any-freebsd-any/sys/bus_dma_internal.h | 61 + .../any-freebsd-any/sys/busdma_bufalloc.h | 120 + .../include/any-freebsd-any/sys/callout.h | 140 + .../include/any-freebsd-any/sys/capability.h | 47 + .../include/any-freebsd-any/sys/caprights.h | 63 + .../include/any-freebsd-any/sys/capsicum.h | 486 +++ lib/libc/include/any-freebsd-any/sys/cdefs.h | 879 +++++ lib/libc/include/any-freebsd-any/sys/cdio.h | 277 ++ lib/libc/include/any-freebsd-any/sys/cdrio.h | 141 + lib/libc/include/any-freebsd-any/sys/cfictl.h | 55 + lib/libc/include/any-freebsd-any/sys/chio.h | 282 ++ lib/libc/include/any-freebsd-any/sys/ck.h | 13 + lib/libc/include/any-freebsd-any/sys/clock.h | 208 ++ lib/libc/include/any-freebsd-any/sys/cnv.h | 120 + .../include/any-freebsd-any/sys/compressor.h | 54 + .../include/any-freebsd-any/sys/condvar.h | 91 + lib/libc/include/any-freebsd-any/sys/conf.h | 373 ++ lib/libc/include/any-freebsd-any/sys/cons.h | 152 + lib/libc/include/any-freebsd-any/sys/consio.h | 468 +++ .../include/any-freebsd-any/sys/copyright.h | 50 + .../include/any-freebsd-any/sys/counter.h | 91 + lib/libc/include/any-freebsd-any/sys/cpu.h | 191 + lib/libc/include/any-freebsd-any/sys/cpuctl.h | 64 + lib/libc/include/any-freebsd-any/sys/cpuset.h | 159 + lib/libc/include/any-freebsd-any/sys/ctype.h | 105 + .../include/any-freebsd-any/sys/devicestat.h | 209 ++ lib/libc/include/any-freebsd-any/sys/devmap.h | 97 + lib/libc/include/any-freebsd-any/sys/dir.h | 53 + lib/libc/include/any-freebsd-any/sys/dirent.h | 144 + lib/libc/include/any-freebsd-any/sys/disk.h | 159 + .../include/any-freebsd-any/sys/disk/apm.h | 69 + .../include/any-freebsd-any/sys/disk/bsd.h | 191 + .../include/any-freebsd-any/sys/disk/gpt.h | 239 ++ .../include/any-freebsd-any/sys/disk/mbr.h | 85 + .../include/any-freebsd-any/sys/disk/vtoc.h | 108 + .../include/any-freebsd-any/sys/disk_zone.h | 186 + .../include/any-freebsd-any/sys/disklabel.h | 171 + .../include/any-freebsd-any/sys/diskmbr.h | 46 + lib/libc/include/any-freebsd-any/sys/dkstat.h | 45 + lib/libc/include/any-freebsd-any/sys/dnv.h | 87 + lib/libc/include/any-freebsd-any/sys/domain.h | 102 + .../include/any-freebsd-any/sys/domainset.h | 127 + .../include/any-freebsd-any/sys/dtrace_bsd.h | 175 + lib/libc/include/any-freebsd-any/sys/dvdio.h | 112 + lib/libc/include/any-freebsd-any/sys/efi.h | 197 ++ lib/libc/include/any-freebsd-any/sys/efiio.h | 58 + lib/libc/include/any-freebsd-any/sys/elf.h | 43 + lib/libc/include/any-freebsd-any/sys/elf32.h | 265 ++ lib/libc/include/any-freebsd-any/sys/elf64.h | 269 ++ .../include/any-freebsd-any/sys/elf_common.h | 1430 ++++++++ .../include/any-freebsd-any/sys/elf_generic.h | 91 + lib/libc/include/any-freebsd-any/sys/endian.h | 207 ++ lib/libc/include/any-freebsd-any/sys/epoch.h | 93 + lib/libc/include/any-freebsd-any/sys/errno.h | 209 ++ lib/libc/include/any-freebsd-any/sys/eui64.h | 59 + lib/libc/include/any-freebsd-any/sys/event.h | 369 ++ .../any-freebsd-any/sys/eventhandler.h | 343 ++ .../include/any-freebsd-any/sys/eventvar.h | 68 + lib/libc/include/any-freebsd-any/sys/exec.h | 133 + .../include/any-freebsd-any/sys/extattr.h | 107 + lib/libc/include/any-freebsd-any/sys/fail.h | 363 ++ lib/libc/include/any-freebsd-any/sys/fbio.h | 622 ++++ lib/libc/include/any-freebsd-any/sys/fcntl.h | 336 ++ lib/libc/include/any-freebsd-any/sys/fdcio.h | 197 ++ lib/libc/include/any-freebsd-any/sys/file.h | 431 +++ .../include/any-freebsd-any/sys/filedesc.h | 250 ++ lib/libc/include/any-freebsd-any/sys/filio.h | 74 + .../include/any-freebsd-any/sys/firmware.h | 66 + .../include/any-freebsd-any/sys/fnv_hash.h | 71 + lib/libc/include/any-freebsd-any/sys/gmon.h | 245 ++ lib/libc/include/any-freebsd-any/sys/gpio.h | 179 + lib/libc/include/any-freebsd-any/sys/gpt.h | 39 + .../include/any-freebsd-any/sys/gtaskqueue.h | 113 + lib/libc/include/any-freebsd-any/sys/hash.h | 136 + lib/libc/include/any-freebsd-any/sys/hhook.h | 163 + lib/libc/include/any-freebsd-any/sys/iconv.h | 252 ++ lib/libc/include/any-freebsd-any/sys/imgact.h | 116 + .../include/any-freebsd-any/sys/imgact_aout.h | 159 + .../any-freebsd-any/sys/imgact_binmisc.h | 174 + .../include/any-freebsd-any/sys/imgact_elf.h | 111 + .../include/any-freebsd-any/sys/inflate.h | 53 + .../include/any-freebsd-any/sys/interrupt.h | 202 ++ lib/libc/include/any-freebsd-any/sys/intr.h | 164 + lib/libc/include/any-freebsd-any/sys/ioccom.h | 86 + lib/libc/include/any-freebsd-any/sys/ioctl.h | 53 + .../any-freebsd-any/sys/ioctl_compat.h | 154 + lib/libc/include/any-freebsd-any/sys/iov.h | 259 ++ .../include/any-freebsd-any/sys/iov_schema.h | 54 + lib/libc/include/any-freebsd-any/sys/ipc.h | 152 + lib/libc/include/any-freebsd-any/sys/ipmi.h | 181 + lib/libc/include/any-freebsd-any/sys/jail.h | 428 +++ .../include/any-freebsd-any/sys/joystick.h | 52 + lib/libc/include/any-freebsd-any/sys/kbio.h | 269 ++ lib/libc/include/any-freebsd-any/sys/kdb.h | 128 + lib/libc/include/any-freebsd-any/sys/kenv.h | 45 + .../any-freebsd-any/sys/kern_prefetch.h | 42 + lib/libc/include/any-freebsd-any/sys/kernel.h | 456 +++ .../include/any-freebsd-any/sys/kerneldump.h | 157 + lib/libc/include/any-freebsd-any/sys/khelp.h | 79 + lib/libc/include/any-freebsd-any/sys/kobj.h | 262 ++ .../include/any-freebsd-any/sys/kpilite.h | 55 + lib/libc/include/any-freebsd-any/sys/ksem.h | 68 + .../include/any-freebsd-any/sys/kthread.h | 81 + lib/libc/include/any-freebsd-any/sys/ktr.h | 269 ++ .../include/any-freebsd-any/sys/ktr_class.h | 89 + lib/libc/include/any-freebsd-any/sys/ktrace.h | 306 ++ .../include/any-freebsd-any/sys/libkern.h | 253 ++ lib/libc/include/any-freebsd-any/sys/limits.h | 102 + .../include/any-freebsd-any/sys/link_aout.h | 290 ++ .../include/any-freebsd-any/sys/link_elf.h | 109 + lib/libc/include/any-freebsd-any/sys/linker.h | 366 ++ .../include/any-freebsd-any/sys/linker_set.h | 111 + lib/libc/include/any-freebsd-any/sys/lock.h | 362 ++ .../any-freebsd-any/sys/lock_profile.h | 77 + lib/libc/include/any-freebsd-any/sys/lockf.h | 135 + .../include/any-freebsd-any/sys/lockmgr.h | 204 ++ .../include/any-freebsd-any/sys/lockstat.h | 149 + .../include/any-freebsd-any/sys/loginclass.h | 56 + lib/libc/include/any-freebsd-any/sys/mac.h | 113 + lib/libc/include/any-freebsd-any/sys/malloc.h | 270 ++ lib/libc/include/any-freebsd-any/sys/mbuf.h | 1393 ++++++++ lib/libc/include/any-freebsd-any/sys/mchain.h | 105 + lib/libc/include/any-freebsd-any/sys/md4.h | 52 + lib/libc/include/any-freebsd-any/sys/md5.h | 59 + .../include/any-freebsd-any/sys/mdioctl.h | 96 + .../include/any-freebsd-any/sys/memdesc.h | 158 + .../include/any-freebsd-any/sys/memrange.h | 79 + lib/libc/include/any-freebsd-any/sys/mman.h | 283 ++ lib/libc/include/any-freebsd-any/sys/module.h | 279 ++ .../any-freebsd-any/sys/module_khelp.h | 98 + lib/libc/include/any-freebsd-any/sys/mount.h | 1006 ++++++ lib/libc/include/any-freebsd-any/sys/mouse.h | 384 ++ .../include/any-freebsd-any/sys/mpt_ioctl.h | 134 + lib/libc/include/any-freebsd-any/sys/mqueue.h | 47 + lib/libc/include/any-freebsd-any/sys/msg.h | 169 + lib/libc/include/any-freebsd-any/sys/msgbuf.h | 87 + lib/libc/include/any-freebsd-any/sys/mtio.h | 351 ++ lib/libc/include/any-freebsd-any/sys/mutex.h | 556 +++ lib/libc/include/any-freebsd-any/sys/namei.h | 226 ++ .../include/any-freebsd-any/sys/nlist_aout.h | 113 + lib/libc/include/any-freebsd-any/sys/nv.h | 256 ++ lib/libc/include/any-freebsd-any/sys/osd.h | 112 + lib/libc/include/any-freebsd-any/sys/param.h | 365 ++ lib/libc/include/any-freebsd-any/sys/pciio.h | 167 + lib/libc/include/any-freebsd-any/sys/pcpu.h | 261 ++ lib/libc/include/any-freebsd-any/sys/pctrie.h | 152 + .../include/any-freebsd-any/sys/physmem.h | 88 + .../include/any-freebsd-any/sys/pidctrl.h | 123 + lib/libc/include/any-freebsd-any/sys/pioctl.h | 85 + lib/libc/include/any-freebsd-any/sys/pipe.h | 147 + lib/libc/include/any-freebsd-any/sys/pmc.h | 1231 +++++++ .../include/any-freebsd-any/sys/pmckern.h | 272 ++ lib/libc/include/any-freebsd-any/sys/pmclog.h | 326 ++ lib/libc/include/any-freebsd-any/sys/poll.h | 124 + lib/libc/include/any-freebsd-any/sys/posix4.h | 116 + lib/libc/include/any-freebsd-any/sys/power.h | 67 + .../include/any-freebsd-any/sys/priority.h | 135 + lib/libc/include/any-freebsd-any/sys/priv.h | 540 +++ lib/libc/include/any-freebsd-any/sys/proc.h | 1207 +++++++ .../include/any-freebsd-any/sys/procctl.h | 144 + .../include/any-freebsd-any/sys/procdesc.h | 139 + lib/libc/include/any-freebsd-any/sys/procfs.h | 122 + .../include/any-freebsd-any/sys/protosw.h | 354 ++ lib/libc/include/any-freebsd-any/sys/ptio.h | 39 + lib/libc/include/any-freebsd-any/sys/ptrace.h | 232 ++ lib/libc/include/any-freebsd-any/sys/queue.h | 875 +++++ lib/libc/include/any-freebsd-any/sys/racct.h | 279 ++ lib/libc/include/any-freebsd-any/sys/random.h | 166 + .../include/any-freebsd-any/sys/rangelock.h | 107 + .../include/any-freebsd-any/sys/rangeset.h | 88 + lib/libc/include/any-freebsd-any/sys/rctl.h | 174 + lib/libc/include/any-freebsd-any/sys/reboot.h | 71 + .../include/any-freebsd-any/sys/refcount.h | 130 + .../include/any-freebsd-any/sys/regression.h | 40 + .../include/any-freebsd-any/sys/resource.h | 194 ++ .../include/any-freebsd-any/sys/resourcevar.h | 161 + lib/libc/include/any-freebsd-any/sys/rman.h | 169 + lib/libc/include/any-freebsd-any/sys/rmlock.h | 137 + lib/libc/include/any-freebsd-any/sys/rtprio.h | 95 + lib/libc/include/any-freebsd-any/sys/runq.h | 77 + lib/libc/include/any-freebsd-any/sys/rwlock.h | 300 ++ lib/libc/include/any-freebsd-any/sys/sbuf.h | 117 + lib/libc/include/any-freebsd-any/sys/sched.h | 266 ++ lib/libc/include/any-freebsd-any/sys/sdt.h | 431 +++ lib/libc/include/any-freebsd-any/sys/select.h | 110 + .../include/any-freebsd-any/sys/selinfo.h | 63 + lib/libc/include/any-freebsd-any/sys/sem.h | 159 + lib/libc/include/any-freebsd-any/sys/sema.h | 64 + lib/libc/include/any-freebsd-any/sys/seq.h | 156 + lib/libc/include/any-freebsd-any/sys/serial.h | 94 + lib/libc/include/any-freebsd-any/sys/sf_buf.h | 196 ++ lib/libc/include/any-freebsd-any/sys/sglist.h | 113 + lib/libc/include/any-freebsd-any/sys/shm.h | 180 + lib/libc/include/any-freebsd-any/sys/sigio.h | 69 + lib/libc/include/any-freebsd-any/sys/signal.h | 514 +++ .../include/any-freebsd-any/sys/signalvar.h | 404 +++ .../include/any-freebsd-any/sys/sleepqueue.h | 123 + lib/libc/include/any-freebsd-any/sys/slicer.h | 66 + lib/libc/include/any-freebsd-any/sys/smp.h | 279 ++ lib/libc/include/any-freebsd-any/sys/snoop.h | 43 + .../include/any-freebsd-any/sys/sockbuf.h | 254 ++ lib/libc/include/any-freebsd-any/sys/socket.h | 731 ++++ .../include/any-freebsd-any/sys/socketvar.h | 538 +++ lib/libc/include/any-freebsd-any/sys/sockio.h | 148 + .../include/any-freebsd-any/sys/sockopt.h | 73 + .../include/any-freebsd-any/sys/soundcard.h | 2006 +++++++++++ .../include/any-freebsd-any/sys/spigenio.h | 56 + lib/libc/include/any-freebsd-any/sys/stack.h | 67 + lib/libc/include/any-freebsd-any/sys/stat.h | 404 +++ .../include/any-freebsd-any/sys/statvfs.h | 81 + .../include/any-freebsd-any/sys/stdatomic.h | 410 +++ lib/libc/include/any-freebsd-any/sys/stddef.h | 45 + lib/libc/include/any-freebsd-any/sys/stdint.h | 78 + .../any-freebsd-any/sys/sun_disklabel.h | 125 + lib/libc/include/any-freebsd-any/sys/sx.h | 304 ++ .../include/any-freebsd-any/sys/syscall.h | 508 +++ .../include/any-freebsd-any/sys/syscall.mk | 413 +++ .../include/any-freebsd-any/sys/syscallsubr.h | 322 ++ lib/libc/include/any-freebsd-any/sys/sysctl.h | 1122 ++++++ lib/libc/include/any-freebsd-any/sys/sysent.h | 327 ++ .../include/any-freebsd-any/sys/syslimits.h | 81 + lib/libc/include/any-freebsd-any/sys/syslog.h | 205 ++ .../include/any-freebsd-any/sys/sysproto.h | 3100 +++++++++++++++++ lib/libc/include/any-freebsd-any/sys/systm.h | 588 ++++ .../include/any-freebsd-any/sys/taskqueue.h | 217 ++ .../include/any-freebsd-any/sys/terminal.h | 240 ++ .../include/any-freebsd-any/sys/termios.h | 5 + lib/libc/include/any-freebsd-any/sys/thr.h | 87 + lib/libc/include/any-freebsd-any/sys/tiio.h | 335 ++ lib/libc/include/any-freebsd-any/sys/time.h | 631 ++++ lib/libc/include/any-freebsd-any/sys/timeb.h | 70 + lib/libc/include/any-freebsd-any/sys/timeet.h | 108 + .../include/any-freebsd-any/sys/timeffc.h | 391 +++ .../include/any-freebsd-any/sys/timepps.h | 268 ++ lib/libc/include/any-freebsd-any/sys/timers.h | 119 + lib/libc/include/any-freebsd-any/sys/times.h | 64 + .../include/any-freebsd-any/sys/timespec.h | 65 + lib/libc/include/any-freebsd-any/sys/timetc.h | 99 + lib/libc/include/any-freebsd-any/sys/timex.h | 171 + lib/libc/include/any-freebsd-any/sys/tree.h | 803 +++++ lib/libc/include/any-freebsd-any/sys/tslog.h | 62 + lib/libc/include/any-freebsd-any/sys/tty.h | 233 ++ lib/libc/include/any-freebsd-any/sys/ttycom.h | 147 + .../include/any-freebsd-any/sys/ttydefaults.h | 113 + .../include/any-freebsd-any/sys/ttydevsw.h | 211 ++ .../include/any-freebsd-any/sys/ttydisc.h | 89 + .../include/any-freebsd-any/sys/ttyhook.h | 149 + .../include/any-freebsd-any/sys/ttyqueue.h | 180 + .../include/any-freebsd-any/sys/turnstile.h | 108 + lib/libc/include/any-freebsd-any/sys/types.h | 437 +++ .../include/any-freebsd-any/sys/ucontext.h | 92 + lib/libc/include/any-freebsd-any/sys/ucred.h | 121 + lib/libc/include/any-freebsd-any/sys/uio.h | 118 + lib/libc/include/any-freebsd-any/sys/umtx.h | 202 ++ lib/libc/include/any-freebsd-any/sys/un.h | 77 + lib/libc/include/any-freebsd-any/sys/unistd.h | 202 ++ lib/libc/include/any-freebsd-any/sys/unpcb.h | 177 + lib/libc/include/any-freebsd-any/sys/user.h | 614 ++++ .../include/any-freebsd-any/sys/utsname.h | 71 + lib/libc/include/any-freebsd-any/sys/uuid.h | 101 + lib/libc/include/any-freebsd-any/sys/vdso.h | 136 + lib/libc/include/any-freebsd-any/sys/vmem.h | 145 + .../include/any-freebsd-any/sys/vmmeter.h | 238 ++ lib/libc/include/any-freebsd-any/sys/vnode.h | 928 +++++ lib/libc/include/any-freebsd-any/sys/vtoc.h | 5 + lib/libc/include/any-freebsd-any/sys/wait.h | 176 + .../include/any-freebsd-any/sys/watchdog.h | 125 + lib/libc/include/any-freebsd-any/sys/zlib.h | 1020 ++++++ lib/libc/include/any-freebsd-any/sys/zutil.h | 228 ++ lib/libc/include/any-freebsd-any/sysexits.h | 118 + lib/libc/include/any-freebsd-any/syslog.h | 1 + lib/libc/include/any-freebsd-any/tar.h | 73 + lib/libc/include/any-freebsd-any/termios.h | 103 + lib/libc/include/any-freebsd-any/tgmath.h | 212 ++ lib/libc/include/any-freebsd-any/time.h | 222 ++ lib/libc/include/any-freebsd-any/timeconv.h | 63 + lib/libc/include/any-freebsd-any/timers.h | 47 + lib/libc/include/any-freebsd-any/ttyent.h | 79 + lib/libc/include/any-freebsd-any/uchar.h | 69 + lib/libc/include/any-freebsd-any/ulimit.h | 43 + lib/libc/include/any-freebsd-any/unistd.h | 595 ++++ lib/libc/include/any-freebsd-any/unwind.h | 160 + lib/libc/include/any-freebsd-any/utime.h | 55 + lib/libc/include/any-freebsd-any/utmpx.h | 90 + lib/libc/include/any-freebsd-any/uuid.h | 65 + lib/libc/include/any-freebsd-any/varargs.h | 37 + lib/libc/include/any-freebsd-any/wchar.h | 241 ++ lib/libc/include/any-freebsd-any/wctype.h | 127 + lib/libc/include/any-freebsd-any/wordexp.h | 77 + lib/libc/include/any-freebsd-any/xlocale.h | 87 + .../include/any-freebsd-any/xlocale/_ctype.h | 205 ++ .../any-freebsd-any/xlocale/_inttypes.h | 46 + .../any-freebsd-any/xlocale/_langinfo.h | 44 + .../include/any-freebsd-any/xlocale/_locale.h | 59 + .../any-freebsd-any/xlocale/_monetary.h | 47 + .../include/any-freebsd-any/xlocale/_stdio.h | 66 + .../include/any-freebsd-any/xlocale/_stdlib.h | 61 + .../include/any-freebsd-any/xlocale/_string.h | 61 + .../any-freebsd-any/xlocale/_strings.h | 48 + .../include/any-freebsd-any/xlocale/_time.h | 60 + .../include/any-freebsd-any/xlocale/_uchar.h | 48 + .../include/any-freebsd-any/xlocale/_wchar.h | 135 + 500 files changed, 96811 insertions(+) create mode 100644 lib/libc/include/any-freebsd-any/_ctype.h create mode 100644 lib/libc/include/any-freebsd-any/a.out.h create mode 100644 lib/libc/include/any-freebsd-any/ar.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/ftp.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/inet.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/nameser.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/nameser_compat.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/telnet.h create mode 100644 lib/libc/include/any-freebsd-any/arpa/tftp.h create mode 100644 lib/libc/include/any-freebsd-any/assert.h create mode 100644 lib/libc/include/any-freebsd-any/bitstring.h create mode 100644 lib/libc/include/any-freebsd-any/complex.h create mode 100644 lib/libc/include/any-freebsd-any/cpio.h create mode 100644 lib/libc/include/any-freebsd-any/ctype.h create mode 100644 lib/libc/include/any-freebsd-any/db.h create mode 100644 lib/libc/include/any-freebsd-any/dirent.h create mode 100644 lib/libc/include/any-freebsd-any/dlfcn.h create mode 100644 lib/libc/include/any-freebsd-any/elf-hints.h create mode 100644 lib/libc/include/any-freebsd-any/elf.h create mode 100644 lib/libc/include/any-freebsd-any/err.h create mode 100644 lib/libc/include/any-freebsd-any/fmtmsg.h create mode 100644 lib/libc/include/any-freebsd-any/fnmatch.h create mode 100644 lib/libc/include/any-freebsd-any/fstab.h create mode 100644 lib/libc/include/any-freebsd-any/fts.h create mode 100644 lib/libc/include/any-freebsd-any/ftw.h create mode 100644 lib/libc/include/any-freebsd-any/getopt.h create mode 100644 lib/libc/include/any-freebsd-any/glob.h create mode 100644 lib/libc/include/any-freebsd-any/grp.h create mode 100644 lib/libc/include/any-freebsd-any/gssapi.h create mode 100644 lib/libc/include/any-freebsd-any/gssapi/gssapi.h create mode 100644 lib/libc/include/any-freebsd-any/hesiod.h create mode 100644 lib/libc/include/any-freebsd-any/iconv.h create mode 100644 lib/libc/include/any-freebsd-any/ieeefp.h create mode 100644 lib/libc/include/any-freebsd-any/ifaddrs.h create mode 100644 lib/libc/include/any-freebsd-any/inttypes.h create mode 100644 lib/libc/include/any-freebsd-any/iso646.h create mode 100644 lib/libc/include/any-freebsd-any/kenv.h create mode 100644 lib/libc/include/any-freebsd-any/langinfo.h create mode 100644 lib/libc/include/any-freebsd-any/libgen.h create mode 100644 lib/libc/include/any-freebsd-any/limits.h create mode 100644 lib/libc/include/any-freebsd-any/link.h create mode 100644 lib/libc/include/any-freebsd-any/locale.h create mode 100644 lib/libc/include/any-freebsd-any/malloc.h create mode 100644 lib/libc/include/any-freebsd-any/malloc_np.h create mode 100644 lib/libc/include/any-freebsd-any/memory.h create mode 100755 lib/libc/include/any-freebsd-any/mk-osreldate.sh create mode 100644 lib/libc/include/any-freebsd-any/monetary.h create mode 100644 lib/libc/include/any-freebsd-any/mpool.h create mode 100644 lib/libc/include/any-freebsd-any/mqueue.h create mode 100644 lib/libc/include/any-freebsd-any/ndbm.h create mode 100644 lib/libc/include/any-freebsd-any/netconfig.h create mode 100644 lib/libc/include/any-freebsd-any/netdb.h create mode 100644 lib/libc/include/any-freebsd-any/nl_types.h create mode 100644 lib/libc/include/any-freebsd-any/nlist.h create mode 100644 lib/libc/include/any-freebsd-any/nss.h create mode 100644 lib/libc/include/any-freebsd-any/nsswitch.h create mode 100644 lib/libc/include/any-freebsd-any/osreldate.h create mode 100644 lib/libc/include/any-freebsd-any/paths.h create mode 100644 lib/libc/include/any-freebsd-any/printf.h create mode 100644 lib/libc/include/any-freebsd-any/proc_service.h create mode 100644 lib/libc/include/any-freebsd-any/protocols/dumprestore.h create mode 100644 lib/libc/include/any-freebsd-any/protocols/routed.h create mode 100644 lib/libc/include/any-freebsd-any/protocols/rwhod.h create mode 100644 lib/libc/include/any-freebsd-any/protocols/talkd.h create mode 100644 lib/libc/include/any-freebsd-any/protocols/timed.h create mode 100644 lib/libc/include/any-freebsd-any/pthread.h create mode 100644 lib/libc/include/any-freebsd-any/pthread_np.h create mode 100644 lib/libc/include/any-freebsd-any/pwd.h create mode 100644 lib/libc/include/any-freebsd-any/ranlib.h create mode 100644 lib/libc/include/any-freebsd-any/readpassphrase.h create mode 100644 lib/libc/include/any-freebsd-any/regex.h create mode 100644 lib/libc/include/any-freebsd-any/res_update.h create mode 100644 lib/libc/include/any-freebsd-any/resolv.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/auth.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/auth_des.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/auth_kerb.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/auth_unix.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/clnt.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/clnt_soc.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/clnt_stat.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/des.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/des_crypt.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/nettype.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/pmap_clnt.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/pmap_prot.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/pmap_rmt.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/raw.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpc.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpc_com.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpc_msg.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpcb_clnt.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpcb_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpcent.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/rpcsec_gss.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/svc.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/svc_auth.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/svc_dg.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/svc_soc.h create mode 100644 lib/libc/include/any-freebsd-any/rpc/xdr.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/bootparam_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/crypt.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/key_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/klm_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/mount.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nfs_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis_cache.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis_callback.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis_db.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis_object.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nis_tags.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nislib.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/nlm_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/pmap_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/rex.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/rnusers.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/rquota.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/rstat.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/rwall.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/sm_inter.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/spray.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/yp.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/yp_prot.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/ypclnt.h create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/yppasswd.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/ypupdate_prot.x create mode 100644 lib/libc/include/any-freebsd-any/rpcsvc/ypxfrd.x create mode 100644 lib/libc/include/any-freebsd-any/runetype.h create mode 100644 lib/libc/include/any-freebsd-any/search.h create mode 100644 lib/libc/include/any-freebsd-any/semaphore.h create mode 100644 lib/libc/include/any-freebsd-any/setjmp.h create mode 100644 lib/libc/include/any-freebsd-any/signal.h create mode 100644 lib/libc/include/any-freebsd-any/spawn.h create mode 100644 lib/libc/include/any-freebsd-any/stab.h create mode 100644 lib/libc/include/any-freebsd-any/stdalign.h create mode 100644 lib/libc/include/any-freebsd-any/stdbool.h create mode 100644 lib/libc/include/any-freebsd-any/stddef.h create mode 100644 lib/libc/include/any-freebsd-any/stdio.h create mode 100644 lib/libc/include/any-freebsd-any/stdlib.h create mode 100644 lib/libc/include/any-freebsd-any/stdnoreturn.h create mode 100644 lib/libc/include/any-freebsd-any/string.h create mode 100644 lib/libc/include/any-freebsd-any/stringlist.h create mode 100644 lib/libc/include/any-freebsd-any/strings.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_bitset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_bus_dma.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_callout.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_cpuset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_domainset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_ffcounter.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_iovec.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_kstack_cache.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_lock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_lockmgr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_mutex.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_null.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_pctrie.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_pthreadtypes.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_rangeset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_rmlock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_rwlock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_semaphore.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_sigset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_sockaddr_storage.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_stack.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_stdarg.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_stdint.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_sx.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_task.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_termios.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_timespec.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_timeval.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_types.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_ucontext.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_uio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_umtx.h create mode 100644 lib/libc/include/any-freebsd-any/sys/_unrhdr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/aac_ioctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/abi_compat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/acct.h create mode 100644 lib/libc/include/any-freebsd-any/sys/acl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/agpio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/aio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/alq.h create mode 100644 lib/libc/include/any-freebsd-any/sys/apm.h create mode 100644 lib/libc/include/any-freebsd-any/sys/assym.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ata.h create mode 100644 lib/libc/include/any-freebsd-any/sys/atomic_common.h create mode 100644 lib/libc/include/any-freebsd-any/sys/auxv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bitset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bitstring.h create mode 100644 lib/libc/include/any-freebsd-any/sys/blist.h create mode 100644 lib/libc/include/any-freebsd-any/sys/boot.h create mode 100644 lib/libc/include/any-freebsd-any/sys/buf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/buf_ring.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bufobj.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bus.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bus_dma.h create mode 100644 lib/libc/include/any-freebsd-any/sys/bus_dma_internal.h create mode 100644 lib/libc/include/any-freebsd-any/sys/busdma_bufalloc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/callout.h create mode 100644 lib/libc/include/any-freebsd-any/sys/capability.h create mode 100644 lib/libc/include/any-freebsd-any/sys/caprights.h create mode 100644 lib/libc/include/any-freebsd-any/sys/capsicum.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cdefs.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cdio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cdrio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cfictl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/chio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ck.h create mode 100644 lib/libc/include/any-freebsd-any/sys/clock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cnv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/compressor.h create mode 100644 lib/libc/include/any-freebsd-any/sys/condvar.h create mode 100644 lib/libc/include/any-freebsd-any/sys/conf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cons.h create mode 100644 lib/libc/include/any-freebsd-any/sys/consio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/copyright.h create mode 100644 lib/libc/include/any-freebsd-any/sys/counter.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cpu.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cpuctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/cpuset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ctype.h create mode 100644 lib/libc/include/any-freebsd-any/sys/devicestat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/devmap.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dir.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dirent.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk/apm.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk/bsd.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk/gpt.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk/mbr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk/vtoc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disk_zone.h create mode 100644 lib/libc/include/any-freebsd-any/sys/disklabel.h create mode 100644 lib/libc/include/any-freebsd-any/sys/diskmbr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dkstat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dnv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/domain.h create mode 100644 lib/libc/include/any-freebsd-any/sys/domainset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dtrace_bsd.h create mode 100644 lib/libc/include/any-freebsd-any/sys/dvdio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/efi.h create mode 100644 lib/libc/include/any-freebsd-any/sys/efiio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/elf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/elf32.h create mode 100644 lib/libc/include/any-freebsd-any/sys/elf64.h create mode 100644 lib/libc/include/any-freebsd-any/sys/elf_common.h create mode 100644 lib/libc/include/any-freebsd-any/sys/elf_generic.h create mode 100644 lib/libc/include/any-freebsd-any/sys/endian.h create mode 100644 lib/libc/include/any-freebsd-any/sys/epoch.h create mode 100644 lib/libc/include/any-freebsd-any/sys/errno.h create mode 100644 lib/libc/include/any-freebsd-any/sys/eui64.h create mode 100644 lib/libc/include/any-freebsd-any/sys/event.h create mode 100644 lib/libc/include/any-freebsd-any/sys/eventhandler.h create mode 100644 lib/libc/include/any-freebsd-any/sys/eventvar.h create mode 100644 lib/libc/include/any-freebsd-any/sys/exec.h create mode 100644 lib/libc/include/any-freebsd-any/sys/extattr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/fail.h create mode 100644 lib/libc/include/any-freebsd-any/sys/fbio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/fcntl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/fdcio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/file.h create mode 100644 lib/libc/include/any-freebsd-any/sys/filedesc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/filio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/firmware.h create mode 100644 lib/libc/include/any-freebsd-any/sys/fnv_hash.h create mode 100644 lib/libc/include/any-freebsd-any/sys/gmon.h create mode 100644 lib/libc/include/any-freebsd-any/sys/gpio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/gpt.h create mode 100644 lib/libc/include/any-freebsd-any/sys/gtaskqueue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/hash.h create mode 100644 lib/libc/include/any-freebsd-any/sys/hhook.h create mode 100644 lib/libc/include/any-freebsd-any/sys/iconv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/imgact.h create mode 100644 lib/libc/include/any-freebsd-any/sys/imgact_aout.h create mode 100644 lib/libc/include/any-freebsd-any/sys/imgact_binmisc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/imgact_elf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/inflate.h create mode 100644 lib/libc/include/any-freebsd-any/sys/interrupt.h create mode 100644 lib/libc/include/any-freebsd-any/sys/intr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ioccom.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ioctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ioctl_compat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/iov.h create mode 100644 lib/libc/include/any-freebsd-any/sys/iov_schema.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ipc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ipmi.h create mode 100644 lib/libc/include/any-freebsd-any/sys/jail.h create mode 100644 lib/libc/include/any-freebsd-any/sys/joystick.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kbio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kdb.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kenv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kern_prefetch.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kernel.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kerneldump.h create mode 100644 lib/libc/include/any-freebsd-any/sys/khelp.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kobj.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kpilite.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ksem.h create mode 100644 lib/libc/include/any-freebsd-any/sys/kthread.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ktr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ktr_class.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ktrace.h create mode 100644 lib/libc/include/any-freebsd-any/sys/libkern.h create mode 100644 lib/libc/include/any-freebsd-any/sys/limits.h create mode 100644 lib/libc/include/any-freebsd-any/sys/link_aout.h create mode 100644 lib/libc/include/any-freebsd-any/sys/link_elf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/linker.h create mode 100644 lib/libc/include/any-freebsd-any/sys/linker_set.h create mode 100644 lib/libc/include/any-freebsd-any/sys/lock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/lock_profile.h create mode 100644 lib/libc/include/any-freebsd-any/sys/lockf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/lockmgr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/lockstat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/loginclass.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mac.h create mode 100644 lib/libc/include/any-freebsd-any/sys/malloc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mbuf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mchain.h create mode 100644 lib/libc/include/any-freebsd-any/sys/md4.h create mode 100644 lib/libc/include/any-freebsd-any/sys/md5.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mdioctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/memdesc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/memrange.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mman.h create mode 100644 lib/libc/include/any-freebsd-any/sys/module.h create mode 100644 lib/libc/include/any-freebsd-any/sys/module_khelp.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mount.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mouse.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mpt_ioctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mqueue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/msg.h create mode 100644 lib/libc/include/any-freebsd-any/sys/msgbuf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mtio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/mutex.h create mode 100644 lib/libc/include/any-freebsd-any/sys/namei.h create mode 100644 lib/libc/include/any-freebsd-any/sys/nlist_aout.h create mode 100644 lib/libc/include/any-freebsd-any/sys/nv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/osd.h create mode 100644 lib/libc/include/any-freebsd-any/sys/param.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pciio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pcpu.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pctrie.h create mode 100644 lib/libc/include/any-freebsd-any/sys/physmem.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pidctrl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pioctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pipe.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pmc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pmckern.h create mode 100644 lib/libc/include/any-freebsd-any/sys/pmclog.h create mode 100644 lib/libc/include/any-freebsd-any/sys/poll.h create mode 100644 lib/libc/include/any-freebsd-any/sys/posix4.h create mode 100644 lib/libc/include/any-freebsd-any/sys/power.h create mode 100644 lib/libc/include/any-freebsd-any/sys/priority.h create mode 100644 lib/libc/include/any-freebsd-any/sys/priv.h create mode 100644 lib/libc/include/any-freebsd-any/sys/proc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/procctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/procdesc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/procfs.h create mode 100644 lib/libc/include/any-freebsd-any/sys/protosw.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ptio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ptrace.h create mode 100644 lib/libc/include/any-freebsd-any/sys/queue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/racct.h create mode 100644 lib/libc/include/any-freebsd-any/sys/random.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rangelock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rangeset.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/reboot.h create mode 100644 lib/libc/include/any-freebsd-any/sys/refcount.h create mode 100644 lib/libc/include/any-freebsd-any/sys/regression.h create mode 100644 lib/libc/include/any-freebsd-any/sys/resource.h create mode 100644 lib/libc/include/any-freebsd-any/sys/resourcevar.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rman.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rmlock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rtprio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/runq.h create mode 100644 lib/libc/include/any-freebsd-any/sys/rwlock.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sbuf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sched.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sdt.h create mode 100644 lib/libc/include/any-freebsd-any/sys/select.h create mode 100644 lib/libc/include/any-freebsd-any/sys/selinfo.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sem.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sema.h create mode 100644 lib/libc/include/any-freebsd-any/sys/seq.h create mode 100644 lib/libc/include/any-freebsd-any/sys/serial.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sf_buf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sglist.h create mode 100644 lib/libc/include/any-freebsd-any/sys/shm.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sigio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/signal.h create mode 100644 lib/libc/include/any-freebsd-any/sys/signalvar.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sleepqueue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/slicer.h create mode 100644 lib/libc/include/any-freebsd-any/sys/smp.h create mode 100644 lib/libc/include/any-freebsd-any/sys/snoop.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sockbuf.h create mode 100644 lib/libc/include/any-freebsd-any/sys/socket.h create mode 100644 lib/libc/include/any-freebsd-any/sys/socketvar.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sockio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sockopt.h create mode 100644 lib/libc/include/any-freebsd-any/sys/soundcard.h create mode 100644 lib/libc/include/any-freebsd-any/sys/spigenio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/stack.h create mode 100644 lib/libc/include/any-freebsd-any/sys/stat.h create mode 100644 lib/libc/include/any-freebsd-any/sys/statvfs.h create mode 100644 lib/libc/include/any-freebsd-any/sys/stdatomic.h create mode 100644 lib/libc/include/any-freebsd-any/sys/stddef.h create mode 100644 lib/libc/include/any-freebsd-any/sys/stdint.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sun_disklabel.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sx.h create mode 100644 lib/libc/include/any-freebsd-any/sys/syscall.h create mode 100644 lib/libc/include/any-freebsd-any/sys/syscall.mk create mode 100644 lib/libc/include/any-freebsd-any/sys/syscallsubr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sysctl.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sysent.h create mode 100644 lib/libc/include/any-freebsd-any/sys/syslimits.h create mode 100644 lib/libc/include/any-freebsd-any/sys/syslog.h create mode 100644 lib/libc/include/any-freebsd-any/sys/sysproto.h create mode 100644 lib/libc/include/any-freebsd-any/sys/systm.h create mode 100644 lib/libc/include/any-freebsd-any/sys/taskqueue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/terminal.h create mode 100644 lib/libc/include/any-freebsd-any/sys/termios.h create mode 100644 lib/libc/include/any-freebsd-any/sys/thr.h create mode 100644 lib/libc/include/any-freebsd-any/sys/tiio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/time.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timeb.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timeet.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timeffc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timepps.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timers.h create mode 100644 lib/libc/include/any-freebsd-any/sys/times.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timespec.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timetc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/timex.h create mode 100644 lib/libc/include/any-freebsd-any/sys/tree.h create mode 100644 lib/libc/include/any-freebsd-any/sys/tslog.h create mode 100644 lib/libc/include/any-freebsd-any/sys/tty.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttycom.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttydefaults.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttydevsw.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttydisc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttyhook.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ttyqueue.h create mode 100644 lib/libc/include/any-freebsd-any/sys/turnstile.h create mode 100644 lib/libc/include/any-freebsd-any/sys/types.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ucontext.h create mode 100644 lib/libc/include/any-freebsd-any/sys/ucred.h create mode 100644 lib/libc/include/any-freebsd-any/sys/uio.h create mode 100644 lib/libc/include/any-freebsd-any/sys/umtx.h create mode 100644 lib/libc/include/any-freebsd-any/sys/un.h create mode 100644 lib/libc/include/any-freebsd-any/sys/unistd.h create mode 100644 lib/libc/include/any-freebsd-any/sys/unpcb.h create mode 100644 lib/libc/include/any-freebsd-any/sys/user.h create mode 100644 lib/libc/include/any-freebsd-any/sys/utsname.h create mode 100644 lib/libc/include/any-freebsd-any/sys/uuid.h create mode 100644 lib/libc/include/any-freebsd-any/sys/vdso.h create mode 100644 lib/libc/include/any-freebsd-any/sys/vmem.h create mode 100644 lib/libc/include/any-freebsd-any/sys/vmmeter.h create mode 100644 lib/libc/include/any-freebsd-any/sys/vnode.h create mode 100644 lib/libc/include/any-freebsd-any/sys/vtoc.h create mode 100644 lib/libc/include/any-freebsd-any/sys/wait.h create mode 100644 lib/libc/include/any-freebsd-any/sys/watchdog.h create mode 100644 lib/libc/include/any-freebsd-any/sys/zlib.h create mode 100644 lib/libc/include/any-freebsd-any/sys/zutil.h create mode 100644 lib/libc/include/any-freebsd-any/sysexits.h create mode 120000 lib/libc/include/any-freebsd-any/syslog.h create mode 100644 lib/libc/include/any-freebsd-any/tar.h create mode 100644 lib/libc/include/any-freebsd-any/termios.h create mode 100644 lib/libc/include/any-freebsd-any/tgmath.h create mode 100644 lib/libc/include/any-freebsd-any/time.h create mode 100644 lib/libc/include/any-freebsd-any/timeconv.h create mode 100644 lib/libc/include/any-freebsd-any/timers.h create mode 100644 lib/libc/include/any-freebsd-any/ttyent.h create mode 100644 lib/libc/include/any-freebsd-any/uchar.h create mode 100644 lib/libc/include/any-freebsd-any/ulimit.h create mode 100644 lib/libc/include/any-freebsd-any/unistd.h create mode 100644 lib/libc/include/any-freebsd-any/unwind.h create mode 100644 lib/libc/include/any-freebsd-any/utime.h create mode 100644 lib/libc/include/any-freebsd-any/utmpx.h create mode 100644 lib/libc/include/any-freebsd-any/uuid.h create mode 100644 lib/libc/include/any-freebsd-any/varargs.h create mode 100644 lib/libc/include/any-freebsd-any/wchar.h create mode 100644 lib/libc/include/any-freebsd-any/wctype.h create mode 100644 lib/libc/include/any-freebsd-any/wordexp.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_ctype.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_inttypes.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_langinfo.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_locale.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_monetary.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_stdio.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_stdlib.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_string.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_strings.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_time.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_uchar.h create mode 100644 lib/libc/include/any-freebsd-any/xlocale/_wchar.h diff --git a/lib/libc/include/any-freebsd-any/_ctype.h b/lib/libc/include/any-freebsd-any/_ctype.h new file mode 100644 index 000000000000..96fbaeba00d6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/_ctype.h @@ -0,0 +1,189 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * From @(#)ctype.h 8.4 (Berkeley) 1/21/94 + * From FreeBSD: src/include/ctype.h,v 1.27 2004/06/23 07:11:39 tjr Exp + * $FreeBSD$ + */ + +#ifndef __CTYPE_H_ +#define __CTYPE_H_ + +#include +#include + +#define _CTYPE_A 0x00000100L /* Alpha */ +#define _CTYPE_C 0x00000200L /* Control */ +#define _CTYPE_D 0x00000400L /* Digit */ +#define _CTYPE_G 0x00000800L /* Graph */ +#define _CTYPE_L 0x00001000L /* Lower */ +#define _CTYPE_P 0x00002000L /* Punct */ +#define _CTYPE_S 0x00004000L /* Space */ +#define _CTYPE_U 0x00008000L /* Upper */ +#define _CTYPE_X 0x00010000L /* X digit */ +#define _CTYPE_B 0x00020000L /* Blank */ +#define _CTYPE_R 0x00040000L /* Print */ +#define _CTYPE_I 0x00080000L /* Ideogram */ +#define _CTYPE_T 0x00100000L /* Special */ +#define _CTYPE_Q 0x00200000L /* Phonogram */ +#define _CTYPE_N 0x00400000L /* Number (superset of digit) */ +#define _CTYPE_SW0 0x20000000L /* 0 width character */ +#define _CTYPE_SW1 0x40000000L /* 1 width character */ +#define _CTYPE_SW2 0x80000000L /* 2 width character */ +#define _CTYPE_SW3 0xc0000000L /* 3 width character */ +#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */ +#define _CTYPE_SWS 30 /* Bits to shift to get width */ + +/* See comments in about __ct_rune_t. */ +__BEGIN_DECLS +unsigned long ___runetype(__ct_rune_t) __pure; +__ct_rune_t ___tolower(__ct_rune_t) __pure; +__ct_rune_t ___toupper(__ct_rune_t) __pure; +__END_DECLS + +/* + * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us + * to generate code for extern versions of all our inline functions. + */ +#ifdef _EXTERNALIZE_CTYPE_INLINES_ +#define _USE_CTYPE_INLINE_ +#define static +#define __inline +#endif + +extern int __mb_sb_limit; + +/* + * Use inline functions if we are allowed to and the compiler supports them. + */ +#if !defined(_DONT_USE_CTYPE_INLINE_) && \ + (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) + +#include + +static __inline int +__maskrune(__ct_rune_t _c, unsigned long _f) +{ + return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : + _CurrentRuneLocale->__runetype[_c]) & _f; +} + +static __inline int +__sbmaskrune(__ct_rune_t _c, unsigned long _f) +{ + return (_c < 0 || _c >= __mb_sb_limit) ? 0 : + _CurrentRuneLocale->__runetype[_c] & _f; +} + +static __inline int +__istype(__ct_rune_t _c, unsigned long _f) +{ + return (!!__maskrune(_c, _f)); +} + +static __inline int +__sbistype(__ct_rune_t _c, unsigned long _f) +{ + return (!!__sbmaskrune(_c, _f)); +} + +static __inline int +__isctype(__ct_rune_t _c, unsigned long _f) +{ + return (_c < 0 || _c >= 128) ? 0 : + !!(_DefaultRuneLocale.__runetype[_c] & _f); +} + +static __inline __ct_rune_t +__toupper(__ct_rune_t _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : + _CurrentRuneLocale->__mapupper[_c]; +} + +static __inline __ct_rune_t +__sbtoupper(__ct_rune_t _c) +{ + return (_c < 0 || _c >= __mb_sb_limit) ? _c : + _CurrentRuneLocale->__mapupper[_c]; +} + +static __inline __ct_rune_t +__tolower(__ct_rune_t _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : + _CurrentRuneLocale->__maplower[_c]; +} + +static __inline __ct_rune_t +__sbtolower(__ct_rune_t _c) +{ + return (_c < 0 || _c >= __mb_sb_limit) ? _c : + _CurrentRuneLocale->__maplower[_c]; +} + +static __inline int +__wcwidth(__ct_rune_t _c) +{ + unsigned int _x; + + if (_c == 0) + return (0); + _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R); + if ((_x & _CTYPE_SWM) != 0) + return ((_x & _CTYPE_SWM) >> _CTYPE_SWS); + return ((_x & _CTYPE_R) != 0 ? 1 : -1); +} + +#else /* not using inlines */ + +__BEGIN_DECLS +int __maskrune(__ct_rune_t, unsigned long); +int __sbmaskrune(__ct_rune_t, unsigned long); +int __istype(__ct_rune_t, unsigned long); +int __sbistype(__ct_rune_t, unsigned long); +int __isctype(__ct_rune_t, unsigned long); +__ct_rune_t __toupper(__ct_rune_t); +__ct_rune_t __sbtoupper(__ct_rune_t); +__ct_rune_t __tolower(__ct_rune_t); +__ct_rune_t __sbtolower(__ct_rune_t); +int __wcwidth(__ct_rune_t); +__END_DECLS +#endif /* using inlines */ + +#endif /* !__CTYPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/a.out.h b/lib/libc/include/any-freebsd-any/a.out.h new file mode 100644 index 000000000000..d532d062cacf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/a.out.h @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)a.out.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _AOUT_H_ +#define _AOUT_H_ + +#include +#include +#include +#include +#include + +#define _AOUT_INCLUDE_ +#include + +#endif /* !_AOUT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ar.h b/lib/libc/include/any-freebsd-any/ar.h new file mode 100644 index 000000000000..01a57a57d785 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ar.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Hugh Smith at The University of Guelph. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ar.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD$ + */ + +#ifndef _AR_H_ +#define _AR_H_ + +#include + +/* Pre-4BSD archives had these magic numbers in them. */ +#define OARMAG1 0177555 +#define OARMAG2 0177545 + +#define ARMAG "!\n" /* ar "magic number" */ +#define SARMAG 8 /* strlen(ARMAG); */ + +#define AR_EFMT1 "#1/" /* extended format #1 */ + +struct ar_hdr { + char ar_name[16]; /* name */ + char ar_date[12]; /* modification time */ + char ar_uid[6]; /* user id */ + char ar_gid[6]; /* group id */ + char ar_mode[8]; /* octal file permissions */ + char ar_size[10]; /* size in bytes */ +#define ARFMAG "`\n" + char ar_fmag[2]; /* consistency check */ +} __packed; + +#endif /* !_AR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/arpa/ftp.h b/lib/libc/include/any-freebsd-any/arpa/ftp.h new file mode 100644 index 000000000000..5ba431529404 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/ftp.h @@ -0,0 +1,109 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ftp.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _ARPA_FTP_H_ +#define _ARPA_FTP_H_ + +/* Definitions for FTP; see RFC-765. */ + +/* + * Reply codes. + */ +#define PRELIM 1 /* positive preliminary */ +#define COMPLETE 2 /* positive completion */ +#define CONTINUE 3 /* positive intermediate */ +#define TRANSIENT 4 /* transient negative completion */ +#define ERROR 5 /* permanent negative completion */ + +/* + * Type codes + */ +#define TYPE_A 1 /* ASCII */ +#define TYPE_E 2 /* EBCDIC */ +#define TYPE_I 3 /* image */ +#define TYPE_L 4 /* local byte size */ + +#ifdef FTP_NAMES +char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; +#endif + +/* + * Form codes + */ +#define FORM_N 1 /* non-print */ +#define FORM_T 2 /* telnet format effectors */ +#define FORM_C 3 /* carriage control (ASA) */ +#ifdef FTP_NAMES +char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; +#endif + +/* + * Structure codes + */ +#define STRU_F 1 /* file (no record structure) */ +#define STRU_R 2 /* record structure */ +#define STRU_P 3 /* page structure */ +#ifdef FTP_NAMES +char *strunames[] = {"0", "File", "Record", "Page" }; +#endif + +/* + * Mode types + */ +#define MODE_S 1 /* stream */ +#define MODE_B 2 /* block */ +#define MODE_C 3 /* compressed */ +#ifdef FTP_NAMES +char *modenames[] = {"0", "Stream", "Block", "Compressed" }; +#endif + +/* + * Record Tokens + */ +#define REC_ESC '\377' /* Record-mode Escape */ +#define REC_EOR '\001' /* Record-mode End-of-Record */ +#define REC_EOF '\002' /* Record-mode End-of-File */ + +/* + * Block Header + */ +#define BLK_EOR 0x80 /* Block is End-of-Record */ +#define BLK_EOF 0x40 /* Block is End-of-File */ +#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */ +#define BLK_RESTART 0x10 /* Block is Restart Marker */ + +#define BLK_BYTECOUNT 2 /* Bytes in this block */ + +#endif /* !_FTP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/arpa/inet.h b/lib/libc/include/any-freebsd-any/arpa/inet.h new file mode 100644 index 000000000000..357a444a0d2e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/inet.h @@ -0,0 +1,180 @@ +/*- + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) + * + * ++Copyright++ 1983, 1993 + * - + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- + */ + +/*% + * @(#)inet.h 8.1 (Berkeley) 6/2/93 + * $Id: inet.h,v 1.3 2005/04/27 04:56:16 sra Exp $ + * $FreeBSD$ + */ + +#ifndef _ARPA_INET_H_ +#define _ARPA_INET_H_ + +/* External definitions for functions in inet(3). */ + +#include +#include + +/* Required for byteorder(3) functions. */ +#include + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _IN_ADDR_T_DECLARED +typedef uint32_t in_addr_t; +#define _IN_ADDR_T_DECLARED +#endif + +#ifndef _IN_PORT_T_DECLARED +typedef uint16_t in_port_t; +#define _IN_PORT_T_DECLARED +#endif + +#if __BSD_VISIBLE +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif +#endif + +/* + * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by + * POSIX.1-2001. + */ +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _STRUCT_IN_ADDR_DECLARED +struct in_addr { + in_addr_t s_addr; +}; +#define _STRUCT_IN_ADDR_DECLARED +#endif + +/* XXX all new diversions!! argh!! */ +#if __BSD_VISIBLE +#define inet_addr __inet_addr +#define inet_aton __inet_aton +#define inet_lnaof __inet_lnaof +#define inet_makeaddr __inet_makeaddr +#define inet_neta __inet_neta +#define inet_netof __inet_netof +#define inet_network __inet_network +#define inet_net_ntop __inet_net_ntop +#define inet_net_pton __inet_net_pton +#define inet_cidr_ntop __inet_cidr_ntop +#define inet_cidr_pton __inet_cidr_pton +#define inet_ntoa __inet_ntoa +#define inet_ntoa_r __inet_ntoa_r +#define inet_pton __inet_pton +#define inet_ntop __inet_ntop +#define inet_nsap_addr __inet_nsap_addr +#define inet_nsap_ntoa __inet_nsap_ntoa +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +uint32_t htonl(uint32_t); +uint16_t htons(uint16_t); +uint32_t ntohl(uint32_t); +uint16_t ntohs(uint16_t); +#endif + +in_addr_t inet_addr(const char *); +/*const*/ char *inet_ntoa(struct in_addr); +const char *inet_ntop(int, const void * __restrict, char * __restrict, + socklen_t); +int inet_pton(int, const char * __restrict, void * __restrict); + +#if __BSD_VISIBLE +int inet_aton(const char *, struct in_addr *); +in_addr_t inet_lnaof(struct in_addr); +struct in_addr inet_makeaddr(in_addr_t, in_addr_t); +char * inet_neta(in_addr_t, char *, size_t); +in_addr_t inet_netof(struct in_addr); +in_addr_t inet_network(const char *); +char *inet_net_ntop(int, const void *, int, char *, size_t); +int inet_net_pton(int, const char *, void *, size_t); +char *inet_ntoa_r(struct in_addr, char *buf, socklen_t size); +char *inet_cidr_ntop(int, const void *, int, char *, size_t); +int inet_cidr_pton(int, const char *, void *, int *); +unsigned inet_nsap_addr(const char *, unsigned char *, int); +char *inet_nsap_ntoa(int, const unsigned char *, char *); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif + +#endif /* !_ARPA_INET_H_ */ + +/*! \file */ diff --git a/lib/libc/include/any-freebsd-any/arpa/nameser.h b/lib/libc/include/any-freebsd-any/arpa/nameser.h new file mode 100644 index 000000000000..5dcc4f3b911c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/nameser.h @@ -0,0 +1,682 @@ +/*- + * SPDX-License-Identifier: (ISC AND BSD-3-Clause) + * + * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/*- + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * $Id: nameser.h,v 1.16 2009/03/03 01:52:48 each Exp $ + * $FreeBSD$ + */ + +#ifndef _ARPA_NAMESER_H_ +#define _ARPA_NAMESER_H_ + +/*! \file */ + +#define BIND_4_COMPAT + +#include +#include +#include + +/*% + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not + * compare for equality; rather, use it to determine whether your libbind.a + * contains a new enough lib/nameser/ to support the feature you need. + */ + +#define __NAMESER 20090302 /*%< New interface version stamp. */ +/* + * Define constants based on RFC0883, RFC1034, RFC 1035 + */ +#define NS_PACKETSZ 512 /*%< default UDP packet size */ +#define NS_MAXDNAME 1025 /*%< maximum domain name (presentation format)*/ +#define NS_MAXMSG 65535 /*%< maximum message size */ +#define NS_MAXCDNAME 255 /*%< maximum compressed domain name */ +#define NS_MAXLABEL 63 /*%< maximum length of domain label */ +#define NS_MAXLABELS 128 /*%< theoretical max #/labels per domain name */ +#define NS_MAXNNAME 256 /*%< maximum uncompressed (binary) domain name*/ +#define NS_MAXPADDR (sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") +#define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */ +#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */ +#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */ +#define NS_INT8SZ 1 /*%< #/bytes of data in a u_int8_t */ +#define NS_INADDRSZ 4 /*%< IPv4 T_A */ +#define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */ +#define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */ +/* + * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() + * in synch with it. + */ +typedef enum __ns_sect { + ns_s_qd = 0, /*%< Query: Question. */ + ns_s_zn = 0, /*%< Update: Zone. */ + ns_s_an = 1, /*%< Query: Answer. */ + ns_s_pr = 1, /*%< Update: Prerequisites. */ + ns_s_ns = 2, /*%< Query: Name servers. */ + ns_s_ud = 2, /*%< Update: Update. */ + ns_s_ar = 3, /*%< Query|Update: Additional records. */ + ns_s_max = 4 +} ns_sect; + +/*% + * Network name (compressed or not) type. Equivalent to a pointer when used + * in a function prototype. Can be const'd. + */ +typedef u_char ns_nname[NS_MAXNNAME]; +typedef const u_char *ns_nname_ct; +typedef u_char *ns_nname_t; + +struct ns_namemap { ns_nname_ct base; int len; }; +typedef struct ns_namemap *ns_namemap_t; +typedef const struct ns_namemap *ns_namemap_ct; + +/*% + * This is a message handle. It is caller allocated and has no dynamic data. + * This structure is intended to be opaque to all but ns_parse.c, thus the + * leading _'s on the member names. Use the accessor functions, not the _'s. + */ +typedef struct __ns_msg { + const u_char *_msg, *_eom; + u_int16_t _id, _flags, _counts[ns_s_max]; + const u_char *_sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const u_char *_msg_ptr; +} ns_msg; + +/* + * This is a newmsg handle, used when constructing new messages with + * ns_newmsg_init, et al. + */ +struct ns_newmsg { + ns_msg msg; + const u_char *dnptrs[25]; + const u_char **lastdnptr; +}; +typedef struct ns_newmsg ns_newmsg; + +/* Private data structure - do not use from outside library. */ +struct _ns_flagdata { int mask, shift; }; +extern struct _ns_flagdata _ns_flagdata[]; + +/* Accessor macros - this is part of the public interface. */ + +#define ns_msg_id(handle) ((handle)._id + 0) +#define ns_msg_base(handle) ((handle)._msg + 0) +#define ns_msg_end(handle) ((handle)._eom + 0) +#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) +#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) + +/*% + * This is a parsed record. It is caller allocated and has no dynamic data. + */ +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + u_int16_t type; + u_int16_t rr_class; + u_int32_t ttl; + u_int16_t rdlength; + const u_char * rdata; +} ns_rr; + +/* + * Same thing, but using uncompressed network binary names, and real C types. + */ +typedef struct __ns_rr2 { + ns_nname nname; + size_t nnamel; + int type; + int rr_class; + u_int ttl; + int rdlength; + const u_char * rdata; +} ns_rr2; + +/* Accessor macros - this is part of the public interface. */ +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_nname(rr) ((const ns_nname_t)(rr).nname) +#define ns_rr_nnamel(rr) ((rr).nnamel + 0) +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +/*% + * These don't have to be in the same order as in the packet flags word, + * and they can even overlap in some cases, but they will need to be kept + * in synch with ns_parse.c:ns_flagdata[]. + */ +typedef enum __ns_flag { + ns_f_qr, /*%< Question/Response. */ + ns_f_opcode, /*%< Operation code. */ + ns_f_aa, /*%< Authoritative Answer. */ + ns_f_tc, /*%< Truncation occurred. */ + ns_f_rd, /*%< Recursion Desired. */ + ns_f_ra, /*%< Recursion Available. */ + ns_f_z, /*%< MBZ. */ + ns_f_ad, /*%< Authentic Data (DNSSEC). */ + ns_f_cd, /*%< Checking Disabled (DNSSEC). */ + ns_f_rcode, /*%< Response code. */ + ns_f_max +} ns_flag; + +/*% + * Currently defined opcodes. + */ +typedef enum __ns_opcode { + ns_o_query = 0, /*%< Standard query. */ + ns_o_iquery = 1, /*%< Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /*%< Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /*%< Zone change notification. */ + ns_o_update = 5, /*%< Zone update message. */ + ns_o_max = 6 +} ns_opcode; + +/*% + * Currently defined response codes. + */ +typedef enum __ns_rcode { + ns_r_noerror = 0, /*%< No error occurred. */ + ns_r_formerr = 1, /*%< Format error. */ + ns_r_servfail = 2, /*%< Server failure. */ + ns_r_nxdomain = 3, /*%< Name error. */ + ns_r_notimpl = 4, /*%< Unimplemented. */ + ns_r_refused = 5, /*%< Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /*%< Name exists */ + ns_r_yxrrset = 7, /*%< RRset exists */ + ns_r_nxrrset = 8, /*%< RRset does not exist */ + ns_r_notauth = 9, /*%< Not authoritative for zone */ + ns_r_notzone = 10, /*%< Zone of record different from zone section */ + ns_r_max = 11, + /* The following are EDNS extended rcodes */ + ns_r_badvers = 16, + /* The following are TSIG errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 +} ns_rcode; + +/* BIND_UPDATE */ +typedef enum __ns_update_operation { + ns_uop_delete = 0, + ns_uop_add = 1, + ns_uop_max = 2 +} ns_update_operation; + +/*% + * This structure is used for TSIG authenticated messages + */ +struct ns_tsig_key { + char name[NS_MAXDNAME], alg[NS_MAXDNAME]; + unsigned char *data; + int len; +}; +typedef struct ns_tsig_key ns_tsig_key; + +/*% + * This structure is used for TSIG authenticated TCP messages + */ +struct ns_tcp_tsig_state { + int counter; + struct dst_key *key; + void *ctx; + unsigned char sig[NS_PACKETSZ]; + int siglen; +}; +typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; + +#define NS_TSIG_FUDGE 300 +#define NS_TSIG_TCP_COUNT 100 +#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" + +#define NS_TSIG_ERROR_NO_TSIG -10 +#define NS_TSIG_ERROR_NO_SPACE -11 +#define NS_TSIG_ERROR_FORMERR -12 + +/*% + * Currently defined type values for resources and queries. + */ +typedef enum __ns_type { + ns_t_invalid = 0, /*%< Cookie. */ + ns_t_a = 1, /*%< Host address. */ + ns_t_ns = 2, /*%< Authoritative server. */ + ns_t_md = 3, /*%< Mail destination. */ + ns_t_mf = 4, /*%< Mail forwarder. */ + ns_t_cname = 5, /*%< Canonical name. */ + ns_t_soa = 6, /*%< Start of authority zone. */ + ns_t_mb = 7, /*%< Mailbox domain name. */ + ns_t_mg = 8, /*%< Mail group member. */ + ns_t_mr = 9, /*%< Mail rename name. */ + ns_t_null = 10, /*%< Null resource record. */ + ns_t_wks = 11, /*%< Well known service. */ + ns_t_ptr = 12, /*%< Domain name pointer. */ + ns_t_hinfo = 13, /*%< Host information. */ + ns_t_minfo = 14, /*%< Mailbox information. */ + ns_t_mx = 15, /*%< Mail routing information. */ + ns_t_txt = 16, /*%< Text strings. */ + ns_t_rp = 17, /*%< Responsible person. */ + ns_t_afsdb = 18, /*%< AFS cell database. */ + ns_t_x25 = 19, /*%< X_25 calling address. */ + ns_t_isdn = 20, /*%< ISDN calling address. */ + ns_t_rt = 21, /*%< Router. */ + ns_t_nsap = 22, /*%< NSAP address. */ + ns_t_nsap_ptr = 23, /*%< Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /*%< Security signature. */ + ns_t_key = 25, /*%< Security key. */ + ns_t_px = 26, /*%< X.400 mail mapping. */ + ns_t_gpos = 27, /*%< Geographical position (withdrawn). */ + ns_t_aaaa = 28, /*%< IPv6 Address. */ + ns_t_loc = 29, /*%< Location Information. */ + ns_t_nxt = 30, /*%< Next domain (security). */ + ns_t_eid = 31, /*%< Endpoint identifier. */ + ns_t_nimloc = 32, /*%< Nimrod Locator. */ + ns_t_srv = 33, /*%< Server Selection. */ + ns_t_atma = 34, /*%< ATM Address */ + ns_t_naptr = 35, /*%< Naming Authority PoinTeR */ + ns_t_kx = 36, /*%< Key Exchange */ + ns_t_cert = 37, /*%< Certification record */ + ns_t_a6 = 38, /*%< IPv6 address (experimental) */ + ns_t_dname = 39, /*%< Non-terminal DNAME */ + ns_t_sink = 40, /*%< Kitchen sink (experimentatl) */ + ns_t_opt = 41, /*%< EDNS0 option (meta-RR) */ + ns_t_apl = 42, /*%< Address prefix list (RFC3123) */ + ns_t_ds = 43, /*%< Delegation Signer */ + ns_t_sshfp = 44, /*%< SSH Fingerprint */ + ns_t_ipseckey = 45, /*%< IPSEC Key */ + ns_t_rrsig = 46, /*%< RRset Signature */ + ns_t_nsec = 47, /*%< Negative security */ + ns_t_dnskey = 48, /*%< DNS Key */ + ns_t_dhcid = 49, /*%< Dynamic host configuratin identifier */ + ns_t_nsec3 = 50, /*%< Negative security type 3 */ + ns_t_nsec3param = 51, /*%< Negative security type 3 parameters */ + ns_t_hip = 55, /*%< Host Identity Protocol */ + ns_t_spf = 99, /*%< Sender Policy Framework */ + ns_t_tkey = 249, /*%< Transaction key */ + ns_t_tsig = 250, /*%< Transaction signature. */ + ns_t_ixfr = 251, /*%< Incremental zone transfer. */ + ns_t_axfr = 252, /*%< Transfer zone of authority. */ + ns_t_mailb = 253, /*%< Transfer mailbox records. */ + ns_t_maila = 254, /*%< Transfer mail agent records. */ + ns_t_any = 255, /*%< Wildcard match. */ + ns_t_zxfr = 256, /*%< BIND-specific, nonstandard. */ + ns_t_dlv = 32769, /*%< DNSSEC look-aside validatation. */ + ns_t_max = 65536 +} ns_type; + +/* Exclusively a QTYPE? (not also an RTYPE) */ +#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ + (t) == ns_t_mailb || (t) == ns_t_maila) +/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */ +#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) +/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */ +#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) +#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) +#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ + (t) == ns_t_zxfr) + +/*% + * Values for class field + */ +typedef enum __ns_class { + ns_c_invalid = 0, /*%< Cookie. */ + ns_c_in = 1, /*%< Internet. */ + ns_c_2 = 2, /*%< unallocated/unsupported. */ + ns_c_chaos = 3, /*%< MIT Chaos-net. */ + ns_c_hs = 4, /*%< MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /*%< for prereq. sections in update requests */ + ns_c_any = 255, /*%< Wildcard match. */ + ns_c_max = 65536 +} ns_class; + +/* DNSSEC constants. */ + +typedef enum __ns_key_types { + ns_kt_rsa = 1, /*%< key type RSA/MD5 */ + ns_kt_dh = 2, /*%< Diffie Hellman */ + ns_kt_dsa = 3, /*%< Digital Signature Standard (MANDATORY) */ + ns_kt_private = 254 /*%< Private key type starts with OID */ +} ns_key_types; + +typedef enum __ns_cert_types { + cert_t_pkix = 1, /*%< PKIX (X.509v3) */ + cert_t_spki = 2, /*%< SPKI */ + cert_t_pgp = 3, /*%< PGP */ + cert_t_url = 253, /*%< URL private type */ + cert_t_oid = 254 /*%< OID private type */ +} ns_cert_types; + +/* Flags field of the KEY RR rdata. */ +#define NS_KEY_TYPEMASK 0xC000 /*%< Mask for "type" bits */ +#define NS_KEY_TYPE_AUTH_CONF 0x0000 /*%< Key usable for both */ +#define NS_KEY_TYPE_CONF_ONLY 0x8000 /*%< Key usable for confidentiality */ +#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /*%< Key usable for authentication */ +#define NS_KEY_TYPE_NO_KEY 0xC000 /*%< No key usable for either; no key */ +/* The type bits can also be interpreted independently, as single bits: */ +#define NS_KEY_NO_AUTH 0x8000 /*%< Key unusable for authentication */ +#define NS_KEY_NO_CONF 0x4000 /*%< Key unusable for confidentiality */ +#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ +#define NS_KEY_EXTENDED_FLAGS 0x1000 /*%< reserved - must be zero */ +#define NS_KEY_RESERVED4 0x0800 /*%< reserved - must be zero */ +#define NS_KEY_RESERVED5 0x0400 /*%< reserved - must be zero */ +#define NS_KEY_NAME_TYPE 0x0300 /*%< these bits determine the type */ +#define NS_KEY_NAME_USER 0x0000 /*%< key is assoc. with user */ +#define NS_KEY_NAME_ENTITY 0x0200 /*%< key is assoc. with entity eg host */ +#define NS_KEY_NAME_ZONE 0x0100 /*%< key is zone key */ +#define NS_KEY_NAME_RESERVED 0x0300 /*%< reserved meaning */ +#define NS_KEY_RESERVED8 0x0080 /*%< reserved - must be zero */ +#define NS_KEY_RESERVED9 0x0040 /*%< reserved - must be zero */ +#define NS_KEY_RESERVED10 0x0020 /*%< reserved - must be zero */ +#define NS_KEY_RESERVED11 0x0010 /*%< reserved - must be zero */ +#define NS_KEY_SIGNATORYMASK 0x000F /*%< key can sign RR's of same name */ +#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ + NS_KEY_RESERVED4 | \ + NS_KEY_RESERVED5 | \ + NS_KEY_RESERVED8 | \ + NS_KEY_RESERVED9 | \ + NS_KEY_RESERVED10 | \ + NS_KEY_RESERVED11 ) +#define NS_KEY_RESERVED_BITMASK2 0xFFFF /*%< no bits defined here */ +/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ +#define NS_ALG_MD5RSA 1 /*%< MD5 with RSA */ +#define NS_ALG_DH 2 /*%< Diffie Hellman KEY */ +#define NS_ALG_DSA 3 /*%< DSA KEY */ +#define NS_ALG_DSS NS_ALG_DSA +#define NS_ALG_EXPIRE_ONLY 253 /*%< No alg, no security */ +#define NS_ALG_PRIVATE_OID 254 /*%< Key begins with OID giving alg */ +/* Protocol values */ +/* value 0 is reserved */ +#define NS_KEY_PROT_TLS 1 +#define NS_KEY_PROT_EMAIL 2 +#define NS_KEY_PROT_DNSSEC 3 +#define NS_KEY_PROT_IPSEC 4 +#define NS_KEY_PROT_ANY 255 + +/* Signatures */ +#define NS_MD5RSA_MIN_BITS 512 /*%< Size of a mod or exp in bits */ +#define NS_MD5RSA_MAX_BITS 4096 + /* Total of binary mod and exp */ +#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) + /* Max length of text sig block */ +#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) +#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) +#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) + +#define NS_DSA_SIG_SIZE 41 +#define NS_DSA_MIN_SIZE 213 +#define NS_DSA_MAX_BYTES 405 + +/* Offsets into SIG record rdata to find various values */ +#define NS_SIG_TYPE 0 /*%< Type flags */ +#define NS_SIG_ALG 2 /*%< Algorithm */ +#define NS_SIG_LABELS 3 /*%< How many labels in name */ +#define NS_SIG_OTTL 4 /*%< Original TTL */ +#define NS_SIG_EXPIR 8 /*%< Expiration time */ +#define NS_SIG_SIGNED 12 /*%< Signature time */ +#define NS_SIG_FOOT 16 /*%< Key footprint */ +#define NS_SIG_SIGNER 18 /*%< Domain name of who signed it */ +/* How RR types are represented as bit-flags in NXT records */ +#define NS_NXT_BITS 8 +#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_MAX 127 + +/*% + * EDNS0 extended flags and option codes, host order. + */ +#define NS_OPT_DNSSEC_OK 0x8000U +#define NS_OPT_NSID 3 + +/*% + * Inline versions of get/put short/long. Pointer is advanced. + */ +#define NS_GET16(s, cp) do { \ + register const u_char *t_cp = (const u_char *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) \ + | ((u_int16_t)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ +} while (0) + +#define NS_GET32(l, cp) do { \ + register const u_char *t_cp = (const u_char *)(cp); \ + (l) = ((u_int32_t)t_cp[0] << 24) \ + | ((u_int32_t)t_cp[1] << 16) \ + | ((u_int32_t)t_cp[2] << 8) \ + | ((u_int32_t)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ +} while (0) + +#define NS_PUT16(s, cp) do { \ + register u_int16_t t_s = (u_int16_t)(s); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += NS_INT16SZ; \ +} while (0) + +#define NS_PUT32(l, cp) do { \ + register u_int32_t t_l = (u_int32_t)(l); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += NS_INT32SZ; \ +} while (0) + +/*% + * ANSI C identifier hiding for bind's lib/nameser. + */ +#define ns_msg_getflag __ns_msg_getflag +#define ns_get16 __ns_get16 +#define ns_get32 __ns_get32 +#define ns_put16 __ns_put16 +#define ns_put32 __ns_put32 +#define ns_initparse __ns_initparse +#define ns_skiprr __ns_skiprr +#define ns_parserr __ns_parserr +#define ns_parserr2 __ns_parserr2 +#define ns_sprintrr __ns_sprintrr +#define ns_sprintrrf __ns_sprintrrf +#define ns_format_ttl __ns_format_ttl +#define ns_parse_ttl __ns_parse_ttl +#if 0 +#define ns_datetosecs __ns_datetosecs +#endif +#define ns_name_ntol __ns_name_ntol +#define ns_name_ntop __ns_name_ntop +#define ns_name_pton __ns_name_pton +#define ns_name_pton2 __ns_name_pton2 +#define ns_name_unpack __ns_name_unpack +#define ns_name_unpack2 __ns_name_unpack2 +#define ns_name_pack __ns_name_pack +#define ns_name_compress __ns_name_compress +#define ns_name_uncompress __ns_name_uncompress +#define ns_name_skip __ns_name_skip +#define ns_name_rollback __ns_name_rollback +#define ns_name_length __ns_name_length +#define ns_name_eq __ns_name_eq +#define ns_name_owned __ns_name_owned +#define ns_name_map __ns_name_map +#define ns_name_labels __ns_name_labels +#if 0 +#define ns_sign __ns_sign +#define ns_sign2 __ns_sign2 +#define ns_sign_tcp __ns_sign_tcp +#define ns_sign_tcp2 __ns_sign_tcp2 +#define ns_sign_tcp_init __ns_sign_tcp_init +#define ns_find_tsig __ns_find_tsig +#define ns_verify __ns_verify +#define ns_verify_tcp __ns_verify_tcp +#define ns_verify_tcp_init __ns_verify_tcp_init +#endif +#define ns_samedomain __ns_samedomain +#if 0 +#define ns_subdomain __ns_subdomain +#endif +#define ns_makecanon __ns_makecanon +#define ns_samename __ns_samename +#define ns_newmsg_init __ns_newmsg_init +#define ns_newmsg_copy __ns_newmsg_copy +#define ns_newmsg_id __ns_newmsg_id +#define ns_newmsg_flag __ns_newmsg_flag +#define ns_newmsg_q __ns_newmsg_q +#define ns_newmsg_rr __ns_newmsg_rr +#define ns_newmsg_done __ns_newmsg_done +#define ns_rdata_unpack __ns_rdata_unpack +#define ns_rdata_equal __ns_rdata_equal +#define ns_rdata_refers __ns_rdata_refers + +__BEGIN_DECLS +int ns_msg_getflag(ns_msg, int); +u_int ns_get16(const u_char *); +u_long ns_get32(const u_char *); +void ns_put16(u_int, u_char *); +void ns_put32(u_long, u_char *); +int ns_initparse(const u_char *, int, ns_msg *); +int ns_skiprr(const u_char *, const u_char *, ns_sect, int); +int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); +int ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *); +int ns_sprintrr(const ns_msg *, const ns_rr *, + const char *, const char *, char *, size_t); +int ns_sprintrrf(const u_char *, size_t, const char *, + ns_class, ns_type, u_long, const u_char *, + size_t, const char *, const char *, + char *, size_t); +int ns_format_ttl(u_long, char *, size_t); +int ns_parse_ttl(const char *, u_long *); +#if 0 +u_int32_t ns_datetosecs(const char *cp, int *errp); +#endif +int ns_name_ntol(const u_char *, u_char *, size_t); +int ns_name_ntop(const u_char *, char *, size_t); +int ns_name_pton(const char *, u_char *, size_t); +int ns_name_pton2(const char *, u_char *, size_t, size_t *); +int ns_name_unpack(const u_char *, const u_char *, + const u_char *, u_char *, size_t); +int ns_name_unpack2(const u_char *, const u_char *, + const u_char *, u_char *, size_t, + size_t *); +int ns_name_pack(const u_char *, u_char *, int, + const u_char **, const u_char **); +int ns_name_uncompress(const u_char *, const u_char *, + const u_char *, char *, size_t); +int ns_name_compress(const char *, u_char *, size_t, + const u_char **, const u_char **); +int ns_name_skip(const u_char **, const u_char *); +void ns_name_rollback(const u_char *, const u_char **, + const u_char **); +ssize_t ns_name_length(ns_nname_ct, size_t); +int ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t); +int ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int); +int ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int); +int ns_name_labels(ns_nname_ct, size_t); +#if 0 +int ns_sign(u_char *, int *, int, int, void *, + const u_char *, int, u_char *, int *, time_t); +int ns_sign2(u_char *, int *, int, int, void *, + const u_char *, int, u_char *, int *, time_t, + u_char **, u_char **); +int ns_sign_tcp(u_char *, int *, int, int, + ns_tcp_tsig_state *, int); +int ns_sign_tcp2(u_char *, int *, int, int, + ns_tcp_tsig_state *, int, + u_char **, u_char **); +int ns_sign_tcp_init(void *, const u_char *, int, + ns_tcp_tsig_state *); +u_char *ns_find_tsig(u_char *, u_char *); +int ns_verify(u_char *, int *, void *, + const u_char *, int, u_char *, int *, + time_t *, int); +int ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int); +int ns_verify_tcp_init(void *, const u_char *, int, + ns_tcp_tsig_state *); +#endif +int ns_samedomain(const char *, const char *); +#if 0 +int ns_subdomain(const char *, const char *); +#endif +int ns_makecanon(const char *, char *, size_t); +int ns_samename(const char *, const char *); +int ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *); +int ns_newmsg_copy(ns_newmsg *, ns_msg *); +void ns_newmsg_id(ns_newmsg *handle, u_int16_t id); +void ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value); +int ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname, + ns_type qtype, ns_class qclass); +int ns_newmsg_rr(ns_newmsg *handle, ns_sect sect, + ns_nname_ct name, ns_type type, + ns_class rr_class, u_int32_t ttl, + u_int16_t rdlen, const u_char *rdata); +size_t ns_newmsg_done(ns_newmsg *handle); +ssize_t ns_rdata_unpack(const u_char *, const u_char *, ns_type, + const u_char *, size_t, u_char *, size_t); +int ns_rdata_equal(ns_type, + const u_char *, size_t, + const u_char *, size_t); +int ns_rdata_refers(ns_type, + const u_char *, size_t, + const u_char *); +__END_DECLS + +#ifdef BIND_4_COMPAT +#include +#endif + +#endif /* !_ARPA_NAMESER_H_ */ +/*! \file */ diff --git a/lib/libc/include/any-freebsd-any/arpa/nameser_compat.h b/lib/libc/include/any-freebsd-any/arpa/nameser_compat.h new file mode 100644 index 000000000000..7562984ab0ff --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/nameser_compat.h @@ -0,0 +1,203 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1989 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*% + * from nameser.h 8.1 (Berkeley) 6/2/93 + * $Id: nameser_compat.h,v 1.8 2006/05/19 02:33:40 marka Exp $ + * $FreeBSD$ + */ + +#ifndef _ARPA_NAMESER_COMPAT_ +#define _ARPA_NAMESER_COMPAT_ + +#define __BIND 19950621 /*%< (DEAD) interface version stamp. */ + +#include + +#if !defined(_BYTE_ORDER) || \ + (_BYTE_ORDER != _BIG_ENDIAN && _BYTE_ORDER != _LITTLE_ENDIAN && \ + _BYTE_ORDER != _PDP_ENDIAN) + /* you must determine what the correct bit order is for + * your compiler - the next line is an intentional error + * which will force your compiles to bomb until you fix + * the above macros. + */ +#error "Undefined or invalid _BYTE_ORDER"; +#endif + +/*% + * Structure for query header. The order of the fields is machine- and + * compiler-dependent, depending on the byte/bit order and the layout + * of bit fields. We use bit fields only in int variables, as this + * is all ANSI requires. This requires a somewhat confusing rearrangement. + */ + +typedef struct { + unsigned id :16; /*%< query identification number */ +#if _BYTE_ORDER == _BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /*%< response flag */ + unsigned opcode: 4; /*%< purpose of message */ + unsigned aa: 1; /*%< authoritative answer */ + unsigned tc: 1; /*%< truncated message */ + unsigned rd: 1; /*%< recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /*%< recursion available */ + unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /*%< authentic data from named */ + unsigned cd: 1; /*%< checking disabled by resolver */ + unsigned rcode :4; /*%< response code */ +#endif +#if _BYTE_ORDER == _LITTLE_ENDIAN || _BYTE_ORDER == _PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /*%< recursion desired */ + unsigned tc :1; /*%< truncated message */ + unsigned aa :1; /*%< authoritative answer */ + unsigned opcode :4; /*%< purpose of message */ + unsigned qr :1; /*%< response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /*%< response code */ + unsigned cd: 1; /*%< checking disabled by resolver */ + unsigned ad: 1; /*%< authentic data from named */ + unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /*%< recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /*%< number of question entries */ + unsigned ancount :16; /*%< number of answer entries */ + unsigned nscount :16; /*%< number of authority entries */ + unsigned arcount :16; /*%< number of resource entries */ +} HEADER; + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INT32SZ NS_INT32SZ +#define INT16SZ NS_INT16SZ +#define INT8SZ NS_INT8SZ +#define INADDRSZ NS_INADDRSZ +#define IN6ADDRSZ NS_IN6ADDRSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define S_ZONE ns_s_zn +#define S_PREREQ ns_s_pr +#define S_UPDATE ns_s_ud +#define S_ADDT ns_s_ar + +#define QUERY ns_o_query +#define IQUERY ns_o_iquery +#define STATUS ns_o_status +#define NS_NOTIFY_OP ns_o_notify +#define NS_UPDATE_OP ns_o_update + +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define SERVFAIL ns_r_servfail +#define NXDOMAIN ns_r_nxdomain +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define NXRRSET ns_r_nxrrset +#define NOTAUTH ns_r_notauth +#define NOTZONE ns_r_notzone +/*#define BADSIG ns_r_badsig*/ +/*#define BADKEY ns_r_badkey*/ +/*#define BADTIME ns_r_badtime*/ + + +#define DELETE ns_uop_delete +#define ADD ns_uop_add + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_A6 ns_t_a6 +#define T_DNAME ns_t_dname +#define T_OPT ns_t_opt +#define T_TSIG ns_t_tsig +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +/* BIND_UPDATE */ +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define GETSHORT NS_GET16 +#define GETLONG NS_GET32 +#define PUTSHORT NS_PUT16 +#define PUTLONG NS_PUT32 + +#endif /* _ARPA_NAMESER_COMPAT_ */ +/*! \file */ diff --git a/lib/libc/include/any-freebsd-any/arpa/telnet.h b/lib/libc/include/any-freebsd-any/arpa/telnet.h new file mode 100644 index 000000000000..855b3d26f9cf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/telnet.h @@ -0,0 +1,345 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)telnet.h 8.2 (Berkeley) 12/15/93 + * $FreeBSD$ + */ + +#ifndef _ARPA_TELNET_H_ +#define _ARPA_TELNET_H_ + +/* + * Definitions for the TELNET protocol. + */ +#define IAC 255 /* interpret as command: */ +#define DONT 254 /* you are not to use option */ +#define DO 253 /* please, you use option */ +#define WONT 252 /* I won't use option */ +#define WILL 251 /* I will use option */ +#define SB 250 /* interpret as subnegotiation */ +#define GA 249 /* you may reverse the line */ +#define EL 248 /* erase the current line */ +#define EC 247 /* erase the current character */ +#define AYT 246 /* are you there */ +#define AO 245 /* abort output--but let prog finish */ +#define IP 244 /* interrupt process--permanently */ +#define BREAK 243 /* break */ +#define DM 242 /* data mark--for connect. cleaning */ +#define NOP 241 /* nop */ +#define SE 240 /* end sub negotiation */ +#define EOR 239 /* end of record (transparent mode) */ +#define ABORT 238 /* Abort process */ +#define SUSP 237 /* Suspend process */ +#define xEOF 236 /* End of file: EOF is already used... */ + +#define SYNCH 242 /* for telfunc calls */ + +#ifdef TELCMDS +const char *telcmds[] = { + "EOF", "SUSP", "ABORT", "EOR", + "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", + "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", + 0 +}; +#else +extern char *telcmds[]; +#endif + +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ + (unsigned int)(x) >= TELCMD_FIRST) +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] + +/* telnet options */ +#define TELOPT_BINARY 0 /* 8-bit data path */ +#define TELOPT_ECHO 1 /* echo */ +#define TELOPT_RCP 2 /* prepare to reconnect */ +#define TELOPT_SGA 3 /* suppress go ahead */ +#define TELOPT_NAMS 4 /* approximate message size */ +#define TELOPT_STATUS 5 /* give status */ +#define TELOPT_TM 6 /* timing mark */ +#define TELOPT_RCTE 7 /* remote controlled transmission and echo */ +#define TELOPT_NAOL 8 /* negotiate about output line width */ +#define TELOPT_NAOP 9 /* negotiate about output page size */ +#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ +#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ +#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ +#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ +#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ +#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ +#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ +#define TELOPT_XASCII 17 /* extended ascic character set */ +#define TELOPT_LOGOUT 18 /* force logout */ +#define TELOPT_BM 19 /* byte macro */ +#define TELOPT_DET 20 /* data entry terminal */ +#define TELOPT_SUPDUP 21 /* supdup protocol */ +#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ +#define TELOPT_SNDLOC 23 /* send location */ +#define TELOPT_TTYPE 24 /* terminal type */ +#define TELOPT_EOR 25 /* end or record */ +#define TELOPT_TUID 26 /* TACACS user identification */ +#define TELOPT_OUTMRK 27 /* output marking */ +#define TELOPT_TTYLOC 28 /* terminal location number */ +#define TELOPT_3270REGIME 29 /* 3270 regime */ +#define TELOPT_X3PAD 30 /* X.3 PAD */ +#define TELOPT_NAWS 31 /* window size */ +#define TELOPT_TSPEED 32 /* terminal speed */ +#define TELOPT_LFLOW 33 /* remote flow control */ +#define TELOPT_LINEMODE 34 /* Linemode option */ +#define TELOPT_XDISPLOC 35 /* X Display Location */ +#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ +#define TELOPT_AUTHENTICATION 37/* Authenticate */ +#define TELOPT_ENCRYPT 38 /* Encryption option */ +#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ +#define TELOPT_TN3270E 40 /* RFC2355 - TN3270 Enhancements */ +#define TELOPT_CHARSET 42 /* RFC2066 - Charset */ +#define TELOPT_COMPORT 44 /* RFC2217 - Com Port Control */ +#define TELOPT_KERMIT 47 /* RFC2840 - Kermit */ +#define TELOPT_EXOPL 255 /* extended-options-list */ + + +#define NTELOPTS (1+TELOPT_KERMIT) +#ifdef TELOPTS +const char *telopts[NTELOPTS+1] = { + "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", + "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", + "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", + "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", + "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", + "TACACS UID", "OUTPUT MARKING", "TTYLOC", + "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", + "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", + "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", + "RSP", "COM-PORT", "SLE", "STARTTLS", "KERMIT", + 0 +}; +#define TELOPT_FIRST TELOPT_BINARY +#define TELOPT_LAST TELOPT_KERMIT +#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) +#define TELOPT(x) telopts[(x)-TELOPT_FIRST] +#endif + +/* sub-option qualifiers */ +#define TELQUAL_IS 0 /* option is... */ +#define TELQUAL_SEND 1 /* send option */ +#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ +#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ +#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ + +#define LFLOW_OFF 0 /* Disable remote flow control */ +#define LFLOW_ON 1 /* Enable remote flow control */ +#define LFLOW_RESTART_ANY 2 /* Restart output on any char */ +#define LFLOW_RESTART_XON 3 /* Restart output only on XON */ + +/* + * LINEMODE suboptions + */ + +#define LM_MODE 1 +#define LM_FORWARDMASK 2 +#define LM_SLC 3 + +#define MODE_EDIT 0x01 +#define MODE_TRAPSIG 0x02 +#define MODE_ACK 0x04 +#define MODE_SOFT_TAB 0x08 +#define MODE_LIT_ECHO 0x10 + +#define MODE_MASK 0x1f + +/* Not part of protocol, but needed to simplify things... */ +#define MODE_FLOW 0x0100 +#define MODE_ECHO 0x0200 +#define MODE_INBIN 0x0400 +#define MODE_OUTBIN 0x0800 +#define MODE_FORCE 0x1000 + +#define SLC_SYNCH 1 +#define SLC_BRK 2 +#define SLC_IP 3 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_EOR 6 +#define SLC_ABORT 7 +#define SLC_EOF 8 +#define SLC_SUSP 9 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EW 12 +#define SLC_RP 13 +#define SLC_LNEXT 14 +#define SLC_XON 15 +#define SLC_XOFF 16 +#define SLC_FORW1 17 +#define SLC_FORW2 18 +#define SLC_MCL 19 +#define SLC_MCR 20 +#define SLC_MCWL 21 +#define SLC_MCWR 22 +#define SLC_MCBOL 23 +#define SLC_MCEOL 24 +#define SLC_INSRT 25 +#define SLC_OVER 26 +#define SLC_ECR 27 +#define SLC_EWR 28 +#define SLC_EBOL 29 +#define SLC_EEOL 30 + +#define NSLC 30 + +/* + * For backwards compatibility, we define SLC_NAMES to be the + * list of names if SLC_NAMES is not defined. + */ +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ + "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ + "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \ + "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \ + "MCEOL", "INSRT", "OVER", "ECR", "EWR", \ + "EBOL", "EEOL", \ + 0 + +#ifdef SLC_NAMES +const char *slc_names[] = { + SLC_NAMELIST +}; +#else +extern char *slc_names[]; +#define SLC_NAMES SLC_NAMELIST +#endif + +#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) +#define SLC_NAME(x) slc_names[x] + +#define SLC_NOSUPPORT 0 +#define SLC_CANTCHANGE 1 +#define SLC_VARIABLE 2 +#define SLC_DEFAULT 3 +#define SLC_LEVELBITS 0x03 + +#define SLC_FUNC 0 +#define SLC_FLAGS 1 +#define SLC_VALUE 2 + +#define SLC_ACK 0x80 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 + +#define OLD_ENV_VAR 1 +#define OLD_ENV_VALUE 0 +#define NEW_ENV_VAR 0 +#define NEW_ENV_VALUE 1 +#define ENV_ESC 2 +#define ENV_USERVAR 3 + +/* + * AUTHENTICATION suboptions + */ + +/* + * Who is authenticating who ... + */ +#define AUTH_WHO_CLIENT 0 /* Client authenticating server */ +#define AUTH_WHO_SERVER 1 /* Server authenticating client */ +#define AUTH_WHO_MASK 1 + +/* + * amount of authentication done + */ +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_MASK 2 + +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_SRA 6 +#define AUTHTYPE_CNT 7 + +#define AUTHTYPE_TEST 99 + +#ifdef AUTH_NAMES +const char *authtype_names[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", NULL, "SRA", + 0 +}; +#else +extern char *authtype_names[]; +#endif + +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NAME(x) authtype_names[x] + +/* + * ENCRYPTion suboptions + */ +#define ENCRYPT_IS 0 /* I pick encryption type ... */ +#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ +#define ENCRYPT_REPLY 2 /* Initial setup response */ +#define ENCRYPT_START 3 /* Am starting to send encrypted */ +#define ENCRYPT_END 4 /* Am ending encrypted */ +#define ENCRYPT_REQSTART 5 /* Request you start encrypting */ +#define ENCRYPT_REQEND 6 /* Request you end encrypting */ +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_CNT 9 + +#define ENCTYPE_ANY 0 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_CNT 3 + +#ifdef ENCRYPT_NAMES +const char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0 +}; +const char *enctype_names[] = { + "ANY", "DES_CFB64", "DES_OFB64", + 0 +}; +#else +extern char *encrypt_names[]; +extern char *enctype_names[]; +#endif + + +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_NAME(x) encrypt_names[x] + +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENCTYPE_NAME(x) enctype_names[x] + +#endif /* !_TELNET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/arpa/tftp.h b/lib/libc/include/any-freebsd-any/arpa/tftp.h new file mode 100644 index 000000000000..50147137db15 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/arpa/tftp.h @@ -0,0 +1,83 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _ARPA_TFTP_H_ +#define _ARPA_TFTP_H_ + +#include + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ +#define OACK 06 /* option acknowledgement */ + +struct tftphdr { + unsigned short th_opcode; /* packet type */ + union { + unsigned short tu_block; /* block # */ + unsigned short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } __packed th_u; + char th_data[1]; /* data or error string */ +} __packed; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ +#define EOPTNEG 8 /* option negotiation failed */ + +#endif /* !_TFTP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/assert.h b/lib/libc/include/any-freebsd-any/assert.h new file mode 100644 index 000000000000..702e231603e6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/assert.h @@ -0,0 +1,80 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#include + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#undef assert +#undef _assert + +#ifdef NDEBUG +#define assert(e) ((void)0) +#define _assert(e) ((void)0) +#else +#define _assert(e) assert(e) + +#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \ + __LINE__, #e)) +#endif /* NDEBUG */ + +#ifndef _ASSERT_H_ +#define _ASSERT_H_ + +/* + * Static assertions. In principle we could define static_assert for + * C++ older than C++11, but this breaks if _Static_assert is + * implemented as a macro. + * + * C++ template parameters may contain commas, even if not enclosed in + * parentheses, causing the _Static_assert macro to be invoked with more + * than two parameters. + */ +#if __ISO_C_VISIBLE >= 2011 && !defined(__cplusplus) +#define static_assert _Static_assert +#endif + +__BEGIN_DECLS +void __assert(const char *, const char *, int, const char *) __dead2; +__END_DECLS + +#endif /* !_ASSERT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/bitstring.h b/lib/libc/include/any-freebsd-any/bitstring.h new file mode 100644 index 000000000000..b179880f1e42 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/bitstring.h @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _BITSTRING_H_ +#define _BITSTRING_H_ + +#include +#include +#include + +#endif /* _BITSTRING_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/complex.h b/lib/libc/include/any-freebsd-any/complex.h new file mode 100644 index 000000000000..892bc55e5145 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/complex.h @@ -0,0 +1,138 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001-2011 The FreeBSD Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _COMPLEX_H +#define _COMPLEX_H + +#include + +#ifdef __GNUC__ +#if __STDC_VERSION__ < 199901 +#define _Complex __complex__ +#endif +#define _Complex_I ((float _Complex)1.0i) +#endif + +#ifdef __generic +_Static_assert(__generic(_Complex_I, float _Complex, 1, 0), + "_Complex_I must be of type float _Complex"); +#endif + +#define complex _Complex +#define I _Complex_I + +#if __ISO_C_VISIBLE >= 2011 +#ifdef __clang__ +#define CMPLX(x, y) ((double complex){ x, y }) +#define CMPLXF(x, y) ((float complex){ x, y }) +#define CMPLXL(x, y) ((long double complex){ x, y }) +#elif __GNUC_PREREQ__(4, 7) +#define CMPLX(x, y) __builtin_complex((double)(x), (double)(y)) +#define CMPLXF(x, y) __builtin_complex((float)(x), (float)(y)) +#define CMPLXL(x, y) __builtin_complex((long double)(x), (long double)(y)) +#endif +#endif /* __ISO_C_VISIBLE >= 2011 */ + +__BEGIN_DECLS + +double cabs(double complex); +float cabsf(float complex); +long double cabsl(long double complex); +double complex cacos(double complex); +float complex cacosf(float complex); +double complex cacosh(double complex); +float complex cacoshf(float complex); +long double complex + cacoshl(long double complex); +long double complex + cacosl(long double complex); +double carg(double complex); +float cargf(float complex); +long double cargl(long double complex); +double complex casin(double complex); +float complex casinf(float complex); +double complex casinh(double complex); +float complex casinhf(float complex); +long double complex + casinhl(long double complex); +long double complex + casinl(long double complex); +double complex catan(double complex); +float complex catanf(float complex); +double complex catanh(double complex); +float complex catanhf(float complex); +long double complex + catanhl(long double complex); +long double complex + catanl(long double complex); +double complex ccos(double complex); +float complex ccosf(float complex); +double complex ccosh(double complex); +float complex ccoshf(float complex); +double complex cexp(double complex); +float complex cexpf(float complex); +double cimag(double complex) __pure2; +float cimagf(float complex) __pure2; +long double cimagl(long double complex) __pure2; +double complex clog(double complex); +float complex clogf(float complex); +long double complex + clogl(long double complex); +double complex conj(double complex) __pure2; +float complex conjf(float complex) __pure2; +long double complex + conjl(long double complex) __pure2; +float complex cpowf(float complex, float complex); +double complex cpow(double complex, double complex); +long double complex + cpowl(long double complex, long double complex); +float complex cprojf(float complex) __pure2; +double complex cproj(double complex) __pure2; +long double complex + cprojl(long double complex) __pure2; +double creal(double complex) __pure2; +float crealf(float complex) __pure2; +long double creall(long double complex) __pure2; +double complex csin(double complex); +float complex csinf(float complex); +double complex csinh(double complex); +float complex csinhf(float complex); +double complex csqrt(double complex); +float complex csqrtf(float complex); +long double complex + csqrtl(long double complex); +double complex ctan(double complex); +float complex ctanf(float complex); +double complex ctanh(double complex); +float complex ctanhf(float complex); + +__END_DECLS + +#endif /* _COMPLEX_H */ diff --git a/lib/libc/include/any-freebsd-any/cpio.h b/lib/libc/include/any-freebsd-any/cpio.h new file mode 100644 index 000000000000..9cbd44e16522 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/cpio.h @@ -0,0 +1,57 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _CPIO_H_ +#define _CPIO_H_ + +#define C_ISSOCK 0140000 /* Socket. */ +#define C_ISLNK 0120000 /* Symbolic link. */ +#define C_ISCTG 0110000 /* Reserved. */ +#define C_ISREG 0100000 /* Regular file. */ +#define C_ISBLK 0060000 /* Block special. */ +#define C_ISDIR 0040000 /* Directory. */ +#define C_ISCHR 0020000 /* Character special. */ +#define C_ISFIFO 0010000 /* FIFO. */ +#define C_ISUID 0004000 /* Set user ID. */ +#define C_ISGID 0002000 /* Set group ID. */ +#define C_ISVTX 0001000 /* On directories, restricted deletion flag. */ +#define C_IRUSR 0000400 /* Read by owner. */ +#define C_IWUSR 0000200 /* Write by owner. */ +#define C_IXUSR 0000100 /* Execute by owner. */ +#define C_IRGRP 0000040 /* Read by group. */ +#define C_IWGRP 0000020 /* Write by group. */ +#define C_IXGRP 0000010 /* Execute by group. */ +#define C_IROTH 0000004 /* Read by others. */ +#define C_IWOTH 0000002 /* Write by others. */ +#define C_IXOTH 0000001 /* Execute by others. */ + +#define MAGIC "070707" + +#endif /* _CPIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ctype.h b/lib/libc/include/any-freebsd-any/ctype.h new file mode 100644 index 000000000000..13173139777b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ctype.h @@ -0,0 +1,137 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ctype.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#include +#include +#include <_ctype.h> + +__BEGIN_DECLS +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +#if __XSI_VISIBLE +int isascii(int); +int toascii(int); +#endif + +#if __ISO_C_VISIBLE >= 1999 +int isblank(int); +#endif + +#if __BSD_VISIBLE +int digittoint(int); +int ishexnumber(int); +int isideogram(int); +int isnumber(int); +int isphonogram(int); +int isrune(int); +int isspecial(int); +#endif + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif +__END_DECLS + +#ifndef __cplusplus +#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D|_CTYPE_N) +#define isalpha(c) __sbistype((c), _CTYPE_A) +#define iscntrl(c) __sbistype((c), _CTYPE_C) +#define isdigit(c) __sbistype((c), _CTYPE_D) +#define isgraph(c) __sbistype((c), _CTYPE_G) +#define islower(c) __sbistype((c), _CTYPE_L) +#define isprint(c) __sbistype((c), _CTYPE_R) +#define ispunct(c) __sbistype((c), _CTYPE_P) +#define isspace(c) __sbistype((c), _CTYPE_S) +#define isupper(c) __sbistype((c), _CTYPE_U) +#define isxdigit(c) __sbistype((c), _CTYPE_X) +#define tolower(c) __sbtolower(c) +#define toupper(c) __sbtoupper(c) +#endif /* !__cplusplus */ + +#if __XSI_VISIBLE +/* + * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to + * tolower() and toupper() respectively, minus extra checking to ensure that + * the argument is a lower or uppercase letter respectively. We've chosen to + * implement these macros with the same error checking as tolower() and + * toupper() since this doesn't violate the specification itself, only its + * intent. We purposely leave _tolower() and _toupper() undocumented to + * discourage their use. + * + * XXX isascii() and toascii() should similarly be undocumented. + */ +#define _tolower(c) __sbtolower(c) +#define _toupper(c) __sbtoupper(c) +#define isascii(c) (((c) & ~0x7F) == 0) +#define toascii(c) ((c) & 0x7F) +#endif + +#if __ISO_C_VISIBLE >= 1999 && !defined(__cplusplus) +#define isblank(c) __sbistype((c), _CTYPE_B) +#endif + +#if __BSD_VISIBLE +#define digittoint(c) __sbmaskrune((c), 0xFF) +#define ishexnumber(c) __sbistype((c), _CTYPE_X) +#define isideogram(c) __sbistype((c), _CTYPE_I) +#define isnumber(c) __sbistype((c), _CTYPE_D|_CTYPE_N) +#define isphonogram(c) __sbistype((c), _CTYPE_Q) +#define isrune(c) __sbistype((c), 0xFFFFFF00L) +#define isspecial(c) __sbistype((c), _CTYPE_T) +#endif + +#endif /* !_CTYPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/db.h b/lib/libc/include/any-freebsd-any/db.h new file mode 100644 index 000000000000..13fa91d68048 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/db.h @@ -0,0 +1,219 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)db.h 8.7 (Berkeley) 6/16/94 + * $FreeBSD$ + */ + +#ifndef _DB_H_ +#define _DB_H_ + +#include +#include + +#include + +#define RET_ERROR -1 /* Return values. */ +#define RET_SUCCESS 0 +#define RET_SPECIAL 1 + +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ +typedef uint32_t pgno_t; +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ +typedef uint16_t indx_t; +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ +typedef uint32_t recno_t; + +/* Key/data structure -- a Data-Base Thang. */ +typedef struct { + void *data; /* data */ + size_t size; /* data length */ +} DBT; + +/* Routine flags. */ +#define R_CURSOR 1 /* del, put, seq */ +#define __R_UNUSED 2 /* UNUSED */ +#define R_FIRST 3 /* seq */ +#define R_IAFTER 4 /* put (RECNO) */ +#define R_IBEFORE 5 /* put (RECNO) */ +#define R_LAST 6 /* seq (BTREE, RECNO) */ +#define R_NEXT 7 /* seq */ +#define R_NOOVERWRITE 8 /* put */ +#define R_PREV 9 /* seq (BTREE, RECNO) */ +#define R_SETCURSOR 10 /* put (RECNO) */ +#define R_RECNOSYNC 11 /* sync (RECNO) */ + +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; + +/* + * !!! + * The following flags are included in the dbopen(3) call as part of the + * open(2) flags. In order to avoid conflicts with the open flags, start + * at the top of the 16 or 32-bit number space and work our way down. If + * the open flags were significantly expanded in the future, it could be + * a problem. Wish I'd left another flags word in the dbopen call. + * + * !!! + * None of this stuff is implemented yet. The only reason that it's here + * is so that the access methods can skip copying the key/data pair when + * the DB_LOCK flag isn't set. + */ +#if UINT_MAX > 65535 +#define DB_LOCK 0x20000000 /* Do locking. */ +#define DB_SHMEM 0x40000000 /* Use shared memory. */ +#define DB_TXN 0x80000000 /* Do transactions. */ +#else +#define DB_LOCK 0x2000 /* Do locking. */ +#define DB_SHMEM 0x4000 /* Use shared memory. */ +#define DB_TXN 0x8000 /* Do transactions. */ +#endif + +/* Access method description structure. */ +typedef struct __db { + DBTYPE type; /* Underlying db type. */ + int (*close)(struct __db *); + int (*del)(const struct __db *, const DBT *, unsigned int); + int (*get)(const struct __db *, const DBT *, DBT *, unsigned int); + int (*put)(const struct __db *, DBT *, const DBT *, unsigned int); + int (*seq)(const struct __db *, DBT *, DBT *, unsigned int); + int (*sync)(const struct __db *, unsigned int); + void *internal; /* Access method private. */ + int (*fd)(const struct __db *); +} DB; + +#define BTREEMAGIC 0x053162 +#define BTREEVERSION 3 + +/* Structure used to pass parameters to the btree routines. */ +typedef struct { +#define R_DUP 0x01 /* duplicate keys */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + int maxkeypage; /* maximum keys per page */ + int minkeypage; /* minimum keys per page */ + unsigned int psize; /* page size */ + int (*compare) /* comparison function */ + (const DBT *, const DBT *); + size_t (*prefix) /* prefix function */ + (const DBT *, const DBT *); + int lorder; /* byte order */ +} BTREEINFO; + +#define HASHMAGIC 0x061561 +#define HASHVERSION 2 + +/* Structure used to pass parameters to the hashing routines. */ +typedef struct { + unsigned int bsize; /* bucket size */ + unsigned int ffactor; /* fill factor */ + unsigned int nelem; /* number of elements */ + unsigned int cachesize; /* bytes to cache */ + uint32_t /* hash function */ + (*hash)(const void *, size_t); + int lorder; /* byte order */ +} HASHINFO; + +/* Structure used to pass parameters to the record routines. */ +typedef struct { +#define R_FIXEDLEN 0x01 /* fixed-length records */ +#define R_NOKEY 0x02 /* key not required */ +#define R_SNAPSHOT 0x04 /* snapshot the input */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + unsigned int psize; /* page size */ + int lorder; /* byte order */ + size_t reclen; /* record length (fixed-length records) */ + unsigned char bval; /* delimiting byte (variable-length records */ + char *bfname; /* btree file name */ +} RECNOINFO; + +#ifdef __DBINTERFACE_PRIVATE +/* + * Little endian <==> big endian 32-bit swap macros. + * M_32_SWAP swap a memory location + * P_32_SWAP swap a referenced memory location + * P_32_COPY swap from one location to another + */ +#define M_32_SWAP(a) { \ + uint32_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[3]; \ + ((char *)&a)[1] = ((char *)&_tmp)[2]; \ + ((char *)&a)[2] = ((char *)&_tmp)[1]; \ + ((char *)&a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_SWAP(a) { \ + uint32_t _tmp = *(uint32_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[3]; \ + ((char *)a)[1] = ((char *)&_tmp)[2]; \ + ((char *)a)[2] = ((char *)&_tmp)[1]; \ + ((char *)a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[3]; \ + ((char *)&(b))[1] = ((char *)&(a))[2]; \ + ((char *)&(b))[2] = ((char *)&(a))[1]; \ + ((char *)&(b))[3] = ((char *)&(a))[0]; \ +} + +/* + * Little endian <==> big endian 16-bit swap macros. + * M_16_SWAP swap a memory location + * P_16_SWAP swap a referenced memory location + * P_16_COPY swap from one location to another + */ +#define M_16_SWAP(a) { \ + uint16_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[1]; \ + ((char *)&a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_SWAP(a) { \ + uint16_t _tmp = *(uint16_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[1]; \ + ((char *)a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[1]; \ + ((char *)&(b))[1] = ((char *)&(a))[0]; \ +} +#endif + +__BEGIN_DECLS +#if __BSD_VISIBLE +DB *dbopen(const char *, int, int, DBTYPE, const void *); +#endif + +#ifdef __DBINTERFACE_PRIVATE +DB *__bt_open(const char *, int, int, const BTREEINFO *, int); +DB *__hash_open(const char *, int, int, const HASHINFO *, int); +DB *__rec_open(const char *, int, int, const RECNOINFO *, int); +void __dbpanic(DB *dbp); +#endif +__END_DECLS +#endif /* !_DB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/dirent.h b/lib/libc/include/any-freebsd-any/dirent.h new file mode 100644 index 000000000000..702153e28fc0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/dirent.h @@ -0,0 +1,143 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dirent.h 8.2 (Berkeley) 7/28/94 + * $FreeBSD$ + */ + +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +/* + * The kernel defines the format of directory entries returned by + * the getdirentries(2) system call. + */ +#include +#include +#include + +#if __BSD_VISIBLE + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#endif /* __BSD_VISIBLE */ + +#if __XSI_VISIBLE + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; +#define _INO_T_DECLARED +#endif + +/* + * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer + * to the specification. + */ +#define d_ino d_fileno /* backward and XSI compatibility */ + +#endif /* __XSI_VISIBLE */ + +#if __BSD_VISIBLE + +#include + +/* definitions for library routines operating on directories. */ +#define DIRBLKSIZ 1024 + +struct _dirdesc; +typedef struct _dirdesc DIR; + +/* flags for opendir2 */ +#define DTF_HIDEW 0x0001 /* hide whiteout entries */ +#define DTF_NODUP 0x0002 /* don't return duplicate names */ +#define DTF_REWIND 0x0004 /* rewind after reading union stack */ +#define __DTF_READALL 0x0008 /* everything has been read */ +#define __DTF_SKIPREAD 0x0010 /* assume internal buffer is populated */ + +#else /* !__BSD_VISIBLE */ + +typedef void * DIR; + +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +__BEGIN_DECLS +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 +int alphasort(const struct dirent **, const struct dirent **); +int dirfd(DIR *); +#endif +#if __BSD_VISIBLE +DIR *__opendir2(const char *, int); +int fdclosedir(DIR *); +ssize_t getdents(int, char *, size_t); +ssize_t getdirentries(int, char *, size_t, off_t *); +#endif +DIR *opendir(const char *); +DIR *fdopendir(int); +struct dirent * + readdir(DIR *); +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 +int readdir_r(DIR *, struct dirent *, struct dirent **); +#endif +void rewinddir(DIR *); +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 +int scandir(const char *, struct dirent ***, + int (*)(const struct dirent *), int (*)(const struct dirent **, + const struct dirent **)); +#ifdef __BLOCKS__ +int scandir_b(const char *, struct dirent ***, + int (^)(const struct dirent *), + int (^)(const struct dirent **, const struct dirent **)); +#endif +#endif +#if __XSI_VISIBLE +void seekdir(DIR *, long); +long telldir(DIR *); +#endif +int closedir(DIR *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_DIRENT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/dlfcn.h b/lib/libc/include/any-freebsd-any/dlfcn.h new file mode 100644 index 000000000000..f219879b8fa5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/dlfcn.h @@ -0,0 +1,141 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _DLFCN_H_ +#define _DLFCN_H_ + +#include + +/* + * Modes and flags for dlopen(). + */ +#define RTLD_LAZY 1 /* Bind function calls lazily. */ +#define RTLD_NOW 2 /* Bind function calls immediately. */ +#define RTLD_MODEMASK 0x3 +#define RTLD_GLOBAL 0x100 /* Make symbols globally available. */ +#define RTLD_LOCAL 0 /* Opposite of RTLD_GLOBAL, and the default. */ +#define RTLD_TRACE 0x200 /* Trace loaded objects and exit. */ +#define RTLD_NODELETE 0x01000 /* Do not remove members. */ +#define RTLD_NOLOAD 0x02000 /* Do not load if not already loaded. */ +#define RTLD_DEEPBIND 0x04000 /* Put symbols from the dso ahead of + the global list */ + +/* + * Request arguments for dlinfo(). + */ +#define RTLD_DI_LINKMAP 2 /* Obtain link map. */ +#define RTLD_DI_SERINFO 4 /* Obtain search path info. */ +#define RTLD_DI_SERINFOSIZE 5 /* ... query for required space. */ +#define RTLD_DI_ORIGIN 6 /* Obtain object origin */ +#define RTLD_DI_MAX RTLD_DI_ORIGIN + +/* + * Special handle arguments for dlsym()/dlinfo(). + */ +#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ +#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ +#define RTLD_SELF ((void *) -3) /* Search the caller itself. */ + +#if __BSD_VISIBLE + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +/* + * Structure filled in by dladdr(). + */ +typedef struct dl_info { + const char *dli_fname; /* Pathname of shared object. */ + void *dli_fbase; /* Base address of shared object. */ + const char *dli_sname; /* Name of nearest symbol. */ + void *dli_saddr; /* Address of nearest symbol. */ +} Dl_info; + +/*- + * The actual type declared by this typedef is immaterial, provided that + * it is a function pointer. Its purpose is to provide a return type for + * dlfunc() which can be cast to a function pointer type without depending + * on behavior undefined by the C standard, which might trigger a compiler + * diagnostic. We intentionally declare a unique type signature to force + * a diagnostic should the application not cast the return value of dlfunc() + * appropriately. + */ +struct __dlfunc_arg { + int __dlfunc_dummy; +}; + +typedef void (*dlfunc_t)(struct __dlfunc_arg); + +/* + * Structures, returned by the RTLD_DI_SERINFO dlinfo() request. + */ +typedef struct dl_serpath { + char * dls_name; /* single search path entry */ + unsigned int dls_flags; /* path information */ +} Dl_serpath; + +typedef struct dl_serinfo { + size_t dls_size; /* total buffer size */ + unsigned int dls_cnt; /* number of path entries */ + Dl_serpath dls_serpath[1]; /* there may be more than one */ +} Dl_serinfo; + +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +/* XSI functions first. */ +int dlclose(void *); +char *dlerror(void); +void *dlopen(const char *, int); +void *dlsym(void * __restrict, const char * __restrict); + +#if __BSD_VISIBLE +void *fdlopen(int, int); +int dladdr(const void * __restrict, Dl_info * __restrict); +dlfunc_t dlfunc(void * __restrict, const char * __restrict); +int dlinfo(void * __restrict, int, void * __restrict); +void dllockinit(void *_context, + void *(*_lock_create)(void *_context), + void (*_rlock_acquire)(void *_lock), + void (*_wlock_acquire)(void *_lock), + void (*_lock_release)(void *_lock), + void (*_lock_destroy)(void *_lock), + void (*_context_destroy)(void *_context)); +void *dlvsym(void * __restrict, const char * __restrict, + const char * __restrict); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_DLFCN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/elf-hints.h b/lib/libc/include/any-freebsd-any/elf-hints.h new file mode 100644 index 000000000000..679cc34e249e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/elf-hints.h @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ELF_HINTS_H_ +#define _ELF_HINTS_H_ + +/* + * Hints file produced by ldconfig. + */ +struct elfhints_hdr { + u_int32_t magic; /* Magic number */ + u_int32_t version; /* File version (1) */ + u_int32_t strtab; /* Offset of string table in file */ + u_int32_t strsize; /* Size of string table */ + u_int32_t dirlist; /* Offset of directory list in + string table */ + u_int32_t dirlistlen; /* strlen(dirlist) */ + u_int32_t spare[26]; /* Room for expansion */ +}; + +#define ELFHINTS_MAGIC 0x746e6845 + +#define _PATH_ELF_HINTS "/var/run/ld-elf.so.hints" + +#endif /* !_ELF_HINTS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/elf.h b/lib/libc/include/any-freebsd-any/elf.h new file mode 100644 index 000000000000..f230ae729fea --- /dev/null +++ b/lib/libc/include/any-freebsd-any/elf.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 David E. O'Brien. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * This is a Solaris compatibility header + */ + +#ifndef _ELF_H_ +#define _ELF_H_ + +#include +#include +#include +#include + +#endif /* !_ELF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/err.h b/lib/libc/include/any-freebsd-any/err.h new file mode 100644 index 000000000000..4b67275a3450 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/err.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _ERR_H_ +#define _ERR_H_ + +/* + * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include err.h, so we get + * __va_list from and use it. + */ +#include +#include + +__NULLABILITY_PRAGMA_PUSH + +__BEGIN_DECLS +void err(int, const char *, ...) __dead2 __printf0like(2, 3); +void verr(int, const char *, __va_list) __dead2 __printf0like(2, 0); +void errc(int, int, const char *, ...) __dead2 __printf0like(3, 4); +void verrc(int, int, const char *, __va_list) __dead2 + __printf0like(3, 0); +void errx(int, const char *, ...) __dead2 __printf0like(2, 3); +void verrx(int, const char *, __va_list) __dead2 __printf0like(2, 0); +void warn(const char *, ...) __printf0like(1, 2); +void vwarn(const char *, __va_list) __printf0like(1, 0); +void warnc(int, const char *, ...) __printf0like(2, 3); +void vwarnc(int, const char *, __va_list) __printf0like(2, 0); +void warnx(const char *, ...) __printflike(1, 2); +void vwarnx(const char *, __va_list) __printf0like(1, 0); +void err_set_file(void *); +void err_set_exit(void (* _Nullable)(int)); +__END_DECLS +__NULLABILITY_PRAGMA_POP + +#endif /* !_ERR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/fmtmsg.h b/lib/libc/include/any-freebsd-any/fmtmsg.h new file mode 100644 index 000000000000..1251c95d489d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/fmtmsg.h @@ -0,0 +1,75 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _FMTMSG_H_ +#define _FMTMSG_H_ + +/* Source of condition is... */ +#define MM_HARD 0x0001 /* ...hardware. */ +#define MM_SOFT 0x0002 /* ...software. */ +#define MM_FIRM 0x0004 /* ...firmware. */ + +/* Condition detected by... */ +#define MM_APPL 0x0010 /* ...application. */ +#define MM_UTIL 0x0020 /* ...utility. */ +#define MM_OPSYS 0x0040 /* ...operating system. */ + +/* Display on... */ +#define MM_PRINT 0x0100 /* ...standard error. */ +#define MM_CONSOLE 0x0200 /* ...system console. */ + +#define MM_RECOVER 0x1000 /* Recoverable error. */ +#define MM_NRECOV 0x2000 /* Non-recoverable error. */ + +/* Severity levels. */ +#define MM_NOSEV 0 /* No severity level provided. */ +#define MM_HALT 1 /* Error causing application to halt. */ +#define MM_ERROR 2 /* Non-fault fault. */ +#define MM_WARNING 3 /* Unusual non-error condition. */ +#define MM_INFO 4 /* Informative message. */ + +/* Null options. */ +#define MM_NULLLBL (char *)0 +#define MM_NULLSEV 0 +#define MM_NULLMC 0L +#define MM_NULLTXT (char *)0 +#define MM_NULLACT (char *)0 +#define MM_NULLTAG (char *)0 + +/* Return values. */ +#define MM_OK 0 /* Success. */ +#define MM_NOMSG 1 /* Failed to output to stderr. */ +#define MM_NOCON 2 /* Failed to output to console. */ +#define MM_NOTOK 3 /* Failed to output anything. */ + +int fmtmsg(long, const char *, int, const char *, const char *, + const char *); + +#endif /* !_FMTMSG_H_ */ diff --git a/lib/libc/include/any-freebsd-any/fnmatch.h b/lib/libc/include/any-freebsd-any/fnmatch.h new file mode 100644 index 000000000000..34485381abf7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/fnmatch.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FNMATCH_H_ +#define _FNMATCH_H_ + +#include + +#define FNM_NOMATCH 1 /* Match failed. */ + +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ + +#if __XSI_VISIBLE +#define FNM_NOSYS (-1) /* Reserved. */ +#endif + +#if __BSD_VISIBLE +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME +#endif + +__BEGIN_DECLS +int fnmatch(const char *, const char *, int); +__END_DECLS + +#endif /* !_FNMATCH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/fstab.h b/lib/libc/include/any-freebsd-any/fstab.h new file mode 100644 index 000000000000..364d132bc4c8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/fstab.h @@ -0,0 +1,80 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fstab.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _FSTAB_H_ +#define _FSTAB_H_ + +/* + * File system table, see fstab(5). + * + * Used by dump, mount, umount, swapon, fsck, df, ... + * + * For ufs fs_spec field is the block special name. Programs that want to + * use the character special name must create that name by prepending a 'r' + * after the right most slash. Quota files are always named "quotas", so + * if type is "rq", then use concatenation of fs_file and "quotas" to locate + * quota file. + */ +#define _PATH_FSTAB "/etc/fstab" +#define FSTAB "/etc/fstab" /* deprecated */ + +#define FSTAB_RW "rw" /* read/write device */ +#define FSTAB_RQ "rq" /* read/write with quotas */ +#define FSTAB_RO "ro" /* read-only device */ +#define FSTAB_SW "sw" /* swap device */ +#define FSTAB_XX "xx" /* ignore totally */ + +struct fstab { + char *fs_spec; /* block special device name */ + char *fs_file; /* file system path prefix */ + char *fs_vfstype; /* File system type, ufs, nfs */ + char *fs_mntops; /* Mount options ala -o */ + char *fs_type; /* FSTAB_* from fs_mntops */ + int fs_freq; /* dump frequency, in days */ + int fs_passno; /* pass number on parallel fsck */ +}; + +#include + +__BEGIN_DECLS +struct fstab *getfsent(void); +struct fstab *getfsspec(const char *); +struct fstab *getfsfile(const char *); +int setfsent(void); +void endfsent(void); +void setfstab(const char *); +const char *getfstab(void); +__END_DECLS + +#endif /* !_FSTAB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/fts.h b/lib/libc/include/any-freebsd-any/fts.h new file mode 100644 index 000000000000..6f4674e4a76e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/fts.h @@ -0,0 +1,138 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fts.h 8.3 (Berkeley) 8/14/94 + * $FreeBSD$ + */ + +#ifndef _FTS_H_ +#define _FTS_H_ + +#include + +typedef struct { + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + __dev_t fts_dev; /* starting device # */ + char *fts_path; /* path for this descent */ + int fts_rfd; /* fd for root */ + __size_t fts_pathlen; /* sizeof(path) */ + __size_t fts_nitems; /* elements in the sort array */ + int (*fts_compar) /* compare function */ + (const struct _ftsent * const *, const struct _ftsent * const *); + +#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ +#define FTS_LOGICAL 0x002 /* logical walk */ +#define FTS_NOCHDIR 0x004 /* don't change directories */ +#define FTS_NOSTAT 0x008 /* don't get stat info */ +#define FTS_PHYSICAL 0x010 /* physical walk */ +#define FTS_SEEDOT 0x020 /* return dot and dot-dot */ +#define FTS_XDEV 0x040 /* don't cross devices */ +#define FTS_WHITEOUT 0x080 /* return whiteout information */ +#define FTS_OPTIONMASK 0x0ff /* valid user option mask */ + +#define FTS_NAMEONLY 0x100 /* (private) child names only */ +#define FTS_STOP 0x200 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ + void *fts_clientptr; /* thunk for sort function */ +} FTS; + +typedef struct _ftsent { + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + long long fts_number; /* local numeric value */ +#define fts_bignum fts_number /* XXX non-std, should go away */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access path */ + char *fts_path; /* root path */ + int fts_errno; /* errno for this node */ + int fts_symfd; /* fd for symlink */ + __size_t fts_pathlen; /* strlen(fts_path) */ + __size_t fts_namelen; /* strlen(fts_name) */ + + __ino_t fts_ino; /* inode */ + __dev_t fts_dev; /* device */ + __nlink_t fts_nlink; /* link count */ + +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_ROOTLEVEL 0 + long fts_level; /* depth (-1 to N) */ + +#define FTS_D 1 /* preorder directory */ +#define FTS_DC 2 /* directory that causes cycles */ +#define FTS_DEFAULT 3 /* none of the above */ +#define FTS_DNR 4 /* unreadable directory */ +#define FTS_DOT 5 /* dot or dot-dot */ +#define FTS_DP 6 /* postorder directory */ +#define FTS_ERR 7 /* error; errno is set */ +#define FTS_F 8 /* regular file */ +#define FTS_INIT 9 /* initialized only */ +#define FTS_NS 10 /* stat(2) failed */ +#define FTS_NSOK 11 /* no stat(2) requested */ +#define FTS_SL 12 /* symbolic link */ +#define FTS_SLNONE 13 /* symbolic link without target */ +#define FTS_W 14 /* whiteout object */ + int fts_info; /* user status for FTSENT structure */ + +#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ +#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ +#define FTS_ISW 0x04 /* this is a whiteout object */ + unsigned fts_flags; /* private flags for FTSENT structure */ + +#define FTS_AGAIN 1 /* read node again */ +#define FTS_FOLLOW 2 /* follow symbolic link */ +#define FTS_NOINSTR 3 /* no instructions */ +#define FTS_SKIP 4 /* discard node */ + int fts_instr; /* fts_set() instructions */ + + struct stat *fts_statp; /* stat(2) information */ + char *fts_name; /* file name */ + FTS *fts_fts; /* back pointer to main FTS */ +} FTSENT; + +#include + +__BEGIN_DECLS +FTSENT *fts_children(FTS *, int); +int fts_close(FTS *); +void *fts_get_clientptr(FTS *); +#define fts_get_clientptr(fts) ((fts)->fts_clientptr) +FTS *fts_get_stream(FTSENT *); +#define fts_get_stream(ftsent) ((ftsent)->fts_fts) +FTS *fts_open(char * const *, int, + int (*)(const FTSENT * const *, const FTSENT * const *)); +FTSENT *fts_read(FTS *); +int fts_set(FTS *, FTSENT *, int); +void fts_set_clientptr(FTS *, void *); +__END_DECLS + +#endif /* !_FTS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ftw.h b/lib/libc/include/any-freebsd-any/ftw.h new file mode 100644 index 000000000000..95f2ef285c1a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ftw.h @@ -0,0 +1,64 @@ +/* $OpenBSD: ftw.h,v 1.1 2003/07/21 21:13:18 millert Exp $ */ + +/*- + * SPDX-License-Identifier: ISC + * + * Copyright (c) 2003 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + * + * $FreeBSD$ + */ + +#ifndef _FTW_H +#define _FTW_H + +#include +#include + +/* + * Valid flags for the 3rd argument to the function that is passed as the + * second argument to ftw(3) and nftw(3). Say it three times fast! + */ +#define FTW_F 0 /* File. */ +#define FTW_D 1 /* Directory. */ +#define FTW_DNR 2 /* Directory without read permission. */ +#define FTW_DP 3 /* Directory with subdirectories visited. */ +#define FTW_NS 4 /* Unknown type; stat() failed. */ +#define FTW_SL 5 /* Symbolic link. */ +#define FTW_SLN 6 /* Sym link that names a nonexistent file. */ + +/* + * Flags for use as the 4th argument to nftw(3). These may be ORed together. + */ +#define FTW_PHYS 0x01 /* Physical walk, don't follow sym links. */ +#define FTW_MOUNT 0x02 /* The walk does not cross a mount point. */ +#define FTW_DEPTH 0x04 /* Subdirs visited before the dir itself. */ +#define FTW_CHDIR 0x08 /* Change to a directory before reading it. */ + +struct FTW { + int base; + int level; +}; + +__BEGIN_DECLS +int ftw(const char *, int (*)(const char *, const struct stat *, int), int); +int nftw(const char *, int (*)(const char *, const struct stat *, int, + struct FTW *), int, int); +__END_DECLS + +#endif /* !_FTW_H */ diff --git a/lib/libc/include/any-freebsd-any/getopt.h b/lib/libc/include/any-freebsd-any/getopt.h new file mode 100644 index 000000000000..789b4d1d434c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/getopt.h @@ -0,0 +1,80 @@ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#include + +/* + * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension. + * getopt() is declared here too for GNU programs. + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +__BEGIN_DECLS +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +#endif +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED +extern int optreset; /* getopt(3) external variable */ +#endif +__END_DECLS + +#endif /* !_GETOPT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/glob.h b/lib/libc/include/any-freebsd-any/glob.h new file mode 100644 index 000000000000..80d78a219444 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/glob.h @@ -0,0 +1,108 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)glob.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _GLOB_H_ +#define _GLOB_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +struct stat; +typedef struct { + size_t gl_pathc; /* Count of total paths so far. */ + size_t gl_matchc; /* Count of paths matching pattern. */ + size_t gl_offs; /* Reserved at beginning of gl_pathv. */ + int gl_flags; /* Copy of flags parameter to glob. */ + char **gl_pathv; /* List of paths matching pattern. */ + /* Copy of errfunc parameter to glob. */ + int (*gl_errfunc)(const char *, int); + + /* + * Alternate filesystem access methods for glob; replacement + * versions of closedir(3), readdir(3), opendir(3), stat(2) + * and lstat(2). + */ + void (*gl_closedir)(void *); + struct dirent *(*gl_readdir)(void *); + void *(*gl_opendir)(const char *); + int (*gl_lstat)(const char *, struct stat *); + int (*gl_stat)(const char *, struct stat *); +} glob_t; + +#if __POSIX_VISIBLE >= 199209 +/* Believed to have been introduced in 1003.2-1992 */ +#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ +#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ +#define GLOB_ERR 0x0004 /* Return on error. */ +#define GLOB_MARK 0x0008 /* Append / to matching directories. */ +#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOSORT 0x0020 /* Don't sort. */ +#define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */ + +/* Error values returned by glob(3) */ +#define GLOB_NOSPACE (-1) /* Malloc call failed. */ +#define GLOB_ABORTED (-2) /* Unignored error. */ +#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */ +#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */ +#endif /* __POSIX_VISIBLE >= 199209 */ + +#if __BSD_VISIBLE +#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ +#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ +#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ +#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ +#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ +#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#define GLOB_LIMIT 0x1000 /* limit number of returned paths */ + +/* source compatibility, these are the old names */ +#define GLOB_MAXPATH GLOB_LIMIT +#define GLOB_ABEND GLOB_ABORTED +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +int glob(const char * __restrict, int, + int (*)(const char *, int), glob_t * __restrict); +void globfree(glob_t *); +__END_DECLS + +#endif /* !_GLOB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/grp.h b/lib/libc/include/any-freebsd-any/grp.h new file mode 100644 index 000000000000..655bfdc66ec8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/grp.h @@ -0,0 +1,94 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)grp.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _GRP_H_ +#define _GRP_H_ + +#include +#include + +#define _PATH_GROUP "/etc/group" + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +struct group { + char *gr_name; /* group name */ + char *gr_passwd; /* group password */ + gid_t gr_gid; /* group id */ + char **gr_mem; /* group members */ +}; + +__BEGIN_DECLS +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +void endgrent(void); +struct group *getgrent(void); +#endif +struct group *getgrgid(gid_t); +struct group *getgrnam(const char *); +#if __BSD_VISIBLE +const char *group_from_gid(gid_t, int); +int gid_from_group(const char *, gid_t *); +int pwcache_groupdb(int (*)(int), void (*)(void), + struct group * (*)(const char *), + struct group * (*)(gid_t)); +#endif +#if __XSI_VISIBLE +void setgrent(void); +#endif +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +int getgrgid_r(gid_t, struct group *, char *, size_t, + struct group **); +int getgrnam_r(const char *, struct group *, char *, size_t, + struct group **); +#endif +#if __BSD_VISIBLE +int getgrent_r(struct group *, char *, size_t, struct group **); +int setgroupent(int); +#endif +__END_DECLS + +#endif /* !_GRP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/gssapi.h b/lib/libc/include/any-freebsd-any/gssapi.h new file mode 100644 index 000000000000..5557de8f7356 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/gssapi.h @@ -0,0 +1,5 @@ +/* $FreeBSD$ */ +#ifdef __GNUC__ +#warning "this file includes which is deprecated, use instead" +#endif +#include diff --git a/lib/libc/include/any-freebsd-any/gssapi/gssapi.h b/lib/libc/include/any-freebsd-any/gssapi/gssapi.h new file mode 100644 index 000000000000..bd2722c9a582 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/gssapi/gssapi.h @@ -0,0 +1,876 @@ +/* + * Copyright (C) The Internet Society (2000). All Rights Reserved. + * + * This document and translations of it may be copied and furnished to + * others, and derivative works that comment on or otherwise explain it + * or assist in its implementation may be prepared, copied, published + * and distributed, in whole or in part, without restriction of any + * kind, provided that the above copyright notice and this paragraph are + * included on all such copies and derivative works. However, this + * document itself may not be modified in any way, such as by removing + * the copyright notice or references to the Internet Society or other + * Internet organizations, except as needed for the purpose of + * developing Internet standards in which case the procedures for + * copyrights defined in the Internet Standards process must be + * followed, or as required to translate it into languages other than + * English. + * + * The limited permissions granted above are perpetual and will not be + * revoked by the Internet Society or its successors or assigns. + * + * This document and the information contained herein is provided on an + * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING + * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION + * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * $FreeBSD$ + */ + +#ifndef _GSSAPI_GSSAPI_H_ +#define _GSSAPI_GSSAPI_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +/* Compatibility with Heimdal 1.5.1 */ +#ifndef GSSAPI_CPP_START +#ifdef __cplusplus +#define GSSAPI_CPP_START extern "C" { +#define GSSAPI_CPP_END } +#else +#define GSSAPI_CPP_START +#define GSSAPI_CPP_END +#endif +#endif + +/* Compatibility with Heimdal 1.5.1 */ +#ifndef BUILD_GSSAPI_LIB +#define GSSAPI_LIB_FUNCTION +#define GSSAPI_LIB_CALL +#define GSSAPI_LIB_VARIABLE +#endif + +/* Compatibility with Heimdal 1.5.1 */ +#ifndef GSSAPI_DEPRECATED_FUNCTION +#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 ))) +#define GSSAPI_DEPRECATED_FUNCTION(X) __attribute__((deprecated)) +#else +#define GSSAPI_DEPRECATED_FUNCTION(X) +#endif +#endif + +#if 0 +/* + * If the platform supports the xom.h header file, it should be + * included here. + */ +#include +#endif + + +/* + * Now define the three implementation-dependent types. + */ +typedef struct _gss_ctx_id_t *gss_ctx_id_t; +typedef struct _gss_cred_id_t *gss_cred_id_t; +typedef struct _gss_name_t *gss_name_t; + +/* + * The following type must be defined as the smallest natural + * unsigned integer supported by the platform that has at least + * 32 bits of precision. + */ +typedef __uint32_t gss_uint32; + + +#ifdef OM_STRING +/* + * We have included the xom.h header file. Verify that OM_uint32 + * is defined correctly. + */ + +#if sizeof(gss_uint32) != sizeof(OM_uint32) +#error Incompatible definition of OM_uint32 from xom.h +#endif + +typedef OM_object_identifier gss_OID_desc, *gss_OID; + +#else + +/* + * We can't use X/Open definitions, so roll our own. + */ + +typedef gss_uint32 OM_uint32; +typedef __uint64_t OM_uint64; + +typedef struct gss_OID_desc_struct { + OM_uint32 length; + void *elements; +} gss_OID_desc, *gss_OID; + +#endif + +typedef struct gss_OID_set_desc_struct { + size_t count; + gss_OID elements; +} gss_OID_set_desc, *gss_OID_set; + +typedef struct gss_buffer_desc_struct { + size_t length; + void *value; +} gss_buffer_desc, *gss_buffer_t; + +typedef struct gss_channel_bindings_struct { + OM_uint32 initiator_addrtype; + gss_buffer_desc initiator_address; + OM_uint32 acceptor_addrtype; + gss_buffer_desc acceptor_address; + gss_buffer_desc application_data; +} *gss_channel_bindings_t; + +/* + * For now, define a QOP-type as an OM_uint32 + */ +typedef OM_uint32 gss_qop_t; + +typedef int gss_cred_usage_t; + +/* + * Flag bits for context-level services. + */ +#define GSS_C_DELEG_FLAG 1 +#define GSS_C_MUTUAL_FLAG 2 +#define GSS_C_REPLAY_FLAG 4 +#define GSS_C_SEQUENCE_FLAG 8 +#define GSS_C_CONF_FLAG 16 +#define GSS_C_INTEG_FLAG 32 +#define GSS_C_ANON_FLAG 64 +#define GSS_C_PROT_READY_FLAG 128 +#define GSS_C_TRANS_FLAG 256 + +/* + * Credential usage options + */ +#define GSS_C_BOTH 0 +#define GSS_C_INITIATE 1 +#define GSS_C_ACCEPT 2 + +/* + * Status code types for gss_display_status + */ +#define GSS_C_GSS_CODE 1 +#define GSS_C_MECH_CODE 2 + +/* + * The constant definitions for channel-bindings address families + */ +#define GSS_C_AF_UNSPEC 0 +#define GSS_C_AF_LOCAL 1 +#define GSS_C_AF_INET 2 +#define GSS_C_AF_IMPLINK 3 +#define GSS_C_AF_PUP 4 +#define GSS_C_AF_CHAOS 5 +#define GSS_C_AF_NS 6 +#define GSS_C_AF_NBS 7 +#define GSS_C_AF_ECMA 8 +#define GSS_C_AF_DATAKIT 9 +#define GSS_C_AF_CCITT 10 +#define GSS_C_AF_SNA 11 +#define GSS_C_AF_DECnet 12 +#define GSS_C_AF_DLI 13 +#define GSS_C_AF_LAT 14 +#define GSS_C_AF_HYLINK 15 +#define GSS_C_AF_APPLETALK 16 +#define GSS_C_AF_BSC 17 +#define GSS_C_AF_DSS 18 +#define GSS_C_AF_OSI 19 +#define GSS_C_AF_X25 21 +#define GSS_C_AF_NULLADDR 255 + +/* + * Various Null values + */ +#define GSS_C_NO_NAME ((gss_name_t) 0) +#define GSS_C_NO_BUFFER ((gss_buffer_t) 0) +#define GSS_C_NO_OID ((gss_OID) 0) +#define GSS_C_NO_OID_SET ((gss_OID_set) 0) +#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0) +#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0) +#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0) +#define GSS_C_EMPTY_BUFFER {0, NULL} + +/* + * Some alternate names for a couple of the above + * values. These are defined for V1 compatibility. + */ +#define GSS_C_NULL_OID GSS_C_NO_OID +#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET + +/* + * Define the default Quality of Protection for per-message + * services. Note that an implementation that offers multiple + * levels of QOP may define GSS_C_QOP_DEFAULT to be either zero + * (as done here) to mean "default protection", or to a specific + * explicit QOP value. However, a value of 0 should always be + * interpreted by a GSS-API implementation as a request for the + * default protection level. + */ +#define GSS_C_QOP_DEFAULT 0 + +/* + * Expiration time of 2^32-1 seconds means infinite lifetime for a + * credential or security context + */ +#define GSS_C_INDEFINITE 0xfffffffful + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x01"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_USER_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x02"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_MACHINE_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x03"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_STRING_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + * corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ +extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x04"}, corresponding to an + * object-identifier value of {iso(1) member-body(2) + * Unites States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The constant + * GSS_C_NT_HOSTBASED_SERVICE should be initialized + * to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + * corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_ANONYMOUS; + + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + * corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_EXPORT_NAME; + +/* + * This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5_name(1)}. The recommended symbolic name for this type + * is "GSS_KRB5_NT_PRINCIPAL_NAME". + */ +extern gss_OID GSS_KRB5_NT_PRINCIPAL_NAME; + +/* + * This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) user_name(1)}. The recommended symbolic name for this + * type is "GSS_KRB5_NT_USER_NAME". + */ +extern gss_OID GSS_KRB5_NT_USER_NAME; + +/* + * This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) machine_uid_name(2)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_MACHINE_UID_NAME". + */ +extern gss_OID GSS_KRB5_NT_MACHINE_UID_NAME; + +/* + * This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) string_uid_name(3)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_STRING_UID_NAME". + */ +extern gss_OID GSS_KRB5_NT_STRING_UID_NAME; + +/* Major status codes */ + +#define GSS_S_COMPLETE 0 + +/* + * Some "helper" definitions to make the status code macros obvious. + */ +#define GSS_C_CALLING_ERROR_OFFSET 24 +#define GSS_C_ROUTINE_ERROR_OFFSET 16 +#define GSS_C_SUPPLEMENTARY_OFFSET 0 +#define GSS_C_CALLING_ERROR_MASK 0377ul +#define GSS_C_ROUTINE_ERROR_MASK 0377ul +#define GSS_C_SUPPLEMENTARY_MASK 0177777ul + +/* + * The macros that test status codes for error conditions. + * Note that the GSS_ERROR() macro has changed slightly from + * the V1 GSS-API so that it now evaluates its argument + * only once. + */ +#define GSS_CALLING_ERROR(x) \ + (x & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET)) +#define GSS_ROUTINE_ERROR(x) \ + (x & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)) +#define GSS_SUPPLEMENTARY_INFO(x) \ + (x & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET)) +#define GSS_ERROR(x) \ + (x & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \ + (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))) + +/* + * Now the actual status code definitions + */ + +/* + * Calling errors: + */ +#define GSS_S_CALL_INACCESSIBLE_READ \ +(1ul << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_INACCESSIBLE_WRITE \ +(2ul << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_BAD_STRUCTURE \ +(3ul << GSS_C_CALLING_ERROR_OFFSET) + +/* + * Routine errors: + */ +#define GSS_S_BAD_MECH (1ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAME (2ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAMETYPE (3ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_BINDINGS (4ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_STATUS (5ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_SIG (6ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MIC GSS_S_BAD_SIG +#define GSS_S_NO_CRED (7ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NO_CONTEXT (8ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_TOKEN (9ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_CREDENTIAL (10ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CREDENTIALS_EXPIRED (11ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CONTEXT_EXPIRED (12ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_FAILURE (13ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_QOP (14ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAUTHORIZED (15ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAVAILABLE (16ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DUPLICATE_ELEMENT (17ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NAME_NOT_MN (18ul << GSS_C_ROUTINE_ERROR_OFFSET) + +/* + * Supplementary info bits: + */ +#define GSS_S_CONTINUE_NEEDED \ + (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 0)) +#define GSS_S_DUPLICATE_TOKEN \ + (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 1)) +#define GSS_S_OLD_TOKEN \ + (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 2)) +#define GSS_S_UNSEQ_TOKEN \ + (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 3)) +#define GSS_S_GAP_TOKEN \ + (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 4)) + +__BEGIN_DECLS + +/* + * Finally, function prototypes for the GSS-API routines. + */ +OM_uint32 gss_acquire_cred + (OM_uint32 *, /* minor_status */ + const gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + const gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 * /* time_rec */ + ); + +OM_uint32 gss_release_cred + (OM_uint32 *, /* minor_status */ + gss_cred_id_t * /* cred_handle */ + ); + +OM_uint32 gss_init_sec_context + (OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* initiator_cred_handle */ + gss_ctx_id_t *, /* context_handle */ + const gss_name_t, /* target_name */ + const gss_OID, /* mech_type */ + OM_uint32, /* req_flags */ + OM_uint32, /* time_req */ + const gss_channel_bindings_t, + /* input_chan_bindings */ + const gss_buffer_t, /* input_token */ + gss_OID *, /* actual_mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 * /* time_rec */ + ); + +OM_uint32 gss_accept_sec_context + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + const gss_cred_id_t, /* acceptor_cred_handle */ + const gss_buffer_t, /* input_token_buffer */ + const gss_channel_bindings_t, + /* input_chan_bindings */ + gss_name_t *, /* src_name */ + gss_OID *, /* mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 *, /* time_rec */ + gss_cred_id_t * /* delegated_cred_handle */ + ); + +OM_uint32 gss_process_context_token + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + const gss_buffer_t /* token_buffer */ + ); + +OM_uint32 gss_delete_sec_context + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t /* output_token */ + ); + +OM_uint32 gss_context_time + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + OM_uint32 * /* time_rec */ + ); + +OM_uint32 gss_get_mic + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + const gss_buffer_t, /* message_buffer */ + gss_buffer_t /* message_token */ + ); + +OM_uint32 gss_verify_mic + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + const gss_buffer_t, /* message_buffer */ + const gss_buffer_t, /* token_buffer */ + gss_qop_t * /* qop_state */ + ); + +OM_uint32 gss_wrap + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + const gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t /* output_message_buffer */ + ); + +OM_uint32 gss_unwrap + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + const gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + gss_qop_t * /* qop_state */ + ); + +OM_uint32 gss_display_status + (OM_uint32 *, /* minor_status */ + OM_uint32, /* status_value */ + int, /* status_type */ + const gss_OID, /* mech_type */ + OM_uint32 *, /* message_context */ + gss_buffer_t /* status_string */ + ); + +OM_uint32 gss_indicate_mechs + (OM_uint32 *, /* minor_status */ + gss_OID_set * /* mech_set */ + ); + +OM_uint32 gss_compare_name + (OM_uint32 *, /* minor_status */ + const gss_name_t, /* name1 */ + const gss_name_t, /* name2 */ + int * /* name_equal */ + ); + +OM_uint32 gss_display_name + (OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_buffer_t, /* output_name_buffer */ + gss_OID * /* output_name_type */ + ); + +OM_uint32 gss_import_name + (OM_uint32 *, /* minor_status */ + const gss_buffer_t, /* input_name_buffer */ + const gss_OID, /* input_name_type */ + gss_name_t * /* output_name */ + ); + +OM_uint32 gss_export_name + (OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_buffer_t /* exported_name */ + ); + +OM_uint32 gss_release_name + (OM_uint32 *, /* minor_status */ + gss_name_t * /* input_name */ + ); + +OM_uint32 gss_release_buffer + (OM_uint32 *, /* minor_status */ + gss_buffer_t /* buffer */ + ); + +OM_uint32 gss_release_oid_set + (OM_uint32 *, /* minor_status */ + gss_OID_set * /* set */ + ); + +OM_uint32 gss_inquire_cred + (OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* cred_handle */ + gss_name_t *, /* name */ + OM_uint32 *, /* lifetime */ + gss_cred_usage_t *, /* cred_usage */ + gss_OID_set * /* mechanisms */ + ); + +OM_uint32 gss_inquire_context ( + OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + gss_name_t *, /* src_name */ + gss_name_t *, /* targ_name */ + OM_uint32 *, /* lifetime_rec */ + gss_OID *, /* mech_type */ + OM_uint32 *, /* ctx_flags */ + int *, /* locally_initiated */ + int * /* open */ + ); + +OM_uint32 gss_wrap_size_limit ( + OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + OM_uint32, /* req_output_size */ + OM_uint32 * /* max_input_size */ + ); + +OM_uint32 gss_add_cred ( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* input_cred_handle */ + const gss_name_t, /* desired_name */ + const gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 * /* acceptor_time_rec */ + ); + +OM_uint32 gss_inquire_cred_by_mech ( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* cred_handle */ + const gss_OID, /* mech_type */ + gss_name_t *, /* name */ + OM_uint32 *, /* initiator_lifetime */ + OM_uint32 *, /* acceptor_lifetime */ + gss_cred_usage_t * /* cred_usage */ + ); + +OM_uint32 gss_export_sec_context ( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t /* interprocess_token */ + ); + +OM_uint32 gss_import_sec_context ( + OM_uint32 *, /* minor_status */ + const gss_buffer_t, /* interprocess_token */ + gss_ctx_id_t * /* context_handle */ + ); + +OM_uint32 gss_create_empty_oid_set ( + OM_uint32 *, /* minor_status */ + gss_OID_set * /* oid_set */ + ); + +OM_uint32 gss_add_oid_set_member ( + OM_uint32 *, /* minor_status */ + const gss_OID, /* member_oid */ + gss_OID_set * /* oid_set */ + ); + +OM_uint32 gss_test_oid_set_member ( + OM_uint32 *, /* minor_status */ + const gss_OID, /* member */ + const gss_OID_set, /* set */ + int * /* present */ + ); + +OM_uint32 gss_inquire_names_for_mech ( + OM_uint32 *, /* minor_status */ + const gss_OID, /* mechanism */ + gss_OID_set * /* name_types */ + ); + +OM_uint32 gss_inquire_mechs_for_name ( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_OID_set * /* mech_types */ + ); + +OM_uint32 gss_canonicalize_name ( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + const gss_OID, /* mech_type */ + gss_name_t * /* output_name */ + ); + +OM_uint32 gss_duplicate_name ( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* src_name */ + gss_name_t * /* dest_name */ + ); + +/* + * The following routines are obsolete variants of gss_get_mic, + * gss_verify_mic, gss_wrap and gss_unwrap. They should be + * provided by GSS-API V2 implementations for backwards + * compatibility with V1 applications. Distinct entrypoints + * (as opposed to #defines) should be provided, both to allow + * GSS-API V1 applications to link against GSS-API V2 implementations, + * and to retain the slight parameter type differences between the + * obsolete versions of these routines and their current forms. + */ + +OM_uint32 gss_sign + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* qop_req */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t /* message_token */ + ); + + +OM_uint32 gss_verify + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t, /* token_buffer */ + int * /* qop_state */ + ); + +OM_uint32 gss_seal + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + int, /* qop_req */ + gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t /* output_message_buffer */ + ); + + +OM_uint32 gss_unseal + (OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + int * /* qop_state */ + ); + +/* + * Other extensions and helper functions. + */ + +int gss_oid_equal + (const gss_OID, /* first OID to compare */ + const gss_OID /* second OID to compare */ + ); + +OM_uint32 gss_release_oid + (OM_uint32 *, /* minor status */ + gss_OID * /* oid to free */ + ); + +OM_uint32 gss_decapsulate_token + (const gss_buffer_t, /* mechanism independent token */ + gss_OID, /* desired mechanism */ + gss_buffer_t /* decapsulated mechanism dependent token */ + ); + +OM_uint32 gss_encapsulate_token + (const gss_buffer_t, /* mechanism dependent token */ + gss_OID, /* desired mechanism */ + gss_buffer_t /* encapsulated mechanism independent token */ + ); + +OM_uint32 gss_duplicate_oid + (OM_uint32 *, /* minor status */ + const gss_OID, /* oid to copy */ + gss_OID * /* result */ + ); + +OM_uint32 gss_oid_to_str + (OM_uint32 *, /* minor status */ + gss_OID, /* oid to convert */ + gss_buffer_t /* buffer to contain string */ + ); + +typedef struct gss_buffer_set_desc_struct { + size_t count; + gss_buffer_desc *elements; +} gss_buffer_set_desc, *gss_buffer_set_t; + +#define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t) 0) + +OM_uint32 gss_create_empty_buffer_set + (OM_uint32 *, /* minor status */ + gss_buffer_set_t * /* location for new buffer set */ + ); + +OM_uint32 gss_add_buffer_set_member + (OM_uint32 *, /* minor status */ + gss_buffer_t, /* buffer to add */ + gss_buffer_set_t * /* set to add to */ + ); + +OM_uint32 gss_release_buffer_set + (OM_uint32 *, /* minor status */ + gss_buffer_set_t * /* set to release */ + ); + +OM_uint32 gss_inquire_sec_context_by_oid + (OM_uint32 *, /* minor_status */ + const gss_ctx_id_t, /* context_handle */ + const gss_OID, /* desired_object */ + gss_buffer_set_t * /* result */ + ); + +OM_uint32 gss_inquire_cred_by_oid + (OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* cred_handle */ + const gss_OID, /* desired_object */ + gss_buffer_set_t * /* result */ + ); + +OM_uint32 gss_set_sec_context_option + (OM_uint32 *, /* minor status */ + gss_ctx_id_t *, /* context */ + const gss_OID, /* option to set */ + const gss_buffer_t /* option value */ + ); + +OM_uint32 gss_set_cred_option + (OM_uint32 *, /* minor status */ + gss_cred_id_t *, /* cred */ + const gss_OID, /* option to set */ + const gss_buffer_t /* option value */ + ); + +OM_uint32 gss_pseudo_random + (OM_uint32 *, /* minor status */ + gss_ctx_id_t, /* context handle */ + int prf_key, /* XXX */ + const gss_buffer_t, /* data to seed generator */ + ssize_t, /* amount of data required */ + gss_buffer_t /* buffer for result */ + ); + +#ifdef _UID_T_DECLARED +OM_uint32 gss_pname_to_uid + (OM_uint32 *, /* minor status */ + const gss_name_t pname, /* principal name */ + const gss_OID mech, /* mechanism to query */ + uid_t *uidp /* pointer to UID for result */ + ); +#endif + +__END_DECLS + +#endif /* _GSSAPI_GSSAPI_H_ */ diff --git a/lib/libc/include/any-freebsd-any/hesiod.h b/lib/libc/include/any-freebsd-any/hesiod.h new file mode 100644 index 000000000000..e8c38d84dccb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/hesiod.h @@ -0,0 +1,93 @@ +/* $NetBSD: hesiod.h,v 1.3 1999/01/24 23:53:18 lukem Exp $ */ +/* $FreeBSD$ */ + + +/*- + * SPDX-License-Identifier: (BSD-2-Clause-NetBSD AND ISC) + * + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifndef _HESIOD_H_ +#define _HESIOD_H_ + + /* Application-visible indication that we have the new interfaces */ + +#define HESIOD_INTERFACES + + /* Configuration information. */ + +#ifndef _PATH_HESIOD_CONF /* Configuration file. */ +#define _PATH_HESIOD_CONF "/etc/hesiod.conf" +#endif + +#define DEF_RHS "" /* Defaults if HESIOD_CONF */ +#define DEF_LHS "" /* file is not present. */ + + /* Error codes (for backwards compatibility) */ + +#define HES_ER_UNINIT -1 /* uninitialized */ +#define HES_ER_OK 0 /* no error */ +#define HES_ER_NOTFOUND 1 /* Hesiod name not found by server */ +#define HES_ER_CONFIG 2 /* local problem (no config file?) */ +#define HES_ER_NET 3 /* network problem */ + + /* Declaration of routines */ + +#include + +__BEGIN_DECLS +int hesiod_init(void **); +char **hesiod_resolve(void *, const char *, const char *); +void hesiod_free_list(void *, char **); +char *hesiod_to_bind(void *, const char *, const char *); +void hesiod_end(void *); + + /* backwards compatibility */ +int hes_init(void); +char *hes_to_bind(const char *, const char *); +char **hes_resolve(const char *, const char *); +int hes_error(void); +void hes_free(char **); +__END_DECLS + +#endif /* ! _HESIOD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/iconv.h b/lib/libc/include/any-freebsd-any/iconv.h new file mode 100644 index 000000000000..338ca1544d8a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/iconv.h @@ -0,0 +1,135 @@ +/* $FreeBSD$ */ +/* $NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2003 Citrus Project, + * Copyright (c) 2009, 2010 Gabor Kovesdan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _ICONV_H_ +#define _ICONV_H_ + +#include +#include + +#include + +#include +#include + +#ifdef __cplusplus +typedef bool __iconv_bool; +#elif __STDC_VERSION__ >= 199901L +typedef _Bool __iconv_bool; +#else +typedef int __iconv_bool; +#endif + +struct __tag_iconv_t; +typedef struct __tag_iconv_t *iconv_t; + +__BEGIN_DECLS +iconv_t iconv_open(const char *, const char *); +size_t iconv(iconv_t, char ** __restrict, + size_t * __restrict, char ** __restrict, + size_t * __restrict); +int iconv_close(iconv_t); +/* + * non-portable interfaces for iconv + */ +int __iconv_get_list(char ***, size_t *, __iconv_bool); +void __iconv_free_list(char **, size_t); +size_t __iconv(iconv_t, char **, size_t *, char **, + size_t *, __uint32_t, size_t *); +#define __ICONV_F_HIDE_INVALID 0x0001 + +/* + * GNU interfaces for iconv + */ +typedef struct { + void *spaceholder[64]; +} iconv_allocation_t; + +int iconv_open_into(const char *, const char *, iconv_allocation_t *); +void iconv_set_relocation_prefix(const char *, const char *); + +/* + * iconvctl() request macros + */ +#define ICONV_TRIVIALP 0 +#define ICONV_GET_TRANSLITERATE 1 +#define ICONV_SET_TRANSLITERATE 2 +#define ICONV_GET_DISCARD_ILSEQ 3 +#define ICONV_SET_DISCARD_ILSEQ 4 +#define ICONV_SET_HOOKS 5 +#define ICONV_SET_FALLBACKS 6 +#define ICONV_GET_ILSEQ_INVALID 128 +#define ICONV_SET_ILSEQ_INVALID 129 + +typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data); +typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data); + +struct iconv_hooks { + iconv_unicode_char_hook uc_hook; + iconv_wide_char_hook wc_hook; + void *data; +}; + +/* + * Fallbacks aren't supported but type definitions are provided for + * source compatibility. + */ +typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*, + size_t, void (*write_replacement) (const unsigned int *, + size_t, void*), void*, void*); +typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int, + void (*write_replacement) (const char *, size_t, void*), + void*, void*); +typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t, + void (*write_replacement) (const wchar_t *, size_t, void*), + void*, void*); +typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t, + void (*write_replacement) (const char *, size_t, void*), + void*, void*); + +struct iconv_fallbacks { + iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; + iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; + iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; + iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; + void *data; +}; + + +void iconvlist(int (*do_one) (unsigned int, const char * const *, + void *), void *); +const char *iconv_canonicalize(const char *); +int iconvctl(iconv_t, int, void *); +__END_DECLS + +#endif /* !_ICONV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ieeefp.h b/lib/libc/include/any-freebsd-any/ieeefp.h new file mode 100644 index 000000000000..3f64555d5a14 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ieeefp.h @@ -0,0 +1,15 @@ +/* $NetBSD: ieeefp.h,v 1.4 1998/01/09 08:03:43 perry Exp $ */ +/* $FreeBSD$ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _IEEEFP_H_ +#define _IEEEFP_H_ + +#include +#include + +#endif /* _IEEEFP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ifaddrs.h b/lib/libc/include/any-freebsd-any/ifaddrs.h new file mode 100644 index 000000000000..5e1953639af6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ifaddrs.h @@ -0,0 +1,67 @@ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-1-Clause + * + * Copyright (c) 1995, 1999 + * Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp + */ + +#ifndef _IFADDRS_H_ +#define _IFADDRS_H_ + +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + unsigned int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; + +/* + * This may have been defined in . Note that if is + * to be included it must be included before this header file. + */ +#ifndef ifa_broadaddr +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ +#endif + +struct ifmaddrs { + struct ifmaddrs *ifma_next; + struct sockaddr *ifma_name; + struct sockaddr *ifma_addr; + struct sockaddr *ifma_lladdr; +}; + +#include + +__BEGIN_DECLS +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); +extern int getifmaddrs(struct ifmaddrs **); +extern void freeifmaddrs(struct ifmaddrs *); +__END_DECLS + +#endif diff --git a/lib/libc/include/any-freebsd-any/inttypes.h b/lib/libc/include/any-freebsd-any/inttypes.h new file mode 100644 index 000000000000..adf74e5a3e9d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/inttypes.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ + +#include +#include + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef ___wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +typedef struct { + intmax_t quot; /* Quotient. */ + intmax_t rem; /* Remainder. */ +} imaxdiv_t; + +__BEGIN_DECLS +#ifdef _XLOCALE_H_ +#include +#endif +intmax_t imaxabs(intmax_t) __pure2; +imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2; + +intmax_t strtoimax(const char * __restrict, char ** __restrict, int); +uintmax_t strtoumax(const char * __restrict, char ** __restrict, int); +intmax_t wcstoimax(const wchar_t * __restrict, + wchar_t ** __restrict, int); +uintmax_t wcstoumax(const wchar_t * __restrict, + wchar_t ** __restrict, int); +__END_DECLS + +#endif /* !_INTTYPES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/iso646.h b/lib/libc/include/any-freebsd-any/iso646.h new file mode 100644 index 000000000000..a2ab46abf4e0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/iso646.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 Alex Nash + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ISO646_H_ +#define _ISO646_H_ + +#ifndef __cplusplus + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= + +#endif /* !__cplusplus */ + +#endif /* !_ISO646_H_ */ diff --git a/lib/libc/include/any-freebsd-any/kenv.h b/lib/libc/include/any-freebsd-any/kenv.h new file mode 100644 index 000000000000..0f5e8a92fa27 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/kenv.h @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Maxime Henrion + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _KENV_H_ +#define _KENV_H_ + +#include +#include + +__BEGIN_DECLS +int kenv(int, const char *, char *, int); +__END_DECLS + +#endif /* !_KENV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/langinfo.h b/lib/libc/include/any-freebsd-any/langinfo.h new file mode 100644 index 000000000000..87273072a905 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/langinfo.h @@ -0,0 +1,141 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Alexey Zelkin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LANGINFO_H_ +#define _LANGINFO_H_ + +#include +#include + +#ifndef _NL_ITEM_DECLARED +typedef __nl_item nl_item; +#define _NL_ITEM_DECLARED +#endif + +#define CODESET 0 /* codeset name */ +#define D_T_FMT 1 /* string for formatting date and time */ +#define D_FMT 2 /* date format string */ +#define T_FMT 3 /* time format string */ +#define T_FMT_AMPM 4 /* a.m. or p.m. time formatting string */ +#define AM_STR 5 /* Ante Meridian affix */ +#define PM_STR 6 /* Post Meridian affix */ + +/* week day names */ +#define DAY_1 7 +#define DAY_2 8 +#define DAY_3 9 +#define DAY_4 10 +#define DAY_5 11 +#define DAY_6 12 +#define DAY_7 13 + +/* abbreviated week day names */ +#define ABDAY_1 14 +#define ABDAY_2 15 +#define ABDAY_3 16 +#define ABDAY_4 17 +#define ABDAY_5 18 +#define ABDAY_6 19 +#define ABDAY_7 20 + +/* month names */ +#define MON_1 21 +#define MON_2 22 +#define MON_3 23 +#define MON_4 24 +#define MON_5 25 +#define MON_6 26 +#define MON_7 27 +#define MON_8 28 +#define MON_9 29 +#define MON_10 30 +#define MON_11 31 +#define MON_12 32 + +/* abbreviated month names */ +#define ABMON_1 33 +#define ABMON_2 34 +#define ABMON_3 35 +#define ABMON_4 36 +#define ABMON_5 37 +#define ABMON_6 38 +#define ABMON_7 39 +#define ABMON_8 40 +#define ABMON_9 41 +#define ABMON_10 42 +#define ABMON_11 43 +#define ABMON_12 44 + +#define ERA 45 /* era description segments */ +#define ERA_D_FMT 46 /* era date format string */ +#define ERA_D_T_FMT 47 /* era date and time format string */ +#define ERA_T_FMT 48 /* era time format string */ +#define ALT_DIGITS 49 /* alternative symbols for digits */ + +#define RADIXCHAR 50 /* radix char */ +#define THOUSEP 51 /* separator for thousands */ + +#define YESEXPR 52 /* affirmative response expression */ +#define NOEXPR 53 /* negative response expression */ + +#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE <= 500) +#define YESSTR 54 /* affirmative response for yes/no queries */ +#define NOSTR 55 /* negative response for yes/no queries */ +#endif + +#define CRNCYSTR 56 /* currency symbol */ + +#if __BSD_VISIBLE +#define D_MD_ORDER 57 /* month/day order (local extension) */ +#endif + +/* standalone months forms for %OB */ +#define ALTMON_1 58 +#define ALTMON_2 59 +#define ALTMON_3 60 +#define ALTMON_4 61 +#define ALTMON_5 62 +#define ALTMON_6 63 +#define ALTMON_7 64 +#define ALTMON_8 65 +#define ALTMON_9 66 +#define ALTMON_10 67 +#define ALTMON_11 68 +#define ALTMON_12 69 + +__BEGIN_DECLS +char *nl_langinfo(nl_item); + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif +__END_DECLS + +#endif /* !_LANGINFO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/libgen.h b/lib/libc/include/any-freebsd-any/libgen.h new file mode 100644 index 000000000000..615d1dd6202e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/libgen.h @@ -0,0 +1,65 @@ +/* $OpenBSD: libgen.h,v 1.4 1999/05/28 22:00:22 espie Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIBGEN_H_ +#define _LIBGEN_H_ + +#include + +__BEGIN_DECLS +char *basename(char *); +char *dirname(char *); +__END_DECLS + +/* + * In FreeBSD 12, the prototypes of basename() and dirname() were + * modified to comply to POSIX. These functions may now modify their + * input. Unfortunately, our copy of xinstall(8) shipped with previous + * versions of FreeBSD is built using the host headers and libc during + * the bootstrapping phase and depends on the old behavior. + * + * Apply a workaround where we explicitly link against basename@FBSD_1.0 + * and dirname@FBSD_1.0 in case these functions are called on constant + * strings, instead of making the program crash at runtime. + */ +#if defined(__generic) && !defined(__cplusplus) +__BEGIN_DECLS +char *__old_basename(char *); +char *__old_dirname(char *); +__END_DECLS +__sym_compat(basename, __old_basename, FBSD_1.0); +__sym_compat(dirname, __old_dirname, FBSD_1.0); +#define basename(x) __generic(x, const char *, __old_basename, basename)(x) +#define dirname(x) __generic(x, const char *, __old_dirname, dirname)(x) +#endif + +#endif /* !_LIBGEN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/limits.h b/lib/libc/include/any-freebsd-any/limits.h new file mode 100644 index 000000000000..fc1470c058cb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/limits.h @@ -0,0 +1,149 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)limits.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + +#include + +#if __POSIX_VISIBLE +#define _POSIX_ARG_MAX 4096 +#define _POSIX_LINK_MAX 8 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_NAME_MAX 14 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_STREAM_MAX 8 + +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_CHILD_MAX 25 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_PATH_MAX 256 +#define _POSIX_TZNAME_MAX 6 +#else +#define _POSIX_CHILD_MAX 6 +#define _POSIX_NGROUPS_MAX 0 +#define _POSIX_OPEN_MAX 16 +#define _POSIX_PATH_MAX 255 +#define _POSIX_TZNAME_MAX 3 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define BC_BASE_MAX 99 /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 2048 /* max array elements in bc(1) */ +#define BC_SCALE_MAX 99 /* max scale value in bc(1) */ +#define BC_STRING_MAX 1000 /* max const string length in bc(1) */ +#define CHARCLASS_NAME_MAX 14 /* max character class name size */ +#define COLL_WEIGHTS_MAX 10 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#define RE_DUP_MAX 255 /* max RE's in interval notation */ + +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_CHARCLASS_NAME_MAX 14 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX2_EQUIV_CLASS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 +#endif +#endif + +#if __POSIX_VISIBLE >= 199309 +#define _POSIX_AIO_LISTIO_MAX 2 +#define _POSIX_AIO_MAX 1 +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_TIMER_MAX 32 + +#define _POSIX_CLOCKRES_MIN 20000000 +#endif + +#if __POSIX_VISIBLE >= 199506 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_THREADS_MAX 64 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_SS_REPL_MAX 4 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 +#define _POSIX_TRACE_NAME_MAX 8 +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 + +#define _POSIX_RE_DUP_MAX _POSIX2_RE_DUP_MAX +#endif + +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200809 +#define NL_ARGMAX 4096 /* max # of position args for printf */ +#define NL_MSGMAX 32767 +#define NL_SETMAX 255 +#define NL_TEXTMAX 2048 +#endif + +#if __XSI_VISIBLE +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 +#define PASS_MAX 128 /* _PASSWORD_LEN from */ + +#define NL_LANGMAX 31 /* max LANG name length */ +#define NL_NMAX 1 +#endif + +#define MB_LEN_MAX 6 /* 31-bit UTF-8 */ + +#include + +#if __POSIX_VISIBLE +#include +#endif + +#endif /* !_LIMITS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/link.h b/lib/libc/include/any-freebsd-any/link.h new file mode 100644 index 000000000000..60f6bd69add7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/link.h @@ -0,0 +1,35 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1993 Paul Kranenburg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include diff --git a/lib/libc/include/any-freebsd-any/locale.h b/lib/libc/include/any-freebsd-any/locale.h new file mode 100644 index 000000000000..de8e03ade5c8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/locale.h @@ -0,0 +1,89 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)locale.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _LOCALE_H_ +#define _LOCALE_H_ + +#include + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *int_curr_symbol; + char *currency_symbol; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +#define LC_ALL 0 +#define LC_COLLATE 1 +#define LC_CTYPE 2 +#define LC_MONETARY 3 +#define LC_NUMERIC 4 +#define LC_TIME 5 +#define LC_MESSAGES 6 + +#define _LC_LAST 7 /* marks end */ + +#include + +__BEGIN_DECLS +struct lconv *localeconv(void); +char *setlocale(int, const char *); + +#if __POSIX_VISIBLE >= 200809 +#include +#endif +__END_DECLS + + +#endif /* _LOCALE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/malloc.h b/lib/libc/include/any-freebsd-any/malloc.h new file mode 100644 index 000000000000..75673c72ed85 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/malloc.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + * $FreeBSD$ + */ +#include +#include diff --git a/lib/libc/include/any-freebsd-any/malloc_np.h b/lib/libc/include/any-freebsd-any/malloc_np.h new file mode 100644 index 000000000000..94c7026ef10f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/malloc_np.h @@ -0,0 +1,132 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 2006 Jason Evans . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MALLOC_NP_H_ +#define _MALLOC_NP_H_ + +#include + +#ifdef __cplusplus +#define __MyBool bool +#else +#define __MyBool _Bool +#endif + +__BEGIN_DECLS +typedef struct extent_hooks_s extent_hooks_t; +typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, + __MyBool *, __MyBool *, unsigned); +typedef __MyBool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, __MyBool, + unsigned); +typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, __MyBool, + unsigned); +typedef __MyBool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t, + size_t, unsigned); +typedef __MyBool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t, + size_t, unsigned); +typedef __MyBool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t, + unsigned); +typedef __MyBool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t, + __MyBool, unsigned); +typedef __MyBool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t, + __MyBool, unsigned); +struct extent_hooks_s { + extent_alloc_t *alloc; + extent_dalloc_t *dalloc; + extent_destroy_t *destroy; + extent_commit_t *commit; + extent_decommit_t *decommit; + extent_purge_t *purge_lazy; + extent_purge_t *purge_forced; + extent_split_t *split; + extent_merge_t *merge; +}; + +size_t malloc_usable_size(const void *ptr); + +void malloc_stats_print(void (*write_cb)(void *, const char *), + void *cbopaque, const char *opts); + +#define MALLCTL_ARENAS_ALL 4096 +#define MALLCTL_ARENAS_DESTROYED 4097 + +int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, + size_t newlen); +int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); +int mallctlbymib(const size_t *mib, size_t miblen, void *oldp, + size_t *oldlenp, void *newp, size_t newlen); + +#define MALLOCX_LG_ALIGN(la) ((int)(la)) +#define MALLOCX_ALIGN(a) ((int)(ffsl((int)(a))-1)) +#define MALLOCX_ZERO ((int)0x40) +#define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) +#define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) +#define MALLOCX_ARENA(a) ((((int)(a))+1) << 20) + +void *mallocx(size_t size, int flags); +void *rallocx(void *ptr, size_t size, int flags); +size_t xallocx(void *ptr, size_t size, size_t extra, int flags); +size_t sallocx(const void *ptr, int flags); +void dallocx(void *ptr, int flags); +void sdallocx(void *ptr, size_t size, int flags); +size_t nallocx(size_t size, int flags); + +void * __calloc(size_t number, size_t size) __malloc_like; +void * __malloc(size_t size) __malloc_like; +void * __realloc(void *ptr, size_t size); +void __free(void *ptr); +int __posix_memalign(void **ptr, size_t alignment, size_t size); +void *__aligned_alloc(size_t alignment, size_t size); +size_t __malloc_usable_size(const void *ptr); +void __malloc_stats_print(void (*write_cb)(void *, const char *), + void *cbopaque, const char *opts); +int __mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, + size_t newlen); +int __mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); +int __mallctlbymib(const size_t *mib, size_t miblen, void *oldp, + size_t *oldlenp, void *newp, size_t newlen); +void *__mallocx(size_t size, int flags); +void *__rallocx(void *ptr, size_t size, int flags); +size_t __xallocx(void *ptr, size_t size, size_t extra, int flags); +size_t __sallocx(const void *ptr, int flags); +void __dallocx(void *ptr, int flags); +void __sdallocx(void *ptr, size_t size, int flags); +size_t __nallocx(size_t size, int flags); + +void *memalign(size_t, size_t) __malloc_like __alloc_align(1) + __alloc_size(2); +__END_DECLS + +#undef __MyBool + +#endif /* _MALLOC_NP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/memory.h b/lib/libc/include/any-freebsd-any/memory.h new file mode 100644 index 000000000000..dd0c63ac73b2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/memory.h @@ -0,0 +1,36 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)memory.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#include diff --git a/lib/libc/include/any-freebsd-any/mk-osreldate.sh b/lib/libc/include/any-freebsd-any/mk-osreldate.sh new file mode 100755 index 000000000000..cf7d55a43697 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/mk-osreldate.sh @@ -0,0 +1,54 @@ +#!/bin/sh - +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2013 Garrett Cooper +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +set -e + +CURDIR=$(pwd) +ECHO=${ECHO:=echo} + +tmpfile=$(mktemp osreldate.XXXXXXXX) +trap "rm -f $tmpfile" EXIT + +${ECHO} creating osreldate.h from newvers.sh + +set +e +VARS_ONLY=1 +. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}" || exit 1 +set -e +cat > $tmpfile < cannot be used in the kernel, use " +#else +#undef __FreeBSD_version +#define __FreeBSD_version $RELDATE +#endif +EOF +chmod 644 $tmpfile +mv -f $tmpfile osreldate.h diff --git a/lib/libc/include/any-freebsd-any/monetary.h b/lib/libc/include/any-freebsd-any/monetary.h new file mode 100644 index 000000000000..d7b381b82042 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/monetary.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Alexey Zelkin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MONETARY_H_ +#define _MONETARY_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +__BEGIN_DECLS +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif +ssize_t strfmon(char * __restrict, size_t, const char * __restrict, ...); +__END_DECLS + +#endif /* !_MONETARY_H_ */ diff --git a/lib/libc/include/any-freebsd-any/mpool.h b/lib/libc/include/any-freebsd-any/mpool.h new file mode 100644 index 000000000000..2c6866020e7c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/mpool.h @@ -0,0 +1,111 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mpool.h 8.4 (Berkeley) 11/2/95 + * $FreeBSD$ + */ + +#ifndef _MPOOL_H_ +#define _MPOOL_H_ + +#include + +/* + * The memory pool scheme is a simple one. Each in-memory page is referenced + * by a bucket which is threaded in up to two of three ways. All active pages + * are threaded on a hash chain (hashed by page number) and an lru chain. + * Inactive pages are threaded on a free chain. Each reference to a memory + * pool is handed an opaque MPOOL cookie which stores all of this information. + */ +#define HASHSIZE 128 +#define HASHKEY(pgno) ((pgno - 1 + HASHSIZE) % HASHSIZE) + +/* The BKT structures are the elements of the queues. */ +typedef struct _bkt { + TAILQ_ENTRY(_bkt) hq; /* hash queue */ + TAILQ_ENTRY(_bkt) q; /* lru queue */ + void *page; /* page */ + pgno_t pgno; /* page number */ + +#define MPOOL_DIRTY 0x01 /* page needs to be written */ +#define MPOOL_PINNED 0x02 /* page is pinned into memory */ +#define MPOOL_INUSE 0x04 /* page address is valid */ + u_int8_t flags; /* flags */ +} BKT; + +typedef struct MPOOL { + TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ + /* hash queue array */ + TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; + pgno_t curcache; /* current number of cached pages */ + pgno_t maxcache; /* max number of cached pages */ + pgno_t npages; /* number of pages in the file */ + unsigned long pagesize; /* file page size */ + int fd; /* file descriptor */ + /* page in conversion routine */ + void (*pgin)(void *, pgno_t, void *); + /* page out conversion routine */ + void (*pgout)(void *, pgno_t, void *); + void *pgcookie; /* cookie for page in/out routines */ +#ifdef STATISTICS + unsigned long cachehit; + unsigned long cachemiss; + unsigned long pagealloc; + unsigned long pageflush; + unsigned long pageget; + unsigned long pagenew; + unsigned long pageput; + unsigned long pageread; + unsigned long pagewrite; +#endif +} MPOOL; + +#define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ +#define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a + specific page number. */ +#define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next + page number. */ + +__BEGIN_DECLS +MPOOL *mpool_open(void *, int, pgno_t, pgno_t); +void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), + void (*)(void *, pgno_t, void *), void *); +void *mpool_new(MPOOL *, pgno_t *, unsigned int); +void *mpool_get(MPOOL *, pgno_t, unsigned int); +int mpool_delete(MPOOL *, void *); +int mpool_put(MPOOL *, void *, unsigned int); +int mpool_sync(MPOOL *); +int mpool_close(MPOOL *); +#ifdef STATISTICS +void mpool_stat(MPOOL *); +#endif +__END_DECLS + +#endif diff --git a/lib/libc/include/any-freebsd-any/mqueue.h b/lib/libc/include/any-freebsd-any/mqueue.h new file mode 100644 index 000000000000..987cf0bd4e23 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/mqueue.h @@ -0,0 +1,60 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 David Xu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MQUEUE_H_ +#define _MQUEUE_H_ + +#include +#include +#include +#include + +struct timespec; + +__BEGIN_DECLS +int mq_close(mqd_t); +int mq_getattr(mqd_t, struct mq_attr *); +int mq_notify(mqd_t, const struct sigevent *); +mqd_t mq_open(const char *, int, ...); +ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); +int mq_send(mqd_t, const char *, size_t, unsigned); +int mq_setattr(mqd_t, const struct mq_attr *__restrict, + struct mq_attr *__restrict); +ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, + unsigned *__restrict, const struct timespec *__restrict); +int mq_timedsend(mqd_t, const char *, size_t, unsigned, + const struct timespec *); +int mq_unlink(const char *); +#if __BSD_VISIBLE +int mq_getfd_np(mqd_t mqd); +#endif /* __BSD_VISIBLE */ + +__END_DECLS +#endif diff --git a/lib/libc/include/any-freebsd-any/ndbm.h b/lib/libc/include/any-freebsd-any/ndbm.h new file mode 100644 index 000000000000..f9b0d2b4b0ff --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ndbm.h @@ -0,0 +1,82 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _NDBM_H_ +#define _NDBM_H_ + +#include + +/* Map dbm interface onto db(3). */ +#define DBM_RDONLY O_RDONLY + +/* Flags to dbm_store(). */ +#define DBM_INSERT 0 +#define DBM_REPLACE 1 + +/* + * The db(3) support for ndbm always appends this suffix to the + * file name to avoid overwriting the user's original database. + */ +#define DBM_SUFFIX ".db" + +typedef struct { + void *dptr; + int dsize; /* XXX Should be size_t according to 1003.1-2008. */ +} datum; + +typedef DB DBM; +#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE + +__BEGIN_DECLS +int dbm_clearerr(DBM *); +void dbm_close(DBM *); +int dbm_delete(DBM *, datum); +int dbm_error(DBM *); +datum dbm_fetch(DBM *, datum); +datum dbm_firstkey(DBM *); +#if __BSD_VISIBLE +long dbm_forder(DBM *, datum); +#endif +datum dbm_nextkey(DBM *); +DBM *dbm_open(const char *, int, mode_t); +int dbm_store(DBM *, datum, datum, int); +#if __BSD_VISIBLE +int dbm_dirfno(DBM *); +#endif +__END_DECLS + +#endif /* !_NDBM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/netconfig.h b/lib/libc/include/any-freebsd-any/netconfig.h new file mode 100644 index 000000000000..b459e2ee0bf2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/netconfig.h @@ -0,0 +1,126 @@ +/* $NetBSD: netconfig.h,v 1.6 2008/04/28 20:22:54 martin Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NETCONFIG_H_ +#define _NETCONFIG_H_ + +#include + +#define NETCONFIG "/etc/netconfig" +#define NETPATH "NETPATH" + +struct netconfig { + char *nc_netid; /* Network ID */ + unsigned long nc_semantics; /* Semantics (see below) */ + unsigned long nc_flag; /* Flags (see below) */ + char *nc_protofmly; /* Protocol family */ + char *nc_proto; /* Protocol name */ + char *nc_device; /* Network device pathname */ + unsigned long nc_nlookups; /* Number of directory lookup libs */ + char **nc_lookups; /* Names of the libraries */ + unsigned long nc_unused[9]; /* reserved */ +}; + +typedef struct { + struct netconfig **nc_head; + struct netconfig **nc_curr; +} NCONF_HANDLE; + +/* + * nc_semantics values + */ +#define NC_TPI_CLTS 1 /* Connectionless transport */ +#define NC_TPI_COTS 2 /* Connection oriented transport */ +#define NC_TPI_COTS_ORD 3 /* Connection oriented, ordered transport */ +#define NC_TPI_RAW 4 /* Raw connection */ + +/* + * nc_flag values + */ +#define NC_NOFLAG 0x00 +#define NC_VISIBLE 0x01 +#define NC_BROADCAST 0x02 + +/* + * nc_protofmly values + */ +#define NC_NOPROTOFMLY "-" +#define NC_LOOPBACK "loopback" +#define NC_INET "inet" +#define NC_INET6 "inet6" +#define NC_IMPLINK "implink" +#define NC_PUP "pup" +#define NC_CHAOS "chaos" +#define NC_NS "ns" +#define NC_NBS "nbs" +#define NC_ECMA "ecma" +#define NC_DATAKIT "datakit" +#define NC_CCITT "ccitt" +#define NC_SNA "sna" +#define NC_DECNET "decnet" +#define NC_DLI "dli" +#define NC_LAT "lat" +#define NC_HYLINK "hylink" +#define NC_APPLETALK "appletalk" +#define NC_NIT "nit" +#define NC_IEEE802 "ieee802" +#define NC_OSI "osi" +#define NC_X25 "x25" +#define NC_OSINET "osinet" +#define NC_GOSIP "gosip" + +/* + * nc_proto values + */ +#define NC_NOPROTO "-" +#define NC_TCP "tcp" +#define NC_UDP "udp" +#define NC_ICMP "icmp" + +__BEGIN_DECLS +void *setnetconfig(void); +struct netconfig *getnetconfig(void *); +struct netconfig *getnetconfigent(const char *); +void freenetconfigent(struct netconfig *); +int endnetconfig(void *); + +void *setnetpath(void); +struct netconfig *getnetpath(void *); +int endnetpath(void *); + +void nc_perror(const char *); +char *nc_sperror(void); +__END_DECLS + +#endif /* _NETCONFIG_H_ */ diff --git a/lib/libc/include/any-freebsd-any/netdb.h b/lib/libc/include/any-freebsd-any/netdb.h new file mode 100644 index 000000000000..731e7f7376b5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/netdb.h @@ -0,0 +1,306 @@ +/*- + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) + * + * Copyright (c) 1980, 1983, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- + */ + +/* + * @(#)netdb.h 8.1 (Berkeley) 6/2/93 + * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ + * $FreeBSD$ + */ + +#ifndef _NETDB_H_ +#define _NETDB_H_ + +#include +#include + +#ifndef _IN_ADDR_T_DECLARED +typedef __uint32_t in_addr_t; +#define _IN_ADDR_T_DECLARED +#endif + +#ifndef _IN_PORT_T_DECLARED +typedef __uint16_t in_port_t; +#define _IN_PORT_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _PATH_HEQUIV +# define _PATH_HEQUIV "/etc/hosts.equiv" +#endif +#define _PATH_HOSTS "/etc/hosts" +#define _PATH_NETWORKS "/etc/networks" +#define _PATH_PROTOCOLS "/etc/protocols" +#define _PATH_SERVICES "/etc/services" +#define _PATH_SERVICES_DB "/var/db/services.db" + +#define h_errno (*__h_errno()) + +/* + * Structures returned by network data base library. All addresses are + * supplied in host order, and returned in network order (suitable for + * use in system calls). + */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +}; + +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net address type */ + uint32_t n_net; /* network # */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; + +struct protoent { + char *p_name; /* official protocol name */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol # */ +}; + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* AF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + socklen_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +#define IPPORT_RESERVED 1024 + +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in h_errno). + */ + +#define NETDB_INTERNAL -1 /* see errno */ +#define NETDB_SUCCESS 0 /* no problem */ +#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ +#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ +#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ +#define NO_DATA 4 /* Valid name, no data record of requested type */ +#define NO_ADDRESS NO_DATA /* no address, look for MX record */ + +/* + * Error return codes from gai_strerror(3), see RFC 3493. + */ +#if 0 +/* Obsoleted on RFC 2553bis-02 */ +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#endif +#define EAI_AGAIN 2 /* name could not be resolved at this time */ +#define EAI_BADFLAGS 3 /* flags parameter had an invalid value */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* address family not recognized */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#if 0 +/* Obsoleted on RFC 2553bis-02 */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#endif +#define EAI_NONAME 8 /* name does not resolve */ +#define EAI_SERVICE 9 /* service not recognized for socket type */ +#define EAI_SOCKTYPE 10 /* intended socket type was not recognized */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 /* invalid value for hints */ +#define EAI_PROTOCOL 13 /* resolved protocol is unknown */ +#define EAI_OVERFLOW 14 /* argument buffer overflow */ +#define EAI_MAX 15 + +/* + * Flag values for getaddrinfo() + */ +#define AI_PASSIVE 0x00000001 /* get address to use bind() */ +#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ +#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ +#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ +/* valid flags for addrinfo (not a standard def, apps should not use it) */ +#define AI_MASK \ + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ + AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED) + +#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ +#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ +#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ +/* special recommended flags for getipnodebyname */ +#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) + +/* + * Constants for getnameinfo() + */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +/* + * Flag values for getnameinfo() + */ +#define NI_NOFQDN 0x00000001 +#define NI_NUMERICHOST 0x00000002 +#define NI_NAMEREQD 0x00000004 +#define NI_NUMERICSERV 0x00000008 +#define NI_DGRAM 0x00000010 +#define NI_NUMERICSCOPE 0x00000020 + +/* + * Scope delimit character + */ +#define SCOPE_DELIMITER '%' + +__BEGIN_DECLS +void endhostent(void); +void endnetent(void); +void endprotoent(void); +void endservent(void); +#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112) +struct hostent *gethostbyaddr(const void *, socklen_t, int); +struct hostent *gethostbyname(const char *); +#endif +struct hostent *gethostent(void); +struct netent *getnetbyaddr(uint32_t, int); +struct netent *getnetbyname(const char *); +struct netent *getnetent(void); +struct protoent *getprotobyname(const char *); +struct protoent *getprotobynumber(int); +struct protoent *getprotoent(void); +struct servent *getservbyname(const char *, const char *); +struct servent *getservbyport(int, const char *); +struct servent *getservent(void); +void sethostent(int); +/* void sethostfile(const char *); */ +void setnetent(int); +void setprotoent(int); +int getaddrinfo(const char *, const char *, + const struct addrinfo *, struct addrinfo **); +int getnameinfo(const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int); +void freeaddrinfo(struct addrinfo *); +const char *gai_strerror(int); +void setservent(int); + +#if __BSD_VISIBLE +void endnetgrent(void); +void freehostent(struct hostent *); +int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, + char *, size_t, struct hostent **, int *); +int gethostbyname_r(const char *, struct hostent *, char *, size_t, + struct hostent **, int *); +struct hostent *gethostbyname2(const char *, int); +int gethostbyname2_r(const char *, int, struct hostent *, char *, + size_t, struct hostent **, int *); +int gethostent_r(struct hostent *, char *, size_t, + struct hostent **, int *); +struct hostent *getipnodebyaddr(const void *, size_t, int, int *); +struct hostent *getipnodebyname(const char *, int, int, int *); +int getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, + struct netent**, int *); +int getnetbyname_r(const char *, struct netent *, char *, size_t, + struct netent **, int *); +int getnetent_r(struct netent *, char *, size_t, struct netent **, + int *); +int getnetgrent(char **, char **, char **); +int getnetgrent_r(char **, char **, char **, char *, size_t); +int getprotobyname_r(const char *, struct protoent *, char *, + size_t, struct protoent **); +int getprotobynumber_r(int, struct protoent *, char *, size_t, + struct protoent **); +int getprotoent_r(struct protoent *, char *, size_t, + struct protoent **); +int getservbyname_r(const char *, const char *, struct servent *, + char *, size_t, struct servent **); +int getservbyport_r(int, const char *, struct servent *, char *, + size_t, struct servent **); +int getservent_r(struct servent *, char *, size_t, + struct servent **); +void herror(const char *); +const char *hstrerror(int); +int innetgr(const char *, const char *, const char *, const char *); +void setnetgrent(const char *); +#endif + + +/* + * PRIVATE functions specific to the FreeBSD implementation + */ + +/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ +int * __h_errno(void); +__END_DECLS + +#endif /* !_NETDB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/nl_types.h b/lib/libc/include/any-freebsd-any/nl_types.h new file mode 100644 index 000000000000..bf88144aefd4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/nl_types.h @@ -0,0 +1,99 @@ +/* $NetBSD: nl_types.h,v 1.9 2000/10/03 19:53:32 sommerfeld Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NL_TYPES_H_ +#define _NL_TYPES_H_ + +#include +#include + +#ifdef _NLS_PRIVATE +/* + * MESSAGE CATALOG FILE FORMAT. + * + * The NetBSD/FreeBSD message catalog format is similar to the format used by + * Svr4 systems. The differences are: + * * fixed byte order (big endian) + * * fixed data field sizes + * + * A message catalog contains four data types: a catalog header, one + * or more set headers, one or more message headers, and one or more + * text strings. + */ + +#define _NLS_MAGIC 0xff88ff89 + +struct _nls_cat_hdr { + int32_t __magic; + int32_t __nsets; + int32_t __mem; + int32_t __msg_hdr_offset; + int32_t __msg_txt_offset; +} ; + +struct _nls_set_hdr { + int32_t __setno; /* set number: 0 < x <= NL_SETMAX */ + int32_t __nmsgs; /* number of messages in the set */ + int32_t __index; /* index of first msg_hdr in msg_hdr table */ +} ; + +struct _nls_msg_hdr { + int32_t __msgno; /* msg number: 0 < x <= NL_MSGMAX */ + int32_t __msglen; + int32_t __offset; +} ; + +#endif /* _NLS_PRIVATE */ + +#define NL_SETD 0 +#define NL_CAT_LOCALE 1 + +typedef struct __nl_cat_d { + void *__data; + int __size; +} *nl_catd; + +#ifndef _NL_ITEM_DECLARED +typedef __nl_item nl_item; +#define _NL_ITEM_DECLARED +#endif + +__BEGIN_DECLS +nl_catd catopen(const char *, int); +char *catgets(nl_catd, int, int, const char *) __format_arg(4); +int catclose(nl_catd); +__END_DECLS + +#endif /* _NL_TYPES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/nlist.h b/lib/libc/include/any-freebsd-any/nlist.h new file mode 100644 index 000000000000..5ea6f5ea555e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/nlist.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD$ + */ + +#ifndef _NLIST_H_ +#define _NLIST_H_ + +#include +#include + +__BEGIN_DECLS +int nlist(const char *, struct nlist *); +__END_DECLS + +#endif /* !_NLIST_H_ */ diff --git a/lib/libc/include/any-freebsd-any/nss.h b/lib/libc/include/any-freebsd-any/nss.h new file mode 100644 index 000000000000..0cc155a0393c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/nss.h @@ -0,0 +1,59 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Compatibility header for the GNU C Library-style nsswitch interface. + */ +#ifndef _NSS_H_ +#define _NSS_H_ + +#include + +enum nss_status { + NSS_STATUS_TRYAGAIN = -2, + NSS_STATUS_UNAVAIL, + NSS_STATUS_NOTFOUND, + NSS_STATUS_SUCCESS, + NSS_STATUS_RETURN +}; + +#define __nss_compat_result(rv, err) \ +((rv == NSS_STATUS_TRYAGAIN && err == ERANGE) ? NS_RETURN : \ + (rv == NSS_STATUS_TRYAGAIN) ? NS_TRYAGAIN : \ + (rv == NSS_STATUS_UNAVAIL) ? NS_UNAVAIL : \ + (rv == NSS_STATUS_NOTFOUND) ? NS_NOTFOUND : \ + (rv == NSS_STATUS_SUCCESS) ? NS_SUCCESS : \ + (rv == NSS_STATUS_RETURN) ? NS_RETURN : 0) + +#endif diff --git a/lib/libc/include/any-freebsd-any/nsswitch.h b/lib/libc/include/any-freebsd-any/nsswitch.h new file mode 100644 index 000000000000..f7131292dd78 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/nsswitch.h @@ -0,0 +1,246 @@ +/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NSSWITCH_H +#define _NSSWITCH_H 1 + +#include +#include + +#define NSS_MODULE_INTERFACE_VERSION 1 + +#ifndef _PATH_NS_CONF +#define _PATH_NS_CONF "/etc/nsswitch.conf" +#endif + +/* NSS source actions */ +#define NS_ACTION_CONTINUE 0 /* try the next source */ +#define NS_ACTION_RETURN 1 /* look no further */ + +#define NS_SUCCESS (1<<0) /* entry was found */ +#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ +#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ +#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ +#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ +#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ +#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ + +/* + * currently implemented sources + */ +#define NSSRC_FILES "files" /* local files */ +#define NSSRC_DB "db" /* database */ +#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ +#define NSSRC_NIS "nis" /* YP/NIS */ +#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ +#define NSSRC_CACHE "cache" /* nscd daemon */ +#define NSSRC_FALLBACK "__fallback" /* internal fallback source */ + +/* + * currently implemented databases + */ +#define NSDB_HOSTS "hosts" +#define NSDB_GROUP "group" +#define NSDB_GROUP_COMPAT "group_compat" +#define NSDB_NETGROUP "netgroup" +#define NSDB_NETWORKS "networks" +#define NSDB_PASSWD "passwd" +#define NSDB_PASSWD_COMPAT "passwd_compat" +#define NSDB_SHELLS "shells" +#define NSDB_SERVICES "services" +#define NSDB_SERVICES_COMPAT "services_compat" +#define NSDB_SSH_HOSTKEYS "ssh_hostkeys" +#define NSDB_PROTOCOLS "protocols" +#define NSDB_RPC "rpc" + +/* + * suggested databases to implement + */ +#define NSDB_ALIASES "aliases" +#define NSDB_AUTH "auth" +#define NSDB_AUTOMOUNT "automount" +#define NSDB_BOOTPARAMS "bootparams" +#define NSDB_ETHERS "ethers" +#define NSDB_EXPORTS "exports" +#define NSDB_NETMASKS "netmasks" +#define NSDB_PHONES "phones" +#define NSDB_PRINTCAP "printcap" +#define NSDB_REMOTE "remote" +#define NSDB_SENDMAILVARS "sendmailvars" +#define NSDB_TERMCAP "termcap" +#define NSDB_TTYS "ttys" + +/* + * ns_dtab `method' function signature. + */ +typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); + +/* + * Macro for generating method prototypes. + */ +#define NSS_METHOD_PROTOTYPE(method) \ + int method(void *, void *, va_list) + +/* + * ns_dtab - `nsswitch dispatch table' + * Contains an entry for each source and the appropriate function to + * call. ns_dtabs are used in the nsdispatch() API in order to allow + * the application to override built-in actions. + */ +typedef struct _ns_dtab { + const char *src; /* Source this entry implements */ + nss_method method; /* Method to be called */ + void *mdata; /* Data passed to method */ +} ns_dtab; + +/* + * macros to help build an ns_dtab[] + */ +#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, +#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, +#define NS_FALLBACK_CB(F) { NSSRC_FALLBACK, F, NULL }, + +#ifdef HESIOD +# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, +#else +# define NS_DNS_CB(F,C) +#endif + +#ifdef YP +# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, +#else +# define NS_NIS_CB(F,C) +#endif + +/* + * ns_src - `nsswitch source' + * used by the nsparser routines to store a mapping between a source + * and its dispatch control flags for a given database. + */ +typedef struct _ns_src { + const char *name; + u_int32_t flags; +} ns_src; + + +/* + * default sourcelist (if nsswitch.conf is missing, corrupt, + * or the requested database doesn't have an entry. + */ +extern const ns_src __nsdefaultsrc[]; + +/* + * ns_mtab - NSS method table + * An NSS module provides a mapping from (database name, method name) + * tuples to the nss_method and associated data. + */ +typedef struct _ns_mtab { + const char *database; + const char *name; + nss_method method; + void *mdata; +} ns_mtab; + +/* + * NSS module de-registration, called at module unload. + */ +typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); + +/* + * NSS module registration, called at module load. + */ +typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, + nss_module_unregister_fn *); + +/* + * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. + * Developers are encouraged to use nss_lookup_type where approriate. + */ +enum nss_lookup_type { + nss_lt_name = 1, + nss_lt_id = 2, + nss_lt_all = 3 +}; + +#ifdef _NS_PRIVATE +/* + * private data structures for back-end nsswitch implementation + */ + +/* + * ns_dbt - `nsswitch database thang' + * for each database in /etc/nsswitch.conf there is a ns_dbt, with its + * name and a list of ns_src's containing the source information. + */ +typedef struct _ns_dbt { + const char *name; /* name of database */ + ns_src *srclist; /* list of sources */ + int srclistsize; /* size of srclist */ +} ns_dbt; + +/* + * ns_mod - NSS module + */ +typedef struct _ns_mod { + char *name; /* module name */ + void *handle; /* handle from dlopen */ + ns_mtab *mtab; /* method table */ + unsigned int mtabsize; /* count of entries in method table */ + nss_module_unregister_fn unregister; /* called to unload module */ +} ns_mod; + +#endif /* _NS_PRIVATE */ + + +#include + +__BEGIN_DECLS +extern int nsdispatch(void *, const ns_dtab [], const char *, + const char *, const ns_src [], ...); + +#ifdef _NS_PRIVATE +extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); +extern void _nsdbtput(const ns_dbt *); +extern void _nsyyerror(const char *); +extern int _nsyylex(void); +extern int _nsyyparse(void); +extern int _nsyylineno; +#ifdef _NSS_DEBUG +extern void _nsdbtdump(const ns_dbt *); +#endif +#endif /* _NS_PRIVATE */ + +__END_DECLS + +#endif /* !_NSSWITCH_H */ diff --git a/lib/libc/include/any-freebsd-any/osreldate.h b/lib/libc/include/any-freebsd-any/osreldate.h new file mode 100644 index 000000000000..b1537b94ddea --- /dev/null +++ b/lib/libc/include/any-freebsd-any/osreldate.h @@ -0,0 +1,34 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 1992-2020 The FreeBSD Project. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifdef _KERNEL +#error " cannot be used in the kernel, use " +#else +#undef __FreeBSD_version +#define __FreeBSD_version 1202000 +#endif diff --git a/lib/libc/include/any-freebsd-any/paths.h b/lib/libc/include/any-freebsd-any/paths.h new file mode 100644 index 000000000000..f8df80518c5c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/paths.h @@ -0,0 +1,148 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)paths.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +#include + +/* Default search path. */ +#define _PATH_DEFPATH "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin" +/* All standard utilities path. */ +#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" +/* Locate system binaries. */ +#define _PATH_SYSPATH "/sbin:/usr/sbin" + +#define _PATH_BSHELL "/bin/sh" +#define _PATH_CAPABILITY "/etc/capability" +#define _PATH_CAPABILITY_DB "/etc/capability.db" +#define _PATH_CONSOLE "/dev/console" +#define _PATH_CP "/bin/cp" +#define _PATH_CSHELL "/bin/csh" +#define _PATH_CSMAPPER "/usr/share/i18n/csmapper" +#define _PATH_DEFTAPE "/dev/sa0" +#define _PATH_DEVGPIOC "/dev/gpioc" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_DEVZERO "/dev/zero" +#define _PATH_DRUM "/dev/drum" +#define _PATH_ESDB "/usr/share/i18n/esdb" +#define _PATH_ETC "/etc" +#define _PATH_FIRMWARE "/usr/share/firmware" +#define _PATH_FTPUSERS "/etc/ftpusers" +#define _PATH_FWMEM "/dev/fwmem" +#define _PATH_GBDE "/sbin/gbde" +#define _PATH_GELI "/sbin/geli" +#define _PATH_HALT "/sbin/halt" +#ifdef COMPAT_32BIT +#define _PATH_I18NMODULE "/usr/lib32/i18n" +#else +#define _PATH_I18NMODULE "/usr/lib/i18n" +#endif +#define _PATH_IFCONFIG "/sbin/ifconfig" +#define _PATH_KMEM "/dev/kmem" +#define _PATH_LIBMAP_CONF "/etc/libmap.conf" +#define _PATH_LOCALE "/usr/share/locale" +#define _PATH_LOGIN "/usr/bin/login" +#define _PATH_MAILDIR "/var/mail" +#define _PATH_MAN "/usr/share/man" +#define _PATH_MDCONFIG "/sbin/mdconfig" +#define _PATH_MEM "/dev/mem" +#define _PATH_MKSNAP_FFS "/sbin/mksnap_ffs" +#define _PATH_MOUNT "/sbin/mount" +#define _PATH_NEWFS "/sbin/newfs" +#define _PATH_NOLOGIN "/var/run/nologin" +#define _PATH_RCP "/bin/rcp" +#define _PATH_REBOOT "/sbin/reboot" +#define _PATH_RLOGIN "/usr/bin/rlogin" +#define _PATH_RM "/bin/rm" +#define _PATH_RSH "/usr/bin/rsh" +#define _PATH_SENDMAIL "/usr/sbin/sendmail" +#define _PATH_SHELLS "/etc/shells" +#define _PATH_TTY "/dev/tty" +#define _PATH_UNIX "don't use _PATH_UNIX" +#define _PATH_UFSSUSPEND "/dev/ufssuspend" +#define _PATH_VI "/usr/bin/vi" +#define _PATH_WALL "/usr/bin/wall" + +/* Provide trailing slash, since mostly used for building pathnames. */ +#define _PATH_DEV "/dev/" +#define _PATH_TMP "/tmp/" +#define _PATH_VARDB "/var/db/" +#define _PATH_VARRUN "/var/run/" +#define _PATH_VARTMP "/var/tmp/" +#define _PATH_DEVVMM "/dev/vmm/" +#define _PATH_YP "/var/yp/" +#define _PATH_UUCPLOCK "/var/spool/lock/" + +/* How to get the correct name of the kernel. */ +__BEGIN_DECLS +const char *getbootfile(void); +__END_DECLS + +#ifdef RESCUE +#undef _PATH_DEFPATH +#define _PATH_DEFPATH "/rescue:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin" +#undef _PATH_STDPATH +#define _PATH_STDPATH "/rescue:/usr/bin:/bin:/usr/sbin:/sbin" +#undef _PATH_SYSPATH +#define _PATH_SYSPATH "/rescue:/sbin:/usr/sbin" +#undef _PATH_BSHELL +#define _PATH_BSHELL "/rescue/sh" +#undef _PATH_CP +#define _PATH_CP "/rescue/cp" +#undef _PATH_CSHELL +#define _PATH_CSHELL "/rescue/csh" +#undef _PATH_HALT +#define _PATH_HALT "/rescue/halt" +#undef _PATH_IFCONFIG +#define _PATH_IFCONFIG "/rescue/ifconfig" +#undef _PATH_MDCONFIG +#define _PATH_MDCONFIG "/rescue/mdconfig" +#undef _PATH_MOUNT +#define _PATH_MOUNT "/rescue/mount" +#undef _PATH_NEWFS +#define _PATH_NEWFS "/rescue/newfs" +#undef _PATH_RCP +#define _PATH_RCP "/rescue/rcp" +#undef _PATH_REBOOT +#define _PATH_REBOOT "/rescue/reboot" +#undef _PATH_RM +#define _PATH_RM "/rescue/rm" +#undef _PATH_VI +#define _PATH_VI "/rescue/vi" +#undef _PATH_WALL +#define _PATH_WALL "/rescue/wall" +#endif /* RESCUE */ + +#endif /* !_PATHS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/printf.h b/lib/libc/include/any-freebsd-any/printf.h new file mode 100644 index 000000000000..2a643f94c657 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/printf.h @@ -0,0 +1,166 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _PRINTF_H_ +#define _PRINTF_H_ + +#include +#include + +/* + * The API defined by glibc allows a renderer to take multiple arguments + * This is obviously usable for things like (ptr+len) pairs etc. + * But the do not actually provide support for it at the end of the day, + * they offer only one argument to the arginfo function, but do accept + * >1 returns, although the do not check the types of those arguments + * argument + * Be compatible for now. + */ +#define __PRINTFMAXARG 2 + +struct printf_info { + /* GLIBC compatible */ + int prec; + int width; + wchar_t spec; + unsigned is_long_double; + unsigned is_char; + unsigned is_short; + unsigned is_long; + unsigned alt; + unsigned space; + unsigned left; + unsigned showsign; + unsigned group; + unsigned extra; + unsigned wide; + wchar_t pad; + + /* FreeBSD extensions */ + + unsigned is_quad; + unsigned is_intmax; + unsigned is_ptrdiff; + unsigned is_size; + + /* private */ + int sofar; + unsigned get_width; + unsigned get_prec; + const char *begin; + const char *end; + void *arg[__PRINTFMAXARG]; +}; + +enum { + PA_INT = (1 << 0), /* int */ + PA_CHAR = (1 << 1), /* int, cast to char */ + PA_WCHAR = (1 << 2), /* wide char */ + PA_STRING = (1 << 3), /* const char * (with '\0') */ + PA_WSTRING = (1 << 4), /* const wchar_t * */ + PA_POINTER = (1 << 5), /* void * */ + PA_FLOAT = (1 << 6), /* float */ + PA_DOUBLE = (1 << 7) /* double */ +}; + +#define PA_FLAG_MASK 0xff0000 +#define PA_FLAG_LONG_LONG (1 << 16) +#define PA_FLAG_LONG (1 << 17) +#define PA_FLAG_SHORT (1 << 18) +#define PA_FLAG_PTR (1 << 19) +#define PA_FLAG_QUAD (1 << 20) +#define PA_FLAG_INTMAX (1 << 21) +#define PA_FLAG_SIZE (1 << 22) +#define PA_FLAG_PTRDIFF (1 << 23) +#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG + +typedef int printf_arginfo_function(const struct printf_info *, size_t, int *); +typedef int printf_function(FILE *, const struct printf_info *, const void *const *); + +/* FreeBSD extension */ +struct __printf_io; +typedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *); + +/* vprintf.c */ +extern const char __lowercase_hex[17]; +extern const char __uppercase_hex[17]; + +void __printf_flush(struct __printf_io *io); +int __printf_puts(struct __printf_io *io, const void *ptr, int len); +int __printf_pad(struct __printf_io *io, int n, int zero); +int __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len); + +int __xvprintf(FILE *fp, const char *fmt0, va_list ap); +extern int __use_xprintf; + +/* GLIBC compat */ +int register_printf_function(int spec, printf_function *render, printf_arginfo_function *arginfo); + +/* FreeBSD */ +int register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo); +int register_printf_render_std(const char *specs); + +/* vprintf_errno.c */ +printf_arginfo_function __printf_arginfo_errno; +printf_render __printf_render_errno; + +/* vprintf_float.c */ +printf_arginfo_function __printf_arginfo_float; +printf_render __printf_render_float; + +/* vprintf_hexdump.c */ +printf_arginfo_function __printf_arginfo_hexdump; +printf_render __printf_render_hexdump; + +/* vprintf_int.c */ +printf_arginfo_function __printf_arginfo_ptr; +printf_arginfo_function __printf_arginfo_int; +printf_render __printf_render_ptr; +printf_render __printf_render_int; + +/* vprintf_quoute.c */ +printf_arginfo_function __printf_arginfo_quote; +printf_render __printf_render_quote; + +/* vprintf_str.c */ +printf_arginfo_function __printf_arginfo_chr; +printf_render __printf_render_chr; +printf_arginfo_function __printf_arginfo_str; +printf_render __printf_render_str; + +/* vprintf_time.c */ +printf_arginfo_function __printf_arginfo_time; +printf_render __printf_render_time; + +/* vprintf_vis.c */ +printf_arginfo_function __printf_arginfo_vis; +printf_render __printf_render_vis; + +#endif /* !_PRINTF_H */ diff --git a/lib/libc/include/any-freebsd-any/proc_service.h b/lib/libc/include/any-freebsd-any/proc_service.h new file mode 100644 index 000000000000..3b12ff949460 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/proc_service.h @@ -0,0 +1,72 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 David Xu + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _PROC_SERVICE_H_ +#define _PROC_SERVICE_H_ + +#include +#include + +typedef enum { + PS_OK = 0, /* No errors. */ + PS_ERR, /* Generic error. */ + PS_BADADDR, /* Bad address. */ + PS_BADLID, /* Bad LWP Id. */ + PS_BADPID, /* Bad process Id. */ + PS_NOFREGS, /* FPU register set not available. */ + PS_NOSYM /* Symbol not found. */ +} ps_err_e; + +struct ps_prochandle; /* Opaque type. Defined by the implementor. */ + +__BEGIN_DECLS +ps_err_e ps_lcontinue(struct ps_prochandle *, lwpid_t); +ps_err_e ps_lgetfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *); +ps_err_e ps_lgetregs(struct ps_prochandle *, lwpid_t, prgregset_t); +ps_err_e ps_lsetfpregs(struct ps_prochandle *, lwpid_t, const prfpregset_t *); +ps_err_e ps_lsetregs(struct ps_prochandle *, lwpid_t, const prgregset_t); +#ifdef __i386__ +ps_err_e ps_lgetxmmregs (struct ps_prochandle *, lwpid_t, char *); +ps_err_e ps_lsetxmmregs (struct ps_prochandle *, lwpid_t, const char *); +#endif +ps_err_e ps_lstop(struct ps_prochandle *, lwpid_t); +ps_err_e ps_linfo(struct ps_prochandle *, lwpid_t, void *); +ps_err_e ps_pcontinue(struct ps_prochandle *); +ps_err_e ps_pdmodel(struct ps_prochandle *, int *); +ps_err_e ps_pglobal_lookup(struct ps_prochandle *, const char *, const char *, + psaddr_t *); +void ps_plog(const char *, ...); +ps_err_e ps_pread(struct ps_prochandle *, psaddr_t, void *, size_t); +ps_err_e ps_pstop(struct ps_prochandle *); +ps_err_e ps_pwrite(struct ps_prochandle *, psaddr_t, const void *, size_t); +__END_DECLS + +#endif /* _PROC_SERVICE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/protocols/dumprestore.h b/lib/libc/include/any-freebsd-any/protocols/dumprestore.h new file mode 100644 index 000000000000..6d22763e96de --- /dev/null +++ b/lib/libc/include/any-freebsd-any/protocols/dumprestore.h @@ -0,0 +1,144 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dumprestore.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD$ + */ + +#ifndef _PROTOCOLS_DUMPRESTORE_H_ +#define _PROTOCOLS_DUMPRESTORE_H_ + +/* + * TP_BSIZE is the size of file blocks on the dump tapes. + * Note that TP_BSIZE must be a multiple of DEV_BSIZE. + * + * NTREC is the number of TP_BSIZE blocks that are written + * in each tape record. HIGHDENSITYTREC is the number of + * TP_BSIZE blocks that are written in each tape record on + * 6250 BPI or higher density tapes. + * + * TP_NINDIR is the number of indirect pointers in a TS_INODE + * or TS_ADDR record. Note that it must be a power of two. + */ +#define TP_BSIZE 1024 +#define NTREC 10 +#define HIGHDENSITYTREC 32 +#define TP_NINDIR (TP_BSIZE/2) +#define LBLSIZE 16 +#define NAMELEN 64 + +#define OFS_MAGIC (int)60011 +#define NFS_MAGIC (int)60012 +#ifndef FS_UFS2_MAGIC +#define FS_UFS2_MAGIC (int)0x19540119 +#endif +#define CHECKSUM (int)84446 + +/* + * Since ino_t size is changing to 64-bits, yet we desire this structure to + * remain compatible with exiting dump formats, we do NOT use ino_t here, + * but rather define a 32-bit type in its place. At some point, it may be + * necessary to use some of the c_spare[] in order to fully support 64-bit + * inode numbers. + */ +typedef uint32_t dump_ino_t; + +extern union u_spcl { + char dummy[TP_BSIZE]; + struct s_spcl { + int32_t c_type; /* record type (see below) */ + int32_t c_old_date; /* date of this dump */ + int32_t c_old_ddate; /* date of previous dump */ + int32_t c_volume; /* dump volume number */ + int32_t c_old_tapea; /* logical block of this record */ + dump_ino_t c_inumber; /* number of inode */ + int32_t c_magic; /* magic number (see above) */ + int32_t c_checksum; /* record checksum */ + /* + * Start old dinode structure, expanded for binary + * compatibility with UFS1. + */ + u_int16_t c_mode; /* file mode */ + int16_t c_spare1[3]; /* old nlink, ids */ + u_int64_t c_size; /* file byte count */ + int32_t c_old_atime; /* old last access time, seconds */ + int32_t c_atimensec; /* last access time, nanoseconds */ + int32_t c_old_mtime; /* old last modified time, secs */ + int32_t c_mtimensec; /* last modified time, nanosecs */ + int32_t c_spare2[2]; /* old ctime */ + int32_t c_rdev; /* for devices, device number */ + int32_t c_birthtimensec; /* creation time, nanosecs */ + int64_t c_birthtime; /* creation time, seconds */ + int64_t c_atime; /* last access time, seconds */ + int64_t c_mtime; /* last modified time, seconds */ + int32_t c_extsize; /* external attribute size */ + int32_t c_spare4[6]; /* old block pointers */ + u_int32_t c_file_flags; /* status flags (chflags) */ + int32_t c_spare5[2]; /* old blocks, generation number */ + u_int32_t c_uid; /* file owner */ + u_int32_t c_gid; /* file group */ + int32_t c_spare6[2]; /* previously unused spares */ + /* + * End old dinode structure. + */ + int32_t c_count; /* number of valid c_addr entries */ + char c_addr[TP_NINDIR]; /* 1 => data; 0 => hole in inode */ + char c_label[LBLSIZE]; /* dump label */ + int32_t c_level; /* level of this dump */ + char c_filesys[NAMELEN]; /* name of dumpped file system */ + char c_dev[NAMELEN]; /* name of dumpped device */ + char c_host[NAMELEN]; /* name of dumpped host */ + int32_t c_flags; /* additional information */ + int32_t c_old_firstrec; /* first record on volume */ + int64_t c_date; /* date of this dump */ + int64_t c_ddate; /* date of previous dump */ + int64_t c_tapea; /* logical block of this record */ + int64_t c_firstrec; /* first record on volume */ + int32_t c_spare[24]; /* reserved for future uses */ + } s_spcl; +} u_spcl; +#define spcl u_spcl.s_spcl +/* + * special record types + */ +#define TS_TAPE 1 /* dump tape header */ +#define TS_INODE 2 /* beginning of file record */ +#define TS_ADDR 4 /* continuation of file record */ +#define TS_BITS 3 /* map of inodes on tape */ +#define TS_CLRI 6 /* map of inodes deleted since last dump */ +#define TS_END 5 /* end of volume marker */ + +#endif /* !_DUMPRESTORE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/protocols/routed.h b/lib/libc/include/any-freebsd-any/protocols/routed.h new file mode 100644 index 000000000000..dab9bba56617 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/protocols/routed.h @@ -0,0 +1,174 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)routed.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + * $Revision: 2.26 $ + */ + +#ifndef _ROUTED_H_ +#define _ROUTED_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Routing Information Protocol + * + * Derived from Xerox NS Routing Information Protocol + * by changing 32-bit net numbers to sockaddr's and + * padding stuff to 32-bit boundaries. + */ + +#define RIPv1 1 +#define RIPv2 2 +#ifndef RIPVERSION +#define RIPVERSION RIPv1 +#endif + +#define RIP_PORT 520 + +#if RIPVERSION == 1 +/* Note that this so called sockaddr has a 2-byte sa_family and no sa_len. + * It is not a UNIX sockaddr, but the shape of an address as defined + * in RIPv1. It is still defined to allow old versions of programs + * such as `gated` to use this file to define RIPv1. + */ +struct netinfo { + struct sockaddr rip_dst; /* destination net/host */ + u_int32_t rip_metric; /* cost of route */ +}; +#else +struct netinfo { + u_int16_t n_family; +#define RIP_AF_INET htons(AF_INET) +#define RIP_AF_UNSPEC 0 +#define RIP_AF_AUTH 0xffff + u_int16_t n_tag; /* optional in RIPv2 */ + u_int32_t n_dst; /* destination net or host */ +#define RIP_DEFAULT 0 + u_int32_t n_mask; /* netmask in RIPv2 */ + u_int32_t n_nhop; /* optional next hop in RIPv2 */ + u_int32_t n_metric; /* cost of route */ +}; +#endif + +/* RIPv2 authentication */ +struct netauth { + u_int16_t a_family; /* always RIP_AF_AUTH */ + u_int16_t a_type; +#define RIP_AUTH_NONE 0 +#define RIP_AUTH_PW htons(2) /* password type */ +#define RIP_AUTH_MD5 htons(3) /* Keyed MD5 */ + union { +#define RIP_AUTH_PW_LEN 16 + u_int8_t au_pw[RIP_AUTH_PW_LEN]; + struct a_md5 { + int16_t md5_pkt_len; /* RIP-II packet length */ + int8_t md5_keyid; /* key ID and auth data len */ + int8_t md5_auth_len; /* 16 */ + u_int32_t md5_seqno; /* sequence number */ + u_int32_t rsvd[2]; /* must be 0 */ +#define RIP_AUTH_MD5_KEY_LEN RIP_AUTH_PW_LEN +#define RIP_AUTH_MD5_HASH_XTRA (sizeof(struct netauth)-sizeof(struct a_md5)) +#define RIP_AUTH_MD5_HASH_LEN (RIP_AUTH_MD5_KEY_LEN+RIP_AUTH_MD5_HASH_XTRA) + } a_md5; + } au; +}; + +struct rip { + u_int8_t rip_cmd; /* request/response */ + u_int8_t rip_vers; /* protocol version # */ + u_int16_t rip_res1; /* pad to 32-bit boundary */ + union { /* variable length... */ + struct netinfo ru_nets[1]; + int8_t ru_tracefile[1]; + struct netauth ru_auth[1]; + } ripun; +#define rip_nets ripun.ru_nets +#define rip_auths ripun.ru_auth +#define rip_tracefile ripun.ru_tracefile +}; + +/* Packet types. + */ +#define RIPCMD_REQUEST 1 /* want info */ +#define RIPCMD_RESPONSE 2 /* responding to request */ +#define RIPCMD_TRACEON 3 /* turn tracing on */ +#define RIPCMD_TRACEOFF 4 /* turn it off */ + +/* Gated extended RIP to include a "poll" command instead of using + * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT). RFC 1058 says + * command 5 is used by Sun Microsystems for its own purposes. + */ +#define RIPCMD_POLL 5 + +#define RIPCMD_MAX 6 + +#ifdef RIPCMDS +const char *ripcmds[RIPCMD_MAX] = { + "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF" +}; +#endif + +#define HOPCNT_INFINITY 16 +#define MAXPACKETSIZE 512 /* max broadcast size */ +#define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip)) \ + / sizeof(struct netinfo) +1) + +#define INADDR_RIP_GROUP (u_int32_t)0xe0000009 /* 224.0.0.9 */ + + +/* Timer values used in managing the routing table. + * + * Complete tables are broadcast every SUPPLY_INTERVAL seconds. + * If changes occur between updates, dynamic updates containing only changes + * may be sent. When these are sent, a timer is set for a random value + * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates + * are sent until the timer expires. + * + * Every update of a routing entry forces an entry's timer to be reset. + * After EXPIRE_TIME without updates, the entry is marked invalid, + * but held onto until GARBAGE_TIME so that others may see it, to + * "poison" the bad route. + */ +#define SUPPLY_INTERVAL 30 /* time to supply tables */ +#define MIN_WAITTIME 2 /* min sec until next flash updates */ +#define MAX_WAITTIME 5 /* max sec until flash update */ + +#define STALE_TIME 90 /* switch to a new gateway */ +#define EXPIRE_TIME 180 /* time to mark entry invalid */ +#define GARBAGE_TIME 240 /* time to garbage collect */ + +#ifdef __cplusplus +} +#endif +#endif /* !_ROUTED_H_ */ diff --git a/lib/libc/include/any-freebsd-any/protocols/rwhod.h b/lib/libc/include/any-freebsd-any/protocols/rwhod.h new file mode 100644 index 000000000000..f598ec7a7ac3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/protocols/rwhod.h @@ -0,0 +1,70 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)rwhod.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _PROTOCOLS_RWHOD_H_ +#define _PROTOCOLS_RWHOD_H_ + +#include + +/* + * rwho protocol packet format. + */ +struct outmp { + char out_line[8]; /* tty name */ + char out_name[8]; /* user id */ + __int32_t out_time; /* time on */ +}; + +struct whod { + char wd_vers; /* protocol version # */ + char wd_type; /* packet type, see below */ + char wd_pad[2]; + int wd_sendtime; /* time stamp by sender */ + int wd_recvtime; /* time stamp applied by receiver */ + char wd_hostname[32]; /* hosts's name */ + int wd_loadav[3]; /* load average as in uptime */ + int wd_boottime; /* time system booted */ + struct whoent { + struct outmp we_utmp; /* active tty info */ + int we_idle; /* tty idle time */ + } wd_we[1024 / sizeof (struct whoent)]; +}; + +#define WHODVERSION 1 +#define WHODTYPE_STATUS 1 /* host status */ + +#define _PATH_RWHODIR "/var/rwho" + +#endif /* !_RWHOD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/protocols/talkd.h b/lib/libc/include/any-freebsd-any/protocols/talkd.h new file mode 100644 index 000000000000..f8b74b9c6981 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/protocols/talkd.h @@ -0,0 +1,114 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)talkd.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _PROTOCOLS_TALKD_H_ +#define _PROTOCOLS_TALKD_H_ + +/* + * This describes the protocol used by the talk server and clients. + * + * The talk server acts a repository of invitations, responding to + * requests by clients wishing to rendezvous for the purpose of + * holding a conversation. In normal operation, a client, the caller, + * initiates a rendezvous by sending a CTL_MSG to the server of + * type LOOK_UP. This causes the server to search its invitation + * tables to check if an invitation currently exists for the caller + * (to speak to the callee specified in the message). If the lookup + * fails, the caller then sends an ANNOUNCE message causing the server + * to broadcast an announcement on the callee's login ports requesting + * contact. When the callee responds, the local server uses the + * recorded invitation to respond with the appropriate rendezvous + * address and the caller and callee client programs establish a + * stream connection through which the conversation takes place. + */ + +/* + * Client->server request message format. + */ +typedef struct { + u_char vers; /* protocol version */ + u_char type; /* request type, see below */ + u_char answer; /* not used */ + u_char pad; + u_int32_t id_num; /* message id */ + struct osockaddr addr; /* old (4.3) style */ + struct osockaddr ctl_addr; /* old (4.3) style */ + int32_t pid; /* caller's process id */ +#define NAME_SIZE 12 + char l_name[NAME_SIZE];/* caller's name */ + char r_name[NAME_SIZE];/* callee's name */ +#define TTY_SIZE 16 + char r_tty[TTY_SIZE];/* callee's tty name */ +} CTL_MSG; + +/* + * Server->client response message format. + */ +typedef struct { + u_char vers; /* protocol version */ + u_char type; /* type of request message, see below */ + u_char answer; /* respose to request message, see below */ + u_char pad; + u_int32_t id_num; /* message id */ + struct osockaddr addr; /* address for establishing conversation */ +} CTL_RESPONSE; + +#define TALK_VERSION 1 /* protocol version */ + +/* message type values */ +#define LEAVE_INVITE 0 /* leave invitation with server */ +#define LOOK_UP 1 /* check for invitation by callee */ +#define DELETE 2 /* delete invitation by caller */ +#define ANNOUNCE 3 /* announce invitation by caller */ + +/* answer values */ +#define SUCCESS 0 /* operation completed properly */ +#define NOT_HERE 1 /* callee not logged in */ +#define FAILED 2 /* operation failed for unexplained reason */ +#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */ +#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */ +#define UNKNOWN_REQUEST 5 /* request has invalid type value */ +#define BADVERSION 6 /* request has invalid protocol version */ +#define BADADDR 7 /* request has invalid addr value */ +#define BADCTLADDR 8 /* request has invalid ctl_addr value */ + +/* + * Operational parameters. + */ +#define MAX_LIFE 60 /* max time daemon saves invitations */ +/* RING_WAIT should be 10's of seconds less than MAX_LIFE */ +#define RING_WAIT 30 /* time to wait before resending invitation */ + +#endif /* !_TALKD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/protocols/timed.h b/lib/libc/include/any-freebsd-any/protocols/timed.h new file mode 100644 index 000000000000..de4243c576fe --- /dev/null +++ b/lib/libc/include/any-freebsd-any/protocols/timed.h @@ -0,0 +1,104 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)timed.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _PROTOCOLS_TIMED_H_ +#define _PROTOCOLS_TIMED_H_ + +/* + * Time Synchronization Protocol + */ + +#define TSPVERSION 1 +#define ANYADDR NULL + +struct tsp { + u_int8_t tsp_type; + u_int8_t tsp_vers; + u_int16_t tsp_seq; + union { + struct { + int32_t tv_sec; + int32_t tv_usec; + } tspu_time; + char tspu_hopcnt; + } tsp_u; + char tsp_name[MAXHOSTNAMELEN]; +}; + +#define tsp_time tsp_u.tspu_time +#define tsp_hopcnt tsp_u.tspu_hopcnt + +/* + * Command types. + */ +#define TSP_ANY 0 /* match any types */ +#define TSP_ADJTIME 1 /* send adjtime */ +#define TSP_ACK 2 /* generic acknowledgement */ +#define TSP_MASTERREQ 3 /* ask for master's name */ +#define TSP_MASTERACK 4 /* acknowledge master request */ +#define TSP_SETTIME 5 /* send network time */ +#define TSP_MASTERUP 6 /* inform slaves that master is up */ +#define TSP_SLAVEUP 7 /* slave is up but not polled */ +#define TSP_ELECTION 8 /* advance candidature for master */ +#define TSP_ACCEPT 9 /* support candidature of master */ +#define TSP_REFUSE 10 /* reject candidature of master */ +#define TSP_CONFLICT 11 /* two or more masters present */ +#define TSP_RESOLVE 12 /* masters' conflict resolution */ +#define TSP_QUIT 13 /* reject candidature if master is up */ +#define TSP_DATE 14 /* reset the time (date command) */ +#define TSP_DATEREQ 15 /* remote request to reset the time */ +#define TSP_DATEACK 16 /* acknowledge time setting */ +#define TSP_TRACEON 17 /* turn tracing on */ +#define TSP_TRACEOFF 18 /* turn tracing off */ +#define TSP_MSITE 19 /* find out master's site */ +#define TSP_MSITEREQ 20 /* remote master's site request */ +#define TSP_TEST 21 /* for testing election algo */ +#define TSP_SETDATE 22 /* New from date command */ +#define TSP_SETDATEREQ 23 /* New remote for above */ +#define TSP_LOOP 24 /* loop detection packet */ + +#define TSPTYPENUMBER 25 + +#ifdef TSPTYPES +static char const * const tsptype[] = + { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", + "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", + "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", + "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; +_Static_assert(sizeof(tsptype) / sizeof(const char *) == TSPTYPENUMBER, + "Size of tsptype does not match TSPTYPENUMBER"); +#endif + +#endif /* !_TIMED_H_ */ diff --git a/lib/libc/include/any-freebsd-any/pthread.h b/lib/libc/include/any-freebsd-any/pthread.h new file mode 100644 index 000000000000..143401ddf68b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/pthread.h @@ -0,0 +1,354 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu + * Copyright (c) 1995-1998 by John Birrell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _PTHREAD_H_ +#define _PTHREAD_H_ + +/* + * Header files. + */ +#include +#include +#include +#include +#include +#include +#include + +/* + * Run-time invariant values: + */ +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#define PTHREAD_KEYS_MAX 256 +#define PTHREAD_STACK_MIN __MINSIGSTKSZ +#define PTHREAD_THREADS_MAX __ULONG_MAX +#define PTHREAD_BARRIER_SERIAL_THREAD -1 + +/* + * Flags for threads and thread attributes. + */ +#define PTHREAD_DETACHED 0x1 +#define PTHREAD_SCOPE_SYSTEM 0x2 +#define PTHREAD_INHERIT_SCHED 0x4 +#define PTHREAD_NOFLOAT 0x8 + +#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_SCOPE_PROCESS 0 +#define PTHREAD_EXPLICIT_SCHED 0 + +/* + * Values for process shared/private attributes. + */ +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 + +/* + * Flags for cancelling threads + */ +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_ASYNCHRONOUS 2 +#define PTHREAD_CANCELED ((void *) 1) + +/* + * Flags for once initialization. + */ +#define PTHREAD_NEEDS_INIT 0 +#define PTHREAD_DONE_INIT 1 + +/* + * Static once initialization values. + */ +#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } + +/* + * Static initialization values. + */ +#define PTHREAD_MUTEX_INITIALIZER NULL +#define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP ((pthread_mutex_t)1) +#define PTHREAD_COND_INITIALIZER NULL +#define PTHREAD_RWLOCK_INITIALIZER NULL + +/* + * Default attribute arguments (draft 4, deprecated). + */ +#ifndef PTHREAD_KERNEL +#define pthread_condattr_default NULL +#define pthread_mutexattr_default NULL +#define pthread_attr_default NULL +#endif + +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_PROTECT 2 + +/* + * Mutex types (Single UNIX Specification, Version 2, 1997). + * + * Note that a mutex attribute with one of the following types: + * + * PTHREAD_MUTEX_NORMAL + * PTHREAD_MUTEX_RECURSIVE + * + * will deviate from POSIX specified semantics. + */ +enum pthread_mutextype { + PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */ + PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ + PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ + PTHREAD_MUTEX_ADAPTIVE_NP = 4, /* Adaptive mutex, spins briefly before blocking on lock */ + PTHREAD_MUTEX_TYPE_MAX +}; + +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK + +#define PTHREAD_MUTEX_STALLED 0 +#define PTHREAD_MUTEX_ROBUST 1 + +struct _pthread_cleanup_info { + __uintptr_t pthread_cleanup_pad[8]; +}; + +/* + * Thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); +int pthread_attr_destroy(pthread_attr_t *); +int pthread_attr_getstack( + const pthread_attr_t * __restrict, void ** __restrict, + size_t * __restrict); +int pthread_attr_getstacksize(const pthread_attr_t * __restrict, + size_t * __restrict); +int pthread_attr_getguardsize(const pthread_attr_t * __restrict, + size_t * __restrict); +int pthread_attr_getstackaddr(const pthread_attr_t *, void **); +int pthread_attr_getdetachstate(const pthread_attr_t *, + int *); +int pthread_attr_init(pthread_attr_t *); +int pthread_attr_setstacksize(pthread_attr_t *, size_t); +int pthread_attr_setguardsize(pthread_attr_t *, size_t); +int pthread_attr_setstack(pthread_attr_t *, void *, + size_t); +int pthread_attr_setstackaddr(pthread_attr_t *, void *); +int pthread_attr_setdetachstate(pthread_attr_t *, int); +int pthread_barrier_destroy(pthread_barrier_t *); +int pthread_barrier_init(pthread_barrier_t * __restrict, + const pthread_barrierattr_t * __restrict, unsigned); +int pthread_barrier_wait(pthread_barrier_t *); +int pthread_barrierattr_destroy(pthread_barrierattr_t *); +int pthread_barrierattr_getpshared( + const pthread_barrierattr_t * __restrict, int * __restrict); +int pthread_barrierattr_init(pthread_barrierattr_t *); +int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); + +#define pthread_cleanup_push(cleanup_routine, cleanup_arg) \ + { \ + struct _pthread_cleanup_info __cleanup_info__; \ + __pthread_cleanup_push_imp(cleanup_routine, cleanup_arg,\ + &__cleanup_info__); \ + { + +#define pthread_cleanup_pop(execute) \ + (void)0; \ + } \ + __pthread_cleanup_pop_imp(execute); \ + } + +int pthread_condattr_destroy(pthread_condattr_t *); +int pthread_condattr_getclock(const pthread_condattr_t * __restrict, + clockid_t * __restrict); +int pthread_condattr_getpshared(const pthread_condattr_t *, int *); +int pthread_condattr_init(pthread_condattr_t *); +int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); +int pthread_condattr_setpshared(pthread_condattr_t *, int); +int pthread_cond_broadcast(pthread_cond_t *); +int pthread_cond_destroy(pthread_cond_t *); +int pthread_cond_init(pthread_cond_t * __restrict, + const pthread_condattr_t * __restrict); +int pthread_cond_signal(pthread_cond_t *); +int pthread_cond_timedwait(pthread_cond_t *, + pthread_mutex_t * __mutex, + const struct timespec *) + __requires_exclusive(*__mutex); +int pthread_cond_wait(pthread_cond_t * __restrict, + pthread_mutex_t * __restrict __mutex) + __requires_exclusive(*__mutex); +int pthread_create(pthread_t * __restrict, + const pthread_attr_t * __restrict, void *(*) (void *), + void * __restrict); +int pthread_detach(pthread_t); +int pthread_equal(pthread_t, pthread_t); +void pthread_exit(void *) __dead2; +void *pthread_getspecific(pthread_key_t); +int pthread_getcpuclockid(pthread_t, clockid_t *); +int pthread_join(pthread_t, void **); +int pthread_key_create(pthread_key_t *, void (*) (void *)); +int pthread_key_delete(pthread_key_t); +int pthread_mutexattr_init(pthread_mutexattr_t *); +int pthread_mutexattr_destroy(pthread_mutexattr_t *); +int pthread_mutexattr_getpshared( + const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_gettype( + const pthread_mutexattr_t * __restrict, int * __restrict); +int pthread_mutexattr_settype(pthread_mutexattr_t *, int); +int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); +int pthread_mutex_consistent(pthread_mutex_t * __mutex) + __requires_exclusive(*__mutex); +int pthread_mutex_destroy(pthread_mutex_t * __mutex) + __requires_unlocked(*__mutex); +int pthread_mutex_init(pthread_mutex_t * __restrict __mutex, + const pthread_mutexattr_t * __restrict) + __requires_unlocked(*__mutex); +int pthread_mutex_lock(pthread_mutex_t * __mutex) + __locks_exclusive(*__mutex); +int pthread_mutex_trylock(pthread_mutex_t * __mutex) + __trylocks_exclusive(0, *__mutex); +int pthread_mutex_timedlock(pthread_mutex_t * __restrict __mutex, + const struct timespec * __restrict) + __trylocks_exclusive(0, *__mutex); +int pthread_mutex_unlock(pthread_mutex_t * __mutex) + __unlocks(*__mutex); +int pthread_once(pthread_once_t *, void (*) (void)); +int pthread_rwlock_destroy(pthread_rwlock_t * __rwlock) + __requires_unlocked(*__rwlock); +int pthread_rwlock_init(pthread_rwlock_t * __restrict __rwlock, + const pthread_rwlockattr_t * __restrict) + __requires_unlocked(*__rwlock); +int pthread_rwlock_rdlock(pthread_rwlock_t * __rwlock) + __locks_shared(*__rwlock); +int pthread_rwlock_timedrdlock( + pthread_rwlock_t * __restrict __rwlock, + const struct timespec * __restrict) + __trylocks_shared(0, *__rwlock); +int pthread_rwlock_timedwrlock( + pthread_rwlock_t * __restrict __rwlock, + const struct timespec * __restrict) + __trylocks_exclusive(0, *__rwlock); +int pthread_rwlock_tryrdlock(pthread_rwlock_t * __rwlock) + __trylocks_shared(0, *__rwlock); +int pthread_rwlock_trywrlock(pthread_rwlock_t * __rwlock) + __trylocks_exclusive(0, *__rwlock); +int pthread_rwlock_unlock(pthread_rwlock_t * __rwlock) + __unlocks(*__rwlock); +int pthread_rwlock_wrlock(pthread_rwlock_t * __rwlock) + __locks_exclusive(*__rwlock); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); +int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *, + int *); +int pthread_rwlockattr_getpshared( + const pthread_rwlockattr_t * __restrict, + int * __restrict); +int pthread_rwlockattr_init(pthread_rwlockattr_t *); +int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *, + int); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); +pthread_t pthread_self(void); +int pthread_setspecific(pthread_key_t, const void *); + +int pthread_spin_init(pthread_spinlock_t * __spin, int) + __requires_unlocked(*__spin); +int pthread_spin_destroy(pthread_spinlock_t * __spin) + __requires_unlocked(*__spin); +int pthread_spin_lock(pthread_spinlock_t * __spin) + __locks_exclusive(*__spin); +int pthread_spin_trylock(pthread_spinlock_t * __spin) + __trylocks_exclusive(0, *__spin); +int pthread_spin_unlock(pthread_spinlock_t * __spin) + __unlocks(*__spin); +int pthread_cancel(pthread_t); +int pthread_setcancelstate(int, int *); +int pthread_setcanceltype(int, int *); +void pthread_testcancel(void); + +#if __BSD_VISIBLE +int pthread_getprio(pthread_t); +int pthread_setprio(pthread_t, int); +void pthread_yield(void); + +int pthread_getname_np(pthread_t, char *, size_t); +int pthread_setname_np(pthread_t, const char *); +#endif + +int pthread_mutexattr_getprioceiling( + const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); +int pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict, + int * __restrict); +int pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int, + int * __restrict); + +int pthread_mutexattr_getprotocol( + const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); + +int pthread_mutexattr_getrobust( + pthread_mutexattr_t * __restrict, int * __restrict); +int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); + +int pthread_attr_getinheritsched(const pthread_attr_t * __restrict, + int * __restrict); +int pthread_attr_getschedparam(const pthread_attr_t *, + struct sched_param *); +int pthread_attr_getschedpolicy(const pthread_attr_t * __restrict, + int * __restrict); +int pthread_attr_getscope(const pthread_attr_t * __restrict, + int * __restrict); +int pthread_attr_setinheritsched(pthread_attr_t *, int); +int pthread_attr_setschedparam(pthread_attr_t *, + const struct sched_param *); +int pthread_attr_setschedpolicy(pthread_attr_t *, int); +int pthread_attr_setscope(pthread_attr_t *, int); +int pthread_getschedparam(pthread_t pthread, int * __restrict, + struct sched_param * __restrict); +int pthread_setschedparam(pthread_t, int, + const struct sched_param *); +#if __XSI_VISIBLE +int pthread_getconcurrency(void); +int pthread_setconcurrency(int); +#endif + +void __pthread_cleanup_push_imp(void (*)(void *), void *, + struct _pthread_cleanup_info *); +void __pthread_cleanup_pop_imp(int); +__END_DECLS + +#endif /* !_PTHREAD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/pthread_np.h b/lib/libc/include/any-freebsd-any/pthread_np.h new file mode 100644 index 000000000000..f93a023f0fce --- /dev/null +++ b/lib/libc/include/any-freebsd-any/pthread_np.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1996-98 John Birrell . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _PTHREAD_NP_H_ +#define _PTHREAD_NP_H_ + +#include +#include + +/* + * Non-POSIX type definitions: + */ +typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t); + +/* + * Non-POSIX thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_attr_setcreatesuspend_np(pthread_attr_t *); +int pthread_attr_get_np(pthread_t, pthread_attr_t *); +int pthread_attr_getaffinity_np(const pthread_attr_t *, size_t, cpuset_t *); +int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpuset_t *); +void pthread_get_name_np(pthread_t, char *, size_t); +int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *); +int pthread_getthreadid_np(void); +int pthread_main_np(void); +int pthread_multi_np(void); +int pthread_mutexattr_getkind_np(pthread_mutexattr_t); +int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int); +int pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count); +int pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count); +int pthread_mutex_getyieldloops_np(pthread_mutex_t *mutex, int *count); +int pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count); +int pthread_mutex_isowned_np(pthread_mutex_t *mutex); +void pthread_resume_all_np(void); +int pthread_resume_np(pthread_t); +int pthread_peekjoin_np(pthread_t, void **); +void pthread_set_name_np(pthread_t, const char *); +int pthread_setaffinity_np(pthread_t, size_t, const cpuset_t *); +int pthread_single_np(void); +void pthread_suspend_all_np(void); +int pthread_suspend_np(pthread_t); +int pthread_switch_add_np(pthread_switch_routine_t); +int pthread_switch_delete_np(pthread_switch_routine_t); +int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); +__END_DECLS + +#endif diff --git a/lib/libc/include/any-freebsd-any/pwd.h b/lib/libc/include/any-freebsd-any/pwd.h new file mode 100644 index 000000000000..1548400b7eb8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/pwd.h @@ -0,0 +1,177 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)pwd.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _PWD_H_ +#define _PWD_H_ + +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#define _PATH_PWD "/etc" +#define _PATH_PASSWD "/etc/passwd" +#define _PASSWD "passwd" +#define _PATH_MASTERPASSWD "/etc/master.passwd" +#define _MASTERPASSWD "master.passwd" + +#define _PATH_MP_DB "/etc/pwd.db" +#define _MP_DB "pwd.db" +#define _PATH_SMP_DB "/etc/spwd.db" +#define _SMP_DB "spwd.db" + +#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" + +/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format + * `1 octet tag | key', where the tag is one of the _PW_KEY* values + * listed below. These values happen to be ASCII digits. Starting + * with FreeBSD 5.1, the tag is now still a single octet, but the + * upper 4 bits are interpreted as a version. Pre-FreeBSD 5.1 format + * entries are version `3' -- this conveniently results in the same + * key values as before. The new, architecture-independent entries + * are version `4'. + * As it happens, some applications read the database directly. + * (Bad app, no cookie!) Thus, we leave the _PW_KEY* symbols at their + * old pre-FreeBSD 5.1 values so these apps still work. Consequently + * we have to muck around a bit more to get the correct, versioned + * tag, and that is what the _PW_VERSIONED macro is about. + */ + +#define _PW_VERSION_MASK '\xF0' +#define _PW_VERSIONED(x, v) ((unsigned char)(((x) & 0xCF) | ((v)<<4))) + +#define _PW_KEYBYNAME '\x31' /* stored by name */ +#define _PW_KEYBYNUM '\x32' /* stored by entry in the "file" */ +#define _PW_KEYBYUID '\x33' /* stored by uid */ +#define _PW_KEYYPENABLED '\x34' /* YP is enabled */ +#define _PW_KEYYPBYNUM '\x35' /* special +@netgroup entries */ + +/* The database also contains a key to indicate the format version of + * the entries therein. There may be other, older versioned entries + * as well. + */ +#define _PWD_VERSION_KEY "\xFF" "VERSION" +#define _PWD_CURRENT_VERSION '\x04' + +#define _PASSWORD_EFMT1 '_' /* extended encryption format */ + +#define _PASSWORD_LEN 128 /* max length, not counting NULL */ + +struct passwd { + char *pw_name; /* user name */ + char *pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + time_t pw_change; /* password change time */ + char *pw_class; /* user access class */ + char *pw_gecos; /* Honeywell login info */ + char *pw_dir; /* home directory */ + char *pw_shell; /* default shell */ + time_t pw_expire; /* account expiration */ + int pw_fields; /* internal: fields filled in */ +}; + +/* Mapping from fields to bits for pw_fields. */ +#define _PWF(x) (1 << x) +#define _PWF_NAME _PWF(0) +#define _PWF_PASSWD _PWF(1) +#define _PWF_UID _PWF(2) +#define _PWF_GID _PWF(3) +#define _PWF_CHANGE _PWF(4) +#define _PWF_CLASS _PWF(5) +#define _PWF_GECOS _PWF(6) +#define _PWF_DIR _PWF(7) +#define _PWF_SHELL _PWF(8) +#define _PWF_EXPIRE _PWF(9) + +/* XXX These flags are bogus. With nsswitch, there are many + * possible sources and they cannot be represented in a small integer. + */ +#define _PWF_SOURCE 0x3000 +#define _PWF_FILES 0x1000 +#define _PWF_NIS 0x2000 +#define _PWF_HESIOD 0x3000 + +__BEGIN_DECLS +struct passwd *getpwnam(const char *); +struct passwd *getpwuid(uid_t); + +#if __XSI_VISIBLE >= 500 +void endpwent(void); +struct passwd *getpwent(void); +void setpwent(void); +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 +int getpwnam_r(const char *, struct passwd *, char *, size_t, + struct passwd **); +int getpwuid_r(uid_t, struct passwd *, char *, size_t, + struct passwd **); +#endif + +#if __BSD_VISIBLE +int getpwent_r(struct passwd *, char *, size_t, struct passwd **); +int setpassent(int); +const char *user_from_uid(uid_t, int); +int uid_from_user(const char *, uid_t *); +int pwcache_userdb(int (*)(int), void (*)(void), + struct passwd * (*)(const char *), + struct passwd * (*)(uid_t)); +#endif +__END_DECLS + +#endif /* !_PWD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ranlib.h b/lib/libc/include/any-freebsd-any/ranlib.h new file mode 100644 index 000000000000..cdba75f9f6f3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ranlib.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ranlib.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _RANLIB_H_ +#define _RANLIB_H_ + +#define RANLIBMAG "__.SYMDEF" /* archive file name */ +#define RANLIBSKEW 3 /* creation time offset */ + +struct ranlib { + union { + long ran_strx; /* string table index */ + char *ran_name; /* in memory symbol name */ + } ran_un; + long ran_off; /* archive file offset */ +}; + +#endif /* !_RANLIB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/readpassphrase.h b/lib/libc/include/any-freebsd-any/readpassphrase.h new file mode 100644 index 000000000000..fd54642da21b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/readpassphrase.h @@ -0,0 +1,49 @@ +/* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: ISC + * + * Copyright (c) 2000, 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#ifndef _READPASSPHRASE_H_ +#define _READPASSPHRASE_H_ + +#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ +#define RPP_ECHO_ON 0x01 /* Leave echo on. */ +#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ +#define RPP_FORCELOWER 0x04 /* Force input to lower case. */ +#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ +#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ +#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +char * readpassphrase(const char *, char *, size_t, int); +__END_DECLS + +#endif /* !_READPASSPHRASE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/regex.h b/lib/libc/include/any-freebsd-any/regex.h new file mode 100644 index 000000000000..6b0838a9bd97 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/regex.h @@ -0,0 +1,118 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992 Henry Spencer. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Henry Spencer of the University of Toronto. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)regex.h 8.2 (Berkeley) 1/3/94 + * $FreeBSD$ + */ + +#ifndef _REGEX_H_ +#define _REGEX_H_ + +#include +#include + +/* types */ +typedef __off_t regoff_t; + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct { + int re_magic; + size_t re_nsub; /* number of parenthesized subexpressions */ + const char *re_endp; /* end pointer for REG_PEND */ + struct re_guts *re_g; /* none of your business :-) */ +} regex_t; + +typedef struct { + regoff_t rm_so; /* start of match */ + regoff_t rm_eo; /* end of match */ +} regmatch_t; + +/* regcomp() flags */ +#define REG_BASIC 0000 +#define REG_EXTENDED 0001 +#define REG_ICASE 0002 +#define REG_NOSUB 0004 +#define REG_NEWLINE 0010 +#define REG_NOSPEC 0020 +#define REG_PEND 0040 +#define REG_DUMP 0200 + +/* regerror() flags */ +#define REG_ENOSYS (-1) +#define REG_NOMATCH 1 +#define REG_BADPAT 2 +#define REG_ECOLLATE 3 +#define REG_ECTYPE 4 +#define REG_EESCAPE 5 +#define REG_ESUBREG 6 +#define REG_EBRACK 7 +#define REG_EPAREN 8 +#define REG_EBRACE 9 +#define REG_BADBR 10 +#define REG_ERANGE 11 +#define REG_ESPACE 12 +#define REG_BADRPT 13 +#define REG_EMPTY 14 +#define REG_ASSERT 15 +#define REG_INVARG 16 +#define REG_ILLSEQ 17 +#define REG_ATOI 255 /* convert name to number (!) */ +#define REG_ITOA 0400 /* convert number to name (!) */ + +/* regexec() flags */ +#define REG_NOTBOL 00001 +#define REG_NOTEOL 00002 +#define REG_STARTEND 00004 +#define REG_TRACE 00400 /* tracing of execution */ +#define REG_LARGE 01000 /* force large representation */ +#define REG_BACKR 02000 /* force use of backref code */ + +__BEGIN_DECLS +int regcomp(regex_t * __restrict, const char * __restrict, int); +size_t regerror(int, const regex_t * __restrict, char * __restrict, size_t); +/* + * XXX forth parameter should be `regmatch_t [__restrict]', but isn't because + * of a bug in GCC 3.2 (when -std=c99 is specified) which perceives this as a + * syntax error. + */ +int regexec(const regex_t * __restrict, const char * __restrict, size_t, + regmatch_t * __restrict, int); +void regfree(regex_t *); +__END_DECLS + +#endif /* !_REGEX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/res_update.h b/lib/libc/include/any-freebsd-any/res_update.h new file mode 100644 index 000000000000..32d363bacfae --- /dev/null +++ b/lib/libc/include/any-freebsd-any/res_update.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: ISC + * + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1999 by Internet Software Consortium, Inc. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * $Id: res_update.h,v 1.3 2005/04/27 04:56:15 sra Exp $ + * $FreeBSD$ + */ + +#ifndef __RES_UPDATE_H +#define __RES_UPDATE_H + +/*! \file */ + +#include +#include +#include + +/*% + * This RR-like structure is particular to UPDATE. + */ +struct ns_updrec { + struct { + struct ns_updrec *prev; + struct ns_updrec *next; + } r_link, r_glink; + ns_sect r_section; /*%< ZONE/PREREQUISITE/UPDATE */ + char * r_dname; /*%< owner of the RR */ + ns_class r_class; /*%< class number */ + ns_type r_type; /*%< type number */ + u_int32_t r_ttl; /*%< time to live */ + u_char * r_data; /*%< rdata fields as text string */ + u_int r_size; /*%< size of r_data field */ + int r_opcode; /*%< type of operation */ + /* following fields for private use by the resolver/server routines */ + struct databuf *r_dp; /*%< databuf to process */ + struct databuf *r_deldp; /*%< databuf's deleted/overwritten */ + u_int r_zone; /*%< zone number on server */ +}; +typedef struct ns_updrec ns_updrec; +typedef struct { + ns_updrec *head; + ns_updrec *tail; +} ns_updque; + +#define res_mkupdate __res_mkupdate +#define res_update __res_update +#define res_mkupdrec __res_mkupdrec +#define res_freeupdrec __res_freeupdrec +#define res_nmkupdate __res_nmkupdate +#define res_nupdate __res_nupdate + +int res_mkupdate(ns_updrec *, u_char *, int); +int res_update(ns_updrec *); +ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long); +void res_freeupdrec(ns_updrec *); +int res_nmkupdate(res_state, ns_updrec *, u_char *, int); +int res_nupdate(res_state, ns_updrec *, ns_tsig_key *); + +#endif /*__RES_UPDATE_H*/ + +/*! \file */ diff --git a/lib/libc/include/any-freebsd-any/resolv.h b/lib/libc/include/any-freebsd-any/resolv.h new file mode 100644 index 000000000000..2226c481c7e6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/resolv.h @@ -0,0 +1,505 @@ +/*- + * SPDX-License-Identifier: (ISC AND BSD-3-Clause) + * + * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1995-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Copyright (c) 1983, 1987, 1989 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*% + * @(#)resolv.h 8.1 (Berkeley) 6/2/93 + * $Id: resolv.h,v 1.30 2009/03/03 01:52:48 each Exp $ + * $FreeBSD$ + */ + +#ifndef _RESOLV_H_ +#define _RESOLV_H_ + +#include +#include +#include +#include +#include +#include + +/*% + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__RES > 19931104)". Do not + * compare for equality; rather, use it to determine whether your resolver + * is new enough to contain a certain feature. + */ + +#define __RES 20090302 + +/*% + * This used to be defined in res_query.c, now it's in herror.c. + * [XXX no it's not. It's in irs/irs_data.c] + * It was + * never extern'd by any *.h file before it was placed here. For thread + * aware programs, the last h_errno value set is stored in res->h_errno. + * + * XXX: There doesn't seem to be a good reason for exposing RES_SET_H_ERRNO + * (and __h_errno_set) to the public via . + * XXX: __h_errno_set is really part of IRS, not part of the resolver. + * If somebody wants to build and use a resolver that doesn't use IRS, + * what do they do? Perhaps something like + * #ifdef WANT_IRS + * # define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x) + * #else + * # define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x)) + * #endif + */ + +#define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x) +struct __res_state; /*%< forward */ +__BEGIN_DECLS +void __h_errno_set(struct __res_state *, int); +__END_DECLS + +/*% + * Resolver configuration file. + * Normally not present, but may contain the address of the + * initial name server(s) to query and the domain search list. + */ + +#ifndef _PATH_RESCONF +#define _PATH_RESCONF "/etc/resolv.conf" +#endif + +typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } + res_sendhookact; + +typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *, + const u_char **, int *, + u_char *, int, int *); + +typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *, + const u_char *, int, u_char *, + int, int *); + +struct res_sym { + int number; /*%< Identifying number, like T_MX */ + const char * name; /*%< Its symbolic name, like "MX" */ + const char * humanname; /*%< Its fun name, like "mail exchanger" */ +}; + +/*% + * Global defines and variables for resolver stub. + */ +#define MAXNS 3 /*%< max # name servers we'll track */ +#define MAXDFLSRCH 3 /*%< # default domain levels to try */ +#define MAXDNSRCH 6 /*%< max # domains in search path */ +#define LOCALDOMAINPARTS 2 /*%< min levels in name that is "local" */ +#define RES_TIMEOUT 5 /*%< min. seconds between retries */ +#define MAXRESOLVSORT 10 /*%< number of net to sort on */ +#define RES_MAXNDOTS 15 /*%< should reflect bit field size */ +#define RES_MAXRETRANS 30 /*%< only for resolv.conf/RES_OPTIONS */ +#define RES_MAXRETRY 5 /*%< only for resolv.conf/RES_OPTIONS */ +#define RES_DFLRETRY 2 /*%< Default #/tries. */ +#define RES_MAXTIME 65535 /*%< Infinity, in milliseconds. */ +struct __res_state_ext; + +struct __res_state { + int retrans; /*%< retransmission time interval */ + int retry; /*%< number of times to retransmit */ + /* + * XXX: If `sun' is defined, `options' and `pfcode' are + * defined as u_int in original BIND9 distribution. However, + * it breaks binary backward compatibility against FreeBSD's + * resolver. So, we changed not to see `sun'. + */ +#if defined(sun) && 0 + u_int options; /*%< option flags - see below. */ +#else + u_long options; /*%< option flags - see below. */ +#endif + int nscount; /*%< number of name servers */ + struct sockaddr_in + nsaddr_list[MAXNS]; /*%< address of name server */ +#define nsaddr nsaddr_list[0] /*%< for backward compatibility */ + u_short id; /*%< current message id */ + char *dnsrch[MAXDNSRCH+1]; /*%< components of domain to search */ + char defdname[256]; /*%< default domain (deprecated) */ +#if defined(sun) && 0 + u_int pfcode; /*%< RES_PRF_ flags - see below. */ +#else + u_long pfcode; /*%< RES_PRF_ flags - see below. */ +#endif + unsigned ndots:4; /*%< threshold for initial abs. query */ + unsigned nsort:4; /*%< number of elements in sort_list[] */ + char unused[3]; + struct { + struct in_addr addr; + u_int32_t mask; + } sort_list[MAXRESOLVSORT]; + res_send_qhook qhook; /*%< query hook */ + res_send_rhook rhook; /*%< response hook */ + int res_h_errno; /*%< last one set for this context */ + int _vcsock; /*%< PRIVATE: for res_send VC i/o */ + u_int _flags; /*%< PRIVATE: see below */ + u_int _pad; /*%< make _u 64 bit aligned */ + union { + /* On an 32-bit arch this means 512b total. */ + char pad[72 - 4*sizeof (int) - 3*sizeof (void *)]; + struct { + u_int16_t nscount; + u_int16_t nstimes[MAXNS]; /*%< ms. */ + int nssocks[MAXNS]; + struct __res_state_ext *ext; /*%< extension for IPv6 */ + } _ext; + } _u; + u_char *_rnd; /*%< PRIVATE: random state */ +}; + +typedef struct __res_state *res_state; + +union res_sockaddr_union { + struct sockaddr_in sin; +#ifdef IN6ADDR_ANY_INIT + struct sockaddr_in6 sin6; +#endif +#ifdef ISC_ALIGN64 + int64_t __align64; /*%< 64bit alignment */ +#else + int32_t __align32; /*%< 32bit alignment */ +#endif + char __space[128]; /*%< max size */ +}; + +/*% + * Resolver flags (used to be discrete per-module statics ints). + */ +#define RES_F_VC 0x00000001 /*%< socket is TCP */ +#define RES_F_CONN 0x00000002 /*%< socket is connected */ +#define RES_F_EDNS0ERR 0x00000004 /*%< EDNS0 caused errors */ +#define RES_F__UNUSED 0x00000008 /*%< (unused) */ +#define RES_F_LASTMASK 0x000000F0 /*%< ordinal server of last res_nsend */ +#define RES_F_LASTSHIFT 4 /*%< bit position of LASTMASK "flag" */ +#define RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT) + +/* res_findzonecut2() options */ +#define RES_EXHAUSTIVE 0x00000001 /*%< always do all queries */ +#define RES_IPV4ONLY 0x00000002 /*%< IPv4 only */ +#define RES_IPV6ONLY 0x00000004 /*%< IPv6 only */ + +/*% + * Resolver options (keep these in synch with res_debug.c, please) + */ +#define RES_INIT 0x00000001 /*%< address initialized */ +#define RES_DEBUG 0x00000002 /*%< print debug messages */ +#define RES_AAONLY 0x00000004 /*%< authoritative answers only (!IMPL)*/ +#define RES_USEVC 0x00000008 /*%< use virtual circuit */ +#define RES_PRIMARY 0x00000010 /*%< query primary server only (!IMPL) */ +#define RES_IGNTC 0x00000020 /*%< ignore truncation errors */ +#define RES_RECURSE 0x00000040 /*%< recursion desired */ +#define RES_DEFNAMES 0x00000080 /*%< use default domain name */ +#define RES_STAYOPEN 0x00000100 /*%< Keep TCP socket open */ +#define RES_DNSRCH 0x00000200 /*%< search up local domain tree */ +#define RES_INSECURE1 0x00000400 /*%< type 1 security disabled */ +#define RES_INSECURE2 0x00000800 /*%< type 2 security disabled */ +#define RES_NOALIASES 0x00001000 /*%< shuts off HOSTALIASES feature */ +#define RES_USE_INET6 0x00002000 /*%< use/map IPv6 in gethostbyname() */ +#define RES_ROTATE 0x00004000 /*%< rotate ns list after each query */ +#define RES_NOCHECKNAME 0x00008000 /*%< do not check names for sanity. */ +#define RES_KEEPTSIG 0x00010000 /*%< do not strip TSIG records */ +#define RES_BLAST 0x00020000 /*%< blast all recursive servers */ +#define RES_NSID 0x00040000 /*%< request name server ID */ +#define RES_NOTLDQUERY 0x00100000 /*%< don't unqualified name as a tld */ +#define RES_USE_DNSSEC 0x00200000 /*%< use DNSSEC using OK bit in OPT */ +/* #define RES_DEBUG2 0x00400000 */ /* nslookup internal */ +/* KAME extensions: use higher bit to avoid conflict with ISC use */ +#define RES_USE_DNAME 0x10000000 /*%< use DNAME */ +#define RES_USE_EDNS0 0x40000000 /*%< use EDNS0 if configured */ +#define RES_NO_NIBBLE2 0x80000000 /*%< disable alternate nibble lookup */ + +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \ + RES_DNSRCH | RES_NO_NIBBLE2) + +/*% + * Resolver "pfcode" values. Used by dig. + */ +#define RES_PRF_STATS 0x00000001 +#define RES_PRF_UPDATE 0x00000002 +#define RES_PRF_CLASS 0x00000004 +#define RES_PRF_CMD 0x00000008 +#define RES_PRF_QUES 0x00000010 +#define RES_PRF_ANS 0x00000020 +#define RES_PRF_AUTH 0x00000040 +#define RES_PRF_ADD 0x00000080 +#define RES_PRF_HEAD1 0x00000100 +#define RES_PRF_HEAD2 0x00000200 +#define RES_PRF_TTLID 0x00000400 +#define RES_PRF_HEADX 0x00000800 +#define RES_PRF_QUERY 0x00001000 +#define RES_PRF_REPLY 0x00002000 +#define RES_PRF_INIT 0x00004000 +#define RES_PRF_TRUNC 0x00008000 +/* 0x00010000 */ + +/* Things involving an internal (static) resolver context. */ +__BEGIN_DECLS +extern struct __res_state *__res_state(void); +__END_DECLS +#define _res (*__res_state()) + +#ifndef __BIND_NOSTATIC +#define fp_nquery __fp_nquery +#define fp_query __fp_query +#define hostalias __hostalias +#define p_query __p_query +#define res_close __res_close +#define res_init __res_init +#define res_isourserver __res_isourserver +#define res_mkquery __res_mkquery +#define res_opt __res_opt +#define res_query __res_query +#define res_querydomain __res_querydomain +#define res_search __res_search +#define res_send __res_send +#define res_sendsigned __res_sendsigned + +__BEGIN_DECLS +void fp_nquery(const u_char *, int, FILE *); +void fp_query(const u_char *, FILE *); +const char * hostalias(const char *); +void p_query(const u_char *); +void res_close(void); +int res_init(void); +int res_isourserver(const struct sockaddr_in *); +int res_mkquery(int, const char *, int, int, const u_char *, + int, const u_char *, u_char *, int); +int res_opt(int, u_char *, int, int); +int res_query(const char *, int, int, u_char *, int); +int res_querydomain(const char *, const char *, int, int, + u_char *, int); +int res_search(const char *, int, int, u_char *, int); +int res_send(const u_char *, int, u_char *, int); +int res_sendsigned(const u_char *, int, ns_tsig_key *, + u_char *, int); +__END_DECLS +#endif + +#if !defined(SHARED_LIBBIND) || defined(LIB) +/* + * If libbind is a shared object (well, DLL anyway) + * these externs break the linker when resolv.h is + * included by a lib client (like named) + * Make them go away if a client is including this + * + */ +extern const struct res_sym __p_key_syms[]; +extern const struct res_sym __p_cert_syms[]; +extern const struct res_sym __p_class_syms[]; +extern const struct res_sym __p_type_syms[]; +extern const struct res_sym __p_rcode_syms[]; +#endif /* SHARED_LIBBIND */ + +#define b64_ntop __b64_ntop +#define b64_pton __b64_pton +#define dn_comp __dn_comp +#define dn_count_labels __dn_count_labels +#define dn_expand __dn_expand +#define dn_skipname __dn_skipname +#define fp_resstat __fp_resstat +#define loc_aton __loc_aton +#define loc_ntoa __loc_ntoa +#define p_cdname __p_cdname +#define p_cdnname __p_cdnname +#define p_class __p_class +#define p_fqname __p_fqname +#define p_fqnname __p_fqnname +#define p_option __p_option +#define p_secstodate __p_secstodate +#define p_section __p_section +#define p_time __p_time +#define p_type __p_type +#define p_rcode __p_rcode +#define p_sockun __p_sockun +#define putlong __putlong +#define putshort __putshort +#define res_dnok __res_dnok +#if 0 +#define res_findzonecut __res_findzonecut +#endif +#define res_findzonecut2 __res_findzonecut2 +#define res_hnok __res_hnok +#define res_hostalias __res_hostalias +#define res_mailok __res_mailok +#define res_nameinquery __res_nameinquery +#define res_nclose __res_nclose +#define res_ninit __res_ninit +#define res_nmkquery __res_nmkquery +#define res_pquery __res_pquery +#define res_nquery __res_nquery +#define res_nquerydomain __res_nquerydomain +#define res_nsearch __res_nsearch +#define res_nsend __res_nsend +#if 0 +#define res_nsendsigned __res_nsendsigned +#endif +#define res_nisourserver __res_nisourserver +#define res_ownok __res_ownok +#define res_queriesmatch __res_queriesmatch +#define res_rndinit __res_rndinit +#define res_randomid __res_randomid +#define res_nrandomid __res_nrandomid +#define sym_ntop __sym_ntop +#define sym_ntos __sym_ntos +#define sym_ston __sym_ston +#define res_nopt __res_nopt +#define res_nopt_rdata __res_nopt_rdata +#define res_ndestroy __res_ndestroy +#define res_nametoclass __res_nametoclass +#define res_nametotype __res_nametotype +#define res_setservers __res_setservers +#define res_getservers __res_getservers +#if 0 +#define res_buildprotolist __res_buildprotolist +#define res_destroyprotolist __res_destroyprotolist +#define res_destroyservicelist __res_destroyservicelist +#define res_get_nibblesuffix __res_get_nibblesuffix +#define res_get_nibblesuffix2 __res_get_nibblesuffix2 +#endif +#define res_ourserver_p __res_ourserver_p +#if 0 +#define res_protocolname __res_protocolname +#define res_protocolnumber __res_protocolnumber +#endif +#define res_send_setqhook __res_send_setqhook +#define res_send_setrhook __res_send_setrhook +#if 0 +#define res_servicename __res_servicename +#define res_servicenumber __res_servicenumber +#endif +__BEGIN_DECLS +int res_hnok(const char *); +int res_ownok(const char *); +int res_mailok(const char *); +int res_dnok(const char *); +int sym_ston(const struct res_sym *, const char *, int *); +const char * sym_ntos(const struct res_sym *, int, int *); +const char * sym_ntop(const struct res_sym *, int, int *); +int b64_ntop(u_char const *, size_t, char *, size_t); +int b64_pton(char const *, u_char *, size_t); +int loc_aton(const char *, u_char *); +const char * loc_ntoa(const u_char *, char *); +int dn_skipname(const u_char *, const u_char *); +void putlong(u_int32_t, u_char *); +void putshort(u_int16_t, u_char *); +#ifndef __ultrix__ +u_int16_t _getshort(const u_char *); +u_int32_t _getlong(const u_char *); +#endif +const char * p_class(int); +const char * p_time(u_int32_t); +const char * p_type(int); +const char * p_rcode(int); +const char * p_sockun(union res_sockaddr_union, char *, size_t); +const u_char * p_cdnname(const u_char *, const u_char *, int, FILE *); +const u_char * p_cdname(const u_char *, const u_char *, FILE *); +const u_char * p_fqnname(const u_char *, const u_char *, int, char *, int); +const u_char * p_fqname(const u_char *, const u_char *, FILE *); +const char * p_option(u_long); +char * p_secstodate(u_long); +int dn_count_labels(const char *); +int dn_comp(const char *, u_char *, int, u_char **, u_char **); +int dn_expand(const u_char *, const u_char *, const u_char *, + char *, int); +void res_rndinit(res_state); +u_int res_randomid(void); +u_int res_nrandomid(res_state); +int res_nameinquery(const char *, int, int, const u_char *, + const u_char *); +int res_queriesmatch(const u_char *, const u_char *, + const u_char *, const u_char *); +const char * p_section(int, int); +/* Things involving a resolver context. */ +int res_ninit(res_state); +int res_nisourserver(const res_state, const struct sockaddr_in *); +void fp_resstat(const res_state, FILE *); +void res_pquery(const res_state, const u_char *, int, FILE *); +const char * res_hostalias(const res_state, const char *, char *, size_t); +int res_nquery(res_state, const char *, int, int, u_char *, int); +int res_nsearch(res_state, const char *, int, int, u_char *, int); +int res_nquerydomain(res_state, const char *, const char *, + int, int, u_char *, int); +int res_nmkquery(res_state, int, const char *, int, int, + const u_char *, int, const u_char *, + u_char *, int); +int res_nsend(res_state, const u_char *, int, u_char *, int); +#if 0 +int res_nsendsigned(res_state, const u_char *, int, + ns_tsig_key *, u_char *, int); +int res_findzonecut(res_state, const char *, ns_class, int, + char *, size_t, struct in_addr *, int); +#endif +int res_findzonecut2(res_state, const char *, ns_class, int, + char *, size_t, + union res_sockaddr_union *, int); +void res_nclose(res_state); +int res_nopt(res_state, int, u_char *, int, int); +int res_nopt_rdata(res_state, int, u_char *, int, u_char *, + u_short, u_short, u_char *); +void res_send_setqhook(res_send_qhook); +void res_send_setrhook(res_send_rhook); +int __res_vinit(res_state, int); +#if 0 +void res_destroyservicelist(void); +const char * res_servicename(u_int16_t, const char *); +const char * res_protocolname(int); +void res_destroyprotolist(void); +void res_buildprotolist(void); +const char * res_get_nibblesuffix(res_state); +const char * res_get_nibblesuffix2(res_state); +#endif +void res_ndestroy(res_state); +u_int16_t res_nametoclass(const char *, int *); +u_int16_t res_nametotype(const char *, int *); +void res_setservers(res_state, const union res_sockaddr_union *, + int); +int res_getservers(res_state, union res_sockaddr_union *, int); +__END_DECLS + +#endif /* !_RESOLV_H_ */ +/*! \file */ diff --git a/lib/libc/include/any-freebsd-any/rpc/auth.h b/lib/libc/include/any-freebsd-any/rpc/auth.h new file mode 100644 index 000000000000..bf0d76c046c6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/auth.h @@ -0,0 +1,370 @@ +/* $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)auth.h 1.17 88/02/08 SMI + * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC + * from: @(#)auth.h 1.43 98/02/02 SMI + * $FreeBSD$ + */ + +/* + * auth.h, Authentication interface. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + * + * The data structures are completely opaque to the client. The client + * is required to pass an AUTH * to routines that create rpc + * "sessions". + */ + +#ifndef _RPC_AUTH_H +#define _RPC_AUTH_H +#include +#include +#include +#include + +#define MAX_AUTH_BYTES 400 +#define MAXNETNAMELEN 255 /* maximum length of network user's name */ + +/* + * Client side authentication/security data + */ + +typedef struct sec_data { + u_int secmod; /* security mode number e.g. in nfssec.conf */ + u_int rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */ + int flags; /* AUTH_F_xxx flags */ + caddr_t data; /* opaque data per flavor */ +} sec_data_t; + +#ifdef _SYSCALL32_IMPL +struct sec_data32 { + uint32_t secmod; /* security mode number e.g. in nfssec.conf */ + uint32_t rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */ + int32_t flags; /* AUTH_F_xxx flags */ + caddr32_t data; /* opaque data per flavor */ +}; +#endif /* _SYSCALL32_IMPL */ + +/* + * AUTH_DES flavor specific data from sec_data opaque data field. + * AUTH_KERB has the same structure. + */ +typedef struct des_clnt_data { + struct netbuf syncaddr; /* time sync addr */ + struct knetconfig *knconf; /* knetconfig info that associated */ + /* with the syncaddr. */ + char *netname; /* server's netname */ + int netnamelen; /* server's netname len */ +} dh_k4_clntdata_t; + +#ifdef _SYSCALL32_IMPL +struct des_clnt_data32 { + struct netbuf32 syncaddr; /* time sync addr */ + caddr32_t knconf; /* knetconfig info that associated */ + /* with the syncaddr. */ + caddr32_t netname; /* server's netname */ + int32_t netnamelen; /* server's netname len */ +}; +#endif /* _SYSCALL32_IMPL */ + +#ifdef KERBEROS +/* + * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4) + * in sec_data->data opaque field. + */ +typedef struct krb4_svc_data { + int window; /* window option value */ +} krb4_svcdata_t; + +typedef struct krb4_svc_data des_svcdata_t; +#endif /* KERBEROS */ + +/* + * authentication/security specific flags + */ +#define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */ +#define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */ + + +/* + * Status returned from authentication check + */ +enum auth_stat { + AUTH_OK=0, + /* + * failed at remote end + */ + AUTH_BADCRED=1, /* bogus credentials (seal broken) */ + AUTH_REJECTEDCRED=2, /* client should begin new session */ + AUTH_BADVERF=3, /* bogus verifier (seal broken) */ + AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ + AUTH_TOOWEAK=5, /* rejected due to security reasons */ + /* + * failed locally + */ + AUTH_INVALIDRESP=6, /* bogus response verifier */ + AUTH_FAILED=7, /* some unknown reason */ +#ifdef KERBEROS + /* + * kerberos errors + */ + , + AUTH_KERB_GENERIC = 8, /* kerberos generic error */ + AUTH_TIMEEXPIRE = 9, /* time of credential expired */ + AUTH_TKT_FILE = 10, /* something wrong with ticket file */ + AUTH_DECODE = 11, /* can't decode authenticator */ + AUTH_NET_ADDR = 12, /* wrong net address in ticket */ +#endif /* KERBEROS */ + /* + * RPCSEC_GSS errors + */ + RPCSEC_GSS_CREDPROBLEM = 13, + RPCSEC_GSS_CTXPROBLEM = 14, + RPCSEC_GSS_NODISPATCH = 0x8000000 +}; + +union des_block { + struct { + uint32_t high; + uint32_t low; + } key; + char c[8]; +}; +typedef union des_block des_block; +__BEGIN_DECLS +extern bool_t xdr_des_block(XDR *, des_block *); +__END_DECLS + +/* + * Authentication info. Opaque to client. + */ +struct opaque_auth { + enum_t oa_flavor; /* flavor of auth */ + caddr_t oa_base; /* address of more auth stuff */ + u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ +}; + + +/* + * Auth handle, interface to client side authenticators. + */ +typedef struct __auth { + struct opaque_auth ah_cred; + struct opaque_auth ah_verf; + union des_block ah_key; + struct auth_ops { + void (*ah_nextverf) (struct __auth *); + /* nextverf & serialize */ + int (*ah_marshal) (struct __auth *, XDR *); + /* validate verifier */ + int (*ah_validate) (struct __auth *, + struct opaque_auth *); + /* refresh credentials */ + int (*ah_refresh) (struct __auth *, void *); + /* destroy this structure */ + void (*ah_destroy) (struct __auth *); + } *ah_ops; + void *ah_private; +} AUTH; + + +/* + * Authentication ops. + * The ops and the auth handle provide the interface to the authenticators. + * + * AUTH *auth; + * XDR *xdrs; + * struct opaque_auth verf; + */ +#define AUTH_NEXTVERF(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) +#define auth_nextverf(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) + +#define AUTH_MARSHALL(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) +#define auth_marshall(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) + +#define AUTH_VALIDATE(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) +#define auth_validate(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) + +#define AUTH_REFRESH(auth, msg) \ + ((*((auth)->ah_ops->ah_refresh))(auth, msg)) +#define auth_refresh(auth, msg) \ + ((*((auth)->ah_ops->ah_refresh))(auth, msg)) + +#define AUTH_DESTROY(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) +#define auth_destroy(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) + + +__BEGIN_DECLS +extern struct opaque_auth _null_auth; +__END_DECLS + +/* + * These are the various implementations of client side authenticators. + */ + +/* + * System style authentication + * AUTH *authunix_create(machname, uid, gid, len, aup_gids) + * char *machname; + * u_int uid; + * u_int gid; + * int len; + * u_int *aup_gids; + */ +__BEGIN_DECLS +extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *); +extern AUTH *authunix_create_default(void); /* takes no parameters */ +extern AUTH *authnone_create(void); /* takes no parameters */ +__END_DECLS +/* + * DES style authentication + * AUTH *authsecdes_create(servername, window, timehost, ckey) + * char *servername; - network name of server + * u_int window; - time to live + * const char *timehost; - optional hostname to sync with + * des_block *ckey; - optional conversation key to use + */ +__BEGIN_DECLS +extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *); +extern AUTH *authdes_seccreate (const char *, const u_int, const char *, + const des_block *); +__END_DECLS + +__BEGIN_DECLS +extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *); +__END_DECLS + +#define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip)) +#define authsys_create_default() authunix_create_default() + +/* + * Netname manipulation routines. + */ +__BEGIN_DECLS +extern int getnetname(char *); +extern int host2netname(char *, const char *, const char *); +extern int user2netname(char *, const uid_t, const char *); +extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *); +extern int netname2host(char *, char *, const int); +extern void passwd2des ( char *, char * ); +__END_DECLS + +/* + * + * These routines interface to the keyserv daemon + * + */ +__BEGIN_DECLS +extern int key_decryptsession(const char *, des_block *); +extern int key_encryptsession(const char *, des_block *); +extern int key_gendes(des_block *); +extern int key_setsecret(const char *); +extern int key_secretkey_is_set(void); +__END_DECLS + +/* + * Publickey routines. + */ +__BEGIN_DECLS +extern int getpublickey (const char *, char *); +extern int getpublicandprivatekey (const char *, char *); +extern int getsecretkey (char *, char *, char *); +__END_DECLS + +#ifdef KERBEROS +/* + * Kerberos style authentication + * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status) + * const char *service; - service name + * const char *srv_inst; - server instance + * const char *realm; - server realm + * const u_int window; - time to live + * const char *timehost; - optional hostname to sync with + * int *status; - kerberos status returned + */ +__BEGIN_DECLS +extern AUTH *authkerb_seccreate(const char *, const char *, const char *, + const u_int, const char *, int *); +__END_DECLS + +/* + * Map a kerberos credential into a unix cred. + * + * authkerb_getucred(rqst, uid, gid, grouplen, groups) + * const struct svc_req *rqst; - request pointer + * uid_t *uid; + * gid_t *gid; + * short *grouplen; + * int *groups; + * + */ +__BEGIN_DECLS +extern int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *, + short *, int * */); +__END_DECLS +#endif /* KERBEROS */ + +__BEGIN_DECLS +struct svc_req; +struct rpc_msg; +enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *); +enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *); +enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *); +__END_DECLS + +#define AUTH_NONE 0 /* no authentication */ +#define AUTH_NULL 0 /* backward compatibility */ +#define AUTH_SYS 1 /* unix style (uid, gids) */ +#define AUTH_UNIX AUTH_SYS +#define AUTH_SHORT 2 /* short hand unix style */ +#define AUTH_DH 3 /* for Diffie-Hellman mechanism */ +#define AUTH_DES AUTH_DH /* for backward compatibility */ +#define AUTH_KERB 4 /* kerberos style */ +#define RPCSEC_GSS 6 /* RPCSEC_GSS */ + +/* + * Pseudo auth flavors for RPCSEC_GSS. + */ +#define RPCSEC_GSS_KRB5 390003 +#define RPCSEC_GSS_KRB5I 390004 +#define RPCSEC_GSS_KRB5P 390005 + +#endif /* !_RPC_AUTH_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/auth_des.h b/lib/libc/include/any-freebsd-any/rpc/auth_des.h new file mode 100644 index 000000000000..3b860d8c7ac3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/auth_des.h @@ -0,0 +1,127 @@ +/* @(#)auth_des.h 2.2 88/07/29 4.0 RPCSRC; from 1.3 88/02/08 SMI */ +/* $FreeBSD$ */ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)auth_des.h 2.2 88/07/29 4.0 RPCSRC + * from: @(#)auth_des.h 1.14 94/04/25 SMI + */ + +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * auth_des.h, Protocol for DES style authentication for RPC + */ + +#ifndef _AUTH_DES_ +#define _AUTH_DES_ + +/* + * There are two kinds of "names": fullnames and nicknames + */ +enum authdes_namekind { + ADN_FULLNAME, + ADN_NICKNAME +}; + +/* + * A fullname contains the network name of the client, + * a conversation key and the window + */ +struct authdes_fullname { + char *name; /* network name of client, up to MAXNETNAMELEN */ + des_block key; /* conversation key */ + u_long window; /* associated window */ +}; + + +/* + * A credential + */ +struct authdes_cred { + enum authdes_namekind adc_namekind; + struct authdes_fullname adc_fullname; + u_long adc_nickname; +}; + + + +/* + * A des authentication verifier + */ +struct authdes_verf { + union { + struct timeval adv_ctime; /* clear time */ + des_block adv_xtime; /* crypt time */ + } adv_time_u; + u_long adv_int_u; +}; + +/* + * des authentication verifier: client variety + * + * adv_timestamp is the current time. + * adv_winverf is the credential window + 1. + * Both are encrypted using the conversation key. + */ +#define adv_timestamp adv_time_u.adv_ctime +#define adv_xtimestamp adv_time_u.adv_xtime +#define adv_winverf adv_int_u + +/* + * des authentication verifier: server variety + * + * adv_timeverf is the client's timestamp + client's window + * adv_nickname is the server's nickname for the client. + * adv_timeverf is encrypted using the conversation key. + */ +#define adv_timeverf adv_time_u.adv_ctime +#define adv_xtimeverf adv_time_u.adv_xtime +#define adv_nickname adv_int_u + +/* + * Map a des credential into a unix cred. + * + */ +__BEGIN_DECLS +extern int authdes_getucred( struct authdes_cred *, uid_t *, gid_t *, int *, gid_t * ); +__END_DECLS + +__BEGIN_DECLS +extern bool_t xdr_authdes_cred(XDR *, struct authdes_cred *); +extern bool_t xdr_authdes_verf(XDR *, struct authdes_verf *); +extern int rtime(dev_t, struct netbuf *, int, struct timeval *, + struct timeval *); +extern void kgetnetname(char *); +extern enum auth_stat _svcauth_des(struct svc_req *, struct rpc_msg *); +__END_DECLS + +#endif /* ndef _AUTH_DES_ */ diff --git a/lib/libc/include/any-freebsd-any/rpc/auth_kerb.h b/lib/libc/include/any-freebsd-any/rpc/auth_kerb.h new file mode 100644 index 000000000000..29b09d507006 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/auth_kerb.h @@ -0,0 +1,142 @@ +/* $FreeBSD$ */ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * auth_kerb.h, Protocol for Kerberos style authentication for RPC + * + * Copyright (C) 1986, Sun Microsystems, Inc. + */ + +#ifndef _RPC_AUTH_KERB_H +#define _RPC_AUTH_KERB_H + +#ifdef KERBEROS + +#include +#include +#include +#include +#include + +/* + * There are two kinds of "names": fullnames and nicknames + */ +enum authkerb_namekind { + AKN_FULLNAME, + AKN_NICKNAME +}; +/* + * A fullname contains the ticket and the window + */ +struct authkerb_fullname { + KTEXT_ST ticket; + u_long window; /* associated window */ +}; + +/* + * cooked credential stored in rq_clntcred + */ +struct authkerb_clnt_cred { + /* start of AUTH_DAT */ + unsigned char k_flags; /* Flags from ticket */ + char pname[ANAME_SZ]; /* Principal's name */ + char pinst[INST_SZ]; /* His Instance */ + char prealm[REALM_SZ]; /* His Realm */ + unsigned long checksum; /* Data checksum (opt) */ + C_Block session; /* Session Key */ + int life; /* Life of ticket */ + unsigned long time_sec; /* Time ticket issued */ + unsigned long address; /* Address in ticket */ + /* KTEXT_ST reply; Auth reply (opt) */ + /* end of AUTH_DAT */ + unsigned long expiry; /* time the ticket is expiring */ + u_long nickname; /* Nickname into cache */ + u_long window; /* associated window */ +}; + +typedef struct authkerb_clnt_cred authkerb_clnt_cred; + +/* + * A credential + */ +struct authkerb_cred { + enum authkerb_namekind akc_namekind; + struct authkerb_fullname akc_fullname; + u_long akc_nickname; +}; + +/* + * A kerb authentication verifier + */ +struct authkerb_verf { + union { + struct timeval akv_ctime; /* clear time */ + des_block akv_xtime; /* crypt time */ + } akv_time_u; + u_long akv_int_u; +}; + +/* + * des authentication verifier: client variety + * + * akv_timestamp is the current time. + * akv_winverf is the credential window + 1. + * Both are encrypted using the conversation key. + */ +#ifndef akv_timestamp +#define akv_timestamp akv_time_u.akv_ctime +#define akv_xtimestamp akv_time_u.akv_xtime +#define akv_winverf akv_int_u +#endif +/* + * des authentication verifier: server variety + * + * akv_timeverf is the client's timestamp + client's window + * akv_nickname is the server's nickname for the client. + * akv_timeverf is encrypted using the conversation key. + */ +#ifndef akv_timeverf +#define akv_timeverf akv_time_u.akv_ctime +#define akv_xtimeverf akv_time_u.akv_xtime +#define akv_nickname akv_int_u +#endif + +/* + * Register the service name, instance and realm. + */ +extern int authkerb_create(char *, char *, char *, u_int, + struct netbuf *, int *, dev_t, int, AUTH **); +extern bool_t xdr_authkerb_cred(XDR *, struct authkerb_cred *); +extern bool_t xdr_authkerb_verf(XDR *, struct authkerb_verf *); +extern int svc_kerb_reg(SVCXPRT *, char *, char *, char *); +extern enum auth_stat _svcauth_kerb(struct svc_req *, struct rpc_msg *); + +#endif /* KERBEROS */ +#endif /* !_RPC_AUTH_KERB_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/auth_unix.h b/lib/libc/include/any-freebsd-any/rpc/auth_unix.h new file mode 100644 index 000000000000..6d1fc315a18d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/auth_unix.h @@ -0,0 +1,85 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)auth_unix.h 1.8 88/02/08 SMI + * from: @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * auth_unix.h, Protocol for UNIX style authentication parameters for RPC + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +/* + * The system is very weak. The client uses no encryption for it + * credentials and only sends null verifiers. The server sends backs + * null verifiers or optionally a verifier that suggests a new short hand + * for the credentials. + */ + +#ifndef _RPC_AUTH_UNIX_H +#define _RPC_AUTH_UNIX_H +#include + +/* The machine name is part of a credential; it may not exceed 255 bytes */ +#define MAX_MACHINE_NAME 255 + +/* gids compose part of a credential; there may not be more than 16 of them */ +#define NGRPS 16 + +/* + * Unix style credentials. + */ +struct authunix_parms { + u_long aup_time; + char *aup_machname; + u_int aup_uid; + u_int aup_gid; + u_int aup_len; + u_int *aup_gids; +}; + +#define authsys_parms authunix_parms + +__BEGIN_DECLS +extern bool_t xdr_authunix_parms(XDR *, struct authunix_parms *); +__END_DECLS + +/* + * If a response verifier has flavor AUTH_SHORT, + * then the body of the response verifier encapsulates the following structure; + * again it is serialized in the obvious fashion. + */ +struct short_hand_verf { + struct opaque_auth new_cred; +}; + +#endif /* !_RPC_AUTH_UNIX_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/clnt.h b/lib/libc/include/any-freebsd-any/rpc/clnt.h new file mode 100644 index 000000000000..8d9ce1eccb09 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/clnt.h @@ -0,0 +1,538 @@ +/* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2010, Oracle America, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)clnt.h 1.31 94/04/29 SMI + * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * clnt.h - Client side remote procedure call interface. + */ + +#ifndef _RPC_CLNT_H_ +#define _RPC_CLNT_H_ +#include +#include +#include +#include + +/* + * Well-known IPV6 RPC broadcast address. + */ +#define RPCB_MULTICAST_ADDR "ff02::202" + +/* + * the following errors are in general unrecoverable. The caller + * should give up rather than retry. + */ +#define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \ + ((s) == RPC_CANTENCODEARGS) || \ + ((s) == RPC_CANTDECODERES) || \ + ((s) == RPC_VERSMISMATCH) || \ + ((s) == RPC_PROCUNAVAIL) || \ + ((s) == RPC_PROGUNAVAIL) || \ + ((s) == RPC_PROGVERSMISMATCH) || \ + ((s) == RPC_CANTDECODEARGS)) + +/* + * Error info. + */ +struct rpc_err { + enum clnt_stat re_status; + union { + int RE_errno; /* related system error */ + enum auth_stat RE_why; /* why the auth error occurred */ + struct { + rpcvers_t low; /* lowest version supported */ + rpcvers_t high; /* highest version supported */ + } RE_vers; + struct { /* maybe meaningful if RPC_FAILED */ + int32_t s1; + int32_t s2; + } RE_lb; /* life boot & debugging only */ + } ru; +#define re_errno ru.RE_errno +#define re_why ru.RE_why +#define re_vers ru.RE_vers +#define re_lb ru.RE_lb +}; + + +/* + * Client rpc handle. + * Created by individual implementations + * Client is responsible for initializing auth, see e.g. auth_none.c. + */ +typedef struct __rpc_client { + AUTH *cl_auth; /* authenticator */ + struct clnt_ops { + /* call remote procedure */ + enum clnt_stat (*cl_call)(struct __rpc_client *, + rpcproc_t, xdrproc_t, void *, xdrproc_t, + void *, struct timeval); + /* abort a call */ + void (*cl_abort)(struct __rpc_client *); + /* get specific error code */ + void (*cl_geterr)(struct __rpc_client *, + struct rpc_err *); + /* frees results */ + bool_t (*cl_freeres)(struct __rpc_client *, + xdrproc_t, void *); + /* destroy this structure */ + void (*cl_destroy)(struct __rpc_client *); + /* the ioctl() of rpc */ + bool_t (*cl_control)(struct __rpc_client *, u_int, + void *); + } *cl_ops; + void *cl_private; /* private stuff */ + char *cl_netid; /* network token */ + char *cl_tp; /* device name */ +} CLIENT; + + +/* + * Timers used for the pseudo-transport protocol when using datagrams + */ +struct rpc_timers { + u_short rt_srtt; /* smoothed round-trip time */ + u_short rt_deviate; /* estimated deviation */ + u_long rt_rtxcur; /* current (backed-off) rto */ +}; + +/* + * Feedback values used for possible congestion and rate control + */ +#define FEEDBACK_REXMIT1 1 /* first retransmit */ +#define FEEDBACK_OK 2 /* no retransmits */ + +/* Used to set version of portmapper used in broadcast */ + +#define CLCR_SET_LOWVERS 3 +#define CLCR_GET_LOWVERS 4 + +#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ + +/* + * client side rpc interface ops + * + * Parameter types are: + * + */ + +/* + * enum clnt_stat + * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) + * CLIENT *rh; + * rpcproc_t proc; + * xdrproc_t xargs; + * void *argsp; + * xdrproc_t xres; + * void *resp; + * struct timeval timeout; + */ +#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \ + argsp, xres, resp, secs)) +#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \ + argsp, xres, resp, secs)) + +/* + * void + * CLNT_ABORT(rh); + * CLIENT *rh; + */ +#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) +#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) + +/* + * struct rpc_err + * CLNT_GETERR(rh); + * CLIENT *rh; + */ +#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) +#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) + + +/* + * bool_t + * CLNT_FREERES(rh, xres, resp); + * CLIENT *rh; + * xdrproc_t xres; + * void *resp; + */ +#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) +#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) + +/* + * bool_t + * CLNT_CONTROL(cl, request, info) + * CLIENT *cl; + * u_int request; + * char *info; + */ +#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) +#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) + +/* + * control operations that apply to both udp and tcp transports + */ +#define CLSET_TIMEOUT 1 /* set timeout (timeval) */ +#define CLGET_TIMEOUT 2 /* get timeout (timeval) */ +#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ +#define CLGET_FD 6 /* get connections file descriptor */ +#define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */ +#define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ +#define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */ +#define CLGET_XID 10 /* Get xid */ +#define CLSET_XID 11 /* Set xid */ +#define CLGET_VERS 12 /* Get version number */ +#define CLSET_VERS 13 /* Set version number */ +#define CLGET_PROG 14 /* Get program number */ +#define CLSET_PROG 15 /* Set program number */ +#define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */ +#define CLSET_PUSH_TIMOD 17 /* push timod if not already present */ +#define CLSET_POP_TIMOD 18 /* pop timod */ +/* + * Connectionless only control operations + */ +#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ +#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ +#define CLSET_ASYNC 19 +#define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */ + +/* + * void + * CLNT_DESTROY(rh); + * CLIENT *rh; + */ +#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) +#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) + + +/* + * RPCTEST is a test program which is accessible on every rpc + * transport/port. It is used for testing, performance evaluation, + * and network administration. + */ + +#define RPCTEST_PROGRAM ((rpcprog_t)1) +#define RPCTEST_VERSION ((rpcvers_t)1) +#define RPCTEST_NULL_PROC ((rpcproc_t)2) +#define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3) + +/* + * By convention, procedure 0 takes null arguments and returns them + */ + +#define NULLPROC ((rpcproc_t)0) + +/* + * Below are the client handle creation routines for the various + * implementations of client side rpc. They can return NULL if a + * creation failure occurs. + */ + +/* + * Generic client creation routine. Supported protocols are those that + * belong to the nettype namespace (/etc/netconfig). + */ +__BEGIN_DECLS +extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t, + const char *); +/* + * + * const char *hostname; -- hostname + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const char *nettype; -- network type + */ + + /* + * Generic client creation routine. Just like clnt_create(), except + * it takes an additional timeout parameter. + */ +extern CLIENT * clnt_create_timed(const char *, const rpcprog_t, + const rpcvers_t, const char *, const struct timeval *); +/* + * + * const char *hostname; -- hostname + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const char *nettype; -- network type + * const struct timeval *tp; -- timeout + */ + +/* + * Generic client creation routine. Supported protocols are which belong + * to the nettype name space. + */ +extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *, + const rpcvers_t, const rpcvers_t, + const char *); +/* + * const char *host; -- hostname + * const rpcprog_t prog; -- program number + * rpcvers_t *vers_out; -- servers highest available version + * const rpcvers_t vers_low; -- low version number + * const rpcvers_t vers_high; -- high version number + * const char *nettype; -- network type + */ + +/* + * Generic client creation routine. Supported protocols are which belong + * to the nettype name space. + */ +extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t, + rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *, + const struct timeval *); +/* + * const char *host; -- hostname + * const rpcprog_t prog; -- program number + * rpcvers_t *vers_out; -- servers highest available version + * const rpcvers_t vers_low; -- low version number + * const rpcvers_t vers_high; -- high version number + * const char *nettype; -- network type + * const struct timeval *tp -- timeout + */ + +/* + * Generic client creation routine. It takes a netconfig structure + * instead of nettype + */ +extern CLIENT *clnt_tp_create(const char *, const rpcprog_t, + const rpcvers_t, const struct netconfig *); +/* + * const char *hostname; -- hostname + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const struct netconfig *netconf; -- network config structure + */ + +/* + * Generic client creation routine. Just like clnt_tp_create(), except + * it takes an additional timeout parameter. + */ +extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t, + const rpcvers_t, const struct netconfig *, const struct timeval *); +/* + * const char *hostname; -- hostname + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const struct netconfig *netconf; -- network config structure + * const struct timeval *tp -- timeout + */ + +/* + * Generic TLI create routine. Only provided for compatibility. + */ + +extern CLIENT *clnt_tli_create(const int, const struct netconfig *, + struct netbuf *, const rpcprog_t, + const rpcvers_t, const u_int, const u_int); +/* + * const register int fd; -- fd + * const struct netconfig *nconf; -- netconfig structure + * struct netbuf *svcaddr; -- servers address + * const u_long prog; -- program number + * const u_long vers; -- version number + * const u_int sendsz; -- send size + * const u_int recvsz; -- recv size + */ + +/* + * Low level clnt create routine for connectionful transports, e.g. tcp. + */ +extern CLIENT *clnt_vc_create(const int, const struct netbuf *, + const rpcprog_t, const rpcvers_t, + u_int, u_int); +/* + * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create(). + */ +extern CLIENT *clntunix_create(struct sockaddr_un *, + u_long, u_long, int *, u_int, u_int); +/* + * const int fd; -- open file descriptor + * const struct netbuf *svcaddr; -- servers address + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const u_int sendsz; -- buffer recv size + * const u_int recvsz; -- buffer send size + */ + +/* + * Low level clnt create routine for connectionless transports, e.g. udp. + */ +extern CLIENT *clnt_dg_create(const int, const struct netbuf *, + const rpcprog_t, const rpcvers_t, + const u_int, const u_int); +/* + * const int fd; -- open file descriptor + * const struct netbuf *svcaddr; -- servers address + * const rpcprog_t program; -- program number + * const rpcvers_t version; -- version number + * const u_int sendsz; -- buffer recv size + * const u_int recvsz; -- buffer send size + */ + +/* + * Memory based rpc (for speed check and testing) + * CLIENT * + * clnt_raw_create(prog, vers) + * u_long prog; + * u_long vers; + */ +extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t); + +__END_DECLS + + +/* + * Print why creation failed + */ +__BEGIN_DECLS +extern void clnt_pcreateerror(const char *); /* stderr */ +extern char *clnt_spcreateerror(const char *); /* string */ +__END_DECLS + +/* + * Like clnt_perror(), but is more verbose in its output + */ +__BEGIN_DECLS +extern void clnt_perrno(enum clnt_stat); /* stderr */ +extern char *clnt_sperrno(enum clnt_stat); /* string */ +__END_DECLS + +/* + * Print an English error message, given the client error code + */ +__BEGIN_DECLS +extern void clnt_perror(CLIENT *, const char *); /* stderr */ +extern char *clnt_sperror(CLIENT *, const char *); /* string */ +__END_DECLS + + +/* + * If a creation fails, the following allows the user to figure out why. + */ +struct rpc_createerr { + enum clnt_stat cf_stat; + struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ +}; + +__BEGIN_DECLS +extern struct rpc_createerr *__rpc_createerr(void); +__END_DECLS +#define rpc_createerr (*(__rpc_createerr())) + +/* + * The simplified interface: + * enum clnt_stat + * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype) + * const char *host; + * const rpcprog_t prognum; + * const rpcvers_t versnum; + * const rpcproc_t procnum; + * const xdrproc_t inproc, outproc; + * const char *in; + * char *out; + * const char *nettype; + */ +__BEGIN_DECLS +extern enum clnt_stat rpc_call(const char *, const rpcprog_t, + const rpcvers_t, const rpcproc_t, + const xdrproc_t, const char *, + const xdrproc_t, char *, const char *); +__END_DECLS + +/* + * RPC broadcast interface + * The call is broadcasted to all locally connected nets. + * + * extern enum clnt_stat + * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, + * eachresult, nettype) + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const rpcproc_t proc; -- procedure number + * const xdrproc_t xargs; -- xdr routine for args + * caddr_t argsp; -- pointer to args + * const xdrproc_t xresults; -- xdr routine for results + * caddr_t resultsp; -- pointer to results + * const resultproc_t eachresult; -- call with each result + * const char *nettype; -- Transport type + * + * For each valid response received, the procedure eachresult is called. + * Its form is: + * done = eachresult(resp, raddr, nconf) + * bool_t done; + * caddr_t resp; + * struct netbuf *raddr; + * struct netconfig *nconf; + * where resp points to the results of the call and raddr is the + * address if the responder to the broadcast. nconf is the transport + * on which the response was received. + * + * extern enum clnt_stat + * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, + * eachresult, inittime, waittime, nettype) + * const rpcprog_t prog; -- program number + * const rpcvers_t vers; -- version number + * const rpcproc_t proc; -- procedure number + * const xdrproc_t xargs; -- xdr routine for args + * caddr_t argsp; -- pointer to args + * const xdrproc_t xresults; -- xdr routine for results + * caddr_t resultsp; -- pointer to results + * const resultproc_t eachresult; -- call with each result + * const int inittime; -- how long to wait initially + * const int waittime; -- maximum time to wait + * const char *nettype; -- Transport type + */ + +typedef bool_t (*resultproc_t)(caddr_t, ...); + +__BEGIN_DECLS +extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t, + const rpcproc_t, const xdrproc_t, + caddr_t, const xdrproc_t, caddr_t, + const resultproc_t, const char *); +extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t, + const rpcproc_t, const xdrproc_t, + caddr_t, const xdrproc_t, caddr_t, + const resultproc_t, const int, + const int, const char *); +__END_DECLS + +/* For backward compatibility */ +#include + +#endif /* !_RPC_CLNT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/rpc/clnt_soc.h b/lib/libc/include/any-freebsd-any/rpc/clnt_soc.h new file mode 100644 index 000000000000..c16609bb6aac --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/clnt_soc.h @@ -0,0 +1,107 @@ +/* $NetBSD: clnt_soc.h,v 1.1 2000/06/02 22:57:55 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1984 - 1991 by Sun Microsystems, Inc. + */ + +/* + * clnt.h - Client side remote procedure call interface. + */ + +#ifndef _RPC_CLNT_SOC_H +#define _RPC_CLNT_SOC_H + +/* derived from clnt_soc.h 1.3 88/12/17 SMI */ + +/* + * All the following declarations are only for backward compatibility + * with TS-RPC. + */ + +#include + +#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ + +/* + * TCP based rpc + * CLIENT * + * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * u_long prog; + * u_long version; + * register int *sockp; + * u_int sendsz; + * u_int recvsz; + */ +__BEGIN_DECLS +extern CLIENT *clnttcp_create(struct sockaddr_in *, u_long, u_long, int *, + u_int, u_int); +__END_DECLS + +/* + * Raw (memory) rpc. + */ +__BEGIN_DECLS +extern CLIENT *clntraw_create(u_long, u_long); +__END_DECLS + + +/* + * UDP based rpc. + * CLIENT * + * clntudp_create(raddr, program, version, wait, sockp) + * struct sockaddr_in *raddr; + * u_long program; + * u_long version; + * struct timeval wait; + * int *sockp; + * + * Same as above, but you specify max packet sizes. + * CLIENT * + * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * u_long program; + * u_long version; + * struct timeval wait; + * int *sockp; + * u_int sendsz; + * u_int recvsz; + */ +__BEGIN_DECLS +extern CLIENT *clntudp_create(struct sockaddr_in *, u_long, u_long, + struct timeval, int *); +extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, u_long, u_long, + struct timeval, int *, u_int, u_int); +__END_DECLS + +#endif /* _RPC_CLNT_SOC_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/clnt_stat.h b/lib/libc/include/any-freebsd-any/rpc/clnt_stat.h new file mode 100644 index 000000000000..6148b4eb94a5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/clnt_stat.h @@ -0,0 +1,83 @@ +/* $FreeBSD$ */ +/* + * Copyright (c) 1986 - 1991, 1994, 1996, 1997 by Sun Microsystems, Inc. + * All rights reserved. + */ + +/* + * clnt_stat.h - Client side remote procedure call enum + * + */ + +#ifndef _RPC_CLNT_STAT_H +#define _RPC_CLNT_STAT_H + +/* #pragma ident "@(#)clnt_stat.h 1.2 97/04/28 SMI" */ + +#ifdef __cplusplus +extern "C" { +#endif + +enum clnt_stat { + RPC_SUCCESS = 0, /* call succeeded */ + /* + * local errors + */ + RPC_CANTENCODEARGS = 1, /* can't encode arguments */ + RPC_CANTDECODERES = 2, /* can't decode results */ + RPC_CANTSEND = 3, /* failure in sending call */ + RPC_CANTRECV = 4, + /* failure in receiving result */ + RPC_TIMEDOUT = 5, /* call timed out */ + RPC_INTR = 18, /* call interrupted */ + RPC_UDERROR = 23, /* recv got uderr indication */ + /* + * remote errors + */ + RPC_VERSMISMATCH = 6, /* rpc versions not compatible */ + RPC_AUTHERROR = 7, /* authentication error */ + RPC_PROGUNAVAIL = 8, /* program not available */ + RPC_PROGVERSMISMATCH = 9, /* program version mismatched */ + RPC_PROCUNAVAIL = 10, /* procedure unavailable */ + RPC_CANTDECODEARGS = 11, /* decode arguments error */ + RPC_SYSTEMERROR = 12, /* generic "other problem" */ + + /* + * rpc_call & clnt_create errors + */ + RPC_UNKNOWNHOST = 13, /* unknown host name */ + RPC_UNKNOWNPROTO = 17, /* unknown protocol */ + RPC_UNKNOWNADDR = 19, /* Remote address unknown */ + RPC_NOBROADCAST = 21, /* Broadcasting not supported */ + + /* + * rpcbind errors + */ + RPC_RPCBFAILURE = 14, /* the pmapper failed in its call */ +#define RPC_PMAPFAILURE RPC_RPCBFAILURE + RPC_PROGNOTREGISTERED = 15, /* remote program is not registered */ + RPC_N2AXLATEFAILURE = 22, + /* Name to address translation failed */ + /* + * Misc error in the TLI library + */ + RPC_TLIERROR = 20, + /* + * unspecified error + */ + RPC_FAILED = 16, + /* + * asynchronous errors + */ + RPC_INPROGRESS = 24, + RPC_STALERACHANDLE = 25, + RPC_CANTCONNECT = 26, /* couldn't make connection (cots) */ + RPC_XPRTFAILED = 27, /* received discon from remote (cots) */ + RPC_CANTCREATESTREAM = 28 /* can't push rpc module (cots) */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* !_RPC_CLNT_STAT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/des.h b/lib/libc/include/any-freebsd-any/rpc/des.h new file mode 100644 index 000000000000..93698cce6cbc --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/des.h @@ -0,0 +1,84 @@ +/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */ +/* $FreeBSD$ */ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Generic DES driver interface + * Keep this file hardware independent! + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */ +#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */ + +enum desdir { ENCRYPT, DECRYPT }; +enum desmode { CBC, ECB }; + +/* + * parameters to ioctl call + */ +struct desparams { + u_char des_key[8]; /* key (with low bit parity) */ + enum desdir des_dir; /* direction */ + enum desmode des_mode; /* mode */ + u_char des_ivec[8]; /* input vector */ + unsigned des_len; /* number of bytes to crypt */ + union { + u_char UDES_data[DES_QUICKLEN]; + u_char *UDES_buf; + } UDES; +# define des_data UDES.UDES_data /* direct data here if quick */ +# define des_buf UDES.UDES_buf /* otherwise, pointer to data */ +}; + +#ifdef notdef + +/* + * These ioctls are only implemented in SunOS. Maybe someday + * if somebody writes a driver for DES hardware that works + * with FreeBSD, we can being that back. + */ + +/* + * Encrypt an arbitrary sized buffer + */ +#define DESIOCBLOCK _IOWR('d', 6, struct desparams) + +/* + * Encrypt of small amount of data, quickly + */ +#define DESIOCQUICK _IOWR('d', 7, struct desparams) + +#endif + +/* + * Software DES. + */ +extern int _des_crypt( char *, int, struct desparams * ); diff --git a/lib/libc/include/any-freebsd-any/rpc/des_crypt.h b/lib/libc/include/any-freebsd-any/rpc/des_crypt.h new file mode 100644 index 000000000000..ef938c5cc900 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/des_crypt.h @@ -0,0 +1,107 @@ +/* + * @(#)des_crypt.h 2.1 88/08/11 4.0 RPCSRC; from 1.4 88/02/08 (C) 1986 SMI + * $FreeBSD$ + * + * des_crypt.h, des library routine interface + * Copyright (C) 1986, Sun Microsystems, Inc. + */ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * des_crypt.h, des library routine interface + */ + +#ifndef _DES_DES_CRYPT_H +#define _DES_DES_CRYPT_H + +#include +#include + +#define DES_MAXDATA 8192 /* max bytes encrypted in one call */ +#define DES_DIRMASK (1 << 0) +#define DES_ENCRYPT (0*DES_DIRMASK) /* Encrypt */ +#define DES_DECRYPT (1*DES_DIRMASK) /* Decrypt */ + + +#define DES_DEVMASK (1 << 1) +#define DES_HW (0*DES_DEVMASK) /* Use hardware device */ +#define DES_SW (1*DES_DEVMASK) /* Use software device */ + + +#define DESERR_NONE 0 /* succeeded */ +#define DESERR_NOHWDEVICE 1 /* succeeded, but hw device not available */ +#define DESERR_HWERROR 2 /* failed, hardware/driver error */ +#define DESERR_BADPARAM 3 /* failed, bad parameter to call */ + +#define DES_FAILED(err) \ + ((err) > DESERR_NOHWDEVICE) + +/* + * cbc_crypt() + * ecb_crypt() + * + * Encrypt (or decrypt) len bytes of a buffer buf. + * The length must be a multiple of eight. + * The key should have odd parity in the low bit of each byte. + * ivec is the input vector, and is updated to the new one (cbc only). + * The mode is created by oring together the appropriate parameters. + * DESERR_NOHWDEVICE is returned if DES_HW was specified but + * there was no hardware to do it on (the data will still be + * encrypted though, in software). + */ + + +/* + * Cipher Block Chaining mode + */ +__BEGIN_DECLS +int cbc_crypt( char *, char *, unsigned int, unsigned int, char *); +__END_DECLS + +/* + * Electronic Code Book mode + */ +__BEGIN_DECLS +int ecb_crypt( char *, char *, unsigned int, unsigned int ); +__END_DECLS + +/* + * Set des parity for a key. + * DES parity is odd and in the low bit of each byte + */ +__BEGIN_DECLS +void des_setparity( char *); +__END_DECLS + +#endif /* _DES_DES_CRYPT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/nettype.h b/lib/libc/include/any-freebsd-any/rpc/nettype.h new file mode 100644 index 000000000000..39c1f76970fb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/nettype.h @@ -0,0 +1,65 @@ +/* $NetBSD: nettype.h,v 1.2 2000/07/06 03:17:19 christos Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * nettype.h, Nettype definitions. + * All for the topmost layer of rpc + * + */ + +#ifndef _RPC_NETTYPE_H +#define _RPC_NETTYPE_H + +#include + +#define _RPC_NONE 0 +#define _RPC_NETPATH 1 +#define _RPC_VISIBLE 2 +#define _RPC_CIRCUIT_V 3 +#define _RPC_DATAGRAM_V 4 +#define _RPC_CIRCUIT_N 5 +#define _RPC_DATAGRAM_N 6 +#define _RPC_TCP 7 +#define _RPC_UDP 8 + +__BEGIN_DECLS +extern void *__rpc_setconf(const char *); +extern void __rpc_endconf(void *); +extern struct netconfig *__rpc_getconf(void *); +extern struct netconfig *__rpc_getconfip(const char *); +__END_DECLS + +#endif /* !_RPC_NETTYPE_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/pmap_clnt.h b/lib/libc/include/any-freebsd-any/rpc/pmap_clnt.h new file mode 100644 index 000000000000..465cb0c02623 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/pmap_clnt.h @@ -0,0 +1,87 @@ +/* $NetBSD: pmap_clnt.h,v 1.9 2000/06/02 22:57:55 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)pmap_clnt.h 1.11 88/02/08 SMI + * from: @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * pmap_clnt.h + * Supplies C routines to get to portmap services. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +/* + * Usage: + * success = pmap_set(program, version, protocol, port); + * success = pmap_unset(program, version); + * port = pmap_getport(address, program, version, protocol); + * head = pmap_getmaps(address); + * clnt_stat = pmap_rmtcall(address, program, version, procedure, + * xdrargs, argsp, xdrres, resp, tout, port_ptr) + * (works for udp only.) + * clnt_stat = clnt_broadcast(program, version, procedure, + * xdrargs, argsp, xdrres, resp, eachresult) + * (like pmap_rmtcall, except the call is broadcasted to all + * locally connected nets. For each valid response received, + * the procedure eachresult is called. Its form is: + * done = eachresult(resp, raddr) + * bool_t done; + * caddr_t resp; + * struct sockaddr_in raddr; + * where resp points to the results of the call and raddr is the + * address if the responder to the broadcast. + */ + +#ifndef _RPC_PMAP_CLNT_H_ +#define _RPC_PMAP_CLNT_H_ +#include + +__BEGIN_DECLS +extern bool_t pmap_set(u_long, u_long, int, int); +extern bool_t pmap_unset(u_long, u_long); +extern struct pmaplist *pmap_getmaps(struct sockaddr_in *); +extern enum clnt_stat pmap_rmtcall(struct sockaddr_in *, + u_long, u_long, u_long, + xdrproc_t, caddr_t, + xdrproc_t, caddr_t, + struct timeval, u_long *); +extern enum clnt_stat clnt_broadcast(u_long, u_long, u_long, + xdrproc_t, void *, + xdrproc_t, void *, + resultproc_t); +extern u_short pmap_getport(struct sockaddr_in *, + u_long, u_long, u_int); +__END_DECLS + +#endif /* !_RPC_PMAP_CLNT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/rpc/pmap_prot.h b/lib/libc/include/any-freebsd-any/rpc/pmap_prot.h new file mode 100644 index 000000000000..f69bad9ca1a7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/pmap_prot.h @@ -0,0 +1,108 @@ +/* $NetBSD: pmap_prot.h,v 1.8 2000/06/02 22:57:55 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)pmap_prot.h 1.14 88/02/08 SMI + * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * pmap_prot.h + * Protocol for the local binder service, or pmap. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + * + * The following procedures are supported by the protocol: + * + * PMAPPROC_NULL() returns () + * takes nothing, returns nothing + * + * PMAPPROC_SET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Registers the tuple + * [prog, vers, prot, port]. + * + * PMAPPROC_UNSET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Un-registers pair + * [prog, vers]. prot and port are ignored. + * + * PMAPPROC_GETPORT(struct pmap) returns (long unsigned). + * 0 is failure. Otherwise returns the port number where the pair + * [prog, vers] is registered. It may lie! + * + * PMAPPROC_DUMP() RETURNS (struct pmaplist *) + * + * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>) + * RETURNS (port, string<>); + * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); + * Calls the procedure on the local machine. If it is not registered, + * this procedure is quite; ie it does not return error information!!! + * This procedure only is supported on rpc/udp and calls via + * rpc/udp. This routine only passes null authentication parameters. + * This file has no interface to xdr routines for PMAPPROC_CALLIT. + * + * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. + */ + +#ifndef _RPC_PMAP_PROT_H +#define _RPC_PMAP_PROT_H +#include + +#define PMAPPORT ((u_short)111) +#define PMAPPROG ((u_long)100000) +#define PMAPVERS ((u_long)2) +#define PMAPVERS_PROTO ((u_long)2) +#define PMAPVERS_ORIG ((u_long)1) +#define PMAPPROC_NULL ((u_long)0) +#define PMAPPROC_SET ((u_long)1) +#define PMAPPROC_UNSET ((u_long)2) +#define PMAPPROC_GETPORT ((u_long)3) +#define PMAPPROC_DUMP ((u_long)4) +#define PMAPPROC_CALLIT ((u_long)5) + +struct pmap { + long unsigned pm_prog; + long unsigned pm_vers; + long unsigned pm_prot; + long unsigned pm_port; +}; + +struct pmaplist { + struct pmap pml_map; + struct pmaplist *pml_next; +}; + +__BEGIN_DECLS +extern bool_t xdr_pmap(XDR *, struct pmap *); +extern bool_t xdr_pmaplist(XDR *, struct pmaplist **); +extern bool_t xdr_pmaplist_ptr(XDR *, struct pmaplist *); +__END_DECLS + +#endif /* !_RPC_PMAP_PROT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/pmap_rmt.h b/lib/libc/include/any-freebsd-any/rpc/pmap_rmt.h new file mode 100644 index 000000000000..791b3f486bc2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/pmap_rmt.h @@ -0,0 +1,66 @@ +/* $NetBSD: pmap_rmt.h,v 1.7 1998/02/11 23:01:23 lukem Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)pmap_rmt.h 1.2 88/02/08 SMI + * from: @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * Structures and XDR routines for parameters to and replies from + * the portmapper remote-call-service. + * + * Copyright (C) 1986, Sun Microsystems, Inc. + */ + +#ifndef _RPC_PMAP_RMT_H +#define _RPC_PMAP_RMT_H +#include + +struct rmtcallargs { + u_long prog, vers, proc, arglen; + caddr_t args_ptr; + xdrproc_t xdr_args; +}; + +struct rmtcallres { + u_long *port_ptr; + u_long resultslen; + caddr_t results_ptr; + xdrproc_t xdr_results; +}; + +__BEGIN_DECLS +extern bool_t xdr_rmtcall_args(XDR *, struct rmtcallargs *); +extern bool_t xdr_rmtcallres(XDR *, struct rmtcallres *); +__END_DECLS + +#endif /* !_RPC_PMAP_RMT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/raw.h b/lib/libc/include/any-freebsd-any/rpc/raw.h new file mode 100644 index 000000000000..b56b9026d93f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/raw.h @@ -0,0 +1,59 @@ +/* $NetBSD: raw.h,v 1.1 2000/06/02 22:57:56 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +#ifndef _RPC_RAW_H +#define _RPC_RAW_H + +/* from: @(#)raw.h 1.11 94/04/25 SMI */ +/* from: @(#)raw.h 1.2 88/10/25 SMI */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * raw.h + * + * Raw interface + * The common memory area over which they will communicate + */ +extern char *__rpc_rawcombuf; + +#ifdef __cplusplus +} +#endif + +#endif /* _RPC_RAW_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpc.h b/lib/libc/include/any-freebsd-any/rpc/rpc.h new file mode 100644 index 000000000000..561437c30943 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpc.h @@ -0,0 +1,109 @@ +/* $NetBSD: rpc.h,v 1.13 2000/06/02 22:57:56 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)rpc.h 1.9 88/02/08 SMI + * from: @(#)rpc.h 2.4 89/07/11 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * rpc.h, Just includes the billions of rpc header files necessary to + * do remote procedure calling. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ +#ifndef _RPC_RPC_H +#define _RPC_RPC_H + +#include /* some typedefs */ +#include +#include + +/* external data representation interfaces */ +#include /* generic (de)serializer */ + +/* Client side only authentication */ +#include /* generic authenticator (client side) */ + +/* Client side (mostly) remote procedure call */ +#include /* generic rpc stuff */ + +/* semi-private protocol headers */ +#include /* protocol for rpc messages */ +#include /* protocol for unix style cred */ +/* + * Uncomment-out the next line if you are building the rpc library with + * DES Authentication (see the README file in the secure_rpc/ directory). + */ +#include /* protocol for des style cred */ + +/* Server side only remote procedure callee */ +#include /* service manager and multiplexer */ +#include /* service side authenticator */ + +/* Portmapper client, server, and protocol headers */ +#include +#include + +#ifndef _KERNEL +#include /* rpcbind interface functions */ +#endif + +#include + +__BEGIN_DECLS +extern int get_myaddress(struct sockaddr_in *); +extern int bindresvport(int, struct sockaddr_in *); +extern int registerrpc(int, int, int, char *(*)(char [UDPMSGSIZE]), + xdrproc_t, xdrproc_t); +extern int callrpc(const char *, int, int, int, xdrproc_t, void *, + xdrproc_t , void *); +extern int getrpcport(char *, int, int, int); + +char *taddr2uaddr(const struct netconfig *, const struct netbuf *); +struct netbuf *uaddr2taddr(const struct netconfig *, const char *); + +struct sockaddr; +extern int bindresvport_sa(int, struct sockaddr *); +__END_DECLS + +/* + * The following are not exported interfaces, they are for internal library + * and rpcbind use only. Do not use, they may change without notice. + */ +__BEGIN_DECLS +int __rpc_nconf2fd(const struct netconfig *); +int __rpc_nconf2sockinfo(const struct netconfig *, struct __rpc_sockinfo *); +int __rpc_fd2sockinfo(int, struct __rpc_sockinfo *); +u_int __rpc_get_t_size(int, int, int); +__END_DECLS + +#endif /* !_RPC_RPC_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpc_com.h b/lib/libc/include/any-freebsd-any/rpc/rpc_com.h new file mode 100644 index 000000000000..dd331e2601f6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpc_com.h @@ -0,0 +1,84 @@ +/* $NetBSD: rpc_com.h,v 1.3 2000/12/10 04:10:08 christos Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * rpc_com.h, Common definitions for both the server and client side. + * All for the topmost layer of rpc + * + */ + +#ifndef _RPC_RPCCOM_H +#define _RPC_RPCCOM_H + +#include + +/* #pragma ident "@(#)rpc_com.h 1.11 93/07/05 SMI" */ + +/* + * The max size of the transport, if the size cannot be determined + * by other means. + */ +#define RPC_MAXDATASIZE 9000 +#define RPC_MAXADDRSIZE 1024 + +#define __RPC_GETXID(now) ((u_int32_t)getpid() ^ (u_int32_t)(now)->tv_sec ^ \ + (u_int32_t)(now)->tv_usec) + +__BEGIN_DECLS +extern u_int __rpc_get_a_size(int); +extern int __rpc_dtbsize(void); +extern int _rpc_dtablesize(void); +extern struct netconfig * __rpcgettp(int); +extern int __rpc_get_default_domain(char **); + +char *__rpc_taddr2uaddr_af(int, const struct netbuf *); +struct netbuf *__rpc_uaddr2taddr_af(int, const char *); +int __rpc_fixup_addr(struct netbuf *, const struct netbuf *); +int __rpc_sockinfo2netid(struct __rpc_sockinfo *, const char **); +int __rpc_seman2socktype(int); +int __rpc_socktype2seman(int); +void *rpc_nullproc(CLIENT *); +int __rpc_sockisbound(int); + +struct netbuf *__rpcb_findaddr(rpcprog_t, rpcvers_t, const struct netconfig *, + const char *, CLIENT **); +bool_t rpc_control(int,void *); + +char *_get_next_token(char *, int); + +__END_DECLS + +#endif /* _RPC_RPCCOM_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpc_msg.h b/lib/libc/include/any-freebsd-any/rpc/rpc_msg.h new file mode 100644 index 000000000000..136b617f58e8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpc_msg.h @@ -0,0 +1,215 @@ +/* $NetBSD: rpc_msg.h,v 1.11 2000/06/02 22:57:56 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)rpc_msg.h 1.7 86/07/16 SMI + * from: @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * rpc_msg.h + * rpc message definition + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +#ifndef _RPC_RPC_MSG_H +#define _RPC_RPC_MSG_H + +#define RPC_MSG_VERSION ((u_int32_t) 2) +#define RPC_SERVICE_PORT ((u_short) 2048) + +/* + * Bottom up definition of an rpc message. + * NOTE: call and reply use the same overall stuct but + * different parts of unions within it. + */ + +enum msg_type { + CALL=0, + REPLY=1 +}; + +enum reply_stat { + MSG_ACCEPTED=0, + MSG_DENIED=1 +}; + +enum accept_stat { + SUCCESS=0, + PROG_UNAVAIL=1, + PROG_MISMATCH=2, + PROC_UNAVAIL=3, + GARBAGE_ARGS=4, + SYSTEM_ERR=5 +}; + +enum reject_stat { + RPC_MISMATCH=0, + AUTH_ERROR=1 +}; + +/* + * Reply part of an rpc exchange + */ + +/* + * Reply to an rpc request that was accepted by the server. + * Note: there could be an error even though the request was + * accepted. + */ +struct accepted_reply { + struct opaque_auth ar_verf; + enum accept_stat ar_stat; + union { + struct { + rpcvers_t low; + rpcvers_t high; + } AR_versions; + struct { + caddr_t where; + xdrproc_t proc; + } AR_results; + /* and many other null cases */ + } ru; +#define ar_results ru.AR_results +#define ar_vers ru.AR_versions +}; + +/* + * Reply to an rpc request that was rejected by the server. + */ +struct rejected_reply { + enum reject_stat rj_stat; + union { + struct { + rpcvers_t low; + rpcvers_t high; + } RJ_versions; + enum auth_stat RJ_why; /* why authentication did not work */ + } ru; +#define rj_vers ru.RJ_versions +#define rj_why ru.RJ_why +}; + +/* + * Body of a reply to an rpc request. + */ +struct reply_body { + enum reply_stat rp_stat; + union { + struct accepted_reply RP_ar; + struct rejected_reply RP_dr; + } ru; +#define rp_acpt ru.RP_ar +#define rp_rjct ru.RP_dr +}; + +/* + * Body of an rpc request call. + */ +struct call_body { + rpcvers_t cb_rpcvers; /* must be equal to two */ + rpcprog_t cb_prog; + rpcvers_t cb_vers; + rpcproc_t cb_proc; + struct opaque_auth cb_cred; + struct opaque_auth cb_verf; /* protocol specific - provided by client */ +}; + +/* + * The rpc message + */ +struct rpc_msg { + u_int32_t rm_xid; + enum msg_type rm_direction; + union { + struct call_body RM_cmb; + struct reply_body RM_rmb; + } ru; +#define rm_call ru.RM_cmb +#define rm_reply ru.RM_rmb +}; +#define acpted_rply ru.RM_rmb.ru.RP_ar +#define rjcted_rply ru.RM_rmb.ru.RP_dr + +__BEGIN_DECLS +/* + * XDR routine to handle a rpc message. + * xdr_callmsg(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callmsg(XDR *, struct rpc_msg *); + +/* + * XDR routine to pre-serialize the static part of a rpc message. + * xdr_callhdr(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callhdr(XDR *, struct rpc_msg *); + +/* + * XDR routine to handle a rpc reply. + * xdr_replymsg(xdrs, rmsg) + * XDR *xdrs; + * struct rpc_msg *rmsg; + */ +extern bool_t xdr_replymsg(XDR *, struct rpc_msg *); + + +/* + * XDR routine to handle an accepted rpc reply. + * xdr_accepted_reply(xdrs, rej) + * XDR *xdrs; + * struct accepted_reply *rej; + */ +extern bool_t xdr_accepted_reply(XDR *, struct accepted_reply *); + +/* + * XDR routine to handle a rejected rpc reply. + * xdr_rejected_reply(xdrs, rej) + * XDR *xdrs; + * struct rejected_reply *rej; + */ +extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *); + +/* + * Fills in the error part of a reply message. + * _seterr_reply(msg, error) + * struct rpc_msg *msg; + * struct rpc_err *error; + */ +extern void _seterr_reply(struct rpc_msg *, struct rpc_err *); +__END_DECLS + +#endif /* !_RPC_RPC_MSG_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpcb_clnt.h b/lib/libc/include/any-freebsd-any/rpc/rpcb_clnt.h new file mode 100644 index 000000000000..b642aacd6a57 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpcb_clnt.h @@ -0,0 +1,86 @@ +/* $NetBSD: rpcb_clnt.h,v 1.1 2000/06/02 22:57:56 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * rpcb_clnt.h + * Supplies C routines to get to rpcbid services. + * + */ + +/* + * Usage: + * success = rpcb_set(program, version, nconf, address); + * success = rpcb_unset(program, version, nconf); + * success = rpcb_getaddr(program, version, nconf, host); + * head = rpcb_getmaps(nconf, host); + * clnt_stat = rpcb_rmtcall(nconf, host, program, version, procedure, + * xdrargs, argsp, xdrres, resp, tout, addr_ptr) + * success = rpcb_gettime(host, timep) + * uaddr = rpcb_taddr2uaddr(nconf, taddr); + * taddr = rpcb_uaddr2uaddr(nconf, uaddr); + */ + +#ifndef _RPC_RPCB_CLNT_H +#define _RPC_RPCB_CLNT_H + +/* #pragma ident "@(#)rpcb_clnt.h 1.13 94/04/25 SMI" */ +/* rpcb_clnt.h 1.3 88/12/05 SMI */ + +#include +#include + +__BEGIN_DECLS +extern bool_t rpcb_set(const rpcprog_t, const rpcvers_t, + const struct netconfig *, const struct netbuf *); +extern bool_t rpcb_unset(const rpcprog_t, const rpcvers_t, + const struct netconfig *); +extern rpcblist *rpcb_getmaps(const struct netconfig *, const char *); +extern enum clnt_stat rpcb_rmtcall(const struct netconfig *, + const char *, const rpcprog_t, + const rpcvers_t, const rpcproc_t, + const xdrproc_t, const caddr_t, + const xdrproc_t, const caddr_t, + const struct timeval, + const struct netbuf *); +extern bool_t rpcb_getaddr(const rpcprog_t, const rpcvers_t, + const struct netconfig *, struct netbuf *, + const char *); +extern bool_t rpcb_gettime(const char *, time_t *); +extern char *rpcb_taddr2uaddr(struct netconfig *, struct netbuf *); +extern struct netbuf *rpcb_uaddr2taddr(struct netconfig *, char *); +__END_DECLS + +#endif /* !_RPC_RPCB_CLNT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpcb_prot.x b/lib/libc/include/any-freebsd-any/rpc/rpcb_prot.x new file mode 100644 index 000000000000..a34bcc12502a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpcb_prot.x @@ -0,0 +1,553 @@ +%/*- +% * $FreeBSD$ +% * +% * Copyright (c) 2009, Sun Microsystems, Inc. +% * All rights reserved. +% * +% * Redistribution and use in source and binary forms, with or without +% * modification, are permitted provided that the following conditions are met: +% * - Redistributions of source code must retain the above copyright notice, +% * this list of conditions and the following disclaimer. +% * - Redistributions in binary form must reproduce the above copyright notice, +% * this list of conditions and the following disclaimer in the documentation +% * and/or other materials provided with the distribution. +% * - Neither the name of Sun Microsystems, Inc. nor the names of its +% * contributors may be used to endorse or promote products derived +% * from this software without specific prior written permission. +% * +% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +% * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +% * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +% * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +% * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +% * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +% * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +% * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +% * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% * POSSIBILITY OF SUCH DAMAGE. +% */ +%/* +% * Copyright (c) 1988 by Sun Microsystems, Inc. +% */ + +%/* from rpcb_prot.x */ + +#ifdef RPC_HDR +% +%/* #pragma ident "@(#)rpcb_prot.x 1.5 94/04/29 SMI" */ +% +%#ifndef _KERNEL +% +#endif + +/* + * rpcb_prot.x + * rpcbind protocol, versions 3 and 4, in RPC Language + */ +% +%/* +% * The following procedures are supported by the protocol in version 3: +% * +% * RPCBPROC_NULL() returns () +% * takes nothing, returns nothing +% * +% * RPCBPROC_SET(rpcb) returns (bool_t) +% * TRUE is success, FALSE is failure. Registers the tuple +% * [prog, vers, address, owner, netid]. +% * Finds out owner and netid information on its own. +% * +% * RPCBPROC_UNSET(rpcb) returns (bool_t) +% * TRUE is success, FALSE is failure. Un-registers tuple +% * [prog, vers, netid]. addresses is ignored. +% * If netid is NULL, unregister all. +% * +% * RPCBPROC_GETADDR(rpcb) returns (string). +% * 0 is failure. Otherwise returns the universal address where the +% * triple [prog, vers, netid] is registered. Ignore address and owner. +% * +% * RPCBPROC_DUMP() RETURNS (rpcblist_ptr) +% * used to dump the entire rpcbind maps +% * +% * RPCBPROC_CALLIT(rpcb_rmtcallargs) +% * RETURNS (rpcb_rmtcallres); +% * Calls the procedure on the remote machine. If it is not registered, +% * this procedure is quiet; i.e. it does not return error information!!! +% * This routine only passes null authentication parameters. +% * It has no interface to xdr routines for RPCBPROC_CALLIT. +% * +% * RPCBPROC_GETTIME() returns (int). +% * Gets the remote machines time +% * +% * RPCBPROC_UADDR2TADDR(strint) RETURNS (struct netbuf) +% * Returns the netbuf address from universal address. +% * +% * RPCBPROC_TADDR2UADDR(struct netbuf) RETURNS (string) +% * Returns the universal address from netbuf address. +% * +% * END OF RPCBIND VERSION 3 PROCEDURES +% */ +%/* +% * Except for RPCBPROC_CALLIT, the procedures above are carried over to +% * rpcbind version 4. Those below are added or modified for version 4. +% * NOTE: RPCBPROC_BCAST HAS THE SAME FUNCTIONALITY AND PROCEDURE NUMBER +% * AS RPCBPROC_CALLIT. +% * +% * RPCBPROC_BCAST(rpcb_rmtcallargs) +% * RETURNS (rpcb_rmtcallres); +% * Calls the procedure on the remote machine. If it is not registered, +% * this procedure IS quiet; i.e. it DOES NOT return error information!!! +% * This routine should be used for broadcasting and nothing else. +% * +% * RPCBPROC_GETVERSADDR(rpcb) returns (string). +% * 0 is failure. Otherwise returns the universal address where the +% * triple [prog, vers, netid] is registered. Ignore address and owner. +% * Same as RPCBPROC_GETADDR except that if the given version number +% * is not available, the address is not returned. +% * +% * RPCBPROC_INDIRECT(rpcb_rmtcallargs) +% * RETURNS (rpcb_rmtcallres); +% * Calls the procedure on the remote machine. If it is not registered, +% * this procedure is NOT quiet; i.e. it DOES return error information!!! +% * as any normal application would expect. +% * +% * RPCBPROC_GETADDRLIST(rpcb) returns (rpcb_entry_list_ptr). +% * Same as RPCBPROC_GETADDR except that it returns a list of all the +% * addresses registered for the combination (prog, vers) (for all +% * transports). +% * +% * RPCBPROC_GETSTAT(void) returns (rpcb_stat_byvers) +% * Returns the statistics about the kind of requests received by rpcbind. +% */ +% +%/* +% * A mapping of (program, version, network ID) to address +% */ +struct rpcb { + rpcprog_t r_prog; /* program number */ + rpcvers_t r_vers; /* version number */ + string r_netid<>; /* network id */ + string r_addr<>; /* universal address */ + string r_owner<>; /* owner of this service */ +}; +#ifdef RPC_HDR +% +%typedef rpcb RPCB; +% +#endif +% +%/* +% * A list of mappings +% * +% * Below are two definitions for the rpcblist structure. This is done because +% * xdr_rpcblist() is specified to take a struct rpcblist **, rather than a +% * struct rpcblist * that rpcgen would produce. One version of the rpcblist +% * structure (actually called rp__list) is used with rpcgen, and the other is +% * defined only in the header file for compatibility with the specified +% * interface. +% */ + +struct rp__list { + rpcb rpcb_map; + struct rp__list *rpcb_next; +}; + +typedef rp__list *rpcblist_ptr; /* results of RPCBPROC_DUMP */ + +#ifdef RPC_HDR +% +%typedef struct rp__list rpcblist; +%typedef struct rp__list RPCBLIST; +% +%#ifndef __cplusplus +%struct rpcblist { +% RPCB rpcb_map; +% struct rpcblist *rpcb_next; +%}; +%#endif +% +%#ifdef __cplusplus +%extern "C" { +%#endif +%extern bool_t xdr_rpcblist(XDR *, rpcblist**); +%#ifdef __cplusplus +%} +%#endif +% +#endif + +% +%/* +% * Arguments of remote calls +% */ +struct rpcb_rmtcallargs { + rpcprog_t prog; /* program number */ + rpcvers_t vers; /* version number */ + rpcproc_t proc; /* procedure number */ + opaque args<>; /* argument */ +}; +#ifdef RPC_HDR +% +%/* +% * Client-side only representation of rpcb_rmtcallargs structure. +% * +% * The routine that XDRs the rpcb_rmtcallargs structure must deal with the +% * opaque arguments in the "args" structure. xdr_rpcb_rmtcallargs() needs to +% * be passed the XDR routine that knows the args' structure. This routine +% * doesn't need to go over-the-wire (and it wouldn't make sense anyway) since +% * the application being called already knows the args structure. So we use a +% * different "XDR" structure on the client side, r_rpcb_rmtcallargs, which +% * includes the args' XDR routine. +% */ +%struct r_rpcb_rmtcallargs { +% rpcprog_t prog; +% rpcvers_t vers; +% rpcproc_t proc; +% struct { +% u_int args_len; +% char *args_val; +% } args; +% xdrproc_t xdr_args; /* encodes args */ +%}; +% +#endif /* def RPC_HDR */ +% +%/* +% * Results of the remote call +% */ +struct rpcb_rmtcallres { + string addr<>; /* remote universal address */ + opaque results<>; /* result */ +}; +#ifdef RPC_HDR +% +%/* +% * Client-side only representation of rpcb_rmtcallres structure. +% */ +%struct r_rpcb_rmtcallres { +% char *addr; +% struct { +% u_int32_t results_len; +% char *results_val; +% } results; +% xdrproc_t xdr_res; /* decodes results */ +%}; +#endif /* RPC_HDR */ +% +%/* +% * rpcb_entry contains a merged address of a service on a particular +% * transport, plus associated netconfig information. A list of rpcb_entrys +% * is returned by RPCBPROC_GETADDRLIST. See netconfig.h for values used +% * in r_nc_* fields. +% */ +struct rpcb_entry { + string r_maddr<>; /* merged address of service */ + string r_nc_netid<>; /* netid field */ + unsigned int r_nc_semantics; /* semantics of transport */ + string r_nc_protofmly<>; /* protocol family */ + string r_nc_proto<>; /* protocol name */ +}; +% +%/* +% * A list of addresses supported by a service. +% */ +struct rpcb_entry_list { + rpcb_entry rpcb_entry_map; + struct rpcb_entry_list *rpcb_entry_next; +}; + +typedef rpcb_entry_list *rpcb_entry_list_ptr; + +% +%/* +% * rpcbind statistics +% */ +% +const rpcb_highproc_2 = RPCBPROC_CALLIT; +const rpcb_highproc_3 = RPCBPROC_TADDR2UADDR; +const rpcb_highproc_4 = RPCBPROC_GETSTAT; + +const RPCBSTAT_HIGHPROC = 13; /* # of procs in rpcbind V4 plus one */ +const RPCBVERS_STAT = 3; /* provide only for rpcbind V2, V3 and V4 */ +const RPCBVERS_4_STAT = 2; +const RPCBVERS_3_STAT = 1; +const RPCBVERS_2_STAT = 0; +% +%/* Link list of all the stats about getport and getaddr */ +struct rpcbs_addrlist { + rpcprog_t prog; + rpcvers_t vers; + int success; + int failure; + string netid<>; + struct rpcbs_addrlist *next; +}; +% +%/* Link list of all the stats about rmtcall */ +struct rpcbs_rmtcalllist { + rpcprog_t prog; + rpcvers_t vers; + rpcproc_t proc; + int success; + int failure; + int indirect; /* whether callit or indirect */ + string netid<>; + struct rpcbs_rmtcalllist *next; +}; + +typedef int rpcbs_proc[RPCBSTAT_HIGHPROC]; +typedef rpcbs_addrlist *rpcbs_addrlist_ptr; +typedef rpcbs_rmtcalllist *rpcbs_rmtcalllist_ptr; + +struct rpcb_stat { + rpcbs_proc info; + int setinfo; + int unsetinfo; + rpcbs_addrlist_ptr addrinfo; + rpcbs_rmtcalllist_ptr rmtinfo; +}; +% +%/* +% * One rpcb_stat structure is returned for each version of rpcbind +% * being monitored. +% */ + +typedef rpcb_stat rpcb_stat_byvers[RPCBVERS_STAT]; + +#ifdef RPC_HDR +% +%/* +% * We don't define netbuf in RPCL, since it would contain structure member +% * names that would conflict with the definition of struct netbuf in +% * . Instead we merely declare the XDR routine xdr_netbuf() here, +% * and implement it ourselves in rpc/rpcb_prot.c. +% */ +%#ifdef __cplusplus +%extern "C" bool_t xdr_netbuf(XDR *, struct netbuf *); +% +%#else /* __STDC__ */ +%extern bool_t xdr_netbuf(XDR *, struct netbuf *); +% +%#endif +#endif /* def RPC_HDR */ + +/* + * rpcbind procedures + */ +program RPCBPROG { + version RPCBVERS { + bool + RPCBPROC_SET(rpcb) = 1; + + bool + RPCBPROC_UNSET(rpcb) = 2; + + string + RPCBPROC_GETADDR(rpcb) = 3; + + rpcblist_ptr + RPCBPROC_DUMP(void) = 4; + + rpcb_rmtcallres + RPCBPROC_CALLIT(rpcb_rmtcallargs) = 5; + + unsigned int + RPCBPROC_GETTIME(void) = 6; + + struct netbuf + RPCBPROC_UADDR2TADDR(string) = 7; + + string + RPCBPROC_TADDR2UADDR(struct netbuf) = 8; + } = 3; + + version RPCBVERS4 { + bool + RPCBPROC_SET(rpcb) = 1; + + bool + RPCBPROC_UNSET(rpcb) = 2; + + string + RPCBPROC_GETADDR(rpcb) = 3; + + rpcblist_ptr + RPCBPROC_DUMP(void) = 4; + + /* + * NOTE: RPCBPROC_BCAST has the same functionality as CALLIT; + * the new name is intended to indicate that this + * procedure should be used for broadcast RPC, and + * RPCBPROC_INDIRECT should be used for indirect calls. + */ + rpcb_rmtcallres + RPCBPROC_BCAST(rpcb_rmtcallargs) = RPCBPROC_CALLIT; + + unsigned int + RPCBPROC_GETTIME(void) = 6; + + struct netbuf + RPCBPROC_UADDR2TADDR(string) = 7; + + string + RPCBPROC_TADDR2UADDR(struct netbuf) = 8; + + string + RPCBPROC_GETVERSADDR(rpcb) = 9; + + rpcb_rmtcallres + RPCBPROC_INDIRECT(rpcb_rmtcallargs) = 10; + + rpcb_entry_list_ptr + RPCBPROC_GETADDRLIST(rpcb) = 11; + + rpcb_stat_byvers + RPCBPROC_GETSTAT(void) = 12; + } = 4; +} = 100000; +#ifdef RPC_HDR +% +%#define RPCBVERS_3 RPCBVERS +%#define RPCBVERS_4 RPCBVERS4 +% +%#define _PATH_RPCBINDSOCK "/var/run/rpcbind.sock" +% +%#else /* ndef _KERNEL */ +%#ifdef __cplusplus +%extern "C" { +%#endif +% +%/* +% * A mapping of (program, version, network ID) to address +% */ +%struct rpcb { +% rpcprog_t r_prog; /* program number */ +% rpcvers_t r_vers; /* version number */ +% char *r_netid; /* network id */ +% char *r_addr; /* universal address */ +% char *r_owner; /* owner of the mapping */ +%}; +%typedef struct rpcb RPCB; +% +%/* +% * A list of mappings +% */ +%struct rpcblist { +% RPCB rpcb_map; +% struct rpcblist *rpcb_next; +%}; +%typedef struct rpcblist RPCBLIST; +%typedef struct rpcblist *rpcblist_ptr; +% +%/* +% * Remote calls arguments +% */ +%struct rpcb_rmtcallargs { +% rpcprog_t prog; /* program number */ +% rpcvers_t vers; /* version number */ +% rpcproc_t proc; /* procedure number */ +% u_int32_t arglen; /* arg len */ +% caddr_t args_ptr; /* argument */ +% xdrproc_t xdr_args; /* XDR routine for argument */ +%}; +%typedef struct rpcb_rmtcallargs rpcb_rmtcallargs; +% +%/* +% * Remote calls results +% */ +%struct rpcb_rmtcallres { +% char *addr_ptr; /* remote universal address */ +% u_int32_t resultslen; /* results length */ +% caddr_t results_ptr; /* results */ +% xdrproc_t xdr_results; /* XDR routine for result */ +%}; +%typedef struct rpcb_rmtcallres rpcb_rmtcallres; +% +%struct rpcb_entry { +% char *r_maddr; +% char *r_nc_netid; +% unsigned int r_nc_semantics; +% char *r_nc_protofmly; +% char *r_nc_proto; +%}; +%typedef struct rpcb_entry rpcb_entry; +% +%/* +% * A list of addresses supported by a service. +% */ +% +%struct rpcb_entry_list { +% rpcb_entry rpcb_entry_map; +% struct rpcb_entry_list *rpcb_entry_next; +%}; +%typedef struct rpcb_entry_list rpcb_entry_list; +% +%typedef rpcb_entry_list *rpcb_entry_list_ptr; +% +%/* +% * rpcbind statistics +% */ +% +%#define rpcb_highproc_2 RPCBPROC_CALLIT +%#define rpcb_highproc_3 RPCBPROC_TADDR2UADDR +%#define rpcb_highproc_4 RPCBPROC_GETSTAT +%#define RPCBSTAT_HIGHPROC 13 +%#define RPCBVERS_STAT 3 +%#define RPCBVERS_4_STAT 2 +%#define RPCBVERS_3_STAT 1 +%#define RPCBVERS_2_STAT 0 +% +%/* Link list of all the stats about getport and getaddr */ +% +%struct rpcbs_addrlist { +% rpcprog_t prog; +% rpcvers_t vers; +% int success; +% int failure; +% char *netid; +% struct rpcbs_addrlist *next; +%}; +%typedef struct rpcbs_addrlist rpcbs_addrlist; +% +%/* Link list of all the stats about rmtcall */ +% +%struct rpcbs_rmtcalllist { +% rpcprog_t prog; +% rpcvers_t vers; +% rpcproc_t proc; +% int success; +% int failure; +% int indirect; +% char *netid; +% struct rpcbs_rmtcalllist *next; +%}; +%typedef struct rpcbs_rmtcalllist rpcbs_rmtcalllist; +% +%typedef int rpcbs_proc[RPCBSTAT_HIGHPROC]; +% +%typedef rpcbs_addrlist *rpcbs_addrlist_ptr; +% +%typedef rpcbs_rmtcalllist *rpcbs_rmtcalllist_ptr; +% +%struct rpcb_stat { +% rpcbs_proc info; +% int setinfo; +% int unsetinfo; +% rpcbs_addrlist_ptr addrinfo; +% rpcbs_rmtcalllist_ptr rmtinfo; +%}; +%typedef struct rpcb_stat rpcb_stat; +% +%/* +% * One rpcb_stat structure is returned for each version of rpcbind +% * being monitored. +% */ +% +%typedef rpcb_stat rpcb_stat_byvers[RPCBVERS_STAT]; +% +%#ifdef __cplusplus +%} +%#endif +% +%#endif /* ndef _KERNEL */ +#endif /* RPC_HDR */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpcent.h b/lib/libc/include/any-freebsd-any/rpc/rpcent.h new file mode 100644 index 000000000000..15c4ae4d00a6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpcent.h @@ -0,0 +1,68 @@ +/* $NetBSD: rpcent.h,v 1.1 2000/06/02 22:57:56 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * rpcent.h, + * For converting rpc program numbers to names etc. + * + */ + +#ifndef _RPC_RPCENT_H +#define _RPC_RPCENT_H + +/* #pragma ident "@(#)rpcent.h 1.13 94/04/25 SMI" */ +/* @(#)rpcent.h 1.1 88/12/06 SMI */ + + +struct rpcent { + char *r_name; /* name of server for this rpc program */ + char **r_aliases; /* alias list */ + int r_number; /* rpc program number */ +}; + +__BEGIN_DECLS +/* + * These interfaces are currently implemented through nsswitch and are + * MT-safe. + */ +extern struct rpcent *getrpcbyname(const char *); +extern struct rpcent *getrpcbynumber(int); +extern struct rpcent *getrpcent(void); +extern void setrpcent(int); +extern void endrpcent(void); +__END_DECLS + +#endif /* !_RPC_CENT_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/rpcsec_gss.h b/lib/libc/include/any-freebsd-any/rpc/rpcsec_gss.h new file mode 100644 index 000000000000..2878ae04b70d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/rpcsec_gss.h @@ -0,0 +1,181 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _RPCSEC_GSS_H +#define _RPCSEC_GSS_H + +#include + +#ifndef MAX_GSS_MECH +#define MAX_GSS_MECH 64 +#endif + +/* + * Define the types of security service required for rpc_gss_seccreate(). + */ +typedef enum { + rpc_gss_svc_default = 0, + rpc_gss_svc_none = 1, + rpc_gss_svc_integrity = 2, + rpc_gss_svc_privacy = 3 +} rpc_gss_service_t; + +/* + * Structure containing options for rpc_gss_seccreate(). + */ +typedef struct { + int req_flags; /* GSS request bits */ + int time_req; /* requested credential lifetime */ + gss_cred_id_t my_cred; /* GSS credential */ + gss_channel_bindings_t input_channel_bindings; +} rpc_gss_options_req_t; + +/* + * Structure containing options returned by rpc_gss_seccreate(). + */ +typedef struct { + int major_status; + int minor_status; + u_int rpcsec_version; + int ret_flags; + int time_req; + gss_ctx_id_t gss_context; + char actual_mechanism[MAX_GSS_MECH]; +} rpc_gss_options_ret_t; + +/* + * Client principal type. Used as an argument to + * rpc_gss_get_principal_name(). Also referenced by the + * rpc_gss_rawcred_t structure. + */ +typedef struct { + int len; + char name[1]; +} *rpc_gss_principal_t; + +/* + * Structure for raw credentials used by rpc_gss_getcred() and + * rpc_gss_set_callback(). + */ +typedef struct { + u_int version; /* RPC version number */ + const char *mechanism; /* security mechanism */ + const char *qop; /* quality of protection */ + rpc_gss_principal_t client_principal; /* client name */ + const char *svc_principal; /* server name */ + rpc_gss_service_t service; /* service type */ +} rpc_gss_rawcred_t; + +/* + * Unix credentials derived from raw credentials. Returned by + * rpc_gss_getcred(). + */ +typedef struct { + uid_t uid; /* user ID */ + gid_t gid; /* group ID */ + short gidlen; + gid_t *gidlist; /* list of groups */ +} rpc_gss_ucred_t; + +/* + * Structure used to enforce a particular QOP and service. + */ +typedef struct { + bool_t locked; + rpc_gss_rawcred_t *raw_cred; +} rpc_gss_lock_t; + +/* + * Callback structure used by rpc_gss_set_callback(). + */ +typedef struct { + u_int program; /* RPC program number */ + u_int version; /* RPC version number */ + /* user defined callback */ + bool_t (*callback)(struct svc_req *req, + gss_cred_id_t deleg, + gss_ctx_id_t gss_context, + rpc_gss_lock_t *lock, + void **cookie); +} rpc_gss_callback_t; + +/* + * Structure used to return error information by rpc_gss_get_error() + */ +typedef struct { + int rpc_gss_error; + int system_error; /* same as errno */ +} rpc_gss_error_t; + +/* + * Values for rpc_gss_error + */ +#define RPC_GSS_ER_SUCCESS 0 /* no error */ +#define RPC_GSS_ER_SYSTEMERROR 1 /* system error */ + +__BEGIN_DECLS + +AUTH *rpc_gss_seccreate(CLIENT *clnt, const char *principal, + const char *mechanism, rpc_gss_service_t service, const char *qop, + rpc_gss_options_req_t *options_req, rpc_gss_options_ret_t *options_ret); +bool_t rpc_gss_set_defaults(AUTH *auth, rpc_gss_service_t service, + const char *qop); +int rpc_gss_max_data_length(AUTH *handle, int max_tp_unit_len); +void rpc_gss_get_error(rpc_gss_error_t *error); + +bool_t rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret); +bool_t rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret); +bool_t rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret); +const char **rpc_gss_get_mechanisms(void); +const char **rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service); +bool_t rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo); +bool_t rpc_gss_is_installed(const char *mech); + +bool_t rpc_gss_set_svc_name(const char *principal, const char *mechanism, + u_int req_time, u_int program, u_int version); +bool_t rpc_gss_getcred(struct svc_req *req, rpc_gss_rawcred_t **rcred, + rpc_gss_ucred_t **ucred, void **cookie); +bool_t rpc_gss_set_callback(rpc_gss_callback_t *cb); +bool_t rpc_gss_get_principal_name(rpc_gss_principal_t *principal, + const char *mech, const char *name, const char *node, const char *domain); +int rpc_gss_svc_max_data_length(struct svc_req *req, int max_tp_unit_len); + +/* + * Internal interface from the RPC implementation. + */ +bool_t __rpc_gss_wrap(AUTH *auth, void *header, size_t headerlen, + XDR* xdrs, xdrproc_t xdr_args, void *args_ptr); +bool_t __rpc_gss_unwrap(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args, + void *args_ptr); +bool_t __rpc_gss_set_error(int rpc_gss_error, int system_error); + +__END_DECLS + +#endif /* !_RPCSEC_GSS_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/svc.h b/lib/libc/include/any-freebsd-any/rpc/svc.h new file mode 100644 index 000000000000..912d26ba4461 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/svc.h @@ -0,0 +1,476 @@ +/* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)svc.h 1.35 88/12/17 SMI + * from: @(#)svc.h 1.27 94/04/25 SMI + * $FreeBSD$ + */ + +/* + * svc.h, Server-side remote procedure call interface. + * + * Copyright (C) 1986-1993 by Sun Microsystems, Inc. + */ + +#ifndef _RPC_SVC_H +#define _RPC_SVC_H +#include + +/* + * This interface must manage two items concerning remote procedure calling: + * + * 1) An arbitrary number of transport connections upon which rpc requests + * are received. The two most notable transports are TCP and UDP; they are + * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; + * they in turn call xprt_register and xprt_unregister. + * + * 2) An arbitrary number of locally registered services. Services are + * described by the following four data: program number, version number, + * "service dispatch" function, a transport handle, and a boolean that + * indicates whether or not the exported program should be registered with a + * local binder service; if true the program's number and version and the + * port number from the transport handle are registered with the binder. + * These data are registered with the rpc svc system via svc_register. + * + * A service's dispatch function is called whenever an rpc request comes in + * on a transport. The request's program and version numbers must match + * those of the registered service. The dispatch function is passed two + * parameters, struct svc_req * and SVCXPRT *, defined below. + */ + +/* + * Service control requests + */ +#define SVCGET_VERSQUIET 1 +#define SVCSET_VERSQUIET 2 +#define SVCGET_CONNMAXREC 3 +#define SVCSET_CONNMAXREC 4 + +/* + * Operations for rpc_control(). + */ +#define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */ +#define RPC_SVC_CONNMAXREC_GET 1 + +enum xprt_stat { + XPRT_DIED, + XPRT_MOREREQS, + XPRT_IDLE +}; + +/* + * Server side transport handle + */ +typedef struct __rpc_svcxprt { + int xp_fd; +#define xp_sock xp_fd + u_short xp_port; /* associated port number */ + const struct xp_ops { + /* receive incoming requests */ + bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *); + /* get transport status */ + enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *); + /* get arguments */ + bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, + void *); + /* send reply */ + bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *); + /* free mem allocated for args */ + bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, + void *); + /* destroy this struct */ + void (*xp_destroy)(struct __rpc_svcxprt *); + } *xp_ops; + int xp_addrlen; /* length of remote address */ + struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */ + /* XXX - fvdl stick this here for ABI backward compat reasons */ + const struct xp_ops2 { + /* catch-all function */ + bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, + void *); + } *xp_ops2; + char *xp_tp; /* transport provider device name */ + char *xp_netid; /* network token */ + struct netbuf xp_ltaddr; /* local transport address */ + struct netbuf xp_rtaddr; /* remote transport address */ + struct opaque_auth xp_verf; /* raw response verifier */ + void *xp_p1; /* private: for use by svc ops */ + void *xp_p2; /* private: for use by svc ops */ + void *xp_p3; /* private: for use by svc lib */ + int xp_type; /* transport type */ +} SVCXPRT; + +/* + * Interface to server-side authentication flavors. + */ +typedef struct __rpc_svcauth { + struct svc_auth_ops { + int (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *, + xdrproc_t, caddr_t); + int (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *, + xdrproc_t, caddr_t); + } *svc_ah_ops; + void *svc_ah_private; +} SVCAUTH; + +/* + * Server transport extensions (accessed via xp_p3). + */ +typedef struct __rpc_svcxprt_ext { + int xp_flags; /* versquiet */ + SVCAUTH xp_auth; /* interface to auth methods */ +} SVCXPRT_EXT; + +/* + * Service request + */ +struct svc_req { + u_int32_t rq_prog; /* service program number */ + u_int32_t rq_vers; /* service protocol version */ + u_int32_t rq_proc; /* the desired procedure */ + struct opaque_auth rq_cred; /* raw creds from the wire */ + void *rq_clntcred; /* read only cooked cred */ + SVCXPRT *rq_xprt; /* associated transport */ +}; + +/* + * Approved way of getting address of caller + */ +#define svc_getrpccaller(x) (&(x)->xp_rtaddr) + +/* + * Operations defined on an SVCXPRT handle + * + * SVCXPRT *xprt; + * struct rpc_msg *msg; + * xdrproc_t xargs; + * void * argsp; + */ +#define SVC_RECV(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) +#define svc_recv(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) + +#define SVC_STAT(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) +#define svc_stat(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) + +#define SVC_GETARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) +#define svc_getargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) + +#define SVC_REPLY(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) +#define svc_reply(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) + +#define SVC_FREEARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) +#define svc_freeargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) + +#define SVC_DESTROY(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) +#define svc_destroy(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) + +#define SVC_CONTROL(xprt, rq, in) \ + (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in)) + +#define SVC_EXT(xprt) \ + ((SVCXPRT_EXT *) xprt->xp_p3) + +#define SVC_AUTH(xprt) \ + (SVC_EXT(xprt)->xp_auth) + +/* + * Operations defined on an SVCAUTH handle + */ +#define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \ + ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere)) +#define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \ + ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere)) + +/* + * Service registration + * + * svc_reg(xprt, prog, vers, dispatch, nconf) + * const SVCXPRT *xprt; + * const rpcprog_t prog; + * const rpcvers_t vers; + * const void (*dispatch)(struct svc_req *, SVCXPRT *); + * const struct netconfig *nconf; + */ + +__BEGIN_DECLS +extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t, + void (*)(struct svc_req *, SVCXPRT *), + const struct netconfig *); +__END_DECLS + +/* + * Service un-registration + * + * svc_unreg(prog, vers) + * const rpcprog_t prog; + * const rpcvers_t vers; + */ + +__BEGIN_DECLS +extern void svc_unreg(const rpcprog_t, const rpcvers_t); +__END_DECLS + +/* + * Transport registration. + * + * xprt_register(xprt) + * SVCXPRT *xprt; + */ +__BEGIN_DECLS +extern void xprt_register(SVCXPRT *); +__END_DECLS + +/* + * Transport un-register + * + * xprt_unregister(xprt) + * SVCXPRT *xprt; + */ +__BEGIN_DECLS +extern void xprt_unregister(SVCXPRT *); +__END_DECLS + + +/* + * When the service routine is called, it must first check to see if it + * knows about the procedure; if not, it should call svcerr_noproc + * and return. If so, it should deserialize its arguments via + * SVC_GETARGS (defined above). If the deserialization does not work, + * svcerr_decode should be called followed by a return. Successful + * decoding of the arguments should be followed the execution of the + * procedure's code and a call to svc_sendreply. + * + * Also, if the service refuses to execute the procedure due to too- + * weak authentication parameters, svcerr_weakauth should be called. + * Note: do not confuse access-control failure with weak authentication! + * + * NB: In pure implementations of rpc, the caller always waits for a reply + * msg. This message is sent when svc_sendreply is called. + * Therefore pure service implementations should always call + * svc_sendreply even if the function logically returns void; use + * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows + * for the abuse of pure rpc via batched calling or pipelining. In the + * case of a batched call, svc_sendreply should NOT be called since + * this would send a return message, which is what batching tries to avoid. + * It is the service/protocol writer's responsibility to know which calls are + * batched and which are not. Warning: responding to batch calls may + * deadlock the caller and server processes! + */ + +__BEGIN_DECLS +extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *); +extern void svcerr_decode(SVCXPRT *); +extern void svcerr_weakauth(SVCXPRT *); +extern void svcerr_noproc(SVCXPRT *); +extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t); +extern void svcerr_auth(SVCXPRT *, enum auth_stat); +extern void svcerr_noprog(SVCXPRT *); +extern void svcerr_systemerr(SVCXPRT *); +extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t, + char *(*)(char *), xdrproc_t, xdrproc_t, + char *); +__END_DECLS + +/* + * Lowest level dispatching -OR- who owns this process anyway. + * Somebody has to wait for incoming requests and then call the correct + * service routine. The routine svc_run does infinite waiting; i.e., + * svc_run never returns. + * Since another (co-existent) package may wish to selectively wait for + * incoming calls or other events outside of the rpc architecture, the + * routine svc_getreq is provided. It must be passed readfds, the + * "in-place" results of a select system call (see select, section 2). + */ + +/* + * Global keeper of rpc service descriptors in use + * dynamic; must be inspected before each call to select + */ +extern int svc_maxfd; +#ifdef FD_SETSIZE +extern fd_set svc_fdset; +#define svc_fds svc_fdset.fds_bits[0] /* compatibility */ +#else +extern int svc_fds; +#endif /* def FD_SETSIZE */ + +/* + * A set of null auth methods used by any authentication protocols + * that don't need to inspect or modify the message body. + */ +extern SVCAUTH _svc_auth_null; + +/* + * a small program implemented by the svc_rpc implementation itself; + * also see clnt.h for protocol numbers. + */ +__BEGIN_DECLS +extern void rpctest_service(void); +__END_DECLS + +__BEGIN_DECLS +extern SVCXPRT *svc_xprt_alloc(void); +extern void svc_xprt_free(SVCXPRT *); +extern void svc_getreq(int); +extern void svc_getreqset(fd_set *); +extern void svc_getreq_common(int); +struct pollfd; +extern void svc_getreq_poll(struct pollfd *, int); + +extern void svc_run(void); +extern void svc_exit(void); +__END_DECLS + +/* + * Socket to use on svcxxx_create call to get default socket + */ +#define RPC_ANYSOCK -1 +#define RPC_ANYFD RPC_ANYSOCK + +/* + * These are the existing service side transport implementations + */ + +__BEGIN_DECLS +/* + * Transport independent svc_create routine. + */ +extern int svc_create(void (*)(struct svc_req *, SVCXPRT *), + const rpcprog_t, const rpcvers_t, const char *); +/* + * void (*dispatch)(struct svc_req *, SVCXPRT *); + * const rpcprog_t prognum; -- program number + * const rpcvers_t versnum; -- version number + * const char *nettype; -- network type + */ + + +/* + * Generic server creation routine. It takes a netconfig structure + * instead of a nettype. + */ + +extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *), + const rpcprog_t, const rpcvers_t, + const struct netconfig *); + /* + * void (*dispatch)(struct svc_req *, SVCXPRT *); + * const rpcprog_t prognum; -- program number + * const rpcvers_t versnum; -- version number + * const struct netconfig *nconf; -- netconfig structure + */ + + +/* + * Generic TLI create routine + */ +extern SVCXPRT *svc_tli_create(const int, const struct netconfig *, + const struct t_bind *, const u_int, + const u_int); +/* + * const int fd; -- connection end point + * const struct netconfig *nconf; -- netconfig structure for network + * const struct t_bind *bindaddr; -- local bind address + * const u_int sendsz; -- max sendsize + * const u_int recvsz; -- max recvsize + */ + +/* + * Connectionless and connectionful create routines + */ + +extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int); +/* + * const int fd; -- open connection end point + * const u_int sendsize; -- max send size + * const u_int recvsize; -- max recv size + */ + +/* + * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create(). + */ +extern SVCXPRT *svcunix_create(int, u_int, u_int, char *); + +extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int); + /* + * const int fd; -- open connection + * const u_int sendsize; -- max send size + * const u_int recvsize; -- max recv size + */ + + +/* + * the routine takes any *open* connection + * descriptor as its first input and is used for open connections. + */ +extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int); +/* + * const int fd; -- open connection end point + * const u_int sendsize; -- max send size + * const u_int recvsize; -- max recv size + */ + +/* + * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create(). + */ +extern SVCXPRT *svcunixfd_create(int, u_int, u_int); + +/* + * Memory based rpc (for speed check and testing) + */ +extern SVCXPRT *svc_raw_create(void); + +/* + * svc_dg_enable_cache() enables the cache on dg transports. + */ +int svc_dg_enablecache(SVCXPRT *, const u_int); + +int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid); + +__END_DECLS + + +/* for backward compatibility */ +#include + +#endif /* !_RPC_SVC_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/svc_auth.h b/lib/libc/include/any-freebsd-any/rpc/svc_auth.h new file mode 100644 index 000000000000..e9b6cd4be4f3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/svc_auth.h @@ -0,0 +1,58 @@ +/* $NetBSD: svc_auth.h,v 1.8 2000/06/02 22:57:57 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)svc_auth.h 1.6 86/07/16 SMI + * @(#)svc_auth.h 2.1 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * svc_auth.h, Service side of rpc authentication. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +#ifndef _RPC_SVC_AUTH_H +#define _RPC_SVC_AUTH_H + +/* + * Server side authenticator + */ +__BEGIN_DECLS +extern struct svc_auth_ops svc_auth_null_ops; + +extern enum auth_stat _authenticate(struct svc_req *, struct rpc_msg *); +extern int svc_auth_reg(int, enum auth_stat (*)(struct svc_req *, + struct rpc_msg *)); + +__END_DECLS + +#endif /* !_RPC_SVC_AUTH_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/svc_dg.h b/lib/libc/include/any-freebsd-any/rpc/svc_dg.h new file mode 100644 index 000000000000..d9f3012c4f06 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/svc_dg.h @@ -0,0 +1,52 @@ +/* $NetBSD: svc_dg.h,v 1.1 2000/06/02 23:11:16 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * XXX - this file exists only so that the rpcbind code can pull it in. + * This should go away. It should only be include by svc_dg.c and + * rpcb_svc_com.c in the rpcbind code. + */ + +/* + * kept in xprt->xp_p2 + */ +struct svc_dg_data { + /* XXX: optbuf should be the first field, used by ti_opts.c code */ + size_t su_iosz; /* size of send.recv buffer */ + u_int32_t su_xid; /* transaction id */ + XDR su_xdrs; /* XDR handle */ + char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */ + void *su_cache; /* cached data, NULL if none */ + struct netbuf su_srcaddr; /* dst address of last msg */ +}; + +#define __rpcb_get_dg_xidp(x) (&((struct svc_dg_data *)(x)->xp_p2)->su_xid) diff --git a/lib/libc/include/any-freebsd-any/rpc/svc_soc.h b/lib/libc/include/any-freebsd-any/rpc/svc_soc.h new file mode 100644 index 000000000000..912e2ec2df1f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/svc_soc.h @@ -0,0 +1,117 @@ +/* $NetBSD: svc_soc.h,v 1.1 2000/06/02 22:57:57 fvdl Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc. + */ + +/* + * svc.h, Server-side remote procedure call interface. + */ + +#ifndef _RPC_SVC_SOC_H +#define _RPC_SVC_SOC_H +#include + +/* #pragma ident "@(#)svc_soc.h 1.11 94/04/25 SMI" */ +/* svc_soc.h 1.8 89/05/01 SMI */ + +/* + * All the following declarations are only for backward compatibility + * with TS-RPC + */ + +/* + * Approved way of getting address of caller + */ +#define svc_getcaller(x) (&(x)->xp_raddr) + +/* + * Service registration + * + * svc_register(xprt, prog, vers, dispatch, protocol) + * SVCXPRT *xprt; + * u_long prog; + * u_long vers; + * void (*dispatch)(); + * int protocol; like TCP or UDP, zero means do not register + */ +__BEGIN_DECLS +extern bool_t svc_register(SVCXPRT *, u_long, u_long, + void (*)(struct svc_req *, SVCXPRT *), int); +__END_DECLS + +/* + * Service un-registration + * + * svc_unregister(prog, vers) + * u_long prog; + * u_long vers; + */ +__BEGIN_DECLS +extern void svc_unregister(u_long, u_long); +__END_DECLS + + +/* + * Memory based rpc for testing and timing. + */ +__BEGIN_DECLS +extern SVCXPRT *svcraw_create(void); +__END_DECLS + + +/* + * Udp based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svcudp_create(int); +extern SVCXPRT *svcudp_bufcreate(int, u_int, u_int); +extern int svcudp_enablecache(SVCXPRT *, u_long); +__END_DECLS + + +/* + * Tcp based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svctcp_create(int, u_int, u_int); +__END_DECLS + +/* + * Fd based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svcfd_create(int, u_int, u_int); +__END_DECLS + +#endif /* !_RPC_SVC_SOC_H */ diff --git a/lib/libc/include/any-freebsd-any/rpc/xdr.h b/lib/libc/include/any-freebsd-any/rpc/xdr.h new file mode 100644 index 000000000000..ad1672cd1db8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpc/xdr.h @@ -0,0 +1,366 @@ +/* $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from: @(#)xdr.h 1.19 87/04/22 SMI + * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC + * $FreeBSD$ + */ + +/* + * xdr.h, External Data Representation Serialization Routines. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +#ifndef _RPC_XDR_H +#define _RPC_XDR_H +#include + +/* + * XDR provides a conventional way for converting between C data + * types and an external bit-string representation. Library supplied + * routines provide for the conversion on built-in C data types. These + * routines and utility routines defined here are used to help implement + * a type encode/decode routine for each user-defined type. + * + * Each data type provides a single procedure which takes two arguments: + * + * bool_t + * xdrproc(xdrs, argresp) + * XDR *xdrs; + * *argresp; + * + * xdrs is an instance of a XDR handle, to which or from which the data + * type is to be converted. argresp is a pointer to the structure to be + * converted. The XDR handle contains an operation field which indicates + * which of the operations (ENCODE, DECODE * or FREE) is to be performed. + * + * XDR_DECODE may allocate space if the pointer argresp is null. This + * data can be freed with the XDR_FREE operation. + * + * We write only one procedure per data type to make it easy + * to keep the encode and decode procedures for a data type consistent. + * In many cases the same code performs all operations on a user defined type, + * because all the hard work is done in the component type routines. + * decode as a series of calls on the nested data types. + */ + +/* + * Xdr operations. XDR_ENCODE causes the type to be encoded into the + * stream. XDR_DECODE causes the type to be extracted from the stream. + * XDR_FREE can be used to release the space allocated by an XDR_DECODE + * request. + */ +enum xdr_op { + XDR_ENCODE=0, + XDR_DECODE=1, + XDR_FREE=2 +}; + +/* + * This is the number of bytes per unit of external data. + */ +#define BYTES_PER_XDR_UNIT (4) +#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ + * BYTES_PER_XDR_UNIT) + +/* + * The XDR handle. + * Contains operation which is being applied to the stream, + * an operations vector for the particular implementation (e.g. see xdr_mem.c), + * and two private fields for the use of the particular implementation. + */ +typedef struct XDR { + enum xdr_op x_op; /* operation; fast additional param */ + const struct xdr_ops { + /* get a long from underlying stream */ + bool_t (*x_getlong)(struct XDR *, long *); + /* put a long to " */ + bool_t (*x_putlong)(struct XDR *, const long *); + /* get some bytes from " */ + bool_t (*x_getbytes)(struct XDR *, char *, u_int); + /* put some bytes to " */ + bool_t (*x_putbytes)(struct XDR *, const char *, u_int); + /* returns bytes off from beginning */ + u_int (*x_getpostn)(struct XDR *); + /* lets you reposition the stream */ + bool_t (*x_setpostn)(struct XDR *, u_int); + /* buf quick ptr to buffered data */ + int32_t *(*x_inline)(struct XDR *, u_int); + /* free privates of this xdr_stream */ + void (*x_destroy)(struct XDR *); + bool_t (*x_control)(struct XDR *, int, void *); + } *x_ops; + char * x_public; /* users' data */ + void * x_private; /* pointer to private data */ + char * x_base; /* private used for position info */ + u_int x_handy; /* extra private word */ +} XDR; + +/* + * A xdrproc_t exists for each data type which is to be encoded or decoded. + * + * The second argument to the xdrproc_t is a pointer to an opaque pointer. + * The opaque pointer generally points to a structure of the data type + * to be decoded. If this pointer is 0, then the type routines should + * allocate dynamic storage of the appropriate size and return it. + */ +#ifdef _KERNEL +typedef bool_t (*xdrproc_t)(XDR *, void *, u_int); +#else +/* + * XXX can't actually prototype it, because some take three args!!! + */ +typedef bool_t (*xdrproc_t)(XDR *, ...); +#endif + +/* + * Operations defined on a XDR handle + * + * XDR *xdrs; + * long *longp; + * char * addr; + * u_int len; + * u_int pos; + */ +#define XDR_GETLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) +#define xdr_getlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) + +#define XDR_PUTLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +#define xdr_putlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) + +static __inline int +xdr_getint32(XDR *xdrs, int32_t *ip) +{ + long l; + + if (!xdr_getlong(xdrs, &l)) + return (FALSE); + *ip = (int32_t)l; + return (TRUE); +} + +static __inline int +xdr_putint32(XDR *xdrs, int32_t *ip) +{ + long l; + + l = (long)*ip; + return xdr_putlong(xdrs, &l); +} + +#define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p) +#define XDR_PUTINT32(xdrs, int32p) xdr_putint32(xdrs, int32p) + +#define XDR_GETBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) +#define xdr_getbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) + +#define XDR_PUTBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) +#define xdr_putbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) + +#define XDR_GETPOS(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) +#define xdr_getpos(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) + +#define XDR_SETPOS(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) +#define xdr_setpos(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) + +#define XDR_INLINE(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) +#define xdr_inline(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) + +#define XDR_DESTROY(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) +#define xdr_destroy(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) + +#define XDR_CONTROL(xdrs, req, op) \ + if ((xdrs)->x_ops->x_control) \ + (*(xdrs)->x_ops->x_control)(xdrs, req, op) +#define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op) + +#define xdr_rpcvers(xdrs, versp) xdr_u_int32_t(xdrs, versp) +#define xdr_rpcprog(xdrs, progp) xdr_u_int32_t(xdrs, progp) +#define xdr_rpcproc(xdrs, procp) xdr_u_int32_t(xdrs, procp) +#define xdr_rpcprot(xdrs, protp) xdr_u_int32_t(xdrs, protp) +#define xdr_rpcport(xdrs, portp) xdr_u_int32_t(xdrs, portp) + +/* + * Support struct for discriminated unions. + * You create an array of xdrdiscrim structures, terminated with + * an entry with a null procedure pointer. The xdr_union routine gets + * the discriminant value and then searches the array of structures + * for a matching value. If a match is found the associated xdr routine + * is called to handle that part of the union. If there is + * no match, then a default routine may be called. + * If there is no match and no default routine it is an error. + */ +#define NULL_xdrproc_t ((xdrproc_t)0) +struct xdr_discrim { + int value; + xdrproc_t proc; +}; + +/* + * In-line routines for fast encode/decode of primitive data types. + * Caveat emptor: these use single memory cycles to get the + * data from the underlying buffer, and will fail to operate + * properly if the data is not aligned. The standard way to use these + * is to say: + * if ((buf = XDR_INLINE(xdrs, count)) == NULL) + * return (FALSE); + * <<< macro calls >>> + * where ``count'' is the number of bytes of data occupied + * by the primitive data types. + * + * N.B. and frozen for all time: each data type here uses 4 bytes + * of external representation. + */ +#define IXDR_GET_INT32(buf) ((int32_t)__ntohl((u_int32_t)*(buf)++)) +#define IXDR_PUT_INT32(buf, v) (*(buf)++ =(int32_t)__htonl((u_int32_t)v)) +#define IXDR_GET_U_INT32(buf) ((u_int32_t)IXDR_GET_INT32(buf)) +#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) + +#define IXDR_GET_LONG(buf) ((long)__ntohl((u_int32_t)*(buf)++)) +#define IXDR_PUT_LONG(buf, v) (*(buf)++ =(int32_t)__htonl((u_int32_t)v)) + +#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) +#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) +#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf)) +#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) +#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf)) + +#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v)) +#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v)) +#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v)) +#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) +#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) + +/* + * These are the "generic" xdr routines. + */ +__BEGIN_DECLS +extern bool_t xdr_void(void); +extern bool_t xdr_int(XDR *, int *); +extern bool_t xdr_u_int(XDR *, u_int *); +extern bool_t xdr_long(XDR *, long *); +extern bool_t xdr_u_long(XDR *, u_long *); +extern bool_t xdr_short(XDR *, short *); +extern bool_t xdr_u_short(XDR *, u_short *); +extern bool_t xdr_int16_t(XDR *, int16_t *); +extern bool_t xdr_u_int16_t(XDR *, u_int16_t *); +extern bool_t xdr_uint16_t(XDR *, u_int16_t *); +extern bool_t xdr_int32_t(XDR *, int32_t *); +extern bool_t xdr_u_int32_t(XDR *, u_int32_t *); +extern bool_t xdr_uint32_t(XDR *, u_int32_t *); +extern bool_t xdr_int64_t(XDR *, int64_t *); +extern bool_t xdr_u_int64_t(XDR *, u_int64_t *); +extern bool_t xdr_uint64_t(XDR *, u_int64_t *); +extern bool_t xdr_bool(XDR *, bool_t *); +extern bool_t xdr_enum(XDR *, enum_t *); +extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t); +extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int); +extern bool_t xdr_opaque(XDR *, char *, u_int); +extern bool_t xdr_string(XDR *, char **, u_int); +extern bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t); +extern bool_t xdr_char(XDR *, char *); +extern bool_t xdr_u_char(XDR *, u_char *); +extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); +extern bool_t xdr_float(XDR *, float *); +extern bool_t xdr_double(XDR *, double *); +extern bool_t xdr_quadruple(XDR *, long double *); +extern bool_t xdr_reference(XDR *, char **, u_int, xdrproc_t); +extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t); +extern bool_t xdr_wrapstring(XDR *, char **); +extern void xdr_free(xdrproc_t, void *); +extern bool_t xdr_hyper(XDR *, quad_t *); +extern bool_t xdr_u_hyper(XDR *, u_quad_t *); +extern bool_t xdr_longlong_t(XDR *, quad_t *); +extern bool_t xdr_u_longlong_t(XDR *, u_quad_t *); +extern unsigned long xdr_sizeof(xdrproc_t, void *); +__END_DECLS + +/* + * Common opaque bytes objects used by many rpc protocols; + * declared here due to commonality. + */ +#define MAX_NETOBJ_SZ 1024 +struct netobj { + u_int n_len; + char *n_bytes; +}; +typedef struct netobj netobj; +extern bool_t xdr_netobj(XDR *, struct netobj *); + +/* + * These are the public routines for the various implementations of + * xdr streams. + */ +__BEGIN_DECLS +/* XDR using memory buffers */ +extern void xdrmem_create(XDR *, char *, u_int, enum xdr_op); + +/* XDR using stdio library */ +#ifdef _STDIO_H_ +extern void xdrstdio_create(XDR *, FILE *, enum xdr_op); +#endif + +/* XDR pseudo records for tcp */ +extern void xdrrec_create(XDR *, u_int, u_int, void *, + int (*)(void *, void *, int), + int (*)(void *, void *, int)); + +/* make end of xdr record */ +extern bool_t xdrrec_endofrecord(XDR *, int); + +/* move to beginning of next record */ +extern bool_t xdrrec_skiprecord(XDR *); + +/* true if no more input */ +extern bool_t xdrrec_eof(XDR *); +extern u_int xdrrec_readbytes(XDR *, caddr_t, u_int); +__END_DECLS + +#endif /* !_RPC_XDR_H */ diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/bootparam_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/bootparam_prot.x new file mode 100644 index 000000000000..548d618755d7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/bootparam_prot.x @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * RPC for bootparms service. + * There are two procedures: + * WHOAMI takes a net address and returns a client name and also a + * likely net address for routing + * GETFILE takes a client name and file identifier and returns the + * server name, server net address and pathname for the file. + * file identifiers typically include root, swap, pub and dump + */ + +#ifdef RPC_HDR +%#include +%#include +%#include +%#include +%#include +#else +%#ifndef lint +%/*static char sccsid[] = "from: @(#)bootparam_prot.x 1.2 87/06/24 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)bootparam_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const MAX_MACHINE_NAME = 255; +const MAX_PATH_LEN = 1024; +const MAX_FILEID = 32; +const IP_ADDR_TYPE = 1; + +typedef string bp_machine_name_t; +typedef string bp_path_t; +typedef string bp_fileid_t; + +struct ip_addr_t { + char net; + char host; + char lh; + char impno; +}; + +union bp_address switch (int address_type) { + case IP_ADDR_TYPE: + ip_addr_t ip_addr; +}; + +struct bp_whoami_arg { + bp_address client_address; +}; + +struct bp_whoami_res { + bp_machine_name_t client_name; + bp_machine_name_t domain_name; + bp_address router_address; +}; + +struct bp_getfile_arg { + bp_machine_name_t client_name; + bp_fileid_t file_id; +}; + +struct bp_getfile_res { + bp_machine_name_t server_name; + bp_address server_address; + bp_path_t server_path; +}; + +program BOOTPARAMPROG { + version BOOTPARAMVERS { + bp_whoami_res BOOTPARAMPROC_WHOAMI(bp_whoami_arg) = 1; + bp_getfile_res BOOTPARAMPROC_GETFILE(bp_getfile_arg) = 2; + } = 1; +} = 100026; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/crypt.x b/lib/libc/include/any-freebsd-any/rpcsvc/crypt.x new file mode 100644 index 000000000000..3b296c0ddf1d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/crypt.x @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1996 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +/* + * This protocol definition exists because of the U.S. government and + * its stupid export laws. We can't export DES code from the United + * States to other countries (even though the code already exists + * outside the U.S. -- go figure that one out) but we need to make + * Secure RPC work. The normal way around this is to break the DES + * code out into a shared library; we can then provide a dummy lib + * in the base OS and provide the real lib in the secure dist, which + * the user can install later. But we need Secure RPC for NIS+, and + * there are several system programs that use NIS+ which are statically + * linked. We would have to provide replacements for these programs + * in the secure dist, but there are a lot, and this is a pain. The + * shared lib trick won't work for these programs, and we can't change + * them once they're compiled. + * + * One solution for this problem is to do the DES encryption as a system + * call; no programs need to be changed and we can even supply the DES + * support as an LKM. But this bloats the kernel. Maybe if we have + * Secure NFS one day this will be worth it, but for now we should keep + * this mess in user space. + * + * So we have this second solution: we provide a server that does the + * DES encryption for us. In this case, the server is keyserv (we need + * it to make Secure RPC work anyway) and we use this protocol to ship + * the data back and forth between keyserv and the application. + */ + +enum des_dir { ENCRYPT_DES, DECRYPT_DES }; +enum des_mode { CBC_DES, ECB_DES }; + +struct desargs { + u_char des_key[8]; /* key (with low bit parity) */ + des_dir des_dir; /* direction */ + des_mode des_mode; /* mode */ + u_char des_ivec[8]; /* input vector */ + opaque desbuf<>; +}; + +struct desresp { + opaque desbuf<>; + u_char des_ivec[8]; + int stat; +}; + +program CRYPT_PROG { + version CRYPT_VERS { + desresp + DES_CRYPT(desargs) = 1; + } = 1; +} = 600100029; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/key_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/key_prot.x new file mode 100644 index 000000000000..1fccd957941d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/key_prot.x @@ -0,0 +1,287 @@ +%/*- +% * Copyright (c) 2010, Oracle America, Inc. +% * +% * Redistribution and use in source and binary forms, with or without +% * modification, are permitted provided that the following conditions are +% * met: +% * +% * * Redistributions of source code must retain the above copyright +% * notice, this list of conditions and the following disclaimer. +% * * Redistributions in binary form must reproduce the above +% * copyright notice, this list of conditions and the following +% * disclaimer in the documentation and/or other materials +% * provided with the distribution. +% * * Neither the name of the "Oracle America, Inc." nor the names of its +% * contributors may be used to endorse or promote products derived +% * from this software without specific prior written permission. +% * +% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +% * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +% * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +% * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +% * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +% * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +% * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +% * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +% */ +/* + * Key server protocol definition + * Copyright (C) 1990, 1991 Sun Microsystems, Inc. + * + * The keyserver is a public key storage/encryption/decryption service + * The encryption method used is based on the Diffie-Hellman exponential + * key exchange technology. + * + * The key server is local to each machine, akin to the portmapper. + * Under TI-RPC, communication with the keyserver is through the + * loopback transport. + * + * NOTE: This .x file generates the USER level headers for the keyserver. + * the KERNEL level headers are created by hand as they kernel has special + * requirements. + */ + +%/* From: #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" */ +%/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */ +%#include +%__FBSDID("$FreeBSD$"); +% +%/* +% * Compiled from key_prot.x using rpcgen. +% * DO NOT EDIT THIS FILE! +% * This is NOT source code! +% */ + +/* + * PROOT and MODULUS define the way the Diffie-Hellman key is generated. + * + * MODULUS should be chosen as a prime of the form: MODULUS == 2*p + 1, + * where p is also prime. + * + * PROOT satisfies the following two conditions: + * (1) (PROOT ** 2) % MODULUS != 1 + * (2) (PROOT ** p) % MODULUS != 1 + * + */ + +const PROOT = 3; +const HEXMODULUS = "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"; + +const HEXKEYBYTES = 48; /* HEXKEYBYTES == strlen(HEXMODULUS) */ +const KEYSIZE = 192; /* KEYSIZE == bit length of key */ +const KEYBYTES = 24; /* byte length of key */ + +/* + * The first 16 hex digits of the encrypted secret key are used as + * a checksum in the database. + */ +const KEYCHECKSUMSIZE = 16; + +/* + * status of operation + */ +enum keystatus { + KEY_SUCCESS, /* no problems */ + KEY_NOSECRET, /* no secret key stored */ + KEY_UNKNOWN, /* unknown netname */ + KEY_SYSTEMERR /* system error (out of memory, encryption failure) */ +}; + +typedef opaque keybuf[HEXKEYBYTES]; /* store key in hex */ + +typedef string netnamestr; + +/* + * Argument to ENCRYPT or DECRYPT + */ +struct cryptkeyarg { + netnamestr remotename; + des_block deskey; +}; + +/* + * Argument to ENCRYPT_PK or DECRYPT_PK + */ +struct cryptkeyarg2 { + netnamestr remotename; + netobj remotekey; /* Contains a length up to 1024 bytes */ + des_block deskey; +}; + + +/* + * Result of ENCRYPT, DECRYPT, ENCRYPT_PK, and DECRYPT_PK + */ +union cryptkeyres switch (keystatus status) { +case KEY_SUCCESS: + des_block deskey; +default: + void; +}; + +const MAXGIDS = 16; /* max number of gids in gid list */ + +/* + * Unix credential + */ +struct unixcred { + u_int uid; + u_int gid; + u_int gids; +}; + +/* + * Result returned from GETCRED + */ +union getcredres switch (keystatus status) { +case KEY_SUCCESS: + unixcred cred; +default: + void; +}; +/* + * key_netstarg; + */ + +struct key_netstarg { + keybuf st_priv_key; + keybuf st_pub_key; + netnamestr st_netname; +}; + +union key_netstres switch (keystatus status){ +case KEY_SUCCESS: + key_netstarg knet; +default: + void; +}; + +#ifdef RPC_HDR +% +%#ifndef opaque +%#define opaque char +%#endif +% +#endif +program KEY_PROG { + version KEY_VERS { + + /* + * This is my secret key. + * Store it for me. + */ + keystatus + KEY_SET(keybuf) = 1; + + /* + * I want to talk to X. + * Encrypt a conversation key for me. + */ + cryptkeyres + KEY_ENCRYPT(cryptkeyarg) = 2; + + /* + * X just sent me a message. + * Decrypt the conversation key for me. + */ + cryptkeyres + KEY_DECRYPT(cryptkeyarg) = 3; + + /* + * Generate a secure conversation key for me + */ + des_block + KEY_GEN(void) = 4; + + /* + * Get me the uid, gid and group-access-list associated + * with this netname (for kernel which cannot use NIS) + */ + getcredres + KEY_GETCRED(netnamestr) = 5; + } = 1; + version KEY_VERS2 { + + /* + * ####### + * Procedures 1-5 are identical to version 1 + * ####### + */ + + /* + * This is my secret key. + * Store it for me. + */ + keystatus + KEY_SET(keybuf) = 1; + + /* + * I want to talk to X. + * Encrypt a conversation key for me. + */ + cryptkeyres + KEY_ENCRYPT(cryptkeyarg) = 2; + + /* + * X just sent me a message. + * Decrypt the conversation key for me. + */ + cryptkeyres + KEY_DECRYPT(cryptkeyarg) = 3; + + /* + * Generate a secure conversation key for me + */ + des_block + KEY_GEN(void) = 4; + + /* + * Get me the uid, gid and group-access-list associated + * with this netname (for kernel which cannot use NIS) + */ + getcredres + KEY_GETCRED(netnamestr) = 5; + + /* + * I want to talk to X. and I know X's public key + * Encrypt a conversation key for me. + */ + cryptkeyres + KEY_ENCRYPT_PK(cryptkeyarg2) = 6; + + /* + * X just sent me a message. and I know X's public key + * Decrypt the conversation key for me. + */ + cryptkeyres + KEY_DECRYPT_PK(cryptkeyarg2) = 7; + + /* + * Store my public key, netname and private key. + */ + keystatus + KEY_NET_PUT(key_netstarg) = 8; + + /* + * Retrieve my public key, netname and private key. + */ + key_netstres + KEY_NET_GET(void) = 9; + + /* + * Return me the conversation key that is constructed + * from my secret key and this publickey. + */ + + cryptkeyres + KEY_GET_CONV(keybuf) = 10; + + + } = 2; +} = 100029; + + diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/klm_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/klm_prot.x new file mode 100644 index 000000000000..5860f3251c17 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/klm_prot.x @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Kernel/lock manager protocol definition + * Copyright (C) 1986 Sun Microsystems, Inc. + * + * protocol used between the UNIX kernel (the "client") and the + * local lock manager. The local lock manager is a daemon running + * above the kernel. + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)klm_prot.x 1.7 87/07/08 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)klm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const LM_MAXSTRLEN = 1024; + +/* + * lock manager status returns + */ +enum klm_stats { + klm_granted = 0, /* lock is granted */ + klm_denied = 1, /* lock is denied */ + klm_denied_nolocks = 2, /* no lock entry available */ + klm_working = 3 /* lock is being processed */ +}; + +/* + * lock manager lock identifier + */ +struct klm_lock { + string server_name; + netobj fh; /* a counted file handle */ + int pid; /* holder of the lock */ + unsigned l_offset; /* beginning offset of the lock */ + unsigned l_len; /* byte length of the lock; + * zero means through end of file */ +}; + +/* + * lock holder identifier + */ +struct klm_holder { + bool exclusive; /* FALSE if shared lock */ + int svid; /* holder of the lock (pid) */ + unsigned l_offset; /* beginning offset of the lock */ + unsigned l_len; /* byte length of the lock; + * zero means through end of file */ +}; + +/* + * reply to KLM_LOCK / KLM_UNLOCK / KLM_CANCEL + */ +struct klm_stat { + klm_stats stat; +}; + +/* + * reply to a KLM_TEST call + */ +union klm_testrply switch (klm_stats stat) { + case klm_denied: + struct klm_holder holder; + default: /* All other cases return no arguments */ + void; +}; + + +/* + * arguments to KLM_LOCK + */ +struct klm_lockargs { + bool block; + bool exclusive; + struct klm_lock alock; +}; + +/* + * arguments to KLM_TEST + */ +struct klm_testargs { + bool exclusive; + struct klm_lock alock; +}; + +/* + * arguments to KLM_UNLOCK + */ +struct klm_unlockargs { + struct klm_lock alock; +}; + +program KLM_PROG { + version KLM_VERS { + + klm_testrply KLM_TEST (struct klm_testargs) = 1; + + klm_stat KLM_LOCK (struct klm_lockargs) = 2; + + klm_stat KLM_CANCEL (struct klm_lockargs) = 3; + /* klm_granted=> the cancel request fails due to lock is already granted */ + /* klm_denied=> the cancel request successfully aborts +lock request */ + + klm_stat KLM_UNLOCK (struct klm_unlockargs) = 4; + } = 1; +} = 100020; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/mount.x b/lib/libc/include/any-freebsd-any/rpcsvc/mount.x new file mode 100644 index 000000000000..9ebee835b273 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/mount.x @@ -0,0 +1,259 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Protocol description for the mount program + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)mount.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)mount.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const MNTPATHLEN = 1024; /* maximum bytes in a pathname argument */ +const MNTNAMLEN = 255; /* maximum bytes in a name argument */ +const FHSIZE = 32; /* size in bytes of a file handle */ +#ifdef WANT_NFS3 +const FHSIZE3 = 64; /* size in bytes of a file handle (v3) */ +#endif + +/* + * The fhandle is the file handle that the server passes to the client. + * All file operations are done using the file handles to refer to a file + * or a directory. The file handle can contain whatever information the + * server needs to distinguish an individual file. + */ +typedef opaque fhandle[FHSIZE]; +#ifdef WANT_NFS3 +typedef opaque fhandle3; +#endif + +/* + * If a status of zero is returned, the call completed successfully, and + * a file handle for the directory follows. A non-zero status indicates + * some sort of error. The status corresponds with UNIX error numbers. + */ +union fhstatus switch (unsigned fhs_status) { +case 0: + fhandle fhs_fhandle; +default: + void; +}; + +#ifdef WANT_NFS3 +/* + * Status codes returned by the version 3 mount call. + */ +enum mountstat3 { + MNT3_OK = 0, /* no error */ + MNT3ERR_PERM = 1, /* Not owner */ + MNT3ERR_NOENT = 2, /* No such file or directory */ + MNT3ERR_IO = 5, /* I/O error */ + MNT3ERR_ACCES = 13, /* Permission denied */ + MNT3ERR_NOTDIR = 20, /* Not a directory */ + MNT3ERR_INVAL = 22, /* Invalid argument */ + MNT3ERR_NAMETOOLONG = 63, /* Filename too long */ + MNT3ERR_NOTSUPP = 10004, /* Operation not supported */ + MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */ +}; + +struct mountres3_ok { + fhandle3 fhandle; + int auth_flavors<>; +}; + +union mountres3 switch (mountstat3 fhs_status) { +case 0: + mountres3_ok mountinfo; +default: + void; +}; +#endif + +/* + * The type dirpath is the pathname of a directory + */ +typedef string dirpath; + +/* + * The type name is used for arbitrary names (hostnames, groupnames) + */ +typedef string name; + +/* + * A list of who has what mounted + */ +typedef struct mountbody *mountlist; +struct mountbody { + name ml_hostname; + dirpath ml_directory; + mountlist ml_next; +}; + +/* + * A list of netgroups + */ +typedef struct groupnode *groups; +struct groupnode { + name gr_name; + groups gr_next; +}; + +/* + * A list of what is exported and to whom + */ +typedef struct exportnode *exports; +struct exportnode { + dirpath ex_dir; + groups ex_groups; + exports ex_next; +}; + +program MOUNTPROG { + /* + * Version one of the mount protocol communicates with version two + * of the NFS protocol. Version three communicates with + * version three of the NFS protocol. The only connecting + * point is the fhandle structure, which is the same for both + * protocols. + */ + version MOUNTVERS { + /* + * Does no work. It is made available in all RPC services + * to allow server response testing and timing + */ + void + MOUNTPROC_NULL(void) = 0; + + /* + * If fhs_status is 0, then fhs_fhandle contains the + * file handle for the directory. This file handle may + * be used in the NFS protocol. This procedure also adds + * a new entry to the mount list for this client mounting + * the directory. + * Unix authentication required. + */ + fhstatus + MOUNTPROC_MNT(dirpath) = 1; + + /* + * Returns the list of remotely mounted filesystems. The + * mountlist contains one entry for each hostname and + * directory pair. + */ + mountlist + MOUNTPROC_DUMP(void) = 2; + + /* + * Removes the mount list entry for the directory + * Unix authentication required. + */ + void + MOUNTPROC_UMNT(dirpath) = 3; + + /* + * Removes all of the mount list entries for this client + * Unix authentication required. + */ + void + MOUNTPROC_UMNTALL(void) = 4; + + /* + * Returns a list of all the exported filesystems, and which + * machines are allowed to import it. + */ + exports + MOUNTPROC_EXPORT(void) = 5; + + /* + * Identical to MOUNTPROC_EXPORT above + */ + exports + MOUNTPROC_EXPORTALL(void) = 6; + } = 1; +#ifdef WANT_NFS3 + version MOUNTVERS3 { + /* + * Does no work. It is made available in all RPC services + * to allow server response testing and timing + */ + void + MOUNTPROC_NULL(void) = 0; + + /* + * If mountres3.fhs_status is MNT3_OK, then + * mountres3.mountinfo contains the file handle for + * the directory and a list of acceptable + * authentication flavors. This file handle may only + * be used in the NFS version 3 protocol. This + * procedure also results in the server adding a new + * entry to its mount list recording that this client + * has mounted the directory. AUTH_UNIX authentication + * or better is required. + */ + mountres3 + MOUNTPROC_MNT(dirpath) = 1; + + /* + * Returns the list of remotely mounted filesystems. The + * mountlist contains one entry for each hostname and + * directory pair. + */ + mountlist + MOUNTPROC_DUMP(void) = 2; + + /* + * Removes the mount list entry for the directory + * Unix authentication required. + */ + void + MOUNTPROC_UMNT(dirpath) = 3; + + /* + * Removes all of the mount list entries for this client + * Unix authentication required. + */ + void + MOUNTPROC_UMNTALL(void) = 4; + + /* + * Returns a list of all the exported filesystems, and which + * machines are allowed to import it. + */ + exports + MOUNTPROC_EXPORT(void) = 5; + } = 3; +#endif +} = 100005; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nfs_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/nfs_prot.x new file mode 100644 index 000000000000..17791b6a18b2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nfs_prot.x @@ -0,0 +1,1268 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)nfs_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const NFS_PORT = 2049; +const NFS_MAXDATA = 8192; +const NFS_MAXPATHLEN = 1024; +const NFS_MAXNAMLEN = 255; +const NFS_FHSIZE = 32; +const NFS_COOKIESIZE = 4; +const NFS_FIFO_DEV = -1; /* size kludge for named pipes */ + +/* + * File types + */ +const NFSMODE_FMT = 0170000; /* type of file */ +const NFSMODE_DIR = 0040000; /* directory */ +const NFSMODE_CHR = 0020000; /* character special */ +const NFSMODE_BLK = 0060000; /* block special */ +const NFSMODE_REG = 0100000; /* regular */ +const NFSMODE_LNK = 0120000; /* symbolic link */ +const NFSMODE_SOCK = 0140000; /* socket */ +const NFSMODE_FIFO = 0010000; /* fifo */ + +/* + * Error status + */ +enum nfsstat { + NFS_OK= 0, /* no error */ + NFSERR_PERM=1, /* Not owner */ + NFSERR_NOENT=2, /* No such file or directory */ + NFSERR_IO=5, /* I/O error */ + NFSERR_NXIO=6, /* No such device or address */ + NFSERR_ACCES=13, /* Permission denied */ + NFSERR_EXIST=17, /* File exists */ + NFSERR_NODEV=19, /* No such device */ + NFSERR_NOTDIR=20, /* Not a directory*/ + NFSERR_ISDIR=21, /* Is a directory */ + NFSERR_FBIG=27, /* File too large */ + NFSERR_NOSPC=28, /* No space left on device */ + NFSERR_ROFS=30, /* Read-only file system */ + NFSERR_NAMETOOLONG=63, /* File name too long */ + NFSERR_NOTEMPTY=66, /* Directory not empty */ + NFSERR_DQUOT=69, /* Disc quota exceeded */ + NFSERR_STALE=70, /* Stale NFS file handle */ + NFSERR_WFLUSH=99 /* write cache flushed */ +}; + +/* + * File types + */ +enum ftype { + NFNON = 0, /* non-file */ + NFREG = 1, /* regular file */ + NFDIR = 2, /* directory */ + NFBLK = 3, /* block special */ + NFCHR = 4, /* character special */ + NFLNK = 5, /* symbolic link */ + NFSOCK = 6, /* unix domain sockets */ + NFBAD = 7, /* unused */ + NFFIFO = 8 /* named pipe */ +}; + +/* + * File access handle + */ +struct nfs_fh { + opaque data[NFS_FHSIZE]; +}; + +/* + * Timeval + */ +struct nfstime { + unsigned seconds; + unsigned useconds; +}; + + +/* + * File attributes + */ +struct fattr { + ftype type; /* file type */ + unsigned mode; /* protection mode bits */ + unsigned nlink; /* # hard links */ + unsigned uid; /* owner user id */ + unsigned gid; /* owner group id */ + unsigned size; /* file size in bytes */ + unsigned blocksize; /* preferred block size */ + unsigned rdev; /* special device # */ + unsigned blocks; /* Kb of disk used by file */ + unsigned fsid; /* device # */ + unsigned fileid; /* inode # */ + nfstime atime; /* time of last access */ + nfstime mtime; /* time of last modification */ + nfstime ctime; /* time of last change */ +}; + +/* + * File attributes which can be set + */ +struct sattr { + unsigned mode; /* protection mode bits */ + unsigned uid; /* owner user id */ + unsigned gid; /* owner group id */ + unsigned size; /* file size in bytes */ + nfstime atime; /* time of last access */ + nfstime mtime; /* time of last modification */ +}; + + +typedef string filename; +typedef string nfspath; + +/* + * Reply status with file attributes + */ +union attrstat switch (nfsstat status) { +case NFS_OK: + fattr attributes; +default: + void; +}; + +struct sattrargs { + nfs_fh file; + sattr attributes; +}; + +/* + * Arguments for directory operations + */ +struct diropargs { + nfs_fh dir; /* directory file handle */ + filename name; /* name (up to NFS_MAXNAMLEN bytes) */ +}; + +struct diropokres { + nfs_fh file; + fattr attributes; +}; + +/* + * Results from directory operation + */ +union diropres switch (nfsstat status) { +case NFS_OK: + diropokres diropres; +default: + void; +}; + +union readlinkres switch (nfsstat status) { +case NFS_OK: + nfspath data; +default: + void; +}; + +/* + * Arguments to remote read + */ +struct readargs { + nfs_fh file; /* handle for file */ + unsigned offset; /* byte offset in file */ + unsigned count; /* immediate read count */ + unsigned totalcount; /* total read count (from this offset)*/ +}; + +/* + * Status OK portion of remote read reply + */ +struct readokres { + fattr attributes; /* attributes, need for pagin*/ + opaque data; +}; + +union readres switch (nfsstat status) { +case NFS_OK: + readokres reply; +default: + void; +}; + +/* + * Arguments to remote write + */ +struct writeargs { + nfs_fh file; /* handle for file */ + unsigned beginoffset; /* beginning byte offset in file */ + unsigned offset; /* current byte offset in file */ + unsigned totalcount; /* total write count (to this offset)*/ + opaque data; +}; + +struct createargs { + diropargs where; + sattr attributes; +}; + +struct renameargs { + diropargs from; + diropargs to; +}; + +struct linkargs { + nfs_fh from; + diropargs to; +}; + +struct symlinkargs { + diropargs from; + nfspath to; + sattr attributes; +}; + + +typedef opaque nfscookie[NFS_COOKIESIZE]; + +/* + * Arguments to readdir + */ +struct readdirargs { + nfs_fh dir; /* directory handle */ + nfscookie cookie; + unsigned count; /* number of directory bytes to read */ +}; + +struct entry { + unsigned fileid; + filename name; + nfscookie cookie; + entry *nextentry; +}; + +struct dirlist { + entry *entries; + bool eof; +}; + +union readdirres switch (nfsstat status) { +case NFS_OK: + dirlist reply; +default: + void; +}; + +struct statfsokres { + unsigned tsize; /* preferred transfer size in bytes */ + unsigned bsize; /* fundamental file system block size */ + unsigned blocks; /* total blocks in file system */ + unsigned bfree; /* free blocks in fs */ + unsigned bavail; /* free blocks avail to non-superuser */ +}; + +union statfsres switch (nfsstat status) { +case NFS_OK: + statfsokres reply; +default: + void; +}; + +#ifdef WANT_NFS3 + +/* + * NFSv3 constants and types + */ +const NFS3_FHSIZE = 64; /* maximum size in bytes of a file handle */ +const NFS3_COOKIEVERFSIZE = 8; /* size of a cookie verifier for READDIR */ +const NFS3_CREATEVERFSIZE = 8; /* size of the verifier used for CREATE */ +const NFS3_WRITEVERFSIZE = 8; /* size of the verifier used for WRITE */ + +typedef unsigned hyper uint64; +typedef hyper int64; +typedef unsigned long uint32; +typedef long int32; +typedef string filename3<>; +typedef string nfspath3<>; +typedef uint64 fileid3; +typedef uint64 cookie3; +typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE]; +typedef opaque createverf3[NFS3_CREATEVERFSIZE]; +typedef opaque writeverf3[NFS3_WRITEVERFSIZE]; +typedef uint32 uid3; +typedef uint32 gid3; +typedef uint64 size3; +typedef uint64 offset3; +typedef uint32 mode3; +typedef uint32 count3; + +/* + * Error status (v3) + */ +enum nfsstat3 { + NFS3_OK = 0, + NFS3ERR_PERM = 1, + NFS3ERR_NOENT = 2, + NFS3ERR_IO = 5, + NFS3ERR_NXIO = 6, + NFS3ERR_ACCES = 13, + NFS3ERR_EXIST = 17, + NFS3ERR_XDEV = 18, + NFS3ERR_NODEV = 19, + NFS3ERR_NOTDIR = 20, + NFS3ERR_ISDIR = 21, + NFS3ERR_INVAL = 22, + NFS3ERR_FBIG = 27, + NFS3ERR_NOSPC = 28, + NFS3ERR_ROFS = 30, + NFS3ERR_MLINK = 31, + NFS3ERR_NAMETOOLONG = 63, + NFS3ERR_NOTEMPTY = 66, + NFS3ERR_DQUOT = 69, + NFS3ERR_STALE = 70, + NFS3ERR_REMOTE = 71, + NFS3ERR_BADHANDLE = 10001, + NFS3ERR_NOT_SYNC = 10002, + NFS3ERR_BAD_COOKIE = 10003, + NFS3ERR_NOTSUPP = 10004, + NFS3ERR_TOOSMALL = 10005, + NFS3ERR_SERVERFAULT = 10006, + NFS3ERR_BADTYPE = 10007, + NFS3ERR_JUKEBOX = 10008 +}; + +/* + * File types (v3) + */ +enum ftype3 { + NF3REG = 1, /* regular file */ + NF3DIR = 2, /* directory */ + NF3BLK = 3, /* block special */ + NF3CHR = 4, /* character special */ + NF3LNK = 5, /* symbolic link */ + NF3SOCK = 6, /* unix domain sockets */ + NF3FIFO = 7 /* named pipe */ +}; + +struct specdata3 { + uint32 specdata1; + uint32 specdata2; +}; + +/* + * File access handle (v3) + */ +struct nfs_fh3 { + opaque data; +}; + +/* + * Timeval (v3) + */ +struct nfstime3 { + uint32 seconds; + uint32 nseconds; +}; + + +/* + * File attributes (v3) + */ +struct fattr3 { + ftype3 type; /* file type */ + mode3 mode; /* protection mode bits */ + uint32 nlink; /* # hard links */ + uid3 uid; /* owner user id */ + gid3 gid; /* owner group id */ + size3 size; /* file size in bytes */ + size3 used; /* preferred block size */ + specdata3 rdev; /* special device # */ + uint64 fsid; /* device # */ + fileid3 fileid; /* inode # */ + nfstime3 atime; /* time of last access */ + nfstime3 mtime; /* time of last modification */ + nfstime3 ctime; /* time of last change */ +}; + +union post_op_attr switch (bool attributes_follow) { +case TRUE: + fattr3 attributes; +case FALSE: + void; +}; + +struct wcc_attr { + size3 size; + nfstime3 mtime; + nfstime3 ctime; +}; + +union pre_op_attr switch (bool attributes_follow) { +case TRUE: + wcc_attr attributes; +case FALSE: + void; +}; + +struct wcc_data { + pre_op_attr before; + post_op_attr after; +}; + +union post_op_fh3 switch (bool handle_follows) { +case TRUE: + nfs_fh3 handle; +case FALSE: + void; +}; + +/* + * File attributes which can be set (v3) + */ +enum time_how { + DONT_CHANGE = 0, + SET_TO_SERVER_TIME = 1, + SET_TO_CLIENT_TIME = 2 +}; + +union set_mode3 switch (bool set_it) { +case TRUE: + mode3 mode; +default: + void; +}; + +union set_uid3 switch (bool set_it) { +case TRUE: + uid3 uid; +default: + void; +}; + +union set_gid3 switch (bool set_it) { +case TRUE: + gid3 gid; +default: + void; +}; + +union set_size3 switch (bool set_it) { +case TRUE: + size3 size; +default: + void; +}; + +union set_atime switch (time_how set_it) { +case SET_TO_CLIENT_TIME: + nfstime3 atime; +default: + void; +}; + +union set_mtime switch (time_how set_it) { +case SET_TO_CLIENT_TIME: + nfstime3 mtime; +default: + void; +}; + +struct sattr3 { + set_mode3 mode; + set_uid3 uid; + set_gid3 gid; + set_size3 size; + set_atime atime; + set_mtime mtime; +}; + +/* + * Arguments for directory operations (v3) + */ +struct diropargs3 { + nfs_fh3 dir; /* directory file handle */ + filename3 name; /* name (up to NFS_MAXNAMLEN bytes) */ +}; + +/* + * Arguments to getattr (v3). + */ +struct GETATTR3args { + nfs_fh3 object; +}; + +struct GETATTR3resok { + fattr3 obj_attributes; +}; + +union GETATTR3res switch (nfsstat3 status) { +case NFS3_OK: + GETATTR3resok resok; +default: + void; +}; + +/* + * Arguments to setattr (v3). + */ +union sattrguard3 switch (bool check) { +case TRUE: + nfstime3 obj_ctime; +case FALSE: + void; +}; + +struct SETATTR3args { + nfs_fh3 object; + sattr3 new_attributes; + sattrguard3 guard; +}; + +struct SETATTR3resok { + wcc_data obj_wcc; +}; + +struct SETATTR3resfail { + wcc_data obj_wcc; +}; + +union SETATTR3res switch (nfsstat3 status) { +case NFS3_OK: + SETATTR3resok resok; +default: + SETATTR3resfail resfail; +}; + +/* + * Arguments to lookup (v3). + */ +struct LOOKUP3args { + diropargs3 what; +}; + +struct LOOKUP3resok { + nfs_fh3 object; + post_op_attr obj_attributes; + post_op_attr dir_attributes; +}; + +struct LOOKUP3resfail { + post_op_attr dir_attributes; +}; + +union LOOKUP3res switch (nfsstat3 status) { +case NFS3_OK: + LOOKUP3resok resok; +default: + LOOKUP3resfail resfail; +}; + +/* + * Arguments to access (v3). + */ +const ACCESS3_READ = 0x0001; +const ACCESS3_LOOKUP = 0x0002; +const ACCESS3_MODIFY = 0x0004; +const ACCESS3_EXTEND = 0x0008; +const ACCESS3_DELETE = 0x0010; +const ACCESS3_EXECUTE = 0x0020; + +struct ACCESS3args { + nfs_fh3 object; + uint32 access; +}; + +struct ACCESS3resok { + post_op_attr obj_attributes; + uint32 access; +}; + +struct ACCESS3resfail { + post_op_attr obj_attributes; +}; + +union ACCESS3res switch (nfsstat3 status) { +case NFS3_OK: + ACCESS3resok resok; +default: + ACCESS3resfail resfail; +}; + +/* + * Arguments to readlink (v3). + */ +struct READLINK3args { + nfs_fh3 symlink; +}; + +struct READLINK3resok { + post_op_attr symlink_attributes; + nfspath3 data; +}; + +struct READLINK3resfail { + post_op_attr symlink_attributes; +}; + +union READLINK3res switch (nfsstat3 status) { +case NFS3_OK: + READLINK3resok resok; +default: + READLINK3resfail resfail; +}; + +/* + * Arguments to read (v3). + */ +struct READ3args { + nfs_fh3 file; + offset3 offset; + count3 count; +}; + +struct READ3resok { + post_op_attr file_attributes; + count3 count; + bool eof; + opaque data<>; +}; + +struct READ3resfail { + post_op_attr file_attributes; +}; + +/* XXX: solaris 2.6 uses ``nfsstat'' here */ +union READ3res switch (nfsstat3 status) { +case NFS3_OK: + READ3resok resok; +default: + READ3resfail resfail; +}; + +/* + * Arguments to write (v3). + */ +enum stable_how { + UNSTABLE = 0, + DATA_SYNC = 1, + FILE_SYNC = 2 +}; + +struct WRITE3args { + nfs_fh3 file; + offset3 offset; + count3 count; + stable_how stable; + opaque data<>; +}; + +struct WRITE3resok { + wcc_data file_wcc; + count3 count; + stable_how committed; + writeverf3 verf; +}; + +struct WRITE3resfail { + wcc_data file_wcc; +}; + +union WRITE3res switch (nfsstat3 status) { +case NFS3_OK: + WRITE3resok resok; +default: + WRITE3resfail resfail; +}; + +/* + * Arguments to create (v3). + */ +enum createmode3 { + UNCHECKED = 0, + GUARDED = 1, + EXCLUSIVE = 2 +}; + +union createhow3 switch (createmode3 mode) { +case UNCHECKED: +case GUARDED: + sattr3 obj_attributes; +case EXCLUSIVE: + createverf3 verf; +}; + +struct CREATE3args { + diropargs3 where; + createhow3 how; +}; + +struct CREATE3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct CREATE3resfail { + wcc_data dir_wcc; +}; + +union CREATE3res switch (nfsstat3 status) { +case NFS3_OK: + CREATE3resok resok; +default: + CREATE3resfail resfail; +}; + +/* + * Arguments to mkdir (v3). + */ +struct MKDIR3args { + diropargs3 where; + sattr3 attributes; +}; + +struct MKDIR3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct MKDIR3resfail { + wcc_data dir_wcc; +}; + +union MKDIR3res switch (nfsstat3 status) { +case NFS3_OK: + MKDIR3resok resok; +default: + MKDIR3resfail resfail; +}; + +/* + * Arguments to symlink (v3). + */ +struct symlinkdata3 { + sattr3 symlink_attributes; + nfspath3 symlink_data; +}; + +struct SYMLINK3args { + diropargs3 where; + symlinkdata3 symlink; +}; + +struct SYMLINK3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct SYMLINK3resfail { + wcc_data dir_wcc; +}; + +union SYMLINK3res switch (nfsstat3 status) { +case NFS3_OK: + SYMLINK3resok resok; +default: + SYMLINK3resfail resfail; +}; + +/* + * Arguments to mknod (v3). + */ +struct devicedata3 { + sattr3 dev_attributes; + specdata3 spec; +}; + +union mknoddata3 switch (ftype3 type) { +case NF3CHR: +case NF3BLK: + devicedata3 device; +case NF3SOCK: +case NF3FIFO: + sattr3 pipe_attributes; +default: + void; +}; + +struct MKNOD3args { + diropargs3 where; + mknoddata3 what; +}; + +struct MKNOD3resok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +struct MKNOD3resfail { + wcc_data dir_wcc; +}; + +union MKNOD3res switch (nfsstat3 status) { +case NFS3_OK: + MKNOD3resok resok; +default: + MKNOD3resfail resfail; +}; + +/* + * Arguments to remove (v3). + */ +struct REMOVE3args { + diropargs3 object; +}; + +struct REMOVE3resok { + wcc_data dir_wcc; +}; + +struct REMOVE3resfail { + wcc_data dir_wcc; +}; + +union REMOVE3res switch (nfsstat3 status) { +case NFS3_OK: + REMOVE3resok resok; +default: + REMOVE3resfail resfail; +}; + +/* + * Arguments to rmdir (v3). + */ +struct RMDIR3args { + diropargs3 object; +}; + +struct RMDIR3resok { + wcc_data dir_wcc; +}; + +struct RMDIR3resfail { + wcc_data dir_wcc; +}; + +union RMDIR3res switch (nfsstat3 status) { +case NFS3_OK: + RMDIR3resok resok; +default: + RMDIR3resfail resfail; +}; + +/* + * Arguments to rename (v3). + */ +struct RENAME3args { + diropargs3 from; + diropargs3 to; +}; + +struct RENAME3resok { + wcc_data fromdir_wcc; + wcc_data todir_wcc; +}; + +struct RENAME3resfail { + wcc_data fromdir_wcc; + wcc_data todir_wcc; +}; + +union RENAME3res switch (nfsstat3 status) { +case NFS3_OK: + RENAME3resok resok; +default: + RENAME3resfail resfail; +}; + +/* + * Arguments to link (v3). + */ +struct LINK3args { + nfs_fh3 file; + diropargs3 link; +}; + +struct LINK3resok { + post_op_attr file_attributes; + wcc_data linkdir_wcc; +}; + +struct LINK3resfail { + post_op_attr file_attributes; + wcc_data linkdir_wcc; +}; + +union LINK3res switch (nfsstat3 status) { +case NFS3_OK: + LINK3resok resok; +default: + LINK3resfail resfail; +}; + +/* + * Arguments to readdir (v3). + */ +struct READDIR3args { + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 count; +}; + +struct entry3 { + fileid3 fileid; + filename3 name; + cookie3 cookie; + entry3 *nextentry; +}; + +struct dirlist3 { + entry3 *entries; + bool eof; +}; + +struct READDIR3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlist3 reply; +}; + +struct READDIR3resfail { + post_op_attr dir_attributes; +}; + +union READDIR3res switch (nfsstat3 status) { +case NFS3_OK: + READDIR3resok resok; +default: + READDIR3resfail resfail; +}; + +/* + * Arguments to readdirplus (v3). + */ +struct READDIRPLUS3args { + nfs_fh3 dir; + cookie3 cookie; + cookieverf3 cookieverf; + count3 dircount; + count3 maxcount; +}; + +struct entryplus3 { + fileid3 fileid; + filename3 name; + cookie3 cookie; + post_op_attr name_attributes; + post_op_fh3 name_handle; + entryplus3 *nextentry; +}; + +struct dirlistplus3 { + entryplus3 *entries; + bool eof; +}; + +struct READDIRPLUS3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlistplus3 reply; +}; + +struct READDIRPLUS3resfail { + post_op_attr dir_attributes; +}; + +union READDIRPLUS3res switch (nfsstat3 status) { +case NFS3_OK: + READDIRPLUS3resok resok; +default: + READDIRPLUS3resfail resfail; +}; + +/* + * Arguments to fsstat (v3). + */ +struct FSSTAT3args { + nfs_fh3 fsroot; +}; + +struct FSSTAT3resok { + post_op_attr obj_attributes; + size3 tbytes; + size3 fbytes; + size3 abytes; + size3 tfiles; + size3 ffiles; + size3 afiles; + uint32 invarsec; +}; + +struct FSSTAT3resfail { + post_op_attr obj_attributes; +}; + +union FSSTAT3res switch (nfsstat3 status) { +case NFS3_OK: + FSSTAT3resok resok; +default: + FSSTAT3resfail resfail; +}; + +/* + * Arguments to fsinfo (v3). + */ +const FSF3_LINK = 0x0001; +const FSF3_SYMLINK = 0x0002; +const FSF3_HOMOGENEOUS = 0x0008; +const FSF3_CANSETTIME = 0x0010; + +struct FSINFO3args { + nfs_fh3 fsroot; +}; + +struct FSINFO3resok { + post_op_attr obj_attributes; + uint32 rtmax; + uint32 rtpref; + uint32 rtmult; + uint32 wtmax; + uint32 wtpref; + uint32 wtmult; + uint32 dtpref; + size3 maxfilesize; + nfstime3 time_delta; + uint32 properties; +}; + +struct FSINFO3resfail { + post_op_attr obj_attributes; +}; + +union FSINFO3res switch (nfsstat3 status) { +case NFS3_OK: + FSINFO3resok resok; +default: + FSINFO3resfail resfail; +}; + +/* + * Arguments to pathconf (v3). + */ +struct PATHCONF3args { + nfs_fh3 object; +}; + +struct PATHCONF3resok { + post_op_attr obj_attributes; + uint32 linkmax; + uint32 name_max; + bool no_trunc; + bool chown_restricted; + bool case_insensitive; + bool case_preserving; +}; + +struct PATHCONF3resfail { + post_op_attr obj_attributes; +}; + +union PATHCONF3res switch (nfsstat3 status) { +case NFS3_OK: + PATHCONF3resok resok; +default: + PATHCONF3resfail resfail; +}; + +/* + * Arguments to commit (v3). + */ +struct COMMIT3args { + nfs_fh3 file; + offset3 offset; + count3 count; +}; + +struct COMMIT3resok { + wcc_data file_wcc; + writeverf3 verf; +}; + +struct COMMIT3resfail { + wcc_data file_wcc; +}; + +union COMMIT3res switch (nfsstat3 status) { +case NFS3_OK: + COMMIT3resok resok; +default: + COMMIT3resfail resfail; +}; + +#endif /* WANT_NFS3 */ + +/* + * Remote file service routines + */ +program NFS_PROGRAM { + version NFS_VERSION { + void + NFSPROC_NULL(void) = 0; + + attrstat + NFSPROC_GETATTR(nfs_fh) = 1; + + attrstat + NFSPROC_SETATTR(sattrargs) = 2; + + void + NFSPROC_ROOT(void) = 3; + + diropres + NFSPROC_LOOKUP(diropargs) = 4; + + readlinkres + NFSPROC_READLINK(nfs_fh) = 5; + + readres + NFSPROC_READ(readargs) = 6; + + void + NFSPROC_WRITECACHE(void) = 7; + + attrstat + NFSPROC_WRITE(writeargs) = 8; + + diropres + NFSPROC_CREATE(createargs) = 9; + + nfsstat + NFSPROC_REMOVE(diropargs) = 10; + + nfsstat + NFSPROC_RENAME(renameargs) = 11; + + nfsstat + NFSPROC_LINK(linkargs) = 12; + + nfsstat + NFSPROC_SYMLINK(symlinkargs) = 13; + + diropres + NFSPROC_MKDIR(createargs) = 14; + + nfsstat + NFSPROC_RMDIR(diropargs) = 15; + + readdirres + NFSPROC_READDIR(readdirargs) = 16; + + statfsres + NFSPROC_STATFS(nfs_fh) = 17; + } = 2; +} = 100003; +#ifdef WANT_NFS3 +program NFS3_PROGRAM { + version NFS_V3 { + void + NFSPROC3_NULL(void) = 0; + + GETATTR3res + NFSPROC3_GETATTR(GETATTR3args) = 1; + + SETATTR3res + NFSPROC3_SETATTR(SETATTR3args) = 2; + + LOOKUP3res + NFSPROC3_LOOKUP(LOOKUP3args) = 3; + + ACCESS3res + NFSPROC3_ACCESS(ACCESS3args) = 4; + + READLINK3res + NFSPROC3_READLINK(READLINK3args) = 5; + + READ3res + NFSPROC3_READ(READ3args) = 6; + + WRITE3res + NFSPROC3_WRITE(WRITE3args) = 7; + + CREATE3res + NFSPROC3_CREATE(CREATE3args) = 8; + + MKDIR3res + NFSPROC3_MKDIR(MKDIR3args) = 9; + + SYMLINK3res + NFSPROC3_SYMLINK(SYMLINK3args) = 10; + + MKNOD3res + NFSPROC3_MKNOD(MKNOD3args) = 11; + + REMOVE3res + NFSPROC3_REMOVE(REMOVE3args) = 12; + + RMDIR3res + NFSPROC3_RMDIR(RMDIR3args) = 13; + + RENAME3res + NFSPROC3_RENAME(RENAME3args) = 14; + + LINK3res + NFSPROC3_LINK(LINK3args) = 15; + + READDIR3res + NFSPROC3_READDIR(READDIR3args) = 16; + + READDIRPLUS3res + NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17; + + FSSTAT3res + NFSPROC3_FSSTAT(FSSTAT3args) = 18; + + FSINFO3res + NFSPROC3_FSINFO(FSINFO3args) = 19; + + PATHCONF3res + NFSPROC3_PATHCONF(PATHCONF3args) = 20; + + COMMIT3res + NFSPROC3_COMMIT(COMMIT3args) = 21; + } = 3; +} = 100003; +#endif + diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis.x b/lib/libc/include/any-freebsd-any/rpcsvc/nis.x new file mode 100644 index 000000000000..ee822d039b86 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis.x @@ -0,0 +1,460 @@ +%/*- +% * Copyright (c) 2010, Oracle America, Inc. +% * +% * Redistribution and use in source and binary forms, with or without +% * modification, are permitted provided that the following conditions are +% * met: +% * +% * * Redistributions of source code must retain the above copyright +% * notice, this list of conditions and the following disclaimer. +% * * Redistributions in binary form must reproduce the above +% * copyright notice, this list of conditions and the following +% * disclaimer in the documentation and/or other materials +% * provided with the distribution. +% * * Neither the name of the "Oracle America, Inc." nor the names of its +% * contributors may be used to endorse or promote products derived +% * from this software without specific prior written permission. +% * +% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +% * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +% * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +% * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +% * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +% * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +% * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +% * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +% */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +/* + * From 4.1 : @(#)nis.x 1.61 Copyright 1989 Sun Microsystems + * + * RPC Language Protocol description file for NIS Plus + * This version : 1.61 + * Last Modified : 3/19/91 + */ +#ifdef RPC_HDR +%/* +% * nis.h +% * +% * This file is the main include file for NIS clients. It contains +% * both the client library function defines and the various data +% * structures used by the NIS service. It includes the file nis_tags.h +% * which defines the tag values. This allows the tags to change without +% * having to change the nis.x file. +% * +% * NOTE : DO NOT EDIT THIS FILE! It is automatically generated when +% * rpcgen is run on the nis.x file. Note that there is a +% * simple sed script to remove some unneeded lines. (See the +% * Makefile target nis.h) +% * +% */ +%#include +#endif + +/* This gets stuffed into the source files. */ +#if RPC_HDR +%#include +#endif +/* + * This is just pointless. + */ +#ifdef SUN_STUPIDITY +#if RPC_SVC +%#include "nis_svc.h" +#endif +#endif + +/* Include the RPC Language description of NIS objects */ +#include "nis_object.x" + +/* Errors that can be returned by the service */ +enum nis_error { + NIS_SUCCESS = 0, /* A-ok, let's rock n roll */ + NIS_S_SUCCESS = 1, /* Name found (maybe) */ + NIS_NOTFOUND = 2, /* Name definitely not found */ + NIS_S_NOTFOUND = 3, /* Name maybe not found */ + NIS_CACHEEXPIRED = 4, /* Name exists but cache out of date */ + NIS_NAMEUNREACHABLE = 5, /* Can't get there from here */ + NIS_UNKNOWNOBJ = 6, /* Object type is bogus */ + NIS_TRYAGAIN = 7, /* I'm busy, call back */ + NIS_SYSTEMERROR = 8, /* Out of band failure */ + NIS_CHAINBROKEN = 9, /* First/Next warning */ + NIS_PERMISSION = 10, /* Not enough permission to access */ + NIS_NOTOWNER = 11, /* You don't own it, sorry */ + NIS_NOT_ME = 12, /* I don't serve this name */ + NIS_NOMEMORY = 13, /* Outta VM! Help! */ + NIS_NAMEEXISTS = 14, /* Can't create over another name */ + NIS_NOTMASTER = 15, /* I'm justa secondaray, don't ask me */ + NIS_INVALIDOBJ = 16, /* Object is broken somehow */ + NIS_BADNAME = 17, /* Unparsable name */ + NIS_NOCALLBACK = 18, /* Couldn't talk to call back proc */ + NIS_CBRESULTS = 19, /* Results being called back to you */ + NIS_NOSUCHNAME = 20, /* Name unknown */ + NIS_NOTUNIQUE = 21, /* Value is not uniques (entry) */ + NIS_IBMODERROR = 22, /* Inf. Base. Modify error. */ + NIS_NOSUCHTABLE = 23, /* Name for table was wrong */ + NIS_TYPEMISMATCH = 24, /* Entry and table type mismatch */ + NIS_LINKNAMEERROR = 25, /* Link points to bogus name */ + NIS_PARTIAL = 26, /* Partial success, found table */ + NIS_TOOMANYATTRS = 27, /* Too many attributes */ + NIS_RPCERROR = 28, /* RPC error encountered */ + NIS_BADATTRIBUTE = 29, /* Bad or invalid attribute */ + NIS_NOTSEARCHABLE = 30, /* Non-searchable object searched */ + NIS_CBERROR = 31, /* Error during callback (svc crash) */ + NIS_FOREIGNNS = 32, /* Foreign Namespace */ + NIS_BADOBJECT = 33, /* Malformed object structure */ + NIS_NOTSAMEOBJ = 34, /* Object swapped during deletion */ + NIS_MODFAIL = 35, /* Failure during a Modify. */ + NIS_BADREQUEST = 36, /* Illegal query for table */ + NIS_NOTEMPTY = 37, /* Attempt to remove a non-empty tbl */ + NIS_COLDSTART_ERR = 38, /* Error accesing the cold start file */ + NIS_RESYNC = 39, /* Transaction log too far out of date */ + NIS_FAIL = 40, /* NIS operation failed. */ + NIS_UNAVAIL = 41, /* NIS+ service is unavailable (client) */ + NIS_RES2BIG = 42, /* NIS+ result too big for datagram */ + NIS_SRVAUTH = 43, /* NIS+ server wasn't authenticated. */ + NIS_CLNTAUTH = 44, /* NIS+ Client wasn't authenticated. */ + NIS_NOFILESPACE = 45, /* NIS+ server ran out of disk space */ + NIS_NOPROC = 46, /* NIS+ server couldn't create new proc */ + NIS_DUMPLATER = 47 /* NIS+ server already has dump child */ +}; + + +/* + * Structure definitions for the parameters and results of the actual + * NIS RPC calls. + * + * This is the standard result (in the protocol) of most of the nis + * requests. + */ + +struct nis_result { + nis_error status; /* Status of the response */ + nis_object objects<>; /* objects found */ + netobj cookie; /* Cookie Data */ + u_long zticks; /* server ticks */ + u_long dticks; /* DBM ticks. */ + u_long aticks; /* Cache (accel) ticks */ + u_long cticks; /* Client ticks */ +}; + +/* + * A Name Service request + * This request is used to access the name space, ns_name is the name + * of the object within the namespace and the object is it's value, for + * add/modify, a copy of the original for remove. + */ + +struct ns_request { + nis_name ns_name; /* Name in the NIS name space */ + nis_object ns_object<1>; /* Optional Object (add/remove) */ +}; + +/* + * An information base request + * This request includes the NIS name of the table we wish to search, the + * search criteria in the form of attribute/value pairs and an optional + * callback program number. If the callback program number is provided + * the server will send back objects one at a time, otherwise it will + * return them all in the response. + */ + +struct ib_request { + nis_name ibr_name; /* The name of the Table */ + nis_attr ibr_srch<>; /* The search critereia */ + u_long ibr_flags; /* Optional flags */ + nis_object ibr_obj<1>; /* optional object (add/modify) */ + nis_server ibr_cbhost<1>; /* Optional callback info */ + u_long ibr_bufsize; /* Optional first/next bufsize */ + netobj ibr_cookie; /* The first/next cookie */ +}; + +/* + * This argument to the PING call notifies the replicas that something in + * a directory has changed and this is it's timestamp. The replica will use + * the timestamp to determine if its resync operation was successful. + */ +struct ping_args { + nis_name dir; /* Directory that had the change */ + u_long stamp; /* timestamp of the transaction */ +}; + +/* + * These are the type of entries that are stored in the transaction log, + * note that modifications will appear as two entries, for names, they have + * an "OLD" entry followed by a "NEW" entry. For entries in tables, there + * is a remove followed by an add. It is done this way so that we can read + * the log backwards to back out transactions and forwards to propagate + * updates. + */ +enum log_entry_t { + LOG_NOP = 0, + ADD_NAME = 1, /* Name Added to name space */ + REM_NAME = 2, /* Name removed from name space */ + MOD_NAME_OLD = 3, /* Name was modified in the name space */ + MOD_NAME_NEW = 4, /* Name was modified in the name space */ + ADD_IBASE = 5, /* Entry added to information base */ + REM_IBASE = 6, /* Entry removed from information base */ + MOD_IBASE = 7, /* Entry was modified in information base */ + UPD_STAMP = 8 /* Update timestamp (used as fenceposts) */ +}; + +/* + * This result is returned from the name service when it is requested to + * dump logged entries from its transaction log. Information base updates + * will have the name of the information base in the le_name field and + * a canonical set of attribute/value pairs to fully specify the entry's + * 'name'. + */ +struct log_entry { + u_long le_time; /* Time in seconds */ + log_entry_t le_type; /* Type of log entry */ + nis_name le_princp; /* Principal making the change */ + nis_name le_name; /* Name of table/dir involved */ + nis_attr le_attrs<>; /* List of AV pairs. */ + nis_object le_object; /* Actual object value */ +}; + +struct log_result { + nis_error lr_status; /* The status itself */ + netobj lr_cookie; /* Used by the dump callback */ + log_entry lr_entries<>; /* zero or more entries */ +}; + +struct cp_result { + nis_error cp_status; /* Status of the checkpoint */ + u_long cp_zticks; /* Service 'ticks' */ + u_long cp_dticks; /* Database 'ticks' */ +}; + +/* + * This structure defines a generic NIS tag list. The taglist contains + * zero or tags, each of which is a type and a value. (u_long). + * These are used to report statistics (see tag definitions below) + * and to set or reset state variables. + */ +struct nis_tag { + u_long tag_type; /* Statistic tag (may vary) */ + string tag_val<1024>; /* Statistic value may also vary */ +}; + +struct nis_taglist { + nis_tag tags<>; /* List of tags */ +}; + +struct dump_args { + nis_name da_dir; /* Directory to dump */ + u_long da_time; /* From this timestamp */ + nis_server da_cbhost<1>; /* Callback to use. */ +}; + +struct fd_args { + nis_name dir_name; /* The directory we're looking for */ + nis_name requester; /* Host principal name for signature */ +}; + +struct fd_result { + nis_error status; /* Status returned by function */ + nis_name source; /* Source of this answer */ + opaque dir_data<>; /* Directory Data (XDR'ed) */ + opaque signature<>; /* Signature of the source */ +}; + + +/* + * What's going on here? Well, it's like this. When the service + * is being compiled it wants to have the service definition specific + * info included, and when the client is being compiled it wants that + * info. This includes the appropriate file which was generated by + * make in the protocols directory (probably /usr/include/rpcsvc). + * + * Uhm... guys? With RPC, you aren't supposed to have separate + * server-specific and client-specific header files. You have one header + * file that's suitable for both. If your code doesn't work using just + * the one header file, I submit to you that it's broken. + * -Bill + */ +#ifdef SUN_STUPIDITY +#ifdef RPC_SVC +%#include "nis_svc.h" +#endif +#ifdef RPC_CLNT +%#include "nis_clnt.h" +#endif +#endif + +program NIS_PROG { + + /* RPC Language description of the NIS+ protocol */ + version NIS_VERSION { + /* The name service functions */ + nis_result NIS_LOOKUP(ns_request) = 1; + nis_result NIS_ADD(ns_request) = 2; + nis_result NIS_MODIFY(ns_request) = 3; + nis_result NIS_REMOVE(ns_request) = 4; + + /* The information base functions */ + nis_result NIS_IBLIST(ib_request) = 5; + nis_result NIS_IBADD(ib_request) = 6; + nis_result NIS_IBMODIFY(ib_request) = 7; + nis_result NIS_IBREMOVE(ib_request) = 8; + nis_result NIS_IBFIRST(ib_request) = 9; + nis_result NIS_IBNEXT(ib_request) = 10; + + /* NIS Administrative functions */ + fd_result NIS_FINDDIRECTORY(fd_args) = 12; + + /* If fetch and optionally reset statistics */ + nis_taglist NIS_STATUS(nis_taglist) = 14; + + /* Dump changes to directory since time in da_time */ + log_result NIS_DUMPLOG(dump_args) = 15; + + /* Dump contents of directory named */ + log_result NIS_DUMP(dump_args) = 16; + + /* Check status of callback thread */ + bool NIS_CALLBACK(netobj) = 17; + + /* Return last update time for named dir */ + u_long NIS_CPTIME(nis_name) = 18; + + /* Checkpoint directory or table named */ + cp_result NIS_CHECKPOINT(nis_name) = 19; + + /* Send 'status changed' ping to replicates */ + void NIS_PING(ping_args) = 20; + + /* Modify server behaviour (such as debugging) */ + nis_taglist NIS_SERVSTATE(nis_taglist) = 21; + + /* Create a Directory */ + nis_error NIS_MKDIR(nis_name) = 22; + + /* Remove a Directory */ + nis_error NIS_RMDIR(nis_name) = 23; + + /* Update public keys of a directory object */ + nis_error NIS_UPDKEYS(nis_name) = 24; + } = 3; +} = 100300; + +/* + * Included below are the defines that become part of nis.h, + * they are technically not part of the protocol, but do define + * key aspects of the implementation and are therefore useful + * in building a conforming server or client. + */ +#if RPC_HDR +%/* +% * Generic "hash" datastructures, used by all types of hashed data. +% */ +%struct nis_hash_data { +% nis_name name; /* NIS name of hashed item */ +% int keychain; /* It's hash key (for pop) */ +% struct nis_hash_data *next; /* Hash collision pointer */ +% struct nis_hash_data *prv_item; /* A serial, doubly linked list */ +% struct nis_hash_data *nxt_item; /* of items in the hash table */ +%}; +%typedef struct nis_hash_data NIS_HASH_ITEM; +% +%struct nis_hash_table { +% NIS_HASH_ITEM *keys[64]; /* A hash table of items */ +% NIS_HASH_ITEM *first; /* The first "item" in serial list */ +%}; +%typedef struct nis_hash_table NIS_HASH_TABLE; +% +%/* Structure for storing dynamically allocated static data */ +%struct nis_sdata { +% void *buf; /* Memory allocation pointer */ +% u_long size; /* Buffer size */ +%}; +% +%/* Generic client creating flags */ +%#define ZMH_VC 1 +%#define ZMH_DG 2 +%#define ZMH_AUTH 4 +% +%/* Testing Access rights for objects */ +% +%#define NIS_READ_ACC 1 +%#define NIS_MODIFY_ACC 2 +%#define NIS_CREATE_ACC 4 +%#define NIS_DESTROY_ACC 8 +%/* Test macros. a == access rights, m == desired rights. */ +%#define WORLD(a, m) (((a) & (m)) != 0) +%#define GROUP(a, m) (((a) & ((m) << 8)) != 0) +%#define OWNER(a, m) (((a) & ((m) << 16)) != 0) +%#define NOBODY(a, m) (((a) & ((m) << 24)) != 0) +% +%#define OATYPE(d, n) (((d)->do_armask.do_armask_val+n)->oa_otype) +%#define OARIGHTS(d, n) (((d)->do_armask.do_armask_val+n)->oa_rights) +%#define WORLD_DEFAULT (NIS_READ_ACC) +%#define GROUP_DEFAULT (NIS_READ_ACC << 8) +%#define OWNER_DEFAULT ((NIS_READ_ACC + NIS_MODIFY_ACC + NIS_CREATE_ACC + NIS_DESTROY_ACC) << 16) +%#define DEFAULT_RIGHTS (WORLD_DEFAULT | GROUP_DEFAULT | OWNER_DEFAULT) +% +%/* Result manipulation defines ... */ +%#define NIS_RES_NUMOBJ(x) ((x)->objects.objects_len) +%#define NIS_RES_OBJECT(x) ((x)->objects.objects_val) +%#define NIS_RES_COOKIE(x) ((x)->cookie) +%#define NIS_RES_STATUS(x) ((x)->status) +% +%/* These defines make getting at the variant part of the object easier. */ +%#define TA_data zo_data.objdata_u.ta_data +%#define EN_data zo_data.objdata_u.en_data +%#define DI_data zo_data.objdata_u.di_data +%#define LI_data zo_data.objdata_u.li_data +%#define GR_data zo_data.objdata_u.gr_data +% +%#define __type_of(o) ((o)->zo_data.zo_type) +% +%/* Declarations for the internal subroutines in nislib.c */ +%enum name_pos {SAME_NAME, HIGHER_NAME, LOWER_NAME, NOT_SEQUENTIAL, BAD_NAME}; +%typedef enum name_pos name_pos; +% +%/* +% * Defines for getting at column data in entry objects. Because RPCGEN +% * generates some rather wordy structures, we create some defines that +% * collapse the needed keystrokes to access a particular value using +% * these definitions they take an nis_object *, and an int and return +% * a u_char * for Value, and an int for length. +% */ +%#define ENTRY_VAL(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val +%#define ENTRY_LEN(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len +% +%#ifdef __cplusplus +%} +%#endif +% +%/* Prototypes, and extern declarations for the NIS library functions. */ +%#include +%#endif /* __NIS_RPCGEN_H */ +%/* EDIT_START */ +% +%/* +% * nis_3.h +% * +% * This file contains definitions that are only of interest to the actual +% * service daemon and client stubs. Normal users of NIS will not include +% * this file. +% * +% * NOTE : This include file is automatically created by a combination +% * of rpcgen and sed. DO NOT EDIT IT, change the nis.x file instead +% * and then remake this file. +% */ +%#ifndef __nis_3_h +%#define __nis_3_h +%#ifdef __cplusplus +%extern "C" { +%#endif +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis_cache.x b/lib/libc/include/any-freebsd-any/rpcsvc/nis_cache.x new file mode 100644 index 000000000000..6edaea92c38b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis_cache.x @@ -0,0 +1,85 @@ +%/* +% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for +% * unrestricted use provided that this legend is included on all tape +% * media and as a part of the software program in whole or part. Users +% * may copy or modify Sun RPC without charge, but are not authorized +% * to license or distribute it to anyone else except as part of a product or +% * program developed by the user or with the express written consent of +% * Sun Microsystems, Inc. +% * +% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE +% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR +% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +% * +% * Sun RPC is provided with no support and without any obligation on the +% * part of Sun Microsystems, Inc. to assist in its use, correction, +% * modification or enhancement. +% * +% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE +% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC +% * OR ANY PART THEREOF. +% * +% * In no event will Sun Microsystems, Inc. be liable for any lost revenue +% * or profits or other special, indirect and consequential damages, even if +% * Sun has been advised of the possibility of such damages. +% * +% * Sun Microsystems, Inc. +% * 2550 Garcia Avenue +% * Mountain View, California 94043 +% */ + +/* + * nis_cache.x + * + * Copyright (c) 1988-1992 Sun Microsystems Inc + * All Rights Reserved. + */ + +/* From: %#pragma ident "@(#)nis_cache.x 1.11 94/05/03 SMI" */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +#ifdef RPC_HDR +%#include +%#include +% +%/* default cache file */ +%#define CACHEFILE "/var/nis/NIS_SHARED_DIRCACHE" +% +%/* clients have to read-lock the cache file, and SVR4 locking requires that */ +%/* the file be writable, but we don't want a world-writable cache file. */ +%/* So... everyone agrees to use a different, world-writable file for the */ +%/* locking operations, but the data is in CACHEFILE. */ +%#define CACHELOCK "/usr/tmp/.NIS_DIR_CACHELOCK" +% +%/* the file containing one trusted XDR'ed directory object. +% * This has to be present for the system to work. +% */ +%#define COLD_START_FILE "/var/nis/NIS_COLD_START" +% +%enum pc_status {HIT, MISS, NEAR_MISS}; +% +%extern int __nis_debuglevel; +% +% +#endif + +#ifdef RPC_CLNT +#ifdef SOLARIS +%#include "../gen/nis_clnt.h" +#else +%#include "nis.h" +#endif +#endif + +program CACHEPROG { + version CACHE_VER_1 { + void NIS_CACHE_ADD_ENTRY(fd_result) = 1; + void NIS_CACHE_REMOVE_ENTRY(directory_obj) = 2; + void NIS_CACHE_READ_COLDSTART(void) = 3; + void NIS_CACHE_REFRESH_ENTRY(string<>) = 4; + } = 1; +} = 100301; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis_callback.x b/lib/libc/include/any-freebsd-any/rpcsvc/nis_callback.x new file mode 100644 index 000000000000..74a555b4f16b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis_callback.x @@ -0,0 +1,75 @@ +%/*- +% * Copyright (c) 2010, Oracle America, Inc. +% * +% * Redistribution and use in source and binary forms, with or without +% * modification, are permitted provided that the following conditions are +% * met: +% * +% * * Redistributions of source code must retain the above copyright +% * notice, this list of conditions and the following disclaimer. +% * * Redistributions in binary form must reproduce the above +% * copyright notice, this list of conditions and the following +% * disclaimer in the documentation and/or other materials +% * provided with the distribution. +% * * Neither the name of the "Oracle America, Inc." nor the names of its +% * contributors may be used to endorse or promote products derived +% * from this software without specific prior written permission. +% * +% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +% * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +% * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +% * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +% * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +% * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +% * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +% * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +% */ + +/* + * nis_callback.x + * + * Copyright (c) 1988-1992 Sun Microsystems Inc + * All Rights Reserved. + */ + +/* From: %#pragma ident "@(#)nis_callback.x 1.7 94/05/03 SMI" */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +/* + * "@(#)zns_cback.x 1.2 90/09/10 Copyr 1990 Sun Micro" + * + * RPCL description of the Callback Service. + */ + +#ifdef RPC_HDR +%#include +#endif +#ifdef RPC_XDR +#ifdef SOLARIS +%#include "nis_clnt.h" +#else +%#include "nis.h" +#endif +#endif + +typedef nis_object *obj_p; + +struct cback_data { + obj_p entries<>; /* List of objects */ +}; + +program CB_PROG { + version CB_VERS { + bool CBPROC_RECEIVE(cback_data) = 1; + void CBPROC_FINISH(void) = 2; + void CBPROC_ERROR(nis_error) = 3; + } = 1; +} = 100302; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis_db.h b/lib/libc/include/any-freebsd-any/rpcsvc/nis_db.h new file mode 100644 index 000000000000..9dcc78376b1a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis_db.h @@ -0,0 +1,135 @@ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + * + * $FreeBSD$ + */ + +/* + * Copyright (c) 1991, by Sun Microsystems Inc. + */ + +/* + * This header file defines the interface to the NIS database. All + * implementations of the database must export at least these routines. + * They must also follow the conventions set herein. See the implementors + * guide for specific semantics that are required. + */ + +#ifndef _RPCSVC_NIS_DB_H +#define _RPCSVC_NIS_DB_H + + +/* From: #pragma ident "@(#)nis_db.h 1.8 94/05/03 SMI" */ + +/* + * Note: although the version of shipped with Solaris + * 2.5/2.5.x is actually older than this one (according to the ident + * string), it contains changes and a few added functions. Those changes + * have been hand merged into this file to bring it up to date. + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum db_status { + DB_SUCCESS = 0, + DB_NOTFOUND = 1, + DB_NOTUNIQUE = 2, + DB_BADTABLE = 3, + DB_BADQUERY = 4, + DB_BADOBJECT = 5, + DB_MEMORY_LIMIT = 6, + DB_STORAGE_LIMIT = 7, + DB_INTERNAL_ERROR = 8 +}; +typedef enum db_status db_status; + +enum db_action { + DB_LOOKUP = 0, + DB_REMOVE = 1, + DB_ADD = 2, + DB_FIRST = 3, + DB_NEXT = 4, + DB_ALL = 5, + DB_RESET_NEXT = 6 +}; +typedef enum db_action db_action; + +typedef entry_obj *entry_object_p; + +typedef struct { + u_int db_next_desc_len; + char *db_next_desc_val; +} db_next_desc; + +struct db_result { + db_status status; + db_next_desc nextinfo; + struct { + u_int objects_len; + entry_object_p *objects_val; + } objects; + long ticks; +}; +typedef struct db_result db_result; + +/* + * Prototypes for the database functions. + */ + +extern bool_t db_initialize(char *); +#ifdef ORIGINAL_DECLS +extern bool_t db_create_table(char *, table_obj *); +extern bool_t db_destroy_table(char *); +#else +extern db_status db_create_table(char *, table_obj *); +extern db_status db_destroy_table(char *); +#endif +extern db_result *db_first_entry(char *, int, nis_attr *); +extern db_result *db_next_entry(char *, db_next_desc *); +extern db_result *db_reset_next_entry(char *, db_next_desc *); +extern db_result *db_list_entries(char *, int, nis_attr *); +extern db_result *db_add_entry(char *, int, nis_attr *, entry_obj *); +extern db_result *db_remove_entry(char *, int, nis_attr *); +extern db_status db_checkpoint(char *); +extern db_status db_standby(char *); +#ifndef ORIGINAL_DECLS +extern db_status db_table_exists(char *); +extern db_status db_unload_table(char *); +extern void db_free_result(db_result *); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _RPCSVC_NIS_DB_H */ diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis_object.x b/lib/libc/include/any-freebsd-any/rpcsvc/nis_object.x new file mode 100644 index 000000000000..f63cf938571a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis_object.x @@ -0,0 +1,319 @@ +%/*- +% * Copyright (c) 2010, Oracle America, Inc. +% * +% * Redistribution and use in source and binary forms, with or without +% * modification, are permitted provided that the following conditions are +% * met: +% * +% * * Redistributions of source code must retain the above copyright +% * notice, this list of conditions and the following disclaimer. +% * * Redistributions in binary form must reproduce the above +% * copyright notice, this list of conditions and the following +% * disclaimer in the documentation and/or other materials +% * provided with the distribution. +% * * Neither the name of the "Oracle America, Inc." nor the names of its +% * contributors may be used to endorse or promote products derived +% * from this software without specific prior written permission. +% * +% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +% * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +% * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +% * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +% * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +% * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +% * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +% * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +% */ + +/* + * nis_object.x + * + * Copyright (c) 1988-1992 Sun Microsystems Inc + * All Rights Reserved. + */ + +/* $FreeBSD$ */ +/* From: %#pragma ident "@(#)nis_object.x 1.10 94/05/03 SMI" */ + +#if RPC_HDR +% +%#ifndef __nis_object_h +%#define __nis_object_h +% +#endif +/* + * This file defines the format for a NIS object in RPC language. + * It is included by the main .x file and the database access protocol + * file. It is common because both of them need to deal with the same + * type of object. Generating the actual code though is a bit messy because + * the nis.x file and the nis_dba.x file will generate xdr routines to + * encode/decode objects when only one set is needed. Such is life when + * one is using rpcgen. + * + * Note, the protocol doesn't specify any limits on such things as + * maximum name length, number of attributes, etc. These are enforced + * by the database backend. When you hit them you will no. Also see + * the db_getlimits() function for fetching the limit values. + * + */ + +/* Some manifest constants, chosen to maximize flexibility without + * plugging the wire full of data. + */ +const NIS_MAXSTRINGLEN = 255; +const NIS_MAXNAMELEN = 1024; +const NIS_MAXATTRNAME = 32; +const NIS_MAXATTRVAL = 2048; +const NIS_MAXCOLUMNS = 64; +const NIS_MAXATTR = 16; +const NIS_MAXPATH = 1024; +const NIS_MAXREPLICAS = 128; +const NIS_MAXLINKS = 16; + +const NIS_PK_NONE = 0; /* no public key (unix/sys auth) */ +const NIS_PK_DH = 1; /* Public key is Diffie-Hellman type */ +const NIS_PK_RSA = 2; /* Public key if RSA type */ +const NIS_PK_KERB = 3; /* Use kerberos style authentication */ + +/* + * The fundamental name type of NIS. The name may consist of two parts, + * the first being the fully qualified name, and the second being an + * optional set of attribute/value pairs. + */ +struct nis_attr { + string zattr_ndx<>; /* name of the index */ + opaque zattr_val<>; /* Value for the attribute. */ +}; + +typedef string nis_name<>; /* The NIS name itself. */ + +/* NIS object types are defined by the following enumeration. The numbers + * they use are based on the following scheme : + * 0 - 1023 are reserved for Sun, + * 1024 - 2047 are defined to be private to a particular tree. + * 2048 - 4095 are defined to be user defined. + * 4096 - ... are reserved for future use. + */ + +enum zotypes { + BOGUS_OBJ = 0, /* Uninitialized object structure */ + NO_OBJ = 1, /* NULL object (no data) */ + DIRECTORY_OBJ = 2, /* Directory object describing domain */ + GROUP_OBJ = 3, /* Group object (a list of names) */ + TABLE_OBJ = 4, /* Table object (a database schema) */ + ENTRY_OBJ = 5, /* Entry object (a database record) */ + LINK_OBJ = 6, /* A name link. */ + PRIVATE_OBJ = 7 /* Private object (all opaque data) */ +}; + +/* + * The types of Name services NIS knows about. They are enumerated + * here. The Binder code will use this type to determine if it has + * a set of library routines that will access the indicated name service. + */ +enum nstype { + UNKNOWN = 0, + NIS = 1, /* Nis Plus Service */ + SUNYP = 2, /* Old NIS Service */ + IVY = 3, /* Nis Plus Plus Service */ + DNS = 4, /* Domain Name Service */ + X500 = 5, /* ISO/CCCIT X.500 Service */ + DNANS = 6, /* Digital DECNet Name Service */ + XCHS = 7, /* Xerox ClearingHouse Service */ + CDS= 8 +}; + +/* + * DIRECTORY - The name service object. These objects identify other name + * servers that are serving some portion of the name space. Each has a + * type associated with it. The resolver library will note whether or not + * is has the needed routines to access that type of service. + * The oarmask structure defines an access rights mask on a per object + * type basis for the name spaces. The only bits currently used are + * create and destroy. By enabling or disabling these access rights for + * a specific object type for a one of the accessor entities (owner, + * group, world) the administrator can control what types of objects + * may be freely added to the name space and which require the + * administrator's approval. + */ +struct oar_mask { + u_long oa_rights; /* Access rights mask */ + zotypes oa_otype; /* Object type */ +}; + +struct endpoint { + string uaddr<>; + string family<>; /* Transport family (INET, OSI, etc) */ + string proto<>; /* Protocol (TCP, UDP, CLNP, etc) */ +}; + +/* + * Note: pkey is a netobj which is limited to 1024 bytes which limits the + * keysize to 8192 bits. This is consider to be a reasonable limit for + * the expected lifetime of this service. + */ +struct nis_server { + nis_name name; /* Principal name of the server */ + endpoint ep<>; /* Universal addr(s) for server */ + u_long key_type; /* Public key type */ + netobj pkey; /* server's public key */ +}; + +struct directory_obj { + nis_name do_name; /* Name of the directory being served */ + nstype do_type; /* one of NIS, DNS, IVY, YP, or X.500 */ + nis_server do_servers<>; /* <0> == Primary name server */ + u_long do_ttl; /* Time To Live (for caches) */ + oar_mask do_armask<>; /* Create/Destroy rights by object type */ +}; + +/* + * ENTRY - This is one row of data from an information base. + * The type value is used by the client library to convert the entry to + * it's internal structure representation. The Table name is a back pointer + * to the table where the entry is stored. This allows the client library + * to determine where to send a request if the client wishes to change this + * entry but got to it through a LINK rather than directly. + * If the entry is a "standalone" entry then this field is void. + */ +const EN_BINARY = 1; /* Indicates value is binary data */ +const EN_CRYPT = 2; /* Indicates the value is encrypted */ +const EN_XDR = 4; /* Indicates the value is XDR encoded */ +const EN_MODIFIED = 8; /* Indicates entry is modified. */ +const EN_ASN1 = 64; /* Means contents use ASN.1 encoding */ + +struct entry_col { + u_long ec_flags; /* Flags for this value */ + opaque ec_value<>; /* It's textual value */ +}; + +struct entry_obj { + string en_type<>; /* Type of entry such as "passwd" */ + entry_col en_cols<>; /* Value for the entry */ +}; + +/* + * GROUP - The group object contains a list of NIS principal names. Groups + * are used to authorize principals. Each object has a set of access rights + * for members of its group. Principal names in groups are in the form + * name.directory and recursive groups are expressed as @groupname.directory + */ +struct group_obj { + u_long gr_flags; /* Flags controlling group */ + nis_name gr_members<>; /* List of names in group */ +}; + +/* + * LINK - This is the LINK object. It is quite similar to a symbolic link + * in the UNIX filesystem. The attributes in the main object structure are + * relative to the LINK data and not what it points to (like the file system) + * "modify" privleges here indicate the right to modify what the link points + * at and not to modify that actual object pointed to by the link. + */ +struct link_obj { + zotypes li_rtype; /* Real type of the object */ + nis_attr li_attrs<>; /* Attribute/Values for tables */ + nis_name li_name; /* The object's real NIS name */ +}; + +/* + * TABLE - This is the table object. It implements a simple + * data base that applications and use for configuration or + * administration purposes. The role of the table is to group together + * a set of related entries. Tables are the simple database component + * of NIS. Like many databases, tables are logically divided into columns + * and rows. The columns are labeled with indexes and each ENTRY makes + * up a row. Rows may be addressed within the table by selecting one + * or more indexes, and values for those indexes. Each row which has + * a value for the given index that matches the desired value is returned. + * Within the definition of each column there is a flags variable, this + * variable contains flags which determine whether or not the column is + * searchable, contains binary data, and access rights for the entry objects + * column value. + */ + +const TA_BINARY = 1; /* Means table data is binary */ +const TA_CRYPT = 2; /* Means value should be encrypted */ +const TA_XDR = 4; /* Means value is XDR encoded */ +const TA_SEARCHABLE = 8; /* Means this column is searchable */ +const TA_CASE = 16; /* Means this column is Case Sensitive */ +const TA_MODIFIED = 32; /* Means this columns attrs are modified*/ +const TA_ASN1 = 64; /* Means contents use ASN.1 encoding */ + +struct table_col { + string tc_name<64>; /* Column Name */ + u_long tc_flags; /* control flags */ + u_long tc_rights; /* Access rights mask */ +}; + +struct table_obj { + string ta_type<64>; /* Table type such as "passwd" */ + int ta_maxcol; /* Total number of columns */ + u_char ta_sep; /* Separator character */ + table_col ta_cols<>; /* The number of table indexes */ + string ta_path<>; /* A search path for this table */ +}; + +/* + * This union joins together all of the currently known objects. + */ +union objdata switch (zotypes zo_type) { + case DIRECTORY_OBJ : + struct directory_obj di_data; + case GROUP_OBJ : + struct group_obj gr_data; + case TABLE_OBJ : + struct table_obj ta_data; + case ENTRY_OBJ: + struct entry_obj en_data; + case LINK_OBJ : + struct link_obj li_data; + case PRIVATE_OBJ : + opaque po_data<>; + case NO_OBJ : + void; + case BOGUS_OBJ : + void; + default : + void; +}; + +/* + * This is the basic NIS object data type. It consists of a generic part + * which all objects contain, and a specialized part which varies depending + * on the type of the object. All of the specialized sections have been + * described above. You might have wondered why they all start with an + * integer size, followed by the useful data. The answer is, when the + * server doesn't recognize the type returned it treats it as opaque data. + * And the definition for opaque data is {int size; char *data;}. In this + * way, servers and utility routines that do not understand a given type + * may still pass it around. One has to be careful in setting + * this variable accurately, it must take into account such things as + * XDR padding of structures etc. The best way to set it is to note one's + * position in the XDR encoding stream, encode the structure, look at the + * new position and calculate the size. + */ +struct nis_oid { + u_long ctime; /* Time of objects creation */ + u_long mtime; /* Time of objects modification */ +}; + +struct nis_object { + nis_oid zo_oid; /* object identity verifier. */ + nis_name zo_name; /* The NIS name for this object */ + nis_name zo_owner; /* NIS name of object owner. */ + nis_name zo_group; /* NIS name of access group. */ + nis_name zo_domain; /* The administrator for the object */ + u_long zo_access; /* Access rights (owner, group, world) */ + u_long zo_ttl; /* Object's time to live in seconds. */ + objdata zo_data; /* Data structure for this type */ +}; +#if RPC_HDR +% +%#endif /* if __nis_object_h */ +% +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nis_tags.h b/lib/libc/include/any-freebsd-any/rpcsvc/nis_tags.h new file mode 100644 index 000000000000..55920a0297fd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nis_tags.h @@ -0,0 +1,142 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1991, Sun Microsystems Inc. + */ + +/* + * nis_tags.h + * + * This file contains the tags and statistics definitions. It is + * automatically included by nis.h + */ + +#ifndef _RPCSVC_NIS_TAGS_H +#define _RPCSVC_NIS_TAGS_H + +/* $FreeBSD$ */ +/* From: #pragma ident "@(#)nis_tags.h 1.10 94/05/03 SMI" */ +/* from file: zns_tags.h 1.7 Copyright (c) 1990 Sun Microsystems */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ORIGINAL_DECLS +#define NIS_DIR "data" +#endif + +/* Lookup and List function flags */ +#define FOLLOW_LINKS (1<<0) /* Follow link objects */ +#define FOLLOW_PATH (1<<1) /* Follow the path in a table */ +#define HARD_LOOKUP (1<<2) /* Block until successful */ +#define ALL_RESULTS (1<<3) /* Retrieve all results */ +#define NO_CACHE (1<<4) /* Do not return 'cached' results */ +#define MASTER_ONLY (1<<5) /* Get value only from master server */ +#define EXPAND_NAME (1<<6) /* Expand partitially qualified names */ + +/* Semantic modification for table operations flags */ +#define RETURN_RESULT (1<<7) /* Return resulting object to client */ +#define ADD_OVERWRITE (1<<8) /* Allow overwrites on ADD */ +#define REM_MULTIPLE (1<<9) /* Allow wildcard deletes */ +#define MOD_SAMEOBJ (1<<10) /* Check modified object before write */ +#define ADD_RESERVED (1<<11) /* Spare ADD semantic */ +#define REM_RESERVED (1<<12) /* Spare REM semantic */ +#ifdef ORIGINAL_DECLS +#define MOD_RESERVED (1<<13) /* Spare MOD semantic */ +#else +#define MOD_EXCLUSIVE (1<<13) /* Modify no overwrite on modified keys */ +#endif + +/* Transport specific modifications to the operation */ +#define USE_DGRAM (1<<16) /* Use a datagram transport */ +#define NO_AUTHINFO (1<<17) /* Don't bother attaching auth info */ + +/* + * Declarations for "standard" NIS+ tags + * State variable tags have values 0 - 2047 + * Statistic tags have values 2048 - 65535 + * User Tags have values >2^16 + */ +#define TAG_DEBUG 1 /* set debug level */ +#define TAG_STATS 2 /* Enable/disable statistics */ +#define TAG_GCACHE 3 /* Flush the Group Cache */ +#ifndef ORIGINAL_DECLS +#define TAG_GCACHE_ALL TAG_GCACHE +#endif +#define TAG_DCACHE 4 /* Flush the directory cache */ +#ifndef ORIGINAL_DECLS +#define TAG_DCACHE_ONE TAG_DCACHE +#endif +#define TAG_OCACHE 5 /* Flush the Object Cache */ +#define TAG_SECURE 6 /* Set the security level */ +#ifndef ORIGINAL_DECLS +#define TAG_TCACHE_ONE 7 /* Flush the table cache */ +#define TAG_DCACHE_ALL 8 /* Flush entire directory cache */ +#define TAG_TCACHE_ALL 9 /* Flush entire table cache */ +#define TAG_GCACHE_ONE 10 /* Flush one group object */ +#define TAG_DCACHE_ONE_REFRESH 11 /* Flush and refresh one DO */ +#endif + +#define TAG_OPSTATS 2048 /* NIS+ operations statistics */ +#define TAG_THREADS 2049 /* Child process/thread status */ +#define TAG_HEAP 2050 /* Heap usage statistics */ +#define TAG_UPDATES 2051 /* Updates to this service */ +#define TAG_VISIBLE 2052 /* First update that isn't replicated */ +#define TAG_S_DCACHE 2053 /* Directory cache statistics */ +#define TAG_S_OCACHE 2054 /* Object cache statistics */ +#define TAG_S_GCACHE 2055 /* Group cache statistics */ +#define TAG_S_STORAGE 2056 /* Group cache statistics */ +#define TAG_UPTIME 2057 /* Time that server has been up */ +#ifndef ORIGINAL_DECLS +#define TAG_DIRLIST 2058 /* Dir served by this server */ +#define TAG_NISCOMPAT 2059 /* Whether supports NIS compat mode */ +#define TAG_DNSFORWARDING 2060 /* Whether DNS forwarding supported*/ +#define TAG_SECURITY_LEVEL 2061 /* Security level of the server */ +#define TAG_ROOTSERVER 2062 /* Whether root server */ +#endif + +/* + * Declarations for the Group object flags. Currently + * there are only 3. + */ +#define IMPMEM_GROUPS 1 /* Implicit Membership allowed */ +#define RECURS_GROUPS 2 /* Recursive Groups allowed */ +#define NEGMEM_GROUPS 4 /* Negative Groups allowed */ + +#ifdef __cplusplus +} +#endif + +#endif /* _RPCSVC_NIS_TAGS_H */ diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nislib.h b/lib/libc/include/any-freebsd-any/rpcsvc/nislib.h new file mode 100644 index 000000000000..754affe9a430 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nislib.h @@ -0,0 +1,188 @@ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + * + * $FreeBSD$ + */ + +/* + * Copyright (c) 1991, Sun Microsystems Inc. + */ + +/* + * This file contains the interfaces that are visible in the SunOS 5.x + * implementation of NIS Plus. + */ + +#ifndef _RPCSVC_NISLIB_H +#define _RPCSVC_NISLIB_H + +/* From: #pragma ident "@(#)nislib.h 1.16 94/05/03 SMI" */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct signature { + int signature_len; + char *signature_val; +}; + +extern void nis_freeresult(nis_result *); +extern nis_result * nis_lookup(nis_name, u_long); +extern nis_result * nis_list(nis_name, u_long, + int (*)(nis_name, nis_object *, void *), void *); +extern nis_result * nis_add(nis_name, nis_object *); +extern nis_result * nis_remove(nis_name, nis_object *); +extern nis_result * nis_modify(nis_name, nis_object *); + +extern nis_result * nis_add_entry(nis_name, nis_object *, u_long); +extern nis_result * nis_remove_entry(nis_name, nis_object *, u_long); +extern nis_result * nis_modify_entry(nis_name, nis_object *, u_long); +extern nis_result * nis_first_entry(nis_name); +extern nis_result * nis_next_entry(nis_name, netobj *); + +extern nis_error nis_mkdir(nis_name, nis_server *); +extern nis_error nis_rmdir(nis_name, nis_server *); +extern name_pos nis_dir_cmp(nis_name, nis_name); + +extern nis_name * nis_getnames(nis_name); +extern void nis_freenames(nis_name *); +extern nis_name nis_domain_of(nis_name); +extern nis_name nis_leaf_of(nis_name); +extern nis_name nis_leaf_of_r(const nis_name, char *, size_t); +extern nis_name nis_name_of(nis_name); +extern nis_name nis_local_group(void); +extern nis_name nis_local_directory(void); +extern nis_name nis_local_principal(void); +extern nis_name nis_local_host(void); + +extern void nis_destroy_object(nis_object *); +extern nis_object * nis_clone_object(nis_object *, nis_object *); +extern void nis_print_object(nis_object *); + +extern char * nis_sperrno(nis_error); +extern void nis_perror(nis_error, char *); +extern char * nis_sperror(nis_error, char *); +extern void nis_lerror(nis_error, char *); + +extern void nis_print_group_entry(nis_name); +extern bool_t nis_ismember(nis_name, nis_name); +extern nis_error nis_creategroup(nis_name, u_long); +extern nis_error nis_destroygroup(nis_name); +extern nis_error nis_addmember(nis_name, nis_name); +extern nis_error nis_removemember(nis_name, nis_name); +extern nis_error nis_verifygroup(nis_name); + +extern void nis_freeservlist(nis_server **); +extern nis_server ** nis_getservlist(nis_name); +extern nis_error nis_stats(nis_server *, nis_tag *, int, nis_tag **); +extern nis_error nis_servstate(nis_server *, nis_tag *, int, nis_tag **); +extern void nis_freetags(nis_tag *, int); + +extern nis_result * nis_checkpoint(nis_name); +extern void nis_ping(nis_name, u_long, nis_object *); + +/* + * XXX: PLEASE NOTE THAT THE FOLLOWING FUNCTIONS ARE INTERNAL + * TO NIS+ AND SHOULD NOT BE USED BY ANY APPLICATION PROGRAM. + * THEIR SEMANTICS AND/OR SIGNATURE CAN CHANGE WITHOUT NOTICE. + * SO, PLEASE DO NOT USE THEM. YOU ARE WARNED!!!! + */ + +extern char ** __break_name(nis_name, int *); +extern int __name_distance(char **, char **); +extern nis_result * nis_make_error(nis_error, u_long, u_long, u_long, u_long); +extern nis_attr * __cvt2attr(int *, char **); +extern void nis_free_request(ib_request *); +extern nis_error nis_get_request(nis_name, nis_object *, netobj*, ib_request*); +extern nis_object * nis_read_obj(char *); +extern int nis_write_obj(char *, nis_object *); +extern int nis_in_table(nis_name, NIS_HASH_TABLE *, int *); +extern int nis_insert_item(NIS_HASH_ITEM *, NIS_HASH_TABLE *); +extern NIS_HASH_ITEM * nis_find_item(nis_name, NIS_HASH_TABLE *); +extern NIS_HASH_ITEM * nis_remove_item(nis_name, NIS_HASH_TABLE *); +extern void nis_insert_name(nis_name, NIS_HASH_TABLE *); +extern void nis_remove_name(nis_name, NIS_HASH_TABLE *); +extern CLIENT * nis_make_rpchandle(nis_server *, int, u_long, u_long, u_long, + int, int); +extern void * nis_get_static_storage(struct nis_sdata *, u_long, u_long); +extern char * nis_data(char *); +extern void nis_print_rights(u_long); +extern void nis_print_directory(directory_obj *); +extern void nis_print_group(group_obj *); +extern void nis_print_table(table_obj *); +extern void nis_print_link(link_obj *); +extern void nis_print_entry(entry_obj *); +extern nis_object * nis_get_object(char *, char *, char *, u_long, u_long, + zotypes); +extern nis_server * __nis_init_callback(CLIENT *, + int (*)(nis_name, nis_object *, void *), void *); +extern int nis_getdtblsize(void); +extern int __nis_run_callback(netobj *, u_long, struct timeval *, CLIENT *); + +extern log_result *nis_dumplog(nis_server *, nis_name, u_long); +extern log_result *nis_dump(nis_server *, nis_name, + int (*)(nis_name, nis_object *, void *)); + +extern bool_t __do_ismember(nis_name, nis_name, + nis_result *(*)(nis_name, u_long)); +extern nis_name __nis_map_group(nis_name); +extern nis_name __nis_map_group_r(nis_name, char*, size_t); + +extern nis_error __nis_CacheBind(char *, directory_obj *); +extern nis_error __nis_CacheSearch(char *, directory_obj *); +extern bool_t __nis_CacheRemoveEntry(directory_obj *); +extern void __nis_CacheRestart(void); +extern void __nis_CachePrint(void); +extern void __nis_CacheDumpStatistics(void); +extern bool_t writeColdStartFile(directory_obj *); + +extern CLIENT * __get_ti_clnt(char *, CLIENT *, char **, pid_t *); +extern int __strcmp_case_insens(char *, char *); +extern int __strncmp_case_insens(char *, char *); + +extern fd_result * nis_finddirectory(directory_obj *, nis_name); +extern int __start_clock(int); +extern u_long __stop_clock(int); + +/* + * This particular function is part of the FreeBSD NIS+ implementation + * only. Ideally it should be somewhere else, but it is used by both + * rpc.nisd and nis_cachemgr, and there aren't that many headers common + * to both programs. + */ + +extern struct signature *__nis_calculate_encrypted_cksum(unsigned char *, unsigned int, char *, int); + +#define NUL '\0' + +#ifdef __cplusplus +} +#endif + +#endif /* _RPCSVC_NISLIB_H */ diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/nlm_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/nlm_prot.x new file mode 100644 index 000000000000..87bf6c844359 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/nlm_prot.x @@ -0,0 +1,327 @@ +/* + * Network lock manager protocol definition + * Copyright (C) 1986 Sun Microsystems, Inc. + * + * protocol used between local lock manager and remote lock manager + */ + +#ifdef RPC_HDR +%#define LM_MAXSTRLEN 1024 +%#define MAXNAMELEN LM_MAXSTRLEN+1 +#else +%#include +%#ifndef lint +%/*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ +%__RCSID("$NetBSD: nlm_prot.x,v 1.6 2000/06/07 14:30:15 bouyer Exp $"); +%#endif /* not lint */ +%__FBSDID("$FreeBSD$"); +#endif + +/* + * status of a call to the lock manager + */ +enum nlm_stats { + nlm_granted = 0, + nlm_denied = 1, + nlm_denied_nolocks = 2, + nlm_blocked = 3, + nlm_denied_grace_period = 4, + nlm_deadlck = 5 +}; + +struct nlm_holder { + bool exclusive; + int svid; + netobj oh; + unsigned l_offset; + unsigned l_len; +}; + +union nlm_testrply switch (nlm_stats stat) { + case nlm_denied: + struct nlm_holder holder; + default: + void; +}; + +struct nlm_stat { + nlm_stats stat; +}; + +struct nlm_res { + netobj cookie; + nlm_stat stat; +}; + +struct nlm_testres { + netobj cookie; + nlm_testrply stat; +}; + +struct nlm_lock { + string caller_name; + netobj fh; /* identify a file */ + netobj oh; /* identify owner of a lock */ + int svid; /* generated from pid for svid */ + unsigned l_offset; + unsigned l_len; +}; + +struct nlm_lockargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm_lock alock; + bool reclaim; /* used for recovering locks */ + int state; /* specify local status monitor state */ +}; + +struct nlm_cancargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm_lock alock; +}; + +struct nlm_testargs { + netobj cookie; + bool exclusive; + struct nlm_lock alock; +}; + +struct nlm_unlockargs { + netobj cookie; + struct nlm_lock alock; +}; + + +#ifdef RPC_HDR +%/* +% * The following enums are actually bit encoded for efficient +% * boolean algebra.... DON'T change them..... +% */ +#endif +enum fsh_mode { + fsm_DN = 0, /* deny none */ + fsm_DR = 1, /* deny read */ + fsm_DW = 2, /* deny write */ + fsm_DRW = 3 /* deny read/write */ +}; + +enum fsh_access { + fsa_NONE = 0, /* for completeness */ + fsa_R = 1, /* read only */ + fsa_W = 2, /* write only */ + fsa_RW = 3 /* read/write */ +}; + +struct nlm_share { + string caller_name; + netobj fh; + netobj oh; + fsh_mode mode; + fsh_access access; +}; + +struct nlm_shareargs { + netobj cookie; + nlm_share share; + bool reclaim; +}; + +struct nlm_shareres { + netobj cookie; + nlm_stats stat; + int sequence; +}; + +struct nlm_notify { + string name; + long state; +}; + +#ifdef RPC_HDR +%/* definitions for NLM version 4 */ +#endif +enum nlm4_stats { + nlm4_granted = 0, + nlm4_denied = 1, + nlm4_denied_nolocks = 2, + nlm4_blocked = 3, + nlm4_denied_grace_period = 4, + nlm4_deadlck = 5, + nlm4_rofs = 6, + nlm4_stale_fh = 7, + nlm4_fbig = 8, + nlm4_failed = 9 +}; + +struct nlm4_stat { + nlm4_stats stat; +}; + +struct nlm4_holder { + bool exclusive; + u_int32_t svid; + netobj oh; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_lock { + string caller_name; + netobj fh; + netobj oh; + u_int32_t svid; + u_int64_t l_offset; + u_int64_t l_len; +}; + +struct nlm4_share { + string caller_name; + netobj fh; + netobj oh; + fsh_mode mode; + fsh_access access; +}; + +union nlm4_testrply switch (nlm4_stats stat) { + case nlm_denied: + struct nlm4_holder holder; + default: + void; +}; + +struct nlm4_testres { + netobj cookie; + nlm4_testrply stat; +}; + +struct nlm4_testargs { + netobj cookie; + bool exclusive; + struct nlm4_lock alock; +}; + +struct nlm4_res { + netobj cookie; + nlm4_stat stat; +}; + +struct nlm4_lockargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm4_lock alock; + bool reclaim; /* used for recovering locks */ + int state; /* specify local status monitor state */ +}; + +struct nlm4_cancargs { + netobj cookie; + bool block; + bool exclusive; + struct nlm4_lock alock; +}; + +struct nlm4_unlockargs { + netobj cookie; + struct nlm4_lock alock; +}; + +struct nlm4_shareargs { + netobj cookie; + nlm4_share share; + bool reclaim; +}; + +struct nlm4_shareres { + netobj cookie; + nlm4_stats stat; + int sequence; +}; + +/* + * argument for the procedure called by rpc.statd when a monitored host + * status change. + * XXX assumes LM_MAXSTRLEN == SM_MAXSTRLEN + */ +struct nlm_sm_status { + string mon_name; /* name of host */ + int state; /* new state */ + opaque priv[16]; /* private data */ +}; + +struct nlm4_notify { + string name; + int32_t state; +}; + +/* + * Over-the-wire protocol used between the network lock managers + */ + +program NLM_PROG { + + version NLM_SM { + void NLM_SM_NOTIFY(struct nlm_sm_status) = 1; + } = 0; + + version NLM_VERS { + + nlm_testres NLM_TEST(struct nlm_testargs) = 1; + + nlm_res NLM_LOCK(struct nlm_lockargs) = 2; + + nlm_res NLM_CANCEL(struct nlm_cancargs) = 3; + nlm_res NLM_UNLOCK(struct nlm_unlockargs) = 4; + + /* + * remote lock manager call-back to grant lock + */ + nlm_res NLM_GRANTED(struct nlm_testargs)= 5; + /* + * message passing style of requesting lock + */ + void NLM_TEST_MSG(struct nlm_testargs) = 6; + void NLM_LOCK_MSG(struct nlm_lockargs) = 7; + void NLM_CANCEL_MSG(struct nlm_cancargs) =8; + void NLM_UNLOCK_MSG(struct nlm_unlockargs) = 9; + void NLM_GRANTED_MSG(struct nlm_testargs) = 10; + void NLM_TEST_RES(nlm_testres) = 11; + void NLM_LOCK_RES(nlm_res) = 12; + void NLM_CANCEL_RES(nlm_res) = 13; + void NLM_UNLOCK_RES(nlm_res) = 14; + void NLM_GRANTED_RES(nlm_res) = 15; + } = 1; + + version NLM_VERSX { + nlm_shareres NLM_SHARE(nlm_shareargs) = 20; + nlm_shareres NLM_UNSHARE(nlm_shareargs) = 21; + nlm_res NLM_NM_LOCK(nlm_lockargs) = 22; + void NLM_FREE_ALL(nlm_notify) = 23; + } = 3; + + version NLM_VERS4 { + nlm4_testres NLM4_TEST(nlm4_testargs) = 1; + nlm4_res NLM4_LOCK(nlm4_lockargs) = 2; + nlm4_res NLM4_CANCEL(nlm4_cancargs) = 3; + nlm4_res NLM4_UNLOCK(nlm4_unlockargs) = 4; + nlm4_res NLM4_GRANTED(nlm4_testargs) = 5; + void NLM4_TEST_MSG(nlm4_testargs) = 6; + void NLM4_LOCK_MSG(nlm4_lockargs) = 7; + void NLM4_CANCEL_MSG(nlm4_cancargs) = 8; + void NLM4_UNLOCK_MSG(nlm4_unlockargs) = 9; + void NLM4_GRANTED_MSG(nlm4_testargs) = 10; + void NLM4_TEST_RES(nlm4_testres) = 11; + void NLM4_LOCK_RES(nlm4_res) = 12; + void NLM4_CANCEL_RES(nlm4_res) = 13; + void NLM4_UNLOCK_RES(nlm4_res) = 14; + void NLM4_GRANTED_RES(nlm4_res) = 15; + nlm4_shareres NLM4_SHARE(nlm4_shareargs) = 20; + nlm4_shareres NLM4_UNSHARE(nlm4_shareargs) = 21; + nlm4_res NLM4_NM_LOCK(nlm4_lockargs) = 22; + void NLM4_FREE_ALL(nlm4_notify) = 23; + } = 4; +} = 100021; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/pmap_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/pmap_prot.x new file mode 100644 index 000000000000..19a4d8c5a2fd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/pmap_prot.x @@ -0,0 +1,279 @@ +%/* +% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for +% * unrestricted use provided that this legend is included on all tape +% * media and as a part of the software program in whole or part. Users +% * may copy or modify Sun RPC without charge, but are not authorized +% * to license or distribute it to anyone else except as part of a product or +% * program developed by the user. +% * +% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE +% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR +% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +% * +% * Sun RPC is provided with no support and without any obligation on the +% * part of Sun Microsystems, Inc. to assist in its use, correction, +% * modification or enhancement. +% * +% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE +% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC +% * OR ANY PART THEREOF. +% * +% * In no event will Sun Microsystems, Inc. be liable for any lost revenue +% * or profits or other special, indirect and consequential damages, even if +% * Sun has been advised of the possibility of such damages. +% * +% * Sun Microsystems, Inc. +% * 2550 Garcia Avenue +% * Mountain View, California 94043 +% */ +%/* +% * Copyright (c) 1984,1989 by Sun Microsystems, Inc. +% */ + +%/* from pmap_prot.x */ + +#ifdef RPC_HDR +% +%#pragma ident "@(#)pmap_prot.x 1.6 94/04/29 SMI" +%#include +%__FBSDID("$FreeBSD$"); +% +%#ifndef _KERNEL +% +#endif + +/* + * Port Mapper Protocol Specification (in RPC Language) + * derived from RFC 1057 + */ + +%/* +% * Protocol for the local binder service, or pmap. +% * +% * Copyright (C) 1984, Sun Microsystems, Inc. +% * +% * The following procedures are supported by the protocol: +% * +% * PMAPPROC_NULL() returns () +% * takes nothing, returns nothing +% * +% * PMAPPROC_SET(struct pmap) returns (bool_t) +% * TRUE is success, FALSE is failure. Registers the tuple +% * [prog, vers, prot, port]. +% * +% * PMAPPROC_UNSET(struct pmap) returns (bool_t) +% * TRUE is success, FALSE is failure. Un-registers pair +% * [prog, vers]. prot and port are ignored. +% * +% * PMAPPROC_GETPORT(struct pmap) returns (long unsigned). +% * 0 is failure. Otherwise returns the port number where the pair +% * [prog, vers] is registered. It may lie! +% * +% * PMAPPROC_DUMP() RETURNS (struct pmaplist_ptr) +% * +% * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>) +% * RETURNS (port, string<>); +% * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, +% * encapsulatedargs); +% * Calls the procedure on the local machine. If it is not registered, +% * this procedure is quite; ie it does not return error information!!! +% * This procedure only is supported on rpc/udp and calls via +% * rpc/udp. This routine only passes null authentication parameters. +% * This file has no interface to xdr routines for PMAPPROC_CALLIT. +% * +% * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. +% */ +% +const PMAPPORT = 111; /* portmapper port number */ +% +% +%/* +% * A mapping of (program, version, protocol) to port number +% */ + +struct pmap { + unsigned long pm_prog; + unsigned long pm_vers; + unsigned long pm_prot; + unsigned long pm_port; +}; +#ifdef RPC_HDR +% +%typedef pmap PMAP; +% +#endif +% +%/* +% * Supported values for the "prot" field +% */ +% +const PMAP_IPPROTO_TCP = 6; /* protocol number for TCP/IP */ +const PMAP_IPPROTO_UDP = 17; /* protocol number for UDP/IP */ +% +% +%/* +% * A list of mappings +% * +% * Below are two definitions for the pmaplist structure. This is done because +% * xdr_pmaplist() is specified to take a struct pmaplist **, rather than a +% * struct pmaplist * that rpcgen would produce. One version of the pmaplist +% * structure (actually called pm__list) is used with rpcgen, and the other is +% * defined only in the header file for compatibility with the specified +% * interface. +% */ + +struct pm__list { + pmap pml_map; + struct pm__list *pml_next; +}; + +typedef pm__list *pmaplist_ptr; /* results of PMAPPROC_DUMP */ + +#ifdef RPC_HDR +% +%typedef struct pm__list pmaplist; +%typedef struct pm__list PMAPLIST; +% +%#ifndef __cplusplus +%struct pmaplist { +% PMAP pml_map; +% struct pmaplist *pml_next; +%}; +%#endif +% +%#ifdef __cplusplus +%extern "C" { +%#endif +%extern bool_t xdr_pmaplist(XDR *, pmaplist**); +%#ifdef __cplusplus +%} +%#endif +% +#endif + +% +%/* +% * Arguments to callit +% */ + +struct rmtcallargs { + unsigned long prog; + unsigned long vers; + unsigned long proc; + opaque args<>; +}; +#ifdef RPC_HDR +% +%/* +% * Client-side only representation of rmtcallargs structure. +% * +% * The routine that XDRs the rmtcallargs structure must deal with the +% * opaque arguments in the "args" structure. xdr_rmtcall_args() needs to be +% * passed the XDR routine that knows the args' structure. This routine +% * doesn't need to go over-the-wire (and it wouldn't make sense anyway) since +% * the application being called knows the args structure already. So we use a +% * different "XDR" structure on the client side, p_rmtcallargs, which includes +% * the args' XDR routine. +% */ +%struct p_rmtcallargs { +% u_long prog; +% u_long vers; +% u_long proc; +% struct { +% u_int args_len; +% char *args_val; +% } args; +% xdrproc_t xdr_args; /* encodes args */ +%}; +% +#endif /* def RPC_HDR */ +% +% +%/* +% * Results of callit +% */ + +struct rmtcallres { + unsigned long port; + opaque res<>; +}; +#ifdef RPC_HDR +% +%/* +% * Client-side only representation of rmtcallres structure. +% */ +%struct p_rmtcallres { +% u_long port; +% struct { +% u_int res_len; +% char *res_val; +% } res; +% xdrproc_t xdr_res; /* decodes res */ +%}; +% +#endif /* def RPC_HDR */ + +/* + * Port mapper procedures + */ + +program PMAPPROG { + version PMAPVERS { + void + PMAPPROC_NULL(void) = 0; + + bool + PMAPPROC_SET(pmap) = 1; + + bool + PMAPPROC_UNSET(pmap) = 2; + + unsigned long + PMAPPROC_GETPORT(pmap) = 3; + + pmaplist_ptr + PMAPPROC_DUMP(void) = 4; + + rmtcallres + PMAPPROC_CALLIT(rmtcallargs) = 5; + } = 2; +} = 100000; +% +#ifdef RPC_HDR +%#define PMAPVERS_PROTO ((u_long)2) +%#define PMAPVERS_ORIG ((u_long)1) +% +%#else /* ndef _KERNEL */ +% +%#include +% +%#ifdef __cplusplus +%extern "C" { +%#endif +% +%#define PMAPPORT 111 +% +%struct pmap { +% long unsigned pm_prog; +% long unsigned pm_vers; +% long unsigned pm_prot; +% long unsigned pm_port; +%}; +%typedef struct pmap PMAP; +%extern bool_t xdr_pmap (XDR *, struct pmap *); +% +%struct pmaplist { +% struct pmap pml_map; +% struct pmaplist *pml_next; +%}; +%typedef struct pmaplist PMAPLIST; +%typedef struct pmaplist *pmaplist_ptr; +% +% +%#ifdef __cplusplus +%} +%#endif +% +%#endif /* ndef _KERNEL */ +#endif + diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/rex.x b/lib/libc/include/any-freebsd-any/rpcsvc/rex.x new file mode 100644 index 000000000000..4d4bda65f283 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/rex.x @@ -0,0 +1,237 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Remote execution (rex) protocol specification + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)rex.x 1.3 87/09/18 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)rex.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const STRINGSIZE = 1024; +typedef string rexstring<1024>; + +/* + * values to pass to REXPROC_SIGNAL + */ +const SIGINT = 2; /* interrupt */ + +/* + * Values for rst_flags, below + */ +const REX_INTERACTIVE = 1; /* interactive mode */ + +struct rex_start { + rexstring rst_cmd<>; /* list of command and args */ + rexstring rst_host; /* working directory host name */ + rexstring rst_fsname; /* working directory file system name */ + rexstring rst_dirwithin;/* working directory within file system */ + rexstring rst_env<>; /* list of environment */ + unsigned int rst_port0; /* port for stdin */ + unsigned int rst_port1; /* port for stdout */ + unsigned int rst_port2; /* port for stderr */ + unsigned int rst_flags; /* options - see const above */ +}; + +struct rex_result { + int rlt_stat; /* integer status code */ + rexstring rlt_message; /* string message for human consumption */ +}; + + +struct sgttyb { + unsigned four; /* always equals 4 */ + opaque chars[4]; + /* chars[0] == input speed */ + /* chars[1] == output speed */ + /* chars[2] == kill character */ + /* chars[3] == erase character */ + unsigned flags; +}; +/* values for speeds above (baud rates) */ +const B0 = 0; +const B50 = 1; +const B75 = 2; +const B110 = 3; +const B134 = 4; +const B150 = 5; +const B200 = 6; +const B300 = 7; +const B600 = 8; +const B1200 = 9; +const B1800 = 10; +const B2400 = 11; +const B4800 = 12; +const B9600 = 13; +const B19200 = 14; +const B38400 = 15; + +/* values for flags above */ +const TANDEM = 0x00000001; /* send stopc on out q full */ +const CBREAK = 0x00000002; /* half-cooked mode */ +const LCASE = 0x00000004; /* simulate lower case */ +const ECHO = 0x00000008; /* echo input */ +const CRMOD = 0x00000010; /* map \r to \r\n on output */ +const RAW = 0x00000020; /* no i/o processing */ +const ODDP = 0x00000040; /* get/send odd parity */ +const EVENP = 0x00000080; /* get/send even parity */ +const ANYP = 0x000000c0; /* get any parity/send none */ +const NLDELAY = 0x00000300; /* \n delay */ +const NL0 = 0x00000000; +const NL1 = 0x00000100; /* tty 37 */ +const NL2 = 0x00000200; /* vt05 */ +const NL3 = 0x00000300; +const TBDELAY = 0x00000c00; /* horizontal tab delay */ +const TAB0 = 0x00000000; +const TAB1 = 0x00000400; /* tty 37 */ +const TAB2 = 0x00000800; +const XTABS = 0x00000c00; /* expand tabs on output */ +const CRDELAY = 0x00003000; /* \r delay */ +const CR0 = 0x00000000; +const CR1 = 0x00001000; /* tn 300 */ +const CR2 = 0x00002000; /* tty 37 */ +const CR3 = 0x00003000; /* concept 100 */ +const VTDELAY = 0x00004000; /* vertical tab delay */ +const FF0 = 0x00000000; +const FF1 = 0x00004000; /* tty 37 */ +const BSDELAY = 0x00008000; /* \b delay */ +const BS0 = 0x00000000; +const BS1 = 0x00008000; +const CRTBS = 0x00010000; /* do backspacing for crt */ +const PRTERA = 0x00020000; /* \ ... / erase */ +const CRTERA = 0x00040000; /* " \b " to wipe out char */ +const TILDE = 0x00080000; /* hazeltine tilde kludge */ +const MDMBUF = 0x00100000; /* start/stop output on carrier intr */ +const LITOUT = 0x00200000; /* literal output */ +const TOSTOP = 0x00400000; /* SIGTTOU on background output */ +const FLUSHO = 0x00800000; /* flush output to terminal */ +const NOHANG = 0x01000000; /* no SIGHUP on carrier drop */ +const L001000 = 0x02000000; +const CRTKIL = 0x04000000; /* kill line with " \b " */ +const PASS8 = 0x08000000; +const CTLECH = 0x10000000; /* echo control chars as ^X */ +const PENDIN = 0x20000000; /* tp->t_rawq needs reread */ +const DECCTQ = 0x40000000; /* only ^Q starts after ^S */ +const NOFLSH = 0x80000000; /* no output flush on signal */ + +struct tchars { + unsigned six; /* always equals 6 */ + opaque chars[6]; + /* chars[0] == interrupt char */ + /* chars[1] == quit char */ + /* chars[2] == start output char */ + /* chars[3] == stop output char */ + /* chars[4] == end-of-file char */ + /* chars[5] == input delimeter (like nl) */ +}; + +struct ltchars { + unsigned six; /* always equals 6 */ + opaque chars[6]; + /* chars[0] == stop process signal */ + /* chars[1] == delayed stop process signal */ + /* chars[2] == reprint line */ + /* chars[3] == flush output */ + /* chars[4] == word erase */ + /* chars[5] == literal next character */ + unsigned mode; +}; + +struct rex_ttysize { + int ts_lines; + int ts_cols; +}; + +struct rex_ttymode { + sgttyb basic; /* standard unix tty flags */ + tchars more; /* interrupt, kill characters, etc. */ + ltchars yetmore; /* special Berkeley characters */ + unsigned andmore; /* and Berkeley modes */ +}; + +/* values for andmore above */ +const LCRTBS = 0x0001; /* do backspacing for crt */ +const LPRTERA = 0x0002; /* \ ... / erase */ +const LCRTERA = 0x0004; /* " \b " to wipe out char */ +const LTILDE = 0x0008; /* hazeltine tilde kludge */ +const LMDMBUF = 0x0010; /* start/stop output on carrier intr */ +const LLITOUT = 0x0020; /* literal output */ +const LTOSTOP = 0x0040; /* SIGTTOU on background output */ +const LFLUSHO = 0x0080; /* flush output to terminal */ +const LNOHANG = 0x0100; /* no SIGHUP on carrier drop */ +const LL001000 = 0x0200; +const LCRTKIL = 0x0400; /* kill line with " \b " */ +const LPASS8 = 0x0800; +const LCTLECH = 0x1000; /* echo control chars as ^X */ +const LPENDIN = 0x2000; /* needs reread */ +const LDECCTQ = 0x4000; /* only ^Q starts after ^S */ +const LNOFLSH = 0x8000; /* no output flush on signal */ + +program REXPROG { + version REXVERS { + + /* + * Start remote execution + */ + rex_result + REXPROC_START(rex_start) = 1; + + /* + * Wait for remote execution to terminate + */ + rex_result + REXPROC_WAIT(void) = 2; + + /* + * Send tty modes + */ + void + REXPROC_MODES(rex_ttymode) = 3; + + /* + * Send window size change + */ + void + REXPROC_WINCH(rex_ttysize) = 4; + + /* + * Send other signal + */ + void + REXPROC_SIGNAL(int) = 5; + } = 1; +} = 100017; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/rnusers.x b/lib/libc/include/any-freebsd-any/rpcsvc/rnusers.x new file mode 100644 index 000000000000..421a515ac725 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/rnusers.x @@ -0,0 +1,125 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Find out about remote users + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)rnusers.x 1.2 87/09/20 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)rnusers.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const MAXUSERS = 100; +const MAXUTLEN = 256; + +struct utmp { + string ut_line; + string ut_name; + string ut_host; + int ut_time; +}; + + +struct utmpidle { + utmp ui_utmp; + unsigned int ui_idle; +}; + +typedef utmp utmparr; + +typedef utmpidle utmpidlearr; + +const RUSERS_MAXUSERLEN = 32; +const RUSERS_MAXLINELEN = 32; +const RUSERS_MAXHOSTLEN = 257; + +struct rusers_utmp { + string ut_user; /* aka ut_name */ + string ut_line; /* device */ + string ut_host; /* host user logged on from */ + int ut_type; /* type of entry */ + int ut_time; /* time entry was made */ + unsigned int ut_idle; /* minutes idle */ +}; + +typedef rusers_utmp utmp_array<>; + +program RUSERSPROG { + /* + * Old version does not include idle information + */ + version RUSERSVERS_ORIG { + int + RUSERSPROC_NUM(void) = 1; + + utmparr + RUSERSPROC_NAMES(void) = 2; + + utmparr + RUSERSPROC_ALLNAMES(void) = 3; + } = 1; + + /* + * Includes idle information + */ + version RUSERSVERS_IDLE { + int + RUSERSPROC_NUM(void) = 1; + + utmpidlearr + RUSERSPROC_NAMES(void) = 2; + + utmpidlearr + RUSERSPROC_ALLNAMES(void) = 3; + } = 2; + + /* + * Version 3 rusers procedures (from Solaris). + * (Thanks a lot Sun.) + */ + version RUSERSVERS_3 { + int + RUSERSPROC_NUM(void) = 1; + + utmp_array + RUSERSPROC_NAMES(void) = 2; + + utmp_array + RUSERSPROC_ALLNAMES(void) = 3; + } = 3; + +} = 100002; + diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/rquota.x b/lib/libc/include/any-freebsd-any/rpcsvc/rquota.x new file mode 100644 index 000000000000..8c8dfe452b54 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/rquota.x @@ -0,0 +1,144 @@ +/* @(#)rquota.x 2.1 88/08/01 4.0 RPCSRC */ +/* @(#)rquota.x 1.2 87/09/20 Copyr 1987 Sun Micro */ + +/* + * Remote quota protocol + * Requires unix authentication + */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const RQ_PATHLEN = 1024; + +struct sq_dqblk { + unsigned int rq_bhardlimit; /* absolute limit on disk blks alloc */ + unsigned int rq_bsoftlimit; /* preferred limit on disk blks */ + unsigned int rq_curblocks; /* current block count */ + unsigned int rq_fhardlimit; /* absolute limit on allocated files */ + unsigned int rq_fsoftlimit; /* preferred file limit */ + unsigned int rq_curfiles; /* current # allocated files */ + unsigned int rq_btimeleft; /* time left for excessive disk use */ + unsigned int rq_ftimeleft; /* time left for excessive files */ +}; + +struct getquota_args { + string gqa_pathp; /* path to filesystem of interest */ + int gqa_uid; /* Inquire about quota for uid */ +}; + +struct setquota_args { + int sqa_qcmd; + string sqa_pathp; /* path to filesystem of interest */ + int sqa_id; /* Set quota for uid */ + sq_dqblk sqa_dqblk; +}; + +struct ext_getquota_args { + string gqa_pathp; /* path to filesystem of interest */ + int gqa_type; /* Type of quota info is needed about */ + int gqa_id; /* Inquire about quota for id */ +}; + +struct ext_setquota_args { + int sqa_qcmd; + string sqa_pathp; /* path to filesystem of interest */ + int sqa_id; /* Set quota for id */ + int sqa_type; /* Type of quota to set */ + sq_dqblk sqa_dqblk; +}; + +/* + * remote quota structure + */ +struct rquota { + int rq_bsize; /* block size for block counts */ + bool rq_active; /* indicates whether quota is active */ + unsigned int rq_bhardlimit; /* absolute limit on disk blks alloc */ + unsigned int rq_bsoftlimit; /* preferred limit on disk blks */ + unsigned int rq_curblocks; /* current block count */ + unsigned int rq_fhardlimit; /* absolute limit on allocated files */ + unsigned int rq_fsoftlimit; /* preferred file limit */ + unsigned int rq_curfiles; /* current # allocated files */ + unsigned int rq_btimeleft; /* time left for excessive disk use */ + unsigned int rq_ftimeleft; /* time left for excessive files */ +}; + +enum gqr_status { + Q_OK = 1, /* quota returned */ + Q_NOQUOTA = 2, /* noquota for uid */ + Q_EPERM = 3 /* no permission to access quota */ +}; + +union getquota_rslt switch (gqr_status status) { +case Q_OK: + rquota gqr_rquota; /* valid if status == Q_OK */ +case Q_NOQUOTA: + void; +case Q_EPERM: + void; +}; + +union setquota_rslt switch (gqr_status status) { +case Q_OK: + rquota sqr_rquota; /* valid if status == Q_OK */ +case Q_NOQUOTA: + void; +case Q_EPERM: + void; +}; + +program RQUOTAPROG { + version RQUOTAVERS { + /* + * Get all quotas + */ + getquota_rslt + RQUOTAPROC_GETQUOTA(getquota_args) = 1; + + /* + * Get active quotas only + */ + getquota_rslt + RQUOTAPROC_GETACTIVEQUOTA(getquota_args) = 2; + + /* + * Set all quotas + */ + setquota_rslt + RQUOTAPROC_SETQUOTA(setquota_args) = 3; + + /* + * Get active quotas only + */ + setquota_rslt + RQUOTAPROC_SETACTIVEQUOTA(setquota_args) = 4; + } = 1; + version EXT_RQUOTAVERS { + /* + * Get all quotas + */ + getquota_rslt + RQUOTAPROC_GETQUOTA(ext_getquota_args) = 1; + + /* + * Get active quotas only + */ + getquota_rslt + RQUOTAPROC_GETACTIVEQUOTA(ext_getquota_args) = 2; + + /* + * Set all quotas + */ + setquota_rslt + RQUOTAPROC_SETQUOTA(ext_setquota_args) = 3; + + /* + * Set active quotas only + */ + setquota_rslt + RQUOTAPROC_SETACTIVEQUOTA(ext_setquota_args) = 4; + } = 2; +} = 100011; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/rstat.x b/lib/libc/include/any-freebsd-any/rpcsvc/rstat.x new file mode 100644 index 000000000000..a34456082afa --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/rstat.x @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Gather statistics on remote machines + */ + +#ifdef RPC_HDR + +%#ifndef FSCALE +%/* +% * Scale factor for scaled integers used to count load averages. +% */ +%#define FSHIFT 8 /* bits to right of fixed binary point */ +%#define FSCALE (1< +%__FBSDID("$FreeBSD$"); + +#endif /* def RPC_HDR */ + +const RSTAT_CPUSTATES = 4; +const RSTAT_DK_NDRIVE = 4; + +/* + * GMT since 0:00, January 1, 1970 + */ +struct rstat_timeval { + unsigned int tv_sec; /* seconds */ + unsigned int tv_usec; /* and microseconds */ +}; + +struct statstime { /* RSTATVERS_TIME */ + int cp_time[RSTAT_CPUSTATES]; + int dk_xfer[RSTAT_DK_NDRIVE]; + unsigned int v_pgpgin; /* these are cumulative sum */ + unsigned int v_pgpgout; + unsigned int v_pswpin; + unsigned int v_pswpout; + unsigned int v_intr; + int if_ipackets; + int if_ierrors; + int if_oerrors; + int if_collisions; + unsigned int v_swtch; + int avenrun[3]; /* scaled by FSCALE */ + rstat_timeval boottime; + rstat_timeval curtime; + int if_opackets; +}; + +struct statsswtch { /* RSTATVERS_SWTCH */ + int cp_time[RSTAT_CPUSTATES]; + int dk_xfer[RSTAT_DK_NDRIVE]; + unsigned int v_pgpgin; /* these are cumulative sum */ + unsigned int v_pgpgout; + unsigned int v_pswpin; + unsigned int v_pswpout; + unsigned int v_intr; + int if_ipackets; + int if_ierrors; + int if_oerrors; + int if_collisions; + unsigned int v_swtch; + unsigned int avenrun[3];/* scaled by FSCALE */ + rstat_timeval boottime; + int if_opackets; +}; + +struct stats { /* RSTATVERS_ORIG */ + int cp_time[RSTAT_CPUSTATES]; + int dk_xfer[RSTAT_DK_NDRIVE]; + unsigned int v_pgpgin; /* these are cumulative sum */ + unsigned int v_pgpgout; + unsigned int v_pswpin; + unsigned int v_pswpout; + unsigned int v_intr; + int if_ipackets; + int if_ierrors; + int if_oerrors; + int if_collisions; + int if_opackets; +}; + + +program RSTATPROG { + /* + * Newest version includes current time and context switching info + */ + version RSTATVERS_TIME { + statstime + RSTATPROC_STATS(void) = 1; + + unsigned int + RSTATPROC_HAVEDISK(void) = 2; + } = 3; + /* + * Does not have current time + */ + version RSTATVERS_SWTCH { + statsswtch + RSTATPROC_STATS(void) = 1; + + unsigned int + RSTATPROC_HAVEDISK(void) = 2; + } = 2; + /* + * Old version has no info about current time or context switching + */ + version RSTATVERS_ORIG { + stats + RSTATPROC_STATS(void) = 1; + + unsigned int + RSTATPROC_HAVEDISK(void) = 2; + } = 1; +} = 100001; + +#ifdef RPC_HDR +% +%enum clnt_stat rstat(char *, struct statstime *); +%int havedisk(char *); +% +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/rwall.x b/lib/libc/include/any-freebsd-any/rpcsvc/rwall.x new file mode 100644 index 000000000000..6c26c1f18f3e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/rwall.x @@ -0,0 +1,57 @@ +%/* +% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for +% * unrestricted use provided that this legend is included on all tape +% * media and as a part of the software program in whole or part. Users +% * may copy or modify Sun RPC without charge, but are not authorized +% * to license or distribute it to anyone else except as part of a product or +% * program developed by the user or with the express written consent of +% * Sun Microsystems, Inc. +% * +% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE +% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR +% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +% * +% * Sun RPC is provided with no support and without any obligation on the +% * part of Sun Microsystems, Inc. to assist in its use, correction, +% * modification or enhancement. +% * +% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE +% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC +% * OR ANY PART THEREOF. +% * +% * In no event will Sun Microsystems, Inc. be liable for any lost revenue +% * or profits or other special, indirect and consequential damages, even if +% * Sun has been advised of the possibility of such damages. +% * +% * Sun Microsystems, Inc. +% * 2550 Garcia Avenue +% * Mountain View, California 94043 +% */ + +%/* +% * Copyright (c) 1984, 1990 by Sun Microsystems, Inc. +% */ +% +%/* from @(#)rwall.x 1.6 91/03/11 TIRPC 1.0 */ + +#ifdef RPC_HDR +% +%#ifndef _rpcsvc_rwall_h +%#define _rpcsvc_rwall_h +% +%typedef char *wrapstring; +% +#endif + +program WALLPROG { + version WALLVERS { + void + WALLPROC_WALL(wrapstring) = 2; + + } = 1; +} = 100008; + +#ifdef RPC_HDR +% +%#endif /* ! _rpcsvc_rwall_h */ +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/sm_inter.x b/lib/libc/include/any-freebsd-any/rpcsvc/sm_inter.x new file mode 100644 index 000000000000..42a00915e8f7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/sm_inter.x @@ -0,0 +1,127 @@ +/* @(#)sm_inter.x 2.2 88/08/01 4.0 RPCSRC */ +/* @(#)sm_inter.x 1.7 87/06/24 Copyr 1987 Sun Micro */ + +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Status monitor protocol specification + * Copyright (C) 1986 Sun Microsystems, Inc. + * + */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +program SM_PROG { + version SM_VERS { + /* res_stat = stat_succ if status monitor agrees to monitor */ + /* res_stat = stat_fail if status monitor cannot monitor */ + /* if res_stat == stat_succ, state = state number of site sm_name */ + struct sm_stat_res SM_STAT(struct sm_name) = 1; + + /* res_stat = stat_succ if status monitor agrees to monitor */ + /* res_stat = stat_fail if status monitor cannot monitor */ + /* stat consists of state number of local site */ + struct sm_stat_res SM_MON(struct mon) = 2; + + /* stat consists of state number of local site */ + struct sm_stat SM_UNMON(struct mon_id) = 3; + + /* stat consists of state number of local site */ + struct sm_stat SM_UNMON_ALL(struct my_id) = 4; + + void SM_SIMU_CRASH(void) = 5; + void SM_NOTIFY(struct stat_chge) = 6; + + } = 1; +} = 100024; + +const SM_MAXSTRLEN = 1024; + +struct sm_name { + string mon_name; +}; + +struct my_id { + string my_name; /* name of the site iniates the monitoring request*/ + int my_prog; /* rpc program # of the requesting process */ + int my_vers; /* rpc version # of the requesting process */ + int my_proc; /* rpc procedure # of the requesting process */ +}; + +struct mon_id { + string mon_name; /* name of the site to be monitored */ + struct my_id my_id; +}; + + +struct mon{ + struct mon_id mon_id; + opaque priv[16]; /* private information to store at monitor for requesting process */ +}; + +struct stat_chge { + string mon_name; /* name of the site that had the state change */ + int state; +}; + +/* + * state # of status monitor monitonically increases each time + * status of the site changes: + * an even number (>= 0) indicates the site is down and + * an odd number (> 0) indicates the site is up; + */ +struct sm_stat { + int state; /* state # of status monitor */ +}; + +enum sm_res { + stat_succ = 0, /* status monitor agrees to monitor */ + stat_fail = 1 /* status monitor cannot monitor */ +}; + +struct sm_stat_res { + sm_res res_stat; + int state; +}; + +/* + * structure of the status message sent back by the status monitor + * when monitor site status changes + */ +struct sm_status { + string mon_name; + int state; + opaque priv[16]; /* stored private information */ +}; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/spray.x b/lib/libc/include/any-freebsd-any/rpcsvc/spray.x new file mode 100644 index 000000000000..b6a5b849a079 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/spray.x @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Spray a server with packets + * Useful for testing flakiness of network interfaces + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)spray.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)spray.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const SPRAYMAX = 8845; /* max amount can spray */ + +/* + * GMT since 0:00, 1 January 1970 + */ +struct spraytimeval { + unsigned int sec; + unsigned int usec; +}; + +/* + * spray statistics + */ +struct spraycumul { + unsigned int counter; + spraytimeval clock; +}; + +/* + * spray data + */ +typedef opaque sprayarr; + +program SPRAYPROG { + version SPRAYVERS { + /* + * Just throw away the data and increment the counter + * This call never returns, so the client should always + * time it out. + */ + void + SPRAYPROC_SPRAY(sprayarr) = 1; + + /* + * Get the value of the counter and elapsed time since + * last CLEAR. + */ + spraycumul + SPRAYPROC_GET(void) = 2; + + /* + * Clear the counter and reset the elapsed time + */ + void + SPRAYPROC_CLEAR(void) = 3; + } = 1; +} = 100012; diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/yp.x b/lib/libc/include/any-freebsd-any/rpcsvc/yp.x new file mode 100644 index 000000000000..91614b20486f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/yp.x @@ -0,0 +1,379 @@ +/* @(#)yp.x 2.1 88/08/01 4.0 RPCSRC */ + +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Protocol description file for the Yellow Pages Service + */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +const YPMAXRECORD = 16777216; +const YPMAXDOMAIN = 64; +const YPMAXMAP = 64; +const YPMAXPEER = 64; + + +enum ypstat { + YP_TRUE = 1, + YP_NOMORE = 2, + YP_FALSE = 0, + YP_NOMAP = -1, + YP_NODOM = -2, + YP_NOKEY = -3, + YP_BADOP = -4, + YP_BADDB = -5, + YP_YPERR = -6, + YP_BADARGS = -7, + YP_VERS = -8 +}; + + +enum ypxfrstat { + YPXFR_SUCC = 1, + YPXFR_AGE = 2, + YPXFR_NOMAP = -1, + YPXFR_NODOM = -2, + YPXFR_RSRC = -3, + YPXFR_RPC = -4, + YPXFR_MADDR = -5, + YPXFR_YPERR = -6, + YPXFR_BADARGS = -7, + YPXFR_DBM = -8, + YPXFR_FILE = -9, + YPXFR_SKEW = -10, + YPXFR_CLEAR = -11, + YPXFR_FORCE = -12, + YPXFR_XFRERR = -13, + YPXFR_REFUSED = -14 +}; + + +typedef string domainname; +typedef string mapname; +typedef string peername; +typedef opaque keydat; +typedef opaque valdat; + + +struct ypmap_parms { + domainname domain; + mapname map; + unsigned int ordernum; + peername peer; +}; + +struct ypreq_key { + domainname domain; + mapname map; + keydat key; +}; + +struct ypreq_nokey { + domainname domain; + mapname map; +}; + +struct ypreq_xfr { + ypmap_parms map_parms; + unsigned int transid; + unsigned int prog; + unsigned int port; +}; + + +struct ypresp_val { + ypstat stat; + valdat val; +}; + +struct ypresp_key_val { + ypstat stat; +#ifdef STUPID_SUN_BUG /* These are backwards */ + keydat key; + valdat val; +#else + valdat val; + keydat key; +#endif +}; + + +struct ypresp_master { + ypstat stat; + peername peer; +}; + +struct ypresp_order { + ypstat stat; + unsigned int ordernum; +}; + +union ypresp_all switch (bool more) { +case TRUE: + ypresp_key_val val; +case FALSE: + void; +}; + +struct ypresp_xfr { + unsigned int transid; + ypxfrstat xfrstat; +}; + +struct ypmaplist { + mapname map; + ypmaplist *next; +}; + +struct ypresp_maplist { + ypstat stat; + ypmaplist *maps; +}; + +enum yppush_status { + YPPUSH_SUCC = 1, /* Success */ + YPPUSH_AGE = 2, /* Master's version not newer */ + YPPUSH_NOMAP = -1, /* Can't find server for map */ + YPPUSH_NODOM = -2, /* Domain not supported */ + YPPUSH_RSRC = -3, /* Local resource alloc failure */ + YPPUSH_RPC = -4, /* RPC failure talking to server */ + YPPUSH_MADDR = -5, /* Can't get master address */ + YPPUSH_YPERR = -6, /* YP server/map db error */ + YPPUSH_BADARGS = -7, /* Request arguments bad */ + YPPUSH_DBM = -8, /* Local dbm operation failed */ + YPPUSH_FILE = -9, /* Local file I/O operation failed */ + YPPUSH_SKEW = -10, /* Map version skew during transfer */ + YPPUSH_CLEAR = -11, /* Can't send "Clear" req to local ypserv */ + YPPUSH_FORCE = -12, /* No local order number in map use -f flag. */ + YPPUSH_XFRERR = -13, /* ypxfr error */ + YPPUSH_REFUSED = -14 /* Transfer request refused by ypserv */ +}; + +struct yppushresp_xfr { + unsigned transid; + yppush_status status; +}; + +/* + * Response structure and overall result status codes. Success and failure + * represent two separate response message types. + */ + +enum ypbind_resptype { + YPBIND_SUCC_VAL = 1, + YPBIND_FAIL_VAL = 2 +}; + +struct ypbind_binding { + opaque ypbind_binding_addr[4]; /* In network order */ + opaque ypbind_binding_port[2]; /* In network order */ +}; + +union ypbind_resp switch (ypbind_resptype ypbind_status) { +case YPBIND_FAIL_VAL: + unsigned ypbind_error; +case YPBIND_SUCC_VAL: + ypbind_binding ypbind_bindinfo; +}; + +/* Detailed failure reason codes for response field ypbind_error*/ + +const YPBIND_ERR_ERR = 1; /* Internal error */ +const YPBIND_ERR_NOSERV = 2; /* No bound server for passed domain */ +const YPBIND_ERR_RESC = 3; /* System resource allocation failure */ + + +/* + * Request data structure for ypbind "Set domain" procedure. + */ +struct ypbind_setdom { + domainname ypsetdom_domain; + ypbind_binding ypsetdom_binding; + unsigned ypsetdom_vers; +}; + + +/* + * NIS v1 support for backwards compatibility + */ +enum ypreqtype { + YPREQ_KEY = 1, + YPREQ_NOKEY = 2, + YPREQ_MAP_PARMS = 3 +}; + +enum ypresptype { + YPRESP_VAL = 1, + YPRESP_KEY_VAL = 2, + YPRESP_MAP_PARMS = 3 +}; + +union yprequest switch (ypreqtype yp_reqtype) { +case YPREQ_KEY: + ypreq_key yp_req_keytype; +case YPREQ_NOKEY: + ypreq_nokey yp_req_nokeytype; +case YPREQ_MAP_PARMS: + ypmap_parms yp_req_map_parmstype; +}; + +union ypresponse switch (ypresptype yp_resptype) { +case YPRESP_VAL: + ypresp_val yp_resp_valtype; +case YPRESP_KEY_VAL: + ypresp_key_val yp_resp_key_valtype; +case YPRESP_MAP_PARMS: + ypmap_parms yp_resp_map_parmstype; +}; + +#if !defined(YPBIND_ONLY) && !defined(YPPUSH_ONLY) +/* + * YP access protocol + */ +program YPPROG { +/* + * NIS v1 support for backwards compatibility + */ + version YPOLDVERS { + void + YPOLDPROC_NULL(void) = 0; + + bool + YPOLDPROC_DOMAIN(domainname) = 1; + + bool + YPOLDPROC_DOMAIN_NONACK(domainname) = 2; + + ypresponse + YPOLDPROC_MATCH(yprequest) = 3; + + ypresponse + YPOLDPROC_FIRST(yprequest) = 4; + + ypresponse + YPOLDPROC_NEXT(yprequest) = 5; + + ypresponse + YPOLDPROC_POLL(yprequest) = 6; + + ypresponse + YPOLDPROC_PUSH(yprequest) = 7; + + ypresponse + YPOLDPROC_PULL(yprequest) = 8; + + ypresponse + YPOLDPROC_GET(yprequest) = 9; + } = 1; + + version YPVERS { + void + YPPROC_NULL(void) = 0; + + bool + YPPROC_DOMAIN(domainname) = 1; + + bool + YPPROC_DOMAIN_NONACK(domainname) = 2; + + ypresp_val + YPPROC_MATCH(ypreq_key) = 3; + + ypresp_key_val +#ifdef STUPID_SUN_BUG /* should be ypreq_nokey */ + YPPROC_FIRST(ypreq_key) = 4; +#else + YPPROC_FIRST(ypreq_nokey) = 4; +#endif + ypresp_key_val + YPPROC_NEXT(ypreq_key) = 5; + + ypresp_xfr + YPPROC_XFR(ypreq_xfr) = 6; + + void + YPPROC_CLEAR(void) = 7; + + ypresp_all + YPPROC_ALL(ypreq_nokey) = 8; + + ypresp_master + YPPROC_MASTER(ypreq_nokey) = 9; + + ypresp_order + YPPROC_ORDER(ypreq_nokey) = 10; + + ypresp_maplist + YPPROC_MAPLIST(domainname) = 11; + } = 2; +} = 100004; +#endif +#if !defined(YPSERV_ONLY) && !defined(YPBIND_ONLY) +/* + * YPPUSHPROC_XFRRESP is the callback routine for result of YPPROC_XFR + */ +program YPPUSH_XFRRESPPROG { + version YPPUSH_XFRRESPVERS { + void + YPPUSHPROC_NULL(void) = 0; +#ifdef STUPID_SUN_BUG /* argument and return value are backwards */ + yppushresp_xfr + YPPUSHPROC_XFRRESP(void) = 1; +#else + void + YPPUSHPROC_XFRRESP(yppushresp_xfr) = 1; +#endif + } = 1; +} = 0x40000000; /* transient: could be anything up to 0x5fffffff */ +#endif +#if !defined(YPSERV_ONLY) && !defined(YPPUSH_ONLY) +/* + * YP binding protocol + */ +program YPBINDPROG { + version YPBINDVERS { + void + YPBINDPROC_NULL(void) = 0; + + ypbind_resp + YPBINDPROC_DOMAIN(domainname) = 1; + + void + YPBINDPROC_SETDOM(ypbind_setdom) = 2; + } = 2; +} = 100007; + +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/yp_prot.h b/lib/libc/include/any-freebsd-any/rpcsvc/yp_prot.h new file mode 100644 index 000000000000..889e7cceea8c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/yp_prot.h @@ -0,0 +1,331 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992/3 Theo de Raadt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _RPCSVC_YP_PROT_H_ +#define _RPCSVC_YP_PROT_H_ + +/* + * YPSERV PROTOCOL: + * + * ypserv supports the following procedures: + * + * YPPROC_NULL takes (void), returns (void). + * called to check if server is alive. + * YPPROC_DOMAIN takes (char *), returns (bool_t). + * true if ypserv serves the named domain. + * YPPROC_DOMAIN_NOACK takes (char *), returns (bool_t). + * true if ypserv serves the named domain. + * used for broadcasts, does not ack if ypserv + * doesn't handle named domain. + * YPPROC_MATCH takes (struct ypreq_key), returns (struct ypresp_val) + * does a lookup. + * YPPROC_FIRST takes (struct ypreq_nokey) returns (ypresp_key_val). + * gets the first key/datum from the map. + * YPPROC_NEXT takes (struct ypreq_key) returns (ypresp_key_val). + * gets the next key/datum from the map. + * YPPROC_XFR takes (struct ypreq_xfr), returns (void). + * tells ypserv to check if there is a new version of + * the map. + * YPPROC_CLEAR takes (void), returns (void). + * tells ypserv to flush it's file cache, so that + * newly transferred files will get read. + * YPPROC_ALL takes (struct ypreq_nokey), returns (bool_t and + * struct ypresp_key_val). + * returns an array of data, with the bool_t being + * false on the last datum. read the source, it's + * convoluted. + * YPPROC_MASTER takes (struct ypreq_nokey), returns (ypresp_master). + * YPPROC_ORDER takes (struct ypreq_nokey), returns (ypresp_order). + * YPPROC_MAPLIST takes (char *), returns (struct ypmaplist *). + */ + +#ifndef BOOL_DEFINED +typedef u_int bool; +#define BOOL_DEFINED +#endif + +/* Program and version symbols, magic numbers */ + +#define YPPROG ((u_long)100004) +#define YPVERS ((u_long)2) +#define YPVERS_ORIG ((u_long)1) +#define YPMAXRECORD ((u_long)16 * 1024 * 1024) +#define YPMAXDOMAIN ((u_long)64) +#define YPMAXMAP ((u_long)64) +#define YPMAXPEER ((u_long)256) + +/* + * I don't know if anything of sun's depends on this, or if they + * simply defined it so that their own code wouldn't try to send + * packets over the ethernet MTU. This YP code doesn't use it. + */ +#define YPMSGSZ 1600 + +#ifndef DATUM +typedef struct { + char *dptr; + int dsize; +} datum; +#define DATUM +#endif + +struct ypmap_parms { + char *domain; + char *map; + u_int ordernum; + char *owner; +}; + +struct ypreq_key { + char *domain; + char *map; + datum keydat; +}; + +struct ypreq_nokey { + char *domain; + char *map; +}; + +struct ypreq_xfr { + struct ypmap_parms map_parms; + u_int transid; + u_int proto; + u_int port; +}; +#define ypxfr_domain map_parms.domain +#define ypxfr_map map_parms.map +#define ypxfr_ordernum map_parms.ordernum +#define ypxfr_owner map_parms.owner + +struct ypresp_val { + u_int status; + datum valdat; +}; + +struct ypresp_key_val { + u_int status; + datum keydat; + datum valdat; +}; + +struct ypresp_master { + u_int status; + char *master; +}; + +struct ypresp_order { + u_int status; + u_int ordernum; +}; + +struct ypmaplist { + char *ypml_name; + struct ypmaplist *ypml_next; +}; + +struct ypresp_maplist { + u_int status; + struct ypmaplist *list; +}; + +/* ypserv procedure numbers */ +#define YPPROC_NULL ((u_long)0) +#define YPPROC_DOMAIN ((u_long)1) +#define YPPROC_DOMAIN_NONACK ((u_long)2) +#define YPPROC_MATCH ((u_long)3) +#define YPPROC_FIRST ((u_long)4) +#define YPPROC_NEXT ((u_long)5) +#define YPPROC_XFR ((u_long)6) +#define YPPROC_CLEAR ((u_long)7) +#define YPPROC_ALL ((u_long)8) +#define YPPROC_MASTER ((u_long)9) +#define YPPROC_ORDER ((u_long)10) +#define YPPROC_MAPLIST ((u_long)11) + +/* ypserv procedure return status values */ +#define YP_TRUE ((long)1) /* general purpose success code */ +#define YP_NOMORE ((long)2) /* no more entries in map */ +#define YP_FALSE ((long)0) /* general purpose failure code */ +#define YP_NOMAP ((long)-1) /* no such map in domain */ +#define YP_NODOM ((long)-2) /* domain not supported */ +#define YP_NOKEY ((long)-3) /* no such key in map */ +#define YP_BADOP ((long)-4) /* invalid operation */ +#define YP_BADDB ((long)-5) /* server data base is bad */ +#define YP_YPERR ((long)-6) /* YP server error */ +#define YP_BADARGS ((long)-7) /* request arguments bad */ +#define YP_VERS ((long)-8) /* YP server version mismatch */ + +/* + * Sun's header file says: + * "Domain binding data structure, used by ypclnt package and ypserv modules. + * Users of the ypclnt package (or of this protocol) don't HAVE to know about + * it, but it must be available to users because _yp_dobind is a public + * interface." + * + * This is totally bogus! Nowhere else does Sun state that _yp_dobind() is + * a public interface, and I don't know any reason anyone would want to call + * it. But, just in case anyone does actually expect it to be available.. + * we provide this.. exactly as Sun wants it. + */ +struct dom_binding { + struct dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; + struct sockaddr_in dom_server_addr; + u_short dom_server_port; + int dom_socket; + CLIENT *dom_client; + u_short dom_local_port; + long dom_vers; +}; + +/* + * YPBIND PROTOCOL: + * + * ypbind supports the following procedures: + * + * YPBINDPROC_NULL takes (void), returns (void). + * to check if ypbind is running. + * YPBINDPROC_DOMAIN takes (char *), returns (struct ypbind_resp). + * requests that ypbind start to serve the + * named domain (if it doesn't already) + * YPBINDPROC_SETDOM takes (struct ypbind_setdom), returns (void). + * used by ypset. + */ + +#define YPBINDPROG ((u_long)100007) +#define YPBINDVERS ((u_long)2) +#define YPBINDVERS_ORIG ((u_long)1) + +/* ypbind procedure numbers */ +#define YPBINDPROC_NULL ((u_long)0) +#define YPBINDPROC_DOMAIN ((u_long)1) +#define YPBINDPROC_SETDOM ((u_long)2) + +/* error code in ypbind_resp.ypbind_status */ +enum ypbind_resptype { + YPBIND_SUCC_VAL = 1, + YPBIND_FAIL_VAL = 2 +}; + +/* network order, of course */ +struct ypbind_binding { + struct in_addr ypbind_binding_addr; + u_short ypbind_binding_port; +}; + +struct ypbind_resp { + enum ypbind_resptype ypbind_status; + union { + u_int ypbind_error; + struct ypbind_binding ypbind_bindinfo; + } ypbind_respbody; +}; + +/* error code in ypbind_resp.ypbind_respbody.ypbind_error */ +#define YPBIND_ERR_ERR 1 /* internal error */ +#define YPBIND_ERR_NOSERV 2 /* no bound server for passed domain */ +#define YPBIND_ERR_RESC 3 /* system resource allocation failure */ + +/* + * Request data structure for ypbind "Set domain" procedure. + */ +struct ypbind_setdom { + char ypsetdom_domain[YPMAXDOMAIN + 1]; + struct ypbind_binding ypsetdom_binding; + u_int ypsetdom_vers; +}; +#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr +#define ypsetdom_port ypsetdom_binding.ypbind_binding_port + +/* + * YPPUSH PROTOCOL: + * + * Sun says: + * "Protocol between clients (ypxfr, only) and yppush + * yppush speaks a protocol in the transient range, which + * is supplied to ypxfr as a command-line parameter when it + * is activated by ypserv." + * + * This protocol is not implemented, naturally, because this YP + * implementation only does the client side. + */ +#define YPPUSHVERS ((u_long)1) +#define YPPUSHVERS_ORIG ((u_long)1) + +/* yppush procedure numbers */ +#define YPPUSHPROC_NULL ((u_long)0) +#define YPPUSHPROC_XFRRESP ((u_long)1) + +struct yppushresp_xfr { + u_int transid; + u_int status; +}; + +/* yppush status value in yppushresp_xfr.status */ +#define YPPUSH_SUCC ((long)1) /* Success */ +#define YPPUSH_AGE ((long)2) /* Master's version not newer */ +#define YPPUSH_NOMAP ((long)-1) /* Can't find server for map */ +#define YPPUSH_NODOM ((long)-2) /* Domain not supported */ +#define YPPUSH_RSRC ((long)-3) /* Local resource alloc failure */ +#define YPPUSH_RPC ((long)-4) /* RPC failure talking to server */ +#define YPPUSH_MADDR ((long)-5) /* Can't get master address */ +#define YPPUSH_YPERR ((long)-6) /* YP server/map db error */ +#define YPPUSH_BADARGS ((long)-7) /* Request arguments bad */ +#define YPPUSH_DBM ((long)-8) /* Local dbm operation failed */ +#define YPPUSH_FILE ((long)-9) /* Local file I/O operation failed */ +#define YPPUSH_SKEW ((long)-10) /* Map version skew during transfer */ +#define YPPUSH_CLEAR ((long)-11) /* Can't send "Clear" req to local ypserv */ +#define YPPUSH_FORCE ((long)-12) /* No local order number in map - use -f */ +#define YPPUSH_XFRERR ((long)-13) /* ypxfr error */ +#define YPPUSH_REFUSED ((long)-14) /* Transfer request refused by ypserv */ + +struct inaddr; +__BEGIN_DECLS +bool_t xdr_datum(XDR *, datum *); +bool_t xdr_ypreq_key(XDR *, struct ypreq_key *); +bool_t xdr_ypreq_nokey(XDR *, struct ypreq_nokey *); +bool_t xdr_ypreq_xfr(XDR *, struct ypreq_xfr *); +bool_t xdr_ypresp_val(XDR *, struct ypresp_val *); +bool_t xdr_ypresp_key_val(XDR *, struct ypresp_key_val *); +bool_t xdr_ypbind_resp(XDR *, struct ypbind_resp *); +bool_t xdr_ypbind_setdom(XDR *, struct ypbind_setdom *); +bool_t xdr_yp_inaddr(XDR *, struct inaddr *); +bool_t xdr_ypmap_parms(XDR *, struct ypmap_parms *); +bool_t xdr_yppushresp_xfr(XDR *, struct yppushresp_xfr *); +bool_t xdr_ypresp_order(XDR *, struct ypresp_order *); +bool_t xdr_ypresp_master(XDR *, struct ypresp_master *); +bool_t xdr_ypresp_maplist(XDR *, struct ypresp_maplist *); +__END_DECLS + +#endif /* _RPCSVC_YP_PROT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/ypclnt.h b/lib/libc/include/any-freebsd-any/rpcsvc/ypclnt.h new file mode 100644 index 000000000000..c0a0a46e1851 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/ypclnt.h @@ -0,0 +1,95 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992/3 Theo de Raadt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _RPCSVC_YPCLNT_H_ +#define _RPCSVC_YPCLNT_H_ + +#include + +#define YPERR_BADARGS 1 /* args to function are bad */ +#define YPERR_RPC 2 /* RPC failure */ +#define YPERR_DOMAIN 3 /* can't bind to a server for domain */ +#define YPERR_MAP 4 /* no such map in server's domain */ +#define YPERR_KEY 5 /* no such key in map */ +#define YPERR_YPERR 6 /* some internal YP server or client error */ +#define YPERR_RESRC 7 /* local resource allocation failure */ +#define YPERR_NOMORE 8 /* no more records in map database */ +#define YPERR_PMAP 9 /* can't communicate with portmapper */ +#define YPERR_YPBIND 10 /* can't communicate with ypbind */ +#define YPERR_YPSERV 11 /* can't communicate with ypserv */ +#define YPERR_NODOM 12 /* local domain name not set */ +#define YPERR_BADDB 13 /* YP data base is bad */ +#define YPERR_VERS 14 /* YP version mismatch */ +#define YPERR_ACCESS 15 /* access violation */ +#define YPERR_BUSY 16 /* database is busy */ + +/* + * Types of update operations + */ +#define YPOP_CHANGE 1 /* change, do not add */ +#define YPOP_INSERT 2 /* add, do not change */ +#define YPOP_DELETE 3 /* delete this entry */ +#define YPOP_STORE 4 /* add, or change */ + +struct ypall_callback { + /* return non-0 to stop getting called */ + int (*foreach)(unsigned long, char *, int, char *, int, void *); + char *data; /* opaque pointer for use of callback fn */ +}; + +struct dom_binding; +struct ypmaplist; +struct ypall_callback; + +__BEGIN_DECLS +int yp_bind(char *dom); +int _yp_dobind(char *dom, struct dom_binding **ypdb); +void yp_unbind(char *dom); +int yp_get_default_domain(char **domp); +int yp_match(char *indomain, char *inmap, const char *inkey, int inkeylen, + char **outval, int *outvallen); +int yp_first(char *indomain, char *inmap, char **outkey, int *outkeylen, + char **outval, int *outvallen); +int yp_next(char *indomain, char *inmap, char *inkey, int inkeylen, + char **outkey, int *outkeylen, char **outval, int *outvallen); +int yp_maplist(char *indomain, struct ypmaplist **outmaplist); +int yp_master(char *indomain, char *inmap, char **outname); +int yp_order(char *indomain, char *inmap, int *outorder); +int yp_all(char *indomain, char *inmap, struct ypall_callback *incallback); +const char *yperr_string(int incode); +const char *ypbinderr_string(int incode); +int ypprot_err(unsigned int incode); +__END_DECLS + +#endif /* _RPCSVC_YPCLNT_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/yppasswd.x b/lib/libc/include/any-freebsd-any/rpcsvc/yppasswd.x new file mode 100644 index 000000000000..1b39a632fa94 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/yppasswd.x @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * YP password update protocol + * Requires unix authentication + */ + +#ifndef RPC_HDR +%#ifndef lint +%/*static char sccsid[] = "from: @(#)yppasswd.x 1.1 87/04/13 Copyr 1987 Sun Micro";*/ +%/*static char sccsid[] = "from: @(#)yppasswd.x 2.1 88/08/01 4.0 RPCSRC";*/ +%#endif /* not lint */ +%#include +%__FBSDID("$FreeBSD$"); +#endif + +program YPPASSWDPROG { + version YPPASSWDVERS { + /* + * Update my passwd entry + */ + int + YPPASSWDPROC_UPDATE(yppasswd) = 1; + } = 1; +} = 100009; + + +struct x_passwd { + string pw_name<>; /* username */ + string pw_passwd<>; /* encrypted password */ + int pw_uid; /* user id */ + int pw_gid; /* group id */ + string pw_gecos<>; /* in real life name */ + string pw_dir<>; /* home directory */ + string pw_shell<>; /* default shell */ +}; + +struct yppasswd { + string oldpass<>; /* unencrypted old password */ + x_passwd newpw; /* new passwd entry */ +}; + + +#ifdef RPC_HDR +%#include +%extern int _yppasswd( char * , struct x_passwd * ); +%#define yppasswd(x,y) _yppasswd(x,y) +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/ypupdate_prot.x b/lib/libc/include/any-freebsd-any/rpcsvc/ypupdate_prot.x new file mode 100644 index 000000000000..90648a023e6e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/ypupdate_prot.x @@ -0,0 +1,86 @@ +%/* +% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for +% * unrestricted use provided that this legend is included on all tape +% * media and as a part of the software program in whole or part. Users +% * may copy or modify Sun RPC without charge, but are not authorized +% * to license or distribute it to anyone else except as part of a product or +% * program developed by the user or with the express written consent of +% * Sun Microsystems, Inc. +% * +% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE +% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR +% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +% * +% * Sun RPC is provided with no support and without any obligation on the +% * part of Sun Microsystems, Inc. to assist in its use, correction, +% * modification or enhancement. +% * +% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE +% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC +% * OR ANY PART THEREOF. +% * +% * In no event will Sun Microsystems, Inc. be liable for any lost revenue +% * or profits or other special, indirect and consequential damages, even if +% * Sun has been advised of the possibility of such damages. +% * +% * Sun Microsystems, Inc. +% * 2550 Garcia Avenue +% * Mountain View, California 94043 +% */ + +%/* +% * Copyright (c) 1986, 1990 by Sun Microsystems, Inc. +% */ +% +%/* from @(#)ypupdate_prot.x 1.3 91/03/11 TIRPC 1.0 */ +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif +% +%/* +% * Compiled from ypupdate_prot.x using rpcgen +% * This is NOT source code! +% * DO NOT EDIT THIS FILE! +% */ + +/* + * YP update service protocol + */ +#ifdef RPC_HDR +% +%#ifndef _rpcsvc_ypupdate_prot_h +%#define _rpcsvc_ypupdate_prot_h +% +#endif + +const MAXMAPNAMELEN = 255; +const MAXYPDATALEN = 1023; +const MAXERRMSGLEN = 255; + +program YPU_PROG { + version YPU_VERS { + u_int YPU_CHANGE(ypupdate_args) = 1; + u_int YPU_INSERT(ypupdate_args) = 2; + u_int YPU_DELETE(ypdelete_args) = 3; + u_int YPU_STORE(ypupdate_args) = 4; + } = 1; +} = 100028; + +typedef opaque yp_buf; + +struct ypupdate_args { + string mapname; + yp_buf key; + yp_buf datum; +}; + +struct ypdelete_args { + string mapname; + yp_buf key; +}; + +#ifdef RPC_HDR +% +%#endif /* !_rpcsvc_ypupdate_prot_h */ +#endif diff --git a/lib/libc/include/any-freebsd-any/rpcsvc/ypxfrd.x b/lib/libc/include/any-freebsd-any/rpcsvc/ypxfrd.x new file mode 100644 index 000000000000..e6ff902a1dfe --- /dev/null +++ b/lib/libc/include/any-freebsd-any/rpcsvc/ypxfrd.x @@ -0,0 +1,169 @@ +/* + * Copyright (c) 1995, 1996 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * This protocol definition file describes a file transfer + * system used to very quickly move NIS maps from one host to + * another. This is similar to what Sun does with their ypxfrd + * protocol, but it must be stressed that this protocol is _NOT_ + * compatible with Sun's. There are a couple of reasons for this: + * + * 1) Sun's protocol is proprietary. The protocol definition is + * not freely available in any of the SunRPC source distributions, + * even though the NIS v2 protocol is. + * + * 2) The idea here is to transfer entire raw files rather than + * sending just the records. Sun uses ndbm for its NIS map files, + * while FreeBSD uses Berkeley DB. Both are hash databases, but the + * formats are incompatible, making it impossible for them to + * use each others' files. Even if FreeBSD adopted ndbm for its + * database format, FreeBSD/i386 is a little-endian OS and + * SunOS/SPARC is big-endian; ndbm is byte-order sensitive and + * not very smart about it, which means an attempt to read a + * database on a little-endian box that was created on a big-endian + * box (or vice-versa) can cause the ndbm code to eat itself. + * Luckily, Berkeley DB is able to deal with this situation in + * a more graceful manner. + * + * While the protocol is incompatible, the idea is the same: we just open + * up a TCP pipe to the client and transfer the raw map database + * from the master server to the slave. This is many times faster than + * the standard yppush/ypxfr transfer method since it saves us from + * having to recreate the map databases via the DB library each time. + * For example: creating a passwd database with 30,000 entries with yp_mkdb + * can take a couple of minutes, but to just copy the file takes only a few + * seconds. + */ + +#ifndef RPC_HDR +%#include +%__FBSDID("$FreeBSD$"); +#endif + +/* XXX cribbed from yp.x */ +const _YPMAXRECORD = 16777216; +const _YPMAXDOMAIN = 64; +const _YPMAXMAP = 64; +const _YPMAXPEER = 64; + +/* Suggested default -- not necessarily the one used. */ +const YPXFRBLOCK = 32767; + +/* + * Possible return codes from the remote server. + */ +enum xfrstat { + XFR_REQUEST_OK = 1, /* Transfer request granted */ + XFR_DENIED = 2, /* Transfer request denied */ + XFR_NOFILE = 3, /* Requested map file doesn't exist */ + XFR_ACCESS = 4, /* File exists, but I couldn't access it */ + XFR_BADDB = 5, /* File is not a hash database */ + XFR_READ_OK = 6, /* Block read successfully */ + XFR_READ_ERR = 7, /* Read error during transfer */ + XFR_DONE = 8, /* Transfer completed */ + XFR_DB_ENDIAN_MISMATCH = 9, /* Database byte order mismatch */ + XFR_DB_TYPE_MISMATCH = 10 /* Database type mismatch */ +}; + +/* + * Database type specifications. The client can use this to ask + * the server for a particular type of database or just take whatever + * the server has to offer. + */ +enum xfr_db_type { + XFR_DB_ASCII = 1, /* Flat ASCII text */ + XFR_DB_BSD_HASH = 2, /* Berkeley DB, hash method */ + XFR_DB_BSD_BTREE = 3, /* Berkeley DB, btree method */ + XFR_DB_BSD_RECNO = 4, /* Berkeley DB, recno method */ + XFR_DB_BSD_MPOOL = 5, /* Berkeley DB, mpool method */ + XFR_DB_BSD_NDBM = 6, /* Berkeley DB, hash, ndbm compat */ + XFR_DB_GNU_GDBM = 7, /* GNU GDBM */ + XFR_DB_DBM = 8, /* Old, deprecated dbm format */ + XFR_DB_NDBM = 9, /* ndbm format (used by Sun's NISv2) */ + XFR_DB_OPAQUE = 10, /* Mystery format -- just pass along */ + XFR_DB_ANY = 11, /* I'll take any format you've got */ + XFR_DB_UNKNOWN = 12 /* Unknown format */ +}; + +/* + * Machine byte order specification. This allows the client to check + * that it's copying a map database from a machine of similar byte sex. + * This is necessary for handling database libraries that are fatally + * byte order sensitive. + * + * The XFR_ENDIAN_ANY type is for use with the Berkeley DB database + * formats; Berkeley DB is smart enough to make up for byte order + * differences, so byte sex isn't important. + */ +enum xfr_byte_order { + XFR_ENDIAN_BIG = 1, /* We want big endian */ + XFR_ENDIAN_LITTLE = 2, /* We want little endian */ + XFR_ENDIAN_ANY = 3 /* We'll take whatever you got */ +}; + +typedef string xfrdomain<_YPMAXDOMAIN>; +typedef string xfrmap<_YPMAXMAP>; +typedef string xfrmap_filename<_YPMAXMAP>; /* actual name of map file */ + +/* + * Ask the remote ypxfrd for a map using this structure. + * Note: we supply both a map name and a map file name. These are not + * the same thing. In the case of ndbm, maps are stored in two files: + * map.bykey.pag and may.bykey.dir. We may also have to deal with + * file extensions (on the off chance that the remote server is supporting + * multiple DB formats). To handle this, we tell the remote server both + * what map we want and, in the case of ndbm, whether we want the .dir + * or the .pag part. This name should not be a fully qualified path: + * it's up to the remote server to decide which directories to look in. + */ +struct ypxfr_mapname { + xfrmap xfrmap; + xfrdomain xfrdomain; + xfrmap_filename xfrmap_filename; + xfr_db_type xfr_db_type; + xfr_byte_order xfr_byte_order; +}; + +/* Read response using this structure. */ +union xfr switch (bool ok) { +case TRUE: + opaque xfrblock_buf<>; +case FALSE: + xfrstat xfrstat; +}; + +program YPXFRD_FREEBSD_PROG { + version YPXFRD_FREEBSD_VERS { + union xfr + YPXFRD_GETMAP(ypxfr_mapname) = 1; + } = 1; +} = 600100069; /* 100069 + 60000000 -- 100069 is the Sun ypxfrd prog number */ diff --git a/lib/libc/include/any-freebsd-any/runetype.h b/lib/libc/include/any-freebsd-any/runetype.h new file mode 100644 index 000000000000..4aca128f8c8a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/runetype.h @@ -0,0 +1,106 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)runetype.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _RUNETYPE_H_ +#define _RUNETYPE_H_ + +#include +#include + +#define _CACHED_RUNES (1 <<8 ) /* Must be a power of 2 */ +#define _CRMASK (~(_CACHED_RUNES - 1)) + +/* + * The lower 8 bits of runetype[] contain the digit value of the rune. + */ +typedef struct { + __rune_t __min; /* First rune of the range */ + __rune_t __max; /* Last rune (inclusive) of the range */ + __rune_t __map; /* What first maps to in maps */ + unsigned long *__types; /* Array of types in range */ +} _RuneEntry; + +typedef struct { + int __nranges; /* Number of ranges stored */ + _RuneEntry *__ranges; /* Pointer to the ranges */ +} _RuneRange; + +typedef struct { + char __magic[8]; /* Magic saying what version we are */ + char __encoding[32]; /* ASCII name of this encoding */ + + __rune_t (*__sgetrune)(const char *, __size_t, char const **); + int (*__sputrune)(__rune_t, char *, __size_t, char **); + __rune_t __invalid_rune; + + unsigned long __runetype[_CACHED_RUNES]; + __rune_t __maplower[_CACHED_RUNES]; + __rune_t __mapupper[_CACHED_RUNES]; + + /* + * The following are to deal with Runes larger than _CACHED_RUNES - 1. + * Their data is actually contiguous with this structure so as to make + * it easier to read/write from/to disk. + */ + _RuneRange __runetype_ext; + _RuneRange __maplower_ext; + _RuneRange __mapupper_ext; + + void *__variable; /* Data which depends on the encoding */ + int __variable_len; /* how long that data is */ +} _RuneLocale; + +#define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */ +__BEGIN_DECLS +extern const _RuneLocale _DefaultRuneLocale; +extern const _RuneLocale *_CurrentRuneLocale; +#if defined(__NO_TLS) || defined(__RUNETYPE_INTERNAL) +extern const _RuneLocale *__getCurrentRuneLocale(void); +#else +extern _Thread_local const _RuneLocale *_ThreadRuneLocale; +static __inline const _RuneLocale *__getCurrentRuneLocale(void) +{ + + if (_ThreadRuneLocale) + return _ThreadRuneLocale; + return _CurrentRuneLocale; +} +#endif /* __NO_TLS || __RUNETYPE_INTERNAL */ +#define _CurrentRuneLocale (__getCurrentRuneLocale()) +__END_DECLS + +#endif /* !_RUNETYPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/search.h b/lib/libc/include/any-freebsd-any/search.h new file mode 100644 index 000000000000..068446fdcb88 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/search.h @@ -0,0 +1,85 @@ +/*- + * Written by J.T. Conklin + * Public domain. + * + * $NetBSD: search.h,v 1.16 2005/02/03 04:39:32 perry Exp $ + * $FreeBSD$ + */ + +#ifndef _SEARCH_H_ +#define _SEARCH_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct entry { + char *key; + void *data; +} ENTRY; + +typedef enum { + FIND, ENTER +} ACTION; + +typedef enum { + preorder, + postorder, + endorder, + leaf +} VISIT; + +#ifdef _SEARCH_PRIVATE +typedef struct __posix_tnode { + void *key; + struct __posix_tnode *llink, *rlink; + signed char balance; +} posix_tnode; + +struct que_elem { + struct que_elem *next; + struct que_elem *prev; +}; +#else +typedef void posix_tnode; +#endif + +#if __BSD_VISIBLE +struct hsearch_data { + struct __hsearch *__hsearch; +}; +#endif + +__BEGIN_DECLS +int hcreate(size_t); +void hdestroy(void); +ENTRY *hsearch(ENTRY, ACTION); +void insque(void *, void *); +void *lfind(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *)); +void *lsearch(const void *, void *, size_t *, size_t, + int (*)(const void *, const void *)); +void remque(void *); +void *tdelete(const void * __restrict, posix_tnode ** __restrict, + int (*)(const void *, const void *)); +posix_tnode * + tfind(const void *, posix_tnode * const *, + int (*)(const void *, const void *)); +posix_tnode * + tsearch(const void *, posix_tnode **, + int (*)(const void *, const void *)); +void twalk(const posix_tnode *, void (*)(const posix_tnode *, VISIT, int)); + +#if __BSD_VISIBLE +int hcreate_r(size_t, struct hsearch_data *); +void hdestroy_r(struct hsearch_data *); +int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); +#endif + +__END_DECLS + +#endif /* !_SEARCH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/semaphore.h b/lib/libc/include/any-freebsd-any/semaphore.h new file mode 100644 index 000000000000..f330d5142058 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/semaphore.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 David Xu + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* semaphore.h: POSIX 1003.1b semaphores */ + +#ifndef _SEMAPHORE_H_ +#define _SEMAPHORE_H_ + +#include +#include +#include + +#include + +struct _sem { + __uint32_t _magic; + struct _usem2 _kern; + __uint32_t _padding; /* Preserve structure size */ +}; + +typedef struct _sem sem_t; + +#define SEM_FAILED ((sem_t *)0) +#define SEM_VALUE_MAX __INT_MAX + +struct timespec; + +__BEGIN_DECLS +#if __BSD_VISIBLE +int sem_clockwait_np(sem_t * __restrict, __clockid_t, int, + const struct timespec *, struct timespec *); +#endif +int sem_close(sem_t *); +int sem_destroy(sem_t *); +int sem_getvalue(sem_t * __restrict, int * __restrict); +int sem_init(sem_t *, int, unsigned int); +sem_t *sem_open(const char *, int, ...); +int sem_post(sem_t *); +int sem_timedwait(sem_t * __restrict, const struct timespec * __restrict); +int sem_trywait(sem_t *); +int sem_unlink(const char *); +int sem_wait(sem_t *); +__END_DECLS + +#endif /* !_SEMAPHORE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/setjmp.h b/lib/libc/include/any-freebsd-any/setjmp.h new file mode 100644 index 000000000000..1cc8b7762499 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/setjmp.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)setjmp.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#include + +/* The size of the jmp_buf is machine dependent: */ +#include + +__BEGIN_DECLS +#if __XSI_VISIBLE >= 600 +void _longjmp(jmp_buf, int) __dead2; +int _setjmp(jmp_buf) __returns_twice; +#endif +void longjmp(jmp_buf, int) __dead2; +#if __BSD_VISIBLE +void longjmperror(void); +#endif +int setjmp(jmp_buf) __returns_twice; +#if __POSIX_VISIBLE || __XSI_VISIBLE +void siglongjmp(sigjmp_buf, int) __dead2; +int sigsetjmp(sigjmp_buf, int) __returns_twice; +#endif +__END_DECLS + +#endif /* !_SETJMP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/signal.h b/lib/libc/include/any-freebsd-any/signal.h new file mode 100644 index 000000000000..3b20875290d6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/signal.h @@ -0,0 +1,137 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.3 (Berkeley) 3/30/94 + * $FreeBSD$ + */ + +#ifndef _SIGNAL_H_ +#define _SIGNAL_H_ + +#include +#include +#include +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#include +#include +#endif + +__NULLABILITY_PRAGMA_PUSH + +#if __BSD_VISIBLE +/* + * XXX should enlarge these, if only to give empty names instead of bounds + * errors for large signal numbers. + */ +extern const char * const sys_signame[NSIG]; +extern const char * const sys_siglist[NSIG]; +extern const int sys_nsig; +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +struct pthread; /* XXX */ +typedef struct pthread *__pthread_t; +#if !defined(_PTHREAD_T_DECLARED) && __POSIX_VISIBLE >= 200809 +typedef __pthread_t pthread_t; +#define _PTHREAD_T_DECLARED +#endif +#endif /* __POSIX_VISIBLE || __XSI_VISIBLE */ + +__BEGIN_DECLS +int raise(int); + +#if __POSIX_VISIBLE || __XSI_VISIBLE +int kill(__pid_t, int); +int pthread_kill(__pthread_t, int); +int pthread_sigmask(int, const __sigset_t * __restrict, + __sigset_t * __restrict); +int sigaction(int, const struct sigaction * __restrict, + struct sigaction * __restrict); +int sigaddset(sigset_t *, int); +int sigdelset(sigset_t *, int); +int sigemptyset(sigset_t *); +int sigfillset(sigset_t *); +int sigismember(const sigset_t *, int); +int sigpending(sigset_t * _Nonnull); +int sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict); +int sigsuspend(const sigset_t * _Nonnull); +int sigwait(const sigset_t * _Nonnull __restrict, + int * _Nonnull __restrict); +#endif + +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 600 +int sigqueue(__pid_t, int, const union sigval); + +struct timespec; +int sigtimedwait(const sigset_t * __restrict, siginfo_t * __restrict, + const struct timespec * __restrict); +int sigwaitinfo(const sigset_t * __restrict, siginfo_t * __restrict); +#endif + +#if __XSI_VISIBLE +int killpg(__pid_t, int); +int sigaltstack(const stack_t * __restrict, stack_t * __restrict); +int sighold(int); +int sigignore(int); +int sigpause(int); +int sigrelse(int); +void (* _Nullable sigset(int, void (* _Nullable)(int)))(int); +int xsi_sigpause(int); +#endif + +#if __XSI_VISIBLE >= 600 +int siginterrupt(int, int); +#endif + +#if __POSIX_VISIBLE >= 200809 +void psignal(int, const char *); +#endif + +#if __BSD_VISIBLE +int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right); +int sigblock(int); +int sigisemptyset(const sigset_t *set); +int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right); +int sigreturn(const struct __ucontext *); +int sigsetmask(int); +int sigstack(const struct sigstack *, struct sigstack *); +int sigvec(int, struct sigvec *, struct sigvec *); +#endif +__END_DECLS +__NULLABILITY_PRAGMA_POP + +#endif /* !_SIGNAL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/spawn.h b/lib/libc/include/any-freebsd-any/spawn.h new file mode 100644 index 000000000000..79753bba0510 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/spawn.h @@ -0,0 +1,120 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SPAWN_H_ +#define _SPAWN_H_ + +#include +#include +#include + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif + +struct sched_param; + +typedef struct __posix_spawnattr *posix_spawnattr_t; +typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; + +#define POSIX_SPAWN_RESETIDS 0x01 +#define POSIX_SPAWN_SETPGROUP 0x02 +#define POSIX_SPAWN_SETSCHEDPARAM 0x04 +#define POSIX_SPAWN_SETSCHEDULER 0x08 +#define POSIX_SPAWN_SETSIGDEF 0x10 +#define POSIX_SPAWN_SETSIGMASK 0x20 + +__BEGIN_DECLS +/* + * Spawn routines + * + * XXX both arrays should be __restrict, but this does not work when GCC + * is invoked with -std=c99. + */ +int posix_spawn(pid_t * __restrict, const char * __restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, + char * const [], char * const []); +int posix_spawnp(pid_t * __restrict, const char * __restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, + char * const [], char * const []); + +/* + * File descriptor actions + */ +int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); +int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); + +int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict, + int, const char * __restrict, int, mode_t); +int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); +int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); + +/* + * Spawn attributes + */ +int posix_spawnattr_init(posix_spawnattr_t *); +int posix_spawnattr_destroy(posix_spawnattr_t *); + +int posix_spawnattr_getflags(const posix_spawnattr_t * __restrict, + short * __restrict); +int posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict, + pid_t * __restrict); +int posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict, + struct sched_param * __restrict); +int posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict, + int * __restrict); +int posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict, + sigset_t * __restrict); +int posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict, + sigset_t * __restrict sigmask); + +int posix_spawnattr_setflags(posix_spawnattr_t *, short); +int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); +int posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict, + const struct sched_param * __restrict); +int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int); +int posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict, + const sigset_t * __restrict); +int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict, + const sigset_t * __restrict); +__END_DECLS + +#endif /* !_SPAWN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/stab.h b/lib/libc/include/any-freebsd-any/stab.h new file mode 100644 index 000000000000..9abff130ff7d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stab.h @@ -0,0 +1,72 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stab.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _STAB_H_ +#define _STAB_H_ + +/* + * The following are symbols used by various debuggers and by the Pascal + * compiler. Each of them must have one (or more) of the bits defined by + * the N_STAB mask set. + */ + +#define N_GSYM 0x20 /* global symbol */ +#define N_FNAME 0x22 /* F77 function name */ +#define N_FUN 0x24 /* procedure name */ +#define N_STSYM 0x26 /* data segment variable */ +#define N_LCSYM 0x28 /* bss segment variable */ +#define N_MAIN 0x2a /* main function name */ +#define N_PC 0x30 /* global Pascal symbol */ +#define N_RSYM 0x40 /* register variable */ +#define N_SLINE 0x44 /* text segment line number */ +#define N_DSLINE 0x46 /* data segment line number */ +#define N_BSLINE 0x48 /* bss segment line number */ +#define N_SSYM 0x60 /* structure/union element */ +#define N_SO 0x64 /* main source file name */ +#define N_LSYM 0x80 /* stack variable */ +#define N_BINCL 0x82 /* include file beginning */ +#define N_SOL 0x84 /* included source file name */ +#define N_PSYM 0xa0 /* parameter variable */ +#define N_EINCL 0xa2 /* include file end */ +#define N_ENTRY 0xa4 /* alternate entry point */ +#define N_LBRAC 0xc0 /* left bracket */ +#define N_EXCL 0xc2 /* deleted include file */ +#define N_RBRAC 0xe0 /* right bracket */ +#define N_BCOMM 0xe2 /* begin common */ +#define N_ECOMM 0xe4 /* end common */ +#define N_ECOML 0xe8 /* end common (local name) */ +#define N_LENG 0xfe /* length of preceding entry */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/stdalign.h b/lib/libc/include/any-freebsd-any/stdalign.h new file mode 100644 index 000000000000..6f777fde3df5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdalign.h @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __alignas_is_defined +#define __alignas_is_defined 1 + +#if !defined(__cplusplus) || __cplusplus < 201103L +#include +#define alignas _Alignas +#endif + +#endif /* !__alignas_is_defined */ + +#ifndef __alignof_is_defined +#define __alignof_is_defined 1 + +#if !defined(__cplusplus) || __cplusplus < 201103L +#include +#define alignof _Alignof +#endif + +#endif /* !__alignof_is_defined */ diff --git a/lib/libc/include/any-freebsd-any/stdbool.h b/lib/libc/include/any-freebsd-any/stdbool.h new file mode 100644 index 000000000000..267e1ad2a1a0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdbool.h @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Jeroen Ruigrok van der Werven + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __bool_true_false_are_defined +#define __bool_true_false_are_defined 1 + +#ifndef __cplusplus + +#define false 0 +#define true 1 + +#define bool _Bool +#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 && !defined(__INTEL_COMPILER) +typedef int _Bool; +#endif + +#endif /* !__cplusplus */ +#endif /* __bool_true_false_are_defined */ diff --git a/lib/libc/include/any-freebsd-any/stddef.h b/lib/libc/include/any-freebsd-any/stddef.h new file mode 100644 index 000000000000..a52e6d312f84 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stddef.h @@ -0,0 +1,85 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stddef.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _STDDEF_H_ +#define _STDDEF_H_ + +#include +#include +#include + +#ifndef _PTRDIFF_T_DECLARED +typedef __ptrdiff_t ptrdiff_t; +#define _PTRDIFF_T_DECLARED +#endif + +#if __BSD_VISIBLE +#ifndef _RUNE_T_DECLARED +typedef __rune_t rune_t; +#define _RUNE_T_DECLARED +#endif +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef ___wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +#ifndef __CLANG_MAX_ALIGN_T_DEFINED +typedef __max_align_t max_align_t; +#define __CLANG_MAX_ALIGN_T_DEFINED +#define _GCC_MAX_ALIGN_T +#endif +#endif + +#define offsetof(type, field) __offsetof(type, field) + +#if __EXT1_VISIBLE +/* ISO/IEC 9899:2011 K.3.3.2 */ +#ifndef _RSIZE_T_DEFINED +#define _RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif +#endif /* __EXT1_VISIBLE */ + +#endif /* _STDDEF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/stdio.h b/lib/libc/include/any-freebsd-any/stdio.h new file mode 100644 index 000000000000..eb155a0c231e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdio.h @@ -0,0 +1,535 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stdio.h 8.5 (Berkeley) 4/29/95 + * $FreeBSD$ + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include +#include +#include + +__NULLABILITY_PRAGMA_PUSH + +typedef __off_t fpos_t; + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _RSIZE_T_DEFINED +#define _RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _OFF_T_DECLARED +#define _OFF_T_DECLARED +typedef __off_t off_t; +#endif +#ifndef _SSIZE_T_DECLARED +#define _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#endif +#endif + +#ifndef _OFF64_T_DECLARED +#define _OFF64_T_DECLARED +typedef __off64_t off64_t; +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#ifndef _VA_LIST_DECLARED +typedef __va_list va_list; +#define _VA_LIST_DECLARED +#endif +#endif + +#define _FSTDIO /* Define for new stdio with functions. */ + +/* + * NB: to fit things in six character monocase externals, the stdio + * code uses the prefix `__s' for stdio objects, typically followed + * by a three-character attempt at a mnemonic. + */ + +/* stdio buffers */ +struct __sbuf { + unsigned char *_base; + int _size; +}; + +/* + * stdio state variables. + * + * The following always hold: + * + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), + * _lbfsize is -_bf._size, else _lbfsize is 0 + * if _flags&__SRD, _w is 0 + * if _flags&__SWR, _r is 0 + * + * This ensures that the getc and putc macros (or inline functions) never + * try to write or read from a file that is in `read' or `write' mode. + * (Moreover, they can, and do, automatically switch from read mode to + * write mode, and back, on "r+" and "w+" files.) + * + * _lbfsize is used only to make the inline line-buffered output stream + * code as compact as possible. + * + * _ub, _up, and _ur are used when ungetc() pushes back more characters + * than fit in the current _bf, or when ungetc() pushes back a character + * that does not match the previous one in _bf. When this happens, + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. + * + * Certain members of __sFILE are accessed directly via macros or + * inline functions. To preserve ABI compat, these members must not + * be disturbed. These members are marked below with (*). + */ +struct __sFILE { + unsigned char *_p; /* (*) current position in (some) buffer */ + int _r; /* (*) read space left for getc() */ + int _w; /* (*) write space left for putc() */ + short _flags; /* (*) flags, below; this FILE is free if 0 */ + short _file; /* (*) fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ + + /* operations */ + void *_cookie; /* (*) cookie passed to io functions */ + int (* _Nullable _close)(void *); + int (* _Nullable _read)(void *, char *, int); + fpos_t (* _Nullable _seek)(void *, fpos_t, int); + int (* _Nullable _write)(void *, const char *, int); + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetln() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetln() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + fpos_t _offset; /* current lseek offset */ + + struct pthread_mutex *_fl_mutex; /* used for MT-safety */ + struct pthread *_fl_owner; /* current owner */ + int _fl_count; /* recursive lock count */ + int _orientation; /* orientation for fwide() */ + __mbstate_t _mbstate; /* multibyte conversion state */ + int _flags2; /* additional flags */ +}; +#ifndef _STDFILE_DECLARED +#define _STDFILE_DECLARED +typedef struct __sFILE FILE; +#endif +#ifndef _STDSTREAM_DECLARED +__BEGIN_DECLS +extern FILE *__stdinp; +extern FILE *__stdoutp; +extern FILE *__stderrp; +__END_DECLS +#define _STDSTREAM_DECLARED +#endif + +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* OK to read */ +#define __SWR 0x0008 /* OK to write */ + /* RD and WR are never simultaneously asserted */ +#define __SRW 0x0010 /* open for reading & writing */ +#define __SEOF 0x0020 /* found EOF */ +#define __SERR 0x0040 /* found error */ +#define __SMBF 0x0080 /* _bf._base is from malloc */ +#define __SAPP 0x0100 /* fdopen()ed in append mode */ +#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ +#define __SOPT 0x0400 /* do fseek() optimization */ +#define __SNPT 0x0800 /* do not do fseek() optimization */ +#define __SOFF 0x1000 /* set iff _offset is in fact correct */ +#define __SMOD 0x2000 /* true => fgetln modified _p text */ +#define __SALC 0x4000 /* allocate string space dynamically */ +#define __SIGN 0x8000 /* ignore this file in _fwalk */ + +#define __S2OAP 0x0001 /* O_APPEND mode is set */ + +/* + * The following three definitions are for ANSI C, which took them + * from System V, which brilliantly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although numbered as their counterparts above, the implementation + * does not rely on this. + */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +#define BUFSIZ 1024 /* size of buffer used by setbuf */ +#define EOF (-1) + +/* + * FOPEN_MAX is a minimum maximum, and is the number of streams that + * stdio can provide without attempting to allocate further resources + * (which could fail). Do not use this for anything. + */ + /* must be == _POSIX_STREAM_MAX */ +#ifndef FOPEN_MAX +#define FOPEN_MAX 20 /* must be <= OPEN_MAX */ +#endif +#define FILENAME_MAX 1024 /* must be <= PATH_MAX */ + +/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ +#if __XSI_VISIBLE +#define P_tmpdir "/tmp/" +#endif +#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ +#define TMP_MAX 308915776 + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define stdin __stdinp +#define stdout __stdoutp +#define stderr __stderrp + +__BEGIN_DECLS +#ifdef _XLOCALE_H_ +#include +#endif +/* + * Functions defined in ANSI C standard. + */ +void clearerr(FILE *); +int fclose(FILE *); +int feof(FILE *); +int ferror(FILE *); +int fflush(FILE *); +int fgetc(FILE *); +int fgetpos(FILE * __restrict, fpos_t * __restrict); +char *fgets(char * __restrict, int, FILE * __restrict); +FILE *fopen(const char * __restrict, const char * __restrict); +int fprintf(FILE * __restrict, const char * __restrict, ...); +int fputc(int, FILE *); +int fputs(const char * __restrict, FILE * __restrict); +size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); +FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); +int fscanf(FILE * __restrict, const char * __restrict, ...); +int fseek(FILE *, long, int); +int fsetpos(FILE *, const fpos_t *); +long ftell(FILE *); +size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); +int getc(FILE *); +int getchar(void); +char *gets(char *); +#if __EXT1_VISIBLE +char *gets_s(char *, rsize_t); +#endif +void perror(const char *); +int printf(const char * __restrict, ...); +int putc(int, FILE *); +int putchar(int); +int puts(const char *); +int remove(const char *); +int rename(const char *, const char *); +void rewind(FILE *); +int scanf(const char * __restrict, ...); +void setbuf(FILE * __restrict, char * __restrict); +int setvbuf(FILE * __restrict, char * __restrict, int, size_t); +int sprintf(char * __restrict, const char * __restrict, ...); +int sscanf(const char * __restrict, const char * __restrict, ...); +FILE *tmpfile(void); +char *tmpnam(char *); +int ungetc(int, FILE *); +int vfprintf(FILE * __restrict, const char * __restrict, + __va_list); +int vprintf(const char * __restrict, __va_list); +int vsprintf(char * __restrict, const char * __restrict, + __va_list); + +#if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 199506 +int snprintf(char * __restrict, size_t, const char * __restrict, + ...) __printflike(3, 4); +int vsnprintf(char * __restrict, size_t, const char * __restrict, + __va_list) __printflike(3, 0); +#endif +#if __ISO_C_VISIBLE >= 1999 +int vfscanf(FILE * __restrict, const char * __restrict, __va_list) + __scanflike(2, 0); +int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); +int vsscanf(const char * __restrict, const char * __restrict, __va_list) + __scanflike(2, 0); +#endif + +/* + * Functions defined in all versions of POSIX 1003.1. + */ +#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506) +#define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */ +#endif + +#if __POSIX_VISIBLE +#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ + +char *ctermid(char *); +FILE *fdopen(int, const char *); +int fileno(FILE *); +#endif /* __POSIX_VISIBLE */ + +#if __POSIX_VISIBLE >= 199209 +int pclose(FILE *); +FILE *popen(const char *, const char *); +#endif + +#if __POSIX_VISIBLE >= 199506 +int ftrylockfile(FILE *); +void flockfile(FILE *); +void funlockfile(FILE *); + +/* + * These are normally used through macros as defined below, but POSIX + * requires functions as well. + */ +int getc_unlocked(FILE *); +int getchar_unlocked(void); +int putc_unlocked(int, FILE *); +int putchar_unlocked(int); +#endif +#if __BSD_VISIBLE +void clearerr_unlocked(FILE *); +int feof_unlocked(FILE *); +int ferror_unlocked(FILE *); +int fflush_unlocked(FILE *); +int fileno_unlocked(FILE *); +int fputc_unlocked(int, FILE *); +int fputs_unlocked(const char * __restrict, FILE * __restrict); +size_t fread_unlocked(void * __restrict, size_t, size_t, FILE * __restrict); +size_t fwrite_unlocked(const void * __restrict, size_t, size_t, + FILE * __restrict); +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 +int fseeko(FILE *, __off_t, int); +__off_t ftello(FILE *); +#endif + +#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 +int getw(FILE *); +int putw(int, FILE *); +#endif /* BSD or X/Open before issue 6 */ + +#if __XSI_VISIBLE +char *tempnam(const char *, const char *); +#endif + +#if __POSIX_VISIBLE >= 200809 +FILE *fmemopen(void * __restrict, size_t, const char * __restrict); +ssize_t getdelim(char ** __restrict, size_t * __restrict, int, + FILE * __restrict); +FILE *open_memstream(char **, size_t *); +int renameat(int, const char *, int, const char *); +int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0); +/* _WITH_GETLINE to allow pre 11 sources to build on 11+ systems */ +ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); +int dprintf(int, const char * __restrict, ...) __printflike(2, 3); +#endif /* __POSIX_VISIBLE >= 200809 */ + +/* + * Routines that are purely local. + */ +#if __BSD_VISIBLE +int asprintf(char **, const char *, ...) __printflike(2, 3); +char *ctermid_r(char *); +void fcloseall(void); +int fdclose(FILE *, int *); +char *fgetln(FILE *, size_t *); +const char *fmtcheck(const char *, const char *) __format_arg(2); +int fpurge(FILE *); +void setbuffer(FILE *, char *, int); +int setlinebuf(FILE *); +int vasprintf(char **, const char *, __va_list) + __printflike(2, 0); + +/* + * The system error table contains messages for the first sys_nerr + * positive errno values. Use strerror() or strerror_r() from + * instead. + */ +extern const int sys_nerr; +extern const char * const sys_errlist[]; + +/* + * Stdio function-access interface. + */ +FILE *funopen(const void *, + int (* _Nullable)(void *, char *, int), + int (* _Nullable)(void *, const char *, int), + fpos_t (* _Nullable)(void *, fpos_t, int), + int (* _Nullable)(void *)); +#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) +#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) + +typedef __ssize_t cookie_read_function_t(void *, char *, size_t); +typedef __ssize_t cookie_write_function_t(void *, const char *, size_t); +typedef int cookie_seek_function_t(void *, off64_t *, int); +typedef int cookie_close_function_t(void *); +typedef struct { + cookie_read_function_t *read; + cookie_write_function_t *write; + cookie_seek_function_t *seek; + cookie_close_function_t *close; +} cookie_io_functions_t; +FILE *fopencookie(void *, const char *, cookie_io_functions_t); + +/* + * Portability hacks. See . + */ +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, __off_t); +#endif +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +__off_t lseek(int, __off_t, int); +#endif +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void *mmap(void *, size_t, int, int, int, __off_t); +#endif +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, __off_t); +#endif +#endif /* __BSD_VISIBLE */ + +/* + * Functions internal to the implementation. + */ +int __srget(FILE *); +int __swbuf(int, FILE *); + +/* + * The __sfoo macros are here so that we can + * define function versions in the C library. + */ +#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) +#if defined(__GNUC__) && defined(__STDC__) +static __inline int __sputc(int _c, FILE *_p) { + if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) + return (*_p->_p++ = _c); + else + return (__swbuf(_c, _p)); +} +#else +/* + * This has been tuned to generate reasonable code on the vax using pcc. + */ +#define __sputc(c, p) \ + (--(p)->_w < 0 ? \ + (p)->_w >= (p)->_lbfsize ? \ + (*(p)->_p = (c)), *(p)->_p != '\n' ? \ + (int)*(p)->_p++ : \ + __swbuf('\n', p) : \ + __swbuf((int)(c), p) : \ + (*(p)->_p = (c), (int)*(p)->_p++)) +#endif + +#ifndef __LIBC_ISTHREADED_DECLARED +#define __LIBC_ISTHREADED_DECLARED +extern int __isthreaded; +#endif + +#ifndef __cplusplus + +#define __sfeof(p) (((p)->_flags & __SEOF) != 0) +#define __sferror(p) (((p)->_flags & __SERR) != 0) +#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) +#define __sfileno(p) ((p)->_file) + + +#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) +#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) +#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) + +#if __POSIX_VISIBLE +#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) +#endif + +#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) +#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdout) + +#if __BSD_VISIBLE +/* + * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 + * B.8.2.7 for the rationale behind the *_unlocked() macros. + */ +#define clearerr_unlocked(p) __sclearerr(p) +#define feof_unlocked(p) __sfeof(p) +#define ferror_unlocked(p) __sferror(p) +#define fileno_unlocked(p) __sfileno(p) +#define fputc_unlocked(s, p) __sputc(s, p) +#endif +#if __POSIX_VISIBLE >= 199506 +#define getc_unlocked(fp) __sgetc(fp) +#define putc_unlocked(x, fp) __sputc(x, fp) + +#define getchar_unlocked() getc_unlocked(stdin) +#define putchar_unlocked(x) putc_unlocked(x, stdout) +#endif +#endif /* __cplusplus */ + +__END_DECLS +__NULLABILITY_PRAGMA_POP + +#endif /* !_STDIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/stdlib.h b/lib/libc/include/any-freebsd-any/stdlib.h new file mode 100644 index 000000000000..b2264784ed80 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdlib.h @@ -0,0 +1,347 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 + * $FreeBSD$ + */ + +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include +#include +#include + +__NULLABILITY_PRAGMA_PUSH + +#if __BSD_VISIBLE +#ifndef _RUNE_T_DECLARED +typedef __rune_t rune_t; +#define _RUNE_T_DECLARED +#endif +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef ___wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +typedef struct { + long quot; + long rem; +} ldiv_t; + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7ffffffd + +__BEGIN_DECLS +#ifdef _XLOCALE_H_ +#include +#endif +extern int __mb_cur_max; +extern int ___mb_cur_max(void); +#define MB_CUR_MAX ((size_t)___mb_cur_max()) + +_Noreturn void abort(void); +int abs(int) __pure2; +int atexit(void (* _Nonnull)(void)); +double atof(const char *); +int atoi(const char *); +long atol(const char *); +void *bsearch(const void *, const void *, size_t, + size_t, int (*)(const void * _Nonnull, const void *)); +void *calloc(size_t, size_t) __malloc_like __result_use_check + __alloc_size2(1, 2); +div_t div(int, int) __pure2; +_Noreturn void exit(int); +void free(void *); +char *getenv(const char *); +long labs(long) __pure2; +ldiv_t ldiv(long, long) __pure2; +void *malloc(size_t) __malloc_like __result_use_check __alloc_size(1); +int mblen(const char *, size_t); +size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); +int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); +void qsort(void *, size_t, size_t, + int (* _Nonnull)(const void *, const void *)); +int rand(void); +void *realloc(void *, size_t) __result_use_check __alloc_size(2); +void srand(unsigned); +double strtod(const char * __restrict, char ** __restrict); +float strtof(const char * __restrict, char ** __restrict); +long strtol(const char * __restrict, char ** __restrict, int); +long double + strtold(const char * __restrict, char ** __restrict); +unsigned long + strtoul(const char * __restrict, char ** __restrict, int); +int system(const char *); +int wctomb(char *, wchar_t); +size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); + +/* + * Functions added in C99 which we make conditionally available in the + * BSD^C89 namespace if the compiler supports `long long'. + * The #if test is more complicated than it ought to be because + * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' + * is not supported in the compilation environment (which therefore means + * that it can't really be ISO C99). + * + * (The only other extension made by C99 in thie header is _Exit().) + */ +#if __ISO_C_VISIBLE >= 1999 || defined(__cplusplus) +#ifdef __LONG_LONG_SUPPORTED +/* LONGLONG */ +typedef struct { + long long quot; + long long rem; +} lldiv_t; + +/* LONGLONG */ +long long + atoll(const char *); +/* LONGLONG */ +long long + llabs(long long) __pure2; +/* LONGLONG */ +lldiv_t lldiv(long long, long long) __pure2; +/* LONGLONG */ +long long + strtoll(const char * __restrict, char ** __restrict, int); +/* LONGLONG */ +unsigned long long + strtoull(const char * __restrict, char ** __restrict, int); +#endif /* __LONG_LONG_SUPPORTED */ + +_Noreturn void _Exit(int); +#endif /* __ISO_C_VISIBLE >= 1999 */ + +/* + * If we're in a mode greater than C99, expose C11 functions. + */ +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1) + __alloc_size(2); +int at_quick_exit(void (*)(void)); +_Noreturn void + quick_exit(int); +#endif /* __ISO_C_VISIBLE >= 2011 */ +/* + * Extensions made by POSIX relative to C. + */ +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE +char *realpath(const char * __restrict, char * __restrict); +#endif +#if __POSIX_VISIBLE >= 199506 +int rand_r(unsigned *); /* (TSF) */ +#endif +#if __POSIX_VISIBLE >= 200112 +int posix_memalign(void **, size_t, size_t); /* (ADV) */ +int setenv(const char *, const char *, int); +int unsetenv(const char *); +#endif + +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE +int getsubopt(char **, char *const *, char **); +#ifndef _MKDTEMP_DECLARED +char *mkdtemp(char *); +#define _MKDTEMP_DECLARED +#endif +#ifndef _MKSTEMP_DECLARED +int mkstemp(char *); +#define _MKSTEMP_DECLARED +#endif +#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ + +/* + * The only changes to the XSI namespace in revision 6 were the deletion + * of the ttyslot() and valloc() functions, which FreeBSD never declared + * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which + * FreeBSD also does not have, and mktemp(), are to be deleted. + */ +#if __XSI_VISIBLE +/* XXX XSI requires pollution from here. We'd rather not. */ +long a64l(const char *); +double drand48(void); +/* char *ecvt(double, int, int * __restrict, int * __restrict); */ +double erand48(unsigned short[3]); +/* char *fcvt(double, int, int * __restrict, int * __restrict); */ +/* char *gcvt(double, int, int * __restrict, int * __restrict); */ +int grantpt(int); +char *initstate(unsigned int, char *, size_t); +long jrand48(unsigned short[3]); +char *l64a(long); +void lcong48(unsigned short[7]); +long lrand48(void); +#if !defined(_MKTEMP_DECLARED) && (__BSD_VISIBLE || __XSI_VISIBLE <= 600) +char *mktemp(char *); +#define _MKTEMP_DECLARED +#endif +long mrand48(void); +long nrand48(unsigned short[3]); +int posix_openpt(int); +char *ptsname(int); +int putenv(char *); +long random(void); +unsigned short + *seed48(unsigned short[3]); +char *setstate(/* const */ char *); +void srand48(long); +void srandom(unsigned int); +int unlockpt(int); +#endif /* __XSI_VISIBLE */ + +#if __BSD_VISIBLE +extern const char *malloc_conf; +extern void (*malloc_message)(void *, const char *); + +/* + * The alloca() function can't be implemented in C, and on some + * platforms it can't be implemented at all as a callable function. + * The GNU C compiler provides a built-in alloca() which we can use. + * On platforms where alloca() is not in libc, programs which use it + * will fail to link when compiled with non-GNU compilers. + */ +#if __GNUC__ >= 2 || defined(__INTEL_COMPILER) +#undef alloca /* some GNU bits try to get cute and define this on their own */ +#define alloca(sz) __builtin_alloca(sz) +#endif + +void abort2(const char *, int, void **) __dead2; +__uint32_t + arc4random(void); +void arc4random_buf(void *, size_t); +__uint32_t + arc4random_uniform(__uint32_t); + +#ifdef __BLOCKS__ +int atexit_b(void (^ _Nonnull)(void)); +void *bsearch_b(const void *, const void *, size_t, + size_t, int (^ _Nonnull)(const void *, const void *)); +#endif +char *getbsize(int *, long *); + /* getcap(3) functions */ +char *cgetcap(char *, const char *, int); +int cgetclose(void); +int cgetent(char **, char **, const char *); +int cgetfirst(char **, char **); +int cgetmatch(const char *, const char *); +int cgetnext(char **, char **); +int cgetnum(char *, const char *, long *); +int cgetset(const char *); +int cgetstr(char *, const char *, char **); +int cgetustr(char *, const char *, char **); + +int daemon(int, int); +int daemonfd(int, int); +char *devname(__dev_t, __mode_t); +char *devname_r(__dev_t, __mode_t, char *, int); +char *fdevname(int); +char *fdevname_r(int, char *, int); +int getloadavg(double [], int); +const char * + getprogname(void); + +int heapsort(void *, size_t, size_t, + int (* _Nonnull)(const void *, const void *)); +#ifdef __BLOCKS__ +int heapsort_b(void *, size_t, size_t, + int (^ _Nonnull)(const void *, const void *)); +void qsort_b(void *, size_t, size_t, + int (^ _Nonnull)(const void *, const void *)); +#endif +int l64a_r(long, char *, int); +int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); +#ifdef __BLOCKS__ +int mergesort_b(void *, size_t, size_t, int (^)(const void *, const void *)); +#endif +int mkostemp(char *, int); +int mkostemps(char *, int, int); +void qsort_r(void *, size_t, size_t, void *, + int (*)(void *, const void *, const void *)); +int radixsort(const unsigned char **, int, const unsigned char *, + unsigned); +void *reallocarray(void *, size_t, size_t) __result_use_check + __alloc_size2(2, 3); +void *reallocf(void *, size_t) __result_use_check __alloc_size(2); +int rpmatch(const char *); +void setprogname(const char *); +int sradixsort(const unsigned char **, int, const unsigned char *, + unsigned); +void sranddev(void); +void srandomdev(void); +long long + strtonum(const char *, long long, long long, const char **); + +/* Deprecated interfaces, to be removed. */ +__int64_t + strtoq(const char *, char **, int); +__uint64_t + strtouq(const char *, char **, int); + +extern char *suboptarg; /* getsubopt(3) external variable */ +#endif /* __BSD_VISIBLE */ + +#if __EXT1_VISIBLE + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif + +/* K.3.6 */ +typedef void (*constraint_handler_t)(const char * __restrict, + void * __restrict, errno_t); +/* K.3.6.1.1 */ +constraint_handler_t set_constraint_handler_s(constraint_handler_t handler); +/* K.3.6.1.2 */ +_Noreturn void abort_handler_s(const char * __restrict, void * __restrict, + errno_t); +/* K3.6.1.3 */ +void ignore_handler_s(const char * __restrict, void * __restrict, errno_t); +#endif /* __EXT1_VISIBLE */ + +__END_DECLS +__NULLABILITY_PRAGMA_POP + +#endif /* !_STDLIB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/stdnoreturn.h b/lib/libc/include/any-freebsd-any/stdnoreturn.h new file mode 100644 index 000000000000..e8fc7dca71b3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdnoreturn.h @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifdef __cplusplus +#error " cannot be used in combination with C++11." +#endif + +#ifndef noreturn + +#include +#define noreturn _Noreturn + +#endif /* !noreturn */ diff --git a/lib/libc/include/any-freebsd-any/string.h b/lib/libc/include/any-freebsd-any/string.h new file mode 100644 index 000000000000..3c5cceaeb857 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/string.h @@ -0,0 +1,164 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)string.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#include +#include +#include + +/* + * Prototype functions which were historically defined in , but + * are required by POSIX to be prototyped in . + */ +#if __BSD_VISIBLE +#include +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +#if __XSI_VISIBLE >= 600 +void *memccpy(void * __restrict, const void * __restrict, int, size_t); +#endif +void *memchr(const void *, int, size_t) __pure; +#if __BSD_VISIBLE +void *memrchr(const void *, int, size_t) __pure; +#endif +int memcmp(const void *, const void *, size_t) __pure; +void *memcpy(void * __restrict, const void * __restrict, size_t); +#if __BSD_VISIBLE +void *memmem(const void *, size_t, const void *, size_t) __pure; +#endif +void *memmove(void *, const void *, size_t); +void *memset(void *, int, size_t); +#if __POSIX_VISIBLE >= 200809 +char *stpcpy(char * __restrict, const char * __restrict); +char *stpncpy(char * __restrict, const char * __restrict, size_t); +#endif +#if __BSD_VISIBLE +char *strcasestr(const char *, const char *) __pure; +#endif +char *strcat(char * __restrict, const char * __restrict); +char *strchr(const char *, int) __pure; +#if __BSD_VISIBLE +char *strchrnul(const char*, int) __pure; +#endif +int strcmp(const char *, const char *) __pure; +int strcoll(const char *, const char *); +char *strcpy(char * __restrict, const char * __restrict); +size_t strcspn(const char *, const char *) __pure; +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +char *strdup(const char *) __malloc_like; +#endif +char *strerror(int); +#if __POSIX_VISIBLE >= 200112 +int strerror_r(int, char *, size_t); +#endif +#if __BSD_VISIBLE +size_t strlcat(char * __restrict, const char * __restrict, size_t); +size_t strlcpy(char * __restrict, const char * __restrict, size_t); +#endif +size_t strlen(const char *) __pure; +#if __BSD_VISIBLE +void strmode(int, char *); +#endif +char *strncat(char * __restrict, const char * __restrict, size_t); +int strncmp(const char *, const char *, size_t) __pure; +char *strncpy(char * __restrict, const char * __restrict, size_t); +#if __POSIX_VISIBLE >= 200809 +char *strndup(const char *, size_t) __malloc_like; +size_t strnlen(const char *, size_t) __pure; +#endif +#if __BSD_VISIBLE +char *strnstr(const char *, const char *, size_t) __pure; +#endif +char *strpbrk(const char *, const char *) __pure; +char *strrchr(const char *, int) __pure; +#if __BSD_VISIBLE +char *strsep(char **, const char *); +#endif +#if __POSIX_VISIBLE >= 200809 +char *strsignal(int); +#endif +size_t strspn(const char *, const char *) __pure; +char *strstr(const char *, const char *) __pure; +char *strtok(char * __restrict, const char * __restrict); +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 +char *strtok_r(char *, const char *, char **); +#endif +size_t strxfrm(char * __restrict, const char * __restrict, size_t); +#if __BSD_VISIBLE + +#ifndef _SWAB_DECLARED +#define _SWAB_DECLARED + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif /* _SIZE_T_DECLARED */ + +void swab(const void * __restrict, void * __restrict, ssize_t); +#endif /* _SWAB_DECLARED */ + +int timingsafe_bcmp(const void *, const void *, size_t); +int timingsafe_memcmp(const void *, const void *, size_t); +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif + +#if __EXT1_VISIBLE + +#ifndef _RSIZE_T_DEFINED +#define _RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif + +/* ISO/IEC 9899:2011 K.3.7.4.1.1 */ +errno_t memset_s(void *, rsize_t, int, rsize_t); +#endif /* __EXT1_VISIBLE */ +__END_DECLS + +#endif /* _STRING_H_ */ diff --git a/lib/libc/include/any-freebsd-any/stringlist.h b/lib/libc/include/any-freebsd-any/stringlist.h new file mode 100644 index 000000000000..b570e631b526 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stringlist.h @@ -0,0 +1,54 @@ +/* $NetBSD: stringlist.h,v 1.2 1997/01/17 06:11:36 lukem Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _STRINGLIST_H +#define _STRINGLIST_H +#include +#include + +/* + * Simple string list + */ +typedef struct _stringlist { + char **sl_str; + size_t sl_max; + size_t sl_cur; +} StringList; + +__BEGIN_DECLS +StringList *sl_init(void); +int sl_add(StringList *, char *); +void sl_free(StringList *, int); +char *sl_find(StringList *, const char *); +__END_DECLS + +#endif /* _STRINGLIST_H */ diff --git a/lib/libc/include/any-freebsd-any/strings.h b/lib/libc/include/any-freebsd-any/strings.h new file mode 100644 index 000000000000..9df19e4ce9ce --- /dev/null +++ b/lib/libc/include/any-freebsd-any/strings.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _STRINGS_H_ +#define _STRINGS_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 +int bcmp(const void *, const void *, size_t) __pure; /* LEGACY */ +void bcopy(const void *, void *, size_t); /* LEGACY */ +void bzero(void *, size_t); /* LEGACY */ +#endif +#if __BSD_VISIBLE +void explicit_bzero(void *, size_t); +#endif +#if __XSI_VISIBLE +int ffs(int) __pure2; +#endif +#if __BSD_VISIBLE +int ffsl(long) __pure2; +int ffsll(long long) __pure2; +int fls(int) __pure2; +int flsl(long) __pure2; +int flsll(long long) __pure2; +#endif +#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 +char *index(const char *, int) __pure; /* LEGACY */ +char *rindex(const char *, int) __pure; /* LEGACY */ +#endif +int strcasecmp(const char *, const char *) __pure; +int strncasecmp(const char *, const char *, size_t) __pure; + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif +__END_DECLS + +#endif /* _STRINGS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_bitset.h b/lib/libc/include/any-freebsd-any/sys/_bitset.h new file mode 100644 index 000000000000..e54f04cbeee7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_bitset.h @@ -0,0 +1,66 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__BITSET_H_ +#define _SYS__BITSET_H_ + +/* + * Macros addressing word and bit within it, tuned to make compiler + * optimize cases when SETSIZE fits into single machine word. + */ +#define _BITSET_BITS (sizeof(long) * 8) + +#define __howmany(x, y) (((x) + ((y) - 1)) / (y)) + +#define __bitset_words(_s) (__howmany(_s, _BITSET_BITS)) + +#define BITSET_DEFINE(t, _s) \ +struct t { \ + long __bits[__bitset_words((_s))]; \ +} + +/* + * Helper to declare a bitset without it's size being a constant. + * + * Sadly we cannot declare a bitset struct with '__bits[]', because it's + * the only member of the struct and the compiler complains. + */ +#define BITSET_DEFINE_VAR(t) BITSET_DEFINE(t, 1) + +/* + * Define a default type that can be used while manually specifying size + * to every call. + */ +BITSET_DEFINE(bitset, 1); + +#endif /* !_SYS__BITSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_bus_dma.h b/lib/libc/include/any-freebsd-any/sys/_bus_dma.h new file mode 100644 index 000000000000..c2a1730186c9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_bus_dma.h @@ -0,0 +1,65 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 2006 John-Mark Gurney. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS__BUS_DMA_H_ +#define _SYS__BUS_DMA_H_ + +typedef int bus_dmasync_op_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the characteristics + * of how to perform DMA mappings. This structure encapsultes + * information concerning address and alignment restrictions, number + * of S/G segments, amount of data per S/G segment, etc. + */ +typedef struct bus_dma_tag *bus_dma_tag_t; + +/* + * bus_dmamap_t + * + * DMA mapping instance information. + */ +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * A function that performs driver-specific synchronization on behalf of + * busdma. + */ +typedef enum { + BUS_DMA_LOCK = 0x01, + BUS_DMA_UNLOCK = 0x02, +} bus_dma_lock_op_t; + +typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); + +#endif /* !_SYS__BUS_DMA_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_callout.h b/lib/libc/include/any-freebsd-any/sys/_callout.h new file mode 100644 index 000000000000..1108d8ad74fd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_callout.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)callout.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS__CALLOUT_H +#define _SYS__CALLOUT_H + +#include + +struct lock_object; + +LIST_HEAD(callout_list, callout); +SLIST_HEAD(callout_slist, callout); +TAILQ_HEAD(callout_tailq, callout); + +typedef void callout_func_t(void *); + +struct callout { + union { + LIST_ENTRY(callout) le; + SLIST_ENTRY(callout) sle; + TAILQ_ENTRY(callout) tqe; + } c_links; + sbintime_t c_time; /* ticks to the event */ + sbintime_t c_precision; /* delta allowed wrt opt */ + void *c_arg; /* function argument */ + callout_func_t *c_func; /* function to call */ + struct lock_object *c_lock; /* lock to handle */ + short c_flags; /* User State */ + short c_iflags; /* Internal State */ + volatile int c_cpu; /* CPU we're scheduled on */ +}; + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/_cpuset.h b/lib/libc/include/any-freebsd-any/sys/_cpuset.h new file mode 100644 index 000000000000..cb3c0f9d586e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_cpuset.h @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__CPUSET_H_ +#define _SYS__CPUSET_H_ + +#include + +#ifdef _KERNEL +#define CPU_SETSIZE MAXCPU +#endif + +#define CPU_MAXSIZE 256 + +#ifndef CPU_SETSIZE +#define CPU_SETSIZE CPU_MAXSIZE +#endif + +BITSET_DEFINE(_cpuset, CPU_SETSIZE); +typedef struct _cpuset cpuset_t; + +#endif /* !_SYS__CPUSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_domainset.h b/lib/libc/include/any-freebsd-any/sys/_domainset.h new file mode 100644 index 000000000000..5685d532a9e3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_domainset.h @@ -0,0 +1,60 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__DOMAINSET_H_ +#define _SYS__DOMAINSET_H_ + +#include + +#ifdef _KERNEL +#define DOMAINSET_SETSIZE MAXMEMDOM +#endif + +#define DOMAINSET_MAXSIZE 256 + +#ifndef DOMAINSET_SETSIZE +#define DOMAINSET_SETSIZE DOMAINSET_MAXSIZE +#endif + +BITSET_DEFINE(_domainset, DOMAINSET_SETSIZE); +typedef struct _domainset domainset_t; + +/* + * This structure is intended to be embedded in objects which have policy + * attributes. Each object keeps its own iterator so round-robin is + * synchronized and accurate. + */ +struct domainset; +struct domainset_ref { + struct domainset * volatile dr_policy; + unsigned int dr_iter; +}; + +#endif /* !_SYS__DOMAINSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_ffcounter.h b/lib/libc/include/any-freebsd-any/sys/_ffcounter.h new file mode 100644 index 000000000000..511b0a598eb7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_ffcounter.h @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 The University of Melbourne + * All rights reserved. + * + * This software was developed by Julien Ridoux at the University of Melbourne + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__FFCOUNTER_H_ +#define _SYS__FFCOUNTER_H_ + +/* + * The feed-forward clock counter. The fundamental element of a feed-forward + * clock is a wide monotonically increasing counter that accumulates at the same + * rate as the selected timecounter. + */ +typedef uint64_t ffcounter; + +#endif /* _SYS__FFCOUNTER_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_iovec.h b/lib/libc/include/any-freebsd-any/sys/_iovec.h new file mode 100644 index 000000000000..da9a16a6351e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_iovec.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + * $FreeBSD$ + */ + +#ifndef _SYS__IOVEC_H_ +#define _SYS__IOVEC_H_ + +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +struct iovec { + void *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; + +#endif /* !_SYS__IOVEC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_kstack_cache.h b/lib/libc/include/any-freebsd-any/sys/_kstack_cache.h new file mode 100644 index 000000000000..61863b79c514 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_kstack_cache.h @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2009 Konstantin Belousov + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__KSTACK_CACHE_H +#define _SYS__KSTACK_CACHE_H + +struct kstack_cache_entry { + struct vm_object *ksobj; + struct kstack_cache_entry *next_ks_entry; +}; + +extern struct kstack_cache_entry *kstack_cache; + +#ifndef KSTACK_MAX_PAGES +#define KSTACK_MAX_PAGES 32 +#endif + +#endif + + diff --git a/lib/libc/include/any-freebsd-any/sys/_lock.h b/lib/libc/include/any-freebsd-any/sys/_lock.h new file mode 100644 index 000000000000..6a9e4b018067 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_lock.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__LOCK_H_ +#define _SYS__LOCK_H_ + +struct lock_object { + const char *lo_name; /* Individual lock name. */ + u_int lo_flags; + u_int lo_data; /* General class specific data. */ + struct witness *lo_witness; /* Data for witness. */ +}; + +#endif /* !_SYS__LOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_lockmgr.h b/lib/libc/include/any-freebsd-any/sys/_lockmgr.h new file mode 100644 index 000000000000..62e50df1ac4e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_lockmgr.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Attilio Rao + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__LOCKMGR_H_ +#define _SYS__LOCKMGR_H_ + +#ifdef DEBUG_LOCKS +#include +#endif + +struct lock { + struct lock_object lock_object; + volatile uintptr_t lk_lock; + u_int lk_exslpfail; + int lk_timo; + int lk_pri; +#ifdef DEBUG_LOCKS + struct stack lk_stack; +#endif +}; + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/_mutex.h b/lib/libc/include/any-freebsd-any/sys/_mutex.h new file mode 100644 index 000000000000..e37226cc8e5d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_mutex.h @@ -0,0 +1,66 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__MUTEX_H_ +#define _SYS__MUTEX_H_ + +#include + +/* + * Sleep/spin mutex. + * + * All mutex implementations must always have a member called mtx_lock. + * Other locking primitive structures are not allowed to use this name + * for their members. + * If this rule needs to change, the bits in the mutex implementation must + * be modified appropriately. + */ +struct mtx { + struct lock_object lock_object; /* Common lock properties. */ + volatile uintptr_t mtx_lock; /* Owner and flags. */ +}; + +/* + * Members of struct mtx_padalign must mirror members of struct mtx. + * mtx_padalign mutexes can use the mtx(9) API transparently without + * modification. + * Pad-aligned mutexes used within structures should generally be the + * first member of the struct. Otherwise, the compiler can generate + * additional padding for the struct to keep a correct alignment for + * the mutex. + */ +struct mtx_padalign { + struct lock_object lock_object; /* Common lock properties. */ + volatile uintptr_t mtx_lock; /* Owner and flags. */ +} __aligned(CACHE_LINE_SIZE); + +#endif /* !_SYS__MUTEX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_null.h b/lib/libc/include/any-freebsd-any/sys/_null.h new file mode 100644 index 000000000000..8fa5e4246bf8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_null.h @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef NULL + +#if !defined(__cplusplus) +#define NULL ((void *)0) +#else +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 +#define NULL __null +#else +#if defined(__LP64__) +#define NULL (0L) +#else +#define NULL 0 +#endif /* __LP64__ */ +#endif /* __GNUG__ */ +#endif /* !__cplusplus */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/_pctrie.h b/lib/libc/include/any-freebsd-any/sys/_pctrie.h new file mode 100644 index 000000000000..d9a98a78bfb2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_pctrie.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 EMC Corp. + * Copyright (c) 2011 Jeffrey Roberson + * Copyright (c) 2008 Mayur Shardul + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __SYS_PCTRIE_H_ +#define __SYS_PCTRIE_H_ + +/* + * Radix tree root. + */ +struct pctrie { + uintptr_t pt_root; +}; + +#endif /* !__SYS_PCTRIE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_pthreadtypes.h b/lib/libc/include/any-freebsd-any/sys/_pthreadtypes.h new file mode 100644 index 000000000000..fdd0878ff94c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_pthreadtypes.h @@ -0,0 +1,100 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu + * Copyright (c) 1995-1998 by John Birrell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__PTHREADTYPES_H_ +#define _SYS__PTHREADTYPES_H_ + +/* + * Forward structure definitions. + * + * These are mostly opaque to the user. + */ +struct pthread; +struct pthread_attr; +struct pthread_cond; +struct pthread_cond_attr; +struct pthread_mutex; +struct pthread_mutex_attr; +struct pthread_once; +struct pthread_rwlock; +struct pthread_rwlockattr; +struct pthread_barrier; +struct pthread_barrier_attr; +struct pthread_spinlock; + +/* + * Primitive system data type definitions required by P1003.1c. + * + * Note that P1003.1c specifies that there are no defined comparison + * or assignment operators for the types pthread_attr_t, pthread_cond_t, + * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t. + */ +#ifndef _PTHREAD_T_DECLARED +typedef struct pthread *pthread_t; +#define _PTHREAD_T_DECLARED +#endif +typedef struct pthread_attr *pthread_attr_t; +typedef struct pthread_mutex *pthread_mutex_t; +typedef struct pthread_mutex_attr *pthread_mutexattr_t; +typedef struct pthread_cond *pthread_cond_t; +typedef struct pthread_cond_attr *pthread_condattr_t; +typedef int pthread_key_t; +typedef struct pthread_once pthread_once_t; +typedef struct pthread_rwlock *pthread_rwlock_t; +typedef struct pthread_rwlockattr *pthread_rwlockattr_t; +typedef struct pthread_barrier *pthread_barrier_t; +typedef struct pthread_barrierattr *pthread_barrierattr_t; +typedef struct pthread_spinlock *pthread_spinlock_t; + +/* + * Additional type definitions: + * + * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for + * use in header symbols. + */ +typedef void *pthread_addr_t; +typedef void *(*pthread_startroutine_t)(void *); + +/* + * Once definitions. + */ +struct pthread_once { + int state; + pthread_mutex_t mutex; +}; + +#endif /* ! _SYS__PTHREADTYPES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_rangeset.h b/lib/libc/include/any-freebsd-any/sys/_rangeset.h new file mode 100644 index 000000000000..a700c6eaf23e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_rangeset.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__RANGESET_H +#define _SYS__RANGESET_H + +#include + +typedef void *(*rs_dup_data_t)(void *ctx, void *data); +typedef void (*rs_free_data_t)(void *ctx, void *data); + +struct rangeset { + struct pctrie rs_trie; + rs_dup_data_t rs_dup_data; + rs_free_data_t rs_free_data; + void *rs_data_ctx; + u_int rs_alloc_flags; +}; + +#endif + diff --git a/lib/libc/include/any-freebsd-any/sys/_rmlock.h b/lib/libc/include/any-freebsd-any/sys/_rmlock.h new file mode 100644 index 000000000000..89a25ee68798 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_rmlock.h @@ -0,0 +1,71 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2007 Stephan Uphoff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__RMLOCK_H_ +#define _SYS__RMLOCK_H_ + +/* + * Mostly reader/occasional writer lock. + */ + +LIST_HEAD(rmpriolist,rm_priotracker); + +struct rm_queue { + struct rm_queue *volatile rmq_next; + struct rm_queue *volatile rmq_prev; +}; + +struct rmlock { + struct lock_object lock_object; + volatile cpuset_t rm_writecpus; + LIST_HEAD(,rm_priotracker) rm_activeReaders; + union { + struct lock_object _rm_wlock_object; + struct mtx _rm_lock_mtx; + struct sx _rm_lock_sx; + } _rm_lock; +}; + +#define rm_wlock_object _rm_lock._rm_wlock_object +#define rm_lock_mtx _rm_lock._rm_lock_mtx +#define rm_lock_sx _rm_lock._rm_lock_sx + +struct rm_priotracker { + struct rm_queue rmp_cpuQueue; /* Must be first */ + struct rmlock *rmp_rmlock; + struct thread *rmp_thread; + int rmp_flags; + LIST_ENTRY(rm_priotracker) rmp_qentry; +}; + +#endif /* !_SYS__RMLOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_rwlock.h b/lib/libc/include/any-freebsd-any/sys/_rwlock.h new file mode 100644 index 000000000000..2e5583fcee9c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_rwlock.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__RWLOCK_H_ +#define _SYS__RWLOCK_H_ + +#include + +/* + * Reader/writer lock. + * + * All reader/writer lock implementations must always have a member + * called rw_lock. Other locking primitive structures are not allowed to + * use this name for their members. + * If this rule needs to change, the bits in the reader/writer lock + * implementation must be modified appropriately. + */ +struct rwlock { + struct lock_object lock_object; + volatile uintptr_t rw_lock; +}; + +/* + * Members of struct rwlock_padalign must mirror members of struct rwlock. + * rwlock_padalign rwlocks can use the rwlock(9) API transparently without + * modification. + * Pad-aligned rwlocks used within structures should generally be the + * first member of the struct. Otherwise, the compiler can generate + * additional padding for the struct to keep a correct alignment for + * the rwlock. + */ +struct rwlock_padalign { + struct lock_object lock_object; + volatile uintptr_t rw_lock; +} __aligned(CACHE_LINE_SIZE); + +#endif /* !_SYS__RWLOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_semaphore.h b/lib/libc/include/any-freebsd-any/sys/_semaphore.h new file mode 100644 index 000000000000..e9991439340c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_semaphore.h @@ -0,0 +1,58 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Alfred Perlstein + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef __SEMAPHORE_H_ +#define __SEMAPHORE_H_ + +typedef intptr_t semid_t; +struct timespec; + +#define SEM_VALUE_MAX __INT_MAX + +#ifndef _KERNEL + +__BEGIN_DECLS + +int ksem_close(semid_t id); +int ksem_post(semid_t id); +int ksem_wait(semid_t id); +int ksem_trywait(semid_t id); +int ksem_timedwait(semid_t id, const struct timespec *abstime); +int ksem_init(semid_t *idp, unsigned int value); +int ksem_open(semid_t *idp, const char *name, int oflag, mode_t mode, + unsigned int value); +int ksem_unlink(const char *name); +int ksem_getvalue(semid_t id, int *val); +int ksem_destroy(semid_t id); + +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* __SEMAPHORE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_sigset.h b/lib/libc/include/any-freebsd-any/sys/_sigset.h new file mode 100644 index 000000000000..662fcc1e216c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_sigset.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + * $FreeBSD$ + */ + +#ifndef _SYS__SIGSET_H_ +#define _SYS__SIGSET_H_ + +/* + * sigset_t macros. + */ +#define _SIG_WORDS 4 +#define _SIG_MAXSIG 128 +#define _SIG_IDX(sig) ((sig) - 1) +#define _SIG_WORD(sig) (_SIG_IDX(sig) >> 5) +#define _SIG_BIT(sig) (1U << (_SIG_IDX(sig) & 31)) +#define _SIG_VALID(sig) ((sig) <= _SIG_MAXSIG && (sig) > 0) + +typedef struct __sigset { + __uint32_t __bits[_SIG_WORDS]; +} __sigset_t; + +#if defined(_KERNEL) && defined(COMPAT_43) +typedef unsigned int osigset_t; +#endif + +#endif /* !_SYS__SIGSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_sockaddr_storage.h b/lib/libc/include/any-freebsd-any/sys/_sockaddr_storage.h new file mode 100644 index 000000000000..9584b4c76788 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_sockaddr_storage.h @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socket.h 8.4 (Berkeley) 2/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS__SOCKADDR_STORAGE_H_ +#define _SYS__SOCKADDR_STORAGE_H_ + +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128U +#define _SS_ALIGNSIZE (sizeof(__int64_t)) +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) - \ + sizeof(sa_family_t)) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) - \ + sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE) + +struct sockaddr_storage { + unsigned char ss_len; /* address length */ + sa_family_t ss_family; /* address family */ + char __ss_pad1[_SS_PAD1SIZE]; + __int64_t __ss_align; /* force desired struct alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; + +#endif /* !_SYS__SOCKADDR_STORAGE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_stack.h b/lib/libc/include/any-freebsd-any/sys/_stack.h new file mode 100644 index 000000000000..a7d440440b45 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_stack.h @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 Antoine Brodin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__STACK_H_ +#define _SYS__STACK_H_ + +#define STACK_MAX 18 /* Don't change, stack_ktr relies on this. */ + +struct stack { + int depth; + vm_offset_t pcs[STACK_MAX]; +}; + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/_stdarg.h b/lib/libc/include/any-freebsd-any/sys/_stdarg.h new file mode 100644 index 000000000000..d20cfaa988ce --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_stdarg.h @@ -0,0 +1,55 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__STDARG_H_ +#define _SYS__STDARG_H_ + +#include +#include + +#ifndef _VA_LIST_DECLARED + #define _VA_LIST_DECLARED + typedef __va_list va_list; +#endif + +#ifdef __GNUCLIKE_BUILTIN_STDARG + #define va_start(ap, last) __builtin_va_start((ap), (last)) + #define va_arg(ap, type) __builtin_va_arg((ap), type) + #define __va_copy(dest, src) __builtin_va_copy((dest), (src)) + #if __ISO_C_VISIBLE >= 1999 + #define va_copy(dest, src) __va_copy(dest, src) + #endif + #define va_end(ap) __builtin_va_end(ap) +#endif + +#endif /* ! _SYS__STDARG_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/sys/_stdint.h b/lib/libc/include/any-freebsd-any/sys/_stdint.h new file mode 100644 index 000000000000..248651535f35 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_stdint.h @@ -0,0 +1,92 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 David E. O'Brien + * Copyright (c) 2001 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__STDINT_H_ +#define _SYS__STDINT_H_ + +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif + +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif + +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif + +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +#ifndef _INTPTR_T_DECLARED +typedef __intptr_t intptr_t; +#define _INTPTR_T_DECLARED +#endif +#ifndef _UINTPTR_T_DECLARED +typedef __uintptr_t uintptr_t; +#define _UINTPTR_T_DECLARED +#endif +#ifndef _INTMAX_T_DECLARED +typedef __intmax_t intmax_t; +#define _INTMAX_T_DECLARED +#endif +#ifndef _UINTMAX_T_DECLARED +typedef __uintmax_t uintmax_t; +#define _UINTMAX_T_DECLARED +#endif + +#endif /* !_SYS__STDINT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_sx.h b/lib/libc/include/any-freebsd-any/sys/_sx.h new file mode 100644 index 000000000000..7e53200393b3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_sx.h @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2007 Attilio Rao + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__SX_H_ +#define _SYS__SX_H_ + +/* + * Shared/exclusive lock main structure definition. + */ +struct sx { + struct lock_object lock_object; + volatile uintptr_t sx_lock; +}; + +#endif /* !_SYS__SX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_task.h b/lib/libc/include/any-freebsd-any/sys/_task.h new file mode 100644 index 000000000000..ae0e95f71a63 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_task.h @@ -0,0 +1,76 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__TASK_H_ +#define _SYS__TASK_H_ + +#include + +/* + * Each task includes a function which is called from + * taskqueue_run(). The first argument is taken from the 'ta_context' + * field of struct task and the second argument is a count of how many + * times the task was enqueued before the call to taskqueue_run(). + * + * List of locks + * (c) const after init + * (q) taskqueue lock + */ +typedef void task_fn_t(void *context, int pending); +typedef void gtask_fn_t(void *context); + +struct task { + STAILQ_ENTRY(task) ta_link; /* (q) link for queue */ + uint16_t ta_pending; /* (q) count times queued */ + u_short ta_priority; /* (c) Priority */ + task_fn_t *ta_func; /* (c) task handler */ + void *ta_context; /* (c) argument for handler */ +}; + +struct gtask { + STAILQ_ENTRY(gtask) ta_link; /* (q) link for queue */ + uint16_t ta_flags; /* (q) state flags */ + u_short ta_priority; /* (c) Priority */ + gtask_fn_t *ta_func; /* (c) task handler */ + void *ta_context; /* (c) argument for handler */ +}; + +struct grouptask { + struct gtask gt_task; + void *gt_taskqueue; + LIST_ENTRY(grouptask) gt_list; + void *gt_uniq; +#define GROUPTASK_NAMELEN 32 + char gt_name[GROUPTASK_NAMELEN]; + int16_t gt_irq; + int16_t gt_cpu; +}; + +#endif /* !_SYS__TASK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_termios.h b/lib/libc/include/any-freebsd-any/sys/_termios.h new file mode 100644 index 000000000000..7a68dee99148 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_termios.h @@ -0,0 +1,230 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS__TERMIOS_H_ +#define _SYS__TERMIOS_H_ + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#if __BSD_VISIBLE +#define VEOL2 2 /* ICANON together with IEXTEN */ +#endif +#define VERASE 3 /* ICANON */ +#if __BSD_VISIBLE +#define VWERASE 4 /* ICANON together with IEXTEN */ +#endif +#define VKILL 5 /* ICANON */ +#if __BSD_VISIBLE +#define VREPRINT 6 /* ICANON together with IEXTEN */ +#define VERASE2 7 /* ICANON */ +#endif +/* 7 ex-spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#if __BSD_VISIBLE +#define VDSUSP 11 /* ISIG together with IEXTEN */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#if __BSD_VISIBLE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#if __BSD_VISIBLE +#define VSTATUS 18 /* ICANON together with IEXTEN */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE 0xff + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINTR */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200809 +#define IXANY 0x00000800 /* any char will restart after stop */ +#endif +#if __BSD_VISIBLE +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#if __XSI_VISIBLE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#endif +#if __BSD_VISIBLE +#define TABDLY 0x00000004 /* tab delay mask */ +#define TAB0 0x00000000 /* no tab delay and expansion */ +#define TAB3 0x00000004 /* expand tabs to spaces */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */ +#endif +#if __XSI_VISIBLE +#define OCRNL 0x00000010 /* map CR to NL on output */ +#define ONOCR 0x00000020 /* no CR output at column 0 */ +#define ONLRET 0x00000040 /* NL performs CR function */ +#endif + +/* + * Control flags - hardware control of terminal + */ +#if __BSD_VISIBLE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#if __BSD_VISIBLE +#define CCTS_OFLOW 0x00010000 /* CTS flow control of output */ +#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW) +#define CRTS_IFLOW 0x00020000 /* RTS flow control of input */ +#define CDTR_IFLOW 0x00040000 /* DTR flow control of input */ +#define CDSR_OFLOW 0x00080000 /* DSR flow control of output */ +#define CCAR_OFLOW 0x00100000 /* DCD flow control of output */ +#endif + + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#if __BSD_VISIBLE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#if __BSD_VISIBLE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#if __BSD_VISIBLE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#if __BSD_VISIBLE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#if __BSD_VISIBLE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define B460800 460800 +#define B921600 921600 +#define EXTA 19200 +#define EXTB 38400 +#endif + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ +}; + +#endif /* !_SYS__TERMIOS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_timespec.h b/lib/libc/include/any-freebsd-any/sys/_timespec.h new file mode 100644 index 000000000000..d12d1f740e61 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_timespec.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD$ + */ + +#ifndef _SYS__TIMESPEC_H_ +#define _SYS__TIMESPEC_H_ + +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#endif /* !_SYS__TIMESPEC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_timeval.h b/lib/libc/include/any-freebsd-any/sys/_timeval.h new file mode 100644 index 000000000000..3da7a711eb19 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_timeval.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__TIMEVAL_H_ +#define _SYS__TIMEVAL_H_ + +#include + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; +#define _SUSECONDS_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +/* + * Structure returned by gettimeofday(2) system call, and used in other calls. + */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; + +#endif /* !_SYS__TIMEVAL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_types.h b/lib/libc/include/any-freebsd-any/sys/_types.h new file mode 100644 index 000000000000..020ba025ea98 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_types.h @@ -0,0 +1,150 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__TYPES_H_ +#define _SYS__TYPES_H_ + +#include +#include + +/* + * Standard type definitions. + */ +typedef __int32_t __blksize_t; /* file block size */ +typedef __int64_t __blkcnt_t; /* file block count */ +typedef __int32_t __clockid_t; /* clock_gettime()... */ +typedef __uint32_t __fflags_t; /* file flags */ +typedef __uint64_t __fsblkcnt_t; +typedef __uint64_t __fsfilcnt_t; +typedef __uint32_t __gid_t; +typedef __int64_t __id_t; /* can hold a gid_t, pid_t, or uid_t */ +typedef __uint64_t __ino_t; /* inode number */ +typedef long __key_t; /* IPC key (for Sys V IPC) */ +typedef __int32_t __lwpid_t; /* Thread ID (a.k.a. LWP) */ +typedef __uint16_t __mode_t; /* permissions */ +typedef int __accmode_t; /* access permissions */ +typedef int __nl_item; +typedef __uint64_t __nlink_t; /* link count */ +typedef __int64_t __off_t; /* file offset */ +typedef __int64_t __off64_t; /* file offset (alias) */ +typedef __int32_t __pid_t; /* process [group] */ +typedef __int64_t __rlim_t; /* resource limit - intentionally */ + /* signed, because of legacy code */ + /* that uses -1 for RLIM_INFINITY */ +typedef __uint8_t __sa_family_t; +typedef __uint32_t __socklen_t; +typedef long __suseconds_t; /* microseconds (signed) */ +typedef struct __timer *__timer_t; /* timer_gettime()... */ +typedef struct __mq *__mqd_t; /* mq_open()... */ +typedef __uint32_t __uid_t; +typedef unsigned int __useconds_t; /* microseconds (unsigned) */ +typedef int __cpuwhich_t; /* which parameter for cpuset. */ +typedef int __cpulevel_t; /* level parameter for cpuset. */ +typedef int __cpusetid_t; /* cpuset identifier. */ +typedef __int64_t __daddr_t; /* bwrite(3), FIOBMAP2, etc */ + +/* + * Unusual type definitions. + */ +/* + * rune_t is declared to be an ``int'' instead of the more natural + * ``unsigned long'' or ``long''. Two things are happening here. It is not + * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, + * it looks like 10646 will be a 31 bit standard. This means that if your + * ints cannot hold 32 bits, you will be in trouble. The reason an int was + * chosen over a long is that the is*() and to*() routines take ints (says + * ANSI C), but they use __ct_rune_t instead of int. + * + * NOTE: rune_t is not covered by ANSI nor other standards, and should not + * be instantiated outside of lib/libc/locale. Use wchar_t. wint_t and + * rune_t must be the same type. Also, wint_t should be able to hold all + * members of the largest character set plus one extra value (WEOF), and + * must be at least 16 bits. + */ +typedef int __ct_rune_t; /* arg type for ctype funcs */ +typedef __ct_rune_t __rune_t; /* rune_t (see above) */ +typedef __ct_rune_t __wint_t; /* wint_t (see above) */ + +/* Clang already provides these types as built-ins, but only in C++ mode. */ +#if !defined(__clang__) || !defined(__cplusplus) +typedef __uint_least16_t __char16_t; +typedef __uint_least32_t __char32_t; +#endif +/* In C++11, char16_t and char32_t are built-in types. */ +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _CHAR16_T_DECLARED +#define _CHAR32_T_DECLARED +#endif + +typedef struct { + long long __max_align1 __aligned(_Alignof(long long)); +#ifndef _STANDALONE + long double __max_align2 __aligned(_Alignof(long double)); +#endif +} __max_align_t; + +typedef __uint64_t __dev_t; /* device number */ + +typedef __uint32_t __fixpt_t; /* fixed point number */ + +/* + * mbstate_t is an opaque object to keep conversion state during multibyte + * stream conversions. + */ +typedef union { + char __mbstate8[128]; + __int64_t _mbstateL; /* for alignment */ +} __mbstate_t; + +typedef __uintmax_t __rman_res_t; + +/* + * Types for varargs. These are all provided by builtin types these + * days, so centralize their definition. + */ +#ifdef __GNUCLIKE_BUILTIN_VARARGS +typedef __builtin_va_list __va_list; /* internally known to gcc */ +#else +#error "No support for your compiler for stdargs" +#endif +#if defined(__GNUC_VA_LIST_COMPATIBILITY) && !defined(__GNUC_VA_LIST) \ + && !defined(__NO_GNUC_VA_LIST) +#define __GNUC_VA_LIST +typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ +#endif + +/* + * When the following macro is defined, the system uses 64-bit inode numbers. + * Programs can use this to avoid including , with its associated + * namespace pollution. + */ +#define __INO64 + +#endif /* !_SYS__TYPES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_ucontext.h b/lib/libc/include/any-freebsd-any/sys/_ucontext.h new file mode 100644 index 000000000000..2cdec1bf0a53 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_ucontext.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__UCONTEXT_H_ +#define _SYS__UCONTEXT_H_ + +typedef struct __ucontext { + /* + * Keep the order of the first two fields. Also, + * keep them the first two fields in the structure. + * This way we can have a union with struct + * sigcontext and ucontext_t. This allows us to + * support them both at the same time. + * note: the union is not defined, though. + */ + __sigset_t uc_sigmask; + mcontext_t uc_mcontext; + + struct __ucontext *uc_link; + struct __stack_t uc_stack; + int uc_flags; + int __spare__[4]; +} ucontext_t; + +#endif /* _SYS__UCONTEXT_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/_uio.h b/lib/libc/include/any-freebsd-any/sys/_uio.h new file mode 100644 index 000000000000..18612ed7367b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_uio.h @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + * $FreeBSD$ + */ + +#ifndef _SYS__UIO_H_ +#define _SYS__UIO_H_ + +#if __BSD_VISIBLE +enum uio_rw { + UIO_READ, + UIO_WRITE +}; + +/* Segment flag values. */ +enum uio_seg { + UIO_USERSPACE, /* from user data space */ + UIO_SYSSPACE, /* from system space */ + UIO_NOCOPY /* don't copy, already in object */ +}; +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS__UIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_umtx.h b/lib/libc/include/any-freebsd-any/sys/_umtx.h new file mode 100644 index 000000000000..b9d10b756a0c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_umtx.h @@ -0,0 +1,81 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010, David Xu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS__UMTX_H_ +#define _SYS__UMTX_H_ + +#include +#include + +struct umutex { + volatile __lwpid_t m_owner; /* Owner of the mutex */ + __uint32_t m_flags; /* Flags of the mutex */ + __uint32_t m_ceilings[2]; /* Priority protect ceiling */ + __uintptr_t m_rb_lnk; /* Robust linkage */ +#ifndef __LP64__ + __uint32_t m_pad; +#endif + __uint32_t m_spare[2]; +}; + +struct ucond { + volatile __uint32_t c_has_waiters; /* Has waiters in kernel */ + __uint32_t c_flags; /* Flags of the condition variable */ + __uint32_t c_clockid; /* Clock id */ + __uint32_t c_spare[1]; /* Spare space */ +}; + +struct urwlock { + volatile __int32_t rw_state; + __uint32_t rw_flags; + __uint32_t rw_blocked_readers; + __uint32_t rw_blocked_writers; + __uint32_t rw_spare[4]; +}; + +struct _usem { + volatile __uint32_t _has_waiters; + volatile __uint32_t _count; + __uint32_t _flags; +}; + +struct _usem2 { + volatile __uint32_t _count; /* Waiters flag in high bit. */ + __uint32_t _flags; +}; + +struct _umtx_time { + struct timespec _timeout; + __uint32_t _flags; + __uint32_t _clockid; +}; + +#endif /* !_SYS__UMTX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/_unrhdr.h b/lib/libc/include/any-freebsd-any/sys/_unrhdr.h new file mode 100644 index 000000000000..65abe5789710 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/_unrhdr.h @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_UNRHDR_H +#define _SYS_UNRHDR_H + +#include + +struct mtx; + +/* Header element for a unr number space. */ + +struct unrhdr { + TAILQ_HEAD(unrhd,unr) head; + u_int low; /* Lowest item */ + u_int high; /* Highest item */ + u_int busy; /* Count of allocated items */ + u_int alloc; /* Count of memory allocations */ + u_int first; /* items in allocated from start */ + u_int last; /* items free at end */ + struct mtx *mtx; + TAILQ_HEAD(unrfr,unr) ppfree; /* Items to be freed after mtx + lock dropped */ +}; + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/aac_ioctl.h b/lib/libc/include/any-freebsd-any/sys/aac_ioctl.h new file mode 100644 index 000000000000..6b6e2dee756e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/aac_ioctl.h @@ -0,0 +1,218 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 Scott Long + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Command queue statistics + */ +#define AACQ_FREE 0 +#define AACQ_BIO 1 +#define AACQ_READY 2 +#define AACQ_BUSY 3 +#define AACQ_COUNT 4 /* total number of queues */ + +struct aac_qstat { + u_int32_t q_length; + u_int32_t q_max; +}; + +/* + * Statistics request + */ +union aac_statrequest { + u_int32_t as_item; + struct aac_qstat as_qstat; +}; + +#define AACIO_STATS _IOWR('T', 101, union aac_statrequest) + +/* + * Ioctl commands likely to be submitted from a Linux management application. + * These bit encodings are actually descended from Windows NT. Ick. + */ + +#define CTL_CODE(devType, func, meth, acc) (((devType) << 16) | ((acc) << 14) | ((func) << 2) | (meth)) +#define METHOD_BUFFERED 0 +#define METHOD_IN_DIRECT 1 +#define METHOD_OUT_DIRECT 2 +#define METHOD_NEITHER 3 +#define FILE_ANY_ACCESS 0 +#define FILE_READ_ACCESS ( 0x0001 ) +#define FILE_WRITE_ACCESS ( 0x0002 ) +#define FILE_DEVICE_CONTROLLER 0x00000004 + +#define FSACTL_LNX_SENDFIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2050, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_SEND_RAW_SRB CTL_CODE(FILE_DEVICE_CONTROLLER, 2067, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_GET_COMM_PERF_DATA CTL_CODE(FILE_DEVICE_CONTROLLER, 2084, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_OPENCLS_COMM_PERF_DATA CTL_CODE(FILE_DEVICE_CONTROLLER, \ + 2085, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_OPEN_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2100, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_GET_NEXT_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2101, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_CLOSE_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, \ + 2102, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_CLOSE_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2104, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_OPEN_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2105, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_MINIPORT_REV_CHECK CTL_CODE(FILE_DEVICE_CONTROLLER, 2107, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_QUERY_ADAPTER_CONFIG CTL_CODE(FILE_DEVICE_CONTROLLER, 2113, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_GET_PCI_INFO CTL_CODE(FILE_DEVICE_CONTROLLER, 2119, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_FORCE_DELETE_DISK CTL_CODE(FILE_DEVICE_CONTROLLER, 2120, \ + METHOD_NEITHER, FILE_ANY_ACCESS) +#define FSACTL_LNX_AIF_THREAD CTL_CODE(FILE_DEVICE_CONTROLLER, 2127, \ + METHOD_NEITHER, FILE_ANY_ACCESS) +#define FSACTL_LNX_SEND_LARGE_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2138, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_LNX_GET_FEATURES CTL_CODE(FILE_DEVICE_CONTROLLER, 2139, \ + METHOD_BUFFERED, FILE_ANY_ACCESS) + +/* Why these don't follow the previous convention, I don't know */ +#define FSACTL_LNX_NULL_IO_TEST 0x43 +#define FSACTL_LNX_SIM_IO_TEST 0x53 +#define FSACTL_LNX_DOWNLOAD 0x83 +#define FSACTL_LNX_GET_VAR 0x93 +#define FSACTL_LNX_SET_VAR 0xa3 +#define FSACTL_LNX_GET_FIBTIMES 0xb3 +#define FSACTL_LNX_ZERO_FIBTIMES 0xc3 +#define FSACTL_LNX_DELETE_DISK 0x163 +#define FSACTL_LNX_QUERY_DISK 0x173 + +/* Ok, here it gets really lame */ +#define FSACTL_LNX_PROBE_CONTAINERS 2131 /* Just guessing */ + +/* Do the native version of the ioctls. Since the BSD encoding scheme + * conflicts with the 'standard' AAC encoding scheme, the resulting numbers + * will be different. The '8' comes from the fact that the previous scheme + * used 12 bits for the number, with the 12th bit being the only set + * bit above bit 8. Thus the value of 8, with the lower 8 bits holding the + * command number. 9 is used for the odd overflow case. + */ +#define FSACTL_SENDFIB _IO('8', 2) +#define FSACTL_SEND_RAW_SRB _IO('8', 19) +#define FSACTL_GET_COMM_PERF_DATA _IO('8', 36) +#define FSACTL_OPENCLS_COMM_PERF_DATA _IO('8', 37) +#define FSACTL_OPEN_GET_ADAPTER_FIB _IO('8', 52) +#define FSACTL_GET_NEXT_ADAPTER_FIB _IO('8', 53) +#define FSACTL_CLOSE_GET_ADAPTER_FIB _IO('8', 54) +#define FSACTL_CLOSE_ADAPTER_CONFIG _IO('8', 56) +#define FSACTL_OPEN_ADAPTER_CONFIG _IO('8', 57) +#define FSACTL_MINIPORT_REV_CHECK _IO('8', 59) +#define FSACTL_QUERY_ADAPTER_CONFIG _IO('8', 65) +#define FSACTL_GET_PCI_INFO _IO('8', 71) +#define FSACTL_FORCE_DELETE_DISK _IO('8', 72) +#define FSACTL_AIF_THREAD _IO('8', 79) +#define FSACTL_SEND_LARGE_FIB _IO('8', 90) +#define FSACTL_GET_FEATURES _IO('8', 91) + +#define FSACTL_NULL_IO_TEST _IO('8', 67) +#define FSACTL_SIM_IO_TEST _IO('8', 83) +#define FSACTL_DOWNLOAD _IO('8', 131) +#define FSACTL_GET_VAR _IO('8', 147) +#define FSACTL_SET_VAR _IO('8', 163) +#define FSACTL_GET_FIBTIMES _IO('8', 179) +#define FSACTL_ZERO_FIBTIMES _IO('8', 195) +#define FSACTL_DELETE_DISK _IO('8', 99) +#define FSACTL_QUERY_DISK _IO('9', 115) + +#define FSACTL_PROBE_CONTAINERS _IO('9', 83) /* Just guessing */ + +#ifdef _KERNEL +/* + * Support for faking the "miniport" version. + */ +struct aac_rev_check { + RevComponent callingComponent; + struct FsaRevision callingRevision; +}; + +struct aac_rev_check_resp { + int possiblyCompatible; + struct FsaRevision adapterSWRevision; +}; + +/* + * Context passed in by a consumer looking to collect an AIF. + */ +struct get_adapter_fib_ioctl { + u_int32_t AdapterFibContext; + int Wait; + caddr_t AifFib; +}; + +#ifdef _KERNEL +struct get_adapter_fib_ioctl32 { + u_int32_t AdapterFibContext; + int Wait; + u_int32_t AifFib; +}; +#endif + +struct aac_query_disk { + int32_t ContainerNumber; + int32_t Bus; + int32_t Target; + int32_t Lun; + u_int32_t Valid; + u_int32_t Locked; + u_int32_t Deleted; + int32_t Instance; + char diskDeviceName[10]; + u_int32_t UnMapped; +}; + +/* Features, asked from the tools to know if the driver + * supports drives >2TB + */ +typedef union { + struct { + u_int32_t largeLBA : 1; /* disk support greater 2TB */ + u_int32_t IoctlBuf : 1; /* ARCIOCTL call support */ + u_int32_t AIFSupport: 1; /* AIF support */ + u_int32_t JBODSupport:1; /* fw + driver support JBOD */ + u_int32_t fReserved : 28; + } fBits; + u_int32_t fValue; +} featuresState; + +struct aac_features { + featuresState feat; + u_int32_t data[31]; + u_int32_t reserved[32]; +} __packed; +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/abi_compat.h b/lib/libc/include/any-freebsd-any/sys/abi_compat.h new file mode 100644 index 000000000000..0df31dbfbdce --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/abi_compat.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _COMPAT_H_ +#define _COMPAT_H_ + +/* + * Helper macros for translating objects between different ABIs. + */ + +#define PTRIN(v) (void *)(uintptr_t)(v) +#define PTROUT(v) (uintptr_t)(v) + +#define CP(src, dst, fld) do { \ + (dst).fld = (src).fld; \ +} while (0) + +#define CP2(src, dst, sfld, dfld) do { \ + (dst).dfld = (src).sfld; \ +} while (0) + +#define PTRIN_CP(src, dst, fld) do { \ + (dst).fld = PTRIN((src).fld); \ +} while (0) + +#define PTROUT_CP(src, dst, fld) do { \ + (dst).fld = PTROUT((src).fld); \ +} while (0) + +#define TV_CP(src, dst, fld) do { \ + CP((src).fld, (dst).fld, tv_sec); \ + CP((src).fld, (dst).fld, tv_usec); \ +} while (0) + +#define TS_CP(src, dst, fld) do { \ + CP((src).fld, (dst).fld, tv_sec); \ + CP((src).fld, (dst).fld, tv_nsec); \ +} while (0) + +#define ITS_CP(src, dst) do { \ + TS_CP((src), (dst), it_interval); \ + TS_CP((src), (dst), it_value); \ +} while (0) + +#define BT_CP(src, dst, fld) do { \ + CP((src).fld, (dst).fld, sec); \ + *(uint64_t *)&(dst).fld.frac[0] = (src).fld.frac; \ +} while (0) + +#endif /* !_COMPAT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/acct.h b/lib/libc/include/any-freebsd-any/sys/acct.h new file mode 100644 index 000000000000..36c6a5e23d06 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/acct.h @@ -0,0 +1,149 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)acct.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_ACCT_H_ +#define _SYS_ACCT_H_ + +#ifdef _KERNEL +#define float uint32_t +#endif + +#define AC_COMM_LEN 16 + +/* + * Accounting structure version 3 (current). + * The first byte is always zero. + * Time units are microseconds. + */ + +struct acctv3 { + uint8_t ac_zero; /* zero identifies new version */ + uint8_t ac_version; /* record version number */ + uint16_t ac_len; /* record length */ + + char ac_comm[AC_COMM_LEN]; /* command name */ + float ac_utime; /* user time */ + float ac_stime; /* system time */ + float ac_etime; /* elapsed time */ + time_t ac_btime; /* starting time */ + uid_t ac_uid; /* user id */ + gid_t ac_gid; /* group id */ + float ac_mem; /* average memory usage */ + float ac_io; /* count of IO blocks */ + __dev_t ac_tty; /* controlling tty */ + uint32_t ac_pad0; + uint16_t ac_len2; /* record length */ + union { + uint32_t ac_align; /* force v1 compatible alignment */ + +#define AFORK 0x01 /* forked but not exec'ed */ +/* ASU is no longer supported */ +#define ASU 0x02 /* used super-user permissions */ +#define ACOMPAT 0x04 /* used compatibility mode */ +#define ACORE 0x08 /* dumped core */ +#define AXSIG 0x10 /* killed by a signal */ +#define ANVER 0x20 /* new record version */ + + uint8_t ac_flag; /* accounting flags */ + } ac_trailer; + +#define ac_flagx ac_trailer.ac_flag +}; + +struct acctv2 { + uint8_t ac_zero; /* zero identifies new version */ + uint8_t ac_version; /* record version number */ + uint16_t ac_len; /* record length */ + + char ac_comm[AC_COMM_LEN]; /* command name */ + float ac_utime; /* user time */ + float ac_stime; /* system time */ + float ac_etime; /* elapsed time */ + time_t ac_btime; /* starting time */ + uid_t ac_uid; /* user id */ + gid_t ac_gid; /* group id */ + float ac_mem; /* average memory usage */ + float ac_io; /* count of IO blocks */ + uint32_t ac_tty; /* controlling tty */ + + uint16_t ac_len2; /* record length */ + union { + uint32_t ac_align; /* force v1 compatible alignment */ + uint8_t ac_flag; /* accounting flags */ + } ac_trailer; +}; + +/* + * Legacy accounting structure (rev. 1.5-1.18). + * The first byte is always non-zero. + * Some fields use a comp_t type which is a 3 bits base 8 + * exponent, 13 bit fraction ``floating point'' number. + * Units are 1/AHZV1 seconds. + */ + +typedef uint16_t comp_t; + +struct acctv1 { + char ac_comm[AC_COMM_LEN]; /* command name */ + comp_t ac_utime; /* user time */ + comp_t ac_stime; /* system time */ + comp_t ac_etime; /* elapsed time */ + time_t ac_btime; /* starting time */ + uid_t ac_uid; /* user id */ + gid_t ac_gid; /* group id */ + uint16_t ac_mem; /* average memory usage */ + comp_t ac_io; /* count of IO blocks */ + uint32_t ac_tty; /* controlling tty */ + uint8_t ac_flag; /* accounting flags */ +}; + +/* + * 1/AHZV1 is the granularity of the data encoded in the comp_t fields. + * This is not necessarily equal to hz. + */ +#define AHZV1 64 + +#ifdef _KERNEL +struct thread; + +int acct_process(struct thread *td); +#undef float +#endif + +#endif /* !_SYS_ACCT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/acl.h b/lib/libc/include/any-freebsd-any/sys/acl.h new file mode 100644 index 000000000000..196447a6d9cb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/acl.h @@ -0,0 +1,419 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999-2001 Robert N. M. Watson + * Copyright (c) 2008 Edward Tomasz Napierała + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * Developed by the TrustedBSD Project. + * Support for POSIX.1e and NFSv4 access control lists. + */ + +#ifndef _SYS_ACL_H_ +#define _SYS_ACL_H_ + +#include +#include +#include + +/* + * POSIX.1e and NFSv4 ACL types and related constants. + */ + +typedef uint32_t acl_tag_t; +typedef uint32_t acl_perm_t; +typedef uint16_t acl_entry_type_t; +typedef uint16_t acl_flag_t; +typedef int acl_type_t; +typedef int *acl_permset_t; +typedef uint16_t *acl_flagset_t; + +/* + * With 254 entries, "struct acl_t_struct" is exactly one 4kB page big. + * Note that with NFSv4 ACLs, the maximum number of ACL entries one + * may set on file or directory is about half of ACL_MAX_ENTRIES. + * + * If you increase this, you might also need to increase + * _ACL_T_ALIGNMENT_BITS in lib/libc/posix1e/acl_support.h. + * + * The maximum number of POSIX.1e ACLs is controlled + * by OLDACL_MAX_ENTRIES. Changing that one will break binary + * compatibility with pre-8.0 userland and change on-disk ACL layout. + */ +#define ACL_MAX_ENTRIES 254 + +#if defined(_KERNEL) || defined(_ACL_PRIVATE) + +#define POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_ACCESS_EXTATTR_NAME "posix1e.acl_access" +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAME "posix1e.acl_default" +#define NFS4_ACL_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define NFS4_ACL_EXTATTR_NAME "nfs4.acl" +#define OLDACL_MAX_ENTRIES 32 + +/* + * "struct oldacl" is used in compatibility ACL syscalls and for on-disk + * storage of POSIX.1e ACLs. + */ +typedef int oldacl_tag_t; +typedef mode_t oldacl_perm_t; + +struct oldacl_entry { + oldacl_tag_t ae_tag; + uid_t ae_id; + oldacl_perm_t ae_perm; +}; +typedef struct oldacl_entry *oldacl_entry_t; + +struct oldacl { + int acl_cnt; + struct oldacl_entry acl_entry[OLDACL_MAX_ENTRIES]; +}; + +/* + * Current "struct acl". + */ +struct acl_entry { + acl_tag_t ae_tag; + uid_t ae_id; + acl_perm_t ae_perm; + /* NFSv4 entry type, "allow" or "deny". Unused in POSIX.1e ACLs. */ + acl_entry_type_t ae_entry_type; + /* NFSv4 ACL inheritance. Unused in POSIX.1e ACLs. */ + acl_flag_t ae_flags; +}; +typedef struct acl_entry *acl_entry_t; + +/* + * Internal ACL structure, used in libc, kernel APIs and for on-disk + * storage of NFSv4 ACLs. POSIX.1e ACLs use "struct oldacl" for on-disk + * storage. + */ +struct acl { + unsigned int acl_maxcnt; + unsigned int acl_cnt; + /* Will be required e.g. to implement NFSv4.1 ACL inheritance. */ + int acl_spare[4]; + struct acl_entry acl_entry[ACL_MAX_ENTRIES]; +}; + +/* + * ACL structure internal to libc. + */ +struct acl_t_struct { + struct acl ats_acl; + int ats_cur_entry; + /* + * ats_brand is for libc internal bookkeeping only. + * Applications should use acl_get_brand_np(3). + * Kernel code should use the "type" argument passed + * to VOP_SETACL, VOP_GETACL or VOP_ACLCHECK calls; + * ACL_TYPE_ACCESS or ACL_TYPE_DEFAULT mean POSIX.1e + * ACL, ACL_TYPE_NFS4 means NFSv4 ACL. + */ + int ats_brand; +}; +typedef struct acl_t_struct *acl_t; + +#else /* _KERNEL || _ACL_PRIVATE */ + +typedef void *acl_entry_t; +typedef void *acl_t; + +#endif /* !_KERNEL && !_ACL_PRIVATE */ + +/* + * Possible valid values for ats_brand field. + */ +#define ACL_BRAND_UNKNOWN 0 +#define ACL_BRAND_POSIX 1 +#define ACL_BRAND_NFS4 2 + +/* + * Possible valid values for ae_tag field. For explanation, see acl(9). + */ +#define ACL_UNDEFINED_TAG 0x00000000 +#define ACL_USER_OBJ 0x00000001 +#define ACL_USER 0x00000002 +#define ACL_GROUP_OBJ 0x00000004 +#define ACL_GROUP 0x00000008 +#define ACL_MASK 0x00000010 +#define ACL_OTHER 0x00000020 +#define ACL_OTHER_OBJ ACL_OTHER +#define ACL_EVERYONE 0x00000040 + +/* + * Possible valid values for ae_entry_type field, valid only for NFSv4 ACLs. + */ +#define ACL_ENTRY_TYPE_ALLOW 0x0100 +#define ACL_ENTRY_TYPE_DENY 0x0200 +#define ACL_ENTRY_TYPE_AUDIT 0x0400 +#define ACL_ENTRY_TYPE_ALARM 0x0800 + +/* + * Possible valid values for acl_type_t arguments. First two + * are provided only for backwards binary compatibility. + */ +#define ACL_TYPE_ACCESS_OLD 0x00000000 +#define ACL_TYPE_DEFAULT_OLD 0x00000001 +#define ACL_TYPE_ACCESS 0x00000002 +#define ACL_TYPE_DEFAULT 0x00000003 +#define ACL_TYPE_NFS4 0x00000004 + +/* + * Possible bits in ae_perm field for POSIX.1e ACLs. Note + * that ACL_EXECUTE may be used in both NFSv4 and POSIX.1e ACLs. + */ +#define ACL_EXECUTE 0x0001 +#define ACL_WRITE 0x0002 +#define ACL_READ 0x0004 +#define ACL_PERM_NONE 0x0000 +#define ACL_PERM_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) +#define ACL_POSIX1E_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) + +/* + * Possible bits in ae_perm field for NFSv4 ACLs. + */ +#define ACL_READ_DATA 0x00000008 +#define ACL_LIST_DIRECTORY 0x00000008 +#define ACL_WRITE_DATA 0x00000010 +#define ACL_ADD_FILE 0x00000010 +#define ACL_APPEND_DATA 0x00000020 +#define ACL_ADD_SUBDIRECTORY 0x00000020 +#define ACL_READ_NAMED_ATTRS 0x00000040 +#define ACL_WRITE_NAMED_ATTRS 0x00000080 +/* ACL_EXECUTE is defined above. */ +#define ACL_DELETE_CHILD 0x00000100 +#define ACL_READ_ATTRIBUTES 0x00000200 +#define ACL_WRITE_ATTRIBUTES 0x00000400 +#define ACL_DELETE 0x00000800 +#define ACL_READ_ACL 0x00001000 +#define ACL_WRITE_ACL 0x00002000 +#define ACL_WRITE_OWNER 0x00004000 +#define ACL_SYNCHRONIZE 0x00008000 + +#define ACL_FULL_SET (ACL_READ_DATA | ACL_WRITE_DATA | \ + ACL_APPEND_DATA | ACL_READ_NAMED_ATTRS | ACL_WRITE_NAMED_ATTRS | \ + ACL_EXECUTE | ACL_DELETE_CHILD | ACL_READ_ATTRIBUTES | \ + ACL_WRITE_ATTRIBUTES | ACL_DELETE | ACL_READ_ACL | ACL_WRITE_ACL | \ + ACL_WRITE_OWNER | ACL_SYNCHRONIZE) + +#define ACL_MODIFY_SET (ACL_FULL_SET & \ + ~(ACL_WRITE_ACL | ACL_WRITE_OWNER)) + +#define ACL_READ_SET (ACL_READ_DATA | ACL_READ_NAMED_ATTRS | \ + ACL_READ_ATTRIBUTES | ACL_READ_ACL) + +#define ACL_WRITE_SET (ACL_WRITE_DATA | ACL_APPEND_DATA | \ + ACL_WRITE_NAMED_ATTRS | ACL_WRITE_ATTRIBUTES) + +#define ACL_NFS4_PERM_BITS ACL_FULL_SET + +/* + * Possible entry_id values for acl_get_entry(3). + */ +#define ACL_FIRST_ENTRY 0 +#define ACL_NEXT_ENTRY 1 + +/* + * Possible values in ae_flags field; valid only for NFSv4 ACLs. + */ +#define ACL_ENTRY_FILE_INHERIT 0x0001 +#define ACL_ENTRY_DIRECTORY_INHERIT 0x0002 +#define ACL_ENTRY_NO_PROPAGATE_INHERIT 0x0004 +#define ACL_ENTRY_INHERIT_ONLY 0x0008 +#define ACL_ENTRY_SUCCESSFUL_ACCESS 0x0010 +#define ACL_ENTRY_FAILED_ACCESS 0x0020 +#define ACL_ENTRY_INHERITED 0x0080 + +#define ACL_FLAGS_BITS (ACL_ENTRY_FILE_INHERIT | \ + ACL_ENTRY_DIRECTORY_INHERIT | ACL_ENTRY_NO_PROPAGATE_INHERIT | \ + ACL_ENTRY_INHERIT_ONLY | ACL_ENTRY_SUCCESSFUL_ACCESS | \ + ACL_ENTRY_FAILED_ACCESS | ACL_ENTRY_INHERITED) + +/* + * Undefined value in ae_id field. ae_id should be set to this value + * iff ae_tag is ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER or ACL_EVERYONE. + */ +#define ACL_UNDEFINED_ID ((uid_t)-1) + +/* + * Possible values for _flags parameter in acl_to_text_np(3). + */ +#define ACL_TEXT_VERBOSE 0x01 +#define ACL_TEXT_NUMERIC_IDS 0x02 +#define ACL_TEXT_APPEND_ID 0x04 + +/* + * POSIX.1e ACLs are capable of expressing the read, write, and execute bits + * of the POSIX mode field. We provide two masks: one that defines the bits + * the ACL will replace in the mode, and the other that defines the bits that + * must be preseved when an ACL is updating a mode. + */ +#define ACL_OVERRIDE_MASK (S_IRWXU | S_IRWXG | S_IRWXO) +#define ACL_PRESERVE_MASK (~ACL_OVERRIDE_MASK) + +#ifdef _KERNEL + +/* + * Filesystem-independent code to move back and forth between POSIX mode and + * POSIX.1e ACL representations. + */ +acl_perm_t acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode); +struct acl_entry acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, + gid_t gid, mode_t mode); +mode_t acl_posix1e_perms_to_mode( + struct acl_entry *acl_user_obj_entry, + struct acl_entry *acl_group_obj_entry, + struct acl_entry *acl_other_entry); +mode_t acl_posix1e_acl_to_mode(struct acl *acl); +mode_t acl_posix1e_newfilemode(mode_t cmode, + struct acl *dacl); +struct acl *acl_alloc(int flags); +void acl_free(struct acl *aclp); + +void acl_nfs4_sync_acl_from_mode(struct acl *aclp, + mode_t mode, int file_owner_id); +void acl_nfs4_sync_mode_from_acl(mode_t *mode, + const struct acl *aclp); +int acl_nfs4_is_trivial(const struct acl *aclp, + int file_owner_id); +void acl_nfs4_compute_inherited_acl( + const struct acl *parent_aclp, + struct acl *child_aclp, mode_t mode, + int file_owner_id, int is_directory); +int acl_copy_oldacl_into_acl(const struct oldacl *source, + struct acl *dest); +int acl_copy_acl_into_oldacl(const struct acl *source, + struct oldacl *dest); + +/* + * To allocate 'struct acl', use acl_alloc()/acl_free() instead of this. + */ +MALLOC_DECLARE(M_ACL); +/* + * Filesystem-independent syntax check for a POSIX.1e ACL. + */ +int acl_posix1e_check(struct acl *acl); +int acl_nfs4_check(const struct acl *aclp, int is_directory); + +#else /* !_KERNEL */ + +#if defined(_ACL_PRIVATE) + +/* + * Syscall interface -- use the library calls instead as the syscalls have + * strict ACL entry ordering requirements. + */ +__BEGIN_DECLS +int __acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_aclcheck_file(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_aclcheck_link(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_delete_fd(int _filedes, acl_type_t _type); +int __acl_delete_file(const char *_path_p, acl_type_t _type); +int __acl_delete_link(const char *_path_p, acl_type_t _type); +int __acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_get_link(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_link(const char *_path, acl_type_t _type, struct acl *_aclp); +__END_DECLS + +#endif /* _ACL_PRIVATE */ + +/* + * Supported POSIX.1e ACL manipulation and assignment/retrieval API _np calls + * are local extensions that reflect an environment capable of opening file + * descriptors of directories, and allowing additional ACL type for different + * filesystems (i.e., AFS). + */ +__BEGIN_DECLS +int acl_add_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_calc_mask(acl_t *_acl_p); +int acl_clear_flags_np(acl_flagset_t _flagset_d); +int acl_clear_perms(acl_permset_t _permset_d); +int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d); +ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size); +acl_t acl_copy_int(const void *_buf_p); +int acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p); +int acl_create_entry_np(acl_t *_acl_p, acl_entry_t *_entry_p, int _index); +int acl_delete_entry(acl_t _acl, acl_entry_t _entry_d); +int acl_delete_entry_np(acl_t _acl, int _index); +int acl_delete_fd_np(int _filedes, acl_type_t _type); +int acl_delete_file_np(const char *_path_p, acl_type_t _type); +int acl_delete_link_np(const char *_path_p, acl_type_t _type); +int acl_delete_def_file(const char *_path_p); +int acl_delete_def_link_np(const char *_path_p); +int acl_delete_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm); +acl_t acl_dup(acl_t _acl); +int acl_free(void *_obj_p); +acl_t acl_from_text(const char *_buf_p); +int acl_get_brand_np(acl_t _acl, int *_brand_p); +int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p); +acl_t acl_get_fd(int _fd); +acl_t acl_get_fd_np(int fd, acl_type_t _type); +acl_t acl_get_file(const char *_path_p, acl_type_t _type); +int acl_get_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t *_entry_type_p); +acl_t acl_get_link_np(const char *_path_p, acl_type_t _type); +void *acl_get_qualifier(acl_entry_t _entry_d); +int acl_get_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_get_perm_np(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_get_flagset_np(acl_entry_t _entry_d, acl_flagset_t *_flagset_p); +int acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p); +int acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p); +acl_t acl_init(int _count); +int acl_set_fd(int _fd, acl_t _acl); +int acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type); +int acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t _entry_type); +int acl_set_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_flagset_np(acl_entry_t _entry_d, acl_flagset_t _flagset_d); +int acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d); +int acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p); +int acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type); +ssize_t acl_size(acl_t _acl); +char *acl_to_text(acl_t _acl, ssize_t *_len_p); +char *acl_to_text_np(acl_t _acl, ssize_t *_len_p, int _flags); +int acl_valid(acl_t _acl); +int acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl); +int acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_valid_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_is_trivial_np(const acl_t _acl, int *_trivialp); +acl_t acl_strip_np(const acl_t _acl, int recalculate_mask); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_ACL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/agpio.h b/lib/libc/include/any-freebsd-any/sys/agpio.h new file mode 100644 index 000000000000..69b91462f39b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/agpio.h @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_AGPIO_H_ +#define _SYS_AGPIO_H_ + +/* + * The AGP gatt uses 4k pages irrespective of the host page size. + */ +#define AGP_PAGE_SIZE 4096 +#define AGP_PAGE_SHIFT 12 + +/* + * Macros to manipulate AGP mode words. + * + * SBA = Sideband Address Port + * FW = Fast Writes + */ +#define AGP_MODE_GET_RQ(x) (((x) & 0xff000000U) >> 24) +#define AGP_MODE_GET_ARQSZ(x) (((x) & 0x0000e000U) >> 13) +#define AGP_MODE_GET_CAL(x) (((x) & 0x00001c00U) >> 10) +#define AGP_MODE_GET_SBA(x) (((x) & 0x00000200U) >> 9) +#define AGP_MODE_GET_AGP(x) (((x) & 0x00000100U) >> 8) +#define AGP_MODE_GET_GART_64(x) (((x) & 0x00000080U) >> 7) +#define AGP_MODE_GET_OVER_4G(x) (((x) & 0x00000020U) >> 5) +#define AGP_MODE_GET_FW(x) (((x) & 0x00000010U) >> 4) +#define AGP_MODE_GET_MODE_3(x) (((x) & 0x00000008U) >> 3) +#define AGP_MODE_GET_RATE(x) ((x) & 0x00000007U) +#define AGP_MODE_SET_RQ(x,v) (((x) & ~0xff000000U) | ((v) << 24)) +#define AGP_MODE_SET_ARQSZ(x,v) (((x) & ~0x0000e000U) | ((v) << 13)) +#define AGP_MODE_SET_CAL(x,v) (((x) & ~0x00001c00U) | ((v) << 10)) +#define AGP_MODE_SET_SBA(x,v) (((x) & ~0x00000200U) | ((v) << 9)) +#define AGP_MODE_SET_AGP(x,v) (((x) & ~0x00000100U) | ((v) << 8)) +#define AGP_MODE_SET_GART_64(x,v) (((x) & ~0x00000080U) | ((v) << 7)) +#define AGP_MODE_SET_OVER_4G(x,v) (((x) & ~0x00000020U) | ((v) << 5)) +#define AGP_MODE_SET_FW(x,v) (((x) & ~0x00000010U) | ((v) << 4)) +#define AGP_MODE_SET_MODE_3(x,v) (((x) & ~0x00000008U) | ((v) << 3)) +#define AGP_MODE_SET_RATE(x,v) (((x) & ~0x00000007U) | (v)) +#define AGP_MODE_V2_RATE_1x 0x00000001 +#define AGP_MODE_V2_RATE_2x 0x00000002 +#define AGP_MODE_V2_RATE_4x 0x00000004 +#define AGP_MODE_V3_RATE_4x 0x00000001 +#define AGP_MODE_V3_RATE_8x 0x00000002 +#define AGP_MODE_V3_RATE_RSVD 0x00000004 + +/* XXX: Compat */ +#define AGP_MODE_GET_4G(x) AGP_MODE_GET_OVER_4G(x) +#define AGP_MODE_SET_4G(x) AGP_MODE_SET_OVER_4G(x) +#define AGP_MODE_RATE_1x AGP_MODE_V2_RATE_1x +#define AGP_MODE_RATE_2x AGP_MODE_V2_RATE_2x +#define AGP_MODE_RATE_4x AGP_MODE_V2_RATE_4x + +#define AGPIOC_BASE 'A' +#define AGPIOC_INFO _IOR (AGPIOC_BASE, 0, agp_info) +#define AGPIOC_ACQUIRE _IO (AGPIOC_BASE, 1) +#define AGPIOC_RELEASE _IO (AGPIOC_BASE, 2) +#define AGPIOC_SETUP _IOW (AGPIOC_BASE, 3, agp_setup) +#if 0 +#define AGPIOC_RESERVE _IOW (AGPIOC_BASE, 4, agp_region) +#define AGPIOC_PROTECT _IOW (AGPIOC_BASE, 5, agp_region) +#endif +#define AGPIOC_ALLOCATE _IOWR(AGPIOC_BASE, 6, agp_allocate) +#define AGPIOC_DEALLOCATE _IOW (AGPIOC_BASE, 7, int) +#define AGPIOC_BIND _IOW (AGPIOC_BASE, 8, agp_bind) +#define AGPIOC_UNBIND _IOW (AGPIOC_BASE, 9, agp_unbind) +#define AGPIOC_CHIPSET_FLUSH _IO (AGPIOC_BASE, 10) + +typedef struct _agp_version { + u_int16_t major; + u_int16_t minor; +} agp_version; + +typedef struct _agp_info { + agp_version version; /* version of the driver */ + u_int32_t bridge_id; /* bridge vendor/device */ + u_int32_t agp_mode; /* mode info of bridge */ + off_t aper_base; /* base of aperture */ + size_t aper_size; /* size of aperture */ + size_t pg_total; /* max pages (swap + system) */ + size_t pg_system; /* max pages (system) */ + size_t pg_used; /* current pages used */ +} agp_info; + +typedef struct _agp_setup { + u_int32_t agp_mode; /* mode info of bridge */ +} agp_setup; + +#if 0 +/* + * The "prot" down below needs still a "sleep" flag somehow ... + */ +typedef struct _agp_segment { + off_t pg_start; /* starting page to populate */ + size_t pg_count; /* number of pages */ + int prot; /* prot flags for mmap */ +} agp_segment; + +typedef struct _agp_region { + pid_t pid; /* pid of process */ + size_t seg_count; /* number of segments */ + struct _agp_segment *seg_list; +} agp_region; +#endif + +typedef struct _agp_allocate { + int key; /* tag of allocation */ + size_t pg_count; /* number of pages */ + u_int32_t type; /* 0 == normal, other devspec */ + u_int32_t physical; /* device specific (some devices + * need a phys address of the + * actual page behind the gatt + * table) */ +} agp_allocate; + +typedef struct _agp_bind { + int key; /* tag of allocation */ + off_t pg_start; /* starting page to populate */ +} agp_bind; + +typedef struct _agp_unbind { + int key; /* tag of allocation */ + u_int32_t priority; /* priority for paging out */ +} agp_unbind; + +#endif /* !_SYS_AGPIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/aio.h b/lib/libc/include/any-freebsd-any/sys/aio.h new file mode 100644 index 000000000000..6ab8bdb7f296 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/aio.h @@ -0,0 +1,266 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997 John S. Dyson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. John S. Dyson's name may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * DISCLAIMER: This code isn't warranted to do anything useful. Anything + * bad that happens because of using this software isn't the responsibility + * of the author. This software is distributed AS-IS. + * + * $FreeBSD$ + */ + +#ifndef _SYS_AIO_H_ +#define _SYS_AIO_H_ + +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif + +/* + * Returned by aio_cancel: + */ +#define AIO_CANCELED 0x1 +#define AIO_NOTCANCELED 0x2 +#define AIO_ALLDONE 0x3 + +/* + * LIO opcodes + */ +#define LIO_NOP 0x0 +#define LIO_WRITE 0x1 +#define LIO_READ 0x2 +#ifdef _KERNEL +#define LIO_SYNC 0x3 +#define LIO_MLOCK 0x4 +#endif + +/* + * LIO modes + */ +#define LIO_NOWAIT 0x0 +#define LIO_WAIT 0x1 + +/* + * Maximum number of operations in a single lio_listio call + */ +#define AIO_LISTIO_MAX 16 + +#ifdef _KERNEL + +/* Default values of tunables for the AIO worker pool. */ + +#ifndef MAX_AIO_PROCS +#define MAX_AIO_PROCS 32 +#endif + +#ifndef TARGET_AIO_PROCS +#define TARGET_AIO_PROCS 4 +#endif + +#ifndef AIOD_LIFETIME_DEFAULT +#define AIOD_LIFETIME_DEFAULT (30 * hz) +#endif + +#endif + +/* + * Private members for aiocb -- don't access + * directly. + */ +struct __aiocb_private { + long status; + long error; + void *kernelinfo; +}; + +/* + * I/O control block + */ +typedef struct aiocb { + int aio_fildes; /* File descriptor */ + off_t aio_offset; /* File offset for I/O */ + volatile void *aio_buf; /* I/O buffer in process space */ + size_t aio_nbytes; /* Number of bytes for I/O */ + int __spare__[2]; + void *__spare2__; + int aio_lio_opcode; /* LIO opcode */ + int aio_reqprio; /* Request priority -- ignored */ + struct __aiocb_private _aiocb_private; + struct sigevent aio_sigevent; /* Signal to deliver */ +} aiocb_t; + +#ifdef _KERNEL + +typedef void aio_cancel_fn_t(struct kaiocb *); +typedef void aio_handle_fn_t(struct kaiocb *); + +/* + * Kernel version of an I/O control block. + * + * Locking key: + * * - need not protected + * a - locked by kaioinfo lock + * b - locked by backend lock + * c - locked by aio_job_mtx + */ +struct kaiocb { + TAILQ_ENTRY(kaiocb) list; /* (b) backend-specific list of jobs */ + TAILQ_ENTRY(kaiocb) plist; /* (a) lists of pending / done jobs */ + TAILQ_ENTRY(kaiocb) allist; /* (a) list of all jobs in proc */ + int jobflags; /* (a) job flags */ + int inblock; /* (*) input blocks */ + int outblock; /* (*) output blocks */ + int msgsnd; /* (*) messages sent */ + int msgrcv; /* (*) messages received */ + struct proc *userproc; /* (*) user process */ + struct ucred *cred; /* (*) active credential when created */ + struct file *fd_file; /* (*) pointer to file structure */ + struct aioliojob *lio; /* (*) optional lio job */ + struct aiocb *ujob; /* (*) pointer in userspace of aiocb */ + struct knlist klist; /* (a) list of knotes */ + struct aiocb uaiocb; /* (*) copy of user I/O control block */ + ksiginfo_t ksi; /* (a) realtime signal info */ + uint64_t seqno; /* (*) job number */ + aio_cancel_fn_t *cancel_fn; /* (a) backend cancel function */ + aio_handle_fn_t *handle_fn; /* (c) backend handle function */ + union { /* Backend-specific data fields */ + struct { /* BIO backend */ + struct bio *bp; /* (*) BIO pointer */ + struct buf *pbuf; /* (*) buffer pointer */ + struct vm_page *pages[btoc(MAXPHYS)+1]; /* (*) */ + int npages; /* (*) number of pages */ + }; + struct { /* fsync() requests */ + int pending; /* (a) number of pending I/O */ + }; + struct { + void *backend1; + void *backend2; + long backend3; + int backend4; + }; + }; +}; + +struct socket; +struct sockbuf; + +/* + * AIO backends should permit cancellation of queued requests waiting to + * be serviced by installing a cancel routine while the request is + * queued. The cancellation routine should dequeue the request if + * necessary and cancel it. Care must be used to handle races between + * queueing and dequeueing requests and cancellation. + * + * When queueing a request somewhere such that it can be cancelled, the + * caller should: + * + * 1) Acquire lock that protects the associated queue. + * 2) Call aio_set_cancel_function() to install the cancel routine. + * 3) If that fails, the request has a pending cancel and should be + * cancelled via aio_cancel(). + * 4) Queue the request. + * + * When dequeueing a request to service it or hand it off to somewhere else, + * the caller should: + * + * 1) Acquire the lock that protects the associated queue. + * 2) Dequeue the request. + * 3) Call aio_clear_cancel_function() to clear the cancel routine. + * 4) If that fails, the cancel routine is about to be called. The + * caller should ignore the request. + * + * The cancel routine should: + * + * 1) Acquire the lock that protects the associated queue. + * 2) Call aio_cancel_cleared() to determine if the request is already + * dequeued due to a race with dequeueing thread. + * 3) If that fails, dequeue the request. + * 4) Cancel the request via aio_cancel(). + */ + +bool aio_cancel_cleared(struct kaiocb *job); +void aio_cancel(struct kaiocb *job); +bool aio_clear_cancel_function(struct kaiocb *job); +void aio_complete(struct kaiocb *job, long status, int error); +void aio_schedule(struct kaiocb *job, aio_handle_fn_t *func); +bool aio_set_cancel_function(struct kaiocb *job, aio_cancel_fn_t *func); +void aio_switch_vmspace(struct kaiocb *job); + +#else /* !_KERNEL */ + +struct timespec; + +__BEGIN_DECLS +/* + * Asynchronously read from a file + */ +int aio_read(struct aiocb *); + +/* + * Asynchronously write to file + */ +int aio_write(struct aiocb *); + +/* + * List I/O Asynchronously/synchronously read/write to/from file + * "lio_mode" specifies whether or not the I/O is synchronous. + * "acb_list" is an array of "nacb_listent" I/O control blocks. + * when all I/Os are complete, the optional signal "sig" is sent. + */ +int lio_listio(int, struct aiocb *__restrict const *__restrict, int, + struct sigevent *); + +/* + * Get completion status + * returns EINPROGRESS until I/O is complete. + * this routine does not block. + */ +int aio_error(const struct aiocb *); + +/* + * Finish up I/O, releasing I/O resources and returns the value + * that would have been associated with a synchronous I/O request. + * This routine must be called once and only once for each + * I/O control block who has had I/O associated with it. + */ +ssize_t aio_return(struct aiocb *); + +/* + * Cancel I/O + */ +int aio_cancel(int, struct aiocb *); + +/* + * Suspend until all specified I/O or timeout is complete. + */ +int aio_suspend(const struct aiocb * const[], int, const struct timespec *); + +/* + * Asynchronous mlock + */ +int aio_mlock(struct aiocb *); + +#if __BSD_VISIBLE +ssize_t aio_waitcomplete(struct aiocb **, struct timespec *); +#endif + +int aio_fsync(int op, struct aiocb *aiocbp); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_AIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/alq.h b/lib/libc/include/any-freebsd-any/sys/alq.h new file mode 100644 index 000000000000..536fa2077357 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/alq.h @@ -0,0 +1,146 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2002, Jeffrey Roberson + * Copyright (c) 2008-2009, Lawrence Stewart + * Copyright (c) 2010, The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed at the Centre for Advanced + * Internet Architectures, Swinburne University of Technology, Melbourne, + * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ +#ifndef _SYS_ALQ_H_ +#define _SYS_ALQ_H_ + +/* + * Opaque type for the Async. Logging Queue + */ +struct alq; + +/* The thread for the logging daemon */ +extern struct thread *ald_thread; + +/* + * Async. Logging Entry + */ +struct ale { + intptr_t ae_bytesused; /* # bytes written to ALE. */ + char *ae_data; /* Write ptr. */ + int ae_pad; /* Unused, compat. */ +}; + +/* Flag options. */ +#define ALQ_NOWAIT 0x0001 /* ALQ may not sleep. */ +#define ALQ_WAITOK 0x0002 /* ALQ may sleep. */ +#define ALQ_NOACTIVATE 0x0004 /* Don't activate ALQ after write. */ +#define ALQ_ORDERED 0x0010 /* Maintain write ordering between threads. */ + +/* Suggested mode for file creation. */ +#define ALQ_DEFAULT_CMODE 0600 + +/* + * alq_open_flags: Creates a new queue + * + * Arguments: + * alq Storage for a pointer to the newly created queue. + * file The filename to open for logging. + * cred Credential to authorize open and I/O with. + * cmode Creation mode for file, if new. + * size The size of the queue in bytes. + * flags ALQ_ORDERED + * Returns: + * error from open or 0 on success + */ +struct ucred; +int alq_open_flags(struct alq **alqp, const char *file, struct ucred *cred, int cmode, + int size, int flags); +int alq_open(struct alq **alqp, const char *file, struct ucred *cred, int cmode, + int size, int count); + +/* + * alq_writen: Write data into the queue + * + * Arguments: + * alq The queue we're writing to + * data The entry to be recorded + * len The number of bytes to write from *data + * flags (ALQ_NOWAIT || ALQ_WAITOK), ALQ_NOACTIVATE + * + * Returns: + * EWOULDBLOCK if: + * Waitok is ALQ_NOWAIT and the queue is full. + * The system is shutting down. + * 0 on success. + */ +int alq_writen(struct alq *alq, void *data, int len, int flags); +int alq_write(struct alq *alq, void *data, int flags); + +/* + * alq_flush: Flush the queue out to disk + */ +void alq_flush(struct alq *alq); + +/* + * alq_close: Flush the queue and free all resources. + */ +void alq_close(struct alq *alq); + +/* + * alq_getn: Return an entry for direct access + * + * Arguments: + * alq The queue to retrieve an entry from + * len Max number of bytes required + * flags (ALQ_NOWAIT || ALQ_WAITOK) + * + * Returns: + * The next available ale on success. + * NULL if: + * flags is ALQ_NOWAIT and the queue is full. + * The system is shutting down. + * + * This leaves the queue locked until a subsequent alq_post. + */ +struct ale *alq_getn(struct alq *alq, int len, int flags); +struct ale *alq_get(struct alq *alq, int flags); + +/* + * alq_post_flags: Schedule the ale retrieved by alq_get/alq_getn for writing. + * alq The queue to post the entry to. + * ale An asynch logging entry returned by alq_get. + * flags ALQ_NOACTIVATE + */ +void alq_post_flags(struct alq *alq, struct ale *ale, int flags); + +static __inline void +alq_post(struct alq *alq, struct ale *ale) +{ + alq_post_flags(alq, ale, 0); +} + +#endif /* _SYS_ALQ_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/apm.h b/lib/libc/include/any-freebsd-any/sys/apm.h new file mode 100644 index 000000000000..ef076ea594b4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/apm.h @@ -0,0 +1,5 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ +#include diff --git a/lib/libc/include/any-freebsd-any/sys/assym.h b/lib/libc/include/any-freebsd-any/sys/assym.h new file mode 100644 index 000000000000..f5204fa83b16 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/assym.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ASSYM_H_ +#define _SYS_ASSYM_H_ + +#define ASSYM_BIAS 0x10000 /* avoid zero-length arrays */ +#define ASSYM_ABS(value) ((value) < 0 ? -((value) + 1) + 1ULL : (value)) + +#define ASSYM(name, value) \ +char name ## sign[((value) < 0 ? 1 : 0) + ASSYM_BIAS]; \ +char name ## w0[(ASSYM_ABS(value) & 0xFFFFU) + ASSYM_BIAS]; \ +char name ## w1[((ASSYM_ABS(value) & 0xFFFF0000UL) >> 16) + ASSYM_BIAS]; \ +char name ## w2[((ASSYM_ABS(value) & 0xFFFF00000000ULL) >> 32) + ASSYM_BIAS]; \ +char name ## w3[((ASSYM_ABS(value) & 0xFFFF000000000000ULL) >> 48) + ASSYM_BIAS] + + +/* char name ## _datatype_ ## STRINGIFY(typeof(((struct parenttype *)(0x0))-> name)) [1]; */ +#ifdef OFFSET_TEST +#define OFFSET_CTASSERT CTASSERT +#else +#define OFFSET_CTASSERT(...) +#endif + +#define OFFSYM(name, parenttype, datatype) \ +ASSYM(name, offsetof(struct parenttype, name)); \ +char name ## _datatype_ ## datatype [1]; \ +char name ## _parenttype_ ## parenttype [1]; \ +CTASSERT(__builtin_types_compatible_p(__typeof(((struct parenttype *)(0x0))-> name), datatype)); \ +OFFSET_CTASSERT(offsetof(struct parenttype, name) == offsetof(struct parenttype ## _lite, name)) + +#endif /* !_SYS_ASSYM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ata.h b/lib/libc/include/any-freebsd-any/sys/ata.h new file mode 100644 index 000000000000..da05718931b8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ata.h @@ -0,0 +1,1060 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 - 2008 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ATA_H_ +#define _SYS_ATA_H_ + +#include + +/* ATA/ATAPI device parameters */ +struct ata_params { +/*000*/ u_int16_t config; /* configuration info */ +#define ATA_PROTO_MASK 0x8003 +#define ATA_PROTO_ATAPI 0x8000 +#define ATA_PROTO_ATAPI_12 0x8000 +#define ATA_PROTO_ATAPI_16 0x8001 +#define ATA_PROTO_CFA 0x848a +#define ATA_ATAPI_TYPE_MASK 0x1f00 +#define ATA_ATAPI_TYPE_DIRECT 0x0000 /* disk/floppy */ +#define ATA_ATAPI_TYPE_TAPE 0x0100 /* streaming tape */ +#define ATA_ATAPI_TYPE_CDROM 0x0500 /* CD-ROM device */ +#define ATA_ATAPI_TYPE_OPTICAL 0x0700 /* optical disk */ +#define ATA_ATAPI_REMOVABLE 0x0080 +#define ATA_DRQ_MASK 0x0060 +#define ATA_DRQ_SLOW 0x0000 /* cpu 3 ms delay */ +#define ATA_DRQ_INTR 0x0020 /* interrupt 10 ms delay */ +#define ATA_DRQ_FAST 0x0040 /* accel 50 us delay */ +#define ATA_RESP_INCOMPLETE 0x0004 + +/*001*/ u_int16_t cylinders; /* # of cylinders */ +/*002*/ u_int16_t specconf; /* specific configuration */ +/*003*/ u_int16_t heads; /* # heads */ + u_int16_t obsolete4; + u_int16_t obsolete5; +/*006*/ u_int16_t sectors; /* # sectors/track */ +/*007*/ u_int16_t vendor7[3]; +/*010*/ u_int8_t serial[20]; /* serial number */ +/*020*/ u_int16_t retired20; + u_int16_t retired21; + u_int16_t obsolete22; +/*023*/ u_int8_t revision[8]; /* firmware revision */ +/*027*/ u_int8_t model[40]; /* model name */ +/*047*/ u_int16_t sectors_intr; /* sectors per interrupt */ +/*048*/ u_int16_t tcg; /* Trusted Computing Group */ +#define ATA_SUPPORT_TCG 0x0001 +/*049*/ u_int16_t capabilities1; +#define ATA_SUPPORT_DMA 0x0100 +#define ATA_SUPPORT_LBA 0x0200 +#define ATA_SUPPORT_IORDYDIS 0x0400 +#define ATA_SUPPORT_IORDY 0x0800 +#define ATA_SUPPORT_OVERLAP 0x4000 + +/*050*/ u_int16_t capabilities2; +/*051*/ u_int16_t retired_piomode; /* PIO modes 0-2 */ +#define ATA_RETIRED_PIO_MASK 0x0300 + +/*052*/ u_int16_t retired_dmamode; /* DMA modes */ +#define ATA_RETIRED_DMA_MASK 0x0003 + +/*053*/ u_int16_t atavalid; /* fields valid */ +#define ATA_FLAG_54_58 0x0001 /* words 54-58 valid */ +#define ATA_FLAG_64_70 0x0002 /* words 64-70 valid */ +#define ATA_FLAG_88 0x0004 /* word 88 valid */ + +/*054*/ u_int16_t current_cylinders; +/*055*/ u_int16_t current_heads; +/*056*/ u_int16_t current_sectors; +/*057*/ u_int16_t current_size_1; +/*058*/ u_int16_t current_size_2; +/*059*/ u_int16_t multi; +#define ATA_SUPPORT_BLOCK_ERASE_EXT 0x8000 +#define ATA_SUPPORT_OVERWRITE_EXT 0x4000 +#define ATA_SUPPORT_CRYPTO_SCRAMBLE_EXT 0x2000 +#define ATA_SUPPORT_SANITIZE 0x1000 +#define ATA_SUPPORT_SANITIZE_ALLOWED 0x0800 +#define ATA_SUPPORT_ANTIFREEZE_LOCK_EXT 0x0400 +#define ATA_MULTI_VALID 0x0100 + +/*060*/ u_int16_t lba_size_1; + u_int16_t lba_size_2; + u_int16_t obsolete62; +/*063*/ u_int16_t mwdmamodes; /* multiword DMA modes */ +/*064*/ u_int16_t apiomodes; /* advanced PIO modes */ + +/*065*/ u_int16_t mwdmamin; /* min. M/W DMA time/word ns */ +/*066*/ u_int16_t mwdmarec; /* rec. M/W DMA time ns */ +/*067*/ u_int16_t pioblind; /* min. PIO cycle w/o flow */ +/*068*/ u_int16_t pioiordy; /* min. PIO cycle IORDY flow */ +/*069*/ u_int16_t support3; +#define ATA_SUPPORT_RZAT 0x0020 +#define ATA_SUPPORT_DRAT 0x4000 +#define ATA_ENCRYPTS_ALL_USER_DATA 0x0010 /* Self-encrypting drive */ +#define ATA_SUPPORT_ZONE_MASK 0x0003 +#define ATA_SUPPORT_ZONE_NR 0x0000 +#define ATA_SUPPORT_ZONE_HOST_AWARE 0x0001 +#define ATA_SUPPORT_ZONE_DEV_MANAGED 0x0002 + u_int16_t reserved70; +/*071*/ u_int16_t rlsovlap; /* rel time (us) for overlap */ +/*072*/ u_int16_t rlsservice; /* rel time (us) for service */ + u_int16_t reserved73; + u_int16_t reserved74; +/*075*/ u_int16_t queue; +#define ATA_QUEUE_LEN(x) ((x) & 0x001f) + +/*76*/ u_int16_t satacapabilities; +#define ATA_SATA_GEN1 0x0002 +#define ATA_SATA_GEN2 0x0004 +#define ATA_SATA_GEN3 0x0008 +#define ATA_SUPPORT_NCQ 0x0100 +#define ATA_SUPPORT_IFPWRMNGTRCV 0x0200 +#define ATA_SUPPORT_PHYEVENTCNT 0x0400 +#define ATA_SUPPORT_NCQ_UNLOAD 0x0800 +#define ATA_SUPPORT_NCQ_PRIO 0x1000 +#define ATA_SUPPORT_HAPST 0x2000 +#define ATA_SUPPORT_DAPST 0x4000 +#define ATA_SUPPORT_READLOGDMAEXT 0x8000 + +/*77*/ u_int16_t satacapabilities2; +#define ATA_SATA_CURR_GEN_MASK 0x0006 +#define ATA_SUPPORT_NCQ_STREAM 0x0010 +#define ATA_SUPPORT_NCQ_NON_DATA 0x0020 +#define ATA_SUPPORT_NCQ_QMANAGEMENT ATA_SUPPORT_NCQ_NON_DATA +#define ATA_SUPPORT_RCVSND_FPDMA_QUEUED 0x0040 +/*78*/ u_int16_t satasupport; +#define ATA_SUPPORT_NONZERO 0x0002 +#define ATA_SUPPORT_AUTOACTIVATE 0x0004 +#define ATA_SUPPORT_IFPWRMNGT 0x0008 +#define ATA_SUPPORT_INORDERDATA 0x0010 +#define ATA_SUPPORT_ASYNCNOTIF 0x0020 +#define ATA_SUPPORT_SOFTSETPRESERVE 0x0040 +#define ATA_SUPPORT_NCQ_AUTOSENSE 0x0080 +/*79*/ u_int16_t sataenabled; +#define ATA_ENABLED_DAPST 0x0080 + +/*080*/ u_int16_t version_major; +/*081*/ u_int16_t version_minor; + + struct { +/*082/085*/ u_int16_t command1; +#define ATA_SUPPORT_SMART 0x0001 +#define ATA_SUPPORT_SECURITY 0x0002 +#define ATA_SUPPORT_REMOVABLE 0x0004 +#define ATA_SUPPORT_POWERMGT 0x0008 +#define ATA_SUPPORT_PACKET 0x0010 +#define ATA_SUPPORT_WRITECACHE 0x0020 +#define ATA_SUPPORT_LOOKAHEAD 0x0040 +#define ATA_SUPPORT_RELEASEIRQ 0x0080 +#define ATA_SUPPORT_SERVICEIRQ 0x0100 +#define ATA_SUPPORT_RESET 0x0200 +#define ATA_SUPPORT_PROTECTED 0x0400 +#define ATA_SUPPORT_WRITEBUFFER 0x1000 +#define ATA_SUPPORT_READBUFFER 0x2000 +#define ATA_SUPPORT_NOP 0x4000 + +/*083/086*/ u_int16_t command2; +#define ATA_SUPPORT_MICROCODE 0x0001 +#define ATA_SUPPORT_QUEUED 0x0002 +#define ATA_SUPPORT_CFA 0x0004 +#define ATA_SUPPORT_APM 0x0008 +#define ATA_SUPPORT_NOTIFY 0x0010 +#define ATA_SUPPORT_STANDBY 0x0020 +#define ATA_SUPPORT_SPINUP 0x0040 +#define ATA_SUPPORT_MAXSECURITY 0x0100 +#define ATA_SUPPORT_AUTOACOUSTIC 0x0200 +#define ATA_SUPPORT_ADDRESS48 0x0400 +#define ATA_SUPPORT_OVERLAY 0x0800 +#define ATA_SUPPORT_FLUSHCACHE 0x1000 +#define ATA_SUPPORT_FLUSHCACHE48 0x2000 + +/*084/087*/ u_int16_t extension; +#define ATA_SUPPORT_SMARTLOG 0x0001 +#define ATA_SUPPORT_SMARTTEST 0x0002 +#define ATA_SUPPORT_MEDIASN 0x0004 +#define ATA_SUPPORT_MEDIAPASS 0x0008 +#define ATA_SUPPORT_STREAMING 0x0010 +#define ATA_SUPPORT_GENLOG 0x0020 +#define ATA_SUPPORT_WRITEDMAFUAEXT 0x0040 +#define ATA_SUPPORT_WRITEDMAQFUAEXT 0x0080 +#define ATA_SUPPORT_64BITWWN 0x0100 +#define ATA_SUPPORT_UNLOAD 0x2000 + } __packed support, enabled; + +/*088*/ u_int16_t udmamodes; /* UltraDMA modes */ +/*089*/ u_int16_t erase_time; /* time req'd in 2min units */ +/*090*/ u_int16_t enhanced_erase_time; /* time req'd in 2min units */ +/*091*/ u_int16_t apm_value; +/*092*/ u_int16_t master_passwd_revision; /* password revision code */ +/*093*/ u_int16_t hwres; +#define ATA_CABLE_ID 0x2000 + +/*094*/ u_int16_t acoustic; +#define ATA_ACOUSTIC_CURRENT(x) ((x) & 0x00ff) +#define ATA_ACOUSTIC_VENDOR(x) (((x) & 0xff00) >> 8) + +/*095*/ u_int16_t stream_min_req_size; +/*096*/ u_int16_t stream_transfer_time; +/*097*/ u_int16_t stream_access_latency; +/*098*/ u_int32_t stream_granularity; +/*100*/ u_int16_t lba_size48_1; + u_int16_t lba_size48_2; + u_int16_t lba_size48_3; + u_int16_t lba_size48_4; + u_int16_t reserved104; +/*105*/ u_int16_t max_dsm_blocks; +/*106*/ u_int16_t pss; +#define ATA_PSS_LSPPS 0x000F +#define ATA_PSS_LSSABOVE512 0x1000 +#define ATA_PSS_MULTLS 0x2000 +#define ATA_PSS_VALID_MASK 0xC000 +#define ATA_PSS_VALID_VALUE 0x4000 +/*107*/ u_int16_t isd; +/*108*/ u_int16_t wwn[4]; + u_int16_t reserved112[5]; +/*117*/ u_int16_t lss_1; +/*118*/ u_int16_t lss_2; +/*119*/ u_int16_t support2; +#define ATA_SUPPORT_WRITEREADVERIFY 0x0002 +#define ATA_SUPPORT_WRITEUNCORREXT 0x0004 +#define ATA_SUPPORT_RWLOGDMAEXT 0x0008 +#define ATA_SUPPORT_MICROCODE3 0x0010 +#define ATA_SUPPORT_FREEFALL 0x0020 +#define ATA_SUPPORT_SENSE_REPORT 0x0040 +#define ATA_SUPPORT_EPC 0x0080 +#define ATA_SUPPORT_AMAX_ADDR 0x0100 +#define ATA_SUPPORT_DSN 0x0200 +/*120*/ u_int16_t enabled2; +#define ATA_ENABLED_WRITEREADVERIFY 0x0002 +#define ATA_ENABLED_WRITEUNCORREXT 0x0004 +#define ATA_ENABLED_FREEFALL 0x0020 +#define ATA_ENABLED_SENSE_REPORT 0x0040 +#define ATA_ENABLED_EPC 0x0080 +#define ATA_ENABLED_DSN 0x0200 + u_int16_t reserved121[6]; +/*127*/ u_int16_t removable_status; +/*128*/ u_int16_t security_status; +#define ATA_SECURITY_LEVEL 0x0100 /* 0: high, 1: maximum */ +#define ATA_SECURITY_ENH_SUPP 0x0020 /* enhanced erase supported */ +#define ATA_SECURITY_COUNT_EXP 0x0010 /* count expired */ +#define ATA_SECURITY_FROZEN 0x0008 /* security config is frozen */ +#define ATA_SECURITY_LOCKED 0x0004 /* drive is locked */ +#define ATA_SECURITY_ENABLED 0x0002 /* ATA Security is enabled */ +#define ATA_SECURITY_SUPPORTED 0x0001 /* ATA Security is supported */ + + u_int16_t reserved129[31]; +/*160*/ u_int16_t cfa_powermode1; + u_int16_t reserved161; +/*162*/ u_int16_t cfa_kms_support; +/*163*/ u_int16_t cfa_trueide_modes; +/*164*/ u_int16_t cfa_memory_modes; + u_int16_t reserved165[3]; +/*168*/ u_int16_t form_factor; +#define ATA_FORM_FACTOR_MASK 0x000f +#define ATA_FORM_FACTOR_NOT_REPORTED 0x0000 +#define ATA_FORM_FACTOR_5_25 0x0001 +#define ATA_FORM_FACTOR_3_5 0x0002 +#define ATA_FORM_FACTOR_2_5 0x0003 +#define ATA_FORM_FACTOR_1_8 0x0004 +#define ATA_FORM_FACTOR_SUB_1_8 0x0005 +#define ATA_FORM_FACTOR_MSATA 0x0006 +#define ATA_FORM_FACTOR_M_2 0x0007 +#define ATA_FORM_FACTOR_MICRO_SSD 0x0008 +#define ATA_FORM_FACTOR_C_FAST 0x0009 +/*169*/ u_int16_t support_dsm; +#define ATA_SUPPORT_DSM_TRIM 0x0001 +/*170*/ u_int8_t product_id[8]; /* Additional Product Identifier */ + u_int16_t reserved174[2]; +/*176*/ u_int8_t media_serial[60]; +/*206*/ u_int16_t sct; + u_int16_t reserved207[2]; +/*209*/ u_int16_t lsalign; +/*210*/ u_int16_t wrv_sectors_m3_1; + u_int16_t wrv_sectors_m3_2; +/*212*/ u_int16_t wrv_sectors_m2_1; + u_int16_t wrv_sectors_m2_2; +/*214*/ u_int16_t nv_cache_caps; +/*215*/ u_int16_t nv_cache_size_1; + u_int16_t nv_cache_size_2; +/*217*/ u_int16_t media_rotation_rate; +#define ATA_RATE_NOT_REPORTED 0x0000 +#define ATA_RATE_NON_ROTATING 0x0001 + u_int16_t reserved218; +/*219*/ u_int16_t nv_cache_opt; +/*220*/ u_int16_t wrv_mode; + u_int16_t reserved221; +/*222*/ u_int16_t transport_major; +/*223*/ u_int16_t transport_minor; + u_int16_t reserved224[31]; +/*255*/ u_int16_t integrity; +} __packed; + +/* ATA Dataset Management */ +#define ATA_DSM_BLK_SIZE 512 +#define ATA_DSM_BLK_RANGES 64 +#define ATA_DSM_RANGE_SIZE 8 +#define ATA_DSM_RANGE_MAX 65535 + +/* + * ATA Device Register + * + * bit 7 Obsolete (was 1 in early ATA specs) + * bit 6 Sets LBA/CHS mode. 1=LBA, 0=CHS + * bit 5 Obsolete (was 1 in early ATA specs) + * bit 4 1 = Slave Drive, 0 = Master Drive + * bit 3-0 In LBA mode, 27-24 of address. In CHS mode, head number +*/ + +#define ATA_DEV_MASTER 0x00 +#define ATA_DEV_SLAVE 0x10 +#define ATA_DEV_LBA 0x40 + +/* ATA limits */ +#define ATA_MAX_28BIT_LBA 268435455UL + +/* ATA Status Register */ +#define ATA_STATUS_ERROR 0x01 +#define ATA_STATUS_SENSE_AVAIL 0x02 +#define ATA_STATUS_ALIGN_ERR 0x04 +#define ATA_STATUS_DATA_REQ 0x08 +#define ATA_STATUS_DEF_WRITE_ERR 0x10 +#define ATA_STATUS_DEVICE_FAULT 0x20 +#define ATA_STATUS_DEVICE_READY 0x40 +#define ATA_STATUS_BUSY 0x80 + +/* ATA Error Register */ +#define ATA_ERROR_ABORT 0x04 +#define ATA_ERROR_ID_NOT_FOUND 0x10 + +/* ATA HPA Features */ +#define ATA_HPA_FEAT_MAX_ADDR 0x00 +#define ATA_HPA_FEAT_SET_PWD 0x01 +#define ATA_HPA_FEAT_LOCK 0x02 +#define ATA_HPA_FEAT_UNLOCK 0x03 +#define ATA_HPA_FEAT_FREEZE 0x04 + +/* ATA transfer modes */ +#define ATA_MODE_MASK 0x0f +#define ATA_DMA_MASK 0xf0 +#define ATA_PIO 0x00 +#define ATA_PIO0 0x08 +#define ATA_PIO1 0x09 +#define ATA_PIO2 0x0a +#define ATA_PIO3 0x0b +#define ATA_PIO4 0x0c +#define ATA_PIO_MAX 0x0f +#define ATA_DMA 0x10 +#define ATA_WDMA0 0x20 +#define ATA_WDMA1 0x21 +#define ATA_WDMA2 0x22 +#define ATA_UDMA0 0x40 +#define ATA_UDMA1 0x41 +#define ATA_UDMA2 0x42 +#define ATA_UDMA3 0x43 +#define ATA_UDMA4 0x44 +#define ATA_UDMA5 0x45 +#define ATA_UDMA6 0x46 +#define ATA_SA150 0x47 +#define ATA_SA300 0x48 +#define ATA_SA600 0x49 +#define ATA_DMA_MAX 0x4f + + +/* ATA commands */ +#define ATA_NOP 0x00 /* NOP */ +#define ATA_NF_FLUSHQUEUE 0x00 /* flush queued cmd's */ +#define ATA_NF_AUTOPOLL 0x01 /* start autopoll function */ +#define ATA_DATA_SET_MANAGEMENT 0x06 +#define ATA_DSM_TRIM 0x01 +#define ATA_DEVICE_RESET 0x08 /* reset device */ +#define ATA_READ 0x20 /* read */ +#define ATA_READ48 0x24 /* read 48bit LBA */ +#define ATA_READ_DMA48 0x25 /* read DMA 48bit LBA */ +#define ATA_READ_DMA_QUEUED48 0x26 /* read DMA QUEUED 48bit LBA */ +#define ATA_READ_NATIVE_MAX_ADDRESS48 0x27 /* read native max addr 48bit */ +#define ATA_READ_MUL48 0x29 /* read multi 48bit LBA */ +#define ATA_READ_STREAM_DMA48 0x2a /* read DMA stream 48bit LBA */ +#define ATA_READ_LOG_EXT 0x2f /* read log ext - PIO Data-In */ +#define ATA_READ_STREAM48 0x2b /* read stream 48bit LBA */ +#define ATA_WRITE 0x30 /* write */ +#define ATA_WRITE48 0x34 /* write 48bit LBA */ +#define ATA_WRITE_DMA48 0x35 /* write DMA 48bit LBA */ +#define ATA_WRITE_DMA_QUEUED48 0x36 /* write DMA QUEUED 48bit LBA*/ +#define ATA_SET_MAX_ADDRESS48 0x37 /* set max address 48bit */ +#define ATA_WRITE_MUL48 0x39 /* write multi 48bit LBA */ +#define ATA_WRITE_STREAM_DMA48 0x3a +#define ATA_WRITE_STREAM48 0x3b +#define ATA_WRITE_DMA_FUA48 0x3d +#define ATA_WRITE_DMA_QUEUED_FUA48 0x3e +#define ATA_WRITE_LOG_EXT 0x3f +#define ATA_READ_VERIFY 0x40 +#define ATA_READ_VERIFY48 0x42 +#define ATA_WRITE_UNCORRECTABLE48 0x45 /* write uncorrectable 48bit LBA */ +#define ATA_WU_PSEUDO 0x55 /* pseudo-uncorrectable error */ +#define ATA_WU_FLAGGED 0xaa /* flagged-uncorrectable error */ +#define ATA_READ_LOG_DMA_EXT 0x47 /* read log DMA ext - PIO Data-In */ +#define ATA_ZAC_MANAGEMENT_IN 0x4a /* ZAC management in */ +#define ATA_ZM_REPORT_ZONES 0x00 /* report zones */ +#define ATA_WRITE_LOG_DMA_EXT 0x57 /* WRITE LOG DMA EXT */ +#define ATA_TRUSTED_NON_DATA 0x5b /* TRUSTED NON-DATA */ +#define ATA_TRUSTED_RECEIVE 0x5c /* TRUSTED RECEIVE */ +#define ATA_TRUSTED_RECEIVE_DMA 0x5d /* TRUSTED RECEIVE DMA */ +#define ATA_TRUSTED_SEND 0x5e /* TRUSTED SEND */ +#define ATA_TRUSTED_SEND_DMA 0x5f /* TRUSTED SEND DMA */ +#define ATA_READ_FPDMA_QUEUED 0x60 /* read DMA NCQ */ +#define ATA_WRITE_FPDMA_QUEUED 0x61 /* write DMA NCQ */ +#define ATA_NCQ_NON_DATA 0x63 /* NCQ non-data command */ +#define ATA_ABORT_NCQ_QUEUE 0x00 /* abort NCQ queue */ +#define ATA_DEADLINE_HANDLING 0x01 /* deadline handling */ +#define ATA_SET_FEATURES 0x05 /* set features */ +#define ATA_ZERO_EXT 0x06 /* zero ext */ +#define ATA_NCQ_ZAC_MGMT_OUT 0x07 /* NCQ ZAC mgmt out no data */ +#define ATA_SEND_FPDMA_QUEUED 0x64 /* send DMA NCQ */ +#define ATA_SFPDMA_DSM 0x00 /* Data set management */ +#define ATA_SFPDMA_DSM_TRIM 0x01 /* Set trim bit in auxiliary */ +#define ATA_SFPDMA_HYBRID_EVICT 0x01 /* Hybrid Evict */ +#define ATA_SFPDMA_WLDMA 0x02 /* Write Log DMA EXT */ +#define ATA_SFPDMA_ZAC_MGMT_OUT 0x03 /* NCQ ZAC mgmt out w/data */ +#define ATA_RECV_FPDMA_QUEUED 0x65 /* receive DMA NCQ */ +#define ATA_RFPDMA_RL_DMA_EXT 0x00 /* Read Log DMA EXT */ +#define ATA_RFPDMA_ZAC_MGMT_IN 0x02 /* NCQ ZAC mgmt in w/data */ +#define ATA_SEP_ATTN 0x67 /* SEP request */ +#define ATA_SEEK 0x70 /* seek */ +#define ATA_AMAX_ADDR 0x78 /* Accessible Max Address */ +#define ATA_AMAX_ADDR_GET 0x00 /* GET NATIVE MAX ADDRESS EXT */ +#define ATA_AMAX_ADDR_SET 0x01 /* SET ACCESSIBLE MAX ADDRESS EXT */ +#define ATA_AMAX_ADDR_FREEZE 0x02 /* FREEZE ACCESSIBLE MAX ADDRESS EXT */ +#define ATA_ZAC_MANAGEMENT_OUT 0x9f /* ZAC management out */ +#define ATA_ZM_CLOSE_ZONE 0x01 /* close zone */ +#define ATA_ZM_FINISH_ZONE 0x02 /* finish zone */ +#define ATA_ZM_OPEN_ZONE 0x03 /* open zone */ +#define ATA_ZM_RWP 0x04 /* reset write pointer */ +#define ATA_DOWNLOAD_MICROCODE 0x92 /* DOWNLOAD MICROCODE */ +#define ATA_DOWNLOAD_MICROCODE_DMA 0x93 /* DOWNLOAD MICROCODE DMA */ +#define ATA_PACKET_CMD 0xa0 /* packet command */ +#define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/ +#define ATA_SERVICE 0xa2 /* service command */ +#define ATA_SMART_CMD 0xb0 /* SMART command */ +#define ATA_SANITIZE 0xb4 /* sanitize device */ +#define ATA_CFA_ERASE 0xc0 /* CFA erase */ +#define ATA_READ_MUL 0xc4 /* read multi */ +#define ATA_WRITE_MUL 0xc5 /* write multi */ +#define ATA_SET_MULTI 0xc6 /* set multi size */ +#define ATA_READ_DMA_QUEUED 0xc7 /* read DMA QUEUED */ +#define ATA_READ_DMA 0xc8 /* read DMA */ +#define ATA_WRITE_DMA 0xca /* write DMA */ +#define ATA_WRITE_DMA_QUEUED 0xcc /* write DMA QUEUED */ +#define ATA_WRITE_MUL_FUA48 0xce +#define ATA_STANDBY_IMMEDIATE 0xe0 /* standby immediate */ +#define ATA_IDLE_IMMEDIATE 0xe1 /* idle immediate */ +#define ATA_STANDBY_CMD 0xe2 /* standby */ +#define ATA_IDLE_CMD 0xe3 /* idle */ +#define ATA_READ_BUFFER 0xe4 /* read buffer */ +#define ATA_READ_PM 0xe4 /* read portmultiplier */ +#define ATA_CHECK_POWER_MODE 0xe5 /* device power mode */ +#define ATA_SLEEP 0xe6 /* sleep */ +#define ATA_FLUSHCACHE 0xe7 /* flush cache to disk */ +#define ATA_WRITE_BUFFER 0xe8 /* write buffer */ +#define ATA_WRITE_PM 0xe8 /* write portmultiplier */ +#define ATA_READ_BUFFER_DMA 0xe9 /* read buffer DMA */ +#define ATA_FLUSHCACHE48 0xea /* flush cache to disk */ +#define ATA_WRITE_BUFFER_DMA 0xeb /* write buffer DMA */ +#define ATA_ATA_IDENTIFY 0xec /* get ATA params */ +#define ATA_SETFEATURES 0xef /* features command */ +#define ATA_SF_ENAB_WCACHE 0x02 /* enable write cache */ +#define ATA_SF_DIS_WCACHE 0x82 /* disable write cache */ +#define ATA_SF_SETXFER 0x03 /* set transfer mode */ +#define ATA_SF_APM 0x05 /* Enable APM feature set */ +#define ATA_SF_ENAB_PUIS 0x06 /* enable PUIS */ +#define ATA_SF_DIS_PUIS 0x86 /* disable PUIS */ +#define ATA_SF_PUIS_SPINUP 0x07 /* PUIS spin-up */ +#define ATA_SF_WRV 0x0b /* Enable Write-Read-Verify */ +#define ATA_SF_DLC 0x0c /* Enable device life control */ +#define ATA_SF_SATA 0x10 /* Enable use of SATA feature */ +#define ATA_SF_FFC 0x41 /* Free-fall Control */ +#define ATA_SF_MHIST 0x43 /* Set Max Host Sect. Times */ +#define ATA_SF_RATE 0x45 /* Set Rate Basis */ +#define ATA_SF_EPC 0x4A /* Extended Power Conditions */ +#define ATA_SF_ENAB_RCACHE 0xaa /* enable readahead cache */ +#define ATA_SF_DIS_RCACHE 0x55 /* disable readahead cache */ +#define ATA_SF_ENAB_RELIRQ 0x5d /* enable release interrupt */ +#define ATA_SF_DIS_RELIRQ 0xdd /* disable release interrupt */ +#define ATA_SF_ENAB_SRVIRQ 0x5e /* enable service interrupt */ +#define ATA_SF_DIS_SRVIRQ 0xde /* disable service interrupt */ +#define ATA_SF_LPSAERC 0x62 /* Long Phys Sect Align ErrRep*/ +#define ATA_SF_DSN 0x63 /* Device Stats Notification */ +#define ATA_CHECK_POWER_MODE 0xe5 /* Check Power Mode */ +#define ATA_SECURITY_SET_PASSWORD 0xf1 /* set drive password */ +#define ATA_SECURITY_UNLOCK 0xf2 /* unlock drive using passwd */ +#define ATA_SECURITY_ERASE_PREPARE 0xf3 /* prepare to erase drive */ +#define ATA_SECURITY_ERASE_UNIT 0xf4 /* erase all blocks on drive */ +#define ATA_SECURITY_FREEZE_LOCK 0xf5 /* freeze security config */ +#define ATA_SECURITY_DISABLE_PASSWORD 0xf6 /* disable drive password */ +#define ATA_READ_NATIVE_MAX_ADDRESS 0xf8 /* read native max address */ +#define ATA_SET_MAX_ADDRESS 0xf9 /* set max address */ + + +/* ATAPI commands */ +#define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */ +#define ATAPI_REZERO 0x01 /* rewind */ +#define ATAPI_REQUEST_SENSE 0x03 /* get sense data */ +#define ATAPI_FORMAT 0x04 /* format unit */ +#define ATAPI_READ 0x08 /* read data */ +#define ATAPI_WRITE 0x0a /* write data */ +#define ATAPI_WEOF 0x10 /* write filemark */ +#define ATAPI_WF_WRITE 0x01 +#define ATAPI_SPACE 0x11 /* space command */ +#define ATAPI_SP_FM 0x01 +#define ATAPI_SP_EOD 0x03 +#define ATAPI_INQUIRY 0x12 /* get inquiry data */ +#define ATAPI_MODE_SELECT 0x15 /* mode select */ +#define ATAPI_ERASE 0x19 /* erase */ +#define ATAPI_MODE_SENSE 0x1a /* mode sense */ +#define ATAPI_START_STOP 0x1b /* start/stop unit */ +#define ATAPI_SS_LOAD 0x01 +#define ATAPI_SS_RETENSION 0x02 +#define ATAPI_SS_EJECT 0x04 +#define ATAPI_PREVENT_ALLOW 0x1e /* media removal */ +#define ATAPI_READ_FORMAT_CAPACITIES 0x23 /* get format capacities */ +#define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */ +#define ATAPI_READ_BIG 0x28 /* read data */ +#define ATAPI_WRITE_BIG 0x2a /* write data */ +#define ATAPI_LOCATE 0x2b /* locate to position */ +#define ATAPI_READ_POSITION 0x34 /* read position */ +#define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */ +#define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */ +#define ATAPI_READ_BUFFER 0x3c /* read device buffer */ +#define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */ +#define ATAPI_READ_TOC 0x43 /* get table of contents */ +#define ATAPI_PLAY_10 0x45 /* play by lba */ +#define ATAPI_PLAY_MSF 0x47 /* play by MSF address */ +#define ATAPI_PLAY_TRACK 0x48 /* play by track number */ +#define ATAPI_PAUSE 0x4b /* pause audio operation */ +#define ATAPI_READ_DISK_INFO 0x51 /* get disk info structure */ +#define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */ +#define ATAPI_RESERVE_TRACK 0x53 /* reserve track */ +#define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */ +#define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */ +#define ATAPI_REPAIR_TRACK 0x58 /* repair track */ +#define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */ +#define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */ +#define ATAPI_CLOSE_TRACK 0x5b /* close track/session */ +#define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */ +#define ATAPI_SEND_CUE_SHEET 0x5d /* send CUE sheet */ +#define ATAPI_SERVICE_ACTION_IN 0x96 /* get service data */ +#define ATAPI_BLANK 0xa1 /* blank the media */ +#define ATAPI_SEND_KEY 0xa3 /* send DVD key structure */ +#define ATAPI_REPORT_KEY 0xa4 /* get DVD key structure */ +#define ATAPI_PLAY_12 0xa5 /* play by lba */ +#define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */ +#define ATAPI_READ_STRUCTURE 0xad /* get DVD structure */ +#define ATAPI_PLAY_CD 0xb4 /* universal play command */ +#define ATAPI_SET_SPEED 0xbb /* set drive speed */ +#define ATAPI_MECH_STATUS 0xbd /* get changer status */ +#define ATAPI_READ_CD 0xbe /* read data */ +#define ATAPI_POLL_DSC 0xff /* poll DSC status bit */ + + +struct ata_ioc_devices { + int channel; + char name[2][32]; + struct ata_params params[2]; +}; + +/* pr channel ATA ioctl calls */ +#define IOCATAGMAXCHANNEL _IOR('a', 1, int) +#define IOCATAREINIT _IOW('a', 2, int) +#define IOCATAATTACH _IOW('a', 3, int) +#define IOCATADETACH _IOW('a', 4, int) +#define IOCATADEVICES _IOWR('a', 5, struct ata_ioc_devices) + +/* ATAPI request sense structure */ +struct atapi_sense { + u_int8_t error; /* current or deferred errors */ +#define ATA_SENSE_VALID 0x80 + + u_int8_t segment; /* segment number */ + u_int8_t key; /* sense key */ +#define ATA_SENSE_KEY_MASK 0x0f /* sense key mask */ +#define ATA_SENSE_NO_SENSE 0x00 /* no specific sense key info */ +#define ATA_SENSE_RECOVERED_ERROR 0x01 /* command OK, data recovered */ +#define ATA_SENSE_NOT_READY 0x02 /* no access to drive */ +#define ATA_SENSE_MEDIUM_ERROR 0x03 /* non-recovered data error */ +#define ATA_SENSE_HARDWARE_ERROR 0x04 /* non-recoverable HW failure */ +#define ATA_SENSE_ILLEGAL_REQUEST 0x05 /* invalid command param(s) */ +#define ATA_SENSE_UNIT_ATTENTION 0x06 /* media changed */ +#define ATA_SENSE_DATA_PROTECT 0x07 /* write protect */ +#define ATA_SENSE_BLANK_CHECK 0x08 /* blank check */ +#define ATA_SENSE_VENDOR_SPECIFIC 0x09 /* vendor specific skey */ +#define ATA_SENSE_COPY_ABORTED 0x0a /* copy aborted */ +#define ATA_SENSE_ABORTED_COMMAND 0x0b /* command aborted, try again */ +#define ATA_SENSE_EQUAL 0x0c /* equal */ +#define ATA_SENSE_VOLUME_OVERFLOW 0x0d /* volume overflow */ +#define ATA_SENSE_MISCOMPARE 0x0e /* data dont match the medium */ +#define ATA_SENSE_RESERVED 0x0f +#define ATA_SENSE_ILI 0x20; +#define ATA_SENSE_EOM 0x40; +#define ATA_SENSE_FILEMARK 0x80; + + u_int32_t cmd_info; /* cmd information */ + u_int8_t sense_length; /* additional sense len (n-7) */ + u_int32_t cmd_specific_info; /* additional cmd spec info */ + u_int8_t asc; /* additional sense code */ + u_int8_t ascq; /* additional sense code qual */ + u_int8_t replaceable_unit_code; /* replaceable unit code */ + u_int8_t specific; /* sense key specific */ +#define ATA_SENSE_SPEC_VALID 0x80 +#define ATA_SENSE_SPEC_MASK 0x7f + + u_int8_t specific1; /* sense key specific */ + u_int8_t specific2; /* sense key specific */ +} __packed; + +/* + * SET FEATURES subcommands + */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * These values go in the LBA 3:0. + */ +#define ATA_SF_EPC_RESTORE 0x00 /* Restore Power Condition Settings */ +#define ATA_SF_EPC_GOTO 0x01 /* Go To Power Condition */ +#define ATA_SF_EPC_SET_TIMER 0x02 /* Set Power Condition Timer */ +#define ATA_SF_EPC_SET_STATE 0x03 /* Set Power Condition State */ +#define ATA_SF_EPC_ENABLE 0x04 /* Enable the EPC feature set */ +#define ATA_SF_EPC_DISABLE 0x05 /* Disable the EPC feature set */ +#define ATA_SF_EPC_SET_SOURCE 0x06 /* Set EPC Power Source */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Power Condition ID field + * These values go in the count register. + */ +#define ATA_EPC_STANDBY_Z 0x00 /* Substate of PM2:Standby */ +#define ATA_EPC_STANDBY_Y 0x01 /* Substate of PM2:Standby */ +#define ATA_EPC_IDLE_A 0x81 /* Substate of PM1:Idle */ +#define ATA_EPC_IDLE_B 0x82 /* Substate of PM1:Idle */ +#define ATA_EPC_IDLE_C 0x83 /* Substate of PM1:Idle */ +#define ATA_EPC_ALL 0xff /* All supported power conditions */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Restore Power Conditions Settings subcommand + * These values go in the LBA register. + */ +#define ATA_SF_EPC_RST_DFLT 0x40 /* 1=Rst from Default, 0= from Saved */ +#define ATA_SF_EPC_RST_SAVE 0x10 /* 1=Save on completion */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Got To Power Condition subcommand + * These values go in the LBA register. + */ +#define ATA_SF_EPC_GOTO_DELAY 0x02000000 /* Delayed entry bit */ +#define ATA_SF_EPC_GOTO_HOLD 0x01000000 /* Hold Power Cond bit */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Set Power Condition Timer subcommand + * These values go in the LBA register. + */ +#define ATA_SF_EPC_TIMER_MASK 0x00ffff00 /* Timer field */ +#define ATA_SF_EPC_TIMER_SHIFT 8 +#define ATA_SF_EPC_TIMER_SEC 0x00000080 /* Timer units, 1=sec, 0=.1s */ +#define ATA_SF_EPC_TIMER_EN 0x00000020 /* Enable/disable cond. */ +#define ATA_SF_EPC_TIMER_SAVE 0x00000010 /* Save settings on comp. */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Set Power Condition State subcommand + * These values go in the LBA register. + */ +#define ATA_SF_EPC_SETCON_EN 0x00000020 /* Enable power cond. */ +#define ATA_SF_EPC_SETCON_SAVE 0x00000010 /* Save settings on comp */ + +/* + * SET FEATURES command + * Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A) + * Set EPC Power Source subcommand + * These values go in the count register. + */ +#define ATA_SF_EPC_SRC_UNKNOWN 0x0000 /* Unknown source */ +#define ATA_SF_EPC_SRC_BAT 0x0001 /* battery source */ +#define ATA_SF_EPC_SRC_NOT_BAT 0x0002 /* not battery source */ + +#define ATA_LOG_DIRECTORY 0x00 /* Directory of all logs */ +#define ATA_POWER_COND_LOG 0x08 /* Power Conditions Log */ +#define ATA_PCL_IDLE 0x00 /* Idle Power Conditions Page */ +#define ATA_PCL_STANDBY 0x01 /* Standby Power Conditions Page */ +#define ATA_IDENTIFY_DATA_LOG 0x30 /* Identify Device Data Log */ +#define ATA_IDL_PAGE_LIST 0x00 /* List of supported pages */ +#define ATA_IDL_IDENTIFY_DATA 0x01 /* Copy of Identify Device data */ +#define ATA_IDL_CAPACITY 0x02 /* Capacity */ +#define ATA_IDL_SUP_CAP 0x03 /* Supported Capabilities */ +#define ATA_IDL_CUR_SETTINGS 0x04 /* Current Settings */ +#define ATA_IDL_ATA_STRINGS 0x05 /* ATA Strings */ +#define ATA_IDL_SECURITY 0x06 /* Security */ +#define ATA_IDL_PARALLEL_ATA 0x07 /* Parallel ATA */ +#define ATA_IDL_SERIAL_ATA 0x08 /* Serial ATA */ +#define ATA_IDL_ZDI 0x09 /* Zoned Device Information */ + +struct ata_gp_log_dir { + uint8_t header[2]; +#define ATA_GP_LOG_DIR_VERSION 0x0001 + uint8_t num_pages[255*2]; /* Number of log pages at address */ +}; + +/* + * ATA Power Conditions log descriptor + */ +struct ata_power_cond_log_desc { + uint8_t reserved1; + uint8_t flags; +#define ATA_PCL_COND_SUPPORTED 0x80 +#define ATA_PCL_COND_SAVEABLE 0x40 +#define ATA_PCL_COND_CHANGEABLE 0x20 +#define ATA_PCL_DEFAULT_TIMER_EN 0x10 +#define ATA_PCL_SAVED_TIMER_EN 0x08 +#define ATA_PCL_CURRENT_TIMER_EN 0x04 +#define ATA_PCL_HOLD_PC_NOT_SUP 0x02 + uint8_t reserved2[2]; + uint8_t default_timer[4]; + uint8_t saved_timer[4]; + uint8_t current_timer[4]; + uint8_t nom_time_to_active[4]; + uint8_t min_timer[4]; + uint8_t max_timer[4]; + uint8_t num_transitions_to_pc[4]; + uint8_t hours_in_pc[4]; + uint8_t reserved3[28]; +}; + +/* + * ATA Power Conditions Log (0x08), Idle power conditions page (0x00) + */ +struct ata_power_cond_log_idle { + struct ata_power_cond_log_desc idle_a_desc; + struct ata_power_cond_log_desc idle_b_desc; + struct ata_power_cond_log_desc idle_c_desc; + uint8_t reserved[320]; +}; + +/* + * ATA Power Conditions Log (0x08), Standby power conditions page (0x01) + */ +struct ata_power_cond_log_standby { + uint8_t reserved[384]; + struct ata_power_cond_log_desc standby_y_desc; + struct ata_power_cond_log_desc standby_z_desc; +}; + +/* + * ATA IDENTIFY DEVICE data log (0x30) page 0x00 + * List of Supported IDENTIFY DEVICE data pages. + */ +struct ata_identify_log_pages { + uint8_t header[8]; +#define ATA_IDLOG_REVISION 0x0000000000000001 + uint8_t entry_count; + uint8_t entries[503]; +}; + +/* + * ATA IDENTIFY DEVICE data log (0x30) + * Capacity (Page 0x02). + */ +struct ata_identify_log_capacity { + uint8_t header[8]; +#define ATA_CAP_HEADER_VALID 0x8000000000000000 +#define ATA_CAP_PAGE_NUM_MASK 0x0000000000ff0000 +#define ATA_CAP_PAGE_NUM_SHIFT 16 +#define ATA_CAP_REV_MASK 0x00000000000000ff + uint8_t capacity[8]; +#define ATA_CAP_CAPACITY_VALID 0x8000000000000000 +#define ATA_CAP_ACCESSIBLE_CAP 0x0000ffffffffffff + uint8_t phys_logical_sect_size[8]; +#define ATA_CAP_PL_VALID 0x8000000000000000 +#define ATA_CAP_LTOP_REL_SUP 0x4000000000000000 +#define ATA_CAP_LOG_SECT_SUP 0x2000000000000000 +#define ATA_CAP_ALIGN_ERR_MASK 0x0000000000300000 +#define ATA_CAP_LTOP_MASK 0x00000000000f0000 +#define ATA_CAP_LOG_SECT_OFF 0x000000000000ffff + uint8_t logical_sect_size[8]; +#define ATA_CAP_LOG_SECT_VALID 0x8000000000000000 +#define ATA_CAP_LOG_SECT_SIZE 0x00000000ffffffff + uint8_t nominal_buffer_size[8]; +#define ATA_CAP_NOM_BUF_VALID 0x8000000000000000 +#define ATA_CAP_NOM_BUF_SIZE 0x7fffffffffffffff + uint8_t reserved[472]; +}; + +/* + * ATA IDENTIFY DEVICE data log (0x30) + * Supported Capabilities (Page 0x03). + */ + +struct ata_identify_log_sup_cap { + uint8_t header[8]; +#define ATA_SUP_CAP_HEADER_VALID 0x8000000000000000 +#define ATA_SUP_CAP_PAGE_NUM_MASK 0x0000000000ff0000 +#define ATA_SUP_CAP_PAGE_NUM_SHIFT 16 +#define ATA_SUP_CAP_REV_MASK 0x00000000000000ff + uint8_t sup_cap[8]; +#define ATA_SUP_CAP_VALID 0x8000000000000000 +#define ATA_SC_SET_SECT_CONFIG_SUP 0x0002000000000000 /* Set Sect Conf*/ +#define ATA_SC_ZERO_EXT_SUP 0x0001000000000000 /* Zero EXT */ +#define ATA_SC_SUCC_NCQ_SENSE_SUP 0x0000800000000000 /* Succ. NCQ Sns */ +#define ATA_SC_DLC_SUP 0x0000400000000000 /* DLC */ +#define ATA_SC_RQSN_DEV_FAULT_SUP 0x0000200000000000 /* Req Sns Dev Flt*/ +#define ATA_SC_DSN_SUP 0x0000100000000000 /* DSN */ +#define ATA_SC_LP_STANDBY_SUP 0x0000080000000000 /* LP Standby */ +#define ATA_SC_SET_EPC_PS_SUP 0x0000040000000000 /* Set EPC PS */ +#define ATA_SC_AMAX_ADDR_SUP 0x0000020000000000 /* AMAX Addr */ +#define ATA_SC_DRAT_SUP 0x0000008000000000 /* DRAT */ +#define ATA_SC_LPS_MISALGN_SUP 0x0000004000000000 /* LPS Misalign */ +#define ATA_SC_RB_DMA_SUP 0x0000001000000000 /* Read Buf DMA */ +#define ATA_SC_WB_DMA_SUP 0x0000000800000000 /* Write Buf DMA */ +#define ATA_SC_DNLD_MC_DMA_SUP 0x0000000200000000 /* DL MCode DMA */ +#define ATA_SC_28BIT_SUP 0x0000000100000000 /* 28-bit */ +#define ATA_SC_RZAT_SUP 0x0000000080000000 /* RZAT */ +#define ATA_SC_NOP_SUP 0x0000000020000000 /* NOP */ +#define ATA_SC_READ_BUFFER_SUP 0x0000000010000000 /* Read Buffer */ +#define ATA_SC_WRITE_BUFFER_SUP 0x0000000008000000 /* Write Buffer */ +#define ATA_SC_READ_LOOK_AHEAD_SUP 0x0000000002000000 /* Read Look-Ahead*/ +#define ATA_SC_VOLATILE_WC_SUP 0x0000000001000000 /* Volatile WC */ +#define ATA_SC_SMART_SUP 0x0000000000800000 /* SMART */ +#define ATA_SC_FLUSH_CACHE_EXT_SUP 0x0000000000400000 /* Flush Cache Ext */ +#define ATA_SC_48BIT_SUP 0x0000000000100000 /* 48-Bit */ +#define ATA_SC_SPINUP_SUP 0x0000000000040000 /* Spin-Up */ +#define ATA_SC_PUIS_SUP 0x0000000000020000 /* PUIS */ +#define ATA_SC_APM_SUP 0x0000000000010000 /* APM */ +#define ATA_SC_DL_MICROCODE_SUP 0x0000000000004000 /* DL Microcode */ +#define ATA_SC_UNLOAD_SUP 0x0000000000002000 /* Unload */ +#define ATA_SC_WRITE_FUA_EXT_SUP 0x0000000000001000 /* Write FUA EXT */ +#define ATA_SC_GPL_SUP 0x0000000000000800 /* GPL */ +#define ATA_SC_STREAMING_SUP 0x0000000000000400 /* Streaming */ +#define ATA_SC_SMART_SELFTEST_SUP 0x0000000000000100 /* SMART self-test */ +#define ATA_SC_SMART_ERR_LOG_SUP 0x0000000000000080 /* SMART Err Log */ +#define ATA_SC_EPC_SUP 0x0000000000000040 /* EPC */ +#define ATA_SC_SENSE_SUP 0x0000000000000020 /* Sense data */ +#define ATA_SC_FREEFALL_SUP 0x0000000000000010 /* Free-Fall */ +#define ATA_SC_DM_MODE3_SUP 0x0000000000000008 /* DM Mode 3 */ +#define ATA_SC_GPL_DMA_SUP 0x0000000000000004 /* GPL DMA */ +#define ATA_SC_WRITE_UNCOR_SUP 0x0000000000000002 /* Write uncorr. */ +#define ATA_SC_WRV_SUP 0x0000000000000001 /* WRV */ + uint8_t download_code_cap[8]; +#define ATA_DL_CODE_VALID 0x8000000000000000 +#define ATA_DLC_DM_OFFSETS_DEFER_SUP 0x0000000400000000 +#define ATA_DLC_DM_IMMED_SUP 0x0000000200000000 +#define ATA_DLC_DM_OFF_IMMED_SUP 0x0000000100000000 +#define ATA_DLC_DM_MAX_XFER_SIZE_MASK 0x00000000ffff0000 +#define ATA_DLC_DM_MAX_XFER_SIZE_SHIFT 16 +#define ATA_DLC_DM_MIN_XFER_SIZE_MASK 0x000000000000ffff + uint8_t nom_media_rotation_rate[8]; +#define ATA_NOM_MEDIA_ROTATION_VALID 0x8000000000000000 +#define ATA_ROTATION_MASK 0x000000000000ffff + uint8_t form_factor[8]; +#define ATA_FORM_FACTOR_VALID 0x8000000000000000 +#define ATA_FF_MASK 0x000000000000000f +#define ATA_FF_NOT_REPORTED 0x0000000000000000 /* Not reported */ +#define ATA_FF_525_IN 0x0000000000000001 /* 5.25 inch */ +#define ATA_FF_35_IN 0x0000000000000002 /* 3.5 inch */ +#define ATA_FF_25_IN 0x0000000000000003 /* 2.5 inch */ +#define ATA_FF_18_IN 0x0000000000000004 /* 1.8 inch */ +#define ATA_FF_LT_18_IN 0x0000000000000005 /* < 1.8 inch */ +#define ATA_FF_MSATA 0x0000000000000006 /* mSATA */ +#define ATA_FF_M2 0x0000000000000007 /* M.2 */ +#define ATA_FF_MICROSSD 0x0000000000000008 /* MicroSSD */ +#define ATA_FF_CFAST 0x0000000000000009 /* CFast */ + uint8_t wrv_sec_cnt_mode3[8]; +#define ATA_WRV_MODE3_VALID 0x8000000000000000 +#define ATA_WRV_MODE3_COUNT 0x00000000ffffffff + uint8_t wrv_sec_cnt_mode2[8]; +#define ATA_WRV_MODE2_VALID 0x8000000000000000 +#define ATA_WRV_MODE2_COUNT 0x00000000ffffffff + uint8_t wwn[16]; + /* XXX KDM need to figure out how to handle 128-bit fields */ + uint8_t dsm[8]; +#define ATA_DSM_VALID 0x8000000000000000 +#define ATA_LB_MARKUP_SUP 0x000000000000ff00 +#define ATA_TRIM_SUP 0x0000000000000001 + uint8_t util_per_unit_time[16]; + /* XXX KDM need to figure out how to handle 128-bit fields */ + uint8_t util_usage_rate_sup[8]; +#define ATA_UTIL_USAGE_RATE_VALID 0x8000000000000000 +#define ATA_SETTING_RATE_SUP 0x0000000000800000 +#define ATA_SINCE_POWERON_SUP 0x0000000000000100 +#define ATA_POH_RATE_SUP 0x0000000000000010 +#define ATA_DATE_TIME_RATE_SUP 0x0000000000000001 + uint8_t zoned_cap[8]; +#define ATA_ZONED_VALID 0x8000000000000000 +#define ATA_ZONED_MASK 0x0000000000000003 + uint8_t sup_zac_cap[8]; +#define ATA_SUP_ZAC_CAP_VALID 0x8000000000000000 +#define ATA_ND_RWP_SUP 0x0000000000000010 /* Reset Write Ptr*/ +#define ATA_ND_FINISH_ZONE_SUP 0x0000000000000008 /* Finish Zone */ +#define ATA_ND_CLOSE_ZONE_SUP 0x0000000000000004 /* Close Zone */ +#define ATA_ND_OPEN_ZONE_SUP 0x0000000000000002 /* Open Zone */ +#define ATA_REPORT_ZONES_SUP 0x0000000000000001 /* Report Zones */ + uint8_t reserved[392]; +}; + +/* + * ATA Identify Device Data Log Zoned Device Information Page (0x09). + * Current as of ZAC r04a, August 25, 2015. + */ +struct ata_zoned_info_log { + uint8_t header[8]; +#define ATA_ZDI_HEADER_VALID 0x8000000000000000 +#define ATA_ZDI_PAGE_NUM_MASK 0x0000000000ff0000 +#define ATA_ZDI_PAGE_NUM_SHIFT 16 +#define ATA_ZDI_REV_MASK 0x00000000000000ff + uint8_t zoned_cap[8]; +#define ATA_ZDI_CAP_VALID 0x8000000000000000 +#define ATA_ZDI_CAP_URSWRZ 0x0000000000000001 + uint8_t zoned_settings[8]; +#define ATA_ZDI_SETTINGS_VALID 0x8000000000000000 + uint8_t optimal_seq_zones[8]; +#define ATA_ZDI_OPT_SEQ_VALID 0x8000000000000000 +#define ATA_ZDI_OPT_SEQ_MASK 0x00000000ffffffff + uint8_t optimal_nonseq_zones[8]; +#define ATA_ZDI_OPT_NS_VALID 0x8000000000000000 +#define ATA_ZDI_OPT_NS_MASK 0x00000000ffffffff + uint8_t max_seq_req_zones[8]; +#define ATA_ZDI_MAX_SEQ_VALID 0x8000000000000000 +#define ATA_ZDI_MAX_SEQ_MASK 0x00000000ffffffff + uint8_t version_info[8]; +#define ATA_ZDI_VER_VALID 0x8000000000000000 +#define ATA_ZDI_VER_ZAC_SUP 0x0100000000000000 +#define ATA_ZDI_VER_ZAC_MASK 0x00000000000000ff + uint8_t reserved[456]; +}; + +struct ata_ioc_request { + union { + struct { + u_int8_t command; + u_int8_t feature; + u_int64_t lba; + u_int16_t count; + } ata; + struct { + char ccb[16]; + struct atapi_sense sense; + } atapi; + } u; + caddr_t data; + int count; + int flags; +#define ATA_CMD_CONTROL 0x01 +#define ATA_CMD_READ 0x02 +#define ATA_CMD_WRITE 0x04 +#define ATA_CMD_ATAPI 0x08 + + int timeout; + int error; +}; + +struct ata_security_password { + u_int16_t ctrl; +#define ATA_SECURITY_PASSWORD_USER 0x0000 +#define ATA_SECURITY_PASSWORD_MASTER 0x0001 +#define ATA_SECURITY_ERASE_NORMAL 0x0000 +#define ATA_SECURITY_ERASE_ENHANCED 0x0002 +#define ATA_SECURITY_LEVEL_HIGH 0x0000 +#define ATA_SECURITY_LEVEL_MAXIMUM 0x0100 + + u_int8_t password[32]; + u_int16_t revision; + u_int16_t reserved[238]; +}; + +/* pr device ATA ioctl calls */ +#define IOCATAREQUEST _IOWR('a', 100, struct ata_ioc_request) +#define IOCATAGPARM _IOR('a', 101, struct ata_params) +#define IOCATAGMODE _IOR('a', 102, int) +#define IOCATASMODE _IOW('a', 103, int) + +#define IOCATAGSPINDOWN _IOR('a', 104, int) +#define IOCATASSPINDOWN _IOW('a', 105, int) + + +struct ata_ioc_raid_config { + int lun; + int type; +#define AR_JBOD 0x0001 +#define AR_SPAN 0x0002 +#define AR_RAID0 0x0004 +#define AR_RAID1 0x0008 +#define AR_RAID01 0x0010 +#define AR_RAID3 0x0020 +#define AR_RAID4 0x0040 +#define AR_RAID5 0x0080 + + int interleave; + int status; +#define AR_READY 1 +#define AR_DEGRADED 2 +#define AR_REBUILDING 4 + + int progress; + int total_disks; + int disks[16]; +}; + +struct ata_ioc_raid_status { + int lun; + int type; + int interleave; + int status; + int progress; + int total_disks; + struct { + int state; +#define AR_DISK_ONLINE 0x01 +#define AR_DISK_PRESENT 0x02 +#define AR_DISK_SPARE 0x04 + int lun; + } disks[16]; +}; + +/* ATA RAID ioctl calls */ +#define IOCATARAIDCREATE _IOWR('a', 200, struct ata_ioc_raid_config) +#define IOCATARAIDDELETE _IOW('a', 201, int) +#define IOCATARAIDSTATUS _IOWR('a', 202, struct ata_ioc_raid_status) +#define IOCATARAIDADDSPARE _IOW('a', 203, struct ata_ioc_raid_config) +#define IOCATARAIDREBUILD _IOW('a', 204, int) + +#endif /* _SYS_ATA_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/atomic_common.h b/lib/libc/include/any-freebsd-any/sys/atomic_common.h new file mode 100644 index 000000000000..9aa30fa24a27 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/atomic_common.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_ATOMIC_COMMON_H_ +#define _SYS_ATOMIC_COMMON_H_ + +#ifndef _MACHINE_ATOMIC_H_ +#error do not include this header, use machine/atomic.h +#endif + +#define atomic_load_char(p) (*(volatile u_char *)(p)) +#define atomic_load_short(p) (*(volatile u_short *)(p)) +#define atomic_load_int(p) (*(volatile u_int *)(p)) +#define atomic_load_long(p) (*(volatile u_long *)(p)) +#define atomic_load_ptr(p) (*(volatile uintptr_t*)(p)) +#define atomic_load_8(p) (*(volatile uint8_t *)(p)) +#define atomic_load_16(p) (*(volatile uint16_t *)(p)) +#define atomic_load_32(p) (*(volatile uint32_t *)(p)) +#ifdef _LP64 +#define atomic_load_64(p) (*(volatile uint64_t *)(p)) +#endif + +#define atomic_store_char(p, v) \ + (*(volatile u_char *)(p) = (u_char)(v)) +#define atomic_store_short(p, v) \ + (*(volatile u_short *)(p) = (u_short)(v)) +#define atomic_store_int(p, v) \ + (*(volatile u_int *)(p) = (u_int)(v)) +#define atomic_store_long(p, v) \ + (*(volatile u_long *)(p) = (u_long)(v)) +#define atomic_store_ptr(p, v) \ + (*(uintptr_t *)(p) = (uintptr_t)(v)) +#define atomic_store_8(p, v) \ + (*(volatile uint8_t *)(p) = (uint8_t)(v)) +#define atomic_store_16(p, v) \ + (*(volatile uint16_t *)(p) = (uint16_t)(v)) +#define atomic_store_32(p, v) \ + (*(volatile uint32_t *)(p) = (uint32_t)(v)) +#ifdef _LP64 +#define atomic_store_64(p, v) \ + (*(volatile uint64_t *)(p) = (uint64_t)(v)) +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/auxv.h b/lib/libc/include/any-freebsd-any/sys/auxv.h new file mode 100644 index 000000000000..97616055ecc6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/auxv.h @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017 Michal Meloun + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_AUXV_H_ +#define _SYS_AUXV_H_ + +#include +#include + +__BEGIN_DECLS +int elf_aux_info(int aux, void *buf, int buflen); +__END_DECLS + +#endif /* !_SYS_AUXV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bio.h b/lib/libc/include/any-freebsd-any/sys/bio.h new file mode 100644 index 000000000000..1dab615578ec --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bio.h @@ -0,0 +1,184 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)buf.h 8.9 (Berkeley) 3/30/95 + * $FreeBSD$ + */ + +#ifndef _SYS_BIO_H_ +#define _SYS_BIO_H_ + +#include +#include + +/* bio_cmd */ +#define BIO_READ 0x01 /* Read I/O data */ +#define BIO_WRITE 0x02 /* Write I/O data */ +#define BIO_DELETE 0x03 /* TRIM or free blocks, i.e. mark as unused */ +#define BIO_GETATTR 0x04 /* Get GEOM attributes of object */ +#define BIO_FLUSH 0x05 /* Commit outstanding I/O now */ +#define BIO_CMD0 0x06 /* Available for local hacks */ +#define BIO_CMD1 0x07 /* Available for local hacks */ +#define BIO_CMD2 0x08 /* Available for local hacks */ +#define BIO_ZONE 0x09 /* Zone command */ + +/* bio_flags */ +#define BIO_ERROR 0x01 /* An error occurred processing this bio. */ +#define BIO_DONE 0x02 /* This bio is finished. */ +#define BIO_ONQUEUE 0x04 /* This bio is in a queue & not yet taken. */ +/* + * This bio must be executed after all previous bios in the queue have been + * executed, and before any successive bios can be executed. + */ +#define BIO_ORDERED 0x08 +#define BIO_UNMAPPED 0x10 +#define BIO_TRANSIENT_MAPPING 0x20 +#define BIO_VLIST 0x40 + +#ifdef _KERNEL +struct disk; +struct bio; +struct vm_map; + +/* Empty classifier tag, to prevent further classification. */ +#define BIO_NOTCLASSIFIED (void *)(~0UL) + +typedef void bio_task_t(void *); + +/* + * The bio structure describes an I/O operation in the kernel. + */ +struct bio { + uint16_t bio_cmd; /* I/O operation. */ + uint16_t bio_flags; /* General flags. */ + uint16_t bio_cflags; /* Private use by the consumer. */ + uint16_t bio_pflags; /* Private use by the provider. */ + struct cdev *bio_dev; /* Device to do I/O on. */ + struct disk *bio_disk; /* Valid below geom_disk.c only */ + off_t bio_offset; /* Offset into file. */ + long bio_bcount; /* Valid bytes in buffer. */ + caddr_t bio_data; /* Memory, superblocks, indirect etc. */ + struct vm_page **bio_ma; /* Or unmapped. */ + int bio_ma_offset; /* Offset in the first page of bio_ma. */ + int bio_ma_n; /* Number of pages in bio_ma. */ + int bio_error; /* Errno for BIO_ERROR. */ + long bio_resid; /* Remaining I/O in bytes. */ + void (*bio_done)(struct bio *); + void *bio_driver1; /* Private use by the provider. */ + void *bio_driver2; /* Private use by the provider. */ + void *bio_caller1; /* Private use by the consumer. */ + void *bio_caller2; /* Private use by the consumer. */ + TAILQ_ENTRY(bio) bio_queue; /* Disksort queue. */ + const char *bio_attribute; /* Attribute for BIO_[GS]ETATTR */ + struct disk_zone_args bio_zone;/* Used for BIO_ZONE */ + struct g_consumer *bio_from; /* GEOM linkage */ + struct g_provider *bio_to; /* GEOM linkage */ + off_t bio_length; /* Like bio_bcount */ + off_t bio_completed; /* Inverse of bio_resid */ + u_int bio_children; /* Number of spawned bios */ + u_int bio_inbed; /* Children safely home by now */ + struct bio *bio_parent; /* Pointer to parent */ + struct bintime bio_t0; /* Time request started */ + + bio_task_t *bio_task; /* Task_queue handler */ + void *bio_task_arg; /* Argument to above */ + + void *bio_classifier1; /* Classifier tag. */ + void *bio_classifier2; /* Classifier tag. */ + +#ifdef DIAGNOSTIC + void *_bio_caller1; + void *_bio_caller2; + uint8_t _bio_cflags; +#endif +#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) + struct buf *bio_track_bp; /* Parent buf for tracking */ +#endif + + /* XXX: these go away when bio chaining is introduced */ + daddr_t bio_pblkno; /* physical block number */ +}; + +struct uio; +struct devstat; + +struct bio_queue_head { + TAILQ_HEAD(bio_queue, bio) queue; + off_t last_offset; + struct bio *insert_point; + int total; + int batched; +}; + +extern struct vm_map *bio_transient_map; +extern int bio_transient_maxcnt; + +void biodone(struct bio *bp); +void biofinish(struct bio *bp, struct devstat *stat, int error); +int biowait(struct bio *bp, const char *wchan); + +#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) +void biotrack_buf(struct bio *bp, const char *location); + +static __inline void +biotrack(struct bio *bp, const char *location) +{ + + if (bp->bio_track_bp != NULL) + biotrack_buf(bp, location); +} +#else +static __inline void +biotrack(struct bio *bp __unused, const char *location __unused) +{ +} +#endif + +void bioq_disksort(struct bio_queue_head *ap, struct bio *bp); +struct bio *bioq_first(struct bio_queue_head *head); +struct bio *bioq_takefirst(struct bio_queue_head *head); +void bioq_flush(struct bio_queue_head *head, struct devstat *stp, int error); +void bioq_init(struct bio_queue_head *head); +void bioq_insert_head(struct bio_queue_head *head, struct bio *bp); +void bioq_insert_tail(struct bio_queue_head *head, struct bio *bp); +void bioq_remove(struct bio_queue_head *head, struct bio *bp); + +int physio(struct cdev *dev, struct uio *uio, int ioflag); +#define physread physio +#define physwrite physio + +#endif /* _KERNEL */ + +#endif /* !_SYS_BIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bitset.h b/lib/libc/include/any-freebsd-any/sys/bitset.h new file mode 100644 index 000000000000..3ae66db9cb8a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bitset.h @@ -0,0 +1,255 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_BITSET_H_ +#define _SYS_BITSET_H_ + +#define __bitset_mask(_s, n) \ + (1UL << ((__bitset_words((_s)) == 1) ? \ + (__size_t)(n) : ((n) % _BITSET_BITS))) + +#define __bitset_word(_s, n) \ + ((__bitset_words((_s)) == 1) ? 0 : ((n) / _BITSET_BITS)) + +#define BIT_CLR(_s, n, p) \ + ((p)->__bits[__bitset_word(_s, n)] &= ~__bitset_mask((_s), (n))) + +#define BIT_COPY(_s, f, t) (void)(*(t) = *(f)) + +#define BIT_ISSET(_s, n, p) \ + ((((p)->__bits[__bitset_word(_s, n)] & __bitset_mask((_s), (n))) != 0)) + +#define BIT_SET(_s, n, p) \ + ((p)->__bits[__bitset_word(_s, n)] |= __bitset_mask((_s), (n))) + +#define BIT_ZERO(_s, p) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (p)->__bits[__i] = 0L; \ +} while (0) + +#define BIT_FILL(_s, p) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (p)->__bits[__i] = -1L; \ +} while (0) + +#define BIT_SETOF(_s, n, p) do { \ + BIT_ZERO(_s, p); \ + (p)->__bits[__bitset_word(_s, n)] = __bitset_mask((_s), (n)); \ +} while (0) + +/* Is p empty. */ +#define BIT_EMPTY(_s, p) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if ((p)->__bits[__i]) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Is p full set. */ +#define BIT_ISFULLSET(_s, p) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if ((p)->__bits[__i] != (long)-1) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Is c a subset of p. */ +#define BIT_SUBSET(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] & \ + (p)->__bits[__i]) != \ + (c)->__bits[__i]) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Are there any common bits between b & c? */ +#define BIT_OVERLAP(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] & \ + (p)->__bits[__i]) != 0) \ + break; \ + __i != __bitset_words((_s)); \ +}) + +/* Compare two sets, returns 0 if equal 1 otherwise. */ +#define BIT_CMP(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] != \ + (p)->__bits[__i])) \ + break; \ + __i != __bitset_words((_s)); \ +}) + +#define BIT_OR(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] |= (s)->__bits[__i]; \ +} while (0) + +#define BIT_OR2(_s, d, s1, s2) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\ +} while (0) + +#define BIT_AND(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] &= (s)->__bits[__i]; \ +} while (0) + +#define BIT_AND2(_s, d, s1, s2) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] = (s1)->__bits[__i] & (s2)->__bits[__i];\ +} while (0) + +#define BIT_NAND(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] &= ~(s)->__bits[__i]; \ +} while (0) + +#define BIT_NAND2(_s, d, s1, s2) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] = (s1)->__bits[__i] & ~(s2)->__bits[__i];\ +} while (0) + +#define BIT_XOR(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] ^= (s)->__bits[__i]; \ +} while (0) + +#define BIT_XOR2(_s, d, s1, s2) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] = (s1)->__bits[__i] ^ (s2)->__bits[__i];\ +} while (0) + +#define BIT_CLR_ATOMIC(_s, n, p) \ + atomic_clear_long(&(p)->__bits[__bitset_word(_s, n)], \ + __bitset_mask((_s), n)) + +#define BIT_SET_ATOMIC(_s, n, p) \ + atomic_set_long(&(p)->__bits[__bitset_word(_s, n)], \ + __bitset_mask((_s), n)) + +#define BIT_SET_ATOMIC_ACQ(_s, n, p) \ + atomic_set_acq_long(&(p)->__bits[__bitset_word(_s, n)], \ + __bitset_mask((_s), n)) + +/* Convenience functions catering special cases. */ +#define BIT_AND_ATOMIC(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + atomic_clear_long(&(d)->__bits[__i], \ + ~(s)->__bits[__i]); \ +} while (0) + +#define BIT_OR_ATOMIC(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + atomic_set_long(&(d)->__bits[__i], \ + (s)->__bits[__i]); \ +} while (0) + +#define BIT_COPY_STORE_REL(_s, f, t) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + atomic_store_rel_long(&(t)->__bits[__i], \ + (f)->__bits[__i]); \ +} while (0) + +#define BIT_FFS(_s, p) __extension__ ({ \ + __size_t __i; \ + int __bit; \ + \ + __bit = 0; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) { \ + if ((p)->__bits[__i] != 0) { \ + __bit = ffsl((p)->__bits[__i]); \ + __bit += __i * _BITSET_BITS; \ + break; \ + } \ + } \ + __bit; \ +}) + +#define BIT_FLS(_s, p) __extension__ ({ \ + __size_t __i; \ + int __bit; \ + \ + __bit = 0; \ + for (__i = __bitset_words((_s)); __i > 0; __i--) { \ + if ((p)->__bits[__i - 1] != 0) { \ + __bit = flsl((p)->__bits[__i - 1]); \ + __bit += (__i - 1) * _BITSET_BITS; \ + break; \ + } \ + } \ + __bit; \ +}) + +#define BIT_COUNT(_s, p) __extension__ ({ \ + __size_t __i; \ + int __count; \ + \ + __count = 0; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + __count += __bitcountl((p)->__bits[__i]); \ + __count; \ +}) + +#define BITSET_T_INITIALIZER(x) \ + { .__bits = { x } } + +#define BITSET_FSET(n) \ + [ 0 ... ((n) - 1) ] = (-1L) + +/* + * Dynamically allocate a bitset. + */ +#define BITSET_ALLOC(_s, mt, mf) \ + malloc(__bitset_words(_s) * sizeof(long), mt, (mf)) + +#endif /* !_SYS_BITSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bitstring.h b/lib/libc/include/any-freebsd-any/sys/bitstring.h new file mode 100644 index 000000000000..97b841bbdda6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bitstring.h @@ -0,0 +1,422 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Vixie. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Copyright (c) 2014 Spectra Logic Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ +#ifndef _SYS_BITSTRING_H_ +#define _SYS_BITSTRING_H_ + +#ifdef _KERNEL +#include +#include +#endif + +#include + +typedef unsigned long bitstr_t; + +/*---------------------- Private Implementation Details ----------------------*/ +#define _BITSTR_MASK (~0UL) +#define _BITSTR_BITS (sizeof(bitstr_t) * 8) + +#ifdef roundup2 +#define _bit_roundup2 roundup2 +#else +#define _bit_roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ +#endif + +/* bitstr_t in bit string containing the bit. */ +static inline int +_bit_idx(int _bit) +{ + return (_bit / _BITSTR_BITS); +} + +/* bit number within bitstr_t at _bit_idx(_bit). */ +static inline int +_bit_offset(int _bit) +{ + return (_bit % _BITSTR_BITS); +} + +/* Mask for the bit within its long. */ +static inline bitstr_t +_bit_mask(int _bit) +{ + return (1UL << _bit_offset(_bit)); +} + +static inline bitstr_t +_bit_make_mask(int _start, int _stop) +{ + return ((_BITSTR_MASK << _bit_offset(_start)) & + (_BITSTR_MASK >> (_BITSTR_BITS - _bit_offset(_stop) - 1))); +} + +/*----------------------------- Public Interface -----------------------------*/ +/* Number of bytes allocated for a bit string of nbits bits */ +#define bitstr_size(_nbits) (_bit_roundup2(_nbits, _BITSTR_BITS) / 8) + +/* Allocate a bit string initialized with no bits set. */ +#ifdef _KERNEL +static inline bitstr_t * +bit_alloc(int _nbits, struct malloc_type *type, int flags) +{ + return ((bitstr_t *)malloc(bitstr_size(_nbits), type, flags | M_ZERO)); +} +#else +static inline bitstr_t * +bit_alloc(int _nbits) +{ + return ((bitstr_t *)calloc(bitstr_size(_nbits), 1)); +} +#endif + +/* Allocate a bit string on the stack */ +#define bit_decl(name, nbits) \ + ((name)[bitstr_size(nbits) / sizeof(bitstr_t)]) + +/* Is bit N of bit string set? */ +static inline int +bit_test(const bitstr_t *_bitstr, int _bit) +{ + return ((_bitstr[_bit_idx(_bit)] & _bit_mask(_bit)) != 0); +} + +/* Set bit N of bit string. */ +static inline void +bit_set(bitstr_t *_bitstr, int _bit) +{ + _bitstr[_bit_idx(_bit)] |= _bit_mask(_bit); +} + +/* clear bit N of bit string name */ +static inline void +bit_clear(bitstr_t *_bitstr, int _bit) +{ + _bitstr[_bit_idx(_bit)] &= ~_bit_mask(_bit); +} + +/* Set bits start ... stop inclusive in bit string. */ +static inline void +bit_nset(bitstr_t *_bitstr, int _start, int _stop) +{ + bitstr_t *_stopbitstr; + + _stopbitstr = _bitstr + _bit_idx(_stop); + _bitstr += _bit_idx(_start); + + if (_bitstr == _stopbitstr) { + *_bitstr |= _bit_make_mask(_start, _stop); + } else { + *_bitstr |= _bit_make_mask(_start, _BITSTR_BITS - 1); + while (++_bitstr < _stopbitstr) + *_bitstr = _BITSTR_MASK; + *_stopbitstr |= _bit_make_mask(0, _stop); + } +} + +/* Clear bits start ... stop inclusive in bit string. */ +static inline void +bit_nclear(bitstr_t *_bitstr, int _start, int _stop) +{ + bitstr_t *_stopbitstr; + + _stopbitstr = _bitstr + _bit_idx(_stop); + _bitstr += _bit_idx(_start); + + if (_bitstr == _stopbitstr) { + *_bitstr &= ~_bit_make_mask(_start, _stop); + } else { + *_bitstr &= ~_bit_make_mask(_start, _BITSTR_BITS - 1); + while (++_bitstr < _stopbitstr) + *_bitstr = 0; + *_stopbitstr &= ~_bit_make_mask(0, _stop); + } +} + +/* Find the first bit set in bit string at or after bit start. */ +static inline void +bit_ffs_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) +{ + bitstr_t *_curbitstr; + bitstr_t *_stopbitstr; + bitstr_t _test; + int _value, _offset; + + if (_start >= _nbits) { + *_result = -1; + return; + } + + if (_nbits > 0) { + _curbitstr = _bitstr + _bit_idx(_start); + _stopbitstr = _bitstr + _bit_idx(_nbits - 1); + + _test = *_curbitstr; + if (_bit_offset(_start) != 0) + _test &= _bit_make_mask(_start, _BITSTR_BITS - 1); + while (_test == 0 && _curbitstr < _stopbitstr) + _test = *(++_curbitstr); + + _offset = ffsl(_test); + _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1; + if (_offset == 0 || _value >= _nbits) + _value = -1; + } else { + _value = -1; + } + *_result = _value; +} + +/* Find the first bit clear in bit string at or after bit start. */ +static inline void +bit_ffc_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) +{ + bitstr_t *_curbitstr; + bitstr_t *_stopbitstr; + bitstr_t _test; + int _value, _offset; + + if (_start >= _nbits) { + *_result = -1; + return; + } + + if (_nbits > 0) { + _curbitstr = _bitstr + _bit_idx(_start); + _stopbitstr = _bitstr + _bit_idx(_nbits - 1); + + _test = *_curbitstr; + if (_bit_offset(_start) != 0) + _test |= _bit_make_mask(0, _start - 1); + while (_test == _BITSTR_MASK && _curbitstr < _stopbitstr) + _test = *(++_curbitstr); + + _offset = ffsl(~_test); + _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1; + if (_offset == 0 || _value >= _nbits) + _value = -1; + } else { + _value = -1; + } + *_result = _value; +} + +/* Find the first bit set in bit string. */ +static inline void +bit_ffs(bitstr_t *_bitstr, int _nbits, int *_result) +{ + bit_ffs_at(_bitstr, /*start*/0, _nbits, _result); +} + +/* Find the first bit clear in bit string. */ +static inline void +bit_ffc(bitstr_t *_bitstr, int _nbits, int *_result) +{ + bit_ffc_at(_bitstr, /*start*/0, _nbits, _result); +} + +/* Find contiguous sequence of at least size set bits at or after start */ +static inline void +bit_ffs_area_at(bitstr_t *_bitstr, int _start, int _nbits, int _size, + int *_result) +{ + bitstr_t *_curbitstr; + bitstr_t _test; + int _value, _offset, _logsize, _b; + + if (_start + _size > _nbits || _nbits <= 0) { + *_result = -1; + return; + } + + _logsize = fls(_size - 1); + _value = _start; + _curbitstr = _bitstr + _bit_idx(_start); + _test = ~*_curbitstr; + if (_bit_offset(_start) != 0) + _test |= _bit_make_mask(0, _start - 1); + for (_offset = 0;; _offset -= _BITSTR_BITS, _test = ~*++_curbitstr) { + if (_test != 0) { + /* If leading 0s in _test can finish 0-area, stop. */ + if (_offset + _size < (int)_BITSTR_BITS && + (_test & _bit_make_mask(0, _offset + _size)) == 0) + break; + /* Shrink-left every 0-area in _test by size-1 bits. */ + _b = _logsize; + while ((_test & (_test + 1)) != 0 && _b-- > 0) + _test |= _test >> (((_size - 1) >> _b) + 1) / 2; + /* Find the start of the first 0-area in _test. */ + _offset = (~_test == 0) ? (int)_BITSTR_BITS : + ffsl(~_test) - 1; + _value = (_curbitstr - _bitstr) * _BITSTR_BITS + + _offset; + /* If there's insufficient space left, give up. */ + if (_value + _size > _nbits) { + _value = -1; + break; + } + } + if (_offset + _size <= (int)_BITSTR_BITS) + break; + } + *_result = _value; +} + +/* Find contiguous sequence of at least size cleared bits at or after start */ +static inline void +bit_ffc_area_at(bitstr_t *_bitstr, int _start, int _nbits, int _size, + int *_result) +{ + bitstr_t *_curbitstr; + bitstr_t _test; + int _value, _offset, _logsize, _b; + + if (_start + _size > _nbits || _nbits <= 0) { + *_result = -1; + return; + } + + _logsize = fls(_size - 1); + _value = _start; + _curbitstr = _bitstr + _bit_idx(_start); + _test = *_curbitstr; + if (_bit_offset(_start) != 0) + _test |= _bit_make_mask(0, _start - 1); + for (_offset = 0;; _offset -= _BITSTR_BITS, _test = *++_curbitstr) { + if (_test != 0) { + /* If leading 0s in _test can finish 0-area, stop. */ + if (_offset + _size < (int)_BITSTR_BITS && + (_test & _bit_make_mask(0, _offset + _size)) == 0) + break; + /* Shrink-left every 0-area in _test by size-1 bits. */ + _b = _logsize; + while ((_test & (_test + 1)) != 0 && _b-- > 0) + _test |= _test >> (((_size - 1) >> _b) + 1) / 2; + /* Find the start of the first 0-area in _test. */ + _offset = (~_test == 0) ? (int)_BITSTR_BITS : + ffsl(~_test) - 1; + _value = (_curbitstr - _bitstr) * _BITSTR_BITS + + _offset; + /* If there's insufficient space left, give up. */ + if (_value + _size > _nbits) { + _value = -1; + break; + } + } + if (_offset + _size <= (int)_BITSTR_BITS) + break; + } + *_result = _value; +} + +/* Find contiguous sequence of at least size set bits in bit string */ +static inline void +bit_ffs_area(bitstr_t *_bitstr, int _nbits, int _size, int *_result) +{ + bit_ffs_area_at(_bitstr, /*start*/0, _nbits, _size, _result); +} + +/* Find contiguous sequence of at least size cleared bits in bit string */ +static inline void +bit_ffc_area(bitstr_t *_bitstr, int _nbits, int _size, int *_result) +{ + bit_ffc_area_at(_bitstr, /*start*/0, _nbits, _size, _result); +} + +/* Count the number of bits set in a bitstr of size _nbits at or after _start */ +static inline void +bit_count(bitstr_t *_bitstr, int _start, int _nbits, int *_result) +{ + bitstr_t *_curbitstr, mask; + int _value = 0, curbitstr_len; + + if (_start >= _nbits) + goto out; + + _curbitstr = _bitstr + _bit_idx(_start); + _nbits -= _BITSTR_BITS * _bit_idx(_start); + _start -= _BITSTR_BITS * _bit_idx(_start); + + if (_start > 0) { + curbitstr_len = (int)_BITSTR_BITS < _nbits ? + (int)_BITSTR_BITS : _nbits; + mask = _bit_make_mask(_start, _bit_offset(curbitstr_len - 1)); + _value += __bitcountl(*_curbitstr & mask); + _curbitstr++; + _nbits -= _BITSTR_BITS; + } + while (_nbits >= (int)_BITSTR_BITS) { + _value += __bitcountl(*_curbitstr); + _curbitstr++; + _nbits -= _BITSTR_BITS; + } + if (_nbits > 0) { + mask = _bit_make_mask(0, _bit_offset(_nbits - 1)); + _value += __bitcountl(*_curbitstr & mask); + } + +out: + *_result = _value; +} + +#endif /* _SYS_BITSTRING_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/blist.h b/lib/libc/include/any-freebsd-any/sys/blist.h new file mode 100644 index 000000000000..595d3477aa08 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/blist.h @@ -0,0 +1,106 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1998 Matthew Dillon. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Implements bitmap resource lists. + * + * Usage: + * blist = blist_create(blocks, flags) + * (void) blist_destroy(blist) + * blkno = blist_alloc(blist, count) + * (void) blist_free(blist, blkno, count) + * nblks = blist_fill(blist, blkno, count) + * (void) blist_resize(&blist, count, freeextra, flags) + * + * + * Notes: + * on creation, the entire list is marked reserved. You should + * first blist_free() the sections you want to make available + * for allocation before doing general blist_alloc()/free() + * ops. + * + * SWAPBLK_NONE is returned on failure. This module is typically + * capable of managing up to (2^63) blocks per blist, though + * the memory utilization would be insane if you actually did + * that. Managing something like 512MB worth of 4K blocks + * eats around 32 KBytes of memory. + * + * $FreeBSD$ + + */ + +#ifndef _SYS_BLIST_H_ +#define _SYS_BLIST_H_ + +typedef uint64_t u_daddr_t; /* unsigned disk address */ + +/* + * note: currently use SWAPBLK_NONE as an absolute value rather then + * a flag bit. + */ + +#define SWAPBLK_MASK ((daddr_t)((u_daddr_t)-1 >> 1)) /* mask */ +#define SWAPBLK_NONE ((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */ + +/* + * Both blmeta and bmu_bitmap MUST be a power of 2 in size. + */ + +typedef struct blmeta { + u_daddr_t bm_bitmap; /* bitmap if we are a leaf */ + daddr_t bm_bighint; /* biggest contiguous block hint*/ +} blmeta_t; + +typedef struct blist { + daddr_t bl_blocks; /* area of coverage */ + daddr_t bl_avail; /* # available blocks */ + u_daddr_t bl_radix; /* coverage radix */ + daddr_t bl_cursor; /* next-fit search starts at */ + blmeta_t bl_root[1]; /* root of radix tree */ +} *blist_t; + +#define BLIST_BMAP_RADIX (sizeof(u_daddr_t)*8) +#define BLIST_META_RADIX BLIST_BMAP_RADIX + +#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX + +struct sbuf; + +daddr_t blist_alloc(blist_t blist, daddr_t count); +daddr_t blist_avail(blist_t blist); +blist_t blist_create(daddr_t blocks, int flags); +void blist_destroy(blist_t blist); +daddr_t blist_fill(blist_t bl, daddr_t blkno, daddr_t count); +void blist_free(blist_t blist, daddr_t blkno, daddr_t count); +void blist_print(blist_t blist); +void blist_resize(blist_t *pblist, daddr_t count, int freenew, int flags); +void blist_stats(blist_t blist, struct sbuf *s); + +#endif /* _SYS_BLIST_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/sys/boot.h b/lib/libc/include/any-freebsd-any/sys/boot.h new file mode 100644 index 000000000000..7874d9663736 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/boot.h @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 Roger Pau Monné + * All rights reserved. + * Copyright (c) 2018 Netflix, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_BOOT_H_ +#define _SYS_BOOT_H_ + +#define PATH_KERNEL "/boot/kernel/kernel" + +int boot_env_to_howto(void); +void boot_howto_to_env(int howto); +int boot_parse_arg(char *v); +int boot_parse_cmdline_delim(char *cmdline, const char *delim); +int boot_parse_cmdline(char *cmdline); +int boot_parse_args(int argc, char *argv[]); + +#endif /* !_SYS_BOOT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/buf.h b/lib/libc/include/any-freebsd-any/sys/buf.h new file mode 100644 index 000000000000..209174b4c81a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/buf.h @@ -0,0 +1,586 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)buf.h 8.9 (Berkeley) 3/30/95 + * $FreeBSD$ + */ + +#ifndef _SYS_BUF_H_ +#define _SYS_BUF_H_ + +#include +#include +#include +#include + +struct bio; +struct buf; +struct bufobj; +struct mount; +struct vnode; +struct uio; + +/* + * To avoid including + */ +LIST_HEAD(workhead, worklist); +/* + * These are currently used only by the soft dependency code, hence + * are stored once in a global variable. If other subsystems wanted + * to use these hooks, a pointer to a set of bio_ops could be added + * to each buffer. + */ +extern struct bio_ops { + void (*io_start)(struct buf *); + void (*io_complete)(struct buf *); + void (*io_deallocate)(struct buf *); + int (*io_countdeps)(struct buf *, int); +} bioops; + +struct vm_object; +struct vm_page; + +typedef uint32_t b_xflags_t; + +/* + * The buffer header describes an I/O operation in the kernel. + * + * NOTES: + * b_bufsize, b_bcount. b_bufsize is the allocation size of the + * buffer, either DEV_BSIZE or PAGE_SIZE aligned. b_bcount is the + * originally requested buffer size and can serve as a bounds check + * against EOF. For most, but not all uses, b_bcount == b_bufsize. + * + * b_dirtyoff, b_dirtyend. Buffers support piecemeal, unaligned + * ranges of dirty data that need to be written to backing store. + * The range is typically clipped at b_bcount ( not b_bufsize ). + * + * b_resid. Number of bytes remaining in I/O. After an I/O operation + * completes, b_resid is usually 0 indicating 100% success. + * + * All fields are protected by the buffer lock except those marked: + * V - Protected by owning bufobj lock + * Q - Protected by the buf queue lock + * D - Protected by an dependency implementation specific lock + */ +struct buf { + struct bufobj *b_bufobj; + long b_bcount; + void *b_caller1; + caddr_t b_data; + int b_error; + uint16_t b_iocmd; /* BIO_* bio_cmd from bio.h */ + uint16_t b_ioflags; /* BIO_* bio_flags from bio.h */ + off_t b_iooffset; + long b_resid; + void (*b_iodone)(struct buf *); + void (*b_ckhashcalc)(struct buf *); + uint64_t b_ckhash; /* B_CKHASH requested check-hash */ + daddr_t b_blkno; /* Underlying physical block number. */ + off_t b_offset; /* Offset into file. */ + TAILQ_ENTRY(buf) b_bobufs; /* (V) Buffer's associated vnode. */ + uint32_t b_vflags; /* (V) BV_* flags */ + uint8_t b_qindex; /* (Q) buffer queue index */ + uint8_t b_domain; /* (Q) buf domain this resides in */ + uint16_t b_subqueue; /* (Q) per-cpu q if any */ + uint32_t b_flags; /* B_* flags. */ + b_xflags_t b_xflags; /* extra flags */ + struct lock b_lock; /* Buffer lock */ + long b_bufsize; /* Allocated buffer size. */ + int b_runningbufspace; /* when I/O is running, pipelining */ + int b_kvasize; /* size of kva for buffer */ + int b_dirtyoff; /* Offset in buffer of dirty region. */ + int b_dirtyend; /* Offset of end of dirty region. */ + caddr_t b_kvabase; /* base kva for buffer */ + daddr_t b_lblkno; /* Logical block number. */ + struct vnode *b_vp; /* Device vnode. */ + struct ucred *b_rcred; /* Read credentials reference. */ + struct ucred *b_wcred; /* Write credentials reference. */ + union { + TAILQ_ENTRY(buf) b_freelist; /* (Q) */ + struct { + void (*b_pgiodone)(void *, vm_page_t *, int, int); + int b_pgbefore; + int b_pgafter; + }; + }; + union cluster_info { + TAILQ_HEAD(cluster_list_head, buf) cluster_head; + TAILQ_ENTRY(buf) cluster_entry; + } b_cluster; + struct vm_page *b_pages[btoc(MAXPHYS)]; + int b_npages; + struct workhead b_dep; /* (D) List of filesystem dependencies. */ + void *b_fsprivate1; + void *b_fsprivate2; + void *b_fsprivate3; + +#if defined(FULL_BUF_TRACKING) +#define BUF_TRACKING_SIZE 32 +#define BUF_TRACKING_ENTRY(x) ((x) & (BUF_TRACKING_SIZE - 1)) + const char *b_io_tracking[BUF_TRACKING_SIZE]; + uint32_t b_io_tcnt; +#elif defined(BUF_TRACKING) + const char *b_io_tracking; +#endif +}; + +#define b_object b_bufobj->bo_object + +/* + * These flags are kept in b_flags. + * + * Notes: + * + * B_ASYNC VOP calls on bp's are usually async whether or not + * B_ASYNC is set, but some subsystems, such as NFS, like + * to know what is best for the caller so they can + * optimize the I/O. + * + * B_PAGING Indicates that bp is being used by the paging system or + * some paging system and that the bp is not linked into + * the b_vp's clean/dirty linked lists or ref counts. + * Buffer vp reassignments are illegal in this case. + * + * B_CACHE This may only be set if the buffer is entirely valid. + * The situation where B_DELWRI is set and B_CACHE is + * clear MUST be committed to disk by getblk() so + * B_DELWRI can also be cleared. See the comments for + * getblk() in kern/vfs_bio.c. If B_CACHE is clear, + * the caller is expected to clear BIO_ERROR and B_INVAL, + * set BIO_READ, and initiate an I/O. + * + * The 'entire buffer' is defined to be the range from + * 0 through b_bcount. + * + * B_MALLOC Request that the buffer be allocated from the malloc + * pool, DEV_BSIZE aligned instead of PAGE_SIZE aligned. + * + * B_CLUSTEROK This flag is typically set for B_DELWRI buffers + * by filesystems that allow clustering when the buffer + * is fully dirty and indicates that it may be clustered + * with other adjacent dirty buffers. Note the clustering + * may not be used with the stage 1 data write under NFS + * but may be used for the commit rpc portion. + * + * B_VMIO Indicates that the buffer is tied into an VM object. + * The buffer's data is always PAGE_SIZE aligned even + * if b_bufsize and b_bcount are not. ( b_bufsize is + * always at least DEV_BSIZE aligned, though ). + * + * B_DIRECT Hint that we should attempt to completely free + * the pages underlying the buffer. B_DIRECT is + * sticky until the buffer is released and typically + * only has an effect when B_RELBUF is also set. + * + */ + +#define B_AGE 0x00000001 /* Move to age queue when I/O done. */ +#define B_NEEDCOMMIT 0x00000002 /* Append-write in progress. */ +#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */ +#define B_DIRECT 0x00000008 /* direct I/O flag (pls free vmio) */ +#define B_DEFERRED 0x00000010 /* Skipped over for cleaning */ +#define B_CACHE 0x00000020 /* Bread found us in the cache. */ +#define B_VALIDSUSPWRT 0x00000040 /* Valid write during suspension. */ +#define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */ +#define B_CKHASH 0x00000100 /* checksum hash calculated on read */ +#define B_DONE 0x00000200 /* I/O completed. */ +#define B_EINTR 0x00000400 /* I/O was interrupted */ +#define B_NOREUSE 0x00000800 /* Contents not reused once released. */ +#define B_REUSE 0x00001000 /* Contents reused, second chance. */ +#define B_INVAL 0x00002000 /* Does not contain valid info. */ +#define B_BARRIER 0x00004000 /* Write this and all preceding first. */ +#define B_NOCACHE 0x00008000 /* Do not cache block after use. */ +#define B_MALLOC 0x00010000 /* malloced b_data */ +#define B_CLUSTEROK 0x00020000 /* Pagein op, so swap() can count it. */ +#define B_00040000 0x00040000 /* Available flag. */ +#define B_00080000 0x00080000 /* Available flag. */ +#define B_00100000 0x00100000 /* Available flag. */ +#define B_00200000 0x00200000 /* Available flag. */ +#define B_RELBUF 0x00400000 /* Release VMIO buffer. */ +#define B_FS_FLAG1 0x00800000 /* Available flag for FS use. */ +#define B_NOCOPY 0x01000000 /* Don't copy-on-write this buf. */ +#define B_INFREECNT 0x02000000 /* buf is counted in numfreebufs */ +#define B_PAGING 0x04000000 /* volatile paging I/O -- bypass VMIO */ +#define B_MANAGED 0x08000000 /* Managed by FS. */ +#define B_RAM 0x10000000 /* Read ahead mark (flag) */ +#define B_VMIO 0x20000000 /* VMIO flag */ +#define B_CLUSTER 0x40000000 /* pagein op, so swap() can count it */ +#define B_REMFREE 0x80000000 /* Delayed bremfree */ + +#define PRINT_BUF_FLAGS "\20\40remfree\37cluster\36vmio\35ram\34managed" \ + "\33paging\32infreecnt\31nocopy\30b23\27relbuf\26b21\25b20" \ + "\24b19\23b18\22clusterok\21malloc\20nocache\17b14\16inval" \ + "\15reuse\14noreuse\13eintr\12done\11b8\10delwri" \ + "\7validsuspwrt\6cache\5deferred\4direct\3async\2needcommit\1age" + +/* + * These flags are kept in b_xflags. + * + * BX_FSPRIV reserves a set of eight flags that may be used by individual + * filesystems for their own purpose. Their specific definitions are + * found in the header files for each filesystem that uses them. + */ +#define BX_VNDIRTY 0x00000001 /* On vnode dirty list */ +#define BX_VNCLEAN 0x00000002 /* On vnode clean list */ +#define BX_BKGRDWRITE 0x00000010 /* Do writes in background */ +#define BX_BKGRDMARKER 0x00000020 /* Mark buffer for splay tree */ +#define BX_ALTDATA 0x00000040 /* Holds extended data */ +#define BX_FSPRIV 0x00FF0000 /* filesystem-specific flags mask */ + +#define PRINT_BUF_XFLAGS "\20\7altdata\6bkgrdmarker\5bkgrdwrite\2clean\1dirty" + +#define NOOFFSET (-1LL) /* No buffer offset calculated yet */ + +/* + * These flags are kept in b_vflags. + */ +#define BV_SCANNED 0x00000001 /* VOP_FSYNC funcs mark written bufs */ +#define BV_BKGRDINPROG 0x00000002 /* Background write in progress */ +#define BV_BKGRDWAIT 0x00000004 /* Background write waiting */ +#define BV_BKGRDERR 0x00000008 /* Error from background write */ + +#define PRINT_BUF_VFLAGS "\20\4bkgrderr\3bkgrdwait\2bkgrdinprog\1scanned" + +#ifdef _KERNEL +/* + * Buffer locking + */ +extern const char *buf_wmesg; /* Default buffer lock message */ +#define BUF_WMESG "bufwait" +#include /* XXX for curthread */ +#include + +/* + * Initialize a lock. + */ +#define BUF_LOCKINIT(bp) \ + lockinit(&(bp)->b_lock, PRIBIO + 4, buf_wmesg, 0, 0) +/* + * + * Get a lock sleeping non-interruptably until it becomes available. + */ +#define BUF_LOCK(bp, locktype, interlock) \ + _lockmgr_args_rw(&(bp)->b_lock, (locktype), (interlock), \ + LK_WMESG_DEFAULT, LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, \ + LOCK_FILE, LOCK_LINE) + +/* + * Get a lock sleeping with specified interruptably and timeout. + */ +#define BUF_TIMELOCK(bp, locktype, interlock, wmesg, catch, timo) \ + _lockmgr_args_rw(&(bp)->b_lock, (locktype) | LK_TIMELOCK, \ + (interlock), (wmesg), (PRIBIO + 4) | (catch), (timo), \ + LOCK_FILE, LOCK_LINE) + +/* + * Release a lock. Only the acquiring process may free the lock unless + * it has been handed off to biodone. + */ +#define BUF_UNLOCK(bp) do { \ + KASSERT(((bp)->b_flags & B_REMFREE) == 0, \ + ("BUF_UNLOCK %p while B_REMFREE is still set.", (bp))); \ + \ + (void)_lockmgr_args(&(bp)->b_lock, LK_RELEASE, NULL, \ + LK_WMESG_DEFAULT, LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, \ + LOCK_FILE, LOCK_LINE); \ +} while (0) + +/* + * Check if a buffer lock is recursed. + */ +#define BUF_LOCKRECURSED(bp) \ + lockmgr_recursed(&(bp)->b_lock) + +/* + * Check if a buffer lock is currently held. + */ +#define BUF_ISLOCKED(bp) \ + lockstatus(&(bp)->b_lock) +/* + * Free a buffer lock. + */ +#define BUF_LOCKFREE(bp) \ + lockdestroy(&(bp)->b_lock) + +/* + * Print informations on a buffer lock. + */ +#define BUF_LOCKPRINTINFO(bp) \ + lockmgr_printinfo(&(bp)->b_lock) + +/* + * Buffer lock assertions. + */ +#if defined(INVARIANTS) && defined(INVARIANT_SUPPORT) +#define BUF_ASSERT_LOCKED(bp) \ + _lockmgr_assert(&(bp)->b_lock, KA_LOCKED, LOCK_FILE, LOCK_LINE) +#define BUF_ASSERT_SLOCKED(bp) \ + _lockmgr_assert(&(bp)->b_lock, KA_SLOCKED, LOCK_FILE, LOCK_LINE) +#define BUF_ASSERT_XLOCKED(bp) \ + _lockmgr_assert(&(bp)->b_lock, KA_XLOCKED, LOCK_FILE, LOCK_LINE) +#define BUF_ASSERT_UNLOCKED(bp) \ + _lockmgr_assert(&(bp)->b_lock, KA_UNLOCKED, LOCK_FILE, LOCK_LINE) +#define BUF_ASSERT_HELD(bp) +#define BUF_ASSERT_UNHELD(bp) +#else +#define BUF_ASSERT_LOCKED(bp) +#define BUF_ASSERT_SLOCKED(bp) +#define BUF_ASSERT_XLOCKED(bp) +#define BUF_ASSERT_UNLOCKED(bp) +#define BUF_ASSERT_HELD(bp) +#define BUF_ASSERT_UNHELD(bp) +#endif + +#ifdef _SYS_PROC_H_ /* Avoid #include pollution */ +/* + * When initiating asynchronous I/O, change ownership of the lock to the + * kernel. Once done, the lock may legally released by biodone. The + * original owning process can no longer acquire it recursively, but must + * wait until the I/O is completed and the lock has been freed by biodone. + */ +#define BUF_KERNPROC(bp) \ + _lockmgr_disown(&(bp)->b_lock, LOCK_FILE, LOCK_LINE) +#endif + +#endif /* _KERNEL */ + +struct buf_queue_head { + TAILQ_HEAD(buf_queue, buf) queue; + daddr_t last_pblkno; + struct buf *insert_point; + struct buf *switch_point; +}; + +/* + * This structure describes a clustered I/O. + */ +struct cluster_save { + long bs_bcount; /* Saved b_bcount. */ + long bs_bufsize; /* Saved b_bufsize. */ + int bs_nchildren; /* Number of associated buffers. */ + struct buf **bs_children; /* List of associated buffers. */ +}; + +#ifdef _KERNEL + +static __inline int +bwrite(struct buf *bp) +{ + + KASSERT(bp->b_bufobj != NULL, ("bwrite: no bufobj bp=%p", bp)); + KASSERT(bp->b_bufobj->bo_ops != NULL, ("bwrite: no bo_ops bp=%p", bp)); + KASSERT(bp->b_bufobj->bo_ops->bop_write != NULL, + ("bwrite: no bop_write bp=%p", bp)); + return (BO_WRITE(bp->b_bufobj, bp)); +} + +static __inline void +bstrategy(struct buf *bp) +{ + + KASSERT(bp->b_bufobj != NULL, ("bstrategy: no bufobj bp=%p", bp)); + KASSERT(bp->b_bufobj->bo_ops != NULL, + ("bstrategy: no bo_ops bp=%p", bp)); + KASSERT(bp->b_bufobj->bo_ops->bop_strategy != NULL, + ("bstrategy: no bop_strategy bp=%p", bp)); + BO_STRATEGY(bp->b_bufobj, bp); +} + +static __inline void +buf_start(struct buf *bp) +{ + if (bioops.io_start) + (*bioops.io_start)(bp); +} + +static __inline void +buf_complete(struct buf *bp) +{ + if (bioops.io_complete) + (*bioops.io_complete)(bp); +} + +static __inline void +buf_deallocate(struct buf *bp) +{ + if (bioops.io_deallocate) + (*bioops.io_deallocate)(bp); +} + +static __inline int +buf_countdeps(struct buf *bp, int i) +{ + if (bioops.io_countdeps) + return ((*bioops.io_countdeps)(bp, i)); + else + return (0); +} + +static __inline void +buf_track(struct buf *bp __unused, const char *location __unused) +{ + +#if defined(FULL_BUF_TRACKING) + bp->b_io_tracking[BUF_TRACKING_ENTRY(bp->b_io_tcnt++)] = location; +#elif defined(BUF_TRACKING) + bp->b_io_tracking = location; +#endif +} + +#endif /* _KERNEL */ + +/* + * Zero out the buffer's data area. + */ +#define clrbuf(bp) { \ + bzero((bp)->b_data, (u_int)(bp)->b_bcount); \ + (bp)->b_resid = 0; \ +} + +/* + * Flags for getblk's last parameter. + */ +#define GB_LOCK_NOWAIT 0x0001 /* Fail if we block on a buf lock. */ +#define GB_NOCREAT 0x0002 /* Don't create a buf if not found. */ +#define GB_NOWAIT_BD 0x0004 /* Do not wait for bufdaemon. */ +#define GB_UNMAPPED 0x0008 /* Do not mmap buffer pages. */ +#define GB_KVAALLOC 0x0010 /* But allocate KVA. */ +#define GB_CKHASH 0x0020 /* If reading, calc checksum hash */ +#define GB_NOSPARSE 0x0040 /* Do not instantiate holes */ + +#ifdef _KERNEL +extern int nbuf; /* The number of buffer headers */ +extern long maxswzone; /* Max KVA for swap structures */ +extern long maxbcache; /* Max KVA for buffer cache */ +extern int maxbcachebuf; /* Max buffer cache block size */ +extern long runningbufspace; +extern long hibufspace; +extern int dirtybufthresh; +extern int bdwriteskip; +extern int dirtybufferflushes; +extern int altbufferflushes; +extern int nswbuf; /* Number of swap I/O buffer headers. */ +extern int cluster_pbuf_freecnt; /* Number of pbufs for clusters */ +extern int vnode_pbuf_freecnt; /* Number of pbufs for vnode pager */ +extern int vnode_async_pbuf_freecnt; /* Number of pbufs for vnode pager, + asynchronous reads */ +extern caddr_t unmapped_buf; /* Data address for unmapped buffers. */ + +static inline int +buf_mapped(struct buf *bp) +{ + + return (bp->b_data != unmapped_buf); +} + +void runningbufwakeup(struct buf *); +void waitrunningbufspace(void); +caddr_t kern_vfs_bio_buffer_alloc(caddr_t v, long physmem_est); +void bufinit(void); +void bufshutdown(int); +void bdata2bio(struct buf *bp, struct bio *bip); +void bwillwrite(void); +int buf_dirty_count_severe(void); +void bremfree(struct buf *); +void bremfreef(struct buf *); /* XXX Force bremfree, only for nfs. */ +#define bread(vp, blkno, size, cred, bpp) \ + breadn_flags(vp, blkno, size, NULL, NULL, 0, cred, 0, NULL, bpp) +#define bread_gb(vp, blkno, size, cred, gbflags, bpp) \ + breadn_flags(vp, blkno, size, NULL, NULL, 0, cred, \ + gbflags, NULL, bpp) +#define breadn(vp, blkno, size, rablkno, rabsize, cnt, cred, bpp) \ + breadn_flags(vp, blkno, size, rablkno, rabsize, cnt, cred, \ + 0, NULL, bpp) +int breadn_flags(struct vnode *, daddr_t, int, daddr_t *, int *, int, + struct ucred *, int, void (*)(struct buf *), struct buf **); +void bdwrite(struct buf *); +void bawrite(struct buf *); +void babarrierwrite(struct buf *); +int bbarrierwrite(struct buf *); +void bdirty(struct buf *); +void bundirty(struct buf *); +void bufstrategy(struct bufobj *, struct buf *); +void brelse(struct buf *); +void bqrelse(struct buf *); +int vfs_bio_awrite(struct buf *); +void vfs_drain_busy_pages(struct buf *bp); +struct buf * getpbuf(int *); +struct buf *incore(struct bufobj *, daddr_t); +struct buf *gbincore(struct bufobj *, daddr_t); +struct buf *getblk(struct vnode *, daddr_t, int, int, int, int); +int getblkx(struct vnode *vp, daddr_t blkno, int size, int slpflag, + int slptimeo, int flags, struct buf **bpp); +struct buf *geteblk(int, int); +int bufwait(struct buf *); +int bufwrite(struct buf *); +void bufdone(struct buf *); +void bd_speedup(void); + +int cluster_read(struct vnode *, u_quad_t, daddr_t, long, + struct ucred *, long, int, int, struct buf **); +int cluster_wbuild(struct vnode *, long, daddr_t, int, int); +void cluster_write(struct vnode *, struct buf *, u_quad_t, int, int); +void vfs_bio_brelse(struct buf *bp, int ioflags); +void vfs_bio_bzero_buf(struct buf *bp, int base, int size); +void vfs_bio_clrbuf(struct buf *); +void vfs_bio_set_flags(struct buf *bp, int ioflags); +void vfs_bio_set_valid(struct buf *, int base, int size); +void vfs_busy_pages(struct buf *, int clear_modify); +void vfs_unbusy_pages(struct buf *); +int vmapbuf(struct buf *, int); +void vunmapbuf(struct buf *); +void relpbuf(struct buf *, int *); +void brelvp(struct buf *); +void bgetvp(struct vnode *, struct buf *); +void pbgetbo(struct bufobj *bo, struct buf *bp); +void pbgetvp(struct vnode *, struct buf *); +void pbrelbo(struct buf *); +void pbrelvp(struct buf *); +int allocbuf(struct buf *bp, int size); +void reassignbuf(struct buf *); +struct buf *trypbuf(int *); +void bwait(struct buf *, u_char, const char *); +void bdone(struct buf *); + +typedef daddr_t (vbg_get_lblkno_t)(struct vnode *, vm_ooffset_t); +typedef int (vbg_get_blksize_t)(struct vnode *, daddr_t); +int vfs_bio_getpages(struct vnode *vp, struct vm_page **ma, int count, + int *rbehind, int *rahead, vbg_get_lblkno_t get_lblkno, + vbg_get_blksize_t get_blksize); + +#endif /* _KERNEL */ + +#endif /* !_SYS_BUF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/buf_ring.h b/lib/libc/include/any-freebsd-any/sys/buf_ring.h new file mode 100644 index 000000000000..b04b2cb5b81f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/buf_ring.h @@ -0,0 +1,372 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2007-2009 Kip Macy + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS_BUF_RING_H_ +#define _SYS_BUF_RING_H_ + +#include + +#ifdef DEBUG_BUFRING +#include +#include +#endif + +struct buf_ring { + volatile uint32_t br_prod_head; + volatile uint32_t br_prod_tail; + int br_prod_size; + int br_prod_mask; + uint64_t br_drops; + volatile uint32_t br_cons_head __aligned(CACHE_LINE_SIZE); + volatile uint32_t br_cons_tail; + int br_cons_size; + int br_cons_mask; +#ifdef DEBUG_BUFRING + struct mtx *br_lock; +#endif + void *br_ring[0] __aligned(CACHE_LINE_SIZE); +}; + +/* + * multi-producer safe lock-free ring buffer enqueue + * + */ +static __inline int +buf_ring_enqueue(struct buf_ring *br, void *buf) +{ + uint32_t prod_head, prod_next, cons_tail; +#ifdef DEBUG_BUFRING + int i; + + /* + * Note: It is possible to encounter an mbuf that was removed + * via drbr_peek(), and then re-added via drbr_putback() and + * trigger a spurious panic. + */ + for (i = br->br_cons_head; i != br->br_prod_head; + i = ((i + 1) & br->br_cons_mask)) + if(br->br_ring[i] == buf) + panic("buf=%p already enqueue at %d prod=%d cons=%d", + buf, i, br->br_prod_tail, br->br_cons_tail); +#endif + critical_enter(); + do { + prod_head = br->br_prod_head; + prod_next = (prod_head + 1) & br->br_prod_mask; + cons_tail = br->br_cons_tail; + + if (prod_next == cons_tail) { + rmb(); + if (prod_head == br->br_prod_head && + cons_tail == br->br_cons_tail) { + br->br_drops++; + critical_exit(); + return (ENOBUFS); + } + continue; + } + } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next)); +#ifdef DEBUG_BUFRING + if (br->br_ring[prod_head] != NULL) + panic("dangling value in enqueue"); +#endif + br->br_ring[prod_head] = buf; + + /* + * If there are other enqueues in progress + * that preceded us, we need to wait for them + * to complete + */ + while (br->br_prod_tail != prod_head) + cpu_spinwait(); + atomic_store_rel_int(&br->br_prod_tail, prod_next); + critical_exit(); + return (0); +} + +/* + * multi-consumer safe dequeue + * + */ +static __inline void * +buf_ring_dequeue_mc(struct buf_ring *br) +{ + uint32_t cons_head, cons_next; + void *buf; + + critical_enter(); + do { + cons_head = br->br_cons_head; + cons_next = (cons_head + 1) & br->br_cons_mask; + + if (cons_head == br->br_prod_tail) { + critical_exit(); + return (NULL); + } + } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next)); + + buf = br->br_ring[cons_head]; +#ifdef DEBUG_BUFRING + br->br_ring[cons_head] = NULL; +#endif + /* + * If there are other dequeues in progress + * that preceded us, we need to wait for them + * to complete + */ + while (br->br_cons_tail != cons_head) + cpu_spinwait(); + + atomic_store_rel_int(&br->br_cons_tail, cons_next); + critical_exit(); + + return (buf); +} + +/* + * single-consumer dequeue + * use where dequeue is protected by a lock + * e.g. a network driver's tx queue lock + */ +static __inline void * +buf_ring_dequeue_sc(struct buf_ring *br) +{ + uint32_t cons_head, cons_next; +#ifdef PREFETCH_DEFINED + uint32_t cons_next_next; +#endif + uint32_t prod_tail; + void *buf; + + /* + * This is a workaround to allow using buf_ring on ARM and ARM64. + * ARM64TODO: Fix buf_ring in a generic way. + * REMARKS: It is suspected that br_cons_head does not require + * load_acq operation, but this change was extensively tested + * and confirmed it's working. To be reviewed once again in + * FreeBSD-12. + * + * Preventing following situation: + + * Core(0) - buf_ring_enqueue() Core(1) - buf_ring_dequeue_sc() + * ----------------------------------------- ---------------------------------------------- + * + * cons_head = br->br_cons_head; + * atomic_cmpset_acq_32(&br->br_prod_head, ...)); + * buf = br->br_ring[cons_head]; > + * br->br_ring[prod_head] = buf; + * atomic_store_rel_32(&br->br_prod_tail, ...); + * prod_tail = br->br_prod_tail; + * if (cons_head == prod_tail) + * return (NULL); + * ` + * + * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU. + */ +#if defined(__arm__) || defined(__aarch64__) + cons_head = atomic_load_acq_32(&br->br_cons_head); +#else + cons_head = br->br_cons_head; +#endif + prod_tail = atomic_load_acq_32(&br->br_prod_tail); + + cons_next = (cons_head + 1) & br->br_cons_mask; +#ifdef PREFETCH_DEFINED + cons_next_next = (cons_head + 2) & br->br_cons_mask; +#endif + + if (cons_head == prod_tail) + return (NULL); + +#ifdef PREFETCH_DEFINED + if (cons_next != prod_tail) { + prefetch(br->br_ring[cons_next]); + if (cons_next_next != prod_tail) + prefetch(br->br_ring[cons_next_next]); + } +#endif + br->br_cons_head = cons_next; + buf = br->br_ring[cons_head]; + +#ifdef DEBUG_BUFRING + br->br_ring[cons_head] = NULL; + if (!mtx_owned(br->br_lock)) + panic("lock not held on single consumer dequeue"); + if (br->br_cons_tail != cons_head) + panic("inconsistent list cons_tail=%d cons_head=%d", + br->br_cons_tail, cons_head); +#endif + br->br_cons_tail = cons_next; + return (buf); +} + +/* + * single-consumer advance after a peek + * use where it is protected by a lock + * e.g. a network driver's tx queue lock + */ +static __inline void +buf_ring_advance_sc(struct buf_ring *br) +{ + uint32_t cons_head, cons_next; + uint32_t prod_tail; + + cons_head = br->br_cons_head; + prod_tail = br->br_prod_tail; + + cons_next = (cons_head + 1) & br->br_cons_mask; + if (cons_head == prod_tail) + return; + br->br_cons_head = cons_next; +#ifdef DEBUG_BUFRING + br->br_ring[cons_head] = NULL; +#endif + br->br_cons_tail = cons_next; +} + +/* + * Used to return a buffer (most likely already there) + * to the top of the ring. The caller should *not* + * have used any dequeue to pull it out of the ring + * but instead should have used the peek() function. + * This is normally used where the transmit queue + * of a driver is full, and an mbuf must be returned. + * Most likely whats in the ring-buffer is what + * is being put back (since it was not removed), but + * sometimes the lower transmit function may have + * done a pullup or other function that will have + * changed it. As an optimization we always put it + * back (since jhb says the store is probably cheaper), + * if we have to do a multi-queue version we will need + * the compare and an atomic. + */ +static __inline void +buf_ring_putback_sc(struct buf_ring *br, void *new) +{ + KASSERT(br->br_cons_head != br->br_prod_tail, + ("Buf-Ring has none in putback")) ; + br->br_ring[br->br_cons_head] = new; +} + +/* + * return a pointer to the first entry in the ring + * without modifying it, or NULL if the ring is empty + * race-prone if not protected by a lock + */ +static __inline void * +buf_ring_peek(struct buf_ring *br) +{ + +#ifdef DEBUG_BUFRING + if ((br->br_lock != NULL) && !mtx_owned(br->br_lock)) + panic("lock not held on single consumer dequeue"); +#endif + /* + * I believe it is safe to not have a memory barrier + * here because we control cons and tail is worst case + * a lagging indicator so we worst case we might + * return NULL immediately after a buffer has been enqueued + */ + if (br->br_cons_head == br->br_prod_tail) + return (NULL); + + return (br->br_ring[br->br_cons_head]); +} + +static __inline void * +buf_ring_peek_clear_sc(struct buf_ring *br) +{ +#ifdef DEBUG_BUFRING + void *ret; + + if (!mtx_owned(br->br_lock)) + panic("lock not held on single consumer dequeue"); +#endif + + if (br->br_cons_head == br->br_prod_tail) + return (NULL); + +#if defined(__arm__) || defined(__aarch64__) + /* + * The barrier is required there on ARM and ARM64 to ensure, that + * br->br_ring[br->br_cons_head] will not be fetched before the above + * condition is checked. + * Without the barrier, it is possible, that buffer will be fetched + * before the enqueue will put mbuf into br, then, in the meantime, the + * enqueue will update the array and the br_prod_tail, and the + * conditional check will be true, so we will return previously fetched + * (and invalid) buffer. + */ + atomic_thread_fence_acq(); +#endif + +#ifdef DEBUG_BUFRING + /* + * Single consumer, i.e. cons_head will not move while we are + * running, so atomic_swap_ptr() is not necessary here. + */ + ret = br->br_ring[br->br_cons_head]; + br->br_ring[br->br_cons_head] = NULL; + return (ret); +#else + return (br->br_ring[br->br_cons_head]); +#endif +} + +static __inline int +buf_ring_full(struct buf_ring *br) +{ + + return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail); +} + +static __inline int +buf_ring_empty(struct buf_ring *br) +{ + + return (br->br_cons_head == br->br_prod_tail); +} + +static __inline int +buf_ring_count(struct buf_ring *br) +{ + + return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail) + & br->br_prod_mask); +} + +struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags, + struct mtx *); +void buf_ring_free(struct buf_ring *br, struct malloc_type *type); + + + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/bufobj.h b/lib/libc/include/any-freebsd-any/sys/bufobj.h new file mode 100644 index 000000000000..b02d42761208 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bufobj.h @@ -0,0 +1,140 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Architectural notes: + * + * bufobj is a new object which is what buffers hang from in the buffer + * cache. + * + * This used to be vnodes, but we need non-vnode code to be able + * to use the buffer cache as well, specifically geom classes like gbde, + * raid3 and raid5. + * + * All vnodes will contain a bufobj initially, but down the road we may + * want to only allocate bufobjs when they are needed. There could be a + * large number of vnodes in the system which wouldn't need a bufobj during + * their lifetime. + * + * The exact relationship to the vmobject is not determined at this point, + * it may in fact be that we find them to be two sides of the same object + * once things starts to crystalize. + */ + +#ifndef _SYS_BUFOBJ_H_ +#define _SYS_BUFOBJ_H_ + +#if defined(_KERNEL) || defined(_KVM_VNODE) + +#include +#include +#include +#include + +struct bufobj; +struct buf_ops; + +extern struct buf_ops buf_ops_bio; + +TAILQ_HEAD(buflists, buf); + +/* A Buffer list & trie */ +struct bufv { + struct buflists bv_hd; /* Sorted blocklist */ + struct pctrie bv_root; /* Buf trie */ + int bv_cnt; /* Number of buffers */ +}; + +typedef void b_strategy_t(struct bufobj *, struct buf *); +typedef int b_write_t(struct buf *); +typedef int b_sync_t(struct bufobj *, int waitfor); +typedef void b_bdflush_t(struct bufobj *, struct buf *); + +struct buf_ops { + char *bop_name; + b_write_t *bop_write; + b_strategy_t *bop_strategy; + b_sync_t *bop_sync; + b_bdflush_t *bop_bdflush; +}; + +#define BO_STRATEGY(bo, bp) ((bo)->bo_ops->bop_strategy((bo), (bp))) +#define BO_SYNC(bo, w) ((bo)->bo_ops->bop_sync((bo), (w))) +#define BO_WRITE(bo, bp) ((bo)->bo_ops->bop_write((bp))) +#define BO_BDFLUSH(bo, bp) ((bo)->bo_ops->bop_bdflush((bo), (bp))) + +/* + * Locking notes: + * 'S' is sync_mtx + * 'v' is the vnode lock which embeds the bufobj. + * '-' Constant and unchanging after initialization. + */ +struct bufobj { + struct rwlock bo_lock; /* Lock which protects "i" things */ + struct buf_ops *bo_ops; /* - Buffer operations */ + struct vm_object *bo_object; /* v Place to store VM object */ + LIST_ENTRY(bufobj) bo_synclist; /* S dirty vnode list */ + void *bo_private; /* private pointer */ + struct bufv bo_clean; /* i Clean buffers */ + struct bufv bo_dirty; /* i Dirty buffers */ + long bo_numoutput; /* i Writes in progress */ + u_int bo_flag; /* i Flags */ + int bo_domain; /* - Clean queue affinity */ + int bo_bsize; /* - Block size for i/o */ +}; + +/* + * XXX BO_ONWORKLST could be replaced with a check for NULL list elements + * in v_synclist. + */ +#define BO_ONWORKLST (1 << 0) /* On syncer work-list */ +#define BO_WWAIT (1 << 1) /* Wait for output to complete */ +#define BO_DEAD (1 << 2) /* Dead; only with INVARIANTS */ + +#define BO_LOCKPTR(bo) (&(bo)->bo_lock) +#define BO_LOCK(bo) rw_wlock(BO_LOCKPTR((bo))) +#define BO_UNLOCK(bo) rw_wunlock(BO_LOCKPTR((bo))) +#define BO_RLOCK(bo) rw_rlock(BO_LOCKPTR((bo))) +#define BO_RUNLOCK(bo) rw_runlock(BO_LOCKPTR((bo))) +#define ASSERT_BO_WLOCKED(bo) rw_assert(BO_LOCKPTR((bo)), RA_WLOCKED) +#define ASSERT_BO_LOCKED(bo) rw_assert(BO_LOCKPTR((bo)), RA_LOCKED) +#define ASSERT_BO_UNLOCKED(bo) rw_assert(BO_LOCKPTR((bo)), RA_UNLOCKED) + +void bufobj_init(struct bufobj *bo, void *private); +void bufobj_wdrop(struct bufobj *bo); +void bufobj_wref(struct bufobj *bo); +void bufobj_wrefl(struct bufobj *bo); +int bufobj_invalbuf(struct bufobj *bo, int flags, int slpflag, int slptimeo); +int bufobj_wwait(struct bufobj *bo, int slpflag, int timeo); +int bufsync(struct bufobj *bo, int waitfor); +void bufbdflush(struct bufobj *bo, struct buf *bp); + +#endif /* defined(_KERNEL) || defined(_KVM_VNODE) */ +#endif /* _SYS_BUFOBJ_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bus.h b/lib/libc/include/any-freebsd-any/sys/bus.h new file mode 100644 index 000000000000..64dc2468957c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bus.h @@ -0,0 +1,971 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997,1998,2003 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_BUS_H_ +#define _SYS_BUS_H_ + +#include +#include +#include +#include + +/** + * @defgroup NEWBUS newbus - a generic framework for managing devices + * @{ + */ + +/** + * @brief Interface information structure. + */ +struct u_businfo { + int ub_version; /**< @brief interface version */ +#define BUS_USER_VERSION 2 + int ub_generation; /**< @brief generation count */ +}; + +/** + * @brief State of the device. + */ +typedef enum device_state { + DS_NOTPRESENT = 10, /**< @brief not probed or probe failed */ + DS_ALIVE = 20, /**< @brief probe succeeded */ + DS_ATTACHING = 25, /**< @brief currently attaching */ + DS_ATTACHED = 30, /**< @brief attach method called */ + DS_BUSY = 40 /**< @brief device is open */ +} device_state_t; + +/** + * @brief Device information exported to userspace. + * The strings are placed one after the other, separated by NUL characters. + * Fields should be added after the last one and order maintained for compatibility + */ +#define BUS_USER_BUFFER (3*1024) +struct u_device { + uintptr_t dv_handle; + uintptr_t dv_parent; + uint32_t dv_devflags; /**< @brief API Flags for device */ + uint16_t dv_flags; /**< @brief flags for dev state */ + device_state_t dv_state; /**< @brief State of attachment */ + char dv_fields[BUS_USER_BUFFER]; /**< @brief NUL terminated fields */ + /* name (name of the device in tree) */ + /* desc (driver description) */ + /* drivername (Name of driver without unit number) */ + /* pnpinfo (Plug and play information from bus) */ + /* location (Location of device on parent */ + /* NUL */ +}; + +/* Flags exported via dv_flags. */ +#define DF_ENABLED 0x01 /* device should be probed/attached */ +#define DF_FIXEDCLASS 0x02 /* devclass specified at create time */ +#define DF_WILDCARD 0x04 /* unit was originally wildcard */ +#define DF_DESCMALLOCED 0x08 /* description was malloced */ +#define DF_QUIET 0x10 /* don't print verbose attach message */ +#define DF_DONENOMATCH 0x20 /* don't execute DEVICE_NOMATCH again */ +#define DF_EXTERNALSOFTC 0x40 /* softc not allocated by us */ +#define DF_REBID 0x80 /* Can rebid after attach */ +#define DF_SUSPENDED 0x100 /* Device is suspended. */ +#define DF_QUIET_CHILDREN 0x200 /* Default to quiet for all my children */ +#define DF_ATTACHED_ONCE 0x400 /* Has been attached at least once */ +#define DF_NEEDNOMATCH 0x800 /* Has a pending NOMATCH event */ + +/** + * @brief Device request structure used for ioctl's. + * + * Used for ioctl's on /dev/devctl2. All device ioctl's + * must have parameter definitions which begin with dr_name. + */ +struct devreq_buffer { + void *buffer; + size_t length; +}; + +struct devreq { + char dr_name[128]; + int dr_flags; /* request-specific flags */ + union { + struct devreq_buffer dru_buffer; + void *dru_data; + } dr_dru; +#define dr_buffer dr_dru.dru_buffer /* variable-sized buffer */ +#define dr_data dr_dru.dru_data /* fixed-size buffer */ +}; + +#define DEV_ATTACH _IOW('D', 1, struct devreq) +#define DEV_DETACH _IOW('D', 2, struct devreq) +#define DEV_ENABLE _IOW('D', 3, struct devreq) +#define DEV_DISABLE _IOW('D', 4, struct devreq) +#define DEV_SUSPEND _IOW('D', 5, struct devreq) +#define DEV_RESUME _IOW('D', 6, struct devreq) +#define DEV_SET_DRIVER _IOW('D', 7, struct devreq) +#define DEV_CLEAR_DRIVER _IOW('D', 8, struct devreq) +#define DEV_RESCAN _IOW('D', 9, struct devreq) +#define DEV_DELETE _IOW('D', 10, struct devreq) +#define DEV_FREEZE _IOW('D', 11, struct devreq) +#define DEV_THAW _IOW('D', 12, struct devreq) +#define DEV_RESET _IOW('D', 13, struct devreq) + +/* Flags for DEV_DETACH and DEV_DISABLE. */ +#define DEVF_FORCE_DETACH 0x0000001 + +/* Flags for DEV_SET_DRIVER. */ +#define DEVF_SET_DRIVER_DETACH 0x0000001 /* Detach existing driver. */ + +/* Flags for DEV_CLEAR_DRIVER. */ +#define DEVF_CLEAR_DRIVER_DETACH 0x0000001 /* Detach existing driver. */ + +/* Flags for DEV_DELETE. */ +#define DEVF_FORCE_DELETE 0x0000001 + +/* Flags for DEV_RESET */ +#define DEVF_RESET_DETACH 0x0000001 /* Detach drivers vs suspend + device */ + +#ifdef _KERNEL + +#include +#include +#include + +/** + * devctl hooks. Typically one should use the devctl_notify + * hook to send the message. However, devctl_queue_data is also + * included in case devctl_notify isn't sufficiently general. + */ +boolean_t devctl_process_running(void); +void devctl_notify_f(const char *__system, const char *__subsystem, + const char *__type, const char *__data, int __flags); +void devctl_notify(const char *__system, const char *__subsystem, + const char *__type, const char *__data); +void devctl_queue_data_f(char *__data, int __flags); +void devctl_queue_data(char *__data); +struct sbuf; +void devctl_safe_quote_sb(struct sbuf *__sb, const char *__src); + +/** + * Device name parsers. Hook to allow device enumerators to map + * scheme-specific names to a device. + */ +typedef void (*dev_lookup_fn)(void *arg, const char *name, + device_t *result); +EVENTHANDLER_DECLARE(dev_lookup, dev_lookup_fn); + +/** + * @brief A device driver (included mainly for compatibility with + * FreeBSD 4.x). + */ +typedef struct kobj_class driver_t; + +/** + * @brief A device class + * + * The devclass object has two main functions in the system. The first + * is to manage the allocation of unit numbers for device instances + * and the second is to hold the list of device drivers for a + * particular bus type. Each devclass has a name and there cannot be + * two devclasses with the same name. This ensures that unique unit + * numbers are allocated to device instances. + * + * Drivers that support several different bus attachments (e.g. isa, + * pci, pccard) should all use the same devclass to ensure that unit + * numbers do not conflict. + * + * Each devclass may also have a parent devclass. This is used when + * searching for device drivers to allow a form of inheritance. When + * matching drivers with devices, first the driver list of the parent + * device's devclass is searched. If no driver is found in that list, + * the search continues in the parent devclass (if any). + */ +typedef struct devclass *devclass_t; + +/** + * @brief A device method + */ +#define device_method_t kobj_method_t + +/** + * @brief Driver interrupt filter return values + * + * If a driver provides an interrupt filter routine it must return an + * integer consisting of oring together zero or more of the following + * flags: + * + * FILTER_STRAY - this device did not trigger the interrupt + * FILTER_HANDLED - the interrupt has been fully handled and can be EOId + * FILTER_SCHEDULE_THREAD - the threaded interrupt handler should be + * scheduled to execute + * + * If the driver does not provide a filter, then the interrupt code will + * act is if the filter had returned FILTER_SCHEDULE_THREAD. Note that it + * is illegal to specify any other flag with FILTER_STRAY and that it is + * illegal to not specify either of FILTER_HANDLED or FILTER_SCHEDULE_THREAD + * if FILTER_STRAY is not specified. + */ +#define FILTER_STRAY 0x01 +#define FILTER_HANDLED 0x02 +#define FILTER_SCHEDULE_THREAD 0x04 + +/** + * @brief Driver interrupt service routines + * + * The filter routine is run in primary interrupt context and may not + * block or use regular mutexes. It may only use spin mutexes for + * synchronization. The filter may either completely handle the + * interrupt or it may perform some of the work and defer more + * expensive work to the regular interrupt handler. If a filter + * routine is not registered by the driver, then the regular interrupt + * handler is always used to handle interrupts from this device. + * + * The regular interrupt handler executes in its own thread context + * and may use regular mutexes. However, it is prohibited from + * sleeping on a sleep queue. + */ +typedef int driver_filter_t(void*); +typedef void driver_intr_t(void*); + +/** + * @brief Interrupt type bits. + * + * These flags are used both by newbus interrupt + * registration (nexus.c) and also in struct intrec, which defines + * interrupt properties. + * + * XXX We should probably revisit this and remove the vestiges of the + * spls implicit in names like INTR_TYPE_TTY. In the meantime, don't + * confuse things by renaming them (Grog, 18 July 2000). + * + * Buses which do interrupt remapping will want to change their type + * to reflect what sort of devices are underneath. + */ +enum intr_type { + INTR_TYPE_TTY = 1, + INTR_TYPE_BIO = 2, + INTR_TYPE_NET = 4, + INTR_TYPE_CAM = 8, + INTR_TYPE_MISC = 16, + INTR_TYPE_CLK = 32, + INTR_TYPE_AV = 64, + INTR_EXCL = 256, /* exclusive interrupt */ + INTR_MPSAFE = 512, /* this interrupt is SMP safe */ + INTR_ENTROPY = 1024, /* this interrupt provides entropy */ + INTR_MD1 = 4096, /* flag reserved for MD use */ + INTR_MD2 = 8192, /* flag reserved for MD use */ + INTR_MD3 = 16384, /* flag reserved for MD use */ + INTR_MD4 = 32768 /* flag reserved for MD use */ +}; + +enum intr_trigger { + INTR_TRIGGER_INVALID = -1, + INTR_TRIGGER_CONFORM = 0, + INTR_TRIGGER_EDGE = 1, + INTR_TRIGGER_LEVEL = 2 +}; + +enum intr_polarity { + INTR_POLARITY_CONFORM = 0, + INTR_POLARITY_HIGH = 1, + INTR_POLARITY_LOW = 2 +}; + +/** + * CPU sets supported by bus_get_cpus(). Note that not all sets may be + * supported for a given device. If a request is not supported by a + * device (or its parents), then bus_get_cpus() will fail with EINVAL. + */ +enum cpu_sets { + LOCAL_CPUS = 0, + INTR_CPUS +}; + +typedef int (*devop_t)(void); + +/** + * @brief This structure is deprecated. + * + * Use the kobj(9) macro DEFINE_CLASS to + * declare classes which implement device drivers. + */ +struct driver { + KOBJ_CLASS_FIELDS; +}; + +/** + * @brief A resource mapping. + */ +struct resource_map { + bus_space_tag_t r_bustag; + bus_space_handle_t r_bushandle; + bus_size_t r_size; + void *r_vaddr; +}; + +/** + * @brief Optional properties of a resource mapping request. + */ +struct resource_map_request { + size_t size; + rman_res_t offset; + rman_res_t length; + vm_memattr_t memattr; +}; + +void resource_init_map_request_impl(struct resource_map_request *_args, + size_t _sz); +#define resource_init_map_request(rmr) \ + resource_init_map_request_impl((rmr), sizeof(*(rmr))) + +/* + * Definitions for drivers which need to keep simple lists of resources + * for their child devices. + */ +struct resource; + +/** + * @brief An entry for a single resource in a resource list. + */ +struct resource_list_entry { + STAILQ_ENTRY(resource_list_entry) link; + int type; /**< @brief type argument to alloc_resource */ + int rid; /**< @brief resource identifier */ + int flags; /**< @brief resource flags */ + struct resource *res; /**< @brief the real resource when allocated */ + rman_res_t start; /**< @brief start of resource range */ + rman_res_t end; /**< @brief end of resource range */ + rman_res_t count; /**< @brief count within range */ +}; +STAILQ_HEAD(resource_list, resource_list_entry); + +#define RLE_RESERVED 0x0001 /* Reserved by the parent bus. */ +#define RLE_ALLOCATED 0x0002 /* Reserved resource is allocated. */ +#define RLE_PREFETCH 0x0004 /* Resource is a prefetch range. */ + +void resource_list_init(struct resource_list *rl); +void resource_list_free(struct resource_list *rl); +struct resource_list_entry * + resource_list_add(struct resource_list *rl, + int type, int rid, + rman_res_t start, rman_res_t end, rman_res_t count); +int resource_list_add_next(struct resource_list *rl, + int type, + rman_res_t start, rman_res_t end, rman_res_t count); +int resource_list_busy(struct resource_list *rl, + int type, int rid); +int resource_list_reserved(struct resource_list *rl, int type, int rid); +struct resource_list_entry* + resource_list_find(struct resource_list *rl, + int type, int rid); +void resource_list_delete(struct resource_list *rl, + int type, int rid); +struct resource * + resource_list_alloc(struct resource_list *rl, + device_t bus, device_t child, + int type, int *rid, + rman_res_t start, rman_res_t end, + rman_res_t count, u_int flags); +int resource_list_release(struct resource_list *rl, + device_t bus, device_t child, + int type, int rid, struct resource *res); +int resource_list_release_active(struct resource_list *rl, + device_t bus, device_t child, + int type); +struct resource * + resource_list_reserve(struct resource_list *rl, + device_t bus, device_t child, + int type, int *rid, + rman_res_t start, rman_res_t end, + rman_res_t count, u_int flags); +int resource_list_unreserve(struct resource_list *rl, + device_t bus, device_t child, + int type, int rid); +void resource_list_purge(struct resource_list *rl); +int resource_list_print_type(struct resource_list *rl, + const char *name, int type, + const char *format); + +/* + * The root bus, to which all top-level buses are attached. + */ +extern device_t root_bus; +extern devclass_t root_devclass; +void root_bus_configure(void); + +/* + * Useful functions for implementing buses. + */ + +int bus_generic_activate_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); +device_t + bus_generic_add_child(device_t dev, u_int order, const char *name, + int unit); +int bus_generic_adjust_resource(device_t bus, device_t child, int type, + struct resource *r, rman_res_t start, + rman_res_t end); +struct resource * + bus_generic_alloc_resource(device_t bus, device_t child, int type, + int *rid, rman_res_t start, rman_res_t end, + rman_res_t count, u_int flags); +int bus_generic_translate_resource(device_t dev, int type, rman_res_t start, + rman_res_t *newstart); +int bus_generic_attach(device_t dev); +int bus_generic_bind_intr(device_t dev, device_t child, + struct resource *irq, int cpu); +int bus_generic_child_present(device_t dev, device_t child); +int bus_generic_config_intr(device_t, int, enum intr_trigger, + enum intr_polarity); +int bus_generic_describe_intr(device_t dev, device_t child, + struct resource *irq, void *cookie, + const char *descr); +int bus_generic_deactivate_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); +int bus_generic_detach(device_t dev); +void bus_generic_driver_added(device_t dev, driver_t *driver); +int bus_generic_get_cpus(device_t dev, device_t child, enum cpu_sets op, + size_t setsize, struct _cpuset *cpuset); +bus_dma_tag_t + bus_generic_get_dma_tag(device_t dev, device_t child); +bus_space_tag_t + bus_generic_get_bus_tag(device_t dev, device_t child); +int bus_generic_get_domain(device_t dev, device_t child, int *domain); +struct resource_list * + bus_generic_get_resource_list (device_t, device_t); +int bus_generic_map_resource(device_t dev, device_t child, int type, + struct resource *r, + struct resource_map_request *args, + struct resource_map *map); +void bus_generic_new_pass(device_t dev); +int bus_print_child_header(device_t dev, device_t child); +int bus_print_child_domain(device_t dev, device_t child); +int bus_print_child_footer(device_t dev, device_t child); +int bus_generic_print_child(device_t dev, device_t child); +int bus_generic_probe(device_t dev); +int bus_generic_read_ivar(device_t dev, device_t child, int which, + uintptr_t *result); +int bus_generic_release_resource(device_t bus, device_t child, + int type, int rid, struct resource *r); +int bus_generic_resume(device_t dev); +int bus_generic_resume_child(device_t dev, device_t child); +int bus_generic_setup_intr(device_t dev, device_t child, + struct resource *irq, int flags, + driver_filter_t *filter, driver_intr_t *intr, + void *arg, void **cookiep); + +struct resource * + bus_generic_rl_alloc_resource (device_t, device_t, int, int *, + rman_res_t, rman_res_t, rman_res_t, u_int); +void bus_generic_rl_delete_resource (device_t, device_t, int, int); +int bus_generic_rl_get_resource (device_t, device_t, int, int, rman_res_t *, + rman_res_t *); +int bus_generic_rl_set_resource (device_t, device_t, int, int, rman_res_t, + rman_res_t); +int bus_generic_rl_release_resource (device_t, device_t, int, int, + struct resource *); + +int bus_generic_shutdown(device_t dev); +int bus_generic_suspend(device_t dev); +int bus_generic_suspend_child(device_t dev, device_t child); +int bus_generic_teardown_intr(device_t dev, device_t child, + struct resource *irq, void *cookie); +int bus_generic_suspend_intr(device_t dev, device_t child, + struct resource *irq); +int bus_generic_resume_intr(device_t dev, device_t child, + struct resource *irq); +int bus_generic_unmap_resource(device_t dev, device_t child, int type, + struct resource *r, + struct resource_map *map); +int bus_generic_write_ivar(device_t dev, device_t child, int which, + uintptr_t value); +int bus_helper_reset_post(device_t dev, int flags); +int bus_helper_reset_prepare(device_t dev, int flags); +int bus_null_rescan(device_t dev); + +/* + * Wrapper functions for the BUS_*_RESOURCE methods to make client code + * a little simpler. + */ + +struct resource_spec { + int type; + int rid; + int flags; +}; +#define RESOURCE_SPEC_END {-1, 0, 0} + +int bus_alloc_resources(device_t dev, struct resource_spec *rs, + struct resource **res); +void bus_release_resources(device_t dev, const struct resource_spec *rs, + struct resource **res); + +int bus_adjust_resource(device_t child, int type, struct resource *r, + rman_res_t start, rman_res_t end); +struct resource *bus_alloc_resource(device_t dev, int type, int *rid, + rman_res_t start, rman_res_t end, + rman_res_t count, u_int flags); +int bus_activate_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_deactivate_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_map_resource(device_t dev, int type, struct resource *r, + struct resource_map_request *args, + struct resource_map *map); +int bus_unmap_resource(device_t dev, int type, struct resource *r, + struct resource_map *map); +int bus_get_cpus(device_t dev, enum cpu_sets op, size_t setsize, + struct _cpuset *cpuset); +bus_dma_tag_t bus_get_dma_tag(device_t dev); +bus_space_tag_t bus_get_bus_tag(device_t dev); +int bus_get_domain(device_t dev, int *domain); +int bus_release_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_free_resource(device_t dev, int type, struct resource *r); +int bus_setup_intr(device_t dev, struct resource *r, int flags, + driver_filter_t filter, driver_intr_t handler, + void *arg, void **cookiep); +int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); +int bus_suspend_intr(device_t dev, struct resource *r); +int bus_resume_intr(device_t dev, struct resource *r); +int bus_bind_intr(device_t dev, struct resource *r, int cpu); +int bus_describe_intr(device_t dev, struct resource *irq, void *cookie, + const char *fmt, ...) __printflike(4, 5); +int bus_set_resource(device_t dev, int type, int rid, + rman_res_t start, rman_res_t count); +int bus_get_resource(device_t dev, int type, int rid, + rman_res_t *startp, rman_res_t *countp); +rman_res_t bus_get_resource_start(device_t dev, int type, int rid); +rman_res_t bus_get_resource_count(device_t dev, int type, int rid); +void bus_delete_resource(device_t dev, int type, int rid); +int bus_child_present(device_t child); +int bus_child_pnpinfo_str(device_t child, char *buf, size_t buflen); +int bus_child_location_str(device_t child, char *buf, size_t buflen); +void bus_enumerate_hinted_children(device_t bus); +int bus_delayed_attach_children(device_t bus); + +static __inline struct resource * +bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags) +{ + return (bus_alloc_resource(dev, type, rid, 0, ~0, 1, flags)); +} + +static __inline struct resource * +bus_alloc_resource_anywhere(device_t dev, int type, int *rid, + rman_res_t count, u_int flags) +{ + return (bus_alloc_resource(dev, type, rid, 0, ~0, count, flags)); +} + +/* + * Access functions for device. + */ +device_t device_add_child(device_t dev, const char *name, int unit); +device_t device_add_child_ordered(device_t dev, u_int order, + const char *name, int unit); +void device_busy(device_t dev); +int device_delete_child(device_t dev, device_t child); +int device_delete_children(device_t dev); +int device_attach(device_t dev); +int device_detach(device_t dev); +void device_disable(device_t dev); +void device_enable(device_t dev); +device_t device_find_child(device_t dev, const char *classname, + int unit); +const char *device_get_desc(device_t dev); +devclass_t device_get_devclass(device_t dev); +driver_t *device_get_driver(device_t dev); +u_int32_t device_get_flags(device_t dev); +device_t device_get_parent(device_t dev); +int device_get_children(device_t dev, device_t **listp, int *countp); +void *device_get_ivars(device_t dev); +void device_set_ivars(device_t dev, void *ivars); +const char *device_get_name(device_t dev); +const char *device_get_nameunit(device_t dev); +void *device_get_softc(device_t dev); +device_state_t device_get_state(device_t dev); +int device_get_unit(device_t dev); +struct sysctl_ctx_list *device_get_sysctl_ctx(device_t dev); +struct sysctl_oid *device_get_sysctl_tree(device_t dev); +int device_has_quiet_children(device_t dev); +int device_is_alive(device_t dev); /* did probe succeed? */ +int device_is_attached(device_t dev); /* did attach succeed? */ +int device_is_enabled(device_t dev); +int device_is_suspended(device_t dev); +int device_is_quiet(device_t dev); +device_t device_lookup_by_name(const char *name); +int device_print_prettyname(device_t dev); +int device_printf(device_t dev, const char *, ...) __printflike(2, 3); +int device_probe(device_t dev); +int device_probe_and_attach(device_t dev); +int device_probe_child(device_t bus, device_t dev); +int device_quiesce(device_t dev); +void device_quiet(device_t dev); +void device_quiet_children(device_t dev); +void device_set_desc(device_t dev, const char* desc); +void device_set_desc_copy(device_t dev, const char* desc); +int device_set_devclass(device_t dev, const char *classname); +int device_set_devclass_fixed(device_t dev, const char *classname); +int device_set_driver(device_t dev, driver_t *driver); +void device_set_flags(device_t dev, u_int32_t flags); +void device_set_softc(device_t dev, void *softc); +void device_free_softc(void *softc); +void device_claim_softc(device_t dev); +int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */ +int device_shutdown(device_t dev); +void device_unbusy(device_t dev); +void device_verbose(device_t dev); + +/* + * Access functions for devclass. + */ +int devclass_add_driver(devclass_t dc, driver_t *driver, + int pass, devclass_t *dcp); +devclass_t devclass_create(const char *classname); +int devclass_delete_driver(devclass_t busclass, driver_t *driver); +devclass_t devclass_find(const char *classname); +const char *devclass_get_name(devclass_t dc); +device_t devclass_get_device(devclass_t dc, int unit); +void *devclass_get_softc(devclass_t dc, int unit); +int devclass_get_devices(devclass_t dc, device_t **listp, int *countp); +int devclass_get_drivers(devclass_t dc, driver_t ***listp, int *countp); +int devclass_get_count(devclass_t dc); +int devclass_get_maxunit(devclass_t dc); +int devclass_find_free_unit(devclass_t dc, int unit); +void devclass_set_parent(devclass_t dc, devclass_t pdc); +devclass_t devclass_get_parent(devclass_t dc); +struct sysctl_ctx_list *devclass_get_sysctl_ctx(devclass_t dc); +struct sysctl_oid *devclass_get_sysctl_tree(devclass_t dc); + +/* + * Access functions for device resources. + */ +int resource_int_value(const char *name, int unit, const char *resname, + int *result); +int resource_long_value(const char *name, int unit, const char *resname, + long *result); +int resource_string_value(const char *name, int unit, const char *resname, + const char **result); +int resource_disabled(const char *name, int unit); +int resource_find_match(int *anchor, const char **name, int *unit, + const char *resname, const char *value); +int resource_find_dev(int *anchor, const char *name, int *unit, + const char *resname, const char *value); +int resource_unset_value(const char *name, int unit, const char *resname); + +/* + * Functions for maintaining and checking consistency of + * bus information exported to userspace. + */ +int bus_data_generation_check(int generation); +void bus_data_generation_update(void); + +/** + * Some convenience defines for probe routines to return. These are just + * suggested values, and there's nothing magical about them. + * BUS_PROBE_SPECIFIC is for devices that cannot be reprobed, and that no + * possible other driver may exist (typically legacy drivers who don't follow + * all the rules, or special needs drivers). BUS_PROBE_VENDOR is the + * suggested value that vendor supplied drivers use. This is for source or + * binary drivers that are not yet integrated into the FreeBSD tree. Its use + * in the base OS is prohibited. BUS_PROBE_DEFAULT is the normal return value + * for drivers to use. It is intended that nearly all of the drivers in the + * tree should return this value. BUS_PROBE_LOW_PRIORITY are for drivers that + * have special requirements like when there are two drivers that support + * overlapping series of hardware devices. In this case the one that supports + * the older part of the line would return this value, while the one that + * supports the newer ones would return BUS_PROBE_DEFAULT. BUS_PROBE_GENERIC + * is for drivers that wish to have a generic form and a specialized form, + * like is done with the pci bus and the acpi pci bus. BUS_PROBE_HOOVER is + * for those buses that implement a generic device placeholder for devices on + * the bus that have no more specific driver for them (aka ugen). + * BUS_PROBE_NOWILDCARD or lower means that the device isn't really bidding + * for a device node, but accepts only devices that its parent has told it + * use this driver. + */ +#define BUS_PROBE_SPECIFIC 0 /* Only I can use this device */ +#define BUS_PROBE_VENDOR (-10) /* Vendor supplied driver */ +#define BUS_PROBE_DEFAULT (-20) /* Base OS default driver */ +#define BUS_PROBE_LOW_PRIORITY (-40) /* Older, less desirable drivers */ +#define BUS_PROBE_GENERIC (-100) /* generic driver for dev */ +#define BUS_PROBE_HOOVER (-1000000) /* Driver for any dev on bus */ +#define BUS_PROBE_NOWILDCARD (-2000000000) /* No wildcard device matches */ + +/** + * During boot, the device tree is scanned multiple times. Each scan, + * or pass, drivers may be attached to devices. Each driver + * attachment is assigned a pass number. Drivers may only probe and + * attach to devices if their pass number is less than or equal to the + * current system-wide pass number. The default pass is the last pass + * and is used by most drivers. Drivers needed by the scheduler are + * probed in earlier passes. + */ +#define BUS_PASS_ROOT 0 /* Used to attach root0. */ +#define BUS_PASS_BUS 10 /* Buses and bridges. */ +#define BUS_PASS_CPU 20 /* CPU devices. */ +#define BUS_PASS_RESOURCE 30 /* Resource discovery. */ +#define BUS_PASS_INTERRUPT 40 /* Interrupt controllers. */ +#define BUS_PASS_TIMER 50 /* Timers and clocks. */ +#define BUS_PASS_SCHEDULER 60 /* Start scheduler. */ +#define BUS_PASS_SUPPORTDEV 100000 /* Drivers which support DEFAULT drivers. */ +#define BUS_PASS_DEFAULT __INT_MAX /* Everything else. */ + +#define BUS_PASS_ORDER_FIRST 0 +#define BUS_PASS_ORDER_EARLY 2 +#define BUS_PASS_ORDER_MIDDLE 5 +#define BUS_PASS_ORDER_LATE 7 +#define BUS_PASS_ORDER_LAST 9 + +extern int bus_current_pass; + +void bus_set_pass(int pass); + +/** + * Shorthands for constructing method tables. + */ +#define DEVMETHOD KOBJMETHOD +#define DEVMETHOD_END KOBJMETHOD_END + +/* + * Some common device interfaces. + */ +#include "device_if.h" +#include "bus_if.h" + +struct module; + +int driver_module_handler(struct module *, int, void *); + +/** + * Module support for automatically adding drivers to buses. + */ +struct driver_module_data { + int (*dmd_chainevh)(struct module *, int, void *); + void *dmd_chainarg; + const char *dmd_busname; + kobj_class_t dmd_driver; + devclass_t *dmd_devclass; + int dmd_pass; +}; + +#define EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass, \ + evh, arg, order, pass) \ + \ +static struct driver_module_data name##_##busname##_driver_mod = { \ + evh, arg, \ + #busname, \ + (kobj_class_t) &driver, \ + &devclass, \ + pass \ +}; \ + \ +static moduledata_t name##_##busname##_mod = { \ + #busname "/" #name, \ + driver_module_handler, \ + &name##_##busname##_driver_mod \ +}; \ +DECLARE_MODULE(name##_##busname, name##_##busname##_mod, \ + SI_SUB_DRIVERS, order) + +#define EARLY_DRIVER_MODULE(name, busname, driver, devclass, evh, arg, pass) \ + EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass, \ + evh, arg, SI_ORDER_MIDDLE, pass) + +#define DRIVER_MODULE_ORDERED(name, busname, driver, devclass, evh, arg,\ + order) \ + EARLY_DRIVER_MODULE_ORDERED(name, busname, driver, devclass, \ + evh, arg, order, BUS_PASS_DEFAULT) + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + EARLY_DRIVER_MODULE(name, busname, driver, devclass, evh, arg, \ + BUS_PASS_DEFAULT) + +/** + * Generic ivar accessor generation macros for bus drivers + */ +#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \ + \ +static __inline type varp ## _get_ ## var(device_t dev) \ +{ \ + uintptr_t v; \ + int e; \ + e = BUS_READ_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, &v); \ + KASSERT(e == 0, ("%s failed for %s on bus %s, error = %d", \ + __func__, device_get_nameunit(dev), \ + device_get_nameunit(device_get_parent(dev)), e)); \ + return ((type) v); \ +} \ + \ +static __inline void varp ## _set_ ## var(device_t dev, type t) \ +{ \ + uintptr_t v = (uintptr_t) t; \ + int e; \ + e = BUS_WRITE_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, v); \ + KASSERT(e == 0, ("%s failed for %s on bus %s, error = %d", \ + __func__, device_get_nameunit(dev), \ + device_get_nameunit(device_get_parent(dev)), e)); \ +} + +/** + * Shorthand macros, taking resource argument + * Generated with sys/tools/bus_macro.sh + */ + +#define bus_barrier(r, o, l, f) \ + bus_space_barrier((r)->r_bustag, (r)->r_bushandle, (o), (l), (f)) +#define bus_read_1(r, o) \ + bus_space_read_1((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_1(r, o, d, c) \ + bus_space_read_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_1(r, o, d, c) \ + bus_space_read_region_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_1(r, o, v, c) \ + bus_space_set_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_1(r, o, v, c) \ + bus_space_set_region_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_1(r, o, v) \ + bus_space_write_1((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_1(r, o, d, c) \ + bus_space_write_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_1(r, o, d, c) \ + bus_space_write_region_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_1(r, o) \ + bus_space_read_stream_1((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_1(r, o, d, c) \ + bus_space_read_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_1(r, o, d, c) \ + bus_space_read_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_1(r, o, v, c) \ + bus_space_set_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_1(r, o, v, c) \ + bus_space_set_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_1(r, o, v) \ + bus_space_write_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_1(r, o, d, c) \ + bus_space_write_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_1(r, o, d, c) \ + bus_space_write_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_2(r, o) \ + bus_space_read_2((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_2(r, o, d, c) \ + bus_space_read_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_2(r, o, d, c) \ + bus_space_read_region_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_2(r, o, v, c) \ + bus_space_set_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_2(r, o, v, c) \ + bus_space_set_region_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_2(r, o, v) \ + bus_space_write_2((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_2(r, o, d, c) \ + bus_space_write_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_2(r, o, d, c) \ + bus_space_write_region_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_2(r, o) \ + bus_space_read_stream_2((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_2(r, o, d, c) \ + bus_space_read_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_2(r, o, d, c) \ + bus_space_read_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_2(r, o, v, c) \ + bus_space_set_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_2(r, o, v, c) \ + bus_space_set_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_2(r, o, v) \ + bus_space_write_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_2(r, o, d, c) \ + bus_space_write_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_2(r, o, d, c) \ + bus_space_write_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_4(r, o) \ + bus_space_read_4((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_4(r, o, d, c) \ + bus_space_read_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_4(r, o, d, c) \ + bus_space_read_region_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_4(r, o, v, c) \ + bus_space_set_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_4(r, o, v, c) \ + bus_space_set_region_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_4(r, o, v) \ + bus_space_write_4((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_4(r, o, d, c) \ + bus_space_write_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_4(r, o, d, c) \ + bus_space_write_region_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_4(r, o) \ + bus_space_read_stream_4((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_4(r, o, d, c) \ + bus_space_read_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_4(r, o, d, c) \ + bus_space_read_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_4(r, o, v, c) \ + bus_space_set_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_4(r, o, v, c) \ + bus_space_set_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_4(r, o, v) \ + bus_space_write_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_4(r, o, d, c) \ + bus_space_write_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_4(r, o, d, c) \ + bus_space_write_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_8(r, o) \ + bus_space_read_8((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_8(r, o, d, c) \ + bus_space_read_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_8(r, o, d, c) \ + bus_space_read_region_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_8(r, o, v, c) \ + bus_space_set_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_8(r, o, v, c) \ + bus_space_set_region_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_8(r, o, v) \ + bus_space_write_8((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_8(r, o, d, c) \ + bus_space_write_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_8(r, o, d, c) \ + bus_space_write_region_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_8(r, o) \ + bus_space_read_stream_8((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_8(r, o, d, c) \ + bus_space_read_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_8(r, o, d, c) \ + bus_space_read_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_8(r, o, v, c) \ + bus_space_set_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_8(r, o, v, c) \ + bus_space_set_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_8(r, o, v) \ + bus_space_write_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_8(r, o, d, c) \ + bus_space_write_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_8(r, o, d, c) \ + bus_space_write_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#endif /* _KERNEL */ + +#endif /* !_SYS_BUS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bus_dma.h b/lib/libc/include/any-freebsd-any/sys/bus_dma.h new file mode 100644 index 000000000000..e99d8ecebe11 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bus_dma.h @@ -0,0 +1,310 @@ +/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ + +/*- + * SPDX-License-Identifier: (BSD-2-Clause-NetBSD AND BSD-4-Clause) + * + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* $FreeBSD$ */ + +#ifndef _BUS_DMA_H_ +#define _BUS_DMA_H_ + +#ifdef _KERNEL +#include +#endif + +/* + * Machine independent interface for mapping physical addresses to peripheral + * bus 'physical' addresses, and assisting with DMA operations. + * + * XXX This file is always included from and should not + * (yet) be included directly. + */ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ +#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x20 +#define BUS_DMA_BUS3 0x40 +#define BUS_DMA_BUS4 0x80 + +/* + * The following two flags are non-standard or specific to only certain + * architectures + */ +#define BUS_DMA_NOWRITE 0x100 +#define BUS_DMA_NOCACHE 0x200 + +/* + * The following flag is a DMA tag hint that the page offset of the + * loaded kernel virtual address must be preserved in the first + * physical segment address, when the KVA is loaded into DMA. + */ +#define BUS_DMA_KEEP_PG_OFFSET 0x400 + +#define BUS_DMA_LOAD_MBUF 0x800 + +/* Forwards needed by prototypes below. */ +union ccb; +struct bio; +struct mbuf; +struct memdesc; +struct pmap; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 1 +#define BUS_DMASYNC_POSTREAD 2 +#define BUS_DMASYNC_PREWRITE 4 +#define BUS_DMASYNC_POSTWRITE 8 + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +typedef struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ +} bus_dma_segment_t; + +#ifdef _KERNEL +/* + * A function that returns 1 if the address cannot be accessed by + * a device and 0 if it can be. + */ +typedef int bus_dma_filter_t(void *, bus_addr_t); + +/* + * Generic helper function for manipulating mutexes. + */ +void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); + +/* + * Allocate a device specific dma_tag encapsulating the constraints of + * the parent tag in addition to other restrictions specified: + * + * alignment: Alignment for segments. + * boundary: Boundary that segments cannot cross. + * lowaddr: Low restricted address that cannot appear in a mapping. + * highaddr: High restricted address that cannot appear in a mapping. + * filtfunc: An optional function to further test if an address + * within the range of lowaddr and highaddr cannot appear + * in a mapping. + * filtfuncarg: An argument that will be passed to filtfunc in addition + * to the address to test. + * maxsize: Maximum mapping size supported by this tag. + * nsegments: Number of discontinuities allowed in maps. + * maxsegsz: Maximum size of a segment in the map. + * flags: Bus DMA flags. + * lockfunc: An optional function to handle driver-defined lock + * operations. + * lockfuncarg: An argument that will be passed to lockfunc in addition + * to the lock operation. + * dmat: A pointer to set to a valid dma tag should the return + * value of this function indicate success. + */ +/* XXX Should probably allow specification of alignment */ +int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, + bus_addr_t boundary, bus_addr_t lowaddr, + bus_addr_t highaddr, bus_dma_filter_t *filtfunc, + void *filtfuncarg, bus_size_t maxsize, int nsegments, + bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat); + +/* + * Set the memory domain to be used for allocations. + * + * Automatic for PCI devices. Must be set prior to creating maps or + * allocating memory. + */ +int bus_dma_tag_set_domain(bus_dma_tag_t dmat, int domain); + +int bus_dma_tag_destroy(bus_dma_tag_t dmat); + +/* + * A function that processes a successfully loaded dma map or an error + * from a delayed load map. + */ +typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); + +/* + * Like bus_dmamap_callback but includes map size in bytes. This is + * defined as a separate interface to maintain compatibility for users + * of bus_dmamap_callback_t--at some point these interfaces should be merged. + */ +typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); + +/* + * Map the buffer buf into bus space using the dmamap map. + */ +int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, bus_dmamap_callback_t *callback, + void *callback_arg, int flags); + +/* + * Like bus_dmamap_load but for mbufs. Note the use of the + * bus_dmamap_callback2_t interface. + */ +int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *mbuf, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags); + +int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *mbuf, bus_dma_segment_t *segs, + int *nsegs, int flags); + +/* + * Like bus_dmamap_load but for uios. Note the use of the + * bus_dmamap_callback2_t interface. + */ +int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, + struct uio *ui, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags); + +/* + * Like bus_dmamap_load but for cam control blocks. + */ +int bus_dmamap_load_ccb(bus_dma_tag_t dmat, bus_dmamap_t map, union ccb *ccb, + bus_dmamap_callback_t *callback, void *callback_arg, + int flags); + +/* + * Like bus_dmamap_load but for bios. + */ +int bus_dmamap_load_bio(bus_dma_tag_t dmat, bus_dmamap_t map, struct bio *bio, + bus_dmamap_callback_t *callback, void *callback_arg, + int flags); + +/* + * Loads any memory descriptor. + */ +int bus_dmamap_load_mem(bus_dma_tag_t dmat, bus_dmamap_t map, + struct memdesc *mem, bus_dmamap_callback_t *callback, + void *callback_arg, int flags); + +/* + * Placeholder for use by busdma implementations which do not benefit + * from optimized procedure to load an array of vm_page_t. Falls back + * to do _bus_dmamap_load_phys() in loop. + */ +int bus_dmamap_load_ma_triv(bus_dma_tag_t dmat, bus_dmamap_t map, + struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags, + bus_dma_segment_t *segs, int *segp); + +#ifdef WANT_INLINE_DMAMAP +#define BUS_DMAMAP_OP static inline +#else +#define BUS_DMAMAP_OP +#endif + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +BUS_DMAMAP_OP int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +BUS_DMAMAP_OP int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints listed in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +BUS_DMAMAP_OP int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp); + +/* + * Free a piece of memory and its allocated dmamap, that was allocated + * via bus_dmamem_alloc. + */ +BUS_DMAMAP_OP void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); + +/* + * Perform a synchronization operation on the given map. If the map + * is NULL we have a fully IO-coherent system. + */ +BUS_DMAMAP_OP void bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t dmamap, bus_dmasync_op_t op); + +/* + * Release the mapping held by map. + */ +BUS_DMAMAP_OP void bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t dmamap); + +#undef BUS_DMAMAP_OP +#endif /* _KERNEL */ + +#endif /* _BUS_DMA_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/bus_dma_internal.h b/lib/libc/include/any-freebsd-any/sys/bus_dma_internal.h new file mode 100644 index 000000000000..ca67eb343975 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/bus_dma_internal.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017 Jason A. Harmening. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _BUS_DMA_INTERNAL_H_ +#define _BUS_DMA_INTERNAL_H_ + +/* + * The following functions define the interface between the MD and MI + * busdma layers. These are not intended for consumption by driver + * software. + */ + +bus_dma_segment_t *_bus_dmamap_complete(bus_dma_tag_t dmat, + bus_dmamap_t map, bus_dma_segment_t *segs, + int nsegs, int error); + +int _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, + void *buf, bus_size_t buflen, struct pmap *pmap, + int flags, bus_dma_segment_t *segs, int *segp); + +int _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, + struct vm_page **ma, bus_size_t tlen, int ma_offs, + int flags, bus_dma_segment_t *segs, int *segp); + +int _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, + vm_paddr_t paddr, bus_size_t buflen, + int flags, bus_dma_segment_t *segs, int *segp); + +void _bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, + struct memdesc *mem, bus_dmamap_callback_t *callback, + void *callback_arg); + +#endif /* !_BUS_DMA_INTERNAL_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/sys/busdma_bufalloc.h b/lib/libc/include/any-freebsd-any/sys/busdma_bufalloc.h new file mode 100644 index 000000000000..fe281212d20a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/busdma_bufalloc.h @@ -0,0 +1,120 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Ian Lepore + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * $FreeBSD$ + */ + +/* + * A buffer pool manager, for use by a platform's busdma implementation. + */ + +#ifndef _MACHINE_BUSDMA_BUFALLOC_H_ +#define _MACHINE_BUSDMA_BUFALLOC_H_ + +#include +#include + +/* + * Information about a buffer zone, returned by busdma_bufalloc_findzone(). + */ +struct busdma_bufzone { + bus_size_t size; + uma_zone_t umazone; + char name[24]; +}; + +/* + * Opaque handle type returned by busdma_bufalloc_create(). + */ +struct busdma_bufalloc; +typedef struct busdma_bufalloc *busdma_bufalloc_t; + +/* + * Create an allocator that manages a pool of DMA buffers. + * + * The allocator manages a collection of uma(9) zones of buffers in power-of-two + * sized increments ranging from minimum_alignment to the platform's PAGE_SIZE. + * The buffers within each zone are aligned on boundaries corresponding to the + * buffer size, and thus by implication each buffer is contiguous within a page + * and does not cross a power of two boundary larger than the buffer size. + * These rules are intended to make it easy for a busdma implementation to + * check whether a tag's constraints allow use of a buffer from the allocator. + * + * minimum_alignment is also the minimum buffer allocation size. For platforms + * with software-assisted cache coherency, this is typically the data cache line + * size (and MUST not be smaller than the cache line size). + * + * name appears in zone stats as 'dma name nnnnn' where 'dma' is fixed and + * 'nnnnn' is the size of buffers in that zone. + * + * If the alloc/free function pointers are NULL, the regular uma internal + * allocators are used (I.E., you get "plain old kernel memory"). On a platform + * with an exclusion zone that applies to all DMA operations, a custom allocator + * could be used to ensure no buffer memory is ever allocated from that zone, + * allowing the bus_dmamem_alloc() implementation to make the assumption that + * buffers provided by the allocation could never lead to the need for a bounce. + */ +busdma_bufalloc_t busdma_bufalloc_create(const char *name, + bus_size_t minimum_alignment, + uma_alloc uma_alloc_func, uma_free uma_free_func, + u_int32_t uma_zcreate_flags); + +/* + * Destroy an allocator created by busdma_bufalloc_create(). + * Safe to call with a NULL pointer. + */ +void busdma_bufalloc_destroy(busdma_bufalloc_t ba); + +/* + * Return a pointer to the busdma_bufzone that should be used to allocate or + * free a buffer of the given size. Returns NULL if the size is larger than the + * largest zone handled by the allocator. + */ +struct busdma_bufzone * busdma_bufalloc_findzone(busdma_bufalloc_t ba, + bus_size_t size); + +/* + * These built-in allocation routines are available for managing a pools of + * uncacheable memory on platforms that support VM_MEMATTR_UNCACHEABLE. + * + * Allocation is done using kmem_alloc_attr() with these parameters: + * lowaddr = 0 + * highaddr = BUS_SPACE_MAXADDR + * memattr = VM_MEMATTR_UNCACHEABLE. + * + * If your platform has no exclusion region (lowaddr/highaddr), and its pmap + * routines support pmap_page_set_memattr() and the VM_MEMATTR_UNCACHEABLE flag + * you can probably use these when you need uncacheable buffers. + */ +void * busdma_bufalloc_alloc_uncacheable(uma_zone_t zone, vm_size_t size, + int domain, uint8_t *pflag, int wait); +void busdma_bufalloc_free_uncacheable(void *item, vm_size_t size, + uint8_t pflag); + +#endif /* _MACHINE_BUSDMA_BUFALLOC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/callout.h b/lib/libc/include/any-freebsd-any/sys/callout.h new file mode 100644 index 000000000000..e4d91c69da3f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/callout.h @@ -0,0 +1,140 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)callout.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_CALLOUT_H_ +#define _SYS_CALLOUT_H_ + +#include + +#define CALLOUT_LOCAL_ALLOC 0x0001 /* was allocated from callfree */ +#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */ +#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */ +#define CALLOUT_MPSAFE 0x0008 /* deprecated */ +#define CALLOUT_RETURNUNLOCKED 0x0010 /* handler returns with mtx unlocked */ +#define CALLOUT_SHAREDLOCK 0x0020 /* callout lock held in shared mode */ +#define CALLOUT_DFRMIGRATION 0x0040 /* callout in deferred migration mode */ +#define CALLOUT_PROCESSED 0x0080 /* callout in wheel or processing list? */ +#define CALLOUT_DIRECT 0x0100 /* allow exec from hw int context */ + +#define C_DIRECT_EXEC 0x0001 /* direct execution of callout */ +#define C_PRELBITS 7 +#define C_PRELRANGE ((1 << C_PRELBITS) - 1) +#define C_PREL(x) (((x) + 1) << 1) +#define C_PRELGET(x) (int)((((x) >> 1) & C_PRELRANGE) - 1) +#define C_HARDCLOCK 0x0100 /* align to hardclock() calls */ +#define C_ABSOLUTE 0x0200 /* event time is absolute. */ +#define C_PRECALC 0x0400 /* event time is pre-calculated. */ +#define C_CATCH 0x0800 /* catch signals, used by pause_sbt(9) */ + +struct callout_handle { + struct callout *callout; +}; + +/* Flags for callout_stop_safe() */ +#define CS_DRAIN 0x0001 /* callout_drain(), wait allowed */ +#define CS_EXECUTING 0x0002 /* Positive return value indicates that + the callout was executing */ + +#ifdef _KERNEL +/* + * Note the flags field is actually *two* fields. The c_flags + * field is the one that caller operations that may, or may not have + * a lock touches i.e. callout_deactivate(). The other, the c_iflags, + * is the internal flags that *must* be kept correct on which the + * callout system depend on e.g. callout_pending(). + * The c_iflag is used internally by the callout system to determine which + * list the callout is on and track internal state. Callers *should not* + * use the c_flags field directly but should use the macros provided. + * + * The c_iflags field holds internal flags that are protected by internal + * locks of the callout subsystem. The c_flags field holds external flags. + * The caller must hold its own lock while manipulating or reading external + * flags via callout_active(), callout_deactivate(), callout_reset*(), or + * callout_stop() to avoid races. + */ +#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE) +#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE) +#define callout_drain(c) _callout_stop_safe(c, CS_DRAIN, NULL) +void callout_init(struct callout *, int); +void _callout_init_lock(struct callout *, struct lock_object *, int); +#define callout_init_mtx(c, mtx, flags) \ + _callout_init_lock((c), ((mtx) != NULL) ? &(mtx)->lock_object : \ + NULL, (flags)) +#define callout_init_rm(c, rm, flags) \ + _callout_init_lock((c), ((rm) != NULL) ? &(rm)->lock_object : \ + NULL, (flags)) +#define callout_init_rw(c, rw, flags) \ + _callout_init_lock((c), ((rw) != NULL) ? &(rw)->lock_object : \ + NULL, (flags)) +#define callout_pending(c) ((c)->c_iflags & CALLOUT_PENDING) +int callout_reset_sbt_on(struct callout *, sbintime_t, sbintime_t, + void (*)(void *), void *, int, int); +#define callout_reset_sbt(c, sbt, pr, fn, arg, flags) \ + callout_reset_sbt_on((c), (sbt), (pr), (fn), (arg), -1, (flags)) +#define callout_reset_sbt_curcpu(c, sbt, pr, fn, arg, flags) \ + callout_reset_sbt_on((c), (sbt), (pr), (fn), (arg), PCPU_GET(cpuid),\ + (flags)) +#define callout_reset_on(c, to_ticks, fn, arg, cpu) \ + callout_reset_sbt_on((c), tick_sbt * (to_ticks), 0, (fn), (arg), \ + (cpu), C_HARDCLOCK) +#define callout_reset(c, on_tick, fn, arg) \ + callout_reset_on((c), (on_tick), (fn), (arg), -1) +#define callout_reset_curcpu(c, on_tick, fn, arg) \ + callout_reset_on((c), (on_tick), (fn), (arg), PCPU_GET(cpuid)) +#define callout_schedule_sbt_on(c, sbt, pr, cpu, flags) \ + callout_reset_sbt_on((c), (sbt), (pr), (c)->c_func, (c)->c_arg, \ + (cpu), (flags)) +#define callout_schedule_sbt(c, sbt, pr, flags) \ + callout_schedule_sbt_on((c), (sbt), (pr), -1, (flags)) +#define callout_schedule_sbt_curcpu(c, sbt, pr, flags) \ + callout_schedule_sbt_on((c), (sbt), (pr), PCPU_GET(cpuid), (flags)) +int callout_schedule(struct callout *, int); +int callout_schedule_on(struct callout *, int, int); +#define callout_schedule_curcpu(c, on_tick) \ + callout_schedule_on((c), (on_tick), PCPU_GET(cpuid)) +#define callout_stop(c) _callout_stop_safe(c, 0, NULL) +int _callout_stop_safe(struct callout *, int, void (*)(void *)); +void callout_process(sbintime_t now); +#define callout_async_drain(c, d) \ + _callout_stop_safe(c, 0, d) +void callout_when(sbintime_t sbt, sbintime_t precision, int flags, + sbintime_t *sbt_res, sbintime_t *prec_res); +#endif + +#endif /* _SYS_CALLOUT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/capability.h b/lib/libc/include/any-freebsd-any/sys/capability.h new file mode 100644 index 000000000000..39195e034c56 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/capability.h @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 Robert N. M. Watson + * All rights reserved. + * + * This software was developed at the University of Cambridge Computer + * Laboratory with support from a grant from Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Historically, the key userspace and kernel Capsicum definitions were found + * in this file. However, it conflicted with POSIX.1e's capability.h, so has + * been renamed capsicum.h. The file remains for backwards compatibility + * reasons as a nested include. It is expected to be removed before + * FreeBSD 13. + */ +#ifndef _SYS_CAPABILITY_H_ +#define _SYS_CAPABILITY_H_ + +#warning this file includes which is deprecated +#include + +#endif /* !_SYS_CAPABILITY_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/caprights.h b/lib/libc/include/any-freebsd-any/sys/caprights.h new file mode 100644 index 000000000000..8698483ce22c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/caprights.h @@ -0,0 +1,63 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CAPRIGHTS_H_ +#define _SYS_CAPRIGHTS_H_ + +/* + * The top two bits in the first element of the cr_rights[] array contain + * total number of elements in the array - 2. This means if those two bits are + * equal to 0, we have 2 array elements. + * The top two bits in all remaining array elements should be 0. + * The next five bits contain array index. Only one bit is used and bit position + * in this five-bits range defines array index. This means there can be at most + * five array elements. + */ +#define CAP_RIGHTS_VERSION_00 0 +/* +#define CAP_RIGHTS_VERSION_01 1 +#define CAP_RIGHTS_VERSION_02 2 +#define CAP_RIGHTS_VERSION_03 3 +*/ +#define CAP_RIGHTS_VERSION CAP_RIGHTS_VERSION_00 + +struct cap_rights { + uint64_t cr_rights[CAP_RIGHTS_VERSION + 2]; +}; + +#ifndef _CAP_RIGHTS_T_DECLARED +#define _CAP_RIGHTS_T_DECLARED +typedef struct cap_rights cap_rights_t; +#endif + +#endif /* !_SYS_CAPRIGHTS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/capsicum.h b/lib/libc/include/any-freebsd-any/sys/capsicum.h new file mode 100644 index 000000000000..71be7011eae9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/capsicum.h @@ -0,0 +1,486 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008-2010, 2015 Robert N. M. Watson + * Copyright (c) 2012 FreeBSD Foundation + * All rights reserved. + * + * This software was developed at the University of Cambridge Computer + * Laboratory with support from a grant from Google, Inc. + * + * Portions of this software were developed by Pawel Jakub Dawidek under + * sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Definitions for FreeBSD capabilities facility. + */ +#ifndef _SYS_CAPSICUM_H_ +#define _SYS_CAPSICUM_H_ + +#include +#include + +#include +#include +#include + +#ifndef _KERNEL +#include +#endif + +#define CAPRIGHT(idx, bit) ((1ULL << (57 + (idx))) | (bit)) + +/* + * Possible rights on capabilities. + * + * Notes: + * Some system calls don't require a capability in order to perform an + * operation on an fd. These include: close, dup, dup2. + * + * sendfile is authorized using CAP_READ on the file and CAP_WRITE on the + * socket. + * + * mmap() and aio*() system calls will need special attention as they may + * involve reads or writes depending a great deal on context. + */ + +/* INDEX 0 */ + +/* + * General file I/O. + */ +/* Allows for openat(O_RDONLY), read(2), readv(2). */ +#define CAP_READ CAPRIGHT(0, 0x0000000000000001ULL) +/* Allows for openat(O_WRONLY | O_APPEND), write(2), writev(2). */ +#define CAP_WRITE CAPRIGHT(0, 0x0000000000000002ULL) +/* Allows for lseek(fd, 0, SEEK_CUR). */ +#define CAP_SEEK_TELL CAPRIGHT(0, 0x0000000000000004ULL) +/* Allows for lseek(2). */ +#define CAP_SEEK (CAP_SEEK_TELL | 0x0000000000000008ULL) +/* Allows for aio_read(2), pread(2), preadv(2). */ +#define CAP_PREAD (CAP_SEEK | CAP_READ) +/* + * Allows for aio_write(2), openat(O_WRONLY) (without O_APPEND), pwrite(2), + * pwritev(2). + */ +#define CAP_PWRITE (CAP_SEEK | CAP_WRITE) +/* Allows for mmap(PROT_NONE). */ +#define CAP_MMAP CAPRIGHT(0, 0x0000000000000010ULL) +/* Allows for mmap(PROT_READ). */ +#define CAP_MMAP_R (CAP_MMAP | CAP_SEEK | CAP_READ) +/* Allows for mmap(PROT_WRITE). */ +#define CAP_MMAP_W (CAP_MMAP | CAP_SEEK | CAP_WRITE) +/* Allows for mmap(PROT_EXEC). */ +#define CAP_MMAP_X (CAP_MMAP | CAP_SEEK | 0x0000000000000020ULL) +/* Allows for mmap(PROT_READ | PROT_WRITE). */ +#define CAP_MMAP_RW (CAP_MMAP_R | CAP_MMAP_W) +/* Allows for mmap(PROT_READ | PROT_EXEC). */ +#define CAP_MMAP_RX (CAP_MMAP_R | CAP_MMAP_X) +/* Allows for mmap(PROT_WRITE | PROT_EXEC). */ +#define CAP_MMAP_WX (CAP_MMAP_W | CAP_MMAP_X) +/* Allows for mmap(PROT_READ | PROT_WRITE | PROT_EXEC). */ +#define CAP_MMAP_RWX (CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X) +/* Allows for openat(O_CREAT). */ +#define CAP_CREATE CAPRIGHT(0, 0x0000000000000040ULL) +/* Allows for openat(O_EXEC) and fexecve(2) in turn. */ +#define CAP_FEXECVE CAPRIGHT(0, 0x0000000000000080ULL) +/* Allows for openat(O_SYNC), openat(O_FSYNC), fsync(2), aio_fsync(2). */ +#define CAP_FSYNC CAPRIGHT(0, 0x0000000000000100ULL) +/* Allows for openat(O_TRUNC), ftruncate(2). */ +#define CAP_FTRUNCATE CAPRIGHT(0, 0x0000000000000200ULL) + +/* Lookups - used to constrain *at() calls. */ +#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL) + +/* VFS methods. */ +/* Allows for fchdir(2). */ +#define CAP_FCHDIR CAPRIGHT(0, 0x0000000000000800ULL) +/* Allows for fchflags(2). */ +#define CAP_FCHFLAGS CAPRIGHT(0, 0x0000000000001000ULL) +/* Allows for fchflags(2) and chflagsat(2). */ +#define CAP_CHFLAGSAT (CAP_FCHFLAGS | CAP_LOOKUP) +/* Allows for fchmod(2). */ +#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL) +/* Allows for fchmod(2) and fchmodat(2). */ +#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP) +/* Allows for fchown(2). */ +#define CAP_FCHOWN CAPRIGHT(0, 0x0000000000004000ULL) +/* Allows for fchown(2) and fchownat(2). */ +#define CAP_FCHOWNAT (CAP_FCHOWN | CAP_LOOKUP) +/* Allows for fcntl(2). */ +#define CAP_FCNTL CAPRIGHT(0, 0x0000000000008000ULL) +/* + * Allows for flock(2), openat(O_SHLOCK), openat(O_EXLOCK), + * fcntl(F_SETLK_REMOTE), fcntl(F_SETLKW), fcntl(F_SETLK), fcntl(F_GETLK). + */ +#define CAP_FLOCK CAPRIGHT(0, 0x0000000000010000ULL) +/* Allows for fpathconf(2). */ +#define CAP_FPATHCONF CAPRIGHT(0, 0x0000000000020000ULL) +/* Allows for UFS background-fsck operations. */ +#define CAP_FSCK CAPRIGHT(0, 0x0000000000040000ULL) +/* Allows for fstat(2). */ +#define CAP_FSTAT CAPRIGHT(0, 0x0000000000080000ULL) +/* Allows for fstat(2), fstatat(2) and faccessat(2). */ +#define CAP_FSTATAT (CAP_FSTAT | CAP_LOOKUP) +/* Allows for fstatfs(2). */ +#define CAP_FSTATFS CAPRIGHT(0, 0x0000000000100000ULL) +/* Allows for futimens(2) and futimes(2). */ +#define CAP_FUTIMES CAPRIGHT(0, 0x0000000000200000ULL) +/* Allows for futimens(2), futimes(2), futimesat(2) and utimensat(2). */ +#define CAP_FUTIMESAT (CAP_FUTIMES | CAP_LOOKUP) +/* Allows for linkat(2) (target directory descriptor). */ +#define CAP_LINKAT_TARGET (CAP_LOOKUP | 0x0000000000400000ULL) +/* Allows for mkdirat(2). */ +#define CAP_MKDIRAT (CAP_LOOKUP | 0x0000000000800000ULL) +/* Allows for mkfifoat(2). */ +#define CAP_MKFIFOAT (CAP_LOOKUP | 0x0000000001000000ULL) +/* Allows for mknodat(2). */ +#define CAP_MKNODAT (CAP_LOOKUP | 0x0000000002000000ULL) +/* Allows for renameat(2) (source directory descriptor). */ +#define CAP_RENAMEAT_SOURCE (CAP_LOOKUP | 0x0000000004000000ULL) +/* Allows for symlinkat(2). */ +#define CAP_SYMLINKAT (CAP_LOOKUP | 0x0000000008000000ULL) +/* + * Allows for unlinkat(2) and renameat(2) if destination object exists and + * will be removed. + */ +#define CAP_UNLINKAT (CAP_LOOKUP | 0x0000000010000000ULL) + +/* Socket operations. */ +/* Allows for accept(2) and accept4(2). */ +#define CAP_ACCEPT CAPRIGHT(0, 0x0000000020000000ULL) +/* Allows for bind(2). */ +#define CAP_BIND CAPRIGHT(0, 0x0000000040000000ULL) +/* Allows for connect(2). */ +#define CAP_CONNECT CAPRIGHT(0, 0x0000000080000000ULL) +/* Allows for getpeername(2). */ +#define CAP_GETPEERNAME CAPRIGHT(0, 0x0000000100000000ULL) +/* Allows for getsockname(2). */ +#define CAP_GETSOCKNAME CAPRIGHT(0, 0x0000000200000000ULL) +/* Allows for getsockopt(2). */ +#define CAP_GETSOCKOPT CAPRIGHT(0, 0x0000000400000000ULL) +/* Allows for listen(2). */ +#define CAP_LISTEN CAPRIGHT(0, 0x0000000800000000ULL) +/* Allows for sctp_peeloff(2). */ +#define CAP_PEELOFF CAPRIGHT(0, 0x0000001000000000ULL) +#define CAP_RECV CAP_READ +#define CAP_SEND CAP_WRITE +/* Allows for setsockopt(2). */ +#define CAP_SETSOCKOPT CAPRIGHT(0, 0x0000002000000000ULL) +/* Allows for shutdown(2). */ +#define CAP_SHUTDOWN CAPRIGHT(0, 0x0000004000000000ULL) + +/* Allows for bindat(2) on a directory descriptor. */ +#define CAP_BINDAT (CAP_LOOKUP | 0x0000008000000000ULL) +/* Allows for connectat(2) on a directory descriptor. */ +#define CAP_CONNECTAT (CAP_LOOKUP | 0x0000010000000000ULL) + +/* Allows for linkat(2) (source directory descriptor). */ +#define CAP_LINKAT_SOURCE (CAP_LOOKUP | 0x0000020000000000ULL) +/* Allows for renameat(2) (target directory descriptor). */ +#define CAP_RENAMEAT_TARGET (CAP_LOOKUP | 0x0000040000000000ULL) + +#define CAP_SOCK_CLIENT \ + (CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \ + CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN) +#define CAP_SOCK_SERVER \ + (CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \ + CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \ + CAP_SETSOCKOPT | CAP_SHUTDOWN) + +/* All used bits for index 0. */ +#define CAP_ALL0 CAPRIGHT(0, 0x000007FFFFFFFFFFULL) + +/* Available bits for index 0. */ +#define CAP_UNUSED0_44 CAPRIGHT(0, 0x0000080000000000ULL) +/* ... */ +#define CAP_UNUSED0_57 CAPRIGHT(0, 0x0100000000000000ULL) + +/* INDEX 1 */ + +/* Mandatory Access Control. */ +/* Allows for mac_get_fd(3). */ +#define CAP_MAC_GET CAPRIGHT(1, 0x0000000000000001ULL) +/* Allows for mac_set_fd(3). */ +#define CAP_MAC_SET CAPRIGHT(1, 0x0000000000000002ULL) + +/* Methods on semaphores. */ +#define CAP_SEM_GETVALUE CAPRIGHT(1, 0x0000000000000004ULL) +#define CAP_SEM_POST CAPRIGHT(1, 0x0000000000000008ULL) +#define CAP_SEM_WAIT CAPRIGHT(1, 0x0000000000000010ULL) + +/* Allows select(2) and poll(2) on descriptor. */ +#define CAP_EVENT CAPRIGHT(1, 0x0000000000000020ULL) +/* Allows for kevent(2) on kqueue descriptor with eventlist != NULL. */ +#define CAP_KQUEUE_EVENT CAPRIGHT(1, 0x0000000000000040ULL) + +/* Strange and powerful rights that should not be given lightly. */ +/* Allows for ioctl(2). */ +#define CAP_IOCTL CAPRIGHT(1, 0x0000000000000080ULL) +#define CAP_TTYHOOK CAPRIGHT(1, 0x0000000000000100ULL) + +/* Process management via process descriptors. */ +/* Allows for pdgetpid(2). */ +#define CAP_PDGETPID CAPRIGHT(1, 0x0000000000000200ULL) +/* + * Allows for pdwait4(2). + * + * XXX: this constant was imported unused, but is targeted to be implemented + * in the future (bug 235871). + */ +#define CAP_PDWAIT CAPRIGHT(1, 0x0000000000000400ULL) +/* Allows for pdkill(2). */ +#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL) + +/* Extended attributes. */ +/* Allows for extattr_delete_fd(2). */ +#define CAP_EXTATTR_DELETE CAPRIGHT(1, 0x0000000000001000ULL) +/* Allows for extattr_get_fd(2). */ +#define CAP_EXTATTR_GET CAPRIGHT(1, 0x0000000000002000ULL) +/* Allows for extattr_list_fd(2). */ +#define CAP_EXTATTR_LIST CAPRIGHT(1, 0x0000000000004000ULL) +/* Allows for extattr_set_fd(2). */ +#define CAP_EXTATTR_SET CAPRIGHT(1, 0x0000000000008000ULL) + +/* Access Control Lists. */ +/* Allows for acl_valid_fd_np(3). */ +#define CAP_ACL_CHECK CAPRIGHT(1, 0x0000000000010000ULL) +/* Allows for acl_delete_fd_np(3). */ +#define CAP_ACL_DELETE CAPRIGHT(1, 0x0000000000020000ULL) +/* Allows for acl_get_fd(3) and acl_get_fd_np(3). */ +#define CAP_ACL_GET CAPRIGHT(1, 0x0000000000040000ULL) +/* Allows for acl_set_fd(3) and acl_set_fd_np(3). */ +#define CAP_ACL_SET CAPRIGHT(1, 0x0000000000080000ULL) + +/* Allows for kevent(2) on kqueue descriptor with changelist != NULL. */ +#define CAP_KQUEUE_CHANGE CAPRIGHT(1, 0x0000000000100000ULL) + +#define CAP_KQUEUE (CAP_KQUEUE_EVENT | CAP_KQUEUE_CHANGE) + +/* All used bits for index 1. */ +#define CAP_ALL1 CAPRIGHT(1, 0x00000000001FFFFFULL) + +/* Available bits for index 1. */ +#define CAP_UNUSED1_22 CAPRIGHT(1, 0x0000000000200000ULL) +/* ... */ +#define CAP_UNUSED1_57 CAPRIGHT(1, 0x0100000000000000ULL) + +/* Backward compatibility. */ +#define CAP_POLL_EVENT CAP_EVENT + +#define CAP_ALL(rights) do { \ + (rights)->cr_rights[0] = \ + ((uint64_t)CAP_RIGHTS_VERSION << 62) | CAP_ALL0; \ + (rights)->cr_rights[1] = CAP_ALL1; \ +} while (0) + +#define CAP_NONE(rights) do { \ + (rights)->cr_rights[0] = \ + ((uint64_t)CAP_RIGHTS_VERSION << 62) | CAPRIGHT(0, 0ULL); \ + (rights)->cr_rights[1] = CAPRIGHT(1, 0ULL); \ +} while (0) + +#define CAPRVER(right) ((int)((right) >> 62)) +#define CAPVER(rights) CAPRVER((rights)->cr_rights[0]) +#define CAPARSIZE(rights) (CAPVER(rights) + 2) +#define CAPIDXBIT(right) ((int)(((right) >> 57) & 0x1F)) + +/* + * Allowed fcntl(2) commands. + */ +#define CAP_FCNTL_GETFL (1 << F_GETFL) +#define CAP_FCNTL_SETFL (1 << F_SETFL) +#define CAP_FCNTL_GETOWN (1 << F_GETOWN) +#define CAP_FCNTL_SETOWN (1 << F_SETOWN) +#define CAP_FCNTL_ALL (CAP_FCNTL_GETFL | CAP_FCNTL_SETFL | \ + CAP_FCNTL_GETOWN | CAP_FCNTL_SETOWN) + +#define CAP_IOCTLS_ALL SSIZE_MAX + +__BEGIN_DECLS + +#define cap_rights_init(...) \ + __cap_rights_init(CAP_RIGHTS_VERSION, __VA_ARGS__, 0ULL) +cap_rights_t *__cap_rights_init(int version, cap_rights_t *rights, ...); + +#define cap_rights_set(...) \ + __cap_rights_set(__VA_ARGS__, 0ULL) +cap_rights_t *__cap_rights_set(cap_rights_t *rights, ...); + +#define cap_rights_clear(...) \ + __cap_rights_clear(__VA_ARGS__, 0ULL) +cap_rights_t *__cap_rights_clear(cap_rights_t *rights, ...); + +#define cap_rights_is_set(...) \ + __cap_rights_is_set(__VA_ARGS__, 0ULL) +bool __cap_rights_is_set(const cap_rights_t *rights, ...); + +bool cap_rights_is_valid(const cap_rights_t *rights); +cap_rights_t *cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src); +cap_rights_t *cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src); +bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little); + +__END_DECLS + +#ifdef _KERNEL + +#include +extern cap_rights_t cap_accept_rights; +extern cap_rights_t cap_bind_rights; +extern cap_rights_t cap_connect_rights; +extern cap_rights_t cap_event_rights; +extern cap_rights_t cap_fchdir_rights; +extern cap_rights_t cap_fchflags_rights; +extern cap_rights_t cap_fchmod_rights; +extern cap_rights_t cap_fchown_rights; +extern cap_rights_t cap_fcntl_rights; +extern cap_rights_t cap_fexecve_rights; +extern cap_rights_t cap_flock_rights; +extern cap_rights_t cap_fpathconf_rights; +extern cap_rights_t cap_fstat_rights; +extern cap_rights_t cap_fstatfs_rights; +extern cap_rights_t cap_fsync_rights; +extern cap_rights_t cap_ftruncate_rights; +extern cap_rights_t cap_futimes_rights; +extern cap_rights_t cap_getpeername_rights; +extern cap_rights_t cap_getsockopt_rights; +extern cap_rights_t cap_getsockname_rights; +extern cap_rights_t cap_ioctl_rights; +extern cap_rights_t cap_linkat_source_rights; +extern cap_rights_t cap_linkat_target_rights; +extern cap_rights_t cap_listen_rights; +extern cap_rights_t cap_mkdirat_rights; +extern cap_rights_t cap_mkfifoat_rights; +extern cap_rights_t cap_mknodat_rights; +extern cap_rights_t cap_mmap_rights; +extern cap_rights_t cap_no_rights; +extern cap_rights_t cap_pdgetpid_rights; +extern cap_rights_t cap_pdkill_rights; +extern cap_rights_t cap_pread_rights; +extern cap_rights_t cap_pwrite_rights; +extern cap_rights_t cap_read_rights; +extern cap_rights_t cap_recv_rights; +extern cap_rights_t cap_renameat_source_rights; +extern cap_rights_t cap_renameat_target_rights; +extern cap_rights_t cap_seek_rights; +extern cap_rights_t cap_send_rights; +extern cap_rights_t cap_send_connect_rights; +extern cap_rights_t cap_setsockopt_rights; +extern cap_rights_t cap_shutdown_rights; +extern cap_rights_t cap_symlinkat_rights; +extern cap_rights_t cap_unlinkat_rights; +extern cap_rights_t cap_write_rights; + +#define IN_CAPABILITY_MODE(td) (((td)->td_ucred->cr_flags & CRED_FLAG_CAPMODE) != 0) + +struct filedesc; +struct filedescent; + +/* + * Test whether a capability grants the requested rights. + */ +int cap_check(const cap_rights_t *havep, const cap_rights_t *needp); +/* + * Convert capability rights into VM access flags. + */ +vm_prot_t cap_rights_to_vmprot(const cap_rights_t *havep); + +/* + * For the purposes of procstat(1) and similar tools, allow kern_descrip.c to + * extract the rights from a capability. + * + * Dereferencing fdep requires filedesc.h, but including it would cause + * significant pollution. Instead add a macro for consumers which want it, + * most notably kern_descrip.c. + */ +#define cap_rights_fde_inline(fdep) (&(fdep)->fde_rights) + +const cap_rights_t *cap_rights_fde(const struct filedescent *fde); +const cap_rights_t *cap_rights(struct filedesc *fdp, int fd); + +int cap_ioctl_check(struct filedesc *fdp, int fd, u_long cmd); +int cap_fcntl_check_fde(struct filedescent *fde, int cmd); +int cap_fcntl_check(struct filedesc *fdp, int fd, int cmd); + +extern bool trap_enotcap; + +#else /* !_KERNEL */ + +__BEGIN_DECLS +/* + * cap_enter(): Cause the process to enter capability mode, which will + * prevent it from directly accessing global namespaces. System calls will + * be limited to process-local, process-inherited, or file descriptor + * operations. If already in capability mode, a no-op. + */ +int cap_enter(void); + +/* + * Are we sandboxed (in capability mode)? + * This is a libc wrapper around the cap_getmode(2) system call. + */ +bool cap_sandboxed(void); + +/* + * cap_getmode(): Are we in capability mode? + */ +int cap_getmode(u_int *modep); + +/* + * Limits capability rights for the given descriptor (CAP_*). + */ +int cap_rights_limit(int fd, const cap_rights_t *rights); +/* + * Returns capability rights for the given descriptor. + */ +#define cap_rights_get(fd, rights) \ + __cap_rights_get(CAP_RIGHTS_VERSION, (fd), (rights)) +int __cap_rights_get(int version, int fd, cap_rights_t *rights); +/* + * Limits allowed ioctls for the given descriptor. + */ +int cap_ioctls_limit(int fd, const cap_ioctl_t *cmds, size_t ncmds); +/* + * Returns array of allowed ioctls for the given descriptor. + * If all ioctls are allowed, the cmds array is not populated and + * the function returns CAP_IOCTLS_ALL. + */ +ssize_t cap_ioctls_get(int fd, cap_ioctl_t *cmds, size_t maxcmds); +/* + * Limits allowed fcntls for the given descriptor (CAP_FCNTL_*). + */ +int cap_fcntls_limit(int fd, uint32_t fcntlrights); +/* + * Returns bitmask of allowed fcntls for the given descriptor. + */ +int cap_fcntls_get(int fd, uint32_t *fcntlrightsp); + +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_CAPSICUM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cdefs.h b/lib/libc/include/any-freebsd-any/sys/cdefs.h new file mode 100644 index 000000000000..a2625a1ed5b4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cdefs.h @@ -0,0 +1,879 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ + +/* + * Testing against Clang-specific extensions. + */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#ifndef __has_extension +#define __has_extension __has_feature +#endif +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * This code has been put in place to help reduce the addition of + * compiler specific defines in FreeBSD code. It helps to aid in + * having a compiler-agnostic source tree. + */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) +#define __GNUCLIKE_ASM 3 +#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS +#else +#define __GNUCLIKE_ASM 2 +#endif +#define __GNUCLIKE___TYPEOF 1 +#define __GNUCLIKE___OFFSETOF 1 +#define __GNUCLIKE___SECTION 1 + +#ifndef __INTEL_COMPILER +#define __GNUCLIKE_CTOR_SECTION_HANDLING 1 +#endif + +#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 +#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ + __INTEL_COMPILER < 800 +#undef __GNUCLIKE_BUILTIN_CONSTANT_P +#endif + +#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) +#define __GNUCLIKE_BUILTIN_VARARGS 1 +#define __GNUCLIKE_BUILTIN_STDARG 1 +#define __GNUCLIKE_BUILTIN_VAALIST 1 +#endif + +#if defined(__GNUC__) +#define __GNUC_VA_LIST_COMPATIBILITY 1 +#endif + +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#endif + +#ifndef __INTEL_COMPILER +#define __GNUCLIKE_BUILTIN_NEXT_ARG 1 +#define __GNUCLIKE_MATH_BUILTIN_RELOPS +#endif + +#define __GNUCLIKE_BUILTIN_MEMCPY 1 + +/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ +#define __CC_SUPPORTS_INLINE 1 +#define __CC_SUPPORTS___INLINE 1 +#define __CC_SUPPORTS___INLINE__ 1 + +#define __CC_SUPPORTS___FUNC__ 1 +#define __CC_SUPPORTS_WARNING 1 + +#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ + +#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI + * mode -- there must be no spaces between its arguments, and for nested + * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also + * concatenate double-quoted strings produced by the __STRING macro, but + * this only works with ANSI C. + * + * __XSTRING is like __STRING, but it expands any macros in its argument + * first. It is only available with ANSI C. + */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) +#define __inline inline /* convert to C++ keyword */ +#else +#if !(defined(__CC_SUPPORTS___INLINE)) +#define __inline /* delete GCC keyword */ +#endif /* ! __CC_SUPPORTS___INLINE */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !defined(__CC_SUPPORTS___INLINE) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * When using a compiler other than gcc, programs using the ANSI C keywords + * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. + * When using "gcc -traditional", we assume that this is the intent; if + * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. + */ +#ifndef NO_ANSI_KEYWORDS +#define const /* delete ANSI C keywords */ +#define inline +#define signed +#define volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !__CC_SUPPORTS___INLINE */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * Compiler-dependent macros to help declare dead (non-returning) and + * pure (no side effects) functions, and unused variables. They are + * null except for versions of gcc that are known to support the features + * properly (old versions of gcc-2 supported the dead and pure features + * in a different (wrong) way). If we do not provide an implementation + * for a given compiler, let the compile fail if it is told to use + * a feature that we cannot live without. + */ +#define __weak_symbol __attribute__((__weak__)) +#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#define __dead2 +#define __pure2 +#define __unused +#endif +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused +/* XXX Find out what to do for __packed, __aligned and __section */ +#endif +#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __used __attribute__((__used__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif +#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) +#define __alloc_size(x) __attribute__((__alloc_size__(x))) +#define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x))) +#else +#define __alloc_size(x) +#define __alloc_size2(n, x) +#endif +#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) +#define __alloc_align(x) __attribute__((__alloc_align__(x))) +#else +#define __alloc_align(x) +#endif + +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + +/* + * Keywords added in C11. + */ + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L + +#if !__has_extension(c_alignas) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_alignas) +#define _Alignas(x) alignas(x) +#else +/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ +#define _Alignas(x) __aligned(x) +#endif +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(x) alignof(x) +#else +#define _Alignof(x) __alignof(x) +#endif + +#if !defined(__cplusplus) && !__has_extension(c_atomic) && \ + !__has_extension(cxx_atomic) && !__GNUC_PREREQ__(4, 7) +/* + * No native support for _Atomic(). Place object in structure to prevent + * most forms of direct non-atomic access. + */ +#define _Atomic(T) struct { T volatile __val; } +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Noreturn [[noreturn]] +#else +#define _Noreturn __dead2 +#endif + +#if !__has_extension(c_static_assert) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_static_assert) +#define _Static_assert(x, y) static_assert(x, y) +#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) +/* Nothing, gcc 4.6 and higher has _Static_assert built-in */ +#elif defined(__COUNTER__) +#define _Static_assert(x, y) __Static_assert(x, __COUNTER__) +#define __Static_assert(x, y) ___Static_assert(x, y) +#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ + __unused +#else +#define _Static_assert(x, y) struct __hack +#endif +#endif + +#if !__has_extension(c_thread_local) +/* + * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode + * without actually supporting the thread_local keyword. Don't check for + * the presence of C++11 when defining _Thread_local. + */ +#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ + __has_extension(cxx_thread_local) +#define _Thread_local thread_local +#else +#define _Thread_local __thread +#endif +#endif + +#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + +/* + * Emulation of C11 _Generic(). Unlike the previously defined C11 + * keywords, it is not possible to implement this using exactly the same + * syntax. Therefore implement something similar under the name + * __generic(). Unlike _Generic(), this macro can only distinguish + * between a single type, so it requires nested invocations to + * distinguish multiple cases. + */ + +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + __has_extension(c_generic_selections) +#define __generic(expr, t, yes, no) \ + _Generic(expr, t: yes, default: no) +#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) +#define __generic(expr, t, yes, no) \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof(expr), t), yes, no) +#endif + +/* + * C99 Static array indices in function parameter declarations. Syntax such as: + * void bar(int myArray[static 10]); + * is allowed in C99 but not in C++. Define __min_size appropriately so + * headers using it can be compiled in either language. Use like this: + * void bar(int myArray[__min_size(10)]); + */ +#if !defined(__cplusplus) && \ + (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ + (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) +#define __min_size(x) static (x) +#else +#define __min_size(x) (x) +#endif + +#if __GNUC_PREREQ__(2, 96) +#define __malloc_like __attribute__((__malloc__)) +#define __pure __attribute__((__pure__)) +#else +#define __malloc_like +#define __pure +#endif + +#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __always_inline __attribute__((__always_inline__)) +#else +#define __always_inline +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __noinline __attribute__ ((__noinline__)) +#else +#define __noinline +#endif + +#if __GNUC_PREREQ__(3, 4) +#define __fastcall __attribute__((__fastcall__)) +#define __result_use_check __attribute__((__warn_unused_result__)) +#else +#define __fastcall +#define __result_use_check +#endif + +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((__returns_twice__)) +#else +#define __returns_twice +#endif + +#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) +#define __unreachable() __builtin_unreachable() +#else +#define __unreachable() ((void)0) +#endif + +/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __func__ NULL +#endif + +#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 +#define __LONG_LONG_SUPPORTED +#endif + +/* C++11 exposes a load of C99 stuff */ +#if defined(__cplusplus) && __cplusplus >= 201103L +#define __LONG_LONG_SUPPORTED +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +#endif +#endif + +/* + * GCC 2.95 provides `__restrict' as an extension to C90 to support the + * C99-specific `restrict' type qualifier. We happen to use `__restrict' as + * a way to define the `restrict' type qualifier without disturbing older + * software that is unaware of C99 keywords. + */ +#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 +#define __restrict +#else +#define __restrict restrict +#endif +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect((exp), 1) +#define __predict_false(exp) __builtin_expect((exp), 0) +#else +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +#if __GNUC_PREREQ__(4, 0) +#define __null_sentinel __attribute__((__sentinel__)) +#define __exported __attribute__((__visibility__("default"))) +#define __hidden __attribute__((__visibility__("hidden"))) +#else +#define __null_sentinel +#define __exported +#define __hidden +#endif + +/* + * We define this here since , , and + * require it. + */ +#if __GNUC_PREREQ__(4, 1) +#define __offsetof(type, field) __builtin_offsetof(type, field) +#else +#ifndef __cplusplus +#define __offsetof(type, field) \ + ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) +#else +#define __offsetof(type, field) \ + (__offsetof__ (reinterpret_cast <__size_t> \ + (&reinterpret_cast \ + (static_cast (0)->field)))) +#endif +#endif +#define __rangeof(type, start, end) \ + (__offsetof(type, end) - __offsetof(type, start)) + +/* + * Given the pointer x to the member m of the struct s, return + * a pointer to the containing structure. When using GCC, we first + * assign pointer x to a local variable, to check that its type is + * compatible with member m. + */ +#if __GNUC_PREREQ__(3, 1) +#define __containerof(x, s, m) ({ \ + const volatile __typeof(((s *)0)->m) *__x = (x); \ + __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ +}) +#else +#define __containerof(x, s, m) \ + __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) +#endif + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __printflike(fmtarg, firstvararg) +#define __scanflike(fmtarg, firstvararg) +#define __format_arg(fmtarg) +#define __strfmonlike(fmtarg, firstvararg) +#define __strftimelike(fmtarg, firstvararg) +#else +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) +#define __strfmonlike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) +#define __strftimelike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) +#endif + +/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ +#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ + defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __printf0like(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) +#else +#define __printf0like(fmtarg, firstvararg) +#endif + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#ifndef __INTEL_COMPILER +#define __strong_reference(sym,aliassym) \ + extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) +#endif +#ifdef __STDC__ +#define __weak_reference(sym,alias) \ + __asm__(".weak " #alias); \ + __asm__(".equ " #alias ", " #sym) +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning." #sym); \ + __asm__(".asciz \"" msg "\""); \ + __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@" #verid) +#define __sym_default(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@@@" #verid) +#else +#define __weak_reference(sym,alias) \ + __asm__(".weak alias"); \ + __asm__(".equ alias, sym") +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning.sym"); \ + __asm__(".asciz \"msg\""); \ + __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver impl, sym@verid") +#define __sym_default(impl,sym,verid) \ + __asm__(".symver impl, sym@@@verid") +#endif /* __STDC__ */ +#endif /* __GNUC__ || __INTEL_COMPILER */ + +#define __GLOBL1(sym) __asm__(".globl " #sym) +#define __GLOBL(sym) __GLOBL1(sym) + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") +#else +/* + * The following definition might not work well if used in header files, + * but it should be better than nothing. If you want a "do nothing" + * version, then it should generate some harmless declaration, such as: + * #define __IDSTRING(name,string) struct __hack + */ +#define __IDSTRING(name,string) static const char name[] __unused = string +#endif + +/* + * Embed the rcs id of a source file in the resulting library. Note that in + * more recent ELF binutils, we use .ident allowing the ID to be stripped. + * Usage: + * __FBSDID("$FreeBSD$"); + */ +#ifndef __FBSDID +#if !defined(STRIP_FBSDID) +#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __FBSDID(s) struct __hack +#endif +#endif + +#ifndef __RCSID +#ifndef NO__RCSID +#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __RCSID(s) struct __hack +#endif +#endif + +#ifndef __RCSID_SOURCE +#ifndef NO__RCSID_SOURCE +#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) +#else +#define __RCSID_SOURCE(s) struct __hack +#endif +#endif + +#ifndef __SCCSID +#ifndef NO__SCCSID +#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) +#else +#define __SCCSID(s) struct __hack +#endif +#endif + +#ifndef __COPYRIGHT +#ifndef NO__COPYRIGHT +#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) +#else +#define __COPYRIGHT(s) struct __hack +#endif +#endif + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) +#endif + +#ifndef __DEVOLATILE +#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) +#endif + +#ifndef __DEQUALIFY +#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) +#endif + +/*- + * The following definitions are an extension of the behavior originally + * implemented in , but with a different level of granularity. + * POSIX.1 requires that the macros we test be defined before any standard + * header file is included. + * + * Here's a quick run-down of the versions: + * defined(_POSIX_SOURCE) 1003.1-1988 + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option + * _POSIX_C_SOURCE == 199309 1003.1b-1993 + * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1: 1996 + * _POSIX_C_SOURCE == 200112 1003.1-2001 + * _POSIX_C_SOURCE == 200809 1003.1-2008 + * + * In addition, the X/Open Portability Guide, which is now the Single UNIX + * Specification, defines a feature-test macro which indicates the version of + * that specification, and which subsumes _POSIX_C_SOURCE. + * + * Our macros begin with two underscores to avoid namespace screwage. + */ + +/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 +#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ +#define _POSIX_C_SOURCE 199009 +#endif + +/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199209 +#endif + +/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +#ifdef _XOPEN_SOURCE +#if _XOPEN_SOURCE - 0 >= 700 +#define __XSI_VISIBLE 700 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809 +#elif _XOPEN_SOURCE - 0 >= 600 +#define __XSI_VISIBLE 600 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112 +#elif _XOPEN_SOURCE - 0 >= 500 +#define __XSI_VISIBLE 500 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506 +#endif +#endif + +/* + * Deal with all versions of POSIX. The ordering relative to the tests above is + * important. + */ +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 198808 +#endif +#ifdef _POSIX_C_SOURCE +#if _POSIX_C_SOURCE >= 200809 +#define __POSIX_VISIBLE 200809 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 200112 +#define __POSIX_VISIBLE 200112 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 199506 +#define __POSIX_VISIBLE 199506 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199309 +#define __POSIX_VISIBLE 199309 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199209 +#define __POSIX_VISIBLE 199209 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199009 +#define __POSIX_VISIBLE 199009 +#define __ISO_C_VISIBLE 1990 +#else +#define __POSIX_VISIBLE 198808 +#define __ISO_C_VISIBLE 0 +#endif /* _POSIX_C_SOURCE */ +#else +/*- + * Deal with _ANSI_SOURCE: + * If it is defined, and no other compilation environment is explicitly + * requested, then define our internal feature-test macros to zero. This + * makes no difference to the preprocessor (undefined symbols in preprocessing + * expressions are defined to have value zero), but makes it more convenient for + * a test program to print out the values. + * + * If a program mistakenly defines _ANSI_SOURCE and some other macro such as + * _POSIX_C_SOURCE, we will assume that it wants the broader compilation + * environment (and in fact we will never get here). + */ +#if defined(_ANSI_SOURCE) /* Hide almost everything. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1990 +#define __EXT1_VISIBLE 0 +#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1999 +#define __EXT1_VISIBLE 0 +#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 2011 +#define __EXT1_VISIBLE 0 +#else /* Default environment: show everything. */ +#define __POSIX_VISIBLE 200809 +#define __XSI_VISIBLE 700 +#define __BSD_VISIBLE 1 +#define __ISO_C_VISIBLE 2011 +#define __EXT1_VISIBLE 1 +#endif +#endif + +/* User override __EXT1_VISIBLE */ +#if defined(__STDC_WANT_LIB_EXT1__) +#undef __EXT1_VISIBLE +#if __STDC_WANT_LIB_EXT1__ +#define __EXT1_VISIBLE 1 +#else +#define __EXT1_VISIBLE 0 +#endif +#endif /* __STDC_WANT_LIB_EXT1__ */ + +#if defined(__mips) || defined(__powerpc64__) || defined(__riscv) +#define __NO_TLS 1 +#endif + +/* + * Old versions of GCC use non-standard ARM arch symbols; acle-compat.h + * translates them to __ARM_ARCH and the modern feature symbols defined by ARM. + */ +#if defined(__arm__) && !defined(__ARM_ARCH) +#include +#endif + +/* + * Nullability qualifiers: currently only supported by Clang. + */ +#if !(defined(__clang__) && __has_feature(nullability)) +#define _Nonnull +#define _Nullable +#define _Null_unspecified +#define __NULLABILITY_PRAGMA_PUSH +#define __NULLABILITY_PRAGMA_POP +#else +#define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") +#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") +#endif + +/* + * Type Safety Checking + * + * Clang provides additional attributes to enable checking type safety + * properties that cannot be enforced by the C type system. + */ + +#if __has_attribute(__argument_with_type_tag__) && \ + __has_attribute(__type_tag_for_datatype__) +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ + __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) +#define __datatype_type_tag(kind, type) \ + __attribute__((__type_tag_for_datatype__(kind, type))) +#else +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) +#define __datatype_type_tag(kind, type) +#endif + +/* + * Lock annotations. + * + * Clang provides support for doing basic thread-safety tests at + * compile-time, by marking which locks will/should be held when + * entering/leaving a functions. + * + * Furthermore, it is also possible to annotate variables and structure + * members to enforce that they are only accessed when certain locks are + * held. + */ + +#if __has_extension(c_thread_safety_attributes) +#define __lock_annotate(x) __attribute__((x)) +#else +#define __lock_annotate(x) +#endif + +/* Structure implements a lock. */ +#define __lockable __lock_annotate(lockable) + +/* Function acquires an exclusive or shared lock. */ +#define __locks_exclusive(...) \ + __lock_annotate(exclusive_lock_function(__VA_ARGS__)) +#define __locks_shared(...) \ + __lock_annotate(shared_lock_function(__VA_ARGS__)) + +/* Function attempts to acquire an exclusive or shared lock. */ +#define __trylocks_exclusive(...) \ + __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) +#define __trylocks_shared(...) \ + __lock_annotate(shared_trylock_function(__VA_ARGS__)) + +/* Function releases a lock. */ +#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) + +/* Function asserts that an exclusive or shared lock is held. */ +#define __asserts_exclusive(...) \ + __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) +#define __asserts_shared(...) \ + __lock_annotate(assert_shared_lock(__VA_ARGS__)) + +/* Function requires that an exclusive or shared lock is or is not held. */ +#define __requires_exclusive(...) \ + __lock_annotate(exclusive_locks_required(__VA_ARGS__)) +#define __requires_shared(...) \ + __lock_annotate(shared_locks_required(__VA_ARGS__)) +#define __requires_unlocked(...) \ + __lock_annotate(locks_excluded(__VA_ARGS__)) + +/* Function should not be analyzed. */ +#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) + +/* Guard variables and structure members by lock. */ +#define __guarded_by(x) __lock_annotate(guarded_by(x)) +#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) + +#endif /* !_SYS_CDEFS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cdio.h b/lib/libc/include/any-freebsd-any/sys/cdio.h new file mode 100644 index 000000000000..a3eb271a7514 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cdio.h @@ -0,0 +1,277 @@ +/* + * 16 Feb 93 Julian Elischer (julian@dialix.oz.au) + * + * $FreeBSD$ + */ + +/* +<1> Fixed a conflict with ioctl usage. There were two different + functions using code #25. Made file formatting consistent. + Added two new ioctl codes: door closing and audio pitch playback. + Added a STEREO union called STEREO. + 5-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org + +<2> Added a new ioctl that allows you to find out what capabilities + a drive has and what commands it will accept. This allows a + user application to only offer controls (buttons, sliders, etc) + for functions that drive can actually do. Things it can't do + can disappear or be greyed-out (like some other system). + If the driver doesn't respond to this call, well, handle it the + way you used to do it. + 2-Apr-95 Frank Durda IV bsdmail@nemesis.lonestar.org +*/ + +/* Shared between kernel & process */ + +#ifndef _SYS_CDIO_H_ +#define _SYS_CDIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +union msf_lba { + struct { + unsigned char unused; + unsigned char minute; + unsigned char second; + unsigned char frame; + } msf; + int lba; /* network byte order */ + u_char addr[4]; +}; + +struct cd_toc_entry { +#if BYTE_ORDER == LITTLE_ENDIAN + u_int :8; + u_int control:4; + u_int addr_type:4; +#else + u_int :8; + u_int addr_type:4; + u_int control:4; +#endif + u_char track; + u_int :8; + union msf_lba addr; +}; + +struct cd_sub_channel_header { + u_int :8; + u_char audio_status; +#define CD_AS_AUDIO_INVALID 0x00 +#define CD_AS_PLAY_IN_PROGRESS 0x11 +#define CD_AS_PLAY_PAUSED 0x12 +#define CD_AS_PLAY_COMPLETED 0x13 +#define CD_AS_PLAY_ERROR 0x14 +#define CD_AS_NO_STATUS 0x15 + u_char data_len[2]; +}; + +struct cd_sub_channel_position_data { + u_char data_format; + u_int control:4; + u_int addr_type:4; + u_char track_number; + u_char index_number; + union msf_lba absaddr; + union msf_lba reladdr; +}; + +struct cd_sub_channel_media_catalog { + u_char data_format; + u_int :8; + u_int :8; + u_int :8; + u_int :7; + u_int mc_valid:1; + u_char mc_number[15]; +}; + +struct cd_sub_channel_track_info { + u_char data_format; + u_int :8; + u_char track_number; + u_int :8; + u_int :7; + u_int ti_valid:1; + u_char ti_number[15]; +}; + +struct cd_sub_channel_info { + struct cd_sub_channel_header header; + union { + struct cd_sub_channel_position_data position; + struct cd_sub_channel_media_catalog media_catalog; + struct cd_sub_channel_track_info track_info; + } what; +}; + + +/***************************************************************\ +* Ioctls for the CD drive * +\***************************************************************/ + +struct ioc_play_track { + u_char start_track; + u_char start_index; + u_char end_track; + u_char end_index; +}; +#define CDIOCPLAYTRACKS _IOW('c',1,struct ioc_play_track) + + +struct ioc_play_blocks { + int blk; + int len; +}; +#define CDIOCPLAYBLOCKS _IOW('c',2,struct ioc_play_blocks) + + +struct ioc_read_subchannel { + u_char address_format; +#define CD_LBA_FORMAT 1 +#define CD_MSF_FORMAT 2 + u_char data_format; +#define CD_SUBQ_DATA 0 +#define CD_CURRENT_POSITION 1 +#define CD_MEDIA_CATALOG 2 +#define CD_TRACK_INFO 3 + u_char track; + int data_len; + struct cd_sub_channel_info *data; +}; +#define CDIOCREADSUBCHANNEL _IOWR('c', 3 , struct ioc_read_subchannel ) + + +struct ioc_toc_header { + u_short len; + u_char starting_track; + u_char ending_track; +}; +#define CDIOREADTOCHEADER _IOR('c',4,struct ioc_toc_header) + + +struct ioc_read_toc_entry { + u_char address_format; + u_char starting_track; + u_short data_len; + struct cd_toc_entry *data; +}; +#define CDIOREADTOCENTRYS _IOWR('c',5,struct ioc_read_toc_entry) + + +struct ioc_read_toc_single_entry { + u_char address_format; + u_char track; + struct cd_toc_entry entry; +}; +#define CDIOREADTOCENTRY _IOWR('c',6,struct ioc_read_toc_single_entry) + + +struct ioc_patch { + u_char patch[4]; /* one for each channel */ +}; +#define CDIOCSETPATCH _IOW('c',9,struct ioc_patch) + + +struct ioc_vol { + u_char vol[4]; /* one for each channel */ +}; +#define CDIOCGETVOL _IOR('c',10,struct ioc_vol) + +#define CDIOCSETVOL _IOW('c',11,struct ioc_vol) + +#define CDIOCSETMONO _IO('c',12) + +#define CDIOCSETSTERIO _IO('c',13) +#define CDIOCSETSTEREO _IO('c',13) + +#define CDIOCSETMUTE _IO('c',14) + +#define CDIOCSETLEFT _IO('c',15) + +#define CDIOCSETRIGHT _IO('c',16) + +#define CDIOCSETDEBUG _IO('c',17) + +#define CDIOCCLRDEBUG _IO('c',18) + +#define CDIOCPAUSE _IO('c',19) + +#define CDIOCRESUME _IO('c',20) + +#define CDIOCRESET _IO('c',21) + +#define CDIOCSTART _IO('c',22) + +#define CDIOCSTOP _IO('c',23) + +#define CDIOCEJECT _IO('c',24) + + +struct ioc_play_msf { + u_char start_m; + u_char start_s; + u_char start_f; + u_char end_m; + u_char end_s; + u_char end_f; +}; +#define CDIOCPLAYMSF _IOW('c',25,struct ioc_play_msf) + +#define CDIOCALLOW _IO('c',26) + +#define CDIOCPREVENT _IO('c',27) + + /*<1>For drives that support it, this*/ + /*<1>causes the drive to close its door*/ + /*<1>and make the media (if any) ready*/ +#define CDIOCCLOSE _IO('c',28) /*<1>*/ + + +struct ioc_pitch { /*<1>For drives that support it, this*/ + /*<1>call instructs the drive to play the*/ + short speed; /*<1>audio at a faster or slower-than-normal*/ +}; /*<1>rate. -32767 to -1 is slower, 0==normal,*/ + /*<1>and 1 to 32767 is faster. LSB bits are*/ + /*<1>discarded first by drives with less res.*/ +#define CDIOCPITCH _IOW('c',29,struct ioc_pitch) /*<1>*/ + +struct ioc_capability { /*<2>*/ + u_long play_function; /*<2>*/ +#define CDDOPLAYTRK 0x00000001 /*<2>Can Play tracks/index*/ +#define CDDOPLAYMSF 0x00000002 /*<2>Can Play msf to msf*/ +#define CDDOPLAYBLOCKS 0x00000004 /*<2>Can Play range of blocks*/ +#define CDDOPAUSE 0x00000100 /*<2>Output can be paused*/ +#define CDDORESUME 0x00000200 /*<2>Output can be resumed*/ +#define CDDORESET 0x00000400 /*<2>Drive can be completely reset*/ +#define CDDOSTART 0x00000800 /*<2>Audio can be started*/ +#define CDDOSTOP 0x00001000 /*<2>Audio can be stopped*/ +#define CDDOPITCH 0x00002000 /*<2>Audio pitch */ + + u_long routing_function; /*<2>*/ +#define CDREADVOLUME 0x00000001 /*<2>Volume settings can be read*/ +#define CDSETVOLUME 0x00000002 /*<2>Volume settings can be set*/ +#define CDSETMONO 0x00000100 /*<2>Output can be set to mono*/ +#define CDSETSTEREO 0x00000200 /*<2>Output can be set to stereo (def)*/ +#define CDSETLEFT 0x00000400 /*<2>Output can be set to left only*/ +#define CDSETRIGHT 0x00000800 /*<2>Output can be set to right only*/ +#define CDSETMUTE 0x00001000 /*<2>Output can be muted*/ +#define CDSETPATCH 0x00008000 /*<2>Direct routing control allowed*/ + + u_long special_function; /*<2>*/ +#define CDDOEJECT 0x00000001 /*<2>The tray can be opened*/ +#define CDDOCLOSE 0x00000002 /*<2>The tray can be closed*/ +#define CDDOLOCK 0x00000004 /*<2>The tray can be locked*/ +#define CDREADHEADER 0x00000100 /*<2>Can read Table of Contents*/ +#define CDREADENTRIES 0x00000200 /*<2>Can read TOC Entries*/ +#define CDREADSUBQ 0x00000200 /*<2>Can read Subchannel info*/ +#define CDREADRW 0x00000400 /*<2>Can read subcodes R-W*/ +#define CDHASDEBUG 0x00004000 /*<2>The tray has dynamic debugging*/ +}; /*<2>*/ + +#define CDIOCCAPABILITY _IOR('c',30,struct ioc_capability) /*<2>*/ + +#endif /* !_SYS_CDIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cdrio.h b/lib/libc/include/any-freebsd-any/sys/cdrio.h new file mode 100644 index 000000000000..f8af2fde5cb5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cdrio.h @@ -0,0 +1,141 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2000,2001,2002 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CDRIO_H_ +#define _SYS_CDRIO_H_ + +#include + +struct cdr_track { + int datablock_type; /* data type code */ +#define CDR_DB_RAW 0x0 /* 2352 bytes of raw data */ +#define CDR_DB_RAW_PQ 0x1 /* 2368 bytes raw data + P/Q subchan */ +#define CDR_DB_RAW_PW 0x2 /* 2448 bytes raw data + P-W subchan */ +#define CDR_DB_RAW_PW_R 0x3 /* 2448 bytes raw data + P-W raw sub */ +#define CDR_DB_RES_4 0x4 /* reserved */ +#define CDR_DB_RES_5 0x5 /* reserved */ +#define CDR_DB_RES_6 0x6 /* reserved */ +#define CDR_DB_VS_7 0x7 /* vendor specific */ +#define CDR_DB_ROM_MODE1 0x8 /* 2048 bytes Mode 1 (ISO/IEC 10149) */ +#define CDR_DB_ROM_MODE2 0x9 /* 2336 bytes Mode 2 (ISO/IEC 10149) */ +#define CDR_DB_XA_MODE1 0xa /* 2048 bytes Mode 1 (CD-ROM XA 1) */ +#define CDR_DB_XA_MODE2_F1 0xb /* 2056 bytes Mode 2 (CD-ROM XA 1) */ +#define CDR_DB_XA_MODE2_F2 0xc /* 2324 bytes Mode 2 (CD-ROM XA 2) */ +#define CDR_DB_XA_MODE2_MIX 0xd /* 2332 bytes Mode 2 (CD-ROM XA 1/2) */ +#define CDR_DB_RES_14 0xe /* reserved */ +#define CDR_DB_VS_15 0xf /* vendor specific */ + + int preemp; /* preemphasis if audio track*/ + int test_write; /* use test writes, laser turned off */ +}; + +struct cdr_cue_entry { + u_int8_t adr:4; + u_int8_t ctl:4; + u_int8_t track; + u_int8_t index; + u_int8_t dataform; + u_int8_t scms; + u_int8_t min; + u_int8_t sec; + u_int8_t frame; +}; + +struct cdr_cuesheet { + int32_t len; + struct cdr_cue_entry *entries; + int session_format; +#define CDR_SESS_CDROM 0x00 +#define CDR_SESS_CDI 0x10 +#define CDR_SESS_CDROM_XA 0x20 + + int session_type; +#define CDR_SESS_NONE 0x00 +#define CDR_SESS_FINAL 0x01 +#define CDR_SESS_RESERVED 0x02 +#define CDR_SESS_MULTI 0x03 + + int test_write; +}; + +struct cdr_format_capacity { + u_int32_t blocks; + u_int32_t reserved:2; + u_int32_t type:6; + u_int32_t param:24; +}; + +struct cdr_format_capacities { + u_int8_t reserved1[3]; + u_int8_t length; + u_int32_t blocks; + u_int32_t type:2; + u_int32_t reserved2:6; + u_int32_t block_size:24; + struct cdr_format_capacity format[32]; +}; + +struct cdr_format_params { + u_int8_t reserved; + u_int8_t vs:1; + u_int8_t immed:1; + u_int8_t try_out:1; + u_int8_t ip:1; + u_int8_t stpf:1; + u_int8_t dcrt:1; + u_int8_t dpry:1; + u_int8_t fov:1; + u_int16_t length; + struct cdr_format_capacity format; +}; + +#define CDRIOCBLANK _IOW('c', 100, int) +#define CDR_B_ALL 0x0 +#define CDR_B_MIN 0x1 +#define CDR_B_SESSION 0x6 + +#define CDRIOCNEXTWRITEABLEADDR _IOR('c', 101, int) +#define CDRIOCINITWRITER _IOW('c', 102, int) +#define CDRIOCINITTRACK _IOW('c', 103, struct cdr_track) +#define CDRIOCSENDCUE _IOW('c', 104, struct cdr_cuesheet) +#define CDRIOCFLUSH _IO('c', 105) +#define CDRIOCFIXATE _IOW('c', 106, int) +#define CDRIOCREADSPEED _IOW('c', 107, int) +#define CDRIOCWRITESPEED _IOW('c', 108, int) +#define CDR_MAX_SPEED 0xffff +#define CDRIOCGETBLOCKSIZE _IOR('c', 109, int) +#define CDRIOCSETBLOCKSIZE _IOW('c', 110, int) +#define CDRIOCGETPROGRESS _IOR('c', 111, int) +#define CDRIOCREADFORMATCAPS _IOR('c', 112, struct cdr_format_capacities) +#define CDRIOCFORMAT _IOW('c', 113, struct cdr_format_params) + +#endif /* !_SYS_CDRIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cfictl.h b/lib/libc/include/any-freebsd-any/sys/cfictl.h new file mode 100644 index 000000000000..db5ecfe6a7c9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cfictl.h @@ -0,0 +1,55 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2007, Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CFICTL_H_ +#define _SYS_CFICTL_H_ + +/* + * Allow reading of the CFI query structure. + */ + +struct cfiocqry { + unsigned long offset; + unsigned long count; + u_char *buffer; +}; + +#define CFIOCQRY _IOWR('q', 0, struct cfiocqry) + +/* Intel StrataFlash Protection Register support */ +#define CFIOCGFACTORYPR _IOR('q', 1, uint64_t) /* get factory protection reg */ +#define CFIOCGOEMPR _IOR('q', 2, uint64_t) /* get oem protection reg */ +#define CFIOCSOEMPR _IOW('q', 3, uint64_t) /* set oem protection reg */ +#define CFIOCGPLR _IOR('q', 4, uint32_t) /* get protection lock reg */ +#define CFIOCSPLR _IO('q', 5) /* set protection log reg */ +#endif /* _SYS_CFICTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/chio.h b/lib/libc/include/any-freebsd-any/sys/chio.h new file mode 100644 index 000000000000..15d52202374a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/chio.h @@ -0,0 +1,282 @@ +/* $NetBSD: chio.h,v 1.9 1997/09/29 17:32:26 mjacob Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1996 Jason R. Thorpe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgements: + * This product includes software developed by Jason R. Thorpe + * for And Communications, http://www.and.com/ + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CHIO_H_ +#define _SYS_CHIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Element types. Used as "to" and "from" type indicators in move + * and exchange operations. + * + * Note that code in sys/scsi/ch.c relies on these values (uses them + * as offsets in an array, and other evil), so don't muck with them + * unless you know what you're doing. + */ +#define CHET_MT 0 /* medium transport (picker) */ +#define CHET_ST 1 /* storage transport (slot) */ +#define CHET_IE 2 /* import/export (portal) */ +#define CHET_DT 3 /* data transfer (drive) */ +#define CHET_MAX CHET_DT + +/* + * Maximum length of a volume identification string + */ +#define CH_VOLTAG_MAXLEN 32 + +/* + * Structure used to execute a MOVE MEDIUM command. + */ +struct changer_move { + u_int16_t cm_fromtype; /* element type to move from */ + u_int16_t cm_fromunit; /* logical unit of from element */ + u_int16_t cm_totype; /* element type to move to */ + u_int16_t cm_tounit; /* logical unit of to element */ + u_int16_t cm_flags; /* misc. flags */ +}; + +/* cm_flags */ +#define CM_INVERT 0x01 /* invert media */ + +/* + * Structure used to execute an EXCHANGE MEDIUM command. In an + * exchange operation, the following steps occur: + * + * - media from source is moved to first destination. + * + * - media previously occupying first destination is moved + * to the second destination. + * + * The second destination may or may not be the same as the source. + * In the case of a simple exchange, the source and second destination + * are the same. + */ +struct changer_exchange { + u_int16_t ce_srctype; /* element type of source */ + u_int16_t ce_srcunit; /* logical unit of source */ + u_int16_t ce_fdsttype; /* element type of first destination */ + u_int16_t ce_fdstunit; /* logical unit of first destination */ + u_int16_t ce_sdsttype; /* element type of second destination */ + u_int16_t ce_sdstunit; /* logical unit of second destination */ + u_int16_t ce_flags; /* misc. flags */ +}; + +/* ce_flags */ +#define CE_INVERT1 0x01 /* invert media 1 */ +#define CE_INVERT2 0x02 /* invert media 2 */ + +/* + * Structure used to execute a POSITION TO ELEMENT command. This + * moves the current picker in front of the specified element. + */ +struct changer_position { + u_int16_t cp_type; /* element type */ + u_int16_t cp_unit; /* logical unit of element */ + u_int16_t cp_flags; /* misc. flags */ +}; + +/* cp_flags */ +#define CP_INVERT 0x01 /* invert picker */ + +/* + * Data returned by CHIOGPARAMS. + */ +struct changer_params { + u_int16_t cp_npickers; /* number of pickers */ + u_int16_t cp_nslots; /* number of slots */ + u_int16_t cp_nportals; /* number of import/export portals */ + u_int16_t cp_ndrives; /* number of drives */ +}; + +/* + * Command used to get element status. + */ + +struct changer_voltag { + u_char cv_volid[CH_VOLTAG_MAXLEN+1]; + u_int16_t cv_serial; +}; + +typedef struct changer_voltag changer_voltag_t; + +/* + * Flags definitions for ces_status + * Not all flags have meaning for all element types. + */ +typedef enum { + CES_STATUS_FULL = 0x001, /* element is full */ + CES_STATUS_IMPEXP = 0x002, /* media deposited by operator */ + CES_STATUS_EXCEPT = 0x004, /* element in abnormal state */ + CES_PICKER_MASK = 0x005, /* flags valid for pickers */ + CES_STATUS_ACCESS = 0x008, /* media accessible by picker */ + CES_SLOT_MASK = 0x00c, /* flags valid for slots */ + CES_DRIVE_MASK = 0x00c, /* flags valid for drives */ + CES_STATUS_EXENAB = 0x010, /* element supports exporting */ + CES_STATUS_INENAB = 0x020, /* element supports importing */ + CES_PORTAL_MASK = 0x03f, /* flags valid for portals */ + CES_INVERT = 0x040, /* invert bit */ + CES_SOURCE_VALID = 0x080, /* source address (ces_source) valid */ + CES_SCSIID_VALID = 0x100, /* ces_scsi_id is valid */ + CES_LUN_VALID = 0x200, /* ces_scsi_lun is valid */ + CES_PIV = 0x400 /* ces_protocol_id is valid */ +} ces_status_flags; + +struct changer_element_status { + u_int8_t ces_type; /* element type */ + u_int16_t ces_addr; /* logical element address */ + u_int16_t ces_int_addr; /* changer element address */ + ces_status_flags ces_flags; /* + * see CESTATUS definitions + * below + */ + u_int8_t ces_sensecode; /* + * additional sense + * code for element */ + u_int8_t ces_sensequal; /* + * additional sense + * code qualifier + */ + u_int8_t ces_source_type; /* + * element type of + * source address + */ + u_int16_t ces_source_addr; /* + * source address of medium + */ + changer_voltag_t ces_pvoltag; /* primary volume tag */ + changer_voltag_t ces_avoltag; /* alternate volume tag */ + u_int8_t ces_scsi_id; /* SCSI id of element */ + u_int8_t ces_scsi_lun; /* SCSI lun of element */ + + /* + * Data members for SMC3 and later versions + */ + u_int8_t ces_medium_type; +#define CES_MEDIUM_TYPE_UNKNOWN 0 /* Medium type unspecified */ +#define CES_MEDIUM_TYPE_DATA 1 /* Data medium */ +#define CES_MEDIUM_TYPE_CLEANING 2 /* Cleaning medium */ +#define CES_MEDIUM_TYPE_DIAGNOSTIC 3 /* Diagnostic medium */ +#define CES_MEDIUM_TYPE_WORM 4 /* WORM medium */ +#define CES_MEDIUM_TYPE_MICROCODE 5 /* Microcode image medium */ + + u_int8_t ces_protocol_id; +#define CES_PROTOCOL_ID_FCP_4 0 /* Fiber channel */ +#define CES_PROTOCOL_ID_SPI_5 1 /* Parallel SCSI */ +#define CES_PROTOCOL_ID_SSA_S3P 2 /* SSA */ +#define CES_PROTOCOL_ID_SBP_3 3 /* IEEE 1394 */ +#define CES_PROTOCOL_ID_SRP 4 /* SCSI Remote DMA */ +#define CES_PROTOCOL_ID_ISCSI 5 /* iSCSI */ +#define CES_PROTOCOL_ID_SPL 6 /* SAS */ +#define CES_PROTOCOL_ID_ADT_2 7 /* Automation/Drive Interface */ +#define CES_PROTOCOL_ID_ACS_2 8 /* ATA */ + + u_int8_t ces_assoc; +#define CES_ASSOC_LOGICAL_UNIT 0 +#define CES_ASSOC_TARGET_PORT 1 +#define CES_ASSOC_TARGET_DEVICE 2 + + u_int8_t ces_designator_type; +#define CES_DESIGNATOR_TYPE_VENDOR_SPECIFIC 0 +#define CES_DESIGNATOR_TYPE_T10_VENDOR_ID 1 +#define CES_DESIGNATOR_TYPE_EUI_64 2 +#define CES_DESIGNATOR_TYPE_NAA 3 +#define CES_DESIGNATOR_TYPE_TARGET_PORT_ID 4 +#define CES_DESIGNATOR_TYPE_TARGET_PORT_GRP 5 +#define CES_DESIGNATOR_TYPE_LOGICAL_UNIT_GRP 6 +#define CES_DESIGNATOR_TYPE_MD5_LOGICAL_UNIT_ID 7 +#define CES_DESIGNATOR_TYPE_SCSI_NAME_STRING 8 + + u_int8_t ces_code_set; +#define CES_CODE_SET_RESERVED 0 +#define CES_CODE_SET_BINARY 1 +#define CES_CODE_SET_ASCII 2 +#define CES_CODE_SET_UTF_8 3 + + u_int8_t ces_designator_length; + +#define CES_MAX_DESIGNATOR_LENGTH (1 << 8) + u_int8_t ces_designator[CES_MAX_DESIGNATOR_LENGTH + 1]; +}; + +struct changer_element_status_request { + u_int16_t cesr_element_type; + u_int16_t cesr_element_base; + u_int16_t cesr_element_count; + + u_int16_t cesr_flags; +#define CESR_VOLTAGS 0x01 + + struct changer_element_status *cesr_element_status; +}; + + +struct changer_set_voltag_request { + u_int16_t csvr_type; + u_int16_t csvr_addr; + + u_int16_t csvr_flags; +#define CSVR_MODE_MASK 0x0f /* mode mask, acceptable modes below: */ +#define CSVR_MODE_SET 0x00 /* set volume tag if not set */ +#define CSVR_MODE_REPLACE 0x01 /* unconditionally replace volume tag */ +#define CSVR_MODE_CLEAR 0x02 /* clear volume tag */ + +#define CSVR_ALTERNATE 0x10 /* set to work with alternate voltag */ + + changer_voltag_t csvr_voltag; +}; + + +#define CESTATUS_BITS \ + "\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL" + +#define CHIOMOVE _IOW('c', 0x01, struct changer_move) +#define CHIOEXCHANGE _IOW('c', 0x02, struct changer_exchange) +#define CHIOPOSITION _IOW('c', 0x03, struct changer_position) +#define CHIOGPICKER _IOR('c', 0x04, int) +#define CHIOSPICKER _IOW('c', 0x05, int) +#define CHIOGPARAMS _IOR('c', 0x06, struct changer_params) +#define CHIOIELEM _IOW('c', 0x07, u_int32_t) +#define OCHIOGSTATUS _IOW('c', 0x08, struct changer_element_status_request) +#define CHIOSETVOLTAG _IOW('c', 0x09, struct changer_set_voltag_request) +#define CHIOGSTATUS _IOW('c', 0x0A, struct changer_element_status_request) + +#endif /* !_SYS_CHIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ck.h b/lib/libc/include/any-freebsd-any/sys/ck.h new file mode 100644 index 000000000000..3bfce70c8d2c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ck.h @@ -0,0 +1,13 @@ +/* + * $FreeBSD$ + */ +#ifdef _KERNEL +#include +#include +#else +#include +#define CK_STAILQ_HEAD STAILQ_HEAD +#define CK_STAILQ_ENTRY STAILQ_ENTRY +#define CK_LIST_HEAD LIST_HEAD +#define CK_LIST_ENTRY LIST_ENTRY +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/clock.h b/lib/libc/include/any-freebsd-any/sys/clock.h new file mode 100644 index 000000000000..bfbd6efd2ad3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/clock.h @@ -0,0 +1,208 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Gordon W. Ross + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $ + * + * + * This file is the central clearing-house for calendrical issues. + * + * In general the kernel does not know about minutes, hours, days, timezones, + * daylight savings time, leap-years and such. All that is theoretically a + * matter for userland only. + * + * Parts of kernel code does however care: badly designed filesystems store + * timestamps in local time and RTC chips sometimes track time in a local + * timezone instead of UTC and so on. + * + * All that code should go here for service. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CLOCK_H_ +#define _SYS_CLOCK_H_ + +#ifdef _KERNEL /* No user serviceable parts */ + +/* + * Timezone info from settimeofday(2), usually not used + */ +extern int tz_minuteswest; +extern int tz_dsttime; + +int utc_offset(void); + +/* + * Structure to hold the values typically reported by time-of-day clocks, + * expressed as binary integers (see below for a BCD version). This can be + * passed to the conversion functions to be converted to/from a struct timespec. + * + * On input, the year is interpreted as follows: + * 0 - 69 = 2000 - 2069 + * 70 - 99 = 1970 - 1999 + * 100 - 199 = 2000 - 2099 (Supports hardware "century bit".) + * 200 - 1969 = Invalid. + * 1970 - 9999 = Full 4-digit century+year. + * + * The dow field is ignored (not even validated) on input, but is always + * populated with day-of-week on output. + * + * clock_ct_to_ts() returns EINVAL if any values are out of range. The year + * field will always be 4-digit on output. + */ +struct clocktime { + int year; /* year (4 digit year) */ + int mon; /* month (1 - 12) */ + int day; /* day (1 - 31) */ + int hour; /* hour (0 - 23) */ + int min; /* minute (0 - 59) */ + int sec; /* second (0 - 59) */ + int dow; /* day of week (0 - 6; 0 = Sunday) */ + long nsec; /* nano seconds */ +}; + +int clock_ct_to_ts(const struct clocktime *, struct timespec *); +void clock_ts_to_ct(const struct timespec *, struct clocktime *); + +/* + * Structure to hold the values typically reported by time-of-day clocks, + * expressed as BCD. This can be passed to the conversion functions to be + * converted to/from a struct timespec. + * + * The clock_bcd_to_ts() function interprets the values in the year through sec + * fields as BCD numbers, and returns EINVAL if any BCD values are out of range. + * After conversion to binary, the values are passed to clock_ct_to_ts() and + * undergo further validation as described above. Year may be 2 or 4-digit BCD, + * interpreted as described above. The nsec field is binary. If the ampm arg + * is true, the incoming hour and ispm values are interpreted as 12-hour am/pm + * representation of the hour, otherwise hour is interpreted as 24-hour and ispm + * is ignored. + * + * The clock_ts_to_bcd() function converts the timespec to BCD values stored + * into year through sec. The value in year will be 4-digit BCD (e.g., + * 0x2017). The mon through sec values will be 2-digit BCD. The nsec field will + * be binary, and the range of dow makes its binary and BCD values identical. + * If the ampm arg is true, the hour and ispm fields are set to the 12-hour + * time plus a pm flag, otherwise the hour is set to 24-hour time and ispm is + * set to false. + */ +struct bcd_clocktime { + uint16_t year; /* year (2 or 4 digit year) */ + uint8_t mon; /* month (1 - 12) */ + uint8_t day; /* day (1 - 31) */ + uint8_t hour; /* hour (0 - 23 or 1 - 12) */ + uint8_t min; /* minute (0 - 59) */ + uint8_t sec; /* second (0 - 59) */ + uint8_t dow; /* day of week (0 - 6; 0 = Sunday) */ + long nsec; /* nanoseconds */ + bool ispm; /* true if hour represents pm time */ +}; + +int clock_bcd_to_ts(const struct bcd_clocktime *, struct timespec *, bool ampm); +void clock_ts_to_bcd(const struct timespec *, struct bcd_clocktime *, bool ampm); + +/* + * Time-of-day clock functions and flags. These functions might sleep. + * + * clock_register and clock_unregister() do what they say. Upon return from + * unregister, the clock's methods are not running and will not be called again. + * + * clock_schedule() requests that a registered clock's clock_settime() calls + * happen at the given offset into the second. The default is 0, meaning no + * specific scheduling. To schedule the call as soon after top-of-second as + * possible, specify 1. Each clock has its own schedule, but taskqueue_thread + * is shared by many tasks; the timing of the call is not guaranteed. + * + * Flags: + * + * CLOCKF_SETTIME_NO_TS + * Do not pass a timespec to clock_settime(), the driver obtains its own time + * and applies its own adjustments (this flag implies CLOCKF_SETTIME_NO_ADJ). + * + * CLOCKF_SETTIME_NO_ADJ + * Do not apply utc offset and resolution/accuracy adjustments to the value + * passed to clock_settime(), the driver applies them itself. + * + * CLOCKF_GETTIME_NO_ADJ + * Do not apply utc offset and resolution/accuracy adjustments to the value + * returned from clock_gettime(), the driver has already applied them. + */ + +#define CLOCKF_SETTIME_NO_TS 0x00000001 +#define CLOCKF_SETTIME_NO_ADJ 0x00000002 +#define CLOCKF_GETTIME_NO_ADJ 0x00000004 + +void clock_register(device_t _clockdev, long _resolution_us); +void clock_register_flags(device_t _clockdev, long _resolution_us, int _flags); +void clock_schedule(device_t clockdev, u_int _offsetns); +void clock_unregister(device_t _clockdev); + +/* + * BCD to decimal and decimal to BCD. + */ +#define FROMBCD(x) bcd2bin(x) +#define TOBCD(x) bin2bcd(x) + +/* Some handy constants. */ +#define SECDAY (24 * 60 * 60) +#define SECYR (SECDAY * 365) + +/* Traditional POSIX base year */ +#define POSIX_BASE_YEAR 1970 + +void timespec2fattime(const struct timespec *tsp, int utc, u_int16_t *ddp, + u_int16_t *dtp, u_int8_t *dhp); +void fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, + struct timespec *tsp); + +/* + * Print a [bcd_]clocktime or timespec, optionally with fractional seconds. The + * nsdig argument can range from 0-9, and specifies how many decimal digits to + * display for fractional seconds. + */ +void clock_print_bcd(const struct bcd_clocktime *bct, int nsdig); +void clock_print_ct(const struct clocktime *ct, int nsdig); +void clock_print_ts(const struct timespec *ts, int nsdig); + +/* + * Debugging helpers for RTC clock drivers. Print a [bcd_]clocktime or + * timespec, only if rtc clock debugging has been enabled. The rw argument is + * one of CLOCK_DBG_READ or CLOCK_DBG_WRITE. + */ +#define CLOCK_DBG_READ 0x01 +#define CLOCK_DBG_WRITE 0x02 +void clock_dbgprint_bcd(device_t dev, int rw, const struct bcd_clocktime *bct); +void clock_dbgprint_ct(device_t dev, int rw, const struct clocktime *ct); +void clock_dbgprint_err(device_t dev, int rw, int err); +void clock_dbgprint_ts(device_t dev, int rw, const struct timespec *ts); + +#endif /* _KERNEL */ + +#endif /* !_SYS_CLOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cnv.h b/lib/libc/include/any-freebsd-any/sys/cnv.h new file mode 100644 index 000000000000..1e56cfbedd90 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cnv.h @@ -0,0 +1,120 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2016 Adam Starak + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _CNV_H_ +#define _CNV_H_ + +#include + +#ifndef _KERNEL +#include +#include +#include +#include +#endif + +#ifndef _NVLIST_T_DECLARED +#define _NVLIST_T_DECLARED +struct nvlist; + +typedef struct nvlist nvlist_t; +#endif + +__BEGIN_DECLS + +/* + * Functions which returns information about the given cookie. + */ +const char *cnvlist_name(const void *cookie); +int cnvlist_type(const void *cookie); + +/* + * The cnvlist_get functions returns value associated with the given cookie. + * If it returns a pointer, the pointer represents internal buffer and should + * not be freed by the caller. + */ + +bool cnvlist_get_bool(const void *cookie); +uint64_t cnvlist_get_number(const void *cookie); +const char *cnvlist_get_string(const void *cookie); +const nvlist_t *cnvlist_get_nvlist(const void *cookie); +const void *cnvlist_get_binary(const void *cookie, size_t *sizep); +const bool *cnvlist_get_bool_array(const void *cookie, size_t *nitemsp); +const uint64_t *cnvlist_get_number_array(const void *cookie, size_t *nitemsp); +const char * const *cnvlist_get_string_array(const void *cookie, size_t *nitemsp); +const nvlist_t * const *cnvlist_get_nvlist_array(const void *cookie, size_t *nitemsp); +#ifndef _KERNEL +int cnvlist_get_descriptor(const void *cookie); +const int *cnvlist_get_descriptor_array(const void *cookie, size_t *nitemsp); +#endif + + +/* + * The cnvlist_take functions returns value associated with the given cookie and + * remove the given entry from the nvlist. + * The caller is responsible for freeing received data. + */ + +bool cnvlist_take_bool(void *cookie); +uint64_t cnvlist_take_number(void *cookie); +char *cnvlist_take_string(void *cookie); +nvlist_t *cnvlist_take_nvlist(void *cookie); +void *cnvlist_take_binary(void *cookie, size_t *sizep); +bool *cnvlist_take_bool_array(void *cookie, size_t *nitemsp); +uint64_t *cnvlist_take_number_array(void *cookie, size_t *nitemsp); +char **cnvlist_take_string_array(void *cookie, size_t *nitemsp); +nvlist_t **cnvlist_take_nvlist_array(void *cookie, size_t *nitemsp); +#ifndef _KERNEL +int cnvlist_take_descriptor(void *cookie); +int *cnvlist_take_descriptor_array(void *cookie, size_t *nitemsp); +#endif + +/* + * The cnvlist_free functions removes the given name/value pair from the nvlist based on cookie + * and frees memory associated with it. + */ + +void cnvlist_free_bool(void *cookie); +void cnvlist_free_number(void *cookie); +void cnvlist_free_string(void *cookie); +void cnvlist_free_nvlist(void *cookie); +void cnvlist_free_binary(void *cookie); +void cnvlist_free_bool_array(void *cookie); +void cnvlist_free_number_array(void *cookie); +void cnvlist_free_string_array(void *cookie); +void cnvlist_free_nvlist_array(void *cookie); +#ifndef _KERNEL +void cnvlist_free_descriptor(void *cookie); +void cnvlist_free_descriptor_array(void *cookie); +#endif + +__END_DECLS + +#endif /* !_CNV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/compressor.h b/lib/libc/include/any-freebsd-any/sys/compressor.h new file mode 100644 index 000000000000..5406ef3c3298 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/compressor.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014, 2017 Mark Johnston + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__COMPRESSOR_H_ +#define _SYS__COMPRESSOR_H_ + +#ifdef _KERNEL + +/* Supported formats. */ +#define COMPRESS_GZIP 1 +#define COMPRESS_ZSTD 2 + +typedef int (*compressor_cb_t)(void *, size_t, off_t, void *); + +struct compressor; + +bool compressor_avail(int format); +struct compressor *compressor_init(compressor_cb_t cb, int format, + size_t maxiosize, int level, void *arg); +void compressor_reset(struct compressor *stream); +int compressor_write(struct compressor *stream, void *data, + size_t len); +int compressor_flush(struct compressor *stream); +void compressor_fini(struct compressor *stream); + +#endif /* _KERNEL */ +#endif /* _SYS__COMPRESSOR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/condvar.h b/lib/libc/include/any-freebsd-any/sys/condvar.h new file mode 100644 index 000000000000..e1a890334afa --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/condvar.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Jake Burkholder . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CONDVAR_H_ +#define _SYS_CONDVAR_H_ + +#ifndef LOCORE +#include + +struct lock_object; +struct thread; + +TAILQ_HEAD(cv_waitq, thread); + +/* + * Condition variable. The waiters count is protected by the mutex that + * protects the condition; that is, the mutex that is passed to cv_wait*() + * and is held across calls to cv_signal() and cv_broadcast(). It is an + * optimization to avoid looking up the sleep queue if there are no waiters. + */ +struct cv { + const char *cv_description; + int cv_waiters; +}; + +#ifdef _KERNEL +void cv_init(struct cv *cvp, const char *desc); +void cv_destroy(struct cv *cvp); + +void _cv_wait(struct cv *cvp, struct lock_object *lock); +void _cv_wait_unlock(struct cv *cvp, struct lock_object *lock); +int _cv_wait_sig(struct cv *cvp, struct lock_object *lock); +int _cv_timedwait_sbt(struct cv *cvp, struct lock_object *lock, + sbintime_t sbt, sbintime_t pr, int flags); +int _cv_timedwait_sig_sbt(struct cv *cvp, struct lock_object *lock, + sbintime_t sbt, sbintime_t pr, int flags); + +void cv_signal(struct cv *cvp); +void cv_broadcastpri(struct cv *cvp, int pri); + +#define cv_wait(cvp, lock) \ + _cv_wait((cvp), &(lock)->lock_object) +#define cv_wait_unlock(cvp, lock) \ + _cv_wait_unlock((cvp), &(lock)->lock_object) +#define cv_wait_sig(cvp, lock) \ + _cv_wait_sig((cvp), &(lock)->lock_object) +#define cv_timedwait(cvp, lock, timo) \ + _cv_timedwait_sbt((cvp), &(lock)->lock_object, \ + tick_sbt * (timo), 0, C_HARDCLOCK) +#define cv_timedwait_sbt(cvp, lock, sbt, pr, flags) \ + _cv_timedwait_sbt((cvp), &(lock)->lock_object, (sbt), (pr), (flags)) +#define cv_timedwait_sig(cvp, lock, timo) \ + _cv_timedwait_sig_sbt((cvp), &(lock)->lock_object, \ + tick_sbt * (timo), 0, C_HARDCLOCK) +#define cv_timedwait_sig_sbt(cvp, lock, sbt, pr, flags) \ + _cv_timedwait_sig_sbt((cvp), &(lock)->lock_object, (sbt), (pr), (flags)) + +#define cv_broadcast(cvp) cv_broadcastpri(cvp, 0) + +#define cv_wmesg(cvp) ((cvp)->cv_description) + +#endif /* _KERNEL */ +#endif /* !LOCORE */ +#endif /* _SYS_CONDVAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/conf.h b/lib/libc/include/any-freebsd-any/sys/conf.h new file mode 100644 index 000000000000..5268a03a7c7d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/conf.h @@ -0,0 +1,373 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2000 + * Poul-Henning Kamp. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)conf.h 8.5 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_CONF_H_ +#define _SYS_CONF_H_ + +#ifdef _KERNEL +#include +#else +#include +#endif + +struct snapdata; +struct devfs_dirent; +struct cdevsw; +struct file; + +struct cdev { + void *si_spare0; + u_int si_flags; +#define SI_ETERNAL 0x0001 /* never destroyed */ +#define SI_ALIAS 0x0002 /* carrier of alias name */ +#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */ +#define SI_UNUSED1 0x0008 /* unused */ +#define SI_CHILD 0x0010 /* child of another struct cdev **/ +#define SI_DUMPDEV 0x0080 /* is kernel dumpdev */ +#define SI_CLONELIST 0x0200 /* on a clone list */ +#define SI_UNMAPPED 0x0400 /* can handle unmapped I/O */ +#define SI_NOSPLIT 0x0800 /* I/O should not be split up */ + struct timespec si_atime; + struct timespec si_ctime; + struct timespec si_mtime; + uid_t si_uid; + gid_t si_gid; + mode_t si_mode; + struct ucred *si_cred; /* cached clone-time credential */ + int si_drv0; + int si_refcount; + LIST_ENTRY(cdev) si_list; + LIST_ENTRY(cdev) si_clone; + LIST_HEAD(, cdev) si_children; + LIST_ENTRY(cdev) si_siblings; + struct cdev *si_parent; + struct mount *si_mountpt; + void *si_drv1, *si_drv2; + struct cdevsw *si_devsw; + int si_iosize_max; /* maximum I/O size (for physio &al) */ + u_long si_usecount; + u_long si_threadcount; + union { + struct snapdata *__sid_snapdata; + } __si_u; + char si_name[SPECNAMELEN + 1]; +}; + +#define si_snapdata __si_u.__sid_snapdata + +#ifdef _KERNEL + +/* + * Definitions of device driver entry switches + */ + +struct bio; +struct buf; +struct dumperinfo; +struct kerneldumpheader; +struct thread; +struct uio; +struct knote; +struct clonedevs; +struct vm_object; +struct vnode; + +typedef int d_open_t(struct cdev *dev, int oflags, int devtype, struct thread *td); +typedef int d_fdopen_t(struct cdev *dev, int oflags, struct thread *td, struct file *fp); +typedef int d_close_t(struct cdev *dev, int fflag, int devtype, struct thread *td); +typedef void d_strategy_t(struct bio *bp); +typedef int d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data, + int fflag, struct thread *td); + +typedef int d_read_t(struct cdev *dev, struct uio *uio, int ioflag); +typedef int d_write_t(struct cdev *dev, struct uio *uio, int ioflag); +typedef int d_poll_t(struct cdev *dev, int events, struct thread *td); +typedef int d_kqfilter_t(struct cdev *dev, struct knote *kn); +typedef int d_mmap_t(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, + int nprot, vm_memattr_t *memattr); +typedef int d_mmap_single_t(struct cdev *cdev, vm_ooffset_t *offset, + vm_size_t size, struct vm_object **object, int nprot); +typedef void d_purge_t(struct cdev *dev); + +typedef int dumper_t( + void *_priv, /* Private to the driver. */ + void *_virtual, /* Virtual (mapped) address. */ + vm_offset_t _physical, /* Physical address of virtual. */ + off_t _offset, /* Byte-offset to write at. */ + size_t _length); /* Number of bytes to dump. */ +typedef int dumper_start_t(struct dumperinfo *di); +typedef int dumper_hdr_t(struct dumperinfo *di, struct kerneldumpheader *kdh, + void *key, uint32_t keylen); + +#endif /* _KERNEL */ + +/* + * Types for d_flags. + */ +#define D_TAPE 0x0001 +#define D_DISK 0x0002 +#define D_TTY 0x0004 +#define D_MEM 0x0008 /* /dev/(k)mem */ + +#ifdef _KERNEL + +#define D_TYPEMASK 0xffff + +/* + * Flags for d_flags which the drivers can set. + */ +#define D_TRACKCLOSE 0x00080000 /* track all closes */ +#define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */ +#define D_NEEDGIANT 0x00400000 /* driver want Giant */ +#define D_NEEDMINOR 0x00800000 /* driver uses clone_create() */ + +/* + * Version numbers. + */ +#define D_VERSION_00 0x20011966 +#define D_VERSION_01 0x17032005 /* Add d_uid,gid,mode & kind */ +#define D_VERSION_02 0x28042009 /* Add d_mmap_single */ +#define D_VERSION_03 0x17122009 /* d_mmap takes memattr,vm_ooffset_t */ +#define D_VERSION D_VERSION_03 + +/* + * Flags used for internal housekeeping + */ +#define D_INIT 0x80000000 /* cdevsw initialized */ + +/* + * Character device switch table + */ +struct cdevsw { + int d_version; + u_int d_flags; + const char *d_name; + d_open_t *d_open; + d_fdopen_t *d_fdopen; + d_close_t *d_close; + d_read_t *d_read; + d_write_t *d_write; + d_ioctl_t *d_ioctl; + d_poll_t *d_poll; + d_mmap_t *d_mmap; + d_strategy_t *d_strategy; + dumper_t *d_dump; + d_kqfilter_t *d_kqfilter; + d_purge_t *d_purge; + d_mmap_single_t *d_mmap_single; + + int32_t d_spare0[3]; + void *d_spare1[3]; + + /* These fields should not be messed with by drivers */ + LIST_HEAD(, cdev) d_devs; + int d_spare2; + union { + struct cdevsw *gianttrick; + SLIST_ENTRY(cdevsw) postfree_list; + } __d_giant; +}; +#define d_gianttrick __d_giant.gianttrick +#define d_postfree_list __d_giant.postfree_list + +struct module; + +struct devsw_module_data { + int (*chainevh)(struct module *, int, void *); /* next handler */ + void *chainarg; /* arg for next event handler */ + /* Do not initialize fields hereafter */ +}; + +#define DEV_MODULE_ORDERED(name, evh, arg, ord) \ +static moduledata_t name##_mod = { \ + #name, \ + evh, \ + arg \ +}; \ +DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, ord) + +#define DEV_MODULE(name, evh, arg) \ + DEV_MODULE_ORDERED(name, evh, arg, SI_ORDER_MIDDLE) + +void clone_setup(struct clonedevs **cdp); +void clone_cleanup(struct clonedevs **); +#define CLONE_UNITMASK 0xfffff +#define CLONE_FLAG0 (CLONE_UNITMASK + 1) +int clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, int extra); + +#define MAKEDEV_REF 0x01 +#define MAKEDEV_WHTOUT 0x02 +#define MAKEDEV_NOWAIT 0x04 +#define MAKEDEV_WAITOK 0x08 +#define MAKEDEV_ETERNAL 0x10 +#define MAKEDEV_CHECKNAME 0x20 +struct make_dev_args { + size_t mda_size; + int mda_flags; + struct cdevsw *mda_devsw; + struct ucred *mda_cr; + uid_t mda_uid; + gid_t mda_gid; + int mda_mode; + int mda_unit; + void *mda_si_drv1; + void *mda_si_drv2; +}; +void make_dev_args_init_impl(struct make_dev_args *_args, size_t _sz); +#define make_dev_args_init(a) \ + make_dev_args_init_impl((a), sizeof(struct make_dev_args)) + +int count_dev(struct cdev *_dev); +void delist_dev(struct cdev *_dev); +void destroy_dev(struct cdev *_dev); +int destroy_dev_sched(struct cdev *dev); +int destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg); +void destroy_dev_drain(struct cdevsw *csw); +void drain_dev_clone_events(void); +struct cdevsw *dev_refthread(struct cdev *_dev, int *_ref); +struct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp, int *_ref); +void dev_relthread(struct cdev *_dev, int _ref); +void dev_depends(struct cdev *_pdev, struct cdev *_cdev); +void dev_ref(struct cdev *dev); +void dev_refl(struct cdev *dev); +void dev_rel(struct cdev *dev); +struct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid, + int _perms, const char *_fmt, ...) __printflike(6, 7); +struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit, + struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms, + const char *_fmt, ...) __printflike(7, 8); +struct cdev *make_dev_credf(int _flags, + struct cdevsw *_devsw, int _unit, + struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode, + const char *_fmt, ...) __printflike(8, 9); +int make_dev_p(int _flags, struct cdev **_cdev, struct cdevsw *_devsw, + struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode, + const char *_fmt, ...) __printflike(8, 9); +int make_dev_s(struct make_dev_args *_args, struct cdev **_cdev, + const char *_fmt, ...) __printflike(3, 4); +struct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...) + __printflike(2, 3); +int make_dev_alias_p(int _flags, struct cdev **_cdev, struct cdev *_pdev, + const char *_fmt, ...) __printflike(4, 5); +int make_dev_physpath_alias(int _flags, struct cdev **_cdev, + struct cdev *_pdev, struct cdev *_old_alias, + const char *_physpath); +void dev_lock(void); +void dev_unlock(void); + +#ifdef KLD_MODULE +#define MAKEDEV_ETERNAL_KLD 0 +#else +#define MAKEDEV_ETERNAL_KLD MAKEDEV_ETERNAL +#endif + +#define dev2unit(d) ((d)->si_drv0) + +typedef void d_priv_dtor_t(void *data); +int devfs_get_cdevpriv(void **datap); +int devfs_set_cdevpriv(void *priv, d_priv_dtor_t *dtr); +void devfs_clear_cdevpriv(void); + +ino_t devfs_alloc_cdp_inode(void); +void devfs_free_cdp_inode(ino_t ino); + +#define UID_ROOT 0 +#define UID_BIN 3 +#define UID_UUCP 66 +#define UID_NOBODY 65534 + +#define GID_WHEEL 0 +#define GID_KMEM 2 +#define GID_TTY 4 +#define GID_OPERATOR 5 +#define GID_BIN 7 +#define GID_GAMES 13 +#define GID_VIDEO 44 +#define GID_DIALER 68 +#define GID_NOGROUP 65533 +#define GID_NOBODY 65534 + +typedef void (*dev_clone_fn)(void *arg, struct ucred *cred, char *name, + int namelen, struct cdev **result); + +int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit); +EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn); + +/* Stuff relating to kernel-dump */ +struct kerneldumpcrypto; +struct kerneldumpheader; + +struct dumperinfo { + dumper_t *dumper; /* Dumping function. */ + dumper_start_t *dumper_start; /* Dumper callback for dump_start(). */ + dumper_hdr_t *dumper_hdr; /* Dumper callback for writing headers. */ + void *priv; /* Private parts. */ + u_int blocksize; /* Size of block in bytes. */ + u_int maxiosize; /* Max size allowed for an individual I/O */ + off_t mediaoffset; /* Initial offset in bytes. */ + off_t mediasize; /* Space available in bytes. */ + + /* MI kernel dump state. */ + void *blockbuf; /* Buffer for padding shorter dump blocks */ + off_t dumpoff; /* Offset of ongoing kernel dump. */ + off_t origdumpoff; /* Starting dump offset. */ + struct kerneldumpcrypto *kdcrypto; /* Kernel dump crypto. */ + struct kerneldumpcomp *kdcomp; /* Kernel dump compression. */ +}; + +extern int dumping; /* system is dumping */ + +int doadump(boolean_t); +int set_dumper(struct dumperinfo *di, const char *devname, struct thread *td, + uint8_t compression, uint8_t encryption, const uint8_t *key, + uint32_t encryptedkeysize, const uint8_t *encryptedkey); +int clear_dumper(struct thread *td); + +int dump_start(struct dumperinfo *di, struct kerneldumpheader *kdh); +int dump_append(struct dumperinfo *, void *, vm_offset_t, size_t); +int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t); +int dump_finish(struct dumperinfo *di, struct kerneldumpheader *kdh); +void dump_init_header(const struct dumperinfo *di, struct kerneldumpheader *kdh, + char *magic, uint32_t archver, uint64_t dumplen); + +#endif /* _KERNEL */ + +#endif /* !_SYS_CONF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cons.h b/lib/libc/include/any-freebsd-any/sys/cons.h new file mode 100644 index 000000000000..047846463bf9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cons.h @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)cons.h 7.2 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_CONS_H_ +#define _MACHINE_CONS_H_ + +struct consdev; +struct tty; + +typedef void cn_probe_t(struct consdev *); +typedef void cn_init_t(struct consdev *); +typedef void cn_term_t(struct consdev *); +typedef void cn_grab_t(struct consdev *); +typedef void cn_ungrab_t(struct consdev *); +typedef int cn_getc_t(struct consdev *); +typedef void cn_putc_t(struct consdev *, int); + +struct consdev_ops { + cn_probe_t *cn_probe; + /* probe hardware and fill in consdev info */ + cn_init_t *cn_init; + /* turn on as console */ + cn_term_t *cn_term; + /* turn off as console */ + cn_getc_t *cn_getc; + /* kernel getchar interface */ + cn_putc_t *cn_putc; + /* kernel putchar interface */ + cn_grab_t *cn_grab; + /* grab console for exclusive kernel use */ + cn_ungrab_t *cn_ungrab; + /* ungrab console */ + cn_init_t *cn_resume; + /* set up console after sleep, optional */ +}; + +struct consdev { + const struct consdev_ops *cn_ops; + /* console device operations. */ + short cn_pri; /* pecking order; the higher the better */ + void *cn_arg; /* drivers method argument */ + int cn_flags; /* capabilities of this console */ + char cn_name[SPECNAMELEN + 1]; /* console (device) name */ +}; + +/* values for cn_pri - reflect our policy for console selection */ +#define CN_DEAD 0 /* device doesn't exist */ +#define CN_LOW 1 /* device is a last restort only */ +#define CN_NORMAL 2 /* device exists but is nothing special */ +#define CN_INTERNAL 3 /* "internal" bit-mapped display */ +#define CN_REMOTE 4 /* serial interface with remote bit set */ + +/* Values for cn_flags. */ +#define CN_FLAG_NODEBUG 0x00000001 /* Not supported with debugger. */ +#define CN_FLAG_NOAVAIL 0x00000002 /* Temporarily not available. */ + +/* Visibility of characters in cngets() */ +#define GETS_NOECHO 0 /* Disable echoing of characters. */ +#define GETS_ECHO 1 /* Enable echoing of characters. */ +#define GETS_ECHOPASS 2 /* Print a * for every character. */ + +#ifdef _KERNEL + +extern struct msgbuf consmsgbuf; /* Message buffer for constty. */ +extern struct tty *constty; /* Temporary virtual console. */ + +#define CONSOLE_DEVICE(name, ops, arg) \ + static struct consdev name = { \ + .cn_ops = &ops, \ + .cn_arg = (arg), \ + }; \ + DATA_SET(cons_set, name) + +#define CONSOLE_DRIVER(name, ...) \ + static const struct consdev_ops name##_consdev_ops = { \ + /* Mandatory methods. */ \ + .cn_probe = name##_cnprobe, \ + .cn_init = name##_cninit, \ + .cn_term = name##_cnterm, \ + .cn_getc = name##_cngetc, \ + .cn_putc = name##_cnputc, \ + .cn_grab = name##_cngrab, \ + .cn_ungrab = name##_cnungrab, \ + /* Optional fields. */ \ + __VA_ARGS__ \ + }; \ + CONSOLE_DEVICE(name##_consdev, name##_consdev_ops, NULL) + +/* Other kernel entry points. */ +void cninit(void); +void cninit_finish(void); +int cnadd(struct consdev *); +void cnavailable(struct consdev *, int); +void cnremove(struct consdev *); +void cnselect(struct consdev *); +void cngrab(void); +void cnungrab(void); +void cnresume(void); +int cncheckc(void); +int cngetc(void); +void cngets(char *, size_t, int); +void cnputc(int); +void cnputs(char *); +int cnunavailable(void); +void constty_set(struct tty *tp); +void constty_clear(void); + +/* sc(4) / vt(4) coexistence shim */ +#define VTY_SC 0x01 +#define VTY_VT 0x02 +int vty_enabled(unsigned int); +void vty_set_preferred(unsigned int); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CONS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/consio.h b/lib/libc/include/any-freebsd-any/sys/consio.h new file mode 100644 index 000000000000..5dfedc4bd9f2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/consio.h @@ -0,0 +1,468 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991-1996 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CONSIO_H_ +#define _SYS_CONSIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Console ioctl commands. Some commands are named as KDXXXX, GIO_XXX, and + * PIO_XXX, rather than CONS_XXX, for historical and compatibility reasons. + * Some other CONS_XXX commands are works as wrapper around frame buffer + * ioctl commands FBIO_XXX. Do not try to change all these commands, + * otherwise we shall have compatibility problems. + */ + +/* get/set video mode */ +#define KD_TEXT 0 /* set text mode restore fonts */ +#define KD_TEXT0 0 /* ditto */ +#define KD_GRAPHICS 1 /* set graphics mode */ +#define KD_TEXT1 2 /* set text mode !restore fonts */ +#define KD_PIXEL 3 /* set pixel mode */ +#define KDGETMODE _IOR('K', 9, int) +#define KDSETMODE _IOWINT('K', 10) + +/* set border color */ +#define KDSBORDER _IOWINT('K', 13) + +/* set up raster(pixel) text mode */ +struct _scr_size { + int scr_size[3]; +}; +typedef struct _scr_size scr_size_t; + +#define KDRASTER _IOW('K', 100, scr_size_t) + +/* get/set screen char map */ +struct _scrmap { + char scrmap[256]; +}; +typedef struct _scrmap scrmap_t; + +#define GIO_SCRNMAP _IOR('k', 2, scrmap_t) +#define PIO_SCRNMAP _IOW('k', 3, scrmap_t) + +/* get the current text attribute */ +#define GIO_ATTR _IOR('a', 0, int) + +/* get the current text color */ +#define GIO_COLOR _IOR('c', 0, int) + +/* get the adapter type (equivalent to FBIO_ADPTYPE) */ +#define CONS_CURRENT _IOR('c', 1, int) + +/* get the current video mode (equivalent to FBIO_GETMODE) */ +#define CONS_GET _IOR('c', 2, int) + +/* not supported? */ +#define CONS_IO _IO('c', 3) + +/* set blank time interval */ +#define CONS_BLANKTIME _IOW('c', 4, int) + +/* set/get the screen saver (these ioctls are current noop) */ +struct ssaver { +#define MAXSSAVER 16 + char name[MAXSSAVER]; + int num; + long time; +}; +typedef struct ssaver ssaver_t; + +#define CONS_SSAVER _IOW('c', 5, ssaver_t) +#define CONS_GSAVER _IOWR('c', 6, ssaver_t) + +/* + * Set the text cursor type. + * + * This is an old interface extended to support the CONS_HIDDEN_CURSOR bit. + * New code should use CONS_CURSORSHAPE. CONS_CURSOR_ATTRS gives the 3 + * bits supported by the (extended) old interface. The old interface is + * especially unusable for hiding the cursor (even with its extension) + * since it changes the cursor on all vtys. + */ +#define CONS_CURSORTYPE _IOW('c', 7, int) + +/* set the bell type to audible or visual */ +#define CONS_VISUAL_BELL (1 << 0) +#define CONS_QUIET_BELL (1 << 1) +#define CONS_BELLTYPE _IOW('c', 8, int) + +/* set the history (scroll back) buffer size (in lines) */ +#define CONS_HISTORY _IOW('c', 9, int) + +/* clear the history (scroll back) buffer */ +#define CONS_CLRHIST _IO('c', 10) + +/* mouse cursor ioctl */ +struct mouse_data { + int x; + int y; + int z; + int buttons; +}; +typedef struct mouse_data mouse_data_t; + +struct mouse_mode { + int mode; + int signal; +}; +typedef struct mouse_mode mouse_mode_t; + +struct mouse_event { + int id; /* one based */ + int value; +}; +typedef struct mouse_event mouse_event_t; + +struct mouse_info { + int operation; +#define MOUSE_SHOW 0x01 +#define MOUSE_HIDE 0x02 +#define MOUSE_MOVEABS 0x03 +#define MOUSE_MOVEREL 0x04 +#define MOUSE_GETINFO 0x05 +#define MOUSE_MODE 0x06 +#define MOUSE_ACTION 0x07 +#define MOUSE_MOTION_EVENT 0x08 +#define MOUSE_BUTTON_EVENT 0x09 +#define MOUSE_MOUSECHAR 0x0a + union { + mouse_data_t data; + mouse_mode_t mode; + mouse_event_t event; + int mouse_char; + } u; +}; +typedef struct mouse_info mouse_info_t; + +#define CONS_MOUSECTL _IOWR('c', 10, mouse_info_t) + +/* see if the vty has been idle */ +#define CONS_IDLE _IOR('c', 11, int) + +/* set the screen saver mode */ +#define CONS_NO_SAVER (-1) +#define CONS_LKM_SAVER 0 +#define CONS_USR_SAVER 1 +#define CONS_SAVERMODE _IOW('c', 12, int) + +/* start the screen saver */ +#define CONS_SAVERSTART _IOW('c', 13, int) + +/* set the text cursor shape (see also CONS_CURSORTYPE above) */ +#define CONS_BLINK_CURSOR (1 << 0) +#define CONS_CHAR_CURSOR (1 << 1) +#define CONS_HIDDEN_CURSOR (1 << 2) +#define CONS_CURSOR_ATTRS (CONS_BLINK_CURSOR | CONS_CHAR_CURSOR | \ + CONS_HIDDEN_CURSOR) +#define CONS_CHARCURSOR_COLORS (1 << 26) +#define CONS_MOUSECURSOR_COLORS (1 << 27) +#define CONS_DEFAULT_CURSOR (1 << 28) +#define CONS_SHAPEONLY_CURSOR (1 << 29) +#define CONS_RESET_CURSOR (1 << 30) +#define CONS_LOCAL_CURSOR (1U << 31) +struct cshape { + /* shape[0]: flags, shape[1]: base, shape[2]: height */ + int shape[3]; +}; +#define CONS_GETCURSORSHAPE _IOWR('c', 14, struct cshape) +#define CONS_SETCURSORSHAPE _IOW('c', 15, struct cshape) + +/* set/get font data */ +struct fnt8 { + char fnt8x8[8*256]; +}; +typedef struct fnt8 fnt8_t; + +struct fnt14 { + char fnt8x14[14*256]; +}; +typedef struct fnt14 fnt14_t; + +struct fnt16 { + char fnt8x16[16*256]; +}; +typedef struct fnt16 fnt16_t; + +struct vfnt_map { + uint32_t src; + uint16_t dst; + uint16_t len; +}; +typedef struct vfnt_map vfnt_map_t; + +#define VFNT_MAP_NORMAL 0 +#define VFNT_MAP_NORMAL_RIGHT 1 +#define VFNT_MAP_BOLD 2 +#define VFNT_MAP_BOLD_RIGHT 3 +#define VFNT_MAPS 4 +struct vfnt { + vfnt_map_t *map[VFNT_MAPS]; + uint8_t *glyphs; + unsigned int map_count[VFNT_MAPS]; + unsigned int glyph_count; + unsigned int width; + unsigned int height; +}; +typedef struct vfnt vfnt_t; + +#define PIO_FONT8x8 _IOW('c', 64, fnt8_t) +#define GIO_FONT8x8 _IOR('c', 65, fnt8_t) +#define PIO_FONT8x14 _IOW('c', 66, fnt14_t) +#define GIO_FONT8x14 _IOR('c', 67, fnt14_t) +#define PIO_FONT8x16 _IOW('c', 68, fnt16_t) +#define GIO_FONT8x16 _IOR('c', 69, fnt16_t) +#define PIO_VFONT _IOW('c', 70, vfnt_t) +#define GIO_VFONT _IOR('c', 71, vfnt_t) +#define PIO_VFONT_DEFAULT _IO('c', 72) + +/* get video mode information */ +struct colors { + char fore; + char back; +}; + +struct vid_info { + short size; + short m_num; + u_short font_size; + u_short mv_row, mv_col; + u_short mv_rsz, mv_csz; + u_short mv_hsz; + struct colors mv_norm, + mv_rev, + mv_grfc; + u_char mv_ovscan; + u_char mk_keylock; +}; +typedef struct vid_info vid_info_t; + +#define CONS_GETINFO _IOWR('c', 73, vid_info_t) + +/* get version */ +#define CONS_GETVERS _IOR('c', 74, int) + +/* get the video adapter index (equivalent to FBIO_ADAPTER) */ +#define CONS_CURRENTADP _IOR('c', 100, int) + +/* get the video adapter information (equivalent to FBIO_ADPINFO) */ +#define CONS_ADPINFO _IOWR('c', 101, video_adapter_info_t) + +/* get the video mode information (equivalent to FBIO_MODEINFO) */ +#define CONS_MODEINFO _IOWR('c', 102, video_info_t) + +/* find a video mode (equivalent to FBIO_FINDMODE) */ +#define CONS_FINDMODE _IOWR('c', 103, video_info_t) + +/* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */ +#define CONS_SETWINORG _IOWINT('c', 104) + +/* use the specified keyboard */ +#define CONS_SETKBD _IOWINT('c', 110) + +/* release the current keyboard */ +#define CONS_RELKBD _IO('c', 111) + +struct scrshot { + int x; + int y; + int xsize; + int ysize; + u_int16_t* buf; +}; +typedef struct scrshot scrshot_t; + +/* Snapshot the current video buffer */ +#define CONS_SCRSHOT _IOWR('c', 105, scrshot_t) + +/* get/set the current terminal emulator info. */ +#define TI_NAME_LEN 32 +#define TI_DESC_LEN 64 + +struct term_info { + int ti_index; + int ti_flags; + u_char ti_name[TI_NAME_LEN]; + u_char ti_desc[TI_DESC_LEN]; +}; +typedef struct term_info term_info_t; + +#define CONS_GETTERM _IOWR('c', 112, term_info_t) +#define CONS_SETTERM _IOW('c', 113, term_info_t) + +/* + * Vty switching ioctl commands. + */ + +/* get the next available vty */ +#define VT_OPENQRY _IOR('v', 1, int) + +/* set/get vty switching mode */ +#ifndef _VT_MODE_DECLARED +#define _VT_MODE_DECLARED +struct vt_mode { + char mode; +#define VT_AUTO 0 /* switching is automatic */ +#define VT_PROCESS 1 /* switching controlled by prog */ +#define VT_KERNEL 255 /* switching controlled in kernel */ + char waitv; /* not implemented yet SOS */ + short relsig; + short acqsig; + short frsig; /* not implemented yet SOS */ +}; +typedef struct vt_mode vtmode_t; +#endif /* !_VT_MODE_DECLARED */ + +#define VT_SETMODE _IOW('v', 2, vtmode_t) +#define VT_GETMODE _IOR('v', 3, vtmode_t) + +/* acknowledge release or acquisition of a vty */ +#define VT_FALSE 0 +#define VT_TRUE 1 +#define VT_ACKACQ 2 +#define VT_RELDISP _IOWINT('v', 4) + +/* activate the specified vty */ +#define VT_ACTIVATE _IOWINT('v', 5) + +/* wait until the specified vty is activate */ +#define VT_WAITACTIVE _IOWINT('v', 6) + +/* get the currently active vty */ +#define VT_GETACTIVE _IOR('v', 7, int) + +/* get the index of the vty */ +#define VT_GETINDEX _IOR('v', 8, int) + +/* prevent switching vtys */ +#define VT_LOCKSWITCH _IOW('v', 9, int) + +/* + * Video mode switching ioctl. See sys/fbio.h for mode numbers. + */ + +#define SW_B40x25 _IO('S', M_B40x25) +#define SW_C40x25 _IO('S', M_C40x25) +#define SW_B80x25 _IO('S', M_B80x25) +#define SW_C80x25 _IO('S', M_C80x25) +#define SW_BG320 _IO('S', M_BG320) +#define SW_CG320 _IO('S', M_CG320) +#define SW_BG640 _IO('S', M_BG640) +#define SW_EGAMONO80x25 _IO('S', M_EGAMONO80x25) +#define SW_CG320_D _IO('S', M_CG320_D) +#define SW_CG640_E _IO('S', M_CG640_E) +#define SW_EGAMONOAPA _IO('S', M_EGAMONOAPA) +#define SW_CG640x350 _IO('S', M_CG640x350) +#define SW_ENH_MONOAPA2 _IO('S', M_ENHMONOAPA2) +#define SW_ENH_CG640 _IO('S', M_ENH_CG640) +#define SW_ENH_B40x25 _IO('S', M_ENH_B40x25) +#define SW_ENH_C40x25 _IO('S', M_ENH_C40x25) +#define SW_ENH_B80x25 _IO('S', M_ENH_B80x25) +#define SW_ENH_C80x25 _IO('S', M_ENH_C80x25) +#define SW_ENH_B80x43 _IO('S', M_ENH_B80x43) +#define SW_ENH_C80x43 _IO('S', M_ENH_C80x43) +#define SW_MCAMODE _IO('S', M_MCA_MODE) +#define SW_VGA_C40x25 _IO('S', M_VGA_C40x25) +#define SW_VGA_C80x25 _IO('S', M_VGA_C80x25) +#define SW_VGA_C80x30 _IO('S', M_VGA_C80x30) +#define SW_VGA_C80x50 _IO('S', M_VGA_C80x50) +#define SW_VGA_C80x60 _IO('S', M_VGA_C80x60) +#define SW_VGA_M80x25 _IO('S', M_VGA_M80x25) +#define SW_VGA_M80x30 _IO('S', M_VGA_M80x30) +#define SW_VGA_M80x50 _IO('S', M_VGA_M80x50) +#define SW_VGA_M80x60 _IO('S', M_VGA_M80x60) +#define SW_VGA11 _IO('S', M_VGA11) +#define SW_BG640x480 _IO('S', M_VGA11) +#define SW_VGA12 _IO('S', M_VGA12) +#define SW_CG640x480 _IO('S', M_VGA12) +#define SW_VGA13 _IO('S', M_VGA13) +#define SW_VGA_CG320 _IO('S', M_VGA13) +#define SW_VGA_CG640 _IO('S', M_VGA_CG640) +#define SW_VGA_MODEX _IO('S', M_VGA_MODEX) + +#define SW_VGA_C90x25 _IO('S', M_VGA_C90x25) +#define SW_VGA_M90x25 _IO('S', M_VGA_M90x25) +#define SW_VGA_C90x30 _IO('S', M_VGA_C90x30) +#define SW_VGA_M90x30 _IO('S', M_VGA_M90x30) +#define SW_VGA_C90x43 _IO('S', M_VGA_C90x43) +#define SW_VGA_M90x43 _IO('S', M_VGA_M90x43) +#define SW_VGA_C90x50 _IO('S', M_VGA_C90x50) +#define SW_VGA_M90x50 _IO('S', M_VGA_M90x50) +#define SW_VGA_C90x60 _IO('S', M_VGA_C90x60) +#define SW_VGA_M90x60 _IO('S', M_VGA_M90x60) + +#define SW_TEXT_80x25 _IO('S', M_TEXT_80x25) +#define SW_TEXT_80x30 _IO('S', M_TEXT_80x30) +#define SW_TEXT_80x43 _IO('S', M_TEXT_80x43) +#define SW_TEXT_80x50 _IO('S', M_TEXT_80x50) +#define SW_TEXT_80x60 _IO('S', M_TEXT_80x60) +#define SW_TEXT_132x25 _IO('S', M_TEXT_132x25) +#define SW_TEXT_132x30 _IO('S', M_TEXT_132x30) +#define SW_TEXT_132x43 _IO('S', M_TEXT_132x43) +#define SW_TEXT_132x50 _IO('S', M_TEXT_132x50) +#define SW_TEXT_132x60 _IO('S', M_TEXT_132x60) + +#define SW_VESA_CG640x400 _IO('V', M_VESA_CG640x400 - M_VESA_BASE) +#define SW_VESA_CG640x480 _IO('V', M_VESA_CG640x480 - M_VESA_BASE) +#define SW_VESA_800x600 _IO('V', M_VESA_800x600 - M_VESA_BASE) +#define SW_VESA_CG800x600 _IO('V', M_VESA_CG800x600 - M_VESA_BASE) +#define SW_VESA_1024x768 _IO('V', M_VESA_1024x768 - M_VESA_BASE) +#define SW_VESA_CG1024x768 _IO('V', M_VESA_CG1024x768 - M_VESA_BASE) +#define SW_VESA_1280x1024 _IO('V', M_VESA_1280x1024 - M_VESA_BASE) +#define SW_VESA_CG1280x1024 _IO('V', M_VESA_CG1280x1024 - M_VESA_BASE) +#define SW_VESA_C80x60 _IO('V', M_VESA_C80x60 - M_VESA_BASE) +#define SW_VESA_C132x25 _IO('V', M_VESA_C132x25 - M_VESA_BASE) +#define SW_VESA_C132x43 _IO('V', M_VESA_C132x43 - M_VESA_BASE) +#define SW_VESA_C132x50 _IO('V', M_VESA_C132x50 - M_VESA_BASE) +#define SW_VESA_C132x60 _IO('V', M_VESA_C132x60 - M_VESA_BASE) +#define SW_VESA_32K_320 _IO('V', M_VESA_32K_320 - M_VESA_BASE) +#define SW_VESA_64K_320 _IO('V', M_VESA_64K_320 - M_VESA_BASE) +#define SW_VESA_FULL_320 _IO('V', M_VESA_FULL_320 - M_VESA_BASE) +#define SW_VESA_32K_640 _IO('V', M_VESA_32K_640 - M_VESA_BASE) +#define SW_VESA_64K_640 _IO('V', M_VESA_64K_640 - M_VESA_BASE) +#define SW_VESA_FULL_640 _IO('V', M_VESA_FULL_640 - M_VESA_BASE) +#define SW_VESA_32K_800 _IO('V', M_VESA_32K_800 - M_VESA_BASE) +#define SW_VESA_64K_800 _IO('V', M_VESA_64K_800 - M_VESA_BASE) +#define SW_VESA_FULL_800 _IO('V', M_VESA_FULL_800 - M_VESA_BASE) +#define SW_VESA_32K_1024 _IO('V', M_VESA_32K_1024 - M_VESA_BASE) +#define SW_VESA_64K_1024 _IO('V', M_VESA_64K_1024 - M_VESA_BASE) +#define SW_VESA_FULL_1024 _IO('V', M_VESA_FULL_1024 - M_VESA_BASE) +#define SW_VESA_32K_1280 _IO('V', M_VESA_32K_1280 - M_VESA_BASE) +#define SW_VESA_64K_1280 _IO('V', M_VESA_64K_1280 - M_VESA_BASE) +#define SW_VESA_FULL_1280 _IO('V', M_VESA_FULL_1280 - M_VESA_BASE) + +#endif /* !_SYS_CONSIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/copyright.h b/lib/libc/include/any-freebsd-any/sys/copyright.h new file mode 100644 index 000000000000..55a91c06e048 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/copyright.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 1992-2020 The FreeBSD Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +/* Copyrights macros */ + +/* Add a FreeBSD vendor copyright here */ +#define COPYRIGHT_Vendor \ + "" + +/* FreeBSD */ +#define COPYRIGHT_FreeBSD \ + "Copyright (c) 1992-2020 The FreeBSD Project.\n" + +/* Foundation */ +#define TRADEMARK_Foundation \ + "FreeBSD is a registered trademark of The FreeBSD Foundation.\n" + +/* Berkeley */ +#define COPYRIGHT_UCB \ + "Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994\n\tThe Regents of the University of California. All rights reserved.\n" + +char copyright[] = COPYRIGHT_Vendor COPYRIGHT_FreeBSD COPYRIGHT_UCB; +char trademark[] = TRADEMARK_Foundation; diff --git a/lib/libc/include/any-freebsd-any/sys/counter.h b/lib/libc/include/any-freebsd-any/sys/counter.h new file mode 100644 index 000000000000..3e1b7828d5d4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/counter.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Gleb Smirnoff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __SYS_COUNTER_H__ +#define __SYS_COUNTER_H__ + +typedef uint64_t *counter_u64_t; + +#ifdef _KERNEL +#include + +counter_u64_t counter_u64_alloc(int); +void counter_u64_free(counter_u64_t); + +void counter_u64_zero(counter_u64_t); +uint64_t counter_u64_fetch(counter_u64_t); + +#define COUNTER_ARRAY_ALLOC(a, n, wait) do { \ + for (int _i = 0; _i < (n); _i++) \ + (a)[_i] = counter_u64_alloc(wait); \ +} while (0) + +#define COUNTER_ARRAY_FREE(a, n) do { \ + for (int _i = 0; _i < (n); _i++) \ + counter_u64_free((a)[_i]); \ +} while (0) + +#define COUNTER_ARRAY_COPY(a, dstp, n) do { \ + for (int _i = 0; _i < (n); _i++) \ + ((uint64_t *)(dstp))[_i] = counter_u64_fetch((a)[_i]);\ +} while (0) + +#define COUNTER_ARRAY_ZERO(a, n) do { \ + for (int _i = 0; _i < (n); _i++) \ + counter_u64_zero((a)[_i]); \ +} while (0) + +/* + * counter(9) based rate checking. + */ +struct counter_rate { + counter_u64_t cr_rate; /* Events since last second */ + volatile int cr_lock; /* Lock to clean the struct */ + int cr_ticks; /* Ticks on last clean */ + int cr_over; /* Over limit since cr_ticks? */ +}; + +int64_t counter_ratecheck(struct counter_rate *, int64_t); + +#define COUNTER_U64_SYSINIT(c) \ + SYSINIT(c##_counter_sysinit, SI_SUB_COUNTER, \ + SI_ORDER_ANY, counter_u64_sysinit, &c); \ + SYSUNINIT(c##_counter_sysuninit, SI_SUB_COUNTER, \ + SI_ORDER_ANY, counter_u64_sysuninit, &c) + +#define COUNTER_U64_DEFINE_EARLY(c) \ + counter_u64_t __read_mostly c = EARLY_COUNTER; \ + COUNTER_U64_SYSINIT(c) + +void counter_u64_sysinit(void *); +void counter_u64_sysuninit(void *); + +#endif /* _KERNEL */ +#endif /* ! __SYS_COUNTER_H__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cpu.h b/lib/libc/include/any-freebsd-any/sys/cpu.h new file mode 100644 index 000000000000..8a74e470efcb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cpu.h @@ -0,0 +1,191 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005-2007 Nate Lawson (SDG) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CPU_H_ +#define _SYS_CPU_H_ + +#include + +/* + * CPU device support. + */ + +#define CPU_IVAR_PCPU 1 +#define CPU_IVAR_NOMINAL_MHZ 2 +#define CPU_IVAR_CPUID_SIZE 3 +#define CPU_IVAR_CPUID 4 + +static __inline struct pcpu *cpu_get_pcpu(device_t dev) +{ + uintptr_t v = 0; + BUS_READ_IVAR(device_get_parent(dev), dev, CPU_IVAR_PCPU, &v); + return ((struct pcpu *)v); +} + +static __inline int32_t cpu_get_nominal_mhz(device_t dev) +{ + uintptr_t v = 0; + if (BUS_READ_IVAR(device_get_parent(dev), dev, + CPU_IVAR_NOMINAL_MHZ, &v) != 0) + return (-1); + return ((int32_t)v); +} + +static __inline const uint32_t *cpu_get_cpuid(device_t dev, size_t *count) +{ + uintptr_t v = 0; + if (BUS_READ_IVAR(device_get_parent(dev), dev, + CPU_IVAR_CPUID_SIZE, &v) != 0) + return (NULL); + *count = (size_t)v; + + if (BUS_READ_IVAR(device_get_parent(dev), dev, + CPU_IVAR_CPUID, &v) != 0) + return (NULL); + return ((const uint32_t *)v); +} + +/* + * CPU frequency control interface. + */ + +/* Each driver's CPU frequency setting is exported in this format. */ +struct cf_setting { + int freq; /* CPU clock in Mhz or 100ths of a percent. */ + int volts; /* Voltage in mV. */ + int power; /* Power consumed in mW. */ + int lat; /* Transition latency in us. */ + device_t dev; /* Driver providing this setting. */ + int spec[4];/* Driver-specific storage for non-standard info. */ +}; + +/* Maximum number of settings a given driver can have. */ +#define MAX_SETTINGS 256 + +/* A combination of settings is a level. */ +struct cf_level { + struct cf_setting total_set; + struct cf_setting abs_set; + struct cf_setting rel_set[MAX_SETTINGS]; + int rel_count; + TAILQ_ENTRY(cf_level) link; +}; + +TAILQ_HEAD(cf_level_lst, cf_level); + +/* Drivers should set all unknown values to this. */ +#define CPUFREQ_VAL_UNKNOWN (-1) + +/* + * Every driver offers a type of CPU control. Absolute levels are mutually + * exclusive while relative levels modify the current absolute level. There + * may be multiple absolute and relative drivers available on a given + * system. + * + * For example, consider a system with two absolute drivers that provide + * frequency settings of 100, 200 and 300, 400 and a relative driver that + * provides settings of 50%, 100%. The cpufreq core would export frequency + * levels of 50, 100, 150, 200, 300, 400. + * + * The "info only" flag signifies that settings returned by + * CPUFREQ_DRV_SETTINGS cannot be passed to the CPUFREQ_DRV_SET method and + * are only informational. This is for some drivers that can return + * information about settings but rely on another machine-dependent driver + * for actually performing the frequency transition (e.g., ACPI performance + * states of type "functional fixed hardware.") + */ +#define CPUFREQ_TYPE_MASK 0xffff +#define CPUFREQ_TYPE_RELATIVE (1<<0) +#define CPUFREQ_TYPE_ABSOLUTE (1<<1) +#define CPUFREQ_FLAG_INFO_ONLY (1<<16) + +/* + * When setting a level, the caller indicates the priority of this request. + * Priorities determine, among other things, whether a level can be + * overridden by other callers. For example, if the user sets a level but + * the system thermal driver needs to override it for emergency cooling, + * the driver would use a higher priority. Once the event has passed, the + * driver would call cpufreq to resume any previous level. + */ +#define CPUFREQ_PRIO_HIGHEST 1000000 +#define CPUFREQ_PRIO_KERN 1000 +#define CPUFREQ_PRIO_USER 100 +#define CPUFREQ_PRIO_LOWEST 0 + +/* + * Register and unregister a driver with the cpufreq core. Once a driver + * is registered, it must support calls to its CPUFREQ_GET, CPUFREQ_GET_LEVEL, + * and CPUFREQ_SET methods. It must also unregister before returning from + * its DEVICE_DETACH method. + */ +int cpufreq_register(device_t dev); +int cpufreq_unregister(device_t dev); + +/* + * Notify the cpufreq core that the number of or values for settings have + * changed. + */ +int cpufreq_settings_changed(device_t dev); + +/* + * Eventhandlers that are called before and after a change in frequency. + * The new level and the result of the change (0 is success) is passed in. + * If the driver wishes to revoke the change from cpufreq_pre_change, it + * stores a non-zero error code in the result parameter and the change will + * not be made. If the post-change eventhandler gets a non-zero result, + * no change was made and the previous level remains in effect. If a change + * is revoked, the post-change eventhandler is still called with the error + * value supplied by the revoking driver. This gives listeners who cached + * some data in preparation for a level change a chance to clean up. + */ +typedef void (*cpufreq_pre_notify_fn)(void *, const struct cf_level *, int *); +typedef void (*cpufreq_post_notify_fn)(void *, const struct cf_level *, int); +EVENTHANDLER_DECLARE(cpufreq_pre_change, cpufreq_pre_notify_fn); +EVENTHANDLER_DECLARE(cpufreq_post_change, cpufreq_post_notify_fn); + +/* + * Eventhandler called when the available list of levels changed. + * The unit number of the device (i.e. "cpufreq0") whose levels changed + * is provided so the listener can retrieve the new list of levels. + */ +typedef void (*cpufreq_levels_notify_fn)(void *, int); +EVENTHANDLER_DECLARE(cpufreq_levels_changed, cpufreq_levels_notify_fn); + +/* Allow values to be +/- a bit since sometimes we have to estimate. */ +#define CPUFREQ_CMP(x, y) (abs((x) - (y)) < 25) + +/* + * Machine-dependent functions. + */ + +/* Estimate the current clock rate for the given CPU id. */ +int cpu_est_clockrate(int cpu_id, uint64_t *rate); + +#endif /* !_SYS_CPU_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cpuctl.h b/lib/libc/include/any-freebsd-any/sys/cpuctl.h new file mode 100644 index 000000000000..8c7fb65632f5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cpuctl.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006-2008 Stanislav Sedov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _CPUCTL_H_ +#define _CPUCTL_H_ + +typedef struct { + int msr; /* MSR to read */ + uint64_t data; +} cpuctl_msr_args_t; + +typedef struct { + int level; /* CPUID level */ + uint32_t data[4]; +} cpuctl_cpuid_args_t; + +typedef struct { + int level; /* CPUID level */ + int level_type; /* CPUID level type */ + uint32_t data[4]; +} cpuctl_cpuid_count_args_t; + +typedef struct { + void *data; + size_t size; +} cpuctl_update_args_t; + +#define CPUCTL_RDMSR _IOWR('c', 1, cpuctl_msr_args_t) +#define CPUCTL_WRMSR _IOWR('c', 2, cpuctl_msr_args_t) +#define CPUCTL_CPUID _IOWR('c', 3, cpuctl_cpuid_args_t) +#define CPUCTL_UPDATE _IOWR('c', 4, cpuctl_update_args_t) +#define CPUCTL_MSRSBIT _IOWR('c', 5, cpuctl_msr_args_t) +#define CPUCTL_MSRCBIT _IOWR('c', 6, cpuctl_msr_args_t) +#define CPUCTL_CPUID_COUNT _IOWR('c', 7, cpuctl_cpuid_count_args_t) +#define CPUCTL_EVAL_CPU_FEATURES _IO('c', 8) + +#endif /* _CPUCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/cpuset.h b/lib/libc/include/any-freebsd-any/sys/cpuset.h new file mode 100644 index 000000000000..829237df6fd2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/cpuset.h @@ -0,0 +1,159 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CPUSET_H_ +#define _SYS_CPUSET_H_ + +#include + +#include + +#define _NCPUBITS _BITSET_BITS +#define _NCPUWORDS __bitset_words(CPU_SETSIZE) + +#define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) + +#define CPU_CLR(n, p) BIT_CLR(CPU_SETSIZE, n, p) +#define CPU_COPY(f, t) BIT_COPY(CPU_SETSIZE, f, t) +#define CPU_ISSET(n, p) BIT_ISSET(CPU_SETSIZE, n, p) +#define CPU_SET(n, p) BIT_SET(CPU_SETSIZE, n, p) +#define CPU_ZERO(p) BIT_ZERO(CPU_SETSIZE, p) +#define CPU_FILL(p) BIT_FILL(CPU_SETSIZE, p) +#define CPU_SETOF(n, p) BIT_SETOF(CPU_SETSIZE, n, p) +#define CPU_EMPTY(p) BIT_EMPTY(CPU_SETSIZE, p) +#define CPU_ISFULLSET(p) BIT_ISFULLSET(CPU_SETSIZE, p) +#define CPU_SUBSET(p, c) BIT_SUBSET(CPU_SETSIZE, p, c) +#define CPU_OVERLAP(p, c) BIT_OVERLAP(CPU_SETSIZE, p, c) +#define CPU_CMP(p, c) BIT_CMP(CPU_SETSIZE, p, c) +#define CPU_OR(d, s) BIT_OR(CPU_SETSIZE, d, s) +#define CPU_AND(d, s) BIT_AND(CPU_SETSIZE, d, s) +#define CPU_NAND(d, s) BIT_NAND(CPU_SETSIZE, d, s) +#define CPU_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(CPU_SETSIZE, n, p) +#define CPU_SET_ATOMIC(n, p) BIT_SET_ATOMIC(CPU_SETSIZE, n, p) +#define CPU_SET_ATOMIC_ACQ(n, p) BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p) +#define CPU_AND_ATOMIC(n, p) BIT_AND_ATOMIC(CPU_SETSIZE, n, p) +#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(CPU_SETSIZE, d, s) +#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(CPU_SETSIZE, f, t) +#define CPU_FFS(p) BIT_FFS(CPU_SETSIZE, p) +#define CPU_COUNT(p) BIT_COUNT(CPU_SETSIZE, p) +#define CPUSET_FSET BITSET_FSET(_NCPUWORDS) +#define CPUSET_T_INITIALIZER BITSET_T_INITIALIZER + +/* + * Valid cpulevel_t values. + */ +#define CPU_LEVEL_ROOT 1 /* All system cpus. */ +#define CPU_LEVEL_CPUSET 2 /* Available cpus for which. */ +#define CPU_LEVEL_WHICH 3 /* Actual mask/id for which. */ + +/* + * Valid cpuwhich_t values. + */ +#define CPU_WHICH_TID 1 /* Specifies a thread id. */ +#define CPU_WHICH_PID 2 /* Specifies a process id. */ +#define CPU_WHICH_CPUSET 3 /* Specifies a set id. */ +#define CPU_WHICH_IRQ 4 /* Specifies an irq #. */ +#define CPU_WHICH_JAIL 5 /* Specifies a jail id. */ +#define CPU_WHICH_DOMAIN 6 /* Specifies a NUMA domain id. */ +#define CPU_WHICH_INTRHANDLER 7 /* Specifies an irq # (not ithread). */ +#define CPU_WHICH_ITHREAD 8 /* Specifies an irq's ithread. */ + +/* + * Reserved cpuset identifiers. + */ +#define CPUSET_INVALID -1 +#define CPUSET_DEFAULT 0 + +#ifdef _KERNEL +#include + +LIST_HEAD(setlist, cpuset); + +/* + * cpusets encapsulate cpu binding information for one or more threads. + * + * a - Accessed with atomics. + * s - Set at creation, never modified. Only a ref required to read. + * c - Locked internally by a cpuset lock. + * + * The bitmask is only modified while holding the cpuset lock. It may be + * read while only a reference is held but the consumer must be prepared + * to deal with inconsistent results. + */ +struct cpuset { + cpuset_t cs_mask; /* bitmask of valid cpus. */ + struct domainset *cs_domain; /* (c) NUMA policy. */ + volatile u_int cs_ref; /* (a) Reference count. */ + int cs_flags; /* (s) Flags from below. */ + cpusetid_t cs_id; /* (s) Id or INVALID. */ + struct cpuset *cs_parent; /* (s) Pointer to our parent. */ + LIST_ENTRY(cpuset) cs_link; /* (c) All identified sets. */ + LIST_ENTRY(cpuset) cs_siblings; /* (c) Sibling set link. */ + struct setlist cs_children; /* (c) List of children. */ +}; + +#define CPU_SET_ROOT 0x0001 /* Set is a root set. */ +#define CPU_SET_RDONLY 0x0002 /* No modification allowed. */ + +extern cpuset_t *cpuset_root; +struct prison; +struct proc; +struct thread; + +struct cpuset *cpuset_thread0(void); +struct cpuset *cpuset_ref(struct cpuset *); +void cpuset_rel(struct cpuset *); +int cpuset_setthread(lwpid_t id, cpuset_t *); +int cpuset_setithread(lwpid_t id, int cpu); +int cpuset_create_root(struct prison *, struct cpuset **); +int cpuset_setproc_update_set(struct proc *, struct cpuset *); +int cpuset_which(cpuwhich_t, id_t, struct proc **, + struct thread **, struct cpuset **); +void cpuset_kernthread(struct thread *); + +char *cpusetobj_strprint(char *, const cpuset_t *); +int cpusetobj_strscan(cpuset_t *, const char *); +#ifdef DDB +void ddb_display_cpuset(const cpuset_t *); +#endif + +#else +__BEGIN_DECLS +int cpuset(cpusetid_t *); +int cpuset_setid(cpuwhich_t, id_t, cpusetid_t); +int cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *); +int cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t *); +int cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const cpuset_t *); +__END_DECLS +#endif +#endif /* !_SYS_CPUSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ctype.h b/lib/libc/include/any-freebsd-any/sys/ctype.h new file mode 100644 index 000000000000..d542e45a9473 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ctype.h @@ -0,0 +1,105 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_CTYPE_H_ +#define _SYS_CTYPE_H_ + +#ifdef _KERNEL + +static __inline int +isspace(int c) +{ + return (c == ' ' || (c >= '\t' && c <= '\r')); +} + +static __inline int +isascii(int c) +{ + return ((c & ~0x7f) == 0); +} + +static __inline int +isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static __inline int +islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static __inline int +isalpha(int c) +{ + return (isupper(c) || islower(c)); +} + +static __inline int +isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static __inline int +isxdigit(int c) +{ + return (isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} + +static __inline int +isprint(int c) +{ + return (c >= ' ' && c <= '~'); +} + +static __inline int +toupper(int c) +{ + return (c - 0x20 * ((c >= 'a') && (c <= 'z'))); +} + +static __inline int +tolower(int c) +{ + return (c + 0x20 * ((c >= 'A') && (c <= 'Z'))); +} + +#endif +#endif /* !_SYS_CTYPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/devicestat.h b/lib/libc/include/any-freebsd-any/sys/devicestat.h new file mode 100644 index 000000000000..e3059ce83a5b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/devicestat.h @@ -0,0 +1,209 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _DEVICESTAT_H +#define _DEVICESTAT_H + +#include +#include + +/* + * XXX: Should really be SPECNAMELEN + */ +#define DEVSTAT_NAME_LEN 16 + +/* + * device name for the mmap device + */ +#define DEVSTAT_DEVICE_NAME "devstat" + +/* + * ATTENTION: The devstat version below should be incremented any time a + * change is made in struct devstat, or any time a change is made in the + * enumerated types that struct devstat uses. (Only if those changes + * would require a recompile -- i.e. re-arranging the order of an + * enumerated type or something like that.) This version number is used by + * userland utilities to determine whether or not they are in sync with the + * kernel. + */ +#define DEVSTAT_VERSION 6 + +/* + * These flags specify which statistics features are supported or not + * supported by a particular device. The default is all statistics are + * supported. + */ +typedef enum { + DEVSTAT_ALL_SUPPORTED = 0x00, + DEVSTAT_NO_BLOCKSIZE = 0x01, + DEVSTAT_NO_ORDERED_TAGS = 0x02, + DEVSTAT_BS_UNAVAILABLE = 0x04 +} devstat_support_flags; + +typedef enum { + DEVSTAT_NO_DATA = 0x00, + DEVSTAT_READ = 0x01, + DEVSTAT_WRITE = 0x02, + DEVSTAT_FREE = 0x03 +} devstat_trans_flags; +#define DEVSTAT_N_TRANS_FLAGS 4 + +typedef enum { + DEVSTAT_TAG_SIMPLE = 0x00, + DEVSTAT_TAG_HEAD = 0x01, + DEVSTAT_TAG_ORDERED = 0x02, + DEVSTAT_TAG_NONE = 0x03 +} devstat_tag_type; + +typedef enum { + DEVSTAT_PRIORITY_MIN = 0x000, + DEVSTAT_PRIORITY_OTHER = 0x020, + DEVSTAT_PRIORITY_PASS = 0x030, + DEVSTAT_PRIORITY_FD = 0x040, + DEVSTAT_PRIORITY_WFD = 0x050, + DEVSTAT_PRIORITY_TAPE = 0x060, + DEVSTAT_PRIORITY_CD = 0x090, + DEVSTAT_PRIORITY_DISK = 0x110, + DEVSTAT_PRIORITY_ARRAY = 0x120, + DEVSTAT_PRIORITY_MAX = 0xfff +} devstat_priority; + +/* + * These types are intended to aid statistics gathering/display programs. + * The first 13 types (up to the 'target' flag) are identical numerically + * to the SCSI device type numbers. The next 3 types designate the device + * interface. Currently the choices are IDE, SCSI, and 'other'. The last + * flag specifies whether or not the given device is a passthrough device + * or not. If it is a passthrough device, the lower 4 bits specify which + * type of physical device lies under the passthrough device, and the next + * 4 bits specify the interface. + */ +typedef enum { + DEVSTAT_TYPE_DIRECT = 0x000, + DEVSTAT_TYPE_SEQUENTIAL = 0x001, + DEVSTAT_TYPE_PRINTER = 0x002, + DEVSTAT_TYPE_PROCESSOR = 0x003, + DEVSTAT_TYPE_WORM = 0x004, + DEVSTAT_TYPE_CDROM = 0x005, + DEVSTAT_TYPE_SCANNER = 0x006, + DEVSTAT_TYPE_OPTICAL = 0x007, + DEVSTAT_TYPE_CHANGER = 0x008, + DEVSTAT_TYPE_COMM = 0x009, + DEVSTAT_TYPE_ASC0 = 0x00a, + DEVSTAT_TYPE_ASC1 = 0x00b, + DEVSTAT_TYPE_STORARRAY = 0x00c, + DEVSTAT_TYPE_ENCLOSURE = 0x00d, + DEVSTAT_TYPE_FLOPPY = 0x00e, + DEVSTAT_TYPE_MASK = 0x00f, + DEVSTAT_TYPE_IF_SCSI = 0x010, + DEVSTAT_TYPE_IF_IDE = 0x020, + DEVSTAT_TYPE_IF_OTHER = 0x030, + DEVSTAT_TYPE_IF_MASK = 0x0f0, + DEVSTAT_TYPE_PASS = 0x100 +} devstat_type_flags; + +/* + * XXX: Next revision should add + * off_t offset[DEVSTAT_N_TRANS_FLAGS]; + * XXX: which should contain the offset of the last completed transfer. + */ +struct devstat { + /* Internal house-keeping fields */ + u_int sequence0; /* Update sequence# */ + int allocated; /* Allocated entry */ + u_int start_count; /* started ops */ + u_int end_count; /* completed ops */ + struct bintime busy_from; /* + * busy time unaccounted + * for since this time + */ + STAILQ_ENTRY(devstat) dev_links; + u_int32_t device_number; /* + * Devstat device + * number. + */ + char device_name[DEVSTAT_NAME_LEN]; + int unit_number; + u_int64_t bytes[DEVSTAT_N_TRANS_FLAGS]; + u_int64_t operations[DEVSTAT_N_TRANS_FLAGS]; + struct bintime duration[DEVSTAT_N_TRANS_FLAGS]; + struct bintime busy_time; + struct bintime creation_time; /* + * Time the device was + * created. + */ + u_int32_t block_size; /* Block size, bytes */ + u_int64_t tag_types[3]; /* + * The number of + * simple, ordered, + * and head of queue + * tags sent. + */ + devstat_support_flags flags; /* + * Which statistics + * are supported by a + * given device. + */ + devstat_type_flags device_type; /* Device type */ + devstat_priority priority; /* Controls list pos. */ + const void *id; /* + * Identification for + * GEOM nodes + */ + u_int sequence1; /* Update sequence# */ +}; + +STAILQ_HEAD(devstatlist, devstat); + +#ifdef _KERNEL +struct bio; + +struct devstat *devstat_new_entry(const void *dev_name, int unit_number, + u_int32_t block_size, + devstat_support_flags flags, + devstat_type_flags device_type, + devstat_priority priority); + +void devstat_remove_entry(struct devstat *ds); +void devstat_start_transaction(struct devstat *ds, const struct bintime *now); +void devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); +void devstat_end_transaction(struct devstat *ds, u_int32_t bytes, + devstat_tag_type tag_type, + devstat_trans_flags flags, + const struct bintime *now, + const struct bintime *then); +void devstat_end_transaction_bio(struct devstat *ds, const struct bio *bp); +void devstat_end_transaction_bio_bt(struct devstat *ds, const struct bio *bp, + const struct bintime *now); +#endif + +#endif /* _DEVICESTAT_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/devmap.h b/lib/libc/include/any-freebsd-any/sys/devmap.h new file mode 100644 index 000000000000..23e4bc664575 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/devmap.h @@ -0,0 +1,97 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Ian Lepore + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DEVMAP_H_ +#define _SYS_DEVMAP_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +/* + * This structure is used by MD code to describe static mappings of devices + * which are established as part of bringing up the MMU early in the boot. + */ +struct devmap_entry { + vm_offset_t pd_va; /* virtual address */ + vm_paddr_t pd_pa; /* physical address */ + vm_size_t pd_size; /* size of region */ +}; + +/* + * Return the lowest KVA address used in any entry in the registered devmap + * table. This works with whatever table is registered, including the internal + * table used by devmap_add_entry() if that routine was used. Platforms can + * implement platform_lastaddr() by calling this if static device mappings are + * their only use of high KVA space. + */ +vm_offset_t devmap_lastaddr(void); + +/* + * Automatically allocate KVA (from the top of the address space downwards) and + * make static device mapping entries in an internal table. The internal table + * is automatically registered on the first call to this. + */ +void devmap_add_entry(vm_paddr_t pa, vm_size_t sz); + +/* + * Register a platform-local table to be bootstrapped by the generic + * initarm() in arm/machdep.c. This is used by newer code that allocates and + * fills in its own local table but does not have its own initarm() routine. + */ +void devmap_register_table(const struct devmap_entry * _table); + +/* + * Establish mappings for all the entries in the table. This is called + * automatically from the common initarm() in arm/machdep.c, and also from the + * custom initarm() routines in older code. If the table pointer is NULL, this + * will use the table installed previously by devmap_register_table(). + */ +void devmap_bootstrap(vm_offset_t _l1pt, + const struct devmap_entry *_table); + +/* + * Translate between virtual and physical addresses within a region that is + * static-mapped by the devmap code. If the given address range isn't + * static-mapped, then ptov returns NULL and vtop returns DEVMAP_PADDR_NOTFOUND. + * The latter implies that you can't vtop just the last byte of physical address + * space. This is not as limiting as it might sound, because even if a device + * occupies the end of the physical address space, you're only prevented from + * doing vtop for that single byte. If you vtop a size bigger than 1 it works. + */ +#define DEVMAP_PADDR_NOTFOUND ((vm_paddr_t)(-1)) + +void * devmap_ptov(vm_paddr_t _pa, vm_size_t _sz); +vm_paddr_t devmap_vtop(void * _va, vm_size_t _sz); + +/* Print the static mapping table; used for bootverbose output. */ +void devmap_print_table(void); + +#endif /* !_SYS_DEVMAP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/dir.h b/lib/libc/include/any-freebsd-any/sys/dir.h new file mode 100644 index 000000000000..3c87370270e0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dir.h @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dir.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DIR_H_ +#define _SYS_DIR_H_ + +#include + +#ifdef __CC_SUPPORTS_WARNING +#warning "The information in this file should be obtained from " +#warning "and is provided solely (and temporarily) for backward compatibility." +#endif + +#include + +/* + * Backwards compatibility. + */ +#define direct dirent +#define DIRSIZ(dp) _GENERIC_DIRSIZ(dp) + +#endif /* !_SYS_DIR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/dirent.h b/lib/libc/include/any-freebsd-any/sys/dirent.h new file mode 100644 index 000000000000..5bc6cf49afe7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dirent.h @@ -0,0 +1,144 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dirent.h 8.3 (Berkeley) 8/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DIRENT_H_ +#define _SYS_DIRENT_H_ + +#include +#include + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; +#define _INO_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +/* + * The dirent structure defines the format of directory entries returned by + * the getdirentries(2) system call. + * + * A directory entry has a struct dirent at the front of it, containing its + * inode number, the length of the entry, and the length of the name + * contained in the entry. These are followed by the name padded to an 8 + * byte boundary with null bytes. All names are guaranteed null terminated. + * The maximum length of a name in a directory is MAXNAMLEN. + * + * Explicit padding between the last member of the header (d_namlen) and + * d_name avoids ABI padding at the end of dirent on LP64 architectures. + * There is code depending on d_name being last. + */ + +struct dirent { + ino_t d_fileno; /* file number of entry */ + off_t d_off; /* directory offset of entry */ + __uint16_t d_reclen; /* length of this record */ + __uint8_t d_type; /* file type, see below */ + __uint8_t d_pad0; + __uint16_t d_namlen; /* length of string in d_name */ + __uint16_t d_pad1; +#if __BSD_VISIBLE +#define MAXNAMLEN 255 + char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ +#else + char d_name[255 + 1]; /* name must be no longer than this */ +#endif +}; + +#if defined(_WANT_FREEBSD11_DIRENT) || defined(_KERNEL) +struct freebsd11_dirent { + __uint32_t d_fileno; /* file number of entry */ + __uint16_t d_reclen; /* length of this record */ + __uint8_t d_type; /* file type, see below */ + __uint8_t d_namlen; /* length of string in d_name */ + char d_name[255 + 1]; /* name must be no longer than this */ +}; +#endif /* _WANT_FREEBSD11_DIRENT || _KERNEL */ + +#if __BSD_VISIBLE + +/* + * File types + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 + +/* + * Convert between stat structure types and directory types. + */ +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dirtype) ((dirtype) << 12) + +/* + * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold + * the directory entry. This returns the amount of space in struct dirent + * without the d_name field, plus enough space for the name with a terminating + * null byte (dp->d_namlen+1), rounded up to a 8 byte boundary. + * + * XXX although this macro is in the implementation namespace, it requires + * a manifest constant that is not. + */ +#define _GENERIC_DIRLEN(namlen) \ + ((__offsetof(struct dirent, d_name) + (namlen) + 1 + 7) & ~7) +#define _GENERIC_DIRSIZ(dp) _GENERIC_DIRLEN((dp)->d_namlen) +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) + +/* + * Ensure that padding bytes are zeroed and that the name is NUL-terminated. + */ +static inline void +dirent_terminate(struct dirent *dp) +{ + + dp->d_pad0 = 0; + dp->d_pad1 = 0; + memset(dp->d_name + dp->d_namlen, 0, + dp->d_reclen - (__offsetof(struct dirent, d_name) + dp->d_namlen)); +} +#endif + +#endif /* !_SYS_DIRENT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk.h b/lib/libc/include/any-freebsd-any/sys/disk.h new file mode 100644 index 000000000000..4338b03e924a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk.h @@ -0,0 +1,159 @@ +/*- + * SPDX-License-Identifier: Beerware + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + * + */ + +#ifndef _SYS_DISK_H_ +#define _SYS_DISK_H_ + +#include +#include +#include +#include + +#ifdef _KERNEL + +#ifndef _SYS_CONF_H_ +#include /* XXX: temporary to avoid breakage */ +#endif + +void disk_err(struct bio *bp, const char *what, int blkdone, int nl); + +#endif + +#define DIOCGSECTORSIZE _IOR('d', 128, u_int) + /* + * Get the sector size of the device in bytes. The sector size is the + * smallest unit of data which can be transferred from this device. + * Usually this is a power of 2 but it might not be (i.e. CDROM audio). + */ + +#define DIOCGMEDIASIZE _IOR('d', 129, off_t) /* Get media size in bytes */ + /* + * Get the size of the entire device in bytes. This should be a + * multiple of the sector size. + */ + +#define DIOCGFWSECTORS _IOR('d', 130, u_int) /* Get firmware's sectorcount */ + /* + * Get the firmware's notion of number of sectors per track. This + * value is mostly used for compatibility with various ill designed + * disk label formats. Don't use it unless you have to. + */ + +#define DIOCGFWHEADS _IOR('d', 131, u_int) /* Get firmware's headcount */ + /* + * Get the firmwares notion of number of heads per cylinder. This + * value is mostly used for compatibility with various ill designed + * disk label formats. Don't use it unless you have to. + */ + +#define DIOCSKERNELDUMP_FREEBSD11 _IOW('d', 133, u_int) + /* + * Enable/Disable (the argument is boolean) the device for kernel + * core dumps. + */ + +#define DIOCGFRONTSTUFF _IOR('d', 134, off_t) + /* + * Many disk formats have some amount of space reserved at the + * start of the disk to hold bootblocks, various disklabels and + * similar stuff. This ioctl returns the number of such bytes + * which may apply to the device. + */ + +#define DIOCGFLUSH _IO('d', 135) /* Flush write cache */ + /* + * Flush write cache of the device. + */ + +#define DIOCGDELETE _IOW('d', 136, off_t[2]) /* Delete data */ + /* + * Mark data on the device as unused. + */ + +#define DISK_IDENT_SIZE 256 +#define DIOCGIDENT _IOR('d', 137, char[DISK_IDENT_SIZE]) + /*- + * Get the ident of the given provider. Ident is (most of the time) + * a uniqe and fixed provider's identifier. Ident's properties are as + * follow: + * - ident value is preserved between reboots, + * - provider can be detached/attached and ident is preserved, + * - provider's name can change - ident can't, + * - ident value should not be based on on-disk metadata; in other + * words copying whole data from one disk to another should not + * yield the same ident for the other disk, + * - there could be more than one provider with the same ident, but + * only if they point at exactly the same physical storage, this is + * the case for multipathing for example, + * - GEOM classes that consumes single providers and provide single + * providers, like geli, gbde, should just attach class name to the + * ident of the underlying provider, + * - ident is an ASCII string (is printable), + * - ident is optional and applications can't relay on its presence. + */ + +#define DIOCGPROVIDERNAME _IOR('d', 138, char[MAXPATHLEN]) + /* + * Store the provider name, given a device path, in a buffer. The buffer + * must be at least MAXPATHLEN bytes long. + */ + +#define DIOCGSTRIPESIZE _IOR('d', 139, off_t) /* Get stripe size in bytes */ + /* + * Get the size of the device's optimal access block in bytes. + * This should be a multiple of the sector size. + */ + +#define DIOCGSTRIPEOFFSET _IOR('d', 140, off_t) /* Get stripe offset in bytes */ + /* + * Get the offset of the first device's optimal access block in bytes. + * This should be a multiple of the sector size. + */ + +#define DIOCGPHYSPATH _IOR('d', 141, char[MAXPATHLEN]) + /* + * Get a string defining the physical path for a given provider. + * This has similar rules to ident, but is intended to uniquely + * identify the physical location of the device, not the current + * occupant of that location. + */ + +struct diocgattr_arg { + char name[64]; + int len; + union { + char str[DISK_IDENT_SIZE]; + off_t off; + int i; + uint16_t u16; + } value; +}; +#define DIOCGATTR _IOWR('d', 142, struct diocgattr_arg) + +#define DIOCZONECMD _IOWR('d', 143, struct disk_zone_args) + +struct diocskerneldump_arg { + uint8_t kda_enable; + uint8_t kda_compression; + uint8_t kda_encryption; + uint8_t kda_key[KERNELDUMP_KEY_MAX_SIZE]; + uint32_t kda_encryptedkeysize; + uint8_t *kda_encryptedkey; +}; +#define DIOCSKERNELDUMP _IOW('d', 144, struct diocskerneldump_arg) + /* + * Enable/Disable the device for kernel core dumps. + */ + +#endif /* _SYS_DISK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk/apm.h b/lib/libc/include/any-freebsd-any/sys/disk/apm.h new file mode 100644 index 000000000000..a9183b5e3aa7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk/apm.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2007 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_APM_H_ +#define _SYS_DISK_APM_H_ + +/* Driver Descriptor Record. */ +struct apm_ddr { + uint16_t ddr_sig; +#define APM_DDR_SIG 0x4552 + uint16_t ddr_blksize; + uint32_t ddr_blkcount; +}; + +#define APM_ENT_NAMELEN 32 +#define APM_ENT_TYPELEN 32 + +/* Partition Map Entry Record. */ +struct apm_ent { + uint16_t ent_sig; +#define APM_ENT_SIG 0x504d + uint16_t _pad_; + uint32_t ent_pmblkcnt; + uint32_t ent_start; + uint32_t ent_size; + char ent_name[APM_ENT_NAMELEN]; + char ent_type[APM_ENT_TYPELEN]; +}; + +#define APM_ENT_TYPE_SELF "Apple_partition_map" +#define APM_ENT_TYPE_UNUSED "Apple_Free" + +#define APM_ENT_TYPE_FREEBSD "FreeBSD" +#define APM_ENT_TYPE_FREEBSD_NANDFS "FreeBSD-nandfs" +#define APM_ENT_TYPE_FREEBSD_SWAP "FreeBSD-swap" +#define APM_ENT_TYPE_FREEBSD_UFS "FreeBSD-UFS" +#define APM_ENT_TYPE_FREEBSD_VINUM "FreeBSD-Vinum" +#define APM_ENT_TYPE_FREEBSD_ZFS "FreeBSD-ZFS" + +#define APM_ENT_TYPE_APPLE_BOOT "Apple_Bootstrap" +#define APM_ENT_TYPE_APPLE_HFS "Apple_HFS" +#define APM_ENT_TYPE_APPLE_UFS "Apple_UNIX_SVR2" + +#endif /* _SYS_DISK_APM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk/bsd.h b/lib/libc/include/any-freebsd-any/sys/disk/bsd.h new file mode 100644 index 000000000000..6b1e55ce6545 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk/bsd.h @@ -0,0 +1,191 @@ +/*- + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_BSD_H_ +#define _SYS_DISK_BSD_H_ + +/* The disk magic number */ +#define BSD_MAGIC 0x82564557U + +#define BSD_NPARTS_MIN 8 +#define BSD_NPARTS_MAX 20 + +/* Size of bootblock area in sector-size neutral bytes */ +#define BSD_BOOTBLOCK_SIZE 8192 + +/* partition containing whole disk */ +#define BSD_PART_RAW 2 + +/* partition normally containing swap */ +#define BSD_PART_SWAP 1 + +/* Drive-type specific data size (in number of 32-bit inegrals) */ +#define BSD_NDRIVEDATA 5 + +/* Number of spare 32-bit integrals following drive-type data */ +#define BSD_NSPARE 5 + +struct disklabel { + uint32_t d_magic; /* the magic number */ + uint16_t d_type; /* drive type */ + uint16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + + char d_packname[16]; /* pack identifier */ + + /* disk geometry: */ + uint32_t d_secsize; /* # of bytes per sector */ + uint32_t d_nsectors; /* # of data sectors per track */ + uint32_t d_ntracks; /* # of tracks per cylinder */ + uint32_t d_ncylinders; /* # of data cylinders per unit */ + uint32_t d_secpercyl; /* # of data sectors per cylinder */ + uint32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * d_nsectors or d_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + uint16_t d_sparespertrack; /* # of spare sectors per track */ + uint16_t d_sparespercyl; /* # of spare sectors per cylinder */ + /* + * Alternate cylinders include maintenance, replacement, configuration + * description areas, etc. + */ + uint32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the + * formatter or controller when formatting. When interleaving is + * in use, logically adjacent sectors are not physically + * contiguous, but instead are separated by some number of + * sectors. It is specified as the ratio of physical sectors + * traversed per logical sector. Thus an interleave of 1:1 + * implies contiguous layout, while 2:1 implies that logical + * sector 0 is separated by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N relative to + * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew + * is the offset of sector 0 on cylinder N relative to sector 0 + * on cylinder N-1. + */ + uint16_t d_rpm; /* rotational speed */ + uint16_t d_interleave; /* hardware sector interleave */ + uint16_t d_trackskew; /* sector 0 skew, per track */ + uint16_t d_cylskew; /* sector 0 skew, per cylinder */ + uint32_t d_headswitch; /* head switch time, usec */ + uint32_t d_trkseek; /* track-to-track seek, usec */ + uint32_t d_flags; /* generic flags */ + uint32_t d_drivedata[BSD_NDRIVEDATA]; /* drive-type specific data */ + uint32_t d_spare[BSD_NSPARE]; /* reserved for future use */ + uint32_t d_magic2; /* the magic number (again) */ + uint16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + uint16_t d_npartitions; /* number of partitions in following */ + uint32_t d_bbsize; /* size of boot area at sn0, bytes */ + uint32_t d_sbsize; /* max size of fs superblock, bytes */ + struct partition { /* the partition table */ + uint32_t p_size; /* number of sectors in partition */ + uint32_t p_offset; /* starting sector */ + uint32_t p_fsize; /* filesystem basic fragment size */ + uint8_t p_fstype; /* filesystem type, see below */ + uint8_t p_frag; /* filesystem fragments per block */ + uint16_t p_cpg; /* filesystem cylinders per group */ + } d_partitions[BSD_NPARTS_MIN]; /* actually may be more */ +}; +#ifdef CTASSERT +CTASSERT(sizeof(struct disklabel) == 148 + BSD_NPARTS_MIN * 16); +#endif + +/* d_type values: */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_CCD 11 /* concatenated disk */ +#define DTYPE_VINUM 12 /* vinum volume */ +#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ +#define DTYPE_RAID 14 /* CMU RAIDFrame */ +#define DTYPE_JFS2 16 /* IBM JFS 2 */ + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast filesystem */ +#define FS_MSDOS 8 /* MSDOS filesystem */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured filesystem */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance filesystem */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_VINUM 14 /* Vinum drive */ +#define FS_RAID 15 /* RAIDFrame drive */ +#define FS_FILECORE 16 /* Acorn Filecore Filing System */ +#define FS_EXT2FS 17 /* ext2fs */ +#define FS_NTFS 18 /* Windows/NT file system */ +#define FS_CCD 20 /* concatenated disk component */ +#define FS_JFS2 21 /* IBM JFS2 */ +#define FS_HAMMER 22 /* DragonFlyBSD Hammer FS */ +#define FS_HAMMER2 23 /* DragonFlyBSD Hammer2 FS */ +#define FS_UDF 24 /* UDF */ +#define FS_EFS 26 /* SGI's Extent File system */ +#define FS_ZFS 27 /* Sun's ZFS */ +#define FS_NANDFS 30 /* FreeBSD nandfs (NiLFS derived) */ + +/* + * flags shared by various drives: + */ +#define D_REMOVABLE 0x01 /* removable media */ +#define D_ECC 0x02 /* supports ECC */ +#define D_BADSECT 0x04 /* supports bad sector forw. */ +#define D_RAMDISK 0x08 /* disk emulator */ +#define D_CHAIN 0x10 /* can do back-back transfers */ + +#endif /* !_SYS_DISK_BSD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk/gpt.h b/lib/libc/include/any-freebsd-any/sys/disk/gpt.h new file mode 100644 index 000000000000..ce38a1d1036a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk/gpt.h @@ -0,0 +1,239 @@ +/*- + * Copyright (c) 2002 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_GPT_H_ +#define _SYS_DISK_GPT_H_ + +/* + * Applications can define GPT_UUID_TYPE if they want the GPT structures + * to use a particular type definition for UUIDs/GUIDs. This header uses + * a generic (DCE 1.1 compatible) definition otherwise. + */ +#ifndef GPT_UUID_TYPE +struct gpt_uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[6]; +}; +#define GPT_UUID_TYPE struct gpt_uuid +#endif /* !GPT_UUID_TYPE */ + +typedef GPT_UUID_TYPE gpt_uuid_t; + +#ifdef CTASSERT +CTASSERT(sizeof(gpt_uuid_t) == 16); +#endif + +struct gpt_hdr { + char hdr_sig[8]; +#define GPT_HDR_SIG "EFI PART" + uint32_t hdr_revision; +#define GPT_HDR_REVISION 0x00010000 + uint32_t hdr_size; + uint32_t hdr_crc_self; + uint32_t __reserved; + uint64_t hdr_lba_self; + uint64_t hdr_lba_alt; + uint64_t hdr_lba_start; + uint64_t hdr_lba_end; + gpt_uuid_t hdr_uuid; + uint64_t hdr_lba_table; + uint32_t hdr_entries; + uint32_t hdr_entsz; + uint32_t hdr_crc_table; + /* + * The header as defined in the EFI spec is not a multiple of 8 bytes + * and given that the alignment requirement is on an 8 byte boundary, + * padding will happen. We make the padding explicit so that we can + * correct the value returned by sizeof() when we put the size of the + * header in field hdr_size, or otherwise use offsetof(). + */ + uint32_t padding; +}; +#ifdef CTASSERT +CTASSERT(offsetof(struct gpt_hdr, padding) == 92); +#endif + +struct gpt_ent { + gpt_uuid_t ent_type; + gpt_uuid_t ent_uuid; + uint64_t ent_lba_start; + uint64_t ent_lba_end; + uint64_t ent_attr; +#define GPT_ENT_ATTR_PLATFORM (1ULL << 0) +#define GPT_ENT_ATTR_BOOTME (1ULL << 59) +#define GPT_ENT_ATTR_BOOTONCE (1ULL << 58) +#define GPT_ENT_ATTR_BOOTFAILED (1ULL << 57) + uint16_t ent_name[36]; /* UTF-16. */ +}; +#ifdef CTASSERT +CTASSERT(sizeof(struct gpt_ent) == 128); +#endif /* CTASSERT */ + +#define GPT_ENT_TYPE_UNUSED \ + {0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}} +#define GPT_ENT_TYPE_EFI \ + {0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}} +#define GPT_ENT_TYPE_MBR \ + {0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}} +#define GPT_ENT_TYPE_FREEBSD \ + {0x516e7cb4,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_BOOT \ + {0x83bd6b9d,0x7f41,0x11dc,0xbe,0x0b,{0x00,0x15,0x60,0xb8,0x4f,0x0f}} +#define GPT_ENT_TYPE_FREEBSD_NANDFS \ + {0x74ba7dd9,0xa689,0x11e1,0xbd,0x04,{0x00,0xe0,0x81,0x28,0x6a,0xcf}} +#define GPT_ENT_TYPE_FREEBSD_SWAP \ + {0x516e7cb5,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_UFS \ + {0x516e7cb6,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_VINUM \ + {0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_ZFS \ + {0x516e7cba,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_PREP_BOOT \ + {0x9e1a2d38,0xc612,0x4316,0xaa,0x26,{0x8b,0x49,0x52,0x1e,0x5a,0x8b}} + +/* + * The following are unused but documented here to avoid reuse. + * + * GPT_ENT_TYPE_FREEBSD_UFS2 \ + * {0x516e7cb7,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} + */ + +/* + * Foreign partition types that we're likely to encounter. Note that Linux + * apparently choose to share data partitions with MS. I don't what the + * advantage might be. I can see how sharing swap partitions is advantageous + * though. + */ +#define GPT_ENT_TYPE_MS_BASIC_DATA \ + {0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}} +#define GPT_ENT_TYPE_MS_LDM_DATA \ + {0xaf9b60a0,0x1431,0x4f62,0xbc,0x68,{0x33,0x11,0x71,0x4a,0x69,0xad}} +#define GPT_ENT_TYPE_MS_LDM_METADATA \ + {0x5808c8aa,0x7e8f,0x42e0,0x85,0xd2,{0xe1,0xe9,0x04,0x34,0xcf,0xb3}} +#define GPT_ENT_TYPE_MS_RECOVERY \ + {0xde94bba4,0x06d1,0x4d40,0xa1,0x6a,{0xbf,0xd5,0x01,0x79,0xd6,0xac}} +#define GPT_ENT_TYPE_MS_RESERVED \ + {0xe3c9e316,0x0b5c,0x4db8,0x81,0x7d,{0xf9,0x2d,0xf0,0x02,0x15,0xae}} +#define GPT_ENT_TYPE_MS_SPACES \ + {0xe75caf8f,0xf680,0x4cee,0xaf,0xa3,{0xb0,0x01,0xe5,0x6e,0xfc,0x2d}} + +#define GPT_ENT_TYPE_LINUX_DATA \ + {0x0fc63daf,0x8483,0x4772,0x8e,0x79,{0x3d,0x69,0xd8,0x47,0x7d,0xe4}} +#define GPT_ENT_TYPE_LINUX_RAID \ + {0xa19d880f,0x05fc,0x4d3b,0xa0,0x06,{0x74,0x3f,0x0f,0x84,0x91,0x1e}} +#define GPT_ENT_TYPE_LINUX_SWAP \ + {0x0657fd6d,0xa4ab,0x43c4,0x84,0xe5,{0x09,0x33,0xc8,0x4b,0x4f,0x4f}} +#define GPT_ENT_TYPE_LINUX_LVM \ + {0xe6d6d379,0xf507,0x44c2,0xa2,0x3c,{0x23,0x8f,0x2a,0x3d,0xf9,0x28}} + +#define GPT_ENT_TYPE_VMFS \ + {0xaa31e02a,0x400f,0x11db,0x95,0x90,{0x00,0x0c,0x29,0x11,0xd1,0xb8}} +#define GPT_ENT_TYPE_VMKDIAG \ + {0x9d275380,0x40ad,0x11db,0xbf,0x97,{0x00,0x0c,0x29,0x11,0xd1,0xb8}} +#define GPT_ENT_TYPE_VMRESERVED \ + {0x9198effc,0x31c0,0x11db,0x8f,0x78,{0x00,0x0c,0x29,0x11,0xd1,0xb8}} +#define GPT_ENT_TYPE_VMVSANHDR \ + {0x381cfccc,0x7288,0x11e0,0x92,0xee,{0x00,0x0c,0x29,0x11,0xd0,0xb2}} + +#define GPT_ENT_TYPE_APPLE_BOOT \ + {0x426F6F74,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_HFS \ + {0x48465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_UFS \ + {0x55465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_ZFS \ + {0x6a898cc3,0x1dd2,0x11b2,0x99,0xa6,{0x08,0x00,0x20,0x73,0x66,0x31}} +#define GPT_ENT_TYPE_APPLE_RAID \ + {0x52414944,0x0000,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_RAID_OFFLINE \ + {0x52414944,0x5f4f,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_LABEL \ + {0x4C616265,0x6c00,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_TV_RECOVERY \ + {0x5265636f,0x7665,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_CORE_STORAGE \ + {0x53746f72,0x6167,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} +#define GPT_ENT_TYPE_APPLE_APFS \ + {0x7c3457ef,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}} + +#define GPT_ENT_TYPE_NETBSD_FFS \ + {0x49f48d5a,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}} +#define GPT_ENT_TYPE_NETBSD_LFS \ + {0x49f48d82,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}} +#define GPT_ENT_TYPE_NETBSD_SWAP \ + {0x49f48d32,0xb10e,0x11dc,0xB9,0x9B,{0x00,0x19,0xd1,0x87,0x96,0x48}} +#define GPT_ENT_TYPE_NETBSD_RAID \ + {0x49f48daa,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}} +#define GPT_ENT_TYPE_NETBSD_CCD \ + {0x2db519c4,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}} +#define GPT_ENT_TYPE_NETBSD_CGD \ + {0x2db519ec,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}} + +#define GPT_ENT_TYPE_DRAGONFLY_LABEL32 \ + {0x9d087404,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_SWAP \ + {0x9d58fdbd,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_UFS1 \ + {0x9d94ce7c,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_VINUM \ + {0x9dd4478f,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_CCD \ + {0xdbd5211b,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_LABEL64 \ + {0x3d48ce54,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_LEGACY \ + {0xbd215ab2,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_HAMMER \ + {0x61dc63ac,0x6e38,0x11dc,0x85,0x13,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} +#define GPT_ENT_TYPE_DRAGONFLY_HAMMER2 \ + {0x5cbb9ad1,0x862d,0x11dc,0xa9,0x4d,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}} + +#define GPT_ENT_TYPE_CHROMEOS_FIRMWARE \ + {0xcab6e88e,0xabf3,0x4102,0xa0,0x7a,{0xd4,0xbb,0x9b,0xe3,0xc1,0xd3}} +#define GPT_ENT_TYPE_CHROMEOS_KERNEL \ + {0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}} +#define GPT_ENT_TYPE_CHROMEOS_RESERVED \ + {0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}} +#define GPT_ENT_TYPE_CHROMEOS_ROOT \ + {0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}} + +#define GPT_ENT_TYPE_OPENBSD_DATA \ + {0x824cc7a0,0x36a8,0x11e3,0x89,0x0a,{0x95,0x25,0x19,0xad,0x3f,0x61}} + +/* + * Boot partition used by GRUB 2. + */ +#define GPT_ENT_TYPE_BIOS_BOOT \ + {0x21686148,0x6449,0x6e6f,0x74,0x4e,{0x65,0x65,0x64,0x45,0x46,0x49}} + +#endif /* _SYS_DISK_GPT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk/mbr.h b/lib/libc/include/any-freebsd-any/sys/disk/mbr.h new file mode 100644 index 000000000000..2d7c07b6271b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk/mbr.h @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_MBR_H_ +#define _SYS_DISK_MBR_H_ + +#define DOSBBSECTOR 0 /* DOS boot block relative sector number */ +#define DOSDSNOFF 440 /* WinNT/2K/XP Drive Serial Number offset */ +#define DOSPARTOFF 446 +#define DOSPARTSIZE 16 +#define NDOSPART 4 +#define NEXTDOSPART 32 +#define DOSMAGICOFFSET 510 +#define DOSMAGIC 0xAA55 + +#define DOSPTYP_EXT 0x05 /* DOS extended partition */ +#define DOSPTYP_FAT16 0x06 /* FAT16 partition */ +#define DOSPTYP_NTFS 0x07 /* NTFS partition */ +#define DOSPTYP_FAT32 0x0b /* FAT32 partition */ +#define DOSPTYP_FAT32LBA 0x0c /* FAT32 with LBA partition */ +#define DOSPTYP_EXTLBA 0x0f /* DOS extended partition */ +#define DOSPTYP_PPCBOOT 0x41 /* PReP/CHRP boot partition */ +#define DOSPTYP_LDM 0x42 /* Win2k dynamic extended partition */ +#define DOSPTYP_LINSWP 0x82 /* Linux swap partition */ +#define DOSPTYP_LINUX 0x83 /* Linux partition */ +#define DOSPTYP_LINLVM 0x8e /* Linux LVM partition */ +#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */ +#define DOSPTYP_APPLE_UFS 0xa8 /* Apple Mac OS X boot */ +#define DOSPTYP_APPLE_BOOT 0xab /* Apple Mac OS X UFS */ +#define DOSPTYP_HFS 0xaf /* HFS/HFS+ partition type */ +#define DOSPTYP_PMBR 0xee /* GPT Protective MBR */ +#define DOSPTYP_EFI 0xef /* EFI FAT parition */ +#define DOSPTYP_VMFS 0xfb /* VMware VMFS partition */ +#define DOSPTYP_VMKDIAG 0xfc /* VMware vmkDiagnostic partition */ +#define DOSPTYP_LINRAID 0xfd /* Linux raid partition */ + +struct dos_partition { + unsigned char dp_flag; /* bootstrap flags */ + unsigned char dp_shd; /* starting head */ + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_scyl; /* starting cylinder */ + unsigned char dp_typ; /* partition type */ + unsigned char dp_ehd; /* end head */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ecyl; /* end cylinder */ + uint32_t dp_start; /* absolute starting sector number */ + uint32_t dp_size; /* partition size in sectors */ +}; +#ifdef CTASSERT +CTASSERT(sizeof (struct dos_partition) == DOSPARTSIZE); +#endif + +#define DPSECT(s) ((s) & 0x3f) /* isolate relevant bits of sector */ +#define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */ + +#endif /* !_SYS_DISK_MBR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk/vtoc.h b/lib/libc/include/any-freebsd-any/sys/disk/vtoc.h new file mode 100644 index 000000000000..c784d92717cf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk/vtoc.h @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2008 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_VTOC_H_ +#define _SYS_DISK_VTOC_H_ + +#define VTOC_TAG_UNASSIGNED 0x00 +#define VTOC_TAG_BOOT 0x01 +#define VTOC_TAG_ROOT 0x02 +#define VTOC_TAG_SWAP 0x03 +#define VTOC_TAG_USR 0x04 +#define VTOC_TAG_BACKUP 0x05 /* "c" partition */ +#define VTOC_TAG_STAND 0x06 +#define VTOC_TAG_VAR 0x07 +#define VTOC_TAG_HOME 0x08 +#define VTOC_TAG_ALTSCTR 0x09 /* alternate sector partition */ +#define VTOC_TAG_CACHE 0x0a /* Solaris cachefs partition */ +#define VTOC_TAG_VXVM_PUB 0x0e /* VxVM public region */ +#define VTOC_TAG_VXVM_PRIV 0x0f /* VxVM private region */ + +/* NetBSD/mips defines this */ +#define VTOC_TAG_NETBSD_FFS 0xff + +/* FreeBSD tags: the high byte equals ELFOSABI_FREEBSD */ +#define VTOC_TAG_FREEBSD_SWAP 0x0901 +#define VTOC_TAG_FREEBSD_UFS 0x0902 +#define VTOC_TAG_FREEBSD_VINUM 0x0903 +#define VTOC_TAG_FREEBSD_ZFS 0x0904 +#define VTOC_TAG_FREEBSD_NANDFS 0x0905 + +#define VTOC_FLAG_UNMNT 0x01 /* unmountable partition */ +#define VTOC_FLAG_RDONLY 0x10 /* partition is read/only */ + +#define VTOC_ASCII_LEN 128 +#define VTOC_BOOTSIZE 8192 /* 16 sectors */ +#define VTOC_MAGIC 0xdabe +#define VTOC_RAW_PART 2 +#define VTOC_SANITY 0x600ddeee +#define VTOC_VERSION 1 +#define VTOC_VOLUME_LEN 8 + +#define VTOC8_NPARTS 8 + +struct vtoc8 { + char ascii[VTOC_ASCII_LEN]; + uint32_t version; + char volume[VTOC_VOLUME_LEN]; + uint16_t nparts; + struct { + uint16_t tag; + uint16_t flag; + } part[VTOC8_NPARTS]; + uint16_t __alignment; + uint32_t bootinfo[3]; + uint32_t sanity; + uint32_t reserved[10]; + uint32_t timestamp[VTOC8_NPARTS]; + uint16_t wskip; + uint16_t rskip; + char padding[152]; + uint16_t rpm; + uint16_t physcyls; + uint16_t sparesecs; + uint16_t spare1[2]; + uint16_t interleave; + uint16_t ncyls; + uint16_t altcyls; + uint16_t nheads; + uint16_t nsecs; + uint16_t spare2[2]; + struct { + uint32_t cyl; + uint32_t nblks; + } map[VTOC8_NPARTS]; + uint16_t magic; + uint16_t cksum; +}; + +#ifdef CTASSERT +CTASSERT(sizeof(struct vtoc8) == 512); +#endif + +#endif /* _SYS_DISK_VTOC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disk_zone.h b/lib/libc/include/any-freebsd-any/sys/disk_zone.h new file mode 100644 index 000000000000..89fc3be716bf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disk_zone.h @@ -0,0 +1,186 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015 Spectra Logic Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * Authors: Ken Merry (Spectra Logic Corporation) + * + * $FreeBSD$ + */ + +#ifndef _SYS_DISK_ZONE_H_ +#define _SYS_DISK_ZONE_H_ + +/* + * Interface for Zone-based disks. This allows managing devices that + * conform to the SCSI Zoned Block Commands (ZBC) and ATA Zoned ATA Command + * Set (ZAC) specifications. Devices using these command sets are + * currently (October 2015) hard drives using Shingled Magnetic Recording + * (SMR). + */ + +/* + * There are currently three types of zoned devices: + * + * Drive Managed: + * Drive Managed drives look and act just like a standard random access + * block device, but underneath, the drive reads and writes the bulk of + * its capacity using SMR zones. Sequential writes will yield better + * performance, but writing sequentially is not required. + * + * Host Aware: + * Host Aware drives expose the underlying zone layout via SCSI or ATA + * commands and allow the host to manage the zone conditions. The host + * is not required to manage the zones on the drive, though. Sequential + * writes will yield better performance in Sequential Write Preferred + * zones, but the host can write randomly in those zones. + * + * Host Managed: + * Host Managed drives expose the underlying zone layout via SCSI or ATA + * commands. The host is required to access the zones according to the + * rules described by the zone layout. Any commands that violate the + * rules will be returned with an error. + */ +struct disk_zone_disk_params { + uint32_t zone_mode; +#define DISK_ZONE_MODE_NONE 0x00 +#define DISK_ZONE_MODE_HOST_AWARE 0x01 +#define DISK_ZONE_MODE_DRIVE_MANAGED 0x02 +#define DISK_ZONE_MODE_HOST_MANAGED 0x04 + uint64_t flags; +#define DISK_ZONE_DISK_URSWRZ 0x001 +#define DISK_ZONE_OPT_SEQ_SET 0x002 +#define DISK_ZONE_OPT_NONSEQ_SET 0x004 +#define DISK_ZONE_MAX_SEQ_SET 0x008 +#define DISK_ZONE_RZ_SUP 0x010 +#define DISK_ZONE_OPEN_SUP 0x020 +#define DISK_ZONE_CLOSE_SUP 0x040 +#define DISK_ZONE_FINISH_SUP 0x080 +#define DISK_ZONE_RWP_SUP 0x100 +#define DISK_ZONE_CMD_SUP_MASK 0x1f0 + uint64_t optimal_seq_zones; + uint64_t optimal_nonseq_zones; + uint64_t max_seq_zones; +}; + +/* + * Used for reset write pointer, open, close and finish. + */ +struct disk_zone_rwp { + uint64_t id; + uint8_t flags; +#define DISK_ZONE_RWP_FLAG_NONE 0x00 +#define DISK_ZONE_RWP_FLAG_ALL 0x01 +}; + +/* + * Report Zones header. All of these values are passed out. + */ +struct disk_zone_rep_header { + uint8_t same; +#define DISK_ZONE_SAME_ALL_DIFFERENT 0x0 /* Lengths and types vary */ +#define DISK_ZONE_SAME_ALL_SAME 0x1 /* Lengths and types the same */ +#define DISK_ZONE_SAME_LAST_DIFFERENT 0x2 /* Types same, last len varies */ +#define DISK_ZONE_SAME_TYPES_DIFFERENT 0x3 /* Types vary, length the same */ + uint64_t maximum_lba; + /* + * XXX KDM padding space may not be a good idea inside the bio. + */ + uint8_t reserved[64]; +}; + +/* + * Report Zones entry. Note that the zone types, conditions, and flags + * are mapped directly from the SCSI/ATA flag values. Any additional + * SCSI/ATA zone types or conditions or flags that are defined in the + * future could result in additional values that are not yet defined here. + */ +struct disk_zone_rep_entry { + uint8_t zone_type; +#define DISK_ZONE_TYPE_CONVENTIONAL 0x01 +#define DISK_ZONE_TYPE_SEQ_REQUIRED 0x02 /* Host Managed */ +#define DISK_ZONE_TYPE_SEQ_PREFERRED 0x03 /* Host Aware */ + uint8_t zone_condition; +#define DISK_ZONE_COND_NOT_WP 0x00 +#define DISK_ZONE_COND_EMPTY 0x01 +#define DISK_ZONE_COND_IMPLICIT_OPEN 0x02 +#define DISK_ZONE_COND_EXPLICIT_OPEN 0x03 +#define DISK_ZONE_COND_CLOSED 0x04 +#define DISK_ZONE_COND_READONLY 0x0D +#define DISK_ZONE_COND_FULL 0x0E +#define DISK_ZONE_COND_OFFLINE 0x0F + uint8_t zone_flags; +#define DISK_ZONE_FLAG_RESET 0x01 /* Zone needs RWP */ +#define DISK_ZONE_FLAG_NON_SEQ 0x02 /* Zone accssessed nonseq */ + uint64_t zone_length; + uint64_t zone_start_lba; + uint64_t write_pointer_lba; + /* XXX KDM padding space may not be a good idea inside the bio */ + uint8_t reserved[32]; +}; + +struct disk_zone_report { + uint64_t starting_id; /* Passed In */ + uint8_t rep_options; /* Passed In */ +#define DISK_ZONE_REP_ALL 0x00 +#define DISK_ZONE_REP_EMPTY 0x01 +#define DISK_ZONE_REP_IMP_OPEN 0x02 +#define DISK_ZONE_REP_EXP_OPEN 0x03 +#define DISK_ZONE_REP_CLOSED 0x04 +#define DISK_ZONE_REP_FULL 0x05 +#define DISK_ZONE_REP_READONLY 0x06 +#define DISK_ZONE_REP_OFFLINE 0x07 +#define DISK_ZONE_REP_RWP 0x10 +#define DISK_ZONE_REP_NON_SEQ 0x11 +#define DISK_ZONE_REP_NON_WP 0x3F + struct disk_zone_rep_header header; + uint32_t entries_allocated; /* Passed In */ + uint32_t entries_filled; /* Passed Out */ + uint32_t entries_available; /* Passed Out */ + struct disk_zone_rep_entry *entries; +}; + +union disk_zone_params { + struct disk_zone_disk_params disk_params; + struct disk_zone_rwp rwp; + struct disk_zone_report report; +}; + +struct disk_zone_args { + uint8_t zone_cmd; +#define DISK_ZONE_OPEN 0x00 +#define DISK_ZONE_CLOSE 0x01 +#define DISK_ZONE_FINISH 0x02 +#define DISK_ZONE_REPORT_ZONES 0x03 +#define DISK_ZONE_RWP 0x04 +#define DISK_ZONE_GET_PARAMS 0x05 + union disk_zone_params zone_params; +}; + +#endif /* _SYS_DISK_ZONE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/disklabel.h b/lib/libc/include/any-freebsd-any/sys/disklabel.h new file mode 100644 index 000000000000..6e24f82793fe --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/disklabel.h @@ -0,0 +1,171 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DISKLABEL_H_ +#define _SYS_DISKLABEL_H_ + +#ifndef _KERNEL +#include +#endif +#include + +#include + +/* Disk description table, see disktab(5) */ +#define _PATH_DISKTAB "/etc/disktab" + +/* + * The label is in block 0 or 1, possibly offset from the beginning + * to leave room for a bootstrap, etc. + * XXX these should be defined per controller (or drive) elsewhere, not here! + * XXX in actuality it can't even be per controller or drive. It should be + * constant/fixed across storage hardware and CPU architectures. Disks can + * travel from one machine to another and a label created on one machine + * should be detectable and understood by the other. + */ +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ + +#define DISKMAGIC BSD_MAGIC /* The disk magic number */ + +#ifndef MAXPARTITIONS +#define MAXPARTITIONS BSD_NPARTS_MIN +#endif + +/* Size of bootblock area in sector-size neutral bytes */ +#define BBSIZE BSD_BOOTBLOCK_SIZE + +#define LABEL_PART BSD_PART_RAW +#define RAW_PART BSD_PART_RAW +#define SWAP_PART BSD_PART_SWAP + +#define NDDATA BSD_NDRIVEDATA +#define NSPARE BSD_NSPARE + +static __inline u_int16_t dkcksum(struct disklabel *lp); +static __inline u_int16_t +dkcksum(struct disklabel *lp) +{ + u_int16_t *start, *end; + u_int16_t sum = 0; + + start = (u_int16_t *)lp; + end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions]; + while (start < end) + sum ^= *start++; + return (sum); +} + +#ifdef DKTYPENAMES +static const char *dktypenames[] = { + "unknown", + "SMD", + "MSCP", + "old DEC", + "SCSI", + "ESDI", + "ST506", + "HP-IB", + "HP-FL", + "type 9", + "floppy", + "CCD", + "Vinum", + "DOC2K", + "Raid", + "?", + "jfs", + NULL +}; +#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) +#endif + +#ifdef FSTYPENAMES +static const char *fstypenames[] = { + "unused", + "swap", + "Version 6", + "Version 7", + "System V", + "4.1BSD", + "Eighth Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "vinum", + "raid", + "Filecore", + "EXT2FS", + "NTFS", + "?", + "ccd", + "jfs", + "HAMMER", + "HAMMER2", + "UDF", + "?", + "EFS", + "ZFS", + "?", + "?", + "nandfs", + NULL +}; +#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) +#endif + +/* + * NB: defines ioctls from 'd'/128 and up. + */ + +/* + * Functions for proper encoding/decoding of struct disklabel into/from + * bytestring. + */ +void bsd_partition_le_dec(u_char *ptr, struct partition *d); +int bsd_disklabel_le_dec(u_char *ptr, struct disklabel *d, int maxpart); +void bsd_partition_le_enc(u_char *ptr, struct partition *d); +void bsd_disklabel_le_enc(u_char *ptr, struct disklabel *d); + +#ifndef _KERNEL +__BEGIN_DECLS +struct disklabel *getdiskbyname(const char *); +__END_DECLS +#endif + +#endif /* !_SYS_DISKLABEL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/diskmbr.h b/lib/libc/include/any-freebsd-any/sys/diskmbr.h new file mode 100644 index 000000000000..7bd1e76d5e3b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/diskmbr.h @@ -0,0 +1,46 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DISKMBR_H_ +#define _SYS_DISKMBR_H_ + +#include +#include + +void dos_partition_dec(void const *pp, struct dos_partition *d); +void dos_partition_enc(void *pp, struct dos_partition *d); + +#define DIOCSMBR _IOW('M', 129, u_char[512]) + +#endif /* !_SYS_DISKMBR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/dkstat.h b/lib/libc/include/any-freebsd-any/sys/dkstat.h new file mode 100644 index 000000000000..5e2fb39557d5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dkstat.h @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dkstat.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_DKSTAT_H_ +#define _SYS_DKSTAT_H_ 1 + +#include + +#endif /* _SYS_DKSTAT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/dnv.h b/lib/libc/include/any-freebsd-any/sys/dnv.h new file mode 100644 index 000000000000..3e0322e8565f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dnv.h @@ -0,0 +1,87 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _DNV_H_ +#define _DNV_H_ + +#include + +#ifndef _KERNEL +#include +#include +#include +#include +#endif + +#ifndef _NVLIST_T_DECLARED +#define _NVLIST_T_DECLARED +struct nvlist; + +typedef struct nvlist nvlist_t; +#endif + +__BEGIN_DECLS + +/* + * The dnvlist_get functions returns value associated with the given name. + * If it returns a pointer, the pointer represents internal buffer and should + * not be freed by the caller. + * If no element of the given name and type exists, the function will return + * provided default value. + */ + +bool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval); +uint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval); +const char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval); +const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval); +int dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval); +const void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize); + +/* + * The dnvlist_take functions returns value associated with the given name and + * remove corresponding nvpair. + * If it returns a pointer, the caller has to free it. + * If no element of the given name and type exists, the function will return + * provided default value. + */ + +bool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval); +uint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval); +char *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval); +nvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval); +int dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval); +void *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize); + +__END_DECLS + +#endif /* !_DNV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/domain.h b/lib/libc/include/any-freebsd-any/sys/domain.h new file mode 100644 index 000000000000..513d624b227c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/domain.h @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)domain.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_DOMAIN_H_ +#define _SYS_DOMAIN_H_ + +/* + * Structure per communications domain. + */ + +/* + * Forward structure declarations for function prototypes [sic]. + */ +struct mbuf; +struct ifnet; +struct socket; + +struct domain { + int dom_family; /* AF_xxx */ + char *dom_name; + void (*dom_init) /* initialize domain data structures */ + (void); + void (*dom_destroy) /* cleanup structures / state */ + (void); + int (*dom_externalize) /* externalize access rights */ + (struct mbuf *, struct mbuf **, int); + void (*dom_dispose) /* dispose of internalized rights */ + (struct socket *); + struct protosw *dom_protosw, *dom_protoswNPROTOSW; + struct domain *dom_next; + int (*dom_rtattach) /* initialize routing table */ + (void **, int); + int (*dom_rtdetach) /* clean up routing table */ + (void **, int); + void *(*dom_ifattach)(struct ifnet *); + void (*dom_ifdetach)(struct ifnet *, void *); + int (*dom_ifmtu)(struct ifnet *); + /* af-dependent data on ifnet */ +}; + +#ifdef _KERNEL +extern int domain_init_status; +extern struct domain *domains; +void domain_add(void *); +void domain_init(void *); +#ifdef VIMAGE +void vnet_domain_init(void *); +void vnet_domain_uninit(void *); +#endif + +#define DOMAIN_SET(name) \ + SYSINIT(domain_add_ ## name, SI_SUB_PROTO_DOMAIN, \ + SI_ORDER_FIRST, domain_add, & name ## domain); \ + SYSINIT(domain_init_ ## name, SI_SUB_PROTO_DOMAIN, \ + SI_ORDER_SECOND, domain_init, & name ## domain); +#ifdef VIMAGE +#define VNET_DOMAIN_SET(name) \ + SYSINIT(domain_add_ ## name, SI_SUB_PROTO_DOMAIN, \ + SI_ORDER_FIRST, domain_add, & name ## domain); \ + VNET_SYSINIT(vnet_domain_init_ ## name, SI_SUB_PROTO_DOMAIN, \ + SI_ORDER_SECOND, vnet_domain_init, & name ## domain); \ + VNET_SYSUNINIT(vnet_domain_uninit_ ## name, \ + SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, vnet_domain_uninit, \ + & name ## domain) +#else /* !VIMAGE */ +#define VNET_DOMAIN_SET(name) DOMAIN_SET(name) +#endif /* VIMAGE */ + +#endif /* _KERNEL */ + +#endif /* !_SYS_DOMAIN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/domainset.h b/lib/libc/include/any-freebsd-any/sys/domainset.h new file mode 100644 index 000000000000..5a00347f29d3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/domainset.h @@ -0,0 +1,127 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DOMAINSET_H_ +#define _SYS_DOMAINSET_H_ + +#include +#include +#include + +#define _NDOMAINSETBITS _BITSET_BITS +#define _NDOMAINSETWORDS __bitset_words(DOMAINSET_SETSIZE) + +#define DOMAINSETBUFSIZ \ + (((2 + sizeof(long) * 2) * _NDOMAINSETWORDS) + \ + sizeof("::") + sizeof(__XSTRING(DOMAINSET_POLICY_MAX)) + \ + sizeof(__XSTRING(MAXMEMDOM))) + + +#define DOMAINSET_CLR(n, p) BIT_CLR(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_COPY(f, t) BIT_COPY(DOMAINSET_SETSIZE, f, t) +#define DOMAINSET_ISSET(n, p) BIT_ISSET(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_SET(n, p) BIT_SET(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_ZERO(p) BIT_ZERO(DOMAINSET_SETSIZE, p) +#define DOMAINSET_FILL(p) BIT_FILL(DOMAINSET_SETSIZE, p) +#define DOMAINSET_SETOF(n, p) BIT_SETOF(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_EMPTY(p) BIT_EMPTY(DOMAINSET_SETSIZE, p) +#define DOMAINSET_ISFULLSET(p) BIT_ISFULLSET(DOMAINSET_SETSIZE, p) +#define DOMAINSET_SUBSET(p, c) BIT_SUBSET(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_OVERLAP(p, c) BIT_OVERLAP(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_CMP(p, c) BIT_CMP(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_OR(d, s) BIT_OR(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_AND(d, s) BIT_AND(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_NAND(d, s) BIT_NAND(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_SET_ATOMIC(n, p) BIT_SET_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_SET_ATOMIC_ACQ(n, p) \ + BIT_SET_ATOMIC_ACQ(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_AND_ATOMIC(n, p) BIT_AND_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_OR_ATOMIC(d, s) BIT_OR_ATOMIC(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_COPY_STORE_REL(f, t) \ + BIT_COPY_STORE_REL(DOMAINSET_SETSIZE, f, t) +#define DOMAINSET_FFS(p) BIT_FFS(DOMAINSET_SETSIZE, p) +#define DOMAINSET_FLS(p) BIT_FLS(DOMAINSET_SETSIZE, p) +#define DOMAINSET_COUNT(p) BIT_COUNT(DOMAINSET_SETSIZE, p) +#define DOMAINSET_FSET BITSET_FSET(_NDOMAINSETWORDS) +#define DOMAINSET_T_INITIALIZER BITSET_T_INITIALIZER + +#define DOMAINSET_POLICY_INVALID 0 +#define DOMAINSET_POLICY_ROUNDROBIN 1 +#define DOMAINSET_POLICY_FIRSTTOUCH 2 +#define DOMAINSET_POLICY_PREFER 3 +#define DOMAINSET_POLICY_INTERLEAVE 4 +#define DOMAINSET_POLICY_MAX DOMAINSET_POLICY_INTERLEAVE + +#ifdef _KERNEL +#if MAXMEMDOM < 256 +typedef uint8_t domainid_t; +#else +typedef uint16_t domainid_t; +#endif + +struct domainset { + LIST_ENTRY(domainset) ds_link; + domainset_t ds_mask; /* allowed domains. */ + uint16_t ds_policy; /* Policy type. */ + domainid_t ds_prefer; /* Preferred domain or -1. */ + domainid_t ds_cnt; /* popcnt from above. */ + domainid_t ds_order[MAXMEMDOM]; /* nth domain table. */ +}; + +extern struct domainset domainset_fixed[MAXMEMDOM], domainset_prefer[MAXMEMDOM]; +#define DOMAINSET_FIXED(domain) (&domainset_fixed[(domain)]) +#define DOMAINSET_PREF(domain) (&domainset_prefer[(domain)]) +extern struct domainset domainset_roundrobin; +#define DOMAINSET_RR() (&domainset_roundrobin) + +void domainset_init(void); +void domainset_zero(void); + +/* + * Add a domainset to the system based on a key initializing policy, prefer, + * and mask. Do not create and directly use domainset structures. The + * returned value will not match the key pointer. + */ +struct domainset *domainset_create(const struct domainset *); +#ifdef _SYS_SYSCTL_H_ +int sysctl_handle_domainset(SYSCTL_HANDLER_ARGS); +#endif + +#else +__BEGIN_DECLS +int cpuset_getdomain(cpulevel_t, cpuwhich_t, id_t, size_t, domainset_t *, + int *); +int cpuset_setdomain(cpulevel_t, cpuwhich_t, id_t, size_t, + const domainset_t *, int); + +__END_DECLS +#endif +#endif /* !_SYS_DOMAINSET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/dtrace_bsd.h b/lib/libc/include/any-freebsd-any/sys/dtrace_bsd.h new file mode 100644 index 000000000000..577e27333b6a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dtrace_bsd.h @@ -0,0 +1,175 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2007-2008 John Birrell (jb@freebsd.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * This file contains BSD shims for Sun's DTrace code. + */ + +#ifndef _SYS_DTRACE_BSD_H +#define _SYS_DTRACE_BSD_H + +/* Forward definitions: */ +struct mbuf; +struct trapframe; +struct thread; +struct vattr; +struct vnode; + +int dtrace_trap(struct trapframe *, u_int); + +/* + * The dtrace module handles traps that occur during a DTrace probe. + * This type definition is used in the trap handler to provide a + * hook for the dtrace module to register its handler with. + */ +typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int); +extern dtrace_trap_func_t dtrace_trap_func; + +/* + * A hook which removes active FBT probes before executing the double fault + * handler. We want to ensure that DTrace doesn't trigger another trap, which + * would result in a reset. + */ +typedef void (*dtrace_doubletrap_func_t)(void); +extern dtrace_doubletrap_func_t dtrace_doubletrap_func; + +/* Pid provider hooks */ +typedef int (*dtrace_pid_probe_ptr_t)(struct trapframe *); +extern dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr; +typedef int (*dtrace_return_probe_ptr_t)(struct trapframe *); +extern dtrace_return_probe_ptr_t dtrace_return_probe_ptr; + +/* Virtual time hook function type. */ +typedef void (*dtrace_vtime_switch_func_t)(struct thread *); + +extern int dtrace_vtime_active; +extern dtrace_vtime_switch_func_t dtrace_vtime_switch_func; + +/* The fasttrap module hooks into the fork, exit and exit. */ +typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *); +typedef void (*dtrace_execexit_func_t)(struct proc *); + +/* Global variable in kern_fork.c */ +extern dtrace_fork_func_t dtrace_fasttrap_fork; + +/* Global variable in kern_exec.c */ +extern dtrace_execexit_func_t dtrace_fasttrap_exec; + +/* Global variable in kern_exit.c */ +extern dtrace_execexit_func_t dtrace_fasttrap_exit; + +/* The dtmalloc provider hooks into malloc. */ +typedef void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0, + uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4); + +extern dtrace_malloc_probe_func_t dtrace_malloc_probe; + +/* dtnfsclient NFSv[34] access cache provider hooks. */ +typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t, + struct vnode *); +extern dtrace_nfsclient_accesscache_flush_probe_func_t + dtrace_nfsclient_accesscache_flush_done_probe; +extern dtrace_nfsclient_accesscache_flush_probe_func_t + dtrace_nfscl_accesscache_flush_done_probe; + +typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t, + struct vnode *, uid_t, uint32_t); +extern dtrace_nfsclient_accesscache_get_probe_func_t + dtrace_nfsclient_accesscache_get_hit_probe, + dtrace_nfsclient_accesscache_get_miss_probe; +extern dtrace_nfsclient_accesscache_get_probe_func_t + dtrace_nfscl_accesscache_get_hit_probe, + dtrace_nfscl_accesscache_get_miss_probe; + +typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t, + struct vnode *, uid_t, uint32_t, int); +extern dtrace_nfsclient_accesscache_load_probe_func_t + dtrace_nfsclient_accesscache_load_done_probe; +extern dtrace_nfsclient_accesscache_load_probe_func_t + dtrace_nfscl_accesscache_load_done_probe; + +/* dtnfsclient NFSv[234] attribute cache provider hooks. */ +typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t, + struct vnode *); +extern dtrace_nfsclient_attrcache_flush_probe_func_t + dtrace_nfsclient_attrcache_flush_done_probe; +extern dtrace_nfsclient_attrcache_flush_probe_func_t + dtrace_nfscl_attrcache_flush_done_probe; + +typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t, + struct vnode *, struct vattr *); +extern dtrace_nfsclient_attrcache_get_hit_probe_func_t + dtrace_nfsclient_attrcache_get_hit_probe; +extern dtrace_nfsclient_attrcache_get_hit_probe_func_t + dtrace_nfscl_attrcache_get_hit_probe; + +typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t, + struct vnode *); +extern dtrace_nfsclient_attrcache_get_miss_probe_func_t + dtrace_nfsclient_attrcache_get_miss_probe; +extern dtrace_nfsclient_attrcache_get_miss_probe_func_t + dtrace_nfscl_attrcache_get_miss_probe; + +typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t, + struct vnode *, struct vattr *, int); +extern dtrace_nfsclient_attrcache_load_probe_func_t + dtrace_nfsclient_attrcache_load_done_probe; +extern dtrace_nfsclient_attrcache_load_probe_func_t + dtrace_nfscl_attrcache_load_done_probe; + +/* dtnfsclient NFSv[234] RPC provider hooks. */ +typedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t, + struct vnode *, struct mbuf *, struct ucred *, int); +extern dtrace_nfsclient_nfs23_start_probe_func_t + dtrace_nfsclient_nfs23_start_probe; +extern dtrace_nfsclient_nfs23_start_probe_func_t + dtrace_nfscl_nfs234_start_probe; + +typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t, + struct vnode *, struct mbuf *, struct ucred *, int, int); +extern dtrace_nfsclient_nfs23_done_probe_func_t + dtrace_nfsclient_nfs23_done_probe; +extern dtrace_nfsclient_nfs23_done_probe_func_t + dtrace_nfscl_nfs234_done_probe; + +/* + * Functions which allow the dtrace module to check that the kernel + * hooks have been compiled with sufficient space for it's private + * structures. + */ +size_t kdtrace_proc_size(void); +size_t kdtrace_thread_size(void); + +/* + * OpenSolaris compatible time functions returning nanoseconds. + * On OpenSolaris these return hrtime_t which we define as uint64_t. + */ +uint64_t dtrace_gethrtime(void); +uint64_t dtrace_gethrestime(void); + +#endif /* _SYS_DTRACE_BSD_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/dvdio.h b/lib/libc/include/any-freebsd-any/sys/dvdio.h new file mode 100644 index 000000000000..6d6f2f53bc1f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/dvdio.h @@ -0,0 +1,112 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999,2000,2001,2002 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_DVDIO_H_ +#define _SYS_DVDIO_H_ + +struct dvd_layer { + u_int8_t book_type :4; + u_int8_t book_version :4; + u_int8_t disc_size :4; + u_int8_t max_rate :4; + u_int8_t nlayers :2; + u_int8_t track_path :1; + u_int8_t layer_type :4; + u_int8_t linear_density :4; + u_int8_t track_density :4; + u_int8_t bca :1; + u_int32_t start_sector; + u_int32_t end_sector; + u_int32_t end_sector_l0; +}; + +struct dvd_struct { + u_char format; + u_char layer_num; + u_char cpst; + u_char rmi; + u_int8_t agid :2; + u_int32_t length; + u_char data[2048]; +}; + +struct dvd_authinfo { + unsigned char format; + u_int8_t agid :2; + u_int8_t asf :1; + u_int8_t cpm :1; + u_int8_t cp_sec :1; + u_int8_t cgms :2; + u_int8_t reg_type :2; + u_int8_t vend_rsts :3; + u_int8_t user_rsts :3; + u_int8_t region; + u_int8_t rpc_scheme; + u_int32_t lba; + u_char keychal[10]; +}; + +#define DVD_STRUCT_PHYSICAL 0x00 +#define DVD_STRUCT_COPYRIGHT 0x01 +#define DVD_STRUCT_DISCKEY 0x02 +#define DVD_STRUCT_BCA 0x03 +#define DVD_STRUCT_MANUFACT 0x04 +#define DVD_STRUCT_CMI 0x05 +#define DVD_STRUCT_PROTDISCID 0x06 +#define DVD_STRUCT_DISCKEYBLOCK 0x07 +#define DVD_STRUCT_DDS 0x08 +#define DVD_STRUCT_MEDIUM_STAT 0x09 +#define DVD_STRUCT_SPARE_AREA 0x0A +#define DVD_STRUCT_RMD_LAST 0x0C +#define DVD_STRUCT_RMD_RMA 0x0D +#define DVD_STRUCT_PRERECORDED 0x0E +#define DVD_STRUCT_UNIQUEID 0x0F +#define DVD_STRUCT_DCB 0x30 +#define DVD_STRUCT_LIST 0xFF + +#define DVD_REPORT_AGID 0 +#define DVD_REPORT_CHALLENGE 1 +#define DVD_REPORT_KEY1 2 +#define DVD_REPORT_TITLE_KEY 4 +#define DVD_REPORT_ASF 5 +#define DVD_REPORT_RPC 8 +#define DVD_INVALIDATE_AGID 0x3f + +#define DVD_SEND_CHALLENGE 1 +#define DVD_SEND_KEY2 3 +#define DVD_SEND_RPC 6 + +#define DVDIOCREPORTKEY _IOWR('c', 200, struct dvd_authinfo) +#define DVDIOCSENDKEY _IOWR('c', 201, struct dvd_authinfo) +#define DVDIOCREADSTRUCTURE _IOWR('c', 202, struct dvd_struct) + +#endif /* _SYS_DVDIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/efi.h b/lib/libc/include/any-freebsd-any/sys/efi.h new file mode 100644 index 000000000000..622df48e7f32 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/efi.h @@ -0,0 +1,197 @@ +/*- + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EFI_H_ +#define _SYS_EFI_H_ + +#include +#include + +#define EFI_PAGE_SHIFT 12 +#define EFI_PAGE_SIZE (1 << EFI_PAGE_SHIFT) +#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1) + +#define EFI_TABLE_ACPI20 \ + {0x8868e871,0xe4f1,0x11d3,0xbc,0x22,{0x00,0x80,0xc7,0x3c,0x88,0x81}} +#define EFI_TABLE_SAL \ + {0xeb9d2d32,0x2d88,0x11d3,0x9a,0x16,{0x00,0x90,0x27,0x3f,0xc1,0x4d}} + +enum efi_reset { + EFI_RESET_COLD, + EFI_RESET_WARM +}; + +typedef uint16_t efi_char; +typedef unsigned long efi_status; + +struct efi_cfgtbl { + struct uuid ct_uuid; + uint64_t ct_data; +}; + +struct efi_md { + uint32_t md_type; +#define EFI_MD_TYPE_NULL 0 +#define EFI_MD_TYPE_CODE 1 /* Loader text. */ +#define EFI_MD_TYPE_DATA 2 /* Loader data. */ +#define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */ +#define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */ +#define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */ +#define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */ +#define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */ +#define EFI_MD_TYPE_BAD 8 /* Bad memory */ +#define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */ +#define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */ +#define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */ +#define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */ +#define EFI_MD_TYPE_PALCODE 13 /* PAL */ +#define EFI_MD_TYPE_PERSISTENT 14 /* Persistent memory. */ + uint32_t __pad; + uint64_t md_phys; + void *md_virt; + uint64_t md_pages; + uint64_t md_attr; +#define EFI_MD_ATTR_UC 0x0000000000000001UL +#define EFI_MD_ATTR_WC 0x0000000000000002UL +#define EFI_MD_ATTR_WT 0x0000000000000004UL +#define EFI_MD_ATTR_WB 0x0000000000000008UL +#define EFI_MD_ATTR_UCE 0x0000000000000010UL +#define EFI_MD_ATTR_WP 0x0000000000001000UL +#define EFI_MD_ATTR_RP 0x0000000000002000UL +#define EFI_MD_ATTR_XP 0x0000000000004000UL +#define EFI_MD_ATTR_NV 0x0000000000008000UL +#define EFI_MD_ATTR_MORE_RELIABLE \ + 0x0000000000010000UL +#define EFI_MD_ATTR_RO 0x0000000000020000UL +#define EFI_MD_ATTR_RT 0x8000000000000000UL +}; + +#define efi_next_descriptor(ptr, size) \ + ((struct efi_md *)(((uint8_t *)(ptr)) + (size))) + +struct efi_tm { + uint16_t tm_year; /* 1998 - 20XX */ + uint8_t tm_mon; /* 1 - 12 */ + uint8_t tm_mday; /* 1 - 31 */ + uint8_t tm_hour; /* 0 - 23 */ + uint8_t tm_min; /* 0 - 59 */ + uint8_t tm_sec; /* 0 - 59 */ + uint8_t __pad1; + uint32_t tm_nsec; /* 0 - 999,999,999 */ + int16_t tm_tz; /* -1440 to 1440 or 2047 */ + uint8_t tm_dst; + uint8_t __pad2; +}; + +struct efi_tmcap { + uint32_t tc_res; /* 1e-6 parts per million */ + uint32_t tc_prec; /* hertz */ + uint8_t tc_stz; /* Set clears sub-second time */ +}; + +struct efi_tblhdr { + uint64_t th_sig; + uint32_t th_rev; + uint32_t th_hdrsz; + uint32_t th_crc32; + uint32_t __res; +}; + +#ifdef _KERNEL + +#ifdef EFIABI_ATTR +struct efi_rt { + struct efi_tblhdr rt_hdr; + efi_status (*rt_gettime)(struct efi_tm *, struct efi_tmcap *) + EFIABI_ATTR; + efi_status (*rt_settime)(struct efi_tm *) EFIABI_ATTR; + efi_status (*rt_getwaketime)(uint8_t *, uint8_t *, + struct efi_tm *) EFIABI_ATTR; + efi_status (*rt_setwaketime)(uint8_t, struct efi_tm *) + EFIABI_ATTR; + efi_status (*rt_setvirtual)(u_long, u_long, uint32_t, + struct efi_md *) EFIABI_ATTR; + efi_status (*rt_cvtptr)(u_long, void **) EFIABI_ATTR; + efi_status (*rt_getvar)(efi_char *, struct uuid *, uint32_t *, + u_long *, void *) EFIABI_ATTR; + efi_status (*rt_scanvar)(u_long *, efi_char *, struct uuid *) + EFIABI_ATTR; + efi_status (*rt_setvar)(efi_char *, struct uuid *, uint32_t, + u_long, void *) EFIABI_ATTR; + efi_status (*rt_gethicnt)(uint32_t *) EFIABI_ATTR; + efi_status (*rt_reset)(enum efi_reset, efi_status, u_long, + efi_char *) EFIABI_ATTR; +}; +#endif + +struct efi_systbl { + struct efi_tblhdr st_hdr; +#define EFI_SYSTBL_SIG 0x5453595320494249UL + efi_char *st_fwvendor; + uint32_t st_fwrev; + uint32_t __pad; + void *st_cin; + void *st_cinif; + void *st_cout; + void *st_coutif; + void *st_cerr; + void *st_cerrif; + uint64_t st_rt; + void *st_bs; + u_long st_entries; + uint64_t st_cfgtbl; +}; + +extern vm_paddr_t efi_systbl_phys; + +struct efirt_callinfo; + +/* Internal MD EFI functions */ +int efi_arch_enter(void); +void efi_arch_leave(void); +vm_offset_t efi_phys_to_kva(vm_paddr_t); +int efi_rt_arch_call(struct efirt_callinfo *); +bool efi_create_1t1_map(struct efi_md *, int, int); +void efi_destroy_1t1_map(void); + +/* Public MI EFI functions */ +int efi_rt_ok(void); +int efi_get_table(struct uuid *uuid, void **ptr); +int efi_get_time(struct efi_tm *tm); +int efi_get_time_capabilities(struct efi_tmcap *tmcap); +int efi_reset_system(void); +int efi_set_time(struct efi_tm *tm); +int efi_var_get(uint16_t *name, struct uuid *vendor, uint32_t *attrib, + size_t *datasize, void *data); +int efi_var_nextname(size_t *namesize, uint16_t *name, struct uuid *vendor); +int efi_var_set(uint16_t *name, struct uuid *vendor, uint32_t attrib, + size_t datasize, void *data); + +#endif /* _KERNEL */ + +#endif /* _SYS_EFI_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/efiio.h b/lib/libc/include/any-freebsd-any/sys/efiio.h new file mode 100644 index 000000000000..87fed9c3afd8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/efiio.h @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2016 Netflix, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EFIIO_H_ +#define _SYS_EFIIO_H_ + +#include +#include +#include + +struct efi_get_table_ioc +{ + struct uuid uuid; /* UUID to look up */ + void *ptr; /* Pointer to table in KVA space */ +}; + +struct efi_var_ioc +{ + efi_char *name; /* User pointer to name, in wide chars */ + size_t namesize; /* Number of wide characters in name */ + struct uuid vendor; /* Vendor's UUID for variable */ + uint32_t attrib; /* Attributes */ + void *data; /* User pointer to the data */ + size_t datasize; /* Number of *bytes* in the data */ +}; + +#define EFIIOC_GET_TABLE _IOWR('E', 1, struct efi_get_table_ioc) +#define EFIIOC_GET_TIME _IOR('E', 2, struct efi_tm) +#define EFIIOC_SET_TIME _IOW('E', 3, struct efi_tm) +#define EFIIOC_VAR_GET _IOWR('E', 4, struct efi_var_ioc) +#define EFIIOC_VAR_NEXT _IOWR('E', 5, struct efi_var_ioc) +#define EFIIOC_VAR_SET _IOWR('E', 6, struct efi_var_ioc) + +#endif /* _SYS_EFIIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/elf.h b/lib/libc/include/any-freebsd-any/sys/elf.h new file mode 100644 index 000000000000..f9bc91b30640 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/elf.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 David E. O'Brien. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * This is a Solaris compatibility header + */ + +#ifndef _SYS_ELF_H_ +#define _SYS_ELF_H_ + +#include +#include +#include +#include + +#endif /* !_SYS_ELF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/elf32.h b/lib/libc/include/any-freebsd-any/sys/elf32.h new file mode 100644 index 000000000000..ad44b7cf970a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/elf32.h @@ -0,0 +1,265 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996-1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ELF32_H_ +#define _SYS_ELF32_H_ 1 + +#include + +/* + * ELF definitions common to all 32-bit architectures. + */ + +typedef uint32_t Elf32_Addr; +typedef uint16_t Elf32_Half; +typedef uint32_t Elf32_Off; +typedef int32_t Elf32_Sword; +typedef uint32_t Elf32_Word; +typedef uint64_t Elf32_Lword; + +typedef Elf32_Word Elf32_Hashelt; + +/* Non-standard class-dependent datatype used for abstraction. */ +typedef Elf32_Word Elf32_Size; +typedef Elf32_Sword Elf32_Ssize; + +/* + * ELF header. + */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* File identification. */ + Elf32_Half e_type; /* File type. */ + Elf32_Half e_machine; /* Machine architecture. */ + Elf32_Word e_version; /* ELF format version. */ + Elf32_Addr e_entry; /* Entry point. */ + Elf32_Off e_phoff; /* Program header file offset. */ + Elf32_Off e_shoff; /* Section header file offset. */ + Elf32_Word e_flags; /* Architecture-specific flags. */ + Elf32_Half e_ehsize; /* Size of ELF header in bytes. */ + Elf32_Half e_phentsize; /* Size of program header entry. */ + Elf32_Half e_phnum; /* Number of program header entries. */ + Elf32_Half e_shentsize; /* Size of section header entry. */ + Elf32_Half e_shnum; /* Number of section header entries. */ + Elf32_Half e_shstrndx; /* Section name strings section. */ +} Elf32_Ehdr; + +/* + * Shared object information, found in SHT_MIPS_LIBLIST. + */ + +typedef struct { + Elf32_Word l_name; /* The name of a shared object. */ + Elf32_Word l_time_stamp; /* 32-bit timestamp. */ + Elf32_Word l_checksum; /* Checksum of visible symbols, sizes. */ + Elf32_Word l_version; /* Interface version string index. */ + Elf32_Word l_flags; /* Flags (LL_*). */ +} Elf32_Lib; + +/* + * Section header. + */ + +typedef struct { + Elf32_Word sh_name; /* Section name (index into the + section header string table). */ + Elf32_Word sh_type; /* Section type. */ + Elf32_Word sh_flags; /* Section flags. */ + Elf32_Addr sh_addr; /* Address in memory image. */ + Elf32_Off sh_offset; /* Offset in file. */ + Elf32_Word sh_size; /* Size in bytes. */ + Elf32_Word sh_link; /* Index of a related section. */ + Elf32_Word sh_info; /* Depends on section type. */ + Elf32_Word sh_addralign; /* Alignment in bytes. */ + Elf32_Word sh_entsize; /* Size of each entry in section. */ +} Elf32_Shdr; + +/* + * Program header. + */ + +typedef struct { + Elf32_Word p_type; /* Entry type. */ + Elf32_Off p_offset; /* File offset of contents. */ + Elf32_Addr p_vaddr; /* Virtual address in memory image. */ + Elf32_Addr p_paddr; /* Physical address (not used). */ + Elf32_Word p_filesz; /* Size of contents in file. */ + Elf32_Word p_memsz; /* Size of contents in memory. */ + Elf32_Word p_flags; /* Access permission flags. */ + Elf32_Word p_align; /* Alignment in memory and file. */ +} Elf32_Phdr; + +/* + * Dynamic structure. The ".dynamic" section contains an array of them. + */ + +typedef struct { + Elf32_Sword d_tag; /* Entry type. */ + union { + Elf32_Word d_val; /* Integer value. */ + Elf32_Addr d_ptr; /* Address value. */ + } d_un; +} Elf32_Dyn; + +/* + * Relocation entries. + */ + +/* Relocations that don't need an addend field. */ +typedef struct { + Elf32_Addr r_offset; /* Location to be relocated. */ + Elf32_Word r_info; /* Relocation type and symbol index. */ +} Elf32_Rel; + +/* Relocations that need an addend field. */ +typedef struct { + Elf32_Addr r_offset; /* Location to be relocated. */ + Elf32_Word r_info; /* Relocation type and symbol index. */ + Elf32_Sword r_addend; /* Addend. */ +} Elf32_Rela; + +/* Macros for accessing the fields of r_info. */ +#define ELF32_R_SYM(info) ((info) >> 8) +#define ELF32_R_TYPE(info) ((unsigned char)(info)) + +/* Macro for constructing r_info from field values. */ +#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) + +/* + * Note entry header + */ +typedef Elf_Note Elf32_Nhdr; + +/* + * Move entry + */ +typedef struct { + Elf32_Lword m_value; /* symbol value */ + Elf32_Word m_info; /* size + index */ + Elf32_Word m_poffset; /* symbol offset */ + Elf32_Half m_repeat; /* repeat count */ + Elf32_Half m_stride; /* stride info */ +} Elf32_Move; + +/* + * The macros compose and decompose values for Move.r_info + * + * sym = ELF32_M_SYM(M.m_info) + * size = ELF32_M_SIZE(M.m_info) + * M.m_info = ELF32_M_INFO(sym, size) + */ +#define ELF32_M_SYM(info) ((info)>>8) +#define ELF32_M_SIZE(info) ((unsigned char)(info)) +#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) + +/* + * Hardware/Software capabilities entry + */ +typedef struct { + Elf32_Word c_tag; /* how to interpret value */ + union { + Elf32_Word c_val; + Elf32_Addr c_ptr; + } c_un; +} Elf32_Cap; + +/* + * Symbol table entries. + */ + +typedef struct { + Elf32_Word st_name; /* String table index of name. */ + Elf32_Addr st_value; /* Symbol value. */ + Elf32_Word st_size; /* Size of associated object. */ + unsigned char st_info; /* Type and binding information. */ + unsigned char st_other; /* Reserved (not used). */ + Elf32_Half st_shndx; /* Section index of symbol. */ +} Elf32_Sym; + +/* Macros for accessing the fields of st_info. */ +#define ELF32_ST_BIND(info) ((info) >> 4) +#define ELF32_ST_TYPE(info) ((info) & 0xf) + +/* Macro for constructing st_info from field values. */ +#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) + +/* Macro for accessing the fields of st_other. */ +#define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3) + +/* Structures used by Sun & GNU symbol versioning. */ +typedef struct +{ + Elf32_Half vd_version; + Elf32_Half vd_flags; + Elf32_Half vd_ndx; + Elf32_Half vd_cnt; + Elf32_Word vd_hash; + Elf32_Word vd_aux; + Elf32_Word vd_next; +} Elf32_Verdef; + +typedef struct +{ + Elf32_Word vda_name; + Elf32_Word vda_next; +} Elf32_Verdaux; + +typedef struct +{ + Elf32_Half vn_version; + Elf32_Half vn_cnt; + Elf32_Word vn_file; + Elf32_Word vn_aux; + Elf32_Word vn_next; +} Elf32_Verneed; + +typedef struct +{ + Elf32_Word vna_hash; + Elf32_Half vna_flags; + Elf32_Half vna_other; + Elf32_Word vna_name; + Elf32_Word vna_next; +} Elf32_Vernaux; + +typedef Elf32_Half Elf32_Versym; + +typedef struct { + Elf32_Half si_boundto; /* direct bindings - symbol bound to */ + Elf32_Half si_flags; /* per symbol flags */ +} Elf32_Syminfo; + +typedef struct { + Elf32_Word ch_type; + Elf32_Word ch_size; + Elf32_Word ch_addralign; +} Elf32_Chdr; + +#endif /* !_SYS_ELF32_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/elf64.h b/lib/libc/include/any-freebsd-any/sys/elf64.h new file mode 100644 index 000000000000..880166a3e83a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/elf64.h @@ -0,0 +1,269 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996-1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ELF64_H_ +#define _SYS_ELF64_H_ 1 + +#include + +/* + * ELF definitions common to all 64-bit architectures. + */ + +typedef uint64_t Elf64_Addr; +typedef uint16_t Elf64_Half; +typedef uint64_t Elf64_Off; +typedef int32_t Elf64_Sword; +typedef int64_t Elf64_Sxword; +typedef uint32_t Elf64_Word; +typedef uint64_t Elf64_Lword; +typedef uint64_t Elf64_Xword; + +/* + * Types of dynamic symbol hash table bucket and chain elements. + * + * This is inconsistent among 64 bit architectures, so a machine dependent + * typedef is required. + */ + +typedef Elf64_Word Elf64_Hashelt; + +/* Non-standard class-dependent datatype used for abstraction. */ +typedef Elf64_Xword Elf64_Size; +typedef Elf64_Sxword Elf64_Ssize; + +/* + * ELF header. + */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* File identification. */ + Elf64_Half e_type; /* File type. */ + Elf64_Half e_machine; /* Machine architecture. */ + Elf64_Word e_version; /* ELF format version. */ + Elf64_Addr e_entry; /* Entry point. */ + Elf64_Off e_phoff; /* Program header file offset. */ + Elf64_Off e_shoff; /* Section header file offset. */ + Elf64_Word e_flags; /* Architecture-specific flags. */ + Elf64_Half e_ehsize; /* Size of ELF header in bytes. */ + Elf64_Half e_phentsize; /* Size of program header entry. */ + Elf64_Half e_phnum; /* Number of program header entries. */ + Elf64_Half e_shentsize; /* Size of section header entry. */ + Elf64_Half e_shnum; /* Number of section header entries. */ + Elf64_Half e_shstrndx; /* Section name strings section. */ +} Elf64_Ehdr; + +/* + * Shared object information, found in SHT_MIPS_LIBLIST. + */ + +typedef struct { + Elf64_Word l_name; /* The name of a shared object. */ + Elf64_Word l_time_stamp; /* 64-bit timestamp. */ + Elf64_Word l_checksum; /* Checksum of visible symbols, sizes. */ + Elf64_Word l_version; /* Interface version string index. */ + Elf64_Word l_flags; /* Flags (LL_*). */ +} Elf64_Lib; + +/* + * Section header. + */ + +typedef struct { + Elf64_Word sh_name; /* Section name (index into the + section header string table). */ + Elf64_Word sh_type; /* Section type. */ + Elf64_Xword sh_flags; /* Section flags. */ + Elf64_Addr sh_addr; /* Address in memory image. */ + Elf64_Off sh_offset; /* Offset in file. */ + Elf64_Xword sh_size; /* Size in bytes. */ + Elf64_Word sh_link; /* Index of a related section. */ + Elf64_Word sh_info; /* Depends on section type. */ + Elf64_Xword sh_addralign; /* Alignment in bytes. */ + Elf64_Xword sh_entsize; /* Size of each entry in section. */ +} Elf64_Shdr; + +/* + * Program header. + */ + +typedef struct { + Elf64_Word p_type; /* Entry type. */ + Elf64_Word p_flags; /* Access permission flags. */ + Elf64_Off p_offset; /* File offset of contents. */ + Elf64_Addr p_vaddr; /* Virtual address in memory image. */ + Elf64_Addr p_paddr; /* Physical address (not used). */ + Elf64_Xword p_filesz; /* Size of contents in file. */ + Elf64_Xword p_memsz; /* Size of contents in memory. */ + Elf64_Xword p_align; /* Alignment in memory and file. */ +} Elf64_Phdr; + +/* + * Dynamic structure. The ".dynamic" section contains an array of them. + */ + +typedef struct { + Elf64_Sxword d_tag; /* Entry type. */ + union { + Elf64_Xword d_val; /* Integer value. */ + Elf64_Addr d_ptr; /* Address value. */ + } d_un; +} Elf64_Dyn; + +/* + * Relocation entries. + */ + +/* Relocations that don't need an addend field. */ +typedef struct { + Elf64_Addr r_offset; /* Location to be relocated. */ + Elf64_Xword r_info; /* Relocation type and symbol index. */ +} Elf64_Rel; + +/* Relocations that need an addend field. */ +typedef struct { + Elf64_Addr r_offset; /* Location to be relocated. */ + Elf64_Xword r_info; /* Relocation type and symbol index. */ + Elf64_Sxword r_addend; /* Addend. */ +} Elf64_Rela; + +/* Macros for accessing the fields of r_info. */ +#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_TYPE(info) ((info) & 0xffffffffL) + +/* Macro for constructing r_info from field values. */ +#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL)) + +#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40) +#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56) +#define ELF64_R_TYPE_INFO(data, type) \ + (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type)) + +/* + * Note entry header + */ +typedef Elf_Note Elf64_Nhdr; + +/* + * Move entry + */ +typedef struct { + Elf64_Lword m_value; /* symbol value */ + Elf64_Xword m_info; /* size + index */ + Elf64_Xword m_poffset; /* symbol offset */ + Elf64_Half m_repeat; /* repeat count */ + Elf64_Half m_stride; /* stride info */ +} Elf64_Move; + +#define ELF64_M_SYM(info) ((info)>>8) +#define ELF64_M_SIZE(info) ((unsigned char)(info)) +#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) + +/* + * Hardware/Software capabilities entry + */ +typedef struct { + Elf64_Xword c_tag; /* how to interpret value */ + union { + Elf64_Xword c_val; + Elf64_Addr c_ptr; + } c_un; +} Elf64_Cap; + +/* + * Symbol table entries. + */ + +typedef struct { + Elf64_Word st_name; /* String table index of name. */ + unsigned char st_info; /* Type and binding information. */ + unsigned char st_other; /* Reserved (not used). */ + Elf64_Half st_shndx; /* Section index of symbol. */ + Elf64_Addr st_value; /* Symbol value. */ + Elf64_Xword st_size; /* Size of associated object. */ +} Elf64_Sym; + +/* Macros for accessing the fields of st_info. */ +#define ELF64_ST_BIND(info) ((info) >> 4) +#define ELF64_ST_TYPE(info) ((info) & 0xf) + +/* Macro for constructing st_info from field values. */ +#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) + +/* Macro for accessing the fields of st_other. */ +#define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3) + +/* Structures used by Sun & GNU-style symbol versioning. */ +typedef struct { + Elf64_Half vd_version; + Elf64_Half vd_flags; + Elf64_Half vd_ndx; + Elf64_Half vd_cnt; + Elf64_Word vd_hash; + Elf64_Word vd_aux; + Elf64_Word vd_next; +} Elf64_Verdef; + +typedef struct { + Elf64_Word vda_name; + Elf64_Word vda_next; +} Elf64_Verdaux; + +typedef struct { + Elf64_Half vn_version; + Elf64_Half vn_cnt; + Elf64_Word vn_file; + Elf64_Word vn_aux; + Elf64_Word vn_next; +} Elf64_Verneed; + +typedef struct { + Elf64_Word vna_hash; + Elf64_Half vna_flags; + Elf64_Half vna_other; + Elf64_Word vna_name; + Elf64_Word vna_next; +} Elf64_Vernaux; + +typedef Elf64_Half Elf64_Versym; + +typedef struct { + Elf64_Half si_boundto; /* direct bindings - symbol bound to */ + Elf64_Half si_flags; /* per symbol flags */ +} Elf64_Syminfo; + +typedef struct { + Elf64_Word ch_type; + Elf64_Word ch_reserved; + Elf64_Xword ch_size; + Elf64_Xword ch_addralign; +} Elf64_Chdr; + +#endif /* !_SYS_ELF64_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/elf_common.h b/lib/libc/include/any-freebsd-any/sys/elf_common.h new file mode 100644 index 000000000000..3b4ec4994432 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/elf_common.h @@ -0,0 +1,1430 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017, 2018 Dell EMC + * Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien + * Copyright (c) 1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ELF_COMMON_H_ +#define _SYS_ELF_COMMON_H_ 1 + +/* + * ELF definitions that are independent of architecture or word size. + */ + +/* + * Note header. The ".note" section contains an array of notes. Each + * begins with this header, aligned to a word boundary. Immediately + * following the note header is n_namesz bytes of name, padded to the + * next word boundary. Then comes n_descsz bytes of descriptor, again + * padded to a word boundary. The values of n_namesz and n_descsz do + * not include the padding. + */ + +typedef struct { + u_int32_t n_namesz; /* Length of name. */ + u_int32_t n_descsz; /* Length of descriptor. */ + u_int32_t n_type; /* Type of this note. */ +} Elf_Note; +typedef Elf_Note Elf_Nhdr; + +/* + * Option kinds. + */ +#define ODK_NULL 0 /* undefined */ +#define ODK_REGINFO 1 /* register usage info */ +#define ODK_EXCEPTIONS 2 /* exception processing info */ +#define ODK_PAD 3 /* section padding */ +#define ODK_HWPATCH 4 /* hardware patch applied */ +#define ODK_FILL 5 /* fill value used by the linker */ +#define ODK_TAGS 6 /* reserved space for tools */ +#define ODK_HWAND 7 /* hardware AND patch applied */ +#define ODK_HWOR 8 /* hardware OR patch applied */ +#define ODK_GP_GROUP 9 /* GP group for text/data sections */ +#define ODK_IDENT 10 /* ID information */ +#define ODK_PAGESIZE 11 /* page size information */ + +/* + * ODK_EXCEPTIONS info field masks. + */ +#define OEX_FPU_MIN 0x0000001f /* min FPU exception required */ +#define OEX_FPU_MAX 0x00001f00 /* max FPU exception allowed */ +#define OEX_PAGE0 0x00010000 /* page zero must be mapped */ +#define OEX_SMM 0x00020000 /* run in sequential memory mode */ +#define OEX_PRECISEFP 0x00040000 /* run in precise FP exception mode */ +#define OEX_DISMISS 0x00080000 /* dismiss invalid address traps */ + +/* + * ODK_PAD info field masks. + */ +#define OPAD_PREFIX 0x0001 +#define OPAD_POSTFIX 0x0002 +#define OPAD_SYMBOL 0x0004 + +/* + * ODK_HWPATCH info field masks. + */ +#define OHW_R4KEOP 0x00000001 /* patch for R4000 branch at end-of-page bug */ +#define OHW_R8KPFETCH 0x00000002 /* R8000 prefetch bug may occur */ +#define OHW_R5KEOP 0x00000004 /* patch for R5000 branch at end-of-page bug */ +#define OHW_R5KCVTL 0x00000008 /* R5000 cvt.[ds].l bug: clean == 1 */ +#define OHW_R10KLDL 0x00000010UL /* need patch for R10000 misaligned load */ + +/* + * ODK_HWAND/ODK_HWOR info field and hwp_flags[12] masks. + */ +#define OHWA0_R4KEOP_CHECKED 0x00000001 /* object checked for R4000 end-of-page bug */ +#define OHWA0_R4KEOP_CLEAN 0x00000002 /* object verified clean for R4000 end-of-page bug */ +#define OHWO0_FIXADE 0x00000001 /* object requires call to fixade */ + +/* + * ODK_IDENT/ODK_GP_GROUP info field masks. + */ +#define OGP_GROUP 0x0000ffff /* GP group number */ +#define OGP_SELF 0x00010000 /* GP group is self-contained */ + +/* + * The header for GNU-style hash sections. + */ + +typedef struct { + u_int32_t gh_nbuckets; /* Number of hash buckets. */ + u_int32_t gh_symndx; /* First visible symbol in .dynsym. */ + u_int32_t gh_maskwords; /* #maskwords used in bloom filter. */ + u_int32_t gh_shift2; /* Bloom filter shift count. */ +} Elf_GNU_Hash_Header; + +/* Indexes into the e_ident array. Keep synced with + http://www.sco.com/developers/gabi/latest/ch4.eheader.html */ +#define EI_MAG0 0 /* Magic number, byte 0. */ +#define EI_MAG1 1 /* Magic number, byte 1. */ +#define EI_MAG2 2 /* Magic number, byte 2. */ +#define EI_MAG3 3 /* Magic number, byte 3. */ +#define EI_CLASS 4 /* Class of machine. */ +#define EI_DATA 5 /* Data format. */ +#define EI_VERSION 6 /* ELF format version. */ +#define EI_OSABI 7 /* Operating system / ABI identification */ +#define EI_ABIVERSION 8 /* ABI version */ +#define OLD_EI_BRAND 8 /* Start of architecture identification. */ +#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */ +#define EI_NIDENT 16 /* Size of e_ident array. */ + +/* Values for the magic number bytes. */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" /* magic string */ +#define SELFMAG 4 /* magic string size */ + +/* Values for e_ident[EI_VERSION] and e_version. */ +#define EV_NONE 0 +#define EV_CURRENT 1 + +/* Values for e_ident[EI_CLASS]. */ +#define ELFCLASSNONE 0 /* Unknown class. */ +#define ELFCLASS32 1 /* 32-bit architecture. */ +#define ELFCLASS64 2 /* 64-bit architecture. */ + +/* Values for e_ident[EI_DATA]. */ +#define ELFDATANONE 0 /* Unknown data format. */ +#define ELFDATA2LSB 1 /* 2's complement little-endian. */ +#define ELFDATA2MSB 2 /* 2's complement big-endian. */ + +/* Values for e_ident[EI_OSABI]. */ +#define ELFOSABI_NONE 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_AIX 7 /* AIX */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_OPENVMS 13 /* Open VMS */ +#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */ +#define ELFOSABI_AROS 15 /* Amiga Research OS */ +#define ELFOSABI_FENIXOS 16 /* FenixOS */ +#define ELFOSABI_CLOUDABI 17 /* Nuxi CloudABI */ +#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +#define ELFOSABI_SYSV ELFOSABI_NONE /* symbol used in old spec */ +#define ELFOSABI_MONTEREY ELFOSABI_AIX /* Monterey */ +#define ELFOSABI_GNU ELFOSABI_LINUX + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* Values for e_type. */ +#define ET_NONE 0 /* Unknown type. */ +#define ET_REL 1 /* Relocatable. */ +#define ET_EXEC 2 /* Executable. */ +#define ET_DYN 3 /* Shared object. */ +#define ET_CORE 4 /* Core file. */ +#define ET_LOOS 0xfe00 /* First operating system specific. */ +#define ET_HIOS 0xfeff /* Last operating system-specific. */ +#define ET_LOPROC 0xff00 /* First processor-specific. */ +#define ET_HIPROC 0xffff /* Last processor-specific. */ + +/* Values for e_machine. */ +#define EM_NONE 0 /* Unknown machine. */ +#define EM_M32 1 /* AT&T WE32100. */ +#define EM_SPARC 2 /* Sun SPARC. */ +#define EM_386 3 /* Intel i386. */ +#define EM_68K 4 /* Motorola 68000. */ +#define EM_88K 5 /* Motorola 88000. */ +#define EM_IAMCU 6 /* Intel MCU. */ +#define EM_860 7 /* Intel i860. */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only. */ +#define EM_S370 9 /* IBM System/370. */ +#define EM_MIPS_RS3_LE 10 /* MIPS R3000 Little-Endian. */ +#define EM_PARISC 15 /* HP PA-RISC. */ +#define EM_VPP500 17 /* Fujitsu VPP500. */ +#define EM_SPARC32PLUS 18 /* SPARC v8plus. */ +#define EM_960 19 /* Intel 80960. */ +#define EM_PPC 20 /* PowerPC 32-bit. */ +#define EM_PPC64 21 /* PowerPC 64-bit. */ +#define EM_S390 22 /* IBM System/390. */ +#define EM_V800 36 /* NEC V800. */ +#define EM_FR20 37 /* Fujitsu FR20. */ +#define EM_RH32 38 /* TRW RH-32. */ +#define EM_RCE 39 /* Motorola RCE. */ +#define EM_ARM 40 /* ARM. */ +#define EM_SH 42 /* Hitachi SH. */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit. */ +#define EM_TRICORE 44 /* Siemens TriCore embedded processor. */ +#define EM_ARC 45 /* Argonaut RISC Core. */ +#define EM_H8_300 46 /* Hitachi H8/300. */ +#define EM_H8_300H 47 /* Hitachi H8/300H. */ +#define EM_H8S 48 /* Hitachi H8S. */ +#define EM_H8_500 49 /* Hitachi H8/500. */ +#define EM_IA_64 50 /* Intel IA-64 Processor. */ +#define EM_MIPS_X 51 /* Stanford MIPS-X. */ +#define EM_COLDFIRE 52 /* Motorola ColdFire. */ +#define EM_68HC12 53 /* Motorola M68HC12. */ +#define EM_MMA 54 /* Fujitsu MMA. */ +#define EM_PCP 55 /* Siemens PCP. */ +#define EM_NCPU 56 /* Sony nCPU. */ +#define EM_NDR1 57 /* Denso NDR1 microprocessor. */ +#define EM_STARCORE 58 /* Motorola Star*Core processor. */ +#define EM_ME16 59 /* Toyota ME16 processor. */ +#define EM_ST100 60 /* STMicroelectronics ST100 processor. */ +#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ processor. */ +#define EM_X86_64 62 /* Advanced Micro Devices x86-64 */ +#define EM_AMD64 EM_X86_64 /* Advanced Micro Devices x86-64 (compat) */ +#define EM_PDSP 63 /* Sony DSP Processor. */ +#define EM_FX66 66 /* Siemens FX66 microcontroller. */ +#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 + microcontroller. */ +#define EM_ST7 68 /* STmicroelectronics ST7 8-bit + microcontroller. */ +#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller. */ +#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller. */ +#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller. */ +#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller. */ +#define EM_SVX 73 /* Silicon Graphics SVx. */ +#define EM_ST19 74 /* STMicroelectronics ST19 8-bit mc. */ +#define EM_VAX 75 /* Digital VAX. */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded + processor. */ +#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded + processor. */ +#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor. */ +#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor. */ +#define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc. */ +#define EM_HUANY 81 /* Harvard University machine-independent + object files. */ +#define EM_PRISM 82 /* SiTera Prism. */ +#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller. */ +#define EM_FR30 84 /* Fujitsu FR30. */ +#define EM_D10V 85 /* Mitsubishi D10V. */ +#define EM_D30V 86 /* Mitsubishi D30V. */ +#define EM_V850 87 /* NEC v850. */ +#define EM_M32R 88 /* Mitsubishi M32R. */ +#define EM_MN10300 89 /* Matsushita MN10300. */ +#define EM_MN10200 90 /* Matsushita MN10200. */ +#define EM_PJ 91 /* picoJava. */ +#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor. */ +#define EM_ARC_A5 93 /* ARC Cores Tangent-A5. */ +#define EM_XTENSA 94 /* Tensilica Xtensa Architecture. */ +#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor. */ +#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose + Processor. */ +#define EM_NS32K 97 /* National Semiconductor 32000 series. */ +#define EM_TPC 98 /* Tenor Network TPC processor. */ +#define EM_SNP1K 99 /* Trebia SNP 1000 processor. */ +#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller. */ +#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family. */ +#define EM_MAX 102 /* MAX Processor. */ +#define EM_CR 103 /* National Semiconductor CompactRISC + microprocessor. */ +#define EM_F2MC16 104 /* Fujitsu F2MC16. */ +#define EM_MSP430 105 /* Texas Instruments embedded microcontroller + msp430. */ +#define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor. */ +#define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors. */ +#define EM_SEP 108 /* Sharp embedded microprocessor. */ +#define EM_ARCA 109 /* Arca RISC Microprocessor. */ +#define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. + and MPRC of Peking University */ +#define EM_AARCH64 183 /* AArch64 (64-bit ARM) */ +#define EM_RISCV 243 /* RISC-V */ + +/* Non-standard or deprecated. */ +#define EM_486 6 /* Intel i486. */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */ +#define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI) */ + +/** + * e_flags + */ +#define EF_ARM_RELEXEC 0x1 +#define EF_ARM_HASENTRY 0x2 +#define EF_ARM_SYMSARESORTED 0x4 +#define EF_ARM_DYNSYMSUSESEGIDX 0x8 +#define EF_ARM_MAPSYMSFIRST 0x10 +#define EF_ARM_LE8 0x00400000 +#define EF_ARM_BE8 0x00800000 +#define EF_ARM_EABIMASK 0xFF000000 +#define EF_ARM_EABI_UNKNOWN 0x00000000 +#define EF_ARM_EABI_VER1 0x01000000 +#define EF_ARM_EABI_VER2 0x02000000 +#define EF_ARM_EABI_VER3 0x03000000 +#define EF_ARM_EABI_VER4 0x04000000 +#define EF_ARM_EABI_VER5 0x05000000 +#define EF_ARM_INTERWORK 0x00000004 +#define EF_ARM_APCS_26 0x00000008 +#define EF_ARM_APCS_FLOAT 0x00000010 +#define EF_ARM_PIC 0x00000020 +#define EF_ARM_ALIGN8 0x00000040 +#define EF_ARM_NEW_ABI 0x00000080 +#define EF_ARM_OLD_ABI 0x00000100 +#define EF_ARM_ABI_FLOAT_SOFT 0x00000200 +#define EF_ARM_SOFT_FLOAT EF_ARM_ABI_FLOAT_SOFT /* Pre-V5 ABI name */ +#define EF_ARM_ABI_FLOAT_HARD 0x00000400 +#define EF_ARM_VFP_FLOAT EF_ARM_ABI_FLOAT_HARD /* Pre-V5 ABI name */ +#define EF_ARM_MAVERICK_FLOAT 0x00000800 + +#define EF_MIPS_NOREORDER 0x00000001 +#define EF_MIPS_PIC 0x00000002 /* Contains PIC code */ +#define EF_MIPS_CPIC 0x00000004 /* STD PIC calling sequence */ +#define EF_MIPS_UCODE 0x00000010 +#define EF_MIPS_ABI2 0x00000020 /* N32 */ +#define EF_MIPS_OPTIONS_FIRST 0x00000080 +#define EF_MIPS_ABI 0x0000F000 +#define EF_MIPS_ABI_O32 0x00001000 +#define EF_MIPS_ABI_O64 0x00002000 +#define EF_MIPS_ABI_EABI32 0x00003000 +#define EF_MIPS_ABI_EABI64 0x00004000 +#define EF_MIPS_ARCH_ASE 0x0F000000 /* Architectural extensions */ +#define EF_MIPS_ARCH_ASE_MDMX 0x08000000 /* MDMX multimedia extension */ +#define EF_MIPS_ARCH_ASE_M16 0x04000000 /* MIPS-16 ISA extensions */ +#define EF_MIPS_ARCH 0xF0000000 /* Architecture field */ +#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */ +#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */ +#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */ +#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */ +#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */ +#define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */ +#define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */ +#define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */ +#define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */ + +#define EF_PPC_EMB 0x80000000 +#define EF_PPC_RELOCATABLE 0x00010000 +#define EF_PPC_RELOCATABLE_LIB 0x00008000 + +#define EF_RISCV_RVC 0x00000001 +#define EF_RISCV_FLOAT_ABI_MASK 0x00000006 +#define EF_RISCV_FLOAT_ABI_SOFT 0x00000000 +#define EF_RISCV_FLOAT_ABI_SINGLE 0x000002 +#define EF_RISCV_FLOAT_ABI_DOUBLE 0x000004 +#define EF_RISCV_FLOAT_ABI_QUAD 0x00000006 +#define EF_RISCV_RVE 0x00000008 +#define EF_RISCV_TSO 0x00000010 + +#define EF_SPARC_EXT_MASK 0x00ffff00 +#define EF_SPARC_32PLUS 0x00000100 +#define EF_SPARC_SUN_US1 0x00000200 +#define EF_SPARC_HAL_R1 0x00000200 +#define EF_SPARC_SUN_US3 0x00000800 + +#define EF_SPARCV9_MM 0x00000003 +#define EF_SPARCV9_TSO 0x00000000 +#define EF_SPARCV9_PSO 0x00000001 +#define EF_SPARCV9_RMO 0x00000002 + +/* Special section indexes. */ +#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */ +#define SHN_LORESERVE 0xff00 /* First of reserved range. */ +#define SHN_LOPROC 0xff00 /* First processor-specific. */ +#define SHN_HIPROC 0xff1f /* Last processor-specific. */ +#define SHN_LOOS 0xff20 /* First operating system-specific. */ +#define SHN_FBSD_CACHED SHN_LOOS /* Transient, for sys/kern/link_elf_obj + linker only: Cached global in local + symtab. */ +#define SHN_HIOS 0xff3f /* Last operating system-specific. */ +#define SHN_ABS 0xfff1 /* Absolute values. */ +#define SHN_COMMON 0xfff2 /* Common data. */ +#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */ +#define SHN_HIRESERVE 0xffff /* Last of reserved range. */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends */ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relocation section - no addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_INIT_ARRAY 14 /* Initialization function pointers. */ +#define SHT_FINI_ARRAY 15 /* Termination function pointers. */ +#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs. */ +#define SHT_GROUP 17 /* Section group. */ +#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */ +#define SHT_LOOS 0x60000000 /* First of OS specific semantics */ +#define SHT_LOSUNW 0x6ffffff4 +#define SHT_SUNW_dof 0x6ffffff4 +#define SHT_SUNW_cap 0x6ffffff5 +#define SHT_GNU_ATTRIBUTES 0x6ffffff5 +#define SHT_SUNW_SIGNATURE 0x6ffffff6 +#define SHT_GNU_HASH 0x6ffffff6 +#define SHT_GNU_LIBLIST 0x6ffffff7 +#define SHT_SUNW_ANNOTATE 0x6ffffff7 +#define SHT_SUNW_DEBUGSTR 0x6ffffff8 +#define SHT_SUNW_DEBUG 0x6ffffff9 +#define SHT_SUNW_move 0x6ffffffa +#define SHT_SUNW_COMDAT 0x6ffffffb +#define SHT_SUNW_syminfo 0x6ffffffc +#define SHT_SUNW_verdef 0x6ffffffd +#define SHT_GNU_verdef 0x6ffffffd /* Symbol versions provided */ +#define SHT_SUNW_verneed 0x6ffffffe +#define SHT_GNU_verneed 0x6ffffffe /* Symbol versions required */ +#define SHT_SUNW_versym 0x6fffffff +#define SHT_GNU_versym 0x6fffffff /* Symbol version table */ +#define SHT_HISUNW 0x6fffffff +#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_X86_64_UNWIND 0x70000001 /* unwind information */ +#define SHT_AMD64_UNWIND SHT_X86_64_UNWIND + +#define SHT_ARM_EXIDX 0x70000001 /* Exception index table. */ +#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking + pre-emption map. */ +#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility + attributes. */ +#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details. */ +#define SHT_ARM_OVERLAYSECTION 0x70000005 /* See DBGOVL for details. */ +#define SHT_MIPS_LIBLIST 0x70000000 +#define SHT_MIPS_MSYM 0x70000001 +#define SHT_MIPS_CONFLICT 0x70000002 +#define SHT_MIPS_GPTAB 0x70000003 +#define SHT_MIPS_UCODE 0x70000004 +#define SHT_MIPS_DEBUG 0x70000005 +#define SHT_MIPS_REGINFO 0x70000006 +#define SHT_MIPS_PACKAGE 0x70000007 +#define SHT_MIPS_PACKSYM 0x70000008 +#define SHT_MIPS_RELD 0x70000009 +#define SHT_MIPS_IFACE 0x7000000b +#define SHT_MIPS_CONTENT 0x7000000c +#define SHT_MIPS_OPTIONS 0x7000000d +#define SHT_MIPS_DELTASYM 0x7000001b +#define SHT_MIPS_DELTAINST 0x7000001c +#define SHT_MIPS_DELTACLASS 0x7000001d +#define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */ +#define SHT_MIPS_DELTADECL 0x7000001f +#define SHT_MIPS_SYMBOL_LIB 0x70000020 +#define SHT_MIPS_EVENTS 0x70000021 +#define SHT_MIPS_TRANSLATE 0x70000022 +#define SHT_MIPS_PIXIE 0x70000023 +#define SHT_MIPS_XLATE 0x70000024 +#define SHT_MIPS_XLATE_DEBUG 0x70000025 +#define SHT_MIPS_WHIRL 0x70000026 +#define SHT_MIPS_EH_REGION 0x70000027 +#define SHT_MIPS_XLATE_OLD 0x70000028 +#define SHT_MIPS_PDR_EXCEPTION 0x70000029 +#define SHT_MIPS_ABIFLAGS 0x7000002a + +#define SHT_SPARC_GOTDATA 0x70000000 + +#define SHTORDERED +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +/* Flags for sh_flags. */ +#define SHF_WRITE 0x1 /* Section contains writable data. */ +#define SHF_ALLOC 0x2 /* Section occupies memory. */ +#define SHF_EXECINSTR 0x4 /* Section contains instructions. */ +#define SHF_MERGE 0x10 /* Section may be merged. */ +#define SHF_STRINGS 0x20 /* Section contains strings. */ +#define SHF_INFO_LINK 0x40 /* sh_info holds section index. */ +#define SHF_LINK_ORDER 0x80 /* Special ordering requirements. */ +#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required. */ +#define SHF_GROUP 0x200 /* Member of section group. */ +#define SHF_TLS 0x400 /* Section contains TLS data. */ +#define SHF_COMPRESSED 0x800 /* Section contains compressed data. */ +#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics. */ +#define SHF_MASKPROC 0xf0000000 /* Processor-specific semantics. */ + +/* Flags for section groups. */ +#define GRP_COMDAT 0x1 /* COMDAT semantics. */ + +/* + * Flags / mask for .gnu.versym sections. + */ +#define VERSYM_VERSION 0x7fff +#define VERSYM_HIDDEN 0x8000 + +/* Values for p_type. */ +#define PT_NULL 0 /* Unused entry. */ +#define PT_LOAD 1 /* Loadable segment. */ +#define PT_DYNAMIC 2 /* Dynamic linking information segment. */ +#define PT_INTERP 3 /* Pathname of interpreter. */ +#define PT_NOTE 4 /* Auxiliary information. */ +#define PT_SHLIB 5 /* Reserved (not used). */ +#define PT_PHDR 6 /* Location of program header itself. */ +#define PT_TLS 7 /* Thread local storage segment */ +#define PT_LOOS 0x60000000 /* First OS-specific. */ +#define PT_SUNW_UNWIND 0x6464e550 /* amd64 UNWIND program header */ +#define PT_GNU_EH_FRAME 0x6474e550 +#define PT_GNU_STACK 0x6474e551 +#define PT_GNU_RELRO 0x6474e552 +#define PT_DUMP_DELTA 0x6fb5d000 /* va->pa map for kernel dumps + (currently arm). */ +#define PT_LOSUNW 0x6ffffffa +#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ +#define PT_SUNWSTACK 0x6ffffffb /* describes the stack segment */ +#define PT_SUNWDTRACE 0x6ffffffc /* private */ +#define PT_SUNWCAP 0x6ffffffd /* hard/soft capabilities segment */ +#define PT_HISUNW 0x6fffffff +#define PT_HIOS 0x6fffffff /* Last OS-specific. */ +#define PT_LOPROC 0x70000000 /* First processor-specific type. */ +#define PT_ARM_ARCHEXT 0x70000000 /* ARM arch compat information. */ +#define PT_ARM_EXIDX 0x70000001 /* ARM exception unwind tables. */ +#define PT_MIPS_REGINFO 0x70000000 /* MIPS register usage info */ +#define PT_MIPS_RTPROC 0x70000001 /* MIPS runtime procedure tbl */ +#define PT_MIPS_OPTIONS 0x70000002 /* MIPS e_flags value*/ +#define PT_MIPS_ABIFLAGS 0x70000003 /* MIPS fp mode */ +#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +#define PT_OPENBSD_RANDOMIZE 0x65A3DBE6 /* OpenBSD random data segment */ +#define PT_OPENBSD_WXNEEDED 0x65A3DBE7 /* OpenBSD EXEC/WRITE pages needed */ +#define PT_OPENBSD_BOOTDATA 0x65A41BE6 /* OpenBSD section for boot args */ + +/* Values for p_flags. */ +#define PF_X 0x1 /* Executable. */ +#define PF_W 0x2 /* Writable. */ +#define PF_R 0x4 /* Readable. */ +#define PF_MASKOS 0x0ff00000 /* Operating system-specific. */ +#define PF_MASKPROC 0xf0000000 /* Processor-specific. */ + +/* Extended program header index. */ +#define PN_XNUM 0xffff + +/* Values for d_tag. */ +#define DT_NULL 0 /* Terminating entry. */ +#define DT_NEEDED 1 /* String table offset of a needed shared + library. */ +#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */ +#define DT_PLTGOT 3 /* Processor-dependent address. */ +#define DT_HASH 4 /* Address of symbol hash table. */ +#define DT_STRTAB 5 /* Address of string table. */ +#define DT_SYMTAB 6 /* Address of symbol table. */ +#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */ +#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */ +#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */ +#define DT_STRSZ 10 /* Size of string table. */ +#define DT_SYMENT 11 /* Size of each symbol table entry. */ +#define DT_INIT 12 /* Address of initialization function. */ +#define DT_FINI 13 /* Address of finalization function. */ +#define DT_SONAME 14 /* String table offset of shared object + name. */ +#define DT_RPATH 15 /* String table offset of library path. [sup] */ +#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */ +#define DT_REL 17 /* Address of ElfNN_Rel relocations. */ +#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */ +#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */ +#define DT_PLTREL 20 /* Type of relocation used for PLT. */ +#define DT_DEBUG 21 /* Reserved (not used). */ +#define DT_TEXTREL 22 /* Indicates there may be relocations in + non-writable segments. [sup] */ +#define DT_JMPREL 23 /* Address of PLT relocations. */ +#define DT_BIND_NOW 24 /* [sup] */ +#define DT_INIT_ARRAY 25 /* Address of the array of pointers to + initialization functions */ +#define DT_FINI_ARRAY 26 /* Address of the array of pointers to + termination functions */ +#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of + initialization functions. */ +#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of + termination functions. */ +#define DT_RUNPATH 29 /* String table offset of a null-terminated + library search path string. */ +#define DT_FLAGS 30 /* Object specific flag values. */ +#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING + and less than DT_LOOS follow the rules for + the interpretation of the d_un union + as follows: even == 'd_ptr', odd == 'd_val' + or none */ +#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to + pre-initialization functions. */ +#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of + pre-initialization functions. */ +#define DT_MAXPOSTAGS 34 /* number of positive tags */ +#define DT_LOOS 0x6000000d /* First OS-specific */ +#define DT_SUNW_AUXILIARY 0x6000000d /* symbol auxiliary name */ +#define DT_SUNW_RTLDINF 0x6000000e /* ld.so.1 info (private) */ +#define DT_SUNW_FILTER 0x6000000f /* symbol filter name */ +#define DT_SUNW_CAP 0x60000010 /* hardware/software */ +#define DT_SUNW_ASLR 0x60000023 /* ASLR control */ +#define DT_HIOS 0x6ffff000 /* Last OS-specific */ + +/* + * DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the + * Dyn.d_un.d_val field of the Elf*_Dyn structure. + */ +#define DT_VALRNGLO 0x6ffffd00 +#define DT_GNU_PRELINKED 0x6ffffdf5 /* prelinking timestamp */ +#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* size of conflict section */ +#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* size of library list */ +#define DT_CHECKSUM 0x6ffffdf8 /* elf checksum */ +#define DT_PLTPADSZ 0x6ffffdf9 /* pltpadding size */ +#define DT_MOVEENT 0x6ffffdfa /* move table entry size */ +#define DT_MOVESZ 0x6ffffdfb /* move table size */ +#define DT_FEATURE 0x6ffffdfc /* feature holder */ +#define DT_FEATURE_1 DT_FEATURE +#define DT_POSFLAG_1 0x6ffffdfd /* flags for DT_* entries, effecting */ + /* the following DT_* entry. */ + /* See DF_P1_* definitions */ +#define DT_SYMINSZ 0x6ffffdfe /* syminfo table size (in bytes) */ +#define DT_SYMINENT 0x6ffffdff /* syminfo entry size (in bytes) */ +#define DT_VALRNGHI 0x6ffffdff + +/* + * DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the + * Dyn.d_un.d_ptr field of the Elf*_Dyn structure. + * + * If any adjustment is made to the ELF object after it has been + * built, these entries will need to be adjusted. + */ +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table */ +#define DT_TLSDESC_PLT 0x6ffffef6 /* loc. of PLT for tlsdesc resolver */ +#define DT_TLSDESC_GOT 0x6ffffef7 /* loc. of GOT for tlsdesc resolver */ +#define DT_GNU_CONFLICT 0x6ffffef8 /* address of conflict section */ +#define DT_GNU_LIBLIST 0x6ffffef9 /* address of library list */ +#define DT_CONFIG 0x6ffffefa /* configuration information */ +#define DT_DEPAUDIT 0x6ffffefb /* dependency auditing */ +#define DT_AUDIT 0x6ffffefc /* object auditing */ +#define DT_PLTPAD 0x6ffffefd /* pltpadding (sparcv9) */ +#define DT_MOVETAB 0x6ffffefe /* move table */ +#define DT_SYMINFO 0x6ffffeff /* syminfo table */ +#define DT_ADDRRNGHI 0x6ffffeff + +#define DT_VERSYM 0x6ffffff0 /* Address of versym section. */ +#define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */ +#define DT_RELCOUNT 0x6ffffffa /* number of RELATIVE relocations */ +#define DT_FLAGS_1 0x6ffffffb /* state flags - see DF_1_* defs */ +#define DT_VERDEF 0x6ffffffc /* Address of verdef section. */ +#define DT_VERDEFNUM 0x6ffffffd /* Number of elems in verdef section */ +#define DT_VERNEED 0x6ffffffe /* Address of verneed section. */ +#define DT_VERNEEDNUM 0x6fffffff /* Number of elems in verneed section */ + +#define DT_LOPROC 0x70000000 /* First processor-specific type. */ + +#define DT_ARM_SYMTABSZ 0x70000001 +#define DT_ARM_PREEMPTMAP 0x70000002 + +#define DT_SPARC_REGISTER 0x70000001 +#define DT_DEPRECATED_SPARC_REGISTER 0x7000001 + +#define DT_MIPS_RLD_VERSION 0x70000001 +#define DT_MIPS_TIME_STAMP 0x70000002 +#define DT_MIPS_ICHECKSUM 0x70000003 +#define DT_MIPS_IVERSION 0x70000004 +#define DT_MIPS_FLAGS 0x70000005 +#define DT_MIPS_BASE_ADDRESS 0x70000006 +#define DT_MIPS_CONFLICT 0x70000008 +#define DT_MIPS_LIBLIST 0x70000009 +#define DT_MIPS_LOCAL_GOTNO 0x7000000a +#define DT_MIPS_CONFLICTNO 0x7000000b +#define DT_MIPS_LIBLISTNO 0x70000010 +#define DT_MIPS_SYMTABNO 0x70000011 +#define DT_MIPS_UNREFEXTNO 0x70000012 +#define DT_MIPS_GOTSYM 0x70000013 +#define DT_MIPS_HIPAGENO 0x70000014 +#define DT_MIPS_RLD_MAP 0x70000016 +#define DT_MIPS_DELTA_CLASS 0x70000017 +#define DT_MIPS_DELTA_CLASS_NO 0x70000018 +#define DT_MIPS_DELTA_INSTANCE 0x70000019 +#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001A +#define DT_MIPS_DELTA_RELOC 0x7000001B +#define DT_MIPS_DELTA_RELOC_NO 0x7000001C +#define DT_MIPS_DELTA_SYM 0x7000001D +#define DT_MIPS_DELTA_SYM_NO 0x7000001E +#define DT_MIPS_DELTA_CLASSSYM 0x70000020 +#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 +#define DT_MIPS_CXX_FLAGS 0x70000022 +#define DT_MIPS_PIXIE_INIT 0x70000023 +#define DT_MIPS_SYMBOL_LIB 0x70000024 +#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 +#define DT_MIPS_LOCAL_GOTIDX 0x70000026 +#define DT_MIPS_HIDDEN_GOTIDX 0x70000027 +#define DT_MIPS_PROTECTED_GOTIDX 0x70000028 +#define DT_MIPS_OPTIONS 0x70000029 +#define DT_MIPS_INTERFACE 0x7000002A +#define DT_MIPS_DYNSTR_ALIGN 0x7000002B +#define DT_MIPS_INTERFACE_SIZE 0x7000002C +#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002D +#define DT_MIPS_PERF_SUFFIX 0x7000002E +#define DT_MIPS_COMPACT_SIZE 0x7000002F +#define DT_MIPS_GP_VALUE 0x70000030 +#define DT_MIPS_AUX_DYNAMIC 0x70000031 +#define DT_MIPS_PLTGOT 0x70000032 +#define DT_MIPS_RLD_OBJ_UPDATE 0x70000033 +#define DT_MIPS_RWPLT 0x70000034 + +#define DT_PPC_GOT 0x70000000 +#define DT_PPC_TLSOPT 0x70000001 + +#define DT_PPC64_GLINK 0x70000000 +#define DT_PPC64_OPD 0x70000001 +#define DT_PPC64_OPDSZ 0x70000002 +#define DT_PPC64_TLSOPT 0x70000003 + +#define DT_AUXILIARY 0x7ffffffd /* shared library auxiliary name */ +#define DT_USED 0x7ffffffe /* ignored - same as needed */ +#define DT_FILTER 0x7fffffff /* shared library filter name */ +#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for DT_FLAGS */ +#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may + make reference to the $ORIGIN substitution + string */ +#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */ +#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in + non-writable segments. */ +#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should + process all relocations for the object + containing this entry before transferring + control to the program. */ +#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or + executable contains code using a static + thread-local storage scheme. */ + +/* Values for DT_FLAGS_1 */ +#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */ +#define DF_1_GLOBAL 0x00000002 /* Set the RTLD_GLOBAL for object */ +#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */ +#define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filtees */ +#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ +#define DF_1_ORIGIN 0x00000080 /* Process $ORIGIN */ +#define DF_1_INTERPOSE 0x00000400 /* Interpose all objects but main */ +#define DF_1_NODEFLIB 0x00000800 /* Do not search default paths */ +#define DF_1_PIE 0x08000000 /* Is position-independent executable */ + +/* Values for l_flags. */ +#define LL_NONE 0x0 /* no flags */ +#define LL_EXACT_MATCH 0x1 /* require an exact match */ +#define LL_IGNORE_INT_VER 0x2 /* ignore version incompatibilities */ +#define LL_REQUIRE_MINOR 0x4 +#define LL_EXPORTS 0x8 +#define LL_DELAY_LOAD 0x10 +#define LL_DELTA 0x20 + +/* Note section names */ +#define ELF_NOTE_FREEBSD "FreeBSD" +#define ELF_NOTE_NETBSD "NetBSD" +#define ELF_NOTE_SOLARIS "SUNW Solaris" +#define ELF_NOTE_GNU "GNU" + +/* Values for n_type used in executables. */ +#define NT_FREEBSD_ABI_TAG 1 +#define NT_FREEBSD_NOINIT_TAG 2 +#define NT_FREEBSD_ARCH_TAG 3 +#define NT_FREEBSD_FEATURE_CTL 4 + +/* NT_FREEBSD_FEATURE_CTL desc[0] bits */ +#define NT_FREEBSD_FCTL_ASLR_DISABLE 0x00000001 +#define NT_FREEBSD_FCTL_PROTMAX_DISABLE 0x00000002 +#define NT_FREEBSD_FCTL_STKGAP_DISABLE 0x00000004 +#define NT_FREEBSD_FCTL_WXNEEDED 0x00000008 + +/* Values for n_type. Used in core files. */ +#define NT_PRSTATUS 1 /* Process status. */ +#define NT_FPREGSET 2 /* Floating point registers. */ +#define NT_PRPSINFO 3 /* Process state info. */ +#define NT_THRMISC 7 /* Thread miscellaneous info. */ +#define NT_PROCSTAT_PROC 8 /* Procstat proc data. */ +#define NT_PROCSTAT_FILES 9 /* Procstat files data. */ +#define NT_PROCSTAT_VMMAP 10 /* Procstat vmmap data. */ +#define NT_PROCSTAT_GROUPS 11 /* Procstat groups data. */ +#define NT_PROCSTAT_UMASK 12 /* Procstat umask data. */ +#define NT_PROCSTAT_RLIMIT 13 /* Procstat rlimit data. */ +#define NT_PROCSTAT_OSREL 14 /* Procstat osreldate data. */ +#define NT_PROCSTAT_PSSTRINGS 15 /* Procstat ps_strings data. */ +#define NT_PROCSTAT_AUXV 16 /* Procstat auxv data. */ +#define NT_PTLWPINFO 17 /* Thread ptrace miscellaneous info. */ +#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ +#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ +#define NT_X86_XSTATE 0x202 /* x86 XSAVE extended state. */ +#define NT_ARM_VFP 0x400 /* ARM VFP registers */ + +/* GNU note types. */ +#define NT_GNU_ABI_TAG 1 +#define NT_GNU_HWCAP 2 +#define NT_GNU_BUILD_ID 3 +#define NT_GNU_GOLD_VERSION 4 +#define NT_GNU_PROPERTY_TYPE_0 5 + +#define GNU_PROPERTY_LOPROC 0xc0000000 +#define GNU_PROPERTY_HIPROC 0xdfffffff + +#define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002 + +#define GNU_PROPERTY_X86_FEATURE_1_IBT 0x00000001 +#define GNU_PROPERTY_X86_FEATURE_1_SHSTK 0x00000002 + +/* Symbol Binding - ELFNN_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_LOOS 10 /* Start of operating system reserved range. */ +#define STB_GNU_UNIQUE 10 /* Unique symbol (GNU) */ +#define STB_HIOS 12 /* End of operating system reserved range. */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific semantics. */ + +/* Symbol type - ELFNN_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* Unspecified type. */ +#define STT_OBJECT 1 /* Data object. */ +#define STT_FUNC 2 /* Function. */ +#define STT_SECTION 3 /* Section. */ +#define STT_FILE 4 /* Source file. */ +#define STT_COMMON 5 /* Uninitialized common block. */ +#define STT_TLS 6 /* TLS object. */ +#define STT_NUM 7 +#define STT_LOOS 10 /* Reserved range for operating system */ +#define STT_GNU_IFUNC 10 +#define STT_HIOS 12 /* specific semantics. */ +#define STT_LOPROC 13 /* Start of processor reserved range. */ +#define STT_SPARC_REGISTER 13 /* SPARC register information. */ +#define STT_HIPROC 15 /* End of processor reserved range. */ + +/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */ +#define STV_DEFAULT 0x0 /* Default visibility (see binding). */ +#define STV_INTERNAL 0x1 /* Special meaning in relocatable objects. */ +#define STV_HIDDEN 0x2 /* Not visible. */ +#define STV_PROTECTED 0x3 /* Visible but not preemptible. */ +#define STV_EXPORTED 0x4 +#define STV_SINGLETON 0x5 +#define STV_ELIMINATE 0x6 + +/* Special symbol table indexes. */ +#define STN_UNDEF 0 /* Undefined symbol index. */ + +/* Symbol versioning flags. */ +#define VER_DEF_CURRENT 1 +#define VER_DEF_IDX(x) VER_NDX(x) + +#define VER_FLG_BASE 0x01 +#define VER_FLG_WEAK 0x02 + +#define VER_NEED_CURRENT 1 +#define VER_NEED_WEAK (1u << 15) +#define VER_NEED_HIDDEN VER_NDX_HIDDEN +#define VER_NEED_IDX(x) VER_NDX(x) + +#define VER_NDX_LOCAL 0 +#define VER_NDX_GLOBAL 1 +#define VER_NDX_GIVEN 2 + +#define VER_NDX_HIDDEN (1u << 15) +#define VER_NDX(x) ((x) & ~(1u << 15)) + +#define CA_SUNW_NULL 0 +#define CA_SUNW_HW_1 1 /* first hardware capabilities entry */ +#define CA_SUNW_SF_1 2 /* first software capabilities entry */ + +/* + * Syminfo flag values + */ +#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association */ + /* to object containing defn. */ +#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */ +#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */ +#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be */ + /* lazily-loaded */ +#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to */ + /* object containing defn. */ +#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference */ + /* directly bind to this symbol */ +#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */ +#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */ + +/* + * Syminfo.si_boundto values. + */ +#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */ +#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */ +#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */ +#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */ +#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */ + +/* + * Syminfo version values. + */ +#define SYMINFO_NONE 0 /* Syminfo version */ +#define SYMINFO_CURRENT 1 +#define SYMINFO_NUM 2 + +/* Values for ch_type (compressed section headers). */ +#define ELFCOMPRESS_ZLIB 1 /* ZLIB/DEFLATE */ +#define ELFCOMPRESS_LOOS 0x60000000 /* OS-specific */ +#define ELFCOMPRESS_HIOS 0x6fffffff +#define ELFCOMPRESS_LOPROC 0x70000000 /* Processor-specific */ +#define ELFCOMPRESS_HIPROC 0x7fffffff + +/* + * Relocation types. + * + * All machine architectures are defined here to allow tools on one to + * handle others. + */ + +#define R_386_NONE 0 /* No relocation. */ +#define R_386_32 1 /* Add symbol value. */ +#define R_386_PC32 2 /* Add PC-relative symbol value. */ +#define R_386_GOT32 3 /* Add PC-relative GOT offset. */ +#define R_386_PLT32 4 /* Add PC-relative PLT offset. */ +#define R_386_COPY 5 /* Copy data from shared object. */ +#define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */ +#define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */ +#define R_386_RELATIVE 8 /* Add load address of shared object. */ +#define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */ +#define R_386_GOTPC 10 /* Add PC-relative GOT table address. */ +#define R_386_TLS_TPOFF 14 /* Negative offset in static TLS block */ +#define R_386_TLS_IE 15 /* Absolute address of GOT for -ve static TLS */ +#define R_386_TLS_GOTIE 16 /* GOT entry for negative static TLS block */ +#define R_386_TLS_LE 17 /* Negative offset relative to static TLS */ +#define R_386_TLS_GD 18 /* 32 bit offset to GOT (index,off) pair */ +#define R_386_TLS_LDM 19 /* 32 bit offset to GOT (index,zero) pair */ +#define R_386_TLS_GD_32 24 /* 32 bit offset to GOT (index,off) pair */ +#define R_386_TLS_GD_PUSH 25 /* pushl instruction for Sun ABI GD sequence */ +#define R_386_TLS_GD_CALL 26 /* call instruction for Sun ABI GD sequence */ +#define R_386_TLS_GD_POP 27 /* popl instruction for Sun ABI GD sequence */ +#define R_386_TLS_LDM_32 28 /* 32 bit offset to GOT (index,zero) pair */ +#define R_386_TLS_LDM_PUSH 29 /* pushl instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDM_CALL 30 /* call instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDM_POP 31 /* popl instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDO_32 32 /* 32 bit offset from start of TLS block */ +#define R_386_TLS_IE_32 33 /* 32 bit offset to GOT static TLS offset entry */ +#define R_386_TLS_LE_32 34 /* 32 bit offset within static TLS block */ +#define R_386_TLS_DTPMOD32 35 /* GOT entry containing TLS index */ +#define R_386_TLS_DTPOFF32 36 /* GOT entry containing TLS offset */ +#define R_386_TLS_TPOFF32 37 /* GOT entry of -ve static TLS offset */ +#define R_386_IRELATIVE 42 /* PLT entry resolved indirectly at runtime */ + +#define R_AARCH64_NONE 0 /* No relocation */ +#define R_AARCH64_ABS64 257 /* Absolute offset */ +#define R_AARCH64_ABS32 258 /* Absolute, 32-bit overflow check */ +#define R_AARCH64_ABS16 259 /* Absolute, 16-bit overflow check */ +#define R_AARCH64_PREL64 260 /* PC relative */ +#define R_AARCH64_PREL32 261 /* PC relative, 32-bit overflow check */ +#define R_AARCH64_PREL16 262 /* PC relative, 16-bit overflow check */ +#define R_AARCH64_TSTBR14 279 /* TBZ/TBNZ immediate */ +#define R_AARCH64_CONDBR19 280 /* Conditional branch immediate */ +#define R_AARCH64_JUMP26 282 /* Branch immediate */ +#define R_AARCH64_CALL26 283 /* Call immediate */ +#define R_AARCH64_COPY 1024 /* Copy data from shared object */ +#define R_AARCH64_GLOB_DAT 1025 /* Set GOT entry to data address */ +#define R_AARCH64_JUMP_SLOT 1026 /* Set GOT entry to code address */ +#define R_AARCH64_RELATIVE 1027 /* Add load address of shared object */ +#define R_AARCH64_TLS_DTPREL64 1028 +#define R_AARCH64_TLS_DTPMOD64 1029 +#define R_AARCH64_TLS_TPREL64 1030 +#define R_AARCH64_TLSDESC 1031 /* Identify the TLS descriptor */ +#define R_AARCH64_IRELATIVE 1032 + +#define R_ARM_NONE 0 /* No relocation. */ +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 +#define R_ARM_ABS12 6 +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 +/* TLS relocations */ +#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ +#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ +#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ +#define R_ARM_COPY 20 /* Copy data from shared object. */ +#define R_ARM_GLOB_DAT 21 /* Set GOT entry to data address. */ +#define R_ARM_JUMP_SLOT 22 /* Set GOT entry to code address. */ +#define R_ARM_RELATIVE 23 /* Add load address of shared object. */ +#define R_ARM_GOTOFF 24 /* Add GOT-relative symbol address. */ +#define R_ARM_GOTPC 25 /* Add PC-relative GOT table address. */ +#define R_ARM_GOT32 26 /* Add PC-relative GOT offset. */ +#define R_ARM_PLT32 27 /* Add PC-relative PLT offset. */ +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS32 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 + +/* Name Value Field Calculation */ +#define R_IA_64_NONE 0 /* None */ +#define R_IA_64_IMM14 0x21 /* immediate14 S + A */ +#define R_IA_64_IMM22 0x22 /* immediate22 S + A */ +#define R_IA_64_IMM64 0x23 /* immediate64 S + A */ +#define R_IA_64_DIR32MSB 0x24 /* word32 MSB S + A */ +#define R_IA_64_DIR32LSB 0x25 /* word32 LSB S + A */ +#define R_IA_64_DIR64MSB 0x26 /* word64 MSB S + A */ +#define R_IA_64_DIR64LSB 0x27 /* word64 LSB S + A */ +#define R_IA_64_GPREL22 0x2a /* immediate22 @gprel(S + A) */ +#define R_IA_64_GPREL64I 0x2b /* immediate64 @gprel(S + A) */ +#define R_IA_64_GPREL32MSB 0x2c /* word32 MSB @gprel(S + A) */ +#define R_IA_64_GPREL32LSB 0x2d /* word32 LSB @gprel(S + A) */ +#define R_IA_64_GPREL64MSB 0x2e /* word64 MSB @gprel(S + A) */ +#define R_IA_64_GPREL64LSB 0x2f /* word64 LSB @gprel(S + A) */ +#define R_IA_64_LTOFF22 0x32 /* immediate22 @ltoff(S + A) */ +#define R_IA_64_LTOFF64I 0x33 /* immediate64 @ltoff(S + A) */ +#define R_IA_64_PLTOFF22 0x3a /* immediate22 @pltoff(S + A) */ +#define R_IA_64_PLTOFF64I 0x3b /* immediate64 @pltoff(S + A) */ +#define R_IA_64_PLTOFF64MSB 0x3e /* word64 MSB @pltoff(S + A) */ +#define R_IA_64_PLTOFF64LSB 0x3f /* word64 LSB @pltoff(S + A) */ +#define R_IA_64_FPTR64I 0x43 /* immediate64 @fptr(S + A) */ +#define R_IA_64_FPTR32MSB 0x44 /* word32 MSB @fptr(S + A) */ +#define R_IA_64_FPTR32LSB 0x45 /* word32 LSB @fptr(S + A) */ +#define R_IA_64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */ +#define R_IA_64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */ +#define R_IA_64_PCREL60B 0x48 /* immediate60 form1 S + A - P */ +#define R_IA_64_PCREL21B 0x49 /* immediate21 form1 S + A - P */ +#define R_IA_64_PCREL21M 0x4a /* immediate21 form2 S + A - P */ +#define R_IA_64_PCREL21F 0x4b /* immediate21 form3 S + A - P */ +#define R_IA_64_PCREL32MSB 0x4c /* word32 MSB S + A - P */ +#define R_IA_64_PCREL32LSB 0x4d /* word32 LSB S + A - P */ +#define R_IA_64_PCREL64MSB 0x4e /* word64 MSB S + A - P */ +#define R_IA_64_PCREL64LSB 0x4f /* word64 LSB S + A - P */ +#define R_IA_64_LTOFF_FPTR22 0x52 /* immediate22 @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64I 0x53 /* immediate64 @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR32MSB 0x54 /* word32 MSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR32LSB 0x55 /* word32 LSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64MSB 0x56 /* word64 MSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64LSB 0x57 /* word64 LSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_SEGREL32MSB 0x5c /* word32 MSB @segrel(S + A) */ +#define R_IA_64_SEGREL32LSB 0x5d /* word32 LSB @segrel(S + A) */ +#define R_IA_64_SEGREL64MSB 0x5e /* word64 MSB @segrel(S + A) */ +#define R_IA_64_SEGREL64LSB 0x5f /* word64 LSB @segrel(S + A) */ +#define R_IA_64_SECREL32MSB 0x64 /* word32 MSB @secrel(S + A) */ +#define R_IA_64_SECREL32LSB 0x65 /* word32 LSB @secrel(S + A) */ +#define R_IA_64_SECREL64MSB 0x66 /* word64 MSB @secrel(S + A) */ +#define R_IA_64_SECREL64LSB 0x67 /* word64 LSB @secrel(S + A) */ +#define R_IA_64_REL32MSB 0x6c /* word32 MSB BD + A */ +#define R_IA_64_REL32LSB 0x6d /* word32 LSB BD + A */ +#define R_IA_64_REL64MSB 0x6e /* word64 MSB BD + A */ +#define R_IA_64_REL64LSB 0x6f /* word64 LSB BD + A */ +#define R_IA_64_LTV32MSB 0x74 /* word32 MSB S + A */ +#define R_IA_64_LTV32LSB 0x75 /* word32 LSB S + A */ +#define R_IA_64_LTV64MSB 0x76 /* word64 MSB S + A */ +#define R_IA_64_LTV64LSB 0x77 /* word64 LSB S + A */ +#define R_IA_64_PCREL21BI 0x79 /* immediate21 form1 S + A - P */ +#define R_IA_64_PCREL22 0x7a /* immediate22 S + A - P */ +#define R_IA_64_PCREL64I 0x7b /* immediate64 S + A - P */ +#define R_IA_64_IPLTMSB 0x80 /* function descriptor MSB special */ +#define R_IA_64_IPLTLSB 0x81 /* function descriptor LSB speciaal */ +#define R_IA_64_SUB 0x85 /* immediate64 A - S */ +#define R_IA_64_LTOFF22X 0x86 /* immediate22 special */ +#define R_IA_64_LDXMOV 0x87 /* immediate22 special */ +#define R_IA_64_TPREL14 0x91 /* imm14 @tprel(S + A) */ +#define R_IA_64_TPREL22 0x92 /* imm22 @tprel(S + A) */ +#define R_IA_64_TPREL64I 0x93 /* imm64 @tprel(S + A) */ +#define R_IA_64_TPREL64MSB 0x96 /* word64 MSB @tprel(S + A) */ +#define R_IA_64_TPREL64LSB 0x97 /* word64 LSB @tprel(S + A) */ +#define R_IA_64_LTOFF_TPREL22 0x9a /* imm22 @ltoff(@tprel(S+A)) */ +#define R_IA_64_DTPMOD64MSB 0xa6 /* word64 MSB @dtpmod(S + A) */ +#define R_IA_64_DTPMOD64LSB 0xa7 /* word64 LSB @dtpmod(S + A) */ +#define R_IA_64_LTOFF_DTPMOD22 0xaa /* imm22 @ltoff(@dtpmod(S+A)) */ +#define R_IA_64_DTPREL14 0xb1 /* imm14 @dtprel(S + A) */ +#define R_IA_64_DTPREL22 0xb2 /* imm22 @dtprel(S + A) */ +#define R_IA_64_DTPREL64I 0xb3 /* imm64 @dtprel(S + A) */ +#define R_IA_64_DTPREL32MSB 0xb4 /* word32 MSB @dtprel(S + A) */ +#define R_IA_64_DTPREL32LSB 0xb5 /* word32 LSB @dtprel(S + A) */ +#define R_IA_64_DTPREL64MSB 0xb6 /* word64 MSB @dtprel(S + A) */ +#define R_IA_64_DTPREL64LSB 0xb7 /* word64 LSB @dtprel(S + A) */ +#define R_IA_64_LTOFF_DTPREL22 0xba /* imm22 @ltoff(@dtprel(S+A)) */ + +#define R_MIPS_NONE 0 /* No reloc */ +#define R_MIPS_16 1 /* Direct 16 bit */ +#define R_MIPS_32 2 /* Direct 32 bit */ +#define R_MIPS_REL32 3 /* PC relative 32 bit */ +#define R_MIPS_26 4 /* Direct 26 bit shifted */ +#define R_MIPS_HI16 5 /* High 16 bit */ +#define R_MIPS_LO16 6 /* Low 16 bit */ +#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ +#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ +#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ +#define R_MIPS_PC16 10 /* PC relative 16 bit */ +#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ +#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ +#define R_MIPS_64 18 /* Direct 64 bit */ +#define R_MIPS_GOT_DISP 19 +#define R_MIPS_GOT_PAGE 20 +#define R_MIPS_GOT_OFST 21 +#define R_MIPS_GOT_HI16 22 /* GOT HI 16 bit */ +#define R_MIPS_GOT_LO16 23 /* GOT LO 16 bit */ +#define R_MIPS_SUB 24 +#define R_MIPS_CALLHI16 30 /* upper 16 bit GOT entry for function */ +#define R_MIPS_CALLLO16 31 /* lower 16 bit GOT entry for function */ +#define R_MIPS_JALR 37 +#define R_MIPS_TLS_GD 42 +#define R_MIPS_COPY 126 +#define R_MIPS_JUMP_SLOT 127 + +#define R_PPC_NONE 0 /* No relocation. */ +#define R_PPC_ADDR32 1 +#define R_PPC_ADDR24 2 +#define R_PPC_ADDR16 3 +#define R_PPC_ADDR16_LO 4 +#define R_PPC_ADDR16_HI 5 +#define R_PPC_ADDR16_HA 6 +#define R_PPC_ADDR14 7 +#define R_PPC_ADDR14_BRTAKEN 8 +#define R_PPC_ADDR14_BRNTAKEN 9 +#define R_PPC_REL24 10 +#define R_PPC_REL14 11 +#define R_PPC_REL14_BRTAKEN 12 +#define R_PPC_REL14_BRNTAKEN 13 +#define R_PPC_GOT16 14 +#define R_PPC_GOT16_LO 15 +#define R_PPC_GOT16_HI 16 +#define R_PPC_GOT16_HA 17 +#define R_PPC_PLTREL24 18 +#define R_PPC_COPY 19 +#define R_PPC_GLOB_DAT 20 +#define R_PPC_JMP_SLOT 21 +#define R_PPC_RELATIVE 22 +#define R_PPC_LOCAL24PC 23 +#define R_PPC_UADDR32 24 +#define R_PPC_UADDR16 25 +#define R_PPC_REL32 26 +#define R_PPC_PLT32 27 +#define R_PPC_PLTREL32 28 +#define R_PPC_PLT16_LO 29 +#define R_PPC_PLT16_HI 30 +#define R_PPC_PLT16_HA 31 +#define R_PPC_SDAREL16 32 +#define R_PPC_SECTOFF 33 +#define R_PPC_SECTOFF_LO 34 +#define R_PPC_SECTOFF_HI 35 +#define R_PPC_SECTOFF_HA 36 + +/* + * 64-bit relocations + */ +#define R_PPC64_ADDR64 38 +#define R_PPC64_ADDR16_HIGHER 39 +#define R_PPC64_ADDR16_HIGHERA 40 +#define R_PPC64_ADDR16_HIGHEST 41 +#define R_PPC64_ADDR16_HIGHESTA 42 +#define R_PPC64_UADDR64 43 +#define R_PPC64_REL64 44 +#define R_PPC64_PLT64 45 +#define R_PPC64_PLTREL64 46 +#define R_PPC64_TOC16 47 +#define R_PPC64_TOC16_LO 48 +#define R_PPC64_TOC16_HI 49 +#define R_PPC64_TOC16_HA 50 +#define R_PPC64_TOC 51 +#define R_PPC64_DTPMOD64 68 +#define R_PPC64_TPREL64 73 +#define R_PPC64_DTPREL64 78 + +/* + * TLS relocations + */ +#define R_PPC_TLS 67 +#define R_PPC_DTPMOD32 68 +#define R_PPC_TPREL16 69 +#define R_PPC_TPREL16_LO 70 +#define R_PPC_TPREL16_HI 71 +#define R_PPC_TPREL16_HA 72 +#define R_PPC_TPREL32 73 +#define R_PPC_DTPREL16 74 +#define R_PPC_DTPREL16_LO 75 +#define R_PPC_DTPREL16_HI 76 +#define R_PPC_DTPREL16_HA 77 +#define R_PPC_DTPREL32 78 +#define R_PPC_GOT_TLSGD16 79 +#define R_PPC_GOT_TLSGD16_LO 80 +#define R_PPC_GOT_TLSGD16_HI 81 +#define R_PPC_GOT_TLSGD16_HA 82 +#define R_PPC_GOT_TLSLD16 83 +#define R_PPC_GOT_TLSLD16_LO 84 +#define R_PPC_GOT_TLSLD16_HI 85 +#define R_PPC_GOT_TLSLD16_HA 86 +#define R_PPC_GOT_TPREL16 87 +#define R_PPC_GOT_TPREL16_LO 88 +#define R_PPC_GOT_TPREL16_HI 89 +#define R_PPC_GOT_TPREL16_HA 90 + +/* + * The remaining relocs are from the Embedded ELF ABI, and are not in the + * SVR4 ELF ABI. + */ + +#define R_PPC_EMB_NADDR32 101 +#define R_PPC_EMB_NADDR16 102 +#define R_PPC_EMB_NADDR16_LO 103 +#define R_PPC_EMB_NADDR16_HI 104 +#define R_PPC_EMB_NADDR16_HA 105 +#define R_PPC_EMB_SDAI16 106 +#define R_PPC_EMB_SDA2I16 107 +#define R_PPC_EMB_SDA2REL 108 +#define R_PPC_EMB_SDA21 109 +#define R_PPC_EMB_MRKREF 110 +#define R_PPC_EMB_RELSEC16 111 +#define R_PPC_EMB_RELST_LO 112 +#define R_PPC_EMB_RELST_HI 113 +#define R_PPC_EMB_RELST_HA 114 +#define R_PPC_EMB_BIT_FLD 115 +#define R_PPC_EMB_RELSDA 116 + +/* + * RISC-V relocation types. + */ + +/* Relocation types used by the dynamic linker. */ +#define R_RISCV_NONE 0 +#define R_RISCV_32 1 +#define R_RISCV_64 2 +#define R_RISCV_RELATIVE 3 +#define R_RISCV_COPY 4 +#define R_RISCV_JUMP_SLOT 5 +#define R_RISCV_TLS_DTPMOD32 6 +#define R_RISCV_TLS_DTPMOD64 7 +#define R_RISCV_TLS_DTPREL32 8 +#define R_RISCV_TLS_DTPREL64 9 +#define R_RISCV_TLS_TPREL32 10 +#define R_RISCV_TLS_TPREL64 11 + +/* Relocation types not used by the dynamic linker. */ +#define R_RISCV_BRANCH 16 +#define R_RISCV_JAL 17 +#define R_RISCV_CALL 18 +#define R_RISCV_CALL_PLT 19 +#define R_RISCV_GOT_HI20 20 +#define R_RISCV_TLS_GOT_HI20 21 +#define R_RISCV_TLS_GD_HI20 22 +#define R_RISCV_PCREL_HI20 23 +#define R_RISCV_PCREL_LO12_I 24 +#define R_RISCV_PCREL_LO12_S 25 +#define R_RISCV_HI20 26 +#define R_RISCV_LO12_I 27 +#define R_RISCV_LO12_S 28 +#define R_RISCV_TPREL_HI20 29 +#define R_RISCV_TPREL_LO12_I 30 +#define R_RISCV_TPREL_LO12_S 31 +#define R_RISCV_TPREL_ADD 32 +#define R_RISCV_ADD8 33 +#define R_RISCV_ADD16 34 +#define R_RISCV_ADD32 35 +#define R_RISCV_ADD64 36 +#define R_RISCV_SUB8 37 +#define R_RISCV_SUB16 38 +#define R_RISCV_SUB32 39 +#define R_RISCV_SUB64 40 +#define R_RISCV_GNU_VTINHERIT 41 +#define R_RISCV_GNU_VTENTRY 42 +#define R_RISCV_ALIGN 43 +#define R_RISCV_RVC_BRANCH 44 +#define R_RISCV_RVC_JUMP 45 +#define R_RISCV_RVC_LUI 46 +#define R_RISCV_GPREL_I 47 +#define R_RISCV_GPREL_S 48 +#define R_RISCV_TPREL_I 49 +#define R_RISCV_TPREL_S 50 +#define R_RISCV_RELAX 51 +#define R_RISCV_SUB6 52 +#define R_RISCV_SET6 53 +#define R_RISCV_SET8 54 +#define R_RISCV_SET16 55 +#define R_RISCV_SET32 56 +#define R_RISCV_32_PCREL 57 +#define R_RISCV_IRELATIVE 58 + +#define R_SPARC_NONE 0 +#define R_SPARC_8 1 +#define R_SPARC_16 2 +#define R_SPARC_32 3 +#define R_SPARC_DISP8 4 +#define R_SPARC_DISP16 5 +#define R_SPARC_DISP32 6 +#define R_SPARC_WDISP30 7 +#define R_SPARC_WDISP22 8 +#define R_SPARC_HI22 9 +#define R_SPARC_22 10 +#define R_SPARC_13 11 +#define R_SPARC_LO10 12 +#define R_SPARC_GOT10 13 +#define R_SPARC_GOT13 14 +#define R_SPARC_GOT22 15 +#define R_SPARC_PC10 16 +#define R_SPARC_PC22 17 +#define R_SPARC_WPLT30 18 +#define R_SPARC_COPY 19 +#define R_SPARC_GLOB_DAT 20 +#define R_SPARC_JMP_SLOT 21 +#define R_SPARC_RELATIVE 22 +#define R_SPARC_UA32 23 +#define R_SPARC_PLT32 24 +#define R_SPARC_HIPLT22 25 +#define R_SPARC_LOPLT10 26 +#define R_SPARC_PCPLT32 27 +#define R_SPARC_PCPLT22 28 +#define R_SPARC_PCPLT10 29 +#define R_SPARC_10 30 +#define R_SPARC_11 31 +#define R_SPARC_64 32 +#define R_SPARC_OLO10 33 +#define R_SPARC_HH22 34 +#define R_SPARC_HM10 35 +#define R_SPARC_LM22 36 +#define R_SPARC_PC_HH22 37 +#define R_SPARC_PC_HM10 38 +#define R_SPARC_PC_LM22 39 +#define R_SPARC_WDISP16 40 +#define R_SPARC_WDISP19 41 +#define R_SPARC_GLOB_JMP 42 +#define R_SPARC_7 43 +#define R_SPARC_5 44 +#define R_SPARC_6 45 +#define R_SPARC_DISP64 46 +#define R_SPARC_PLT64 47 +#define R_SPARC_HIX22 48 +#define R_SPARC_LOX10 49 +#define R_SPARC_H44 50 +#define R_SPARC_M44 51 +#define R_SPARC_L44 52 +#define R_SPARC_REGISTER 53 +#define R_SPARC_UA64 54 +#define R_SPARC_UA16 55 +#define R_SPARC_TLS_GD_HI22 56 +#define R_SPARC_TLS_GD_LO10 57 +#define R_SPARC_TLS_GD_ADD 58 +#define R_SPARC_TLS_GD_CALL 59 +#define R_SPARC_TLS_LDM_HI22 60 +#define R_SPARC_TLS_LDM_LO10 61 +#define R_SPARC_TLS_LDM_ADD 62 +#define R_SPARC_TLS_LDM_CALL 63 +#define R_SPARC_TLS_LDO_HIX22 64 +#define R_SPARC_TLS_LDO_LOX10 65 +#define R_SPARC_TLS_LDO_ADD 66 +#define R_SPARC_TLS_IE_HI22 67 +#define R_SPARC_TLS_IE_LO10 68 +#define R_SPARC_TLS_IE_LD 69 +#define R_SPARC_TLS_IE_LDX 70 +#define R_SPARC_TLS_IE_ADD 71 +#define R_SPARC_TLS_LE_HIX22 72 +#define R_SPARC_TLS_LE_LOX10 73 +#define R_SPARC_TLS_DTPMOD32 74 +#define R_SPARC_TLS_DTPMOD64 75 +#define R_SPARC_TLS_DTPOFF32 76 +#define R_SPARC_TLS_DTPOFF64 77 +#define R_SPARC_TLS_TPOFF32 78 +#define R_SPARC_TLS_TPOFF64 79 + +#define R_X86_64_NONE 0 /* No relocation. */ +#define R_X86_64_64 1 /* Add 64 bit symbol value. */ +#define R_X86_64_PC32 2 /* PC-relative 32 bit signed sym value. */ +#define R_X86_64_GOT32 3 /* PC-relative 32 bit GOT offset. */ +#define R_X86_64_PLT32 4 /* PC-relative 32 bit PLT offset. */ +#define R_X86_64_COPY 5 /* Copy data from shared object. */ +#define R_X86_64_GLOB_DAT 6 /* Set GOT entry to data address. */ +#define R_X86_64_JMP_SLOT 7 /* Set GOT entry to code address. */ +#define R_X86_64_RELATIVE 8 /* Add load address of shared object. */ +#define R_X86_64_GOTPCREL 9 /* Add 32 bit signed pcrel offset to GOT. */ +#define R_X86_64_32 10 /* Add 32 bit zero extended symbol value */ +#define R_X86_64_32S 11 /* Add 32 bit sign extended symbol value */ +#define R_X86_64_16 12 /* Add 16 bit zero extended symbol value */ +#define R_X86_64_PC16 13 /* Add 16 bit signed extended pc relative symbol value */ +#define R_X86_64_8 14 /* Add 8 bit zero extended symbol value */ +#define R_X86_64_PC8 15 /* Add 8 bit signed extended pc relative symbol value */ +#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ +#define R_X86_64_DTPOFF64 17 /* Offset in TLS block */ +#define R_X86_64_TPOFF64 18 /* Offset in static TLS block */ +#define R_X86_64_TLSGD 19 /* PC relative offset to GD GOT entry */ +#define R_X86_64_TLSLD 20 /* PC relative offset to LD GOT entry */ +#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ +#define R_X86_64_GOTTPOFF 22 /* PC relative offset to IE GOT entry */ +#define R_X86_64_TPOFF32 23 /* Offset in static TLS block */ +#define R_X86_64_PC64 24 /* PC-relative 64 bit signed sym value. */ +#define R_X86_64_GOTOFF64 25 +#define R_X86_64_GOTPC32 26 +#define R_X86_64_GOT64 27 +#define R_X86_64_GOTPCREL64 28 +#define R_X86_64_GOTPC64 29 +#define R_X86_64_GOTPLT64 30 +#define R_X86_64_PLTOFF64 31 +#define R_X86_64_SIZE32 32 +#define R_X86_64_SIZE64 33 +#define R_X86_64_GOTPC32_TLSDESC 34 +#define R_X86_64_TLSDESC_CALL 35 +#define R_X86_64_TLSDESC 36 +#define R_X86_64_IRELATIVE 37 + + +#endif /* !_SYS_ELF_COMMON_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/elf_generic.h b/lib/libc/include/any-freebsd-any/sys/elf_generic.h new file mode 100644 index 000000000000..301ee52cf7a1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/elf_generic.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ELF_GENERIC_H_ +#define _SYS_ELF_GENERIC_H_ 1 + +#include + +/* + * Definitions of generic ELF names which relieve applications from + * needing to know the word size. + */ + +#if __ELF_WORD_SIZE != 32 && __ELF_WORD_SIZE != 64 +#error "__ELF_WORD_SIZE must be defined as 32 or 64" +#endif + +#define ELF_CLASS __CONCAT(ELFCLASS,__ELF_WORD_SIZE) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define ELF_DATA ELFDATA2LSB +#elif BYTE_ORDER == BIG_ENDIAN +#define ELF_DATA ELFDATA2MSB +#else +#error "Unknown byte order" +#endif + +#define __elfN(x) __CONCAT(__CONCAT(__CONCAT(elf,__ELF_WORD_SIZE),_),x) +#define __ElfN(x) __CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x) +#define __ELFN(x) __CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x) +#define __ElfType(x) typedef __ElfN(x) __CONCAT(Elf_,x) + +__ElfType(Addr); +__ElfType(Half); +__ElfType(Off); +__ElfType(Sword); +__ElfType(Word); +__ElfType(Ehdr); +__ElfType(Shdr); +__ElfType(Phdr); +__ElfType(Dyn); +__ElfType(Rel); +__ElfType(Rela); +__ElfType(Sym); +__ElfType(Verdef); +__ElfType(Verdaux); +__ElfType(Verneed); +__ElfType(Vernaux); +__ElfType(Versym); + +/* Non-standard ELF types. */ +__ElfType(Hashelt); +__ElfType(Size); +__ElfType(Ssize); + +#define ELF_R_SYM __ELFN(R_SYM) +#define ELF_R_TYPE __ELFN(R_TYPE) +#define ELF_R_INFO __ELFN(R_INFO) +#define ELF_ST_BIND __ELFN(ST_BIND) +#define ELF_ST_TYPE __ELFN(ST_TYPE) +#define ELF_ST_INFO __ELFN(ST_INFO) +#define ELF_ST_VISIBILITY __ELFN(ST_VISIBILITY) + +#endif /* !_SYS_ELF_GENERIC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/endian.h b/lib/libc/include/any-freebsd-any/sys/endian.h new file mode 100644 index 000000000000..3cef6130cd15 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/endian.h @@ -0,0 +1,207 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Thomas Moestl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#include +#include +#include + +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +/* + * General byte order swapping functions. + */ +#define bswap16(x) __bswap16(x) +#define bswap32(x) __bswap32(x) +#define bswap64(x) __bswap64(x) + +/* + * Host to big endian, host to little endian, big endian to host, and little + * endian to host byte order functions as detailed in byteorder(9). + */ +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define htobe16(x) bswap16((x)) +#define htobe32(x) bswap32((x)) +#define htobe64(x) bswap64((x)) +#define htole16(x) ((uint16_t)(x)) +#define htole32(x) ((uint32_t)(x)) +#define htole64(x) ((uint64_t)(x)) + +#define be16toh(x) bswap16((x)) +#define be32toh(x) bswap32((x)) +#define be64toh(x) bswap64((x)) +#define le16toh(x) ((uint16_t)(x)) +#define le32toh(x) ((uint32_t)(x)) +#define le64toh(x) ((uint64_t)(x)) +#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ +#define htobe16(x) ((uint16_t)(x)) +#define htobe32(x) ((uint32_t)(x)) +#define htobe64(x) ((uint64_t)(x)) +#define htole16(x) bswap16((x)) +#define htole32(x) bswap32((x)) +#define htole64(x) bswap64((x)) + +#define be16toh(x) ((uint16_t)(x)) +#define be32toh(x) ((uint32_t)(x)) +#define be64toh(x) ((uint64_t)(x)) +#define le16toh(x) bswap16((x)) +#define le32toh(x) bswap32((x)) +#define le64toh(x) bswap64((x)) +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + +/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ + +static __inline uint16_t +be16dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return ((p[0] << 8) | p[1]); +} + +static __inline uint32_t +be32dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); +} + +static __inline uint64_t +be64dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); +} + +static __inline uint16_t +le16dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return ((p[1] << 8) | p[0]); +} + +static __inline uint32_t +le32dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); +} + +static __inline uint64_t +le64dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p)); +} + +static __inline void +be16enc(void *pp, uint16_t u) +{ + uint8_t *p = (uint8_t *)pp; + + p[0] = (u >> 8) & 0xff; + p[1] = u & 0xff; +} + +static __inline void +be32enc(void *pp, uint32_t u) +{ + uint8_t *p = (uint8_t *)pp; + + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; +} + +static __inline void +be64enc(void *pp, uint64_t u) +{ + uint8_t *p = (uint8_t *)pp; + + be32enc(p, (uint32_t)(u >> 32)); + be32enc(p + 4, (uint32_t)(u & 0xffffffffU)); +} + +static __inline void +le16enc(void *pp, uint16_t u) +{ + uint8_t *p = (uint8_t *)pp; + + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; +} + +static __inline void +le32enc(void *pp, uint32_t u) +{ + uint8_t *p = (uint8_t *)pp; + + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; + p[2] = (u >> 16) & 0xff; + p[3] = (u >> 24) & 0xff; +} + +static __inline void +le64enc(void *pp, uint64_t u) +{ + uint8_t *p = (uint8_t *)pp; + + le32enc(p, (uint32_t)(u & 0xffffffffU)); + le32enc(p + 4, (uint32_t)(u >> 32)); +} + +#endif /* _SYS_ENDIAN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/epoch.h b/lib/libc/include/any-freebsd-any/sys/epoch.h new file mode 100644 index 000000000000..7338c536c024 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/epoch.h @@ -0,0 +1,93 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018, Matthew Macy + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EPOCH_H_ +#define _SYS_EPOCH_H_ + +struct epoch_context { + void *data[2]; +} __aligned(sizeof(void *)); + +typedef struct epoch_context *epoch_context_t; + +#ifdef _KERNEL +#include +#include +#include + +struct epoch; +typedef struct epoch *epoch_t; + +#define EPOCH_PREEMPT 0x1 +#define EPOCH_LOCKED 0x2 + +extern epoch_t global_epoch; +extern epoch_t global_epoch_preempt; + +struct epoch_tracker { +#ifdef EPOCH_TRACKER_DEBUG +#define EPOCH_MAGIC0 0xFADECAFEF00DD00D +#define EPOCH_MAGIC1 0xBADDBABEDEEDFEED + uint64_t et_magic_pre; +#endif + TAILQ_ENTRY(epoch_tracker) et_link; + struct thread *et_td; + ck_epoch_section_t et_section; +#ifdef EPOCH_TRACKER_DEBUG + uint64_t et_magic_post; +#endif +} __aligned(sizeof(void *)); +typedef struct epoch_tracker *epoch_tracker_t; + +epoch_t epoch_alloc(int flags); +void epoch_free(epoch_t epoch); +void epoch_wait(epoch_t epoch); +void epoch_wait_preempt(epoch_t epoch); +void epoch_drain_callbacks(epoch_t epoch); +void epoch_call(epoch_t epoch, epoch_context_t ctx, void (*callback) (epoch_context_t)); +int in_epoch(epoch_t epoch); +int in_epoch_verbose(epoch_t epoch, int dump_onfail); +DPCPU_DECLARE(int, epoch_cb_count); +DPCPU_DECLARE(struct grouptask, epoch_cb_task); +#define EPOCH_MAGIC0 0xFADECAFEF00DD00D +#define EPOCH_MAGIC1 0xBADDBABEDEEDFEED + +void epoch_enter_preempt(epoch_t epoch, epoch_tracker_t et); +void epoch_exit_preempt(epoch_t epoch, epoch_tracker_t et); +void epoch_enter(epoch_t epoch); +void epoch_exit(epoch_t epoch); + +/* for binary compatibility - do not use */ +void epoch_enter_preempt_KBI(epoch_t epoch, epoch_tracker_t et); +void epoch_exit_preempt_KBI(epoch_t epoch, epoch_tracker_t et); +void epoch_enter_KBI(epoch_t epoch); +void epoch_exit_KBI(epoch_t epoch); + +#endif /* _KERNEL */ +#endif /* _SYS_EPOCH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/errno.h b/lib/libc/include/any-freebsd-any/sys/errno.h new file mode 100644 index 000000000000..6994c0612f79 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/errno.h @@ -0,0 +1,209 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_ERRNO_H_ +#define _SYS_ERRNO_H_ + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +__BEGIN_DECLS +int * __error(void); +__END_DECLS +#define errno (* __error()) +#endif + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ + /* 11 was EAGAIN */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#ifndef _POSIX_SOURCE +#define ENOTBLK 15 /* Block device required */ +#endif +#define EBUSY 16 /* Device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#ifndef _POSIX_SOURCE +#define ETXTBSY 26 /* Text file busy */ +#endif +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only filesystem */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#ifndef _POSIX_SOURCE +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define EOPNOTSUPP 45 /* Operation not supported */ +#define ENOTSUP EOPNOTSUPP /* Operation not supported */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Operation timed out */ +#define ECONNREFUSED 61 /* Connection refused */ + +#define ELOOP 62 /* Too many levels of symbolic links */ +#endif /* _POSIX_SOURCE */ +#define ENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#ifndef _POSIX_SOURCE +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#endif /* _POSIX_SOURCE */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#ifndef _POSIX_SOURCE +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#endif /* _POSIX_SOURCE */ + +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ + +#ifndef _POSIX_SOURCE +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ +#define EIDRM 82 /* Identifier removed */ +#define ENOMSG 83 /* No message of desired type */ +#define EOVERFLOW 84 /* Value too large to be stored in data type */ +#define ECANCELED 85 /* Operation canceled */ +#define EILSEQ 86 /* Illegal byte sequence */ +#define ENOATTR 87 /* Attribute not found */ + +#define EDOOFUS 88 /* Programming error */ +#endif /* _POSIX_SOURCE */ + +#define EBADMSG 89 /* Bad message */ +#define EMULTIHOP 90 /* Multihop attempted */ +#define ENOLINK 91 /* Link has been severed */ +#define EPROTO 92 /* Protocol error */ + +#ifndef _POSIX_SOURCE +#define ENOTCAPABLE 93 /* Capabilities insufficient */ +#define ECAPMODE 94 /* Not permitted in capability mode */ +#define ENOTRECOVERABLE 95 /* State not recoverable */ +#define EOWNERDEAD 96 /* Previous owner died */ +#define EINTEGRITY 97 /* Integrity check failed */ +#endif /* _POSIX_SOURCE */ + +#ifndef _POSIX_SOURCE +#define ELAST 97 /* Must be equal largest errno */ +#endif /* _POSIX_SOURCE */ + +#if defined(_KERNEL) || defined(_WANT_KERNEL_ERRNO) +/* pseudo-errors returned inside kernel to modify return to process */ +#define ERESTART (-1) /* restart syscall */ +#define EJUSTRETURN (-2) /* don't modify regs, just return */ +#define ENOIOCTL (-3) /* ioctl not handled by this layer */ +#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */ +#define ERELOOKUP (-5) /* retry the directory lookup */ +#endif + +#ifndef _KERNEL +#if __EXT1_VISIBLE +/* ISO/IEC 9899:2011 K.3.2.2 */ +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif +#endif /* __EXT1_VISIBLE */ +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/eui64.h b/lib/libc/include/any-freebsd-any/sys/eui64.h new file mode 100644 index 000000000000..163a5bdd5198 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/eui64.h @@ -0,0 +1,59 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright 2004 The Aerospace Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of The Aerospace Corporation may not be used to endorse or + * promote products derived from this software. + * + * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_EUI64_H +#define _SYS_EUI64_H + +/* + * Size of the ASCII representation of an EUI-64. + */ +#define EUI64_SIZ 24 + +/* + * The number of bytes in an EUI-64. + */ +#define EUI64_LEN 8 + +/* + * Structure of an IEEE EUI-64. + */ +struct eui64 { + u_char octet[EUI64_LEN]; +}; + +#ifndef _KERNEL +int eui64_aton(const char *, struct eui64 *); +int eui64_ntoa(const struct eui64 *, char *, size_t); +int eui64_ntohost(char *, size_t, const struct eui64 *); +int eui64_hostton(const char *, struct eui64 *); +#endif /* !_KERNEL */ + +#endif /* !_SYS_EUI64_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/event.h b/lib/libc/include/any-freebsd-any/sys/event.h new file mode 100644 index 000000000000..ef1d87ada9f6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/event.h @@ -0,0 +1,369 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999,2000,2001 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EVENT_H_ +#define _SYS_EVENT_H_ + +#include +#include + +#define EVFILT_READ (-1) +#define EVFILT_WRITE (-2) +#define EVFILT_AIO (-3) /* attached to aio requests */ +#define EVFILT_VNODE (-4) /* attached to vnodes */ +#define EVFILT_PROC (-5) /* attached to struct proc */ +#define EVFILT_SIGNAL (-6) /* attached to struct proc */ +#define EVFILT_TIMER (-7) /* timers */ +#define EVFILT_PROCDESC (-8) /* attached to process descriptors */ +#define EVFILT_FS (-9) /* filesystem events */ +#define EVFILT_LIO (-10) /* attached to lio requests */ +#define EVFILT_USER (-11) /* User events */ +#define EVFILT_SENDFILE (-12) /* attached to sendfile requests */ +#define EVFILT_EMPTY (-13) /* empty send socket buf */ +#define EVFILT_SYSCOUNT 13 + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#define EV_SET(kevp_, a, b, c, d, e, f) do { \ + *(kevp_) = (struct kevent){ \ + .ident = (a), \ + .filter = (b), \ + .flags = (c), \ + .fflags = (d), \ + .data = (e), \ + .udata = (f), \ + .ext = {0}, \ + }; \ +} while(0) +#else /* Pre-C99 or not STDC (e.g., C++) */ +/* The definition of the local variable kevp could possibly conflict + * with a user-defined value passed in parameters a-f. + */ +#define EV_SET(kevp_, a, b, c, d, e, f) do { \ + struct kevent *kevp = (kevp_); \ + (kevp)->ident = (a); \ + (kevp)->filter = (b); \ + (kevp)->flags = (c); \ + (kevp)->fflags = (d); \ + (kevp)->data = (e); \ + (kevp)->udata = (f); \ + (kevp)->ext[0] = 0; \ + (kevp)->ext[1] = 0; \ + (kevp)->ext[2] = 0; \ + (kevp)->ext[3] = 0; \ +} while(0) +#endif + +struct kevent { + __uintptr_t ident; /* identifier for this event */ + short filter; /* filter for event */ + unsigned short flags; /* action flags for kqueue */ + unsigned int fflags; /* filter flag value */ + __int64_t data; /* filter data value */ + void *udata; /* opaque user data identifier */ + __uint64_t ext[4]; /* extensions */ +}; + +#if defined(_WANT_FREEBSD11_KEVENT) +/* Older structure used in FreeBSD 11.x and older. */ +struct kevent_freebsd11 { + __uintptr_t ident; /* identifier for this event */ + short filter; /* filter for event */ + unsigned short flags; + unsigned int fflags; + __intptr_t data; + void *udata; /* opaque user data identifier */ +}; +#endif + +#if defined(_WANT_KEVENT32) || (defined(_KERNEL) && defined(__LP64__)) +struct kevent32 { + uint32_t ident; /* identifier for this event */ + short filter; /* filter for event */ + u_short flags; + u_int fflags; +#ifndef __amd64__ + uint32_t pad0; +#endif + uint32_t data1, data2; + uint32_t udata; /* opaque user data identifier */ +#ifndef __amd64__ + uint32_t pad1; +#endif + uint32_t ext64[8]; +}; + +#ifdef _WANT_FREEBSD11_KEVENT +struct kevent32_freebsd11 { + u_int32_t ident; /* identifier for this event */ + short filter; /* filter for event */ + u_short flags; + u_int fflags; + int32_t data; + u_int32_t udata; /* opaque user data identifier */ +}; +#endif +#endif + +/* actions */ +#define EV_ADD 0x0001 /* add event to kq (implies enable) */ +#define EV_DELETE 0x0002 /* delete event from kq */ +#define EV_ENABLE 0x0004 /* enable event */ +#define EV_DISABLE 0x0008 /* disable event (not reported) */ +#define EV_FORCEONESHOT 0x0100 /* enable _ONESHOT and force trigger */ + +/* flags */ +#define EV_ONESHOT 0x0010 /* only report one occurrence */ +#define EV_CLEAR 0x0020 /* clear event state after reporting */ +#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */ +#define EV_DISPATCH 0x0080 /* disable event after reporting */ + +#define EV_SYSFLAGS 0xF000 /* reserved by system */ +#define EV_DROP 0x1000 /* note should be dropped */ +#define EV_FLAG1 0x2000 /* filter-specific flag */ +#define EV_FLAG2 0x4000 /* filter-specific flag */ + +/* returned values */ +#define EV_EOF 0x8000 /* EOF detected */ +#define EV_ERROR 0x4000 /* error, data contains errno */ + + /* + * data/hint flags/masks for EVFILT_USER, shared with userspace + * + * On input, the top two bits of fflags specifies how the lower twenty four + * bits should be applied to the stored value of fflags. + * + * On output, the top two bits will always be set to NOTE_FFNOP and the + * remaining twenty four bits will contain the stored fflags value. + */ +#define NOTE_FFNOP 0x00000000 /* ignore input fflags */ +#define NOTE_FFAND 0x40000000 /* AND fflags */ +#define NOTE_FFOR 0x80000000 /* OR fflags */ +#define NOTE_FFCOPY 0xc0000000 /* copy fflags */ +#define NOTE_FFCTRLMASK 0xc0000000 /* masks for operations */ +#define NOTE_FFLAGSMASK 0x00ffffff + +#define NOTE_TRIGGER 0x01000000 /* Cause the event to be + triggered for output. */ + +/* + * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace + */ +#define NOTE_LOWAT 0x0001 /* low water mark */ +#define NOTE_FILE_POLL 0x0002 /* behave like poll() */ + +/* + * data/hint flags for EVFILT_VNODE, shared with userspace + */ +#define NOTE_DELETE 0x0001 /* vnode was removed */ +#define NOTE_WRITE 0x0002 /* data contents changed */ +#define NOTE_EXTEND 0x0004 /* size increased */ +#define NOTE_ATTRIB 0x0008 /* attributes changed */ +#define NOTE_LINK 0x0010 /* link count changed */ +#define NOTE_RENAME 0x0020 /* vnode was renamed */ +#define NOTE_REVOKE 0x0040 /* vnode access was revoked */ +#define NOTE_OPEN 0x0080 /* vnode was opened */ +#define NOTE_CLOSE 0x0100 /* file closed, fd did not + allowed write */ +#define NOTE_CLOSE_WRITE 0x0200 /* file closed, fd did allowed + write */ +#define NOTE_READ 0x0400 /* file was read */ + +/* + * data/hint flags for EVFILT_PROC and EVFILT_PROCDESC, shared with userspace + */ +#define NOTE_EXIT 0x80000000 /* process exited */ +#define NOTE_FORK 0x40000000 /* process forked */ +#define NOTE_EXEC 0x20000000 /* process exec'd */ +#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ +#define NOTE_PDATAMASK 0x000fffff /* mask for pid */ + +/* additional flags for EVFILT_PROC */ +#define NOTE_TRACK 0x00000001 /* follow across forks */ +#define NOTE_TRACKERR 0x00000002 /* could not track child */ +#define NOTE_CHILD 0x00000004 /* am a child process */ + +/* additional flags for EVFILT_TIMER */ +#define NOTE_SECONDS 0x00000001 /* data is seconds */ +#define NOTE_MSECONDS 0x00000002 /* data is milliseconds */ +#define NOTE_USECONDS 0x00000004 /* data is microseconds */ +#define NOTE_NSECONDS 0x00000008 /* data is nanoseconds */ +#define NOTE_ABSTIME 0x00000010 /* timeout is absolute */ + +struct knote; +SLIST_HEAD(klist, knote); +struct kqueue; +TAILQ_HEAD(kqlist, kqueue); +struct knlist { + struct klist kl_list; + void (*kl_lock)(void *); /* lock function */ + void (*kl_unlock)(void *); + void (*kl_assert_locked)(void *); + void (*kl_assert_unlocked)(void *); + void *kl_lockarg; /* argument passed to lock functions */ + int kl_autodestroy; +}; + + +#ifdef _KERNEL + +/* + * Flags for knote call + */ +#define KNF_LISTLOCKED 0x0001 /* knlist is locked */ +#define KNF_NOKQLOCK 0x0002 /* do not keep KQ_LOCK */ + +#define KNOTE(list, hint, flags) knote(list, hint, flags) +#define KNOTE_LOCKED(list, hint) knote(list, hint, KNF_LISTLOCKED) +#define KNOTE_UNLOCKED(list, hint) knote(list, hint, 0) + +#define KNLIST_EMPTY(list) SLIST_EMPTY(&(list)->kl_list) + +/* + * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also + * shared by EVFILT_PROC (all knotes attached to p->p_klist) + */ +#define NOTE_SIGNAL 0x08000000 + +/* + * Hint values for the optional f_touch event filter. If f_touch is not set + * to NULL and f_isfd is zero the f_touch filter will be called with the type + * argument set to EVENT_REGISTER during a kevent() system call. It is also + * called under the same conditions with the type argument set to EVENT_PROCESS + * when the event has been triggered. + */ +#define EVENT_REGISTER 1 +#define EVENT_PROCESS 2 + +struct filterops { + int f_isfd; /* true if ident == filedescriptor */ + int (*f_attach)(struct knote *kn); + void (*f_detach)(struct knote *kn); + int (*f_event)(struct knote *kn, long hint); + void (*f_touch)(struct knote *kn, struct kevent *kev, u_long type); +}; + +/* + * An in-flux knote cannot be dropped from its kq while the kq is + * unlocked. If the KN_SCAN flag is not set, a thread can only set + * kn_influx when it is exclusive owner of the knote state, and can + * modify kn_status as if it had the KQ lock. KN_SCAN must not be set + * on a knote which is already in flux. + * + * kn_sfflags, kn_sdata, and kn_kevent are protected by the knlist lock. + */ +struct knote { + SLIST_ENTRY(knote) kn_link; /* for kq */ + SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */ + struct knlist *kn_knlist; /* f_attach populated */ + TAILQ_ENTRY(knote) kn_tqe; + struct kqueue *kn_kq; /* which queue we are on */ + struct kevent kn_kevent; + void *kn_hook; + int kn_hookid; + int kn_status; /* protected by kq lock */ +#define KN_ACTIVE 0x01 /* event has been triggered */ +#define KN_QUEUED 0x02 /* event is on queue */ +#define KN_DISABLED 0x04 /* event is disabled */ +#define KN_DETACHED 0x08 /* knote is detached */ +#define KN_MARKER 0x20 /* ignore this knote */ +#define KN_KQUEUE 0x40 /* this knote belongs to a kq */ +#define KN_SCAN 0x100 /* flux set in kqueue_scan() */ + int kn_influx; + int kn_sfflags; /* saved filter flags */ + int64_t kn_sdata; /* saved data field */ + union { + struct file *p_fp; /* file data pointer */ + struct proc *p_proc; /* proc pointer */ + struct kaiocb *p_aio; /* AIO job pointer */ + struct aioliojob *p_lio; /* LIO job pointer */ + void *p_v; /* generic other pointer */ + } kn_ptr; + struct filterops *kn_fop; + +#define kn_id kn_kevent.ident +#define kn_filter kn_kevent.filter +#define kn_flags kn_kevent.flags +#define kn_fflags kn_kevent.fflags +#define kn_data kn_kevent.data +#define kn_fp kn_ptr.p_fp +}; +struct kevent_copyops { + void *arg; + int (*k_copyout)(void *arg, struct kevent *kevp, int count); + int (*k_copyin)(void *arg, struct kevent *kevp, int count); + size_t kevent_size; +}; + +struct thread; +struct proc; +struct knlist; +struct mtx; +struct rwlock; + +void knote(struct knlist *list, long hint, int lockflags); +void knote_fork(struct knlist *list, int pid); +struct knlist *knlist_alloc(struct mtx *lock); +void knlist_detach(struct knlist *knl); +void knlist_add(struct knlist *knl, struct knote *kn, int islocked); +void knlist_remove(struct knlist *knl, struct knote *kn, int islocked); +int knlist_empty(struct knlist *knl); +void knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *), + void (*kl_unlock)(void *), void (*kl_assert_locked)(void *), + void (*kl_assert_unlocked)(void *)); +void knlist_init_mtx(struct knlist *knl, struct mtx *lock); +void knlist_init_rw_reader(struct knlist *knl, struct rwlock *lock); +void knlist_destroy(struct knlist *knl); +void knlist_cleardel(struct knlist *knl, struct thread *td, + int islocked, int killkn); +#define knlist_clear(knl, islocked) \ + knlist_cleardel((knl), NULL, (islocked), 0) +#define knlist_delete(knl, td, islocked) \ + knlist_cleardel((knl), (td), (islocked), 1) +void knote_fdclose(struct thread *p, int fd); +int kqfd_register(int fd, struct kevent *kev, struct thread *p, + int mflag); +int kqueue_add_filteropts(int filt, struct filterops *filtops); +int kqueue_del_filteropts(int filt); + +#else /* !_KERNEL */ + +#include +struct timespec; + +__BEGIN_DECLS +int kqueue(void); +int kevent(int kq, const struct kevent *changelist, int nchanges, + struct kevent *eventlist, int nevents, + const struct timespec *timeout); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_EVENT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/eventhandler.h b/lib/libc/include/any-freebsd-any/sys/eventhandler.h new file mode 100644 index 000000000000..510b89381b88 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/eventhandler.h @@ -0,0 +1,343 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999 Michael Smith + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EVENTHANDLER_H_ +#define _SYS_EVENTHANDLER_H_ + +#include +#include +#include +#include + +struct eventhandler_entry { + TAILQ_ENTRY(eventhandler_entry) ee_link; + int ee_priority; +#define EHE_DEAD_PRIORITY (-1) + void *ee_arg; +}; + +#ifdef VIMAGE +struct eventhandler_entry_vimage { + void (* func)(void); /* Original function registered. */ + void *ee_arg; /* Original argument registered. */ + void *sparep[2]; +}; +#endif + +struct eventhandler_list { + char *el_name; + int el_flags; /* Unused. */ + u_int el_runcount; + struct mtx el_lock; + TAILQ_ENTRY(eventhandler_list) el_link; + TAILQ_HEAD(,eventhandler_entry) el_entries; +}; + +typedef struct eventhandler_entry *eventhandler_tag; + +#define EHL_LOCK(p) mtx_lock(&(p)->el_lock) +#define EHL_UNLOCK(p) mtx_unlock(&(p)->el_lock) +#define EHL_LOCK_ASSERT(p, x) mtx_assert(&(p)->el_lock, x) + +/* + * Macro to invoke the handlers for a given event. + */ +#define _EVENTHANDLER_INVOKE(name, list, ...) do { \ + struct eventhandler_entry *_ep; \ + struct eventhandler_entry_ ## name *_t; \ + \ + EHL_LOCK_ASSERT((list), MA_OWNED); \ + (list)->el_runcount++; \ + KASSERT((list)->el_runcount > 0, \ + ("eventhandler_invoke: runcount overflow")); \ + CTR0(KTR_EVH, "eventhandler_invoke(\"" __STRING(name) "\")"); \ + TAILQ_FOREACH(_ep, &((list)->el_entries), ee_link) { \ + if (_ep->ee_priority != EHE_DEAD_PRIORITY) { \ + EHL_UNLOCK((list)); \ + _t = (struct eventhandler_entry_ ## name *)_ep; \ + CTR1(KTR_EVH, "eventhandler_invoke: executing %p", \ + (void *)_t->eh_func); \ + _t->eh_func(_ep->ee_arg , ## __VA_ARGS__); \ + EHL_LOCK((list)); \ + } \ + } \ + KASSERT((list)->el_runcount > 0, \ + ("eventhandler_invoke: runcount underflow")); \ + (list)->el_runcount--; \ + if ((list)->el_runcount == 0) \ + eventhandler_prune_list(list); \ + EHL_UNLOCK((list)); \ +} while (0) + +/* + * You can optionally use the EVENTHANDLER_LIST and EVENTHANDLER_DIRECT macros + * to pre-define a symbol for the eventhandler list. This symbol can be used by + * EVENTHANDLER_DIRECT_INVOKE, which has the advantage of not needing to do a + * locked search of the global list of eventhandler lists. At least + * EVENTHANDLER_LIST_DEFINE must be be used for EVENTHANDLER_DIRECT_INVOKE to + * work. EVENTHANDLER_LIST_DECLARE is only needed if the call to + * EVENTHANDLER_DIRECT_INVOKE is in a different compilation unit from + * EVENTHANDLER_LIST_DEFINE. If the events are even relatively high frequency + * it is suggested that you directly define a list for them. + */ +#define EVENTHANDLER_LIST_DECLARE(name) \ +extern struct eventhandler_list *_eventhandler_list_ ## name \ + +#define EVENTHANDLER_LIST_DEFINE(name) \ +struct eventhandler_list *_eventhandler_list_ ## name ; \ +static void _ehl_init_ ## name (void * ctx __unused) \ +{ \ + _eventhandler_list_ ## name = eventhandler_create_list(#name); \ +} \ +SYSINIT(name ## _ehl_init, SI_SUB_EVENTHANDLER, SI_ORDER_ANY, \ + _ehl_init_ ## name, NULL); \ + struct __hack + +#define EVENTHANDLER_DIRECT_INVOKE(name, ...) do { \ + struct eventhandler_list *_el; \ + \ + _el = _eventhandler_list_ ## name ; \ + if (!TAILQ_EMPTY(&_el->el_entries)) { \ + EHL_LOCK(_el); \ + _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ + } \ +} while (0) + +/* + * Event handlers need to be declared, but do not need to be defined. The + * declaration must be in scope wherever the handler is to be invoked. + */ +#define EVENTHANDLER_DECLARE(name, type) \ +struct eventhandler_entry_ ## name \ +{ \ + struct eventhandler_entry ee; \ + type eh_func; \ +}; \ +struct __hack + +#define EVENTHANDLER_DEFINE(name, func, arg, priority) \ + static eventhandler_tag name ## _tag; \ + static void name ## _evh_init(void *ctx) \ + { \ + name ## _tag = EVENTHANDLER_REGISTER(name, func, ctx, \ + priority); \ + } \ + SYSINIT(name ## _evh_init, SI_SUB_CONFIGURE, SI_ORDER_ANY, \ + name ## _evh_init, arg); \ + struct __hack + +#define EVENTHANDLER_INVOKE(name, ...) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ +} while (0) + +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ + eventhandler_register(NULL, #name, func, arg, priority) + +#define EVENTHANDLER_DEREGISTER(name, tag) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + eventhandler_deregister(_el, tag); \ +} while(0) + +#define EVENTHANDLER_DEREGISTER_NOWAIT(name, tag) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + eventhandler_deregister_nowait(_el, tag); \ +} while(0) + +eventhandler_tag eventhandler_register(struct eventhandler_list *list, + const char *name, void *func, void *arg, int priority); +void eventhandler_deregister(struct eventhandler_list *list, + eventhandler_tag tag); +void eventhandler_deregister_nowait(struct eventhandler_list *list, + eventhandler_tag tag); +struct eventhandler_list *eventhandler_find_list(const char *name); +void eventhandler_prune_list(struct eventhandler_list *list); +struct eventhandler_list *eventhandler_create_list(const char *name); + +#ifdef VIMAGE +typedef void (*vimage_iterator_func_t)(void *, ...); + +eventhandler_tag vimage_eventhandler_register(struct eventhandler_list *list, + const char *name, void *func, void *arg, int priority, + vimage_iterator_func_t); +#endif + +/* + * Standard system event queues. + */ + +/* Generic priority levels */ +#define EVENTHANDLER_PRI_FIRST 0 +#define EVENTHANDLER_PRI_ANY 10000 +#define EVENTHANDLER_PRI_LAST 20000 + +/* Shutdown events */ +typedef void (*shutdown_fn)(void *, int); + +#define SHUTDOWN_PRI_FIRST EVENTHANDLER_PRI_FIRST +#define SHUTDOWN_PRI_DEFAULT EVENTHANDLER_PRI_ANY +#define SHUTDOWN_PRI_LAST EVENTHANDLER_PRI_LAST + +EVENTHANDLER_DECLARE(shutdown_pre_sync, shutdown_fn); /* before fs sync */ +EVENTHANDLER_DECLARE(shutdown_post_sync, shutdown_fn); /* after fs sync */ +EVENTHANDLER_DECLARE(shutdown_final, shutdown_fn); + +/* Power state change events */ +typedef void (*power_change_fn)(void *); +EVENTHANDLER_DECLARE(power_resume, power_change_fn); +EVENTHANDLER_DECLARE(power_suspend, power_change_fn); +EVENTHANDLER_DECLARE(power_suspend_early, power_change_fn); + +/* Low memory event */ +typedef void (*vm_lowmem_handler_t)(void *, int); +#define LOWMEM_PRI_DEFAULT EVENTHANDLER_PRI_FIRST +EVENTHANDLER_DECLARE(vm_lowmem, vm_lowmem_handler_t); + +/* Root mounted event */ +typedef void (*mountroot_handler_t)(void *); +EVENTHANDLER_DECLARE(mountroot, mountroot_handler_t); + +/* File system mount events */ +struct mount; +struct vnode; +struct thread; +typedef void (*vfs_mounted_notify_fn)(void *, struct mount *, struct vnode *, + struct thread *); +typedef void (*vfs_unmounted_notify_fn)(void *, struct mount *, + struct thread *); +EVENTHANDLER_DECLARE(vfs_mounted, vfs_mounted_notify_fn); +EVENTHANDLER_DECLARE(vfs_unmounted, vfs_unmounted_notify_fn); + +/* + * Process events + * process_fork and exit handlers are called without Giant. + * exec handlers are called with Giant, but that is by accident. + */ +struct proc; +struct image_params; + +typedef void (*exitlist_fn)(void *, struct proc *); +typedef void (*forklist_fn)(void *, struct proc *, struct proc *, int); +typedef void (*execlist_fn)(void *, struct proc *, struct image_params *); +typedef void (*proc_ctor_fn)(void *, struct proc *); +typedef void (*proc_dtor_fn)(void *, struct proc *); +typedef void (*proc_init_fn)(void *, struct proc *); +typedef void (*proc_fini_fn)(void *, struct proc *); +EVENTHANDLER_DECLARE(process_ctor, proc_ctor_fn); +EVENTHANDLER_DECLARE(process_dtor, proc_dtor_fn); +EVENTHANDLER_DECLARE(process_init, proc_init_fn); +EVENTHANDLER_DECLARE(process_fini, proc_fini_fn); +EVENTHANDLER_DECLARE(process_exit, exitlist_fn); +EVENTHANDLER_DECLARE(process_fork, forklist_fn); +EVENTHANDLER_DECLARE(process_exec, execlist_fn); + +/* + * application dump event + */ +typedef void (*app_coredump_start_fn)(void *, struct thread *, char *name); +typedef void (*app_coredump_progress_fn)(void *, struct thread *td, int byte_count); +typedef void (*app_coredump_finish_fn)(void *, struct thread *td); +typedef void (*app_coredump_error_fn)(void *, struct thread *td, char *msg, ...); + +EVENTHANDLER_DECLARE(app_coredump_start, app_coredump_start_fn); +EVENTHANDLER_DECLARE(app_coredump_progress, app_coredump_progress_fn); +EVENTHANDLER_DECLARE(app_coredump_finish, app_coredump_finish_fn); +EVENTHANDLER_DECLARE(app_coredump_error, app_coredump_error_fn); + +typedef void (*thread_ctor_fn)(void *, struct thread *); +typedef void (*thread_dtor_fn)(void *, struct thread *); +typedef void (*thread_fini_fn)(void *, struct thread *); +typedef void (*thread_init_fn)(void *, struct thread *); +EVENTHANDLER_DECLARE(thread_ctor, thread_ctor_fn); +EVENTHANDLER_DECLARE(thread_dtor, thread_dtor_fn); +EVENTHANDLER_DECLARE(thread_init, thread_init_fn); +EVENTHANDLER_DECLARE(thread_fini, thread_fini_fn); + +typedef void (*uma_zone_chfn)(void *); +EVENTHANDLER_DECLARE(nmbclusters_change, uma_zone_chfn); +EVENTHANDLER_DECLARE(nmbufs_change, uma_zone_chfn); +EVENTHANDLER_DECLARE(maxsockets_change, uma_zone_chfn); + +/* Kernel linker file load and unload events */ +struct linker_file; +typedef void (*kld_load_fn)(void *, struct linker_file *); +typedef void (*kld_unload_fn)(void *, const char *, caddr_t, size_t); +typedef void (*kld_unload_try_fn)(void *, struct linker_file *, int *); +EVENTHANDLER_DECLARE(kld_load, kld_load_fn); +EVENTHANDLER_DECLARE(kld_unload, kld_unload_fn); +EVENTHANDLER_DECLARE(kld_unload_try, kld_unload_try_fn); + +/* Generic graphics framebuffer interface */ +struct fb_info; +typedef void (*register_framebuffer_fn)(void *, struct fb_info *); +typedef void (*unregister_framebuffer_fn)(void *, struct fb_info *); +EVENTHANDLER_DECLARE(register_framebuffer, register_framebuffer_fn); +EVENTHANDLER_DECLARE(unregister_framebuffer, unregister_framebuffer_fn); + +/* Veto ada attachment */ +struct cam_path; +struct ata_params; +typedef void (*ada_probe_veto_fn)(void *, struct cam_path *, + struct ata_params *, int *); +EVENTHANDLER_DECLARE(ada_probe_veto, ada_probe_veto_fn); + +/* Swap device events */ +struct swdevt; +typedef void (*swapon_fn)(void *, struct swdevt *); +typedef void (*swapoff_fn)(void *, struct swdevt *); +EVENTHANDLER_DECLARE(swapon, swapon_fn); +EVENTHANDLER_DECLARE(swapoff, swapoff_fn); + +/* newbus device events */ +enum evhdev_detach { + EVHDEV_DETACH_BEGIN, /* Before detach() is called */ + EVHDEV_DETACH_COMPLETE, /* After detach() returns 0 */ + EVHDEV_DETACH_FAILED /* After detach() returns err */ +}; +typedef void (*device_attach_fn)(void *, device_t); +typedef void (*device_detach_fn)(void *, device_t, enum evhdev_detach); +EVENTHANDLER_DECLARE(device_attach, device_attach_fn); +EVENTHANDLER_DECLARE(device_detach, device_detach_fn); + +/* Interface address addition and removal event */ +struct ifaddr; +typedef void (*rt_addrmsg_fn)(void *, struct ifaddr *, int); +EVENTHANDLER_DECLARE(rt_addrmsg, rt_addrmsg_fn); + +#endif /* _SYS_EVENTHANDLER_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/eventvar.h b/lib/libc/include/any-freebsd-any/sys/eventvar.h new file mode 100644 index 000000000000..1ed6e9fc4b6b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/eventvar.h @@ -0,0 +1,68 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999,2000 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_EVENTVAR_H_ +#define _SYS_EVENTVAR_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +#include + +#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */ +#define KQEXTENT 256 /* linear growth by this amount */ + +struct kqueue { + struct mtx kq_lock; + int kq_refcnt; + TAILQ_ENTRY(kqueue) kq_list; + TAILQ_HEAD(, knote) kq_head; /* list of pending event */ + int kq_count; /* number of pending events */ + struct selinfo kq_sel; + struct sigio *kq_sigio; + struct filedesc *kq_fdp; + int kq_state; +#define KQ_SEL 0x01 +#define KQ_SLEEP 0x02 +#define KQ_FLUXWAIT 0x04 /* waiting for a in flux kn */ +#define KQ_ASYNC 0x08 +#define KQ_CLOSING 0x10 +#define KQ_TASKSCHED 0x20 /* task scheduled */ +#define KQ_TASKDRAIN 0x40 /* waiting for task to drain */ + int kq_knlistsize; /* size of knlist */ + struct klist *kq_knlist; /* list of knotes */ + u_long kq_knhashmask; /* size of knhash */ + struct klist *kq_knhash; /* hash table for knotes */ + struct task kq_task; + struct ucred *kq_cred; +}; + +#endif /* !_SYS_EVENTVAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/exec.h b/lib/libc/include/any-freebsd-any/sys/exec.h new file mode 100644 index 000000000000..50b03963b175 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/exec.h @@ -0,0 +1,133 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)exec.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_EXEC_H_ +#define _SYS_EXEC_H_ + +/* + * Before ps_args existed, the following structure, found at the top of + * the user stack of each user process, was used by ps(1) to locate + * environment and argv strings. Normally ps_argvstr points to the + * argv vector, and ps_nargvstr is the same as the program's argc. The + * fields ps_envstr and ps_nenvstr are the equivalent for the environment. + * + * Programs should now use setproctitle(3) to change ps output. + * setproctitle() always informs the kernel with sysctl and sets the + * pointers in ps_strings. The kern.proc.args sysctl first tries p_args. + * If p_args is NULL, it then falls back to reading ps_strings and following + * the pointers. + */ +struct ps_strings { + char **ps_argvstr; /* first of 0 or more argument strings */ + unsigned int ps_nargvstr; /* the number of argument strings */ + char **ps_envstr; /* first of 0 or more environment strings */ + unsigned int ps_nenvstr; /* the number of environment strings */ +}; + +struct image_params; + +struct execsw { + int (*ex_imgact)(struct image_params *); + const char *ex_name; +}; + +#include + +#ifdef _KERNEL +#include + +/* + * Address of ps_strings structure (in user space). + * Prefer the kern.ps_strings or kern.proc.ps_strings sysctls to this constant. + */ +#define PS_STRINGS (USRSTACK - sizeof(struct ps_strings)) +#define SPARE_USRSPACE 4096 + +int exec_map_first_page(struct image_params *); +void exec_unmap_first_page(struct image_params *); + +int exec_register(const struct execsw *); +int exec_unregister(const struct execsw *); + +extern int coredump_pack_fileinfo; +extern int coredump_pack_vmmapinfo; + +/* + * note: name##_mod cannot be const storage because the + * linker_file_sysinit() function modifies _file in the + * moduledata_t. + */ + +#include + +#define EXEC_SET(name, execsw_arg) \ + static int __CONCAT(name,_modevent)(module_t mod, int type, \ + void *data) \ + { \ + struct execsw *exec = (struct execsw *)data; \ + int error = 0; \ + switch (type) { \ + case MOD_LOAD: \ + /* printf(#name " module loaded\n"); */ \ + error = exec_register(exec); \ + if (error) \ + printf(__XSTRING(name) "register failed\n"); \ + break; \ + case MOD_UNLOAD: \ + /* printf(#name " module unloaded\n"); */ \ + error = exec_unregister(exec); \ + if (error) \ + printf(__XSTRING(name) " unregister failed\n");\ + break; \ + default: \ + error = EOPNOTSUPP; \ + break; \ + } \ + return error; \ + } \ + static moduledata_t __CONCAT(name,_mod) = { \ + __XSTRING(name), \ + __CONCAT(name,_modevent), \ + (void *)& execsw_arg \ + }; \ + DECLARE_MODULE_TIED(name, __CONCAT(name,_mod), SI_SUB_EXEC, \ + SI_ORDER_ANY) +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/extattr.h b/lib/libc/include/any-freebsd-any/sys/extattr.h new file mode 100644 index 000000000000..f24995b80c54 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/extattr.h @@ -0,0 +1,107 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999-2001 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * Developed by the TrustedBSD Project. + * Support for extended filesystem attributes. + */ + +#ifndef _SYS_EXTATTR_H_ +#define _SYS_EXTATTR_H_ + +/* + * Defined name spaces for extended attributes. Numeric constants are passed + * via system calls, but a user-friendly string is also defined. + */ +#define EXTATTR_NAMESPACE_EMPTY 0x00000000 +#define EXTATTR_NAMESPACE_EMPTY_STRING "empty" +#define EXTATTR_NAMESPACE_USER 0x00000001 +#define EXTATTR_NAMESPACE_USER_STRING "user" +#define EXTATTR_NAMESPACE_SYSTEM 0x00000002 +#define EXTATTR_NAMESPACE_SYSTEM_STRING "system" + +/* + * The following macro is designed to initialize an array that maps + * extended-attribute namespace values to their names, e.g.: + * + * char *extattr_namespace_names[] = EXTATTR_NAMESPACE_NAMES; + */ +#define EXTATTR_NAMESPACE_NAMES { \ + EXTATTR_NAMESPACE_EMPTY_STRING, \ + EXTATTR_NAMESPACE_USER_STRING, \ + EXTATTR_NAMESPACE_SYSTEM_STRING } + +#define EXTATTR_MAXNAMELEN NAME_MAX + +#ifdef _KERNEL +#include + +struct thread; +struct ucred; +struct vnode; +int extattr_check_cred(struct vnode *vp, int attrnamespace, + struct ucred *cred, struct thread *td, accmode_t accmode); + +#else +#include + +struct iovec; + +__BEGIN_DECLS +int extattrctl(const char *_path, int _cmd, const char *_filename, + int _attrnamespace, const char *_attrname); +int extattr_delete_fd(int _fd, int _attrnamespace, const char *_attrname); +int extattr_delete_file(const char *_path, int _attrnamespace, + const char *_attrname); +int extattr_delete_link(const char *_path, int _attrnamespace, + const char *_attrname); +ssize_t extattr_get_fd(int _fd, int _attrnamespace, const char *_attrname, + void *_data, size_t _nbytes); +ssize_t extattr_get_file(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_get_link(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_list_fd(int _fd, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_file(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_link(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname, + const void *_data, size_t _nbytes); +ssize_t extattr_set_file(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); +ssize_t extattr_set_link(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); +__END_DECLS + +#endif /* !_KERNEL */ +#endif /* !_SYS_EXTATTR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/fail.h b/lib/libc/include/any-freebsd-any/sys/fail.h new file mode 100644 index 000000000000..b9a14e56281a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/fail.h @@ -0,0 +1,363 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 Isilon Inc http://www.isilon.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/** + * @file + * + * Main header for failpoint facility. + */ +#ifndef _SYS_FAIL_H_ +#define _SYS_FAIL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * Failpoint return codes, used internally. + * @ingroup failpoint_private + */ +enum fail_point_return_code { + FAIL_POINT_RC_CONTINUE = 0, /**< Continue with normal execution */ + FAIL_POINT_RC_RETURN, /**< FP evaluated to 'return' */ + FAIL_POINT_RC_QUEUED, /**< sleep_fn will be called */ +}; + +struct fail_point_entry; +struct fail_point_setting; + +/** + * Internal failpoint structure, tracking all the current details of the + * failpoint. This structure is the core component shared between the + * failure-injection code and the user-interface. + * @ingroup failpoint_private + */ +struct fail_point { + const char *fp_name; /* name of fail point */ + const char *fp_location; /* file:line of fail point */ + volatile int fp_ref_cnt; /** + * protects fp_setting: while holding + * a ref, fp_setting points to an + * unfreed fail_point_setting + */ + struct fail_point_setting * volatile fp_setting; + int fp_flags; + + /**< Function to call before sleep or pause */ + void (*fp_pre_sleep_fn)(void *); + /**< Arg for fp_pre_sleep_fn */ + void *fp_pre_sleep_arg; + + /**< Function to call after waking from sleep or pause */ + void (*fp_post_sleep_fn)(void *); + /**< Arg for fp_post_sleep_fn */ + void *fp_post_sleep_arg; +}; + +#define FAIL_POINT_DYNAMIC_NAME 0x01 /**< Must free name on destroy */ +/**< Use timeout path for sleep instead of msleep */ +#define FAIL_POINT_USE_TIMEOUT_PATH 0x02 +/**< If fail point is set to sleep, replace the sleep call with delay */ +#define FAIL_POINT_NONSLEEPABLE 0x04 + +#define FAIL_POINT_CV_DESC "fp cv no iterators" +#define FAIL_POINT_IS_OFF(fp) (__predict_true((fp)->fp_setting == NULL) || \ + __predict_true(fail_point_is_off(fp))) + +__BEGIN_DECLS + +/* Private failpoint eval function -- use fail_point_eval() instead. */ +enum fail_point_return_code fail_point_eval_nontrivial(struct fail_point *, + int *ret); + +/** + * @addtogroup failpoint + * @{ + */ +/* + * Initialize a fail-point. The name is formed in printf-like fashion + * from "fmt" and the subsequent arguments. + * Pair with fail_point_destroy(). + */ +void fail_point_init(struct fail_point *, const char *fmt, ...) + __printflike(2, 3); + +/* Return true iff this fail point is set to off, false otherwise */ +bool fail_point_is_off(struct fail_point *fp); + +/** + * Set the pre-sleep function for a fail point + * If fp_post_sleep_fn is specified, then FAIL_POINT_SLEEP will result in a + * (*fp->fp_pre_sleep_fn)(fp->fp_pre_sleep_arg) call by the thread. + */ +static inline void +fail_point_sleep_set_pre_func(struct fail_point *fp, void (*sleep_fn)(void *)) +{ + fp->fp_pre_sleep_fn = sleep_fn; +} + +static inline void +fail_point_sleep_set_pre_arg(struct fail_point *fp, void *sleep_arg) +{ + fp->fp_pre_sleep_arg = sleep_arg; +} + +/** + * Set the post-sleep function. This will be passed to timeout if we take + * the timeout path. This must be set if you sleep using the timeout path. + */ +static inline void +fail_point_sleep_set_post_func(struct fail_point *fp, void (*sleep_fn)(void *)) +{ + fp->fp_post_sleep_fn = sleep_fn; +} + +static inline void +fail_point_sleep_set_post_arg(struct fail_point *fp, void *sleep_arg) +{ + fp->fp_post_sleep_arg = sleep_arg; +} +/** + * If the FAIL_POINT_USE_TIMEOUT flag is set on a failpoint, then + * FAIL_POINT_SLEEP will result in a call to timeout instead of + * msleep. Note that if you sleep while this flag is set, you must + * set fp_post_sleep_fn or an error will occur upon waking. + */ +static inline void +fail_point_use_timeout_path(struct fail_point *fp, bool use_timeout, + void (*post_sleep_fn)(void *)) +{ + KASSERT(!use_timeout || post_sleep_fn != NULL || + (post_sleep_fn == NULL && fp->fp_post_sleep_fn != NULL), + ("Setting fp to use timeout, but not setting post_sleep_fn\n")); + + if (use_timeout) + fp->fp_flags |= FAIL_POINT_USE_TIMEOUT_PATH; + else + fp->fp_flags &= ~FAIL_POINT_USE_TIMEOUT_PATH; + + if (post_sleep_fn != NULL) + fp->fp_post_sleep_fn = post_sleep_fn; +} + +/** + * Free the resources used by a fail-point. Pair with fail_point_init(). + */ +void fail_point_destroy(struct fail_point *); + +/** + * Evaluate a failpoint. + */ +static inline enum fail_point_return_code +fail_point_eval(struct fail_point *fp, int *ret) +{ + if (__predict_true(fp->fp_setting == NULL)) + return (FAIL_POINT_RC_CONTINUE); + return (fail_point_eval_nontrivial(fp, ret)); +} + +__END_DECLS + +/* Declare a fail_point and its sysctl in a function. */ +#define _FAIL_POINT_NAME(name) _fail_point_##name +#define _FAIL_POINT_LOCATION() "(" __FILE__ ":" __XSTRING(__LINE__) ")" +#define _FAIL_POINT_INIT(parent, name, flags) \ + static struct fail_point _FAIL_POINT_NAME(name) = { \ + .fp_name = #name, \ + .fp_location = _FAIL_POINT_LOCATION(), \ + .fp_ref_cnt = 0, \ + .fp_setting = NULL, \ + .fp_flags = (flags), \ + .fp_pre_sleep_fn = NULL, \ + .fp_pre_sleep_arg = NULL, \ + .fp_post_sleep_fn = NULL, \ + .fp_post_sleep_arg = NULL, \ + }; \ + SYSCTL_OID(parent, OID_AUTO, name, \ + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, \ + &_FAIL_POINT_NAME(name), 0, fail_point_sysctl, \ + "A", ""); \ + SYSCTL_OID(parent, OID_AUTO, status_##name, \ + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, \ + &_FAIL_POINT_NAME(name), 0, \ + fail_point_sysctl_status, "A", ""); +#define _FAIL_POINT_EVAL(name, cond, code...) \ + int RETURN_VALUE; \ + \ + if (__predict_false(cond && \ + fail_point_eval(&_FAIL_POINT_NAME(name), &RETURN_VALUE))) { \ + \ + code; \ + \ + } + + +/** + * Instantiate a failpoint which returns "RETURN_VALUE" from the function + * when triggered. + * @param parent The parent sysctl under which to locate the fp's sysctl + * @param name The name of the failpoint in the sysctl tree (and printouts) + * @return Instantly returns the RETURN_VALUE specified in the + * failpoint, if triggered. + */ +#define KFAIL_POINT_RETURN(parent, name) \ + KFAIL_POINT_CODE(parent, name, return RETURN_VALUE) + +/** + * Instantiate a failpoint which returns (void) from the function when + * triggered. + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree (and printouts) + * @return Instantly returns void, if triggered in the failpoint. + */ +#define KFAIL_POINT_RETURN_VOID(parent, name) \ + KFAIL_POINT_CODE(parent, name, return) + +/** + * Instantiate a failpoint which sets an error when triggered. + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree (and + * printouts) + * @param error_var A variable to set to the failpoint's specified + * return-value when triggered + */ +#define KFAIL_POINT_ERROR(parent, name, error_var) \ + KFAIL_POINT_CODE(parent, name, (error_var) = RETURN_VALUE) + +/** + * Instantiate a failpoint which sets an error and then goes to a + * specified label in the function when triggered. + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree (and + * printouts) + * @param error_var A variable to set to the failpoint's specified + * return-value when triggered + * @param label The location to goto when triggered. + */ +#define KFAIL_POINT_GOTO(parent, name, error_var, label) \ + KFAIL_POINT_CODE(parent, name, (error_var) = RETURN_VALUE; goto label) + +/** + * Instantiate a failpoint which sets its pre- and post-sleep callback + * mechanisms. + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree (and + * printouts) + * @param pre_func Function pointer to the pre-sleep function, which will be + * called directly before going to sleep. + * @param pre_arg Argument to the pre-sleep function + * @param post_func Function pointer to the pot-sleep function, which will be + * called directly before going to sleep. + * @param post_arg Argument to the post-sleep function + */ +#define KFAIL_POINT_SLEEP_CALLBACKS(parent, name, pre_func, pre_arg, \ + post_func, post_arg) \ + KFAIL_POINT_CODE_SLEEP_CALLBACKS(parent, name, pre_func, \ + pre_arg, post_func, post_arg, return RETURN_VALUE) + +/** + * Instantiate a failpoint which runs arbitrary code when triggered, and sets + * its pre- and post-sleep callback mechanisms + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree (and + * printouts) + * @param pre_func Function pointer to the pre-sleep function, which will be + * called directly before going to sleep. + * @param pre_arg Argument to the pre-sleep function + * @param post_func Function pointer to the pot-sleep function, which will be + * called directly before going to sleep. + * @param post_arg Argument to the post-sleep function + * @param code The arbitrary code to run when triggered. Can reference + * "RETURN_VALUE" if desired to extract the specified + * user return-value when triggered. Note that this is + * implemented with a do-while loop so be careful of + * break and continue statements. + */ +#define KFAIL_POINT_CODE_SLEEP_CALLBACKS(parent, name, pre_func, pre_arg, \ + post_func, post_arg, code...) \ + do { \ + _FAIL_POINT_INIT(parent, name) \ + _FAIL_POINT_NAME(name).fp_pre_sleep_fn = pre_func; \ + _FAIL_POINT_NAME(name).fp_pre_sleep_arg = pre_arg; \ + _FAIL_POINT_NAME(name).fp_post_sleep_fn = post_func; \ + _FAIL_POINT_NAME(name).fp_post_sleep_arg = post_arg; \ + _FAIL_POINT_EVAL(name, true, code) \ + } while (0) + + +/** + * Instantiate a failpoint which runs arbitrary code when triggered. + * @param parent The parent sysctl under which to locate the sysctl + * @param name The name of the failpoint in the sysctl tree + * (and printouts) + * @param code The arbitrary code to run when triggered. Can reference + * "RETURN_VALUE" if desired to extract the specified + * user return-value when triggered. Note that this is + * implemented with a do-while loop so be careful of + * break and continue statements. + */ +#define KFAIL_POINT_CODE(parent, name, code...) \ + do { \ + _FAIL_POINT_INIT(parent, name, 0) \ + _FAIL_POINT_EVAL(name, true, code) \ + } while (0) + +#define KFAIL_POINT_CODE_FLAGS(parent, name, flags, code...) \ + do { \ + _FAIL_POINT_INIT(parent, name, flags) \ + _FAIL_POINT_EVAL(name, true, code) \ + } while (0) + +#define KFAIL_POINT_CODE_COND(parent, name, cond, flags, code...) \ + do { \ + _FAIL_POINT_INIT(parent, name, flags) \ + _FAIL_POINT_EVAL(name, cond, code) \ + } while (0) + +/** + * @} + * (end group failpoint) + */ + +#ifdef _KERNEL +int fail_point_sysctl(SYSCTL_HANDLER_ARGS); +int fail_point_sysctl_status(SYSCTL_HANDLER_ARGS); + +/* The fail point sysctl tree. */ +SYSCTL_DECL(_debug_fail_point); +#define DEBUG_FP _debug_fail_point +#endif + +#endif /* _SYS_FAIL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/fbio.h b/lib/libc/include/any-freebsd-any/sys/fbio.h new file mode 100644 index 000000000000..4cc0cc6debba --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/fbio.h @@ -0,0 +1,622 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software developed by the Computer Systems + * Engineering group at Lawrence Berkeley Laboratory under DARPA + * contract BG 91-66 and contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fbio.h 8.2 (Berkeley) 10/30/93 + * + * $FreeBSD$ + */ + +#ifndef _SYS_FBIO_H_ +#define _SYS_FBIO_H_ + +#ifndef _KERNEL +#include +#else +#include +#include +#include +#endif +#include + +/* + * Frame buffer ioctls (from Sprite, trimmed to essentials for X11). + */ + +/* + * Frame buffer type codes. + */ +#define FBTYPE_SUN1BW 0 /* multibus mono */ +#define FBTYPE_SUN1COLOR 1 /* multibus color */ +#define FBTYPE_SUN2BW 2 /* memory mono */ +#define FBTYPE_SUN2COLOR 3 /* color w/rasterop chips */ +#define FBTYPE_SUN2GP 4 /* GP1/GP2 */ +#define FBTYPE_SUN5COLOR 5 /* RoadRunner accelerator */ +#define FBTYPE_SUN3COLOR 6 /* memory color */ +#define FBTYPE_MEMCOLOR 7 /* memory 24-bit */ +#define FBTYPE_SUN4COLOR 8 /* memory color w/overlay */ + +#define FBTYPE_NOTSUN1 9 /* reserved for customer */ +#define FBTYPE_NOTSUN2 10 /* reserved for customer */ +#define FBTYPE_PCIMISC 11 /* (generic) PCI misc. disp. */ + +#define FBTYPE_SUNFAST_COLOR 12 /* accelerated 8bit */ +#define FBTYPE_SUNROP_COLOR 13 /* MEMCOLOR with rop h/w */ +#define FBTYPE_SUNFB_VIDEO 14 /* Simple video mixing */ +#define FBTYPE_RESERVED5 15 /* reserved, do not use */ +#define FBTYPE_RESERVED4 16 /* reserved, do not use */ +#define FBTYPE_SUNGP3 17 +#define FBTYPE_SUNGT 18 +#define FBTYPE_SUNLEO 19 /* zx Leo */ + +#define FBTYPE_MDA 20 +#define FBTYPE_HERCULES 21 +#define FBTYPE_CGA 22 +#define FBTYPE_EGA 23 +#define FBTYPE_VGA 24 +#define FBTYPE_TGA 26 +#define FBTYPE_TGA2 27 + +#define FBTYPE_MDICOLOR 28 /* cg14 */ +#define FBTYPE_TCXCOLOR 29 /* SUNW,tcx */ +#define FBTYPE_CREATOR 30 + +#define FBTYPE_LASTPLUSONE 31 /* max number of fbs (change as add) */ + +/* + * Frame buffer descriptor as returned by FBIOGTYPE. + */ +struct fbtype { + int fb_type; /* as defined above */ + int fb_height; /* in pixels */ + int fb_width; /* in pixels */ + int fb_depth; /* bits per pixel */ + int fb_cmsize; /* size of color map (entries) */ + int fb_size; /* total size in bytes */ +}; +#define FBIOGTYPE _IOR('F', 0, struct fbtype) + +#define FBTYPE_GET_STRIDE(_fb) ((_fb)->fb_size / (_fb)->fb_height) +#define FBTYPE_GET_BPP(_fb) ((_fb)->fb_bpp) +#define FBTYPE_GET_BYTESPP(_fb) ((_fb)->fb_bpp / 8) + +#ifdef _KERNEL + +struct fb_info; + +typedef int fb_enter_t(void *priv); +typedef int fb_leave_t(void *priv); +typedef int fb_setblankmode_t(void *priv, int mode); + +struct fb_info { + /* Raw copy of fbtype. Do not change. */ + int fb_type; /* as defined above */ + int fb_height; /* in pixels */ + int fb_width; /* in pixels */ + int fb_depth; /* bits to define color */ + int fb_cmsize; /* size of color map (entries) */ + int fb_size; /* total size in bytes */ + + struct cdev *fb_cdev; + + device_t fb_fbd_dev; /* "fbd" device. */ + device_t fb_video_dev; /* Video adapter. */ + + fb_enter_t *enter; + fb_leave_t *leave; + fb_setblankmode_t *setblankmode; + + uintptr_t fb_pbase; /* For FB mmap. */ + uintptr_t fb_vbase; /* if NULL, use fb_write/fb_read. */ + void *fb_priv; /* First argument for read/write. */ + const char *fb_name; + uint32_t fb_flags; +#define FB_FLAG_NOMMAP 1 /* mmap unsupported. */ +#define FB_FLAG_NOWRITE 2 /* disable writes for the time being */ +#define FB_FLAG_MEMATTR 4 /* override memattr for mmap */ + vm_memattr_t fb_memattr; + int fb_stride; + int fb_bpp; /* bits per pixel */ + uint32_t fb_cmap[16]; +}; + +int fbd_list(void); +int fbd_register(struct fb_info *); +int fbd_unregister(struct fb_info *); + +static inline int +register_framebuffer(struct fb_info *info) +{ + + EVENTHANDLER_INVOKE(register_framebuffer, info); + return (0); +} + +static inline int +unregister_framebuffer(struct fb_info *info) +{ + + EVENTHANDLER_INVOKE(unregister_framebuffer, info); + return (0); +} +#endif + +#ifdef notdef +/* + * General purpose structure for passing info in and out of frame buffers + * (used for gp1) -- unsupported. + */ +struct fbinfo { + int fb_physaddr; /* physical frame buffer address */ + int fb_hwwidth; /* fb board width */ + int fb_hwheight; /* fb board height */ + int fb_addrdelta; /* phys addr diff between boards */ + u_char *fb_ropaddr; /* fb virtual addr */ + int fb_unit; /* minor devnum of fb */ +}; +#define FBIOGINFO _IOR('F', 2, struct fbinfo) +#endif + +/* + * Color map I/O. + */ +struct fbcmap { + int index; /* first element (0 origin) */ + int count; /* number of elements */ + u_char *red; /* red color map elements */ + u_char *green; /* green color map elements */ + u_char *blue; /* blue color map elements */ +}; +#define FBIOPUTCMAP _IOW('F', 3, struct fbcmap) +#define FBIOGETCMAP _IOW('F', 4, struct fbcmap) + +/* + * Set/get attributes. + */ +#define FB_ATTR_NDEVSPECIFIC 8 /* no. of device specific values */ +#define FB_ATTR_NEMUTYPES 4 /* no. of emulation types */ + +struct fbsattr { + int flags; /* flags; see below */ + int emu_type; /* emulation type (-1 if unused) */ + int dev_specific[FB_ATTR_NDEVSPECIFIC]; /* catchall */ +}; +#define FB_ATTR_AUTOINIT 1 /* emulation auto init flag */ +#define FB_ATTR_DEVSPECIFIC 2 /* dev. specific stuff valid flag */ + +struct fbgattr { + int real_type; /* real device type */ + int owner; /* PID of owner, 0 if myself */ + struct fbtype fbtype; /* fbtype info for real device */ + struct fbsattr sattr; /* see above */ + int emu_types[FB_ATTR_NEMUTYPES]; /* possible emulations */ + /* (-1 if unused) */ +}; +#define FBIOSATTR _IOW('F', 5, struct fbsattr) +#define FBIOGATTR _IOR('F', 6, struct fbgattr) + +/* + * Video control. + */ +#define FBVIDEO_OFF 0 +#define FBVIDEO_ON 1 + +#define FBIOSVIDEO _IOW('F', 7, int) +#define FBIOGVIDEO _IOR('F', 8, int) + +/* vertical retrace */ +#define FBIOVERTICAL _IO('F', 9) + +/* + * Hardware cursor control (for, e.g., CG6). A rather complex and icky + * interface that smells like VMS, but there it is.... + */ +struct fbcurpos { + short x; + short y; +}; + +struct fbcursor { + short set; /* flags; see below */ + short enable; /* nonzero => cursor on, 0 => cursor off */ + struct fbcurpos pos; /* position on display */ + struct fbcurpos hot; /* hot-spot within cursor */ + struct fbcmap cmap; /* cursor color map */ + struct fbcurpos size; /* number of valid bits in image & mask */ + caddr_t image; /* cursor image bits */ + caddr_t mask; /* cursor mask bits */ +}; +#define FB_CUR_SETCUR 0x01 /* set on/off (i.e., obey fbcursor.enable) */ +#define FB_CUR_SETPOS 0x02 /* set position */ +#define FB_CUR_SETHOT 0x04 /* set hot-spot */ +#define FB_CUR_SETCMAP 0x08 /* set cursor color map */ +#define FB_CUR_SETSHAPE 0x10 /* set size & bits */ +#define FB_CUR_SETALL (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT | \ + FB_CUR_SETCMAP | FB_CUR_SETSHAPE) + +/* controls for cursor attributes & shape (including position) */ +#define FBIOSCURSOR _IOW('F', 24, struct fbcursor) +#define FBIOGCURSOR _IOWR('F', 25, struct fbcursor) + +/* controls for cursor position only */ +#define FBIOSCURPOS _IOW('F', 26, struct fbcurpos) +#define FBIOGCURPOS _IOW('F', 27, struct fbcurpos) + +/* get maximum cursor size */ +#define FBIOGCURMAX _IOR('F', 28, struct fbcurpos) + +/* + * Video board information + */ +struct brd_info { + u_short accessible_width; /* accessible bytes in scanline */ + u_short accessible_height; /* number of accessible scanlines */ + u_short line_bytes; /* number of bytes/scanline */ + u_short hdb_capable; /* can this thing hardware db? */ + u_short vmsize; /* video memory size */ + u_char boardrev; /* board revision # */ + u_char pad0; + u_long pad1; +}; +#define FBIOGXINFO _IOR('F', 39, struct brd_info) + +/* + * Monitor information + */ +struct mon_info { + u_long mon_type; /* bit array */ +#define MON_TYPE_STEREO 0x8 /* stereo display */ +#define MON_TYPE_0_OFFSET 0x4 /* black level 0 ire instead of 7.5 */ +#define MON_TYPE_OVERSCAN 0x2 /* overscan */ +#define MON_TYPE_GRAY 0x1 /* greyscale monitor */ + u_long pixfreq; /* pixel frequency in Hz */ + u_long hfreq; /* horizontal freq in Hz */ + u_long vfreq; /* vertical freq in Hz */ + u_long vsync; /* vertical sync in scanlines */ + u_long hsync; /* horizontal sync in pixels */ + /* these are in pixel units */ + u_short hfporch; /* horizontal front porch */ + u_short hbporch; /* horizontal back porch */ + u_short vfporch; /* vertical front porch */ + u_short vbporch; /* vertical back porch */ +}; +#define FBIOMONINFO _IOR('F', 40, struct mon_info) + +/* + * Color map I/O. + */ +struct fbcmap_i { + unsigned int flags; +#define FB_CMAP_BLOCK (1 << 0) /* wait for vertical refresh */ +#define FB_CMAP_KERNEL (1 << 1) /* called within kernel */ + int id; /* color map id */ + int index; /* first element (0 origin) */ + int count; /* number of elements */ + u_char *red; /* red color map elements */ + u_char *green; /* green color map elements */ + u_char *blue; /* blue color map elements */ +}; +#define FBIOPUTCMAPI _IOW('F', 41, struct fbcmap_i) +#define FBIOGETCMAPI _IOW('F', 42, struct fbcmap_i) + +/* The new style frame buffer ioctls. */ + +/* video mode information block */ +struct video_info { + int vi_mode; /* mode number, see below */ + int vi_flags; +#define V_INFO_COLOR (1 << 0) +#define V_INFO_GRAPHICS (1 << 1) +#define V_INFO_LINEAR (1 << 2) +#define V_INFO_VESA (1 << 3) +#define V_INFO_NONVGA (1 << 4) +#define V_INFO_CWIDTH9 (1 << 5) + int vi_width; + int vi_height; + int vi_cwidth; + int vi_cheight; + int vi_depth; + int vi_planes; + vm_offset_t vi_window; /* physical address */ + size_t vi_window_size; + size_t vi_window_gran; + vm_offset_t vi_buffer; /* physical address */ + size_t vi_buffer_size; + int vi_mem_model; +#define V_INFO_MM_OTHER (-1) +#define V_INFO_MM_TEXT 0 +#define V_INFO_MM_PLANAR 1 +#define V_INFO_MM_PACKED 2 +#define V_INFO_MM_DIRECT 3 +#define V_INFO_MM_CGA 100 +#define V_INFO_MM_HGC 101 +#define V_INFO_MM_VGAX 102 + /* for MM_PACKED and MM_DIRECT only */ + int vi_pixel_size; /* in bytes */ + /* for MM_DIRECT only */ + int vi_pixel_fields[4]; /* RGB and reserved fields */ + int vi_pixel_fsizes[4]; + /* reserved */ + u_char vi_reserved[64]; + vm_offset_t vi_registers; /* physical address */ + vm_offset_t vi_registers_size; +}; +typedef struct video_info video_info_t; + +/* adapter infromation block */ +struct video_adapter { + int va_index; + int va_type; +#define KD_OTHER 0 /* unknown */ +#define KD_MONO 1 /* monochrome adapter */ +#define KD_HERCULES 2 /* hercules adapter */ +#define KD_CGA 3 /* color graphics adapter */ +#define KD_EGA 4 /* enhanced graphics adapter */ +#define KD_VGA 5 /* video graphics adapter */ +#define KD_TGA 7 /* TGA */ +#define KD_TGA2 8 /* TGA2 */ + char *va_name; + int va_unit; + int va_minor; + int va_flags; +#define V_ADP_COLOR (1 << 0) +#define V_ADP_MODECHANGE (1 << 1) +#define V_ADP_STATESAVE (1 << 2) +#define V_ADP_STATELOAD (1 << 3) +#define V_ADP_FONT (1 << 4) +#define V_ADP_PALETTE (1 << 5) +#define V_ADP_BORDER (1 << 6) +#define V_ADP_VESA (1 << 7) +#define V_ADP_BOOTDISPLAY (1 << 8) +#define V_ADP_PROBED (1 << 16) +#define V_ADP_INITIALIZED (1 << 17) +#define V_ADP_REGISTERED (1 << 18) +#define V_ADP_ATTACHED (1 << 19) +#define V_ADP_DAC8 (1 << 20) +#define V_ADP_CWIDTH9 (1 << 21) + vm_offset_t va_io_base; + int va_io_size; + vm_offset_t va_crtc_addr; + vm_offset_t va_mem_base; + int va_mem_size; + vm_offset_t va_window; /* virtual address */ + size_t va_window_size; + size_t va_window_gran; + u_int va_window_orig; + vm_offset_t va_buffer; /* virtual address */ + size_t va_buffer_size; + int va_initial_mode; + int va_initial_bios_mode; + int va_mode; + struct video_info va_info; + int va_line_width; + struct { + int x; + int y; + } va_disp_start; + void *va_token; + int va_model; + int va_little_bitian; + int va_little_endian; + int va_buffer_alias; + vm_offset_t va_registers; /* virtual address */ + vm_offset_t va_registers_size; +}; +typedef struct video_adapter video_adapter_t; + +struct video_adapter_info { + int va_index; + int va_type; + char va_name[16]; + int va_unit; + int va_flags; + vm_offset_t va_io_base; + int va_io_size; + vm_offset_t va_crtc_addr; + vm_offset_t va_mem_base; + int va_mem_size; + vm_offset_t va_window; /* virtual address */ + size_t va_window_size; + size_t va_window_gran; + vm_offset_t va_unused0; + size_t va_buffer_size; + int va_initial_mode; + int va_initial_bios_mode; + int va_mode; + int va_line_width; + struct { + int x; + int y; + } va_disp_start; + u_int va_window_orig; + /* reserved */ + u_char va_reserved[64]; +}; +typedef struct video_adapter_info video_adapter_info_t; + +/* some useful video adapter index */ +#define V_ADP_PRIMARY 0 +#define V_ADP_SECONDARY 1 + +/* video mode numbers */ + +#define M_B40x25 0 /* black & white 40 columns */ +#define M_C40x25 1 /* color 40 columns */ +#define M_B80x25 2 /* black & white 80 columns */ +#define M_C80x25 3 /* color 80 columns */ +#define M_BG320 4 /* black & white graphics 320x200 */ +#define M_CG320 5 /* color graphics 320x200 */ +#define M_BG640 6 /* black & white graphics 640x200 hi-res */ +#define M_EGAMONO80x25 7 /* ega-mono 80x25 */ +#define M_CG320_D 13 /* ega mode D */ +#define M_CG640_E 14 /* ega mode E */ +#define M_EGAMONOAPA 15 /* ega mode F */ +#define M_CG640x350 16 /* ega mode 10 */ +#define M_ENHMONOAPA2 17 /* ega mode F with extended memory */ +#define M_ENH_CG640 18 /* ega mode 10* */ +#define M_ENH_B40x25 19 /* ega enhanced black & white 40 columns */ +#define M_ENH_C40x25 20 /* ega enhanced color 40 columns */ +#define M_ENH_B80x25 21 /* ega enhanced black & white 80 columns */ +#define M_ENH_C80x25 22 /* ega enhanced color 80 columns */ +#define M_VGA_C40x25 23 /* vga 8x16 font on color */ +#define M_VGA_C80x25 24 /* vga 8x16 font on color */ +#define M_VGA_M80x25 25 /* vga 8x16 font on mono */ + +#define M_VGA11 26 /* vga 640x480 2 colors */ +#define M_BG640x480 26 +#define M_VGA12 27 /* vga 640x480 16 colors */ +#define M_CG640x480 27 +#define M_VGA13 28 /* vga 320x200 256 colors */ +#define M_VGA_CG320 28 + +#define M_VGA_C80x50 30 /* vga 8x8 font on color */ +#define M_VGA_M80x50 31 /* vga 8x8 font on color */ +#define M_VGA_C80x30 32 /* vga 8x16 font on color */ +#define M_VGA_M80x30 33 /* vga 8x16 font on color */ +#define M_VGA_C80x60 34 /* vga 8x8 font on color */ +#define M_VGA_M80x60 35 /* vga 8x8 font on color */ +#define M_VGA_CG640 36 /* vga 640x400 256 color */ +#define M_VGA_MODEX 37 /* vga 320x240 256 color */ + +#define M_VGA_C90x25 40 /* vga 8x16 font on color */ +#define M_VGA_M90x25 41 /* vga 8x16 font on mono */ +#define M_VGA_C90x30 42 /* vga 8x16 font on color */ +#define M_VGA_M90x30 43 /* vga 8x16 font on mono */ +#define M_VGA_C90x43 44 /* vga 8x8 font on color */ +#define M_VGA_M90x43 45 /* vga 8x8 font on mono */ +#define M_VGA_C90x50 46 /* vga 8x8 font on color */ +#define M_VGA_M90x50 47 /* vga 8x8 font on mono */ +#define M_VGA_C90x60 48 /* vga 8x8 font on color */ +#define M_VGA_M90x60 49 /* vga 8x8 font on mono */ + +#define M_ENH_B80x43 0x70 /* ega black & white 80x43 */ +#define M_ENH_C80x43 0x71 /* ega color 80x43 */ + +#define M_HGC_P0 0xe0 /* hercules graphics - page 0 @ B0000 */ +#define M_HGC_P1 0xe1 /* hercules graphics - page 1 @ B8000 */ +#define M_MCA_MODE 0xff /* monochrome adapter mode */ + +#define M_TEXT_80x25 200 /* generic text modes */ +#define M_TEXT_80x30 201 +#define M_TEXT_80x43 202 +#define M_TEXT_80x50 203 +#define M_TEXT_80x60 204 +#define M_TEXT_132x25 205 +#define M_TEXT_132x30 206 +#define M_TEXT_132x43 207 +#define M_TEXT_132x50 208 +#define M_TEXT_132x60 209 + +#define M_VESA_BASE 0x100 /* VESA mode number base */ +#define M_VESA_CG640x400 0x100 /* 640x400, 256 color */ +#define M_VESA_CG640x480 0x101 /* 640x480, 256 color */ +#define M_VESA_800x600 0x102 /* 800x600, 16 color */ +#define M_VESA_CG800x600 0x103 /* 800x600, 256 color */ +#define M_VESA_1024x768 0x104 /* 1024x768, 16 color */ +#define M_VESA_CG1024x768 0x105 /* 1024x768, 256 color */ +#define M_VESA_1280x1024 0x106 /* 1280x1024, 16 color */ +#define M_VESA_CG1280x1024 0x107 /* 1280x1024, 256 color */ +#define M_VESA_C80x60 0x108 /* 8x8 font */ +#define M_VESA_C132x25 0x109 /* 8x16 font */ +#define M_VESA_C132x43 0x10a /* 8x14 font */ +#define M_VESA_C132x50 0x10b /* 8x8 font */ +#define M_VESA_C132x60 0x10c /* 8x8 font */ +#define M_VESA_32K_320 0x10d /* 320x200, 5:5:5 */ +#define M_VESA_64K_320 0x10e /* 320x200, 5:6:5 */ +#define M_VESA_FULL_320 0x10f /* 320x200, 8:8:8 */ +#define M_VESA_32K_640 0x110 /* 640x480, 5:5:5 */ +#define M_VESA_64K_640 0x111 /* 640x480, 5:6:5 */ +#define M_VESA_FULL_640 0x112 /* 640x480, 8:8:8 */ +#define M_VESA_32K_800 0x113 /* 800x600, 5:5:5 */ +#define M_VESA_64K_800 0x114 /* 800x600, 5:6:5 */ +#define M_VESA_FULL_800 0x115 /* 800x600, 8:8:8 */ +#define M_VESA_32K_1024 0x116 /* 1024x768, 5:5:5 */ +#define M_VESA_64K_1024 0x117 /* 1024x768, 5:6:5 */ +#define M_VESA_FULL_1024 0x118 /* 1024x768, 8:8:8 */ +#define M_VESA_32K_1280 0x119 /* 1280x1024, 5:5:5 */ +#define M_VESA_64K_1280 0x11a /* 1280x1024, 5:6:5 */ +#define M_VESA_FULL_1280 0x11b /* 1280x1024, 8:8:8 */ +#define M_VESA_MODE_MAX 0x1ff + +struct video_display_start { + int x; + int y; +}; +typedef struct video_display_start video_display_start_t; + +struct video_color_palette { + int index; /* first element (zero-based) */ + int count; /* number of elements */ + u_char *red; /* red */ + u_char *green; /* green */ + u_char *blue; /* blue */ + u_char *transparent; /* may be NULL */ +}; +typedef struct video_color_palette video_color_palette_t; + +/* adapter info. */ +#define FBIO_ADAPTER _IOR('F', 100, int) +#define FBIO_ADPTYPE _IOR('F', 101, int) +#define FBIO_ADPINFO _IOR('F', 102, struct video_adapter_info) + +/* video mode control */ +#define FBIO_MODEINFO _IOWR('F', 103, struct video_info) +#define FBIO_FINDMODE _IOWR('F', 104, struct video_info) +#define FBIO_GETMODE _IOR('F', 105, int) +#define FBIO_SETMODE _IOW('F', 106, int) + +/* get/set frame buffer window origin */ +#define FBIO_GETWINORG _IOR('F', 107, u_int) +#define FBIO_SETWINORG _IOW('F', 108, u_int) + +/* get/set display start address */ +#define FBIO_GETDISPSTART _IOR('F', 109, video_display_start_t) +#define FBIO_SETDISPSTART _IOW('F', 110, video_display_start_t) + +/* get/set scan line width */ +#define FBIO_GETLINEWIDTH _IOR('F', 111, u_int) +#define FBIO_SETLINEWIDTH _IOW('F', 112, u_int) + +/* color palette control */ +#define FBIO_GETPALETTE _IOW('F', 113, video_color_palette_t) +#define FBIO_SETPALETTE _IOW('F', 114, video_color_palette_t) + +/* blank display */ +#define V_DISPLAY_ON 0 +#define V_DISPLAY_BLANK 1 +#define V_DISPLAY_STAND_BY 2 +#define V_DISPLAY_SUSPEND 3 + +#define FBIO_BLANK _IOW('F', 115, int) + +#endif /* !_SYS_FBIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/fcntl.h b/lib/libc/include/any-freebsd-any/sys/fcntl.h new file mode 100644 index 000000000000..08fe782974c0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/fcntl.h @@ -0,0 +1,336 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for ; it also includes + * related kernel definitions. + */ + +#include +#include + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + +/* + * Kernel encoding of open mode; separate read and write bits that are + * independently testable: 1 greater than the above. + * + * XXX + * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH, + * which was documented to use FREAD/FWRITE, continues to work. + */ +#if __BSD_VISIBLE +#define FREAD 0x0001 +#define FWRITE 0x0002 +#endif +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#if __BSD_VISIBLE +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* synchronous writes */ +#endif +#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */ +#if __POSIX_VISIBLE >= 200809 +#define O_NOFOLLOW 0x0100 /* don't follow symlinks */ +#endif +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ +#ifdef _KERNEL +#define FHASLOCK 0x4000 /* descriptor holds advisory lock */ +#endif + +/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */ +#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ + +#if __BSD_VISIBLE +/* Attempt to bypass buffer cache */ +#define O_DIRECT 0x00010000 +#endif + +#if __POSIX_VISIBLE >= 200809 +#define O_DIRECTORY 0x00020000 /* Fail if not directory */ +#define O_EXEC 0x00040000 /* Open for execute only */ +#define O_SEARCH O_EXEC +#endif +#ifdef _KERNEL +#define FEXEC O_EXEC +#define FSEARCH O_SEARCH +#endif + +#if __POSIX_VISIBLE >= 200809 +/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */ +#define O_TTY_INIT 0x00080000 /* Restore default termios attributes */ + +#define O_CLOEXEC 0x00100000 +#endif + +#if __BSD_VISIBLE +#define O_VERIFY 0x00200000 /* open only after verification */ +#endif + +/* + * XXX missing O_DSYNC, O_RSYNC. + */ + +#ifdef _KERNEL + +/* Only for devfs d_close() flags. */ +#define FLASTCLOSE O_DIRECTORY +#define FREVOKE O_VERIFY +/* Only for fo_close() from half-succeeded open */ +#define FOPENFAILED O_TTY_INIT + +/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ +#define FFLAGS(oflags) ((oflags) & O_EXEC ? (oflags) : (oflags) + 1) +#define OFLAGS(fflags) ((fflags) & O_EXEC ? (fflags) : (fflags) - 1) + +/* bits to save after open */ +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT|FEXEC) +/* bits settable by fcntl(F_SETFL, ...) */ +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FRDAHEAD|O_DIRECT) + +#if defined(COMPAT_FREEBSD7) || defined(COMPAT_FREEBSD6) || \ + defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) +/* + * Set by shm_open(3) in older libc's to get automatic MAP_ASYNC + * behavior for POSIX shared memory objects (which are otherwise + * implemented as plain files). + */ +#define FPOSIXSHM O_NOFOLLOW +#undef FCNTLFLAGS +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|FRDAHEAD| \ + O_DIRECT) +#endif +#endif + +/* + * The O_* flags used to have only F* names, which were used in the kernel + * and by fcntl. We retain the F* names for the kernel f_flag field + * and for backward compatibility for fcntl. These flags are deprecated. + */ +#if __BSD_VISIBLE +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_FSYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#endif + +/* + * We are out of bits in f_flag (which is a short). However, + * the flag bits not set in FMASK are only meaningful in the + * initial open syscall. Those bits can thus be given a + * different meaning for fcntl(2). + */ +#if __BSD_VISIBLE +/* Read ahead */ +#define FRDAHEAD O_CREAT +#endif + +#if __POSIX_VISIBLE >= 200809 +/* + * Magic value that specify the use of the current working directory + * to determine the target of relative file paths in the openat() and + * similar syscalls. + */ +#define AT_FDCWD -100 + +/* + * Miscellaneous flags for the *at() syscalls. + */ +#define AT_EACCESS 0x100 /* Check access using effective user and group ID */ +#define AT_SYMLINK_NOFOLLOW 0x200 /* Do not follow symbolic links */ +#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic link */ +#define AT_REMOVEDIR 0x800 /* Remove directory instead of file */ +#endif + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#endif +#if __BSD_VISIBLE +#define F_OGETLK 7 /* get record locking information */ +#define F_OSETLK 8 /* set record locking information */ +#define F_OSETLKW 9 /* F_SETLK; wait if blocked */ +#define F_DUP2FD 10 /* duplicate file descriptor to arg */ +#endif +#define F_GETLK 11 /* get record locking information */ +#define F_SETLK 12 /* set record locking information */ +#define F_SETLKW 13 /* F_SETLK; wait if blocked */ +#if __BSD_VISIBLE +#define F_SETLK_REMOTE 14 /* debugging support for remote locks */ +#define F_READAHEAD 15 /* read ahead */ +#define F_RDAHEAD 16 /* Darwin compatible read ahead */ +#endif +#if __POSIX_VISIBLE >= 200809 +#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */ +#endif +#if __BSD_VISIBLE +#define F_DUP2FD_CLOEXEC 18 /* Like F_DUP2FD, but FD_CLOEXEC is set */ +#endif + +/* file descriptor flags (F_GETFD, F_SETFD) */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ +#if __BSD_VISIBLE +#define F_UNLCKSYS 4 /* purge locks for a given system ID */ +#define F_CANCEL 5 /* cancel an async lock request */ +#endif +#ifdef _KERNEL +#define F_WAIT 0x010 /* Wait until lock is granted */ +#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ +#define F_POSIX 0x040 /* Use POSIX semantics for lock */ +#define F_REMOTE 0x080 /* Lock owner is remote NFS client */ +#define F_NOINTR 0x100 /* Ignore signals when waiting */ +#endif + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ + int l_sysid; /* remote system id or zero for local */ +}; + +#if __BSD_VISIBLE +/* + * Old advisory file segment locking data type, + * before adding l_sysid. + */ +struct __oflock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; +#endif + +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + +#if __POSIX_VISIBLE >= 200112 +/* + * Advice to posix_fadvise + */ +#define POSIX_FADV_NORMAL 0 /* no special treatment */ +#define POSIX_FADV_RANDOM 1 /* expect random page references */ +#define POSIX_FADV_SEQUENTIAL 2 /* expect sequential page references */ +#define POSIX_FADV_WILLNEED 3 /* will need these pages */ +#define POSIX_FADV_DONTNEED 4 /* dont need these pages */ +#define POSIX_FADV_NOREUSE 5 /* access data only once */ +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if __BSD_VISIBLE +int flock(int, int); +#endif +#if __POSIX_VISIBLE >= 200809 +int openat(int, const char *, int, ...); +#endif +#if __POSIX_VISIBLE >= 200112 +int posix_fadvise(int, off_t, off_t, int); +int posix_fallocate(int, off_t, off_t); +#endif +__END_DECLS +#endif + +#endif /* !_SYS_FCNTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/fdcio.h b/lib/libc/include/any-freebsd-any/sys/fdcio.h new file mode 100644 index 000000000000..f041a6a8a8e3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/fdcio.h @@ -0,0 +1,197 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#ifndef _KERNEL +#include +#endif +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* FDC_???KBPS */ + + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependent since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.secshift +# define fd_formb_nsecs format_info.nsecs +# define fd_formb_gaplen format_info.gaplen +# define fd_formb_fillbyte format_info.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.idfields[i].cylno +# define fd_formb_headno(i) format_info.idfields[i].headno +# define fd_formb_secno(i) format_info.idfields[i].secno +# define fd_formb_secsize(i) format_info.idfields[i].secsize + +struct fd_type { + int sectrac; /* sectors per track */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int gap; /* gap len between sectors */ + int tracks; /* total number of cylinders */ + int size; /* size of disk in sectors */ + int trans; /* transfer speed code */ + int heads; /* number of heads */ + int f_gap; /* format gap len */ + int f_inter; /* format interleave factor */ + int offset_side2; /* offset of sectors on side2 */ + int flags; /* misc. features */ +#define FL_MFM 0x0001 /* MFM recording */ +#define FL_2STEP 0x0002 /* 2 steps between cylinders */ +#define FL_PERPND 0x0004 /* perpendicular recording */ +#define FL_AUTO 0x0008 /* autodetect format */ +}; + +struct fdc_status { + u_int status[7]; +}; + +/* + * cyl and head are being passed into ioctl(FD_READID) + * all four fields are being returned + */ +struct fdc_readid { + u_char cyl; /* C - 0...79 */ + u_char head; /* H - 0...1 */ + u_char sec; /* R - 1...n */ + u_char secshift; /* N - log2(secsize / 128) */ +}; + +/* + * Diskette drive type, basically the same as stored in RTC on ISA + * machines (see /sys/isa/rtc.h), but right-shifted by four bits. + */ +enum fd_drivetype { + FDT_NONE, FDT_360K, FDT_12M, FDT_720K, FDT_144M, FDT_288M_1, + FDT_288M +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FD_CLRERR _IO('F', 67) /* clear error counter */ + +#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */ + +/* + * Obtain NE765 status registers. Only successful if there is + * a valid status stored in fdc->status[]. + */ +#define FD_GSTAT _IOR('F', 69, struct fdc_status) + +#define FD_GDTYPE _IOR('F', 70, enum fd_drivetype) /* obtain drive type */ + +/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */ +#define FDOPT_NORETRY 0x0001 /* no retries on failure */ +#define FDOPT_NOERRLOG 0x002 /* no "hard error" kernel log messages */ +#define FDOPT_NOERROR 0x0004 /* do not indicate errors, caller will use + FD_GSTAT in order to obtain status */ + +/* + * Transfer rate definitions. Used in the structures above. They + * represent the hardware encoding of bits 0 and 1 of the FDC control + * register when writing to the register. + * Transfer rates for FM encoding are half the values listed here + * (but we currently don't support FM encoding). + */ +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_1MBPS 0x03 /* 1MPBS MFM drive transfer rate */ + +/* + * Parameters for common formats + * + * See struct fd_type for layout. + * XXX: Field 'size' must be calculated. + * XXX: Fields 'f_inter' and 'offset_side2' are unused by kernel. + * + * XXX: These should really go in a /etc/floppycap colon separated file + * XXX: but the kernel needs some of them for proper defaults and it would + * XXX: should have been done 20 years ago to make sense. + */ +#define FDF_3_2880 36,2,0xFF,0x1B,80,0,FDC_1MBPS,002,0x4C,1,1,FL_MFM|FL_PERPND +#define FDF_3_1722 21,2,0xFF,0x04,82,0,FDC_500KBPS,2,0x0C,2,0,FL_MFM +#define FDF_3_1476 18,2,0xFF,0x1B,82,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM +#define FDF_3_1440 18,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM +#define FDF_3_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM +#define FDF_3_820 10,2,0xFF,0x10,82,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM +#define FDF_3_800 10,2,0xFF,0x10,80,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM +#define FDF_3_720 9,2,0xFF,0x20,80,0,FDC_250KBPS,2,0x50,1,0,FL_MFM +#define FDF_5_1480 18,2,0xFF,0x02,82,0,FDC_500KBPS,2,0x02,2,0,FL_MFM +#define FDF_5_1440 18,2,0xFF,0x02,80,0,FDC_500KBPS,2,0x02,2,0,FL_MFM +#define FDF_5_1230 8,3,0xFF,0x35,77,0,FDC_500KBPS,2,0x74,1,0,FL_MFM +#define FDF_5_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM +#define FDF_5_820 10,2,0xFF,0x10,82,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM +#define FDF_5_800 10,2,0xFF,0x10,80,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM +#define FDF_5_720 9,2,0xFF,0x20,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM +#define FDF_5_640 8,2,0xFF,0x2A,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM +#define FDF_5_400 10,2,0xFF,0x10,80,0,FDC_300KBPS,1,0x2e,1,0,FL_MFM /* RX50 */ +#define FDF_5_360 9,2,0xFF,0x23,40,0,FDC_300KBPS,2,0x50,1,0,FL_MFM +/* XXX: 0x2a ? */ + +#endif /* !_MACHINE_IOCTL_FD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/file.h b/lib/libc/include/any-freebsd-any/sys/file.h new file mode 100644 index 000000000000..d17b9db27561 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/file.h @@ -0,0 +1,431 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)file.h 8.3 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_FILE_H_ +#define _SYS_FILE_H_ + +#ifndef _KERNEL +#include /* XXX */ +#include +#include +#else +#include +#include +#include +#include +#include + +struct filedesc; +struct stat; +struct thread; +struct uio; +struct knote; +struct vnode; + +#endif /* _KERNEL */ + +#define DTYPE_NONE 0 /* not yet initialized */ +#define DTYPE_VNODE 1 /* file */ +#define DTYPE_SOCKET 2 /* communications endpoint */ +#define DTYPE_PIPE 3 /* pipe */ +#define DTYPE_FIFO 4 /* fifo (named pipe) */ +#define DTYPE_KQUEUE 5 /* event queue */ +#define DTYPE_CRYPTO 6 /* crypto */ +#define DTYPE_MQUEUE 7 /* posix message queue */ +#define DTYPE_SHM 8 /* swap-backed shared memory */ +#define DTYPE_SEM 9 /* posix semaphore */ +#define DTYPE_PTS 10 /* pseudo teletype master device */ +#define DTYPE_DEV 11 /* Device specific fd type */ +#define DTYPE_PROCDESC 12 /* process descriptor */ +#define DTYPE_LINUXEFD 13 /* emulation eventfd type */ +#define DTYPE_LINUXTFD 14 /* emulation timerfd type */ + +#ifdef _KERNEL + +struct file; +struct filecaps; +struct kaiocb; +struct kinfo_file; +struct ucred; + +#define FOF_OFFSET 0x01 /* Use the offset in uio argument */ +#define FOF_NOLOCK 0x02 /* Do not take FOFFSET_LOCK */ +#define FOF_NEXTOFF 0x04 /* Also update f_nextoff */ +#define FOF_NOUPDATE 0x10 /* Do not update f_offset */ +off_t foffset_lock(struct file *fp, int flags); +void foffset_lock_uio(struct file *fp, struct uio *uio, int flags); +void foffset_unlock(struct file *fp, off_t val, int flags); +void foffset_unlock_uio(struct file *fp, struct uio *uio, int flags); + +static inline off_t +foffset_get(struct file *fp) +{ + + return (foffset_lock(fp, FOF_NOLOCK)); +} + +typedef int fo_rdwr_t(struct file *fp, struct uio *uio, + struct ucred *active_cred, int flags, + struct thread *td); +typedef int fo_truncate_t(struct file *fp, off_t length, + struct ucred *active_cred, struct thread *td); +typedef int fo_ioctl_t(struct file *fp, u_long com, void *data, + struct ucred *active_cred, struct thread *td); +typedef int fo_poll_t(struct file *fp, int events, + struct ucred *active_cred, struct thread *td); +typedef int fo_kqfilter_t(struct file *fp, struct knote *kn); +typedef int fo_stat_t(struct file *fp, struct stat *sb, + struct ucred *active_cred, struct thread *td); +typedef int fo_close_t(struct file *fp, struct thread *td); +typedef int fo_chmod_t(struct file *fp, mode_t mode, + struct ucred *active_cred, struct thread *td); +typedef int fo_chown_t(struct file *fp, uid_t uid, gid_t gid, + struct ucred *active_cred, struct thread *td); +typedef int fo_sendfile_t(struct file *fp, int sockfd, struct uio *hdr_uio, + struct uio *trl_uio, off_t offset, size_t nbytes, + off_t *sent, int flags, struct thread *td); +typedef int fo_seek_t(struct file *fp, off_t offset, int whence, + struct thread *td); +typedef int fo_fill_kinfo_t(struct file *fp, struct kinfo_file *kif, + struct filedesc *fdp); +typedef int fo_mmap_t(struct file *fp, vm_map_t map, vm_offset_t *addr, + vm_size_t size, vm_prot_t prot, vm_prot_t cap_maxprot, + int flags, vm_ooffset_t foff, struct thread *td); +typedef int fo_aio_queue_t(struct file *fp, struct kaiocb *job); +typedef int fo_flags_t; + +struct fileops { + fo_rdwr_t *fo_read; + fo_rdwr_t *fo_write; + fo_truncate_t *fo_truncate; + fo_ioctl_t *fo_ioctl; + fo_poll_t *fo_poll; + fo_kqfilter_t *fo_kqfilter; + fo_stat_t *fo_stat; + fo_close_t *fo_close; + fo_chmod_t *fo_chmod; + fo_chown_t *fo_chown; + fo_sendfile_t *fo_sendfile; + fo_seek_t *fo_seek; + fo_fill_kinfo_t *fo_fill_kinfo; + fo_mmap_t *fo_mmap; + fo_aio_queue_t *fo_aio_queue; + fo_flags_t fo_flags; /* DFLAG_* below */ +}; + +#define DFLAG_PASSABLE 0x01 /* may be passed via unix sockets. */ +#define DFLAG_SEEKABLE 0x02 /* seekable / nonsequential */ +#endif /* _KERNEL */ + +#if defined(_KERNEL) || defined(_WANT_FILE) +/* + * Kernel descriptor table. + * One entry for each open kernel vnode and socket. + * + * Below is the list of locks that protects members in struct file. + * + * (a) f_vnode lock required (shared allows both reads and writes) + * (f) protected with mtx_lock(mtx_pool_find(fp)) + * (d) cdevpriv_mtx + * none not locked + */ + +struct fadvise_info { + int fa_advice; /* (f) FADV_* type. */ + off_t fa_start; /* (f) Region start. */ + off_t fa_end; /* (f) Region end. */ +}; + +struct file { + void *f_data; /* file descriptor specific data */ + struct fileops *f_ops; /* File operations */ + struct ucred *f_cred; /* associated credentials. */ + struct vnode *f_vnode; /* NULL or applicable vnode */ + short f_type; /* descriptor type */ + short f_vnread_flags; /* (f) Sleep lock for f_offset */ + volatile u_int f_flag; /* see fcntl.h */ + volatile u_int f_count; /* reference count */ + /* + * DTYPE_VNODE specific fields. + */ + union { + int16_t f_seqcount; /* (a) Count of sequential accesses. */ + int f_pipegen; + }; + off_t f_nextoff; /* next expected read/write offset. */ + union { + struct cdev_privdata *fvn_cdevpriv; + /* (d) Private data for the cdev. */ + struct fadvise_info *fvn_advice; + } f_vnun; + /* + * DFLAG_SEEKABLE specific fields + */ + off_t f_offset; + /* + * Mandatory Access control information. + */ + void *f_label; /* Place-holder for MAC label. */ +}; + +#define f_cdevpriv f_vnun.fvn_cdevpriv +#define f_advice f_vnun.fvn_advice + +#define FOFFSET_LOCKED 0x1 +#define FOFFSET_LOCK_WAITING 0x2 +#define FDEVFS_VNODE 0x4 + +#endif /* _KERNEL || _WANT_FILE */ + +/* + * Userland version of struct file, for sysctl + */ +struct xfile { + ksize_t xf_size; /* size of struct xfile */ + pid_t xf_pid; /* owning process */ + uid_t xf_uid; /* effective uid of owning process */ + int xf_fd; /* descriptor number */ + int _xf_int_pad1; + kvaddr_t xf_file; /* address of struct file */ + short xf_type; /* descriptor type */ + short _xf_short_pad1; + int xf_count; /* reference count */ + int xf_msgcount; /* references from message queue */ + int _xf_int_pad2; + off_t xf_offset; /* file offset */ + kvaddr_t xf_data; /* file descriptor specific data */ + kvaddr_t xf_vnode; /* vnode pointer */ + u_int xf_flag; /* flags (see fcntl.h) */ + int _xf_int_pad3; + int64_t _xf_int64_pad[6]; +}; + +#ifdef _KERNEL + +extern struct fileops vnops; +extern struct fileops badfileops; +extern struct fileops socketops; +extern int maxfiles; /* kernel limit on number of open files */ +extern int maxfilesperproc; /* per process limit on number of open files */ +extern volatile int openfiles; /* actual number of open files */ + +int fget(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp); +int fget_mmap(struct thread *td, int fd, cap_rights_t *rightsp, + vm_prot_t *maxprotp, struct file **fpp); +int fget_read(struct thread *td, int fd, cap_rights_t *rightsp, + struct file **fpp); +int fget_write(struct thread *td, int fd, cap_rights_t *rightsp, + struct file **fpp); +int fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp, + int needfcntl, struct file **fpp); +int _fdrop(struct file *fp, struct thread *td); + +fo_rdwr_t invfo_rdwr; +fo_truncate_t invfo_truncate; +fo_ioctl_t invfo_ioctl; +fo_poll_t invfo_poll; +fo_kqfilter_t invfo_kqfilter; +fo_chmod_t invfo_chmod; +fo_chown_t invfo_chown; +fo_sendfile_t invfo_sendfile; + +fo_sendfile_t vn_sendfile; +fo_seek_t vn_seek; +fo_fill_kinfo_t vn_fill_kinfo; +int vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif); + +void finit(struct file *, u_int, short, void *, struct fileops *); +int fgetvp(struct thread *td, int fd, cap_rights_t *rightsp, + struct vnode **vpp); +int fgetvp_exec(struct thread *td, int fd, cap_rights_t *rightsp, + struct vnode **vpp); +int fgetvp_rights(struct thread *td, int fd, cap_rights_t *needrightsp, + struct filecaps *havecaps, struct vnode **vpp); +int fgetvp_read(struct thread *td, int fd, cap_rights_t *rightsp, + struct vnode **vpp); +int fgetvp_write(struct thread *td, int fd, cap_rights_t *rightsp, + struct vnode **vpp); + +static __inline int +_fnoop(void) +{ + + return (0); +} + +static __inline __result_use_check bool +fhold(struct file *fp) +{ + return (refcount_acquire_checked(&fp->f_count)); +} + +#define fdrop(fp, td) \ + (refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()) + +static __inline fo_rdwr_t fo_read; +static __inline fo_rdwr_t fo_write; +static __inline fo_truncate_t fo_truncate; +static __inline fo_ioctl_t fo_ioctl; +static __inline fo_poll_t fo_poll; +static __inline fo_kqfilter_t fo_kqfilter; +static __inline fo_stat_t fo_stat; +static __inline fo_close_t fo_close; +static __inline fo_chmod_t fo_chmod; +static __inline fo_chown_t fo_chown; +static __inline fo_sendfile_t fo_sendfile; + +static __inline int +fo_read(struct file *fp, struct uio *uio, struct ucred *active_cred, + int flags, struct thread *td) +{ + + return ((*fp->f_ops->fo_read)(fp, uio, active_cred, flags, td)); +} + +static __inline int +fo_write(struct file *fp, struct uio *uio, struct ucred *active_cred, + int flags, struct thread *td) +{ + + return ((*fp->f_ops->fo_write)(fp, uio, active_cred, flags, td)); +} + +static __inline int +fo_truncate(struct file *fp, off_t length, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_truncate)(fp, length, active_cred, td)); +} + +static __inline int +fo_ioctl(struct file *fp, u_long com, void *data, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_ioctl)(fp, com, data, active_cred, td)); +} + +static __inline int +fo_poll(struct file *fp, int events, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_poll)(fp, events, active_cred, td)); +} + +static __inline int +fo_stat(struct file *fp, struct stat *sb, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_stat)(fp, sb, active_cred, td)); +} + +static __inline int +fo_close(struct file *fp, struct thread *td) +{ + + return ((*fp->f_ops->fo_close)(fp, td)); +} + +static __inline int +fo_kqfilter(struct file *fp, struct knote *kn) +{ + + return ((*fp->f_ops->fo_kqfilter)(fp, kn)); +} + +static __inline int +fo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_chmod)(fp, mode, active_cred, td)); +} + +static __inline int +fo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, + struct thread *td) +{ + + return ((*fp->f_ops->fo_chown)(fp, uid, gid, active_cred, td)); +} + +static __inline int +fo_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, + struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags, + struct thread *td) +{ + + return ((*fp->f_ops->fo_sendfile)(fp, sockfd, hdr_uio, trl_uio, offset, + nbytes, sent, flags, td)); +} + +static __inline int +fo_seek(struct file *fp, off_t offset, int whence, struct thread *td) +{ + + return ((*fp->f_ops->fo_seek)(fp, offset, whence, td)); +} + +static __inline int +fo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp) +{ + + return ((*fp->f_ops->fo_fill_kinfo)(fp, kif, fdp)); +} + +static __inline int +fo_mmap(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t size, + vm_prot_t prot, vm_prot_t cap_maxprot, int flags, vm_ooffset_t foff, + struct thread *td) +{ + + if (fp->f_ops->fo_mmap == NULL) + return (ENODEV); + return ((*fp->f_ops->fo_mmap)(fp, map, addr, size, prot, cap_maxprot, + flags, foff, td)); +} + +static __inline int +fo_aio_queue(struct file *fp, struct kaiocb *job) +{ + + return ((*fp->f_ops->fo_aio_queue)(fp, job)); +} + +#endif /* _KERNEL */ + +#endif /* !SYS_FILE_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/filedesc.h b/lib/libc/include/any-freebsd-any/sys/filedesc.h new file mode 100644 index 000000000000..db5debcfe7c8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/filedesc.h @@ -0,0 +1,250 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_FILEDESC_H_ +#define _SYS_FILEDESC_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct filecaps { + cap_rights_t fc_rights; /* per-descriptor capability rights */ + u_long *fc_ioctls; /* per-descriptor allowed ioctls */ + int16_t fc_nioctls; /* fc_ioctls array size */ + uint32_t fc_fcntls; /* per-descriptor allowed fcntls */ +}; + +struct filedescent { + struct file *fde_file; /* file structure for open file */ + struct filecaps fde_caps; /* per-descriptor rights */ + uint8_t fde_flags; /* per-process open file flags */ + seq_t fde_seq; /* keep file and caps in sync */ +}; +#define fde_rights fde_caps.fc_rights +#define fde_fcntls fde_caps.fc_fcntls +#define fde_ioctls fde_caps.fc_ioctls +#define fde_nioctls fde_caps.fc_nioctls +#define fde_change_size (offsetof(struct filedescent, fde_seq)) + +struct fdescenttbl { + int fdt_nfiles; /* number of open files allocated */ + struct filedescent fdt_ofiles[0]; /* open files */ +}; +#define fd_seq(fdt, fd) (&(fdt)->fdt_ofiles[(fd)].fde_seq) + +/* + * This structure is used for the management of descriptors. It may be + * shared by multiple processes. + */ +#define NDSLOTTYPE u_long + +struct filedesc { + struct fdescenttbl *fd_files; /* open files table */ + struct vnode *fd_cdir; /* current directory */ + struct vnode *fd_rdir; /* root directory */ + struct vnode *fd_jdir; /* jail root directory */ + NDSLOTTYPE *fd_map; /* bitmap of free fds */ + int fd_lastfile; /* high-water mark of fd_ofiles */ + int fd_freefile; /* approx. next free file */ + u_short fd_cmask; /* mask for file creation */ + int fd_refcnt; /* thread reference count */ + int fd_holdcnt; /* hold count on structure + mutex */ + struct sx fd_sx; /* protects members of this struct */ + struct kqlist fd_kqlist; /* list of kqueues on this filedesc */ + int fd_holdleaderscount; /* block fdfree() for shared close() */ + int fd_holdleaderswakeup; /* fdfree() needs wakeup */ +}; + +/* + * Structure to keep track of (process leader, struct fildedesc) tuples. + * Each process has a pointer to such a structure when detailed tracking + * is needed, e.g., when rfork(RFPROC | RFMEM) causes a file descriptor + * table to be shared by processes having different "p_leader" pointers + * and thus distinct POSIX style locks. + * + * fdl_refcount and fdl_holdcount are protected by struct filedesc mtx. + */ +struct filedesc_to_leader { + int fdl_refcount; /* references from struct proc */ + int fdl_holdcount; /* temporary hold during closef */ + int fdl_wakeup; /* fdfree() waits on closef() */ + struct proc *fdl_leader; /* owner of POSIX locks */ + /* Circular list: */ + struct filedesc_to_leader *fdl_prev; + struct filedesc_to_leader *fdl_next; +}; +#define fd_nfiles fd_files->fdt_nfiles +#define fd_ofiles fd_files->fdt_ofiles + +/* + * Per-process open flags. + */ +#define UF_EXCLOSE 0x01 /* auto-close on exec */ + +#ifdef _KERNEL + +/* Lock a file descriptor table. */ +#define FILEDESC_LOCK_INIT(fdp) sx_init(&(fdp)->fd_sx, "filedesc structure") +#define FILEDESC_LOCK_DESTROY(fdp) sx_destroy(&(fdp)->fd_sx) +#define FILEDESC_LOCK(fdp) (&(fdp)->fd_sx) +#define FILEDESC_XLOCK(fdp) sx_xlock(&(fdp)->fd_sx) +#define FILEDESC_XUNLOCK(fdp) sx_xunlock(&(fdp)->fd_sx) +#define FILEDESC_SLOCK(fdp) sx_slock(&(fdp)->fd_sx) +#define FILEDESC_SUNLOCK(fdp) sx_sunlock(&(fdp)->fd_sx) + +#define FILEDESC_LOCK_ASSERT(fdp) sx_assert(&(fdp)->fd_sx, SX_LOCKED | \ + SX_NOTRECURSED) +#define FILEDESC_XLOCK_ASSERT(fdp) sx_assert(&(fdp)->fd_sx, SX_XLOCKED | \ + SX_NOTRECURSED) +#define FILEDESC_UNLOCK_ASSERT(fdp) sx_assert(&(fdp)->fd_sx, SX_UNLOCKED) + +/* Operation types for kern_dup(). */ +enum { + FDDUP_NORMAL, /* dup() behavior. */ + FDDUP_FCNTL, /* fcntl()-style errors. */ + FDDUP_FIXED, /* Force fixed allocation. */ + FDDUP_MUSTREPLACE, /* Target must exist. */ + FDDUP_LASTMODE, +}; + +/* Flags for kern_dup(). */ +#define FDDUP_FLAG_CLOEXEC 0x1 /* Atomically set UF_EXCLOSE. */ + +/* For backward compatibility. */ +#define falloc(td, resultfp, resultfd, flags) \ + falloc_caps(td, resultfp, resultfd, flags, NULL) + +struct thread; + +void filecaps_init(struct filecaps *fcaps); +bool filecaps_copy(const struct filecaps *src, struct filecaps *dst, + bool locked); +void filecaps_move(struct filecaps *src, struct filecaps *dst); +void filecaps_free(struct filecaps *fcaps); + +int closef(struct file *fp, struct thread *td); +int dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, + int openerror, int *indxp); +int falloc_caps(struct thread *td, struct file **resultfp, int *resultfd, + int flags, struct filecaps *fcaps); +int falloc_noinstall(struct thread *td, struct file **resultfp); +void _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags, + struct filecaps *fcaps); +int finstall(struct thread *td, struct file *fp, int *resultfd, int flags, + struct filecaps *fcaps); +int fdalloc(struct thread *td, int minfd, int *result); +int fdallocn(struct thread *td, int minfd, int *fds, int n); +int fdcheckstd(struct thread *td); +void fdclose(struct thread *td, struct file *fp, int idx); +void fdcloseexec(struct thread *td); +void fdsetugidsafety(struct thread *td); +struct filedesc *fdcopy(struct filedesc *fdp); +int fdcopy_remapped(struct filedesc *fdp, const int *fds, size_t nfds, + struct filedesc **newfdp); +void fdinstall_remapped(struct thread *td, struct filedesc *fdp); +void fdunshare(struct thread *td); +void fdescfree(struct thread *td); +void fdescfree_remapped(struct filedesc *fdp); +struct filedesc *fdinit(struct filedesc *fdp, bool prepfiles); +struct filedesc *fdshare(struct filedesc *fdp); +struct filedesc_to_leader * + filedesc_to_leader_alloc(struct filedesc_to_leader *old, + struct filedesc *fdp, struct proc *leader); +int getvnode(struct thread *td, int fd, cap_rights_t *rightsp, + struct file **fpp); +void mountcheckdirs(struct vnode *olddp, struct vnode *newdp); + +int fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, + struct file **fpp, struct filecaps *havecapsp); +int fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, + struct file **fpp, struct filecaps *havecapsp); + +/* Return a referenced file from an unlocked descriptor. */ +int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, + struct file **fpp, seq_t *seqp); + +/* Requires a FILEDESC_{S,X}LOCK held and returns without a ref. */ +static __inline struct file * +fget_locked(struct filedesc *fdp, int fd) +{ + + FILEDESC_LOCK_ASSERT(fdp); + + if (fd < 0 || fd > fdp->fd_lastfile) + return (NULL); + + return (fdp->fd_ofiles[fd].fde_file); +} + +static __inline struct filedescent * +fdeget_locked(struct filedesc *fdp, int fd) +{ + struct filedescent *fde; + + FILEDESC_LOCK_ASSERT(fdp); + + if (fd < 0 || fd > fdp->fd_lastfile) + return (NULL); + + fde = &fdp->fd_ofiles[fd]; + if (fde->fde_file == NULL) + return (NULL); + + return (fde); +} + +#ifdef CAPABILITIES +static __inline bool +fd_modified(struct filedesc *fdp, int fd, seq_t seq) +{ + + return (!seq_consistent(fd_seq(fdp->fd_files, fd), seq)); +} +#endif + +/* cdir/rdir/jdir manipulation functions. */ +void pwd_chdir(struct thread *td, struct vnode *vp); +int pwd_chroot(struct thread *td, struct vnode *vp); +void pwd_ensure_dirs(void); + +#endif /* _KERNEL */ + +#endif /* !_SYS_FILEDESC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/filio.h b/lib/libc/include/any-freebsd-any/sys/filio.h new file mode 100644 index 000000000000..2e4f3c9e6132 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/filio.h @@ -0,0 +1,74 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)filio.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS_FILIO_H_ +#define _SYS_FILIO_H_ + +#include +#include + +/* Generic file-descriptor ioctl's. */ +#define FIOCLEX _IO('f', 1) /* set close on exec on fd */ +#define FIONCLEX _IO('f', 2) /* remove close on exec */ +#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ +#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */ +#define FIOSETOWN _IOW('f', 124, int) /* set owner */ +#define FIOGETOWN _IOR('f', 123, int) /* get owner */ +#define FIODTYPE _IOR('f', 122, int) /* get d_flags type part */ +#define FIOGETLBA _IOR('f', 121, int) /* get start blk # */ +struct fiodgname_arg { + int len; + void *buf; +}; +#define FIODGNAME _IOW('f', 120, struct fiodgname_arg) /* get dev. name */ +#define FIONWRITE _IOR('f', 119, int) /* get # bytes (yet) to write */ +#define FIONSPACE _IOR('f', 118, int) /* get space in send queue */ +/* Handle lseek SEEK_DATA and SEEK_HOLE for holey file knowledge. */ +#define FIOSEEKDATA _IOWR('f', 97, off_t) /* SEEK_DATA */ +#define FIOSEEKHOLE _IOWR('f', 98, off_t) /* SEEK_HOLE */ +struct fiobmap2_arg { + __daddr_t bn; + int runp; + int runb; +}; +/* Get the file's bmap info for the logical block bn. */ +#define FIOBMAP2 _IOWR('f', 99, struct fiobmap2_arg) + +#endif /* !_SYS_FILIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/firmware.h b/lib/libc/include/any-freebsd-any/sys/firmware.h new file mode 100644 index 000000000000..8a9b2cf23bd7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/firmware.h @@ -0,0 +1,66 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005, Sam Leffler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_FIRMWARE_H_ +#define _SYS_FIRMWARE_H_ +/* + * Loadable firmware support. + * + * The firmware abstraction provides an interface for loading firmware + * images into the kernel and making them available to clients. + * + * Firmware images are usually embedded in kernel loadable modules that can + * be loaded on-demand or pre-loaded as desired. Modules may contain + * one or more firmware images that are stored as opaque data arrays + * and registered with a unique string name. Clients request + * firmware by name, and are returned a struct firmware * below on success. + * The kernel keeps track of references to firmware images to allow/prevent + * module/data unload. + * + * When multiple images are stored in one module, the first image is + * treated as the master with the other images holding references + * to it. This means that to unload the module each dependent/subimage + * must first have its references removed. + * In order for automatic loading to work, the master image must have + * the same name as the module it is embedded into. + */ +struct firmware { + const char *name; /* system-wide name */ + const void *data; /* location of image */ + size_t datasize; /* size of image in bytes */ + unsigned int version; /* version of the image */ +}; + +const struct firmware *firmware_register(const char *, + const void *, size_t, unsigned int, const struct firmware *); +int firmware_unregister(const char *); +const struct firmware *firmware_get(const char *); +#define FIRMWARE_UNLOAD 0x0001 /* unload if unreferenced */ +void firmware_put(const struct firmware *, int); +#endif /* _SYS_FIRMWARE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/fnv_hash.h b/lib/libc/include/any-freebsd-any/sys/fnv_hash.h new file mode 100644 index 000000000000..901603eac18a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/fnv_hash.h @@ -0,0 +1,71 @@ +/*- + * Fowler / Noll / Vo Hash (FNV Hash) + * http://www.isthe.com/chongo/tech/comp/fnv/ + * + * This is an implementation of the algorithms posted above. + * This file is placed in the public domain by Peter Wemm. + * + * $FreeBSD$ + */ +#ifndef _SYS_FNV_HASH_H_ +#define _SYS_FNV_HASH_H_ + +typedef u_int32_t Fnv32_t; +typedef u_int64_t Fnv64_t; + +#define FNV1_32_INIT ((Fnv32_t) 33554467UL) +#define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL) + +#define FNV_32_PRIME ((Fnv32_t) 0x01000193UL) +#define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL) + +static __inline Fnv32_t +fnv_32_buf(const void *buf, size_t len, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_32_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv32_t +fnv_32_str(const char *str, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + Fnv32_t c; + + while ((c = *s++) != 0) { + hval *= FNV_32_PRIME; + hval ^= c; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_buf(const void *buf, size_t len, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_64_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_str(const char *str, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + u_register_t c; /* 32 bit on i386, 64 bit on alpha */ + + while ((c = *s++) != 0) { + hval *= FNV_64_PRIME; + hval ^= c; + } + return hval; +} +#endif /* _SYS_FNV_HASH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/gmon.h b/lib/libc/include/any-freebsd-any/sys/gmon.h new file mode 100644 index 000000000000..47b5c5c17573 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/gmon.h @@ -0,0 +1,245 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)gmon.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_GMON_H_ +#define _SYS_GMON_H_ + +#include + +/* + * Structure prepended to gmon.out profiling data file. + */ +struct gmonhdr { + u_long lpc; /* base pc address of sample buffer */ + u_long hpc; /* max pc address of sampled buffer */ + int ncnt; /* size of sample buffer (plus this header) */ + int version; /* version number */ + int profrate; /* profiling clock rate */ + int histcounter_type; /* size (in bits) and sign of HISTCOUNTER */ + int spare[2]; /* reserved */ +}; +#define GMONVERSION 0x00051879 + +/* + * Type of histogram counters used in the kernel. + */ +#ifdef GPROF4 +#define HISTCOUNTER int64_t +#else +#define HISTCOUNTER unsigned short +#endif + +/* + * Fraction of text space to allocate for histogram counters. + * We allocate counters at the same or higher density as function + * addresses, so that each counter belongs to a unique function. + * A lower density of counters would give less resolution but a + * higher density would be wasted. + */ +#define HISTFRACTION (FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER) == 0 \ + ? 1 : FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER)) + +/* + * Fraction of text space to allocate for from hash buckets. + * The value of HASHFRACTION is based on the minimum number of bytes + * of separation between two subroutine call points in the object code. + * Given MIN_SUBR_SEPARATION bytes of separation the value of + * HASHFRACTION is calculated as: + * + * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); + * + * For example, on the VAX, the shortest two call sequence is: + * + * calls $0,(r0) + * calls $0,(r0) + * + * which is separated by only three bytes, thus HASHFRACTION is + * calculated as: + * + * HASHFRACTION = 3 / (2 * 2 - 1) = 1 + * + * Note that the division above rounds down, thus if MIN_SUBR_FRACTION + * is less than three, this algorithm will not work! + * + * In practice, however, call instructions are rarely at a minimal + * distance. Hence, we will define HASHFRACTION to be 2 across all + * architectures. This saves a reasonable amount of space for + * profiling data structures without (in practice) sacrificing + * any granularity. + */ +/* + * XXX I think the above analysis completely misses the point. I think + * the point is that addresses in different functions must hash to + * different values. Since the hash is essentially division by + * sizeof(unsigned short), the correct formula is: + * + * HASHFRACTION = MIN_FUNCTION_ALIGNMENT / sizeof(unsigned short) + * + * Note that he unsigned short here has nothing to do with the one for + * HISTFRACTION. + * + * Hash collisions from a two call sequence don't matter. They get + * handled like collisions for calls to different addresses from the + * same address through a function pointer. + */ +#define HASHFRACTION (FUNCTION_ALIGNMENT / sizeof(unsigned short) == 0 \ + ? 1 : FUNCTION_ALIGNMENT / sizeof(unsigned short)) + +/* + * percent of text space to allocate for tostructs with a minimum. + */ +#define ARCDENSITY 2 +#define MINARCS 50 + +/* + * Limit on the number of arcs to so that arc numbers can be stored in + * `*froms' and stored and incremented without overflow in links. + */ +#define MAXARCS (((u_long)1 << (8 * sizeof(u_short))) - 2) + +struct tostruct { + u_long selfpc; + long count; + u_short link; + u_short pad; +}; + +/* + * a raw arc, with pointers to the calling site and + * the called site and a count. + */ +struct rawarc { + u_long raw_frompc; + u_long raw_selfpc; + long raw_count; +}; + +/* + * general rounding functions. + */ +#define ROUNDDOWN(x,y) rounddown(x,y) +#define ROUNDUP(x,y) roundup(x,y) + +/* + * The profiling data structures are housed in this structure. + */ +struct gmonparam { + int state; + HISTCOUNTER *kcount; + u_long kcountsize; + u_short *froms; + u_long fromssize; + struct tostruct *tos; + u_long tossize; + long tolimit; + uintfptr_t lowpc; + uintfptr_t highpc; + u_long textsize; + u_long hashfraction; + int profrate; /* XXX wrong type to match gmonhdr */ + HISTCOUNTER *cputime_count; + int cputime_overhead; + HISTCOUNTER *mcount_count; + int mcount_overhead; + int mcount_post_overhead; + int mcount_pre_overhead; + HISTCOUNTER *mexitcount_count; + int mexitcount_overhead; + int mexitcount_post_overhead; + int mexitcount_pre_overhead; + int histcounter_type; +}; +extern struct gmonparam _gmonparam; + +/* + * Possible states of profiling. + */ +#define GMON_PROF_ON 0 +#define GMON_PROF_BUSY 1 +#define GMON_PROF_ERROR 2 +#define GMON_PROF_OFF 3 +#define GMON_PROF_HIRES 4 + +/* + * Sysctl definitions for extracting profiling information from the kernel. + */ +#define GPROF_STATE 0 /* int: profiling enabling variable */ +#define GPROF_COUNT 1 /* struct: profile tick count buffer */ +#define GPROF_FROMS 2 /* struct: from location hash bucket */ +#define GPROF_TOS 3 /* struct: destination/count structure */ +#define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */ + +#ifdef _KERNEL + +#define KCOUNT(p,index) \ + ((p)->kcount[(index) / (HISTFRACTION * sizeof(HISTCOUNTER))]) +#define PC_TO_I(p, pc) ((uintfptr_t)(pc) - (uintfptr_t)(p)->lowpc) + +#ifdef GUPROF + +#define CALIB_SCALE 1000 + +extern int cputime_bias; + +int cputime(void); +void nullfunc_loop_profiled(void); +void nullfunc_profiled(void); +void startguprof(struct gmonparam *p); +void stopguprof(struct gmonparam *p); + +#else /* !GUPROF */ + +#define startguprof(p) +#define stopguprof(p) + +#endif /* GUPROF */ + +void empty_loop(void); +void kmupetext(uintfptr_t nhighpc); +void mexitcount(uintfptr_t selfpc); +void nullfunc(void); +void nullfunc_loop(void); + +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +void moncontrol(int); +void monstartup(u_long, u_long); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_GMON_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/gpio.h b/lib/libc/include/any-freebsd-any/sys/gpio.h new file mode 100644 index 000000000000..2505269de64d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/gpio.h @@ -0,0 +1,179 @@ +/* $NetBSD: gpio.h,v 1.7 2009/09/25 20:27:50 mbalmer Exp $ */ +/* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */ +/*- + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND ISC) + * + * Copyright (c) 2009, Oleksandr Tymoshenko + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +/* + * Copyright (c) 2009 Marc Balmer + * Copyright (c) 2004 Alexander Yurchenko + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#include + +/* GPIO pin states */ +#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */ +#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */ + +/* Max name length of a pin */ +#define GPIOMAXNAME 64 + +/* GPIO pin configuration flags */ +#define GPIO_PIN_INPUT 0x00000001 /* input direction */ +#define GPIO_PIN_OUTPUT 0x00000002 /* output direction */ +#define GPIO_PIN_OPENDRAIN 0x00000004 /* open-drain output */ +#define GPIO_PIN_PUSHPULL 0x00000008 /* push-pull output */ +#define GPIO_PIN_TRISTATE 0x00000010 /* output disabled */ +#define GPIO_PIN_PULLUP 0x00000020 /* internal pull-up enabled */ +#define GPIO_PIN_PULLDOWN 0x00000040 /* internal pull-down enabled */ +#define GPIO_PIN_INVIN 0x00000080 /* invert input */ +#define GPIO_PIN_INVOUT 0x00000100 /* invert output */ +#define GPIO_PIN_PULSATE 0x00000200 /* pulsate in hardware */ +#define GPIO_PIN_PRESET_LOW 0x00000400 /* preset pin to high or */ +#define GPIO_PIN_PRESET_HIGH 0x00000800 /* low before enabling output */ +/* GPIO interrupt capabilities */ +#define GPIO_INTR_NONE 0x00000000 /* no interrupt support */ +#define GPIO_INTR_LEVEL_LOW 0x00010000 /* level trigger, low */ +#define GPIO_INTR_LEVEL_HIGH 0x00020000 /* level trigger, high */ +#define GPIO_INTR_EDGE_RISING 0x00040000 /* edge trigger, rising */ +#define GPIO_INTR_EDGE_FALLING 0x00080000 /* edge trigger, falling */ +#define GPIO_INTR_EDGE_BOTH 0x00100000 /* edge trigger, both */ +#define GPIO_INTR_MASK (GPIO_INTR_LEVEL_LOW | GPIO_INTR_LEVEL_HIGH | \ + GPIO_INTR_EDGE_RISING | \ + GPIO_INTR_EDGE_FALLING | GPIO_INTR_EDGE_BOTH) + +struct gpio_pin { + uint32_t gp_pin; /* pin number */ + char gp_name[GPIOMAXNAME]; /* human-readable name */ + uint32_t gp_caps; /* capabilities */ + uint32_t gp_flags; /* current flags */ +}; + +/* GPIO pin request (read/write/toggle) */ +struct gpio_req { + uint32_t gp_pin; /* pin number */ + uint32_t gp_value; /* value */ +}; + +/* + * gpio_access_32 / GPIOACCESS32 + * + * Simultaneously read and/or change up to 32 adjacent pins. + * If the device cannot change the pins simultaneously, returns EOPNOTSUPP. + * + * This accesses an adjacent set of up to 32 pins starting at first_pin within + * the device's collection of pins. How the hardware pins are mapped to the 32 + * bits in the arguments is device-specific. It is expected that lower-numbered + * pins in the device's number space map linearly to lower-ordered bits within + * the 32-bit words (i.e., bit 0 is first_pin, bit 1 is first_pin+1, etc). + * Other mappings are possible; know your device. + * + * Some devices may limit the value of first_pin to 0, or to multiples of 16 or + * 32 or some other hardware-specific number; to access pin 2 would require + * first_pin to be zero and then manipulate bit (1 << 2) in the 32-bit word. + * Invalid values in first_pin result in an EINVAL error return. + * + * The starting state of the pins is captured and stored in orig_pins, then the + * pins are set to ((starting_state & ~clear_pins) ^ change_pins). + * + * Clear Change Hardware pin after call + * 0 0 No change + * 0 1 Opposite of current value + * 1 0 Cleared + * 1 1 Set + */ +struct gpio_access_32 { + uint32_t first_pin; /* First pin in group of 32 adjacent */ + uint32_t clear_pins; /* Pins are changed using: */ + uint32_t change_pins; /* ((hwstate & ~clear_pins) ^ change_pins) */ + uint32_t orig_pins; /* Returned hwstate of pins before change. */ +}; + +/* + * gpio_config_32 / GPIOCONFIG32 + * + * Simultaneously configure up to 32 adjacent pins. This is intended to change + * the configuration of all the pins simultaneously, such that pins configured + * for output all begin to drive the configured values simultaneously, but not + * all hardware can do that, so the driver "does the best it can" in this + * regard. Notably unlike pin_access_32(), this does NOT fail if the pins + * cannot be atomically configured; it is expected that callers understand the + * hardware and have decided to live with any such limitations it may have. + * + * The pin_flags argument is an array of GPIO_PIN_xxxx flags. If the array + * contains any GPIO_PIN_OUTPUT flags, the driver will manipulate the hardware + * such that all output pins become driven with the proper initial values + * simultaneously if it can. The elements in the array map to pins in the same + * way that bits are mapped by pin_acces_32(), and the same restrictions may + * apply. For example, to configure pins 2 and 3 it may be necessary to set + * first_pin to zero and only populate pin_flags[2] and pin_flags[3]. If a + * given array entry doesn't contain GPIO_PIN_INPUT or GPIO_PIN_OUTPUT then no + * configuration is done for that pin. + * + * Some devices may limit the value of first_pin to 0, or to multiples of 16 or + * 32 or some other hardware-specific number. Invalid values in first_pin or + * num_pins result in an error return with errno set to EINVAL. + */ +struct gpio_config_32 { + uint32_t first_pin; + uint32_t num_pins; + uint32_t pin_flags[32]; +}; + +/* + * ioctls + */ +#define GPIOMAXPIN _IOR('G', 0, int) +#define GPIOGETCONFIG _IOWR('G', 1, struct gpio_pin) +#define GPIOSETCONFIG _IOW('G', 2, struct gpio_pin) +#define GPIOGET _IOWR('G', 3, struct gpio_req) +#define GPIOSET _IOW('G', 4, struct gpio_req) +#define GPIOTOGGLE _IOWR('G', 5, struct gpio_req) +#define GPIOSETNAME _IOW('G', 6, struct gpio_pin) +#define GPIOACCESS32 _IOWR('G', 7, struct gpio_access_32) +#define GPIOCONFIG32 _IOW('G', 8, struct gpio_config_32) + +#endif /* __GPIO_H__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/gpt.h b/lib/libc/include/any-freebsd-any/sys/gpt.h new file mode 100644 index 000000000000..4e543063754c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/gpt.h @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_GPT_H_ +#define _SYS_GPT_H_ + +#include + +#define GPT_UUID_TYPE struct uuid +#include + +#endif /* _SYS_GPT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/gtaskqueue.h b/lib/libc/include/any-freebsd-any/sys/gtaskqueue.h new file mode 100644 index 000000000000..16a83ce39fd5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/gtaskqueue.h @@ -0,0 +1,113 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 Jeffrey Roberson + * Copyright (c) 2016 Matthew Macy + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_GTASKQUEUE_H_ +#define _SYS_GTASKQUEUE_H_ +#include + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +struct gtaskqueue; + +/* + * Taskqueue groups. Manages dynamic thread groups and irq binding for + * device and other tasks. + */ + +void gtaskqueue_block(struct gtaskqueue *queue); +void gtaskqueue_unblock(struct gtaskqueue *queue); + +int gtaskqueue_cancel(struct gtaskqueue *queue, struct gtask *gtask); +void gtaskqueue_drain(struct gtaskqueue *queue, struct gtask *task); +void gtaskqueue_drain_all(struct gtaskqueue *queue); + +void grouptask_block(struct grouptask *grouptask); +void grouptask_unblock(struct grouptask *grouptask); +int grouptaskqueue_enqueue(struct gtaskqueue *queue, struct gtask *task); + +void taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *grptask, + void *uniq, int irq, const char *name); +int taskqgroup_attach_cpu(struct taskqgroup *qgroup, + struct grouptask *grptask, void *uniq, int cpu, int irq, + const char *name); +void taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask); +struct taskqgroup *taskqgroup_create(const char *name); +void taskqgroup_destroy(struct taskqgroup *qgroup); +int taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride); + +#define TASK_ENQUEUED 0x1 +#define TASK_SKIP_WAKEUP 0x2 +#define TASK_NOENQUEUE 0x4 + +#define GTASK_INIT(gtask, flags, priority, func, context) do { \ + (gtask)->ta_flags = flags; \ + (gtask)->ta_priority = (priority); \ + (gtask)->ta_func = (func); \ + (gtask)->ta_context = (context); \ +} while (0) + +#define GROUPTASK_INIT(gtask, priority, func, context) \ + GTASK_INIT(&(gtask)->gt_task, TASK_SKIP_WAKEUP, priority, func, context) + +#define GROUPTASK_ENQUEUE(gtask) \ + grouptaskqueue_enqueue((gtask)->gt_taskqueue, &(gtask)->gt_task) + +#define TASKQGROUP_DECLARE(name) \ +extern struct taskqgroup *qgroup_##name + +#define TASKQGROUP_DEFINE(name, cnt, stride) \ + \ +struct taskqgroup *qgroup_##name; \ + \ +static void \ +taskqgroup_define_##name(void *arg) \ +{ \ + qgroup_##name = taskqgroup_create(#name); \ +} \ + \ +SYSINIT(taskqgroup_##name, SI_SUB_TASKQ, SI_ORDER_FIRST, \ + taskqgroup_define_##name, NULL); \ + \ +static void \ +taskqgroup_adjust_##name(void *arg) \ +{ \ + taskqgroup_adjust(qgroup_##name, (cnt), (stride)); \ +} \ + \ +SYSINIT(taskqgroup_adj_##name, SI_SUB_SMP, SI_ORDER_ANY, \ + taskqgroup_adjust_##name, NULL) + +TASKQGROUP_DECLARE(net); +TASKQGROUP_DECLARE(softirq); + +#endif /* !_SYS_GTASKQUEUE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/hash.h b/lib/libc/include/any-freebsd-any/sys/hash.h new file mode 100644 index 000000000000..35e76ec758cb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/hash.h @@ -0,0 +1,136 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Tobias Weingartner + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $OpenBSD: hash.h,v 1.4 2004/05/25 18:37:23 jmc Exp $ + * $FreeBSD$ + */ + +#ifndef _SYS_HASH_H_ +#define _SYS_HASH_H_ +#include + +/* Convenience */ +#ifndef HASHINIT +#define HASHINIT 5381 +#define HASHSTEP(x,c) (((x << 5) + x) + (c)) +#endif + +/* + * Return a 32-bit hash of the given buffer. The init + * value should be 0, or the previous hash value to extend + * the previous hash. + */ +static __inline uint32_t +hash32_buf(const void *buf, size_t len, uint32_t hash) +{ + const unsigned char *p = buf; + + while (len--) + hash = HASHSTEP(hash, *p++); + + return hash; +} + +/* + * Return a 32-bit hash of the given string. + */ +static __inline uint32_t +hash32_str(const void *buf, uint32_t hash) +{ + const unsigned char *p = buf; + + while (*p) + hash = HASHSTEP(hash, *p++); + + return hash; +} + +/* + * Return a 32-bit hash of the given string, limited by N. + */ +static __inline uint32_t +hash32_strn(const void *buf, size_t len, uint32_t hash) +{ + const unsigned char *p = buf; + + while (*p && len--) + hash = HASHSTEP(hash, *p++); + + return hash; +} + +/* + * Return a 32-bit hash of the given string terminated by C, + * (as well as 0). This is mainly here as a helper for the + * namei() hashing of path name parts. + */ +static __inline uint32_t +hash32_stre(const void *buf, int end, const char **ep, uint32_t hash) +{ + const unsigned char *p = buf; + + while (*p && (*p != end)) + hash = HASHSTEP(hash, *p++); + + if (ep) + *ep = p; + + return hash; +} + +/* + * Return a 32-bit hash of the given string, limited by N, + * and terminated by C (as well as 0). This is mainly here + * as a helper for the namei() hashing of path name parts. + */ +static __inline uint32_t +hash32_strne(const void *buf, size_t len, int end, const char **ep, + uint32_t hash) +{ + const unsigned char *p = buf; + + while (*p && (*p != end) && len--) + hash = HASHSTEP(hash, *p++); + + if (ep) + *ep = p; + + return hash; +} + +#ifdef _KERNEL +/* + * Hashing function from Bob Jenkins. Implementation in libkern/jenkins_hash.c. + */ +uint32_t jenkins_hash(const void *, size_t, uint32_t); +uint32_t jenkins_hash32(const uint32_t *, size_t, uint32_t); + +uint32_t murmur3_32_hash(const void *, size_t, uint32_t); +uint32_t murmur3_32_hash32(const uint32_t *, size_t, uint32_t); + +#endif /* _KERNEL */ + +#endif /* !_SYS_HASH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/hhook.h b/lib/libc/include/any-freebsd-any/sys/hhook.h new file mode 100644 index 000000000000..76c827e66939 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/hhook.h @@ -0,0 +1,163 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010,2013 Lawrence Stewart + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Lawrence Stewart while studying at the Centre + * for Advanced Internet Architectures, Swinburne University of Technology, made + * possible in part by grants from the FreeBSD Foundation and Cisco University + * Research Program Fund at Community Foundation Silicon Valley. + * + * Portions of this software were developed at the Centre for Advanced + * Internet Architectures, Swinburne University of Technology, Melbourne, + * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * A KPI modelled on the pfil framework for instantiating helper hook points + * within the kernel for use by Khelp modules. Originally released as part of + * the NewTCP research project at Swinburne University of Technology's Centre + * for Advanced Internet Architectures, Melbourne, Australia, which was made + * possible in part by a grant from the Cisco University Research Program Fund + * at Community Foundation Silicon Valley. More details are available at: + * http://caia.swin.edu.au/urp/newtcp/ + */ + +#ifndef _SYS_HHOOK_H_ +#define _SYS_HHOOK_H_ + +/* XXXLAS: Is there a way around this? */ +#include +#include + +/* hhook_head flags. */ +#define HHH_ISINVNET 0x00000001 /* Is the hook point in a vnet? */ + +/* Flags common to all register functions. */ +#define HHOOK_WAITOK 0x00000001 /* Sleeping allowed. */ +#define HHOOK_NOWAIT 0x00000002 /* Sleeping disallowed. */ +/* Flags only relevant to hhook_head_register() and hhook_head_is_virtual(). */ +#define HHOOK_HEADISINVNET 0x00000100 /* Public proxy for HHH_ISINVNET. */ + +/* Helper hook types. */ +#define HHOOK_TYPE_TCP 1 +#define HHOOK_TYPE_SOCKET 2 +#define HHOOK_TYPE_IPSEC_IN 3 +#define HHOOK_TYPE_IPSEC_OUT 4 + +struct helper; +struct osd; + +/* Signature for helper hook functions. */ +typedef int (*hhook_func_t)(int32_t hhook_type, int32_t hhook_id, void *udata, + void *ctx_data, void *hdata, struct osd *hosd); + +/* + * Information required to add/remove a helper hook function to/from a helper + * hook point. + */ +struct hookinfo { + hhook_func_t hook_func; + struct helper *hook_helper; + void *hook_udata; + int32_t hook_id; + int32_t hook_type; +}; + +/* + * Ideally this would be private but we need access to the hhh_nhooks member + * variable in order to make the HHOOKS_RUN_IF() macro low impact. + */ +struct hhook_head { + STAILQ_HEAD(hhook_list, hhook) hhh_hooks; + struct rmlock hhh_lock; + uintptr_t hhh_vid; + int32_t hhh_id; + int32_t hhh_nhooks; + int32_t hhh_type; + uint32_t hhh_flags; + volatile uint32_t hhh_refcount; + LIST_ENTRY(hhook_head) hhh_next; + LIST_ENTRY(hhook_head) hhh_vnext; +}; + +/* Public KPI functions. */ +void hhook_run_hooks(struct hhook_head *hhh, void *ctx_data, struct osd *hosd); + +int hhook_add_hook(struct hhook_head *hhh, struct hookinfo *hki, + uint32_t flags); + +int hhook_add_hook_lookup(struct hookinfo *hki, uint32_t flags); + +int hhook_remove_hook(struct hhook_head *hhh, struct hookinfo *hki); + +int hhook_remove_hook_lookup(struct hookinfo *hki); + +int hhook_head_register(int32_t hhook_type, int32_t hhook_id, + struct hhook_head **hhh, uint32_t flags); + +int hhook_head_deregister(struct hhook_head *hhh); + +int hhook_head_deregister_lookup(int32_t hhook_type, int32_t hhook_id); + +struct hhook_head * hhook_head_get(int32_t hhook_type, int32_t hhook_id); + +void hhook_head_release(struct hhook_head *hhh); + +uint32_t hhook_head_is_virtualised(struct hhook_head *hhh); + +uint32_t hhook_head_is_virtualised_lookup(int32_t hook_type, int32_t hook_id); + +/* + * A wrapper around hhook_run_hooks() that only calls the function if at least + * one helper hook function is registered for the specified helper hook point. + */ +#define HHOOKS_RUN_IF(hhh, ctx_data, hosd) do { \ + if (hhh != NULL && hhh->hhh_nhooks > 0) \ + hhook_run_hooks(hhh, ctx_data, hosd); \ +} while (0) + +/* + * WARNING: This macro should only be used in code paths that execute + * infrequently, otherwise the refcounting overhead would be excessive. + * + * A similar wrapper to HHOOKS_RUN_IF() for situations where the caller prefers + * not to lookup and store the appropriate hhook_head pointer themselves. + */ +#define HHOOKS_RUN_LOOKUP_IF(hhook_type, hhook_id, ctx_data, hosd) do { \ + struct hhook_head *_hhh; \ + \ + _hhh = hhook_head_get(hhook_type, hhook_id); \ + if (_hhh != NULL) { \ + if (_hhh->hhh_nhooks > 0) \ + hhook_run_hooks(_hhh, ctx_data, hosd); \ + hhook_head_release(_hhh); \ + } \ +} while (0) + +#endif /* _SYS_HHOOK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/iconv.h b/lib/libc/include/any-freebsd-any/sys/iconv.h new file mode 100644 index 000000000000..ba9b0e9dd9c8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/iconv.h @@ -0,0 +1,252 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000-2001 Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_ICONV_H_ +#define _SYS_ICONV_H_ + +#define ICONV_CSNMAXLEN 31 /* maximum length of charset name */ +#define ICONV_CNVNMAXLEN 31 /* maximum length of converter name */ +/* maximum size of data associated with cs pair */ +#define ICONV_CSMAXDATALEN (sizeof(caddr_t) * 0x200 + sizeof(uint32_t) * 0x200 * 0x80) + +#define XLAT16_ACCEPT_NULL_OUT 0x01000000 +#define XLAT16_ACCEPT_NULL_IN 0x02000000 +#define XLAT16_HAS_LOWER_CASE 0x04000000 +#define XLAT16_HAS_UPPER_CASE 0x08000000 +#define XLAT16_HAS_FROM_LOWER_CASE 0x10000000 +#define XLAT16_HAS_FROM_UPPER_CASE 0x20000000 +#define XLAT16_IS_3BYTE_CHR 0x40000000 + +#define KICONV_LOWER 1 /* tolower converted character */ +#define KICONV_UPPER 2 /* toupper converted character */ +#define KICONV_FROM_LOWER 4 /* tolower source character, then convert */ +#define KICONV_FROM_UPPER 8 /* toupper source character, then convert */ +#define KICONV_WCTYPE 16 /* towlower/towupper characters */ + +#define ENCODING_UNICODE "UTF-16BE" +#define KICONV_WCTYPE_NAME "_wctype" + +/* + * Entry for cslist sysctl + */ +#define ICONV_CSPAIR_INFO_VER 1 + +struct iconv_cspair_info { + int cs_version; + int cs_id; + int cs_base; + int cs_refcount; + char cs_to[ICONV_CSNMAXLEN]; + char cs_from[ICONV_CSNMAXLEN]; +}; + +/* + * Parameters for 'add' sysctl + */ +#define ICONV_ADD_VER 1 + +struct iconv_add_in { + int ia_version; + char ia_converter[ICONV_CNVNMAXLEN]; + char ia_to[ICONV_CSNMAXLEN]; + char ia_from[ICONV_CSNMAXLEN]; + int ia_datalen; + const void *ia_data; +}; + +struct iconv_add_out { + int ia_csid; +}; + +#ifndef _KERNEL + +__BEGIN_DECLS + +#define KICONV_VENDOR_MICSFT 1 /* Microsoft Vendor Code for quirk */ + +int kiconv_add_xlat_table(const char *, const char *, const u_char *); +int kiconv_add_xlat16_cspair(const char *, const char *, int); +int kiconv_add_xlat16_cspairs(const char *, const char *); +int kiconv_add_xlat16_table(const char *, const char *, const void *, int); +int kiconv_lookupconv(const char *drvname); +int kiconv_lookupcs(const char *tocode, const char *fromcode); +const char *kiconv_quirkcs(const char *, int); + +__END_DECLS + +#else /* !_KERNEL */ + +#include +#include /* can't avoid that */ +#include /* can't avoid that */ +#include /* can't avoid that */ + +struct iconv_cspair; +struct iconv_cspairdata; + +/* + * iconv converter class definition + */ +struct iconv_converter_class { + KOBJ_CLASS_FIELDS; + TAILQ_ENTRY(iconv_converter_class) cc_link; +}; + +struct iconv_cspair { + int cp_id; /* unique id of charset pair */ + int cp_refcount; /* number of references from other pairs */ + const char * cp_from; + const char * cp_to; + void * cp_data; + struct iconv_converter_class * cp_dcp; + struct iconv_cspair *cp_base; + TAILQ_ENTRY(iconv_cspair) cp_link; +}; + +#define KICONV_CONVERTER(name,size) \ + static struct iconv_converter_class iconv_ ## name ## _class = { \ + "iconv_"#name, iconv_ ## name ## _methods, size, NULL \ + }; \ + static moduledata_t iconv_ ## name ## _mod = { \ + "iconv_"#name, iconv_converter_handler, \ + (void*)&iconv_ ## name ## _class \ + }; \ + DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); + +#define KICONV_CES(name,size) \ + static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \ + static moduledata_t iconv_ces_ ## name ## _mod = { \ + "iconv_ces_"#name, iconv_cesmod_handler, \ + (void*)&iconv_ces_ ## name ## _class \ + }; \ + DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_ICONV); +#endif + +/* + * Basic conversion functions + */ +int iconv_open(const char *to, const char *from, void **handle); +int iconv_close(void *handle); +int iconv_conv(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +int iconv_conv_case(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype); +int iconv_convchr(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +int iconv_convchr_case(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype); +int iconv_add(const char *converter, const char *to, const char *from); +char* iconv_convstr(void *handle, char *dst, const char *src); +void* iconv_convmem(void *handle, void *dst, const void *src, int size); +int iconv_vfs_refcount(const char *fsname); + +int towlower(int c, void *handle); +int towupper(int c, void *handle); + +/* + * Bridge struct of iconv functions + */ +struct iconv_functions { + int (*open)(const char *to, const char *from, void **handle); + int (*close)(void *handle); + int (*conv)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + int (*conv_case)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, int casetype); + int (*convchr)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + int (*convchr_case)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, int casetype); +}; + +#define VFS_DECLARE_ICONV(fsname) \ + static struct iconv_functions fsname ## _iconv_core = { \ + iconv_open, \ + iconv_close, \ + iconv_conv, \ + iconv_conv_case, \ + iconv_convchr, \ + iconv_convchr_case \ + }; \ + extern struct iconv_functions *fsname ## _iconv; \ + static int fsname ## _iconv_mod_handler(module_t mod, \ + int type, void *d); \ + static int \ + fsname ## _iconv_mod_handler(module_t mod, int type, void *d) \ + { \ + int error = 0; \ + switch(type) { \ + case MOD_LOAD: \ + fsname ## _iconv = & fsname ## _iconv_core; \ + break; \ + case MOD_UNLOAD: \ + error = iconv_vfs_refcount(#fsname); \ + if (error) \ + return (EBUSY); \ + fsname ## _iconv = NULL; \ + break; \ + default: \ + error = EINVAL; \ + break; \ + } \ + return (error); \ + } \ + static moduledata_t fsname ## _iconv_mod = { \ + #fsname"_iconv", \ + fsname ## _iconv_mod_handler, \ + NULL \ + }; \ + DECLARE_MODULE(fsname ## _iconv, fsname ## _iconv_mod, \ + SI_SUB_DRIVERS, SI_ORDER_ANY); \ + MODULE_DEPEND(fsname ## _iconv, fsname, 1, 1, 1); \ + MODULE_DEPEND(fsname ## _iconv, libiconv, 2, 2, 2); \ + MODULE_VERSION(fsname ## _iconv, 1) + +/* + * Internal functions + */ +int iconv_lookupcp(char **cpp, const char *s); + +int iconv_converter_initstub(struct iconv_converter_class *dp); +int iconv_converter_donestub(struct iconv_converter_class *dp); +int iconv_converter_tolowerstub(int c, void *handle); +int iconv_converter_handler(module_t mod, int type, void *data); + +#ifdef ICONV_DEBUG +#define ICDEBUG(format, ...) printf("%s: "format, __func__ , ## __VA_ARGS__) +#else +#define ICDEBUG(format, ...) +#endif + +#endif /* !_KERNEL */ + +#endif /* !_SYS_ICONV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/imgact.h b/lib/libc/include/any-freebsd-any/sys/imgact.h new file mode 100644 index 000000000000..a084abea4cfb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/imgact.h @@ -0,0 +1,116 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993, David Greenman + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_IMGACT_H_ +#define _SYS_IMGACT_H_ + +#include + +#include + +#define MAXSHELLCMDLEN PAGE_SIZE + +struct ucred; + +struct image_args { + char *buf; /* pointer to string buffer */ + void *bufkva; /* cookie for string buffer KVA */ + char *begin_argv; /* beginning of argv in buf */ + char *begin_envv; /* beginning of envv in buf */ + char *endp; /* current `end' pointer of arg & env strings */ + char *fname; /* pointer to filename of executable (system space) */ + char *fname_buf; /* pointer to optional malloc(M_TEMP) buffer */ + int stringspace; /* space left in arg & env buffer */ + int argc; /* count of argument strings */ + int envc; /* count of environment strings */ + int fd; /* file descriptor of the executable */ + struct filedesc *fdp; /* new file descriptor table */ +}; + +struct image_params { + struct proc *proc; /* our process struct */ + struct label *execlabel; /* optional exec label */ + struct vnode *vp; /* pointer to vnode of file to exec */ + struct vm_object *object; /* The vm object for this vp */ + struct vattr *attr; /* attributes of file */ + const char *image_header; /* head of file to exec */ + unsigned long entry_addr; /* entry address of target executable */ + unsigned long reloc_base; /* load address of image */ + char vmspace_destroyed; /* flag - we've blown away original vm space */ +#define IMGACT_SHELL 0x1 +#define IMGACT_BINMISC 0x2 + unsigned char interpreted; /* mask of interpreters that have run */ + char opened; /* flag - we have opened executable vnode */ + char *interpreter_name; /* name of the interpreter */ + void *auxargs; /* ELF Auxinfo structure pointer */ + struct sf_buf *firstpage; /* first page that we mapped */ + unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ + struct image_args *args; /* system call arguments */ + struct sysentvec *sysent; /* system entry vector */ + char *execpath; + unsigned long execpathp; + char *freepath; + unsigned long canary; + int canarylen; + unsigned long pagesizes; + int pagesizeslen; + vm_prot_t stack_prot; + u_long stack_sz; + u_long eff_stack_sz; + struct ucred *newcred; /* new credentials if changing */ + bool credential_setid; /* true if becoming setid */ + bool textset; + u_int map_flags; +}; + +#ifdef _KERNEL +struct sysentvec; +struct thread; +struct vmspace; + +int exec_alloc_args(struct image_args *); +int exec_check_permissions(struct image_params *); +register_t *exec_copyout_strings(struct image_params *); +void exec_free_args(struct image_args *); +int exec_new_vmspace(struct image_params *, struct sysentvec *); +void exec_setregs(struct thread *, struct image_params *, u_long); +int exec_shell_imgact(struct image_params *); +int exec_copyin_args(struct image_args *, char *, enum uio_seg, + char **, char **); +int exec_copyin_data_fds(struct thread *, struct image_args *, const void *, + size_t, const int *, size_t); +int pre_execve(struct thread *td, struct vmspace **oldvmspace); +void post_execve(struct thread *td, int error, struct vmspace *oldvmspace); +#endif + +#endif /* !_SYS_IMGACT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/imgact_aout.h b/lib/libc/include/any-freebsd-any/sys/imgact_aout.h new file mode 100644 index 000000000000..f7cad87abb49 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/imgact_aout.h @@ -0,0 +1,159 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)exec.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _IMGACT_AOUT_H_ +#define _IMGACT_AOUT_H_ + +#define N_GETMAGIC(ex) \ + ( le32toh((ex).a_midmag) & 0xffff ) +#define N_GETMID(ex) \ + ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ + ((ex).a_midmag >> 16) & 0x03ff ) +#define N_GETFLAG(ex) \ + ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ + ((ex).a_midmag >> 26) & 0x3f ) +#define N_SETMAGIC(ex,mag,mid,flag) \ + ( (ex).a_midmag = htole32((((flag) & 0x3f) <<26) | \ + (((mid) & 0x03ff) << 16) | \ + ((mag) & 0xffff)) ) + +#define N_GETMAGIC_NET(ex) \ + (ntohl((ex).a_midmag) & 0xffff) +#define N_GETMID_NET(ex) \ + ((ntohl((ex).a_midmag) >> 16) & 0x03ff) +#define N_GETFLAG_NET(ex) \ + ((ntohl((ex).a_midmag) >> 26) & 0x3f) +#define N_SETMAGIC_NET(ex,mag,mid,flag) \ + ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \ + | (((mag)&0xffff)) ) ) + +#define N_ALIGN(ex,x) \ + (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ + N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ + ((x) + __LDPGSZ - 1) & ~(uint32_t)(__LDPGSZ - 1) : (x)) + +/* Valid magic number check. */ +#define N_BADMAG(ex) \ + (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ + N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ + N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ + N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) + + +/* Address of the bottom of the text segment. */ +/* + * This can not be done right. Abuse a_entry in some cases to handle kernels. + */ +#define N_TXTADDR(ex) \ + ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ + N_GETMAGIC(ex) == ZMAGIC) ? \ + (le32toh((ex).a_entry) < le32toh((ex).a_text) ? 0 : \ + le32toh((ex).a_entry) & ~__LDPGSZ) : __LDPGSZ) + +/* Address of the bottom of the data segment. */ +#define N_DATADDR(ex) \ + N_ALIGN(ex, N_TXTADDR(ex) + le32toh((ex).a_text)) + +/* Text segment offset. */ +#define N_TXTOFF(ex) \ + (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ + N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) + +/* Data segment offset. */ +#define N_DATOFF(ex) \ + N_ALIGN(ex, N_TXTOFF(ex) + le32toh((ex).a_text)) + +/* Relocation table offset. */ +#define N_RELOFF(ex) \ + N_ALIGN(ex, N_DATOFF(ex) + le32toh((ex).a_data)) + +/* Symbol table offset. */ +#define N_SYMOFF(ex) \ + (N_RELOFF(ex) + le32toh((ex).a_trsize) + le32toh((ex).a_drsize)) + +/* String table offset. */ +#define N_STROFF(ex) (N_SYMOFF(ex) + le32toh((ex).a_syms)) + +/* + * Header prepended to each a.out file. + * Only manipulate the a_midmag field via the + * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros. + */ + +struct exec { + uint32_t a_midmag; /* flags<<26 | mid<<16 | magic */ + uint32_t a_text; /* text segment size */ + uint32_t a_data; /* initialized data size */ + uint32_t a_bss; /* uninitialized data size */ + uint32_t a_syms; /* symbol table size */ + uint32_t a_entry; /* entry point */ + uint32_t a_trsize; /* text relocation size */ + uint32_t a_drsize; /* data relocation size */ +}; +#define a_magic a_midmag /* Hack for emulators */ + +/* a_magic */ +#define OMAGIC 0407 /* old impure format */ +#define NMAGIC 0410 /* read-only text */ +#define ZMAGIC 0413 /* demand load format */ +#define QMAGIC 0314 /* "compact" demand load format */ + +/* a_mid */ +#define MID_ZERO 0 /* unknown - implementation dependent */ +#define MID_SUN010 1 /* sun 68010/68020 binary */ +#define MID_SUN020 2 /* sun 68020-only binary */ +#define MID_I386 134 /* i386 BSD binary */ +#define MID_SPARC 138 /* sparc */ +#define MID_ARM6 143 /* ARM6 */ +#define MID_HP200 200 /* hp200 (68010) BSD binary */ +#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ +#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ +#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ + +/* + * a_flags + */ +#define EX_PIC 0x10 /* contains position independent code */ +#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */ +#define EX_DPMASK 0x30 /* mask for the above */ + +#ifdef _KERNEL +struct thread; +struct vnode; + +int aout_coredump(struct thread *td, struct vnode *vp, off_t limit, + int flags); +#endif + +#endif /* !_IMGACT_AOUT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/imgact_binmisc.h b/lib/libc/include/any-freebsd-any/sys/imgact_binmisc.h new file mode 100644 index 000000000000..ef976ade464b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/imgact_binmisc.h @@ -0,0 +1,174 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Stacey D. Son + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _IMGACT_BINMISC_H_ +#define _IMGACT_BINMISC_H_ + +/** + * Miscellaneous binary interpreter image activator. + */ + +#include /* for MAXPATHLEN */ + +/* + * Imgact bin misc parameters. + */ +#define IBE_VERSION 1 /* struct ximgact_binmisc_entry version. */ +#define IBE_NAME_MAX 32 /* Max size for entry name. */ +#define IBE_MAGIC_MAX 256 /* Max size for header magic and mask. */ +#define IBE_ARG_LEN_MAX 256 /* Max space for optional interpreter command- + line arguments separated by white space */ +#define IBE_INTERP_LEN_MAX (MAXPATHLEN + IBE_ARG_LEN_MAX) +#define IBE_MAX_ENTRIES 64 /* Max number of interpreter entries. */ + +/* + * Imgact bin misc interpreter entry flags. + */ +#define IBF_ENABLED 0x0001 /* Entry is active. */ +#define IBF_USE_MASK 0x0002 /* Use mask on header magic field. */ + +/* + * Used with sysctlbyname() to pass imgact bin misc entries in and out of the + * kernel. + */ +typedef struct ximgact_binmisc_entry { + uint32_t xbe_version; /* Struct version(IBE_VERSION) */ + uint32_t xbe_flags; /* Entry flags (IBF_*) */ + uint32_t xbe_moffset; /* Magic offset in header */ + uint32_t xbe_msize; /* Magic size */ + uint32_t spare[3]; /* Spare fields for future use */ + char xbe_name[IBE_NAME_MAX]; /* Unique interpreter name */ + char xbe_interpreter[IBE_INTERP_LEN_MAX]; /* Interpreter path + args */ + uint8_t xbe_magic[IBE_MAGIC_MAX]; /* Header Magic */ + uint8_t xbe_mask[IBE_MAGIC_MAX]; /* Magic Mask */ +} ximgact_binmisc_entry_t; + +/* + * sysctl() command names. + */ +#define IBE_SYSCTL_NAME "kern.binmisc" + +#define IBE_SYSCTL_NAME_ADD IBE_SYSCTL_NAME ".add" +#define IBE_SYSCTL_NAME_REMOVE IBE_SYSCTL_NAME ".remove" +#define IBE_SYSCTL_NAME_DISABLE IBE_SYSCTL_NAME ".disable" +#define IBE_SYSCTL_NAME_ENABLE IBE_SYSCTL_NAME ".enable" +#define IBE_SYSCTL_NAME_LOOKUP IBE_SYSCTL_NAME ".lookup" +#define IBE_SYSCTL_NAME_LIST IBE_SYSCTL_NAME ".list" + +#define KMOD_NAME "imgact_binmisc" + +/* + * Examples of manipulating the interpreter table using sysctlbyname(3): + * + * #include + * + * #define LLVM_MAGIC "BC\xc0\xde" + * + * #define MIPS64_ELF_MAGIC "\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00" \ + * "\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08" + * #define MIPS64_ELF_MASK "\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff" \ + * "\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" + * + * ximgact_binmisc_entry_t xbe, *xbep, out_xbe; + * size_t size = 0, osize; + * int error, i; + * + * // Add image activator for LLVM byte code + * bzero(&xbe, sizeof(xbe)); + * xbe.xbe_version = IBE_VERSION; + * xbe.xbe_flags = IBF_ENABLED; + * strlcpy(xbe.xbe_name, "llvm_bc", IBE_NAME_MAX); + * strlcpy(xbe.xbe_interpreter, "/usr/bin/lli --fake-arg0=#a", + * IBE_INTERP_LEN_MAX); + * xbe.xbe_moffset = 0; + * xbe.xbe_msize = 4; + * memcpy(xbe.xbe_magic, LLVM_MAGIC, xbe.xbe_msize); + * error = sysctlbyname(IBE_SYSCTL_NAME_ADD, NULL, NULL, &xbe, sizeof(xbe)); + * + * // Add image activator for mips64 ELF binaries to use qemu user mode + * bzero(&xbe, sizeof(xbe)); + * xbe.xbe_version = IBE_VERSION; + * xbe.xbe_flags = IBF_ENABLED | IBF_USE_MASK; + * strlcpy(xbe.xbe_name, "mips64elf", IBE_NAME_MAX); + * strlcpy(xbe.xbe_interpreter, "/usr/local/bin/qemu-mips64", + * IBE_INTERP_LEN_MAX); + * xbe.xbe_moffset = 0; + * xbe.xbe_msize = 20; + * memcpy(xbe.xbe_magic, MIPS64_ELF_MAGIC, xbe.xbe_msize); + * memcpy(xbe.xbe_mask, MIPS64_ELF_MASK, xbe.xbe_msize); + * sysctlbyname(IBE_SYSCTL_NAME_ADD, NULL, NULL, &xbe, sizeof(xbe)); + * + * // Disable (OR Enable OR Remove) image activator for LLVM byte code + * bzero(&xbe, sizeof(xbe)); + * xbe.xbe_version = IBE_VERSION; + * strlcpy(xbe.xbe_name, "llvm_bc", IBE_NAME_MAX); + * error = sysctlbyname(IBE_SYSCTL_NAME_DISABLE, NULL, NULL, &xbe, sizeof(xbe)); + * // OR sysctlbyname(IBE_SYSCTL_NAME_ENABLE, NULL, NULL, &xbe, sizeof(xbe)); + * // OR sysctlbyname(IBE_SYSCTL_NAME_REMOVE, NULL, NULL, &xbe, sizeof(xbe)); + * + * // Lookup image activator "llvm_bc" + * bzero(&xbe, sizeof(xbe)); + * xbe.xbe_version = IBE_VERSION; + * strlcpy(xbe.xbe_name, "llvm_bc", IBE_NAME_MAX); + * size = sizeof(out_xbe); + * error = sysctlbyname(IBE_SYSCTL_NAME_LOOKUP, &out_xbe, &size, &xbe, + * sizeof(xbe)); + * + * // Get all the currently configured image activators and report + * error = sysctlbyname(IBE_SYSCTL_NAME_LIST, NULL, &size, NULL, 0); + * if (0 == error && size > 0) { + * xbep = malloc(size); + * while(1) { + * osize = size; + * error = sysctlbyname("kern.binmisc.list", xbep, &size, NULL, 0); + * if (-1 == error && ENOMEM == errno && size == osize) { + * // The buffer too small and needs to grow + * size += sizeof(xbe); + * xbep = realloc(xbep, size); + * } else + * break; + * } + * } + * for(i = 0; i < (size / sizeof(xbe)); i++, xbep++) + * printf("name: %s interpreter: %s flags: %s %s\n", xbep->xbe_name, + * xbep->xbe_interpreter, (xbep->xbe_flags & IBF_ENABLED) ? + * "ENABLED" : "", (xbep->xbe_flags & IBF_ENABLED) ? "USE_MASK" : ""); + * + * The sysctlbyname() calls above may return the following errors in addition + * to the standard ones: + * + * [EINVAL] Invalid argument in the input ximgact_binmisc_entry_t structure. + * [EEXIST] Interpreter entry for given name already exist in kernel list. + * [ENOMEM] Allocating memory in the kernel failed or, in the case of + * kern.binmisc.list, the user buffer is too small. + * [ENOENT] Interpreter entry for given name is not found. + * [ENOSPC] Attempted to exceed maximum number of entries (IBE_MAX_ENTRIES). + */ + +#endif /* !_IMGACT_BINMISC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/imgact_elf.h b/lib/libc/include/any-freebsd-any/sys/imgact_elf.h new file mode 100644 index 000000000000..8bf5c5ab3b6d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/imgact_elf.h @@ -0,0 +1,111 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1995-1996 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_IMGACT_ELF_H_ +#define _SYS_IMGACT_ELF_H_ + +#include + +#ifdef _KERNEL + +#define AUXARGS_ENTRY(pos, id, val) \ + {(pos)->a_type = (id); (pos)->a_un.a_val = (val); (pos)++;} + +struct image_params; +struct thread; +struct vnode; + +/* + * Structure used to pass information from the loader to the + * stack fixup routine. + */ +typedef struct { + Elf_Ssize execfd; + Elf_Size phdr; + Elf_Size phent; + Elf_Size phnum; + Elf_Size pagesz; + Elf_Size base; + Elf_Size flags; + Elf_Size entry; + Elf_Word hdr_eflags; /* e_flags field from ehdr */ +} __ElfN(Auxargs); + +typedef struct { + Elf_Note hdr; + const char * vendor; + int flags; + bool (*trans_osrel)(const Elf_Note *, int32_t *); +#define BN_CAN_FETCH_OSREL 0x0001 /* Deprecated. */ +#define BN_TRANSLATE_OSREL 0x0002 /* Use trans_osrel to fetch osrel */ + /* after checking the image ABI specification, if needed. */ +} Elf_Brandnote; + +typedef struct { + int brand; + int machine; + const char *compat_3_brand; /* pre Binutils 2.10 method (FBSD 3) */ + const char *emul_path; + const char *interp_path; + struct sysentvec *sysvec; + const char *interp_newpath; + int flags; + Elf_Brandnote *brand_note; + boolean_t (*header_supported)(struct image_params *); +#define BI_CAN_EXEC_DYN 0x0001 +#define BI_BRAND_NOTE 0x0002 /* May have note.ABI-tag section. */ +#define BI_BRAND_NOTE_MANDATORY 0x0004 /* Must have note.ABI-tag section. */ +#define BI_BRAND_ONLY_STATIC 0x0008 /* Match only interp-less binaries. */ +} __ElfN(Brandinfo); + +__ElfType(Auxargs); +__ElfType(Brandinfo); + +#define MAX_BRANDS 8 + +int __elfN(brand_inuse)(Elf_Brandinfo *entry); +int __elfN(insert_brand_entry)(Elf_Brandinfo *entry); +int __elfN(remove_brand_entry)(Elf_Brandinfo *entry); +int __elfN(freebsd_fixup)(register_t **, struct image_params *); +int __elfN(coredump)(struct thread *, struct vnode *, off_t, int); +size_t __elfN(populate_note)(int, void *, void *, size_t, void **); +void __elfN(stackgap)(struct image_params *, u_long *); + +/* Machine specific function to dump per-thread information. */ +void __elfN(dump_thread)(struct thread *, void *, size_t *); + +extern int __elfN(fallback_brand); +extern Elf_Brandnote __elfN(freebsd_brandnote); +extern Elf_Brandnote __elfN(kfreebsd_brandnote); +#endif /* _KERNEL */ + +#endif /* !_SYS_IMGACT_ELF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/inflate.h b/lib/libc/include/any-freebsd-any/sys/inflate.h new file mode 100644 index 000000000000..b8461a6cf4e4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/inflate.h @@ -0,0 +1,53 @@ +/*- + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + * + */ +#ifndef _SYS_INFLATE_H_ +#define _SYS_INFLATE_H_ + +#if defined(_KERNEL) || defined(KZIP) + +#define GZ_EOF -1 + +#define GZ_WSIZE 0x8000 + +/* + * Global variables used by inflate and friends. + * This structure is used in order to make inflate() reentrant. + */ +struct inflate { + /* Public part */ + + /* This pointer is passed along to the two functions below */ + void *gz_private; + + /* Fetch next character to be uncompressed */ + int (*gz_input)(void *); + + /* Dispose of uncompressed characters */ + int (*gz_output)(void *, u_char *, u_long); + + /* Private part */ + u_long gz_bb; /* bit buffer */ + unsigned gz_bk; /* bits in bit buffer */ + unsigned gz_hufts; /* track memory usage */ + struct huft *gz_fixed_tl; /* must init to NULL !! */ + struct huft *gz_fixed_td; + int gz_fixed_bl; + int gz_fixed_bd; + u_char *gz_slide; + unsigned gz_wp; +}; + +int inflate(struct inflate *); + +#endif /* _KERNEL || KZIP */ + +#endif /* ! _SYS_INFLATE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/interrupt.h b/lib/libc/include/any-freebsd-any/sys/interrupt.h new file mode 100644 index 000000000000..2b66b7ae4597 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/interrupt.h @@ -0,0 +1,202 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997, Stefan Esser + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_INTERRUPT_H_ +#define _SYS_INTERRUPT_H_ + +#include +#include +#include + +struct intr_event; +struct intr_thread; +struct trapframe; + +/* + * Describe a hardware interrupt handler. + * + * Multiple interrupt handlers for a specific event can be chained + * together. + */ +struct intr_handler { + driver_filter_t *ih_filter; /* Filter handler function. */ + driver_intr_t *ih_handler; /* Threaded handler function. */ + void *ih_argument; /* Argument to pass to handlers. */ + int ih_flags; + char ih_name[MAXCOMLEN + 1]; /* Name of handler. */ + struct intr_event *ih_event; /* Event we are connected to. */ + int ih_need; /* Needs service. */ + CK_SLIST_ENTRY(intr_handler) ih_next; /* Next handler for this event. */ + u_char ih_pri; /* Priority of this handler. */ + struct intr_thread *ih_thread; /* Ithread for filtered handler. */ +}; + +/* Interrupt handle flags kept in ih_flags */ +#define IH_EXCLUSIVE 0x00000002 /* Exclusive interrupt. */ +#define IH_ENTROPY 0x00000004 /* Device is a good entropy source. */ +#define IH_DEAD 0x00000008 /* Handler should be removed. */ +#define IH_SUSP 0x00000010 /* Device is powered down. */ +#define IH_CHANGED 0x40000000 /* Handler state is changed. */ +#define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */ + +/* + * Describe an interrupt event. An event holds a list of handlers. + * The 'pre_ithread', 'post_ithread', 'post_filter', and 'assign_cpu' + * hooks are used to invoke MD code for certain operations. + * + * The 'pre_ithread' hook is called when an interrupt thread for + * handlers without filters is scheduled. It is responsible for + * ensuring that 1) the system won't be swamped with an interrupt + * storm from the associated source while the ithread runs and 2) the + * current CPU is able to receive interrupts from other interrupt + * sources. The first is usually accomplished by disabling + * level-triggered interrupts until the ithread completes. The second + * is accomplished on some platforms by acknowledging the interrupt + * via an EOI. + * + * The 'post_ithread' hook is invoked when an ithread finishes. It is + * responsible for ensuring that the associated interrupt source will + * trigger an interrupt when it is asserted in the future. Usually + * this is implemented by enabling a level-triggered interrupt that + * was previously disabled via the 'pre_ithread' hook. + * + * The 'post_filter' hook is invoked when a filter handles an + * interrupt. It is responsible for ensuring that the current CPU is + * able to receive interrupts again. On some platforms this is done + * by acknowledging the interrupts via an EOI. + * + * The 'assign_cpu' hook is used to bind an interrupt source to a + * specific CPU. If the interrupt cannot be bound, this function may + * return an error. + * + * Note that device drivers may also use interrupt events to manage + * multiplexing interrupt interrupt handler into handlers for child + * devices. In that case, the above hooks are not used. The device + * can create an event for its interrupt resource and register child + * event handlers with that event. It can then use + * intr_event_execute_handlers() to execute non-filter handlers. + * Currently filter handlers are not supported by this, but that can + * be added by splitting out the filter loop from intr_event_handle() + * if desired. + */ +struct intr_event { + TAILQ_ENTRY(intr_event) ie_list; + CK_SLIST_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */ + char ie_name[MAXCOMLEN + 1]; /* Individual event name. */ + char ie_fullname[MAXCOMLEN + 1]; + struct mtx ie_lock; + void *ie_source; /* Cookie used by MD code. */ + struct intr_thread *ie_thread; /* Thread we are connected to. */ + void (*ie_pre_ithread)(void *); + void (*ie_post_ithread)(void *); + void (*ie_post_filter)(void *); + int (*ie_assign_cpu)(void *, int); + int ie_flags; + int ie_count; /* Loop counter. */ + int ie_warncnt; /* Rate-check interrupt storm warns. */ + struct timeval ie_warntm; + int ie_irq; /* Physical irq number if !SOFT. */ + int ie_cpu; /* CPU this event is bound to. */ + volatile int ie_phase; /* Switched to establish a barrier. */ + volatile int ie_active[2]; /* Filters in ISR context. */ +}; + +/* Interrupt event flags kept in ie_flags. */ +#define IE_SOFT 0x000001 /* Software interrupt. */ +#define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */ +#define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */ + +/* Flags to pass to swi_sched. */ +#define SWI_FROMNMI 0x1 +#define SWI_DELAY 0x2 + +/* + * Software interrupt numbers in priority order. The priority determines + * the priority of the corresponding interrupt thread. + */ +#define SWI_TTY 0 +#define SWI_NET 1 +#define SWI_CAMBIO 2 +#define SWI_VM 3 +#define SWI_CLOCK 4 +#define SWI_TQ_FAST 5 +#define SWI_TQ 6 +#define SWI_TQ_GIANT 6 + +struct proc; + +extern struct intr_event *tty_intr_event; +extern struct intr_event *clk_intr_event; +extern void *vm_ih; + +/* Counts and names for statistics (defined in MD code). */ +#if defined(__amd64__) || defined(__i386__) +extern u_long *intrcnt; /* counts for for each device and stray */ +extern char *intrnames; /* string table containing device names */ +#else +extern u_long intrcnt[]; /* counts for for each device and stray */ +extern char intrnames[]; /* string table containing device names */ +#endif +extern size_t sintrcnt; /* size of intrcnt table */ +extern size_t sintrnames; /* size of intrnames table */ + +#ifdef DDB +void db_dump_intr_event(struct intr_event *ie, int handlers); +#endif +u_char intr_priority(enum intr_type flags); +int intr_event_add_handler(struct intr_event *ie, const char *name, + driver_filter_t filter, driver_intr_t handler, void *arg, + u_char pri, enum intr_type flags, void **cookiep); +int intr_event_bind(struct intr_event *ie, int cpu); +int intr_event_bind_irqonly(struct intr_event *ie, int cpu); +int intr_event_bind_ithread(struct intr_event *ie, int cpu); +int intr_event_create(struct intr_event **event, void *source, + int flags, int irq, void (*pre_ithread)(void *), + void (*post_ithread)(void *), void (*post_filter)(void *), + int (*assign_cpu)(void *, int), const char *fmt, ...) + __printflike(9, 10); +int intr_event_describe_handler(struct intr_event *ie, void *cookie, + const char *descr); +int intr_event_destroy(struct intr_event *ie); +int intr_event_handle(struct intr_event *ie, struct trapframe *frame); +int intr_event_remove_handler(void *cookie); +int intr_event_suspend_handler(void *cookie); +int intr_event_resume_handler(void *cookie); +int intr_getaffinity(int irq, int mode, void *mask); +void *intr_handler_source(void *cookie); +int intr_setaffinity(int irq, int mode, void *mask); +void _intr_drain(int irq); /* Linux compat only. */ +int swi_add(struct intr_event **eventp, const char *name, + driver_intr_t handler, void *arg, int pri, enum intr_type flags, + void **cookiep); +void swi_sched(void *cookie, int flags); +int swi_remove(void *cookie); + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/intr.h b/lib/libc/include/any-freebsd-any/sys/intr.h new file mode 100644 index 000000000000..74e2ae195b92 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/intr.h @@ -0,0 +1,164 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015-2016 Svatopluk Kraus + * Copyright (c) 2015-2016 Michal Meloun + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_INTR_H_ +#define _SYS_INTR_H_ +#ifndef INTRNG +#error Need INTRNG for this file +#endif + +#include + +#define INTR_IRQ_INVALID 0xFFFFFFFF + +enum intr_map_data_type { + INTR_MAP_DATA_ACPI = 0, + INTR_MAP_DATA_FDT, + INTR_MAP_DATA_GPIO, + INTR_MAP_DATA_MSI, + + /* Placeholders for platform specific types */ + INTR_MAP_DATA_PLAT_1 = 1000, + INTR_MAP_DATA_PLAT_2, + INTR_MAP_DATA_PLAT_3, + INTR_MAP_DATA_PLAT_4, + INTR_MAP_DATA_PLAT_5, +}; + +struct intr_map_data { + size_t len; + enum intr_map_data_type type; +}; + +struct intr_map_data_msi { + struct intr_map_data hdr; + struct intr_irqsrc *isrc; +}; + +#ifdef notyet +#define INTR_SOLO INTR_MD1 +typedef int intr_irq_filter_t(void *arg, struct trapframe *tf); +#else +typedef int intr_irq_filter_t(void *arg); +#endif +typedef int intr_child_irq_filter_t(void *arg, uintptr_t irq); + +#define INTR_ISRC_NAMELEN (MAXCOMLEN + 1) + +#define INTR_ISRCF_IPI 0x01 /* IPI interrupt */ +#define INTR_ISRCF_PPI 0x02 /* PPI interrupt */ +#define INTR_ISRCF_BOUND 0x04 /* bound to a CPU */ + +struct intr_pic; + +/* Interrupt source definition. */ +struct intr_irqsrc { + device_t isrc_dev; /* where isrc is mapped */ + u_int isrc_irq; /* unique identificator */ + u_int isrc_flags; + char isrc_name[INTR_ISRC_NAMELEN]; + cpuset_t isrc_cpu; /* on which CPUs is enabled */ + u_int isrc_index; + u_long * isrc_count; + u_int isrc_handlers; + struct intr_event * isrc_event; +#ifdef INTR_SOLO + intr_irq_filter_t * isrc_filter; + void * isrc_arg; +#endif +}; + +/* Intr interface for PIC. */ +int intr_isrc_deregister(struct intr_irqsrc *); +int intr_isrc_register(struct intr_irqsrc *, device_t, u_int, const char *, ...) + __printflike(4, 5); + +#ifdef SMP +bool intr_isrc_init_on_cpu(struct intr_irqsrc *isrc, u_int cpu); +#endif + +int intr_isrc_dispatch(struct intr_irqsrc *, struct trapframe *); +u_int intr_irq_next_cpu(u_int current_cpu, cpuset_t *cpumask); + +struct intr_pic *intr_pic_register(device_t, intptr_t); +int intr_pic_deregister(device_t, intptr_t); +int intr_pic_claim_root(device_t, intptr_t, intr_irq_filter_t *, void *, u_int); +struct intr_pic *intr_pic_add_handler(device_t, struct intr_pic *, + intr_child_irq_filter_t *, void *, uintptr_t, uintptr_t); + +extern device_t intr_irq_root_dev; + +/* Intr interface for BUS. */ + +int intr_activate_irq(device_t, struct resource *); +int intr_deactivate_irq(device_t, struct resource *); + +int intr_setup_irq(device_t, struct resource *, driver_filter_t, driver_intr_t, + void *, int, void **); +int intr_teardown_irq(device_t, struct resource *, void *); + +int intr_describe_irq(device_t, struct resource *, void *, const char *); +int intr_child_irq_handler(struct intr_pic *, uintptr_t); + +/* Intr resources mapping. */ +struct intr_map_data *intr_alloc_map_data(enum intr_map_data_type, size_t, int); +void intr_free_intr_map_data(struct intr_map_data *); +u_int intr_map_irq(device_t, intptr_t, struct intr_map_data *); +void intr_unmap_irq(u_int ); +u_int intr_map_clone_irq(u_int ); + +/* MSI/MSI-X handling */ +int intr_msi_register(device_t, intptr_t); +int intr_alloc_msi(device_t, device_t, intptr_t, int, int, int *); +int intr_release_msi(device_t, device_t, intptr_t, int, int *); +int intr_map_msi(device_t, device_t, intptr_t, int, uint64_t *, uint32_t *); +int intr_alloc_msix(device_t, device_t, intptr_t, int *); +int intr_release_msix(device_t, device_t, intptr_t, int); + +#ifdef SMP +int intr_bind_irq(device_t, struct resource *, int); + +void intr_pic_init_secondary(void); + +/* Virtualization for interrupt source IPI counter increment. */ +static inline void +intr_ipi_increment_count(u_long *counter, u_int cpu) +{ + + KASSERT(cpu < MAXCPU, ("%s: too big cpu %u", __func__, cpu)); + counter[cpu]++; +} + +/* Virtualization for interrupt source IPI counters setup. */ +u_long * intr_ipi_setup_counters(const char *name); + +#endif +#endif /* _SYS_INTR_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/ioccom.h b/lib/libc/include/any-freebsd-any/sys/ioccom.h new file mode 100644 index 000000000000..3e5f7200fb1a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ioccom.h @@ -0,0 +1,86 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ioccom.h 8.2 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS_IOCCOM_H_ +#define _SYS_IOCCOM_H_ + +/* + * Ioctl's have the command encoded in the lower word, and the size of + * any in or out parameters in the upper word. The high 3 bits of the + * upper word are used to encode the in/out status of the parameter. + */ +#define IOCPARM_SHIFT 13 /* number of bits for ioctl size */ +#define IOCPARM_MASK ((1 << IOCPARM_SHIFT) - 1) /* parameter length mask */ +#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) +#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16)) +#define IOCGROUP(x) (((x) >> 8) & 0xff) + +#define IOCPARM_MAX (1 << IOCPARM_SHIFT) /* max size of ioctl */ +#define IOC_VOID 0x20000000 /* no parameters */ +#define IOC_OUT 0x40000000 /* copy out parameters */ +#define IOC_IN 0x80000000 /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) +#define IOC_DIRMASK (IOC_VOID|IOC_OUT|IOC_IN) + +#define _IOC(inout,group,num,len) ((unsigned long) \ + ((inout) | (((len) & IOCPARM_MASK) << 16) | ((group) << 8) | (num))) +#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) +#define _IOWINT(g,n) _IOC(IOC_VOID, (g), (n), sizeof(int)) +#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) +#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) +/* this should be _IORW, but stdio got there first */ +#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) +/* Replace length/type in an ioctl command. */ +#define _IOC_NEWLEN(ioc, len) \ + (((~(IOCPARM_MASK << 16)) & (ioc)) | (((len) & IOCPARM_MASK) << 16)) +#define _IOC_NEWTYPE(ioc, type) _IOC_NEWLEN((ioc), sizeof(type)) + +#ifdef _KERNEL + +#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD4) || defined(COMPAT_43) +#define IOCPARM_IVAL(x) ((int)(intptr_t)(void *)*(caddr_t *)(void *)(x)) +#endif + +#else + +#include + +__BEGIN_DECLS +int ioctl(int, unsigned long, ...); +__END_DECLS + +#endif + +#endif /* !_SYS_IOCCOM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ioctl.h b/lib/libc/include/any-freebsd-any/sys/ioctl.h new file mode 100644 index 000000000000..e63a64d25ed0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ioctl.h @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ioctl.h 8.6 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS_IOCTL_H_ +#define _SYS_IOCTL_H_ + +#ifdef _KERNEL +#error "Don't #include ioctl.h in the kernel. Include xxxio.h instead." +#endif /* _KERNEL */ + +#include + +#include +#include +#include + +#endif /* !_SYS_IOCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ioctl_compat.h b/lib/libc/include/any-freebsd-any/sys/ioctl_compat.h new file mode 100644 index 000000000000..8ec21990345e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ioctl_compat.h @@ -0,0 +1,154 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ioctl_compat.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_IOCTL_COMPAT_H_ +#define _SYS_IOCTL_COMPAT_H_ + +#ifndef COMPAT_43TTY +#error "Definitions not available without TTY ioctl compat." +#endif + +struct tchars { + char t_intrc; /* interrupt */ + char t_quitc; /* quit */ + char t_startc; /* start output */ + char t_stopc; /* stop output */ + char t_eofc; /* end-of-file */ + char t_brkc; /* input delimiter (like nl) */ +}; + +struct ltchars { + char t_suspc; /* stop process signal */ + char t_dsuspc; /* delayed stop process signal */ + char t_rprntc; /* reprint line */ + char t_flushc; /* flush output (toggles) */ + char t_werasc; /* word erase */ + char t_lnextc; /* literal next character */ +}; + +/* + * Structure for TIOCGETP and TIOCSETP ioctls. + */ +struct sgttyb { + char sg_ispeed; /* input speed */ + char sg_ospeed; /* output speed */ + char sg_erase; /* erase character */ + char sg_kill; /* kill character */ + short sg_flags; /* mode flags */ +}; + +#define OTIOCGETD _IOR('t', 0, int) /* get line discipline */ +#define OTIOCSETD _IOW('t', 1, int) /* set line discipline */ +#define TIOCHPCL _IO('t', 2) /* hang up on last close */ +#define TIOCGETP _IOR('t', 8, struct sgttyb) /* get parameters */ +#define TIOCSETP _IOW('t', 9, struct sgttyb) /* set parameters */ +#define TIOCSETN _IOW('t',10, struct sgttyb) /* as above, but no flush */ +#define TIOCSETC _IOW('t',17, struct tchars) /* set special characters */ +#define TIOCGETC _IOR('t',18, struct tchars) /* get special characters */ +#define TANDEM 0x00000001 /* send stopc on out q full */ +#define CBREAK 0x00000002 /* half-cooked mode */ +#define LCASE 0x00000004 /* simulate lower case */ +#define ECHO 0x00000008 /* echo input */ +#define CRMOD 0x00000010 /* map \r to \r\n on output */ +#define RAW 0x00000020 /* no i/o processing */ +#define ODDP 0x00000040 /* get/send odd parity */ +#define EVENP 0x00000080 /* get/send even parity */ +#define ANYP 0x000000c0 /* get any parity/send none */ +#define NLDELAY 0x00000300 /* \n delay */ +#define NL0 0x00000000 +#define NL1 0x00000100 /* tty 37 */ +#define NL2 0x00000200 /* vt05 */ +#define NL3 0x00000300 +#define TBDELAY 0x00000c00 /* horizontal tab delay */ +#define TAB0 0x00000000 +#define TAB1 0x00000400 /* tty 37 */ +#define TAB2 0x00000800 +#define XTABS 0x00000c00 /* expand tabs on output */ +#define CRDELAY 0x00003000 /* \r delay */ +#define CR0 0x00000000 +#define CR1 0x00001000 /* tn 300 */ +#define CR2 0x00002000 /* tty 37 */ +#define CR3 0x00003000 /* concept 100 */ +#define VTDELAY 0x00004000 /* vertical tab delay */ +#define FF0 0x00000000 +#define FF1 0x00004000 /* tty 37 */ +#define BSDELAY 0x00008000 /* \b delay */ +#define BS0 0x00000000 +#define BS1 0x00008000 +#define ALLDELAY (NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY) +#define CRTBS 0x00010000 /* do backspacing for crt */ +#define PRTERA 0x00020000 /* \ ... / erase */ +#define CRTERA 0x00040000 /* " \b " to wipe out char */ +#define TILDE 0x00080000 /* hazeltine tilde kludge */ +#define MDMBUF 0x00100000 /*start/stop output on carrier*/ +#define LITOUT 0x00200000 /* literal output */ +#define TOSTOP 0x00400000 /*SIGSTOP on background output*/ +#define FLUSHO 0x00800000 /* flush output to terminal */ +#define NOHANG 0x01000000 /* (no-op) was no SIGHUP on carrier drop */ +#define L001000 0x02000000 +#define CRTKIL 0x04000000 /* kill line with " \b " */ +#define PASS8 0x08000000 +#define CTLECH 0x10000000 /* echo control chars as ^X */ +#define PENDIN 0x20000000 /* tp->t_rawq needs reread */ +#define DECCTQ 0x40000000 /* only ^Q starts after ^S */ +#define NOFLSH 0x80000000 /* no output flush on signal */ +#define OTIOCCONS _IO('t', 98) /* for hp300 -- sans int arg */ +#define TIOCGLTC _IOR('t', 116,struct ltchars) /* get special chars */ +#define TIOCSLTC _IOW('t', 117,struct ltchars) /* set special chars */ +#define TIOCLGET _IOR('t', 124, int) /* get local modes */ +#define LCRTBS (CRTBS>>16) +#define LPRTERA (PRTERA>>16) +#define LCRTERA (CRTERA>>16) +#define LTILDE (TILDE>>16) +#define LMDMBUF (MDMBUF>>16) +#define LLITOUT (LITOUT>>16) +#define LTOSTOP (TOSTOP>>16) +#define LFLUSHO (FLUSHO>>16) +#define LNOHANG (NOHANG>>16) +#define LCRTKIL (CRTKIL>>16) +#define LPASS8 (PASS8>>16) +#define LCTLECH (CTLECH>>16) +#define LPENDIN (PENDIN>>16) +#define LDECCTQ (DECCTQ>>16) +#define LNOFLSH (NOFLSH>>16) +#define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */ +#define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */ +#define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */ + +#endif /* !_SYS_IOCTL_COMPAT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/iov.h b/lib/libc/include/any-freebsd-any/sys/iov.h new file mode 100644 index 000000000000..3be01180a107 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/iov.h @@ -0,0 +1,259 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013-2015 Sandvine Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_IOV_H_ +#define _SYS_IOV_H_ + +#include + +#define PF_CONFIG_NAME "PF" +#define VF_SCHEMA_NAME "VF" + +#define VF_PREFIX "VF-" +#define VF_PREFIX_LEN 3 +#define VF_NUM_LEN 5 /* The maximum VF num is 65535. */ +#define VF_MAX_NAME (VF_PREFIX_LEN + VF_NUM_LEN + 1) + +#define DRIVER_CONFIG_NAME "DRIVER" +#define IOV_CONFIG_NAME "IOV" + +#define TYPE_SCHEMA_NAME "TYPE" +#define DEFAULT_SCHEMA_NAME "DEFAULT" +#define REQUIRED_SCHEMA_NAME "REQUIRED" + +/* + * Because each PF device is expected to expose a unique set of possible + * configurations, the SR-IOV infrastructure dynamically queries the PF + * driver for its capabilities. These capabilities are exposed to userland + * with a configuration schema. The schema is exported from the kernel as a + * packed nvlist. See nv(3) for the details of the nvlist API. The expected + * format of the nvlist is: + * + * BASIC RULES + * 1) All keys are case-insensitive. + * 2) No keys that are not specified below may exist at any level of the + * schema. + * 3) All keys are mandatory unless explicitly documented as optional. If a + * key is mandatory then the associated value is also mandatory. + * 4) Order of keys is irrelevant. + * + * TOP LEVEL + * 1) There must be a top-level key with the name PF_CONFIG_NAME. The value + * associated with this key is a nvlist that follows the device schema + * node format. The parameters in this node specify the configuration + * parameters that may be applied to a PF. + * 2) There must be a top-level key with the name VF_SCHEMA_NAME. The value + * associated with this key is a nvlist that follows the device schema + * node format. The parameters in this node specify the configuration + * parameters that may be applied to a VF. + * + * DEVICE SCHEMA NODE + * 1) There must be a key with the name DRIVER_CONFIG_NAME. The value + * associated with this key is a nvlist that follows the device/subsystem + * schema node format. The parameters in this node specify the + * configuration parameters that are specific to a particular device + * driver. + * 2) There must be a key with the name IOV_CONFIG_NAME. The value associated + * with this key is an nvlist that follows the device/subsystem schema node + * format. The parameters in this node specify the configuration + * parameters that are applied by the SR-IOV infrastructure. + * + * DEVICE/SUBSYSTEM SCHEMA NODE + * 1) All keys in the device/subsystem schema node are optional. + * 2) Each key specifies the name of a valid configuration parameter that may + * be applied to the device/subsystem combination specified by this node. + * The value associated with the key specifies the format of valid + * configuration values, and must be a nvlist in parameter schema node + * format. + * + * PARAMETER SCHEMA NODE + * 1) The parameter schema node must contain a key with the name + * TYPE_SCHEMA_NAME. The value associated with this key must be a string. + * This string specifies the type of value that the parameter specified by + * this node must take. The string must have one of the following values: + * - "bool" - The configuration value must be a boolean. + * - "mac-addr" - The configuration value must be a binary value. In + * addition, the value must be exactly 6 bytes long and + * the value must not be a multicast or broadcast mac. + * - "uint8_t" - The configuration value must be a integer value in + * the range [0, UINT8_MAX]. + * - "uint16_t" - The configuration value must be a integer value in + * the range [0, UINT16_MAX]. + * - "uint32_t" - The configuration value must be a integer value in + * the range [0, UINT32_MAX]. + * - "uint64_t" - The configuration value must be a integer value in + * the range [0, UINT64_MAX]. + * 2) The parameter schema may contain a key with the name + * REQUIRED_SCHEMA_NAME. This key is optional. If this key is present, the + * value associated with it must have a boolean type. If the value is true, + * then the parameter specified by this schema is a required parameter. All + * valid configurations must include all required parameters. + * 3) The parameter schema may contain a key with the name DEFAULT_SCHEMA_NAME. + * This key is optional. This key must not be present if the parameter + * specified by this schema is required. If this key is present, the value + * associated with the parent key must follow all restrictions specified by + * the type specified by this schema. If a configuration does not supply a + * value for the parameter specified by this schema, then the kernel will + * apply the value associated with this key in its place. + * + * The following is an example of a valid schema, as printed by nvlist_dump. + * Keys are printed followed by the type of the value in parantheses. The + * value is displayed following a colon. The indentation level reflects the + * level of nesting of nvlists. String values are displayed between [] + * brackets. Binary values are shown with the length of the binary value (in + * bytes) followed by the actual binary values. + * + * PF (NVLIST): + * IOV (NVLIST): + * num_vfs (NVLIST): + * type (STRING): [uint16_t] + * required (BOOL): TRUE + * device (NVLIST): + * type (STRING): [string] + * required (BOOL): TRUE + * DRIVER (NVLIST): + * VF (NVLIST): + * IOV (NVLIST): + * passthrough (NVLIST): + * type (STRING): [bool] + * default (BOOL): FALSE + * DRIVER (NVLIST): + * mac-addr (NVLIST): + * type (STRING): [mac-addr] + * default (BINARY): 6 000000000000 + * vlan (NVLIST): + * type (STRING): [uint16_t] + * spoof-check (NVLIST): + * type (STRING): [bool] + * default (BOOL): TRUE + * allow-set-mac (NVLIST): + * type (STRING): [bool] + * default (BOOL): FALSE + */ +struct pci_iov_schema +{ + void *schema; + size_t len; + int error; +}; + +/* + * SR-IOV configuration is passed to the kernel as a packed nvlist. See nv(3) + * for the details of the nvlist API. The expected format of the nvlist is: + * + * BASIC RULES + * 1) All keys are case-insensitive. + * 2) No keys that are not specified below may exist at any level of the + * config nvlist. + * 3) Unless otherwise specified, all keys are optional. It should go without + * saying a key being mandatory is transitive: that is, if a key is + * specified to contain a sub-nodes that contains a mandatory key, then + * the outer key is implicitly mandatory. If a key is mandatory then the + * associated value is also mandatory. + * 4) Order of keys is irrelevant. + * + * TOP LEVEL OF CONFIG NVLIST + * 1) All keys specified in this section are mandatory. + * 2) There must be a top-level key with the name PF_CONFIG_NAME. The value + * associated is an nvlist that follows the "device node" format. The + * parameters in this node specify parameters that apply to the PF. + * 3) For every VF being configured (this is set via the "num_vfs" parameter + * in the PF section), there must be a top-level key whose name is VF_PREFIX + * immediately followed by the index of the VF as a decimal integer. For + * example, this would be VF-0 for the first VF. VFs are numbered starting + * from 0. The value associated with this key follows the "device node" + * format. The parameters in this node specify configuration that applies + * to the VF specified in the key. Leading zeros are not permitted in VF + * index. Configuration for the second VF must be specified in a node with + * the key VF-1. VF-01 is not a valid key. + * + * DEVICE NODES + * 1) All keys specified in this section are mandatory. + * 2) The device node must contain a key with the name DRIVER_CONFIG_NAME. The + * value associated with this key is an nvlist following the subsystem node + * format. The parameters in this key specify configuration that is specific + * to a particular device driver. + * 3) The device node must contain a key with the name IOV_CONFIG_NAME. The + * value associated with this key is an nvlist following the subsystem node + * format. The parameters in this key specify configuration that is consumed + * by the SR-IOV infrastructure. + * + * SUBSYSTEM NODES + * 1) A subsystem node specifies configuration parameters that apply to a + * particular subsystem (driver or infrastructure) of a particular device + * (PF or individual VF). + * Note: We will refer to the section of the configuration schema that + * specifies the parameters for this subsystem and device + * configuration as the device/subystem schema. + * 2) The subsystem node must contain only keys that correspond to parameters + * that are specified in the device/subsystem schema. + * 3) Every parameter specified as required in the device/subsystem schema is + * a mandatory key in the subsystem node. + * Note: All parameters that are not required in device/subsystem schema are + * optional keys. In particular, any parameter specified to have a + * default value in the device/subsystem schema is optional. The + * kernel is responsible for applying default values. + * 4) The value of every parameter in the device node must conform to the + * restrictions of the type specified for that parameter in the device/ + * subsystem schema. + * + * The following is an example of a valid configuration, when validated against + * the schema example given above. + * + * PF (NVLIST): + * driver (NVLIST): + * iov (NVLIST): + * num_vfs (NUMBER): 3 (3) (0x3) + * device (STRING): [ix0] + * VF-0 (NVLIST): + * driver (NVLIST): + * vlan (NUMBER): 1000 (1000) (0x3e8) + * iov (NVLIST): + * passthrough (BOOL): TRUE + * VF-1 (NVLIST): + * driver (NVLIST): + * iov (NVLIST): + * VF-2 (NVLIST): + * driver (NVLIST): + * mac-addr (BINARY): 6 020102030405 + * iov (NVLIST): + */ +struct pci_iov_arg +{ + void *config; + size_t len; +}; + +#define IOV_CONFIG _IOW('p', 10, struct pci_iov_arg) +#define IOV_DELETE _IO('p', 11) +#define IOV_GET_SCHEMA _IOWR('p', 12, struct pci_iov_schema) + +#endif + diff --git a/lib/libc/include/any-freebsd-any/sys/iov_schema.h b/lib/libc/include/any-freebsd-any/sys/iov_schema.h new file mode 100644 index 000000000000..12e120795bef --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/iov_schema.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014-2015 Sandvine Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_IOV_SCHEMA_H_ +#define _SYS_IOV_SCHEMA_H_ + +#define IOV_SCHEMA_HASDEFAULT (1 << 0) +#define IOV_SCHEMA_REQUIRED (1 << 1) + +nvlist_t *pci_iov_schema_alloc_node(void); + +void pci_iov_schema_add_bool(nvlist_t *schema, const char *name, + uint32_t flags, int defaultVal); +void pci_iov_schema_add_string(nvlist_t *schema, const char *name, + uint32_t flags, const char *defaultVal); +void pci_iov_schema_add_uint8(nvlist_t *schema, const char *name, + uint32_t flags, uint8_t defaultVal); +void pci_iov_schema_add_uint16(nvlist_t *schema, const char *name, + uint32_t flags, uint16_t defaultVal); +void pci_iov_schema_add_uint32(nvlist_t *schema, const char *name, + uint32_t flags, uint32_t defaultVal); +void pci_iov_schema_add_uint64(nvlist_t *schema, const char *name, + uint32_t flags, uint64_t defaultVal); +void pci_iov_schema_add_unicast_mac(nvlist_t *schema, const char *name, + uint32_t flags, const uint8_t * defaultVal); + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/ipc.h b/lib/libc/include/any-freebsd-any/sys/ipc.h new file mode 100644 index 000000000000..a0bd61f7f07d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ipc.h @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ipc.h 8.4 (Berkeley) 2/19/95 + * $FreeBSD$ + */ + +/* + * SVID compatible ipc.h file + */ +#ifndef _SYS_IPC_H_ +#define _SYS_IPC_H_ + +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _KEY_T_DECLARED +typedef __key_t key_t; +#define _KEY_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \ + defined(COMPAT_43) +struct ipc_perm_old { + unsigned short cuid; /* creator user id */ + unsigned short cgid; /* creator group id */ + unsigned short uid; /* user id */ + unsigned short gid; /* group id */ + unsigned short mode; /* r/w permission */ + unsigned short seq; /* sequence # (to generate unique ipcid) */ + key_t key; /* user specified msg/sem/shm key */ +}; +#endif + +struct ipc_perm { + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* r/w permission */ + unsigned short seq; /* sequence # (to generate unique ipcid) */ + key_t key; /* user specified msg/sem/shm key */ +}; + +#if __BSD_VISIBLE +/* common mode bits */ +#define IPC_R 000400 /* read permission */ +#define IPC_W 000200 /* write/alter permission */ +#define IPC_M 010000 /* permission to change control info */ +#endif + +/* SVID required constants (same values as system 5) */ +#define IPC_CREAT 001000 /* create entry if key does not exist */ +#define IPC_EXCL 002000 /* fail if key exists */ +#define IPC_NOWAIT 004000 /* error if request must wait */ + +#define IPC_PRIVATE (key_t)0 /* private key */ + +#define IPC_RMID 0 /* remove identifier */ +#define IPC_SET 1 /* set options */ +#define IPC_STAT 2 /* get options */ +#if __BSD_VISIBLE +/* + * For Linux compatibility. + */ +#define IPC_INFO 3 /* get info */ +#endif + +#if defined(_KERNEL) || defined(_WANT_SYSVIPC_INTERNALS) +/* Macros to convert between ipc ids and array indices or sequence ids */ +#define IPCID_TO_IX(id) ((id) & 0xffff) +#define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) +#define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff)) +#endif + +#ifdef _KERNEL +struct thread; +struct proc; +struct vmspace; + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) +void ipcperm_old2new(struct ipc_perm_old *, struct ipc_perm *); +void ipcperm_new2old(struct ipc_perm *, struct ipc_perm_old *); +#endif + +int ipcperm(struct thread *, struct ipc_perm *, int); +extern void (*shmfork_hook)(struct proc *, struct proc *); +extern void (*shmexit_hook)(struct vmspace *); + +#else /* ! _KERNEL */ + +__BEGIN_DECLS +key_t ftok(const char *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_IPC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ipmi.h b/lib/libc/include/any-freebsd-any/sys/ipmi.h new file mode 100644 index 000000000000..e5b962725287 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ipmi.h @@ -0,0 +1,181 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 IronPort Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __SYS_IPMI_H__ +#define __SYS_IPMI_H__ + +#define IPMI_MAX_ADDR_SIZE 0x20 +#define IPMI_MAX_RX 1024 +#define IPMI_BMC_SLAVE_ADDR 0x20 /* Linux Default slave address */ +#define IPMI_BMC_CHANNEL 0x0f /* Linux BMC channel */ + +#define IPMI_BMC_SMS_LUN 0x02 + +#define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c +#define IPMI_IPMB_ADDR_TYPE 0x01 +#define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x41 + +#define IPMI_IOC_MAGIC 'i' +#define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, struct ipmi_recv) +#define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, struct ipmi_recv) +#define IPMICTL_SEND_COMMAND _IOW(IPMI_IOC_MAGIC, 13, struct ipmi_req) +#define IPMICTL_REGISTER_FOR_CMD _IOW(IPMI_IOC_MAGIC, 14, struct ipmi_cmdspec) +#define IPMICTL_UNREGISTER_FOR_CMD _IOW(IPMI_IOC_MAGIC, 15, struct ipmi_cmdspec) +#define IPMICTL_SET_GETS_EVENTS_CMD _IOW(IPMI_IOC_MAGIC, 16, int) +#define IPMICTL_SET_MY_ADDRESS_CMD _IOW(IPMI_IOC_MAGIC, 17, unsigned int) +#define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int) +#define IPMICTL_SET_MY_LUN_CMD _IOW(IPMI_IOC_MAGIC, 19, unsigned int) +#define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int) + +#define IPMI_RESPONSE_RECV_TYPE 1 +#define IPMI_ASYNC_EVENT_RECV_TYPE 2 +#define IPMI_CMD_RECV_TYPE 3 + +#define IPMI_CHASSIS_REQUEST 0x00 +# define IPMI_CHASSIS_CONTROL 0x02 +# define IPMI_CC_POWER_DOWN 0x0 +# define IPMI_CC_POWER_UP 0x1 +# define IPMI_CC_POWER_CYCLE 0x2 +# define IPMI_CC_HARD_RESET 0x3 +# define IPMI_CC_PULSE_DI 0x4 +# define IPMI_CC_SOFT_OVERTEMP 0x5 + +#define IPMI_APP_REQUEST 0x06 +#define IPMI_GET_DEVICE_ID 0x01 +# define IPMI_ADS_CHASSIS 0x80 +# define IPMI_ADS_BRIDGE 0x40 +# define IPMI_ADS_EVENT_GEN 0x20 +# define IPMI_ADS_EVENT_RCV 0x10 +# define IPMI_ADS_FRU_INV 0x08 +# define IPMI_ADS_SEL 0x04 +# define IPMI_ADS_SDR 0x02 +# define IPMI_ADS_SENSOR 0x01 +#define IPMI_CLEAR_FLAGS 0x30 +#define IPMI_GET_MSG_FLAGS 0x31 +# define IPMI_MSG_AVAILABLE 0x01 +# define IPMI_MSG_BUFFER_FULL 0x02 +# define IPMI_WDT_PRE_TIMEOUT 0x08 +#define IPMI_GET_MSG 0x33 +#define IPMI_SEND_MSG 0x34 +#define IPMI_GET_CHANNEL_INFO 0x42 +#define IPMI_RESET_WDOG 0x22 +#define IPMI_SET_WDOG 0x24 +#define IPMI_GET_WDOG 0x25 + +#define IPMI_SET_WD_TIMER_SMS_OS 0x04 +#define IPMI_SET_WD_TIMER_DONT_STOP 0x40 +#define IPMI_SET_WD_ACTION_NONE 0x00 +#define IPMI_SET_WD_ACTION_RESET 0x01 +#define IPMI_SET_WD_ACTION_POWER_DOWN 0x02 +#define IPMI_SET_WD_ACTION_POWER_CYCLE 0x03 +#define IPMI_SET_WD_PREACTION_NONE (0x00 << 4) +#define IPMI_SET_WD_PREACTION_SMI (0x01 << 4) +#define IPMI_SET_WD_PREACTION_NMI (0x02 << 4) +#define IPMI_SET_WD_PREACTION_MI (0x03 << 4) + +struct ipmi_msg { + unsigned char netfn; + unsigned char cmd; + unsigned short data_len; + unsigned char *data; +}; + +struct ipmi_req { + unsigned char *addr; + unsigned int addr_len; + long msgid; + struct ipmi_msg msg; +}; + +struct ipmi_recv { + int recv_type; + unsigned char *addr; + unsigned int addr_len; + long msgid; + struct ipmi_msg msg; +}; + +struct ipmi_cmdspec { + unsigned char netfn; + unsigned char cmd; +}; + + +struct ipmi_addr { + int addr_type; + short channel; + unsigned char data[IPMI_MAX_ADDR_SIZE]; +}; + +struct ipmi_system_interface_addr { + int addr_type; + short channel; + unsigned char lun; +}; + +struct ipmi_ipmb_addr { + int addr_type; + short channel; + unsigned char slave_addr; + unsigned char lun; +}; + +#if defined(__amd64__) +/* Compatibility with 32-bit binaries. */ + +#define IPMICTL_RECEIVE_MSG_TRUNC_32 _IOWR(IPMI_IOC_MAGIC, 11, struct ipmi_recv32) +#define IPMICTL_RECEIVE_MSG_32 _IOWR(IPMI_IOC_MAGIC, 12, struct ipmi_recv32) +#define IPMICTL_SEND_COMMAND_32 _IOW(IPMI_IOC_MAGIC, 13, struct ipmi_req32) + +struct ipmi_msg32 { + unsigned char netfn; + unsigned char cmd; + unsigned short data_len; + uint32_t data; +}; + +struct ipmi_req32 { + uint32_t addr; + unsigned int addr_len; + int32_t msgid; + struct ipmi_msg32 msg; +}; + +struct ipmi_recv32 { + int recv_type; + uint32_t addr; + unsigned int addr_len; + int32_t msgid; + struct ipmi_msg32 msg; +}; + +#endif + +#endif /* !__SYS_IPMI_H__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/jail.h b/lib/libc/include/any-freebsd-any/sys/jail.h new file mode 100644 index 000000000000..878b97a064a3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/jail.h @@ -0,0 +1,428 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999 Poul-Henning Kamp. + * Copyright (c) 2009 James Gritton. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_JAIL_H_ +#define _SYS_JAIL_H_ + +#ifdef _KERNEL +struct jail_v0 { + u_int32_t version; + char *path; + char *hostname; + u_int32_t ip_number; +}; +#endif + +struct jail { + uint32_t version; + char *path; + char *hostname; + char *jailname; + uint32_t ip4s; + uint32_t ip6s; + struct in_addr *ip4; + struct in6_addr *ip6; +}; +#define JAIL_API_VERSION 2 + +/* + * For all xprison structs, always keep the pr_version an int and + * the first variable so userspace can easily distinguish them. + */ +#ifndef _KERNEL +struct xprison_v1 { + int pr_version; + int pr_id; + char pr_path[MAXPATHLEN]; + char pr_host[MAXHOSTNAMELEN]; + u_int32_t pr_ip; +}; +#endif + +struct xprison { + int pr_version; + int pr_id; + int pr_state; + cpusetid_t pr_cpusetid; + char pr_path[MAXPATHLEN]; + char pr_host[MAXHOSTNAMELEN]; + char pr_name[MAXHOSTNAMELEN]; + uint32_t pr_ip4s; + uint32_t pr_ip6s; +#if 0 + /* + * sizeof(xprison) will be malloced + size needed for all + * IPv4 and IPv6 addesses. Offsets are based numbers of addresses. + */ + struct in_addr pr_ip4[]; + struct in6_addr pr_ip6[]; +#endif +}; +#define XPRISON_VERSION 3 + +#define PRISON_STATE_INVALID 0 +#define PRISON_STATE_ALIVE 1 +#define PRISON_STATE_DYING 2 + +/* + * Flags for jail_set and jail_get. + */ +#define JAIL_CREATE 0x01 /* Create jail if it doesn't exist */ +#define JAIL_UPDATE 0x02 /* Update parameters of existing jail */ +#define JAIL_ATTACH 0x04 /* Attach to jail upon creation */ +#define JAIL_DYING 0x08 /* Allow getting a dying jail */ +#define JAIL_SET_MASK 0x0f +#define JAIL_GET_MASK 0x08 + +#define JAIL_SYS_DISABLE 0 +#define JAIL_SYS_NEW 1 +#define JAIL_SYS_INHERIT 2 + +#ifndef _KERNEL + +struct iovec; + +__BEGIN_DECLS +int jail(struct jail *); +int jail_set(struct iovec *, unsigned int, int); +int jail_get(struct iovec *, unsigned int, int); +int jail_attach(int); +int jail_remove(int); +__END_DECLS + +#else /* _KERNEL */ + +#include +#include +#include +#include +#include + +#define JAIL_MAX 999999 + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_PRISON); +#endif +#endif /* _KERNEL */ + +#if defined(_KERNEL) || defined(_WANT_PRISON) + +#include + +#define HOSTUUIDLEN 64 +#define OSRELEASELEN 32 + +struct racct; +struct prison_racct; + +/* + * This structure describes a prison. It is pointed to by all struct + * ucreds's of the inmates. pr_ref keeps track of them and is used to + * delete the struture when the last inmate is dead. + * + * Lock key: + * (a) allprison_lock + * (p) locked by pr_mtx + * (c) set only during creation before the structure is shared, no mutex + * required to read + */ +struct prison { + TAILQ_ENTRY(prison) pr_list; /* (a) all prisons */ + int pr_id; /* (c) prison id */ + int pr_ref; /* (p) refcount */ + int pr_uref; /* (p) user (alive) refcount */ + unsigned pr_flags; /* (p) PR_* flags */ + LIST_HEAD(, prison) pr_children; /* (a) list of child jails */ + LIST_ENTRY(prison) pr_sibling; /* (a) next in parent's list */ + struct prison *pr_parent; /* (c) containing jail */ + struct mtx pr_mtx; + struct task pr_task; /* (c) destroy task */ + struct osd pr_osd; /* (p) additional data */ + struct cpuset *pr_cpuset; /* (p) cpuset */ + struct vnet *pr_vnet; /* (c) network stack */ + struct vnode *pr_root; /* (c) vnode to rdir */ + int pr_ip4s; /* (p) number of v4 IPs */ + int pr_ip6s; /* (p) number of v6 IPs */ + struct in_addr *pr_ip4; /* (p) v4 IPs of jail */ + struct in6_addr *pr_ip6; /* (p) v6 IPs of jail */ + struct prison_racct *pr_prison_racct; /* (c) racct jail proxy */ + void *pr_sparep[3]; + int pr_childcount; /* (a) number of child jails */ + int pr_childmax; /* (p) maximum child jails */ + unsigned pr_allow; /* (p) PR_ALLOW_* flags */ + int pr_securelevel; /* (p) securelevel */ + int pr_enforce_statfs; /* (p) statfs permission */ + int pr_devfs_rsnum; /* (p) devfs ruleset */ + int pr_spare[3]; + int pr_osreldate; /* (c) kern.osreldate value */ + unsigned long pr_hostid; /* (p) jail hostid */ + char pr_name[MAXHOSTNAMELEN]; /* (p) admin jail name */ + char pr_path[MAXPATHLEN]; /* (c) chroot path */ + char pr_hostname[MAXHOSTNAMELEN]; /* (p) jail hostname */ + char pr_domainname[MAXHOSTNAMELEN]; /* (p) jail domainname */ + char pr_hostuuid[HOSTUUIDLEN]; /* (p) jail hostuuid */ + char pr_osrelease[OSRELEASELEN]; /* (c) kern.osrelease value */ +}; + +struct prison_racct { + LIST_ENTRY(prison_racct) prr_next; + char prr_name[MAXHOSTNAMELEN]; + u_int prr_refcount; + struct racct *prr_racct; +}; +#endif /* _KERNEL || _WANT_PRISON */ + +#ifdef _KERNEL +/* Flag bits set via options */ +#define PR_PERSIST 0x00000001 /* Can exist without processes */ +#define PR_HOST 0x00000002 /* Virtualize hostname et al */ +#define PR_IP4_USER 0x00000004 /* Restrict IPv4 addresses */ +#define PR_IP6_USER 0x00000008 /* Restrict IPv6 addresses */ +#define PR_VNET 0x00000010 /* Virtual network stack */ +#define PR_IP4_SADDRSEL 0x00000080 /* Do IPv4 src addr sel. or use the */ + /* primary jail address. */ +#define PR_IP6_SADDRSEL 0x00000100 /* Do IPv6 src addr sel. or use the */ + /* primary jail address. */ + +/* Internal flag bits */ +#define PR_IP4 0x02000000 /* IPv4 restricted or disabled */ + /* by this jail or an ancestor */ +#define PR_IP6 0x04000000 /* IPv6 restricted or disabled */ + /* by this jail or an ancestor */ + +/* + * Flags for pr_allow + * Bits not noted here may be used for dynamic allow.mount.xxxfs. + */ +#define PR_ALLOW_SET_HOSTNAME 0x00000001 +#define PR_ALLOW_SYSVIPC 0x00000002 +#define PR_ALLOW_RAW_SOCKETS 0x00000004 +#define PR_ALLOW_CHFLAGS 0x00000008 +#define PR_ALLOW_MOUNT 0x00000010 +#define PR_ALLOW_QUOTAS 0x00000020 +#define PR_ALLOW_SOCKET_AF 0x00000040 +#define PR_ALLOW_MLOCK 0x00000080 +#define PR_ALLOW_READ_MSGBUF 0x00000100 +#define PR_ALLOW_RESERVED_PORTS 0x00008000 +#define PR_ALLOW_KMEM_ACCESS 0x00010000 /* reserved, not used yet */ +#define PR_ALLOW_ALL_STATIC 0x000181ff + +/* + * OSD methods + */ +#define PR_METHOD_CREATE 0 +#define PR_METHOD_GET 1 +#define PR_METHOD_SET 2 +#define PR_METHOD_CHECK 3 +#define PR_METHOD_ATTACH 4 +#define PR_METHOD_REMOVE 5 +#define PR_MAXMETHOD 6 + +/* + * Lock/unlock a prison. + * XXX These exist not so much for general convenience, but to be useable in + * the FOREACH_PRISON_DESCENDANT_LOCKED macro which can't handle them in + * non-function form as currently defined. + */ +static __inline void +prison_lock(struct prison *pr) +{ + + mtx_lock(&pr->pr_mtx); +} + +static __inline void +prison_unlock(struct prison *pr) +{ + + mtx_unlock(&pr->pr_mtx); +} + +/* Traverse a prison's immediate children. */ +#define FOREACH_PRISON_CHILD(ppr, cpr) \ + LIST_FOREACH(cpr, &(ppr)->pr_children, pr_sibling) + +/* + * Preorder traversal of all of a prison's descendants. + * This ugly loop allows the macro to be followed by a single block + * as expected in a looping primitive. + */ +#define FOREACH_PRISON_DESCENDANT(ppr, cpr, descend) \ + for ((cpr) = (ppr), (descend) = 1; \ + ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ + ? LIST_FIRST(&(cpr)->pr_children) \ + : ((cpr) == (ppr) \ + ? NULL \ + : (((descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ + ? LIST_NEXT(cpr, pr_sibling) \ + : (cpr)->pr_parent))));) \ + if (!(descend)) \ + ; \ + else + +/* + * As above, but lock descendants on the way down and unlock on the way up. + */ +#define FOREACH_PRISON_DESCENDANT_LOCKED(ppr, cpr, descend) \ + for ((cpr) = (ppr), (descend) = 1; \ + ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ + ? LIST_FIRST(&(cpr)->pr_children) \ + : ((cpr) == (ppr) \ + ? NULL \ + : ((prison_unlock(cpr), \ + (descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ + ? LIST_NEXT(cpr, pr_sibling) \ + : (cpr)->pr_parent))));) \ + if ((descend) ? (prison_lock(cpr), 0) : 1) \ + ; \ + else + +/* + * As above, but also keep track of the level descended to. + */ +#define FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL(ppr, cpr, descend, level)\ + for ((cpr) = (ppr), (descend) = 1, (level) = 0; \ + ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ + ? (level++, LIST_FIRST(&(cpr)->pr_children)) \ + : ((cpr) == (ppr) \ + ? NULL \ + : ((prison_unlock(cpr), \ + (descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ + ? LIST_NEXT(cpr, pr_sibling) \ + : (level--, (cpr)->pr_parent)))));) \ + if ((descend) ? (prison_lock(cpr), 0) : 1) \ + ; \ + else + +/* + * Attributes of the physical system, and the root of the jail tree. + */ +extern struct prison prison0; + +TAILQ_HEAD(prisonlist, prison); +extern struct prisonlist allprison; +extern struct sx allprison_lock; + +/* + * Sysctls to describe jail parameters. + */ +SYSCTL_DECL(_security_jail_param); + +#define SYSCTL_JAIL_PARAM(module, param, type, fmt, descr) \ + SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ + (type) | CTLFLAG_MPSAFE, NULL, 0, sysctl_jail_param, fmt, descr) +#define SYSCTL_JAIL_PARAM_STRING(module, param, access, len, descr) \ + SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ + CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), NULL, len, \ + sysctl_jail_param, "A", descr) +#define SYSCTL_JAIL_PARAM_STRUCT(module, param, access, len, fmt, descr)\ + SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ + CTLTYPE_STRUCT | CTLFLAG_MPSAFE | (access), NULL, len, \ + sysctl_jail_param, fmt, descr) +#define SYSCTL_JAIL_PARAM_NODE(module, descr) \ + SYSCTL_NODE(_security_jail_param, OID_AUTO, module, 0, 0, descr) +#define SYSCTL_JAIL_PARAM_SUBNODE(parent, module, descr) \ + SYSCTL_NODE(_security_jail_param_##parent, OID_AUTO, module, 0, 0, descr) +#define SYSCTL_JAIL_PARAM_SYS_NODE(module, access, descr) \ + SYSCTL_JAIL_PARAM_NODE(module, descr); \ + SYSCTL_JAIL_PARAM(_##module, , CTLTYPE_INT | (access), "E,jailsys", \ + descr) + +/* + * Kernel support functions for jail(). + */ +struct ucred; +struct mount; +struct sockaddr; +struct statfs; +struct vfsconf; +int jailed(struct ucred *cred); +int jailed_without_vnet(struct ucred *); +void getcredhostname(struct ucred *, char *, size_t); +void getcreddomainname(struct ucred *, char *, size_t); +void getcredhostuuid(struct ucred *, char *, size_t); +void getcredhostid(struct ucred *, unsigned long *); +void getjailname(struct ucred *cred, char *name, size_t len); +void prison0_init(void); +int prison_allow(struct ucred *, unsigned); +int prison_check(struct ucred *cred1, struct ucred *cred2); +int prison_owns_vnet(struct ucred *); +int prison_canseemount(struct ucred *cred, struct mount *mp); +void prison_enforce_statfs(struct ucred *cred, struct mount *mp, + struct statfs *sp); +struct prison *prison_find(int prid); +struct prison *prison_find_child(struct prison *, int); +struct prison *prison_find_name(struct prison *, const char *); +int prison_flag(struct ucred *, unsigned); +void prison_free(struct prison *pr); +void prison_free_locked(struct prison *pr); +void prison_hold(struct prison *pr); +void prison_hold_locked(struct prison *pr); +void prison_proc_hold(struct prison *); +void prison_proc_free(struct prison *); +int prison_ischild(struct prison *, struct prison *); +int prison_equal_ip4(struct prison *, struct prison *); +int prison_get_ip4(struct ucred *cred, struct in_addr *ia); +int prison_local_ip4(struct ucred *cred, struct in_addr *ia); +int prison_remote_ip4(struct ucred *cred, struct in_addr *ia); +int prison_check_ip4(const struct ucred *, const struct in_addr *); +int prison_check_ip4_locked(const struct prison *, const struct in_addr *); +int prison_saddrsel_ip4(struct ucred *, struct in_addr *); +int prison_restrict_ip4(struct prison *, struct in_addr *); +int prison_qcmp_v4(const void *, const void *); +#ifdef INET6 +int prison_equal_ip6(struct prison *, struct prison *); +int prison_get_ip6(struct ucred *, struct in6_addr *); +int prison_local_ip6(struct ucred *, struct in6_addr *, int); +int prison_remote_ip6(struct ucred *, struct in6_addr *); +int prison_check_ip6(const struct ucred *, const struct in6_addr *); +int prison_check_ip6_locked(const struct prison *, const struct in6_addr *); +int prison_saddrsel_ip6(struct ucred *, struct in6_addr *); +int prison_restrict_ip6(struct prison *, struct in6_addr *); +int prison_qcmp_v6(const void *, const void *); +#endif +int prison_check_af(struct ucred *cred, int af); +int prison_if(struct ucred *cred, struct sockaddr *sa); +char *prison_name(struct prison *, struct prison *); +int prison_priv_check(struct ucred *cred, int priv); +int sysctl_jail_param(SYSCTL_HANDLER_ARGS); +unsigned prison_add_allow(const char *prefix, const char *name, + const char *prefix_descr, const char *descr); +void prison_add_vfs(struct vfsconf *vfsp); +void prison_racct_foreach(void (*callback)(struct racct *racct, + void *arg2, void *arg3), void (*pre)(void), void (*post)(void), + void *arg2, void *arg3); +struct prison_racct *prison_racct_find(const char *name); +void prison_racct_hold(struct prison_racct *prr); +void prison_racct_free(struct prison_racct *prr); + +#endif /* _KERNEL */ +#endif /* !_SYS_JAIL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/joystick.h b/lib/libc/include/any-freebsd-any/sys/joystick.h new file mode 100644 index 000000000000..60a89dce38c3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/joystick.h @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_JOYSTICK_H_ +#define _SYS_JOYSTICK_H_ + +#include + +struct joystick { + int x; + int y; + int b1; + int b2; +}; + +#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */ +#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */ +#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */ +#define JOY_SET_Y_OFFSET _IOW('J', 4, int) /* set offset on Y-axis */ +#define JOY_GET_X_OFFSET _IOR('J', 5, int) /* get offset on X-axis */ +#define JOY_GET_Y_OFFSET _IOR('J', 6, int) /* get offset on Y-axis */ + +#endif /* !_SYS_JOYSTICK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kbio.h b/lib/libc/include/any-freebsd-any/sys/kbio.h new file mode 100644 index 000000000000..7f17bda76c51 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kbio.h @@ -0,0 +1,269 @@ +/*- + * $FreeBSD$ + */ + +#ifndef _SYS_KBIO_H_ +#define _SYS_KBIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* get/set keyboard I/O mode */ +#define K_RAW 0 /* keyboard returns scancodes */ +#define K_XLATE 1 /* keyboard returns ascii */ +#define K_CODE 2 /* keyboard returns keycodes */ +#define KDGKBMODE _IOR('K', 6, int) +#define KDSKBMODE _IOWINT('K', 7) + +/* make tone */ +#define KDMKTONE _IOWINT('K', 8) + +/* see console.h for the definitions of the following ioctls */ +#ifdef notdef +#define KDGETMODE _IOR('K', 9, int) +#define KDSETMODE _IOWINT('K', 10) +#define KDSBORDER _IOWINT('K', 13) +#endif + +/* get/set keyboard lock state */ +#define CLKED 1 /* Caps locked */ +#define NLKED 2 /* Num locked */ +#define SLKED 4 /* Scroll locked */ +#define ALKED 8 /* AltGr locked */ +#define LOCK_MASK (CLKED | NLKED | SLKED | ALKED) +#define KDGKBSTATE _IOR('K', 19, int) +#define KDSKBSTATE _IOWINT('K', 20) + +/* enable/disable I/O access */ +#define KDENABIO _IO('K', 60) +#define KDDISABIO _IO('K', 61) + +/* make sound */ +#define KIOCSOUND _IOWINT('K', 63) + +/* get keyboard model */ +#define KB_OTHER 0 /* keyboard not known */ +#define KB_84 1 /* 'old' 84 key AT-keyboard */ +#define KB_101 2 /* MF-101 or MF-102 keyboard */ +#define KDGKBTYPE _IOR('K', 64, int) + +/* get/set keyboard LED state */ +#define LED_CAP 1 /* Caps lock LED */ +#define LED_NUM 2 /* Num lock LED */ +#define LED_SCR 4 /* Scroll lock LED */ +#define LED_MASK (LED_CAP | LED_NUM | LED_SCR) +#define KDGETLED _IOR('K', 65, int) +#define KDSETLED _IOWINT('K', 66) + +/* set keyboard repeat rate (obsolete, use KDSETREPEAT below) */ +#define KDSETRAD _IOWINT('K', 67) + +struct keyboard_info { + int kb_index; /* kbdio index# */ + char kb_name[16]; /* driver name */ + int kb_unit; /* unit# */ + int kb_type; /* KB_84, KB_101, KB_OTHER,... */ + int kb_config; /* device configuration flags */ + int kb_flags; /* internal flags */ +}; +typedef struct keyboard_info keyboard_info_t; + +/* add/remove keyboard to/from mux */ +#define KBADDKBD _IOW('K', 68, keyboard_info_t) /* add keyboard */ +#define KBRELKBD _IOW('K', 69, keyboard_info_t) /* release keyboard */ + +/* see console.h for the definition of the following ioctl */ +#ifdef notdef +#define KDRASTER _IOW('K', 100, scr_size_t) +#endif + +/* get keyboard information */ +#define KDGKBINFO _IOR('K', 101, keyboard_info_t) + +/* set/get keyboard repeat rate (new interface) */ +struct keyboard_repeat { + int kb_repeat[2]; +}; +typedef struct keyboard_repeat keyboard_repeat_t; +#define KDSETREPEAT _IOW('K', 102, keyboard_repeat_t) +#define KDGETREPEAT _IOR('K', 103, keyboard_repeat_t) + +/* get/set key map/accent map/function key strings */ + +#define NUM_KEYS 256 /* number of keys in table */ +#define NUM_STATES 8 /* states per key */ +#define ALTGR_OFFSET 128 /* offset for altlock keys */ + +#define NUM_DEADKEYS 15 /* number of accent keys */ +#define NUM_ACCENTCHARS 52 /* max number of accent chars */ + +#define NUM_FKEYS 96 /* max number of function keys */ +#define MAXFK 16 /* max length of a function key str */ + +#ifndef _KEYMAP_DECLARED +#define _KEYMAP_DECLARED + +struct keyent_t { + u_int map[NUM_STATES]; + u_char spcl; + u_char flgs; +#define FLAG_LOCK_O 0 +#define FLAG_LOCK_C 1 +#define FLAG_LOCK_N 2 +}; + +struct keymap { + u_short n_keys; + struct keyent_t key[NUM_KEYS]; +}; +typedef struct keymap keymap_t; + +#ifdef _KERNEL +struct okeyent_t { + u_char map[NUM_STATES]; + u_char spcl; + u_char flgs; +}; + +struct okeymap { + u_short n_keys; + struct okeyent_t key[NUM_KEYS]; +}; +typedef struct okeymap okeymap_t; +#endif /* _KERNEL */ + +#endif /* !_KEYMAP_DECLARED */ + +/* defines for "special" keys (spcl bit set in keymap) */ +#define NOP 0x00 /* nothing (dead key) */ +#define LSH 0x02 /* left shift key */ +#define RSH 0x03 /* right shift key */ +#define CLK 0x04 /* caps lock key */ +#define NLK 0x05 /* num lock key */ +#define SLK 0x06 /* scroll lock key */ +#define LALT 0x07 /* left alt key */ +#define BTAB 0x08 /* backwards tab */ +#define LCTR 0x09 /* left control key */ +#define NEXT 0x0a /* switch to next screen */ +#define F_SCR 0x0b /* switch to first screen */ +#define L_SCR 0x1a /* switch to last screen */ +#define F_FN 0x1b /* first function key */ +#define L_FN 0x7a /* last function key */ +/* 0x7b-0x7f reserved do not use ! */ +#define RCTR 0x80 /* right control key */ +#define RALT 0x81 /* right alt (altgr) key */ +#define ALK 0x82 /* alt lock key */ +#define ASH 0x83 /* alt shift key */ +#define META 0x84 /* meta key */ +#define RBT 0x85 /* boot machine */ +#define DBG 0x86 /* call debugger */ +#define SUSP 0x87 /* suspend power (APM) */ +#define SPSC 0x88 /* toggle splash/text screen */ + +#define F_ACC DGRA /* first accent key */ +#define DGRA 0x89 /* grave */ +#define DACU 0x8a /* acute */ +#define DCIR 0x8b /* circumflex */ +#define DTIL 0x8c /* tilde */ +#define DMAC 0x8d /* macron */ +#define DBRE 0x8e /* breve */ +#define DDOT 0x8f /* dot */ +#define DUML 0x90 /* umlaut/diaresis */ +#define DDIA 0x90 /* diaresis */ +#define DSLA 0x91 /* slash */ +#define DRIN 0x92 /* ring */ +#define DCED 0x93 /* cedilla */ +#define DAPO 0x94 /* apostrophe */ +#define DDAC 0x95 /* double acute */ +#define DOGO 0x96 /* ogonek */ +#define DCAR 0x97 /* caron */ +#define L_ACC DCAR /* last accent key */ + +#define STBY 0x98 /* Go into standby mode (apm) */ +#define PREV 0x99 /* switch to previous screen */ +#define PNC 0x9a /* force system panic */ +#define LSHA 0x9b /* left shift key / alt lock */ +#define RSHA 0x9c /* right shift key / alt lock */ +#define LCTRA 0x9d /* left ctrl key / alt lock */ +#define RCTRA 0x9e /* right ctrl key / alt lock */ +#define LALTA 0x9f /* left alt key / alt lock */ +#define RALTA 0xa0 /* right alt key / alt lock */ +#define HALT 0xa1 /* halt machine */ +#define PDWN 0xa2 /* halt machine and power down */ +#define PASTE 0xa3 /* paste from cut-paste buffer */ + +#define F(x) ((x)+F_FN-1) +#define S(x) ((x)+F_SCR-1) +#define ACC(x) ((x)+F_ACC) + +struct acc_t { + u_char accchar; + u_char map[NUM_ACCENTCHARS][2]; +}; + +struct accentmap { + u_short n_accs; + struct acc_t acc[NUM_DEADKEYS]; +}; +typedef struct accentmap accentmap_t; + +struct keyarg { + u_short keynum; + struct keyent_t key; +}; +typedef struct keyarg keyarg_t; + +struct fkeytab { + u_char str[MAXFK]; + u_char len; +}; +typedef struct fkeytab fkeytab_t; + +struct fkeyarg { + u_short keynum; + char keydef[MAXFK]; + char flen; +}; +typedef struct fkeyarg fkeyarg_t; + +#define GETFKEY _IOWR('k', 0, fkeyarg_t) +#define SETFKEY _IOWR('k', 1, fkeyarg_t) +#ifdef notdef /* see console.h */ +#define GIO_SCRNMAP _IOR('k', 2, scrmap_t) +#define PIO_SCRNMAP _IOW('k', 3, scrmap_t) +#endif +/* XXX: Should have keymap_t as an argument, but that's too big for ioctl()! */ +#define GIO_KEYMAP _IO('k', 6) +#define PIO_KEYMAP _IO('k', 7) +#ifdef _KERNEL +#define OGIO_KEYMAP _IOR('k', 6, okeymap_t) +#define OPIO_KEYMAP _IOW('k', 7, okeymap_t) +#endif /* _KERNEL */ +#define GIO_DEADKEYMAP _IOR('k', 8, accentmap_t) +#define PIO_DEADKEYMAP _IOW('k', 9, accentmap_t) +#define GIO_KEYMAPENT _IOWR('k', 10, keyarg_t) +#define PIO_KEYMAPENT _IOW('k', 11, keyarg_t) + +/* flags set to the return value in the KD_XLATE mode */ + +#define NOKEY 0x01000000 /* no key pressed marker */ +#define FKEY 0x02000000 /* function key marker */ +#define MKEY 0x04000000 /* meta key marker (prepend ESC)*/ +#define BKEY 0x08000000 /* backtab (ESC [ Z) */ + +#define SPCLKEY 0x80000000 /* special key */ +#define RELKEY 0x40000000 /* key released */ +#define ERRKEY 0x20000000 /* error */ + +/* + * The top byte is used to store the flags. This means there are 24 + * bits left to store the actual character. Because UTF-8 can encode + * 2^21 different characters, this is good enough to get Unicode + * working. + */ +#define KEYCHAR(c) ((c) & 0x00ffffff) +#define KEYFLAGS(c) ((c) & ~0x00ffffff) + +#endif /* !_SYS_KBIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kdb.h b/lib/libc/include/any-freebsd-any/sys/kdb.h new file mode 100644 index 000000000000..a8c2db9eeeb6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kdb.h @@ -0,0 +1,128 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KDB_H_ +#define _SYS_KDB_H_ + +#include + +struct pcb; +struct thread; +struct trapframe; + +typedef int dbbe_init_f(void); +typedef void dbbe_trace_f(void); +typedef void dbbe_trace_thread_f(struct thread *); +typedef int dbbe_trap_f(int, int); + +struct kdb_dbbe { + const char *dbbe_name; + dbbe_init_f *dbbe_init; + dbbe_trace_f *dbbe_trace; + dbbe_trace_thread_f *dbbe_trace_thread; + dbbe_trap_f *dbbe_trap; + int dbbe_active; +}; + +#define KDB_BACKEND(name, init, trace, trace_thread, trap) \ + static struct kdb_dbbe name##_dbbe = { \ + .dbbe_name = #name, \ + .dbbe_init = init, \ + .dbbe_trace = trace, \ + .dbbe_trace_thread = trace_thread, \ + .dbbe_trap = trap \ + }; \ + DATA_SET(kdb_dbbe_set, name##_dbbe) + +extern u_char kdb_active; /* Non-zero while in debugger. */ +extern int debugger_on_panic; /* enter the debugger on panic. */ +extern int debugger_on_trap; /* enter the debugger on trap. */ +extern struct kdb_dbbe *kdb_dbbe; /* Default debugger backend or NULL. */ +extern struct trapframe *kdb_frame; /* Frame to kdb_trap(). */ +extern struct pcb *kdb_thrctx; /* Current context. */ +extern struct thread *kdb_thread; /* Current thread. */ + +int kdb_alt_break(int, int *); +int kdb_alt_break_gdb(int, int *); +int kdb_break(void); +void kdb_backtrace(void); +void kdb_backtrace_thread(struct thread *); +int kdb_dbbe_select(const char *); +void kdb_enter(const char *, const char *); +void kdb_init(void); +void * kdb_jmpbuf(jmp_buf); +void kdb_panic(const char *); +void kdb_reboot(void); +void kdb_reenter(void); +void kdb_reenter_silent(void); +struct pcb *kdb_thr_ctx(struct thread *); +struct thread *kdb_thr_first(void); +struct thread *kdb_thr_from_pid(pid_t); +struct thread *kdb_thr_lookup(lwpid_t); +struct thread *kdb_thr_next(struct thread *); +int kdb_thr_select(struct thread *); +int kdb_trap(int, int, struct trapframe *); + +/* + * KDB enters the debugger via breakpoint(), which leaves the debugger without + * a lot of information about why it was entered. This simple enumerated set + * captures some basic information. + * + * It is recommended that values here be short (<16 character) alpha-numeric + * strings, as they will be used to construct DDB(4) script names. + */ +extern const char * volatile kdb_why; +#define KDB_WHY_UNSET NULL /* No reason set. */ +#define KDB_WHY_PANIC "panic" /* panic() was called. */ +#define KDB_WHY_KASSERT "kassert" /* kassert failed. */ +#define KDB_WHY_TRAP "trap" /* Fatal trap. */ +#define KDB_WHY_SYSCTL "sysctl" /* Sysctl entered debugger. */ +#define KDB_WHY_BOOTFLAGS "bootflags" /* Boot flags were set. */ +#define KDB_WHY_WITNESS "witness" /* Witness entered debugger. */ +#define KDB_WHY_VFSLOCK "vfslock" /* VFS detected lock problem. */ +#define KDB_WHY_NETGRAPH "netgraph" /* Netgraph entered debugger. */ +#define KDB_WHY_BREAK "break" /* Console or serial break. */ +#define KDB_WHY_WATCHDOG "watchdog" /* Watchdog entered debugger. */ +#define KDB_WHY_CAM "cam" /* CAM has entered debugger. */ +#define KDB_WHY_NDIS "ndis" /* NDIS entered debugger. */ +#define KDB_WHY_ACPI "acpi" /* ACPI entered debugger. */ +#define KDB_WHY_TRAPSIG "trapsig" /* Sparc fault. */ +#define KDB_WHY_POWERFAIL "powerfail" /* Powerfail NMI. */ +#define KDB_WHY_MAC "mac" /* MAC Framework. */ +#define KDB_WHY_POWERPC "powerpc" /* Unhandled powerpc intr. */ +#define KDB_WHY_UNIONFS "unionfs" /* Unionfs bug. */ +#define KDB_WHY_DTRACE "dtrace" /* DTrace action entered debugger. */ + +/* Return values for kdb_alt_break */ +#define KDB_REQ_DEBUGGER 1 /* User requested Debugger */ +#define KDB_REQ_PANIC 2 /* User requested a panic */ +#define KDB_REQ_REBOOT 3 /* User requested a clean reboot */ + +#endif /* !_SYS_KDB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kenv.h b/lib/libc/include/any-freebsd-any/sys/kenv.h new file mode 100644 index 000000000000..fd1ae31f6a95 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kenv.h @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Maxime Henrion + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KENV_H_ +#define _SYS_KENV_H_ + +/* + * Constants for the kenv(2) syscall + */ +#define KENV_GET 0 +#define KENV_SET 1 +#define KENV_UNSET 2 +#define KENV_DUMP 3 + +#define KENV_MNAMELEN 128 /* Maximum name length (for the syscall) */ +#define KENV_MVALLEN 128 /* Maximum value length (for the syscall) */ + +#endif /* !_SYS_KENV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kern_prefetch.h b/lib/libc/include/any-freebsd-any/sys/kern_prefetch.h new file mode 100644 index 000000000000..6945132f12e0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kern_prefetch.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2016-2018 Netflix, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef __kern_prefetch_h__ +#define __kern_prefetch_h__ +#ifdef _KERNEL + +static __inline void +kern_prefetch(const volatile void *addr, void* before) +{ +#if defined(__amd64__) + __asm __volatile("prefetcht1 (%1)":"=rm"(*((int32_t *)before)):"r"(addr):); +#else +/* __builtin_prefetch(addr);*/ +#endif +} + +#endif /* _KERNEL */ +#endif /* __kern_prefetch_h__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kernel.h b/lib/libc/include/any-freebsd-any/sys/kernel.h new file mode 100644 index 000000000000..0a1cb890b94f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kernel.h @@ -0,0 +1,456 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1995 Terrence R. Lambert + * All rights reserved. + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)kernel.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_KERNEL_H_ +#define _SYS_KERNEL_H_ + +#include + +#ifdef _KERNEL + +/* for intrhook below */ +#include + +/* for timestamping SYSINITs; other files may assume this is included here */ +#include + +/* Global variables for the kernel. */ + +/* 1.1 */ +extern char kernelname[MAXPATHLEN]; + +extern int tick; /* usec per tick (1000000 / hz) */ +extern int hz; /* system clock's frequency */ +extern int psratio; /* ratio: prof / stat */ +extern int stathz; /* statistics clock's frequency */ +extern int profhz; /* profiling clock's frequency */ +extern int profprocs; /* number of process's profiling */ +extern volatile int ticks; + +#endif /* _KERNEL */ + +/* + * Enumerated types for known system startup interfaces. + * + * Startup occurs in ascending numeric order; the list entries are + * sorted prior to attempting startup to guarantee order. Items + * of the same level are arbitrated for order based on the 'order' + * element. + * + * These numbers are arbitrary and are chosen ONLY for ordering; the + * enumeration values are explicit rather than implicit to provide + * for binary compatibility with inserted elements. + * + * The SI_SUB_LAST value must have the highest lexical value. + */ +enum sysinit_sub_id { + SI_SUB_DUMMY = 0x0000000, /* not executed; for linker*/ + SI_SUB_DONE = 0x0000001, /* processed*/ + SI_SUB_TUNABLES = 0x0700000, /* establish tunable values */ + SI_SUB_COPYRIGHT = 0x0800001, /* first use of console*/ + SI_SUB_VM = 0x1000000, /* virtual memory system init */ + SI_SUB_COUNTER = 0x1100000, /* counter(9) is initialized */ + SI_SUB_KMEM = 0x1800000, /* kernel memory*/ + SI_SUB_HYPERVISOR = 0x1A40000, /* + * Hypervisor detection and + * virtualization support + * setup. + */ + SI_SUB_WITNESS = 0x1A80000, /* witness initialization */ + SI_SUB_MTX_POOL_DYNAMIC = 0x1AC0000, /* dynamic mutex pool */ + SI_SUB_LOCK = 0x1B00000, /* various locks */ + SI_SUB_EVENTHANDLER = 0x1C00000, /* eventhandler init */ + SI_SUB_VNET_PRELINK = 0x1E00000, /* vnet init before modules */ + SI_SUB_KLD = 0x2000000, /* KLD and module setup */ + SI_SUB_CPU = 0x2100000, /* CPU resource(s)*/ + SI_SUB_RACCT = 0x2110000, /* resource accounting */ + SI_SUB_KDTRACE = 0x2140000, /* Kernel dtrace hooks */ + SI_SUB_RANDOM = 0x2160000, /* random number generator */ + SI_SUB_MAC = 0x2180000, /* TrustedBSD MAC subsystem */ + SI_SUB_MAC_POLICY = 0x21C0000, /* TrustedBSD MAC policies */ + SI_SUB_MAC_LATE = 0x21D0000, /* TrustedBSD MAC subsystem */ + SI_SUB_VNET = 0x21E0000, /* vnet 0 */ + SI_SUB_INTRINSIC = 0x2200000, /* proc 0*/ + SI_SUB_VM_CONF = 0x2300000, /* config VM, set limits*/ + SI_SUB_DDB_SERVICES = 0x2380000, /* capture, scripting, etc. */ + SI_SUB_RUN_QUEUE = 0x2400000, /* set up run queue*/ + SI_SUB_KTRACE = 0x2480000, /* ktrace */ + SI_SUB_OPENSOLARIS = 0x2490000, /* OpenSolaris compatibility */ + SI_SUB_AUDIT = 0x24C0000, /* audit */ + SI_SUB_CREATE_INIT = 0x2500000, /* create init process*/ + SI_SUB_SCHED_IDLE = 0x2600000, /* required idle procs */ + SI_SUB_MBUF = 0x2700000, /* mbuf subsystem */ + SI_SUB_INTR = 0x2800000, /* interrupt threads */ + SI_SUB_TASKQ = 0x2880000, /* task queues */ +#ifdef EARLY_AP_STARTUP + SI_SUB_SMP = 0x2900000, /* start the APs*/ +#endif + SI_SUB_SOFTINTR = 0x2A00000, /* start soft interrupt thread */ + SI_SUB_DEVFS = 0x2F00000, /* devfs ready for devices */ + SI_SUB_INIT_IF = 0x3000000, /* prep for net interfaces */ + SI_SUB_NETGRAPH = 0x3010000, /* Let Netgraph initialize */ + SI_SUB_DTRACE = 0x3020000, /* DTrace subsystem */ + SI_SUB_DTRACE_PROVIDER = 0x3048000, /* DTrace providers */ + SI_SUB_DTRACE_ANON = 0x308C000, /* DTrace anon enabling */ + SI_SUB_DRIVERS = 0x3100000, /* Let Drivers initialize */ + SI_SUB_CONFIGURE = 0x3800000, /* Configure devices */ + SI_SUB_VFS = 0x4000000, /* virtual filesystem*/ + SI_SUB_CLOCKS = 0x4800000, /* real time and stat clocks*/ + SI_SUB_SYSV_SHM = 0x6400000, /* System V shared memory*/ + SI_SUB_SYSV_SEM = 0x6800000, /* System V semaphores*/ + SI_SUB_SYSV_MSG = 0x6C00000, /* System V message queues*/ + SI_SUB_P1003_1B = 0x6E00000, /* P1003.1B realtime */ + SI_SUB_PSEUDO = 0x7000000, /* pseudo devices*/ + SI_SUB_EXEC = 0x7400000, /* execve() handlers */ + SI_SUB_PROTO_BEGIN = 0x8000000, /* VNET initialization */ + SI_SUB_PROTO_PFIL = 0x8100000, /* Initialize pfil before FWs */ + SI_SUB_PROTO_IF = 0x8400000, /* interfaces*/ + SI_SUB_PROTO_DOMAININIT = 0x8600000, /* domain registration system */ + SI_SUB_PROTO_MC = 0x8700000, /* Multicast */ + SI_SUB_PROTO_DOMAIN = 0x8800000, /* domains (address families?)*/ + SI_SUB_PROTO_FIREWALL = 0x8806000, /* Firewalls */ + SI_SUB_PROTO_IFATTACHDOMAIN = 0x8808000,/* domain dependent data init */ + SI_SUB_PROTO_END = 0x8ffffff, /* VNET helper functions */ + SI_SUB_KPROF = 0x9000000, /* kernel profiling*/ + SI_SUB_KICK_SCHEDULER = 0xa000000, /* start the timeout events*/ + SI_SUB_INT_CONFIG_HOOKS = 0xa800000, /* Interrupts enabled config */ + SI_SUB_ROOT_CONF = 0xb000000, /* Find root devices */ + SI_SUB_INTRINSIC_POST = 0xd000000, /* proc 0 cleanup*/ + SI_SUB_SYSCALLS = 0xd800000, /* register system calls */ + SI_SUB_VNET_DONE = 0xdc00000, /* vnet registration complete */ + SI_SUB_KTHREAD_INIT = 0xe000000, /* init process*/ + SI_SUB_KTHREAD_PAGE = 0xe400000, /* pageout daemon*/ + SI_SUB_KTHREAD_VM = 0xe800000, /* vm daemon*/ + SI_SUB_KTHREAD_BUF = 0xea00000, /* buffer daemon*/ + SI_SUB_KTHREAD_UPDATE = 0xec00000, /* update daemon*/ + SI_SUB_KTHREAD_IDLE = 0xee00000, /* idle procs*/ +#ifndef EARLY_AP_STARTUP + SI_SUB_SMP = 0xf000000, /* start the APs*/ +#endif + SI_SUB_RACCTD = 0xf100000, /* start racctd*/ + SI_SUB_LAST = 0xfffffff /* final initialization */ +}; + + +/* + * Some enumerated orders; "ANY" sorts last. + */ +enum sysinit_elem_order { + SI_ORDER_FIRST = 0x0000000, /* first*/ + SI_ORDER_SECOND = 0x0000001, /* second*/ + SI_ORDER_THIRD = 0x0000002, /* third*/ + SI_ORDER_FOURTH = 0x0000003, /* fourth*/ + SI_ORDER_FIFTH = 0x0000004, /* fifth*/ + SI_ORDER_SIXTH = 0x0000005, /* sixth*/ + SI_ORDER_SEVENTH = 0x0000006, /* seventh*/ + SI_ORDER_EIGHTH = 0x0000007, /* eighth*/ + SI_ORDER_MIDDLE = 0x1000000, /* somewhere in the middle */ + SI_ORDER_ANY = 0xfffffff /* last*/ +}; + + +/* + * A system initialization call instance + * + * At the moment there is one instance of sysinit. We probably do not + * want two which is why this code is if'd out, but we definitely want + * to discern SYSINIT's which take non-constant data pointers and + * SYSINIT's which take constant data pointers, + * + * The C_* macros take functions expecting const void * arguments + * while the non-C_* macros take functions expecting just void * arguments. + * + * With -Wcast-qual on, the compiler issues warnings: + * - if we pass non-const data or functions taking non-const data + * to a C_* macro. + * + * - if we pass const data to the normal macros + * + * However, no warning is issued if we pass a function taking const data + * through a normal non-const macro. This is ok because the function is + * saying it won't modify the data so we don't care whether the data is + * modifiable or not. + */ + +typedef void (*sysinit_nfunc_t)(void *); +typedef void (*sysinit_cfunc_t)(const void *); + +struct sysinit { + enum sysinit_sub_id subsystem; /* subsystem identifier*/ + enum sysinit_elem_order order; /* init order within subsystem*/ + sysinit_cfunc_t func; /* function */ + const void *udata; /* multiplexer/argument */ +}; + +/* + * Default: no special processing + * + * The C_ version of SYSINIT is for data pointers to const + * data ( and functions taking data pointers to const data ). + * At the moment it is no different from SYSINIT and thus + * still results in warnings. + * + * The casts are necessary to have the compiler produce the + * correct warnings when -Wcast-qual is used. + * + */ +#ifdef TSLOG +struct sysinit_tslog { + sysinit_cfunc_t func; + const void * data; + const char * name; +}; +static inline void +sysinit_tslog_shim(const void * data) +{ + const struct sysinit_tslog * x = data; + + TSRAW(curthread, TS_ENTER, "SYSINIT", x->name); + (x->func)(x->data); + TSRAW(curthread, TS_EXIT, "SYSINIT", x->name); +} +#define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ + static struct sysinit_tslog uniquifier ## _sys_init_tslog = { \ + func, \ + (ident), \ + #uniquifier \ + }; \ + static struct sysinit uniquifier ## _sys_init = { \ + subsystem, \ + order, \ + sysinit_tslog_shim, \ + &uniquifier ## _sys_init_tslog \ + }; \ + DATA_WSET(sysinit_set,uniquifier ## _sys_init) +#else +#define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ + static struct sysinit uniquifier ## _sys_init = { \ + subsystem, \ + order, \ + func, \ + (ident) \ + }; \ + DATA_WSET(sysinit_set,uniquifier ## _sys_init) +#endif + +#define SYSINIT(uniquifier, subsystem, order, func, ident) \ + C_SYSINIT(uniquifier, subsystem, order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) + +/* + * Called on module unload: no special processing + */ +#define C_SYSUNINIT(uniquifier, subsystem, order, func, ident) \ + static struct sysinit uniquifier ## _sys_uninit = { \ + subsystem, \ + order, \ + func, \ + (ident) \ + }; \ + DATA_WSET(sysuninit_set,uniquifier ## _sys_uninit) + +#define SYSUNINIT(uniquifier, subsystem, order, func, ident) \ + C_SYSUNINIT(uniquifier, subsystem, order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) + +void sysinit_add(struct sysinit **set, struct sysinit **set_end); + +/* + * Infrastructure for tunable 'constants'. Value may be specified at compile + * time or kernel load time. Rules relating tunables together can be placed + * in a SYSINIT function at SI_SUB_TUNABLES with SI_ORDER_ANY. + * + * WARNING: developers should never use the reserved suffixes specified in + * loader.conf(5) for any tunables or conflicts will result. + */ + +/* + * int + * please avoid using for new tunables! + */ +extern void tunable_int_init(void *); +struct tunable_int { + const char *path; + int *var; +}; +#define TUNABLE_INT(path, var) \ + static struct tunable_int __CONCAT(__tunable_int_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_int_init, \ + &__CONCAT(__tunable_int_, __LINE__)) + +#define TUNABLE_INT_FETCH(path, var) getenv_int((path), (var)) + +/* + * long + */ +extern void tunable_long_init(void *); +struct tunable_long { + const char *path; + long *var; +}; +#define TUNABLE_LONG(path, var) \ + static struct tunable_long __CONCAT(__tunable_long_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_long_init,\ + &__CONCAT(__tunable_long_, __LINE__)) + +#define TUNABLE_LONG_FETCH(path, var) getenv_long((path), (var)) + +/* + * unsigned long + */ +extern void tunable_ulong_init(void *); +struct tunable_ulong { + const char *path; + unsigned long *var; +}; +#define TUNABLE_ULONG(path, var) \ + static struct tunable_ulong __CONCAT(__tunable_ulong_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_ulong_init, \ + &__CONCAT(__tunable_ulong_, __LINE__)) + +#define TUNABLE_ULONG_FETCH(path, var) getenv_ulong((path), (var)) + +/* + * int64_t + */ +extern void tunable_int64_init(void *); +struct tunable_int64 { + const char *path; + int64_t *var; +}; +#define TUNABLE_INT64(path, var) \ + static struct tunable_int64 __CONCAT(__tunable_int64_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_int64_init, \ + &__CONCAT(__tunable_int64_, __LINE__)) + +#define TUNABLE_INT64_FETCH(path, var) getenv_int64((path), (var)) + +/* + * uint64_t + */ +extern void tunable_uint64_init(void *); +struct tunable_uint64 { + const char *path; + uint64_t *var; +}; +#define TUNABLE_UINT64(path, var) \ + static struct tunable_uint64 __CONCAT(__tunable_uint64_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_uint64_init, \ + &__CONCAT(__tunable_uint64_, __LINE__)) + +#define TUNABLE_UINT64_FETCH(path, var) getenv_uint64((path), (var)) + +/* + * quad + */ +extern void tunable_quad_init(void *); +struct tunable_quad { + const char *path; + quad_t *var; +}; +#define TUNABLE_QUAD(path, var) \ + static struct tunable_quad __CONCAT(__tunable_quad_, __LINE__) = { \ + (path), \ + (var), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_quad_init, \ + &__CONCAT(__tunable_quad_, __LINE__)) + +#define TUNABLE_QUAD_FETCH(path, var) getenv_quad((path), (var)) + +extern void tunable_str_init(void *); +struct tunable_str { + const char *path; + char *var; + int size; +}; +#define TUNABLE_STR(path, var, size) \ + static struct tunable_str __CONCAT(__tunable_str_, __LINE__) = { \ + (path), \ + (var), \ + (size), \ + }; \ + SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ + SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_str_init, \ + &__CONCAT(__tunable_str_, __LINE__)) + +#define TUNABLE_STR_FETCH(path, var, size) \ + getenv_string((path), (var), (size)) + +typedef void (*ich_func_t)(void *_arg); + +struct intr_config_hook { + TAILQ_ENTRY(intr_config_hook) ich_links; + ich_func_t ich_func; + void *ich_arg; +}; + +int config_intrhook_establish(struct intr_config_hook *hook); +void config_intrhook_disestablish(struct intr_config_hook *hook); +void config_intrhook_oneshot(ich_func_t _func, void *_arg); + +#endif /* !_SYS_KERNEL_H_*/ diff --git a/lib/libc/include/any-freebsd-any/sys/kerneldump.h b/lib/libc/include/any-freebsd-any/sys/kerneldump.h new file mode 100644 index 000000000000..44676ca066dc --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kerneldump.h @@ -0,0 +1,157 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2002 Poul-Henning Kamp + * Copyright (c) 2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by Poul-Henning Kamp + * and NAI Labs, the Security Research Division of Network Associates, Inc. + * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the + * DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KERNELDUMP_H +#define _SYS_KERNELDUMP_H + +#include +#include + +#include + +#if BYTE_ORDER == LITTLE_ENDIAN +#define dtoh32(x) __bswap32(x) +#define dtoh64(x) __bswap64(x) +#define htod32(x) __bswap32(x) +#define htod64(x) __bswap64(x) +#elif BYTE_ORDER == BIG_ENDIAN +#define dtoh32(x) (x) +#define dtoh64(x) (x) +#define htod32(x) (x) +#define htod64(x) (x) +#endif + +#define KERNELDUMP_COMP_NONE 0 +#define KERNELDUMP_COMP_GZIP 1 +#define KERNELDUMP_COMP_ZSTD 2 + +#define KERNELDUMP_ENC_NONE 0 +#define KERNELDUMP_ENC_AES_256_CBC 1 + +#define KERNELDUMP_BUFFER_SIZE 4096 +#define KERNELDUMP_IV_MAX_SIZE 32 +#define KERNELDUMP_KEY_MAX_SIZE 64 +#define KERNELDUMP_ENCKEY_MAX_SIZE (16384 / 8) + +/* + * All uintX_t fields are in dump byte order, which is the same as + * network byte order. Use the macros defined above to read or + * write the fields. + */ +struct kerneldumpheader { + char magic[20]; +#define KERNELDUMPMAGIC "FreeBSD Kernel Dump" +#define TEXTDUMPMAGIC "FreeBSD Text Dump" +#define KERNELDUMPMAGIC_CLEARED "Cleared Kernel Dump" + char architecture[12]; + uint32_t version; +#define KERNELDUMPVERSION 4 +#define KERNELDUMP_TEXT_VERSION 4 + uint32_t architectureversion; +#define KERNELDUMP_AARCH64_VERSION 1 +#define KERNELDUMP_AMD64_VERSION 2 +#define KERNELDUMP_ARM_VERSION 1 +#define KERNELDUMP_I386_VERSION 2 +#define KERNELDUMP_MIPS_VERSION 1 +#define KERNELDUMP_POWERPC_VERSION 1 +#define KERNELDUMP_RISCV_VERSION 1 +#define KERNELDUMP_SPARC64_VERSION 1 + uint64_t dumplength; /* excl headers */ + uint64_t dumptime; + uint32_t dumpkeysize; + uint32_t blocksize; + char hostname[64]; + char versionstring[192]; + char panicstring[175]; + uint8_t compression; + uint64_t dumpextent; + char unused[4]; + uint32_t parity; +}; + +struct kerneldumpkey { + uint8_t kdk_encryption; + uint8_t kdk_iv[KERNELDUMP_IV_MAX_SIZE]; + uint32_t kdk_encryptedkeysize; + uint8_t kdk_encryptedkey[]; +} __packed; + +/* + * Parity calculation is endian insensitive. + */ +static __inline u_int32_t +kerneldump_parity(struct kerneldumpheader *kdhp) +{ + uint32_t *up, parity; + u_int i; + + up = (uint32_t *)kdhp; + parity = 0; + for (i = 0; i < sizeof *kdhp; i += sizeof *up) + parity ^= *up++; + return (parity); +} + +#ifdef _KERNEL +struct dump_pa { + vm_paddr_t pa_start; + vm_paddr_t pa_size; +}; + +int dumpsys_generic(struct dumperinfo *); + +void dumpsys_map_chunk(vm_paddr_t, size_t, void **); +typedef int dumpsys_callback_t(struct dump_pa *, int, void *); +int dumpsys_foreach_chunk(dumpsys_callback_t, void *); +int dumpsys_cb_dumpdata(struct dump_pa *, int, void *); +int dumpsys_buf_seek(struct dumperinfo *, size_t); +int dumpsys_buf_write(struct dumperinfo *, char *, size_t); +int dumpsys_buf_flush(struct dumperinfo *); + +void dumpsys_gen_pa_init(void); +struct dump_pa *dumpsys_gen_pa_next(struct dump_pa *); +void dumpsys_gen_wbinv_all(void); +void dumpsys_gen_unmap_chunk(vm_paddr_t, size_t, void *); +int dumpsys_gen_write_aux_headers(struct dumperinfo *); + +extern int do_minidump; + +#endif + +#endif /* _SYS_KERNELDUMP_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/khelp.h b/lib/libc/include/any-freebsd-any/sys/khelp.h new file mode 100644 index 000000000000..54c4791d3be9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/khelp.h @@ -0,0 +1,79 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 Lawrence Stewart + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Lawrence Stewart while studying at the Centre + * for Advanced Internet Architectures, Swinburne University of Technology, made + * possible in part by grants from the FreeBSD Foundation and Cisco University + * Research Program Fund at Community Foundation Silicon Valley. + * + * Portions of this software were developed at the Centre for Advanced + * Internet Architectures, Swinburne University of Technology, Melbourne, + * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * A KPI for managing kernel helper modules which perform useful functionality + * within the kernel. Originally released as part of the NewTCP research project + * at Swinburne University of Technology's Centre for Advanced Internet + * Architectures, Melbourne, Australia, which was made possible in part by a + * grant from the Cisco University Research Program Fund at Community Foundation + * Silicon Valley. More details are available at: + * http://caia.swin.edu.au/urp/newtcp/ + */ + +#ifndef _SYS_KHELP_H_ +#define _SYS_KHELP_H_ + +struct helper; +struct hookinfo; +struct osd; + +/* Helper classes. */ +#define HELPER_CLASS_TCP 0x00000001 +#define HELPER_CLASS_SOCKET 0x00000002 + +/* Public KPI functions. */ +int khelp_register_helper(struct helper *h); + +int khelp_deregister_helper(struct helper *h); + +int khelp_init_osd(uint32_t classes, struct osd *hosd); + +int khelp_destroy_osd(struct osd *hosd); + +void * khelp_get_osd(struct osd *hosd, int32_t id); + +int32_t khelp_get_id(char *hname); + +int khelp_add_hhook(struct hookinfo *hki, uint32_t flags); + +int khelp_remove_hhook(struct hookinfo *hki); + +#endif /* _SYS_KHELP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kobj.h b/lib/libc/include/any-freebsd-any/sys/kobj.h new file mode 100644 index 000000000000..5f8b2bb07be3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kobj.h @@ -0,0 +1,262 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000,2003 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KOBJ_H_ +#define _SYS_KOBJ_H_ + +/* + * Forward declarations + */ +typedef struct kobj *kobj_t; +typedef struct kobj_class *kobj_class_t; +typedef const struct kobj_method kobj_method_t; +typedef int (*kobjop_t)(void); +typedef struct kobj_ops *kobj_ops_t; +typedef struct kobjop_desc *kobjop_desc_t; +struct malloc_type; + +struct kobj_method { + kobjop_desc_t desc; + kobjop_t func; +}; + +/* + * A class is simply a method table and a sizeof value. When the first + * instance of the class is created, the method table will be compiled + * into a form more suited to efficient method dispatch. This compiled + * method table is always the first field of the object. + */ +#define KOBJ_CLASS_FIELDS \ + const char *name; /* class name */ \ + kobj_method_t *methods; /* method table */ \ + size_t size; /* object size */ \ + kobj_class_t *baseclasses; /* base classes */ \ + u_int refs; /* reference count */ \ + kobj_ops_t ops /* compiled method table */ + +struct kobj_class { + KOBJ_CLASS_FIELDS; +}; + +/* + * Implementation of kobj. + */ +#define KOBJ_FIELDS \ + kobj_ops_t ops + +struct kobj { + KOBJ_FIELDS; +}; + +/* + * The ops table is used as a cache of results from kobj_lookup_method(). + */ + +#define KOBJ_CACHE_SIZE 256 + +struct kobj_ops { + kobj_method_t *cache[KOBJ_CACHE_SIZE]; + kobj_class_t cls; +}; + +struct kobjop_desc { + unsigned int id; /* unique ID */ + kobj_method_t deflt; /* default implementation */ +}; + +/* + * Shorthand for constructing method tables. + * The ternary operator is (ab)used to provoke a warning when FUNC + * has a signature that is not compatible with kobj method signature. + */ +#define KOBJMETHOD(NAME, FUNC) \ + { &NAME##_desc, (kobjop_t) (1 ? FUNC : (NAME##_t *)NULL) } + +/* + * + */ +#define KOBJMETHOD_END { NULL, NULL } + +/* + * Declare a class (which should be defined in another file. + */ +#define DECLARE_CLASS(name) extern struct kobj_class name + +/* + * Define a class with no base classes (api backward-compatible. with + * FreeBSD-5.1 and earlier). + */ +#define DEFINE_CLASS(name, methods, size) \ +DEFINE_CLASS_0(name, name ## _class, methods, size) + +/* + * Define a class with no base classes. Use like this: + * + * DEFINE_CLASS_0(foo, foo_class, foo_methods, sizeof(foo_softc)); + */ +#define DEFINE_CLASS_0(name, classvar, methods, size) \ + \ +struct kobj_class classvar = { \ + #name, methods, size, NULL \ +} + +/* + * Define a class inheriting a single base class. Use like this: + * + * DEFINE_CLASS_1(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar); + */ +#define DEFINE_CLASS_1(name, classvar, methods, size, \ + base1) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, NULL }; \ +struct kobj_class classvar = { \ + #name, methods, size, name ## _baseclasses \ +} + +/* + * Define a class inheriting two base classes. Use like this: + * + * DEFINE_CLASS_2(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar, baz); + */ +#define DEFINE_CLASS_2(name, classvar, methods, size, \ + base1, base2) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, \ + &base2, NULL }; \ +struct kobj_class classvar = { \ + #name, methods, size, name ## _baseclasses \ +} + +/* + * Define a class inheriting three base classes. Use like this: + * + * DEFINE_CLASS_3(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar, baz, foobar); + */ +#define DEFINE_CLASS_3(name, classvar, methods, size, \ + base1, base2, base3) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, \ + &base2, \ + &base3, NULL }; \ +struct kobj_class classvar = { \ + #name, methods, size, name ## _baseclasses \ +} + + +/* + * Compile the method table in a class. + */ +void kobj_class_compile(kobj_class_t cls); + +/* + * Compile the method table, with the caller providing the space for + * the ops table.(for use before malloc is initialised). + */ +void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops); + +/* + * Free the compiled method table in a class. + */ +void kobj_class_free(kobj_class_t cls); + +/* + * Allocate memory for and initialise a new object. + */ +kobj_t kobj_create(kobj_class_t cls, + struct malloc_type *mtype, + int mflags); + +/* + * Initialise a pre-allocated object. + */ +void kobj_init(kobj_t obj, kobj_class_t cls); +void kobj_init_static(kobj_t obj, kobj_class_t cls); + +/* + * Delete an object. If mtype is non-zero, free the memory. + */ +void kobj_delete(kobj_t obj, struct malloc_type *mtype); + +/* + * Maintain stats on hits/misses in lookup caches. + */ +#ifdef KOBJ_STATS +extern u_int kobj_lookup_hits; +extern u_int kobj_lookup_misses; +#endif + +/* + * Lookup the method in the cache and if it isn't there look it up the + * slow way. + */ +#ifdef KOBJ_STATS +#define KOBJOPLOOKUP(OPS,OP) do { \ + kobjop_desc_t _desc = &OP##_##desc; \ + kobj_method_t **_cep = \ + &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \ + kobj_method_t *_ce = *_cep; \ + if (_ce->desc != _desc) { \ + _ce = kobj_lookup_method(OPS->cls, \ + _cep, _desc); \ + kobj_lookup_misses++; \ + } else \ + kobj_lookup_hits++; \ + _m = _ce->func; \ +} while(0) +#else +#define KOBJOPLOOKUP(OPS,OP) do { \ + kobjop_desc_t _desc = &OP##_##desc; \ + kobj_method_t **_cep = \ + &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \ + kobj_method_t *_ce = *_cep; \ + if (_ce->desc != _desc) \ + _ce = kobj_lookup_method(OPS->cls, \ + _cep, _desc); \ + _m = _ce->func; \ +} while(0) +#endif + +kobj_method_t* kobj_lookup_method(kobj_class_t cls, + kobj_method_t **cep, + kobjop_desc_t desc); + + +/* + * Default method implementation. Returns ENXIO. + */ +int kobj_error_method(void); + +#endif /* !_SYS_KOBJ_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kpilite.h b/lib/libc/include/any-freebsd-any/sys/kpilite.h new file mode 100644 index 000000000000..8742ef5cfbe8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kpilite.h @@ -0,0 +1,55 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018, Matthew Macy + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KPILITE_H_ +#define _SYS_KPILITE_H_ +#if !defined(GENOFFSET) && (!defined(KLD_MODULE) || defined(KLD_TIED)) && defined(_KERNEL) +#include "offset.inc" + +static __inline void +sched_pin_lite(struct thread_lite *td) +{ + + KASSERT((struct thread *)td == curthread, ("sched_pin called on non curthread")); + td->td_pinned++; + __compiler_membar(); +} + +static __inline void +sched_unpin_lite(struct thread_lite *td) +{ + + KASSERT((struct thread *)td == curthread, ("sched_unpin called on non curthread")); + KASSERT(td->td_pinned > 0, ("sched_unpin called on non pinned thread")); + __compiler_membar(); + td->td_pinned--; + __compiler_membar(); +} +#endif +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/ksem.h b/lib/libc/include/any-freebsd-any/sys/ksem.h new file mode 100644 index 000000000000..4776901fd7b1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ksem.h @@ -0,0 +1,68 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Alfred Perlstein + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _POSIX4_KSEM_H_ +#define _POSIX4_KSEM_H_ + +#if !defined(_KERNEL) && !defined(_WANT_FILE) +#error "no user-serviceable parts inside" +#endif + +#include + +struct ksem { + int ks_ref; /* number of references */ + mode_t ks_mode; /* protection bits */ + uid_t ks_uid; /* creator uid */ + gid_t ks_gid; /* creator gid */ + unsigned int ks_value; /* current value */ + struct cv ks_cv; /* waiters sleep here */ + int ks_waiters; /* number of waiters */ + int ks_flags; + + /* + * Values maintained solely to make this a better-behaved file + * descriptor for fstat() to run on. + * + * XXX: dubious + */ + struct timespec ks_atime; + struct timespec ks_mtime; + struct timespec ks_ctime; + struct timespec ks_birthtime; + + struct label *ks_label; /* MAC label */ + const char *ks_path; +}; + +#define KS_ANONYMOUS 0x0001 /* Anonymous (unnamed) semaphore. */ +#define KS_DEAD 0x0002 /* No new waiters allowed. */ + +#endif /* !_POSIX4_KSEM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/kthread.h b/lib/libc/include/any-freebsd-any/sys/kthread.h new file mode 100644 index 000000000000..e6f1fa41a988 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/kthread.h @@ -0,0 +1,81 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_KTHREAD_H_ +#define _SYS_KTHREAD_H_ + +#include + +/* + * A kernel process descriptor; used to start "internal" daemons. + * + * Note: global_procpp may be NULL for no global save area. + */ +struct kproc_desc { + const char *arg0; /* arg 0 (for 'ps' listing) */ + void (*func)(void); /* "main" for kernel process */ + struct proc **global_procpp; /* ptr to proc ptr save area */ +}; + + /* A kernel thread descriptor; used to start "internal" daemons. */ +struct kthread_desc { + const char *arg0; /* arg 0 (for 'ps' listing) */ + void (*func)(void); /* "main" for kernel thread */ + struct thread **global_threadpp; /* ptr to thread ptr save area */ +}; + +int kproc_create(void (*)(void *), void *, struct proc **, + int flags, int pages, const char *, ...) __printflike(6, 7); +void kproc_exit(int) __dead2; +int kproc_resume(struct proc *); +void kproc_shutdown(void *, int); +void kproc_start(const void *); +int kproc_suspend(struct proc *, int); +void kproc_suspend_check(struct proc *); + +/* create a thread inthe given process. create the process if needed */ +int kproc_kthread_add(void (*)(void *), void *, + struct proc **, + struct thread **, + int flags, int pages, + const char *procname, const char *, ...) __printflike(8, 9); + +int kthread_add(void (*)(void *), void *, + struct proc *, struct thread **, + int flags, int pages, const char *, ...) __printflike(7, 8); +void kthread_exit(void) __dead2; +int kthread_resume(struct thread *); +void kthread_shutdown(void *, int); +void kthread_start(const void *); +int kthread_suspend(struct thread *, int); +void kthread_suspend_check(void); + + +#endif /* !_SYS_KTHREAD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ktr.h b/lib/libc/include/any-freebsd-any/sys/ktr.h new file mode 100644 index 000000000000..d9bd2bf6e089 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ktr.h @@ -0,0 +1,269 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $ + * $FreeBSD$ + */ + +/* + * Wraparound kernel trace buffer support. + */ + +#ifndef _SYS_KTR_H_ +#define _SYS_KTR_H_ + +#include + +/* + * Version number for ktr_entry struct. Increment this when you break binary + * compatibility. + */ +#define KTR_VERSION 2 + +#define KTR_PARMS 6 + +#ifndef LOCORE + +#include +#include + +struct ktr_entry { + u_int64_t ktr_timestamp; + int ktr_cpu; + int ktr_line; + const char *ktr_file; + const char *ktr_desc; + struct thread *ktr_thread; + u_long ktr_parms[KTR_PARMS]; +}; + +extern cpuset_t ktr_cpumask; +extern uint64_t ktr_mask; +extern int ktr_entries; +extern int ktr_verbose; + +extern volatile int ktr_idx; +extern struct ktr_entry *ktr_buf; + +#ifdef KTR + +void ktr_tracepoint(uint64_t mask, const char *file, int line, + const char *format, u_long arg1, u_long arg2, u_long arg3, + u_long arg4, u_long arg5, u_long arg6); + +#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ + if (KTR_COMPILE & (m)) \ + ktr_tracepoint((m), __FILE__, __LINE__, format, \ + (u_long)(p1), (u_long)(p2), (u_long)(p3), \ + (u_long)(p4), (u_long)(p5), (u_long)(p6)); \ + } while(0) +#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0) +#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0) +#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0) +#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0) +#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0) +#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0) +#else /* KTR */ +#define CTR0(m, d) (void)0 +#define CTR1(m, d, p1) (void)0 +#define CTR2(m, d, p1, p2) (void)0 +#define CTR3(m, d, p1, p2, p3) (void)0 +#define CTR4(m, d, p1, p2, p3, p4) (void)0 +#define CTR5(m, d, p1, p2, p3, p4, p5) (void)0 +#define CTR6(m, d, p1, p2, p3, p4, p5, p6) (void)0 +#endif /* KTR */ + +#define TR0(d) CTR0(KTR_GEN, d) +#define TR1(d, p1) CTR1(KTR_GEN, d, p1) +#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) +#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) +#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) +#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) +#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6) + +/* + * The event macros implement KTR graphic plotting facilities provided + * by src/tools/sched/schedgraph.py. Three generic types of events are + * supported: states, counters, and points. + * + * m is the ktr class for ktr_mask. + * ident is the string identifier that owns the event (ie: "thread 10001") + * etype is the type of event to plot (state, counter, point) + * edat is the event specific data (state name, counter value, point name) + * up to four attributes may be supplied as a name, value pair of arguments. + * + * etype and attribute names must be string constants. This minimizes the + * number of ktr slots required by construction the final format strings + * at compile time. Both must also include a colon and format specifier + * (ie. "prio:%d", prio). It is recommended that string arguments be + * contained within escaped quotes if they may contain ',' or ':' characters. + * + * The special attribute (KTR_ATTR_LINKED, ident) creates a reference to another + * id on the graph for easy traversal of related graph elements. + */ + +#define KTR_ATTR_LINKED "linkedto:\"%s\"" +#define KTR_EFMT(egroup, ident, etype) \ + "KTRGRAPH group:\"" egroup "\", id:\"%s\", " etype ", attributes: " + +#define KTR_EVENT0(m, egroup, ident, etype, edat) \ + CTR2(m, KTR_EFMT(egroup, ident, etype) "none", ident, edat) +#define KTR_EVENT1(m, egroup, ident, etype, edat, a0, v0) \ + CTR3(m, KTR_EFMT(egroup, ident, etype) a0, ident, edat, (v0)) +#define KTR_EVENT2(m, egroup, ident, etype, edat, a0, v0, a1, v1) \ + CTR4(m, KTR_EFMT(egroup, ident, etype) a0 ", " a1, \ + ident, edat, (v0), (v1)) +#define KTR_EVENT3(m, egroup, ident, etype, edat, a0, v0, a1, v1, a2, v2)\ + CTR5(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2, \ + ident, edat, (v0), (v1), (v2)) +#define KTR_EVENT4(m, egroup, ident, etype, edat, \ + a0, v0, a1, v1, a2, v2, a3, v3) \ + CTR6(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2 ", " a3,\ + ident, edat, (v0), (v1), (v2), (v3)) + +/* + * State functions graph state changes on an ident. + */ +#define KTR_STATE0(m, egroup, ident, state) \ + KTR_EVENT0(m, egroup, ident, "state:\"%s\"", state) +#define KTR_STATE1(m, egroup, ident, state, a0, v0) \ + KTR_EVENT1(m, egroup, ident, "state:\"%s\"", state, a0, (v0)) +#define KTR_STATE2(m, egroup, ident, state, a0, v0, a1, v1) \ + KTR_EVENT2(m, egroup, ident, "state:\"%s\"", state, a0, (v0), a1, (v1)) +#define KTR_STATE3(m, egroup, ident, state, a0, v0, a1, v1, a2, v2) \ + KTR_EVENT3(m, egroup, ident, "state:\"%s\"", \ + state, a0, (v0), a1, (v1), a2, (v2)) +#define KTR_STATE4(m, egroup, ident, state, a0, v0, a1, v1, a2, v2, a3, v3)\ + KTR_EVENT4(m, egroup, ident, "state:\"%s\"", \ + state, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) + +/* + * Counter functions graph counter values. The counter id + * must not be intermixed with a state id. + */ +#define KTR_COUNTER0(m, egroup, ident, counter) \ + KTR_EVENT0(m, egroup, ident, "counter:%d", counter) +#define KTR_COUNTER1(m, egroup, ident, edat, a0, v0) \ + KTR_EVENT1(m, egroup, ident, "counter:%d", counter, a0, (v0)) +#define KTR_COUNTER2(m, egroup, ident, counter, a0, v0, a1, v1) \ + KTR_EVENT2(m, egroup, ident, "counter:%d", counter, a0, (v0), a1, (v1)) +#define KTR_COUNTER3(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2) \ + KTR_EVENT3(m, egroup, ident, "counter:%d", \ + counter, a0, (v0), a1, (v1), a2, (v2)) +#define KTR_COUNTER4(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2, a3, v3)\ + KTR_EVENT4(m, egroup, ident, "counter:%d", \ + counter, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) + +/* + * Point functions plot points of interest on counter or state graphs. + */ +#define KTR_POINT0(m, egroup, ident, point) \ + KTR_EVENT0(m, egroup, ident, "point:\"%s\"", point) +#define KTR_POINT1(m, egroup, ident, point, a0, v0) \ + KTR_EVENT1(m, egroup, ident, "point:\"%s\"", point, a0, (v0)) +#define KTR_POINT2(m, egroup, ident, point, a0, v0, a1, v1) \ + KTR_EVENT2(m, egroup, ident, "point:\"%s\"", point, a0, (v0), a1, (v1)) +#define KTR_POINT3(m, egroup, ident, point, a0, v0, a1, v1, a2, v2) \ + KTR_EVENT3(m, egroup, ident, "point:\"%s\"", point, \ + a0, (v0), a1, (v1), a2, (v2)) +#define KTR_POINT4(m, egroup, ident, point, a0, v0, a1, v1, a2, v2, a3, v3)\ + KTR_EVENT4(m, egroup, ident, "point:\"%s\"", \ + point, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) + +/* + * Start functions denote the start of a region of code or operation + * and should be paired with stop functions for timing of nested + * sequences. + * + * Specifying extra attributes with the name "key" will result in + * multi-part keys. For example a block device and offset pair + * might be used to describe a buf undergoing I/O. + */ +#define KTR_START0(m, egroup, ident, key) \ + KTR_EVENT0(m, egroup, ident, "start:0x%jX", (uintmax_t)key) +#define KTR_START1(m, egroup, ident, key, a0, v0) \ + KTR_EVENT1(m, egroup, ident, "start:0x%jX", (uintmax_t)key, a0, (v0)) +#define KTR_START2(m, egroup, ident, key, a0, v0, a1, v1) \ + KTR_EVENT2(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1)) +#define KTR_START3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ + KTR_EVENT3(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1), a2, (v2)) +#define KTR_START4(m, egroup, ident, key, \ + a0, v0, a1, v1, a2, v2, a3, v3) \ + KTR_EVENT4(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1), a2, (v2), a3, (v3)) + +/* + * Stop functions denote the end of a region of code or operation + * and should be paired with start functions for timing of nested + * sequences. + */ +#define KTR_STOP0(m, egroup, ident, key) \ + KTR_EVENT0(m, egroup, ident, "stop:0x%jX", (uintmax_t)key) +#define KTR_STOP1(m, egroup, ident, key, a0, v0) \ + KTR_EVENT1(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, a0, (v0)) +#define KTR_STOP2(m, egroup, ident, key, a0, v0, a1, v1) \ + KTR_EVENT2(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1)) +#define KTR_STOP3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ + KTR_EVENT3(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1), a2, (v2)) +#define KTR_STOP4(m, egroup, ident, \ + key, a0, v0, a1, v1, a2, v2, a3, v3) \ + KTR_EVENT4(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ + a0, (v0), a1, (v1), a2, (v2), a3, (v3)) + +/* + * Trace initialization events, similar to CTR with KTR_INIT, but + * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to + * save string space, the compiler doesn't optimize out strings + * for the conditional ones above). + */ +#if (KTR_COMPILE & KTR_INIT) != 0 +#define ITR0(d) CTR0(KTR_INIT, d) +#define ITR1(d, p1) CTR1(KTR_INIT, d, p1) +#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) +#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) +#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) +#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) +#define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6) +#else +#define ITR0(d) +#define ITR1(d, p1) +#define ITR2(d, p1, p2) +#define ITR3(d, p1, p2, p3) +#define ITR4(d, p1, p2, p3, p4) +#define ITR5(d, p1, p2, p3, p4, p5) +#define ITR6(d, p1, p2, p3, p4, p5, p6) +#endif + +#endif /* !LOCORE */ + +#endif /* !_SYS_KTR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ktr_class.h b/lib/libc/include/any-freebsd-any/sys/ktr_class.h new file mode 100644 index 000000000000..32d905d23a2e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ktr_class.h @@ -0,0 +1,89 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $ + * $FreeBSD$ + */ + +#ifndef _SYS_KTR_CLASS_H_ +#define _SYS_KTR_CLASS_H_ + +/* + * KTR trace classes + * + * Two of the trace classes (KTR_DEV and KTR_SUBSYS) are special in that + * they are really placeholders so that indvidual drivers and subsystems + * can map their internal tracing to the general class when they wish to + * have tracing enabled and map it to 0 when they don't. + */ +#define KTR_GEN 0x00000001 /* General (TR) */ +#define KTR_NET 0x00000002 /* Network */ +#define KTR_DEV 0x00000004 /* Device driver */ +#define KTR_LOCK 0x00000008 /* MP locking */ +#define KTR_SMP 0x00000010 /* MP general */ +#define KTR_SUBSYS 0x00000020 /* Subsystem. */ +#define KTR_PMAP 0x00000040 /* Pmap tracing */ +#define KTR_MALLOC 0x00000080 /* Malloc tracing */ +#define KTR_TRAP 0x00000100 /* Trap processing */ +#define KTR_INTR 0x00000200 /* Interrupt tracing */ +#define KTR_SIG 0x00000400 /* Signal processing */ +#define KTR_SPARE2 0x00000800 /* cxgb, amd64, xen, clk, &c */ +#define KTR_PROC 0x00001000 /* Process scheduling */ +#define KTR_SYSC 0x00002000 /* System call */ +#define KTR_INIT 0x00004000 /* System initialization */ +#define KTR_SPARE3 0x00008000 /* cxgb, drm2, ioat, ntb */ +#define KTR_SPARE4 0x00010000 /* geom_sched */ +#define KTR_EVH 0x00020000 /* Eventhandler */ +#define KTR_VFS 0x00040000 /* VFS events */ +#define KTR_VOP 0x00080000 /* Auto-generated vop events */ +#define KTR_VM 0x00100000 /* The virtual memory system */ +#define KTR_INET 0x00200000 /* IPv4 stack */ +#define KTR_RUNQ 0x00400000 /* Run queue */ +#define KTR_SPARE5 0x00800000 +#define KTR_UMA 0x01000000 /* UMA slab allocator */ +#define KTR_CALLOUT 0x02000000 /* Callouts and timeouts */ +#define KTR_GEOM 0x04000000 /* GEOM I/O events */ +#define KTR_BUSDMA 0x08000000 /* busdma(9) events */ +#define KTR_INET6 0x10000000 /* IPv6 stack */ +#define KTR_SCHED 0x20000000 /* Machine parsed sched info. */ +#define KTR_BUF 0x40000000 /* Buffer cache */ +#define KTR_PTRACE 0x80000000 /* Process debugging. */ +#define KTR_ALL 0xffffffff + +/* KTR trace classes to compile in */ +#ifdef KTR +#ifndef KTR_COMPILE +#define KTR_COMPILE (KTR_ALL) +#endif +#else /* !KTR */ +#undef KTR_COMPILE +#define KTR_COMPILE 0 +#endif /* KTR */ + +#endif /* !_SYS_KTR_CLASS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ktrace.h b/lib/libc/include/any-freebsd-any/sys/ktrace.h new file mode 100644 index 000000000000..97fe82730315 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ktrace.h @@ -0,0 +1,306 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ktrace.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_KTRACE_H_ +#define _SYS_KTRACE_H_ + +#include + +/* + * operations to ktrace system call (KTROP(op)) + */ +#define KTROP_SET 0 /* set trace points */ +#define KTROP_CLEAR 1 /* clear trace points */ +#define KTROP_CLEARFILE 2 /* stop all tracing to file */ +#define KTROP(o) ((o)&3) /* macro to extract operation */ +/* + * flags (ORed in with operation) + */ +#define KTRFLAG_DESCEND 4 /* perform op on all children too */ + +/* + * ktrace record header + */ +struct ktr_header { + int ktr_len; /* length of buf */ + short ktr_type; /* trace record type */ + pid_t ktr_pid; /* process id */ + char ktr_comm[MAXCOMLEN + 1];/* command name */ + struct timeval ktr_time; /* timestamp */ + intptr_t ktr_tid; /* was ktr_buffer */ +}; + +/* + * Test for kernel trace point (MP SAFE). + * + * KTRCHECK() just checks that the type is enabled and is only for + * internal use in the ktrace subsystem. KTRPOINT() checks against + * ktrace recursion as well as checking that the type is enabled and + * is the public interface. + */ +#define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type)) +#define KTRPOINT(td, type) (__predict_false(KTRCHECK((td), (type)))) +#define KTRCHECKDRAIN(td) (!(STAILQ_EMPTY(&(td)->td_proc->p_ktr))) +#define KTRUSERRET(td) do { \ + if (KTRCHECKDRAIN(td)) \ + ktruserret(td); \ +} while (0) + +/* + * ktrace record types + */ + +/* + * KTR_SYSCALL - system call record + */ +#define KTR_SYSCALL 1 +struct ktr_syscall { + short ktr_code; /* syscall number */ + short ktr_narg; /* number of arguments */ + /* + * followed by ktr_narg register_t + */ + register_t ktr_args[1]; +}; + +/* + * KTR_SYSRET - return from system call record + */ +#define KTR_SYSRET 2 +struct ktr_sysret { + short ktr_code; + short ktr_eosys; + int ktr_error; + register_t ktr_retval; +}; + +/* + * KTR_NAMEI - namei record + */ +#define KTR_NAMEI 3 + /* record contains pathname */ + +/* + * KTR_GENIO - trace generic process i/o + */ +#define KTR_GENIO 4 +struct ktr_genio { + int ktr_fd; + enum uio_rw ktr_rw; + /* + * followed by data successfully read/written + */ +}; + +/* + * KTR_PSIG - trace processed signal + */ +#define KTR_PSIG 5 +struct ktr_psig { + int signo; + sig_t action; + int code; + sigset_t mask; +}; + +/* + * KTR_CSW - trace context switches + */ +#define KTR_CSW 6 +struct ktr_csw_old { + int out; /* 1 if switch out, 0 if switch in */ + int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */ +}; + +struct ktr_csw { + int out; /* 1 if switch out, 0 if switch in */ + int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */ + char wmesg[8]; +}; + +/* + * KTR_USER - data coming from userland + */ +#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */ +#define KTR_USER 7 + +/* + * KTR_STRUCT - misc. structs + */ +#define KTR_STRUCT 8 + /* + * record contains null-terminated struct name followed by + * struct contents + */ +struct sockaddr; +struct stat; +struct sysentvec; + +/* + * KTR_SYSCTL - name of a sysctl MIB + */ +#define KTR_SYSCTL 9 + /* record contains null-terminated MIB name */ + +/* + * KTR_PROCCTOR - trace process creation (multiple ABI support) + */ +#define KTR_PROCCTOR 10 +struct ktr_proc_ctor { + u_int sv_flags; /* struct sysentvec sv_flags copy */ +}; + +/* + * KTR_PROCDTOR - trace process destruction (multiple ABI support) + */ +#define KTR_PROCDTOR 11 + +/* + * KTR_CAPFAIL - trace capability check failures + */ +#define KTR_CAPFAIL 12 +enum ktr_cap_fail_type { + CAPFAIL_NOTCAPABLE, /* insufficient capabilities in cap_check() */ + CAPFAIL_INCREASE, /* attempt to increase capabilities */ + CAPFAIL_SYSCALL, /* disallowed system call */ + CAPFAIL_LOOKUP, /* disallowed VFS lookup */ +}; +struct ktr_cap_fail { + enum ktr_cap_fail_type cap_type; + cap_rights_t cap_needed; + cap_rights_t cap_held; +}; + +/* + * KTR_FAULT - page fault record + */ +#define KTR_FAULT 13 +struct ktr_fault { + vm_offset_t vaddr; + int type; +}; + +/* + * KTR_FAULTEND - end of page fault record + */ +#define KTR_FAULTEND 14 +struct ktr_faultend { + int result; +}; + +/* + * KTR_STRUCT_ARRAY - array of misc. structs + */ +#define KTR_STRUCT_ARRAY 15 +struct ktr_struct_array { + size_t struct_size; + /* + * Followed by null-terminated structure name and then payload + * contents. + */ +}; + +/* + * KTR_DROP - If this bit is set in ktr_type, then at least one event + * between the previous record and this record was dropped. + */ +#define KTR_DROP 0x8000 + +/* + * kernel trace points (in p_traceflag) + */ +#define KTRFAC_MASK 0x00ffffff +#define KTRFAC_SYSCALL (1<sa_len) +#define ktrstat(s) \ + ktrstruct("stat", (s), sizeof(struct stat)) +extern u_int ktr_geniosize; +#else + +#include + +__BEGIN_DECLS +int ktrace(const char *, int, int, pid_t); +int utrace(const void *, size_t); +__END_DECLS + +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/libkern.h b/lib/libc/include/any-freebsd-any/sys/libkern.h new file mode 100644 index 000000000000..0c4e1381be1a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/libkern.h @@ -0,0 +1,253 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)libkern.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD$ + */ + +#ifndef _SYS_LIBKERN_H_ +#define _SYS_LIBKERN_H_ + +#include +#include +#ifdef _KERNEL +#include +#endif + +#ifndef LIBKERN_INLINE +#define LIBKERN_INLINE static __inline +#define LIBKERN_BODY +#endif + +/* BCD conversions. */ +extern u_char const bcd2bin_data[]; +extern u_char const bin2bcd_data[]; +extern char const hex2ascii_data[]; + +#define LIBKERN_LEN_BCD2BIN 154 +#define LIBKERN_LEN_BIN2BCD 100 +#define LIBKERN_LEN_HEX2ASCII 36 + +static inline u_char +bcd2bin(int bcd) +{ + + KASSERT(bcd >= 0 && bcd < LIBKERN_LEN_BCD2BIN, + ("invalid bcd %d", bcd)); + return (bcd2bin_data[bcd]); +} + +static inline u_char +bin2bcd(int bin) +{ + + KASSERT(bin >= 0 && bin < LIBKERN_LEN_BIN2BCD, + ("invalid bin %d", bin)); + return (bin2bcd_data[bin]); +} + +static inline char +hex2ascii(int hex) +{ + + KASSERT(hex >= 0 && hex < LIBKERN_LEN_HEX2ASCII, + ("invalid hex %d", hex)); + return (hex2ascii_data[hex]); +} + +static inline bool +validbcd(int bcd) +{ + + return (bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0)); +} + +static __inline int imax(int a, int b) { return (a > b ? a : b); } +static __inline int imin(int a, int b) { return (a < b ? a : b); } +static __inline long lmax(long a, long b) { return (a > b ? a : b); } +static __inline long lmin(long a, long b) { return (a < b ? a : b); } +static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } +static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } +static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } +static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } +static __inline u_quad_t uqmax(u_quad_t a, u_quad_t b) { return (a > b ? a : b); } +static __inline u_quad_t uqmin(u_quad_t a, u_quad_t b) { return (a < b ? a : b); } +static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } +static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } +static __inline __uintmax_t ummax(__uintmax_t a, __uintmax_t b) +{ + + return (a > b ? a : b); +} +static __inline __uintmax_t ummin(__uintmax_t a, __uintmax_t b) +{ + + return (a < b ? a : b); +} +static __inline off_t omax(off_t a, off_t b) { return (a > b ? a : b); } +static __inline off_t omin(off_t a, off_t b) { return (a < b ? a : b); } + +static __inline int abs(int a) { return (a < 0 ? -a : a); } +static __inline long labs(long a) { return (a < 0 ? -a : a); } +static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); } + +#define ARC4_ENTR_NONE 0 /* Don't have entropy yet. */ +#define ARC4_ENTR_HAVE 1 /* Have entropy. */ +#define ARC4_ENTR_SEED 2 /* Reseeding. */ +extern int arc4rand_iniseed_state; + +/* Prototypes for non-quad routines. */ +struct malloc_type; +uint32_t arc4random(void); +void arc4random_buf(void *, size_t); +uint32_t arc4random_uniform(uint32_t); +void arc4rand(void *, u_int, int); +int timingsafe_bcmp(const void *, const void *, size_t); +void *bsearch(const void *, const void *, size_t, + size_t, int (*)(const void *, const void *)); +#ifndef HAVE_INLINE_FFS +int ffs(int); +#endif +#ifndef HAVE_INLINE_FFSL +int ffsl(long); +#endif +#ifndef HAVE_INLINE_FFSLL +int ffsll(long long); +#endif +#ifndef HAVE_INLINE_FLS +int fls(int); +#endif +#ifndef HAVE_INLINE_FLSL +int flsl(long); +#endif +#ifndef HAVE_INLINE_FLSLL +int flsll(long long); +#endif +#define bitcount64(x) __bitcount64((uint64_t)(x)) +#define bitcount32(x) __bitcount32((uint32_t)(x)) +#define bitcount16(x) __bitcount16((uint16_t)(x)) +#define bitcountl(x) __bitcountl((u_long)(x)) +#define bitcount(x) __bitcount((u_int)(x)) + +int fnmatch(const char *, const char *, int); +int locc(int, char *, u_int); +void *memchr(const void *s, int c, size_t n); +void *memcchr(const void *s, int c, size_t n); +void *memmem(const void *l, size_t l_len, const void *s, size_t s_len); +void qsort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, + int (*compar)(void *, const void *, const void *)); +u_long random(void); +int scanc(u_int, const u_char *, const u_char *, int); +void srandom(u_long); +int strcasecmp(const char *, const char *); +char *strcat(char * __restrict, const char * __restrict); +char *strchr(const char *, int); +int strcmp(const char *, const char *); +char *strcpy(char * __restrict, const char * __restrict); +size_t strcspn(const char * __restrict, const char * __restrict) __pure; +char *strdup_flags(const char *__restrict, struct malloc_type *, int); +char *strdup(const char *__restrict, struct malloc_type *); +char *strncat(char *, const char *, size_t); +char *strndup(const char *__restrict, size_t, struct malloc_type *); +size_t strlcat(char *, const char *, size_t); +size_t strlcpy(char *, const char *, size_t); +size_t strlen(const char *); +int strncasecmp(const char *, const char *, size_t); +int strncmp(const char *, const char *, size_t); +char *strncpy(char * __restrict, const char * __restrict, size_t); +size_t strnlen(const char *, size_t); +char *strrchr(const char *, int); +char *strsep(char **, const char *delim); +size_t strspn(const char *, const char *); +char *strstr(const char *, const char *); +int strvalid(const char *, size_t); + +extern const uint32_t crc32_tab[]; + +static __inline uint32_t +crc32_raw(const void *buf, size_t size, uint32_t crc) +{ + const uint8_t *p = (const uint8_t *)buf; + + while (size--) + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + return (crc); +} + +static __inline uint32_t +crc32(const void *buf, size_t size) +{ + uint32_t crc; + + crc = crc32_raw(buf, size, ~0U); + return (crc ^ ~0U); +} + +uint32_t +calculate_crc32c(uint32_t crc32c, const unsigned char *buffer, + unsigned int length); +#ifdef _KERNEL +#if defined(__amd64__) || defined(__i386__) +uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); +#endif +#if defined(__aarch64__) +uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); +#endif +#endif + +static __inline char * +index(const char *p, int ch) +{ + + return (strchr(p, ch)); +} + +static __inline char * +rindex(const char *p, int ch) +{ + + return (strrchr(p, ch)); +} + +/* fnmatch() return values. */ +#define FNM_NOMATCH 1 /* Match failed. */ + +/* fnmatch() flags. */ +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME + +#endif /* !_SYS_LIBKERN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/limits.h b/lib/libc/include/any-freebsd-any/sys/limits.h new file mode 100644 index 000000000000..d4fb8b7e04e3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/limits.h @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_LIMITS_H_ +#define _SYS_LIMITS_H_ + +#include +#include + +#define CHAR_BIT __CHAR_BIT /* number of bits in a char */ + +#define SCHAR_MAX __SCHAR_MAX /* max value for a signed char */ +#define SCHAR_MIN __SCHAR_MIN /* min value for a signed char */ + +#define UCHAR_MAX __UCHAR_MAX /* max value for an unsigned char */ + +#ifdef __CHAR_UNSIGNED__ +#define CHAR_MAX UCHAR_MAX /* max value for a char */ +#define CHAR_MIN 0 /* min value for a char */ +#else +#define CHAR_MAX SCHAR_MAX +#define CHAR_MIN SCHAR_MIN +#endif + +#define USHRT_MAX __USHRT_MAX /* max value for an unsigned short */ +#define SHRT_MAX __SHRT_MAX /* max value for a short */ +#define SHRT_MIN __SHRT_MIN /* min value for a short */ + +#define UINT_MAX __UINT_MAX /* max value for an unsigned int */ +#define INT_MAX __INT_MAX /* max value for an int */ +#define INT_MIN __INT_MIN /* min value for an int */ + +#define ULONG_MAX __ULONG_MAX /* max for an unsigned long */ +#define LONG_MAX __LONG_MAX /* max for a long */ +#define LONG_MIN __LONG_MIN /* min for a long */ + +#ifdef __LONG_LONG_SUPPORTED +#define ULLONG_MAX __ULLONG_MAX /* max for an unsigned long long */ +#define LLONG_MAX __LLONG_MAX /* max for a long long */ +#define LLONG_MIN __LLONG_MIN /* min for a long long */ +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SSIZE_MAX __SSIZE_MAX /* max value for an ssize_t */ +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIZE_T_MAX __SIZE_T_MAX /* max value for a size_t */ + +#define OFF_MAX __OFF_MAX /* max value for an off_t */ +#define OFF_MIN __OFF_MIN /* min value for an off_t */ +#endif + +#if __BSD_VISIBLE +#define GID_MAX UINT_MAX /* max value for a gid_t */ +#define UID_MAX UINT_MAX /* max value for a uid_t */ + +#define UQUAD_MAX (__UQUAD_MAX) /* max value for a uquad_t */ +#define QUAD_MAX (__QUAD_MAX) /* max value for a quad_t */ +#define QUAD_MIN (__QUAD_MIN) /* min value for a quad_t */ +#endif + +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200809 +#define LONG_BIT __LONG_BIT +#define WORD_BIT __WORD_BIT +#endif + +#if __POSIX_VISIBLE +#define MQ_PRIO_MAX 64 +#endif + +#endif /* !_SYS_LIMITS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/link_aout.h b/lib/libc/include/any-freebsd-any/sys/link_aout.h new file mode 100644 index 000000000000..2e4f3862c747 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/link_aout.h @@ -0,0 +1,290 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1993 Paul Kranenburg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * RRS section definitions. + * + * The layout of some data structures defined in this header file is + * such that we can provide compatibility with the SunOS 4.x shared + * library scheme. + */ + +#ifndef _SYS_LINK_AOUT_H_ +#define _SYS_LINK_AOUT_H_ + +struct dl_info; + +/* + * A `Shared Object Descriptor' describes a shared object that is needed + * to complete the link edit process of the object containing it. + * A list of such objects (chained through `sod_next') is pointed at + * by `sdt_sods' in the section_dispatch_table structure. + */ + +struct sod { /* Shared Object Descriptor */ + long sod_name; /* name (relative to load address) */ + u_int sod_library : 1, /* Searched for by library rules */ + sod_reserved : 31; + short sod_major; /* major version number */ + short sod_minor; /* minor version number */ + long sod_next; /* next sod */ +}; + +/* + * `Shared Object Map's are used by the run-time link editor (ld.so) to + * keep track of all shared objects loaded into a process' address space. + * These structures are only used at run-time and do not occur within + * the text or data segment of an executable or shared library. + */ +struct so_map { /* Shared Object Map */ + caddr_t som_addr; /* Address at which object mapped */ + char *som_path; /* Path to mmap'ed file */ + struct so_map *som_next; /* Next map in chain */ + struct sod *som_sod; /* Sod responsible for this map */ + caddr_t som_sodbase; /* Base address of this sod */ + u_int som_write : 1; /* Text is currently writable */ + struct _dynamic *som_dynamic; /* _dynamic structure */ + caddr_t som_spd; /* Private data */ +}; + +/* + * Symbol description with size. This is simply an `nlist' with + * one field (nz_size) added. + * Used to convey size information on items in the data segment + * of shared objects. An array of these live in the shared object's + * text segment and is addressed by the `sdt_nzlist' field. + */ +struct nzlist { + struct nlist nlist; + u_long nz_size; +}; + +#define nz_un nlist.n_un +#define nz_strx nlist.n_un.n_strx +#define nz_name nlist.n_un.n_name +#define nz_type nlist.n_type +#define nz_value nlist.n_value +#define nz_desc nlist.n_desc +#define nz_other nlist.n_other + +/* + * The `section_dispatch_table' structure contains offsets to various data + * structures needed to do run-time relocation. + */ +struct section_dispatch_table { + struct so_map *sdt_loaded; /* List of loaded objects */ + long sdt_sods; /* List of shared objects descriptors */ + long sdt_paths; /* Library search paths */ + long sdt_got; /* Global offset table */ + long sdt_plt; /* Procedure linkage table */ + long sdt_rel; /* Relocation table */ + long sdt_hash; /* Symbol hash table */ + long sdt_nzlist; /* Symbol table itself */ + long sdt_filler2; /* Unused (was: stab_hash) */ + long sdt_buckets; /* Number of hash buckets */ + long sdt_strings; /* Symbol strings */ + long sdt_str_sz; /* Size of symbol strings */ + long sdt_text_sz; /* Size of text area */ + long sdt_plt_sz; /* Size of procedure linkage table */ +}; + +/* + * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. + * Used to quickly lookup symbols of the shared object by hashing + * on the symbol's name. `rh_symbolnum' is the index of the symbol + * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is + * the next symbol in the hash bucket (in case of collisions). + */ +struct rrs_hash { + int rh_symbolnum; /* Symbol number */ + int rh_next; /* Next hash entry */ +}; + +/* + * `rt_symbols' is used to keep track of run-time allocated commons + * and data items copied from shared objects. + */ +struct rt_symbol { + struct nzlist *rt_sp; /* The symbol */ + struct rt_symbol *rt_next; /* Next in linear list */ + struct rt_symbol *rt_link; /* Next in bucket */ + caddr_t rt_srcaddr; /* Address of "master" copy */ + struct so_map *rt_smp; /* Originating map */ +}; + +/* + * Debugger interface structure. + */ +struct so_debug { + int dd_version; /* Version # of interface */ + int dd_in_debugger; /* Set when run by debugger */ + int dd_sym_loaded; /* Run-time linking brought more + symbols into scope */ + char *dd_bpt_addr; /* Address of rtld-generated bpt */ + int dd_bpt_shadow; /* Original contents of bpt */ + struct rt_symbol *dd_cc; /* Allocated commons/copied data */ +}; + +/* + * Version returned to crt0 from ld.so + */ +#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ +#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ +#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ +#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ + +/* + * Entry points into ld.so - user interface to the run-time linker. + * Entries are valid for the given version numbers returned by ld.so + * to crt0. + */ +struct ld_entry { + void *(*dlopen)(const char *, int); /* NONE */ + int (*dlclose)(void *); /* NONE */ + void *(*dlsym)(void *, const char *); /* NONE */ + const char *(*dlerror)(void); /* NONE */ + void (*dlexit)(void); /* HAS_DLEXIT */ + void *(*dlsym3)(void *, const char *, void *); /* HAS_DLSYM3 */ + int (*dladdr)(const void *, struct dl_info *); /* HAS_DLADDR */ +}; + +/* + * This is the structure pointed at by the __DYNAMIC symbol if an + * executable requires the attention of the run-time link editor. + * __DYNAMIC is given the value zero if no run-time linking needs to + * be done (it is always present in shared objects). + * The union `d_un' provides for different versions of the dynamic + * linking mechanism (switched on by `d_version'). The last version + * used by Sun is 3. We leave some room here and go to version number + * 8 for NetBSD, the main difference lying in the support for the + * `nz_list' type of symbols. + */ + +struct _dynamic { + int d_version; /* version # of this interface */ + struct so_debug *d_debug; + union { + struct section_dispatch_table *d_sdt; + } d_un; + struct ld_entry *d_entry; /* XXX */ +}; + +#define LD_VERSION_SUN (3) +#define LD_VERSION_BSD (8) +#define LD_VERSION_NZLIST_P(v) ((v) >= 8) + +#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) +#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) +#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) +#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) +#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) +#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) +#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) +#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) +#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) + +#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) +#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) +#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) +#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) +#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) +#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) +#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) + +/* + * Interface to ld.so + */ +struct crt_ldso { + int crt_ba; /* Base address of ld.so */ + int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ + int crt_ldfd; /* ld.so file descriptor */ + struct _dynamic *crt_dp; /* Main's __DYNAMIC */ + char **crt_ep; /* environment strings */ + caddr_t crt_bp; /* Breakpoint if run from debugger */ + char *crt_prog; /* Program name (v3) */ + char *crt_ldso; /* Link editor name (v4) */ + struct ld_entry *crt_ldentry; /* dl*() access (v4) */ + char **crt_argv; /* argument strings (v5) */ +}; + +/* + * Version passed from crt0 to ld.so (1st argument to _rtld()). + */ +#define CRT_VERSION_SUN 1 +#define CRT_VERSION_BSD_2 2 +#define CRT_VERSION_BSD_3 3 +#define CRT_VERSION_BSD_4 4 +#define CRT_VERSION_BSD_5 5 + +/* + * Maximum number of recognized shared object version numbers. + */ +#define MAXDEWEY 8 + +/* + * Header of the hints file. + */ +struct hints_header { + long hh_magic; +#define HH_MAGIC 011421044151 + long hh_version; /* Interface version number */ +#define LD_HINTS_VERSION_1 1 +#define LD_HINTS_VERSION_2 2 + long hh_hashtab; /* Location of hash table */ + long hh_nbucket; /* Number of buckets in hashtab */ + long hh_strtab; /* Location of strings */ + long hh_strtab_sz; /* Size of strings */ + long hh_ehints; /* End of hints (max offset in file) */ + long hh_dirlist; /* Colon-separated list of srch dirs */ +}; + +#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) + +/* + * Hash table element in hints file. + */ +struct hints_bucket { + /* namex and pathx are indices into the string table */ + int hi_namex; /* Library name */ + int hi_pathx; /* Full path */ + int hi_dewey[MAXDEWEY]; /* The versions */ + int hi_ndewey; /* Number of version numbers */ +#define hi_major hi_dewey[0] +#define hi_minor hi_dewey[1] + int hi_next; /* Next in this bucket */ +}; + +#define _PATH_LD_HINTS "/var/run/ld.so.hints" + +#endif /* _SYS_LINK_AOUT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/link_elf.h b/lib/libc/include/any-freebsd-any/sys/link_elf.h new file mode 100644 index 000000000000..6114765baa4a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/link_elf.h @@ -0,0 +1,109 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1993 Paul Kranenburg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * RRS section definitions. + * + * The layout of some data structures defined in this header file is + * such that we can provide compatibility with the SunOS 4.x shared + * library scheme. + */ + +#ifndef _SYS_LINK_ELF_H_ +#define _SYS_LINK_ELF_H_ + +#include + +/* + * Flags that describe the origin of the entries in Dl_serinfo. + * SunOS has these in , we follow the suit. + */ +#define LA_SER_ORIG 0x01 /* original (needed) name */ +#define LA_SER_LIBPATH 0x02 /* LD_LIBRARY_PATH entry prepended */ +#define LA_SER_RUNPATH 0x04 /* runpath entry prepended */ +#define LA_SER_CONFIG 0x08 /* configuration entry prepended */ +#define LA_SER_DEFAULT 0x40 /* default path prepended */ +#define LA_SER_SECURE 0x80 /* default (secure) path prepended */ + +typedef struct link_map { + caddr_t l_base; /* Base Address of library */ +#ifdef __mips__ + caddr_t l_xxx; /* unused */ +#endif + const char *l_name; /* Absolute Path to Library */ + const void *l_ld; /* Pointer to .dynamic in memory */ + struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ + caddr_t l_addr; /* Load Offset of library */ + const char *l_refname; /* object we are filtering for */ +} Link_map; + +struct r_debug { + int r_version; /* not used */ + struct link_map *r_map; /* list of loaded images */ + void (*r_brk)(struct r_debug *, struct link_map *); + /* pointer to break point */ + enum { + RT_CONSISTENT, /* things are stable */ + RT_ADD, /* adding a shared library */ + RT_DELETE /* removing a shared library */ + } r_state; +}; + +struct dl_phdr_info +{ + Elf_Addr dlpi_addr; /* module relocation base */ + const char *dlpi_name; /* module name */ + const Elf_Phdr *dlpi_phdr; /* pointer to module's phdr */ + Elf_Half dlpi_phnum; /* number of entries in phdr */ + unsigned long long int dlpi_adds; /* total # of loads */ + unsigned long long int dlpi_subs; /* total # of unloads */ + size_t dlpi_tls_modid; + void *dlpi_tls_data; +}; + +__BEGIN_DECLS + +typedef int (*__dl_iterate_hdr_callback)(struct dl_phdr_info *, size_t, void *); +extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void *); +int _rtld_addr_phdr(const void *, struct dl_phdr_info *); +int _rtld_get_stack_prot(void); +int _rtld_is_dlopened(void *); + +#ifdef __ARM_EABI__ +void * dl_unwind_find_exidx(const void *, int *); +#endif + +__END_DECLS + +#endif /* _SYS_LINK_ELF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/linker.h b/lib/libc/include/any-freebsd-any/sys/linker.h new file mode 100644 index 000000000000..1e1af67e43df --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/linker.h @@ -0,0 +1,366 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997-2000 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_LINKER_H_ +#define _SYS_LINKER_H_ + +#ifdef _KERNEL + +#include +#include + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_LINKER); +#endif + +struct mod_depend; + +/* + * Object representing a file which has been loaded by the linker. + */ +typedef struct linker_file* linker_file_t; +typedef TAILQ_HEAD(, linker_file) linker_file_list_t; + +typedef caddr_t linker_sym_t; /* opaque symbol */ +typedef c_caddr_t c_linker_sym_t; /* const opaque symbol */ +typedef int (*linker_function_name_callback_t)(const char *, void *); + +/* + * expanded out linker_sym_t + */ +typedef struct linker_symval { + const char* name; + caddr_t value; + size_t size; +} linker_symval_t; + +typedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *); + +struct common_symbol { + STAILQ_ENTRY(common_symbol) link; + char* name; + caddr_t address; +}; + +struct linker_file { + KOBJ_FIELDS; + int refs; /* reference count */ + int userrefs; /* kldload(2) count */ + int flags; +#define LINKER_FILE_LINKED 0x1 /* file has been fully linked */ +#define LINKER_FILE_MODULES 0x2 /* file has >0 modules at preload */ + TAILQ_ENTRY(linker_file) link; /* list of all loaded files */ + char* filename; /* file which was loaded */ + char* pathname; /* file name with full path */ + int id; /* unique id */ + caddr_t address; /* load address */ + size_t size; /* size of file */ + caddr_t ctors_addr; /* address of .ctors */ + size_t ctors_size; /* size of .ctors */ + int ndeps; /* number of dependencies */ + linker_file_t* deps; /* list of dependencies */ + STAILQ_HEAD(, common_symbol) common; /* list of common symbols */ + TAILQ_HEAD(, module) modules; /* modules in this file */ + TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */ + int loadcnt; /* load counter value */ + + /* + * Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT) + * fields. + */ + int nenabled; /* number of enabled probes. */ + int fbt_nentries; /* number of fbt entries created. */ + +#ifdef __arm__ + caddr_t exidx_addr; /* Unwind data index table start */ + size_t exidx_size; /* Unwind data index table size */ +#endif +}; + +/* + * Object implementing a class of file (a.out, elf, etc.) + */ +typedef struct linker_class *linker_class_t; +typedef TAILQ_HEAD(, linker_class) linker_class_list_t; + +struct linker_class { + KOBJ_CLASS_FIELDS; + TAILQ_ENTRY(linker_class) link; /* list of all file classes */ +}; + +/* + * Function type used when iterating over the list of linker files. + */ +typedef int linker_predicate_t(linker_file_t, void *); + +/* + * The "file" for the kernel. + */ +extern linker_file_t linker_kernel_file; + +/* + * Obtain a reference to a module, loading it if required. + */ +int linker_reference_module(const char* _modname, struct mod_depend *_verinfo, + linker_file_t* _result); + +/* + * Release a reference to a module, unloading it if there are no more + * references. Note that one should either provide a module name and + * optional version info or a linker file, but not both. + */ +int linker_release_module(const char *_modname, struct mod_depend *_verinfo, + linker_file_t _file); + +/* + * Iterate over all of the currently loaded linker files calling the + * predicate function while the function returns 0. Returns the value + * returned by the last predicate function. + */ +int linker_file_foreach(linker_predicate_t *_predicate, void *_context); + +/* + * Lookup a symbol in a file. If deps is TRUE, look in dependencies + * if not found in file. + */ +caddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name, + int _deps); + +/* + * Lookup a linker set in a file. Return pointers to the first entry, + * last + 1, and count of entries. Use: for (p = start; p < stop; p++) {} + * void *start is really: "struct yoursetmember ***start;" + */ +int linker_file_lookup_set(linker_file_t _file, const char *_name, + void *_start, void *_stop, int *_count); + +/* + * List all functions in a file. + */ +int linker_file_function_listall(linker_file_t, + linker_function_nameval_callback_t, void *); + +/* + * Functions solely for use by the linker class handlers. + */ +int linker_add_class(linker_class_t _cls); +int linker_file_unload(linker_file_t _file, int flags); +int linker_load_dependencies(linker_file_t _lf); +linker_file_t linker_make_file(const char* _filename, linker_class_t _cls); + +/* + * DDB Helpers, tuned specifically for ddb/db_kld.c + */ +int linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym); +int linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym, + long *_diffp); +int linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval); +int linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen, + long *offset); + +/* + * stack(9) helper for situations where kernel locking is required. + */ +int linker_search_symbol_name(caddr_t value, char *buf, u_int buflen, + long *offset); + + +/* HWPMC helper */ +void *linker_hwpmc_list_objects(void); + +#endif /* _KERNEL */ + +/* + * Module information subtypes + */ +#define MODINFO_END 0x0000 /* End of list */ +#define MODINFO_NAME 0x0001 /* Name of module (string) */ +#define MODINFO_TYPE 0x0002 /* Type of module (string) */ +#define MODINFO_ADDR 0x0003 /* Loaded address */ +#define MODINFO_SIZE 0x0004 /* Size of module */ +#define MODINFO_EMPTY 0x0005 /* Has been deleted */ +#define MODINFO_ARGS 0x0006 /* Parameters string */ +#define MODINFO_METADATA 0x8000 /* Module-specfic */ + +#define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */ +#define MODINFOMD_ELFHDR 0x0002 /* ELF header */ +#define MODINFOMD_SSYM 0x0003 /* start of symbols */ +#define MODINFOMD_ESYM 0x0004 /* end of symbols */ +#define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */ +/* These values are MD on these two platforms */ +#if !defined(__sparc64__) && !defined(__powerpc__) +#define MODINFOMD_ENVP 0x0006 /* envp[] */ +#define MODINFOMD_HOWTO 0x0007 /* boothowto */ +#define MODINFOMD_KERNEND 0x0008 /* kernend */ +#endif +#define MODINFOMD_SHDR 0x0009 /* section header table */ +#define MODINFOMD_CTORS_ADDR 0x000a /* address of .ctors */ +#define MODINFOMD_CTORS_SIZE 0x000b /* size of .ctors */ +#define MODINFOMD_FW_HANDLE 0x000c /* Firmware dependent handle */ +#define MODINFOMD_KEYBUF 0x000d /* Crypto key intake buffer */ +#define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */ + +#define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */ + +#ifdef _KERNEL +#define MD_FETCH(mdp, info, type) ({ \ + type *__p; \ + __p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \ + __p ? *__p : 0; \ +}) +#endif + +#define LINKER_HINTS_VERSION 1 /* linker.hints file version */ +#define LINKER_HINTS_MAX (1 << 20) /* Allow at most 1MB for linker.hints */ + +#ifdef _KERNEL + +/* + * Module lookup + */ +extern vm_offset_t preload_addr_relocate; +extern caddr_t preload_metadata; + +extern void * preload_fetch_addr(caddr_t _mod); +extern size_t preload_fetch_size(caddr_t _mod); +extern caddr_t preload_search_by_name(const char *_name); +extern caddr_t preload_search_by_type(const char *_type); +extern caddr_t preload_search_next_name(caddr_t _base); +extern caddr_t preload_search_info(caddr_t _mod, int _inf); +extern void preload_delete_name(const char *_name); +extern void preload_bootstrap_relocate(vm_offset_t _offset); + +#ifdef KLD_DEBUG + +extern int kld_debug; +#define KLD_DEBUG_FILE 1 /* file load/unload */ +#define KLD_DEBUG_SYM 2 /* symbol lookup */ + +#define KLD_DPF(cat, args) \ + do { \ + if (kld_debug & KLD_DEBUG_##cat) printf args; \ + } while (0) + +#else + +#define KLD_DPF(cat, args) + +#endif + +typedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *); + +/* Support functions */ +bool elf_is_ifunc_reloc(Elf_Size r_info); +int elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, + int _type, elf_lookup_fn _lu); +int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, + int _type, elf_lookup_fn _lu); +Elf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr); +const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx); +const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx); +void link_elf_ireloc(caddr_t kmdp); + +typedef struct linker_ctf { + const uint8_t *ctftab; /* Decompressed CTF data. */ + int ctfcnt; /* Number of CTF data bytes. */ + const Elf_Sym *symtab; /* Ptr to the symbol table. */ + int nsym; /* Number of symbols. */ + const char *strtab; /* Ptr to the string table. */ + int strcnt; /* Number of string bytes. */ + uint32_t **ctfoffp; /* Ptr to array of obj/fnc offsets. */ + uint32_t **typoffp; /* Ptr to array of type offsets. */ + long *typlenp; /* Ptr to number of type data entries. */ +} linker_ctf_t; + +int linker_ctf_get(linker_file_t, linker_ctf_t *); + +int elf_cpu_load_file(linker_file_t); +int elf_cpu_unload_file(linker_file_t); + +/* values for type */ +#define ELF_RELOC_REL 1 +#define ELF_RELOC_RELA 2 + +/* + * This is version 1 of the KLD file status structure. It is identified + * by its _size_ in the version field. + */ +struct kld_file_stat_1 { + int version; /* set to sizeof(struct kld_file_stat_1) */ + char name[MAXPATHLEN]; + int refs; + int id; + caddr_t address; /* load address */ + size_t size; /* size in bytes */ +}; +#endif /* _KERNEL */ + +struct kld_file_stat { + int version; /* set to sizeof(struct kld_file_stat) */ + char name[MAXPATHLEN]; + int refs; + int id; + caddr_t address; /* load address */ + size_t size; /* size in bytes */ + char pathname[MAXPATHLEN]; +}; + +struct kld_sym_lookup { + int version; /* set to sizeof(struct kld_sym_lookup) */ + char *symname; /* Symbol name we are looking up */ + u_long symvalue; + size_t symsize; +}; +#define KLDSYM_LOOKUP 1 + +/* + * Flags for kldunloadf() and linker_file_unload() + */ +#define LINKER_UNLOAD_NORMAL 0 +#define LINKER_UNLOAD_FORCE 1 + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int kldload(const char* _file); +int kldunload(int _fileid); +int kldunloadf(int _fileid, int flags); +int kldfind(const char* _file); +int kldnext(int _fileid); +int kldstat(int _fileid, struct kld_file_stat* _stat); +int kldfirstmod(int _fileid); +int kldsym(int _fileid, int _cmd, void *_data); +__END_DECLS + +#endif + +#endif /* !_SYS_LINKER_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/linker_set.h b/lib/libc/include/any-freebsd-any/sys/linker_set.h new file mode 100644 index 000000000000..9f49b802887b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/linker_set.h @@ -0,0 +1,111 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999 John D. Polstra + * Copyright (c) 1999,2001 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_LINKER_SET_H_ +#define _SYS_LINKER_SET_H_ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +/* + * The following macros are used to declare global sets of objects, which + * are collected by the linker into a `linker_set' as defined below. + * For ELF, this is done by constructing a separate segment for each set. + */ + +#if defined(__powerpc64__) +/* + * Move the symbol pointer from ".text" to ".data" segment, to make + * the GCC compiler happy: + */ +#define __MAKE_SET_CONST +#else +#define __MAKE_SET_CONST const +#endif + +/* + * Private macros, not to be used outside this header file. + */ +#ifdef __GNUCLIKE___SECTION +#define __MAKE_SET_QV(set, sym, qv) \ + __GLOBL(__CONCAT(__start_set_,set)); \ + __GLOBL(__CONCAT(__stop_set_,set)); \ + static void const * qv \ + __set_##set##_sym_##sym __section("set_" #set) \ + __used = &(sym) +#define __MAKE_SET(set, sym) __MAKE_SET_QV(set, sym, __MAKE_SET_CONST) +#else /* !__GNUCLIKE___SECTION */ +#error this file needs to be ported to your compiler +#endif /* __GNUCLIKE___SECTION */ + +/* + * Public macros. + */ +#define TEXT_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_WSET(set, sym) __MAKE_SET_QV(set, sym, ) +#define BSS_SET(set, sym) __MAKE_SET(set, sym) +#define ABS_SET(set, sym) __MAKE_SET(set, sym) +#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) + +/* + * Initialize before referring to a given linker set. + */ +#define SET_DECLARE(set, ptype) \ + extern ptype __weak_symbol *__CONCAT(__start_set_,set); \ + extern ptype __weak_symbol *__CONCAT(__stop_set_,set) + +#define SET_BEGIN(set) \ + (&__CONCAT(__start_set_,set)) +#define SET_LIMIT(set) \ + (&__CONCAT(__stop_set_,set)) + +/* + * Iterate over all the elements of a set. + * + * Sets always contain addresses of things, and "pvar" points to words + * containing those addresses. Thus is must be declared as "type **pvar", + * and the address of each set item is obtained inside the loop by "*pvar". + */ +#define SET_FOREACH(pvar, set) \ + for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) + +#define SET_ITEM(set, i) \ + ((SET_BEGIN(set))[i]) + +/* + * Provide a count of the items in a set. + */ +#define SET_COUNT(set) \ + (SET_LIMIT(set) - SET_BEGIN(set)) + +#endif /* _SYS_LINKER_SET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/lock.h b/lib/libc/include/any-freebsd-any/sys/lock.h new file mode 100644 index 000000000000..f7e25d278f3b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/lock.h @@ -0,0 +1,362 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from BSDI Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp + * $FreeBSD$ + */ + +#ifndef _SYS_LOCK_H_ +#define _SYS_LOCK_H_ + +#include +#include +#include + +struct lock_list_entry; +struct thread; + +/* + * Lock classes. Each lock has a class which describes characteristics + * common to all types of locks of a given class. + * + * Spin locks in general must always protect against preemption, as it is + * an error to perform any type of context switch while holding a spin lock. + * Also, for an individual lock to be recursable, its class must allow + * recursion and the lock itself must explicitly allow recursion. + * + * The 'lc_ddb_show' function pointer is used to dump class-specific + * data for the 'show lock' DDB command. The 'lc_lock' and + * 'lc_unlock' function pointers are used in sleep(9) and cv_wait(9) + * to lock and unlock locks while blocking on a sleep queue. The + * return value of 'lc_unlock' will be passed to 'lc_lock' on resume + * to allow communication of state between the two routines. + */ + +struct lock_class { + const char *lc_name; + u_int lc_flags; + void (*lc_assert)(const struct lock_object *lock, int what); + void (*lc_ddb_show)(const struct lock_object *lock); + void (*lc_lock)(struct lock_object *lock, uintptr_t how); + int (*lc_owner)(const struct lock_object *lock, + struct thread **owner); + uintptr_t (*lc_unlock)(struct lock_object *lock); +}; + +#define LC_SLEEPLOCK 0x00000001 /* Sleep lock. */ +#define LC_SPINLOCK 0x00000002 /* Spin lock. */ +#define LC_SLEEPABLE 0x00000004 /* Sleeping allowed with this lock. */ +#define LC_RECURSABLE 0x00000008 /* Locks of this type may recurse. */ +#define LC_UPGRADABLE 0x00000010 /* Upgrades and downgrades permitted. */ + +#define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */ +#define LO_INITIALIZED 0x00010000 /* Lock has been initialized. */ +#define LO_WITNESS 0x00020000 /* Should witness monitor this lock. */ +#define LO_QUIET 0x00040000 /* Don't log locking operations. */ +#define LO_RECURSABLE 0x00080000 /* Lock may recurse. */ +#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */ +#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */ +#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */ +#define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */ +#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */ +#define LO_NOPROFILE 0x10000000 /* Don't profile this lock */ +#define LO_NEW 0x20000000 /* Don't check for double-init */ + +/* + * Lock classes are statically assigned an index into the gobal lock_classes + * array. Debugging code looks up the lock class for a given lock object + * by indexing the array. + */ +#define LO_CLASSSHIFT 24 +#define LO_CLASSINDEX(lock) ((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT) +#define LOCK_CLASS(lock) (lock_classes[LO_CLASSINDEX((lock))]) +#define LOCK_CLASS_MAX (LO_CLASSMASK >> LO_CLASSSHIFT) + +/* + * Option flags passed to lock operations that witness also needs to know + * about or that are generic across all locks. + */ +#define LOP_NEWORDER 0x00000001 /* Define a new lock order. */ +#define LOP_QUIET 0x00000002 /* Don't log locking operations. */ +#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */ +#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */ +#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */ + +/* Flags passed to witness_assert. */ +#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */ +#define LA_UNLOCKED 0x00000000 /* Lock is unlocked. */ +#define LA_LOCKED 0x00000001 /* Lock is at least share locked. */ +#define LA_SLOCKED 0x00000002 /* Lock is exactly share locked. */ +#define LA_XLOCKED 0x00000004 /* Lock is exclusively locked. */ +#define LA_RECURSED 0x00000008 /* Lock is recursed. */ +#define LA_NOTRECURSED 0x00000010 /* Lock is not recursed. */ + +#ifdef _KERNEL +/* + * If any of WITNESS, INVARIANTS, or KTR_LOCK KTR tracing has been enabled, + * then turn on LOCK_DEBUG. When this option is on, extra debugging + * facilities such as tracking the file and line number of lock operations + * are enabled. Also, mutex locking operations are not inlined to avoid + * bloat from all the extra debugging code. We also have to turn on all the + * calling conventions for this debugging code in modules so that modules can + * work with both debug and non-debug kernels. + */ +#if (defined(KLD_MODULE) && !defined(KLD_TIED)) || defined(WITNESS) || defined(INVARIANTS) || \ + defined(LOCK_PROFILING) || defined(KTR) +#define LOCK_DEBUG 1 +#else +#define LOCK_DEBUG 0 +#endif + +/* + * In the LOCK_DEBUG case, use the filename and line numbers for debugging + * operations. Otherwise, use default values to avoid the unneeded bloat. + */ +#if LOCK_DEBUG > 0 +#define LOCK_FILE_LINE_ARG_DEF , const char *file, int line +#define LOCK_FILE_LINE_ARG , file, line +#define LOCK_FILE __FILE__ +#define LOCK_LINE __LINE__ +#else +#define LOCK_FILE_LINE_ARG_DEF +#define LOCK_FILE_LINE_ARG +#define LOCK_FILE NULL +#define LOCK_LINE 0 +#endif + +/* + * Macros for KTR_LOCK tracing. + * + * opname - name of this operation (LOCK/UNLOCK/SLOCK, etc.) + * lo - struct lock_object * for this lock + * flags - flags passed to the lock operation + * recurse - this locks recursion level (or 0 if class is not recursable) + * result - result of a try lock operation + * file - file name + * line - line number + */ +#if LOCK_DEBUG > 0 +#define LOCK_LOG_TEST(lo, flags) \ + (((flags) & LOP_QUIET) == 0 && ((lo)->lo_flags & LO_QUIET) == 0) +#else +#define LOCK_LOG_TEST(lo, flags) 0 +#endif + + +#define LOCK_LOG_LOCK(opname, lo, flags, recurse, file, line) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR6(KTR_LOCK, opname " (%s) %s %p r = %d at %s:%d", \ + LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \ + (lo), (u_int)(recurse), (file), (line)); \ +} while (0) + +#define LOCK_LOG_TRY(opname, lo, flags, result, file, line) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR6(KTR_LOCK, "TRY_" opname " (%s) %s %p result=%d at %s:%d",\ + LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \ + (lo), (u_int)(result), (file), (line)); \ +} while (0) + +#define LOCK_LOG_INIT(lo, flags) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR4(KTR_LOCK, "%s: %p (%s) %s", __func__, (lo), \ + LOCK_CLASS(lo)->lc_name, (lo)->lo_name); \ +} while (0) + +#define LOCK_LOG_DESTROY(lo, flags) LOCK_LOG_INIT(lo, flags) + +#define lock_initialized(lo) ((lo)->lo_flags & LO_INITIALIZED) + +/* + * Helpful macros for quickly coming up with assertions with informative + * panic messages. + */ +#define MPASS(ex) MPASS4(ex, #ex, __FILE__, __LINE__) +#define MPASS2(ex, what) MPASS4(ex, what, __FILE__, __LINE__) +#define MPASS3(ex, file, line) MPASS4(ex, #ex, file, line) +#define MPASS4(ex, what, file, line) \ + KASSERT((ex), ("Assertion %s failed at %s:%d", what, file, line)) + +extern struct lock_class lock_class_mtx_sleep; +extern struct lock_class lock_class_mtx_spin; +extern struct lock_class lock_class_sx; +extern struct lock_class lock_class_rw; +extern struct lock_class lock_class_rm; +extern struct lock_class lock_class_rm_sleepable; +extern struct lock_class lock_class_lockmgr; + +extern struct lock_class *lock_classes[]; + +struct lock_delay_config { + u_int base; + u_int max; +}; + +struct lock_delay_arg { + struct lock_delay_config *config; + u_int delay; + u_int spin_cnt; +}; + +static inline void +lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc) +{ + la->config = lc; + la->delay = lc->base; + la->spin_cnt = 0; +} + +#define lock_delay_spin(n) do { \ + u_int _i; \ + \ + for (_i = (n); _i > 0; _i--) \ + cpu_spinwait(); \ +} while (0) + +#define LOCK_DELAY_SYSINIT(func) \ + SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL) + +#define LOCK_DELAY_SYSINIT_DEFAULT(lc) \ + SYSINIT(lock_delay_##lc##_ld, SI_SUB_LOCK, SI_ORDER_ANY, \ + lock_delay_default_init, &lc) + +void lock_init(struct lock_object *, struct lock_class *, + const char *, const char *, int); +void lock_destroy(struct lock_object *); +void lock_delay(struct lock_delay_arg *); +void lock_delay_default_init(struct lock_delay_config *); +void spinlock_enter(void); +void spinlock_exit(void); +void witness_init(struct lock_object *, const char *); +void witness_destroy(struct lock_object *); +int witness_defineorder(struct lock_object *, struct lock_object *); +void witness_checkorder(struct lock_object *, int, const char *, int, + struct lock_object *); +void witness_lock(struct lock_object *, int, const char *, int); +void witness_upgrade(struct lock_object *, int, const char *, int); +void witness_downgrade(struct lock_object *, int, const char *, int); +void witness_unlock(struct lock_object *, int, const char *, int); +void witness_save(struct lock_object *, const char **, int *); +void witness_restore(struct lock_object *, const char *, int); +int witness_list_locks(struct lock_list_entry **, + int (*)(const char *, ...)); +int witness_warn(int, struct lock_object *, const char *, ...); +void witness_assert(const struct lock_object *, int, const char *, int); +void witness_display_spinlock(struct lock_object *, struct thread *, + int (*)(const char *, ...)); +int witness_line(struct lock_object *); +void witness_norelease(struct lock_object *); +void witness_releaseok(struct lock_object *); +const char *witness_file(struct lock_object *); +void witness_thread_exit(struct thread *); + +#ifdef WITNESS +int witness_startup_count(void); +void witness_startup(void *); + +/* Flags for witness_warn(). */ +#define WARN_GIANTOK 0x01 /* Giant is exempt from this check. */ +#define WARN_PANIC 0x02 /* Panic if check fails. */ +#define WARN_SLEEPOK 0x04 /* Sleepable locks are exempt from check. */ + +#define WITNESS_INIT(lock, type) \ + witness_init((lock), (type)) + +#define WITNESS_DESTROY(lock) \ + witness_destroy(lock) + +#define WITNESS_CHECKORDER(lock, flags, file, line, interlock) \ + witness_checkorder((lock), (flags), (file), (line), (interlock)) + +#define WITNESS_DEFINEORDER(lock1, lock2) \ + witness_defineorder((struct lock_object *)(lock1), \ + (struct lock_object *)(lock2)) + +#define WITNESS_LOCK(lock, flags, file, line) \ + witness_lock((lock), (flags), (file), (line)) + +#define WITNESS_UPGRADE(lock, flags, file, line) \ + witness_upgrade((lock), (flags), (file), (line)) + +#define WITNESS_DOWNGRADE(lock, flags, file, line) \ + witness_downgrade((lock), (flags), (file), (line)) + +#define WITNESS_UNLOCK(lock, flags, file, line) \ + witness_unlock((lock), (flags), (file), (line)) + +#define WITNESS_CHECK(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_WARN(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_SAVE_DECL(n) \ + const char * __CONCAT(n, __wf); \ + int __CONCAT(n, __wl) + +#define WITNESS_SAVE(lock, n) \ + witness_save((lock), &__CONCAT(n, __wf), &__CONCAT(n, __wl)) + +#define WITNESS_RESTORE(lock, n) \ + witness_restore((lock), __CONCAT(n, __wf), __CONCAT(n, __wl)) + +#define WITNESS_NORELEASE(lock) \ + witness_norelease(&(lock)->lock_object) + +#define WITNESS_RELEASEOK(lock) \ + witness_releaseok(&(lock)->lock_object) + +#define WITNESS_FILE(lock) \ + witness_file(lock) + +#define WITNESS_LINE(lock) \ + witness_line(lock) + +#else /* WITNESS */ +#define WITNESS_INIT(lock, type) (void)0 +#define WITNESS_DESTROY(lock) (void)0 +#define WITNESS_DEFINEORDER(lock1, lock2) 0 +#define WITNESS_CHECKORDER(lock, flags, file, line, interlock) (void)0 +#define WITNESS_LOCK(lock, flags, file, line) (void)0 +#define WITNESS_UPGRADE(lock, flags, file, line) (void)0 +#define WITNESS_DOWNGRADE(lock, flags, file, line) (void)0 +#define WITNESS_UNLOCK(lock, flags, file, line) (void)0 +#define WITNESS_CHECK(flags, lock, fmt, ...) 0 +#define WITNESS_WARN(flags, lock, fmt, ...) (void)0 +#define WITNESS_SAVE_DECL(n) (void)0 +#define WITNESS_SAVE(lock, n) (void)0 +#define WITNESS_RESTORE(lock, n) (void)0 +#define WITNESS_NORELEASE(lock) (void)0 +#define WITNESS_RELEASEOK(lock) (void)0 +#define WITNESS_FILE(lock) ("?") +#define WITNESS_LINE(lock) (0) +#endif /* WITNESS */ + +#endif /* _KERNEL */ +#endif /* _SYS_LOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/lock_profile.h b/lib/libc/include/any-freebsd-any/sys/lock_profile.h new file mode 100644 index 000000000000..7c7edee4af0a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/lock_profile.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 Kip Macy kmacy@FreeBSD.org + * Copyright (c) 2006 Kris Kennaway kris@FreeBSD.org + * Copyright (c) 2006 Dag-Erling Smorgrav des@des.no + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHAL THE AUTHORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +#ifndef _SYS_LOCK_PROFILE_H_ +#define _SYS_LOCK_PROFILE_H_ + +struct lock_profile_object; +LIST_HEAD(lpohead, lock_profile_object); + +#ifdef _KERNEL +#ifdef LOCK_PROFILING +#include +#include + +#ifndef USE_CPU_NANOSECONDS +u_int64_t nanoseconds(void); +#endif + +extern volatile int lock_prof_enable; + +void lock_profile_obtain_lock_success(struct lock_object *lo, int contested, + uint64_t waittime, const char *file, int line); +void lock_profile_release_lock(struct lock_object *lo); +void lock_profile_thread_exit(struct thread *td); + + +static inline void +lock_profile_obtain_lock_failed(struct lock_object *lo, int *contested, + uint64_t *waittime) +{ + if (!lock_prof_enable || (lo->lo_flags & LO_NOPROFILE) || *contested) + return; + *waittime = nanoseconds(); + *contested = 1; +} + +#else /* !LOCK_PROFILING */ + +#define lock_profile_release_lock(lo) (void)0 +#define lock_profile_obtain_lock_failed(lo, contested, waittime) (void)0 +#define lock_profile_obtain_lock_success(lo, contested, waittime, file, line) (void)0 +#define lock_profile_thread_exit(td) (void)0 + +#endif /* !LOCK_PROFILING */ + +#endif /* _KERNEL */ + +#endif /* _SYS_LOCK_PROFILE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/lockf.h b/lib/libc/include/any-freebsd-any/sys/lockf.h new file mode 100644 index 000000000000..368c773283ec --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/lockf.h @@ -0,0 +1,135 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Scooter Morris at Genentech Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)lockf.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _SYS_LOCKF_H_ +#define _SYS_LOCKF_H_ + +#include +#include +#include + +struct flock; +struct vop_advlock_args; +struct vop_advlockasync_args; + +/* + * The lockf_entry structure is a kernel structure which contains the + * information associated with a byte range lock. The lockf_entry + * structures are linked into the inode structure. Locks are sorted by + * the starting byte of the lock for efficiency. + * + * Active and pending locks on a vnode are organised into a + * graph. Each pending lock has an out-going edge to each active lock + * that blocks it. + * + * Locks: + * (i) locked by the vnode interlock + * (s) locked by state->ls_lock + * (S) locked by lf_lock_states_lock + * (c) const until freeing + */ +struct lockf_edge { + LIST_ENTRY(lockf_edge) le_outlink; /* (s) link from's out-edge list */ + LIST_ENTRY(lockf_edge) le_inlink; /* (s) link to's in-edge list */ + struct lockf_entry *le_from; /* (c) out-going from here */ + struct lockf_entry *le_to; /* (s) in-coming to here */ +}; +LIST_HEAD(lockf_edge_list, lockf_edge); + +struct lockf_entry { + short lf_flags; /* (c) Semantics: F_POSIX, F_FLOCK, F_WAIT */ + short lf_type; /* (s) Lock type: F_RDLCK, F_WRLCK */ + off_t lf_start; /* (s) Byte # of the start of the lock */ + off_t lf_end; /* (s) Byte # of the end of the lock (OFF_MAX=EOF) */ + struct lock_owner *lf_owner; /* (c) Owner of the lock */ + struct vnode *lf_vnode; /* (c) File being locked (only valid for active lock) */ + struct inode *lf_inode; /* (c) Back pointer to the inode */ + struct task *lf_async_task;/* (c) Async lock callback */ + LIST_ENTRY(lockf_entry) lf_link; /* (s) Linkage for lock lists */ + struct lockf_edge_list lf_outedges; /* (s) list of out-edges */ + struct lockf_edge_list lf_inedges; /* (s) list of in-edges */ + int lf_refs; /* (s) ref count */ +}; +LIST_HEAD(lockf_entry_list, lockf_entry); + +/* + * Extra lf_flags bits used by the implementation + */ +#define F_INTR 0x8000 /* lock was interrupted by lf_purgelocks */ + +/* + * Filesystem private node structures should include space for a + * pointer to a struct lockf_state. This pointer is used by the lock + * manager to track the locking state for a file. + * + * The ls_active list contains the set of active locks on the file. It + * is strictly ordered by the lock's lf_start value. Each active lock + * will have in-coming edges to any pending lock which it blocks. + * + * Lock requests which are blocked by some other active lock are + * listed in ls_pending with newer requests first in the list. Lock + * requests in this list will have out-going edges to each active lock + * that blocks then. They will also have out-going edges to each + * pending lock that is older in the queue - this helps to ensure + * fairness when several processes are contenting to lock the same + * record. + + * The value of ls_threads is the number of threads currently using + * the state structure (typically either setting/clearing locks or + * sleeping waiting to do so). This is used to defer freeing the + * structure while some thread is still using it. + */ +struct lockf { + LIST_ENTRY(lockf) ls_link; /* (S) all active lockf states */ + struct sx ls_lock; + struct lockf_entry_list ls_active; /* (s) Active locks */ + struct lockf_entry_list ls_pending; /* (s) Pending locks */ + int ls_threads; /* (i) Thread count */ +}; +LIST_HEAD(lockf_list, lockf); + +typedef int lf_iterator(struct vnode *, struct flock *, void *); + +int lf_advlock(struct vop_advlock_args *, struct lockf **, u_quad_t); +int lf_advlockasync(struct vop_advlockasync_args *, struct lockf **, u_quad_t); +void lf_purgelocks(struct vnode *vp, struct lockf **statep); +int lf_iteratelocks_sysid(int sysid, lf_iterator *, void *); +int lf_iteratelocks_vnode(struct vnode *vp, lf_iterator *, void *); +int lf_countlocks(int sysid); +void lf_clearremotesys(int sysid); + +#endif /* !_SYS_LOCKF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/lockmgr.h b/lib/libc/include/any-freebsd-any/sys/lockmgr.h new file mode 100644 index 000000000000..03ae6f9e4aca --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/lockmgr.h @@ -0,0 +1,204 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Attilio Rao + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_LOCKMGR_H_ +#define _SYS_LOCKMGR_H_ + +#include +#include +#include +#include + +#define LK_SHARE 0x01 +#define LK_SHARED_WAITERS 0x02 +#define LK_EXCLUSIVE_WAITERS 0x04 +#define LK_EXCLUSIVE_SPINNERS 0x08 +#define LK_ALL_WAITERS \ + (LK_SHARED_WAITERS | LK_EXCLUSIVE_WAITERS) +#define LK_FLAGMASK \ + (LK_SHARE | LK_ALL_WAITERS | LK_EXCLUSIVE_SPINNERS) + +#define LK_HOLDER(x) ((x) & ~LK_FLAGMASK) +#define LK_SHARERS_SHIFT 4 +#define LK_SHARERS(x) (LK_HOLDER(x) >> LK_SHARERS_SHIFT) +#define LK_SHARERS_LOCK(x) ((x) << LK_SHARERS_SHIFT | LK_SHARE) +#define LK_ONE_SHARER (1 << LK_SHARERS_SHIFT) +#define LK_UNLOCKED LK_SHARERS_LOCK(0) +#define LK_KERNPROC ((uintptr_t)(-1) & ~LK_FLAGMASK) + +#ifdef _KERNEL + +#if !defined(LOCK_FILE) || !defined(LOCK_LINE) +#error "LOCK_FILE and LOCK_LINE not defined, include before" +#endif + +struct thread; +#define lk_recurse lock_object.lo_data + +/* + * Function prototipes. Routines that start with an underscore are not part + * of the public interface and might be wrappered with a macro. + */ +int __lockmgr_args(struct lock *lk, u_int flags, struct lock_object *ilk, + const char *wmesg, int prio, int timo, const char *file, int line); +int lockmgr_lock_fast_path(struct lock *lk, u_int flags, + struct lock_object *ilk, const char *file, int line); +int lockmgr_unlock_fast_path(struct lock *lk, u_int flags, + struct lock_object *ilk); +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void _lockmgr_assert(const struct lock *lk, int what, const char *file, int line); +#endif +void _lockmgr_disown(struct lock *lk, const char *file, int line); + +void lockallowrecurse(struct lock *lk); +void lockallowshare(struct lock *lk); +void lockdestroy(struct lock *lk); +void lockdisablerecurse(struct lock *lk); +void lockdisableshare(struct lock *lk); +void lockinit(struct lock *lk, int prio, const char *wmesg, int timo, + int flags); +#ifdef DDB +int lockmgr_chain(struct thread *td, struct thread **ownerp); +#endif +void lockmgr_printinfo(const struct lock *lk); +int lockstatus(const struct lock *lk); + +/* + * As far as the ilk can be a static NULL pointer these functions need a + * strict prototype in order to safely use the lock_object member. + */ +static __inline int +_lockmgr_args(struct lock *lk, u_int flags, struct mtx *ilk, const char *wmesg, + int prio, int timo, const char *file, int line) +{ + + return (__lockmgr_args(lk, flags, (ilk != NULL) ? &ilk->lock_object : + NULL, wmesg, prio, timo, file, line)); +} + +static __inline int +_lockmgr_args_rw(struct lock *lk, u_int flags, struct rwlock *ilk, + const char *wmesg, int prio, int timo, const char *file, int line) +{ + + return (__lockmgr_args(lk, flags, (ilk != NULL) ? &ilk->lock_object : + NULL, wmesg, prio, timo, file, line)); +} + +/* + * Define aliases in order to complete lockmgr KPI. + */ +#define lockmgr(lk, flags, ilk) \ + _lockmgr_args((lk), (flags), (ilk), LK_WMESG_DEFAULT, \ + LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, LOCK_FILE, LOCK_LINE) +#define lockmgr_args(lk, flags, ilk, wmesg, prio, timo) \ + _lockmgr_args((lk), (flags), (ilk), (wmesg), (prio), (timo), \ + LOCK_FILE, LOCK_LINE) +#define lockmgr_args_rw(lk, flags, ilk, wmesg, prio, timo) \ + _lockmgr_args_rw((lk), (flags), (ilk), (wmesg), (prio), (timo), \ + LOCK_FILE, LOCK_LINE) +#define lockmgr_disown(lk) \ + _lockmgr_disown((lk), LOCK_FILE, LOCK_LINE) +#define lockmgr_recursed(lk) \ + ((lk)->lk_recurse != 0) +#define lockmgr_rw(lk, flags, ilk) \ + _lockmgr_args_rw((lk), (flags), (ilk), LK_WMESG_DEFAULT, \ + LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, LOCK_FILE, LOCK_LINE) +#ifdef INVARIANTS +#define lockmgr_assert(lk, what) \ + _lockmgr_assert((lk), (what), LOCK_FILE, LOCK_LINE) +#else +#define lockmgr_assert(lk, what) +#endif + +/* + * Flags for lockinit(). + */ +#define LK_INIT_MASK 0x0000FF +#define LK_CANRECURSE 0x000001 +#define LK_NODUP 0x000002 +#define LK_NOPROFILE 0x000004 +#define LK_NOSHARE 0x000008 +#define LK_NOWITNESS 0x000010 +#define LK_QUIET 0x000020 +#define LK_ADAPTIVE 0x000040 +#define LK_IS_VNODE 0x000080 /* Tell WITNESS about a VNODE lock */ + +/* + * Additional attributes to be used in lockmgr(). + */ +#define LK_EATTR_MASK 0x00FF00 +#define LK_INTERLOCK 0x000100 +#define LK_NOWAIT 0x000200 +#define LK_RETRY 0x000400 +#define LK_SLEEPFAIL 0x000800 +#define LK_TIMELOCK 0x001000 +#define LK_NODDLKTREAT 0x002000 +#define LK_VNHELD 0x004000 + +/* + * Operations for lockmgr(). + */ +#define LK_TYPE_MASK 0xFF0000 +#define LK_DOWNGRADE 0x010000 +#define LK_DRAIN 0x020000 +#define LK_EXCLOTHER 0x040000 +#define LK_EXCLUSIVE 0x080000 +#define LK_RELEASE 0x100000 +#define LK_SHARED 0x200000 +#define LK_UPGRADE 0x400000 +#define LK_TRYUPGRADE 0x800000 + +#define LK_TOTAL_MASK (LK_INIT_MASK | LK_EATTR_MASK | LK_TYPE_MASK) + +/* + * Default values for lockmgr_args(). + */ +#define LK_WMESG_DEFAULT (NULL) +#define LK_PRIO_DEFAULT (0) +#define LK_TIMO_DEFAULT (0) + +/* + * Assertion flags. + */ +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define KA_LOCKED LA_LOCKED +#define KA_SLOCKED LA_SLOCKED +#define KA_XLOCKED LA_XLOCKED +#define KA_UNLOCKED LA_UNLOCKED +#define KA_RECURSED LA_RECURSED +#define KA_NOTRECURSED LA_NOTRECURSED +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_LOCKMGR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/lockstat.h b/lib/libc/include/any-freebsd-any/sys/lockstat.h new file mode 100644 index 000000000000..0526f4fbd94c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/lockstat.h @@ -0,0 +1,149 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008-2009 Stacey Son + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DTrace lockstat provider definitions + */ + +#ifndef _SYS_LOCKSTAT_H +#define _SYS_LOCKSTAT_H + +#ifdef _KERNEL + +#include +#include +#include + +SDT_PROVIDER_DECLARE(lockstat); + +SDT_PROBE_DECLARE(lockstat, , , adaptive__acquire); +SDT_PROBE_DECLARE(lockstat, , , adaptive__release); +SDT_PROBE_DECLARE(lockstat, , , adaptive__spin); +SDT_PROBE_DECLARE(lockstat, , , adaptive__block); + +SDT_PROBE_DECLARE(lockstat, , , spin__acquire); +SDT_PROBE_DECLARE(lockstat, , , spin__release); +SDT_PROBE_DECLARE(lockstat, , , spin__spin); + +SDT_PROBE_DECLARE(lockstat, , , rw__acquire); +SDT_PROBE_DECLARE(lockstat, , , rw__release); +SDT_PROBE_DECLARE(lockstat, , , rw__block); +SDT_PROBE_DECLARE(lockstat, , , rw__spin); +SDT_PROBE_DECLARE(lockstat, , , rw__upgrade); +SDT_PROBE_DECLARE(lockstat, , , rw__downgrade); + +SDT_PROBE_DECLARE(lockstat, , , sx__acquire); +SDT_PROBE_DECLARE(lockstat, , , sx__release); +SDT_PROBE_DECLARE(lockstat, , , sx__block); +SDT_PROBE_DECLARE(lockstat, , , sx__spin); +SDT_PROBE_DECLARE(lockstat, , , sx__upgrade); +SDT_PROBE_DECLARE(lockstat, , , sx__downgrade); + +SDT_PROBE_DECLARE(lockstat, , , lockmgr__acquire); +SDT_PROBE_DECLARE(lockstat, , , lockmgr__release); +SDT_PROBE_DECLARE(lockstat, , , lockmgr__disown); +SDT_PROBE_DECLARE(lockstat, , , lockmgr__block); +SDT_PROBE_DECLARE(lockstat, , , lockmgr__upgrade); +SDT_PROBE_DECLARE(lockstat, , , lockmgr__downgrade); + +SDT_PROBE_DECLARE(lockstat, , , thread__spin); + +#define LOCKSTAT_WRITER 0 +#define LOCKSTAT_READER 1 + +extern volatile bool lockstat_enabled; + +#ifdef KDTRACE_HOOKS + +#define LOCKSTAT_RECORD0(probe, lp) \ + SDT_PROBE1(lockstat, , , probe, lp) + +#define LOCKSTAT_RECORD1(probe, lp, arg1) \ + SDT_PROBE2(lockstat, , , probe, lp, arg1) + +#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \ + SDT_PROBE3(lockstat, , , probe, lp, arg1, arg2) + +#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) \ + SDT_PROBE4(lockstat, , , probe, lp, arg1, arg2, arg3) + +#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) \ + SDT_PROBE5(lockstat, , , probe, lp, arg1, arg2, arg3, arg4) + +#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \ + lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \ + LOCKSTAT_RECORD0(probe, lp); \ +} while (0) + +#define LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) do { \ + lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \ + LOCKSTAT_RECORD1(probe, lp, a); \ +} while (0) + +#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do { \ + lock_profile_release_lock(&(lp)->lock_object); \ + LOCKSTAT_RECORD0(probe, lp); \ +} while (0) + +#define LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) do { \ + lock_profile_release_lock(&(lp)->lock_object); \ + LOCKSTAT_RECORD1(probe, lp, a); \ +} while (0) + +#define LOCKSTAT_PROFILE_ENABLED(probe) __predict_false(lockstat_enabled) + +struct lock_object; +uint64_t lockstat_nsecs(struct lock_object *); + +#else /* !KDTRACE_HOOKS */ + +#define LOCKSTAT_RECORD0(probe, lp) +#define LOCKSTAT_RECORD1(probe, lp, arg1) +#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) +#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) +#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) + +#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) \ + lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l) + +#define LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) \ + LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) + +#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) \ + lock_profile_release_lock(&(lp)->lock_object) + +#define LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) \ + LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) + +#define LOCKSTAT_PROFILE_ENABLED(probe) 0 + +#endif /* !KDTRACE_HOOKS */ + +#endif /* _KERNEL */ +#endif /* _SYS_LOCKSTAT_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/loginclass.h b/lib/libc/include/any-freebsd-any/sys/loginclass.h new file mode 100644 index 000000000000..9bc14766cf26 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/loginclass.h @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Edward Tomasz Napierala under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_LOGINCLASS_H_ +#define _SYS_LOGINCLASS_H_ + +struct racct; + +/* + * Exactly one of these structures exists per login class. + */ +struct loginclass { + LIST_ENTRY(loginclass) lc_next; + char lc_name[MAXLOGNAME]; + u_int lc_refcount; + struct racct *lc_racct; +}; + +void loginclass_hold(struct loginclass *lc); +void loginclass_free(struct loginclass *lc); +struct loginclass *loginclass_find(const char *name); +void loginclass_racct_foreach(void (*callback)(struct racct *racct, + void *arg2, void *arg3), void (*pre)(void), void (*post)(void), + void *arg2, void *arg3); + +#endif /* !_SYS_LOGINCLASS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mac.h b/lib/libc/include/any-freebsd-any/sys/mac.h new file mode 100644 index 000000000000..bc12cb753083 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mac.h @@ -0,0 +1,113 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999-2002 Robert N. M. Watson + * Copyright (c) 2001-2005 Networks Associates Technology, Inc. + * Copyright (c) 2005-2006 SPARTA, Inc. + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * This software was developed for the FreeBSD Project in part by Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), + * as part of the DARPA CHATS research program. + * + * This software was enhanced by SPARTA ISSO under SPAWAR contract + * N66001-04-C-6019 ("SEFOS"). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * Userland interface for Mandatory Access Control. Loosely based on the + * POSIX.1e API. More information may be found at: + * + * http://www.TrustedBSD.org/ + */ + +#ifndef _SYS_MAC_H_ +#define _SYS_MAC_H_ + +#ifndef _POSIX_MAC +#define _POSIX_MAC +#endif + +/* + * MAC framework-related constants and limits. + */ +#define MAC_MAX_POLICY_NAME 32 +#define MAC_MAX_LABEL_ELEMENT_NAME 32 +#define MAC_MAX_LABEL_ELEMENT_DATA 4096 +#define MAC_MAX_LABEL_BUF_LEN 8192 + +/* + * struct mac is the data structure used to carry MAC labels in system calls + * and ioctls between userspace and the kernel. + */ +struct mac { + size_t m_buflen; + char *m_string; +}; + +typedef struct mac *mac_t; + +#ifndef _KERNEL + +/* + * Location of the userland MAC framework configuration file. mac.conf + * set defaults for MAC-aware applications. + */ +#define MAC_CONFFILE "/etc/mac.conf" + +/* + * Extended non-POSIX.1e interfaces that offer additional services available + * from the userland and kernel MAC frameworks. + */ +__BEGIN_DECLS +int mac_execve(char *fname, char **argv, char **envv, mac_t _label); +int mac_free(mac_t _label); +int mac_from_text(mac_t *_label, const char *_text); +int mac_get_fd(int _fd, mac_t _label); +int mac_get_file(const char *_path, mac_t _label); +int mac_get_link(const char *_path, mac_t _label); +int mac_get_peer(int _fd, mac_t _label); +int mac_get_pid(pid_t _pid, mac_t _label); +int mac_get_proc(mac_t _label); +int mac_is_present(const char *_policyname); +int mac_prepare(mac_t *_label, const char *_elements); +int mac_prepare_file_label(mac_t *_label); +int mac_prepare_ifnet_label(mac_t *_label); +int mac_prepare_process_label(mac_t *_label); +int mac_prepare_type(mac_t *_label, const char *_type); +int mac_set_fd(int _fildes, const mac_t _label); +int mac_set_file(const char *_path, mac_t _label); +int mac_set_link(const char *_path, mac_t _label); +int mac_set_proc(const mac_t _label); +int mac_syscall(const char *_policyname, int _call, void *_arg); +int mac_to_text(mac_t mac, char **_text); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_MAC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/malloc.h b/lib/libc/include/any-freebsd-any/sys/malloc.h new file mode 100644 index 000000000000..ffbdc4befd11 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/malloc.h @@ -0,0 +1,270 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993 + * The Regents of the University of California. + * Copyright (c) 2005, 2009 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)malloc.h 8.5 (Berkeley) 5/3/95 + * $FreeBSD$ + */ + +#ifndef _SYS_MALLOC_H_ +#define _SYS_MALLOC_H_ + +#include +#ifdef _KERNEL +#include +#endif +#include +#include +#include +#include + +#define MINALLOCSIZE UMA_SMALLEST_UNIT + +/* + * Flags to memory allocation functions. + */ +#define M_NOWAIT 0x0001 /* do not block */ +#define M_WAITOK 0x0002 /* ok to block */ +#define M_ZERO 0x0100 /* bzero the allocation */ +#define M_NOVM 0x0200 /* don't ask VM for pages */ +#define M_USE_RESERVE 0x0400 /* can alloc out of reserve memory */ +#define M_NODUMP 0x0800 /* don't dump pages in this allocation */ +#define M_FIRSTFIT 0x1000 /* only for vmem, fast fit */ +#define M_BESTFIT 0x2000 /* only for vmem, low fragmentation */ +#define M_EXEC 0x4000 /* allocate executable space */ +#define M_NEXTFIT 0x8000 /* only for vmem, follow cursor */ + +#define M_MAGIC 877983977 /* time when first defined :-) */ + +/* + * Two malloc type structures are present: malloc_type, which is used by a + * type owner to declare the type, and malloc_type_internal, which holds + * malloc-owned statistics and other ABI-sensitive fields, such as the set of + * malloc statistics indexed by the compile-time MAXCPU constant. + * Applications should avoid introducing dependence on the allocator private + * data layout and size. + * + * The malloc_type ks_next field is protected by malloc_mtx. Other fields in + * malloc_type are static after initialization so unsynchronized. + * + * Statistics in malloc_type_stats are written only when holding a critical + * section and running on the CPU associated with the index into the stat + * array, but read lock-free resulting in possible (minor) races, which the + * monitoring app should take into account. + */ +struct malloc_type_stats { + uint64_t mts_memalloced; /* Bytes allocated on CPU. */ + uint64_t mts_memfreed; /* Bytes freed on CPU. */ + uint64_t mts_numallocs; /* Number of allocates on CPU. */ + uint64_t mts_numfrees; /* number of frees on CPU. */ + uint64_t mts_size; /* Bitmask of sizes allocated on CPU. */ + uint64_t _mts_reserved1; /* Reserved field. */ + uint64_t _mts_reserved2; /* Reserved field. */ + uint64_t _mts_reserved3; /* Reserved field. */ +}; + +/* + * Index definitions for the mti_probes[] array. + */ +#define DTMALLOC_PROBE_MALLOC 0 +#define DTMALLOC_PROBE_FREE 1 +#define DTMALLOC_PROBE_MAX 2 + +struct malloc_type_internal { + uint32_t mti_probes[DTMALLOC_PROBE_MAX]; + /* DTrace probe ID array. */ + u_char mti_zone; + struct malloc_type_stats *mti_stats; +}; + +/* + * Public data structure describing a malloc type. Private data is hung off + * of ks_handle to avoid encoding internal malloc(9) data structures in + * modules, which will statically allocate struct malloc_type. + */ +struct malloc_type { + struct malloc_type *ks_next; /* Next in global chain. */ + u_long ks_magic; /* Detect programmer error. */ + const char *ks_shortdesc; /* Printable type name. */ + void *ks_handle; /* Priv. data, was lo_class. */ +}; + +/* + * Statistics structure headers for user space. The kern.malloc sysctl + * exposes a structure stream consisting of a stream header, then a series of + * malloc type headers and statistics structures (quantity maxcpus). For + * convenience, the kernel will provide the current value of maxcpus at the + * head of the stream. + */ +#define MALLOC_TYPE_STREAM_VERSION 0x00000001 +struct malloc_type_stream_header { + uint32_t mtsh_version; /* Stream format version. */ + uint32_t mtsh_maxcpus; /* Value of MAXCPU for stream. */ + uint32_t mtsh_count; /* Number of records. */ + uint32_t _mtsh_pad; /* Pad/reserved field. */ +}; + +#define MALLOC_MAX_NAME 32 +struct malloc_type_header { + char mth_name[MALLOC_MAX_NAME]; +}; + +#ifdef _KERNEL +#define MALLOC_DEFINE(type, shortdesc, longdesc) \ + struct malloc_type type[1] = { \ + { NULL, M_MAGIC, shortdesc, NULL } \ + }; \ + SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_THIRD, malloc_init, \ + type); \ + SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, \ + malloc_uninit, type) + +#define MALLOC_DECLARE(type) \ + extern struct malloc_type type[1] + +MALLOC_DECLARE(M_CACHE); +MALLOC_DECLARE(M_DEVBUF); +MALLOC_DECLARE(M_TEMP); + +/* + * XXX this should be declared in , but that tends to fail + * because is included in a header before the source file + * has a chance to include to get MALLOC_DECLARE() defined. + */ +MALLOC_DECLARE(M_IOV); + +struct domainset; +extern struct mtx malloc_mtx; + +/* + * Function type used when iterating over the list of malloc types. + */ +typedef void malloc_type_list_func_t(struct malloc_type *, void *); + +void contigfree(void *addr, unsigned long size, struct malloc_type *type); +void *contigmalloc(unsigned long size, struct malloc_type *type, int flags, + vm_paddr_t low, vm_paddr_t high, unsigned long alignment, + vm_paddr_t boundary) __malloc_like __result_use_check + __alloc_size(1) __alloc_align(6); +void *contigmalloc_domainset(unsigned long size, struct malloc_type *type, + struct domainset *ds, int flags, vm_paddr_t low, vm_paddr_t high, + unsigned long alignment, vm_paddr_t boundary) + __malloc_like __result_use_check __alloc_size(1) __alloc_align(7); +void free(void *addr, struct malloc_type *type); +void free_domain(void *addr, struct malloc_type *type); +void *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like + __result_use_check __alloc_size(1); +/* + * Try to optimize malloc(..., ..., M_ZERO) allocations by doing zeroing in + * place if the size is known at compilation time. + * + * Passing the flag down requires malloc to blindly zero the entire object. + * In practice a lot of the zeroing can be avoided if most of the object + * gets explicitly initialized after the allocation. Letting the compiler + * zero in place gives it the opportunity to take advantage of this state. + * + * Note that the operation is only applicable if both flags and size are + * known at compilation time. If M_ZERO is passed but M_WAITOK is not, the + * allocation can fail and a NULL check is needed. However, if M_WAITOK is + * passed we know the allocation must succeed and the check can be elided. + * + * _malloc_item = malloc(_size, type, (flags) &~ M_ZERO); + * if (((flags) & M_WAITOK) != 0 || _malloc_item != NULL) + * bzero(_malloc_item, _size); + * + * If the flag is set, the compiler knows the left side is always true, + * therefore the entire statement is true and the callsite is: + * + * _malloc_item = malloc(_size, type, (flags) &~ M_ZERO); + * bzero(_malloc_item, _size); + * + * If the flag is not set, the compiler knows the left size is always false + * and the NULL check is needed, therefore the callsite is: + * + * _malloc_item = malloc(_size, type, (flags) &~ M_ZERO); + * if (_malloc_item != NULL) + * bzero(_malloc_item, _size); + * + * The implementation is a macro because of what appears to be a clang 6 bug: + * an inline function variant ended up being compiled to a mere malloc call + * regardless of argument. gcc generates expected code (like the above). + */ +#define malloc(size, type, flags) ({ \ + void *_malloc_item; \ + size_t _size = (size); \ + if (__builtin_constant_p(size) && __builtin_constant_p(flags) &&\ + ((flags) & M_ZERO) != 0) { \ + _malloc_item = malloc(_size, type, (flags) &~ M_ZERO); \ + if (((flags) & M_WAITOK) != 0 || \ + __predict_true(_malloc_item != NULL)) \ + bzero(_malloc_item, _size); \ + } else { \ + _malloc_item = malloc(_size, type, flags); \ + } \ + _malloc_item; \ +}) + +void *malloc_domainset(size_t size, struct malloc_type *type, + struct domainset *ds, int flags) __malloc_like __result_use_check + __alloc_size(1); +void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type, + int flags) __malloc_like __result_use_check + __alloc_size2(1, 2); +void malloc_init(void *); +int malloc_last_fail(void); +void malloc_type_allocated(struct malloc_type *type, unsigned long size); +void malloc_type_freed(struct malloc_type *type, unsigned long size); +void malloc_type_list(malloc_type_list_func_t *, void *); +void malloc_uninit(void *); +size_t malloc_usable_size(const void *); +void *realloc(void *addr, size_t size, struct malloc_type *type, int flags) + __result_use_check __alloc_size(2); +void *reallocf(void *addr, size_t size, struct malloc_type *type, int flags) + __result_use_check __alloc_size(2); + +struct malloc_type *malloc_desc2type(const char *desc); + +/* + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW + */ +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 8 / 2)) +static inline bool +WOULD_OVERFLOW(size_t nmemb, size_t size) +{ + + return ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + nmemb > 0 && __SIZE_T_MAX / nmemb < size); +} +#undef MUL_NO_OVERFLOW +#endif /* _KERNEL */ + +#endif /* !_SYS_MALLOC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mbuf.h b/lib/libc/include/any-freebsd-any/sys/mbuf.h new file mode 100644 index 000000000000..e2539faed3e0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mbuf.h @@ -0,0 +1,1393 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mbuf.h 8.5 (Berkeley) 2/19/95 + * $FreeBSD$ + */ + +#ifndef _SYS_MBUF_H_ +#define _SYS_MBUF_H_ + +/* XXX: These includes suck. Sorry! */ +#include +#ifdef _KERNEL +#include +#include +#ifdef WITNESS +#include +#endif +#endif + +#ifdef _KERNEL +#include + +#define MBUF_PROBE1(probe, arg0) \ + SDT_PROBE1(sdt, , , probe, arg0) +#define MBUF_PROBE2(probe, arg0, arg1) \ + SDT_PROBE2(sdt, , , probe, arg0, arg1) +#define MBUF_PROBE3(probe, arg0, arg1, arg2) \ + SDT_PROBE3(sdt, , , probe, arg0, arg1, arg2) +#define MBUF_PROBE4(probe, arg0, arg1, arg2, arg3) \ + SDT_PROBE4(sdt, , , probe, arg0, arg1, arg2, arg3) +#define MBUF_PROBE5(probe, arg0, arg1, arg2, arg3, arg4) \ + SDT_PROBE5(sdt, , , probe, arg0, arg1, arg2, arg3, arg4) + +SDT_PROBE_DECLARE(sdt, , , m__init); +SDT_PROBE_DECLARE(sdt, , , m__gethdr); +SDT_PROBE_DECLARE(sdt, , , m__get); +SDT_PROBE_DECLARE(sdt, , , m__getcl); +SDT_PROBE_DECLARE(sdt, , , m__getjcl); +SDT_PROBE_DECLARE(sdt, , , m__clget); +SDT_PROBE_DECLARE(sdt, , , m__cljget); +SDT_PROBE_DECLARE(sdt, , , m__cljset); +SDT_PROBE_DECLARE(sdt, , , m__free); +SDT_PROBE_DECLARE(sdt, , , m__freem); + +#endif /* _KERNEL */ + +/* + * Mbufs are of a single size, MSIZE (sys/param.h), which includes overhead. + * An mbuf may add a single "mbuf cluster" of size MCLBYTES (also in + * sys/param.h), which has no additional overhead and is used instead of the + * internal data area; this is done when at least MINCLSIZE of data must be + * stored. Additionally, it is possible to allocate a separate buffer + * externally and attach it to the mbuf in a way similar to that of mbuf + * clusters. + * + * NB: These calculation do not take actual compiler-induced alignment and + * padding inside the complete struct mbuf into account. Appropriate + * attention is required when changing members of struct mbuf. + * + * MLEN is data length in a normal mbuf. + * MHLEN is data length in an mbuf with pktheader. + * MINCLSIZE is a smallest amount of data that should be put into cluster. + * + * Compile-time assertions in uipc_mbuf.c test these values to ensure that + * they are sensible. + */ +struct mbuf; +#define MHSIZE offsetof(struct mbuf, m_dat) +#define MPKTHSIZE offsetof(struct mbuf, m_pktdat) +#define MLEN ((int)(MSIZE - MHSIZE)) +#define MHLEN ((int)(MSIZE - MPKTHSIZE)) +#define MINCLSIZE (MHLEN + 1) + +#ifdef _KERNEL +/*- + * Macro for type conversion: convert mbuf pointer to data pointer of correct + * type: + * + * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type. + * mtodo(m, o) -- Same as above but with offset 'o' into data. + */ +#define mtod(m, t) ((t)((m)->m_data)) +#define mtodo(m, o) ((void *)(((m)->m_data) + (o))) + +/* + * Argument structure passed to UMA routines during mbuf and packet + * allocations. + */ +struct mb_args { + int flags; /* Flags for mbuf being allocated */ + short type; /* Type of mbuf being allocated */ +}; +#endif /* _KERNEL */ + +/* + * Packet tag structure (see below for details). + */ +struct m_tag { + SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ + u_int16_t m_tag_id; /* Tag ID */ + u_int16_t m_tag_len; /* Length of data */ + u_int32_t m_tag_cookie; /* ABI/Module ID */ + void (*m_tag_free)(struct m_tag *); +}; + +/* + * Static network interface owned tag. + * Allocated through ifp->if_snd_tag_alloc(). + */ +struct m_snd_tag { + struct ifnet *ifp; /* network interface tag belongs to */ +}; + +/* + * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. + * Size ILP32: 48 + * LP64: 56 + * Compile-time assertions in uipc_mbuf.c test these values to ensure that + * they are correct. + */ +struct pkthdr { + union { + struct m_snd_tag *snd_tag; /* send tag, if any */ + struct ifnet *rcvif; /* rcv interface */ + }; + SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ + int32_t len; /* total packet length */ + + /* Layer crossing persistent information. */ + uint32_t flowid; /* packet's 4-tuple system */ + uint32_t csum_flags; /* checksum and offload features */ + uint16_t fibnum; /* this packet should use this fib */ + uint8_t cosqos; /* class/quality of service */ + uint8_t rsstype; /* hash type */ + union { + uint64_t rcv_tstmp; /* timestamp in ns */ + struct { + uint8_t l2hlen; /* layer 2 hdr len */ + uint8_t l3hlen; /* layer 3 hdr len */ + uint8_t l4hlen; /* layer 4 hdr len */ + uint8_t l5hlen; /* layer 5 hdr len */ + uint32_t spare; + }; + }; + union { + uint8_t eight[8]; + uint16_t sixteen[4]; + uint32_t thirtytwo[2]; + uint64_t sixtyfour[1]; + uintptr_t unintptr[1]; + void *ptr; + } PH_per; + + /* Layer specific non-persistent local storage for reassembly, etc. */ + union { + uint8_t eight[8]; + uint16_t sixteen[4]; + uint32_t thirtytwo[2]; + uint64_t sixtyfour[1]; + uintptr_t unintptr[1]; + void *ptr; + } PH_loc; +}; +#define ether_vtag PH_per.sixteen[0] +#define PH_vt PH_per +#define vt_nrecs sixteen[0] +#define tso_segsz PH_per.sixteen[1] +#define lro_nsegs tso_segsz +#define csum_phsum PH_per.sixteen[2] +#define csum_data PH_per.thirtytwo[1] +#define pace_thoff PH_loc.sixteen[0] +#define pace_tlen PH_loc.sixteen[1] +#define pace_drphdrlen PH_loc.sixteen[2] +#define pace_tos PH_loc.eight[6] +#define pace_lock PH_loc.eight[7] + +/* + * Description of external storage mapped into mbuf; valid only if M_EXT is + * set. + * Size ILP32: 28 + * LP64: 48 + * Compile-time assertions in uipc_mbuf.c test these values to ensure that + * they are correct. + */ +typedef void m_ext_free_t(struct mbuf *); +struct m_ext { + union { + /* + * If EXT_FLAG_EMBREF is set, then we use refcount in the + * mbuf, the 'ext_count' member. Otherwise, we have a + * shadow copy and we use pointer 'ext_cnt'. The original + * mbuf is responsible to carry the pointer to free routine + * and its arguments. They aren't copied into shadows in + * mb_dupcl() to avoid dereferencing next cachelines. + */ + volatile u_int ext_count; + volatile u_int *ext_cnt; + }; + char *ext_buf; /* start of buffer */ + uint32_t ext_size; /* size of buffer, for ext_free */ + uint32_t ext_type:8, /* type of external storage */ + ext_flags:24; /* external storage mbuf flags */ + /* + * Fields below store the free context for the external storage. + * They are valid only in the refcount carrying mbuf, the one with + * EXT_FLAG_EMBREF flag, with exclusion for EXT_EXTREF type, where + * the free context is copied into all mbufs that use same external + * storage. + */ +#define m_ext_copylen offsetof(struct m_ext, ext_free) + m_ext_free_t *ext_free; /* free routine if not the usual */ + void *ext_arg1; /* optional argument pointer */ + void *ext_arg2; /* optional argument pointer */ +}; + +/* + * The core of the mbuf object along with some shortcut defines for practical + * purposes. + */ +struct mbuf { + /* + * Header present at the beginning of every mbuf. + * Size ILP32: 24 + * LP64: 32 + * Compile-time assertions in uipc_mbuf.c test these values to ensure + * that they are correct. + */ + union { /* next buffer in chain */ + struct mbuf *m_next; + SLIST_ENTRY(mbuf) m_slist; + STAILQ_ENTRY(mbuf) m_stailq; + }; + union { /* next chain in queue/record */ + struct mbuf *m_nextpkt; + SLIST_ENTRY(mbuf) m_slistpkt; + STAILQ_ENTRY(mbuf) m_stailqpkt; + }; + caddr_t m_data; /* location of data */ + int32_t m_len; /* amount of data in this mbuf */ + uint32_t m_type:8, /* type of data in this mbuf */ + m_flags:24; /* flags; see below */ +#if !defined(__LP64__) + uint32_t m_pad; /* pad for 64bit alignment */ +#endif + + /* + * A set of optional headers (packet header, external storage header) + * and internal data storage. Historically, these arrays were sized + * to MHLEN (space left after a packet header) and MLEN (space left + * after only a regular mbuf header); they are now variable size in + * order to support future work on variable-size mbufs. + */ + union { + struct { + struct pkthdr m_pkthdr; /* M_PKTHDR set */ + union { + struct m_ext m_ext; /* M_EXT set */ + char m_pktdat[0]; + }; + }; + char m_dat[0]; /* !M_PKTHDR, !M_EXT */ + }; +}; + +/* + * mbuf flags of global significance and layer crossing. + * Those of only protocol/layer specific significance are to be mapped + * to M_PROTO[1-12] and cleared at layer handoff boundaries. + * NB: Limited to the lower 24 bits. + */ +#define M_EXT 0x00000001 /* has associated external storage */ +#define M_PKTHDR 0x00000002 /* start of record */ +#define M_EOR 0x00000004 /* end of record */ +#define M_RDONLY 0x00000008 /* associated data is marked read-only */ +#define M_BCAST 0x00000010 /* send/received as link-level broadcast */ +#define M_MCAST 0x00000020 /* send/received as link-level multicast */ +#define M_PROMISC 0x00000040 /* packet was not for us */ +#define M_VLANTAG 0x00000080 /* ether_vtag is valid */ +#define M_NOMAP 0x00000100 /* mbuf data is unmapped (soon from Drew) */ +#define M_NOFREE 0x00000200 /* do not free mbuf, embedded in cluster */ +#define M_TSTMP 0x00000400 /* rcv_tstmp field is valid */ +#define M_TSTMP_HPREC 0x00000800 /* rcv_tstmp is high-prec, typically + hw-stamped on port (useful for IEEE 1588 + and 802.1AS) */ +#define M_TSTMP_LRO 0x00001000 /* Time LRO pushed in pkt is valid in (PH_loc) */ + +#define M_PROTO1 0x00001000 /* protocol-specific */ +#define M_PROTO2 0x00002000 /* protocol-specific */ +#define M_PROTO3 0x00004000 /* protocol-specific */ +#define M_PROTO4 0x00008000 /* protocol-specific */ +#define M_PROTO5 0x00010000 /* protocol-specific */ +#define M_PROTO6 0x00020000 /* protocol-specific */ +#define M_PROTO7 0x00040000 /* protocol-specific */ +#define M_PROTO8 0x00080000 /* protocol-specific */ +#define M_PROTO9 0x00100000 /* protocol-specific */ +#define M_PROTO10 0x00200000 /* protocol-specific */ +#define M_PROTO11 0x00400000 /* protocol-specific */ +#define M_PROTO12 0x00800000 /* protocol-specific */ + +#define MB_DTOR_SKIP 0x1 /* don't pollute the cache by touching a freed mbuf */ + +/* + * Flags to purge when crossing layers. + */ +#define M_PROTOFLAGS \ + (M_PROTO1|M_PROTO2|M_PROTO3|M_PROTO4|M_PROTO5|M_PROTO6|M_PROTO7|M_PROTO8|\ + M_PROTO9|M_PROTO10|M_PROTO11|M_PROTO12) + +/* + * Flags preserved when copying m_pkthdr. + */ +#define M_COPYFLAGS \ + (M_PKTHDR|M_EOR|M_RDONLY|M_BCAST|M_MCAST|M_PROMISC|M_VLANTAG|M_TSTMP| \ + M_TSTMP_HPREC|M_PROTOFLAGS) + +/* + * Mbuf flag description for use with printf(9) %b identifier. + */ +#define M_FLAG_BITS \ + "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_BCAST\6M_MCAST" \ + "\7M_PROMISC\10M_VLANTAG\13M_TSTMP\14M_TSTMP_HPREC" +#define M_FLAG_PROTOBITS \ + "\15M_PROTO1\16M_PROTO2\17M_PROTO3\20M_PROTO4\21M_PROTO5" \ + "\22M_PROTO6\23M_PROTO7\24M_PROTO8\25M_PROTO9\26M_PROTO10" \ + "\27M_PROTO11\30M_PROTO12" +#define M_FLAG_PRINTF (M_FLAG_BITS M_FLAG_PROTOBITS) + +/* + * Network interface cards are able to hash protocol fields (such as IPv4 + * addresses and TCP port numbers) classify packets into flows. These flows + * can then be used to maintain ordering while delivering packets to the OS + * via parallel input queues, as well as to provide a stateless affinity + * model. NIC drivers can pass up the hash via m->m_pkthdr.flowid, and set + * m_flag fields to indicate how the hash should be interpreted by the + * network stack. + * + * Most NICs support RSS, which provides ordering and explicit affinity, and + * use the hash m_flag bits to indicate what header fields were covered by + * the hash. M_HASHTYPE_OPAQUE and M_HASHTYPE_OPAQUE_HASH can be set by non- + * RSS cards or configurations that provide an opaque flow identifier, allowing + * for ordering and distribution without explicit affinity. Additionally, + * M_HASHTYPE_OPAQUE_HASH indicates that the flow identifier has hash + * properties. + * + * The meaning of the IPV6_EX suffix: + * "o Home address from the home address option in the IPv6 destination + * options header. If the extension header is not present, use the Source + * IPv6 Address. + * o IPv6 address that is contained in the Routing-Header-Type-2 from the + * associated extension header. If the extension header is not present, + * use the Destination IPv6 Address." + * Quoted from: + * https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-hashing-types#ndishashipv6ex + */ +#define M_HASHTYPE_HASHPROP 0x80 /* has hash properties */ +#define M_HASHTYPE_HASH(t) (M_HASHTYPE_HASHPROP | (t)) +/* Microsoft RSS standard hash types */ +#define M_HASHTYPE_NONE 0 +#define M_HASHTYPE_RSS_IPV4 M_HASHTYPE_HASH(1) /* IPv4 2-tuple */ +#define M_HASHTYPE_RSS_TCP_IPV4 M_HASHTYPE_HASH(2) /* TCPv4 4-tuple */ +#define M_HASHTYPE_RSS_IPV6 M_HASHTYPE_HASH(3) /* IPv6 2-tuple */ +#define M_HASHTYPE_RSS_TCP_IPV6 M_HASHTYPE_HASH(4) /* TCPv6 4-tuple */ +#define M_HASHTYPE_RSS_IPV6_EX M_HASHTYPE_HASH(5) /* IPv6 2-tuple + + * ext hdrs */ +#define M_HASHTYPE_RSS_TCP_IPV6_EX M_HASHTYPE_HASH(6) /* TCPv6 4-tuple + + * ext hdrs */ +#define M_HASHTYPE_RSS_UDP_IPV4 M_HASHTYPE_HASH(7) /* IPv4 UDP 4-tuple*/ +#define M_HASHTYPE_RSS_UDP_IPV6 M_HASHTYPE_HASH(9) /* IPv6 UDP 4-tuple*/ +#define M_HASHTYPE_RSS_UDP_IPV6_EX M_HASHTYPE_HASH(10)/* IPv6 UDP 4-tuple + + * ext hdrs */ + +#define M_HASHTYPE_OPAQUE 63 /* ordering, not affinity */ +#define M_HASHTYPE_OPAQUE_HASH M_HASHTYPE_HASH(M_HASHTYPE_OPAQUE) + /* ordering+hash, not affinity*/ + +#define M_HASHTYPE_CLEAR(m) ((m)->m_pkthdr.rsstype = 0) +#define M_HASHTYPE_GET(m) ((m)->m_pkthdr.rsstype) +#define M_HASHTYPE_SET(m, v) ((m)->m_pkthdr.rsstype = (v)) +#define M_HASHTYPE_TEST(m, v) (M_HASHTYPE_GET(m) == (v)) +#define M_HASHTYPE_ISHASH(m) (M_HASHTYPE_GET(m) & M_HASHTYPE_HASHPROP) + +/* + * COS/QOS class and quality of service tags. + * It uses DSCP code points as base. + */ +#define QOS_DSCP_CS0 0x00 +#define QOS_DSCP_DEF QOS_DSCP_CS0 +#define QOS_DSCP_CS1 0x20 +#define QOS_DSCP_AF11 0x28 +#define QOS_DSCP_AF12 0x30 +#define QOS_DSCP_AF13 0x38 +#define QOS_DSCP_CS2 0x40 +#define QOS_DSCP_AF21 0x48 +#define QOS_DSCP_AF22 0x50 +#define QOS_DSCP_AF23 0x58 +#define QOS_DSCP_CS3 0x60 +#define QOS_DSCP_AF31 0x68 +#define QOS_DSCP_AF32 0x70 +#define QOS_DSCP_AF33 0x78 +#define QOS_DSCP_CS4 0x80 +#define QOS_DSCP_AF41 0x88 +#define QOS_DSCP_AF42 0x90 +#define QOS_DSCP_AF43 0x98 +#define QOS_DSCP_CS5 0xa0 +#define QOS_DSCP_EF 0xb8 +#define QOS_DSCP_CS6 0xc0 +#define QOS_DSCP_CS7 0xe0 + +/* + * External mbuf storage buffer types. + */ +#define EXT_CLUSTER 1 /* mbuf cluster */ +#define EXT_SFBUF 2 /* sendfile(2)'s sf_buf */ +#define EXT_JUMBOP 3 /* jumbo cluster page sized */ +#define EXT_JUMBO9 4 /* jumbo cluster 9216 bytes */ +#define EXT_JUMBO16 5 /* jumbo cluster 16184 bytes */ +#define EXT_PACKET 6 /* mbuf+cluster from packet zone */ +#define EXT_MBUF 7 /* external mbuf reference */ + +#define EXT_VENDOR1 224 /* for vendor-internal use */ +#define EXT_VENDOR2 225 /* for vendor-internal use */ +#define EXT_VENDOR3 226 /* for vendor-internal use */ +#define EXT_VENDOR4 227 /* for vendor-internal use */ + +#define EXT_EXP1 244 /* for experimental use */ +#define EXT_EXP2 245 /* for experimental use */ +#define EXT_EXP3 246 /* for experimental use */ +#define EXT_EXP4 247 /* for experimental use */ + +#define EXT_NET_DRV 252 /* custom ext_buf provided by net driver(s) */ +#define EXT_MOD_TYPE 253 /* custom module's ext_buf type */ +#define EXT_DISPOSABLE 254 /* can throw this buffer away w/page flipping */ +#define EXT_EXTREF 255 /* has externally maintained ext_cnt ptr */ + +/* + * Flags for external mbuf buffer types. + * NB: limited to the lower 24 bits. + */ +#define EXT_FLAG_EMBREF 0x000001 /* embedded ext_count */ +#define EXT_FLAG_EXTREF 0x000002 /* external ext_cnt, notyet */ + +#define EXT_FLAG_NOFREE 0x000010 /* don't free mbuf to pool, notyet */ + +#define EXT_FLAG_VENDOR1 0x010000 /* These flags are vendor */ +#define EXT_FLAG_VENDOR2 0x020000 /* or submodule specific, */ +#define EXT_FLAG_VENDOR3 0x040000 /* not used by mbuf code. */ +#define EXT_FLAG_VENDOR4 0x080000 /* Set/read by submodule. */ + +#define EXT_FLAG_EXP1 0x100000 /* for experimental use */ +#define EXT_FLAG_EXP2 0x200000 /* for experimental use */ +#define EXT_FLAG_EXP3 0x400000 /* for experimental use */ +#define EXT_FLAG_EXP4 0x800000 /* for experimental use */ + +/* + * EXT flag description for use with printf(9) %b identifier. + */ +#define EXT_FLAG_BITS \ + "\20\1EXT_FLAG_EMBREF\2EXT_FLAG_EXTREF\5EXT_FLAG_NOFREE" \ + "\21EXT_FLAG_VENDOR1\22EXT_FLAG_VENDOR2\23EXT_FLAG_VENDOR3" \ + "\24EXT_FLAG_VENDOR4\25EXT_FLAG_EXP1\26EXT_FLAG_EXP2\27EXT_FLAG_EXP3" \ + "\30EXT_FLAG_EXP4" + +/* + * Flags indicating checksum, segmentation and other offload work to be + * done, or already done, by hardware or lower layers. It is split into + * separate inbound and outbound flags. + * + * Outbound flags that are set by upper protocol layers requesting lower + * layers, or ideally the hardware, to perform these offloading tasks. + * For outbound packets this field and its flags can be directly tested + * against ifnet if_hwassist. + */ +#define CSUM_IP 0x00000001 /* IP header checksum offload */ +#define CSUM_IP_UDP 0x00000002 /* UDP checksum offload */ +#define CSUM_IP_TCP 0x00000004 /* TCP checksum offload */ +#define CSUM_IP_SCTP 0x00000008 /* SCTP checksum offload */ +#define CSUM_IP_TSO 0x00000010 /* TCP segmentation offload */ +#define CSUM_IP_ISCSI 0x00000020 /* iSCSI checksum offload */ + +#define CSUM_IP6_UDP 0x00000200 /* UDP checksum offload */ +#define CSUM_IP6_TCP 0x00000400 /* TCP checksum offload */ +#define CSUM_IP6_SCTP 0x00000800 /* SCTP checksum offload */ +#define CSUM_IP6_TSO 0x00001000 /* TCP segmentation offload */ +#define CSUM_IP6_ISCSI 0x00002000 /* iSCSI checksum offload */ + +/* Inbound checksum support where the checksum was verified by hardware. */ +#define CSUM_L3_CALC 0x01000000 /* calculated layer 3 csum */ +#define CSUM_L3_VALID 0x02000000 /* checksum is correct */ +#define CSUM_L4_CALC 0x04000000 /* calculated layer 4 csum */ +#define CSUM_L4_VALID 0x08000000 /* checksum is correct */ +#define CSUM_L5_CALC 0x10000000 /* calculated layer 5 csum */ +#define CSUM_L5_VALID 0x20000000 /* checksum is correct */ +#define CSUM_COALESCED 0x40000000 /* contains merged segments */ + +#define CSUM_SND_TAG 0x80000000 /* Packet header has send tag */ + +/* + * CSUM flag description for use with printf(9) %b identifier. + */ +#define CSUM_BITS \ + "\20\1CSUM_IP\2CSUM_IP_UDP\3CSUM_IP_TCP\4CSUM_IP_SCTP\5CSUM_IP_TSO" \ + "\6CSUM_IP_ISCSI" \ + "\12CSUM_IP6_UDP\13CSUM_IP6_TCP\14CSUM_IP6_SCTP\15CSUM_IP6_TSO" \ + "\16CSUM_IP6_ISCSI" \ + "\31CSUM_L3_CALC\32CSUM_L3_VALID\33CSUM_L4_CALC\34CSUM_L4_VALID" \ + "\35CSUM_L5_CALC\36CSUM_L5_VALID\37CSUM_COALESCED\40CSUM_SND_TAG" + +/* CSUM flags compatibility mappings. */ +#define CSUM_IP_CHECKED CSUM_L3_CALC +#define CSUM_IP_VALID CSUM_L3_VALID +#define CSUM_DATA_VALID CSUM_L4_VALID +#define CSUM_PSEUDO_HDR CSUM_L4_CALC +#define CSUM_SCTP_VALID CSUM_L4_VALID +#define CSUM_DELAY_DATA (CSUM_TCP|CSUM_UDP) +#define CSUM_DELAY_IP CSUM_IP /* Only v4, no v6 IP hdr csum */ +#define CSUM_DELAY_DATA_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6) +#define CSUM_DATA_VALID_IPV6 CSUM_DATA_VALID +#define CSUM_TCP CSUM_IP_TCP +#define CSUM_UDP CSUM_IP_UDP +#define CSUM_SCTP CSUM_IP_SCTP +#define CSUM_TSO (CSUM_IP_TSO|CSUM_IP6_TSO) +#define CSUM_UDP_IPV6 CSUM_IP6_UDP +#define CSUM_TCP_IPV6 CSUM_IP6_TCP +#define CSUM_SCTP_IPV6 CSUM_IP6_SCTP + +/* + * mbuf types describing the content of the mbuf (including external storage). + */ +#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */ +#define MT_DATA 1 /* dynamic (data) allocation */ +#define MT_HEADER MT_DATA /* packet header, use M_PKTHDR instead */ + +#define MT_VENDOR1 4 /* for vendor-internal use */ +#define MT_VENDOR2 5 /* for vendor-internal use */ +#define MT_VENDOR3 6 /* for vendor-internal use */ +#define MT_VENDOR4 7 /* for vendor-internal use */ + +#define MT_SONAME 8 /* socket name */ + +#define MT_EXP1 9 /* for experimental use */ +#define MT_EXP2 10 /* for experimental use */ +#define MT_EXP3 11 /* for experimental use */ +#define MT_EXP4 12 /* for experimental use */ + +#define MT_CONTROL 14 /* extra-data protocol message */ +#define MT_EXTCONTROL 15 /* control message with externalized contents */ +#define MT_OOBDATA 16 /* expedited data */ + +#define MT_NOINIT 255 /* Not a type but a flag to allocate + a non-initialized mbuf */ + +/* + * String names of mbuf-related UMA(9) and malloc(9) types. Exposed to + * !_KERNEL so that monitoring tools can look up the zones with + * libmemstat(3). + */ +#define MBUF_MEM_NAME "mbuf" +#define MBUF_CLUSTER_MEM_NAME "mbuf_cluster" +#define MBUF_PACKET_MEM_NAME "mbuf_packet" +#define MBUF_JUMBOP_MEM_NAME "mbuf_jumbo_page" +#define MBUF_JUMBO9_MEM_NAME "mbuf_jumbo_9k" +#define MBUF_JUMBO16_MEM_NAME "mbuf_jumbo_16k" +#define MBUF_TAG_MEM_NAME "mbuf_tag" +#define MBUF_EXTREFCNT_MEM_NAME "mbuf_ext_refcnt" + +#ifdef _KERNEL + +#ifdef WITNESS +#define MBUF_CHECKSLEEP(how) do { \ + if (how == M_WAITOK) \ + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, \ + "Sleeping in \"%s\"", __func__); \ +} while (0) +#else +#define MBUF_CHECKSLEEP(how) +#endif + +/* + * Network buffer allocation API + * + * The rest of it is defined in kern/kern_mbuf.c + */ +extern uma_zone_t zone_mbuf; +extern uma_zone_t zone_clust; +extern uma_zone_t zone_pack; +extern uma_zone_t zone_jumbop; +extern uma_zone_t zone_jumbo9; +extern uma_zone_t zone_jumbo16; + +void mb_dupcl(struct mbuf *, struct mbuf *); +void mb_free_ext(struct mbuf *); +void m_adj(struct mbuf *, int); +int m_apply(struct mbuf *, int, int, + int (*)(void *, void *, u_int), void *); +int m_append(struct mbuf *, int, c_caddr_t); +void m_cat(struct mbuf *, struct mbuf *); +void m_catpkt(struct mbuf *, struct mbuf *); +int m_clget(struct mbuf *m, int how); +void *m_cljget(struct mbuf *m, int how, int size); +struct mbuf *m_collapse(struct mbuf *, int, int); +void m_copyback(struct mbuf *, int, int, c_caddr_t); +void m_copydata(const struct mbuf *, int, int, caddr_t); +struct mbuf *m_copym(struct mbuf *, int, int, int); +struct mbuf *m_copypacket(struct mbuf *, int); +void m_copy_pkthdr(struct mbuf *, struct mbuf *); +struct mbuf *m_copyup(struct mbuf *, int, int); +struct mbuf *m_defrag(struct mbuf *, int); +void m_demote_pkthdr(struct mbuf *); +void m_demote(struct mbuf *, int, int); +struct mbuf *m_devget(char *, int, int, struct ifnet *, + void (*)(char *, caddr_t, u_int)); +void m_dispose_extcontrolm(struct mbuf *m); +struct mbuf *m_dup(const struct mbuf *, int); +int m_dup_pkthdr(struct mbuf *, const struct mbuf *, int); +void m_extadd(struct mbuf *, char *, u_int, m_ext_free_t, + void *, void *, int, int); +u_int m_fixhdr(struct mbuf *); +struct mbuf *m_fragment(struct mbuf *, int, int); +void m_freem(struct mbuf *); +struct mbuf *m_get2(int, int, short, int); +struct mbuf *m_getjcl(int, short, int, int); +struct mbuf *m_getm2(struct mbuf *, int, int, short, int); +struct mbuf *m_getptr(struct mbuf *, int, int *); +u_int m_length(struct mbuf *, struct mbuf **); +int m_mbuftouio(struct uio *, const struct mbuf *, int); +void m_move_pkthdr(struct mbuf *, struct mbuf *); +int m_pkthdr_init(struct mbuf *, int); +struct mbuf *m_prepend(struct mbuf *, int, int); +void m_print(const struct mbuf *, int); +struct mbuf *m_pulldown(struct mbuf *, int, int, int *); +struct mbuf *m_pullup(struct mbuf *, int); +int m_sanity(struct mbuf *, int); +struct mbuf *m_split(struct mbuf *, int, int); +struct mbuf *m_uiotombuf(struct uio *, int, int, int, int); +struct mbuf *m_unshare(struct mbuf *, int); + +static __inline int +m_gettype(int size) +{ + int type; + + switch (size) { + case MSIZE: + type = EXT_MBUF; + break; + case MCLBYTES: + type = EXT_CLUSTER; + break; +#if MJUMPAGESIZE != MCLBYTES + case MJUMPAGESIZE: + type = EXT_JUMBOP; + break; +#endif + case MJUM9BYTES: + type = EXT_JUMBO9; + break; + case MJUM16BYTES: + type = EXT_JUMBO16; + break; + default: + panic("%s: invalid cluster size %d", __func__, size); + } + + return (type); +} + +/* + * Associated an external reference counted buffer with an mbuf. + */ +static __inline void +m_extaddref(struct mbuf *m, char *buf, u_int size, u_int *ref_cnt, + m_ext_free_t freef, void *arg1, void *arg2) +{ + + KASSERT(ref_cnt != NULL, ("%s: ref_cnt not provided", __func__)); + + atomic_add_int(ref_cnt, 1); + m->m_flags |= M_EXT; + m->m_ext.ext_buf = buf; + m->m_ext.ext_cnt = ref_cnt; + m->m_data = m->m_ext.ext_buf; + m->m_ext.ext_size = size; + m->m_ext.ext_free = freef; + m->m_ext.ext_arg1 = arg1; + m->m_ext.ext_arg2 = arg2; + m->m_ext.ext_type = EXT_EXTREF; + m->m_ext.ext_flags = 0; +} + +static __inline uma_zone_t +m_getzone(int size) +{ + uma_zone_t zone; + + switch (size) { + case MCLBYTES: + zone = zone_clust; + break; +#if MJUMPAGESIZE != MCLBYTES + case MJUMPAGESIZE: + zone = zone_jumbop; + break; +#endif + case MJUM9BYTES: + zone = zone_jumbo9; + break; + case MJUM16BYTES: + zone = zone_jumbo16; + break; + default: + panic("%s: invalid cluster size %d", __func__, size); + } + + return (zone); +} + +/* + * Initialize an mbuf with linear storage. + * + * Inline because the consumer text overhead will be roughly the same to + * initialize or call a function with this many parameters and M_PKTHDR + * should go away with constant propagation for !MGETHDR. + */ +static __inline int +m_init(struct mbuf *m, int how, short type, int flags) +{ + int error; + + m->m_next = NULL; + m->m_nextpkt = NULL; + m->m_data = m->m_dat; + m->m_len = 0; + m->m_flags = flags; + m->m_type = type; + if (flags & M_PKTHDR) + error = m_pkthdr_init(m, how); + else + error = 0; + + MBUF_PROBE5(m__init, m, how, type, flags, error); + return (error); +} + +static __inline struct mbuf * +m_get(int how, short type) +{ + struct mbuf *m; + struct mb_args args; + + args.flags = 0; + args.type = type; + m = uma_zalloc_arg(zone_mbuf, &args, how); + MBUF_PROBE3(m__get, how, type, m); + return (m); +} + +static __inline struct mbuf * +m_gethdr(int how, short type) +{ + struct mbuf *m; + struct mb_args args; + + args.flags = M_PKTHDR; + args.type = type; + m = uma_zalloc_arg(zone_mbuf, &args, how); + MBUF_PROBE3(m__gethdr, how, type, m); + return (m); +} + +static __inline struct mbuf * +m_getcl(int how, short type, int flags) +{ + struct mbuf *m; + struct mb_args args; + + args.flags = flags; + args.type = type; + m = uma_zalloc_arg(zone_pack, &args, how); + MBUF_PROBE4(m__getcl, how, type, flags, m); + return (m); +} + +/* + * XXX: m_cljset() is a dangerous API. One must attach only a new, + * unreferenced cluster to an mbuf(9). It is not possible to assert + * that, so care can be taken only by users of the API. + */ +static __inline void +m_cljset(struct mbuf *m, void *cl, int type) +{ + int size; + + switch (type) { + case EXT_CLUSTER: + size = MCLBYTES; + break; +#if MJUMPAGESIZE != MCLBYTES + case EXT_JUMBOP: + size = MJUMPAGESIZE; + break; +#endif + case EXT_JUMBO9: + size = MJUM9BYTES; + break; + case EXT_JUMBO16: + size = MJUM16BYTES; + break; + default: + panic("%s: unknown cluster type %d", __func__, type); + break; + } + + m->m_data = m->m_ext.ext_buf = cl; + m->m_ext.ext_free = m->m_ext.ext_arg1 = m->m_ext.ext_arg2 = NULL; + m->m_ext.ext_size = size; + m->m_ext.ext_type = type; + m->m_ext.ext_flags = EXT_FLAG_EMBREF; + m->m_ext.ext_count = 1; + m->m_flags |= M_EXT; + MBUF_PROBE3(m__cljset, m, cl, type); +} + +static __inline void +m_chtype(struct mbuf *m, short new_type) +{ + + m->m_type = new_type; +} + +static __inline void +m_clrprotoflags(struct mbuf *m) +{ + + while (m) { + m->m_flags &= ~M_PROTOFLAGS; + m = m->m_next; + } +} + +static __inline struct mbuf * +m_last(struct mbuf *m) +{ + + while (m->m_next) + m = m->m_next; + return (m); +} + +static inline u_int +m_extrefcnt(struct mbuf *m) +{ + + KASSERT(m->m_flags & M_EXT, ("%s: M_EXT missing", __func__)); + + return ((m->m_ext.ext_flags & EXT_FLAG_EMBREF) ? m->m_ext.ext_count : + *m->m_ext.ext_cnt); +} + +/* + * mbuf, cluster, and external object allocation macros (for compatibility + * purposes). + */ +#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from)) +#define MGET(m, how, type) ((m) = m_get((how), (type))) +#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) +#define MCLGET(m, how) m_clget((m), (how)) +#define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \ + m_extadd((m), (char *)(buf), (size), (free), (arg1), (arg2), \ + (flags), (type)) +#define m_getm(m, len, how, type) \ + m_getm2((m), (len), (how), (type), M_PKTHDR) + +/* + * Evaluate TRUE if it's safe to write to the mbuf m's data region (this can + * be both the local data payload, or an external buffer area, depending on + * whether M_EXT is set). + */ +#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && \ + (!(((m)->m_flags & M_EXT)) || \ + (m_extrefcnt(m) == 1))) + +/* Check if the supplied mbuf has a packet header, or else panic. */ +#define M_ASSERTPKTHDR(m) \ + KASSERT((m) != NULL && (m)->m_flags & M_PKTHDR, \ + ("%s: no mbuf packet header!", __func__)) + +/* + * Ensure that the supplied mbuf is a valid, non-free mbuf. + * + * XXX: Broken at the moment. Need some UMA magic to make it work again. + */ +#define M_ASSERTVALID(m) \ + KASSERT((((struct mbuf *)m)->m_flags & 0) == 0, \ + ("%s: attempted use of a free mbuf!", __func__)) + +/* + * Return the address of the start of the buffer associated with an mbuf, + * handling external storage, packet-header mbufs, and regular data mbufs. + */ +#define M_START(m) \ + (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_buf : \ + ((m)->m_flags & M_PKTHDR) ? &(m)->m_pktdat[0] : \ + &(m)->m_dat[0]) + +/* + * Return the size of the buffer associated with an mbuf, handling external + * storage, packet-header mbufs, and regular data mbufs. + */ +#define M_SIZE(m) \ + (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \ + ((m)->m_flags & M_PKTHDR) ? MHLEN : \ + MLEN) + +/* + * Set the m_data pointer of a newly allocated mbuf to place an object of the + * specified size at the end of the mbuf, longword aligned. + * + * NB: Historically, we had M_ALIGN(), MH_ALIGN(), and MEXT_ALIGN() as + * separate macros, each asserting that it was called at the proper moment. + * This required callers to themselves test the storage type and call the + * right one. Rather than require callers to be aware of those layout + * decisions, we centralize here. + */ +static __inline void +m_align(struct mbuf *m, int len) +{ +#ifdef INVARIANTS + const char *msg = "%s: not a virgin mbuf"; +#endif + int adjust; + + KASSERT(m->m_data == M_START(m), (msg, __func__)); + + adjust = M_SIZE(m) - len; + m->m_data += adjust &~ (sizeof(long)-1); +} + +#define M_ALIGN(m, len) m_align(m, len) +#define MH_ALIGN(m, len) m_align(m, len) +#define MEXT_ALIGN(m, len) m_align(m, len) + +/* + * Compute the amount of space available before the current start of data in + * an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + * + * NB: In previous versions, M_LEADINGSPACE() would only check M_WRITABLE() + * for mbufs with external storage. We now allow mbuf-embedded data to be + * read-only as well. + */ +#define M_LEADINGSPACE(m) \ + (M_WRITABLE(m) ? ((m)->m_data - M_START(m)) : 0) + +/* + * Compute the amount of space available after the end of data in an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + * + * NB: In previous versions, M_TRAILINGSPACE() would only check M_WRITABLE() + * for mbufs with external storage. We now allow mbuf-embedded data to be + * read-only as well. + */ +#define M_TRAILINGSPACE(m) \ + (M_WRITABLE(m) ? \ + ((M_START(m) + M_SIZE(m)) - ((m)->m_data + (m)->m_len)) : 0) + +/* + * Arrange to prepend space of size plen to mbuf m. If a new mbuf must be + * allocated, how specifies whether to wait. If the allocation fails, the + * original mbuf chain is freed and m is set to NULL. + */ +#define M_PREPEND(m, plen, how) do { \ + struct mbuf **_mmp = &(m); \ + struct mbuf *_mm = *_mmp; \ + int _mplen = (plen); \ + int __mhow = (how); \ + \ + MBUF_CHECKSLEEP(how); \ + if (M_LEADINGSPACE(_mm) >= _mplen) { \ + _mm->m_data -= _mplen; \ + _mm->m_len += _mplen; \ + } else \ + _mm = m_prepend(_mm, _mplen, __mhow); \ + if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ + _mm->m_pkthdr.len += _mplen; \ + *_mmp = _mm; \ +} while (0) + +/* + * Change mbuf to new type. This is a relatively expensive operation and + * should be avoided. + */ +#define MCHTYPE(m, t) m_chtype((m), (t)) + +/* Length to m_copy to copy all. */ +#define M_COPYALL 1000000000 + +extern int max_datalen; /* MHLEN - max_hdr */ +extern int max_hdr; /* Largest link + protocol header */ +extern int max_linkhdr; /* Largest link-level header */ +extern int max_protohdr; /* Largest protocol header */ +extern int nmbclusters; /* Maximum number of clusters */ + +/*- + * Network packets may have annotations attached by affixing a list of + * "packet tags" to the pkthdr structure. Packet tags are dynamically + * allocated semi-opaque data structures that have a fixed header + * (struct m_tag) that specifies the size of the memory block and a + * pair that identifies it. The cookie is a 32-bit unique + * unsigned value used to identify a module or ABI. By convention this value + * is chosen as the date+time that the module is created, expressed as the + * number of seconds since the epoch (e.g., using date -u +'%s'). The type + * value is an ABI/module-specific value that identifies a particular + * annotation and is private to the module. For compatibility with systems + * like OpenBSD that define packet tags w/o an ABI/module cookie, the value + * PACKET_ABI_COMPAT is used to implement m_tag_get and m_tag_find + * compatibility shim functions and several tag types are defined below. + * Users that do not require compatibility should use a private cookie value + * so that packet tag-related definitions can be maintained privately. + * + * Note that the packet tag returned by m_tag_alloc has the default memory + * alignment implemented by malloc. To reference private data one can use a + * construct like: + * + * struct m_tag *mtag = m_tag_alloc(...); + * struct foo *p = (struct foo *)(mtag+1); + * + * if the alignment of struct m_tag is sufficient for referencing members of + * struct foo. Otherwise it is necessary to embed struct m_tag within the + * private data structure to insure proper alignment; e.g., + * + * struct foo { + * struct m_tag tag; + * ... + * }; + * struct foo *p = (struct foo *) m_tag_alloc(...); + * struct m_tag *mtag = &p->tag; + */ + +/* + * Persistent tags stay with an mbuf until the mbuf is reclaimed. Otherwise + * tags are expected to ``vanish'' when they pass through a network + * interface. For most interfaces this happens normally as the tags are + * reclaimed when the mbuf is free'd. However in some special cases + * reclaiming must be done manually. An example is packets that pass through + * the loopback interface. Also, one must be careful to do this when + * ``turning around'' packets (e.g., icmp_reflect). + * + * To mark a tag persistent bit-or this flag in when defining the tag id. + * The tag will then be treated as described above. + */ +#define MTAG_PERSISTENT 0x800 + +#define PACKET_TAG_NONE 0 /* Nadda */ + +/* Packet tags for use with PACKET_ABI_COMPAT. */ +#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */ +#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */ +#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */ +#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */ +#define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */ +#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */ +#define PACKET_TAG_BRIDGE 7 /* Bridge processing done */ +#define PACKET_TAG_GIF 8 /* GIF processing done */ +#define PACKET_TAG_GRE 9 /* GRE processing done */ +#define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */ +#define PACKET_TAG_ENCAP 11 /* Encap. processing */ +#define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */ +#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */ +#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */ +#define PACKET_TAG_DUMMYNET 15 /* dummynet info */ +#define PACKET_TAG_DIVERT 17 /* divert info */ +#define PACKET_TAG_IPFORWARD 18 /* ipforward info */ +#define PACKET_TAG_MACLABEL (19 | MTAG_PERSISTENT) /* MAC label */ +#define PACKET_TAG_PF (21 | MTAG_PERSISTENT) /* PF/ALTQ information */ +#define PACKET_TAG_RTSOCKFAM 25 /* rtsock sa family */ +#define PACKET_TAG_IPOPTIONS 27 /* Saved IP options */ +#define PACKET_TAG_CARP 28 /* CARP info */ +#define PACKET_TAG_IPSEC_NAT_T_PORTS 29 /* two uint16_t */ +#define PACKET_TAG_ND_OUTGOING 30 /* ND outgoing */ + +/* Specific cookies and tags. */ + +/* Packet tag routines. */ +struct m_tag *m_tag_alloc(u_int32_t, int, int, int); +void m_tag_delete(struct mbuf *, struct m_tag *); +void m_tag_delete_chain(struct mbuf *, struct m_tag *); +void m_tag_free_default(struct m_tag *); +struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *); +struct m_tag *m_tag_copy(struct m_tag *, int); +int m_tag_copy_chain(struct mbuf *, const struct mbuf *, int); +void m_tag_delete_nonpersistent(struct mbuf *); + +/* + * Initialize the list of tags associated with an mbuf. + */ +static __inline void +m_tag_init(struct mbuf *m) +{ + + SLIST_INIT(&m->m_pkthdr.tags); +} + +/* + * Set up the contents of a tag. Note that this does not fill in the free + * method; the caller is expected to do that. + * + * XXX probably should be called m_tag_init, but that was already taken. + */ +static __inline void +m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len) +{ + + t->m_tag_id = type; + t->m_tag_len = len; + t->m_tag_cookie = cookie; +} + +/* + * Reclaim resources associated with a tag. + */ +static __inline void +m_tag_free(struct m_tag *t) +{ + + (*t->m_tag_free)(t); +} + +/* + * Return the first tag associated with an mbuf. + */ +static __inline struct m_tag * +m_tag_first(struct mbuf *m) +{ + + return (SLIST_FIRST(&m->m_pkthdr.tags)); +} + +/* + * Return the next tag in the list of tags associated with an mbuf. + */ +static __inline struct m_tag * +m_tag_next(struct mbuf *m __unused, struct m_tag *t) +{ + + return (SLIST_NEXT(t, m_tag_link)); +} + +/* + * Prepend a tag to the list of tags associated with an mbuf. + */ +static __inline void +m_tag_prepend(struct mbuf *m, struct m_tag *t) +{ + + SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link); +} + +/* + * Unlink a tag from the list of tags associated with an mbuf. + */ +static __inline void +m_tag_unlink(struct mbuf *m, struct m_tag *t) +{ + + SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link); +} + +/* These are for OpenBSD compatibility. */ +#define MTAG_ABI_COMPAT 0 /* compatibility ABI */ + +static __inline struct m_tag * +m_tag_get(int type, int length, int wait) +{ + return (m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait)); +} + +static __inline struct m_tag * +m_tag_find(struct mbuf *m, int type, struct m_tag *start) +{ + return (SLIST_EMPTY(&m->m_pkthdr.tags) ? (struct m_tag *)NULL : + m_tag_locate(m, MTAG_ABI_COMPAT, type, start)); +} + +static __inline struct mbuf * +m_free(struct mbuf *m) +{ + struct mbuf *n = m->m_next; + + MBUF_PROBE1(m__free, m); + if ((m->m_flags & (M_PKTHDR|M_NOFREE)) == (M_PKTHDR|M_NOFREE)) + m_tag_delete_chain(m, NULL); + if (m->m_flags & M_EXT) + mb_free_ext(m); + else if ((m->m_flags & M_NOFREE) == 0) + uma_zfree(zone_mbuf, m); + return (n); +} + +static __inline int +rt_m_getfib(struct mbuf *m) +{ + KASSERT(m->m_flags & M_PKTHDR , ("Attempt to get FIB from non header mbuf.")); + return (m->m_pkthdr.fibnum); +} + +#define M_GETFIB(_m) rt_m_getfib(_m) + +#define M_SETFIB(_m, _fib) do { \ + KASSERT((_m)->m_flags & M_PKTHDR, ("Attempt to set FIB on non header mbuf.")); \ + ((_m)->m_pkthdr.fibnum) = (_fib); \ +} while (0) + +/* flags passed as first argument for "m_ether_tcpip_hash()" */ +#define MBUF_HASHFLAG_L2 (1 << 2) +#define MBUF_HASHFLAG_L3 (1 << 3) +#define MBUF_HASHFLAG_L4 (1 << 4) + +/* mbuf hashing helper routines */ +uint32_t m_ether_tcpip_hash_init(void); +uint32_t m_ether_tcpip_hash(const uint32_t, const struct mbuf *, const uint32_t); + +#ifdef MBUF_PROFILING + void m_profile(struct mbuf *m); + #define M_PROFILE(m) m_profile(m) +#else + #define M_PROFILE(m) +#endif + +struct mbufq { + STAILQ_HEAD(, mbuf) mq_head; + int mq_len; + int mq_maxlen; +}; + +static inline void +mbufq_init(struct mbufq *mq, int maxlen) +{ + + STAILQ_INIT(&mq->mq_head); + mq->mq_maxlen = maxlen; + mq->mq_len = 0; +} + +static inline struct mbuf * +mbufq_flush(struct mbufq *mq) +{ + struct mbuf *m; + + m = STAILQ_FIRST(&mq->mq_head); + STAILQ_INIT(&mq->mq_head); + mq->mq_len = 0; + return (m); +} + +static inline void +mbufq_drain(struct mbufq *mq) +{ + struct mbuf *m, *n; + + n = mbufq_flush(mq); + while ((m = n) != NULL) { + n = STAILQ_NEXT(m, m_stailqpkt); + m_freem(m); + } +} + +static inline struct mbuf * +mbufq_first(const struct mbufq *mq) +{ + + return (STAILQ_FIRST(&mq->mq_head)); +} + +static inline struct mbuf * +mbufq_last(const struct mbufq *mq) +{ + + return (STAILQ_LAST(&mq->mq_head, mbuf, m_stailqpkt)); +} + +static inline int +mbufq_full(const struct mbufq *mq) +{ + + return (mq->mq_len >= mq->mq_maxlen); +} + +static inline int +mbufq_len(const struct mbufq *mq) +{ + + return (mq->mq_len); +} + +static inline int +mbufq_enqueue(struct mbufq *mq, struct mbuf *m) +{ + + if (mbufq_full(mq)) + return (ENOBUFS); + STAILQ_INSERT_TAIL(&mq->mq_head, m, m_stailqpkt); + mq->mq_len++; + return (0); +} + +static inline struct mbuf * +mbufq_dequeue(struct mbufq *mq) +{ + struct mbuf *m; + + m = STAILQ_FIRST(&mq->mq_head); + if (m) { + STAILQ_REMOVE_HEAD(&mq->mq_head, m_stailqpkt); + m->m_nextpkt = NULL; + mq->mq_len--; + } + return (m); +} + +static inline void +mbufq_prepend(struct mbufq *mq, struct mbuf *m) +{ + + STAILQ_INSERT_HEAD(&mq->mq_head, m, m_stailqpkt); + mq->mq_len++; +} + +/* + * Note: this doesn't enforce the maximum list size for dst. + */ +static inline void +mbufq_concat(struct mbufq *mq_dst, struct mbufq *mq_src) +{ + + mq_dst->mq_len += mq_src->mq_len; + STAILQ_CONCAT(&mq_dst->mq_head, &mq_src->mq_head); + mq_src->mq_len = 0; +} + +#ifdef _SYS_TIMESPEC_H_ +static inline void +mbuf_tstmp2timespec(struct mbuf *m, struct timespec *ts) +{ + + KASSERT((m->m_flags & M_PKTHDR) != 0, ("mbuf %p no M_PKTHDR", m)); + KASSERT((m->m_flags & M_TSTMP) != 0, ("mbuf %p no M_TSTMP", m)); + ts->tv_sec = m->m_pkthdr.rcv_tstmp / 1000000000; + ts->tv_nsec = m->m_pkthdr.rcv_tstmp % 1000000000; +} +#endif + +#ifdef NETDUMP +/* Invoked from the netdump client code. */ +void netdump_mbuf_drain(void); +void netdump_mbuf_dump(void); +void netdump_mbuf_reinit(int nmbuf, int nclust, int clsize); +#endif + +#endif /* _KERNEL */ +#endif /* !_SYS_MBUF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mchain.h b/lib/libc/include/any-freebsd-any/sys/mchain.h new file mode 100644 index 000000000000..28391d749472 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mchain.h @@ -0,0 +1,105 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000, 2001 Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_MCHAIN_H_ +#define _SYS_MCHAIN_H_ + +#ifdef _KERNEL + +/* + * Type of copy for mb_{put|get}_mem() + */ +#define MB_MSYSTEM 0 /* use bcopy() */ +#define MB_MUSER 1 /* use copyin()/copyout() */ +#define MB_MINLINE 2 /* use an inline copy loop */ +#define MB_MZERO 3 /* bzero(), mb_put_mem only */ +#define MB_MCUSTOM 4 /* use an user defined function */ + +struct mbuf; +struct mbchain; + +typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, + size_t *srclen, size_t *dstlen); + +struct mbchain { + struct mbuf * mb_top; /* head of mbufs chain */ + struct mbuf * mb_cur; /* current mbuf */ + int mb_mleft; /* free space in the current mbuf */ + int mb_count; /* total number of bytes */ + mb_copy_t * mb_copy; /* user defined copy function */ + void * mb_udata; /* user data */ +}; + +struct mdchain { + struct mbuf * md_top; /* head of mbufs chain */ + struct mbuf * md_cur; /* current mbuf */ + u_char * md_pos; /* offset in the current mbuf */ +}; + +int mb_init(struct mbchain *mbp); +void mb_initm(struct mbchain *mbp, struct mbuf *m); +void mb_done(struct mbchain *mbp); +struct mbuf *mb_detach(struct mbchain *mbp); +int mb_fixhdr(struct mbchain *mbp); +caddr_t mb_reserve(struct mbchain *mbp, int size); + +int mb_put_padbyte(struct mbchain *mbp); +int mb_put_uint8(struct mbchain *mbp, u_int8_t x); +int mb_put_uint16be(struct mbchain *mbp, u_int16_t x); +int mb_put_uint16le(struct mbchain *mbp, u_int16_t x); +int mb_put_uint32be(struct mbchain *mbp, u_int32_t x); +int mb_put_uint32le(struct mbchain *mbp, u_int32_t x); +int mb_put_int64be(struct mbchain *mbp, int64_t x); +int mb_put_int64le(struct mbchain *mbp, int64_t x); +int mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type); +int mb_put_mbuf(struct mbchain *mbp, struct mbuf *m); +int mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size); + +int md_init(struct mdchain *mdp); +void md_initm(struct mdchain *mbp, struct mbuf *m); +void md_done(struct mdchain *mdp); +void md_append_record(struct mdchain *mdp, struct mbuf *top); +int md_next_record(struct mdchain *mdp); +int md_get_uint8(struct mdchain *mdp, u_int8_t *x); +int md_get_uint16(struct mdchain *mdp, u_int16_t *x); +int md_get_uint16le(struct mdchain *mdp, u_int16_t *x); +int md_get_uint16be(struct mdchain *mdp, u_int16_t *x); +int md_get_uint32(struct mdchain *mdp, u_int32_t *x); +int md_get_uint32be(struct mdchain *mdp, u_int32_t *x); +int md_get_uint32le(struct mdchain *mdp, u_int32_t *x); +int md_get_int64(struct mdchain *mdp, int64_t *x); +int md_get_int64be(struct mdchain *mdp, int64_t *x); +int md_get_int64le(struct mdchain *mdp, int64_t *x); +int md_get_mem(struct mdchain *mdp, caddr_t target, int size, int type); +int md_get_mbuf(struct mdchain *mdp, int size, struct mbuf **m); +int md_get_uio(struct mdchain *mdp, struct uio *uiop, int size); + +#endif /* ifdef _KERNEL */ + +#endif /* !_SYS_MCHAIN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/md4.h b/lib/libc/include/any-freebsd-any/sys/md4.h new file mode 100644 index 000000000000..78873d9f7e8e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/md4.h @@ -0,0 +1,52 @@ +/* MD4.H - header file for MD4C.C + * $FreeBSD$ + */ + +/*- + SPDX-License-Identifier: RSA-MD + + Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD4 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD4 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD4_H_ +#define _MD4_H_ +/* MD4 context. */ +typedef struct MD4Context { + u_int32_t state[4]; /* state (ABCD) */ + u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD4_CTX; + +#include + +__BEGIN_DECLS +void MD4Init(MD4_CTX *); +void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); +void MD4Pad(MD4_CTX *); +void MD4Final(unsigned char [__min_size(16)], MD4_CTX *); +#ifndef _KERNEL +char * MD4End(MD4_CTX *, char *); +char * MD4File(const char *, char *); +char * MD4Data(const unsigned char *, unsigned int, char *); +#endif +__END_DECLS + +#endif /* _MD4_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/md5.h b/lib/libc/include/any-freebsd-any/sys/md5.h new file mode 100644 index 000000000000..f5ddd9c48cd1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/md5.h @@ -0,0 +1,59 @@ +/* MD5.H - header file for MD5C.C + * $FreeBSD$ + */ + +/*- + SPDX-License-Identifier: RSA-MD + + Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + */ + +#ifndef _SYS_MD5_H_ +#define _SYS_MD5_H_ + +#define MD5_BLOCK_LENGTH 64 +#define MD5_DIGEST_LENGTH 16 +#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) + +/* MD5 context. */ +typedef struct MD5Context { + u_int32_t state[4]; /* state (ABCD) */ + u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +#include + +__BEGIN_DECLS +void MD5Init (MD5_CTX *); +void MD5Update (MD5_CTX *, const void *, unsigned int); +void MD5Final (unsigned char[__min_size(MD5_DIGEST_LENGTH)], MD5_CTX *); +#ifndef _KERNEL +char * MD5End(MD5_CTX *, char *); +char * MD5Fd(int, char *); +char * MD5FdChunk(int, char *, off_t, off_t); +char * MD5File(const char *, char *); +char * MD5FileChunk(const char *, char *, off_t, off_t); +char * MD5Data(const void *, unsigned int, char *); +#endif +__END_DECLS +#endif /* _SYS_MD5_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mdioctl.h b/lib/libc/include/any-freebsd-any/sys/mdioctl.h new file mode 100644 index 000000000000..37a3804fe79e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mdioctl.h @@ -0,0 +1,96 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah $Hdr: fdioctl.h 1.1 90/07/09$ + * + * @(#)vnioctl.h 8.1 (Berkeley) 6/10/93 + * + * From: src/sys/sys/vnioctl.h,v 1.4 + * + * $FreeBSD$ + */ + +#ifndef _SYS_MDIOCTL_H_ +#define _SYS_MDIOCTL_H_ + +enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWAP, MD_NULL}; + +/* + * Ioctl definitions for memory disk pseudo-device. + */ + +#define MDNPAD 96 +struct md_ioctl { + unsigned md_version; /* Structure layout version */ + unsigned md_unit; /* unit number */ + enum md_types md_type ; /* type of disk */ + char *md_file; /* pathname of file to mount */ + off_t md_mediasize; /* size of disk in bytes */ + unsigned md_sectorsize; /* sectorsize */ + unsigned md_options; /* options */ + u_int64_t md_base; /* base address */ + int md_fwheads; /* firmware heads */ + int md_fwsectors; /* firmware sectors */ + char *md_label; /* label of the device */ + int md_pad[MDNPAD]; /* storage for MDIOCLIST */ +}; + +#define MD_NAME "md" +#define MDCTL_NAME "mdctl" +#define MDIOVERSION 0 + +/* + * Before you can use a unit, it must be configured with MDIOCSET. + * The configuration persists across opens and closes of the device; + * an MDIOCCLR must be used to reset a configuration. An attempt to + * MDIOCSET an already active unit will return EBUSY. + */ + +#define MDIOCATTACH _IOWR('m', 0, struct md_ioctl) /* attach disk */ +#define MDIOCDETACH _IOWR('m', 1, struct md_ioctl) /* detach disk */ +#define MDIOCQUERY _IOWR('m', 2, struct md_ioctl) /* query status */ +#define MDIOCLIST _IOWR('m', 3, struct md_ioctl) /* query status */ +#define MDIOCRESIZE _IOWR('m', 4, struct md_ioctl) /* resize disk */ + +#define MD_CLUSTER 0x01 /* Don't cluster */ +#define MD_RESERVE 0x02 /* Pre-reserve swap */ +#define MD_AUTOUNIT 0x04 /* Assign next free unit */ +#define MD_READONLY 0x08 /* Readonly mode */ +#define MD_COMPRESS 0x10 /* Compression mode */ +#define MD_FORCE 0x20 /* Don't try to prevent foot-shooting */ +#define MD_ASYNC 0x40 /* Asynchronous mode */ +#define MD_VERIFY 0x80 /* Open file with O_VERIFY (vnode only) */ + +#endif /* _SYS_MDIOCTL_H_*/ diff --git a/lib/libc/include/any-freebsd-any/sys/memdesc.h b/lib/libc/include/any-freebsd-any/sys/memdesc.h new file mode 100644 index 000000000000..8a128fd7f519 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/memdesc.h @@ -0,0 +1,158 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 EMC Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_MEMDESC_H_ +#define _SYS_MEMDESC_H_ + +struct bio; +struct bus_dma_segment; +struct uio; +struct mbuf; +union ccb; + +/* + * struct memdesc encapsulates various memory descriptors and provides + * abstract access to them. + */ +struct memdesc { + union { + void *md_vaddr; + vm_paddr_t md_paddr; + struct bus_dma_segment *md_list; + struct bio *md_bio; + struct uio *md_uio; + struct mbuf *md_mbuf; + union ccb *md_ccb; + } u; + size_t md_opaque; /* type specific data. */ + uint32_t md_type; /* Type of memory. */ +}; + +#define MEMDESC_VADDR 1 /* Contiguous virtual address. */ +#define MEMDESC_PADDR 2 /* Contiguous physical address. */ +#define MEMDESC_VLIST 3 /* scatter/gather list of kva addresses. */ +#define MEMDESC_PLIST 4 /* scatter/gather list of physical addresses. */ +#define MEMDESC_BIO 5 /* Pointer to a bio (block io). */ +#define MEMDESC_UIO 6 /* Pointer to a uio (any io). */ +#define MEMDESC_MBUF 7 /* Pointer to a mbuf (network io). */ +#define MEMDESC_CCB 8 /* Cam control block. (scsi/ata io). */ + +static inline struct memdesc +memdesc_vaddr(void *vaddr, size_t len) +{ + struct memdesc mem; + + mem.u.md_vaddr = vaddr; + mem.md_opaque = len; + mem.md_type = MEMDESC_VADDR; + + return (mem); +} + +static inline struct memdesc +memdesc_paddr(vm_paddr_t paddr, size_t len) +{ + struct memdesc mem; + + mem.u.md_paddr = paddr; + mem.md_opaque = len; + mem.md_type = MEMDESC_PADDR; + + return (mem); +} + +static inline struct memdesc +memdesc_vlist(struct bus_dma_segment *vlist, int sglist_cnt) +{ + struct memdesc mem; + + mem.u.md_list = vlist; + mem.md_opaque = sglist_cnt; + mem.md_type = MEMDESC_VLIST; + + return (mem); +} + +static inline struct memdesc +memdesc_plist(struct bus_dma_segment *plist, int sglist_cnt) +{ + struct memdesc mem; + + mem.u.md_list = plist; + mem.md_opaque = sglist_cnt; + mem.md_type = MEMDESC_PLIST; + + return (mem); +} + +static inline struct memdesc +memdesc_bio(struct bio *bio) +{ + struct memdesc mem; + + mem.u.md_bio = bio; + mem.md_type = MEMDESC_BIO; + + return (mem); +} + +static inline struct memdesc +memdesc_uio(struct uio *uio) +{ + struct memdesc mem; + + mem.u.md_uio = uio; + mem.md_type = MEMDESC_UIO; + + return (mem); +} + +static inline struct memdesc +memdesc_mbuf(struct mbuf *mbuf) +{ + struct memdesc mem; + + mem.u.md_mbuf = mbuf; + mem.md_type = MEMDESC_MBUF; + + return (mem); +} + +static inline struct memdesc +memdesc_ccb(union ccb *ccb) +{ + struct memdesc mem; + + mem.u.md_ccb = ccb; + mem.md_type = MEMDESC_CCB; + + return (mem); +} +#endif /* _SYS_MEMDESC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/memrange.h b/lib/libc/include/any-freebsd-any/sys/memrange.h new file mode 100644 index 000000000000..6d6ff0ecc9c6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/memrange.h @@ -0,0 +1,79 @@ +/* + * Memory range attribute operations, performed on /dev/mem + * + * $FreeBSD$ + */ + +#ifndef _SYS_MEMRANGE_H_ +#define _SYS_MEMRANGE_H_ + +/* Memory range attributes */ +#define MDF_UNCACHEABLE (1<<0) /* region not cached */ +#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */ +#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ +#define MDF_WRITEBACK (1<<3) /* write-back cached */ +#define MDF_WRITEPROTECT (1<<4) /* read-only region */ +#define MDF_UNKNOWN (1<<5) /* any state we don't understand */ +#define MDF_ATTRMASK (0x00ffffff) + +#define MDF_FIXBASE (1<<24) /* fixed base */ +#define MDF_FIXLEN (1<<25) /* fixed length */ +#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ +#define MDF_ACTIVE (1<<27) /* currently active */ +#define MDF_BOGUS (1<<28) /* we don't like it */ +#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ +#define MDF_BUSY (1<<30) /* range is in use */ +#define MDF_FORCE (1<<31) /* force risky changes */ + +struct mem_range_desc +{ + u_int64_t mr_base; + u_int64_t mr_len; + int mr_flags; + char mr_owner[8]; +}; + +struct mem_range_op +{ + struct mem_range_desc *mo_desc; + int mo_arg[2]; +#define MEMRANGE_SET_UPDATE 0 +#define MEMRANGE_SET_REMOVE 1 + /* XXX want a flag that says "set and undo when I exit" */ +}; + +#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op) +#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op) + +#ifdef _KERNEL + +MALLOC_DECLARE(M_MEMDESC); + +struct mem_range_softc; +struct mem_range_ops +{ + void (*init)(struct mem_range_softc *sc); + int (*set)(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg); + void (*initAP)(struct mem_range_softc *sc); + void (*reinit)(struct mem_range_softc *sc); +}; + +struct mem_range_softc +{ + struct mem_range_ops *mr_op; + int mr_cap; + int mr_ndesc; + struct mem_range_desc *mr_desc; +}; + +extern struct mem_range_softc mem_range_softc; + +extern void mem_range_init(void); +extern void mem_range_destroy(void); + +extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg); +extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg); + +#endif /* _KERNEL */ + +#endif /* _SYS_MEMRANGE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mman.h b/lib/libc/include/any-freebsd-any/sys/mman.h new file mode 100644 index 000000000000..aed759b5a8de --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mman.h @@ -0,0 +1,283 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mman.h 8.2 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_MMAN_H_ +#define _SYS_MMAN_H_ + +#include +#include + +#if __BSD_VISIBLE +/* + * Inheritance for minherit() + */ +#define INHERIT_SHARE 0 +#define INHERIT_COPY 1 +#define INHERIT_NONE 2 +#define INHERIT_ZERO 3 +#endif + +/* + * Protections are chosen from these bits, or-ed together + */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* + * Flags contain sharing type and options. + * Sharing types; choose one. + */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ +#if __BSD_VISIBLE +#define MAP_COPY MAP_PRIVATE /* Obsolete */ +#endif + +/* + * Other flags + */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ + +#if __BSD_VISIBLE +#define MAP_RESERVED0020 0x0020 /* previously unimplemented MAP_RENAME */ +#define MAP_RESERVED0040 0x0040 /* previously unimplemented MAP_NORESERVE */ +#define MAP_RESERVED0080 0x0080 /* previously misimplemented MAP_INHERIT */ +#define MAP_RESERVED0100 0x0100 /* previously unimplemented MAP_NOEXTEND */ +#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ +#define MAP_STACK 0x0400 /* region grows down, like a stack */ +#define MAP_NOSYNC 0x0800 /* page to but do not sync underlying file */ + +/* + * Mapping type + */ +#define MAP_FILE 0x0000 /* map from file (default) */ +#define MAP_ANON 0x1000 /* allocated from memory, swap space */ +#ifndef _KERNEL +#define MAP_ANONYMOUS MAP_ANON /* For compatibility. */ +#endif /* !_KERNEL */ + +/* + * Extended flags + */ +#define MAP_GUARD 0x00002000 /* reserve but don't map address range */ +#define MAP_EXCL 0x00004000 /* for MAP_FIXED, fail if address is used */ +#define MAP_NOCORE 0x00020000 /* dont include these pages in a coredump */ +#define MAP_PREFAULT_READ 0x00040000 /* prefault mapping for reading */ +#ifdef __LP64__ +#define MAP_32BIT 0x00080000 /* map in the low 2GB of address space */ +#endif + +/* + * Request specific alignment (n == log2 of the desired alignment). + * + * MAP_ALIGNED_SUPER requests optimal superpage alignment, but does + * not enforce a specific alignment. + */ +#define MAP_ALIGNED(n) ((n) << MAP_ALIGNMENT_SHIFT) +#define MAP_ALIGNMENT_SHIFT 24 +#define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff) +#define MAP_ALIGNED_SUPER MAP_ALIGNED(1) /* align on a superpage */ +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 199309 +/* + * Process memory locking + */ +#define MCL_CURRENT 0x0001 /* Lock only current memory */ +#define MCL_FUTURE 0x0002 /* Lock all future memory as well */ +#endif + +/* + * Error return from mmap() + */ +#define MAP_FAILED ((void *)-1) + +/* + * msync() flags + */ +#define MS_SYNC 0x0000 /* msync synchronously */ +#define MS_ASYNC 0x0001 /* return immediately */ +#define MS_INVALIDATE 0x0002 /* invalidate all cached data */ + +/* + * Advice to madvise + */ +#define _MADV_NORMAL 0 /* no further special treatment */ +#define _MADV_RANDOM 1 /* expect random page references */ +#define _MADV_SEQUENTIAL 2 /* expect sequential page references */ +#define _MADV_WILLNEED 3 /* will need these pages */ +#define _MADV_DONTNEED 4 /* dont need these pages */ + +#if __BSD_VISIBLE +#define MADV_NORMAL _MADV_NORMAL +#define MADV_RANDOM _MADV_RANDOM +#define MADV_SEQUENTIAL _MADV_SEQUENTIAL +#define MADV_WILLNEED _MADV_WILLNEED +#define MADV_DONTNEED _MADV_DONTNEED +#define MADV_FREE 5 /* dont need these pages, and junk contents */ +#define MADV_NOSYNC 6 /* try to avoid flushes to physical media */ +#define MADV_AUTOSYNC 7 /* revert to default flushing strategy */ +#define MADV_NOCORE 8 /* do not include these pages in a core file */ +#define MADV_CORE 9 /* revert to including pages in a core file */ +#define MADV_PROTECT 10 /* protect process from pageout kill */ + +/* + * Return bits from mincore + */ +#define MINCORE_INCORE 0x1 /* Page is incore */ +#define MINCORE_REFERENCED 0x2 /* Page has been referenced by us */ +#define MINCORE_MODIFIED 0x4 /* Page has been modified by us */ +#define MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */ +#define MINCORE_MODIFIED_OTHER 0x10 /* Page has been modified */ +#define MINCORE_SUPER 0x20 /* Page is a "super" page */ + +/* + * Anonymous object constant for shm_open(). + */ +#define SHM_ANON ((char *)1) +#endif /* __BSD_VISIBLE */ + +/* + * XXX missing POSIX_TYPED_MEM_* macros and + * posix_typed_mem_info structure. + */ +#if __POSIX_VISIBLE >= 200112 +#define POSIX_MADV_NORMAL _MADV_NORMAL +#define POSIX_MADV_RANDOM _MADV_RANDOM +#define POSIX_MADV_SEQUENTIAL _MADV_SEQUENTIAL +#define POSIX_MADV_WILLNEED _MADV_WILLNEED +#define POSIX_MADV_DONTNEED _MADV_DONTNEED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if defined(_KERNEL) || defined(_WANT_FILE) +#include +#include +#include +#include +#include + +struct file; + +struct shmfd { + size_t shm_oldsize; + vm_object_t shm_object; + int shm_refs; + uid_t shm_uid; + gid_t shm_gid; + mode_t shm_mode; + int shm_kmappings; + + /* + * Values maintained solely to make this a better-behaved file + * descriptor for fstat() to run on. + */ + struct timespec shm_atime; + struct timespec shm_mtime; + struct timespec shm_ctime; + struct timespec shm_birthtime; + ino_t shm_ino; + + struct label *shm_label; /* MAC label */ + const char *shm_path; + + struct rangelock shm_rl; + struct mtx shm_mtx; + vm_ooffset_t shm_size; +}; +#endif + +#ifdef _KERNEL +int shm_map(struct file *fp, size_t size, off_t offset, void **memp); +int shm_unmap(struct file *fp, void *mem, size_t size); + +int shm_access(struct shmfd *shmfd, struct ucred *ucred, int flags); +struct shmfd *shm_alloc(struct ucred *ucred, mode_t mode); +struct shmfd *shm_hold(struct shmfd *shmfd); +void shm_drop(struct shmfd *shmfd); +int shm_dotruncate(struct shmfd *shmfd, off_t length); + +extern struct fileops shm_ops; +#else /* !_KERNEL */ + +__BEGIN_DECLS +/* + * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(), + * posix_typed_mem_open(). + */ +#if __BSD_VISIBLE +int getpagesizes(size_t *, int); +int madvise(void *, size_t, int); +int mincore(const void *, size_t, char *); +int minherit(void *, size_t, int); +#endif +int mlock(const void *, size_t); +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void * mmap(void *, size_t, int, int, int, off_t); +#endif +int mprotect(void *, size_t, int); +int msync(void *, size_t, int); +int munlock(const void *, size_t); +int munmap(void *, size_t); +#if __POSIX_VISIBLE >= 200112 +int posix_madvise(void *, size_t, int); +#endif +#if __POSIX_VISIBLE >= 199309 +int mlockall(int); +int munlockall(void); +int shm_open(const char *, int, mode_t); +int shm_unlink(const char *); +#endif +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_MMAN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/module.h b/lib/libc/include/any-freebsd-any/sys/module.h new file mode 100644 index 000000000000..89377df401a8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/module.h @@ -0,0 +1,279 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_MODULE_H_ +#define _SYS_MODULE_H_ + +/* + * Module metadata types + */ +#define MDT_DEPEND 1 /* argument is a module name */ +#define MDT_MODULE 2 /* module declaration */ +#define MDT_VERSION 3 /* module version(s) */ +#define MDT_PNP_INFO 4 /* Plug and play hints record */ + +#define MDT_STRUCT_VERSION 1 /* version of metadata structure */ +#define MDT_SETNAME "modmetadata_set" + +typedef enum modeventtype { + MOD_LOAD, + MOD_UNLOAD, + MOD_SHUTDOWN, + MOD_QUIESCE +} modeventtype_t; + +typedef struct module *module_t; +typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *); + +/* + * Struct for registering modules statically via SYSINIT. + */ +typedef struct moduledata { + const char *name; /* module name */ + modeventhand_t evhand; /* event handler */ + void *priv; /* extra data */ +} moduledata_t; + +/* + * A module can use this to report module specific data to the user via + * kldstat(2). + */ +typedef union modspecific { + int intval; + u_int uintval; + long longval; + u_long ulongval; +} modspecific_t; + +/* + * Module dependency declaration + */ +struct mod_depend { + int md_ver_minimum; + int md_ver_preferred; + int md_ver_maximum; +}; + +/* + * Module version declaration + */ +struct mod_version { + int mv_version; +}; + +struct mod_metadata { + int md_version; /* structure version MDTV_* */ + int md_type; /* type of entry MDT_* */ + const void *md_data; /* specific data */ + const char *md_cval; /* common string label */ +}; + +struct mod_pnp_match_info +{ + const char *descr; /* Description of the table */ + const char *bus; /* Name of the bus for this table */ + const void *table; /* Pointer to pnp table */ + int entry_len; /* Length of each entry in the table (may be */ + /* longer than descr describes). */ + int num_entry; /* Number of entries in the table */ +}; +#ifdef _KERNEL + +#include + +#define MODULE_METADATA_CONCAT(uniquifier) _mod_metadata##uniquifier +#define MODULE_METADATA(uniquifier, type, data, cval) \ + static struct mod_metadata MODULE_METADATA_CONCAT(uniquifier) = { \ + MDT_STRUCT_VERSION, \ + type, \ + data, \ + cval \ + }; \ + DATA_SET(modmetadata_set, MODULE_METADATA_CONCAT(uniquifier)) + +#define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) \ + static struct mod_depend _##module##_depend_on_##mdepend \ + __section(".data") = { \ + vmin, \ + vpref, \ + vmax \ + }; \ + MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \ + &_##module##_depend_on_##mdepend, #mdepend) + +/* + * Every kernel has a 'kernel' module with the version set to + * __FreeBSD_version. We embed a MODULE_DEPEND() inside every module + * that depends on the 'kernel' module. It uses the current value of + * __FreeBSD_version as the minimum and preferred versions. For the + * maximum version it rounds the version up to the end of its branch + * (i.e. M99999 for M.x). This allows a module built on M.x to work + * on M.y systems where y >= x, but fail on M.z systems where z < x. + */ +#define MODULE_KERNEL_MAXVER (roundup(__FreeBSD_version, 100000) - 1) + +#define DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, maxver) \ + MODULE_DEPEND(name, kernel, __FreeBSD_version, \ + __FreeBSD_version, maxver); \ + MODULE_METADATA(_md_##name, MDT_MODULE, &data, __XSTRING(name));\ + SYSINIT(name##module, sub, order, module_register_init, &data); \ + struct __hack + +#ifdef KLD_TIED +#define DECLARE_MODULE(name, data, sub, order) \ + DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, __FreeBSD_version) +#else +#define DECLARE_MODULE(name, data, sub, order) \ + DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, MODULE_KERNEL_MAXVER) +#endif + +/* + * The module declared with DECLARE_MODULE_TIED can only be loaded + * into the kernel with exactly the same __FreeBSD_version. + * + * Use it for modules that use kernel interfaces that are not stable + * even on STABLE/X branches. + */ +#define DECLARE_MODULE_TIED(name, data, sub, order) \ + DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, __FreeBSD_version) + +#define MODULE_VERSION_CONCAT(module, version) _##module##_version +#define MODULE_VERSION(module, version) \ + static struct mod_version MODULE_VERSION_CONCAT(module, version)\ + __section(".data") = { \ + version \ + }; \ + MODULE_METADATA(MODULE_VERSION_CONCAT(module, version), MDT_VERSION,\ + &MODULE_VERSION_CONCAT(module, version), __XSTRING(module)) + +/** + * Generic macros to create pnp info hints that modules may export + * to allow external tools to parse their internal device tables + * to make an informed guess about what driver(s) to load. + */ +#define MODULE_PNP_INFO(d, b, unique, t, n) \ + static const struct mod_pnp_match_info _module_pnp_##b##_##unique = { \ + .descr = d, \ + .bus = #b, \ + .table = t, \ + .entry_len = sizeof((t)[0]), \ + .num_entry = n \ + }; \ + MODULE_METADATA(_md_##b##_pnpinfo_##unique, MDT_PNP_INFO, \ + &_module_pnp_##b##_##unique, #b); +/** + * descr is a string that describes each entry in the table. The general + * form is the grammar (TYPE:pnp_name[/pnp_name];)* + * where TYPE is one of the following: + * U8 uint8_t element + * V8 like U8 and 0xff means match any + * G16 uint16_t element, any value >= matches + * L16 uint16_t element, any value <= matches + * M16 uint16_t element, mask of which of the following fields to use. + * U16 uint16_t element + * V16 like U16 and 0xffff means match any + * U32 uint32_t element + * V32 like U32 and 0xffffffff means match any + * W32 Two 16-bit values with first pnp_name in LSW and second in MSW. + * Z pointer to a string to match exactly + * D pointer to a string to human readable description for device + * P A pointer that should be ignored + * E EISA PNP Identifier (in binary, but bus publishes string) + * T Key for whole table. pnp_name=value. must be last, if present. + * + * The pnp_name "#" is reserved for other fields that should be ignored. + * Otherwise pnp_name must match the name from the parent device's pnpinfo + * output. The second pnp_name is used for the W32 type. + */ + +extern struct sx modules_sx; + +#define MOD_XLOCK sx_xlock(&modules_sx) +#define MOD_SLOCK sx_slock(&modules_sx) +#define MOD_XUNLOCK sx_xunlock(&modules_sx) +#define MOD_SUNLOCK sx_sunlock(&modules_sx) +#define MOD_LOCK_ASSERT sx_assert(&modules_sx, SX_LOCKED) +#define MOD_XLOCK_ASSERT sx_assert(&modules_sx, SX_XLOCKED) + +struct linker_file; + +void module_register_init(const void *); +int module_register(const struct moduledata *, struct linker_file *); +module_t module_lookupbyname(const char *); +module_t module_lookupbyid(int); +int module_quiesce(module_t); +void module_reference(module_t); +void module_release(module_t); +int module_unload(module_t); +int module_getid(module_t); +module_t module_getfnext(module_t); +const char * module_getname(module_t); +void module_setspecific(module_t, modspecific_t *); +struct linker_file *module_file(module_t); + +#ifdef MOD_DEBUG +extern int mod_debug; +#define MOD_DEBUG_REFS 1 + +#define MOD_DPF(cat, args) do { \ + if (mod_debug & MOD_DEBUG_##cat) \ + printf args; \ +} while (0) + +#else /* !MOD_DEBUG */ + +#define MOD_DPF(cat, args) +#endif +#endif /* _KERNEL */ + +#define MAXMODNAME 32 + +struct module_stat { + int version; /* set to sizeof(struct module_stat) */ + char name[MAXMODNAME]; + int refs; + int id; + modspecific_t data; +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int modnext(int _modid); +int modfnext(int _modid); +int modstat(int _modid, struct module_stat *_stat); +int modfind(const char *_name); +__END_DECLS + +#endif + +#endif /* !_SYS_MODULE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/module_khelp.h b/lib/libc/include/any-freebsd-any/sys/module_khelp.h new file mode 100644 index 000000000000..a66440277a41 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/module_khelp.h @@ -0,0 +1,98 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 Lawrence Stewart + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Lawrence Stewart while studying at the Centre + * for Advanced Internet Architectures, Swinburne University of Technology, made + * possible in part by grants from the FreeBSD Foundation and Cisco University + * Research Program Fund at Community Foundation Silicon Valley. + * + * Portions of this software were developed at the Centre for Advanced + * Internet Architectures, Swinburne University of Technology, Melbourne, + * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_MODULE_KHELP_H_ +#define _SYS_MODULE_KHELP_H_ + +/* XXXLAS: Needed for uma related typedefs. */ +#include + +/* Helper flags. */ +#define HELPER_NEEDS_OSD 0x0001 + +struct helper { + int (*mod_init) (void); + int (*mod_destroy) (void); +#define HELPER_NAME_MAXLEN 16 + char h_name[HELPER_NAME_MAXLEN]; + uma_zone_t h_zone; + struct hookinfo *h_hooks; + uint32_t h_nhooks; + uint32_t h_classes; + int32_t h_id; + volatile uint32_t h_refcount; + uint16_t h_flags; + TAILQ_ENTRY(helper) h_next; +}; + +struct khelp_modevent_data { + char name[HELPER_NAME_MAXLEN]; + struct helper *helper; + struct hookinfo *hooks; + int nhooks; + int uma_zsize; + uma_ctor umactor; + uma_dtor umadtor; +}; + +#define KHELP_DECLARE_MOD_UMA(hname, hdata, hhooks, version, size, ctor, dtor) \ + static struct khelp_modevent_data kmd_##hname = { \ + .name = #hname, \ + .helper = hdata, \ + .hooks = hhooks, \ + .nhooks = sizeof(hhooks) / sizeof(hhooks[0]), \ + .uma_zsize = size, \ + .umactor = ctor, \ + .umadtor = dtor \ + }; \ + static moduledata_t h_##hname = { \ + .name = #hname, \ + .evhand = khelp_modevent, \ + .priv = &kmd_##hname \ + }; \ + DECLARE_MODULE(hname, h_##hname, SI_SUB_KLD, SI_ORDER_ANY); \ + MODULE_VERSION(hname, version) + +#define KHELP_DECLARE_MOD(hname, hdata, hhooks, version) \ + KHELP_DECLARE_MOD_UMA(hname, hdata, hhooks, version, 0, NULL, NULL) + +int khelp_modevent(module_t mod, int type, void *data); + +#endif /* _SYS_MODULE_KHELP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mount.h b/lib/libc/include/any-freebsd-any/sys/mount.h new file mode 100644 index 000000000000..9f154a308713 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mount.h @@ -0,0 +1,1006 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mount.h 8.21 (Berkeley) 5/20/95 + * $FreeBSD$ + */ + +#ifndef _SYS_MOUNT_H_ +#define _SYS_MOUNT_H_ + +#include +#include +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif + +/* + * NOTE: When changing statfs structure, mount structure, MNT_* flags or + * MNTK_* flags also update DDB show mount command in vfs_subr.c. + */ + +typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */ + +#define fsidcmp(a, b) memcmp((a), (b), sizeof(fsid_t)) + +/* + * File identifier. + * These are unique per filesystem on a single machine. + * + * Note that the offset of fid_data is 4 bytes, so care must be taken to avoid + * undefined behavior accessing unaligned fields within an embedded struct. + */ +#define MAXFIDSZ 16 + +struct fid { + u_short fid_len; /* length of data in bytes */ + u_short fid_data0; /* force longword alignment */ + char fid_data[MAXFIDSZ]; /* data (variable length) */ +}; + +/* + * filesystem statistics + */ +#define MFSNAMELEN 16 /* length of type name including null */ +#define MNAMELEN 1024 /* size of on/from name bufs */ +#define STATFS_VERSION 0x20140518 /* current version number */ +struct statfs { + uint32_t f_version; /* structure version number */ + uint32_t f_type; /* type of filesystem */ + uint64_t f_flags; /* copy of mount exported flags */ + uint64_t f_bsize; /* filesystem fragment size */ + uint64_t f_iosize; /* optimal transfer block size */ + uint64_t f_blocks; /* total data blocks in filesystem */ + uint64_t f_bfree; /* free blocks in filesystem */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + uint64_t f_files; /* total file nodes in filesystem */ + int64_t f_ffree; /* free nodes avail to non-superuser */ + uint64_t f_syncwrites; /* count of sync writes since mount */ + uint64_t f_asyncwrites; /* count of async writes since mount */ + uint64_t f_syncreads; /* count of sync reads since mount */ + uint64_t f_asyncreads; /* count of async reads since mount */ + uint64_t f_spare[10]; /* unused spare */ + uint32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the filesystem */ + fsid_t f_fsid; /* filesystem id */ + char f_charspare[80]; /* spare string space */ + char f_fstypename[MFSNAMELEN]; /* filesystem type name */ + char f_mntfromname[MNAMELEN]; /* mounted filesystem */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ +}; + +#if defined(_WANT_FREEBSD11_STATFS) || defined(_KERNEL) +#define FREEBSD11_STATFS_VERSION 0x20030518 /* current version number */ +struct freebsd11_statfs { + uint32_t f_version; /* structure version number */ + uint32_t f_type; /* type of filesystem */ + uint64_t f_flags; /* copy of mount exported flags */ + uint64_t f_bsize; /* filesystem fragment size */ + uint64_t f_iosize; /* optimal transfer block size */ + uint64_t f_blocks; /* total data blocks in filesystem */ + uint64_t f_bfree; /* free blocks in filesystem */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + uint64_t f_files; /* total file nodes in filesystem */ + int64_t f_ffree; /* free nodes avail to non-superuser */ + uint64_t f_syncwrites; /* count of sync writes since mount */ + uint64_t f_asyncwrites; /* count of async writes since mount */ + uint64_t f_syncreads; /* count of sync reads since mount */ + uint64_t f_asyncreads; /* count of async reads since mount */ + uint64_t f_spare[10]; /* unused spare */ + uint32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the filesystem */ + fsid_t f_fsid; /* filesystem id */ + char f_charspare[80]; /* spare string space */ + char f_fstypename[16]; /* filesystem type name */ + char f_mntfromname[88]; /* mounted filesystem */ + char f_mntonname[88]; /* directory on which mounted */ +}; +#endif /* _WANT_FREEBSD11_STATFS || _KERNEL */ + +#ifdef _KERNEL +#define OMFSNAMELEN 16 /* length of fs type name, including null */ +#define OMNAMELEN (88 - 2 * sizeof(long)) /* size of on/from name bufs */ + +/* XXX getfsstat.2 is out of date with write and read counter changes here. */ +/* XXX statfs.2 is out of date with read counter changes here. */ +struct ostatfs { + long f_spare2; /* placeholder */ + long f_bsize; /* fundamental filesystem block size */ + long f_iosize; /* optimal transfer block size */ + long f_blocks; /* total data blocks in filesystem */ + long f_bfree; /* free blocks in fs */ + long f_bavail; /* free blocks avail to non-superuser */ + long f_files; /* total file nodes in filesystem */ + long f_ffree; /* free file nodes in fs */ + fsid_t f_fsid; /* filesystem id */ + uid_t f_owner; /* user that mounted the filesystem */ + int f_type; /* type of filesystem */ + int f_flags; /* copy of mount exported flags */ + long f_syncwrites; /* count of sync writes since mount */ + long f_asyncwrites; /* count of async writes since mount */ + char f_fstypename[OMFSNAMELEN]; /* fs type name */ + char f_mntonname[OMNAMELEN]; /* directory on which mounted */ + long f_syncreads; /* count of sync reads since mount */ + long f_asyncreads; /* count of async reads since mount */ + short f_spares1; /* unused spare */ + char f_mntfromname[OMNAMELEN];/* mounted filesystem */ + short f_spares2; /* unused spare */ + /* + * XXX on machines where longs are aligned to 8-byte boundaries, there + * is an unnamed int32_t here. This spare was after the apparent end + * of the struct until we bit off the read counters from f_mntonname. + */ + long f_spare[2]; /* unused spare */ +}; + +TAILQ_HEAD(vnodelst, vnode); + +/* Mount options list */ +TAILQ_HEAD(vfsoptlist, vfsopt); +struct vfsopt { + TAILQ_ENTRY(vfsopt) link; + char *name; + void *value; + int len; + int pos; + int seen; +}; + +/* + * Structure per mounted filesystem. Each mounted filesystem has an + * array of operations and an instance record. The filesystems are + * put on a doubly linked list. + * + * Lock reference: + * l - mnt_listmtx + * m - mountlist_mtx + * i - interlock + * v - vnode freelist mutex + * + * Unmarked fields are considered stable as long as a ref is held. + * + */ +struct mount { + struct mtx mnt_mtx; /* mount structure interlock */ + int mnt_gen; /* struct mount generation */ +#define mnt_startzero mnt_list + TAILQ_ENTRY(mount) mnt_list; /* (m) mount list */ + struct vfsops *mnt_op; /* operations on fs */ + struct vfsconf *mnt_vfc; /* configuration info */ + struct vnode *mnt_vnodecovered; /* vnode we mounted on */ + struct vnode *mnt_syncer; /* syncer vnode */ + int mnt_ref; /* (i) Reference count */ + struct vnodelst mnt_nvnodelist; /* (i) list of vnodes */ + int mnt_nvnodelistsize; /* (i) # of vnodes */ + int mnt_writeopcount; /* (i) write syscalls pending */ + int mnt_kern_flag; /* (i) kernel only flags */ + uint64_t mnt_flag; /* (i) flags shared with user */ + struct vfsoptlist *mnt_opt; /* current mount options */ + struct vfsoptlist *mnt_optnew; /* new options passed to fs */ + int mnt_maxsymlinklen; /* max size of short symlink */ + struct statfs mnt_stat; /* cache of filesystem stats */ + struct ucred *mnt_cred; /* credentials of mounter */ + void * mnt_data; /* private data */ + time_t mnt_time; /* last time written*/ + int mnt_iosize_max; /* max size for clusters, etc */ + struct netexport *mnt_export; /* export list */ + struct label *mnt_label; /* MAC label for the fs */ + u_int mnt_hashseed; /* Random seed for vfs_hash */ + int mnt_lockref; /* (i) Lock reference count */ + int mnt_secondary_writes; /* (i) # of secondary writes */ + int mnt_secondary_accwrites;/* (i) secondary wr. starts */ + struct thread *mnt_susp_owner; /* (i) thread owning suspension */ +#define mnt_endzero mnt_gjprovider + char *mnt_gjprovider; /* gjournal provider name */ + struct mtx mnt_listmtx; + struct vnodelst mnt_activevnodelist; /* (l) list of active vnodes */ + int mnt_activevnodelistsize;/* (l) # of active vnodes */ + struct vnodelst mnt_tmpfreevnodelist; /* (l) list of free vnodes */ + int mnt_tmpfreevnodelistsize;/* (l) # of free vnodes */ + struct lock mnt_explock; /* vfs_export walkers lock */ + TAILQ_ENTRY(mount) mnt_upper_link; /* (m) we in the all uppers */ + TAILQ_HEAD(, mount) mnt_uppers; /* (m) upper mounts over us*/ +}; + +/* + * Definitions for MNT_VNODE_FOREACH_ALL. + */ +struct vnode *__mnt_vnode_next_all(struct vnode **mvp, struct mount *mp); +struct vnode *__mnt_vnode_first_all(struct vnode **mvp, struct mount *mp); +void __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp); + +#define MNT_VNODE_FOREACH_ALL(vp, mp, mvp) \ + for (vp = __mnt_vnode_first_all(&(mvp), (mp)); \ + (vp) != NULL; vp = __mnt_vnode_next_all(&(mvp), (mp))) + +#define MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp) \ + do { \ + MNT_ILOCK(mp); \ + __mnt_vnode_markerfree_all(&(mvp), (mp)); \ + /* MNT_IUNLOCK(mp); -- done in above function */ \ + mtx_assert(MNT_MTX(mp), MA_NOTOWNED); \ + } while (0) + +/* + * Definitions for MNT_VNODE_FOREACH_ACTIVE. + */ +struct vnode *__mnt_vnode_next_active(struct vnode **mvp, struct mount *mp); +struct vnode *__mnt_vnode_first_active(struct vnode **mvp, struct mount *mp); +void __mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *); + +#define MNT_VNODE_FOREACH_ACTIVE(vp, mp, mvp) \ + for (vp = __mnt_vnode_first_active(&(mvp), (mp)); \ + (vp) != NULL; vp = __mnt_vnode_next_active(&(mvp), (mp))) + +#define MNT_VNODE_FOREACH_ACTIVE_ABORT(mp, mvp) \ + __mnt_vnode_markerfree_active(&(mvp), (mp)) + +#define MNT_ILOCK(mp) mtx_lock(&(mp)->mnt_mtx) +#define MNT_ITRYLOCK(mp) mtx_trylock(&(mp)->mnt_mtx) +#define MNT_IUNLOCK(mp) mtx_unlock(&(mp)->mnt_mtx) +#define MNT_MTX(mp) (&(mp)->mnt_mtx) +#define MNT_REF(mp) (mp)->mnt_ref++ +#define MNT_REL(mp) do { \ + KASSERT((mp)->mnt_ref > 0, ("negative mnt_ref")); \ + (mp)->mnt_ref--; \ + if ((mp)->mnt_ref == 0) \ + wakeup((mp)); \ +} while (0) + +#endif /* _KERNEL */ + +/* + * User specifiable flags, stored in mnt_flag. + */ +#define MNT_RDONLY 0x0000000000000001ULL /* read only filesystem */ +#define MNT_SYNCHRONOUS 0x0000000000000002ULL /* fs written synchronously */ +#define MNT_NOEXEC 0x0000000000000004ULL /* can't exec from filesystem */ +#define MNT_NOSUID 0x0000000000000008ULL /* don't honor setuid fs bits */ +#define MNT_NFS4ACLS 0x0000000000000010ULL /* enable NFS version 4 ACLs */ +#define MNT_UNION 0x0000000000000020ULL /* union with underlying fs */ +#define MNT_ASYNC 0x0000000000000040ULL /* fs written asynchronously */ +#define MNT_SUIDDIR 0x0000000000100000ULL /* special SUID dir handling */ +#define MNT_SOFTDEP 0x0000000000200000ULL /* using soft updates */ +#define MNT_NOSYMFOLLOW 0x0000000000400000ULL /* do not follow symlinks */ +#define MNT_GJOURNAL 0x0000000002000000ULL /* GEOM journal support enabled */ +#define MNT_MULTILABEL 0x0000000004000000ULL /* MAC support for objects */ +#define MNT_ACLS 0x0000000008000000ULL /* ACL support enabled */ +#define MNT_NOATIME 0x0000000010000000ULL /* dont update file access time */ +#define MNT_NOCLUSTERR 0x0000000040000000ULL /* disable cluster read */ +#define MNT_NOCLUSTERW 0x0000000080000000ULL /* disable cluster write */ +#define MNT_SUJ 0x0000000100000000ULL /* using journaled soft updates */ +#define MNT_AUTOMOUNTED 0x0000000200000000ULL /* mounted by automountd(8) */ +#define MNT_UNTRUSTED 0x0000000800000000ULL /* filesys metadata untrusted */ + +/* + * NFS export related mount flags. + */ +#define MNT_EXRDONLY 0x0000000000000080ULL /* exported read only */ +#define MNT_EXPORTED 0x0000000000000100ULL /* filesystem is exported */ +#define MNT_DEFEXPORTED 0x0000000000000200ULL /* exported to the world */ +#define MNT_EXPORTANON 0x0000000000000400ULL /* anon uid mapping for all */ +#define MNT_EXKERB 0x0000000000000800ULL /* exported with Kerberos */ +#define MNT_EXPUBLIC 0x0000000020000000ULL /* public export (WebNFS) */ + +/* + * Flags set by internal operations, + * but visible to the user. + * XXX some of these are not quite right.. (I've never seen the root flag set) + */ +#define MNT_LOCAL 0x0000000000001000ULL /* filesystem is stored locally */ +#define MNT_QUOTA 0x0000000000002000ULL /* quotas are enabled on fs */ +#define MNT_ROOTFS 0x0000000000004000ULL /* identifies the root fs */ +#define MNT_USER 0x0000000000008000ULL /* mounted by a user */ +#define MNT_IGNORE 0x0000000000800000ULL /* do not show entry in df */ +#define MNT_VERIFIED 0x0000000400000000ULL /* filesystem is verified */ + +/* + * Mask of flags that are visible to statfs(). + * XXX I think that this could now become (~(MNT_CMDFLAGS)) + * but the 'mount' program may need changing to handle this. + */ +#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \ + MNT_NOSUID | MNT_UNION | MNT_SUJ | \ + MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \ + MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \ + MNT_LOCAL | MNT_USER | MNT_QUOTA | \ + MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \ + MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP | \ + MNT_IGNORE | MNT_EXPUBLIC | MNT_NOSYMFOLLOW | \ + MNT_GJOURNAL | MNT_MULTILABEL | MNT_ACLS | \ + MNT_NFS4ACLS | MNT_AUTOMOUNTED | MNT_VERIFIED | \ + MNT_UNTRUSTED) + +/* Mask of flags that can be updated. */ +#define MNT_UPDATEMASK (MNT_NOSUID | MNT_NOEXEC | \ + MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | \ + MNT_NOATIME | \ + MNT_NOSYMFOLLOW | MNT_IGNORE | \ + MNT_NOCLUSTERR | MNT_NOCLUSTERW | MNT_SUIDDIR | \ + MNT_ACLS | MNT_USER | MNT_NFS4ACLS | \ + MNT_AUTOMOUNTED | MNT_UNTRUSTED) + +/* + * External filesystem command modifier flags. + * Unmount can use the MNT_FORCE flag. + * XXX: These are not STATES and really should be somewhere else. + * XXX: MNT_BYFSID and MNT_NONBUSY collide with MNT_ACLS and MNT_MULTILABEL, + * but because MNT_ACLS and MNT_MULTILABEL are only used for mount(2), + * and MNT_BYFSID and MNT_NONBUSY are only used for unmount(2), + * it's harmless. + */ +#define MNT_UPDATE 0x0000000000010000ULL /* not real mount, just update */ +#define MNT_DELEXPORT 0x0000000000020000ULL /* delete export host lists */ +#define MNT_RELOAD 0x0000000000040000ULL /* reload filesystem data */ +#define MNT_FORCE 0x0000000000080000ULL /* force unmount or readonly */ +#define MNT_SNAPSHOT 0x0000000001000000ULL /* snapshot the filesystem */ +#define MNT_NONBUSY 0x0000000004000000ULL /* check vnode use counts. */ +#define MNT_BYFSID 0x0000000008000000ULL /* specify filesystem by ID. */ +#define MNT_CMDFLAGS (MNT_UPDATE | MNT_DELEXPORT | MNT_RELOAD | \ + MNT_FORCE | MNT_SNAPSHOT | MNT_NONBUSY | \ + MNT_BYFSID) +/* + * Internal filesystem control flags stored in mnt_kern_flag. + * + * MNTK_UNMOUNT locks the mount entry so that name lookup cannot + * proceed past the mount point. This keeps the subtree stable during + * mounts and unmounts. When non-forced unmount flushes all vnodes + * from the mp queue, the MNTK_UNMOUNT flag prevents insmntque() from + * queueing new vnodes. + * + * MNTK_UNMOUNTF permits filesystems to detect a forced unmount while + * dounmount() is still waiting to lock the mountpoint. This allows + * the filesystem to cancel operations that might otherwise deadlock + * with the unmount attempt (used by NFS). + */ +#define MNTK_UNMOUNTF 0x00000001 /* forced unmount in progress */ +#define MNTK_ASYNC 0x00000002 /* filtered async flag */ +#define MNTK_SOFTDEP 0x00000004 /* async disabled by softdep */ +#define MNTK_DRAINING 0x00000010 /* lock draining is happening */ +#define MNTK_REFEXPIRE 0x00000020 /* refcount expiring is happening */ +#define MNTK_EXTENDED_SHARED 0x00000040 /* Allow shared locking for more ops */ +#define MNTK_SHARED_WRITES 0x00000080 /* Allow shared locking for writes */ +#define MNTK_NO_IOPF 0x00000100 /* Disallow page faults during reads + and writes. Filesystem shall properly + handle i/o state on EFAULT. */ +#define MNTK_VGONE_UPPER 0x00000200 +#define MNTK_VGONE_WAITER 0x00000400 +#define MNTK_LOOKUP_EXCL_DOTDOT 0x00000800 +#define MNTK_MARKER 0x00001000 +#define MNTK_UNMAPPED_BUFS 0x00002000 +#define MNTK_USES_BCACHE 0x00004000 /* FS uses the buffer cache. */ +#define MNTK_TEXT_REFS 0x00008000 /* Keep use ref for text */ +#define MNTK_VMSETSIZE_BUG 0x00010000 +#define MNTK_NOASYNC 0x00800000 /* disable async */ +#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */ +#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */ +#define MNTK_SUSPEND 0x08000000 /* request write suspension */ +#define MNTK_SUSPEND2 0x04000000 /* block secondary writes */ +#define MNTK_SUSPENDED 0x10000000 /* write operations are suspended */ +#define MNTK_NULL_NOCACHE 0x20000000 /* auto disable cache for nullfs + mounts over this fs */ +#define MNTK_LOOKUP_SHARED 0x40000000 /* FS supports shared lock lookups */ +#define MNTK_NOKNOTE 0x80000000 /* Don't send KNOTEs from VOP hooks */ + +#ifdef _KERNEL +static inline int +MNT_SHARED_WRITES(struct mount *mp) +{ + + return (mp != NULL && (mp->mnt_kern_flag & MNTK_SHARED_WRITES) != 0); +} + +static inline int +MNT_EXTENDED_SHARED(struct mount *mp) +{ + + return (mp != NULL && (mp->mnt_kern_flag & MNTK_EXTENDED_SHARED) != 0); +} +#endif + +/* + * Sysctl CTL_VFS definitions. + * + * Second level identifier specifies which filesystem. Second level + * identifier VFS_VFSCONF returns information about all filesystems. + * Second level identifier VFS_GENERIC is non-terminal. + */ +#define VFS_VFSCONF 0 /* get configured filesystems */ +#define VFS_GENERIC 0 /* generic filesystem information */ +/* + * Third level identifiers for VFS_GENERIC are given below; third + * level identifiers for specific filesystems are given in their + * mount specific header files. + */ +#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ +#define VFS_CONF 2 /* struct: vfsconf for filesystem given + as next argument */ + +/* + * Flags for various system call interfaces. + * + * waitfor flags to vfs_sync() and getfsstat() + */ +#define MNT_WAIT 1 /* synchronously wait for I/O to complete */ +#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ +#define MNT_LAZY 3 /* push data not written by filesystem syncer */ +#define MNT_SUSPEND 4 /* Suspend file system after sync */ + +/* + * Generic file handle + */ +struct fhandle { + fsid_t fh_fsid; /* Filesystem id of mount point */ + struct fid fh_fid; /* Filesys specific id */ +}; +typedef struct fhandle fhandle_t; + +/* + * Old export arguments without security flavor list + */ +struct oexport_args { + int ex_flags; /* export related flags */ + uid_t ex_root; /* mapping for root uid */ + struct xucred ex_anon; /* mapping for anonymous user */ + struct sockaddr *ex_addr; /* net address to which exported */ + u_char ex_addrlen; /* and the net address length */ + struct sockaddr *ex_mask; /* mask of valid bits in saddr */ + u_char ex_masklen; /* and the smask length */ + char *ex_indexfile; /* index file for WebNFS URLs */ +}; + +/* + * Export arguments for local filesystem mount calls. + */ +#define MAXSECFLAVORS 5 +struct export_args { + int ex_flags; /* export related flags */ + uid_t ex_root; /* mapping for root uid */ + struct xucred ex_anon; /* mapping for anonymous user */ + struct sockaddr *ex_addr; /* net address to which exported */ + u_char ex_addrlen; /* and the net address length */ + struct sockaddr *ex_mask; /* mask of valid bits in saddr */ + u_char ex_masklen; /* and the smask length */ + char *ex_indexfile; /* index file for WebNFS URLs */ + int ex_numsecflavors; /* security flavor count */ + int ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */ +}; + +/* + * Structure holding information for a publicly exported filesystem + * (WebNFS). Currently the specs allow just for one such filesystem. + */ +struct nfs_public { + int np_valid; /* Do we hold valid information */ + fhandle_t np_handle; /* Filehandle for pub fs (internal) */ + struct mount *np_mount; /* Mountpoint of exported fs */ + char *np_index; /* Index file */ +}; + +/* + * Filesystem configuration information. One of these exists for each + * type of filesystem supported by the kernel. These are searched at + * mount time to identify the requested filesystem. + * + * XXX: Never change the first two arguments! + */ +struct vfsconf { + u_int vfc_version; /* ABI version number */ + char vfc_name[MFSNAMELEN]; /* filesystem type name */ + struct vfsops *vfc_vfsops; /* filesystem operations vector */ + int vfc_typenum; /* historic filesystem type number */ + int vfc_refcount; /* number mounted of this type */ + int vfc_flags; /* permanent flags */ + int vfc_prison_flag; /* prison allow.mount.* flag */ + struct vfsoptdecl *vfc_opts; /* mount options */ + TAILQ_ENTRY(vfsconf) vfc_list; /* list of vfscons */ +}; + +/* Userland version of the struct vfsconf. */ +struct xvfsconf { + struct vfsops *vfc_vfsops; /* filesystem operations vector */ + char vfc_name[MFSNAMELEN]; /* filesystem type name */ + int vfc_typenum; /* historic filesystem type number */ + int vfc_refcount; /* number mounted of this type */ + int vfc_flags; /* permanent flags */ + struct vfsconf *vfc_next; /* next in list */ +}; + +#ifndef BURN_BRIDGES +struct ovfsconf { + void *vfc_vfsops; + char vfc_name[32]; + int vfc_index; + int vfc_refcount; + int vfc_flags; +}; +#endif + +/* + * NB: these flags refer to IMPLEMENTATION properties, not properties of + * any actual mounts; i.e., it does not make sense to change the flags. + */ +#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */ +#define VFCF_NETWORK 0x00020000 /* may get data over the network */ +#define VFCF_READONLY 0x00040000 /* writes are not implemented */ +#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */ +#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */ +#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode */ +#define VFCF_JAIL 0x00400000 /* can be mounted from within a jail */ +#define VFCF_DELEGADMIN 0x00800000 /* supports delegated administration */ +#define VFCF_SBDRY 0x01000000 /* Stop at Boundary: defer stop requests + to kernel->user (AST) transition */ + +typedef uint32_t fsctlop_t; + +struct vfsidctl { + int vc_vers; /* should be VFSIDCTL_VERS1 (below) */ + fsid_t vc_fsid; /* fsid to operate on */ + char vc_fstypename[MFSNAMELEN]; + /* type of fs 'nfs' or '*' */ + fsctlop_t vc_op; /* operation VFS_CTL_* (below) */ + void *vc_ptr; /* pointer to data structure */ + size_t vc_len; /* sizeof said structure */ + u_int32_t vc_spare[12]; /* spare (must be zero) */ +}; + +/* vfsidctl API version. */ +#define VFS_CTL_VERS1 0x01 + +/* + * New style VFS sysctls, do not reuse/conflict with the namespace for + * private sysctls. + * All "global" sysctl ops have the 33rd bit set: + * 0x...1.... + * Private sysctl ops should have the 33rd bit unset. + */ +#define VFS_CTL_QUERY 0x00010001 /* anything wrong? (vfsquery) */ +#define VFS_CTL_TIMEO 0x00010002 /* set timeout for vfs notification */ +#define VFS_CTL_NOLOCKS 0x00010003 /* disable file locking */ + +struct vfsquery { + u_int32_t vq_flags; + u_int32_t vq_spare[31]; +}; + +/* vfsquery flags */ +#define VQ_NOTRESP 0x0001 /* server down */ +#define VQ_NEEDAUTH 0x0002 /* server bad auth */ +#define VQ_LOWDISK 0x0004 /* we're low on space */ +#define VQ_MOUNT 0x0008 /* new filesystem arrived */ +#define VQ_UNMOUNT 0x0010 /* filesystem has left */ +#define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */ +#define VQ_ASSIST 0x0040 /* filesystem needs assistance from external + program */ +#define VQ_NOTRESPLOCK 0x0080 /* server lockd down */ +#define VQ_FLAG0100 0x0100 /* placeholder */ +#define VQ_FLAG0200 0x0200 /* placeholder */ +#define VQ_FLAG0400 0x0400 /* placeholder */ +#define VQ_FLAG0800 0x0800 /* placeholder */ +#define VQ_FLAG1000 0x1000 /* placeholder */ +#define VQ_FLAG2000 0x2000 /* placeholder */ +#define VQ_FLAG4000 0x4000 /* placeholder */ +#define VQ_FLAG8000 0x8000 /* placeholder */ + +#ifdef _KERNEL +/* Point a sysctl request at a vfsidctl's data. */ +#define VCTLTOREQ(vc, req) \ + do { \ + (req)->newptr = (vc)->vc_ptr; \ + (req)->newlen = (vc)->vc_len; \ + (req)->newidx = 0; \ + } while (0) +#endif + +struct iovec; +struct uio; + +#ifdef _KERNEL + +/* + * vfs_busy specific flags and mask. + */ +#define MBF_NOWAIT 0x01 +#define MBF_MNTLSTLOCK 0x02 +#define MBF_MASK (MBF_NOWAIT | MBF_MNTLSTLOCK) + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_MOUNT); +MALLOC_DECLARE(M_STATFS); +#endif +extern int maxvfsconf; /* highest defined filesystem type */ + +TAILQ_HEAD(vfsconfhead, vfsconf); +extern struct vfsconfhead vfsconf; + +/* + * Operations supported on mounted filesystem. + */ +struct mount_args; +struct nameidata; +struct sysctl_req; +struct mntarg; + +typedef int vfs_cmount_t(struct mntarg *ma, void *data, uint64_t flags); +typedef int vfs_unmount_t(struct mount *mp, int mntflags); +typedef int vfs_root_t(struct mount *mp, int flags, struct vnode **vpp); +typedef int vfs_quotactl_t(struct mount *mp, int cmds, uid_t uid, void *arg); +typedef int vfs_statfs_t(struct mount *mp, struct statfs *sbp); +typedef int vfs_sync_t(struct mount *mp, int waitfor); +typedef int vfs_vget_t(struct mount *mp, ino_t ino, int flags, + struct vnode **vpp); +typedef int vfs_fhtovp_t(struct mount *mp, struct fid *fhp, + int flags, struct vnode **vpp); +typedef int vfs_checkexp_t(struct mount *mp, struct sockaddr *nam, + int *extflagsp, struct ucred **credanonp, + int *numsecflavors, int **secflavors); +typedef int vfs_init_t(struct vfsconf *); +typedef int vfs_uninit_t(struct vfsconf *); +typedef int vfs_extattrctl_t(struct mount *mp, int cmd, + struct vnode *filename_vp, int attrnamespace, + const char *attrname); +typedef int vfs_mount_t(struct mount *mp); +typedef int vfs_sysctl_t(struct mount *mp, fsctlop_t op, + struct sysctl_req *req); +typedef void vfs_susp_clean_t(struct mount *mp); +typedef void vfs_notify_lowervp_t(struct mount *mp, struct vnode *lowervp); +typedef void vfs_purge_t(struct mount *mp); + +struct vfsops { + vfs_mount_t *vfs_mount; + vfs_cmount_t *vfs_cmount; + vfs_unmount_t *vfs_unmount; + vfs_root_t *vfs_root; + vfs_quotactl_t *vfs_quotactl; + vfs_statfs_t *vfs_statfs; + vfs_sync_t *vfs_sync; + vfs_vget_t *vfs_vget; + vfs_fhtovp_t *vfs_fhtovp; + vfs_checkexp_t *vfs_checkexp; + vfs_init_t *vfs_init; + vfs_uninit_t *vfs_uninit; + vfs_extattrctl_t *vfs_extattrctl; + vfs_sysctl_t *vfs_sysctl; + vfs_susp_clean_t *vfs_susp_clean; + vfs_notify_lowervp_t *vfs_reclaim_lowervp; + vfs_notify_lowervp_t *vfs_unlink_lowervp; + vfs_purge_t *vfs_purge; + vfs_mount_t *vfs_spare[6]; /* spares for ABI compat */ +}; + +vfs_statfs_t __vfs_statfs; + +#define VFS_PROLOGUE(MP) do { \ + struct mount *mp__; \ + int _prev_stops; \ + \ + mp__ = (MP); \ + _prev_stops = sigdeferstop((mp__ != NULL && \ + (mp__->mnt_vfc->vfc_flags & VFCF_SBDRY) != 0) ? \ + SIGDEFERSTOP_SILENT : SIGDEFERSTOP_NOP); + +#define VFS_EPILOGUE(MP) \ + sigallowstop(_prev_stops); \ +} while (0) + +#define VFS_MOUNT(MP) ({ \ + int _rc; \ + \ + TSRAW(curthread, TS_ENTER, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_mount)(MP); \ + VFS_EPILOGUE(MP); \ + TSRAW(curthread, TS_EXIT, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\ + _rc; }) + +#define VFS_UNMOUNT(MP, FORCE) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_unmount)(MP, FORCE); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_ROOT(MP, FLAGS, VPP) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_root)(MP, FLAGS, VPP); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_QUOTACTL(MP, C, U, A) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_STATFS(MP, SBP) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = __vfs_statfs((MP), (SBP)); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_SYNC(MP, WAIT) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_sync)(MP, WAIT); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_VGET(MP, INO, FLAGS, VPP) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_vget)(MP, INO, FLAGS, VPP); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_FHTOVP(MP, FIDP, FLAGS, VPP) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, FLAGS, VPP); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED, NUMSEC, SEC) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED, NUMSEC,\ + SEC); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_EXTATTRCTL(MP, C, FN, NS, N) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_extattrctl)(MP, C, FN, NS, N); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_SYSCTL(MP, OP, REQ) ({ \ + int _rc; \ + \ + VFS_PROLOGUE(MP); \ + _rc = (*(MP)->mnt_op->vfs_sysctl)(MP, OP, REQ); \ + VFS_EPILOGUE(MP); \ + _rc; }) + +#define VFS_SUSP_CLEAN(MP) do { \ + if (*(MP)->mnt_op->vfs_susp_clean != NULL) { \ + VFS_PROLOGUE(MP); \ + (*(MP)->mnt_op->vfs_susp_clean)(MP); \ + VFS_EPILOGUE(MP); \ + } \ +} while (0) + +#define VFS_RECLAIM_LOWERVP(MP, VP) do { \ + if (*(MP)->mnt_op->vfs_reclaim_lowervp != NULL) { \ + VFS_PROLOGUE(MP); \ + (*(MP)->mnt_op->vfs_reclaim_lowervp)((MP), (VP)); \ + VFS_EPILOGUE(MP); \ + } \ +} while (0) + +#define VFS_UNLINK_LOWERVP(MP, VP) do { \ + if (*(MP)->mnt_op->vfs_unlink_lowervp != NULL) { \ + VFS_PROLOGUE(MP); \ + (*(MP)->mnt_op->vfs_unlink_lowervp)((MP), (VP)); \ + VFS_EPILOGUE(MP); \ + } \ +} while (0) + +#define VFS_PURGE(MP) do { \ + if (*(MP)->mnt_op->vfs_purge != NULL) { \ + VFS_PROLOGUE(MP); \ + (*(MP)->mnt_op->vfs_purge)(MP); \ + VFS_EPILOGUE(MP); \ + } \ +} while (0) + +#define VFS_KNOTE_LOCKED(vp, hint) do \ +{ \ + if (((vp)->v_vflag & VV_NOKNOTE) == 0) \ + VN_KNOTE((vp), (hint), KNF_LISTLOCKED); \ +} while (0) + +#define VFS_KNOTE_UNLOCKED(vp, hint) do \ +{ \ + if (((vp)->v_vflag & VV_NOKNOTE) == 0) \ + VN_KNOTE((vp), (hint), 0); \ +} while (0) + +#define VFS_NOTIFY_UPPER_RECLAIM 1 +#define VFS_NOTIFY_UPPER_UNLINK 2 + +#include + +/* + * Version numbers. + */ +#define VFS_VERSION_00 0x19660120 +#define VFS_VERSION_01 0x20121030 +#define VFS_VERSION_02 0x20180504 +#define VFS_VERSION VFS_VERSION_02 + +#define VFS_SET(vfsops, fsname, flags) \ + static struct vfsconf fsname ## _vfsconf = { \ + .vfc_version = VFS_VERSION, \ + .vfc_name = #fsname, \ + .vfc_vfsops = &vfsops, \ + .vfc_typenum = -1, \ + .vfc_flags = flags, \ + }; \ + static moduledata_t fsname ## _mod = { \ + #fsname, \ + vfs_modevent, \ + & fsname ## _vfsconf \ + }; \ + DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE) + +/* + * exported vnode operations + */ + +int dounmount(struct mount *, int, struct thread *); + +int kernel_mount(struct mntarg *ma, uint64_t flags); +int kernel_vmount(int flags, ...); +struct mntarg *mount_arg(struct mntarg *ma, const char *name, const void *val, int len); +struct mntarg *mount_argb(struct mntarg *ma, int flag, const char *name); +struct mntarg *mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...); +struct mntarg *mount_argsu(struct mntarg *ma, const char *name, const void *val, int len); +void statfs_scale_blocks(struct statfs *sf, long max_size); +struct vfsconf *vfs_byname(const char *); +struct vfsconf *vfs_byname_kld(const char *, struct thread *td, int *); +void vfs_mount_destroy(struct mount *); +void vfs_event_signal(fsid_t *, u_int32_t, intptr_t); +void vfs_freeopts(struct vfsoptlist *opts); +void vfs_deleteopt(struct vfsoptlist *opts, const char *name); +int vfs_buildopts(struct uio *auio, struct vfsoptlist **options); +int vfs_flagopt(struct vfsoptlist *opts, const char *name, uint64_t *w, + uint64_t val); +int vfs_getopt(struct vfsoptlist *, const char *, void **, int *); +int vfs_getopt_pos(struct vfsoptlist *opts, const char *name); +int vfs_getopt_size(struct vfsoptlist *opts, const char *name, + off_t *value); +char *vfs_getopts(struct vfsoptlist *, const char *, int *error); +int vfs_copyopt(struct vfsoptlist *, const char *, void *, int); +int vfs_filteropt(struct vfsoptlist *, const char **legal); +void vfs_opterror(struct vfsoptlist *opts, const char *fmt, ...); +int vfs_scanopt(struct vfsoptlist *opts, const char *name, const char *fmt, ...); +int vfs_setopt(struct vfsoptlist *opts, const char *name, void *value, + int len); +int vfs_setopt_part(struct vfsoptlist *opts, const char *name, void *value, + int len); +int vfs_setopts(struct vfsoptlist *opts, const char *name, + const char *value); +int vfs_setpublicfs /* set publicly exported fs */ + (struct mount *, struct netexport *, struct export_args *); +void vfs_msync(struct mount *, int); +int vfs_busy(struct mount *, int); +int vfs_export /* process mount export info */ + (struct mount *, struct export_args *); +void vfs_allocate_syncvnode(struct mount *); +void vfs_deallocate_syncvnode(struct mount *); +int vfs_donmount(struct thread *td, uint64_t fsflags, + struct uio *fsoptions); +void vfs_getnewfsid(struct mount *); +struct cdev *vfs_getrootfsid(struct mount *); +struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */ +struct mount *vfs_busyfs(fsid_t *); +int vfs_modevent(module_t, int, void *); +void vfs_mount_error(struct mount *, const char *, ...); +void vfs_mountroot(void); /* mount our root filesystem */ +void vfs_mountedfrom(struct mount *, const char *from); +void vfs_notify_upper(struct vnode *, int); +void vfs_oexport_conv(const struct oexport_args *oexp, + struct export_args *exp); +void vfs_ref(struct mount *); +void vfs_rel(struct mount *); +struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *, const char *, + struct ucred *); +int vfs_suser(struct mount *, struct thread *); +void vfs_unbusy(struct mount *); +void vfs_unmountall(void); +extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ +extern struct mtx mountlist_mtx; +extern struct nfs_public nfs_pub; +extern struct sx vfsconf_sx; +#define vfsconf_lock() sx_xlock(&vfsconf_sx) +#define vfsconf_unlock() sx_xunlock(&vfsconf_sx) +#define vfsconf_slock() sx_slock(&vfsconf_sx) +#define vfsconf_sunlock() sx_sunlock(&vfsconf_sx) + +/* + * Declarations for these vfs default operations are located in + * kern/vfs_default.c. They will be automatically used to replace + * null entries in VFS ops tables when registering a new filesystem + * type in the global table. + */ +vfs_root_t vfs_stdroot; +vfs_quotactl_t vfs_stdquotactl; +vfs_statfs_t vfs_stdstatfs; +vfs_sync_t vfs_stdsync; +vfs_sync_t vfs_stdnosync; +vfs_vget_t vfs_stdvget; +vfs_fhtovp_t vfs_stdfhtovp; +vfs_checkexp_t vfs_stdcheckexp; +vfs_init_t vfs_stdinit; +vfs_uninit_t vfs_stduninit; +vfs_extattrctl_t vfs_stdextattrctl; +vfs_sysctl_t vfs_stdsysctl; + +void syncer_suspend(void); +void syncer_resume(void); + +#else /* !_KERNEL */ + +#include + +struct stat; + +__BEGIN_DECLS +int fhlink(struct fhandle *, const char *); +int fhlinkat(struct fhandle *, int, const char *); +int fhopen(const struct fhandle *, int); +int fhreadlink(struct fhandle *, char *, size_t); +int fhstat(const struct fhandle *, struct stat *); +int fhstatfs(const struct fhandle *, struct statfs *); +int fstatfs(int, struct statfs *); +int getfh(const char *, fhandle_t *); +int getfhat(int, char *, struct fhandle *, int); +int getfsstat(struct statfs *, long, int); +int getmntinfo(struct statfs **, int); +int lgetfh(const char *, fhandle_t *); +int mount(const char *, const char *, int, void *); +int nmount(struct iovec *, unsigned int, int); +int statfs(const char *, struct statfs *); +int unmount(const char *, int); + +/* C library stuff */ +int getvfsbyname(const char *, struct xvfsconf *); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_MOUNT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mouse.h b/lib/libc/include/any-freebsd-any/sys/mouse.h new file mode 100644 index 000000000000..c2e41fe007f7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mouse.h @@ -0,0 +1,384 @@ +/*- + * SPDX-License-Identifier: BSD-1-Clause + * + * Copyright (c) 1992, 1993 Erik Forsberg. + * Copyright (c) 1996, 1997 Kazutaka YOKOTA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_MOUSE_H_ +#define _SYS_MOUSE_H_ + +#include +#include + +/* ioctls */ +#define MOUSE_GETSTATUS _IOR('M', 0, mousestatus_t) +#define MOUSE_GETHWINFO _IOR('M', 1, mousehw_t) +#define MOUSE_GETMODE _IOR('M', 2, mousemode_t) +#define MOUSE_SETMODE _IOW('M', 3, mousemode_t) +#define MOUSE_GETLEVEL _IOR('M', 4, int) +#define MOUSE_SETLEVEL _IOW('M', 5, int) +#define MOUSE_READSTATE _IOWR('M', 8, mousedata_t) +#define MOUSE_READDATA _IOWR('M', 9, mousedata_t) + +#ifdef notyet +#define MOUSE_SETRESOLUTION _IOW('M', 10, int) +#define MOUSE_SETSCALING _IOW('M', 11, int) +#define MOUSE_SETRATE _IOW('M', 12, int) +#define MOUSE_GETHWID _IOR('M', 13, int) +#endif + +#define MOUSE_SYN_GETHWINFO _IOR('M', 100, synapticshw_t) + +/* mouse status block */ +typedef struct mousestatus { + int flags; /* state change flags */ + int button; /* button status */ + int obutton; /* previous button status */ + int dx; /* x movement */ + int dy; /* y movement */ + int dz; /* z movement */ +} mousestatus_t; + +/* button */ +#define MOUSE_BUTTON1DOWN 0x0001 /* left */ +#define MOUSE_BUTTON2DOWN 0x0002 /* middle */ +#define MOUSE_BUTTON3DOWN 0x0004 /* right */ +#define MOUSE_BUTTON4DOWN 0x0008 +#define MOUSE_BUTTON5DOWN 0x0010 +#define MOUSE_BUTTON6DOWN 0x0020 +#define MOUSE_BUTTON7DOWN 0x0040 +#define MOUSE_BUTTON8DOWN 0x0080 +#define MOUSE_MAXBUTTON 31 +#define MOUSE_STDBUTTONS 0x0007 /* buttons 1-3 */ +#define MOUSE_EXTBUTTONS 0x7ffffff8 /* the others (28 of them!) */ +#define MOUSE_BUTTONS (MOUSE_STDBUTTONS | MOUSE_EXTBUTTONS) + +/* flags */ +#define MOUSE_STDBUTTONSCHANGED MOUSE_STDBUTTONS +#define MOUSE_EXTBUTTONSCHANGED MOUSE_EXTBUTTONS +#define MOUSE_BUTTONSCHANGED MOUSE_BUTTONS +#define MOUSE_POSCHANGED 0x80000000 + +typedef struct mousehw { + int buttons; /* -1 if unknown */ + int iftype; /* MOUSE_IF_XXX */ + int type; /* mouse/track ball/pad... */ + int model; /* I/F dependent model ID: MOUSE_MODEL_XXX */ + int hwid; /* I/F dependent hardware ID + * for the PS/2 mouse, it will be PSM_XXX_ID + */ +} mousehw_t; + +typedef struct synapticshw { + int infoMajor; + int infoMinor; + int infoRot180; + int infoPortrait; + int infoSensor; + int infoHardware; + int infoNewAbs; + int capPen; + int infoSimplC; + int infoGeometry; + int capExtended; + int capSleep; + int capFourButtons; + int capMultiFinger; + int capPalmDetect; + int capPassthrough; + int capMiddle; + int capLowPower; + int capMultiFingerReport; + int capBallistics; + int nExtendedButtons; + int nExtendedQueries; + int capClickPad; + int capDeluxeLEDs; + int noAbsoluteFilter; + int capReportsV; + int capUniformClickPad; + int capReportsMin; + int capInterTouch; + int capReportsMax; + int capClearPad; + int capAdvancedGestures; + int multiFingerMode; + int capCoveredPad; + int verticalScroll; + int horizontalScroll; + int verticalWheel; + int capEWmode; + int minimumXCoord; + int minimumYCoord; + int maximumXCoord; + int maximumYCoord; + int infoXupmm; + int infoYupmm; + int forcePad; + int topButtonPad; +} synapticshw_t; + +/* iftype */ +#define MOUSE_IF_UNKNOWN (-1) +#define MOUSE_IF_SERIAL 0 +#define MOUSE_IF_BUS 1 +#define MOUSE_IF_INPORT 2 +#define MOUSE_IF_PS2 3 +#define MOUSE_IF_SYSMOUSE 4 +#define MOUSE_IF_USB 5 + +/* type */ +#define MOUSE_UNKNOWN (-1) /* should be treated as a mouse */ +#define MOUSE_MOUSE 0 +#define MOUSE_TRACKBALL 1 +#define MOUSE_STICK 2 +#define MOUSE_PAD 3 + +/* model */ +#define MOUSE_MODEL_UNKNOWN (-1) +#define MOUSE_MODEL_GENERIC 0 +#define MOUSE_MODEL_GLIDEPOINT 1 +#define MOUSE_MODEL_NETSCROLL 2 +#define MOUSE_MODEL_NET 3 +#define MOUSE_MODEL_INTELLI 4 +#define MOUSE_MODEL_THINK 5 +#define MOUSE_MODEL_EASYSCROLL 6 +#define MOUSE_MODEL_MOUSEMANPLUS 7 +#define MOUSE_MODEL_KIDSPAD 8 +#define MOUSE_MODEL_VERSAPAD 9 +#define MOUSE_MODEL_EXPLORER 10 +#define MOUSE_MODEL_4D 11 +#define MOUSE_MODEL_4DPLUS 12 +#define MOUSE_MODEL_SYNAPTICS 13 +#define MOUSE_MODEL_TRACKPOINT 14 +#define MOUSE_MODEL_ELANTECH 15 + +typedef struct mousemode { + int protocol; /* MOUSE_PROTO_XXX */ + int rate; /* report rate (per sec), -1 if unknown */ + int resolution; /* MOUSE_RES_XXX, -1 if unknown */ + int accelfactor; /* accelation factor (must be 1 or greater) */ + int level; /* driver operation level */ + int packetsize; /* the length of the data packet */ + unsigned char syncmask[2]; /* sync. data bits in the header byte */ +} mousemode_t; + +/* protocol */ +/* + * Serial protocols: + * Microsoft, MouseSystems, Logitech, MM series, MouseMan, Hitachi Tablet, + * GlidePoint, IntelliMouse, Thinking Mouse, MouseRemote, Kidspad, + * VersaPad + * Bus mouse protocols: + * bus, InPort + * PS/2 mouse protocol: + * PS/2 + */ +#define MOUSE_PROTO_UNKNOWN (-1) +#define MOUSE_PROTO_MS 0 /* Microsoft Serial, 3 bytes */ +#define MOUSE_PROTO_MSC 1 /* Mouse Systems, 5 bytes */ +#define MOUSE_PROTO_LOGI 2 /* Logitech, 3 bytes */ +#define MOUSE_PROTO_MM 3 /* MM series, 3 bytes */ +#define MOUSE_PROTO_LOGIMOUSEMAN 4 /* Logitech MouseMan 3/4 bytes */ +#define MOUSE_PROTO_BUS 5 /* MS/Logitech bus mouse */ +#define MOUSE_PROTO_INPORT 6 /* MS/ATI InPort mouse */ +#define MOUSE_PROTO_PS2 7 /* PS/2 mouse, 3 bytes */ +#define MOUSE_PROTO_HITTAB 8 /* Hitachi Tablet 3 bytes */ +#define MOUSE_PROTO_GLIDEPOINT 9 /* ALPS GlidePoint, 3/4 bytes */ +#define MOUSE_PROTO_INTELLI 10 /* MS IntelliMouse, 4 bytes */ +#define MOUSE_PROTO_THINK 11 /* Kensington Thinking Mouse, 3/4 bytes */ +#define MOUSE_PROTO_SYSMOUSE 12 /* /dev/sysmouse */ +#define MOUSE_PROTO_X10MOUSEREM 13 /* X10 MouseRemote, 3 bytes */ +#define MOUSE_PROTO_KIDSPAD 14 /* Genius Kidspad */ +#define MOUSE_PROTO_VERSAPAD 15 /* Interlink VersaPad, 6 bytes */ +#define MOUSE_PROTO_JOGDIAL 16 /* Vaio's JogDial */ +#define MOUSE_PROTO_GTCO_DIGIPAD 17 + +#define MOUSE_RES_UNKNOWN (-1) +#define MOUSE_RES_DEFAULT 0 +#define MOUSE_RES_LOW (-2) +#define MOUSE_RES_MEDIUMLOW (-3) +#define MOUSE_RES_MEDIUMHIGH (-4) +#define MOUSE_RES_HIGH (-5) + +typedef struct mousedata { + int len; /* # of data in the buffer */ + int buf[16]; /* data buffer */ +} mousedata_t; + +/* Synaptics Touchpad */ +#define MOUSE_SYNAPTICS_PACKETSIZE 6 /* '3' works better */ + +/* Elantech Touchpad */ +#define MOUSE_ELANTECH_PACKETSIZE 6 + +/* Microsoft Serial mouse data packet */ +#define MOUSE_MSS_PACKETSIZE 3 +#define MOUSE_MSS_SYNCMASK 0x40 +#define MOUSE_MSS_SYNC 0x40 +#define MOUSE_MSS_BUTTONS 0x30 +#define MOUSE_MSS_BUTTON1DOWN 0x20 /* left */ +#define MOUSE_MSS_BUTTON2DOWN 0x00 /* no middle button */ +#define MOUSE_MSS_BUTTON3DOWN 0x10 /* right */ + +/* Logitech MouseMan data packet (M+ protocol) */ +#define MOUSE_LMAN_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ + +/* ALPS GlidePoint extension (variant of M+ protocol) */ +#define MOUSE_ALPS_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ +#define MOUSE_ALPS_TAP 0x10 /* `tapping' action, the 4th byte */ + +/* Kinsington Thinking Mouse extension (variant of M+ protocol) */ +#define MOUSE_THINK_BUTTON2DOWN 0x20 /* lower-left button, the 4th byte */ +#define MOUSE_THINK_BUTTON4DOWN 0x10 /* lower-right button, the 4th byte */ + +/* MS IntelliMouse (variant of MS Serial) */ +#define MOUSE_INTELLI_PACKETSIZE 4 +#define MOUSE_INTELLI_BUTTON2DOWN 0x10 /* middle button in the 4th byte */ + +/* Mouse Systems Corp. mouse data packet */ +#define MOUSE_MSC_PACKETSIZE 5 +#define MOUSE_MSC_SYNCMASK 0xf8 +#define MOUSE_MSC_SYNC 0x80 +#define MOUSE_MSC_BUTTONS 0x07 +#define MOUSE_MSC_BUTTON1UP 0x04 /* left */ +#define MOUSE_MSC_BUTTON2UP 0x02 /* middle */ +#define MOUSE_MSC_BUTTON3UP 0x01 /* right */ +#define MOUSE_MSC_MAXBUTTON 3 + +/* MM series mouse data packet */ +#define MOUSE_MM_PACKETSIZE 3 +#define MOUSE_MM_SYNCMASK 0xe0 +#define MOUSE_MM_SYNC 0x80 +#define MOUSE_MM_BUTTONS 0x07 +#define MOUSE_MM_BUTTON1DOWN 0x04 /* left */ +#define MOUSE_MM_BUTTON2DOWN 0x02 /* middle */ +#define MOUSE_MM_BUTTON3DOWN 0x01 /* right */ +#define MOUSE_MM_XPOSITIVE 0x10 +#define MOUSE_MM_YPOSITIVE 0x08 + +/* PS/2 mouse data packet */ +#define MOUSE_PS2_PACKETSIZE 3 +#define MOUSE_PS2_SYNCMASK 0xc8 +#define MOUSE_PS2_SYNC 0x08 +#define MOUSE_PS2_BUTTONS 0x07 /* 0x03 for 2 button mouse */ +#define MOUSE_PS2_BUTTON1DOWN 0x01 /* left */ +#define MOUSE_PS2_BUTTON2DOWN 0x04 /* middle */ +#define MOUSE_PS2_BUTTON3DOWN 0x02 /* right */ +#define MOUSE_PS2_TAP MOUSE_PS2_SYNC /* GlidePoint (PS/2) `tapping' + * Yes! this is the same bit + * as SYNC! + */ + +#define MOUSE_PS2_XNEG 0x10 +#define MOUSE_PS2_YNEG 0x20 +#define MOUSE_PS2_XOVERFLOW 0x40 +#define MOUSE_PS2_YOVERFLOW 0x80 + +/* Logitech MouseMan+ (PS/2) data packet (PS/2++ protocol) */ +#define MOUSE_PS2PLUS_SYNCMASK 0x48 +#define MOUSE_PS2PLUS_SYNC 0x48 +#define MOUSE_PS2PLUS_ZNEG 0x08 /* sign bit */ +#define MOUSE_PS2PLUS_BUTTON4DOWN 0x10 /* 4th button on MouseMan+ */ +#define MOUSE_PS2PLUS_BUTTON5DOWN 0x20 + +/* IBM ScrollPoint (PS/2) also uses PS/2++ protocol */ +#define MOUSE_SPOINT_ZNEG 0x80 /* sign bits */ +#define MOUSE_SPOINT_WNEG 0x08 + +/* MS IntelliMouse (PS/2) data packet */ +#define MOUSE_PS2INTELLI_PACKETSIZE 4 +/* some compatible mice have additional buttons */ +#define MOUSE_PS2INTELLI_BUTTON4DOWN 0x40 +#define MOUSE_PS2INTELLI_BUTTON5DOWN 0x80 + +/* MS IntelliMouse Explorer (PS/2) data packet (variation of IntelliMouse) */ +#define MOUSE_EXPLORER_ZNEG 0x08 /* sign bit */ +/* IntelliMouse Explorer has additional button data in the fourth byte */ +#define MOUSE_EXPLORER_BUTTON4DOWN 0x10 +#define MOUSE_EXPLORER_BUTTON5DOWN 0x20 + +/* Interlink VersaPad (serial I/F) data packet */ +#define MOUSE_VERSA_PACKETSIZE 6 +#define MOUSE_VERSA_IN_USE 0x04 +#define MOUSE_VERSA_SYNCMASK 0xc3 +#define MOUSE_VERSA_SYNC 0xc0 +#define MOUSE_VERSA_BUTTONS 0x30 +#define MOUSE_VERSA_BUTTON1DOWN 0x20 /* left */ +#define MOUSE_VERSA_BUTTON2DOWN 0x00 /* middle */ +#define MOUSE_VERSA_BUTTON3DOWN 0x10 /* right */ +#define MOUSE_VERSA_TAP 0x08 + +/* Interlink VersaPad (PS/2 I/F) data packet */ +#define MOUSE_PS2VERSA_PACKETSIZE 6 +#define MOUSE_PS2VERSA_IN_USE 0x10 +#define MOUSE_PS2VERSA_SYNCMASK 0xe8 +#define MOUSE_PS2VERSA_SYNC 0xc8 +#define MOUSE_PS2VERSA_BUTTONS 0x05 +#define MOUSE_PS2VERSA_BUTTON1DOWN 0x04 /* left */ +#define MOUSE_PS2VERSA_BUTTON2DOWN 0x00 /* middle */ +#define MOUSE_PS2VERSA_BUTTON3DOWN 0x01 /* right */ +#define MOUSE_PS2VERSA_TAP 0x02 + +/* A4 Tech 4D Mouse (PS/2) data packet */ +#define MOUSE_4D_PACKETSIZE 3 +#define MOUSE_4D_WHEELBITS 0xf0 + +/* A4 Tech 4D+ Mouse (PS/2) data packet */ +#define MOUSE_4DPLUS_PACKETSIZE 3 +#define MOUSE_4DPLUS_ZNEG 0x04 /* sign bit */ +#define MOUSE_4DPLUS_BUTTON4DOWN 0x08 + +/* sysmouse extended data packet */ +/* + * /dev/sysmouse sends data in two formats, depending on the protocol + * level. At the level 0, format is exactly the same as MousSystems' + * five byte packet. At the level 1, the first five bytes are the same + * as at the level 0. There are additional three bytes which shows + * `dz' and the states of additional buttons. `dz' is expressed as the + * sum of the byte 5 and 6 which contain signed seven bit values. + * The states of the button 4 though 10 are in the bit 0 though 6 in + * the byte 7 respectively: 1 indicates the button is up. + */ +#define MOUSE_SYS_PACKETSIZE 8 +#define MOUSE_SYS_SYNCMASK 0xf8 +#define MOUSE_SYS_SYNC 0x80 +#define MOUSE_SYS_BUTTON1UP 0x04 /* left, 1st byte */ +#define MOUSE_SYS_BUTTON2UP 0x02 /* middle, 1st byte */ +#define MOUSE_SYS_BUTTON3UP 0x01 /* right, 1st byte */ +#define MOUSE_SYS_BUTTON4UP 0x0001 /* 7th byte */ +#define MOUSE_SYS_BUTTON5UP 0x0002 +#define MOUSE_SYS_BUTTON6UP 0x0004 +#define MOUSE_SYS_BUTTON7UP 0x0008 +#define MOUSE_SYS_BUTTON8UP 0x0010 +#define MOUSE_SYS_BUTTON9UP 0x0020 +#define MOUSE_SYS_BUTTON10UP 0x0040 +#define MOUSE_SYS_MAXBUTTON 10 +#define MOUSE_SYS_STDBUTTONS 0x07 +#define MOUSE_SYS_EXTBUTTONS 0x7f /* the others */ + +/* Mouse remote socket */ +#define _PATH_MOUSEREMOTE "/var/run/MouseRemote" + +#endif /* _SYS_MOUSE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mpt_ioctl.h b/lib/libc/include/any-freebsd-any/sys/mpt_ioctl.h new file mode 100644 index 000000000000..527334594faf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mpt_ioctl.h @@ -0,0 +1,134 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2008 Yahoo!, Inc. + * All rights reserved. + * Written by: John Baldwin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * LSI MPT-Fusion Host Adapter FreeBSD userland interface + * + * $FreeBSD$ + */ + +#ifndef _MPT_IOCTL_H_ +#define _MPT_IOCTL_H_ + +#include +#include +#include + +/* + * For the read header requests, the header should include the page + * type or extended page type, page number, and page version. The + * buffer and length are unused. The completed header is returned in + * the 'header' member. + * + * For the read page and write page requests, 'buf' should point to a + * buffer of 'len' bytes which holds the entire page (including the + * header). + * + * All requests specify the page address in 'page_address'. + */ +struct mpt_cfg_page_req { + CONFIG_PAGE_HEADER header; + uint32_t page_address; + void *buf; + int len; + uint16_t ioc_status; +}; + +struct mpt_ext_cfg_page_req { + CONFIG_EXTENDED_PAGE_HEADER header; + uint32_t page_address; + void *buf; + int len; + uint16_t ioc_status; +}; + +struct mpt_raid_action { + uint8_t action; + uint8_t volume_bus; + uint8_t volume_id; + uint8_t phys_disk_num; + uint32_t action_data_word; + void *buf; + int len; + uint32_t volume_status; + uint32_t action_data[4]; + uint16_t action_status; + uint16_t ioc_status; + uint8_t write; +}; + +#define MPTIO_READ_CFG_HEADER _IOWR('M', 100, struct mpt_cfg_page_req) +#define MPTIO_READ_CFG_PAGE _IOWR('M', 101, struct mpt_cfg_page_req) +#define MPTIO_READ_EXT_CFG_HEADER _IOWR('M', 102, struct mpt_ext_cfg_page_req) +#define MPTIO_READ_EXT_CFG_PAGE _IOWR('M', 103, struct mpt_ext_cfg_page_req) +#define MPTIO_WRITE_CFG_PAGE _IOWR('M', 104, struct mpt_cfg_page_req) +#define MPTIO_RAID_ACTION _IOWR('M', 105, struct mpt_raid_action) + +#if defined(__amd64__) +struct mpt_cfg_page_req32 { + CONFIG_PAGE_HEADER header; + uint32_t page_address; + uint32_t buf; + int len; + uint16_t ioc_status; +}; + +struct mpt_ext_cfg_page_req32 { + CONFIG_EXTENDED_PAGE_HEADER header; + uint32_t page_address; + uint32_t buf; + int len; + uint16_t ioc_status; +}; + +struct mpt_raid_action32 { + uint8_t action; + uint8_t volume_bus; + uint8_t volume_id; + uint8_t phys_disk_num; + uint32_t action_data_word; + uint32_t buf; + int len; + uint32_t volume_status; + uint32_t action_data[4]; + uint16_t action_status; + uint16_t ioc_status; + uint8_t write; +}; + +#define MPTIO_READ_CFG_HEADER32 _IOWR('M', 100, struct mpt_cfg_page_req32) +#define MPTIO_READ_CFG_PAGE32 _IOWR('M', 101, struct mpt_cfg_page_req32) +#define MPTIO_READ_EXT_CFG_HEADER32 _IOWR('M', 102, struct mpt_ext_cfg_page_req32) +#define MPTIO_READ_EXT_CFG_PAGE32 _IOWR('M', 103, struct mpt_ext_cfg_page_req32) +#define MPTIO_WRITE_CFG_PAGE32 _IOWR('M', 104, struct mpt_cfg_page_req32) +#define MPTIO_RAID_ACTION32 _IOWR('M', 105, struct mpt_raid_action32) +#endif + +#endif /* !_MPT_IOCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mqueue.h b/lib/libc/include/any-freebsd-any/sys/mqueue.h new file mode 100644 index 000000000000..ca9fd13cca76 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mqueue.h @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 David Xu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_MQUEUE_H_ +#define _SYS_MQUEUE_H_ + +struct mq_attr { + long mq_flags; /* Message queue flags. */ + long mq_maxmsg; /* Maximum number of messages. */ + long mq_msgsize; /* Maximum message size. */ + long mq_curmsgs; /* Number of messages currently queued. */ + long __reserved[4]; /* Ignored for input, zeroed for output */ +}; + +#ifdef _KERNEL +struct thread; +struct file; +extern void (*mq_fdclose)(struct thread *td, int fd, struct file *fp); +#endif +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/msg.h b/lib/libc/include/any-freebsd-any/sys/msg.h new file mode 100644 index 000000000000..c98e0749ad53 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/msg.h @@ -0,0 +1,169 @@ +/* $FreeBSD$ */ +/* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ + +/*- + * SVID compatible msg.h file + * + * Author: Daniel Boulet + * + * Copyright 1993 Daniel Boulet and RTMX Inc. + * + * This system call was implemented by Daniel Boulet under contract from RTMX. + * + * Redistribution and use in source forms, with and without modification, + * are permitted provided that this entire comment appears intact. + * + * Redistribution in binary form may occur without any restrictions. + * Obviously, it would be nice if you gave credit where credit is due + * but requiring it would be too onerous. + * + * This software is provided ``AS IS'' without any warranties of any kind. + */ + +#ifndef _SYS_MSG_H_ +#define _SYS_MSG_H_ + +#include +#include +#ifdef _WANT_SYSVMSG_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif +#include + +/* + * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct + * are as defined by the SV API Intel 386 Processor Supplement. + */ + +#define MSG_NOERROR 010000 /* don't complain about too long msgs */ + +typedef unsigned long msglen_t; +typedef unsigned long msgqnum_t; + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) +struct msqid_ds_old { + struct ipc_perm_old msg_perm; /* msg queue permission bits */ + struct msg *__msg_first; /* first message in the queue */ + struct msg *__msg_last; /* last message in the queue */ + msglen_t msg_cbytes; /* number of bytes in use on the queue */ + msgqnum_t msg_qnum; /* number of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + long msg_pad1; + time_t msg_rtime; /* time of last msgrcv() */ + long msg_pad2; + time_t msg_ctime; /* time of last msgctl() */ + long msg_pad3; + long msg_pad4[4]; +}; +#endif + +/* + * XXX there seems to be no prefix reserved for this header, so the name + * "msg" in "struct msg" and the names of all of the nonstandard members + * are namespace pollution. + */ + +struct msqid_ds { + struct ipc_perm msg_perm; /* msg queue permission bits */ + struct msg *__msg_first; /* first message in the queue */ + struct msg *__msg_last; /* last message in the queue */ + msglen_t msg_cbytes; /* number of bytes in use on the queue */ + msgqnum_t msg_qnum; /* number of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + time_t msg_rtime; /* time of last msgrcv() */ + time_t msg_ctime; /* time of last msgctl() */ +}; + +#ifdef _KERNEL +struct msg { + struct msg *msg_next; /* next msg in the chain */ + long msg_type; /* type of this message */ + /* >0 -> type of this message */ + /* 0 -> free header */ + u_short msg_ts; /* size of this message */ + short msg_spot; /* location of start of msg in buffer */ + struct label *label; /* MAC Framework label */ +}; +#endif + +#if defined(_KERNEL) || defined(_WANT_SYSVMSG_INTERNALS) +/* + * Based on the configuration parameters described in an SVR2 (yes, two) + * config(1m) man page. + * + * Each message is broken up and stored in segments that are msgssz bytes + * long. For efficiency reasons, this should be a power of two. Also, + * it doesn't make sense if it is less than 8 or greater than about 256. + * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of + * two between 8 and 1024 inclusive (and panic's if it isn't). + */ +struct msginfo { + int msgmax; /* max chars in a message */ + int msgmni; /* max message queue identifiers */ + int msgmnb; /* max chars in a queue */ + int msgtql; /* max messages in system */ + int msgssz; /* size of a message segment (see note) */ + int msgseg; /* number of message segments */ +}; + +/* + * Kernel wrapper for the user-level structure. + */ +struct msqid_kernel { + /* + * Data structure exposed to user space. + */ + struct msqid_ds u; + + /* + * Kernel-private components of the message queue. + */ + struct label *label; /* MAC label */ + struct ucred *cred; /* creator's credentials */ +}; +#endif + +#ifdef _KERNEL +extern struct msginfo msginfo; + +#else /* _KERNEL */ + +__BEGIN_DECLS +int msgctl(int, int, struct msqid_ds *); +int msgget(key_t, int); +ssize_t msgrcv(int, void *, size_t, long, int); +int msgsnd(int, const void *, size_t, int); +#if __BSD_VISIBLE +int msgsys(int, ...); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_MSG_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/msgbuf.h b/lib/libc/include/any-freebsd-any/sys/msgbuf.h new file mode 100644 index 000000000000..df61f130e46f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/msgbuf.h @@ -0,0 +1,87 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1981, 1984, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_MSGBUF_H_ +#define _SYS_MSGBUF_H_ + +#include +#include + +struct msgbuf { + char *msg_ptr; /* pointer to buffer */ +#define MSG_MAGIC 0x063062 + u_int msg_magic; + u_int msg_size; /* size of buffer area */ + u_int msg_wseq; /* write sequence number */ + u_int msg_rseq; /* read sequence number */ + u_int msg_cksum; /* checksum of contents */ + u_int msg_seqmod; /* range for sequence numbers */ + int msg_lastpri; /* saved priority value */ + u_int msg_flags; +#define MSGBUF_NEEDNL 0x01 /* set when newline needed */ + struct mtx msg_lock; /* mutex to protect the buffer */ +}; + +/* Normalise a sequence number or a difference between sequence numbers. */ +#define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \ + (mbp)->msg_seqmod) +#define MSGBUF_SEQ_TO_POS(mbp, seq) ((seq) % (mbp)->msg_size) +/* Subtract sequence numbers. Note that only positive values result. */ +#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM((mbp), (seq1) - (seq2))) + +#ifdef _KERNEL +extern int msgbufsize; +extern int msgbuftrigger; +extern struct msgbuf *msgbufp; +extern struct mtx msgbuf_lock; + +void msgbufinit(void *ptr, int size); +void msgbuf_addchar(struct msgbuf *mbp, int c); +void msgbuf_addstr(struct msgbuf *mbp, int pri, const char *str, int filter_cr); +void msgbuf_clear(struct msgbuf *mbp); +void msgbuf_copy(struct msgbuf *src, struct msgbuf *dst); +int msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen); +int msgbuf_getchar(struct msgbuf *mbp); +int msgbuf_getcount(struct msgbuf *mbp); +void msgbuf_init(struct msgbuf *mbp, void *ptr, int size); +int msgbuf_peekbytes(struct msgbuf *mbp, char *buf, int buflen, + u_int *seqp); +void msgbuf_reinit(struct msgbuf *mbp, void *ptr, int size); + +#ifndef MSGBUF_SIZE +#define MSGBUF_SIZE (32768 * 3) +#endif +#endif /* KERNEL */ + +#endif /* !_SYS_MSGBUF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mtio.h b/lib/libc/include/any-freebsd-any/sys/mtio.h new file mode 100644 index 000000000000..d36125b20c39 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mtio.h @@ -0,0 +1,351 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mtio.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_MTIO_H_ +#define _SYS_MTIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Structures and definitions for mag tape io control commands + */ + +/* structure for MTIOCTOP - mag tape op command */ +struct mtop { + short mt_op; /* operations defined below */ + int32_t mt_count; /* how many of them */ +}; + +/* operations */ +#define MTWEOF 0 /* write an end-of-file record */ +#define MTFSF 1 /* forward space file */ +#define MTBSF 2 /* backward space file */ +#define MTFSR 3 /* forward space record */ +#define MTBSR 4 /* backward space record */ +#define MTREW 5 /* rewind */ +#define MTOFFL 6 /* rewind and put the drive offline */ +#define MTNOP 7 /* no operation, sets status only */ +#define MTCACHE 8 /* enable controller cache */ +#define MTNOCACHE 9 /* disable controller cache */ + +#if defined(__FreeBSD__) +/* Set block size for device. If device is a variable size dev */ +/* a non zero parameter will change the device to a fixed block size */ +/* device with block size set to that of the parameter passed in. */ +/* Resetting the block size to 0 will restore the device to a variable */ +/* block size device. */ + +#define MTSETBSIZ 10 + +/* Set density values for device. Sets the value for the opened mode only. */ + +#define MTSETDNSTY 11 + +#define MTERASE 12 /* erase to EOM */ +#define MTEOD 13 /* Space to EOM */ +#define MTCOMP 14 /* select compression mode 0=off, 1=def */ +#define MTRETENS 15 /* re-tension tape */ +#define MTWSS 16 /* write setmark(s) */ +#define MTFSS 17 /* forward space setmark */ +#define MTBSS 18 /* backward space setmark */ +#define MTLOAD 19 /* load tape in drive */ +#define MTWEOFI 20 /* write an end-of-file record without waiting*/ + +#define MT_COMP_ENABLE 0xffffffff +#define MT_COMP_DISABLED 0xfffffffe +#define MT_COMP_UNSUPP 0xfffffffd + +/* + * Values in mt_dsreg that say what the device is doing + */ +#define MTIO_DSREG_NIL 0 /* Unknown */ +#define MTIO_DSREG_REST 1 /* Doing Nothing */ +#define MTIO_DSREG_RBSY 2 /* Communicating with tape (but no motion) */ +#define MTIO_DSREG_WR 20 /* Writing */ +#define MTIO_DSREG_FMK 21 /* Writing Filemarks */ +#define MTIO_DSREG_ZER 22 /* Erasing */ +#define MTIO_DSREG_RD 30 /* Reading */ +#define MTIO_DSREG_FWD 40 /* Spacing Forward */ +#define MTIO_DSREG_REV 41 /* Spacing Reverse */ +#define MTIO_DSREG_POS 42 /* Hardware Positioning (direction unknown) */ +#define MTIO_DSREG_REW 43 /* Rewinding */ +#define MTIO_DSREG_TEN 44 /* Retensioning */ +#define MTIO_DSREG_UNL 45 /* Unloading */ +#define MTIO_DSREG_LD 46 /* Loading */ + +#endif /* __FreeBSD__ */ + +/* structure for MTIOCGET - mag tape get status command */ + +struct mtget { + short mt_type; /* type of magtape device */ +/* the following two registers are grossly device dependent */ + short mt_dsreg; /* ``drive status'' register */ + short mt_erreg; /* ``error'' register */ +/* end device-dependent registers */ + /* + * Note that the residual count, while maintained, may be + * be nonsense because the size of the residual may (greatly) + * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a + * more accurate count. + */ + short mt_resid; /* residual count */ +#if defined (__FreeBSD__) + int32_t mt_blksiz; /* presently operating blocksize */ + int32_t mt_density; /* presently operating density */ + u_int32_t mt_comp; /* presently operating compression */ + int32_t mt_blksiz0; /* blocksize for mode 0 */ + int32_t mt_blksiz1; /* blocksize for mode 1 */ + int32_t mt_blksiz2; /* blocksize for mode 2 */ + int32_t mt_blksiz3; /* blocksize for mode 3 */ + int32_t mt_density0; /* density for mode 0 */ + int32_t mt_density1; /* density for mode 1 */ + int32_t mt_density2; /* density for mode 2 */ + int32_t mt_density3; /* density for mode 3 */ +/* the following are not yet implemented */ + u_int32_t mt_comp0; /* compression type for mode 0 */ + u_int32_t mt_comp1; /* compression type for mode 1 */ + u_int32_t mt_comp2; /* compression type for mode 2 */ + u_int32_t mt_comp3; /* compression type for mode 3 */ +/* end not yet implemented */ +#endif + int32_t mt_fileno; /* relative file number of current position */ + int32_t mt_blkno; /* relative block number of current position */ +}; + +/* structure for MTIOCERRSTAT - tape get error status command */ +/* really only supported for SCSI tapes right now */ +struct scsi_tape_errors { + /* + * These are latched from the last command that had a SCSI + * Check Condition noted for these operations. The act + * of issuing an MTIOCERRSTAT unlatches and clears them. + */ + u_int8_t io_sense[32]; /* Last Sense Data For Data I/O */ + int32_t io_resid; /* residual count from last Data I/O */ + u_int8_t io_cdb[16]; /* Command that Caused the Last Data Sense */ + u_int8_t ctl_sense[32]; /* Last Sense Data For Control I/O */ + int32_t ctl_resid; /* residual count from last Control I/O */ + u_int8_t ctl_cdb[16]; /* Command that Caused the Last Control Sense */ + /* + * These are the read and write cumulative error counters. + * (how to reset cumulative error counters is not yet defined). + * (not implemented as yet but space is being reserved for them) + */ + struct { + u_int32_t retries; /* total # retries performed */ + u_int32_t corrected; /* total # corrections performed */ + u_int32_t processed; /* total # corrections successful */ + u_int32_t failures; /* total # corrections/retries failed */ + u_int64_t nbytes; /* total # bytes processed */ + } wterr, rderr; +}; + +union mterrstat { + struct scsi_tape_errors scsi_errstat; + char _reserved_padding[256]; +}; + +struct mtrblim { + uint32_t granularity; + uint32_t min_block_length; + uint32_t max_block_length; +}; + +typedef enum { + MT_LOCATE_DEST_OBJECT = 0x00, + MT_LOCATE_DEST_FILE = 0x01, + MT_LOCATE_DEST_SET = 0x02, + MT_LOCATE_DEST_EOD = 0x03 +} mt_locate_dest_type; + +typedef enum { + MT_LOCATE_BAM_IMPLICIT = 0x00, + MT_LOCATE_BAM_EXPLICIT = 0x01 +} mt_locate_bam; + +typedef enum { + MT_LOCATE_FLAG_IMMED = 0x01, + MT_LOCATE_FLAG_CHANGE_PART = 0x02 +} mt_locate_flags; + +struct mtlocate { + mt_locate_flags flags; + mt_locate_dest_type dest_type; + mt_locate_bam block_address_mode; + int64_t partition; + uint64_t logical_id; + uint8_t reserved[64]; +}; + +typedef enum { + MT_EXT_GET_NONE, + MT_EXT_GET_OK, + MT_EXT_GET_NEED_MORE_SPACE, + MT_EXT_GET_ERROR +} mt_ext_get_status; + +struct mtextget { + uint32_t alloc_len; + char *status_xml; + uint32_t fill_len; + mt_ext_get_status status; + char error_str[128]; + uint8_t reserved[64]; +}; + +#define MT_EXT_GET_ROOT_NAME "mtextget" +#define MT_DENSITY_ROOT_NAME "mtdensity" +#define MT_MEDIA_DENSITY_NAME "media_density" +#define MT_DENSITY_REPORT_NAME "density_report" +#define MT_MEDIUM_TYPE_REPORT_NAME "medium_type_report" +#define MT_MEDIA_REPORT_NAME "media_report" +#define MT_DENSITY_ENTRY_NAME "density_entry" + +#define MT_DENS_WRITE_OK 0x80 +#define MT_DENS_DUP 0x40 +#define MT_DENS_DEFLT 0x20 + + +#define MT_PARAM_FIXED_STR_LEN 32 +union mt_param_value { + int64_t value_signed; + uint64_t value_unsigned; + char *value_var_str; + char value_fixed_str[MT_PARAM_FIXED_STR_LEN]; + uint8_t reserved[64]; +}; + +typedef enum { + MT_PARAM_SET_NONE, + MT_PARAM_SET_SIGNED, + MT_PARAM_SET_UNSIGNED, + MT_PARAM_SET_VAR_STR, + MT_PARAM_SET_FIXED_STR +} mt_param_set_type; + +typedef enum { + MT_PARAM_STATUS_NONE, + MT_PARAM_STATUS_OK, + MT_PARAM_STATUS_ERROR +} mt_param_set_status; + +#define MT_PARAM_VALUE_NAME_LEN 64 +struct mtparamset { + char value_name[MT_PARAM_VALUE_NAME_LEN]; + mt_param_set_type value_type; + int value_len; + union mt_param_value value; + mt_param_set_status status; + char error_str[128]; +}; + +#define MT_PARAM_ROOT_NAME "mtparamget" +#define MT_PROTECTION_NAME "protection" + +/* + * Set a list of parameters. + */ +struct mtsetlist { + int num_params; + int param_len; + struct mtparamset *params; +}; + +/* + * Constants for mt_type byte. These are the same + * for controllers compatible with the types listed. + */ +#define MT_ISTS 0x01 /* TS-11 */ +#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ +#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ +#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ +#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ +#define MT_ISCPC 0x06 /* SUN */ +#define MT_ISAR 0x07 /* SUN */ +#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ +#define MT_ISCY 0x09 /* CCI Cipher */ +#define MT_ISCT 0x0a /* HP 1/4 tape */ +#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */ +#define MT_ISEXABYTE 0x0c /* Exabyte */ +#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */ +#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */ +#define MT_ISVIPER1 0x0e /* Archive Viper-150 */ +#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */ +#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */ +#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */ +#define MT_ISTK50 0x12 /* DEC SCSI TK50 */ +#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */ + +/* mag tape io control commands */ +#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ +#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ +/* these two do not appear to be used anywhere */ +#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */ +#define MTIOCEEOT _IO('m', 4) /* enable EOT error */ +/* + * When more SCSI-3 SSC (streaming device) devices are out there + * that support the full 32 byte type 2 structure, we'll have to + * rethink these ioctls to support all the entities they haul into + * the picture (64 bit blocks, logical file record numbers, etc..). + */ +#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */ +#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */ +#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */ +#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */ +#define MTIOCERRSTAT _IOR('m', 7, union mterrstat) /* get tape errors */ + +/* + * Set EOT model- argument is number of filemarks to end a tape with. + * Note that not all possible values will be accepted. + */ +#define MTIOCSETEOTMODEL _IOW('m', 8, u_int32_t) +/* Get current EOT model */ +#define MTIOCGETEOTMODEL _IOR('m', 8, u_int32_t) + +#define MTIOCRBLIM _IOR('m', 9, struct mtrblim) /* get block limits */ +#define MTIOCEXTLOCATE _IOW('m', 10, struct mtlocate) /* seek to position */ +#define MTIOCEXTGET _IOWR('m', 11, struct mtextget) /* get tape status */ +#define MTIOCPARAMGET _IOWR('m', 12, struct mtextget) /* get tape params */ +#define MTIOCPARAMSET _IOWR('m', 13, struct mtparamset) /* set tape params */ +#define MTIOCSETLIST _IOWR('m', 14, struct mtsetlist) /* set N params */ + +#ifndef _KERNEL +#define DEFTAPE "/dev/nsa0" +#endif + +#endif /* !_SYS_MTIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/mutex.h b/lib/libc/include/any-freebsd-any/sys/mutex.h new file mode 100644 index 000000000000..d4c9d1cbc815 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/mutex.h @@ -0,0 +1,556 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $ + * $FreeBSD$ + */ + +#ifndef _SYS_MUTEX_H_ +#define _SYS_MUTEX_H_ + +#include +#include +#include + +#ifdef _KERNEL +#include +#include +#include +#include +#include + +/* + * Mutex types and options passed to mtx_init(). MTX_QUIET and MTX_DUPOK + * can also be passed in. + */ +#define MTX_DEF 0x00000000 /* DEFAULT (sleep) lock */ +#define MTX_SPIN 0x00000001 /* Spin lock (disables interrupts) */ +#define MTX_RECURSE 0x00000004 /* Option: lock allowed to recurse */ +#define MTX_NOWITNESS 0x00000008 /* Don't do any witness checking. */ +#define MTX_NOPROFILE 0x00000020 /* Don't profile this lock */ +#define MTX_NEW 0x00000040 /* Don't check for double-init */ + +/* + * Option flags passed to certain lock/unlock routines, through the use + * of corresponding mtx_{lock,unlock}_flags() interface macros. + */ +#define MTX_QUIET LOP_QUIET /* Don't log a mutex event */ +#define MTX_DUPOK LOP_DUPOK /* Don't log a duplicate acquire */ + +/* + * State bits kept in mutex->mtx_lock, for the DEFAULT lock type. None of this, + * with the exception of MTX_UNOWNED, applies to spin locks. + */ +#define MTX_UNOWNED 0x00000000 /* Cookie for free mutex */ +#define MTX_RECURSED 0x00000001 /* lock recursed (for MTX_DEF only) */ +#define MTX_CONTESTED 0x00000002 /* lock contested (for MTX_DEF only) */ +#define MTX_DESTROYED 0x00000004 /* lock destroyed */ +#define MTX_FLAGMASK (MTX_RECURSED | MTX_CONTESTED | MTX_DESTROYED) + +/* + * Prototypes + * + * NOTE: Functions prepended with `_' (underscore) are exported to other parts + * of the kernel via macros, thus allowing us to use the cpp LOCK_FILE + * and LOCK_LINE or for hiding the lock cookie crunching to the + * consumers. These functions should not be called directly by any + * code using the API. Their macros cover their functionality. + * Functions with a `_' suffix are the entrypoint for the common + * KPI covering both compat shims and fast path case. These can be + * used by consumers willing to pass options, file and line + * informations, in an option-independent way. + * + * [See below for descriptions] + * + */ +void _mtx_init(volatile uintptr_t *c, const char *name, const char *type, + int opts); +void _mtx_destroy(volatile uintptr_t *c); +void mtx_sysinit(void *arg); +int _mtx_trylock_flags_int(struct mtx *m, int opts LOCK_FILE_LINE_ARG_DEF); +int _mtx_trylock_flags_(volatile uintptr_t *c, int opts, const char *file, + int line); +void mutex_init(void); +#if LOCK_DEBUG > 0 +void __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, int opts, + const char *file, int line); +void __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v, int opts, + const char *file, int line); +#else +void __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v); +void __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v); +#endif + +#ifdef SMP +#if LOCK_DEBUG > 0 +void _mtx_lock_spin_cookie(volatile uintptr_t *c, uintptr_t v, int opts, + const char *file, int line); +#else +void _mtx_lock_spin_cookie(volatile uintptr_t *c, uintptr_t v); +#endif +#endif +void __mtx_lock_flags(volatile uintptr_t *c, int opts, const char *file, + int line); +void __mtx_unlock_flags(volatile uintptr_t *c, int opts, const char *file, + int line); +void __mtx_lock_spin_flags(volatile uintptr_t *c, int opts, const char *file, + int line); +int __mtx_trylock_spin_flags(volatile uintptr_t *c, int opts, + const char *file, int line); +void __mtx_unlock_spin_flags(volatile uintptr_t *c, int opts, + const char *file, int line); +void mtx_spin_wait_unlocked(struct mtx *m); + +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void __mtx_assert(const volatile uintptr_t *c, int what, const char *file, + int line); +#endif +void thread_lock_flags_(struct thread *, int, const char *, int); +#if LOCK_DEBUG > 0 +void _thread_lock(struct thread *td, int opts, const char *file, int line); +#else +void _thread_lock(struct thread *); +#endif + +#if defined(LOCK_PROFILING) || (defined(KLD_MODULE) && !defined(KLD_TIED)) +#define thread_lock(tdp) \ + thread_lock_flags_((tdp), 0, __FILE__, __LINE__) +#elif LOCK_DEBUG > 0 +#define thread_lock(tdp) \ + _thread_lock((tdp), 0, __FILE__, __LINE__) +#else +#define thread_lock(tdp) \ + _thread_lock((tdp)) +#endif + +#if LOCK_DEBUG > 0 +#define thread_lock_flags(tdp, opt) \ + thread_lock_flags_((tdp), (opt), __FILE__, __LINE__) +#else +#define thread_lock_flags(tdp, opt) \ + _thread_lock(tdp) +#endif + +#define thread_unlock(tdp) \ + mtx_unlock_spin((tdp)->td_lock) + +/* + * Top-level macros to provide lock cookie once the actual mtx is passed. + * They will also prevent passing a malformed object to the mtx KPI by + * failing compilation as the mtx_lock reserved member will not be found. + */ +#define mtx_init(m, n, t, o) \ + _mtx_init(&(m)->mtx_lock, n, t, o) +#define mtx_destroy(m) \ + _mtx_destroy(&(m)->mtx_lock) +#define mtx_trylock_flags_(m, o, f, l) \ + _mtx_trylock_flags_(&(m)->mtx_lock, o, f, l) +#if LOCK_DEBUG > 0 +#define _mtx_lock_sleep(m, v, o, f, l) \ + __mtx_lock_sleep(&(m)->mtx_lock, v, o, f, l) +#define _mtx_unlock_sleep(m, v, o, f, l) \ + __mtx_unlock_sleep(&(m)->mtx_lock, v, o, f, l) +#else +#define _mtx_lock_sleep(m, v, o, f, l) \ + __mtx_lock_sleep(&(m)->mtx_lock, v) +#define _mtx_unlock_sleep(m, v, o, f, l) \ + __mtx_unlock_sleep(&(m)->mtx_lock, v) +#endif +#ifdef SMP +#if LOCK_DEBUG > 0 +#define _mtx_lock_spin(m, v, o, f, l) \ + _mtx_lock_spin_cookie(&(m)->mtx_lock, v, o, f, l) +#else +#define _mtx_lock_spin(m, v, o, f, l) \ + _mtx_lock_spin_cookie(&(m)->mtx_lock, v) +#endif +#endif +#define _mtx_lock_flags(m, o, f, l) \ + __mtx_lock_flags(&(m)->mtx_lock, o, f, l) +#define _mtx_unlock_flags(m, o, f, l) \ + __mtx_unlock_flags(&(m)->mtx_lock, o, f, l) +#define _mtx_lock_spin_flags(m, o, f, l) \ + __mtx_lock_spin_flags(&(m)->mtx_lock, o, f, l) +#define _mtx_trylock_spin_flags(m, o, f, l) \ + __mtx_trylock_spin_flags(&(m)->mtx_lock, o, f, l) +#define _mtx_unlock_spin_flags(m, o, f, l) \ + __mtx_unlock_spin_flags(&(m)->mtx_lock, o, f, l) +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define _mtx_assert(m, w, f, l) \ + __mtx_assert(&(m)->mtx_lock, w, f, l) +#endif + +#define mtx_recurse lock_object.lo_data + +/* Very simple operations on mtx_lock. */ + +/* Try to obtain mtx_lock once. */ +#define _mtx_obtain_lock(mp, tid) \ + atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid)) + +#define _mtx_obtain_lock_fetch(mp, vp, tid) \ + atomic_fcmpset_acq_ptr(&(mp)->mtx_lock, vp, (tid)) + +/* Try to release mtx_lock if it is unrecursed and uncontested. */ +#define _mtx_release_lock(mp, tid) \ + atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED) + +/* Release mtx_lock quickly, assuming we own it. */ +#define _mtx_release_lock_quick(mp) \ + atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED) + +#define _mtx_release_lock_fetch(mp, vp) \ + atomic_fcmpset_rel_ptr(&(mp)->mtx_lock, (vp), MTX_UNOWNED) + +/* + * Full lock operations that are suitable to be inlined in non-debug + * kernels. If the lock cannot be acquired or released trivially then + * the work is deferred to another function. + */ + +/* Lock a normal mutex. */ +#define __mtx_lock(mp, tid, opts, file, line) do { \ + uintptr_t _tid = (uintptr_t)(tid); \ + uintptr_t _v = MTX_UNOWNED; \ + \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(adaptive__acquire) ||\ + !_mtx_obtain_lock_fetch((mp), &_v, _tid))) \ + _mtx_lock_sleep((mp), _v, (opts), (file), (line)); \ +} while (0) + +/* + * Lock a spin mutex. For spinlocks, we handle recursion inline (it + * turns out that function calls can be significantly expensive on + * some architectures). Since spin locks are not _too_ common, + * inlining this code is not too big a deal. + */ +#ifdef SMP +#define __mtx_lock_spin(mp, tid, opts, file, line) do { \ + uintptr_t _tid = (uintptr_t)(tid); \ + uintptr_t _v = MTX_UNOWNED; \ + \ + spinlock_enter(); \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(spin__acquire) || \ + !_mtx_obtain_lock_fetch((mp), &_v, _tid))) \ + _mtx_lock_spin((mp), _v, (opts), (file), (line)); \ +} while (0) +#define __mtx_trylock_spin(mp, tid, opts, file, line) __extension__ ({ \ + uintptr_t _tid = (uintptr_t)(tid); \ + int _ret; \ + \ + spinlock_enter(); \ + if (((mp)->mtx_lock != MTX_UNOWNED || !_mtx_obtain_lock((mp), _tid))) {\ + spinlock_exit(); \ + _ret = 0; \ + } else { \ + LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(spin__acquire, \ + mp, 0, 0, file, line); \ + _ret = 1; \ + } \ + _ret; \ +}) +#else /* SMP */ +#define __mtx_lock_spin(mp, tid, opts, file, line) do { \ + uintptr_t _tid = (uintptr_t)(tid); \ + \ + spinlock_enter(); \ + if ((mp)->mtx_lock == _tid) \ + (mp)->mtx_recurse++; \ + else { \ + KASSERT((mp)->mtx_lock == MTX_UNOWNED, ("corrupt spinlock")); \ + (mp)->mtx_lock = _tid; \ + } \ +} while (0) +#define __mtx_trylock_spin(mp, tid, opts, file, line) __extension__ ({ \ + uintptr_t _tid = (uintptr_t)(tid); \ + int _ret; \ + \ + spinlock_enter(); \ + if ((mp)->mtx_lock != MTX_UNOWNED) { \ + spinlock_exit(); \ + _ret = 0; \ + } else { \ + (mp)->mtx_lock = _tid; \ + _ret = 1; \ + } \ + _ret; \ +}) +#endif /* SMP */ + +/* Unlock a normal mutex. */ +#define __mtx_unlock(mp, tid, opts, file, line) do { \ + uintptr_t _v = (uintptr_t)(tid); \ + \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(adaptive__release) ||\ + !_mtx_release_lock_fetch((mp), &_v))) \ + _mtx_unlock_sleep((mp), _v, (opts), (file), (line)); \ +} while (0) + +/* + * Unlock a spin mutex. For spinlocks, we can handle everything + * inline, as it's pretty simple and a function call would be too + * expensive (at least on some architectures). Since spin locks are + * not _too_ common, inlining this code is not too big a deal. + * + * Since we always perform a spinlock_enter() when attempting to acquire a + * spin lock, we need to always perform a matching spinlock_exit() when + * releasing a spin lock. This includes the recursion cases. + */ +#ifdef SMP +#define __mtx_unlock_spin(mp) do { \ + if (mtx_recursed((mp))) \ + (mp)->mtx_recurse--; \ + else { \ + LOCKSTAT_PROFILE_RELEASE_LOCK(spin__release, mp); \ + _mtx_release_lock_quick((mp)); \ + } \ + spinlock_exit(); \ +} while (0) +#else /* SMP */ +#define __mtx_unlock_spin(mp) do { \ + if (mtx_recursed((mp))) \ + (mp)->mtx_recurse--; \ + else { \ + LOCKSTAT_PROFILE_RELEASE_LOCK(spin__release, mp); \ + (mp)->mtx_lock = MTX_UNOWNED; \ + } \ + spinlock_exit(); \ +} while (0) +#endif /* SMP */ + +/* + * Exported lock manipulation interface. + * + * mtx_lock(m) locks MTX_DEF mutex `m' + * + * mtx_lock_spin(m) locks MTX_SPIN mutex `m' + * + * mtx_unlock(m) unlocks MTX_DEF mutex `m' + * + * mtx_unlock_spin(m) unlocks MTX_SPIN mutex `m' + * + * mtx_lock_spin_flags(m, opts) and mtx_lock_flags(m, opts) locks mutex `m' + * and passes option flags `opts' to the "hard" function, if required. + * With these routines, it is possible to pass flags such as MTX_QUIET + * to the appropriate lock manipulation routines. + * + * mtx_trylock(m) attempts to acquire MTX_DEF mutex `m' but doesn't sleep if + * it cannot. Rather, it returns 0 on failure and non-zero on success. + * It does NOT handle recursion as we assume that if a caller is properly + * using this part of the interface, he will know that the lock in question + * is _not_ recursed. + * + * mtx_trylock_flags(m, opts) is used the same way as mtx_trylock() but accepts + * relevant option flags `opts.' + * + * mtx_trylock_spin(m) attempts to acquire MTX_SPIN mutex `m' but doesn't + * spin if it cannot. Rather, it returns 0 on failure and non-zero on + * success. It always returns failure for recursed lock attempts. + * + * mtx_initialized(m) returns non-zero if the lock `m' has been initialized. + * + * mtx_owned(m) returns non-zero if the current thread owns the lock `m' + * + * mtx_recursed(m) returns non-zero if the lock `m' is presently recursed. + */ +#define mtx_lock(m) mtx_lock_flags((m), 0) +#define mtx_lock_spin(m) mtx_lock_spin_flags((m), 0) +#define mtx_trylock(m) mtx_trylock_flags((m), 0) +#define mtx_trylock_spin(m) mtx_trylock_spin_flags((m), 0) +#define mtx_unlock(m) mtx_unlock_flags((m), 0) +#define mtx_unlock_spin(m) mtx_unlock_spin_flags((m), 0) + +struct mtx_pool; + +struct mtx_pool *mtx_pool_create(const char *mtx_name, int pool_size, int opts); +void mtx_pool_destroy(struct mtx_pool **poolp); +struct mtx *mtx_pool_find(struct mtx_pool *pool, void *ptr); +struct mtx *mtx_pool_alloc(struct mtx_pool *pool); +#define mtx_pool_lock(pool, ptr) \ + mtx_lock(mtx_pool_find((pool), (ptr))) +#define mtx_pool_lock_spin(pool, ptr) \ + mtx_lock_spin(mtx_pool_find((pool), (ptr))) +#define mtx_pool_unlock(pool, ptr) \ + mtx_unlock(mtx_pool_find((pool), (ptr))) +#define mtx_pool_unlock_spin(pool, ptr) \ + mtx_unlock_spin(mtx_pool_find((pool), (ptr))) + +/* + * mtxpool_sleep is a general purpose pool of sleep mutexes. + */ +extern struct mtx_pool *mtxpool_sleep; + +#ifndef LOCK_DEBUG +#error LOCK_DEBUG not defined, include before +#endif +#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE) +#define mtx_lock_flags_(m, opts, file, line) \ + _mtx_lock_flags((m), (opts), (file), (line)) +#define mtx_unlock_flags_(m, opts, file, line) \ + _mtx_unlock_flags((m), (opts), (file), (line)) +#define mtx_lock_spin_flags_(m, opts, file, line) \ + _mtx_lock_spin_flags((m), (opts), (file), (line)) +#define mtx_trylock_spin_flags_(m, opts, file, line) \ + _mtx_trylock_spin_flags((m), (opts), (file), (line)) +#define mtx_unlock_spin_flags_(m, opts, file, line) \ + _mtx_unlock_spin_flags((m), (opts), (file), (line)) +#else /* LOCK_DEBUG == 0 && !MUTEX_NOINLINE */ +#define mtx_lock_flags_(m, opts, file, line) \ + __mtx_lock((m), curthread, (opts), (file), (line)) +#define mtx_unlock_flags_(m, opts, file, line) \ + __mtx_unlock((m), curthread, (opts), (file), (line)) +#define mtx_lock_spin_flags_(m, opts, file, line) \ + __mtx_lock_spin((m), curthread, (opts), (file), (line)) +#define mtx_trylock_spin_flags_(m, opts, file, line) \ + __mtx_trylock_spin((m), curthread, (opts), (file), (line)) +#define mtx_unlock_spin_flags_(m, opts, file, line) \ + __mtx_unlock_spin((m)) +#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */ + +#ifdef INVARIANTS +#define mtx_assert_(m, what, file, line) \ + _mtx_assert((m), (what), (file), (line)) + +#define GIANT_REQUIRED mtx_assert_(&Giant, MA_OWNED, __FILE__, __LINE__) + +#else /* INVARIANTS */ +#define mtx_assert_(m, what, file, line) (void)0 +#define GIANT_REQUIRED +#endif /* INVARIANTS */ + +#define mtx_lock_flags(m, opts) \ + mtx_lock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_flags(m, opts) \ + mtx_unlock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_lock_spin_flags(m, opts) \ + mtx_lock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_spin_flags(m, opts) \ + mtx_unlock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_trylock_flags(m, opts) \ + mtx_trylock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_trylock_spin_flags(m, opts) \ + mtx_trylock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_assert(m, what) \ + mtx_assert_((m), (what), __FILE__, __LINE__) + +#define mtx_sleep(chan, mtx, pri, wmesg, timo) \ + _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), \ + tick_sbt * (timo), 0, C_HARDCLOCK) + +#define MTX_READ_VALUE(m) ((m)->mtx_lock) + +#define mtx_initialized(m) lock_initialized(&(m)->lock_object) + +#define lv_mtx_owner(v) ((struct thread *)((v) & ~MTX_FLAGMASK)) + +#define mtx_owner(m) lv_mtx_owner(MTX_READ_VALUE(m)) + +#define mtx_owned(m) (mtx_owner(m) == curthread) + +#define mtx_recursed(m) ((m)->mtx_recurse != 0) + +#define mtx_name(m) ((m)->lock_object.lo_name) + +/* + * Global locks. + */ +extern struct mtx Giant; +extern struct mtx blocked_lock; + +/* + * Giant lock manipulation and clean exit macros. + * Used to replace return with an exit Giant and return. + * + * Note that DROP_GIANT*() needs to be paired with PICKUP_GIANT() + * The #ifndef is to allow lint-like tools to redefine DROP_GIANT. + */ +#ifndef DROP_GIANT +#define DROP_GIANT() \ +do { \ + int _giantcnt = 0; \ + WITNESS_SAVE_DECL(Giant); \ + \ + if (mtx_owned(&Giant)) { \ + WITNESS_SAVE(&Giant.lock_object, Giant); \ + for (_giantcnt = 0; mtx_owned(&Giant) && \ + !SCHEDULER_STOPPED(); _giantcnt++) \ + mtx_unlock(&Giant); \ + } + +#define PICKUP_GIANT() \ + PARTIAL_PICKUP_GIANT(); \ +} while (0) + +#define PARTIAL_PICKUP_GIANT() \ + mtx_assert(&Giant, MA_NOTOWNED); \ + if (_giantcnt > 0) { \ + while (_giantcnt--) \ + mtx_lock(&Giant); \ + WITNESS_RESTORE(&Giant.lock_object, Giant); \ + } +#endif + +struct mtx_args { + void *ma_mtx; + const char *ma_desc; + int ma_opts; +}; + +#define MTX_SYSINIT(name, mtx, desc, opts) \ + static struct mtx_args name##_args = { \ + (mtx), \ + (desc), \ + (opts) \ + }; \ + SYSINIT(name##_mtx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + mtx_sysinit, &name##_args); \ + SYSUNINIT(name##_mtx_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + _mtx_destroy, __DEVOLATILE(void *, &(mtx)->mtx_lock)) + +/* + * The INVARIANTS-enabled mtx_assert() functionality. + * + * The constants need to be defined for INVARIANT_SUPPORT infrastructure + * support as _mtx_assert() itself uses them and the latter implies that + * _mtx_assert() must build. + */ +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define MA_OWNED LA_XLOCKED +#define MA_NOTOWNED LA_UNLOCKED +#define MA_RECURSED LA_RECURSED +#define MA_NOTRECURSED LA_NOTRECURSED +#endif + +/* + * Common lock type names. + */ +#define MTX_NETWORK_LOCK "network driver" + +#endif /* _KERNEL */ +#endif /* _SYS_MUTEX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/namei.h b/lib/libc/include/any-freebsd-any/sys/namei.h new file mode 100644 index 000000000000..53814117725e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/namei.h @@ -0,0 +1,226 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1985, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)namei.h 8.5 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_NAMEI_H_ +#define _SYS_NAMEI_H_ + +#include +#include +#include +#include + +struct componentname { + /* + * Arguments to lookup. + */ + u_long cn_nameiop; /* namei operation */ + u_int64_t cn_flags; /* flags to namei */ + struct thread *cn_thread;/* thread requesting lookup */ + struct ucred *cn_cred; /* credentials */ + int cn_lkflags; /* Lock flags LK_EXCLUSIVE or LK_SHARED */ + /* + * Shared between lookup and commit routines. + */ + char *cn_pnbuf; /* pathname buffer */ + char *cn_nameptr; /* pointer to looked up name */ + long cn_namelen; /* length of looked up component */ +}; + +struct nameicap_tracker; +TAILQ_HEAD(nameicap_tracker_head, nameicap_tracker); + +/* + * Encapsulation of namei parameters. + */ +struct nameidata { + /* + * Arguments to namei/lookup. + */ + const char *ni_dirp; /* pathname pointer */ + enum uio_seg ni_segflg; /* location of pathname */ + cap_rights_t ni_rightsneeded; /* rights required to look up vnode */ + /* + * Arguments to lookup. + */ + struct vnode *ni_startdir; /* starting directory */ + struct vnode *ni_rootdir; /* logical root directory */ + struct vnode *ni_topdir; /* logical top directory */ + int ni_dirfd; /* starting directory for *at functions */ + int ni_lcf; /* local call flags */ + /* + * Results: returned from namei + */ + struct filecaps ni_filecaps; /* rights the *at base has */ + /* + * Results: returned from/manipulated by lookup + */ + struct vnode *ni_vp; /* vnode of result */ + struct vnode *ni_dvp; /* vnode of intermediate directory */ + /* + * Results: flags returned from namei + */ + u_int ni_resflags; + /* + * Shared between namei and lookup/commit routines. + */ + size_t ni_pathlen; /* remaining chars in path */ + char *ni_next; /* next location in pathname */ + u_int ni_loopcnt; /* count of symlinks encountered */ + /* + * Lookup parameters: this structure describes the subset of + * information from the nameidata structure that is passed + * through the VOP interface. + */ + struct componentname ni_cnd; + struct nameicap_tracker_head ni_cap_tracker; +}; + +#ifdef _KERNEL +/* + * namei operations + */ +#define LOOKUP 0 /* perform name lookup only */ +#define CREATE 1 /* setup for file creation */ +#define DELETE 2 /* setup for file deletion */ +#define RENAME 3 /* setup for file renaming */ +#define OPMASK 3 /* mask for operation */ +/* + * namei operational modifier flags, stored in ni_cnd.flags + */ +#define LOCKLEAF 0x0004 /* lock vnode on return */ +#define LOCKPARENT 0x0008 /* want parent vnode returned locked */ +#define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ +#define NOCACHE 0x0020 /* name must not be left in cache */ +#define FOLLOW 0x0040 /* follow symbolic links */ +#define LOCKSHARED 0x0100 /* Shared lock leaf */ +#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ +#define MODMASK 0x01fc /* mask of operational modifiers */ +/* + * Namei parameter descriptors. + * + * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. + * If the caller of namei sets the flag (for example execve wants to + * know the name of the program that is being executed), then it must + * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must + * be freed by either the commit routine or the VOP_ABORT routine. + * SAVESTART is set only by the callers of namei. It implies SAVENAME + * plus the addition of saving the parent directory that contains the + * name in ni_startdir. It allows repeated calls to lookup for the + * name being sought. The caller is responsible for releasing the + * buffer and for vrele'ing ni_startdir. + */ +#define RDONLY 0x00000200 /* lookup with read-only semantics */ +#define HASBUF 0x00000400 /* has allocated pathname buffer */ +#define SAVENAME 0x00000800 /* save pathname buffer */ +#define SAVESTART 0x00001000 /* save starting directory */ +#define ISDOTDOT 0x00002000 /* current component name is .. */ +#define MAKEENTRY 0x00004000 /* entry is to be added to name cache */ +#define ISLASTCN 0x00008000 /* this is last component of pathname */ +#define ISSYMLINK 0x00010000 /* symlink needs interpretation */ +#define ISWHITEOUT 0x00020000 /* found whiteout */ +#define DOWHITEOUT 0x00040000 /* do whiteouts */ +#define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */ +#define ISUNICODE 0x00100000 /* current component name is unicode*/ +#define ISOPEN 0x00200000 /* caller is opening; return a real vnode. */ +#define NOCROSSMOUNT 0x00400000 /* do not cross mount points */ +#define NOMACCHECK 0x00800000 /* do not perform MAC checks */ +#define AUDITVNODE1 0x04000000 /* audit the looked up vnode information */ +#define AUDITVNODE2 0x08000000 /* audit the looked up vnode information */ +#define TRAILINGSLASH 0x10000000 /* path ended in a slash */ +#define NOCAPCHECK 0x20000000 /* do not perform capability checks */ +#define NOEXECCHECK 0x40000000 /* do not perform exec check on dir */ +#define PARAMASK 0x7ffffe00 /* mask of parameter descriptors */ + +/* + * Namei results flags + */ +#define NIRES_ABS 0x00000001 /* Path was absolute */ + +/* + * Flags in ni_lcf, valid for the duration of the namei call. + */ +#define NI_LCF_STRICTRELATIVE 0x0001 /* relative lookup only */ +#define NI_LCF_CAP_DOTDOT 0x0002 /* ".." in strictrelative case */ + +/* + * Initialization of a nameidata structure. + */ +#define NDINIT(ndp, op, flags, segflg, namep, td) \ + NDINIT_ALL(ndp, op, flags, segflg, namep, AT_FDCWD, NULL, 0, td) +#define NDINIT_AT(ndp, op, flags, segflg, namep, dirfd, td) \ + NDINIT_ALL(ndp, op, flags, segflg, namep, dirfd, NULL, 0, td) +#define NDINIT_ATRIGHTS(ndp, op, flags, segflg, namep, dirfd, rightsp, td) \ + NDINIT_ALL(ndp, op, flags, segflg, namep, dirfd, NULL, rightsp, td) +#define NDINIT_ATVP(ndp, op, flags, segflg, namep, vp, td) \ + NDINIT_ALL(ndp, op, flags, segflg, namep, AT_FDCWD, vp, 0, td) + +void NDINIT_ALL(struct nameidata *ndp, u_long op, u_long flags, + enum uio_seg segflg, const char *namep, int dirfd, struct vnode *startdir, + cap_rights_t *rightsp, struct thread *td); + +#define NDF_NO_DVP_RELE 0x00000001 +#define NDF_NO_DVP_UNLOCK 0x00000002 +#define NDF_NO_DVP_PUT 0x00000003 +#define NDF_NO_VP_RELE 0x00000004 +#define NDF_NO_VP_UNLOCK 0x00000008 +#define NDF_NO_VP_PUT 0x0000000c +#define NDF_NO_STARTDIR_RELE 0x00000010 +#define NDF_NO_FREE_PNBUF 0x00000020 +#define NDF_ONLY_PNBUF (~NDF_NO_FREE_PNBUF) + +void NDFREE(struct nameidata *, const u_int); + +int namei(struct nameidata *ndp); +int lookup(struct nameidata *ndp); +int relookup(struct vnode *dvp, struct vnode **vpp, + struct componentname *cnp); +#endif + +/* + * Stats on usefulness of namei caches. + */ +struct nchstats { + long ncs_goodhits; /* hits that we can really use */ + long ncs_neghits; /* negative hits that we can use */ + long ncs_badhits; /* hits we must drop */ + long ncs_falsehits; /* hits with id mismatch */ + long ncs_miss; /* misses */ + long ncs_long; /* long names that ignore cache */ + long ncs_pass2; /* names found with passes == 2 */ + long ncs_2passes; /* number of times we attempt it */ +}; + +extern struct nchstats nchstats; + +#endif /* !_SYS_NAMEI_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/nlist_aout.h b/lib/libc/include/any-freebsd-any/sys/nlist_aout.h new file mode 100644 index 000000000000..0e1fa284de1e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/nlist_aout.h @@ -0,0 +1,113 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD$ + */ + +#ifndef _SYS_NLIST_AOUT_H_ +#define _SYS_NLIST_AOUT_H_ + +/* + * Symbol table entries in a.out files. + */ + +/* + * Layout of each symbol. The "#ifdef _AOUT_INCLUDE_" is so that + * programs including nlist.h can initialize nlist structures + * statically. + */ +struct nlist { +#ifdef _AOUT_INCLUDE_ + union { + const char *n_name; /* symbol name (in memory) */ + long n_strx; /* file string table offset (on disk) */ + } n_un; +#else + const char *n_name; /* symbol name (in memory) */ +#endif + unsigned char n_type; /* type defines */ + char n_other; /* ".type" and binding information */ + short n_desc; /* used by stab entries */ + unsigned long n_value; /* address/value of the symbol */ +}; + +#define n_hash n_desc /* used internally by ld(1); XXX */ + +/* + * Defines for n_type. + */ +#define N_UNDF 0x00 /* undefined */ +#define N_ABS 0x02 /* absolute address */ +#define N_TEXT 0x04 /* text segment */ +#define N_DATA 0x06 /* data segment */ +#define N_BSS 0x08 /* bss segment */ +#define N_INDR 0x0a /* alias definition */ +#define N_SIZE 0x0c /* pseudo type, defines a symbol's size */ +#define N_COMM 0x12 /* common reference */ +/* GNU extensions */ +#define N_SETA 0x14 /* Absolute set element symbol */ +#define N_SETT 0x16 /* Text set element symbol */ +#define N_SETD 0x18 /* Data set element symbol */ +#define N_SETB 0x1a /* Bss set element symbol */ +#define N_SETV 0x1c /* Pointer to set vector in data area. */ +/* end GNU extensions */ +#define N_FN 0x1e /* file name (N_EXT on) */ +#define N_WARN 0x1e /* warning message (N_EXT off) */ + +#define N_EXT 0x01 /* external (global) bit, OR'ed in */ +#define N_TYPE 0x1e /* mask for all the type bits */ +#define N_STAB 0xe0 /* mask for debugger symbols -- stab(5) */ + +/* + * Defines for n_other. It contains the ".type" (AUX) field in the least + * significant 4 bits, and the binding (for weak symbols) in the most + * significant 4 bits. + */ +#define N_AUX(p) ((p)->n_other & 0xf) +#define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf) +#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf)) + +#define AUX_OBJECT 1 /* data object */ +#define AUX_FUNC 2 /* function */ + +/*#define BIND_LOCAL 0 not used */ +/*#define BIND_GLOBAL 1 not used */ +#define BIND_WEAK 2 /* weak binding */ + +#define N_FORMAT "%08x" /* namelist value format; XXX */ + +#endif /* !_SYS_NLIST_AOUT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/nv.h b/lib/libc/include/any-freebsd-any/sys/nv.h new file mode 100644 index 000000000000..80fb877721f0 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/nv.h @@ -0,0 +1,256 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2009-2013 The FreeBSD Foundation + * Copyright (c) 2013-2015 Mariusz Zaborski + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NV_H_ +#define _NV_H_ + +#include + +#ifndef _KERNEL +#include +#include +#include +#include +#endif + +#ifndef _NVLIST_T_DECLARED +#define _NVLIST_T_DECLARED +struct nvlist; + +typedef struct nvlist nvlist_t; +#endif + +#define NV_NAME_MAX 2048 + +#define NV_TYPE_NONE 0 + +#define NV_TYPE_NULL 1 +#define NV_TYPE_BOOL 2 +#define NV_TYPE_NUMBER 3 +#define NV_TYPE_STRING 4 +#define NV_TYPE_NVLIST 5 +#define NV_TYPE_DESCRIPTOR 6 +#define NV_TYPE_BINARY 7 +#define NV_TYPE_BOOL_ARRAY 8 +#define NV_TYPE_NUMBER_ARRAY 9 +#define NV_TYPE_STRING_ARRAY 10 +#define NV_TYPE_NVLIST_ARRAY 11 +#define NV_TYPE_DESCRIPTOR_ARRAY 12 + +/* + * Perform case-insensitive lookups of provided names. + */ +#define NV_FLAG_IGNORE_CASE 0x01 +/* + * Names don't have to be unique. + */ +#define NV_FLAG_NO_UNIQUE 0x02 + +#if defined(_KERNEL) && defined(MALLOC_DECLARE) +MALLOC_DECLARE(M_NVLIST); +#endif + +__BEGIN_DECLS + +nvlist_t *nvlist_create(int flags); +void nvlist_destroy(nvlist_t *nvl); +int nvlist_error(const nvlist_t *nvl); +bool nvlist_empty(const nvlist_t *nvl); +int nvlist_flags(const nvlist_t *nvl); +void nvlist_set_error(nvlist_t *nvl, int error); + +nvlist_t *nvlist_clone(const nvlist_t *nvl); + +#ifndef _KERNEL +void nvlist_dump(const nvlist_t *nvl, int fd); +void nvlist_fdump(const nvlist_t *nvl, FILE *fp); +#endif + +size_t nvlist_size(const nvlist_t *nvl); +void *nvlist_pack(const nvlist_t *nvl, size_t *sizep); +nvlist_t *nvlist_unpack(const void *buf, size_t size, int flags); + +int nvlist_send(int sock, const nvlist_t *nvl); +nvlist_t *nvlist_recv(int sock, int flags); +nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl, int flags); + +const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep); + +const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep); + +const nvlist_t *nvlist_get_array_next(const nvlist_t *nvl); +bool nvlist_in_array(const nvlist_t *nvl); + +const nvlist_t *nvlist_get_pararr(const nvlist_t *nvl, void **cookiep); + +/* + * The nvlist_exists functions check if the given name (optionally of the given + * type) exists on nvlist. + */ + +bool nvlist_exists(const nvlist_t *nvl, const char *name); +bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type); + +bool nvlist_exists_null(const nvlist_t *nvl, const char *name); +bool nvlist_exists_bool(const nvlist_t *nvl, const char *name); +bool nvlist_exists_number(const nvlist_t *nvl, const char *name); +bool nvlist_exists_string(const nvlist_t *nvl, const char *name); +bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name); +bool nvlist_exists_binary(const nvlist_t *nvl, const char *name); +bool nvlist_exists_bool_array(const nvlist_t *nvl, const char *name); +bool nvlist_exists_number_array(const nvlist_t *nvl, const char *name); +bool nvlist_exists_string_array(const nvlist_t *nvl, const char *name); +bool nvlist_exists_nvlist_array(const nvlist_t *nvl, const char *name); +#ifndef _KERNEL +bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name); +bool nvlist_exists_descriptor_array(const nvlist_t *nvl, const char *name); +#endif + +/* + * The nvlist_add functions add the given name/value pair. + * If a pointer is provided, nvlist_add will internally allocate memory for the + * given data (in other words it won't consume provided buffer). + */ + +void nvlist_add_null(nvlist_t *nvl, const char *name); +void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value); +void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value); +void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value); +void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4); +#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED) +void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0); +#endif +void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value); +void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size); +void nvlist_add_bool_array(nvlist_t *nvl, const char *name, const bool *value, size_t nitems); +void nvlist_add_number_array(nvlist_t *nvl, const char *name, const uint64_t *value, size_t nitems); +void nvlist_add_string_array(nvlist_t *nvl, const char *name, const char * const *value, size_t nitems); +void nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t * const *value, size_t nitems); +#ifndef _KERNEL +void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value); +void nvlist_add_descriptor_array(nvlist_t *nvl, const char *name, const int *value, size_t nitems); +#endif + +void nvlist_append_bool_array(nvlist_t *nvl, const char *name, const bool value); +void nvlist_append_number_array(nvlist_t *nvl, const char *name, const uint64_t value); +void nvlist_append_string_array(nvlist_t *nvl, const char *name, const char * const value); +void nvlist_append_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t * const value); +#ifndef _KERNEL +void nvlist_append_descriptor_array(nvlist_t *nvl, const char *name, int value); +#endif + +/* + * The nvlist_move functions add the given name/value pair. + * The functions consumes provided buffer. + */ + +void nvlist_move_string(nvlist_t *nvl, const char *name, char *value); +void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value); +void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size); +void nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value, size_t nitems); +void nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value, size_t nitems); +void nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value, size_t nitems); +void nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value, size_t nitems); +#ifndef _KERNEL +void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value); +void nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value, size_t nitems); +#endif + +/* + * The nvlist_get functions returns value associated with the given name. + * If it returns a pointer, the pointer represents internal buffer and should + * not be freed by the caller. + */ + +bool nvlist_get_bool(const nvlist_t *nvl, const char *name); +uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name); +const char *nvlist_get_string(const nvlist_t *nvl, const char *name); +const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name); +const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep); +const bool *nvlist_get_bool_array(const nvlist_t *nvl, const char *name, size_t *nitemsp); +const uint64_t *nvlist_get_number_array(const nvlist_t *nvl, const char *name, size_t *nitemsp); +const char * const *nvlist_get_string_array(const nvlist_t *nvl, const char *name, size_t *nitemsp); +const nvlist_t * const *nvlist_get_nvlist_array(const nvlist_t *nvl, const char *name, size_t *nitemsp); +#ifndef _KERNEL +int nvlist_get_descriptor(const nvlist_t *nvl, const char *name); +const int *nvlist_get_descriptor_array(const nvlist_t *nvl, const char *name, size_t *nitemsp); +#endif + +/* + * The nvlist_take functions returns value associated with the given name and + * remove the given entry from the nvlist. + * The caller is responsible for freeing received data. + */ + +bool nvlist_take_bool(nvlist_t *nvl, const char *name); +uint64_t nvlist_take_number(nvlist_t *nvl, const char *name); +char *nvlist_take_string(nvlist_t *nvl, const char *name); +nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name); +void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep); +bool *nvlist_take_bool_array(nvlist_t *nvl, const char *name, size_t *nitemsp); +uint64_t *nvlist_take_number_array(nvlist_t *nvl, const char *name, size_t *nitemsp); +char **nvlist_take_string_array(nvlist_t *nvl, const char *name, size_t *nitemsp); +nvlist_t **nvlist_take_nvlist_array(nvlist_t *nvl, const char *name, size_t *nitemsp); +#ifndef _KERNEL +int nvlist_take_descriptor(nvlist_t *nvl, const char *name); +int *nvlist_take_descriptor_array(nvlist_t *nvl, const char *name, size_t *nitemsp); +#endif + +/* + * The nvlist_free functions removes the given name/value pair from the nvlist + * and frees memory associated with it. + */ + +void nvlist_free(nvlist_t *nvl, const char *name); +void nvlist_free_type(nvlist_t *nvl, const char *name, int type); + +void nvlist_free_null(nvlist_t *nvl, const char *name); +void nvlist_free_bool(nvlist_t *nvl, const char *name); +void nvlist_free_number(nvlist_t *nvl, const char *name); +void nvlist_free_string(nvlist_t *nvl, const char *name); +void nvlist_free_nvlist(nvlist_t *nvl, const char *name); +void nvlist_free_binary(nvlist_t *nvl, const char *name); +void nvlist_free_bool_array(nvlist_t *nvl, const char *name); +void nvlist_free_number_array(nvlist_t *nvl, const char *name); +void nvlist_free_string_array(nvlist_t *nvl, const char *name); +void nvlist_free_nvlist_array(nvlist_t *nvl, const char *name); +void nvlist_free_binary_array(nvlist_t *nvl, const char *name); +#ifndef _KERNEL +void nvlist_free_descriptor(nvlist_t *nvl, const char *name); +void nvlist_free_descriptor_array(nvlist_t *nvl, const char *name); +#endif + +__END_DECLS + +#endif /* !_NV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/osd.h b/lib/libc/include/any-freebsd-any/sys/osd.h new file mode 100644 index 000000000000..a9824184c579 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/osd.h @@ -0,0 +1,112 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2007 Pawel Jakub Dawidek + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_OSD_H_ +#define _SYS_OSD_H_ + +#include + +/* + * Lock key: + * (c) container lock (e.g. jail's pr_mtx) and/or osd_object_lock + * (l) osd_list_lock + */ +struct osd { + u_int osd_nslots; /* (c) */ + void **osd_slots; /* (c) */ + LIST_ENTRY(osd) osd_next; /* (l) */ +}; + +#ifdef _KERNEL + +#define OSD_THREAD 0 +#define OSD_JAIL 1 +#define OSD_KHELP 2 + +#define OSD_FIRST OSD_THREAD +#define OSD_LAST OSD_KHELP + +typedef void (*osd_destructor_t)(void *value); +typedef int (*osd_method_t)(void *obj, void *data); + +int osd_register(u_int type, osd_destructor_t destructor, + osd_method_t *methods); +void osd_deregister(u_int type, u_int slot); + +int osd_set(u_int type, struct osd *osd, u_int slot, void *value); +void **osd_reserve(u_int slot); +int osd_set_reserved(u_int type, struct osd *osd, u_int slot, void **rsv, + void *value); +void osd_free_reserved(void **rsv); +void *osd_get(u_int type, struct osd *osd, u_int slot); +void osd_del(u_int type, struct osd *osd, u_int slot); +int osd_call(u_int type, u_int method, void *obj, void *data); + +void osd_exit(u_int type, struct osd *osd); + +#define osd_thread_register(destructor) \ + osd_register(OSD_THREAD, (destructor), NULL) +#define osd_thread_deregister(slot) \ + osd_deregister(OSD_THREAD, (slot)) +#define osd_thread_set(td, slot, value) \ + osd_set(OSD_THREAD, &(td)->td_osd, (slot), (value)) +#define osd_thread_set_reserved(td, slot, rsv, value) \ + osd_set_reserved(OSD_THREAD, &(td)->td_osd, (slot), (rsv), (value)) +#define osd_thread_get(td, slot) \ + osd_get(OSD_THREAD, &(td)->td_osd, (slot)) +#define osd_thread_del(td, slot) do { \ + KASSERT((td) == curthread, ("Not curthread.")); \ + osd_del(OSD_THREAD, &(td)->td_osd, (slot)); \ +} while (0) +#define osd_thread_call(td, method, data) \ + osd_call(OSD_THREAD, (method), (td), (data)) +#define osd_thread_exit(td) \ + osd_exit(OSD_THREAD, &(td)->td_osd) + +#define osd_jail_register(destructor, methods) \ + osd_register(OSD_JAIL, (destructor), (methods)) +#define osd_jail_deregister(slot) \ + osd_deregister(OSD_JAIL, (slot)) +#define osd_jail_set(pr, slot, value) \ + osd_set(OSD_JAIL, &(pr)->pr_osd, (slot), (value)) +#define osd_jail_set_reserved(pr, slot, rsv, value) \ + osd_set_reserved(OSD_JAIL, &(pr)->pr_osd, (slot), (rsv), (value)) +#define osd_jail_get(pr, slot) \ + osd_get(OSD_JAIL, &(pr)->pr_osd, (slot)) +#define osd_jail_del(pr, slot) \ + osd_del(OSD_JAIL, &(pr)->pr_osd, (slot)) +#define osd_jail_call(pr, method, data) \ + osd_call(OSD_JAIL, (method), (pr), (data)) +#define osd_jail_exit(pr) \ + osd_exit(OSD_JAIL, &(pr)->pr_osd) + +#endif /* _KERNEL */ + +#endif /* !_SYS_OSD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/param.h b/lib/libc/include/any-freebsd-any/sys/param.h new file mode 100644 index 000000000000..cd445326e2fe --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/param.h @@ -0,0 +1,365 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)param.h 8.3 (Berkeley) 4/4/95 + * $FreeBSD$ + */ + +#ifndef _SYS_PARAM_H_ +#define _SYS_PARAM_H_ + +#include + +#define BSD 199506 /* System version (year & month). */ +#define BSD4_3 1 +#define BSD4_4 1 + +/* + * __FreeBSD_version numbers are documented in the Porter's Handbook. + * If you bump the version for any reason, you should update the documentation + * there. + * Currently this lives here in the doc/ repository: + * + * head/en_US.ISO8859-1/books/porters-handbook/versions/chapter.xml + * + * scheme is: Rxx + * 'R' is in the range 0 to 4 if this is a release branch or + * X.0-CURRENT before releng/X.0 is created, otherwise 'R' is + * in the range 5 to 9. + */ +#undef __FreeBSD_version +#define __FreeBSD_version 1202000 /* Master, propagated to newvers */ + +/* + * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, + * which by definition is always true on FreeBSD. This macro is also defined + * on other systems that use the kernel of FreeBSD, such as GNU/kFreeBSD. + * + * It is tempting to use this macro in userland code when we want to enable + * kernel-specific routines, and in fact it's fine to do this in code that + * is part of FreeBSD itself. However, be aware that as presence of this + * macro is still not widespread (e.g. older FreeBSD versions, 3rd party + * compilers, etc), it is STRONGLY DISCOURAGED to check for this macro in + * external applications without also checking for __FreeBSD__ as an + * alternative. + */ +#undef __FreeBSD_kernel__ +#define __FreeBSD_kernel__ + +#if defined(_KERNEL) || defined(IN_RTLD) +#define P_OSREL_SIGWAIT 700000 +#define P_OSREL_SIGSEGV 700004 +#define P_OSREL_MAP_ANON 800104 +#define P_OSREL_MAP_FSTRICT 1100036 +#define P_OSREL_SHUTDOWN_ENOTCONN 1100077 +#define P_OSREL_MAP_GUARD 1200035 +#define P_OSREL_WRFSBASE 1200041 +#define P_OSREL_CK_CYLGRP 1200046 +#define P_OSREL_VMTOTAL64 1200054 + +#define P_OSREL_MAJOR(x) ((x) / 100000) +#endif + +#ifndef LOCORE +#include +#endif + +/* + * Machine-independent constants (some used in following include files). + * Redefined constants are from POSIX 1003.1 limits file. + * + * MAXCOMLEN should be >= sizeof(ac_comm) (see ) + */ +#include + +#define MAXCOMLEN 19 /* max command name remembered */ +#define MAXINTERP PATH_MAX /* max interpreter file name length */ +#define MAXLOGNAME 33 /* max login name length (incl. NUL) */ +#define MAXUPRC CHILD_MAX /* max simultaneous processes */ +#define NCARGS ARG_MAX /* max bytes for an exec function */ +#define NGROUPS (NGROUPS_MAX+1) /* max number groups */ +#define NOFILE OPEN_MAX /* max open files per process */ +#define NOGROUP 65535 /* marker for empty group set member */ +#define MAXHOSTNAMELEN 256 /* max hostname size */ +#define SPECNAMELEN 63 /* max length of devicename */ + +/* More types and definitions used throughout the kernel. */ +#ifdef _KERNEL +#include +#include +#ifndef LOCORE +#include +#include +#endif + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif +#endif + +#ifndef _KERNEL +/* Signals. */ +#include +#endif + +/* Machine type dependent parameters. */ +#include +#ifndef _KERNEL +#include +#endif + +#ifndef DEV_BSHIFT +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#endif +#define DEV_BSIZE (1<>PAGE_SHIFT) +#endif + +/* + * btodb() is messy and perhaps slow because `bytes' may be an off_t. We + * want to shift an unsigned type to avoid sign extension and we don't + * want to widen `bytes' unnecessarily. Assume that the result fits in + * a daddr_t. + */ +#ifndef btodb +#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ + (sizeof (bytes) > sizeof(long) \ + ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ + : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) +#endif + +#ifndef dbtob +#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ + ((off_t)(db) << DEV_BSHIFT) +#endif + +#define PRIMASK 0x0ff +#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ +#define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */ + +#define NZERO 0 /* default "nice" */ + +#define NBBY 8 /* number of bits in a byte */ +#define NBPW sizeof(int) /* number of bytes per word (integer) */ + +#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ + +#define NODEV (dev_t)(-1) /* non-existent device */ + +/* + * File system parameters and macros. + * + * MAXBSIZE - Filesystems are made out of blocks of at most MAXBSIZE bytes + * per block. MAXBSIZE may be made larger without effecting + * any existing filesystems as long as it does not exceed MAXPHYS, + * and may be made smaller at the risk of not being able to use + * filesystems which require a block size exceeding MAXBSIZE. + * + * MAXBCACHEBUF - Maximum size of a buffer in the buffer cache. This must + * be >= MAXBSIZE and can be set differently for different + * architectures by defining it in . + * Making this larger allows NFS to do larger reads/writes. + * + * BKVASIZE - Nominal buffer space per buffer, in bytes. BKVASIZE is the + * minimum KVM memory reservation the kernel is willing to make. + * Filesystems can of course request smaller chunks. Actual + * backing memory uses a chunk size of a page (PAGE_SIZE). + * The default value here can be overridden on a per-architecture + * basis by defining it in . + * + * If you make BKVASIZE too small you risk seriously fragmenting + * the buffer KVM map which may slow things down a bit. If you + * make it too big the kernel will not be able to optimally use + * the KVM memory reserved for the buffer cache and will wind + * up with too-few buffers. + * + * The default is 16384, roughly 2x the block size used by a + * normal UFS filesystem. + */ +#define MAXBSIZE 65536 /* must be power of 2 */ +#ifndef MAXBCACHEBUF +#define MAXBCACHEBUF MAXBSIZE /* must be a power of 2 >= MAXBSIZE */ +#endif +#ifndef BKVASIZE +#define BKVASIZE 16384 /* must be power of 2 */ +#endif +#define BKVAMASK (BKVASIZE-1) + +/* + * MAXPATHLEN defines the longest permissible path length after expanding + * symbolic links. It is used to allocate a temporary buffer from the buffer + * pool in which to do the name expansion, hence should be a power of two, + * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the + * maximum number of symbolic links that may be expanded in a path name. + * It should be set high enough to allow all legitimate uses, but halt + * infinite loops reasonably quickly. + */ +#define MAXPATHLEN PATH_MAX +#define MAXSYMLINKS 32 + +/* Bit map related macros. */ +#define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY)) +#define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY))) +#define isset(a,i) \ + (((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) +#define isclr(a,i) \ + ((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0) + +/* Macros for counting and rounding. */ +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif +#define nitems(x) (sizeof((x)) / sizeof((x)[0])) +#define rounddown(x, y) (((x)/(y))*(y)) +#define rounddown2(x, y) ((x)&(~((y)-1))) /* if y is power of two */ +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ +#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ +#define powerof2(x) ((((x)-1)&(x))==0) + +/* Macros for min/max. */ +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +#ifdef _KERNEL +/* + * Basic byte order function prototypes for non-inline functions. + */ +#ifndef LOCORE +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +__BEGIN_DECLS +__uint32_t htonl(__uint32_t); +__uint16_t htons(__uint16_t); +__uint32_t ntohl(__uint32_t); +__uint16_t ntohs(__uint16_t); +__END_DECLS +#endif +#endif + +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif /* !_BYTEORDER_FUNC_DEFINED */ +#endif /* _KERNEL */ + +/* + * Scale factor for scaled integers used to count %cpu time and load avgs. + * + * The number of CPU `tick's that map to a unique `%age' can be expressed + * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that + * can be calculated (assuming 32 bits) can be closely approximated using + * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). + * + * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', + * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. + */ +#define FSHIFT 11 /* bits to right of fixed binary point */ +#define FSCALE (1<> (PAGE_SHIFT - DEV_BSHIFT)) + +#define ctodb(db) /* calculates pages to devblks */ \ + ((db) << (PAGE_SHIFT - DEV_BSHIFT)) + +/* + * Old spelling of __containerof(). + */ +#define member2struct(s, m, x) \ + ((struct s *)(void *)((char *)(x) - offsetof(struct s, m))) + +/* + * Access a variable length array that has been declared as a fixed + * length array. + */ +#define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) + +#endif /* _SYS_PARAM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pciio.h b/lib/libc/include/any-freebsd-any/sys/pciio.h new file mode 100644 index 000000000000..50e9116d63d4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pciio.h @@ -0,0 +1,167 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997, Stefan Esser + * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS_PCIIO_H_ +#define _SYS_PCIIO_H_ + +#include + +#define PCI_MAXNAMELEN 16 + +typedef enum { + PCI_GETCONF_LAST_DEVICE, + PCI_GETCONF_LIST_CHANGED, + PCI_GETCONF_MORE_DEVS, + PCI_GETCONF_ERROR +} pci_getconf_status; + +typedef enum { + PCI_GETCONF_NO_MATCH = 0x0000, + PCI_GETCONF_MATCH_DOMAIN = 0x0001, + PCI_GETCONF_MATCH_BUS = 0x0002, + PCI_GETCONF_MATCH_DEV = 0x0004, + PCI_GETCONF_MATCH_FUNC = 0x0008, + PCI_GETCONF_MATCH_NAME = 0x0010, + PCI_GETCONF_MATCH_UNIT = 0x0020, + PCI_GETCONF_MATCH_VENDOR = 0x0040, + PCI_GETCONF_MATCH_DEVICE = 0x0080, + PCI_GETCONF_MATCH_CLASS = 0x0100 +} pci_getconf_flags; + +struct pcisel { + u_int32_t pc_domain; /* domain number */ + u_int8_t pc_bus; /* bus number */ + u_int8_t pc_dev; /* device on this bus */ + u_int8_t pc_func; /* function on this device */ +}; + +struct pci_conf { + struct pcisel pc_sel; /* domain+bus+slot+function */ + u_int8_t pc_hdr; /* PCI header type */ + u_int16_t pc_subvendor; /* card vendor ID */ + u_int16_t pc_subdevice; /* card device ID, assigned by + card vendor */ + u_int16_t pc_vendor; /* chip vendor ID */ + u_int16_t pc_device; /* chip device ID, assigned by + chip vendor */ + u_int8_t pc_class; /* chip PCI class */ + u_int8_t pc_subclass; /* chip PCI subclass */ + u_int8_t pc_progif; /* chip PCI programming interface */ + u_int8_t pc_revid; /* chip revision ID */ + char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ + u_long pd_unit; /* device unit number */ +}; + +struct pci_match_conf { + struct pcisel pc_sel; /* domain+bus+slot+function */ + char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ + u_long pd_unit; /* Unit number */ + u_int16_t pc_vendor; /* PCI Vendor ID */ + u_int16_t pc_device; /* PCI Device ID */ + u_int8_t pc_class; /* PCI class */ + pci_getconf_flags flags; /* Matching expression */ +}; + +struct pci_conf_io { + u_int32_t pat_buf_len; /* pattern buffer length */ + u_int32_t num_patterns; /* number of patterns */ + struct pci_match_conf *patterns; /* pattern buffer */ + u_int32_t match_buf_len; /* match buffer length */ + u_int32_t num_matches; /* number of matches returned */ + struct pci_conf *matches; /* match buffer */ + u_int32_t offset; /* offset into device list */ + u_int32_t generation; /* device list generation */ + pci_getconf_status status; /* request status */ +}; + +struct pci_io { + struct pcisel pi_sel; /* device to operate on */ + int pi_reg; /* configuration register to examine */ + int pi_width; /* width (in bytes) of read or write */ + u_int32_t pi_data; /* data to write or result of read */ +}; + +struct pci_bar_io { + struct pcisel pbi_sel; /* device to operate on */ + int pbi_reg; /* starting address of BAR */ + int pbi_enabled; /* decoding enabled */ + uint64_t pbi_base; /* current value of BAR */ + uint64_t pbi_length; /* length of BAR */ +}; + +struct pci_vpd_element { + char pve_keyword[2]; + uint8_t pve_flags; + uint8_t pve_datalen; + uint8_t pve_data[0]; +}; + +#define PVE_FLAG_IDENT 0x01 /* Element is the string identifier */ +#define PVE_FLAG_RW 0x02 /* Element is read/write */ + +#define PVE_NEXT(pve) \ + ((struct pci_vpd_element *)((char *)(pve) + \ + sizeof(struct pci_vpd_element) + (pve)->pve_datalen)) + +struct pci_list_vpd_io { + struct pcisel plvi_sel; /* device to operate on */ + size_t plvi_len; /* size of the data area */ + struct pci_vpd_element *plvi_data; +}; + +struct pci_bar_mmap { + void *pbm_map_base; /* (sometimes IN)/OUT mmaped base */ + size_t pbm_map_length; /* mapped length of the BAR, multiple + of pages */ + uint64_t pbm_bar_length; /* actual length of the BAR */ + int pbm_bar_off; /* offset from the mapped base to the + start of BAR */ + struct pcisel pbm_sel; /* device to operate on */ + int pbm_reg; /* starting address of BAR */ + int pbm_flags; + int pbm_memattr; +}; + +#define PCIIO_BAR_MMAP_FIXED 0x01 +#define PCIIO_BAR_MMAP_EXCL 0x02 +#define PCIIO_BAR_MMAP_RW 0x04 +#define PCIIO_BAR_MMAP_ACTIVATE 0x08 + +#define PCIOCGETCONF _IOWR('p', 5, struct pci_conf_io) +#define PCIOCREAD _IOWR('p', 2, struct pci_io) +#define PCIOCWRITE _IOWR('p', 3, struct pci_io) +#define PCIOCATTACHED _IOWR('p', 4, struct pci_io) +#define PCIOCGETBAR _IOWR('p', 6, struct pci_bar_io) +#define PCIOCLISTVPD _IOWR('p', 7, struct pci_list_vpd_io) +#define PCIOCBARMMAP _IOWR('p', 8, struct pci_bar_mmap) + +#endif /* !_SYS_PCIIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pcpu.h b/lib/libc/include/any-freebsd-any/sys/pcpu.h new file mode 100644 index 000000000000..8ad98ea9513d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pcpu.h @@ -0,0 +1,261 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2001 Wind River Systems, Inc. + * All rights reserved. + * Written by: John Baldwin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PCPU_H_ +#define _SYS_PCPU_H_ + +#ifdef LOCORE +#error "no assembler-serviceable parts inside" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DPCPU_SETNAME "set_pcpu" +#define DPCPU_SYMPREFIX "pcpu_entry_" + +#ifdef _KERNEL + +/* + * Define a set for pcpu data. + */ +extern uintptr_t *__start_set_pcpu; +__GLOBL(__start_set_pcpu); +extern uintptr_t *__stop_set_pcpu; +__GLOBL(__stop_set_pcpu); + +/* + * Array of dynamic pcpu base offsets. Indexed by id. + */ +extern uintptr_t dpcpu_off[]; + +/* + * Convenience defines. + */ +#define DPCPU_START ((uintptr_t)&__start_set_pcpu) +#define DPCPU_STOP ((uintptr_t)&__stop_set_pcpu) +#define DPCPU_BYTES (DPCPU_STOP - DPCPU_START) +#define DPCPU_MODMIN 2048 +#define DPCPU_SIZE roundup2(DPCPU_BYTES, PAGE_SIZE) +#define DPCPU_MODSIZE (DPCPU_SIZE - (DPCPU_BYTES - DPCPU_MODMIN)) + +/* + * Declaration and definition. + */ +#define DPCPU_NAME(n) pcpu_entry_##n +#define DPCPU_DECLARE(t, n) extern t DPCPU_NAME(n) +/* struct _hack is to stop this from being used with the static keyword. */ +#define DPCPU_DEFINE(t, n) \ + struct _hack; t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#if defined(KLD_MODULE) && (defined(__aarch64__) || defined(__riscv)) +/* + * On some architectures the compiler will use PC-relative load to + * find the address of DPCPU data with the static keyword. We then + * use this to find the offset of the data in a per-CPU region. + * This works for in the kernel as we can allocate the space ahead + * of time, however modules need to allocate a sepatate space and + * then use relocations to fix the address of the data. As + * PC-relative data doesn't have a relocation there is nothing for + * the kernel module linker to fix so data is accessed from the + * wrong location. + * + * This is a workaround until a better solution can be found. + * + * VNET_DEFINE_STATIC also has the same workaround. + */ +#define DPCPU_DEFINE_STATIC(t, n) \ + t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#else +#define DPCPU_DEFINE_STATIC(t, n) \ + static t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#endif + +/* + * Accessors with a given base. + */ +#define _DPCPU_PTR(b, n) \ + (__typeof(DPCPU_NAME(n))*)((b) + (uintptr_t)&DPCPU_NAME(n)) +#define _DPCPU_GET(b, n) (*_DPCPU_PTR(b, n)) +#define _DPCPU_SET(b, n, v) (*_DPCPU_PTR(b, n) = v) + +/* + * Accessors for the current cpu. + */ +#define DPCPU_PTR(n) _DPCPU_PTR(PCPU_GET(dynamic), n) +#define DPCPU_GET(n) (*DPCPU_PTR(n)) +#define DPCPU_SET(n, v) (*DPCPU_PTR(n) = v) + +/* + * Accessors for remote cpus. + */ +#define DPCPU_ID_PTR(i, n) _DPCPU_PTR(dpcpu_off[(i)], n) +#define DPCPU_ID_GET(i, n) (*DPCPU_ID_PTR(i, n)) +#define DPCPU_ID_SET(i, n, v) (*DPCPU_ID_PTR(i, n) = v) + +/* + * Utility macros. + */ +#define DPCPU_SUM(n) __extension__ \ +({ \ + u_int _i; \ + __typeof(*DPCPU_PTR(n)) sum; \ + \ + sum = 0; \ + CPU_FOREACH(_i) { \ + sum += *DPCPU_ID_PTR(_i, n); \ + } \ + sum; \ +}) + +#define DPCPU_VARSUM(n, var) __extension__ \ +({ \ + u_int _i; \ + __typeof((DPCPU_PTR(n))->var) sum; \ + \ + sum = 0; \ + CPU_FOREACH(_i) { \ + sum += (DPCPU_ID_PTR(_i, n))->var; \ + } \ + sum; \ +}) + +#define DPCPU_ZERO(n) do { \ + u_int _i; \ + \ + CPU_FOREACH(_i) { \ + bzero(DPCPU_ID_PTR(_i, n), sizeof(*DPCPU_PTR(n))); \ + } \ +} while(0) + +#endif /* _KERNEL */ + +/* + * This structure maps out the global data that needs to be kept on a + * per-cpu basis. The members are accessed via the PCPU_GET/SET/PTR + * macros defined in . Machine dependent fields are + * defined in the PCPU_MD_FIELDS macro defined in . + */ +struct pcpu { + struct thread *pc_curthread; /* Current thread */ + struct thread *pc_idlethread; /* Idle thread */ + struct thread *pc_fpcurthread; /* Fp state owner */ + struct thread *pc_deadthread; /* Zombie thread or NULL */ + struct pcb *pc_curpcb; /* Current pcb */ + uint64_t pc_switchtime; /* cpu_ticks() at last csw */ + int pc_switchticks; /* `ticks' at last csw */ + u_int pc_cpuid; /* This cpu number */ + STAILQ_ENTRY(pcpu) pc_allcpu; + struct lock_list_entry *pc_spinlocks; + long pc_cp_time[CPUSTATES]; /* statclock ticks */ + struct device *pc_device; + void *pc_netisr; /* netisr SWI cookie */ + int pc_unused1; /* unused field */ + int pc_domain; /* Memory domain. */ + struct rm_queue pc_rm_queue; /* rmlock list of trackers */ + uintptr_t pc_dynamic; /* Dynamic per-cpu data area */ + uint64_t pc_early_dummy_counter; /* Startup time counter(9) */ + + /* + * Keep MD fields last, so that CPU-specific variations on a + * single architecture don't result in offset variations of + * the machine-independent fields of the pcpu. Even though + * the pcpu structure is private to the kernel, some ports + * (e.g., lsof, part of gtop) define _KERNEL and include this + * header. While strictly speaking this is wrong, there's no + * reason not to keep the offsets of the MI fields constant + * if only to make kernel debugging easier. + */ + PCPU_MD_FIELDS; +} __aligned(CACHE_LINE_SIZE); + +#ifdef _KERNEL + +STAILQ_HEAD(cpuhead, pcpu); + +extern struct cpuhead cpuhead; +extern struct pcpu *cpuid_to_pcpu[]; + +#define curcpu PCPU_GET(cpuid) +#define curvidata PCPU_GET(vidata) + +#define UMA_PCPU_ALLOC_SIZE PAGE_SIZE + +#include + +#ifndef curthread +#define curthread PCPU_GET(curthread) +#endif +#define curproc (curthread->td_proc) + +/* Accessor to elements allocated via UMA_ZONE_PCPU zone. */ +static inline void * +zpcpu_get(void *base) +{ + + return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * curcpu); +} + +static inline void * +zpcpu_get_cpu(void *base, int cpu) +{ + + return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * cpu); +} + +/* + * Machine dependent callouts. cpu_pcpu_init() is responsible for + * initializing machine dependent fields of struct pcpu, and + * db_show_mdpcpu() is responsible for handling machine dependent + * fields for the DDB 'show pcpu' command. + */ +void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); +void db_show_mdpcpu(struct pcpu *pcpu); + +void *dpcpu_alloc(int size); +void dpcpu_copy(void *s, int size); +void dpcpu_free(void *s, int size); +void dpcpu_init(void *dpcpu, int cpuid); +void pcpu_destroy(struct pcpu *pcpu); +struct pcpu *pcpu_find(u_int cpuid); +void pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); + +#endif /* _KERNEL */ + +#endif /* !_SYS_PCPU_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pctrie.h b/lib/libc/include/any-freebsd-any/sys/pctrie.h new file mode 100644 index 000000000000..88d5d2583e40 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pctrie.h @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 EMC Corp. + * Copyright (c) 2011 Jeffrey Roberson + * Copyright (c) 2008 Mayur Shardul + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PCTRIE_H_ +#define _SYS_PCTRIE_H_ + +#include + +#ifdef _KERNEL + +#define PCTRIE_DEFINE(name, type, field, allocfn, freefn) \ + \ +CTASSERT(sizeof(((struct type *)0)->field) == sizeof(uint64_t)); \ +/* \ + * XXX This assert protects flag bits, it does not enforce natural \ + * alignment. 32bit architectures do not naturally align 64bit fields. \ + */ \ +CTASSERT((__offsetof(struct type, field) & (sizeof(uint32_t) - 1)) == 0); \ + \ +static __inline struct type * \ +name##_PCTRIE_VAL2PTR(uint64_t *val) \ +{ \ + \ + if (val == NULL) \ + return (NULL); \ + return (struct type *) \ + ((uintptr_t)val - __offsetof(struct type, field)); \ +} \ + \ +static __inline uint64_t * \ +name##_PCTRIE_PTR2VAL(struct type *ptr) \ +{ \ + \ + return &ptr->field; \ +} \ + \ +static __inline int \ +name##_PCTRIE_INSERT(struct pctrie *ptree, struct type *ptr) \ +{ \ + \ + return pctrie_insert(ptree, name##_PCTRIE_PTR2VAL(ptr), \ + allocfn); \ +} \ + \ +static __inline struct type * \ +name##_PCTRIE_LOOKUP(struct pctrie *ptree, uint64_t key) \ +{ \ + \ + return name##_PCTRIE_VAL2PTR(pctrie_lookup(ptree, key)); \ +} \ + \ +static __inline __unused struct type * \ +name##_PCTRIE_LOOKUP_LE(struct pctrie *ptree, uint64_t key) \ +{ \ + \ + return name##_PCTRIE_VAL2PTR(pctrie_lookup_le(ptree, key)); \ +} \ + \ +static __inline __unused struct type * \ +name##_PCTRIE_LOOKUP_GE(struct pctrie *ptree, uint64_t key) \ +{ \ + \ + return name##_PCTRIE_VAL2PTR(pctrie_lookup_ge(ptree, key)); \ +} \ + \ +static __inline __unused void \ +name##_PCTRIE_RECLAIM(struct pctrie *ptree) \ +{ \ + \ + pctrie_reclaim_allnodes(ptree, freefn); \ +} \ + \ +static __inline void \ +name##_PCTRIE_REMOVE(struct pctrie *ptree, uint64_t key) \ +{ \ + \ + pctrie_remove(ptree, key, freefn); \ +} + +typedef void *(*pctrie_alloc_t)(struct pctrie *ptree); +typedef void (*pctrie_free_t)(struct pctrie *ptree, void *node); + +int pctrie_insert(struct pctrie *ptree, uint64_t *val, + pctrie_alloc_t allocfn); +uint64_t *pctrie_lookup(struct pctrie *ptree, uint64_t key); +uint64_t *pctrie_lookup_ge(struct pctrie *ptree, uint64_t key); +uint64_t *pctrie_lookup_le(struct pctrie *ptree, uint64_t key); +void pctrie_reclaim_allnodes(struct pctrie *ptree, + pctrie_free_t freefn); +void pctrie_remove(struct pctrie *ptree, uint64_t key, + pctrie_free_t freefn); +size_t pctrie_node_size(void); +int pctrie_zone_init(void *mem, int size, int flags); + +static __inline void +pctrie_init(struct pctrie *ptree) +{ + + ptree->pt_root = 0; +} + +static __inline boolean_t +pctrie_is_empty(struct pctrie *ptree) +{ + + return (ptree->pt_root == 0); +} + +/* + * These widths should allow the pointers to a node's children to fit within + * a single cache line. The extra levels from a narrow width should not be + * a problem thanks to path compression. + */ +#ifdef __LP64__ +#define PCTRIE_WIDTH 4 +#else +#define PCTRIE_WIDTH 3 +#endif + +#define PCTRIE_COUNT (1 << PCTRIE_WIDTH) + +#endif /* _KERNEL */ +#endif /* !_SYS_PCTRIE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/physmem.h b/lib/libc/include/any-freebsd-any/sys/physmem.h new file mode 100644 index 000000000000..f9ba69228c95 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/physmem.h @@ -0,0 +1,88 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 Ian Lepore + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PHYSMEM_H_ +#define _SYS_PHYSMEM_H_ + +/* + * Routines to help configure physical ram. + * + * Multiple regions of contiguous physical ram can be added (in any order). + * + * Multiple regions of physical ram that should be excluded from crash dumps, or + * memory allocation, or both, can be added (in any order). + * + * After all early kernel init is done and it's time to configure all + * remainining non-excluded physical ram for use by other parts of the kernel, + * physmem_init_kernel_globals() processes the hardware regions and + * exclusion regions to generate the global dump_avail and phys_avail arrays + * that communicate physical ram configuration to other parts of the kernel. + */ + +#define EXFLAG_NODUMP 0x01 +#define EXFLAG_NOALLOC 0x02 + +void physmem_hardware_region(uint64_t pa, uint64_t sz); +void physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t flags); +size_t physmem_avail(vm_paddr_t *avail, size_t maxavail); +void physmem_init_kernel_globals(void); +void physmem_print_tables(void); + +/* + * Convenience routines for FDT. + */ + +#ifdef FDT + +#include + +static inline void +physmem_hardware_regions(struct mem_region * mrptr, int mrcount) +{ + while (mrcount--) { + physmem_hardware_region(mrptr->mr_start, mrptr->mr_size); + ++mrptr; + } +} + +static inline void +physmem_exclude_regions(struct mem_region * mrptr, int mrcount, + uint32_t exflags) +{ + while (mrcount--) { + physmem_exclude_region(mrptr->mr_start, mrptr->mr_size, + exflags); + ++mrptr; + } +} + +#endif /* FDT */ + +#endif /* !_SYS_PHYSMEM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pidctrl.h b/lib/libc/include/any-freebsd-any/sys/pidctrl.h new file mode 100644 index 000000000000..e09202e871d7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pidctrl.h @@ -0,0 +1,123 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PIDCTRL_H_ +#define _SYS_PIDCTRL_H_ + +/* + * Proportional Integral Derivative controller. + * + * This controller is intended to replace a multitude of threshold based + * daemon regulation systems. These systems produce sharp sawtooths of + * activity which can cause latency spikes and other undesireable bursty + * behavior. The PID controller adapts to changing load conditions and + * adjusts the work done by the daemon to keep a smoother output. + * + * The setpoint can be thought of as a single watermark that the controller + * is always trying to reach. Compared to a high water/low water type + * algorithm the pid controller is dynamically deciding the low water and + * regulating to the high water. The setpoint should be high enough that + * the controller and daemon have time to observe the rise in value and + * respond to it, else the resource may be exhausted. More frequent wakeups + * permit higher setpoints and less underutilized resources. + * + * The controller has been optimised for simplicity of math making it quite + * inexpensive to execute. There is no floating point and so the gains must + * be the inverse of whole integers. + * + * Failing to measure and tune the gain parameters can result in wild + * oscillations in output. It is strongly encouraged that controllers are + * tested and tuned under a wide variety of workloads before gain values are + * picked. Some reasonable defaults are provided below. + */ + +struct pidctrl { + /* Saved control variables. */ + int pc_error; /* Current error. */ + int pc_olderror; /* Saved error for derivative. */ + int pc_integral; /* Integral accumulator. */ + int pc_derivative; /* Change from last error. */ + int pc_input; /* Last input. */ + int pc_output; /* Last output. */ + int pc_ticks; /* Last sampling time. */ + /* configuration options, runtime tunable via sysctl */ + int pc_setpoint; /* Desired level */ + int pc_interval; /* Update interval in ticks. */ + int pc_bound; /* Integral wind-up limit. */ + int pc_Kpd; /* Proportional gain divisor. */ + int pc_Kid; /* Integral gain divisor. */ + int pc_Kdd; /* Derivative gain divisor. */ +}; + +/* + * Reasonable default divisors. + * + * Actual gains are 1/divisor. Gains interact in complex ways with the + * setpoint and interval. Measurement under multiple loads should be + * taken to ensure adequate stability and rise time. + */ +#define PIDCTRL_KPD 3 /* Default proportional divisor. */ +#define PIDCTRL_KID 4 /* Default integral divisor. */ +#define PIDCTRL_KDD 8 /* Default derivative divisor. */ +#define PIDCTRL_BOUND 4 /* Bound factor, setpoint multiple. */ + +struct sysctl_oid_list; + +void pidctrl_init(struct pidctrl *pc, int interval, int setpoint, + int bound, int Kpd, int Kid, int Kdd); +void pidctrl_init_sysctl(struct pidctrl *pc, struct sysctl_oid_list *parent); + +/* + * This is the classic PID controller where the interval is clamped to + * [-bound, bound] and the output may be negative. This should be used + * in continuous control loops that can adjust a process variable in + * either direction. This is a descrete time controller and should + * only be called once per-interval or the derivative term will be + * inaccurate. + */ +int pidctrl_classic(struct pidctrl *pc, int input); + +/* + * This controler is intended for consumer type daemons that can only + * regulate in a positive direction, that is to say, they can not exert + * positive pressure on the process variable or input. They can only + * reduce it by doing work. As such the integral is bound between [0, bound] + * and the output is similarly a positive value reflecting the units of + * work necessary to be completed in the current interval to eliminate error. + * + * It is a descrete time controller but can be invoked more than once in a + * given time interval for ease of client implementation. This should only + * be done in overload situations or the controller may not produce a stable + * output. Calling it less frequently when there is no work to be done will + * increase the rise time but should otherwise be harmless. + */ +int pidctrl_daemon(struct pidctrl *pc, int input); + +#endif /* !_SYS_PIDCTRL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pioctl.h b/lib/libc/include/any-freebsd-any/sys/pioctl.h new file mode 100644 index 000000000000..ed8a93a3be09 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pioctl.h @@ -0,0 +1,85 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright 1997 Sean Eric Fagan + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Sean Eric Fagan + * 4. Neither the name of the author may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * procfs ioctl definitions. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PIOCTL_H +# define _SYS_PIOCTL_H + +#ifndef _KERNEL +#warning " is deprecated, ptrace() should be used instead" +#endif + +# include + +struct procfs_status { + int state; /* Running, stopped, something else? */ + int flags; /* Any flags */ + unsigned long events; /* Events to stop on */ + int why; /* What event, if any, proc stopped on */ + unsigned long val; /* Any extra data */ +}; + +# define PIOCBIS _IOWINT('p', 1) /* Set event flag */ +# define PIOCBIC _IOWINT('p', 2) /* Clear event flag */ +# define PIOCSFL _IOWINT('p', 3) /* Set flags */ + /* wait for proc to stop */ +# define PIOCWAIT _IOR('p', 4, struct procfs_status) +# define PIOCCONT _IOWINT('p', 5) /* Continue a process */ + /* Get proc status */ +# define PIOCSTATUS _IOR('p', 6, struct procfs_status) +# define PIOCGFL _IOR('p', 7, unsigned int) /* Get flags */ + +# define S_EXEC 0x00000001 /* stop-on-exec */ +# define S_SIG 0x00000002 /* stop-on-signal */ +# define S_SCE 0x00000004 /* stop on syscall entry */ +# define S_SCX 0x00000008 /* stop on syscall exit */ +# define S_CORE 0x00000010 /* stop on coredump */ +# define S_EXIT 0x00000020 /* stop on exit */ +# define S_ALLSTOPS 0x003f /* stop on all events */ + +/* + * If PF_LINGER is set in procp->p_pfsflags, then the last close + * of a /proc//mem file will not clear out the stops and continue + * the process. + */ + +# define PF_LINGER 0x01 /* Keep stops around after last close */ +# define PF_ISUGID 0x02 /* Ignore UID/GID changes */ +# define PF_FORK 0x04 /* Retain settings on fork() */ +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/pipe.h b/lib/libc/include/any-freebsd-any/sys/pipe.h new file mode 100644 index 000000000000..2f1568ab6637 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pipe.h @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 1996 John S. Dyson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice immediately at the beginning of the file, without modification, + * this list of conditions, and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Absolutely no warranty of function or purpose is made by the author + * John S. Dyson. + * 4. This work was done expressly for inclusion into FreeBSD. Other use + * is allowed if this notation is included. + * 5. Modifications may be freely made to this file if the above conditions + * are met. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PIPE_H_ +#define _SYS_PIPE_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +/* + * Pipe buffer size, keep moderate in value, pipes take kva space. + */ +#ifndef PIPE_SIZE +#define PIPE_SIZE 16384 +#endif + +#ifndef BIG_PIPE_SIZE +#define BIG_PIPE_SIZE (64*1024) +#endif + +#ifndef SMALL_PIPE_SIZE +#define SMALL_PIPE_SIZE PAGE_SIZE +#endif + +/* + * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger + * than PIPE_BUF. + */ +#ifndef PIPE_MINDIRECT +#define PIPE_MINDIRECT 8192 +#endif + +#define PIPENPAGES (BIG_PIPE_SIZE / PAGE_SIZE + 1) + +/* + * See sys_pipe.c for info on what these limits mean. + */ +extern long maxpipekva; +extern struct fileops pipeops; + +/* + * Pipe buffer information. + * Separate in, out, cnt are used to simplify calculations. + * Buffered write is active when the buffer.cnt field is set. + */ +struct pipebuf { + u_int cnt; /* number of chars currently in buffer */ + u_int in; /* in pointer */ + u_int out; /* out pointer */ + u_int size; /* size of buffer */ + caddr_t buffer; /* kva of buffer */ +}; + +/* + * Information to support direct transfers between processes for pipes. + */ +struct pipemapping { + vm_size_t cnt; /* number of chars in buffer */ + vm_size_t pos; /* current position of transfer */ + int npages; /* number of pages */ + vm_page_t ms[PIPENPAGES]; /* pages in source process */ +}; + +/* + * Bits in pipe_state. + */ +#define PIPE_ASYNC 0x004 /* Async? I/O. */ +#define PIPE_WANTR 0x008 /* Reader wants some characters. */ +#define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ +#define PIPE_WANT 0x020 /* Pipe is wanted to be run-down. */ +#define PIPE_SEL 0x040 /* Pipe has a select active. */ +#define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ +#define PIPE_LOCKFL 0x100 /* Process has exclusive access to pointers/data. */ +#define PIPE_LWANT 0x200 /* Process wants exclusive access to pointers/data. */ +#define PIPE_DIRECTW 0x400 /* Pipe direct write active. */ +#define PIPE_DIRECTOK 0x800 /* Direct mode ok. */ +#define PIPE_NAMED 0x1000 /* Is a named pipe. */ + +/* + * Per-pipe data structure. + * Two of these are linked together to produce bi-directional pipes. + */ +struct pipe { + struct pipebuf pipe_buffer; /* data storage */ + struct pipemapping pipe_pages; /* wired pages for direct I/O */ + struct selinfo pipe_sel; /* for compat with select */ + struct timespec pipe_atime; /* time of last access */ + struct timespec pipe_mtime; /* time of last modify */ + struct timespec pipe_ctime; /* time of status change */ + struct sigio *pipe_sigio; /* information for async I/O */ + struct pipe *pipe_peer; /* link with other direction */ + struct pipepair *pipe_pair; /* container structure pointer */ + u_int pipe_state; /* pipe status info */ + int pipe_busy; /* busy flag, mostly to handle rundown sanely */ + int pipe_present; /* still present? */ + int pipe_wgen; /* writer generation for named pipe */ + ino_t pipe_ino; /* fake inode for stat(2) */ +}; + +/* + * Values for the pipe_present. + */ +#define PIPE_ACTIVE 1 +#define PIPE_CLOSING 2 +#define PIPE_FINALIZED 3 + +/* + * Container structure to hold the two pipe endpoints, mutex, and label + * pointer. + */ +struct pipepair { + struct pipe pp_rpipe; + struct pipe pp_wpipe; + struct mtx pp_mtx; + struct label *pp_label; +}; + +#define PIPE_MTX(pipe) (&(pipe)->pipe_pair->pp_mtx) +#define PIPE_LOCK(pipe) mtx_lock(PIPE_MTX(pipe)) +#define PIPE_UNLOCK(pipe) mtx_unlock(PIPE_MTX(pipe)) +#define PIPE_LOCK_ASSERT(pipe, type) mtx_assert(PIPE_MTX(pipe), (type)) + +void pipe_dtor(struct pipe *dpipe); +int pipe_named_ctor(struct pipe **ppipe, struct thread *td); +void pipeselwakeup(struct pipe *cpipe); +#endif /* !_SYS_PIPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pmc.h b/lib/libc/include/any-freebsd-any/sys/pmc.h new file mode 100644 index 000000000000..59f41b43da72 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pmc.h @@ -0,0 +1,1231 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003-2008, Joseph Koshy + * Copyright (c) 2007 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by A. Joseph Koshy under + * sponsorship from the FreeBSD Foundation and Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PMC_H_ +#define _SYS_PMC_H_ + +#include +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +#define PMC_MODULE_NAME "hwpmc" +#define PMC_NAME_MAX 64 /* HW counter name size */ +#define PMC_CLASS_MAX 8 /* max #classes of PMCs per-system */ + +/* + * Kernel<->userland API version number [MMmmpppp] + * + * Major numbers are to be incremented when an incompatible change to + * the ABI occurs that older clients will not be able to handle. + * + * Minor numbers are incremented when a backwards compatible change + * occurs that allows older correct programs to run unchanged. For + * example, when support for a new PMC type is added. + * + * The patch version is incremented for every bug fix. + */ +#define PMC_VERSION_MAJOR 0x09 +#define PMC_VERSION_MINOR 0x03 +#define PMC_VERSION_PATCH 0x0000 + +#define PMC_VERSION (PMC_VERSION_MAJOR << 24 | \ + PMC_VERSION_MINOR << 16 | PMC_VERSION_PATCH) + +#define PMC_CPUID_LEN 64 +/* cpu model name for pmu lookup */ +extern char pmc_cpuid[PMC_CPUID_LEN]; + +/* + * Kinds of CPUs known. + * + * We keep track of CPU variants that need to be distinguished in + * some way for PMC operations. CPU names are grouped by manufacturer + * and numbered sparsely in order to minimize changes to the ABI involved + * when new CPUs are added. + */ + +#define __PMC_CPUS() \ + __PMC_CPU(AMD_K7, 0x00, "AMD K7") \ + __PMC_CPU(AMD_K8, 0x01, "AMD K8") \ + __PMC_CPU(INTEL_P5, 0x80, "Intel Pentium") \ + __PMC_CPU(INTEL_P6, 0x81, "Intel Pentium Pro") \ + __PMC_CPU(INTEL_CL, 0x82, "Intel Celeron") \ + __PMC_CPU(INTEL_PII, 0x83, "Intel Pentium II") \ + __PMC_CPU(INTEL_PIII, 0x84, "Intel Pentium III") \ + __PMC_CPU(INTEL_PM, 0x85, "Intel Pentium M") \ + __PMC_CPU(INTEL_PIV, 0x86, "Intel Pentium IV") \ + __PMC_CPU(INTEL_CORE, 0x87, "Intel Core Solo/Duo") \ + __PMC_CPU(INTEL_CORE2, 0x88, "Intel Core2") \ + __PMC_CPU(INTEL_CORE2EXTREME, 0x89, "Intel Core2 Extreme") \ + __PMC_CPU(INTEL_ATOM, 0x8A, "Intel Atom") \ + __PMC_CPU(INTEL_COREI7, 0x8B, "Intel Core i7") \ + __PMC_CPU(INTEL_WESTMERE, 0x8C, "Intel Westmere") \ + __PMC_CPU(INTEL_SANDYBRIDGE, 0x8D, "Intel Sandy Bridge") \ + __PMC_CPU(INTEL_IVYBRIDGE, 0x8E, "Intel Ivy Bridge") \ + __PMC_CPU(INTEL_SANDYBRIDGE_XEON, 0x8F, "Intel Sandy Bridge Xeon") \ + __PMC_CPU(INTEL_IVYBRIDGE_XEON, 0x90, "Intel Ivy Bridge Xeon") \ + __PMC_CPU(INTEL_HASWELL, 0x91, "Intel Haswell") \ + __PMC_CPU(INTEL_ATOM_SILVERMONT, 0x92, "Intel Atom Silvermont") \ + __PMC_CPU(INTEL_NEHALEM_EX, 0x93, "Intel Nehalem Xeon 7500") \ + __PMC_CPU(INTEL_WESTMERE_EX, 0x94, "Intel Westmere Xeon E7") \ + __PMC_CPU(INTEL_HASWELL_XEON, 0x95, "Intel Haswell Xeon E5 v3") \ + __PMC_CPU(INTEL_BROADWELL, 0x96, "Intel Broadwell") \ + __PMC_CPU(INTEL_BROADWELL_XEON, 0x97, "Intel Broadwell Xeon") \ + __PMC_CPU(INTEL_SKYLAKE, 0x98, "Intel Skylake") \ + __PMC_CPU(INTEL_SKYLAKE_XEON, 0x99, "Intel Skylake Xeon") \ + __PMC_CPU(INTEL_ATOM_GOLDMONT, 0x9A, "Intel Atom Goldmont") \ + __PMC_CPU(INTEL_XSCALE, 0x100, "Intel XScale") \ + __PMC_CPU(MIPS_24K, 0x200, "MIPS 24K") \ + __PMC_CPU(MIPS_OCTEON, 0x201, "Cavium Octeon") \ + __PMC_CPU(MIPS_74K, 0x202, "MIPS 74K") \ + __PMC_CPU(PPC_7450, 0x300, "PowerPC MPC7450") \ + __PMC_CPU(PPC_E500, 0x340, "PowerPC e500 Core") \ + __PMC_CPU(PPC_970, 0x380, "IBM PowerPC 970") \ + __PMC_CPU(GENERIC, 0x400, "Generic") \ + __PMC_CPU(ARMV7_CORTEX_A5, 0x500, "ARMv7 Cortex A5") \ + __PMC_CPU(ARMV7_CORTEX_A7, 0x501, "ARMv7 Cortex A7") \ + __PMC_CPU(ARMV7_CORTEX_A8, 0x502, "ARMv7 Cortex A8") \ + __PMC_CPU(ARMV7_CORTEX_A9, 0x503, "ARMv7 Cortex A9") \ + __PMC_CPU(ARMV7_CORTEX_A15, 0x504, "ARMv7 Cortex A15") \ + __PMC_CPU(ARMV7_CORTEX_A17, 0x505, "ARMv7 Cortex A17") \ + __PMC_CPU(ARMV8_CORTEX_A53, 0x600, "ARMv8 Cortex A53") \ + __PMC_CPU(ARMV8_CORTEX_A57, 0x601, "ARMv8 Cortex A57") + +enum pmc_cputype { +#undef __PMC_CPU +#define __PMC_CPU(S,V,D) PMC_CPU_##S = V, + __PMC_CPUS() +}; + +#define PMC_CPU_FIRST PMC_CPU_AMD_K7 +#define PMC_CPU_LAST PMC_CPU_GENERIC + +/* + * Classes of PMCs + */ + +#define __PMC_CLASSES() \ + __PMC_CLASS(TSC, 0x00, "CPU Timestamp counter") \ + __PMC_CLASS(K7, 0x01, "AMD K7 performance counters") \ + __PMC_CLASS(K8, 0x02, "AMD K8 performance counters") \ + __PMC_CLASS(P5, 0x03, "Intel Pentium counters") \ + __PMC_CLASS(P6, 0x04, "Intel Pentium Pro counters") \ + __PMC_CLASS(P4, 0x05, "Intel Pentium-IV counters") \ + __PMC_CLASS(IAF, 0x06, "Intel Core2/Atom, fixed function") \ + __PMC_CLASS(IAP, 0x07, "Intel Core...Atom, programmable") \ + __PMC_CLASS(UCF, 0x08, "Intel Uncore fixed function") \ + __PMC_CLASS(UCP, 0x09, "Intel Uncore programmable") \ + __PMC_CLASS(XSCALE, 0x0A, "Intel XScale counters") \ + __PMC_CLASS(MIPS24K, 0x0B, "MIPS 24K") \ + __PMC_CLASS(OCTEON, 0x0C, "Cavium Octeon") \ + __PMC_CLASS(PPC7450, 0x0D, "Motorola MPC7450 class") \ + __PMC_CLASS(PPC970, 0x0E, "IBM PowerPC 970 class") \ + __PMC_CLASS(SOFT, 0x0F, "Software events") \ + __PMC_CLASS(ARMV7, 0x10, "ARMv7") \ + __PMC_CLASS(ARMV8, 0x11, "ARMv8") \ + __PMC_CLASS(MIPS74K, 0x12, "MIPS 74K") \ + __PMC_CLASS(E500, 0x13, "Freescale e500 class") + +enum pmc_class { +#undef __PMC_CLASS +#define __PMC_CLASS(S,V,D) PMC_CLASS_##S = V, + __PMC_CLASSES() +}; + +#define PMC_CLASS_FIRST PMC_CLASS_TSC +#define PMC_CLASS_LAST PMC_CLASS_E500 + +/* + * A PMC can be in the following states: + * + * Hardware states: + * DISABLED -- administratively prohibited from being used. + * FREE -- HW available for use + * Software states: + * ALLOCATED -- allocated + * STOPPED -- allocated, but not counting events + * RUNNING -- allocated, and in operation; 'pm_runcount' + * holds the number of CPUs using this PMC at + * a given instant + * DELETED -- being destroyed + */ + +#define __PMC_HWSTATES() \ + __PMC_STATE(DISABLED) \ + __PMC_STATE(FREE) + +#define __PMC_SWSTATES() \ + __PMC_STATE(ALLOCATED) \ + __PMC_STATE(STOPPED) \ + __PMC_STATE(RUNNING) \ + __PMC_STATE(DELETED) + +#define __PMC_STATES() \ + __PMC_HWSTATES() \ + __PMC_SWSTATES() + +enum pmc_state { +#undef __PMC_STATE +#define __PMC_STATE(S) PMC_STATE_##S, + __PMC_STATES() + __PMC_STATE(MAX) +}; + +#define PMC_STATE_FIRST PMC_STATE_DISABLED +#define PMC_STATE_LAST PMC_STATE_DELETED + +/* + * An allocated PMC may used as a 'global' counter or as a + * 'thread-private' one. Each such mode of use can be in either + * statistical sampling mode or in counting mode. Thus a PMC in use + * + * SS i.e., SYSTEM STATISTICAL -- system-wide statistical profiling + * SC i.e., SYSTEM COUNTER -- system-wide counting mode + * TS i.e., THREAD STATISTICAL -- thread virtual, statistical profiling + * TC i.e., THREAD COUNTER -- thread virtual, counting mode + * + * Statistical profiling modes rely on the PMC periodically delivering + * a interrupt to the CPU (when the configured number of events have + * been measured), so the PMC must have the ability to generate + * interrupts. + * + * In counting modes, the PMC counts its configured events, with the + * value of the PMC being read whenever needed by its owner process. + * + * The thread specific modes "virtualize" the PMCs -- the PMCs appear + * to be thread private and count events only when the profiled thread + * actually executes on the CPU. + * + * The system-wide "global" modes keep the PMCs running all the time + * and are used to measure the behaviour of the whole system. + */ + +#define __PMC_MODES() \ + __PMC_MODE(SS, 0) \ + __PMC_MODE(SC, 1) \ + __PMC_MODE(TS, 2) \ + __PMC_MODE(TC, 3) + +enum pmc_mode { +#undef __PMC_MODE +#define __PMC_MODE(M,N) PMC_MODE_##M = N, + __PMC_MODES() +}; + +#define PMC_MODE_FIRST PMC_MODE_SS +#define PMC_MODE_LAST PMC_MODE_TC + +#define PMC_IS_COUNTING_MODE(mode) \ + ((mode) == PMC_MODE_SC || (mode) == PMC_MODE_TC) +#define PMC_IS_SYSTEM_MODE(mode) \ + ((mode) == PMC_MODE_SS || (mode) == PMC_MODE_SC) +#define PMC_IS_SAMPLING_MODE(mode) \ + ((mode) == PMC_MODE_SS || (mode) == PMC_MODE_TS) +#define PMC_IS_VIRTUAL_MODE(mode) \ + ((mode) == PMC_MODE_TS || (mode) == PMC_MODE_TC) + +/* + * PMC row disposition + */ + +#define __PMC_DISPOSITIONS(N) \ + __PMC_DISP(STANDALONE) /* global/disabled counters */ \ + __PMC_DISP(FREE) /* free/available */ \ + __PMC_DISP(THREAD) /* thread-virtual PMCs */ \ + __PMC_DISP(UNKNOWN) /* sentinel */ + +enum pmc_disp { +#undef __PMC_DISP +#define __PMC_DISP(D) PMC_DISP_##D , + __PMC_DISPOSITIONS() +}; + +#define PMC_DISP_FIRST PMC_DISP_STANDALONE +#define PMC_DISP_LAST PMC_DISP_THREAD + +/* + * Counter capabilities + * + * __PMC_CAPS(NAME, VALUE, DESCRIPTION) + */ + +#define __PMC_CAPS() \ + __PMC_CAP(INTERRUPT, 0, "generate interrupts") \ + __PMC_CAP(USER, 1, "count user-mode events") \ + __PMC_CAP(SYSTEM, 2, "count system-mode events") \ + __PMC_CAP(EDGE, 3, "do edge detection of events") \ + __PMC_CAP(THRESHOLD, 4, "ignore events below a threshold") \ + __PMC_CAP(READ, 5, "read PMC counter") \ + __PMC_CAP(WRITE, 6, "reprogram PMC counter") \ + __PMC_CAP(INVERT, 7, "invert comparison sense") \ + __PMC_CAP(QUALIFIER, 8, "further qualify monitored events") \ + __PMC_CAP(PRECISE, 9, "perform precise sampling") \ + __PMC_CAP(TAGGING, 10, "tag upstream events") \ + __PMC_CAP(CASCADE, 11, "cascade counters") + +enum pmc_caps +{ +#undef __PMC_CAP +#define __PMC_CAP(NAME, VALUE, DESCR) PMC_CAP_##NAME = (1 << VALUE) , + __PMC_CAPS() +}; + +#define PMC_CAP_FIRST PMC_CAP_INTERRUPT +#define PMC_CAP_LAST PMC_CAP_CASCADE + +/* + * PMC Event Numbers + * + * These are generated from the definitions in "dev/hwpmc/pmc_events.h". + */ + +enum pmc_event { +#undef __PMC_EV +#undef __PMC_EV_BLOCK +#define __PMC_EV_BLOCK(C,V) PMC_EV_ ## C ## __BLOCK_START = (V) - 1 , +#define __PMC_EV(C,N) PMC_EV_ ## C ## _ ## N , + __PMC_EVENTS() +}; + +/* + * PMC SYSCALL INTERFACE + */ + +/* + * "PMC_OPS" -- these are the commands recognized by the kernel + * module, and are used when performing a system call from userland. + */ +#define __PMC_OPS() \ + __PMC_OP(CONFIGURELOG, "Set log file") \ + __PMC_OP(FLUSHLOG, "Flush log file") \ + __PMC_OP(GETCPUINFO, "Get system CPU information") \ + __PMC_OP(GETDRIVERSTATS, "Get driver statistics") \ + __PMC_OP(GETMODULEVERSION, "Get module version") \ + __PMC_OP(GETPMCINFO, "Get per-cpu PMC information") \ + __PMC_OP(PMCADMIN, "Set PMC state") \ + __PMC_OP(PMCALLOCATE, "Allocate and configure a PMC") \ + __PMC_OP(PMCATTACH, "Attach a PMC to a process") \ + __PMC_OP(PMCDETACH, "Detach a PMC from a process") \ + __PMC_OP(PMCGETMSR, "Get a PMC's hardware address") \ + __PMC_OP(PMCRELEASE, "Release a PMC") \ + __PMC_OP(PMCRW, "Read/Set a PMC") \ + __PMC_OP(PMCSETCOUNT, "Set initial count/sampling rate") \ + __PMC_OP(PMCSTART, "Start a PMC") \ + __PMC_OP(PMCSTOP, "Stop a PMC") \ + __PMC_OP(WRITELOG, "Write a cookie to the log file") \ + __PMC_OP(CLOSELOG, "Close log file") \ + __PMC_OP(GETDYNEVENTINFO, "Get dynamic events list") + + +enum pmc_ops { +#undef __PMC_OP +#define __PMC_OP(N, D) PMC_OP_##N, + __PMC_OPS() +}; + + +/* + * Flags used in operations on PMCs. + */ + +#define PMC_F_UNUSED1 0x00000001 /* unused */ +#define PMC_F_DESCENDANTS 0x00000002 /*OP ALLOCATE track descendants */ +#define PMC_F_LOG_PROCCSW 0x00000004 /*OP ALLOCATE track ctx switches */ +#define PMC_F_LOG_PROCEXIT 0x00000008 /*OP ALLOCATE log proc exits */ +#define PMC_F_NEWVALUE 0x00000010 /*OP RW write new value */ +#define PMC_F_OLDVALUE 0x00000020 /*OP RW get old value */ + +/* V2 API */ +#define PMC_F_CALLCHAIN 0x00000080 /*OP ALLOCATE capture callchains */ +#define PMC_F_USERCALLCHAIN 0x00000100 /*OP ALLOCATE use userspace stack */ + +/* internal flags */ +#define PMC_F_ATTACHED_TO_OWNER 0x00010000 /*attached to owner*/ +#define PMC_F_NEEDS_LOGFILE 0x00020000 /*needs log file */ +#define PMC_F_ATTACH_DONE 0x00040000 /*attached at least once */ + +#define PMC_CALLCHAIN_DEPTH_MAX 512 + +#define PMC_CC_F_USERSPACE 0x01 /*userspace callchain*/ + +/* + * Cookies used to denote allocated PMCs, and the values of PMCs. + */ + +typedef uint32_t pmc_id_t; +typedef uint64_t pmc_value_t; + +#define PMC_ID_INVALID (~ (pmc_id_t) 0) + +/* + * PMC IDs have the following format: + * + * +-----------------------+-------+-----------+ + * | CPU | PMC MODE | CLASS | ROW INDEX | + * +-----------------------+-------+-----------+ + * + * where CPU is 12 bits, MODE 8, CLASS 4, and ROW INDEX 8 Field 'CPU' + * is set to the requested CPU for system-wide PMCs or PMC_CPU_ANY for + * process-mode PMCs. Field 'PMC MODE' is the allocated PMC mode. + * Field 'PMC CLASS' is the class of the PMC. Field 'ROW INDEX' is the + * row index for the PMC. + * + * The 'ROW INDEX' ranges over 0..NWPMCS where NHWPMCS is the total + * number of hardware PMCs on this cpu. + */ + + +#define PMC_ID_TO_ROWINDEX(ID) ((ID) & 0xFF) +#define PMC_ID_TO_CLASS(ID) (((ID) & 0xF00) >> 8) +#define PMC_ID_TO_MODE(ID) (((ID) & 0xFF000) >> 12) +#define PMC_ID_TO_CPU(ID) (((ID) & 0xFFF00000) >> 20) +#define PMC_ID_MAKE_ID(CPU,MODE,CLASS,ROWINDEX) \ + ((((CPU) & 0xFFF) << 20) | (((MODE) & 0xFF) << 12) | \ + (((CLASS) & 0xF) << 8) | ((ROWINDEX) & 0xFF)) + +/* + * Data structures for system calls supported by the pmc driver. + */ + +/* + * OP PMCALLOCATE + * + * Allocate a PMC on the named CPU. + */ + +#define PMC_CPU_ANY ~0 + +struct pmc_op_pmcallocate { + uint32_t pm_caps; /* PMC_CAP_* */ + uint32_t pm_cpu; /* CPU number or PMC_CPU_ANY */ + enum pmc_class pm_class; /* class of PMC desired */ + enum pmc_event pm_ev; /* [enum pmc_event] desired */ + uint32_t pm_flags; /* additional modifiers PMC_F_* */ + enum pmc_mode pm_mode; /* desired mode */ + pmc_id_t pm_pmcid; /* [return] process pmc id */ + pmc_value_t pm_count; /* initial/sample count */ + + union pmc_md_op_pmcallocate pm_md; /* MD layer extensions */ +}; + +/* + * OP PMCADMIN + * + * Set the administrative state (i.e., whether enabled or disabled) of + * a PMC 'pm_pmc' on CPU 'pm_cpu'. Note that 'pm_pmc' specifies an + * absolute PMC number and need not have been first allocated by the + * calling process. + */ + +struct pmc_op_pmcadmin { + int pm_cpu; /* CPU# */ + uint32_t pm_flags; /* flags */ + int pm_pmc; /* PMC# */ + enum pmc_state pm_state; /* desired state */ +}; + +/* + * OP PMCATTACH / OP PMCDETACH + * + * Attach/detach a PMC and a process. + */ + +struct pmc_op_pmcattach { + pmc_id_t pm_pmc; /* PMC to attach to */ + pid_t pm_pid; /* target process */ +}; + +/* + * OP PMCSETCOUNT + * + * Set the sampling rate (i.e., the reload count) for statistical counters. + * 'pm_pmcid' need to have been previously allocated using PMCALLOCATE. + */ + +struct pmc_op_pmcsetcount { + pmc_value_t pm_count; /* initial/sample count */ + pmc_id_t pm_pmcid; /* PMC id to set */ +}; + + +/* + * OP PMCRW + * + * Read the value of a PMC named by 'pm_pmcid'. 'pm_pmcid' needs + * to have been previously allocated using PMCALLOCATE. + */ + + +struct pmc_op_pmcrw { + uint32_t pm_flags; /* PMC_F_{OLD,NEW}VALUE*/ + pmc_id_t pm_pmcid; /* pmc id */ + pmc_value_t pm_value; /* new&returned value */ +}; + + +/* + * OP GETPMCINFO + * + * retrieve PMC state for a named CPU. The caller is expected to + * allocate 'npmc' * 'struct pmc_info' bytes of space for the return + * values. + */ + +struct pmc_info { + char pm_name[PMC_NAME_MAX]; /* pmc name */ + enum pmc_class pm_class; /* enum pmc_class */ + int pm_enabled; /* whether enabled */ + enum pmc_disp pm_rowdisp; /* FREE, THREAD or STANDLONE */ + pid_t pm_ownerpid; /* owner, or -1 */ + enum pmc_mode pm_mode; /* current mode [enum pmc_mode] */ + enum pmc_event pm_event; /* current event */ + uint32_t pm_flags; /* current flags */ + pmc_value_t pm_reloadcount; /* sampling counters only */ +}; + +struct pmc_op_getpmcinfo { + int32_t pm_cpu; /* 0 <= cpu < mp_maxid */ + struct pmc_info pm_pmcs[]; /* space for 'npmc' structures */ +}; + + +/* + * OP GETCPUINFO + * + * Retrieve system CPU information. + */ + + +struct pmc_classinfo { + enum pmc_class pm_class; /* class id */ + uint32_t pm_caps; /* counter capabilities */ + uint32_t pm_width; /* width of the PMC */ + uint32_t pm_num; /* number of PMCs in class */ +}; + +struct pmc_op_getcpuinfo { + enum pmc_cputype pm_cputype; /* what kind of CPU */ + uint32_t pm_ncpu; /* max CPU number */ + uint32_t pm_npmc; /* #PMCs per CPU */ + uint32_t pm_nclass; /* #classes of PMCs */ + struct pmc_classinfo pm_classes[PMC_CLASS_MAX]; +}; + +/* + * OP CONFIGURELOG + * + * Configure a log file for writing system-wide statistics to. + */ + +struct pmc_op_configurelog { + int pm_flags; + int pm_logfd; /* logfile fd (or -1) */ +}; + +/* + * OP GETDRIVERSTATS + * + * Retrieve pmc(4) driver-wide statistics. + */ +#ifdef _KERNEL +struct pmc_driverstats { + counter_u64_t pm_intr_ignored; /* #interrupts ignored */ + counter_u64_t pm_intr_processed; /* #interrupts processed */ + counter_u64_t pm_intr_bufferfull; /* #interrupts with ENOSPC */ + counter_u64_t pm_syscalls; /* #syscalls */ + counter_u64_t pm_syscall_errors; /* #syscalls with errors */ + counter_u64_t pm_buffer_requests; /* #buffer requests */ + counter_u64_t pm_buffer_requests_failed; /* #failed buffer requests */ + counter_u64_t pm_log_sweeps; /* #sample buffer processing + passes */ + counter_u64_t pm_merges; /* merged k+u */ + counter_u64_t pm_overwrites; /* UR overwrites */ +}; +#endif + +struct pmc_op_getdriverstats { + unsigned int pm_intr_ignored; /* #interrupts ignored */ + unsigned int pm_intr_processed; /* #interrupts processed */ + unsigned int pm_intr_bufferfull; /* #interrupts with ENOSPC */ + unsigned int pm_syscalls; /* #syscalls */ + unsigned int pm_syscall_errors; /* #syscalls with errors */ + unsigned int pm_buffer_requests; /* #buffer requests */ + unsigned int pm_buffer_requests_failed; /* #failed buffer requests */ + unsigned int pm_log_sweeps; /* #sample buffer processing + passes */ +}; + +/* + * OP RELEASE / OP START / OP STOP + * + * Simple operations on a PMC id. + */ + +struct pmc_op_simple { + pmc_id_t pm_pmcid; +}; + +/* + * OP WRITELOG + * + * Flush the current log buffer and write 4 bytes of user data to it. + */ + +struct pmc_op_writelog { + uint32_t pm_userdata; +}; + +/* + * OP GETMSR + * + * Retrieve the machine specific address associated with the allocated + * PMC. This number can be used subsequently with a read-performance-counter + * instruction. + */ + +struct pmc_op_getmsr { + uint32_t pm_msr; /* machine specific address */ + pmc_id_t pm_pmcid; /* allocated pmc id */ +}; + +/* + * OP GETDYNEVENTINFO + * + * Retrieve a PMC dynamic class events list. + */ + +struct pmc_dyn_event_descr { + char pm_ev_name[PMC_NAME_MAX]; + enum pmc_event pm_ev_code; +}; + +struct pmc_op_getdyneventinfo { + enum pmc_class pm_class; + unsigned int pm_nevent; + struct pmc_dyn_event_descr pm_events[PMC_EV_DYN_COUNT]; +}; + +#ifdef _KERNEL + +#include +#include +#include + +#include + +#define PMC_HASH_SIZE 1024 +#define PMC_MTXPOOL_SIZE 2048 +#define PMC_LOG_BUFFER_SIZE 256 +#define PMC_NLOGBUFFERS_PCPU 32 +#define PMC_NSAMPLES 256 +#define PMC_CALLCHAIN_DEPTH 128 +#define PMC_THREADLIST_MAX 128 + +#define PMC_SYSCTL_NAME_PREFIX "kern." PMC_MODULE_NAME "." + +/* + * Locking keys + * + * (b) - pmc_bufferlist_mtx (spin lock) + * (k) - pmc_kthread_mtx (sleep lock) + * (o) - po->po_mtx (spin lock) + * (g) - global_epoch_preempt (epoch) + * (p) - pmc_sx (sx) + */ + +/* + * PMC commands + */ + +struct pmc_syscall_args { + register_t pmop_code; /* one of PMC_OP_* */ + void *pmop_data; /* syscall parameter */ +}; + +/* + * Interface to processor specific s1tuff + */ + +/* + * struct pmc_descr + * + * Machine independent (i.e., the common parts) of a human readable + * PMC description. + */ + +struct pmc_descr { + char pd_name[PMC_NAME_MAX]; /* name */ + uint32_t pd_caps; /* capabilities */ + enum pmc_class pd_class; /* class of the PMC */ + uint32_t pd_width; /* width in bits */ +}; + +/* + * struct pmc_target + * + * This structure records all the target processes associated with a + * PMC. + */ + +struct pmc_target { + LIST_ENTRY(pmc_target) pt_next; + struct pmc_process *pt_process; /* target descriptor */ +}; + +/* + * struct pmc + * + * Describes each allocated PMC. + * + * Each PMC has precisely one owner, namely the process that allocated + * the PMC. + * + * A PMC may be attached to multiple target processes. The + * 'pm_targets' field links all the target processes being monitored + * by this PMC. + * + * The 'pm_savedvalue' field is protected by a mutex. + * + * On a multi-cpu machine, multiple target threads associated with a + * process-virtual PMC could be concurrently executing on different + * CPUs. The 'pm_runcount' field is atomically incremented every time + * the PMC gets scheduled on a CPU and atomically decremented when it + * get descheduled. Deletion of a PMC is only permitted when this + * field is '0'. + * + */ +struct pmc_pcpu_state { + uint8_t pps_stalled; + uint8_t pps_cpustate; +} __aligned(CACHE_LINE_SIZE); +struct pmc { + LIST_HEAD(,pmc_target) pm_targets; /* list of target processes */ + LIST_ENTRY(pmc) pm_next; /* owner's list */ + + /* + * System-wide PMCs are allocated on a CPU and are not moved + * around. For system-wide PMCs we record the CPU the PMC was + * allocated on in the 'CPU' field of the pmc ID. + * + * Virtual PMCs run on whichever CPU is currently executing + * their targets' threads. For these PMCs we need to save + * their current PMC counter values when they are taken off + * CPU. + */ + + union { + pmc_value_t pm_savedvalue; /* Virtual PMCS */ + } pm_gv; + + /* + * For sampling mode PMCs, we keep track of the PMC's "reload + * count", which is the counter value to be loaded in when + * arming the PMC for the next counting session. For counting + * modes on PMCs that are read-only (e.g., the x86 TSC), we + * keep track of the initial value at the start of + * counting-mode operation. + */ + + union { + pmc_value_t pm_reloadcount; /* sampling PMC modes */ + pmc_value_t pm_initial; /* counting PMC modes */ + } pm_sc; + + struct pmc_pcpu_state *pm_pcpu_state; + volatile cpuset_t pm_cpustate; /* CPUs where PMC should be active */ + uint32_t pm_caps; /* PMC capabilities */ + enum pmc_event pm_event; /* event being measured */ + uint32_t pm_flags; /* additional flags PMC_F_... */ + struct pmc_owner *pm_owner; /* owner thread state */ + counter_u64_t pm_runcount; /* #cpus currently on */ + enum pmc_state pm_state; /* current PMC state */ + uint32_t pm_overflowcnt; /* count overflow interrupts */ + + /* + * The PMC ID field encodes the row-index for the PMC, its + * mode, class and the CPU# associated with the PMC. + */ + + pmc_id_t pm_id; /* allocated PMC id */ + enum pmc_class pm_class; + + /* md extensions */ + union pmc_md_pmc pm_md; +}; + +/* + * Accessor macros for 'struct pmc' + */ + +#define PMC_TO_MODE(P) PMC_ID_TO_MODE((P)->pm_id) +#define PMC_TO_CLASS(P) PMC_ID_TO_CLASS((P)->pm_id) +#define PMC_TO_ROWINDEX(P) PMC_ID_TO_ROWINDEX((P)->pm_id) +#define PMC_TO_CPU(P) PMC_ID_TO_CPU((P)->pm_id) + +/* + * struct pmc_threadpmcstate + * + * Record per-PMC, per-thread state. + */ +struct pmc_threadpmcstate { + pmc_value_t pt_pmcval; /* per-thread reload count */ +}; + +/* + * struct pmc_thread + * + * Record a 'target' thread being profiled. + */ +struct pmc_thread { + LIST_ENTRY(pmc_thread) pt_next; /* linked list */ + struct thread *pt_td; /* target thread */ + struct pmc_threadpmcstate pt_pmcs[]; /* per-PMC state */ +}; + +/* + * struct pmc_process + * + * Record a 'target' process being profiled. + * + * The target process being profiled could be different from the owner + * process which allocated the PMCs. Each target process descriptor + * is associated with NHWPMC 'struct pmc *' pointers. Each PMC at a + * given hardware row-index 'n' will use slot 'n' of the 'pp_pmcs[]' + * array. The size of this structure is thus PMC architecture + * dependent. + * + */ + +struct pmc_targetstate { + struct pmc *pp_pmc; /* target PMC */ + pmc_value_t pp_pmcval; /* per-process value */ +}; + +struct pmc_process { + LIST_ENTRY(pmc_process) pp_next; /* hash chain */ + LIST_HEAD(,pmc_thread) pp_tds; /* list of threads */ + struct mtx *pp_tdslock; /* lock on pp_tds thread list */ + int pp_refcnt; /* reference count */ + uint32_t pp_flags; /* flags PMC_PP_* */ + struct proc *pp_proc; /* target process */ + struct pmc_targetstate pp_pmcs[]; /* NHWPMCs */ +}; + +#define PMC_PP_ENABLE_MSR_ACCESS 0x00000001 + +/* + * struct pmc_owner + * + * We associate a PMC with an 'owner' process. + * + * A process can be associated with 0..NCPUS*NHWPMC PMCs during its + * lifetime, where NCPUS is the numbers of CPUS in the system and + * NHWPMC is the number of hardware PMCs per CPU. These are + * maintained in the list headed by the 'po_pmcs' to save on space. + * + */ + +struct pmc_owner { + LIST_ENTRY(pmc_owner) po_next; /* hash chain */ + CK_LIST_ENTRY(pmc_owner) po_ssnext; /* (g/p) list of SS PMC owners */ + LIST_HEAD(, pmc) po_pmcs; /* owned PMC list */ + TAILQ_HEAD(, pmclog_buffer) po_logbuffers; /* (o) logbuffer list */ + struct mtx po_mtx; /* spin lock for (o) */ + struct proc *po_owner; /* owner proc */ + uint32_t po_flags; /* (k) flags PMC_PO_* */ + struct proc *po_kthread; /* (k) helper kthread */ + struct file *po_file; /* file reference */ + int po_error; /* recorded error */ + short po_sscount; /* # SS PMCs owned */ + short po_logprocmaps; /* global mappings done */ + struct pmclog_buffer *po_curbuf[MAXCPU]; /* current log buffer */ +}; + +#define PMC_PO_OWNS_LOGFILE 0x00000001 /* has a log file */ +#define PMC_PO_SHUTDOWN 0x00000010 /* in the process of shutdown */ +#define PMC_PO_INITIAL_MAPPINGS_DONE 0x00000020 + +/* + * struct pmc_hw -- describe the state of the PMC hardware + * + * When in use, a HW PMC is associated with one allocated 'struct pmc' + * pointed to by field 'phw_pmc'. When inactive, this field is NULL. + * + * On an SMP box, one or more HW PMC's in process virtual mode with + * the same 'phw_pmc' could be executing on different CPUs. In order + * to handle this case correctly, we need to ensure that only + * incremental counts get added to the saved value in the associated + * 'struct pmc'. The 'phw_save' field is used to keep the saved PMC + * value at the time the hardware is started during this context + * switch (i.e., the difference between the new (hardware) count and + * the saved count is atomically added to the count field in 'struct + * pmc' at context switch time). + * + */ + +struct pmc_hw { + uint32_t phw_state; /* see PHW_* macros below */ + struct pmc *phw_pmc; /* current thread PMC */ +}; + +#define PMC_PHW_RI_MASK 0x000000FF +#define PMC_PHW_CPU_SHIFT 8 +#define PMC_PHW_CPU_MASK 0x0000FF00 +#define PMC_PHW_FLAGS_SHIFT 16 +#define PMC_PHW_FLAGS_MASK 0xFFFF0000 + +#define PMC_PHW_INDEX_TO_STATE(ri) ((ri) & PMC_PHW_RI_MASK) +#define PMC_PHW_STATE_TO_INDEX(state) ((state) & PMC_PHW_RI_MASK) +#define PMC_PHW_CPU_TO_STATE(cpu) (((cpu) << PMC_PHW_CPU_SHIFT) & \ + PMC_PHW_CPU_MASK) +#define PMC_PHW_STATE_TO_CPU(state) (((state) & PMC_PHW_CPU_MASK) >> \ + PMC_PHW_CPU_SHIFT) +#define PMC_PHW_FLAGS_TO_STATE(flags) (((flags) << PMC_PHW_FLAGS_SHIFT) & \ + PMC_PHW_FLAGS_MASK) +#define PMC_PHW_STATE_TO_FLAGS(state) (((state) & PMC_PHW_FLAGS_MASK) >> \ + PMC_PHW_FLAGS_SHIFT) +#define PMC_PHW_FLAG_IS_ENABLED (PMC_PHW_FLAGS_TO_STATE(0x01)) +#define PMC_PHW_FLAG_IS_SHAREABLE (PMC_PHW_FLAGS_TO_STATE(0x02)) + +/* + * struct pmc_sample + * + * Space for N (tunable) PC samples and associated control data. + */ + +struct pmc_sample { + uint16_t ps_nsamples; /* callchain depth */ + uint16_t ps_nsamples_actual; + uint16_t ps_cpu; /* cpu number */ + uint16_t ps_flags; /* other flags */ + lwpid_t ps_tid; /* thread id */ + pid_t ps_pid; /* process PID or -1 */ + int ps_ticks; /* ticks at sample time */ + /* pad */ + struct thread *ps_td; /* which thread */ + struct pmc *ps_pmc; /* interrupting PMC */ + uintptr_t *ps_pc; /* (const) callchain start */ + uint64_t ps_tsc; /* tsc value */ +}; + +#define PMC_SAMPLE_FREE ((uint16_t) 0) +#define PMC_USER_CALLCHAIN_PENDING ((uint16_t) 0xFFFF) + +struct pmc_samplebuffer { + volatile uint64_t ps_prodidx; /* producer index */ + volatile uint64_t ps_considx; /* consumer index */ + uintptr_t *ps_callchains; /* all saved call chains */ + struct pmc_sample ps_samples[]; /* array of sample entries */ +}; + +#define PMC_CONS_SAMPLE(psb) \ + (&(psb)->ps_samples[(psb)->ps_considx & pmc_sample_mask]) + +#define PMC_CONS_SAMPLE_OFF(psb, off) \ + (&(psb)->ps_samples[(off) & pmc_sample_mask]) + +#define PMC_PROD_SAMPLE(psb) \ + (&(psb)->ps_samples[(psb)->ps_prodidx & pmc_sample_mask]) + +/* + * struct pmc_cpustate + * + * A CPU is modelled as a collection of HW PMCs with space for additional + * flags. + */ + +struct pmc_cpu { + uint32_t pc_state; /* physical cpu number + flags */ + struct pmc_samplebuffer *pc_sb[3]; /* space for samples */ + struct pmc_hw *pc_hwpmcs[]; /* 'npmc' pointers */ +}; + +#define PMC_PCPU_CPU_MASK 0x000000FF +#define PMC_PCPU_FLAGS_MASK 0xFFFFFF00 +#define PMC_PCPU_FLAGS_SHIFT 8 +#define PMC_PCPU_STATE_TO_CPU(S) ((S) & PMC_PCPU_CPU_MASK) +#define PMC_PCPU_STATE_TO_FLAGS(S) (((S) & PMC_PCPU_FLAGS_MASK) >> PMC_PCPU_FLAGS_SHIFT) +#define PMC_PCPU_FLAGS_TO_STATE(F) (((F) << PMC_PCPU_FLAGS_SHIFT) & PMC_PCPU_FLAGS_MASK) +#define PMC_PCPU_CPU_TO_STATE(C) ((C) & PMC_PCPU_CPU_MASK) +#define PMC_PCPU_FLAG_HTT (PMC_PCPU_FLAGS_TO_STATE(0x1)) + +/* + * struct pmc_binding + * + * CPU binding information. + */ + +struct pmc_binding { + int pb_bound; /* is bound? */ + int pb_cpu; /* if so, to which CPU */ +}; + + +struct pmc_mdep; + +/* + * struct pmc_classdep + * + * PMC class-dependent operations. + */ +struct pmc_classdep { + uint32_t pcd_caps; /* class capabilities */ + enum pmc_class pcd_class; /* class id */ + int pcd_num; /* number of PMCs */ + int pcd_ri; /* row index of the first PMC in class */ + int pcd_width; /* width of the PMC */ + + /* configuring/reading/writing the hardware PMCs */ + int (*pcd_config_pmc)(int _cpu, int _ri, struct pmc *_pm); + int (*pcd_get_config)(int _cpu, int _ri, struct pmc **_ppm); + int (*pcd_read_pmc)(int _cpu, int _ri, pmc_value_t *_value); + int (*pcd_write_pmc)(int _cpu, int _ri, pmc_value_t _value); + + /* pmc allocation/release */ + int (*pcd_allocate_pmc)(int _cpu, int _ri, struct pmc *_t, + const struct pmc_op_pmcallocate *_a); + int (*pcd_release_pmc)(int _cpu, int _ri, struct pmc *_pm); + + /* starting and stopping PMCs */ + int (*pcd_start_pmc)(int _cpu, int _ri); + int (*pcd_stop_pmc)(int _cpu, int _ri); + + /* description */ + int (*pcd_describe)(int _cpu, int _ri, struct pmc_info *_pi, + struct pmc **_ppmc); + + /* class-dependent initialization & finalization */ + int (*pcd_pcpu_init)(struct pmc_mdep *_md, int _cpu); + int (*pcd_pcpu_fini)(struct pmc_mdep *_md, int _cpu); + + /* machine-specific interface */ + int (*pcd_get_msr)(int _ri, uint32_t *_msr); +}; + +/* + * struct pmc_mdep + * + * Machine dependent bits needed per CPU type. + */ + +struct pmc_mdep { + uint32_t pmd_cputype; /* from enum pmc_cputype */ + uint32_t pmd_npmc; /* number of PMCs per CPU */ + uint32_t pmd_nclass; /* number of PMC classes present */ + + /* + * Machine dependent methods. + */ + + /* per-cpu initialization and finalization */ + int (*pmd_pcpu_init)(struct pmc_mdep *_md, int _cpu); + int (*pmd_pcpu_fini)(struct pmc_mdep *_md, int _cpu); + + /* thread context switch in/out */ + int (*pmd_switch_in)(struct pmc_cpu *_p, struct pmc_process *_pp); + int (*pmd_switch_out)(struct pmc_cpu *_p, struct pmc_process *_pp); + + /* handle a PMC interrupt */ + int (*pmd_intr)(struct trapframe *_tf); + + /* + * PMC class dependent information. + */ + struct pmc_classdep pmd_classdep[]; +}; + +/* + * Per-CPU state. This is an array of 'mp_ncpu' pointers + * to struct pmc_cpu descriptors. + */ + +extern struct pmc_cpu **pmc_pcpu; + +/* driver statistics */ +extern struct pmc_driverstats pmc_stats; + +#if defined(HWPMC_DEBUG) +#include + +/* debug flags, major flag groups */ +struct pmc_debugflags { + int pdb_CPU; + int pdb_CSW; + int pdb_LOG; + int pdb_MDP; + int pdb_MOD; + int pdb_OWN; + int pdb_PMC; + int pdb_PRC; + int pdb_SAM; +}; + +extern struct pmc_debugflags pmc_debugflags; + +#define KTR_PMC KTR_SUBSYS + +#define PMC_DEBUG_STRSIZE 128 +#define PMC_DEBUG_DEFAULT_FLAGS { 0, 0, 0, 0, 0, 0, 0, 0, 0 } + +#define PMCDBG0(M, N, L, F) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR0(KTR_PMC, #M ":" #N ":" #L ": " F); \ +} while (0) +#define PMCDBG1(M, N, L, F, p1) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR1(KTR_PMC, #M ":" #N ":" #L ": " F, p1); \ +} while (0) +#define PMCDBG2(M, N, L, F, p1, p2) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR2(KTR_PMC, #M ":" #N ":" #L ": " F, p1, p2); \ +} while (0) +#define PMCDBG3(M, N, L, F, p1, p2, p3) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR3(KTR_PMC, #M ":" #N ":" #L ": " F, p1, p2, p3); \ +} while (0) +#define PMCDBG4(M, N, L, F, p1, p2, p3, p4) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR4(KTR_PMC, #M ":" #N ":" #L ": " F, p1, p2, p3, p4);\ +} while (0) +#define PMCDBG5(M, N, L, F, p1, p2, p3, p4, p5) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR5(KTR_PMC, #M ":" #N ":" #L ": " F, p1, p2, p3, p4, \ + p5); \ +} while (0) +#define PMCDBG6(M, N, L, F, p1, p2, p3, p4, p5, p6) do { \ + if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \ + CTR6(KTR_PMC, #M ":" #N ":" #L ": " F, p1, p2, p3, p4, \ + p5, p6); \ +} while (0) + +/* Major numbers */ +#define PMC_DEBUG_MAJ_CPU 0 /* cpu switches */ +#define PMC_DEBUG_MAJ_CSW 1 /* context switches */ +#define PMC_DEBUG_MAJ_LOG 2 /* logging */ +#define PMC_DEBUG_MAJ_MDP 3 /* machine dependent */ +#define PMC_DEBUG_MAJ_MOD 4 /* misc module infrastructure */ +#define PMC_DEBUG_MAJ_OWN 5 /* owner */ +#define PMC_DEBUG_MAJ_PMC 6 /* pmc management */ +#define PMC_DEBUG_MAJ_PRC 7 /* processes */ +#define PMC_DEBUG_MAJ_SAM 8 /* sampling */ + +/* Minor numbers */ + +/* Common (8 bits) */ +#define PMC_DEBUG_MIN_ALL 0 /* allocation */ +#define PMC_DEBUG_MIN_REL 1 /* release */ +#define PMC_DEBUG_MIN_OPS 2 /* ops: start, stop, ... */ +#define PMC_DEBUG_MIN_INI 3 /* init */ +#define PMC_DEBUG_MIN_FND 4 /* find */ + +/* MODULE */ +#define PMC_DEBUG_MIN_PMH 14 /* pmc_hook */ +#define PMC_DEBUG_MIN_PMS 15 /* pmc_syscall */ + +/* OWN */ +#define PMC_DEBUG_MIN_ORM 8 /* owner remove */ +#define PMC_DEBUG_MIN_OMR 9 /* owner maybe remove */ + +/* PROCESSES */ +#define PMC_DEBUG_MIN_TLK 8 /* link target */ +#define PMC_DEBUG_MIN_TUL 9 /* unlink target */ +#define PMC_DEBUG_MIN_EXT 10 /* process exit */ +#define PMC_DEBUG_MIN_EXC 11 /* process exec */ +#define PMC_DEBUG_MIN_FRK 12 /* process fork */ +#define PMC_DEBUG_MIN_ATT 13 /* attach/detach */ +#define PMC_DEBUG_MIN_SIG 14 /* signalling */ + +/* CONTEXT SWITCHES */ +#define PMC_DEBUG_MIN_SWI 8 /* switch in */ +#define PMC_DEBUG_MIN_SWO 9 /* switch out */ + +/* PMC */ +#define PMC_DEBUG_MIN_REG 8 /* pmc register */ +#define PMC_DEBUG_MIN_ALR 9 /* allocate row */ + +/* MACHINE DEPENDENT LAYER */ +#define PMC_DEBUG_MIN_REA 8 /* read */ +#define PMC_DEBUG_MIN_WRI 9 /* write */ +#define PMC_DEBUG_MIN_CFG 10 /* config */ +#define PMC_DEBUG_MIN_STA 11 /* start */ +#define PMC_DEBUG_MIN_STO 12 /* stop */ +#define PMC_DEBUG_MIN_INT 13 /* interrupts */ + +/* CPU */ +#define PMC_DEBUG_MIN_BND 8 /* bind */ +#define PMC_DEBUG_MIN_SEL 9 /* select */ + +/* LOG */ +#define PMC_DEBUG_MIN_GTB 8 /* get buf */ +#define PMC_DEBUG_MIN_SIO 9 /* schedule i/o */ +#define PMC_DEBUG_MIN_FLS 10 /* flush */ +#define PMC_DEBUG_MIN_SAM 11 /* sample */ +#define PMC_DEBUG_MIN_CLO 12 /* close */ + +#else +#define PMCDBG0(M, N, L, F) /* nothing */ +#define PMCDBG1(M, N, L, F, p1) +#define PMCDBG2(M, N, L, F, p1, p2) +#define PMCDBG3(M, N, L, F, p1, p2, p3) +#define PMCDBG4(M, N, L, F, p1, p2, p3, p4) +#define PMCDBG5(M, N, L, F, p1, p2, p3, p4, p5) +#define PMCDBG6(M, N, L, F, p1, p2, p3, p4, p5, p6) +#endif + +/* declare a dedicated memory pool */ +MALLOC_DECLARE(M_PMC); + +/* + * Functions + */ + +struct pmc_mdep *pmc_md_initialize(void); /* MD init function */ +void pmc_md_finalize(struct pmc_mdep *_md); /* MD fini function */ +int pmc_getrowdisp(int _ri); +int pmc_process_interrupt(int _ring, struct pmc *_pm, struct trapframe *_tf); +int pmc_save_kernel_callchain(uintptr_t *_cc, int _maxsamples, + struct trapframe *_tf); +int pmc_save_user_callchain(uintptr_t *_cc, int _maxsamples, + struct trapframe *_tf); +struct pmc_mdep *pmc_mdep_alloc(int nclasses); +void pmc_mdep_free(struct pmc_mdep *md); +uint64_t pmc_rdtsc(void); +#endif /* _KERNEL */ +#endif /* _SYS_PMC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pmckern.h b/lib/libc/include/any-freebsd-any/sys/pmckern.h new file mode 100644 index 000000000000..e892d658a1ca --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pmckern.h @@ -0,0 +1,272 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003-2007, Joseph Koshy + * Copyright (c) 2007 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by A. Joseph Koshy under + * sponsorship from the FreeBSD Foundation and Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * PMC interface used by the base kernel. + */ + +#ifndef _SYS_PMCKERN_H_ +#define _SYS_PMCKERN_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PMC_FN_PROCESS_EXEC 1 +#define PMC_FN_CSW_IN 2 +#define PMC_FN_CSW_OUT 3 +#define PMC_FN_DO_SAMPLES 4 +#define PMC_FN_UNUSED1 5 +#define PMC_FN_UNUSED2 6 +#define PMC_FN_MMAP 7 +#define PMC_FN_MUNMAP 8 +#define PMC_FN_USER_CALLCHAIN 9 +#define PMC_FN_USER_CALLCHAIN_SOFT 10 +#define PMC_FN_SOFT_SAMPLING 11 +#define PMC_FN_THR_CREATE 12 +#define PMC_FN_THR_EXIT 13 +#define PMC_FN_THR_USERRET 14 +#define PMC_FN_THR_CREATE_LOG 15 +#define PMC_FN_THR_EXIT_LOG 16 +#define PMC_FN_PROC_CREATE_LOG 17 + +typedef enum ring_type { + PMC_HR = 0, /* Hardware ring buffer */ + PMC_SR = 1, /* Software ring buffer */ + PMC_UR = 2, /* userret ring buffer */ + PMC_NUM_SR = PMC_UR+1 +} ring_type_t; + +struct pmckern_procexec { + int pm_credentialschanged; + uintfptr_t pm_entryaddr; +}; + +struct pmckern_map_in { + void *pm_file; /* filename or vnode pointer */ + uintfptr_t pm_address; /* address object is loaded at */ +}; + +struct pmckern_map_out { + uintfptr_t pm_address; /* start address of region */ + size_t pm_size; /* size of unmapped region */ +}; + +struct pmckern_soft { + enum pmc_event pm_ev; + int pm_cpu; + struct trapframe *pm_tf; +}; + +/* + * Soft PMC. + */ + +#define PMC_SOFT_DEFINE_EX(prov, mod, func, name, alloc, release) \ + struct pmc_soft pmc_##prov##_##mod##_##func##_##name = \ + { 0, alloc, release, { #prov "_" #mod "_" #func "." #name, 0 } }; \ + SYSINIT(pmc_##prov##_##mod##_##func##_##name##_init, SI_SUB_KDTRACE, \ + SI_ORDER_SECOND + 1, pmc_soft_ev_register, \ + &pmc_##prov##_##mod##_##func##_##name ); \ + SYSUNINIT(pmc_##prov##_##mod##_##func##_##name##_uninit, \ + SI_SUB_KDTRACE, SI_ORDER_SECOND + 1, pmc_soft_ev_deregister, \ + &pmc_##prov##_##mod##_##func##_##name ) + +#define PMC_SOFT_DEFINE(prov, mod, func, name) \ + PMC_SOFT_DEFINE_EX(prov, mod, func, name, NULL, NULL) + +#define PMC_SOFT_DECLARE(prov, mod, func, name) \ + extern struct pmc_soft pmc_##prov##_##mod##_##func##_##name + +/* + * PMC_SOFT_CALL can be used anywhere in the kernel. + * Require md defined PMC_FAKE_TRAPFRAME. + */ +#ifdef PMC_FAKE_TRAPFRAME +#define PMC_SOFT_CALL(pr, mo, fu, na) \ +do { \ + if (__predict_false(pmc_##pr##_##mo##_##fu##_##na.ps_running)) { \ + struct pmckern_soft ks; \ + register_t intr; \ + intr = intr_disable(); \ + PMC_FAKE_TRAPFRAME(&pmc_tf[curcpu]); \ + ks.pm_ev = pmc_##pr##_##mo##_##fu##_##na.ps_ev.pm_ev_code; \ + ks.pm_cpu = PCPU_GET(cpuid); \ + ks.pm_tf = &pmc_tf[curcpu]; \ + PMC_CALL_HOOK_UNLOCKED(curthread, \ + PMC_FN_SOFT_SAMPLING, (void *) &ks); \ + intr_restore(intr); \ + } \ +} while (0) +#else +#define PMC_SOFT_CALL(pr, mo, fu, na) \ +do { \ +} while (0) +#endif + +/* + * PMC_SOFT_CALL_TF need to be used carefully. + * Userland capture will be done during AST processing. + */ +#define PMC_SOFT_CALL_TF(pr, mo, fu, na, tf) \ +do { \ + if (__predict_false(pmc_##pr##_##mo##_##fu##_##na.ps_running)) { \ + struct pmckern_soft ks; \ + register_t intr; \ + intr = intr_disable(); \ + ks.pm_ev = pmc_##pr##_##mo##_##fu##_##na.ps_ev.pm_ev_code; \ + ks.pm_cpu = PCPU_GET(cpuid); \ + ks.pm_tf = tf; \ + PMC_CALL_HOOK_UNLOCKED(curthread, \ + PMC_FN_SOFT_SAMPLING, (void *) &ks); \ + intr_restore(intr); \ + } \ +} while (0) + +struct pmc_soft { + int ps_running; + void (*ps_alloc)(void); + void (*ps_release)(void); + struct pmc_dyn_event_descr ps_ev; +}; + +struct pmclog_buffer; + +struct pmc_domain_buffer_header { + struct mtx pdbh_mtx; + TAILQ_HEAD(, pmclog_buffer) pdbh_head; + struct pmclog_buffer *pdbh_plbs; + int pdbh_ncpus; +} __aligned(CACHE_LINE_SIZE); + +/* hook */ +extern int (*pmc_hook)(struct thread *_td, int _function, void *_arg); +extern int (*pmc_intr)(struct trapframe *_frame); + +/* SX lock protecting the hook */ +extern struct sx pmc_sx; + +/* Per-cpu flags indicating availability of sampling data */ +DPCPU_DECLARE(uint8_t, pmc_sampled); + +/* Count of system-wide sampling PMCs in existence */ +extern volatile int pmc_ss_count; + +/* kernel version number */ +extern const int pmc_kernel_version; + +/* PMC soft per cpu trapframe */ +extern struct trapframe pmc_tf[MAXCPU]; + +/* per domain buffer header list */ +extern struct pmc_domain_buffer_header *pmc_dom_hdrs[MAXMEMDOM]; + +/* Quick check if preparatory work is necessary */ +#define PMC_HOOK_INSTALLED(cmd) __predict_false(pmc_hook != NULL) + +/* Hook invocation; for use within the kernel */ +#define PMC_CALL_HOOK(t, cmd, arg) \ +do { \ + struct epoch_tracker et; \ + epoch_enter_preempt(global_epoch_preempt, &et); \ + if (pmc_hook != NULL) \ + (pmc_hook)((t), (cmd), (arg)); \ + epoch_exit_preempt(global_epoch_preempt, &et); \ +} while (0) + +/* Hook invocation that needs an exclusive lock */ +#define PMC_CALL_HOOK_X(t, cmd, arg) \ +do { \ + sx_xlock(&pmc_sx); \ + if (pmc_hook != NULL) \ + (pmc_hook)((t), (cmd), (arg)); \ + sx_xunlock(&pmc_sx); \ +} while (0) + +/* + * Some hook invocations (e.g., from context switch and clock handling + * code) need to be lock-free. + */ +#define PMC_CALL_HOOK_UNLOCKED(t, cmd, arg) \ +do { \ + if (pmc_hook != NULL) \ + (pmc_hook)((t), (cmd), (arg)); \ +} while (0) + +#define PMC_SWITCH_CONTEXT(t,cmd) PMC_CALL_HOOK_UNLOCKED(t,cmd,NULL) + +/* Check if a process is using HWPMCs.*/ +#define PMC_PROC_IS_USING_PMCS(p) \ + (__predict_false(p->p_flag & P_HWPMC)) + +#define PMC_THREAD_HAS_SAMPLES(td) \ + (__predict_false((td)->td_pmcpend)) + +/* Check if a thread have pending user capture. */ +#define PMC_IS_PENDING_CALLCHAIN(p) \ + (__predict_false((p)->td_pflags & TDP_CALLCHAIN)) + +#define PMC_SYSTEM_SAMPLING_ACTIVE() (pmc_ss_count > 0) + +/* Check if a CPU has recorded samples. */ +#define PMC_CPU_HAS_SAMPLES(C) (__predict_false(DPCPU_ID_GET((C), pmc_sampled))) + +/* + * Helper functions. + */ +int pmc_cpu_is_disabled(int _cpu); /* deprecated */ +int pmc_cpu_is_active(int _cpu); +int pmc_cpu_is_present(int _cpu); +int pmc_cpu_is_primary(int _cpu); +unsigned int pmc_cpu_max(void); + +#ifdef INVARIANTS +int pmc_cpu_max_active(void); +#endif + +/* + * Soft events functions. + */ +void pmc_soft_ev_register(struct pmc_soft *ps); +void pmc_soft_ev_deregister(struct pmc_soft *ps); +struct pmc_soft *pmc_soft_ev_acquire(enum pmc_event ev); +void pmc_soft_ev_release(struct pmc_soft *ps); + +#endif /* _SYS_PMCKERN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/pmclog.h b/lib/libc/include/any-freebsd-any/sys/pmclog.h new file mode 100644 index 000000000000..51a8a20d14a6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/pmclog.h @@ -0,0 +1,326 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005-2007, Joseph Koshy + * Copyright (c) 2007 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by A. Joseph Koshy under + * sponsorship from the FreeBSD Foundation and Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PMCLOG_H_ +#define _SYS_PMCLOG_H_ + +#include + +enum pmclog_type { + /* V1 ABI */ + PMCLOG_TYPE_CLOSELOG = 1, + PMCLOG_TYPE_DROPNOTIFY = 2, + PMCLOG_TYPE_INITIALIZE = 3, + + PMCLOG_TYPE_PMCALLOCATE = 5, + PMCLOG_TYPE_PMCATTACH = 6, + PMCLOG_TYPE_PMCDETACH = 7, + PMCLOG_TYPE_PROCCSW = 8, + PMCLOG_TYPE_PROCEXEC = 9, + PMCLOG_TYPE_PROCEXIT = 10, + PMCLOG_TYPE_PROCFORK = 11, + PMCLOG_TYPE_SYSEXIT = 12, + PMCLOG_TYPE_USERDATA = 13, + /* + * V2 ABI + * + * The MAP_{IN,OUT} event types obsolete the MAPPING_CHANGE + * event type. The CALLCHAIN event type obsoletes the + * PCSAMPLE event type. + */ + PMCLOG_TYPE_MAP_IN = 14, + PMCLOG_TYPE_MAP_OUT = 15, + PMCLOG_TYPE_CALLCHAIN = 16, + /* + * V3 ABI + * + * New variant of PMCLOG_TYPE_PMCALLOCATE for dynamic event. + */ + PMCLOG_TYPE_PMCALLOCATEDYN = 17, + /* + * V6 ABI + */ + PMCLOG_TYPE_THR_CREATE = 18, + PMCLOG_TYPE_THR_EXIT = 19, + PMCLOG_TYPE_PROC_CREATE = 20 +}; + +/* + * A log entry descriptor comprises of a 32 bit header and a 64 bit + * time stamp followed by as many 32 bit words are required to record + * the event. + * + * Header field format: + * + * 31 24 16 0 + * +------------+------------+-----------------------------------+ + * | MAGIC | TYPE | LENGTH | + * +------------+------------+-----------------------------------+ + * + * MAGIC is the constant PMCLOG_HEADER_MAGIC. + * TYPE contains a value of type enum pmclog_type. + * LENGTH contains the length of the event record, in bytes. + */ + +#define PMCLOG_ENTRY_HEADER \ + uint32_t pl_header; \ + uint32_t pl_spare; \ + uint64_t pl_tsc; \ + +struct pmclog_header { + PMCLOG_ENTRY_HEADER; +}; + +/* + * The following structures are used to describe the size of each kind + * of log entry to sizeof(). To keep the compiler from adding + * padding, the fields of each structure are aligned to their natural + * boundaries, and the structures are marked as 'packed'. + * + * The actual reading and writing of the log file is always in terms + * of 4 byte quantities. + */ + +struct pmclog_callchain { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_tid; + uint32_t pl_pmcid; + uint32_t pl_cpuflags; + /* 8 byte aligned */ + uintptr_t pl_pc[PMC_CALLCHAIN_DEPTH_MAX]; +} __packed; + +#define PMC_CALLCHAIN_CPUFLAGS_TO_CPU(CF) (((CF) >> 16) & 0xFFFF) +#define PMC_CALLCHAIN_CPUFLAGS_TO_USERMODE(CF) ((CF) & PMC_CC_F_USERSPACE) +#define PMC_CALLCHAIN_TO_CPUFLAGS(CPU,FLAGS) \ + (((CPU) << 16) | ((FLAGS) & 0xFFFF)) + +struct pmclog_closelog { + PMCLOG_ENTRY_HEADER +}; + +struct pmclog_dropnotify { + PMCLOG_ENTRY_HEADER +}; + +struct pmclog_initialize { + PMCLOG_ENTRY_HEADER + uint32_t pl_version; /* driver version */ + uint32_t pl_cpu; /* enum pmc_cputype */ + uint64_t pl_tsc_freq; + struct timespec pl_ts; + char pl_cpuid[PMC_CPUID_LEN]; +} __packed; + +struct pmclog_map_in { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_pad; + uintfptr_t pl_start; /* 8 byte aligned */ + char pl_pathname[PATH_MAX]; +} __packed; + +struct pmclog_map_out { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_pad; + uintfptr_t pl_start; /* 8 byte aligned */ + uintfptr_t pl_end; +} __packed; + +struct pmclog_pmcallocate { + PMCLOG_ENTRY_HEADER + uint32_t pl_pmcid; + uint32_t pl_event; + uint32_t pl_flags; + uint32_t pl_pad; + uint64_t pl_rate; +} __packed; + +struct pmclog_pmcattach { + PMCLOG_ENTRY_HEADER + uint32_t pl_pmcid; + uint32_t pl_pid; + char pl_pathname[PATH_MAX]; +} __packed; + +struct pmclog_pmcdetach { + PMCLOG_ENTRY_HEADER + uint32_t pl_pmcid; + uint32_t pl_pid; +} __packed; + +struct pmclog_proccsw { + PMCLOG_ENTRY_HEADER + uint64_t pl_value; /* keep 8 byte aligned */ + uint32_t pl_pmcid; + uint32_t pl_pid; + uint32_t pl_tid; + uint32_t pl_pad; +} __packed; + +struct pmclog_proccreate { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_flags; + char pl_pcomm[MAXCOMLEN+1]; /* keep 8 byte aligned */ +} __packed; + +struct pmclog_procexec { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_pmcid; + uintfptr_t pl_start; /* keep 8 byte aligned */ + char pl_pathname[PATH_MAX]; +} __packed; + +struct pmclog_procexit { + PMCLOG_ENTRY_HEADER + uint32_t pl_pmcid; + uint32_t pl_pid; + uint64_t pl_value; /* keep 8 byte aligned */ +} __packed; + +struct pmclog_procfork { + PMCLOG_ENTRY_HEADER + uint32_t pl_oldpid; + uint32_t pl_newpid; +} __packed; + +struct pmclog_sysexit { + PMCLOG_ENTRY_HEADER + uint32_t pl_pid; + uint32_t pl_pad; +} __packed; + +struct pmclog_threadcreate { + PMCLOG_ENTRY_HEADER + uint32_t pl_tid; + uint32_t pl_pid; + uint32_t pl_flags; + uint32_t pl_pad; + char pl_tdname[MAXCOMLEN+1]; /* keep 8 byte aligned */ +} __packed; + +struct pmclog_threadexit { + PMCLOG_ENTRY_HEADER + uint32_t pl_tid; + uint32_t pl_pad; +} __packed; + +struct pmclog_userdata { + PMCLOG_ENTRY_HEADER + uint32_t pl_userdata; + uint32_t pl_pad; +} __packed; + +struct pmclog_pmcallocatedyn { + PMCLOG_ENTRY_HEADER + uint32_t pl_pmcid; + uint32_t pl_event; + uint32_t pl_flags; + uint32_t pl_pad; + char pl_evname[PMC_NAME_MAX]; +} __packed; + +union pmclog_entry { /* only used to size scratch areas */ + struct pmclog_callchain pl_cc; + struct pmclog_closelog pl_cl; + struct pmclog_dropnotify pl_dn; + struct pmclog_initialize pl_i; + struct pmclog_map_in pl_mi; + struct pmclog_map_out pl_mo; + struct pmclog_pmcallocate pl_a; + struct pmclog_pmcallocatedyn pl_ad; + struct pmclog_pmcattach pl_t; + struct pmclog_pmcdetach pl_d; + struct pmclog_proccsw pl_c; + struct pmclog_procexec pl_x; + struct pmclog_procexit pl_e; + struct pmclog_procfork pl_f; + struct pmclog_sysexit pl_se; + struct pmclog_userdata pl_u; +}; + +#define PMCLOG_HEADER_MAGIC 0xEEU + +#define PMCLOG_HEADER_TO_LENGTH(H) \ + ((H) & 0x0000FFFF) +#define PMCLOG_HEADER_TO_TYPE(H) \ + (((H) & 0x00FF0000) >> 16) +#define PMCLOG_HEADER_TO_MAGIC(H) \ + (((H) & 0xFF000000) >> 24) +#define PMCLOG_HEADER_CHECK_MAGIC(H) \ + (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC) + +#ifdef _KERNEL + +/* + * Prototypes + */ +int pmclog_configure_log(struct pmc_mdep *_md, struct pmc_owner *_po, + int _logfd); +int pmclog_deconfigure_log(struct pmc_owner *_po); +int pmclog_flush(struct pmc_owner *_po, int force); +int pmclog_close(struct pmc_owner *_po); +void pmclog_initialize(void); +int pmclog_proc_create(struct thread *td, void **handlep); +void pmclog_proc_ignite(void *handle, struct pmc_owner *po); +void pmclog_process_callchain(struct pmc *_pm, struct pmc_sample *_ps); +void pmclog_process_closelog(struct pmc_owner *po); +void pmclog_process_dropnotify(struct pmc_owner *po); +void pmclog_process_map_in(struct pmc_owner *po, pid_t pid, + uintfptr_t start, const char *path); +void pmclog_process_map_out(struct pmc_owner *po, pid_t pid, + uintfptr_t start, uintfptr_t end); +void pmclog_process_pmcallocate(struct pmc *_pm); +void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path); +void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid); +void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp, + pmc_value_t _v, struct thread *); +void pmclog_process_procexec(struct pmc_owner *_po, pmc_id_t _pmid, pid_t _pid, + uintfptr_t _startaddr, char *_path); +void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp); +void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid); +void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid); +void pmclog_process_threadcreate(struct pmc_owner *_po, struct thread *td, int sync); +void pmclog_process_threadexit(struct pmc_owner *_po, struct thread *td); +void pmclog_process_proccreate(struct pmc_owner *_po, struct proc *p, int sync); +int pmclog_process_userlog(struct pmc_owner *_po, + struct pmc_op_writelog *_wl); +void pmclog_shutdown(void); +#endif /* _KERNEL */ + +#endif /* _SYS_PMCLOG_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/poll.h b/lib/libc/include/any-freebsd-any/sys/poll.h new file mode 100644 index 000000000000..6805704ca39f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/poll.h @@ -0,0 +1,124 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1997 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_POLL_H_ +#define _SYS_POLL_H_ + +#include + +/* + * This file is intended to be compatible with the traditional poll.h. + */ + +typedef unsigned int nfds_t; + +/* + * This structure is passed as an array to poll(2). + */ +struct pollfd { + int fd; /* which file descriptor to poll */ + short events; /* events we are interested in */ + short revents; /* events found on return */ +}; + +/* + * Requestable events. If poll(2) finds any of these set, they are + * copied to revents on return. + * XXX Note that FreeBSD doesn't make much distinction between POLLPRI + * and POLLRDBAND since none of the file types have distinct priority + * bands - and only some have an urgent "mode". + * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV + * POLLIN includes all of normal, band and urgent data. Most poll handlers + * on FreeBSD only treat it as "normal" data. + */ +#define POLLIN 0x0001 /* any readable data available */ +#define POLLPRI 0x0002 /* OOB/Urgent readable data */ +#define POLLOUT 0x0004 /* file descriptor is writeable */ +#define POLLRDNORM 0x0040 /* non-OOB/URG data available */ +#define POLLWRNORM POLLOUT /* no write type differentiation */ +#define POLLRDBAND 0x0080 /* OOB/Urgent readable data */ +#define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */ + +#if __BSD_VISIBLE +/* General FreeBSD extension (currently only supported for sockets): */ +#define POLLINIGNEOF 0x2000 /* like POLLIN, except ignore EOF */ +#endif + +/* + * These events are set if they occur regardless of whether they were + * requested. + */ +#define POLLERR 0x0008 /* some poll error occurred */ +#define POLLHUP 0x0010 /* file descriptor was "hung up" */ +#define POLLNVAL 0x0020 /* requested events "invalid" */ + +#if __BSD_VISIBLE + +#define POLLSTANDARD (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|\ + POLLWRBAND|POLLERR|POLLHUP|POLLNVAL) + +/* + * Request that poll() wait forever. + * XXX in SYSV, this is defined in stropts.h, which is not included + * by poll.h. + */ +#define INFTIM (-1) + +#endif + +#ifndef _KERNEL + +#if __BSD_VISIBLE +#include + +#include +#include + +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif + +#endif + +__BEGIN_DECLS +int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout); +#if __BSD_VISIBLE +int ppoll(struct pollfd _pfd[], nfds_t _nfds, + const struct timespec *__restrict _timeout, + const sigset_t *__restrict _newsigmask); +#endif +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_POLL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/posix4.h b/lib/libc/include/any-freebsd-any/sys/posix4.h new file mode 100644 index 000000000000..3019c6d5ccf8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/posix4.h @@ -0,0 +1,116 @@ +#ifndef _P1003_1B_P1003_1B_H_ +#define _P1003_1B_P1003_1B_H_ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1996, 1997, 1998 + * HD Associates, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by HD Associates, Inc + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include + +/* Generate syscall stubs for when something is optionally + * loadable as a module. References "syscall_not_present". + * XXX Good candidate for sys/syscall.h + */ +struct proc; +struct nosys_args; +extern int syscall_not_present(struct thread *, const char *, struct nosys_args *); + +#define SYSCALL_NOT_PRESENT_GEN(SC) \ +int sys_ ## SC (struct thread *td, struct SC##_args *uap) \ +{ \ + return syscall_not_present(td, #SC , (struct nosys_args *)uap); \ +} + + +MALLOC_DECLARE(M_P31B); + +int p31b_proc(struct proc *, pid_t, struct proc **); + +void p31b_setcfg(int, int); +int p31b_getcfg(int); +int p31b_iscfg(int); +void p31b_unsetcfg(int); + +#ifdef _KPOSIX_PRIORITY_SCHEDULING + +/* + * KSCHED_OP_RW is a vector of read/write flags for each entry indexed + * by the enum ksched_op. + * + * 1 means you need write access, 0 means read is sufficient. + */ + +enum ksched_op { + +#define KSCHED_OP_RW { 1, 0, 1, 0, 0, 0, 0, 0 } + + SCHED_SETPARAM, + SCHED_GETPARAM, + SCHED_SETSCHEDULER, + SCHED_GETSCHEDULER, + SCHED_YIELD, + SCHED_GET_PRIORITY_MAX, + SCHED_GET_PRIORITY_MIN, + SCHED_RR_GET_INTERVAL, + SCHED_OP_MAX +}; + +struct ksched; + +int ksched_attach(struct ksched **); +int ksched_detach(struct ksched *); + +int ksched_setparam(struct ksched *, + struct thread *, const struct sched_param *); +int ksched_getparam(struct ksched *, + struct thread *, struct sched_param *); + +int ksched_setscheduler(struct ksched *, + struct thread *, int, const struct sched_param *); +int ksched_getscheduler(struct ksched *, struct thread *, int *); + +int ksched_yield(struct ksched *); + +int ksched_get_priority_max(struct ksched *, int, int *); +int ksched_get_priority_min(struct ksched *, int, int *); + +int ksched_rr_get_interval(struct ksched *, + struct thread *, struct timespec *); + +#endif /* _KPOSIX_PRIORITY_SCHEDULING */ + +#endif /* _P1003_1B_P1003_1B_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/power.h b/lib/libc/include/any-freebsd-any/sys/power.h new file mode 100644 index 000000000000..3fcc2c387d61 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/power.h @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Mitsuru IWASAKI + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_POWER_H_ +#define _SYS_POWER_H_ + +#include + +/* Power management system type */ +#define POWER_PM_TYPE_APM 0x00 +#define POWER_PM_TYPE_ACPI 0x01 +#define POWER_PM_TYPE_NONE 0xff + +/* Commands for Power management function */ +#define POWER_CMD_SUSPEND 0x00 + +/* Sleep state */ +#define POWER_SLEEP_STATE_STANDBY 0x00 +#define POWER_SLEEP_STATE_SUSPEND 0x01 +#define POWER_SLEEP_STATE_HIBERNATE 0x02 + +typedef int (*power_pm_fn_t)(u_long, void*, ...); +extern int power_pm_register(u_int, power_pm_fn_t, void *); +extern u_int power_pm_get_type(void); +extern void power_pm_suspend(int); + +/* + * System power API. + */ +#define POWER_PROFILE_PERFORMANCE 0 +#define POWER_PROFILE_ECONOMY 1 + +extern int power_profile_get_state(void); +extern void power_profile_set_state(int); + +typedef void (*power_profile_change_hook)(void *, int); +EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook); + +#endif /* !_SYS_POWER_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/sys/priority.h b/lib/libc/include/any-freebsd-any/sys/priority.h new file mode 100644 index 000000000000..60327cf20293 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/priority.h @@ -0,0 +1,135 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1994, Henrik Vestergaard Draboel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Henrik Vestergaard Draboel. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PRIORITY_H_ +#define _SYS_PRIORITY_H_ + +/* + * Process priority specifications. + */ + +/* + * Priority classes. + */ + +#define PRI_ITHD 1 /* Interrupt thread. */ +#define PRI_REALTIME 2 /* Real time process. */ +#define PRI_TIMESHARE 3 /* Time sharing process. */ +#define PRI_IDLE 4 /* Idle process. */ + +/* + * PRI_FIFO is POSIX.1B SCHED_FIFO. + */ + +#define PRI_FIFO_BIT 8 +#define PRI_FIFO (PRI_FIFO_BIT | PRI_REALTIME) + +#define PRI_BASE(P) ((P) & ~PRI_FIFO_BIT) +#define PRI_IS_REALTIME(P) (PRI_BASE(P) == PRI_REALTIME) +#define PRI_NEED_RR(P) ((P) != PRI_FIFO) + +/* + * Priorities. Note that with 64 run queues, differences less than 4 are + * insignificant. + */ + +/* + * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ) + * are insignificant. Ranges are as follows: + * + * Interrupt threads: 0 - 47 + * Realtime user threads: 48 - 79 + * Top half kernel threads: 80 - 119 + * Time sharing user threads: 120 - 223 + * Idle user threads: 224 - 255 + * + * XXX If/When the specific interrupt thread and top half thread ranges + * disappear, a larger range can be used for user processes. + */ + +#define PRI_MIN (0) /* Highest priority. */ +#define PRI_MAX (255) /* Lowest priority. */ + +#define PRI_MIN_ITHD (PRI_MIN) +#define PRI_MAX_ITHD (PRI_MIN_REALTIME - 1) + +#define PI_REALTIME (PRI_MIN_ITHD + 0) +#define PI_AV (PRI_MIN_ITHD + 4) +#define PI_NET (PRI_MIN_ITHD + 8) +#define PI_DISK (PRI_MIN_ITHD + 12) +#define PI_TTY (PRI_MIN_ITHD + 16) +#define PI_DULL (PRI_MIN_ITHD + 20) +#define PI_SOFT (PRI_MIN_ITHD + 24) +#define PI_SWI(x) (PI_SOFT + (x) * RQ_PPQ) + +#define PRI_MIN_REALTIME (48) +#define PRI_MAX_REALTIME (PRI_MIN_KERN - 1) + +#define PRI_MIN_KERN (80) +#define PRI_MAX_KERN (PRI_MIN_TIMESHARE - 1) + +#define PSWP (PRI_MIN_KERN + 0) +#define PVM (PRI_MIN_KERN + 4) +#define PINOD (PRI_MIN_KERN + 8) +#define PRIBIO (PRI_MIN_KERN + 12) +#define PVFS (PRI_MIN_KERN + 16) +#define PZERO (PRI_MIN_KERN + 20) +#define PSOCK (PRI_MIN_KERN + 24) +#define PWAIT (PRI_MIN_KERN + 28) +#define PLOCK (PRI_MIN_KERN + 32) +#define PPAUSE (PRI_MIN_KERN + 36) + +#define PRI_MIN_TIMESHARE (120) +#define PRI_MAX_TIMESHARE (PRI_MIN_IDLE - 1) + +#define PUSER (PRI_MIN_TIMESHARE) + +#define PRI_MIN_IDLE (224) +#define PRI_MAX_IDLE (PRI_MAX) + +#ifdef _KERNEL +/* Other arguments for kern_yield(9). */ +#define PRI_USER -2 /* Change to current user priority. */ +#define PRI_UNCHANGED -1 /* Do not change priority. */ +#endif + +struct priority { + u_char pri_class; /* Scheduling class. */ + u_char pri_level; /* Normal priority level. */ + u_char pri_native; /* Priority before propagation. */ + u_char pri_user; /* User priority based on p_cpu and p_nice. */ +}; + +#endif /* !_SYS_PRIORITY_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/priv.h b/lib/libc/include/any-freebsd-any/sys/priv.h new file mode 100644 index 000000000000..948a6c28bb69 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/priv.h @@ -0,0 +1,540 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 nCircle Network Security, Inc. + * All rights reserved. + * + * This software was developed by Robert N. M. Watson for the TrustedBSD + * Project under contract to nCircle Network Security, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, + * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Privilege checking interface for BSD kernel. + */ +#ifndef _SYS_PRIV_H_ +#define _SYS_PRIV_H_ + +/* + * Privilege list, sorted loosely by kernel subsystem. + * + * Think carefully before adding or reusing one of these privileges -- are + * there existing instances referring to the same privilege? Third party + * vendors may request the assignment of privileges to be used in loadable + * modules. Particular numeric privilege assignments are part of the + * loadable kernel module ABI, and should not be changed across minor + * releases. + * + * When adding a new privilege, remember to determine if it's appropriate + * for use in jail, and update the privilege switch in prison_priv_check() + * in kern_jail.c as necessary. + */ + +/* + * Track beginning of privilege list. + */ +#define _PRIV_LOWEST 1 + +/* + * The remaining privileges typically correspond to one or a small + * number of specific privilege checks, and have (relatively) precise + * meanings. They are loosely sorted into a set of base system + * privileges, such as the ability to reboot, and then loosely by + * subsystem, indicated by a subsystem name. + */ +#define _PRIV_ROOT 1 /* Removed. */ +#define PRIV_ACCT 2 /* Manage process accounting. */ +#define PRIV_MAXFILES 3 /* Exceed system open files limit. */ +#define PRIV_MAXPROC 4 /* Exceed system processes limit. */ +#define PRIV_KTRACE 5 /* Set/clear KTRFAC_ROOT on ktrace. */ +#define PRIV_SETDUMPER 6 /* Configure dump device. */ +#define PRIV_REBOOT 8 /* Can reboot system. */ +#define PRIV_SWAPON 9 /* Can swapon(). */ +#define PRIV_SWAPOFF 10 /* Can swapoff(). */ +#define PRIV_MSGBUF 11 /* Can read kernel message buffer. */ +#define PRIV_IO 12 /* Can perform low-level I/O. */ +#define PRIV_KEYBOARD 13 /* Reprogram keyboard. */ +#define PRIV_DRIVER 14 /* Low-level driver privilege. */ +#define PRIV_ADJTIME 15 /* Set time adjustment. */ +#define PRIV_NTP_ADJTIME 16 /* Set NTP time adjustment. */ +#define PRIV_CLOCK_SETTIME 17 /* Can call clock_settime. */ +#define PRIV_SETTIMEOFDAY 18 /* Can call settimeofday. */ +#define _PRIV_SETHOSTID 19 /* Removed. */ +#define _PRIV_SETDOMAINNAME 20 /* Removed. */ + +/* + * Audit subsystem privileges. + */ +#define PRIV_AUDIT_CONTROL 40 /* Can configure audit. */ +#define PRIV_AUDIT_FAILSTOP 41 /* Can run during audit fail stop. */ +#define PRIV_AUDIT_GETAUDIT 42 /* Can get proc audit properties. */ +#define PRIV_AUDIT_SETAUDIT 43 /* Can set proc audit properties. */ +#define PRIV_AUDIT_SUBMIT 44 /* Can submit an audit record. */ + +/* + * Credential management privileges. + */ +#define PRIV_CRED_SETUID 50 /* setuid. */ +#define PRIV_CRED_SETEUID 51 /* seteuid to !ruid and !svuid. */ +#define PRIV_CRED_SETGID 52 /* setgid. */ +#define PRIV_CRED_SETEGID 53 /* setgid to !rgid and !svgid. */ +#define PRIV_CRED_SETGROUPS 54 /* Set process additional groups. */ +#define PRIV_CRED_SETREUID 55 /* setreuid. */ +#define PRIV_CRED_SETREGID 56 /* setregid. */ +#define PRIV_CRED_SETRESUID 57 /* setresuid. */ +#define PRIV_CRED_SETRESGID 58 /* setresgid. */ +#define PRIV_SEEOTHERGIDS 59 /* Exempt bsd.seeothergids. */ +#define PRIV_SEEOTHERUIDS 60 /* Exempt bsd.seeotheruids. */ + +/* + * Debugging privileges. + */ +#define PRIV_DEBUG_DIFFCRED 80 /* Exempt debugging other users. */ +#define PRIV_DEBUG_SUGID 81 /* Exempt debugging setuid proc. */ +#define PRIV_DEBUG_UNPRIV 82 /* Exempt unprivileged debug limit. */ +#define PRIV_DEBUG_DENIED 83 /* Exempt P2_NOTRACE. */ + +/* + * Dtrace privileges. + */ +#define PRIV_DTRACE_KERNEL 90 /* Allow use of DTrace on the kernel. */ +#define PRIV_DTRACE_PROC 91 /* Allow attaching DTrace to process. */ +#define PRIV_DTRACE_USER 92 /* Process may submit DTrace events. */ + +/* + * Firmware privilegs. + */ +#define PRIV_FIRMWARE_LOAD 100 /* Can load firmware. */ + +/* + * Jail privileges. + */ +#define PRIV_JAIL_ATTACH 110 /* Attach to a jail. */ +#define PRIV_JAIL_SET 111 /* Set jail parameters. */ +#define PRIV_JAIL_REMOVE 112 /* Remove a jail. */ + +/* + * Kernel environment privileges. + */ +#define PRIV_KENV_SET 120 /* Set kernel env. variables. */ +#define PRIV_KENV_UNSET 121 /* Unset kernel env. variables. */ + +/* + * Loadable kernel module privileges. + */ +#define PRIV_KLD_LOAD 130 /* Load a kernel module. */ +#define PRIV_KLD_UNLOAD 131 /* Unload a kernel module. */ + +/* + * Privileges associated with the MAC Framework and specific MAC policy + * modules. + */ +#define PRIV_MAC_PARTITION 140 /* Privilege in mac_partition policy. */ +#define PRIV_MAC_PRIVS 141 /* Privilege in the mac_privs policy. */ + +/* + * Process-related privileges. + */ +#define PRIV_PROC_LIMIT 160 /* Exceed user process limit. */ +#define PRIV_PROC_SETLOGIN 161 /* Can call setlogin. */ +#define PRIV_PROC_SETRLIMIT 162 /* Can raise resources limits. */ +#define PRIV_PROC_SETLOGINCLASS 163 /* Can call setloginclass(2). */ + +/* + * System V IPC privileges. + */ +#define PRIV_IPC_READ 170 /* Can override IPC read perm. */ +#define PRIV_IPC_WRITE 171 /* Can override IPC write perm. */ +#define PRIV_IPC_ADMIN 172 /* Can override IPC owner-only perm. */ +#define PRIV_IPC_MSGSIZE 173 /* Exempt IPC message queue limit. */ + +/* + * POSIX message queue privileges. + */ +#define PRIV_MQ_ADMIN 180 /* Can override msgq owner-only perm. */ + +/* + * Performance monitoring counter privileges. + */ +#define PRIV_PMC_MANAGE 190 /* Can administer PMC. */ +#define PRIV_PMC_SYSTEM 191 /* Can allocate a system-wide PMC. */ + +/* + * Scheduling privileges. + */ +#define PRIV_SCHED_DIFFCRED 200 /* Exempt scheduling other users. */ +#define PRIV_SCHED_SETPRIORITY 201 /* Can set lower nice value for proc. */ +#define PRIV_SCHED_RTPRIO 202 /* Can set real time scheduling. */ +#define PRIV_SCHED_SETPOLICY 203 /* Can set scheduler policy. */ +#define PRIV_SCHED_SET 204 /* Can set thread scheduler. */ +#define PRIV_SCHED_SETPARAM 205 /* Can set thread scheduler params. */ +#define PRIV_SCHED_CPUSET 206 /* Can manipulate cpusets. */ +#define PRIV_SCHED_CPUSET_INTR 207 /* Can adjust IRQ to CPU binding. */ + +/* + * POSIX semaphore privileges. + */ +#define PRIV_SEM_WRITE 220 /* Can override sem write perm. */ + +/* + * Signal privileges. + */ +#define PRIV_SIGNAL_DIFFCRED 230 /* Exempt signalling other users. */ +#define PRIV_SIGNAL_SUGID 231 /* Non-conserv signal setuid proc. */ + +/* + * Sysctl privileges. + */ +#define PRIV_SYSCTL_DEBUG 240 /* Can invoke sysctl.debug. */ +#define PRIV_SYSCTL_WRITE 241 /* Can write sysctls. */ +#define PRIV_SYSCTL_WRITEJAIL 242 /* Can write sysctls, jail permitted. */ + +/* + * TTY privileges. + */ +#define PRIV_TTY_CONSOLE 250 /* Set console to tty. */ +#define PRIV_TTY_DRAINWAIT 251 /* Set tty drain wait time. */ +#define PRIV_TTY_DTRWAIT 252 /* Set DTR wait on tty. */ +#define PRIV_TTY_EXCLUSIVE 253 /* Override tty exclusive flag. */ +#define _PRIV_TTY_PRISON 254 /* Removed. */ +#define PRIV_TTY_STI 255 /* Simulate input on another tty. */ +#define PRIV_TTY_SETA 256 /* Set tty termios structure. */ + +/* + * UFS-specific privileges. + */ +#define PRIV_UFS_EXTATTRCTL 270 /* Can configure EAs on UFS1. */ +#define PRIV_UFS_QUOTAOFF 271 /* quotaoff(). */ +#define PRIV_UFS_QUOTAON 272 /* quotaon(). */ +#define PRIV_UFS_SETUSE 273 /* setuse(). */ + +/* + * ZFS-specific privileges. + */ +#define PRIV_ZFS_POOL_CONFIG 280 /* Can configure ZFS pools. */ +#define PRIV_ZFS_INJECT 281 /* Can inject faults in the ZFS fault + injection framework. */ +#define PRIV_ZFS_JAIL 282 /* Can attach/detach ZFS file systems + to/from jails. */ + +/* + * NFS-specific privileges. + */ +#define PRIV_NFS_DAEMON 290 /* Can become the NFS daemon. */ +#define PRIV_NFS_LOCKD 291 /* Can become NFS lock daemon. */ + +/* + * VFS privileges. + */ +#define PRIV_VFS_READ 310 /* Override vnode DAC read perm. */ +#define PRIV_VFS_WRITE 311 /* Override vnode DAC write perm. */ +#define PRIV_VFS_ADMIN 312 /* Override vnode DAC admin perm. */ +#define PRIV_VFS_EXEC 313 /* Override vnode DAC exec perm. */ +#define PRIV_VFS_LOOKUP 314 /* Override vnode DAC lookup perm. */ +#define PRIV_VFS_BLOCKRESERVE 315 /* Can use free block reserve. */ +#define PRIV_VFS_CHFLAGS_DEV 316 /* Can chflags() a device node. */ +#define PRIV_VFS_CHOWN 317 /* Can set user; group to non-member. */ +#define PRIV_VFS_CHROOT 318 /* chroot(). */ +#define PRIV_VFS_RETAINSUGID 319 /* Can retain sugid bits on change. */ +#define PRIV_VFS_EXCEEDQUOTA 320 /* Exempt from quota restrictions. */ +#define PRIV_VFS_EXTATTR_SYSTEM 321 /* Operate on system EA namespace. */ +#define PRIV_VFS_FCHROOT 322 /* fchroot(). */ +#define PRIV_VFS_FHOPEN 323 /* Can fhopen(). */ +#define PRIV_VFS_FHSTAT 324 /* Can fhstat(). */ +#define PRIV_VFS_FHSTATFS 325 /* Can fhstatfs(). */ +#define PRIV_VFS_GENERATION 326 /* stat() returns generation number. */ +#define PRIV_VFS_GETFH 327 /* Can retrieve file handles. */ +#define PRIV_VFS_GETQUOTA 328 /* getquota(). */ +#define PRIV_VFS_LINK 329 /* bsd.hardlink_check_uid */ +#define PRIV_VFS_MKNOD_BAD 330 /* Was: mknod() can mark bad inodes. */ +#define PRIV_VFS_MKNOD_DEV 331 /* Can mknod() to create dev nodes. */ +#define PRIV_VFS_MKNOD_WHT 332 /* Can mknod() to create whiteout. */ +#define PRIV_VFS_MOUNT 333 /* Can mount(). */ +#define PRIV_VFS_MOUNT_OWNER 334 /* Can manage other users' file systems. */ +#define PRIV_VFS_MOUNT_EXPORTED 335 /* Can set MNT_EXPORTED on mount. */ +#define PRIV_VFS_MOUNT_PERM 336 /* Override dev node perms at mount. */ +#define PRIV_VFS_MOUNT_SUIDDIR 337 /* Can set MNT_SUIDDIR on mount. */ +#define PRIV_VFS_MOUNT_NONUSER 338 /* Can perform a non-user mount. */ +#define PRIV_VFS_SETGID 339 /* Can setgid if not in group. */ +#define PRIV_VFS_SETQUOTA 340 /* setquota(). */ +#define PRIV_VFS_STICKYFILE 341 /* Can set sticky bit on file. */ +#define PRIV_VFS_SYSFLAGS 342 /* Can modify system flags. */ +#define PRIV_VFS_UNMOUNT 343 /* Can unmount(). */ +#define PRIV_VFS_STAT 344 /* Override vnode MAC stat perm. */ + +/* + * Virtual memory privileges. + */ +#define PRIV_VM_MADV_PROTECT 360 /* Can set MADV_PROTECT. */ +#define PRIV_VM_MLOCK 361 /* Can mlock(), mlockall(). */ +#define PRIV_VM_MUNLOCK 362 /* Can munlock(), munlockall(). */ +#define PRIV_VM_SWAP_NOQUOTA 363 /* + * Can override the global + * swap reservation limits. + */ +#define PRIV_VM_SWAP_NORLIMIT 364 /* + * Can override the per-uid + * swap reservation limits. + */ + +/* + * Device file system privileges. + */ +#define PRIV_DEVFS_RULE 370 /* Can manage devfs rules. */ +#define PRIV_DEVFS_SYMLINK 371 /* Can create symlinks in devfs. */ + +/* + * Random number generator privileges. + */ +#define PRIV_RANDOM_RESEED 380 /* Closing /dev/random reseeds. */ + +/* + * Network stack privileges. + */ +#define PRIV_NET_BRIDGE 390 /* Administer bridge. */ +#define PRIV_NET_GRE 391 /* Administer GRE. */ +#define _PRIV_NET_PPP 392 /* Removed. */ +#define _PRIV_NET_SLIP 393 /* Removed. */ +#define PRIV_NET_BPF 394 /* Monitor BPF. */ +#define PRIV_NET_RAW 395 /* Open raw socket. */ +#define PRIV_NET_ROUTE 396 /* Administer routing. */ +#define PRIV_NET_TAP 397 /* Can open tap device. */ +#define PRIV_NET_SETIFMTU 398 /* Set interface MTU. */ +#define PRIV_NET_SETIFFLAGS 399 /* Set interface flags. */ +#define PRIV_NET_SETIFCAP 400 /* Set interface capabilities. */ +#define PRIV_NET_SETIFNAME 401 /* Set interface name. */ +#define PRIV_NET_SETIFMETRIC 402 /* Set interface metrics. */ +#define PRIV_NET_SETIFPHYS 403 /* Set interface physical layer prop. */ +#define PRIV_NET_SETIFMAC 404 /* Set interface MAC label. */ +#define PRIV_NET_ADDMULTI 405 /* Add multicast addr. to ifnet. */ +#define PRIV_NET_DELMULTI 406 /* Delete multicast addr. from ifnet. */ +#define PRIV_NET_HWIOCTL 407 /* Issue hardware ioctl on ifnet. */ +#define PRIV_NET_SETLLADDR 408 /* Set interface link-level address. */ +#define PRIV_NET_ADDIFGROUP 409 /* Add new interface group. */ +#define PRIV_NET_DELIFGROUP 410 /* Delete interface group. */ +#define PRIV_NET_IFCREATE 411 /* Create cloned interface. */ +#define PRIV_NET_IFDESTROY 412 /* Destroy cloned interface. */ +#define PRIV_NET_ADDIFADDR 413 /* Add protocol addr to interface. */ +#define PRIV_NET_DELIFADDR 414 /* Delete protocol addr on interface. */ +#define PRIV_NET_LAGG 415 /* Administer lagg interface. */ +#define PRIV_NET_GIF 416 /* Administer gif interface. */ +#define PRIV_NET_SETIFVNET 417 /* Move interface to vnet. */ +#define PRIV_NET_SETIFDESCR 418 /* Set interface description. */ +#define PRIV_NET_SETIFFIB 419 /* Set interface fib. */ +#define PRIV_NET_VXLAN 420 /* Administer vxlan. */ +#define PRIV_NET_SETLANPCP 421 /* Set LAN priority. */ +#define PRIV_NET_SETVLANPCP PRIV_NET_SETLANPCP /* Alias Set VLAN priority */ + +/* + * 802.11-related privileges. + */ +#define PRIV_NET80211_VAP_GETKEY 440 /* Query VAP 802.11 keys. */ +#define PRIV_NET80211_VAP_MANAGE 441 /* Administer 802.11 VAP */ +#define PRIV_NET80211_VAP_SETMAC 442 /* Set VAP MAC address */ +#define PRIV_NET80211_CREATE_VAP 443 /* Create a new VAP */ + +/* + * Placeholder for AppleTalk privileges, not supported anymore. + */ +#define _PRIV_NETATALK_RESERVEDPORT 450 /* Bind low port number. */ + +/* + * ATM privileges. + */ +#define PRIV_NETATM_CFG 460 +#define PRIV_NETATM_ADD 461 +#define PRIV_NETATM_DEL 462 +#define PRIV_NETATM_SET 463 + +/* + * Bluetooth privileges. + */ +#define PRIV_NETBLUETOOTH_RAW 470 /* Open raw bluetooth socket. */ + +/* + * Netgraph and netgraph module privileges. + */ +#define PRIV_NETGRAPH_CONTROL 480 /* Open netgraph control socket. */ +#define PRIV_NETGRAPH_TTY 481 /* Configure tty for netgraph. */ + +/* + * IPv4 and IPv6 privileges. + */ +#define PRIV_NETINET_RESERVEDPORT 490 /* Bind low port number. */ +#define PRIV_NETINET_IPFW 491 /* Administer IPFW firewall. */ +#define PRIV_NETINET_DIVERT 492 /* Open IP divert socket. */ +#define PRIV_NETINET_PF 493 /* Administer pf firewall. */ +#define PRIV_NETINET_DUMMYNET 494 /* Administer DUMMYNET. */ +#define PRIV_NETINET_CARP 495 /* Administer CARP. */ +#define PRIV_NETINET_MROUTE 496 /* Administer multicast routing. */ +#define PRIV_NETINET_RAW 497 /* Open netinet raw socket. */ +#define PRIV_NETINET_GETCRED 498 /* Query netinet pcb credentials. */ +#define PRIV_NETINET_ADDRCTRL6 499 /* Administer IPv6 address scopes. */ +#define PRIV_NETINET_ND6 500 /* Administer IPv6 neighbor disc. */ +#define PRIV_NETINET_SCOPE6 501 /* Administer IPv6 address scopes. */ +#define PRIV_NETINET_ALIFETIME6 502 /* Administer IPv6 address lifetimes. */ +#define PRIV_NETINET_IPSEC 503 /* Administer IPSEC. */ +#define PRIV_NETINET_REUSEPORT 504 /* Allow [rapid] port/address reuse. */ +#define PRIV_NETINET_SETHDROPTS 505 /* Set certain IPv4/6 header options. */ +#define PRIV_NETINET_BINDANY 506 /* Allow bind to any address. */ +#define PRIV_NETINET_HASHKEY 507 /* Get and set hash keys for IPv4/6. */ + +/* + * Placeholders for IPX/SPX privileges, not supported any more. + */ +#define _PRIV_NETIPX_RESERVEDPORT 520 /* Bind low port number. */ +#define _PRIV_NETIPX_RAW 521 /* Open netipx raw socket. */ + +/* + * NCP privileges. + */ +#define PRIV_NETNCP 530 /* Use another user's connection. */ + +/* + * SMB privileges. + */ +#define PRIV_NETSMB 540 /* Use another user's connection. */ + +/* + * VM86 privileges. + */ +#define PRIV_VM86_INTCALL 550 /* Allow invoking vm86 int handlers. */ + +/* + * Set of reserved privilege values, which will be allocated to code as + * needed, in order to avoid renumbering later privileges due to insertion. + */ +#define _PRIV_RESERVED0 560 +#define _PRIV_RESERVED1 561 +#define _PRIV_RESERVED2 562 +#define _PRIV_RESERVED3 563 +#define _PRIV_RESERVED4 564 +#define _PRIV_RESERVED5 565 +#define _PRIV_RESERVED6 566 +#define _PRIV_RESERVED7 567 +#define _PRIV_RESERVED8 568 +#define _PRIV_RESERVED9 569 +#define _PRIV_RESERVED10 570 +#define _PRIV_RESERVED11 571 +#define _PRIV_RESERVED12 572 +#define _PRIV_RESERVED13 573 +#define _PRIV_RESERVED14 574 +#define _PRIV_RESERVED15 575 + +/* + * Define a set of valid privilege numbers that can be used by loadable + * modules that don't yet have privilege reservations. Ideally, these should + * not be used, since their meaning is opaque to any policies that are aware + * of specific privileges, such as jail, and as such may be arbitrarily + * denied. + */ +#define PRIV_MODULE0 600 +#define PRIV_MODULE1 601 +#define PRIV_MODULE2 602 +#define PRIV_MODULE3 603 +#define PRIV_MODULE4 604 +#define PRIV_MODULE5 605 +#define PRIV_MODULE6 606 +#define PRIV_MODULE7 607 +#define PRIV_MODULE8 608 +#define PRIV_MODULE9 609 +#define PRIV_MODULE10 610 +#define PRIV_MODULE11 611 +#define PRIV_MODULE12 612 +#define PRIV_MODULE13 613 +#define PRIV_MODULE14 614 +#define PRIV_MODULE15 615 + +/* + * DDB(4) privileges. + */ +#define PRIV_DDB_CAPTURE 620 /* Allow reading of DDB capture log. */ + +/* + * Arla/nnpfs privileges. + */ +#define PRIV_NNPFS_DEBUG 630 /* Perforn ARLA_VIOC_NNPFSDEBUG. */ + +/* + * cpuctl(4) privileges. + */ +#define PRIV_CPUCTL_WRMSR 640 /* Write model-specific register. */ +#define PRIV_CPUCTL_UPDATE 641 /* Update cpu microcode. */ + +/* + * Capi4BSD privileges. + */ +#define PRIV_C4B_RESET_CTLR 650 /* Load firmware, reset controller. */ +#define PRIV_C4B_TRACE 651 /* Unrestricted CAPI message tracing. */ + +/* + * OpenAFS privileges. + */ +#define PRIV_AFS_ADMIN 660 /* Can change AFS client settings. */ +#define PRIV_AFS_DAEMON 661 /* Can become the AFS daemon. */ + +/* + * Resource Limits privileges. + */ +#define PRIV_RCTL_GET_RACCT 670 +#define PRIV_RCTL_GET_RULES 671 +#define PRIV_RCTL_GET_LIMITS 672 +#define PRIV_RCTL_ADD_RULE 673 +#define PRIV_RCTL_REMOVE_RULE 674 + +/* + * mem(4) privileges. + */ +#define PRIV_KMEM_READ 680 /* Open mem/kmem for reading. */ +#define PRIV_KMEM_WRITE 681 /* Open mem/kmem for writing. */ + +/* + * Track end of privilege list. + */ +#define _PRIV_HIGHEST 682 + +/* + * Validate that a named privilege is known by the privilege system. Invalid + * privileges presented to the privilege system by a priv_check interface + * will result in a panic. This is only approximate due to sparse allocation + * of the privilege space. + */ +#define PRIV_VALID(x) ((x) > _PRIV_LOWEST && (x) < _PRIV_HIGHEST) + +#ifdef _KERNEL +/* + * Privilege check interfaces, modeled after historic suser() interfaces, but + * with the addition of a specific privilege name. No flags are currently + * defined for the API. Historically, flags specified using the real uid + * instead of the effective uid, and whether or not the check should be + * allowed in jail. + */ +struct thread; +struct ucred; +int priv_check(struct thread *td, int priv); +int priv_check_cred(struct ucred *cred, int priv, int flags); +#endif + +#endif /* !_SYS_PRIV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/proc.h b/lib/libc/include/any-freebsd-any/sys/proc.h new file mode 100644 index 000000000000..10cf8b8bce4b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/proc.h @@ -0,0 +1,1207 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)proc.h 8.15 (Berkeley) 5/19/95 + * $FreeBSD$ + */ + +#ifndef _SYS_PROC_H_ +#define _SYS_PROC_H_ + +#include /* For struct callout. */ +#include /* For struct klist. */ +#include +#ifndef _KERNEL +#include +#endif +#include +#include +#include +#include +#include +#include +#include /* XXX. */ +#include +#include +#include +#include +#include +#ifndef _KERNEL +#include /* For structs itimerval, timeval. */ +#else +#include +#include +#endif +#include +#include +#include +#include + +#include /* Machine-dependent proc substruct. */ +#ifdef _KERNEL +#include +#endif + +/* + * One structure allocated per session. + * + * List of locks + * (m) locked by s_mtx mtx + * (e) locked by proctree_lock sx + * (c) const until freeing + */ +struct session { + u_int s_count; /* Ref cnt; pgrps in session - atomic. */ + struct proc *s_leader; /* (m + e) Session leader. */ + struct vnode *s_ttyvp; /* (m) Vnode of controlling tty. */ + struct cdev_priv *s_ttydp; /* (m) Device of controlling tty. */ + struct tty *s_ttyp; /* (e) Controlling tty. */ + pid_t s_sid; /* (c) Session ID. */ + /* (m) Setlogin() name: */ + char s_login[roundup(MAXLOGNAME, sizeof(long))]; + struct mtx s_mtx; /* Mutex to protect members. */ +}; + +/* + * One structure allocated per process group. + * + * List of locks + * (m) locked by pg_mtx mtx + * (e) locked by proctree_lock sx + * (c) const until freeing + */ +struct pgrp { + LIST_ENTRY(pgrp) pg_hash; /* (e) Hash chain. */ + LIST_HEAD(, proc) pg_members; /* (m + e) Pointer to pgrp members. */ + struct session *pg_session; /* (c) Pointer to session. */ + struct sigiolst pg_sigiolst; /* (m) List of sigio sources. */ + pid_t pg_id; /* (c) Process group id. */ + int pg_jobc; /* (m) Job control process count. */ + struct mtx pg_mtx; /* Mutex to protect members */ +}; + +/* + * pargs, used to hold a copy of the command line, if it had a sane length. + */ +struct pargs { + u_int ar_ref; /* Reference count. */ + u_int ar_length; /* Length. */ + u_char ar_args[1]; /* Arguments. */ +}; + +/*- + * Description of a process. + * + * This structure contains the information needed to manage a thread of + * control, known in UN*X as a process; it has references to substructures + * containing descriptions of things that the process uses, but may share + * with related processes. The process structure and the substructures + * are always addressable except for those marked "(CPU)" below, + * which might be addressable only on a processor on which the process + * is running. + * + * Below is a key of locks used to protect each member of struct proc. The + * lock is indicated by a reference to a specific character in parens in the + * associated comment. + * * - not yet protected + * a - only touched by curproc or parent during fork/wait + * b - created at fork, never changes + * (exception aiods switch vmspaces, but they are also + * marked 'P_SYSTEM' so hopefully it will be left alone) + * c - locked by proc mtx + * d - locked by allproc_lock lock + * e - locked by proctree_lock lock + * f - session mtx + * g - process group mtx + * h - callout_lock mtx + * i - by curproc or the master session mtx + * j - locked by proc slock + * k - only accessed by curthread + * k*- only accessed by curthread and from an interrupt + * kx- only accessed by curthread and by debugger + * l - the attaching proc or attaching proc parent + * m - Giant + * n - not locked, lazy + * o - ktrace lock + * q - td_contested lock + * r - p_peers lock + * s - see sleepq_switch(), sleeping_on_old_rtc(), and sleep(9) + * t - thread lock + * u - process stat lock + * w - process timer lock + * x - created at fork, only changes during single threading in exec + * y - created at first aio, doesn't change until exit or exec at which + * point we are single-threaded and only curthread changes it + * z - zombie threads lock + * + * If the locking key specifies two identifiers (for example, p_pptr) then + * either lock is sufficient for read access, but both locks must be held + * for write access. + */ +struct cpuset; +struct filecaps; +struct filemon; +struct kaioinfo; +struct kaudit_record; +struct kdtrace_proc; +struct kdtrace_thread; +struct mqueue_notifier; +struct nlminfo; +struct p_sched; +struct proc; +struct procdesc; +struct racct; +struct sbuf; +struct sleepqueue; +struct socket; +struct syscall_args; +struct td_sched; +struct thread; +struct trapframe; +struct turnstile; +struct vm_map; +struct vm_map_entry; + +/* + * XXX: Does this belong in resource.h or resourcevar.h instead? + * Resource usage extension. The times in rusage structs in the kernel are + * never up to date. The actual times are kept as runtimes and tick counts + * (with control info in the "previous" times), and are converted when + * userland asks for rusage info. Backwards compatibility prevents putting + * this directly in the user-visible rusage struct. + * + * Locking for p_rux: (cu) means (u) for p_rux and (c) for p_crux. + * Locking for td_rux: (t) for all fields. + */ +struct rusage_ext { + uint64_t rux_runtime; /* (cu) Real time. */ + uint64_t rux_uticks; /* (cu) Statclock hits in user mode. */ + uint64_t rux_sticks; /* (cu) Statclock hits in sys mode. */ + uint64_t rux_iticks; /* (cu) Statclock hits in intr mode. */ + uint64_t rux_uu; /* (c) Previous user time in usec. */ + uint64_t rux_su; /* (c) Previous sys time in usec. */ + uint64_t rux_tu; /* (c) Previous total time in usec. */ +}; + +/* + * Kernel runnable context (thread). + * This is what is put to sleep and reactivated. + * Thread context. Processes may have multiple threads. + */ +struct thread { + struct mtx *volatile td_lock; /* replaces sched lock */ + struct proc *td_proc; /* (*) Associated process. */ + TAILQ_ENTRY(thread) td_plist; /* (*) All threads in this proc. */ + TAILQ_ENTRY(thread) td_runq; /* (t) Run queue. */ + TAILQ_ENTRY(thread) td_slpq; /* (t) Sleep queue. */ + TAILQ_ENTRY(thread) td_lockq; /* (t) Lock queue. */ + LIST_ENTRY(thread) td_hash; /* (d) Hash chain. */ + struct cpuset *td_cpuset; /* (t) CPU affinity mask. */ + struct domainset_ref td_domain; /* (a) NUMA policy */ + struct seltd *td_sel; /* Select queue/channel. */ + struct sleepqueue *td_sleepqueue; /* (k) Associated sleep queue. */ + struct turnstile *td_turnstile; /* (k) Associated turnstile. */ + struct rl_q_entry *td_rlqe; /* (k) Associated range lock entry. */ + struct umtx_q *td_umtxq; /* (c?) Link for when we're blocked. */ + lwpid_t td_tid; /* (b) Thread ID. */ + sigqueue_t td_sigqueue; /* (c) Sigs arrived, not delivered. */ +#define td_siglist td_sigqueue.sq_signals + u_char td_lend_user_pri; /* (t) Lend user pri. */ + +/* Cleared during fork1() */ +#define td_startzero td_epochnest + u_char td_epochnest; /* (k) Epoch nest counter. */ + int td_flags; /* (t) TDF_* flags. */ + int td_inhibitors; /* (t) Why can not run. */ + int td_pflags; /* (k) Private thread (TDP_*) flags. */ + int td_dupfd; /* (k) Ret value from fdopen. XXX */ + int td_sqqueue; /* (t) Sleepqueue queue blocked on. */ + void *td_wchan; /* (t) Sleep address. */ + const char *td_wmesg; /* (t) Reason for sleep. */ + volatile u_char td_owepreempt; /* (k*) Preempt on last critical_exit */ + u_char td_tsqueue; /* (t) Turnstile queue blocked on. */ + short td_locks; /* (k) Debug: count of non-spin locks */ + short td_rw_rlocks; /* (k) Count of rwlock read locks. */ + short td_sx_slocks; /* (k) Count of sx shared locks. */ + short td_lk_slocks; /* (k) Count of lockmgr shared locks. */ + short td_stopsched; /* (k) Scheduler stopped. */ + struct turnstile *td_blocked; /* (t) Lock thread is blocked on. */ + const char *td_lockname; /* (t) Name of lock blocked on. */ + LIST_HEAD(, turnstile) td_contested; /* (q) Contested locks. */ + struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */ + int td_intr_nesting_level; /* (k) Interrupt recursion. */ + int td_pinned; /* (k) Temporary cpu pin count. */ + struct ucred *td_ucred; /* (k) Reference to credentials. */ + struct plimit *td_limit; /* (k) Resource limits. */ + int td_slptick; /* (t) Time at sleep. */ + int td_blktick; /* (t) Time spent blocked. */ + int td_swvoltick; /* (t) Time at last SW_VOL switch. */ + int td_swinvoltick; /* (t) Time at last SW_INVOL switch. */ + u_int td_cow; /* (*) Number of copy-on-write faults */ + struct rusage td_ru; /* (t) rusage information. */ + struct rusage_ext td_rux; /* (t) Internal rusage information. */ + uint64_t td_incruntime; /* (t) Cpu ticks to transfer to proc. */ + uint64_t td_runtime; /* (t) How many cpu ticks we've run. */ + u_int td_pticks; /* (t) Statclock hits for profiling */ + u_int td_sticks; /* (t) Statclock hits in system mode. */ + u_int td_iticks; /* (t) Statclock hits in intr mode. */ + u_int td_uticks; /* (t) Statclock hits in user mode. */ + int td_intrval; /* (t) Return value for sleepq. */ + sigset_t td_oldsigmask; /* (k) Saved mask from pre sigpause. */ + volatile u_int td_generation; /* (k) For detection of preemption */ + stack_t td_sigstk; /* (k) Stack ptr and on-stack flag. */ + int td_xsig; /* (c) Signal for ptrace */ + u_long td_profil_addr; /* (k) Temporary addr until AST. */ + u_int td_profil_ticks; /* (k) Temporary ticks until AST. */ + char td_name[MAXCOMLEN + 1]; /* (*) Thread name. */ + struct file *td_fpop; /* (k) file referencing cdev under op */ + int td_dbgflags; /* (c) Userland debugger flags */ + siginfo_t td_si; /* (c) For debugger or core file */ + int td_ng_outbound; /* (k) Thread entered ng from above. */ + struct osd td_osd; /* (k) Object specific data. */ + struct vm_map_entry *td_map_def_user; /* (k) Deferred entries. */ + pid_t td_dbg_forked; /* (c) Child pid for debugger. */ + u_int td_vp_reserv; /* (k) Count of reserved vnodes. */ + int td_no_sleeping; /* (k) Sleeping disabled count. */ + void *td_su; /* (k) FFS SU private */ + sbintime_t td_sleeptimo; /* (t) Sleep timeout. */ + int td_rtcgen; /* (s) rtc_generation of abs. sleep */ + size_t td_vslock_sz; /* (k) amount of vslock-ed space */ +#define td_endzero td_sigmask + +/* Copied during fork1() or create_thread(). */ +#define td_startcopy td_endzero + sigset_t td_sigmask; /* (c) Current signal mask. */ + u_char td_rqindex; /* (t) Run queue index. */ + u_char td_base_pri; /* (t) Thread base kernel priority. */ + u_char td_priority; /* (t) Thread active priority. */ + u_char td_pri_class; /* (t) Scheduling class. */ + u_char td_user_pri; /* (t) User pri from estcpu and nice. */ + u_char td_base_user_pri; /* (t) Base user pri */ + u_char td_pre_epoch_prio; /* (k) User pri on entry to epoch */ + uintptr_t td_rb_list; /* (k) Robust list head. */ + uintptr_t td_rbp_list; /* (k) Robust priv list head. */ + uintptr_t td_rb_inact; /* (k) Current in-action mutex loc. */ + struct syscall_args td_sa; /* (kx) Syscall parameters. Copied on + fork for child tracing. */ +#define td_endcopy td_pcb + +/* + * Fields that must be manually set in fork1() or create_thread() + * or already have been set in the allocator, constructor, etc. + */ + struct pcb *td_pcb; /* (k) Kernel VA of pcb and kstack. */ + enum { + TDS_INACTIVE = 0x0, + TDS_INHIBITED, + TDS_CAN_RUN, + TDS_RUNQ, + TDS_RUNNING + } td_state; /* (t) thread state */ + union { + register_t tdu_retval[2]; + off_t tdu_off; + } td_uretoff; /* (k) Syscall aux returns. */ +#define td_retval td_uretoff.tdu_retval + u_int td_cowgen; /* (k) Generation of COW pointers. */ + /* LP64 hole */ + struct callout td_slpcallout; /* (h) Callout for sleep. */ + struct trapframe *td_frame; /* (k) */ + struct vm_object *td_kstack_obj;/* (a) Kstack object. */ + vm_offset_t td_kstack; /* (a) Kernel VA of kstack. */ + int td_kstack_pages; /* (a) Size of the kstack. */ + volatile u_int td_critnest; /* (k*) Critical section nest level. */ +#ifdef __amd64__ + uint32_t td_md_pad0[16]; +#else + struct mdthread td_md; /* (k) Any machine-dependent fields. */ +#endif + struct kaudit_record *td_ar; /* (k) Active audit record, if any. */ + struct lpohead td_lprof[2]; /* (a) lock profiling objects. */ + struct kdtrace_thread *td_dtrace; /* (*) DTrace-specific data. */ + int td_errno; /* Error returned by last syscall. */ + /* LP64 hole */ + struct vnet *td_vnet; /* (k) Effective vnet. */ + const char *td_vnet_lpush; /* (k) Debugging vnet push / pop. */ + struct trapframe *td_intr_frame;/* (k) Frame of the current irq */ + struct proc *td_rfppwait_p; /* (k) The vforked child */ + struct vm_page **td_ma; /* (k) uio pages held */ + int td_ma_cnt; /* (k) size of *td_ma */ + /* LP64 hole */ + void *td_emuldata; /* Emulator state data */ + int td_lastcpu; /* (t) Last cpu we were on. */ + int td_oncpu; /* (t) Which cpu we are on. */ + void *td_lkpi_task; /* LinuxKPI task struct pointer */ + int td_pmcpend; +#ifdef __amd64__ + struct mdthread td_md; /* (k) Any machine-dependent fields. */ +#endif + int td_pflags2; /* (k) Private thread (TDP2_*) flags. */ +}; + +struct thread0_storage { + struct thread t0st_thread; + uint64_t t0st_sched[10]; +}; + +struct mtx *thread_lock_block(struct thread *); +void thread_lock_unblock(struct thread *, struct mtx *); +void thread_lock_set(struct thread *, struct mtx *); +#define THREAD_LOCK_ASSERT(td, type) \ +do { \ + struct mtx *__m = (td)->td_lock; \ + if (__m != &blocked_lock) \ + mtx_assert(__m, (type)); \ +} while (0) + +#ifdef INVARIANTS +#define THREAD_LOCKPTR_ASSERT(td, lock) \ +do { \ + struct mtx *__m = (td)->td_lock; \ + KASSERT((__m == &blocked_lock || __m == (lock)), \ + ("Thread %p lock %p does not match %p", td, __m, (lock))); \ +} while (0) + +#define TD_LOCKS_INC(td) ((td)->td_locks++) +#define TD_LOCKS_DEC(td) do { \ + KASSERT(SCHEDULER_STOPPED_TD(td) || (td)->td_locks > 0, \ + ("thread %p owns no locks", (td))); \ + (td)->td_locks--; \ +} while (0) +#else +#define THREAD_LOCKPTR_ASSERT(td, lock) + +#define TD_LOCKS_INC(td) +#define TD_LOCKS_DEC(td) +#endif + +/* + * Flags kept in td_flags: + * To change these you MUST have the scheduler lock. + */ +#define TDF_BORROWING 0x00000001 /* Thread is borrowing pri from another. */ +#define TDF_INPANIC 0x00000002 /* Caused a panic, let it drive crashdump. */ +#define TDF_INMEM 0x00000004 /* Thread's stack is in memory. */ +#define TDF_SINTR 0x00000008 /* Sleep is interruptible. */ +#define TDF_TIMEOUT 0x00000010 /* Timing out during sleep. */ +#define TDF_IDLETD 0x00000020 /* This is a per-CPU idle thread. */ +#define TDF_CANSWAP 0x00000040 /* Thread can be swapped. */ +#define TDF_SLEEPABORT 0x00000080 /* sleepq_abort was called. */ +#define TDF_KTH_SUSP 0x00000100 /* kthread is suspended */ +#define TDF_ALLPROCSUSP 0x00000200 /* suspended by SINGLE_ALLPROC */ +#define TDF_BOUNDARY 0x00000400 /* Thread suspended at user boundary */ +#define TDF_ASTPENDING 0x00000800 /* Thread has some asynchronous events. */ +#define TDF_UNUSED12 0x00001000 /* --available-- */ +#define TDF_SBDRY 0x00002000 /* Stop only on usermode boundary. */ +#define TDF_UPIBLOCKED 0x00004000 /* Thread blocked on user PI mutex. */ +#define TDF_NEEDSUSPCHK 0x00008000 /* Thread may need to suspend. */ +#define TDF_NEEDRESCHED 0x00010000 /* Thread needs to yield. */ +#define TDF_NEEDSIGCHK 0x00020000 /* Thread may need signal delivery. */ +#define TDF_NOLOAD 0x00040000 /* Ignore during load avg calculations. */ +#define TDF_SERESTART 0x00080000 /* ERESTART on stop attempts. */ +#define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */ +#define TDF_SEINTR 0x00200000 /* EINTR on stop attempts. */ +#define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */ +#define TDF_UNUSED23 0x00800000 /* --available-- */ +#define TDF_SCHED0 0x01000000 /* Reserved for scheduler private use */ +#define TDF_SCHED1 0x02000000 /* Reserved for scheduler private use */ +#define TDF_SCHED2 0x04000000 /* Reserved for scheduler private use */ +#define TDF_SCHED3 0x08000000 /* Reserved for scheduler private use */ +#define TDF_ALRMPEND 0x10000000 /* Pending SIGVTALRM needs to be posted. */ +#define TDF_PROFPEND 0x20000000 /* Pending SIGPROF needs to be posted. */ +#define TDF_MACPEND 0x40000000 /* AST-based MAC event pending. */ + +/* Userland debug flags */ +#define TDB_SUSPEND 0x00000001 /* Thread is suspended by debugger */ +#define TDB_XSIG 0x00000002 /* Thread is exchanging signal under trace */ +#define TDB_USERWR 0x00000004 /* Debugger modified memory or registers */ +#define TDB_SCE 0x00000008 /* Thread performs syscall enter */ +#define TDB_SCX 0x00000010 /* Thread performs syscall exit */ +#define TDB_EXEC 0x00000020 /* TDB_SCX from exec(2) family */ +#define TDB_FORK 0x00000040 /* TDB_SCX from fork(2) that created new + process */ +#define TDB_STOPATFORK 0x00000080 /* Stop at the return from fork (child + only) */ +#define TDB_CHILD 0x00000100 /* New child indicator for ptrace() */ +#define TDB_BORN 0x00000200 /* New LWP indicator for ptrace() */ +#define TDB_EXIT 0x00000400 /* Exiting LWP indicator for ptrace() */ +#define TDB_VFORK 0x00000800 /* vfork indicator for ptrace() */ +#define TDB_FSTP 0x00001000 /* The thread is PT_ATTACH leader */ +#define TDB_STEP 0x00002000 /* (x86) PSL_T set for PT_STEP */ + +/* + * "Private" flags kept in td_pflags: + * These are only written by curthread and thus need no locking. + */ +#define TDP_OLDMASK 0x00000001 /* Need to restore mask after suspend. */ +#define TDP_INKTR 0x00000002 /* Thread is currently in KTR code. */ +#define TDP_INKTRACE 0x00000004 /* Thread is currently in KTRACE code. */ +#define TDP_BUFNEED 0x00000008 /* Do not recurse into the buf flush */ +#define TDP_COWINPROGRESS 0x00000010 /* Snapshot copy-on-write in progress. */ +#define TDP_ALTSTACK 0x00000020 /* Have alternate signal stack. */ +#define TDP_DEADLKTREAT 0x00000040 /* Lock acquisition - deadlock treatment. */ +#define TDP_NOFAULTING 0x00000080 /* Do not handle page faults. */ +#define TDP_UNUSED9 0x00000100 /* --available-- */ +#define TDP_OWEUPC 0x00000200 /* Call addupc() at next AST. */ +#define TDP_ITHREAD 0x00000400 /* Thread is an interrupt thread. */ +#define TDP_SYNCIO 0x00000800 /* Local override, disable async i/o. */ +#define TDP_SCHED1 0x00001000 /* Reserved for scheduler private use */ +#define TDP_SCHED2 0x00002000 /* Reserved for scheduler private use */ +#define TDP_SCHED3 0x00004000 /* Reserved for scheduler private use */ +#define TDP_SCHED4 0x00008000 /* Reserved for scheduler private use */ +#define TDP_GEOM 0x00010000 /* Settle GEOM before finishing syscall */ +#define TDP_SOFTDEP 0x00020000 /* Stuck processing softdep worklist */ +#define TDP_NORUNNINGBUF 0x00040000 /* Ignore runningbufspace check */ +#define TDP_WAKEUP 0x00080000 /* Don't sleep in umtx cond_wait */ +#define TDP_INBDFLUSH 0x00100000 /* Already in BO_BDFLUSH, do not recurse */ +#define TDP_KTHREAD 0x00200000 /* This is an official kernel thread */ +#define TDP_CALLCHAIN 0x00400000 /* Capture thread's callchain */ +#define TDP_IGNSUSP 0x00800000 /* Permission to ignore the MNTK_SUSPEND* */ +#define TDP_AUDITREC 0x01000000 /* Audit record pending on thread */ +#define TDP_RFPPWAIT 0x02000000 /* Handle RFPPWAIT on syscall exit */ +#define TDP_RESETSPUR 0x04000000 /* Reset spurious page fault history. */ +#define TDP_NERRNO 0x08000000 /* Last errno is already in td_errno */ +#define TDP_UIOHELD 0x10000000 /* Current uio has pages held in td_ma */ +#define TDP_FORKING 0x20000000 /* Thread is being created through fork() */ +#define TDP_EXECVMSPC 0x40000000 /* Execve destroyed old vmspace */ + +#define TDP2_SBPAGES 0x00000001 /* Owns sbusy on some pages */ + +/* + * Reasons that the current thread can not be run yet. + * More than one may apply. + */ +#define TDI_SUSPENDED 0x0001 /* On suspension queue. */ +#define TDI_SLEEPING 0x0002 /* Actually asleep! (tricky). */ +#define TDI_SWAPPED 0x0004 /* Stack not in mem. Bad juju if run. */ +#define TDI_LOCK 0x0008 /* Stopped on a lock. */ +#define TDI_IWAIT 0x0010 /* Awaiting interrupt. */ + +#define TD_IS_SLEEPING(td) ((td)->td_inhibitors & TDI_SLEEPING) +#define TD_ON_SLEEPQ(td) ((td)->td_wchan != NULL) +#define TD_IS_SUSPENDED(td) ((td)->td_inhibitors & TDI_SUSPENDED) +#define TD_IS_SWAPPED(td) ((td)->td_inhibitors & TDI_SWAPPED) +#define TD_ON_LOCK(td) ((td)->td_inhibitors & TDI_LOCK) +#define TD_AWAITING_INTR(td) ((td)->td_inhibitors & TDI_IWAIT) +#define TD_IS_RUNNING(td) ((td)->td_state == TDS_RUNNING) +#define TD_ON_RUNQ(td) ((td)->td_state == TDS_RUNQ) +#define TD_CAN_RUN(td) ((td)->td_state == TDS_CAN_RUN) +#define TD_IS_INHIBITED(td) ((td)->td_state == TDS_INHIBITED) +#define TD_ON_UPILOCK(td) ((td)->td_flags & TDF_UPIBLOCKED) +#define TD_IS_IDLETHREAD(td) ((td)->td_flags & TDF_IDLETD) + +#define KTDSTATE(td) \ + (((td)->td_inhibitors & TDI_SLEEPING) != 0 ? "sleep" : \ + ((td)->td_inhibitors & TDI_SUSPENDED) != 0 ? "suspended" : \ + ((td)->td_inhibitors & TDI_SWAPPED) != 0 ? "swapped" : \ + ((td)->td_inhibitors & TDI_LOCK) != 0 ? "blocked" : \ + ((td)->td_inhibitors & TDI_IWAIT) != 0 ? "iwait" : "yielding") + +#define TD_SET_INHIB(td, inhib) do { \ + (td)->td_state = TDS_INHIBITED; \ + (td)->td_inhibitors |= (inhib); \ +} while (0) + +#define TD_CLR_INHIB(td, inhib) do { \ + if (((td)->td_inhibitors & (inhib)) && \ + (((td)->td_inhibitors &= ~(inhib)) == 0)) \ + (td)->td_state = TDS_CAN_RUN; \ +} while (0) + +#define TD_SET_SLEEPING(td) TD_SET_INHIB((td), TDI_SLEEPING) +#define TD_SET_SWAPPED(td) TD_SET_INHIB((td), TDI_SWAPPED) +#define TD_SET_LOCK(td) TD_SET_INHIB((td), TDI_LOCK) +#define TD_SET_SUSPENDED(td) TD_SET_INHIB((td), TDI_SUSPENDED) +#define TD_SET_IWAIT(td) TD_SET_INHIB((td), TDI_IWAIT) +#define TD_SET_EXITING(td) TD_SET_INHIB((td), TDI_EXITING) + +#define TD_CLR_SLEEPING(td) TD_CLR_INHIB((td), TDI_SLEEPING) +#define TD_CLR_SWAPPED(td) TD_CLR_INHIB((td), TDI_SWAPPED) +#define TD_CLR_LOCK(td) TD_CLR_INHIB((td), TDI_LOCK) +#define TD_CLR_SUSPENDED(td) TD_CLR_INHIB((td), TDI_SUSPENDED) +#define TD_CLR_IWAIT(td) TD_CLR_INHIB((td), TDI_IWAIT) + +#define TD_SET_RUNNING(td) (td)->td_state = TDS_RUNNING +#define TD_SET_RUNQ(td) (td)->td_state = TDS_RUNQ +#define TD_SET_CAN_RUN(td) (td)->td_state = TDS_CAN_RUN + +#define TD_SBDRY_INTR(td) \ + (((td)->td_flags & (TDF_SEINTR | TDF_SERESTART)) != 0) +#define TD_SBDRY_ERRNO(td) \ + (((td)->td_flags & TDF_SEINTR) != 0 ? EINTR : ERESTART) + +/* + * Process structure. + */ +struct proc { + LIST_ENTRY(proc) p_list; /* (d) List of all processes. */ + TAILQ_HEAD(, thread) p_threads; /* (c) all threads. */ + struct mtx p_slock; /* process spin lock */ + struct ucred *p_ucred; /* (c) Process owner's identity. */ + struct filedesc *p_fd; /* (b) Open files. */ + struct filedesc_to_leader *p_fdtol; /* (b) Tracking node */ + struct pstats *p_stats; /* (b) Accounting/statistics (CPU). */ + struct plimit *p_limit; /* (c) Resource limits. */ + struct callout p_limco; /* (c) Limit callout handle */ + struct sigacts *p_sigacts; /* (x) Signal actions, state (CPU). */ + + int p_flag; /* (c) P_* flags. */ + int p_flag2; /* (c) P2_* flags. */ + enum { + PRS_NEW = 0, /* In creation */ + PRS_NORMAL, /* threads can be run. */ + PRS_ZOMBIE + } p_state; /* (j/c) Process status. */ + pid_t p_pid; /* (b) Process identifier. */ + LIST_ENTRY(proc) p_hash; /* (d) Hash chain. */ + LIST_ENTRY(proc) p_pglist; /* (g + e) List of processes in pgrp. */ + struct proc *p_pptr; /* (c + e) Pointer to parent process. */ + LIST_ENTRY(proc) p_sibling; /* (e) List of sibling processes. */ + LIST_HEAD(, proc) p_children; /* (e) Pointer to list of children. */ + struct proc *p_reaper; /* (e) My reaper. */ + LIST_HEAD(, proc) p_reaplist; /* (e) List of my descendants + (if I am reaper). */ + LIST_ENTRY(proc) p_reapsibling; /* (e) List of siblings - descendants of + the same reaper. */ + struct mtx p_mtx; /* (n) Lock for this struct. */ + struct mtx p_statmtx; /* Lock for the stats */ + struct mtx p_itimmtx; /* Lock for the virt/prof timers */ + struct mtx p_profmtx; /* Lock for the profiling */ + struct ksiginfo *p_ksi; /* Locked by parent proc lock */ + sigqueue_t p_sigqueue; /* (c) Sigs not delivered to a td. */ +#define p_siglist p_sigqueue.sq_signals + pid_t p_oppid; /* (c + e) Real parent pid. */ + +/* The following fields are all zeroed upon creation in fork. */ +#define p_startzero p_vmspace + struct vmspace *p_vmspace; /* (b) Address space. */ + u_int p_swtick; /* (c) Tick when swapped in or out. */ + u_int p_cowgen; /* (c) Generation of COW pointers. */ + struct itimerval p_realtimer; /* (c) Alarm timer. */ + struct rusage p_ru; /* (a) Exit information. */ + struct rusage_ext p_rux; /* (cu) Internal resource usage. */ + struct rusage_ext p_crux; /* (c) Internal child resource usage. */ + int p_profthreads; /* (c) Num threads in addupc_task. */ + volatile int p_exitthreads; /* (j) Number of threads exiting */ + int p_traceflag; /* (o) Kernel trace points. */ + struct vnode *p_tracevp; /* (c + o) Trace to vnode. */ + struct ucred *p_tracecred; /* (o) Credentials to trace with. */ + struct vnode *p_textvp; /* (b) Vnode of executable. */ + u_int p_lock; /* (c) Proclock (prevent swap) count. */ + struct sigiolst p_sigiolst; /* (c) List of sigio sources. */ + int p_sigparent; /* (c) Signal to parent on exit. */ + int p_sig; /* (n) For core dump/debugger XXX. */ + u_long p_code; /* (n) For core dump/debugger XXX. */ + u_int p_stops; /* (c) Stop event bitmask. */ + u_int p_stype; /* (c) Stop event type. */ + char p_step; /* (c) Process is stopped. */ + u_char p_pfsflags; /* (c) Procfs flags. */ + u_int p_ptevents; /* (c + e) ptrace() event mask. */ + struct nlminfo *p_nlminfo; /* (?) Only used by/for lockd. */ + struct kaioinfo *p_aioinfo; /* (y) ASYNC I/O info. */ + struct thread *p_singlethread;/* (c + j) If single threading this is it */ + int p_suspcount; /* (j) Num threads in suspended mode. */ + struct thread *p_xthread; /* (c) Trap thread */ + int p_boundary_count;/* (j) Num threads at user boundary */ + int p_pendingcnt; /* how many signals are pending */ + struct itimers *p_itimers; /* (c) POSIX interval timers. */ + struct procdesc *p_procdesc; /* (e) Process descriptor, if any. */ + u_int p_treeflag; /* (e) P_TREE flags */ + int p_pendingexits; /* (c) Count of pending thread exits. */ + struct filemon *p_filemon; /* (c) filemon-specific data. */ + int p_pdeathsig; /* (c) Signal from parent on exit. */ +/* End area that is zeroed on creation. */ +#define p_endzero p_magic + +/* The following fields are all copied upon creation in fork. */ +#define p_startcopy p_endzero + u_int p_magic; /* (b) Magic number. */ + int p_osrel; /* (x) osreldate for the + binary (from ELF note, if any) */ + char p_comm[MAXCOMLEN + 1]; /* (x) Process name. */ + struct sysentvec *p_sysent; /* (b) Syscall dispatch info. */ + struct pargs *p_args; /* (c) Process arguments. */ + rlim_t p_cpulimit; /* (c) Current CPU limit in seconds. */ + signed char p_nice; /* (c) Process "nice" value. */ + int p_fibnum; /* in this routing domain XXX MRT */ + pid_t p_reapsubtree; /* (e) Pid of the direct child of the + reaper which spawned + our subtree. */ + uint16_t p_elf_machine; /* (x) ELF machine type */ + uint64_t p_elf_flags; /* (x) ELF flags */ +/* End area that is copied on creation. */ +#define p_endcopy p_xexit + + u_int p_xexit; /* (c) Exit code. */ + u_int p_xsig; /* (c) Stop/kill sig. */ + struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */ + struct knlist *p_klist; /* (c) Knotes attached to this proc. */ + int p_numthreads; /* (c) Number of threads. */ + struct mdproc p_md; /* Any machine-dependent fields. */ + struct callout p_itcallout; /* (h + c) Interval timer callout. */ + u_short p_acflag; /* (c) Accounting flags. */ + struct proc *p_peers; /* (r) */ + struct proc *p_leader; /* (b) */ + void *p_emuldata; /* (c) Emulator state data. */ + struct label *p_label; /* (*) Proc (not subject) MAC label. */ + STAILQ_HEAD(, ktr_request) p_ktr; /* (o) KTR event queue. */ + LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/ + struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */ + struct cv p_pwait; /* (*) wait cv for exit/exec. */ + uint64_t p_prev_runtime; /* (c) Resource usage accounting. */ + struct racct *p_racct; /* (b) Resource accounting. */ + int p_throttled; /* (c) Flag for racct pcpu throttling */ + /* + * An orphan is the child that has been re-parented to the + * debugger as a result of attaching to it. Need to keep + * track of them for parent to be able to collect the exit + * status of what used to be children. + */ + LIST_ENTRY(proc) p_orphan; /* (e) List of orphan processes. */ + LIST_HEAD(, proc) p_orphans; /* (e) Pointer to list of orphans. */ + uint32_t p_fctl0; /* (x) ABI feature control, ELF note */ + u_int p_amd64_md_flags; /* (c) md process flags P_MD */ +}; + +#define p_session p_pgrp->pg_session +#define p_pgid p_pgrp->pg_id + +#define NOCPU (-1) /* For when we aren't on a CPU. */ +#define NOCPU_OLD (255) +#define MAXCPU_OLD (254) + +#define PROC_SLOCK(p) mtx_lock_spin(&(p)->p_slock) +#define PROC_SUNLOCK(p) mtx_unlock_spin(&(p)->p_slock) +#define PROC_SLOCK_ASSERT(p, type) mtx_assert(&(p)->p_slock, (type)) + +#define PROC_STATLOCK(p) mtx_lock_spin(&(p)->p_statmtx) +#define PROC_STATUNLOCK(p) mtx_unlock_spin(&(p)->p_statmtx) +#define PROC_STATLOCK_ASSERT(p, type) mtx_assert(&(p)->p_statmtx, (type)) + +#define PROC_ITIMLOCK(p) mtx_lock_spin(&(p)->p_itimmtx) +#define PROC_ITIMUNLOCK(p) mtx_unlock_spin(&(p)->p_itimmtx) +#define PROC_ITIMLOCK_ASSERT(p, type) mtx_assert(&(p)->p_itimmtx, (type)) + +#define PROC_PROFLOCK(p) mtx_lock_spin(&(p)->p_profmtx) +#define PROC_PROFUNLOCK(p) mtx_unlock_spin(&(p)->p_profmtx) +#define PROC_PROFLOCK_ASSERT(p, type) mtx_assert(&(p)->p_profmtx, (type)) + +/* These flags are kept in p_flag. */ +#define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */ +#define P_CONTROLT 0x00002 /* Has a controlling terminal. */ +#define P_KPROC 0x00004 /* Kernel process. */ +#define P_UNUSED3 0x00008 /* --available-- */ +#define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */ +#define P_PROFIL 0x00020 /* Has started profiling. */ +#define P_STOPPROF 0x00040 /* Has thread requesting to stop profiling. */ +#define P_HADTHREADS 0x00080 /* Has had threads (no cleanup shortcuts) */ +#define P_SUGID 0x00100 /* Had set id privileges since last exec. */ +#define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */ +#define P_SINGLE_EXIT 0x00400 /* Threads suspending should exit, not wait. */ +#define P_TRACED 0x00800 /* Debugged process being traced. */ +#define P_WAITED 0x01000 /* Someone is waiting for us. */ +#define P_WEXIT 0x02000 /* Working on exiting. */ +#define P_EXEC 0x04000 /* Process called exec. */ +#define P_WKILLED 0x08000 /* Killed, go to kernel/user boundary ASAP. */ +#define P_CONTINUED 0x10000 /* Proc has continued from a stopped state. */ +#define P_STOPPED_SIG 0x20000 /* Stopped due to SIGSTOP/SIGTSTP. */ +#define P_STOPPED_TRACE 0x40000 /* Stopped because of tracing. */ +#define P_STOPPED_SINGLE 0x80000 /* Only 1 thread can continue (not to user). */ +#define P_PROTECTED 0x100000 /* Do not kill on memory overcommit. */ +#define P_SIGEVENT 0x200000 /* Process pending signals changed. */ +#define P_SINGLE_BOUNDARY 0x400000 /* Threads should suspend at user boundary. */ +#define P_HWPMC 0x800000 /* Process is using HWPMCs */ +#define P_JAILED 0x1000000 /* Process is in jail. */ +#define P_TOTAL_STOP 0x2000000 /* Stopped in stop_all_proc. */ +#define P_INEXEC 0x4000000 /* Process is in execve(). */ +#define P_STATCHILD 0x8000000 /* Child process stopped or exited. */ +#define P_INMEM 0x10000000 /* Loaded into memory. */ +#define P_SWAPPINGOUT 0x20000000 /* Process is being swapped out. */ +#define P_SWAPPINGIN 0x40000000 /* Process is being swapped in. */ +#define P_PPTRACE 0x80000000 /* PT_TRACEME by vforked child. */ + +#define P_STOPPED (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE) +#define P_SHOULDSTOP(p) ((p)->p_flag & P_STOPPED) +#define P_KILLED(p) ((p)->p_flag & P_WKILLED) + +/* These flags are kept in p_flag2. */ +#define P2_INHERIT_PROTECTED 0x00000001 /* New children get P_PROTECTED. */ +#define P2_NOTRACE 0x00000002 /* No ptrace(2) attach or coredumps. */ +#define P2_NOTRACE_EXEC 0x00000004 /* Keep P2_NOPTRACE on exec(2). */ +#define P2_AST_SU 0x00000008 /* Handles SU ast for kthreads. */ +#define P2_PTRACE_FSTP 0x00000010 /* SIGSTOP from PT_ATTACH not yet handled. */ +#define P2_TRAPCAP 0x00000020 /* SIGTRAP on ENOTCAPABLE */ +#define P2_ASLR_ENABLE 0x00000040 /* Force enable ASLR. */ +#define P2_ASLR_DISABLE 0x00000080 /* Force disable ASLR. */ +#define P2_ASLR_IGNSTART 0x00000100 /* Enable ASLR to consume sbrk area. */ +#define P2_STKGAP_DISABLE 0x00000800 /* Disable stack gap for MAP_STACK */ +#define P2_STKGAP_DISABLE_EXEC 0x00001000 /* Stack gap disabled after exec */ + +/* Flags protected by proctree_lock, kept in p_treeflags. */ +#define P_TREE_ORPHANED 0x00000001 /* Reparented, on orphan list */ +#define P_TREE_FIRST_ORPHAN 0x00000002 /* First element of orphan + list */ +#define P_TREE_REAPER 0x00000004 /* Reaper of subtree */ +#define P_TREE_GRPEXITED 0x00000008 /* exit1() done with job ctl */ + +/* + * These were process status values (p_stat), now they are only used in + * legacy conversion code. + */ +#define SIDL 1 /* Process being created by fork. */ +#define SRUN 2 /* Currently runnable. */ +#define SSLEEP 3 /* Sleeping on an address. */ +#define SSTOP 4 /* Process debugging or suspension. */ +#define SZOMB 5 /* Awaiting collection by parent. */ +#define SWAIT 6 /* Waiting for interrupt. */ +#define SLOCK 7 /* Blocked on a lock. */ + +#define P_MAGIC 0xbeefface + +#ifdef _KERNEL + +/* Types and flags for mi_switch(). */ +#define SW_TYPE_MASK 0xff /* First 8 bits are switch type */ +#define SWT_NONE 0 /* Unspecified switch. */ +#define SWT_PREEMPT 1 /* Switching due to preemption. */ +#define SWT_OWEPREEMPT 2 /* Switching due to owepreempt. */ +#define SWT_TURNSTILE 3 /* Turnstile contention. */ +#define SWT_SLEEPQ 4 /* Sleepq wait. */ +#define SWT_SLEEPQTIMO 5 /* Sleepq timeout wait. */ +#define SWT_RELINQUISH 6 /* yield call. */ +#define SWT_NEEDRESCHED 7 /* NEEDRESCHED was set. */ +#define SWT_IDLE 8 /* Switching from the idle thread. */ +#define SWT_IWAIT 9 /* Waiting for interrupts. */ +#define SWT_SUSPEND 10 /* Thread suspended. */ +#define SWT_REMOTEPREEMPT 11 /* Remote processor preempted. */ +#define SWT_REMOTEWAKEIDLE 12 /* Remote processor preempted idle. */ +#define SWT_COUNT 13 /* Number of switch types. */ +/* Flags */ +#define SW_VOL 0x0100 /* Voluntary switch. */ +#define SW_INVOL 0x0200 /* Involuntary switch. */ +#define SW_PREEMPT 0x0400 /* The invol switch is a preemption */ + +/* How values for thread_single(). */ +#define SINGLE_NO_EXIT 0 +#define SINGLE_EXIT 1 +#define SINGLE_BOUNDARY 2 +#define SINGLE_ALLPROC 3 + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_PARGS); +MALLOC_DECLARE(M_PGRP); +MALLOC_DECLARE(M_SESSION); +MALLOC_DECLARE(M_SUBPROC); +#endif + +#define FOREACH_PROC_IN_SYSTEM(p) \ + LIST_FOREACH((p), &allproc, p_list) +#define FOREACH_THREAD_IN_PROC(p, td) \ + TAILQ_FOREACH((td), &(p)->p_threads, td_plist) + +#define FIRST_THREAD_IN_PROC(p) TAILQ_FIRST(&(p)->p_threads) + +/* + * We use process IDs <= pid_max <= PID_MAX; PID_MAX + 1 must also fit + * in a pid_t, as it is used to represent "no process group". + */ +#define PID_MAX 99999 +#define NO_PID 100000 +extern pid_t pid_max; + +#define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) + + +#define STOPEVENT(p, e, v) do { \ + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, \ + "checking stopevent %d", (e)); \ + if ((p)->p_stops & (e)) { \ + PROC_LOCK(p); \ + stopevent((p), (e), (v)); \ + PROC_UNLOCK(p); \ + } \ +} while (0) +#define _STOPEVENT(p, e, v) do { \ + PROC_LOCK_ASSERT(p, MA_OWNED); \ + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &p->p_mtx.lock_object, \ + "checking stopevent %d", (e)); \ + if ((p)->p_stops & (e)) \ + stopevent((p), (e), (v)); \ +} while (0) + +/* Lock and unlock a process. */ +#define PROC_LOCK(p) mtx_lock(&(p)->p_mtx) +#define PROC_TRYLOCK(p) mtx_trylock(&(p)->p_mtx) +#define PROC_UNLOCK(p) mtx_unlock(&(p)->p_mtx) +#define PROC_LOCKED(p) mtx_owned(&(p)->p_mtx) +#define PROC_LOCK_ASSERT(p, type) mtx_assert(&(p)->p_mtx, (type)) + +/* Lock and unlock a process group. */ +#define PGRP_LOCK(pg) mtx_lock(&(pg)->pg_mtx) +#define PGRP_UNLOCK(pg) mtx_unlock(&(pg)->pg_mtx) +#define PGRP_LOCKED(pg) mtx_owned(&(pg)->pg_mtx) +#define PGRP_LOCK_ASSERT(pg, type) mtx_assert(&(pg)->pg_mtx, (type)) + +#define PGRP_LOCK_PGSIGNAL(pg) do { \ + if ((pg) != NULL) \ + PGRP_LOCK(pg); \ +} while (0) +#define PGRP_UNLOCK_PGSIGNAL(pg) do { \ + if ((pg) != NULL) \ + PGRP_UNLOCK(pg); \ +} while (0) + +/* Lock and unlock a session. */ +#define SESS_LOCK(s) mtx_lock(&(s)->s_mtx) +#define SESS_UNLOCK(s) mtx_unlock(&(s)->s_mtx) +#define SESS_LOCKED(s) mtx_owned(&(s)->s_mtx) +#define SESS_LOCK_ASSERT(s, type) mtx_assert(&(s)->s_mtx, (type)) + +/* + * Non-zero p_lock ensures that: + * - exit1() is not performed until p_lock reaches zero; + * - the process' threads stack are not swapped out if they are currently + * not (P_INMEM). + * + * PHOLD() asserts that the process (except the current process) is + * not exiting, increments p_lock and swaps threads stacks into memory, + * if needed. + * _PHOLD() is same as PHOLD(), it takes the process locked. + * _PHOLD_LITE() also takes the process locked, but comparing with + * _PHOLD(), it only guarantees that exit1() is not executed, + * faultin() is not called. + */ +#define PHOLD(p) do { \ + PROC_LOCK(p); \ + _PHOLD(p); \ + PROC_UNLOCK(p); \ +} while (0) +#define _PHOLD(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + KASSERT(!((p)->p_flag & P_WEXIT) || (p) == curproc, \ + ("PHOLD of exiting process %p", p)); \ + (p)->p_lock++; \ + if (((p)->p_flag & P_INMEM) == 0) \ + faultin((p)); \ +} while (0) +#define _PHOLD_LITE(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + KASSERT(!((p)->p_flag & P_WEXIT) || (p) == curproc, \ + ("PHOLD of exiting process %p", p)); \ + (p)->p_lock++; \ +} while (0) +#define PROC_ASSERT_HELD(p) do { \ + KASSERT((p)->p_lock > 0, ("process %p not held", p)); \ +} while (0) + +#define PRELE(p) do { \ + PROC_LOCK((p)); \ + _PRELE((p)); \ + PROC_UNLOCK((p)); \ +} while (0) +#define _PRELE(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + PROC_ASSERT_HELD(p); \ + (--(p)->p_lock); \ + if (((p)->p_flag & P_WEXIT) && (p)->p_lock == 0) \ + wakeup(&(p)->p_lock); \ +} while (0) +#define PROC_ASSERT_NOT_HELD(p) do { \ + KASSERT((p)->p_lock == 0, ("process %p held", p)); \ +} while (0) + +#define PROC_UPDATE_COW(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + (p)->p_cowgen++; \ +} while (0) + +/* Check whether a thread is safe to be swapped out. */ +#define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP) + +/* Control whether or not it is safe for curthread to sleep. */ +#define THREAD_NO_SLEEPING() ((curthread)->td_no_sleeping++) + +#define THREAD_SLEEPING_OK() ((curthread)->td_no_sleeping--) + +#define THREAD_CAN_SLEEP() ((curthread)->td_no_sleeping == 0) + +#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) +extern LIST_HEAD(pidhashhead, proc) *pidhashtbl; +extern u_long pidhash; +#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash]) +extern LIST_HEAD(tidhashhead, thread) *tidhashtbl; +extern u_long tidhash; +extern struct rwlock tidhash_lock; + +#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash]) +extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl; +extern u_long pgrphash; + +extern struct sx allproc_lock; +extern int allproc_gen; +extern struct sx proctree_lock; +extern struct mtx ppeers_lock; +extern struct proc proc0; /* Process slot for swapper. */ +extern struct thread0_storage thread0_st; /* Primary thread in proc0. */ +#define thread0 (thread0_st.t0st_thread) +extern struct vmspace vmspace0; /* VM space for proc0. */ +extern int hogticks; /* Limit on kernel cpu hogs. */ +extern int lastpid; +extern int nprocs, maxproc; /* Current and max number of procs. */ +extern int maxprocperuid; /* Max procs per uid. */ +extern u_long ps_arg_cache_limit; + +LIST_HEAD(proclist, proc); +TAILQ_HEAD(procqueue, proc); +TAILQ_HEAD(threadqueue, thread); +extern struct proclist allproc; /* List of all processes. */ +extern struct proclist zombproc; /* List of zombie processes. */ +extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */ + +extern struct uma_zone *proc_zone; + +struct proc *pfind(pid_t); /* Find process by id. */ +struct proc *pfind_any(pid_t); /* Find (zombie) process by id. */ +struct proc *pfind_locked(pid_t pid); +struct pgrp *pgfind(pid_t); /* Find process group by id. */ +struct proc *zpfind(pid_t); /* Find zombie process by id. */ + +struct fork_req { + int fr_flags; + int fr_pages; + int *fr_pidp; + struct proc **fr_procp; + int *fr_pd_fd; + int fr_pd_flags; + struct filecaps *fr_pd_fcaps; + int fr_flags2; +#define FR2_DROPSIG_CAUGHT 0x00001 /* Drop caught non-DFL signals */ +}; + +/* + * pget() flags. + */ +#define PGET_HOLD 0x00001 /* Hold the process. */ +#define PGET_CANSEE 0x00002 /* Check against p_cansee(). */ +#define PGET_CANDEBUG 0x00004 /* Check against p_candebug(). */ +#define PGET_ISCURRENT 0x00008 /* Check that the found process is current. */ +#define PGET_NOTWEXIT 0x00010 /* Check that the process is not in P_WEXIT. */ +#define PGET_NOTINEXEC 0x00020 /* Check that the process is not in P_INEXEC. */ +#define PGET_NOTID 0x00040 /* Do not assume tid if pid > PID_MAX. */ + +#define PGET_WANTREAD (PGET_HOLD | PGET_CANDEBUG | PGET_NOTWEXIT) + +int pget(pid_t pid, int flags, struct proc **pp); + +void ast(struct trapframe *framep); +struct thread *choosethread(void); +int cr_cansee(struct ucred *u1, struct ucred *u2); +int cr_canseesocket(struct ucred *cred, struct socket *so); +int cr_canseeothergids(struct ucred *u1, struct ucred *u2); +int cr_canseeotheruids(struct ucred *u1, struct ucred *u2); +int cr_canseejailproc(struct ucred *u1, struct ucred *u2); +int cr_cansignal(struct ucred *cred, struct proc *proc, int signum); +int enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, + struct session *sess); +int enterthispgrp(struct proc *p, struct pgrp *pgrp); +void faultin(struct proc *p); +int fork1(struct thread *, struct fork_req *); +void fork_exit(void (*)(void *, struct trapframe *), void *, + struct trapframe *); +void fork_return(struct thread *, struct trapframe *); +int inferior(struct proc *p); +void kern_proc_vmmap_resident(struct vm_map *map, struct vm_map_entry *entry, + int *resident_count, bool *super); +void kern_yield(int); +void kick_proc0(void); +void killjobc(void); +int leavepgrp(struct proc *p); +int maybe_preempt(struct thread *td); +void maybe_yield(void); +void mi_switch(int flags, struct thread *newtd); +int p_candebug(struct thread *td, struct proc *p); +int p_cansee(struct thread *td, struct proc *p); +int p_cansched(struct thread *td, struct proc *p); +int p_cansignal(struct thread *td, struct proc *p, int signum); +int p_canwait(struct thread *td, struct proc *p); +struct pargs *pargs_alloc(int len); +void pargs_drop(struct pargs *pa); +void pargs_hold(struct pargs *pa); +int proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb); +int proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb); +int proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb); +void procinit(void); +void proc_linkup0(struct proc *p, struct thread *td); +void proc_linkup(struct proc *p, struct thread *td); +struct proc *proc_realparent(struct proc *child); +void proc_reap(struct thread *td, struct proc *p, int *status, int options); +void proc_reparent(struct proc *child, struct proc *newparent, bool set_oppid); +void proc_add_orphan(struct proc *child, struct proc *parent); +void proc_set_traced(struct proc *p, bool stop); +void proc_wkilled(struct proc *p); +struct pstats *pstats_alloc(void); +void pstats_fork(struct pstats *src, struct pstats *dst); +void pstats_free(struct pstats *ps); +void proc_clear_orphan(struct proc *p); +void reaper_abandon_children(struct proc *p, bool exiting); +int securelevel_ge(struct ucred *cr, int level); +int securelevel_gt(struct ucred *cr, int level); +void sess_hold(struct session *); +void sess_release(struct session *); +int setrunnable(struct thread *); +void setsugid(struct proc *p); +int should_yield(void); +int sigonstack(size_t sp); +void stopevent(struct proc *, u_int, u_int); +struct thread *tdfind(lwpid_t, pid_t); +void threadinit(void); +void tidhash_add(struct thread *); +void tidhash_remove(struct thread *); +void cpu_idle(int); +int cpu_idle_wakeup(int); +extern void (*cpu_idle_hook)(sbintime_t); /* Hook to machdep CPU idler. */ +void cpu_switch(struct thread *, struct thread *, struct mtx *); +void cpu_throw(struct thread *, struct thread *) __dead2; +void unsleep(struct thread *); +void userret(struct thread *, struct trapframe *); + +void cpu_exit(struct thread *); +void exit1(struct thread *, int, int) __dead2; +void cpu_copy_thread(struct thread *td, struct thread *td0); +bool cpu_exec_vmspace_reuse(struct proc *p, struct vm_map *map); +int cpu_fetch_syscall_args(struct thread *td); +void cpu_fork(struct thread *, struct proc *, struct thread *, int); +void cpu_fork_kthread_handler(struct thread *, void (*)(void *), void *); +int cpu_procctl(struct thread *td, int idtype, id_t id, int com, + void *data); +void cpu_set_syscall_retval(struct thread *, int); +void cpu_set_upcall(struct thread *, void (*)(void *), void *, + stack_t *); +int cpu_set_user_tls(struct thread *, void *tls_base); +void cpu_thread_alloc(struct thread *); +void cpu_thread_clean(struct thread *); +void cpu_thread_exit(struct thread *); +void cpu_thread_free(struct thread *); +void cpu_thread_swapin(struct thread *); +void cpu_thread_swapout(struct thread *); +struct thread *thread_alloc(int pages); +int thread_alloc_stack(struct thread *, int pages); +int thread_check_susp(struct thread *td, bool sleep); +void thread_cow_get_proc(struct thread *newtd, struct proc *p); +void thread_cow_get(struct thread *newtd, struct thread *td); +void thread_cow_free(struct thread *td); +void thread_cow_update(struct thread *td); +int thread_create(struct thread *td, struct rtprio *rtp, + int (*initialize_thread)(struct thread *, void *), void *thunk); +void thread_exit(void) __dead2; +void thread_free(struct thread *td); +void thread_link(struct thread *td, struct proc *p); +void thread_reap(void); +int thread_single(struct proc *p, int how); +void thread_single_end(struct proc *p, int how); +void thread_stash(struct thread *td); +void thread_stopped(struct proc *p); +void childproc_stopped(struct proc *child, int reason); +void childproc_continued(struct proc *child); +void childproc_exited(struct proc *child); +int thread_suspend_check(int how); +bool thread_suspend_check_needed(void); +void thread_suspend_switch(struct thread *, struct proc *p); +void thread_suspend_one(struct thread *td); +void thread_unlink(struct thread *td); +void thread_unsuspend(struct proc *p); +void thread_wait(struct proc *p); +struct thread *thread_find(struct proc *p, lwpid_t tid); + +void stop_all_proc(void); +void resume_all_proc(void); + +static __inline int +curthread_pflags_set(int flags) +{ + struct thread *td; + int save; + + td = curthread; + save = ~flags | (td->td_pflags & flags); + td->td_pflags |= flags; + return (save); +} + +static __inline void +curthread_pflags_restore(int save) +{ + + curthread->td_pflags &= save; +} + +static __inline int +curthread_pflags2_set(int flags) +{ + struct thread *td; + int save; + + td = curthread; + save = ~flags | (td->td_pflags2 & flags); + td->td_pflags2 |= flags; + return (save); +} + +static __inline void +curthread_pflags2_restore(int save) +{ + + curthread->td_pflags2 &= save; +} + +static __inline __pure2 struct td_sched * +td_get_sched(struct thread *td) +{ + + return ((struct td_sched *)&td[1]); +} + +extern void (*softdep_ast_cleanup)(struct thread *); +static __inline void +td_softdep_cleanup(struct thread *td) +{ + + if (td->td_su != NULL && softdep_ast_cleanup != NULL) + softdep_ast_cleanup(td); +} + +#endif /* _KERNEL */ + +#endif /* !_SYS_PROC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/procctl.h b/lib/libc/include/any-freebsd-any/sys/procctl.h new file mode 100644 index 000000000000..a6837bde579e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/procctl.h @@ -0,0 +1,144 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Hudson River Trading LLC + * Copyright (c) 2014, 2016 The FreeBSD Foundation + * Written by: John H. Baldwin + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PROCCTL_H_ +#define _SYS_PROCCTL_H_ + +#ifndef _KERNEL +#include +#include +#endif + +/* MD PROCCTL verbs start at 0x10000000 */ +#define PROC_PROCCTL_MD_MIN 0x10000000 +#include + +#define PROC_SPROTECT 1 /* set protected state */ +#define PROC_REAP_ACQUIRE 2 /* reaping enable */ +#define PROC_REAP_RELEASE 3 /* reaping disable */ +#define PROC_REAP_STATUS 4 /* reaping status */ +#define PROC_REAP_GETPIDS 5 /* get descendants */ +#define PROC_REAP_KILL 6 /* kill descendants */ +#define PROC_TRACE_CTL 7 /* en/dis ptrace and coredumps */ +#define PROC_TRACE_STATUS 8 /* query tracing status */ +#define PROC_TRAPCAP_CTL 9 /* trap capability errors */ +#define PROC_TRAPCAP_STATUS 10 /* query trap capability status */ +#define PROC_PDEATHSIG_CTL 11 /* set parent death signal */ +#define PROC_PDEATHSIG_STATUS 12 /* get parent death signal */ +#define PROC_ASLR_CTL 13 /* en/dis ASLR */ +#define PROC_ASLR_STATUS 14 /* query ASLR status */ +#define PROC_STACKGAP_CTL 17 /* en/dis stack gap on MAP_STACK */ +#define PROC_STACKGAP_STATUS 18 /* query stack gap */ + +/* Operations for PROC_SPROTECT (passed in integer arg). */ +#define PPROT_OP(x) ((x) & 0xf) +#define PPROT_SET 1 +#define PPROT_CLEAR 2 + +/* Flags for PROC_SPROTECT (ORed in with operation). */ +#define PPROT_FLAGS(x) ((x) & ~0xf) +#define PPROT_DESCEND 0x10 +#define PPROT_INHERIT 0x20 + +/* Result of PREAP_STATUS (returned by value). */ +struct procctl_reaper_status { + u_int rs_flags; + u_int rs_children; + u_int rs_descendants; + pid_t rs_reaper; + pid_t rs_pid; + u_int rs_pad0[15]; +}; + +/* struct procctl_reaper_status rs_flags */ +#define REAPER_STATUS_OWNED 0x00000001 +#define REAPER_STATUS_REALINIT 0x00000002 + +struct procctl_reaper_pidinfo { + pid_t pi_pid; + pid_t pi_subtree; + u_int pi_flags; + u_int pi_pad0[15]; +}; + +#define REAPER_PIDINFO_VALID 0x00000001 +#define REAPER_PIDINFO_CHILD 0x00000002 +#define REAPER_PIDINFO_REAPER 0x00000004 + +struct procctl_reaper_pids { + u_int rp_count; + u_int rp_pad0[15]; + struct procctl_reaper_pidinfo *rp_pids; +}; + +struct procctl_reaper_kill { + int rk_sig; /* in - signal to send */ + u_int rk_flags; /* in - REAPER_KILL flags */ + pid_t rk_subtree; /* in - subtree, if REAPER_KILL_SUBTREE */ + u_int rk_killed; /* out - count of processes successfully + killed */ + pid_t rk_fpid; /* out - first failed pid for which error + is returned */ + u_int rk_pad0[15]; +}; + +#define REAPER_KILL_CHILDREN 0x00000001 +#define REAPER_KILL_SUBTREE 0x00000002 + +#define PROC_TRACE_CTL_ENABLE 1 +#define PROC_TRACE_CTL_DISABLE 2 +#define PROC_TRACE_CTL_DISABLE_EXEC 3 + +#define PROC_TRAPCAP_CTL_ENABLE 1 +#define PROC_TRAPCAP_CTL_DISABLE 2 + +#define PROC_ASLR_FORCE_ENABLE 1 +#define PROC_ASLR_FORCE_DISABLE 2 +#define PROC_ASLR_NOFORCE 3 +#define PROC_ASLR_ACTIVE 0x80000000 + +#define PROC_STACKGAP_ENABLE 0x0001 +#define PROC_STACKGAP_DISABLE 0x0002 +#define PROC_STACKGAP_ENABLE_EXEC 0x0004 +#define PROC_STACKGAP_DISABLE_EXEC 0x0008 + +#ifndef _KERNEL +__BEGIN_DECLS +int procctl(idtype_t, id_t, int, void *); +__END_DECLS + +#endif + +#endif /* !_SYS_PROCCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/procdesc.h b/lib/libc/include/any-freebsd-any/sys/procdesc.h new file mode 100644 index 000000000000..b307917c5479 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/procdesc.h @@ -0,0 +1,139 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 Robert N. M. Watson + * All rights reserved. + * + * This software was developed at the University of Cambridge Computer + * Laboratory with support from a grant from Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PROCDESC_H_ +#define _SYS_PROCDESC_H_ + +#ifdef _KERNEL + +#include /* struct selinfo */ +#include +#include + +/*- + * struct procdesc describes a process descriptor, and essentially consists + * of two pointers -- one to the file descriptor, and one to the process. + * When both become NULL, the process descriptor will be freed. An important + * invariant is that there is only ever one process descriptor for a process, + * so a single file pointer will suffice. + * + * Locking key: + * (c) - Constant after initial setup. + * (p) - Protected by the process descriptor mutex. + * (r) - Atomic reference count. + * (s) - Protected by selinfo. + * (t) - Protected by the proctree_lock + */ +struct proc; +struct sigio; +struct procdesc { + /* + * Basic process descriptor state: the process, a cache of its pid to + * satisfy queries after the process exits, and process descriptor + * refcount. + */ + struct proc *pd_proc; /* (t) Process. */ + pid_t pd_pid; /* (c) Cached pid. */ + u_int pd_refcount; /* (r) Reference count. */ + + /* + * In-flight data and notification of events. + */ + int pd_flags; /* (p) PD_ flags. */ + u_short pd_xstat; /* (p) Exit status. */ + struct selinfo pd_selinfo; /* (p) Event notification. */ + struct mtx pd_lock; /* Protect data + events. */ +}; + +/* + * Locking macros for the procdesc itself. + */ +#define PROCDESC_LOCK_DESTROY(pd) mtx_destroy(&(pd)->pd_lock) +#define PROCDESC_LOCK_INIT(pd) mtx_init(&(pd)->pd_lock, "procdesc", NULL, \ + MTX_DEF) +#define PROCDESC_LOCK(pd) mtx_lock(&(pd)->pd_lock) +#define PROCDESC_UNLOCK(pd) mtx_unlock(&(pd)->pd_lock) + +/* + * Flags for the pd_flags field. + */ +#define PDF_CLOSED 0x00000001 /* Descriptor has closed. */ +#define PDF_SELECTED 0x00000002 /* Issue selwakeup(). */ +#define PDF_EXITED 0x00000004 /* Process exited. */ +#define PDF_DAEMON 0x00000008 /* Don't exit when procdesc closes. */ + +/* + * In-kernel interfaces to process descriptors. + */ +int procdesc_exit(struct proc *); +int procdesc_find(struct thread *, int fd, cap_rights_t *, struct proc **); +int kern_pdgetpid(struct thread *, int fd, cap_rights_t *, pid_t *pidp); +void procdesc_new(struct proc *, int); +void procdesc_finit(struct procdesc *, struct file *); +pid_t procdesc_pid(struct file *); +void procdesc_reap(struct proc *); + +int procdesc_falloc(struct thread *, struct file **, int *, int, + struct filecaps *); + +#else /* !_KERNEL */ + +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +struct rusage; + +/* + * Process descriptor system calls. + */ +__BEGIN_DECLS +pid_t pdfork(int *, int); +int pdkill(int, int); +int pdgetpid(int, pid_t *); +__END_DECLS + +#endif /* _KERNEL */ + +/* + * Flags which can be passed to pdfork(2). + */ +#define PD_DAEMON 0x00000001 /* Don't exit when procdesc closes. */ +#define PD_CLOEXEC 0x00000002 /* Close file descriptor on exec. */ + +#define PD_ALLOWED_AT_FORK (PD_DAEMON | PD_CLOEXEC) + +#endif /* !_SYS_PROCDESC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/procfs.h b/lib/libc/include/any-freebsd-any/sys/procfs.h new file mode 100644 index 000000000000..85e718b20c35 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/procfs.h @@ -0,0 +1,122 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PROCFS_H_ +#define _SYS_PROCFS_H_ + +#include +#include + +typedef struct reg gregset_t; +typedef struct fpreg fpregset_t; + +/* + * These structures define an interface between core files and the debugger. + * Never change or delete any elements. If you add elements, add them to + * the end of the structure, and increment the value of its version field. + * This will help to ensure that today's core dump will still be usable + * with next year's debugger. + * + * A lot more things should be added to these structures. At present, + * they contain the absolute bare minimum required to allow GDB to work + * with ELF core dumps. + */ + +/* + * The parenthsized numbers like (1) indicate the minimum version number + * for which each element exists in the structure. The version number is + * not bumped when adding new fields to the end, only if the meaning of + * an existing field changes. Additional fields are annotated as (1a), + * (1b), etc. to indicate the groupings of additions. + */ + +#define PRSTATUS_VERSION 1 /* Current version of prstatus_t */ + +typedef struct prstatus { + int pr_version; /* Version number of struct (1) */ + size_t pr_statussz; /* sizeof(prstatus_t) (1) */ + size_t pr_gregsetsz; /* sizeof(gregset_t) (1) */ + size_t pr_fpregsetsz; /* sizeof(fpregset_t) (1) */ + int pr_osreldate; /* Kernel version (1) */ + int pr_cursig; /* Current signal (1) */ + pid_t pr_pid; /* LWP (Thread) ID (1) */ + gregset_t pr_reg; /* General purpose registers (1) */ +} prstatus_t; + +typedef gregset_t prgregset_t[1]; +typedef fpregset_t prfpregset_t; + +#define PRFNAMESZ 16 /* Maximum command length saved */ +#define PRARGSZ 80 /* Maximum argument bytes saved */ + +#define PRPSINFO_VERSION 1 /* Current version of prpsinfo_t */ + +typedef struct prpsinfo { + int pr_version; /* Version number of struct (1) */ + size_t pr_psinfosz; /* sizeof(prpsinfo_t) (1) */ + char pr_fname[PRFNAMESZ+1]; /* Command name, null terminated (1) */ + char pr_psargs[PRARGSZ+1]; /* Arguments, null terminated (1) */ + pid_t pr_pid; /* Process ID (1a) */ +} prpsinfo_t; + +typedef struct thrmisc { + char pr_tname[MAXCOMLEN+1]; /* Thread name, null terminated (1) */ + u_int _pad; /* Convenience pad, 0-filled (1) */ +} thrmisc_t; + +typedef uint64_t psaddr_t; /* An address in the target process. */ + +#ifdef __HAVE_REG32 +typedef struct prstatus32 { + int32_t pr_version; + uint32_t pr_statussz; + uint32_t pr_gregsetsz; + uint32_t pr_fpregsetsz; + int32_t pr_osreldate; + int32_t pr_cursig; + int32_t pr_pid; + struct reg32 pr_reg; +} prstatus32_t; + +typedef struct prpsinfo32 { + int32_t pr_version; + uint32_t pr_psinfosz; + char pr_fname[PRFNAMESZ+1]; + char pr_psargs[PRARGSZ+1]; + int32_t pr_pid; +} prpsinfo32_t; + +struct thrmisc32 { + char pr_tname[MAXCOMLEN+1]; + uint32_t _pad; +}; +#endif /* __HAVE_REG32 */ + +#endif /* _SYS_PROCFS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/protosw.h b/lib/libc/include/any-freebsd-any/sys/protosw.h new file mode 100644 index 000000000000..a8aa7f860c09 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/protosw.h @@ -0,0 +1,354 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)protosw.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_PROTOSW_H_ +#define _SYS_PROTOSW_H_ + +/* Forward declare these structures referenced from prototypes below. */ +struct kaiocb; +struct mbuf; +struct thread; +struct sockaddr; +struct socket; +struct sockopt; + +/*#ifdef _KERNEL*/ +/* + * Protocol switch table. + * + * Each protocol has a handle initializing one of these structures, + * which is used for protocol-protocol and system-protocol communication. + * + * A protocol is called through the pr_init entry before any other. + * Thereafter it is called every 200ms through the pr_fasttimo entry and + * every 500ms through the pr_slowtimo for timer based actions. + * The system will call the pr_drain entry if it is low on space and + * this should throw away any non-critical data. + * + * Protocols pass data between themselves as chains of mbufs using + * the pr_input and pr_output hooks. Pr_input passes data up (towards + * the users) and pr_output passes it down (towards the interfaces); control + * information passes up and down on pr_ctlinput and pr_ctloutput. + * The protocol is responsible for the space occupied by any the + * arguments to these entries and must dispose it. + * + * In retrospect, it would be a lot nicer to use an interface + * similar to the vnode VOP interface. + */ +/* USE THESE FOR YOUR PROTOTYPES ! */ +typedef int pr_input_t (struct mbuf **, int*, int); +typedef int pr_output_t (struct mbuf *, struct socket *, ...); +typedef void pr_ctlinput_t (int, struct sockaddr *, void *); +typedef int pr_ctloutput_t (struct socket *, struct sockopt *); +typedef void pr_init_t (void); +typedef void pr_fasttimo_t (void); +typedef void pr_slowtimo_t (void); +typedef void pr_drain_t (void); + +struct protosw { + short pr_type; /* socket type used for */ + struct domain *pr_domain; /* domain protocol a member of */ + short pr_protocol; /* protocol number */ + short pr_flags; /* see below */ +/* protocol-protocol hooks */ + pr_input_t *pr_input; /* input to protocol (from below) */ + pr_output_t *pr_output; /* output to protocol (from above) */ + pr_ctlinput_t *pr_ctlinput; /* control input (from below) */ + pr_ctloutput_t *pr_ctloutput; /* control output (from above) */ +/* utility hooks */ + pr_init_t *pr_init; + pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */ + pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */ + pr_drain_t *pr_drain; /* flush any excess space possible */ + + struct pr_usrreqs *pr_usrreqs; /* user-protocol hook */ +}; +/*#endif*/ + +#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ +#define PR_FASTHZ 5 /* 5 fast timeouts per second */ + +/* + * This number should be defined again within each protocol family to avoid + * confusion. + */ +#define PROTO_SPACER 32767 /* spacer for loadable protocols */ + +/* + * Values for pr_flags. + * PR_ADDR requires PR_ATOMIC; + * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. + * PR_IMPLOPCL means that the protocol allows sendto without prior connect, + * and the protocol understands the MSG_EOF flag. The first property is + * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed + * anyhow). + */ +#define PR_ATOMIC 0x01 /* exchange atomic messages only */ +#define PR_ADDR 0x02 /* addresses given with messages */ +#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ +#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ +#define PR_RIGHTS 0x10 /* passes capabilities */ +#define PR_IMPLOPCL 0x20 /* implied open/close */ +#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */ + +/* + * In earlier BSD network stacks, a single pr_usrreq() function pointer was + * invoked with an operation number indicating what operation was desired. + * We now provide individual function pointers which protocols can implement, + * which offers a number of benefits (such as type checking for arguments). + * These older constants are still present in order to support TCP debugging. + */ +#define PRU_ATTACH 0 /* attach protocol to up */ +#define PRU_DETACH 1 /* detach protocol from up */ +#define PRU_BIND 2 /* bind socket to address */ +#define PRU_LISTEN 3 /* listen for connection */ +#define PRU_CONNECT 4 /* establish connection to peer */ +#define PRU_ACCEPT 5 /* accept connection from peer */ +#define PRU_DISCONNECT 6 /* disconnect from peer */ +#define PRU_SHUTDOWN 7 /* won't send any more data */ +#define PRU_RCVD 8 /* have taken data; more room now */ +#define PRU_SEND 9 /* send this data */ +#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ +#define PRU_CONTROL 11 /* control operations on protocol */ +#define PRU_SENSE 12 /* return status into m */ +#define PRU_RCVOOB 13 /* retrieve out of band data */ +#define PRU_SENDOOB 14 /* send out of band data */ +#define PRU_SOCKADDR 15 /* fetch socket's address */ +#define PRU_PEERADDR 16 /* fetch peer's address */ +#define PRU_CONNECT2 17 /* connect two sockets */ +/* begin for protocols internal use */ +#define PRU_FASTTIMO 18 /* 200ms timeout */ +#define PRU_SLOWTIMO 19 /* 500ms timeout */ +#define PRU_PROTORCV 20 /* receive from below */ +#define PRU_PROTOSEND 21 /* send to below */ +/* end for protocol's internal use */ +#define PRU_SEND_EOF 22 /* send and close */ +#define PRU_SOSETLABEL 23 /* MAC label change */ +#define PRU_CLOSE 24 /* socket close */ +#define PRU_FLUSH 25 /* flush the socket */ +#define PRU_NREQ 25 + +#ifdef PRUREQUESTS +const char *prurequests[] = { + "ATTACH", "DETACH", "BIND", "LISTEN", + "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", + "RCVD", "SEND", "ABORT", "CONTROL", + "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", + "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", + "PROTORCV", "PROTOSEND", "SEND_EOF", "SOSETLABEL", + "CLOSE", "FLUSH", +}; +#endif + +#ifdef _KERNEL /* users shouldn't see this decl */ + +struct ifnet; +struct stat; +struct ucred; +struct uio; + +/* + * If the ordering here looks odd, that's because it's alphabetical. These + * should eventually be merged back into struct protosw. + * + * Some fields initialized to defaults if they are NULL. + * See uipc_domain.c:net_init_domain() + */ +struct pr_usrreqs { + void (*pru_abort)(struct socket *so); + int (*pru_accept)(struct socket *so, struct sockaddr **nam); + int (*pru_attach)(struct socket *so, int proto, struct thread *td); + int (*pru_bind)(struct socket *so, struct sockaddr *nam, + struct thread *td); + int (*pru_connect)(struct socket *so, struct sockaddr *nam, + struct thread *td); + int (*pru_connect2)(struct socket *so1, struct socket *so2); + int (*pru_control)(struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp, struct thread *td); + void (*pru_detach)(struct socket *so); + int (*pru_disconnect)(struct socket *so); + int (*pru_listen)(struct socket *so, int backlog, + struct thread *td); + int (*pru_peeraddr)(struct socket *so, struct sockaddr **nam); + int (*pru_rcvd)(struct socket *so, int flags); + int (*pru_rcvoob)(struct socket *so, struct mbuf *m, int flags); + int (*pru_send)(struct socket *so, int flags, struct mbuf *m, + struct sockaddr *addr, struct mbuf *control, + struct thread *td); +#define PRUS_OOB 0x1 +#define PRUS_EOF 0x2 +#define PRUS_MORETOCOME 0x4 +#define PRUS_NOTREADY 0x8 +#define PRUS_IPV6 0x10 + int (*pru_ready)(struct socket *so, struct mbuf *m, int count); + int (*pru_sense)(struct socket *so, struct stat *sb); + int (*pru_shutdown)(struct socket *so); + int (*pru_flush)(struct socket *so, int direction); + int (*pru_sockaddr)(struct socket *so, struct sockaddr **nam); + int (*pru_sosend)(struct socket *so, struct sockaddr *addr, + struct uio *uio, struct mbuf *top, struct mbuf *control, + int flags, struct thread *td); + int (*pru_soreceive)(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); + int (*pru_sopoll)(struct socket *so, int events, + struct ucred *cred, struct thread *td); + void (*pru_sosetlabel)(struct socket *so); + void (*pru_close)(struct socket *so); + int (*pru_bindat)(int fd, struct socket *so, struct sockaddr *nam, + struct thread *td); + int (*pru_connectat)(int fd, struct socket *so, + struct sockaddr *nam, struct thread *td); + int (*pru_aio_queue)(struct socket *so, struct kaiocb *job); +}; + +/* + * All nonvoid pru_*() functions below return EOPNOTSUPP. + */ +int pru_accept_notsupp(struct socket *so, struct sockaddr **nam); +int pru_aio_queue_notsupp(struct socket *so, struct kaiocb *job); +int pru_attach_notsupp(struct socket *so, int proto, struct thread *td); +int pru_bind_notsupp(struct socket *so, struct sockaddr *nam, + struct thread *td); +int pru_bindat_notsupp(int fd, struct socket *so, struct sockaddr *nam, + struct thread *td); +int pru_connect_notsupp(struct socket *so, struct sockaddr *nam, + struct thread *td); +int pru_connectat_notsupp(int fd, struct socket *so, struct sockaddr *nam, + struct thread *td); +int pru_connect2_notsupp(struct socket *so1, struct socket *so2); +int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp, struct thread *td); +int pru_disconnect_notsupp(struct socket *so); +int pru_listen_notsupp(struct socket *so, int backlog, struct thread *td); +int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam); +int pru_rcvd_notsupp(struct socket *so, int flags); +int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags); +int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m, + struct sockaddr *addr, struct mbuf *control, struct thread *td); +int pru_ready_notsupp(struct socket *so, struct mbuf *m, int count); +int pru_sense_null(struct socket *so, struct stat *sb); +int pru_shutdown_notsupp(struct socket *so); +int pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam); +int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr, + struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, + struct thread *td); +int pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); +int pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred, + struct thread *td); + +#endif /* _KERNEL */ + +/* + * The arguments to the ctlinput routine are + * (*protosw[].pr_ctlinput)(cmd, sa, arg); + * where cmd is one of the commands below, sa is a pointer to a sockaddr, + * and arg is a `void *' argument used within a protocol family. + */ +#define PRC_IFDOWN 0 /* interface transition */ +#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ +#define PRC_IFUP 2 /* interface has come back up */ +/* was PRC_QUENCH2 3 DEC congestion bit says slow down */ +/* was PRC_QUENCH 4 Deprecated by RFC 6633 */ +#define PRC_MSGSIZE 5 /* message size forced drop */ +#define PRC_HOSTDEAD 6 /* host appears to be down */ +#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ +#define PRC_UNREACH_NET 8 /* no route to network */ +#define PRC_UNREACH_HOST 9 /* no route to host */ +#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ +#define PRC_UNREACH_PORT 11 /* bad port # */ +/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ +#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ +#define PRC_REDIRECT_NET 14 /* net routing redirect */ +#define PRC_REDIRECT_HOST 15 /* host routing redirect */ +#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ +#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ +#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ +#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ +#define PRC_PARAMPROB 20 /* header incorrect */ +#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */ + +#define PRC_NCMDS 22 + +#define PRC_IS_REDIRECT(cmd) \ + ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) + +#ifdef PRCREQUESTS +char *prcrequests[] = { + "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", + "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", + "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", + "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", + "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", + "PARAMPROB", "ADMIN-UNREACH" +}; +#endif + +/* + * The arguments to ctloutput are: + * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); + * req is one of the actions listed below, so is a (struct socket *), + * level is an indication of which protocol layer the option is intended. + * optname is a protocol dependent socket option request, + * optval is a pointer to a mbuf-chain pointer, for value-return results. + * The protocol is responsible for disposal of the mbuf chain *optval + * if supplied, + * the caller is responsible for any space held by *optval, when returned. + * A non-zero return from ctloutput gives an + * UNIX error number which should be passed to higher level software. + */ +#define PRCO_GETOPT 0 +#define PRCO_SETOPT 1 + +#define PRCO_NCMDS 2 + +#ifdef PRCOREQUESTS +char *prcorequests[] = { + "GETOPT", "SETOPT", +}; +#endif + +#ifdef _KERNEL +void pfctlinput(int, struct sockaddr *); +void pfctlinput2(int, struct sockaddr *, void *); +struct domain *pffinddomain(int family); +struct protosw *pffindproto(int family, int protocol, int type); +struct protosw *pffindtype(int family, int type); +int pf_proto_register(int family, struct protosw *npr); +int pf_proto_unregister(int family, int protocol, int type); +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/ptio.h b/lib/libc/include/any-freebsd-any/sys/ptio.h new file mode 100644 index 000000000000..1c5aad22197b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ptio.h @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1999 Kenneth D. Merry. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PTIO_H_ +#define _SYS_PTIO_H_ + +#include + +#define PTIOCGETTIMEOUT _IOR('T', 1, int) +#define PTIOCSETTIMEOUT _IOW('T', 2, int) + +#endif /* !_SYS_PTIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ptrace.h b/lib/libc/include/any-freebsd-any/sys/ptrace.h new file mode 100644 index 000000000000..1ee42318e57e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ptrace.h @@ -0,0 +1,232 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1984, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ptrace.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_PTRACE_H_ +#define _SYS_PTRACE_H_ + +#include +#include +#include + +#define PT_TRACE_ME 0 /* child declares it's being traced */ +#define PT_READ_I 1 /* read word in child's I space */ +#define PT_READ_D 2 /* read word in child's D space */ +/* was PT_READ_U 3 * read word in child's user structure */ +#define PT_WRITE_I 4 /* write word in child's I space */ +#define PT_WRITE_D 5 /* write word in child's D space */ +/* was PT_WRITE_U 6 * write word in child's user structure */ +#define PT_CONTINUE 7 /* continue the child */ +#define PT_KILL 8 /* kill the child process */ +#define PT_STEP 9 /* single step the child */ + +#define PT_ATTACH 10 /* trace some running process */ +#define PT_DETACH 11 /* stop tracing a process */ +#define PT_IO 12 /* do I/O to/from stopped process. */ +#define PT_LWPINFO 13 /* Info about the LWP that stopped. */ +#define PT_GETNUMLWPS 14 /* get total number of threads */ +#define PT_GETLWPLIST 15 /* get thread list */ +#define PT_CLEARSTEP 16 /* turn off single step */ +#define PT_SETSTEP 17 /* turn on single step */ +#define PT_SUSPEND 18 /* suspend a thread */ +#define PT_RESUME 19 /* resume a thread */ + +#define PT_TO_SCE 20 +#define PT_TO_SCX 21 +#define PT_SYSCALL 22 + +#define PT_FOLLOW_FORK 23 +#define PT_LWP_EVENTS 24 /* report LWP birth and exit */ + +#define PT_GET_EVENT_MASK 25 /* get mask of optional events */ +#define PT_SET_EVENT_MASK 26 /* set mask of optional events */ + +#define PT_GET_SC_ARGS 27 /* fetch syscall args */ +#define PT_GET_SC_RET 28 /* fetch syscall results */ + +#define PT_GETREGS 33 /* get general-purpose registers */ +#define PT_SETREGS 34 /* set general-purpose registers */ +#define PT_GETFPREGS 35 /* get floating-point registers */ +#define PT_SETFPREGS 36 /* set floating-point registers */ +#define PT_GETDBREGS 37 /* get debugging registers */ +#define PT_SETDBREGS 38 /* set debugging registers */ + +#define PT_VM_TIMESTAMP 40 /* Get VM version (timestamp) */ +#define PT_VM_ENTRY 41 /* Get VM map (entry) */ + +#define PT_FIRSTMACH 64 /* for machine-specific requests */ +#include /* machine-specific requests, if any */ + +/* Events used with PT_GET_EVENT_MASK and PT_SET_EVENT_MASK */ +#define PTRACE_EXEC 0x0001 +#define PTRACE_SCE 0x0002 +#define PTRACE_SCX 0x0004 +#define PTRACE_SYSCALL (PTRACE_SCE | PTRACE_SCX) +#define PTRACE_FORK 0x0008 +#define PTRACE_LWP 0x0010 +#define PTRACE_VFORK 0x0020 + +#define PTRACE_DEFAULT (PTRACE_EXEC) + +struct ptrace_io_desc { + int piod_op; /* I/O operation */ + void *piod_offs; /* child offset */ + void *piod_addr; /* parent offset */ + size_t piod_len; /* request length */ +}; + +/* + * Operations in piod_op. + */ +#define PIOD_READ_D 1 /* Read from D space */ +#define PIOD_WRITE_D 2 /* Write to D space */ +#define PIOD_READ_I 3 /* Read from I space */ +#define PIOD_WRITE_I 4 /* Write to I space */ + +/* Argument structure for PT_LWPINFO. */ +struct ptrace_lwpinfo { + lwpid_t pl_lwpid; /* LWP described. */ + int pl_event; /* Event that stopped the LWP. */ +#define PL_EVENT_NONE 0 +#define PL_EVENT_SIGNAL 1 + int pl_flags; /* LWP flags. */ +#define PL_FLAG_SA 0x01 /* M:N thread */ +#define PL_FLAG_BOUND 0x02 /* M:N bound thread */ +#define PL_FLAG_SCE 0x04 /* syscall enter point */ +#define PL_FLAG_SCX 0x08 /* syscall leave point */ +#define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ +#define PL_FLAG_SI 0x20 /* siginfo is valid */ +#define PL_FLAG_FORKED 0x40 /* new child */ +#define PL_FLAG_CHILD 0x80 /* I am from child */ +#define PL_FLAG_BORN 0x100 /* new LWP */ +#define PL_FLAG_EXITED 0x200 /* exiting LWP */ +#define PL_FLAG_VFORKED 0x400 /* new child via vfork */ +#define PL_FLAG_VFORK_DONE 0x800 /* vfork parent has resumed */ + sigset_t pl_sigmask; /* LWP signal mask */ + sigset_t pl_siglist; /* LWP pending signal */ + struct __siginfo pl_siginfo; /* siginfo for signal */ + char pl_tdname[MAXCOMLEN + 1]; /* LWP name */ + pid_t pl_child_pid; /* New child pid */ + u_int pl_syscall_code; + u_int pl_syscall_narg; +}; + +#if defined(_WANT_LWPINFO32) || (defined(_KERNEL) && defined(__LP64__)) +struct ptrace_lwpinfo32 { + lwpid_t pl_lwpid; /* LWP described. */ + int pl_event; /* Event that stopped the LWP. */ + int pl_flags; /* LWP flags. */ + sigset_t pl_sigmask; /* LWP signal mask */ + sigset_t pl_siglist; /* LWP pending signal */ + struct siginfo32 pl_siginfo; /* siginfo for signal */ + char pl_tdname[MAXCOMLEN + 1]; /* LWP name. */ + pid_t pl_child_pid; /* New child pid */ + u_int pl_syscall_code; + u_int pl_syscall_narg; +}; +#endif + +/* Argument structure for PT_GET_SC_RET. */ +struct ptrace_sc_ret { + register_t sr_retval[2]; /* Only valid if sr_error == 0. */ + int sr_error; +}; + +/* Argument structure for PT_VM_ENTRY. */ +struct ptrace_vm_entry { + int pve_entry; /* Entry number used for iteration. */ + int pve_timestamp; /* Generation number of VM map. */ + u_long pve_start; /* Start VA of range. */ + u_long pve_end; /* End VA of range (incl). */ + u_long pve_offset; /* Offset in backing object. */ + u_int pve_prot; /* Protection of memory range. */ + u_int pve_pathlen; /* Size of path. */ + long pve_fileid; /* File ID. */ + uint32_t pve_fsid; /* File system ID. */ + char *pve_path; /* Path name of object. */ +}; + +#ifdef _KERNEL + +int ptrace_set_pc(struct thread *_td, unsigned long _addr); +int ptrace_single_step(struct thread *_td); +int ptrace_clear_single_step(struct thread *_td); + +#ifdef __HAVE_PTRACE_MACHDEP +int cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data); +#endif + +/* + * These are prototypes for functions that implement some of the + * debugging functionality exported by procfs / linprocfs and by the + * ptrace(2) syscall. They used to be part of procfs, but they don't + * really belong there. + */ +struct reg; +struct fpreg; +struct dbreg; +struct uio; +int proc_read_regs(struct thread *_td, struct reg *_reg); +int proc_write_regs(struct thread *_td, struct reg *_reg); +int proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg); +int proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg); +int proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg); +int proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg); +int proc_sstep(struct thread *_td); +int proc_rwmem(struct proc *_p, struct uio *_uio); +ssize_t proc_readmem(struct thread *_td, struct proc *_p, vm_offset_t _va, + void *_buf, size_t _len); +ssize_t proc_writemem(struct thread *_td, struct proc *_p, vm_offset_t _va, + void *_buf, size_t _len); +#ifdef COMPAT_FREEBSD32 +struct reg32; +struct fpreg32; +struct dbreg32; +int proc_read_regs32(struct thread *_td, struct reg32 *_reg32); +int proc_write_regs32(struct thread *_td, struct reg32 *_reg32); +int proc_read_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); +int proc_write_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); +int proc_read_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); +int proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); +#endif +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_PTRACE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/queue.h b/lib/libc/include/any-freebsd-any/sys/queue.h new file mode 100644 index 000000000000..5e12299e01c6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/queue.h @@ -0,0 +1,875 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD$ + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#include + +/* + * This file defines four types of data structures: singly-linked lists, + * singly-linked tail queues, lists and tail queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may be traversed in either direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * Below is a summary of implemented functions where: + * + means the macro is available + * - means the macro is not available + * s means the macro is available but is slow (runs in O(n) time) + * + * SLIST LIST STAILQ TAILQ + * _HEAD + + + + + * _CLASS_HEAD + + + + + * _HEAD_INITIALIZER + + + + + * _ENTRY + + + + + * _CLASS_ENTRY + + + + + * _INIT + + + + + * _EMPTY + + + + + * _FIRST + + + + + * _NEXT + + + + + * _PREV - + - + + * _LAST - - + + + * _LAST_FAST - - - + + * _FOREACH + + + + + * _FOREACH_FROM + + + + + * _FOREACH_SAFE + + + + + * _FOREACH_FROM_SAFE + + + + + * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE_FROM - - - + + * _FOREACH_REVERSE_SAFE - - - + + * _FOREACH_REVERSE_FROM_SAFE - - - + + * _INSERT_HEAD + + + + + * _INSERT_BEFORE - + - + + * _INSERT_AFTER + + + + + * _INSERT_TAIL - - + + + * _CONCAT s s + + + * _REMOVE_AFTER + - + - + * _REMOVE_HEAD + - + - + * _REMOVE s + s + + * _SWAP + + + + + * + */ +#ifdef QUEUE_MACRO_DEBUG +#warn Use QUEUE_MACRO_DEBUG_TRACE and/or QUEUE_MACRO_DEBUG_TRASH +#define QUEUE_MACRO_DEBUG_TRACE +#define QUEUE_MACRO_DEBUG_TRASH +#endif + +#ifdef QUEUE_MACRO_DEBUG_TRACE +/* Store the last 2 places the queue element or head was altered */ +struct qm_trace { + unsigned long lastline; + unsigned long prevline; + const char *lastfile; + const char *prevfile; +}; + +#define TRACEBUF struct qm_trace trace; +#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } , + +#define QMD_TRACE_HEAD(head) do { \ + (head)->trace.prevline = (head)->trace.lastline; \ + (head)->trace.prevfile = (head)->trace.lastfile; \ + (head)->trace.lastline = __LINE__; \ + (head)->trace.lastfile = __FILE__; \ +} while (0) + +#define QMD_TRACE_ELEM(elem) do { \ + (elem)->trace.prevline = (elem)->trace.lastline; \ + (elem)->trace.prevfile = (elem)->trace.lastfile; \ + (elem)->trace.lastline = __LINE__; \ + (elem)->trace.lastfile = __FILE__; \ +} while (0) + +#else /* !QUEUE_MACRO_DEBUG_TRACE */ +#define QMD_TRACE_ELEM(elem) +#define QMD_TRACE_HEAD(head) +#define TRACEBUF +#define TRACEBUF_INITIALIZER +#endif /* QUEUE_MACRO_DEBUG_TRACE */ + +#ifdef QUEUE_MACRO_DEBUG_TRASH +#define TRASHIT(x) do {(x) = (void *)-1;} while (0) +#define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1) +#else /* !QUEUE_MACRO_DEBUG_TRASH */ +#define TRASHIT(x) +#define QMD_IS_TRASHED(x) 0 +#endif /* QUEUE_MACRO_DEBUG_TRASH */ + +#if defined(QUEUE_MACRO_DEBUG_TRACE) || defined(QUEUE_MACRO_DEBUG_TRASH) +#define QMD_SAVELINK(name, link) void **name = (void *)&(link) +#else /* !QUEUE_MACRO_DEBUG_TRACE && !QUEUE_MACRO_DEBUG_TRASH */ +#define QMD_SAVELINK(name, link) +#endif /* QUEUE_MACRO_DEBUG_TRACE || QUEUE_MACRO_DEBUG_TRASH */ + +#ifdef __cplusplus +/* + * In C++ there can be structure lists and class lists: + */ +#define QUEUE_TYPEOF(type) type +#else +#define QUEUE_TYPEOF(type) struct type +#endif + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +#define SLIST_CLASS_ENTRY(type) \ +struct { \ + class type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) do { \ + if (*(prevp) != (elm)) \ + panic("Bad prevptr *(%p) == %p != %p", \ + (prevp), *(prevp), (elm)); \ +} while (0) +#else +#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) +#endif + +#define SLIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ + SLIST_INIT(head2); \ + } else if (SLIST_FIRST(head2) != NULL) { \ + while (SLIST_NEXT(curelm, field) != NULL) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \ + SLIST_INIT(head2); \ + } \ +} while (0) + +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_REMOVE_AFTER(curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + SLIST_NEXT(elm, field) = \ + SLIST_NEXT(SLIST_NEXT(elm, field), field); \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +#define SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \ + QMD_SLIST_CHECK_PREVPTR(prevp, elm); \ + *(prevp) = SLIST_NEXT(elm, field); \ + TRASHIT((elm)->field.sle_next); \ +} while (0) + +#define SLIST_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \ + SLIST_FIRST(head1) = SLIST_FIRST(head2); \ + SLIST_FIRST(head2) = swap_first; \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *stqh_first; /* first element */ \ + class type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +#define STAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? NULL : \ + __containerof((head)->stqh_last, \ + QUEUE_TYPEOF(type), field.stqe_next)) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ + QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = swap_first; \ + (head2)->stqh_last = swap_last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ +} while (0) + + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +#define LIST_CLASS_ENTRY(type) \ +struct { \ + class type *le_next; /* next element */ \ + class type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#if (defined(_KERNEL) && defined(INVARIANTS)) +/* + * QMD_LIST_CHECK_HEAD(LIST_HEAD *head, LIST_ENTRY NAME) + * + * If the list is non-empty, validates that the first element of the list + * points back at 'head.' + */ +#define QMD_LIST_CHECK_HEAD(head, field) do { \ + if (LIST_FIRST((head)) != NULL && \ + LIST_FIRST((head))->field.le_prev != \ + &LIST_FIRST((head))) \ + panic("Bad list head %p first->prev != head", (head)); \ +} while (0) + +/* + * QMD_LIST_CHECK_NEXT(TYPE *elm, LIST_ENTRY NAME) + * + * If an element follows 'elm' in the list, validates that the next element + * points back at 'elm.' + */ +#define QMD_LIST_CHECK_NEXT(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL && \ + LIST_NEXT((elm), field)->field.le_prev != \ + &((elm)->field.le_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +/* + * QMD_LIST_CHECK_PREV(TYPE *elm, LIST_ENTRY NAME) + * + * Validates that the previous element (or head of the list) points to 'elm.' + */ +#define QMD_LIST_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.le_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_LIST_CHECK_HEAD(head, field) +#define QMD_LIST_CHECK_NEXT(elm, field) +#define QMD_LIST_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define LIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \ + LIST_FIRST(head2)->field.le_prev = \ + &LIST_FIRST((head1)); \ + LIST_INIT(head2); \ + } \ + } else if (LIST_FIRST(head2) != NULL) { \ + while (LIST_NEXT(curelm, field) != NULL) \ + curelm = LIST_NEXT(curelm, field); \ + LIST_NEXT(curelm, field) = LIST_FIRST(head2); \ + LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \ + LIST_INIT(head2); \ + } \ +} while (0) + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_INIT(head) do { \ + LIST_FIRST((head)) = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + QMD_LIST_CHECK_NEXT(listelm, field); \ + if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ + LIST_NEXT((listelm), field)->field.le_prev = \ + &LIST_NEXT((elm), field); \ + LIST_NEXT((listelm), field) = (elm); \ + (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_LIST_CHECK_PREV(listelm, field); \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + QMD_LIST_CHECK_HEAD((head), field); \ + if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ + LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ + LIST_FIRST((head)) = (elm); \ + (elm)->field.le_prev = &LIST_FIRST((head)); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_PREV(elm, head, type, field) \ + ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \ + __containerof((elm)->field.le_prev, \ + QUEUE_TYPEOF(type), field.le_next)) + +#define LIST_REMOVE(elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.le_next); \ + QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ + QMD_LIST_CHECK_NEXT(elm, field); \ + QMD_LIST_CHECK_PREV(elm, field); \ + if (LIST_NEXT((elm), field) != NULL) \ + LIST_NEXT((elm), field)->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = LIST_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ +} while (0) + +#define LIST_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \ + LIST_FIRST((head1)) = LIST_FIRST((head2)); \ + LIST_FIRST((head2)) = swap_tmp; \ + if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ + if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ +} while (0) + +/* + * Tail queue declarations. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *tqh_first; /* first element */ \ + class type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *tqe_next; /* next element */ \ + class type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +/* + * Tail queue functions. + */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +/* + * QMD_TAILQ_CHECK_HEAD(TAILQ_HEAD *head, TAILQ_ENTRY NAME) + * + * If the tailq is non-empty, validates that the first element of the tailq + * points back at 'head.' + */ +#define QMD_TAILQ_CHECK_HEAD(head, field) do { \ + if (!TAILQ_EMPTY(head) && \ + TAILQ_FIRST((head))->field.tqe_prev != \ + &TAILQ_FIRST((head))) \ + panic("Bad tailq head %p first->prev != head", (head)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_TAIL(TAILQ_HEAD *head, TAILQ_ENTRY NAME) + * + * Validates that the tail of the tailq is a pointer to pointer to NULL. + */ +#define QMD_TAILQ_CHECK_TAIL(head, field) do { \ + if (*(head)->tqh_last != NULL) \ + panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_NEXT(TYPE *elm, TAILQ_ENTRY NAME) + * + * If an element follows 'elm' in the tailq, validates that the next element + * points back at 'elm.' + */ +#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \ + if (TAILQ_NEXT((elm), field) != NULL && \ + TAILQ_NEXT((elm), field)->field.tqe_prev != \ + &((elm)->field.tqe_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_PREV(TYPE *elm, TAILQ_ENTRY NAME) + * + * Validates that the previous element (or head of the tailq) points to 'elm.' + */ +#define QMD_TAILQ_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.tqe_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_TAILQ_CHECK_HEAD(head, field) +#define QMD_TAILQ_CHECK_TAIL(head, headname) +#define QMD_TAILQ_CHECK_NEXT(elm, field) +#define QMD_TAILQ_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + QMD_TRACE_HEAD(head1); \ + QMD_TRACE_HEAD(head2); \ + } \ +} while (0) + +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QMD_TAILQ_CHECK_NEXT(listelm, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else { \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + } \ + TAILQ_NEXT((listelm), field) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_TAILQ_CHECK_PREV(listelm, field); \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + TAILQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + QMD_TAILQ_CHECK_HEAD(head, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + QMD_TAILQ_CHECK_TAIL(head, field); \ + TAILQ_NEXT((elm), field) = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +/* + * The FAST function is fast in that it causes no data access other + * then the access to the head. The standard LAST function above + * will cause a data access of both the element you want and + * the previous element. FAST is very useful for instances when + * you may want to prefetch the last data element. + */ +#define TAILQ_LAST_FAST(head, type, field) \ + (TAILQ_EMPTY(head) ? NULL : __containerof((head)->tqh_last, QUEUE_TYPEOF(type), field.tqe_next)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_PREV_FAST(elm, head, type, field) \ + ((elm)->field.tqe_prev == &(head)->tqh_first ? NULL : \ + __containerof((elm)->field.tqe_prev, QUEUE_TYPEOF(type), field.tqe_next)) + +#define TAILQ_REMOVE(head, elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ + QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ + QMD_TAILQ_CHECK_NEXT(elm, field); \ + QMD_TAILQ_CHECK_PREV(elm, field); \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else { \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + QMD_TRACE_HEAD(head); \ + } \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \ + QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \ + (head1)->tqh_first = (head2)->tqh_first; \ + (head1)->tqh_last = (head2)->tqh_last; \ + (head2)->tqh_first = swap_first; \ + (head2)->tqh_last = swap_last; \ + if ((swap_first = (head1)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head1)->tqh_first; \ + else \ + (head1)->tqh_last = &(head1)->tqh_first; \ + if ((swap_first = (head2)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head2)->tqh_first; \ + else \ + (head2)->tqh_last = &(head2)->tqh_first; \ +} while (0) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/racct.h b/lib/libc/include/any-freebsd-any/sys/racct.h new file mode 100644 index 000000000000..84de705f24af --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/racct.h @@ -0,0 +1,279 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Edward Tomasz Napierala under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Resource accounting. + */ + +#ifndef _RACCT_H_ +#define _RACCT_H_ + +#include +#include +#include +#include +#include + +struct buf; +struct proc; +struct rctl_rule_link; +struct ucred; + +/* + * Resources. + */ +#define RACCT_UNDEFINED -1 +#define RACCT_CPU 0 +#define RACCT_DATA 1 +#define RACCT_STACK 2 +#define RACCT_CORE 3 +#define RACCT_RSS 4 +#define RACCT_MEMLOCK 5 +#define RACCT_NPROC 6 +#define RACCT_NOFILE 7 +#define RACCT_VMEM 8 +#define RACCT_NPTS 9 +#define RACCT_SWAP 10 +#define RACCT_NTHR 11 +#define RACCT_MSGQQUEUED 12 +#define RACCT_MSGQSIZE 13 +#define RACCT_NMSGQ 14 +#define RACCT_NSEM 15 +#define RACCT_NSEMOP 16 +#define RACCT_NSHM 17 +#define RACCT_SHMSIZE 18 +#define RACCT_WALLCLOCK 19 +#define RACCT_PCTCPU 20 +#define RACCT_READBPS 21 +#define RACCT_WRITEBPS 22 +#define RACCT_READIOPS 23 +#define RACCT_WRITEIOPS 24 +#define RACCT_MAX RACCT_WRITEIOPS + +/* + * Resource properties. + */ +#define RACCT_IN_MILLIONS 0x01 +#define RACCT_RECLAIMABLE 0x02 +#define RACCT_INHERITABLE 0x04 +#define RACCT_DENIABLE 0x08 +#define RACCT_SLOPPY 0x10 +#define RACCT_DECAYING 0x20 + +extern int racct_types[]; +extern int racct_enable; + +#define ASSERT_RACCT_ENABLED() KASSERT(racct_enable, \ + ("%s called with !racct_enable", __func__)) + +/* + * Amount stored in c_resources[] is 10**6 times bigger than what's + * visible to the userland. It gets fixed up when retrieving resource + * usage or adding rules. + */ +#define RACCT_IS_IN_MILLIONS(X) \ + ((X) != RACCT_UNDEFINED && (racct_types[(X)] & RACCT_IN_MILLIONS) != 0) + +/* + * Resource usage can drop, as opposed to only grow. When the process + * terminates, its resource usage is subtracted from the respective + * per-credential racct containers. + */ +#define RACCT_IS_RECLAIMABLE(X) (racct_types[X] & RACCT_RECLAIMABLE) + +/* + * Children inherit resource usage. + */ +#define RACCT_IS_INHERITABLE(X) (racct_types[X] & RACCT_INHERITABLE) + +/* + * racct_{add,set}(9) can actually return an error and not update resource + * usage counters. Note that even when resource is not deniable, allocating + * resource might cause signals to be sent by RCTL code. + */ +#define RACCT_IS_DENIABLE(X) (racct_types[X] & RACCT_DENIABLE) + +/* + * Per-process resource usage information makes no sense, but per-credential + * one does. This kind of resources are usually allocated for process, but + * freed using credentials. + */ +#define RACCT_IS_SLOPPY(X) (racct_types[X] & RACCT_SLOPPY) + +/* + * When a process terminates, its resource usage is not automatically + * subtracted from per-credential racct containers. Instead, the resource + * usage of per-credential racct containers decays in time. + * Resource usage can also drop for such resource. + */ +#define RACCT_IS_DECAYING(X) (racct_types[X] & RACCT_DECAYING) + +/* + * Resource usage can drop, as opposed to only grow. + */ +#define RACCT_CAN_DROP(X) (RACCT_IS_RECLAIMABLE(X) | RACCT_IS_DECAYING(X)) + +/* + * The 'racct' structure defines resource consumption for a particular + * subject, such as process or jail. + * + * This structure must be filled with zeroes initially. + */ +struct racct { + int64_t r_resources[RACCT_MAX + 1]; + LIST_HEAD(, rctl_rule_link) r_rule_links; +}; + +SYSCTL_DECL(_kern_racct); + +#ifdef RACCT + +extern struct mtx racct_lock; + +#define RACCT_LOCK() mtx_lock(&racct_lock) +#define RACCT_UNLOCK() mtx_unlock(&racct_lock) +#define RACCT_LOCK_ASSERT() mtx_assert(&racct_lock, MA_OWNED) + +#define RACCT_PROC_LOCK(p) do { \ + if (__predict_false(racct_enable)) \ + PROC_LOCK(p); \ +} while (0) +#define RACCT_PROC_UNLOCK(p) do { \ + if (__predict_false(racct_enable)) \ + PROC_UNLOCK(p); \ +} while (0) + +int racct_add(struct proc *p, int resource, uint64_t amount); +void racct_add_cred(struct ucred *cred, int resource, uint64_t amount); +void racct_add_force(struct proc *p, int resource, uint64_t amount); +void racct_add_buf(struct proc *p, const struct buf *bufp, int is_write); +int racct_set(struct proc *p, int resource, uint64_t amount); +void racct_set_force(struct proc *p, int resource, uint64_t amount); +void racct_sub(struct proc *p, int resource, uint64_t amount); +void racct_sub_cred(struct ucred *cred, int resource, uint64_t amount); +uint64_t racct_get_limit(struct proc *p, int resource); +uint64_t racct_get_available(struct proc *p, int resource); + +void racct_create(struct racct **racctp); +void racct_destroy(struct racct **racctp); + +int racct_proc_fork(struct proc *parent, struct proc *child); +void racct_proc_fork_done(struct proc *child); +void racct_proc_exit(struct proc *p); + +void racct_proc_ucred_changed(struct proc *p, struct ucred *oldcred, + struct ucred *newcred); +void racct_move(struct racct *dest, struct racct *src); +void racct_proc_throttle(struct proc *p, int timeout); + +#else + +#define RACCT_PROC_LOCK(p) do { } while (0) +#define RACCT_PROC_UNLOCK(p) do { } while (0) + +static inline int +racct_add(struct proc *p, int resource, uint64_t amount) +{ + + return (0); +} + +static inline void +racct_add_cred(struct ucred *cred, int resource, uint64_t amount) +{ +} + +static inline void +racct_add_force(struct proc *p, int resource, uint64_t amount) +{ +} + +static inline int +racct_set(struct proc *p, int resource, uint64_t amount) +{ + + return (0); +} + +static inline void +racct_set_force(struct proc *p, int resource, uint64_t amount) +{ +} + +static inline void +racct_sub(struct proc *p, int resource, uint64_t amount) +{ +} + +static inline void +racct_sub_cred(struct ucred *cred, int resource, uint64_t amount) +{ +} + +static inline uint64_t +racct_get_limit(struct proc *p, int resource) +{ + + return (UINT64_MAX); +} + +static inline uint64_t +racct_get_available(struct proc *p, int resource) +{ + + return (UINT64_MAX); +} + +#define racct_create(x) +#define racct_destroy(x) + +static inline int +racct_proc_fork(struct proc *parent, struct proc *child) +{ + + return (0); +} + +static inline void +racct_proc_fork_done(struct proc *child) +{ +} + +static inline void +racct_proc_exit(struct proc *p) +{ +} + +#endif + +#endif /* !_RACCT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/random.h b/lib/libc/include/any-freebsd-any/sys/random.h new file mode 100644 index 000000000000..a94d3f378a28 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/random.h @@ -0,0 +1,166 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000-2015, 2017 Mark R. V. Murray + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RANDOM_H_ +#define _SYS_RANDOM_H_ + +#include + +#ifdef _KERNEL + +struct uio; + +#if defined(DEV_RANDOM) +u_int read_random(void *, u_int); +int read_random_uio(struct uio *, bool); +#else +static __inline int +read_random_uio(void *a __unused, u_int b __unused) +{ + return (0); +} +static __inline u_int +read_random(void *a __unused, u_int b __unused) +{ + return (0); +} +#endif + +/* + * Note: if you add or remove members of random_entropy_source, remember to + * also update the strings in the static array random_source_descr[] in + * random_harvestq.c. + * + * NOTE: complain loudly to markm@ or on the lists if this enum gets more than 32 + * distinct values (0-31)! ENTROPYSOURCE may be == 32, but not > 32. + */ +enum random_entropy_source { + RANDOM_START = 0, + RANDOM_CACHED = 0, + /* Environmental sources */ + RANDOM_ATTACH, + RANDOM_KEYBOARD, + RANDOM_MOUSE, + RANDOM_NET_TUN, + RANDOM_NET_ETHER, + RANDOM_NET_NG, + RANDOM_INTERRUPT, + RANDOM_SWI, + RANDOM_FS_ATIME, + RANDOM_UMA, /* Special!! UMA/SLAB Allocator */ + RANDOM_ENVIRONMENTAL_END = RANDOM_UMA, + /* Fast hardware random-number sources from here on. */ + RANDOM_PURE_START, + RANDOM_PURE_OCTEON = RANDOM_PURE_START, + RANDOM_PURE_SAFE, + RANDOM_PURE_GLXSB, + RANDOM_PURE_UBSEC, + RANDOM_PURE_HIFN, + RANDOM_PURE_RDRAND, + RANDOM_PURE_NEHEMIAH, + RANDOM_PURE_RNDTEST, + RANDOM_PURE_VIRTIO, + RANDOM_PURE_BROADCOM, + RANDOM_PURE_CCP, + RANDOM_PURE_DARN, + RANDOM_PURE_TPM, + ENTROPYSOURCE +}; + +#define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) +#define RANDOM_HARVEST_PURE_MASK (((1 << ENTROPYSOURCE) - 1) & (-1UL << RANDOM_PURE_START)) + +#define RANDOM_LEGACY_BOOT_ENTROPY_MODULE "/boot/entropy" +#define RANDOM_CACHED_BOOT_ENTROPY_MODULE "boot_entropy_cache" +#define RANDOM_CACHED_SKIP_START 256 + +#if defined(DEV_RANDOM) +extern u_int hc_source_mask; +void random_harvest_queue_(const void *, u_int, enum random_entropy_source); +void random_harvest_fast_(const void *, u_int); +void random_harvest_direct_(const void *, u_int, enum random_entropy_source); + +static __inline void +random_harvest_queue(const void *entropy, u_int size, enum random_entropy_source origin) +{ + + if (hc_source_mask & (1 << origin)) + random_harvest_queue_(entropy, size, origin); +} + +static __inline void +random_harvest_fast(const void *entropy, u_int size, enum random_entropy_source origin) +{ + + if (hc_source_mask & (1 << origin)) + random_harvest_fast_(entropy, size); +} + +static __inline void +random_harvest_direct(const void *entropy, u_int size, enum random_entropy_source origin) +{ + + if (hc_source_mask & (1 << origin)) + random_harvest_direct_(entropy, size, origin); +} + +void random_harvest_register_source(enum random_entropy_source); +void random_harvest_deregister_source(enum random_entropy_source); +#else +#define random_harvest_queue(a, b, c) do {} while (0) +#define random_harvest_fast(a, b, c) do {} while (0) +#define random_harvest_direct(a, b, c) do {} while (0) +#define random_harvest_register_source(a) do {} while (0) +#define random_harvest_deregister_source(a) do {} while (0) +#endif + +#if defined(RANDOM_ENABLE_UMA) +#define random_harvest_fast_uma(a, b, c) random_harvest_fast(a, b, c) +#else /* !defined(RANDOM_ENABLE_UMA) */ +#define random_harvest_fast_uma(a, b, c) do {} while (0) +#endif /* defined(RANDOM_ENABLE_UMA) */ + +#if defined(RANDOM_ENABLE_ETHER) +#define random_harvest_queue_ether(a, b) random_harvest_queue(a, b, RANDOM_NET_ETHER) +#else /* !defined(RANDOM_ENABLE_ETHER) */ +#define random_harvest_queue_ether(a, b) do {} while (0) +#endif /* defined(RANDOM_ENABLE_ETHER) */ + + +#endif /* _KERNEL */ + +#define GRND_NONBLOCK 0x1 +#define GRND_RANDOM 0x2 + +__BEGIN_DECLS +ssize_t getrandom(void *buf, size_t buflen, unsigned int flags); +__END_DECLS + +#endif /* _SYS_RANDOM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/rangelock.h b/lib/libc/include/any-freebsd-any/sys/rangelock.h new file mode 100644 index 000000000000..f8e46e7d13f7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rangelock.h @@ -0,0 +1,107 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RANGELOCK_H +#define _SYS_RANGELOCK_H + +#include + +#define RL_LOCK_READ 0x0001 +#define RL_LOCK_WRITE 0x0002 +#define RL_LOCK_TYPE_MASK 0x0003 +#define RL_LOCK_GRANTED 0x0004 + +struct rl_q_entry; + +/* + * The structure representing the range lock. Caller may request + * read or write access to the range of bytes. Access is granted if + * all existing lock owners are compatible with the request. Two lock + * owners are compatible if their ranges do not overlap, or both + * owners are for read. + * + * Access to the structure itself is synchronized with the externally + * supplied mutex. + * + * rl_waiters is the queue containing in order (a) granted write lock + * requests, (b) granted read lock requests, and (c) in order of arrival, + * lock requests which cannot be granted yet. + * + * rl_currdep is the first lock request that cannot be granted now due + * to the preceding requests conflicting with it (i.e., it points to + * position (c) in the list above). + */ +struct rangelock { + TAILQ_HEAD(, rl_q_entry) rl_waiters; + struct rl_q_entry *rl_currdep; +}; + +#ifdef _KERNEL + +struct mtx; + +void rangelock_init(struct rangelock *lock); +void rangelock_destroy(struct rangelock *lock); +void rangelock_unlock(struct rangelock *lock, void *cookie, + struct mtx *ilk); +void *rangelock_unlock_range(struct rangelock *lock, void *cookie, + off_t start, off_t end, struct mtx *ilk); +void *rangelock_rlock(struct rangelock *lock, off_t start, off_t end, + struct mtx *ilk); +void *rangelock_wlock(struct rangelock *lock, off_t start, off_t end, + struct mtx *ilk); +void rlqentry_free(struct rl_q_entry *rlqe); +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void _rangelock_cookie_assert(void *cookie, int what, const char *file, + int line); +#endif + +#ifdef INVARIANTS +#define rangelock_cookie_assert_(cookie, what, file, line) \ + _rangelock_cookie_assert((cookie), (what), (file), (line)) +#else +#define rangelock_cookie_assert_(cookie, what, file, line) (void)0 +#endif + +#define rangelock_cookie_assert(cookie, what) \ + rangelock_cookie_assert_((cookie), (what), __FILE__, __LINE__) + +/* + * Assertion flags. + */ +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define RCA_LOCKED 0x0001 +#define RCA_RLOCKED 0x0002 +#define RCA_WLOCKED 0x0004 +#endif + +#endif /* _KERNEL */ + +#endif /* _SYS_RANGELOCK_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/rangeset.h b/lib/libc/include/any-freebsd-any/sys/rangeset.h new file mode 100644 index 000000000000..99733ecfaf51 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rangeset.h @@ -0,0 +1,88 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RANGESET_H +#define _SYS_RANGESET_H + +#ifdef _KERNEL + +#include + +typedef bool (*rs_pred_t)(void *ctx, void *r); + +/* + * This structure must be embedded at the start of the rangeset element. + */ +struct rs_el { + uint64_t re_start; /* pctrie key */ + uint64_t re_end; +}; + +void rangeset_init(struct rangeset *rs, rs_dup_data_t dup_data, + rs_free_data_t free_data, void *rs_data_ctx, u_int alloc_flags); +void rangeset_fini(struct rangeset *rs); + +bool rangeset_check_empty(struct rangeset *rs, uint64_t start, + uint64_t end); + +/* + * r point to the app data with struct rs_el at the beginning. + */ +int rangeset_insert(struct rangeset *rs, uint64_t start, uint64_t end, + void *r); + +/* + * Guarantees that on error the rangeset is not modified. Remove + * might need to split element if its start/end completely cover the + * removed range, in which case ENOMEM might be returned. + */ +void rangeset_remove_all(struct rangeset *rs); +int rangeset_remove(struct rangeset *rs, uint64_t start, uint64_t end); +int rangeset_remove_pred(struct rangeset *rs, uint64_t start, + uint64_t end, rs_pred_t pred); + +/* + * Really returns the pointer to the data with struct rs_el embedded + * at the beginning. + */ +void *rangeset_lookup(struct rangeset *rs, uint64_t place); + +/* + * Copies src_rs entries into dst_rs. dst_rs must be empty. + * Leaves dst_rs empty on failure. + */ +int rangeset_copy(struct rangeset *dst_rs, struct rangeset *src_rs); + +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/rctl.h b/lib/libc/include/any-freebsd-any/sys/rctl.h new file mode 100644 index 000000000000..5d01ff03e7d9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rctl.h @@ -0,0 +1,174 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Edward Tomasz Napierala under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Resource Limits. + */ + +#ifndef _RCTL_H_ +#define _RCTL_H_ + +#include +#include +#include +#include + +struct proc; +struct uidinfo; +struct loginclass; +struct prison_racct; +struct ucred; +struct rctl_rule_link; + +#ifdef _KERNEL + +/* + * Rules describe an action to be taken when conditions defined + * in the rule are met. There is no global list of rules; instead, + * rules are linked to by the racct structures for all the subjects + * they apply to - for example, a rule of type "user" is linked to the + * appropriate struct uidinfo, and to all the processes of that user. + * + * 'rr_refcount' is equal to the number of rctl_rule_link structures + * pointing to the rule. + * + * This structure must never change after being added, via rctl_rule_link + * structures, to subjects. In order to change a rule, add a new rule + * and remove the previous one. + */ +struct rctl_rule { + int rr_subject_type; + union { + struct proc *rs_proc; + struct uidinfo *rs_uip; + struct loginclass *rs_loginclass; + struct prison_racct *rs_prison_racct; + } rr_subject; + int rr_per; + int rr_resource; + int rr_action; + int64_t rr_amount; + u_int rr_refcount; + struct task rr_task; +}; + +/* + * Allowed values for rr_subject_type and rr_per fields. + */ +#define RCTL_SUBJECT_TYPE_UNDEFINED -1 +#define RCTL_SUBJECT_TYPE_PROCESS 0x0000 +#define RCTL_SUBJECT_TYPE_USER 0x0001 +#define RCTL_SUBJECT_TYPE_LOGINCLASS 0x0003 +#define RCTL_SUBJECT_TYPE_JAIL 0x0004 +#define RCTL_SUBJECT_TYPE_MAX RCTL_SUBJECT_TYPE_JAIL + +/* + * Allowed values for rr_action field. + */ +#define RCTL_ACTION_UNDEFINED -1 +#define RCTL_ACTION_SIGHUP SIGHUP +#define RCTL_ACTION_SIGINT SIGINT +#define RCTL_ACTION_SIGQUIT SIGQUIT +#define RCTL_ACTION_SIGILL SIGILL +#define RCTL_ACTION_SIGTRAP SIGTRAP +#define RCTL_ACTION_SIGABRT SIGABRT +#define RCTL_ACTION_SIGEMT SIGEMT +#define RCTL_ACTION_SIGFPE SIGFPE +#define RCTL_ACTION_SIGKILL SIGKILL +#define RCTL_ACTION_SIGBUS SIGBUS +#define RCTL_ACTION_SIGSEGV SIGSEGV +#define RCTL_ACTION_SIGSYS SIGSYS +#define RCTL_ACTION_SIGPIPE SIGPIPE +#define RCTL_ACTION_SIGALRM SIGALRM +#define RCTL_ACTION_SIGTERM SIGTERM +#define RCTL_ACTION_SIGURG SIGURG +#define RCTL_ACTION_SIGSTOP SIGSTOP +#define RCTL_ACTION_SIGTSTP SIGTSTP +#define RCTL_ACTION_SIGCHLD SIGCHLD +#define RCTL_ACTION_SIGTTIN SIGTTIN +#define RCTL_ACTION_SIGTTOU SIGTTOU +#define RCTL_ACTION_SIGIO SIGIO +#define RCTL_ACTION_SIGXCPU SIGXCPU +#define RCTL_ACTION_SIGXFSZ SIGXFSZ +#define RCTL_ACTION_SIGVTALRM SIGVTALRM +#define RCTL_ACTION_SIGPROF SIGPROF +#define RCTL_ACTION_SIGWINCH SIGWINCH +#define RCTL_ACTION_SIGINFO SIGINFO +#define RCTL_ACTION_SIGUSR1 SIGUSR1 +#define RCTL_ACTION_SIGUSR2 SIGUSR2 +#define RCTL_ACTION_SIGTHR SIGTHR +#define RCTL_ACTION_SIGNAL_MAX RCTL_ACTION_SIGTHR +#define RCTL_ACTION_DENY (RCTL_ACTION_SIGNAL_MAX + 1) +#define RCTL_ACTION_LOG (RCTL_ACTION_SIGNAL_MAX + 2) +#define RCTL_ACTION_DEVCTL (RCTL_ACTION_SIGNAL_MAX + 3) +#define RCTL_ACTION_THROTTLE (RCTL_ACTION_SIGNAL_MAX + 4) +#define RCTL_ACTION_MAX RCTL_ACTION_THROTTLE + +#define RCTL_AMOUNT_UNDEFINED -1 + +struct rctl_rule *rctl_rule_alloc(int flags); +struct rctl_rule *rctl_rule_duplicate(const struct rctl_rule *rule, int flags); +void rctl_rule_acquire(struct rctl_rule *rule); +void rctl_rule_release(struct rctl_rule *rule); +int rctl_rule_add(struct rctl_rule *rule); +int rctl_rule_remove(struct rctl_rule *filter); +int rctl_enforce(struct proc *p, int resource, uint64_t amount); +void rctl_throttle_decay(struct racct *racct, int resource); +int64_t rctl_pcpu_available(const struct proc *p); +uint64_t rctl_get_limit(struct proc *p, int resource); +uint64_t rctl_get_available(struct proc *p, int resource); +const char *rctl_resource_name(int resource); +void rctl_proc_ucred_changed(struct proc *p, struct ucred *newcred); +int rctl_proc_fork(struct proc *parent, struct proc *child); +void rctl_racct_release(struct racct *racct); +#else /* !_KERNEL */ + +/* + * Syscall interface. + */ +__BEGIN_DECLS +int rctl_get_racct(const char *inbufp, size_t inbuflen, char *outbufp, + size_t outbuflen); +int rctl_get_rules(const char *inbufp, size_t inbuflen, char *outbufp, + size_t outbuflen); +int rctl_get_limits(const char *inbufp, size_t inbuflen, char *outbufp, + size_t outbuflen); +int rctl_add_rule(const char *inbufp, size_t inbuflen, char *outbufp, + size_t outbuflen); +int rctl_remove_rule(const char *inbufp, size_t inbuflen, char *outbufp, + size_t outbuflen); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_RCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/reboot.h b/lib/libc/include/any-freebsd-any/sys/reboot.h new file mode 100644 index 000000000000..20b91f8ed91d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/reboot.h @@ -0,0 +1,71 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)reboot.h 8.3 (Berkeley) 12/13/94 + * $FreeBSD$ + */ + +#ifndef _SYS_REBOOT_H_ +#define _SYS_REBOOT_H_ + +/* + * Arguments to reboot system call. These are passed to + * the boot program and on to init. + */ +#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */ + +#define RB_ASKNAME 0x001 /* force prompt of device of root filesystem */ +#define RB_SINGLE 0x002 /* reboot to single user only */ +#define RB_NOSYNC 0x004 /* dont sync before reboot */ +#define RB_HALT 0x008 /* don't reboot, just halt */ +#define RB_INITNAME 0x010 /* Unused placeholder to specify init path */ +#define RB_DFLTROOT 0x020 /* use compiled-in rootdev */ +#define RB_KDB 0x040 /* give control to kernel debugger */ +#define RB_RDONLY 0x080 /* mount root fs read-only */ +#define RB_DUMP 0x100 /* dump kernel memory before reboot */ +#define RB_MINIROOT 0x200 /* Unused placeholder */ +#define RB_VERBOSE 0x800 /* print all potentially useful info */ +#define RB_SERIAL 0x1000 /* use serial port as console */ +#define RB_CDROM 0x2000 /* use cdrom as root */ +#define RB_POWEROFF 0x4000 /* turn the power off if possible */ +#define RB_GDB 0x8000 /* use GDB remote debugger instead of DDB */ +#define RB_MUTE 0x10000 /* start up with the console muted */ +#define RB_SELFTEST 0x20000 /* unused placeholder */ +#define RB_RESERVED1 0x40000 /* reserved for internal use of boot blocks */ +#define RB_RESERVED2 0x80000 /* reserved for internal use of boot blocks */ +#define RB_PAUSE 0x100000 /* pause after each output line during probe */ +#define RB_REROOT 0x200000 /* unmount the rootfs and mount it again */ +#define RB_POWERCYCLE 0x400000 /* Power cycle if possible */ +#define RB_PROBE 0x10000000 /* Probe multiple consoles */ +#define RB_MULTIPLE 0x20000000 /* use multiple consoles */ + +#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/refcount.h b/lib/libc/include/any-freebsd-any/sys/refcount.h new file mode 100644 index 000000000000..141d8521b0f5 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/refcount.h @@ -0,0 +1,130 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __SYS_REFCOUNT_H__ +#define __SYS_REFCOUNT_H__ + +#include +#include + +#ifdef _KERNEL +#include +#else +#include +#define KASSERT(exp, msg) /* */ +#endif + +static __inline void +refcount_init(volatile u_int *count, u_int value) +{ + + *count = value; +} + +static __inline void +refcount_acquire(volatile u_int *count) +{ + + KASSERT(*count < UINT_MAX, ("refcount %p overflowed", count)); + atomic_add_int(count, 1); +} + +static __inline __result_use_check bool +refcount_acquire_checked(volatile u_int *count) +{ + u_int lcount; + + for (lcount = *count;;) { + if (__predict_false(lcount + 1 < lcount)) + return (false); + if (__predict_true(atomic_fcmpset_int(count, &lcount, + lcount + 1) == 1)) + return (true); + } +} + +static __inline bool +refcount_release(volatile u_int *count) +{ + u_int old; + + atomic_thread_fence_rel(); + old = atomic_fetchadd_int(count, -1); + KASSERT(old > 0, ("refcount %p is zero", count)); + if (old > 1) + return (false); + + /* + * Last reference. Signal the user to call the destructor. + * + * Ensure that the destructor sees all updates. The fence_rel + * at the start of the function synchronized with this fence. + */ + atomic_thread_fence_acq(); + return (true); +} + +/* + * This functions returns non-zero if the refcount was + * incremented. Else zero is returned. + * + * A temporary hack until refcount_* APIs are sorted out. + */ +static __inline __result_use_check bool +refcount_acquire_if_not_zero(volatile u_int *count) +{ + u_int old; + + old = *count; + for (;;) { + KASSERT(old < UINT_MAX, ("refcount %p overflowed", count)); + if (old == 0) + return (false); + if (atomic_fcmpset_int(count, &old, old + 1)) + return (true); + } +} + +static __inline __result_use_check bool +refcount_release_if_not_last(volatile u_int *count) +{ + u_int old; + + old = *count; + for (;;) { + KASSERT(old > 0, ("refcount %p is zero", count)); + if (old == 1) + return (false); + if (atomic_fcmpset_int(count, &old, old - 1)) + return (true); + } +} + +#endif /* ! __SYS_REFCOUNT_H__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/regression.h b/lib/libc/include/any-freebsd-any/sys/regression.h new file mode 100644 index 000000000000..1ce711faa35f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/regression.h @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_REGRESSION_H_ +#define _SYS_REGRESSION_H_ + +#ifndef _KERNEL +/* + * System calls associated with regression testing functions in kernel. + */ +int __setugid(int _flag); +#endif /* !_KERNEL */ + +#endif /* !_SYS_REGRESSION_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/resource.h b/lib/libc/include/any-freebsd-any/sys/resource.h new file mode 100644 index 000000000000..08bb09b4a645 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/resource.h @@ -0,0 +1,194 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)resource.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ + +#include +#include +#include + +#ifndef _ID_T_DECLARED +typedef __id_t id_t; +#define _ID_T_DECLARED +#endif + +#ifndef _RLIM_T_DECLARED +typedef __rlim_t rlim_t; +#define _RLIM_T_DECLARED +#endif + +/* + * Process priority specifications to get/setpriority. + */ +#define PRIO_MIN -20 +#define PRIO_MAX 20 + +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 + +/* + * Resource utilization information. + * + * All fields are only modified by curthread and + * no locks are required to read. + */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 +#define RUSAGE_THREAD 1 + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; /* max resident set size */ +#define ru_first ru_ixrss + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data " */ + long ru_isrss; /* integral unshared stack " */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary " */ +#define ru_last ru_nivcsw +}; + +#if __BSD_VISIBLE +struct __wrusage { + struct rusage wru_self; + struct rusage wru_children; +}; +#endif + +/* + * Resource limits + */ +#define RLIMIT_CPU 0 /* maximum cpu time in seconds */ +#define RLIMIT_FSIZE 1 /* maximum file size */ +#define RLIMIT_DATA 2 /* data size */ +#define RLIMIT_STACK 3 /* stack size */ +#define RLIMIT_CORE 4 /* core file size */ +#define RLIMIT_RSS 5 /* resident set size */ +#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ +#define RLIMIT_NPROC 7 /* number of processes */ +#define RLIMIT_NOFILE 8 /* number of open files */ +#define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */ +#define RLIMIT_VMEM 10 /* virtual process size (incl. mmap) */ +#define RLIMIT_AS RLIMIT_VMEM /* standard name for RLIMIT_VMEM */ +#define RLIMIT_NPTS 11 /* pseudo-terminals */ +#define RLIMIT_SWAP 12 /* swap used */ +#define RLIMIT_KQUEUES 13 /* kqueues allocated */ +#define RLIMIT_UMTXP 14 /* process-shared umtx */ + +#define RLIM_NLIMITS 15 /* number of resource limits */ + +#define RLIM_INFINITY ((rlim_t)(((__uint64_t)1 << 63) - 1)) +#define RLIM_SAVED_MAX RLIM_INFINITY +#define RLIM_SAVED_CUR RLIM_INFINITY + +/* + * Resource limit string identifiers + */ + +#ifdef _RLIMIT_IDENT +static const char *rlimit_ident[RLIM_NLIMITS] = { + "cpu", + "fsize", + "data", + "stack", + "core", + "rss", + "memlock", + "nproc", + "nofile", + "sbsize", + "vmem", + "npts", + "swap", + "kqueues", + "umtx", +}; +#endif + +struct rlimit { + rlim_t rlim_cur; /* current (soft) limit */ + rlim_t rlim_max; /* maximum value for rlim_cur */ +}; + +#if __BSD_VISIBLE + +struct orlimit { + __int32_t rlim_cur; /* current (soft) limit */ + __int32_t rlim_max; /* maximum value for rlim_cur */ +}; + +struct loadavg { + __fixpt_t ldavg[3]; + long fscale; +}; + +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_INTR 3 +#define CP_IDLE 4 +#define CPUSTATES 5 + +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL + +extern struct loadavg averunnable; +void read_cpu_time(long *cp_time); /* Writes array of CPUSTATES */ + +#else + +__BEGIN_DECLS +/* XXX 2nd arg to [gs]etpriority() should be an id_t */ +int getpriority(int, int); +int getrlimit(int, struct rlimit *); +int getrusage(int, struct rusage *); +int setpriority(int, int, int); +int setrlimit(int, const struct rlimit *); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* !_SYS_RESOURCE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/resourcevar.h b/lib/libc/include/any-freebsd-any/sys/resourcevar.h new file mode 100644 index 000000000000..48d3b87f0f8b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/resourcevar.h @@ -0,0 +1,161 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)resourcevar.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_RESOURCEVAR_H_ +#define _SYS_RESOURCEVAR_H_ + +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +/* + * Kernel per-process accounting / statistics + * (not necessarily resident except when running). + * + * Locking key: + * b - created at fork, never changes + * c - locked by proc mtx + * k - only accessed by curthread + * w - locked by proc itim lock + * w2 - locked by proc prof lock + */ +struct pstats { +#define pstat_startzero p_cru + struct rusage p_cru; /* Stats for reaped children. */ + struct itimerval p_timer[3]; /* (w) Virtual-time timers. */ +#define pstat_endzero pstat_startcopy + +#define pstat_startcopy p_prof + struct uprof { /* Profile arguments. */ + caddr_t pr_base; /* (c + w2) Buffer base. */ + u_long pr_size; /* (c + w2) Buffer size. */ + u_long pr_off; /* (c + w2) PC offset. */ + u_long pr_scale; /* (c + w2) PC scaling. */ + } p_prof; +#define pstat_endcopy p_start + struct timeval p_start; /* (b) Starting time. */ +}; + +#ifdef _KERNEL + +/* + * Kernel shareable process resource limits. Because this structure + * is moderately large but changes infrequently, it is normally + * shared copy-on-write after forks. + */ +struct plimit { + struct rlimit pl_rlimit[RLIM_NLIMITS]; + int pl_refcnt; /* number of references */ +}; + +struct racct; + +/*- + * Per uid resource consumption. This structure is used to track + * the total resource consumption (process count, socket buffer size, + * etc) for the uid and impose limits. + * + * Locking guide: + * (a) Constant from inception + * (b) Lockless, updated using atomics + * (c) Locked by global uihashtbl_lock + */ +struct uidinfo { + LIST_ENTRY(uidinfo) ui_hash; /* (c) hash chain of uidinfos */ + u_long ui_vmsize; /* (b) pages of swap reservation by uid */ + long ui_sbsize; /* (b) socket buffer space consumed */ + long ui_proccnt; /* (b) number of processes */ + long ui_ptscnt; /* (b) number of pseudo-terminals */ + long ui_kqcnt; /* (b) number of kqueues */ + long ui_umtxcnt; /* (b) number of shared umtxs */ + uid_t ui_uid; /* (a) uid */ + u_int ui_ref; /* (b) reference count */ +#ifdef RACCT + struct racct *ui_racct; /* (a) resource accounting */ +#endif +}; + +struct proc; +struct rusage_ext; +struct thread; + +void addupc_intr(struct thread *td, uintfptr_t pc, u_int ticks); +void addupc_task(struct thread *td, uintfptr_t pc, u_int ticks); +void calccru(struct proc *p, struct timeval *up, struct timeval *sp); +void calcru(struct proc *p, struct timeval *up, struct timeval *sp); +int chgkqcnt(struct uidinfo *uip, int diff, rlim_t max); +int chgproccnt(struct uidinfo *uip, int diff, rlim_t maxval); +int chgsbsize(struct uidinfo *uip, u_int *hiwat, u_int to, + rlim_t maxval); +int chgptscnt(struct uidinfo *uip, int diff, rlim_t maxval); +int chgumtxcnt(struct uidinfo *uip, int diff, rlim_t maxval); +int kern_proc_setrlimit(struct thread *td, struct proc *p, u_int which, + struct rlimit *limp); +struct plimit + *lim_alloc(void); +void lim_copy(struct plimit *dst, struct plimit *src); +rlim_t lim_cur(struct thread *td, int which); +rlim_t lim_cur_proc(struct proc *p, int which); +void lim_fork(struct proc *p1, struct proc *p2); +void lim_free(struct plimit *limp); +struct plimit + *lim_hold(struct plimit *limp); +rlim_t lim_max(struct thread *td, int which); +rlim_t lim_max_proc(struct proc *p, int which); +void lim_rlimit(struct thread *td, int which, struct rlimit *rlp); +void lim_rlimit_proc(struct proc *p, int which, struct rlimit *rlp); +void ruadd(struct rusage *ru, struct rusage_ext *rux, struct rusage *ru2, + struct rusage_ext *rux2); +void rucollect(struct rusage *ru, struct rusage *ru2); +void rufetch(struct proc *p, struct rusage *ru); +void rufetchcalc(struct proc *p, struct rusage *ru, struct timeval *up, + struct timeval *sp); +void rufetchtd(struct thread *td, struct rusage *ru); +void ruxagg(struct proc *p, struct thread *td); +struct uidinfo + *uifind(uid_t uid); +void uifree(struct uidinfo *uip); +void uihashinit(void); +void uihold(struct uidinfo *uip); +#ifdef RACCT +void ui_racct_foreach(void (*callback)(struct racct *racct, + void *arg2, void *arg3), void (*pre)(void), void (*post)(void), + void *arg2, void *arg3); +#endif + +#endif /* _KERNEL */ +#endif /* !_SYS_RESOURCEVAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/rman.h b/lib/libc/include/any-freebsd-any/sys/rman.h new file mode 100644 index 000000000000..e955cd5834b9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rman.h @@ -0,0 +1,169 @@ +/*- + * SPDX-License-Identifier: MIT + * + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RMAN_H_ +#define _SYS_RMAN_H_ 1 + +#ifndef _KERNEL +#include +#else +#include +#include +#endif + +#define RF_ALLOCATED 0x0001 /* resource has been reserved */ +#define RF_ACTIVE 0x0002 /* resource allocation has been activated */ +#define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */ +#define RF_SPARE1 0x0008 +#define RF_SPARE2 0x0010 +#define RF_FIRSTSHARE 0x0020 /* first in sharing list */ +#define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */ +#define RF_OPTIONAL 0x0080 /* for bus_alloc_resources() */ +#define RF_UNMAPPED 0x0100 /* don't map resource when activating */ + +#define RF_ALIGNMENT_SHIFT 10 /* alignment size bit starts bit 10 */ +#define RF_ALIGNMENT_MASK (0x003F << RF_ALIGNMENT_SHIFT) + /* resource address alignment size bit mask */ +#define RF_ALIGNMENT_LOG2(x) ((x) << RF_ALIGNMENT_SHIFT) +#define RF_ALIGNMENT(x) (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT) + +enum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY }; + +/* + * String length exported to userspace for resource names, etc. + */ +#define RM_TEXTLEN 32 + +#define RM_MAX_END (~(rman_res_t)0) + +#define RMAN_IS_DEFAULT_RANGE(s,e) ((s) == 0 && (e) == RM_MAX_END) + +/* + * Userspace-exported structures. + */ +struct u_resource { + uintptr_t r_handle; /* resource uniquifier */ + uintptr_t r_parent; /* parent rman */ + uintptr_t r_device; /* device owning this resource */ + char r_devname[RM_TEXTLEN]; /* device name XXX obsolete */ + + rman_res_t r_start; /* offset in resource space */ + rman_res_t r_size; /* size in resource space */ + u_int r_flags; /* RF_* flags */ +}; + +struct u_rman { + uintptr_t rm_handle; /* rman uniquifier */ + char rm_descr[RM_TEXTLEN]; /* rman description */ + + rman_res_t rm_start; /* base of managed region */ + rman_res_t rm_size; /* size of managed region */ + enum rman_type rm_type; /* region type */ +}; + +#ifdef _KERNEL + +/* + * The public (kernel) view of struct resource + * + * NB: Changing the offset/size/type of existing fields in struct resource + * NB: breaks the device driver ABI and is strongly FORBIDDEN. + * NB: Appending new fields is probably just misguided. + */ + +struct resource { + struct resource_i *__r_i; + bus_space_tag_t r_bustag; /* bus_space tag */ + bus_space_handle_t r_bushandle; /* bus_space handle */ +}; + +struct resource_i; +struct resource_map; + +TAILQ_HEAD(resource_head, resource_i); + +struct rman { + struct resource_head rm_list; + struct mtx *rm_mtx; /* mutex used to protect rm_list */ + TAILQ_ENTRY(rman) rm_link; /* link in list of all rmans */ + rman_res_t rm_start; /* index of globally first entry */ + rman_res_t rm_end; /* index of globally last entry */ + enum rman_type rm_type; /* what type of resource this is */ + const char *rm_descr; /* text descripion of this resource */ +}; +TAILQ_HEAD(rman_head, rman); + +int rman_activate_resource(struct resource *r); +int rman_adjust_resource(struct resource *r, rman_res_t start, rman_res_t end); +int rman_first_free_region(struct rman *rm, rman_res_t *start, rman_res_t *end); +bus_space_handle_t rman_get_bushandle(struct resource *); +bus_space_tag_t rman_get_bustag(struct resource *); +rman_res_t rman_get_end(struct resource *); +device_t rman_get_device(struct resource *); +u_int rman_get_flags(struct resource *); +void *rman_get_irq_cookie(struct resource *); +void rman_get_mapping(struct resource *, struct resource_map *); +int rman_get_rid(struct resource *); +rman_res_t rman_get_size(struct resource *); +rman_res_t rman_get_start(struct resource *); +void *rman_get_virtual(struct resource *); +int rman_deactivate_resource(struct resource *r); +int rman_fini(struct rman *rm); +int rman_init(struct rman *rm); +int rman_init_from_resource(struct rman *rm, struct resource *r); +int rman_last_free_region(struct rman *rm, rman_res_t *start, rman_res_t *end); +uint32_t rman_make_alignment_flags(uint32_t size); +int rman_manage_region(struct rman *rm, rman_res_t start, rman_res_t end); +int rman_is_region_manager(struct resource *r, struct rman *rm); +int rman_release_resource(struct resource *r); +struct resource *rman_reserve_resource(struct rman *rm, rman_res_t start, + rman_res_t end, rman_res_t count, + u_int flags, device_t dev); +struct resource *rman_reserve_resource_bound(struct rman *rm, rman_res_t start, + rman_res_t end, rman_res_t count, rman_res_t bound, + u_int flags, device_t dev); +void rman_set_bushandle(struct resource *_r, bus_space_handle_t _h); +void rman_set_bustag(struct resource *_r, bus_space_tag_t _t); +void rman_set_device(struct resource *_r, device_t _dev); +void rman_set_end(struct resource *_r, rman_res_t _end); +void rman_set_irq_cookie(struct resource *_r, void *_c); +void rman_set_mapping(struct resource *, struct resource_map *); +void rman_set_rid(struct resource *_r, int _rid); +void rman_set_start(struct resource *_r, rman_res_t _start); +void rman_set_virtual(struct resource *_r, void *_v); + +extern struct rman_head rman_head; + +#endif /* _KERNEL */ + +#endif /* !_SYS_RMAN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/rmlock.h b/lib/libc/include/any-freebsd-any/sys/rmlock.h new file mode 100644 index 000000000000..cdcb6edc3b92 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rmlock.h @@ -0,0 +1,137 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2007 Stephan Uphoff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RMLOCK_H_ +#define _SYS_RMLOCK_H_ + +#include +#include +#include +#include + +#ifdef _KERNEL + +/* + * Flags passed to rm_init_flags(9). + */ +#define RM_NOWITNESS 0x00000001 +#define RM_RECURSE 0x00000002 +#define RM_SLEEPABLE 0x00000004 +#define RM_NEW 0x00000008 + +void rm_init(struct rmlock *rm, const char *name); +void rm_init_flags(struct rmlock *rm, const char *name, int opts); +void rm_destroy(struct rmlock *rm); +int rm_wowned(const struct rmlock *rm); +void rm_sysinit(void *arg); + +void _rm_wlock_debug(struct rmlock *rm, const char *file, int line); +void _rm_wunlock_debug(struct rmlock *rm, const char *file, int line); +int _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker, + int trylock, const char *file, int line); +void _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker, + const char *file, int line); + +void _rm_wlock(struct rmlock *rm); +void _rm_wunlock(struct rmlock *rm); +int _rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker, + int trylock); +void _rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker); +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void _rm_assert(const struct rmlock *rm, int what, const char *file, + int line); +#endif + +/* + * Public interface for lock operations. + */ +#ifndef LOCK_DEBUG +#error LOCK_DEBUG not defined, include before +#endif + +#if LOCK_DEBUG > 0 +#define rm_wlock(rm) _rm_wlock_debug((rm), LOCK_FILE, LOCK_LINE) +#define rm_wunlock(rm) _rm_wunlock_debug((rm), LOCK_FILE, LOCK_LINE) +#define rm_rlock(rm,tracker) \ + ((void)_rm_rlock_debug((rm),(tracker), 0, LOCK_FILE, LOCK_LINE )) +#define rm_try_rlock(rm,tracker) \ + _rm_rlock_debug((rm),(tracker), 1, LOCK_FILE, LOCK_LINE ) +#define rm_runlock(rm,tracker) \ + _rm_runlock_debug((rm), (tracker), LOCK_FILE, LOCK_LINE ) +#else +#define rm_wlock(rm) _rm_wlock((rm)) +#define rm_wunlock(rm) _rm_wunlock((rm)) +#define rm_rlock(rm,tracker) ((void)_rm_rlock((rm),(tracker), 0)) +#define rm_try_rlock(rm,tracker) _rm_rlock((rm),(tracker), 1) +#define rm_runlock(rm,tracker) _rm_runlock((rm), (tracker)) +#endif +#define rm_sleep(chan, rm, pri, wmesg, timo) \ + _sleep((chan), &(rm)->lock_object, (pri), (wmesg), \ + tick_sbt * (timo), 0, C_HARDCLOCK) + +struct rm_args { + struct rmlock *ra_rm; + const char *ra_desc; + int ra_flags; +}; + +#define RM_SYSINIT_FLAGS(name, rm, desc, flags) \ + static struct rm_args name##_args = { \ + (rm), \ + (desc), \ + (flags), \ + }; \ + SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + rm_sysinit, &name##_args); \ + SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + rm_destroy, (rm)) + +#define RM_SYSINIT(name, rm, desc) RM_SYSINIT_FLAGS(name, rm, desc, 0) + +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define RA_LOCKED LA_LOCKED +#define RA_RLOCKED LA_SLOCKED +#define RA_WLOCKED LA_XLOCKED +#define RA_UNLOCKED LA_UNLOCKED +#define RA_RECURSED LA_RECURSED +#define RA_NOTRECURSED LA_NOTRECURSED +#endif + +#ifdef INVARIANTS +#define rm_assert(rm, what) _rm_assert((rm), (what), LOCK_FILE, LOCK_LINE) +#else +#define rm_assert(rm, what) +#endif + +#endif /* _KERNEL */ +#endif /* !_SYS_RMLOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/rtprio.h b/lib/libc/include/any-freebsd-any/sys/rtprio.h new file mode 100644 index 000000000000..a950e9a459c7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rtprio.h @@ -0,0 +1,95 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1994, Henrik Vestergaard Draboel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Henrik Vestergaard Draboel. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RTPRIO_H_ +#define _SYS_RTPRIO_H_ + +#include + +/* + * Process realtime-priority specifications to rtprio. + */ + +/* priority types. Start at 1 to catch uninitialized fields. */ + +#define RTP_PRIO_ITHD PRI_ITHD /* Interrupt thread. */ +#define RTP_PRIO_REALTIME PRI_REALTIME /* real time process */ +#define RTP_PRIO_NORMAL PRI_TIMESHARE /* time sharing process */ +#define RTP_PRIO_IDLE PRI_IDLE /* idle process */ + +/* RTP_PRIO_FIFO is POSIX.1B SCHED_FIFO. + */ + +#define RTP_PRIO_FIFO_BIT PRI_FIFO_BIT +#define RTP_PRIO_FIFO PRI_FIFO +#define RTP_PRIO_BASE(P) PRI_BASE(P) +#define RTP_PRIO_IS_REALTIME(P) PRI_IS_REALTIME(P) +#define RTP_PRIO_NEED_RR(P) PRI_NEED_RR(P) + +/* priority range */ +#define RTP_PRIO_MIN 0 /* Highest priority */ +#define RTP_PRIO_MAX 31 /* Lowest priority */ + +/* + * rtprio() syscall functions + */ +#define RTP_LOOKUP 0 +#define RTP_SET 1 + +#ifndef LOCORE +/* + * Scheduling class information. + */ +struct rtprio { + u_short type; /* scheduling class */ + u_short prio; +}; + +#ifdef _KERNEL +struct thread; +int rtp_to_pri(struct rtprio *, struct thread *); +void pri_to_rtp(struct thread *, struct rtprio *); +#endif +#endif + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +int rtprio(int, pid_t, struct rtprio *); +int rtprio_thread(int, lwpid_t, struct rtprio *); +__END_DECLS +#endif /* !_KERNEL */ +#endif /* !_SYS_RTPRIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/runq.h b/lib/libc/include/any-freebsd-any/sys/runq.h new file mode 100644 index 000000000000..0e3113b1102f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/runq.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Jake Burkholder + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _RUNQ_H_ +#define _RUNQ_H_ + +#include + +struct thread; + +/* + * Run queue parameters. + */ + +#define RQ_NQS (64) /* Number of run queues. */ +#define RQ_PPQ (4) /* Priorities per queue. */ + +/* + * Head of run queues. + */ +TAILQ_HEAD(rqhead, thread); + +/* + * Bit array which maintains the status of a run queue. When a queue is + * non-empty the bit corresponding to the queue number will be set. + */ +struct rqbits { + rqb_word_t rqb_bits[RQB_LEN]; +}; + +/* + * Run queue structure. Contains an array of run queues on which processes + * are placed, and a structure to maintain the status of each queue. + */ +struct runq { + struct rqbits rq_status; + struct rqhead rq_queues[RQ_NQS]; +}; + +void runq_add(struct runq *, struct thread *, int); +void runq_add_pri(struct runq *, struct thread *, u_char, int); +int runq_check(struct runq *); +struct thread *runq_choose(struct runq *); +struct thread *runq_choose_from(struct runq *, u_char); +struct thread *runq_choose_fuzz(struct runq *, int); +void runq_init(struct runq *); +void runq_remove(struct runq *, struct thread *); +void runq_remove_idx(struct runq *, struct thread *, u_char *); + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/rwlock.h b/lib/libc/include/any-freebsd-any/sys/rwlock.h new file mode 100644 index 000000000000..58d5881eb767 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/rwlock.h @@ -0,0 +1,300 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_RWLOCK_H_ +#define _SYS_RWLOCK_H_ + +#include +#include +#include +#include + +#ifdef _KERNEL +#include +#include +#endif + +/* + * The rw_lock field consists of several fields. The low bit indicates + * if the lock is locked with a read (shared) or write (exclusive) lock. + * A value of 0 indicates a write lock, and a value of 1 indicates a read + * lock. Bit 1 is a boolean indicating if there are any threads waiting + * for a read lock. Bit 2 is a boolean indicating if there are any threads + * waiting for a write lock. The rest of the variable's definition is + * dependent on the value of the first bit. For a write lock, it is a + * pointer to the thread holding the lock, similar to the mtx_lock field of + * mutexes. For read locks, it is a count of read locks that are held. + * + * When the lock is not locked by any thread, it is encoded as a read lock + * with zero waiters. + */ + +#define RW_LOCK_READ 0x01 +#define RW_LOCK_READ_WAITERS 0x02 +#define RW_LOCK_WRITE_WAITERS 0x04 +#define RW_LOCK_WRITE_SPINNER 0x08 +#define RW_LOCK_WRITER_RECURSED 0x10 +#define RW_LOCK_FLAGMASK \ + (RW_LOCK_READ | RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS | \ + RW_LOCK_WRITE_SPINNER | RW_LOCK_WRITER_RECURSED) +#define RW_LOCK_WAITERS (RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS) + +#define RW_OWNER(x) ((x) & ~RW_LOCK_FLAGMASK) +#define RW_READERS_SHIFT 5 +#define RW_READERS(x) (RW_OWNER((x)) >> RW_READERS_SHIFT) +#define RW_READERS_LOCK(x) ((x) << RW_READERS_SHIFT | RW_LOCK_READ) +#define RW_ONE_READER (1 << RW_READERS_SHIFT) + +#define RW_UNLOCKED RW_READERS_LOCK(0) +#define RW_DESTROYED (RW_LOCK_READ_WAITERS | RW_LOCK_WRITE_WAITERS) + +#ifdef _KERNEL + +#define rw_recurse lock_object.lo_data + +#define RW_READ_VALUE(x) ((x)->rw_lock) + +/* Very simple operations on rw_lock. */ + +/* Try to obtain a write lock once. */ +#define _rw_write_lock(rw, tid) \ + atomic_cmpset_acq_ptr(&(rw)->rw_lock, RW_UNLOCKED, (tid)) + +#define _rw_write_lock_fetch(rw, vp, tid) \ + atomic_fcmpset_acq_ptr(&(rw)->rw_lock, vp, (tid)) + +/* Release a write lock quickly if there are no waiters. */ +#define _rw_write_unlock(rw, tid) \ + atomic_cmpset_rel_ptr(&(rw)->rw_lock, (tid), RW_UNLOCKED) + +#define _rw_write_unlock_fetch(rw, tid) \ + atomic_fcmpset_rel_ptr(&(rw)->rw_lock, (tid), RW_UNLOCKED) + +/* + * Full lock operations that are suitable to be inlined in non-debug + * kernels. If the lock cannot be acquired or released trivially then + * the work is deferred to another function. + */ + +/* Acquire a write lock. */ +#define __rw_wlock(rw, tid, file, line) do { \ + uintptr_t _tid = (uintptr_t)(tid); \ + uintptr_t _v = RW_UNLOCKED; \ + \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__acquire) || \ + !_rw_write_lock_fetch((rw), &_v, _tid))) \ + _rw_wlock_hard((rw), _v, (file), (line)); \ +} while (0) + +/* Release a write lock. */ +#define __rw_wunlock(rw, tid, file, line) do { \ + uintptr_t _v = (uintptr_t)(tid); \ + \ + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__release) || \ + !_rw_write_unlock_fetch((rw), &_v))) \ + _rw_wunlock_hard((rw), _v, (file), (line)); \ +} while (0) + +/* + * Function prototypes. Routines that start with _ are not part of the + * external API and should not be called directly. Wrapper macros should + * be used instead. + */ +void _rw_init_flags(volatile uintptr_t *c, const char *name, int opts); +void _rw_destroy(volatile uintptr_t *c); +void rw_sysinit(void *arg); +int _rw_wowned(const volatile uintptr_t *c); +void _rw_wlock_cookie(volatile uintptr_t *c, const char *file, int line); +int __rw_try_wlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +int __rw_try_wlock(volatile uintptr_t *c, const char *file, int line); +void _rw_wunlock_cookie(volatile uintptr_t *c, const char *file, int line); +void __rw_rlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +void __rw_rlock(volatile uintptr_t *c, const char *file, int line); +int __rw_try_rlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +int __rw_try_rlock(volatile uintptr_t *c, const char *file, int line); +void _rw_runlock_cookie_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +void _rw_runlock_cookie(volatile uintptr_t *c, const char *file, int line); +void __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v + LOCK_FILE_LINE_ARG_DEF); +void __rw_wunlock_hard(volatile uintptr_t *c, uintptr_t v + LOCK_FILE_LINE_ARG_DEF); +int __rw_try_upgrade_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +int __rw_try_upgrade(volatile uintptr_t *c, const char *file, int line); +void __rw_downgrade_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF); +void __rw_downgrade(volatile uintptr_t *c, const char *file, int line); +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void __rw_assert(const volatile uintptr_t *c, int what, const char *file, + int line); +#endif + +/* + * Top-level macros to provide lock cookie once the actual rwlock is passed. + * They will also prevent passing a malformed object to the rwlock KPI by + * failing compilation as the rw_lock reserved member will not be found. + */ +#define rw_init(rw, n) \ + _rw_init_flags(&(rw)->rw_lock, n, 0) +#define rw_init_flags(rw, n, o) \ + _rw_init_flags(&(rw)->rw_lock, n, o) +#define rw_destroy(rw) \ + _rw_destroy(&(rw)->rw_lock) +#define rw_wowned(rw) \ + _rw_wowned(&(rw)->rw_lock) +#define _rw_wlock(rw, f, l) \ + _rw_wlock_cookie(&(rw)->rw_lock, f, l) +#define _rw_try_wlock(rw, f, l) \ + __rw_try_wlock(&(rw)->rw_lock, f, l) +#define _rw_wunlock(rw, f, l) \ + _rw_wunlock_cookie(&(rw)->rw_lock, f, l) +#define _rw_try_rlock(rw, f, l) \ + __rw_try_rlock(&(rw)->rw_lock, f, l) +#if LOCK_DEBUG > 0 +#define _rw_rlock(rw, f, l) \ + __rw_rlock(&(rw)->rw_lock, f, l) +#define _rw_runlock(rw, f, l) \ + _rw_runlock_cookie(&(rw)->rw_lock, f, l) +#else +#define _rw_rlock(rw, f, l) \ + __rw_rlock_int((struct rwlock *)rw) +#define _rw_runlock(rw, f, l) \ + _rw_runlock_cookie_int((struct rwlock *)rw) +#endif +#if LOCK_DEBUG > 0 +#define _rw_wlock_hard(rw, v, f, l) \ + __rw_wlock_hard(&(rw)->rw_lock, v, f, l) +#define _rw_wunlock_hard(rw, v, f, l) \ + __rw_wunlock_hard(&(rw)->rw_lock, v, f, l) +#define _rw_try_upgrade(rw, f, l) \ + __rw_try_upgrade(&(rw)->rw_lock, f, l) +#define _rw_downgrade(rw, f, l) \ + __rw_downgrade(&(rw)->rw_lock, f, l) +#else +#define _rw_wlock_hard(rw, v, f, l) \ + __rw_wlock_hard(&(rw)->rw_lock, v) +#define _rw_wunlock_hard(rw, v, f, l) \ + __rw_wunlock_hard(&(rw)->rw_lock, v) +#define _rw_try_upgrade(rw, f, l) \ + __rw_try_upgrade_int(rw) +#define _rw_downgrade(rw, f, l) \ + __rw_downgrade_int(rw) +#endif +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define _rw_assert(rw, w, f, l) \ + __rw_assert(&(rw)->rw_lock, w, f, l) +#endif + + +/* + * Public interface for lock operations. + */ + +#ifndef LOCK_DEBUG +#error LOCK_DEBUG not defined, include before +#endif +#if LOCK_DEBUG > 0 || defined(RWLOCK_NOINLINE) +#define rw_wlock(rw) _rw_wlock((rw), LOCK_FILE, LOCK_LINE) +#define rw_wunlock(rw) _rw_wunlock((rw), LOCK_FILE, LOCK_LINE) +#else +#define rw_wlock(rw) \ + __rw_wlock((rw), curthread, LOCK_FILE, LOCK_LINE) +#define rw_wunlock(rw) \ + __rw_wunlock((rw), curthread, LOCK_FILE, LOCK_LINE) +#endif +#define rw_rlock(rw) _rw_rlock((rw), LOCK_FILE, LOCK_LINE) +#define rw_runlock(rw) _rw_runlock((rw), LOCK_FILE, LOCK_LINE) +#define rw_try_rlock(rw) _rw_try_rlock((rw), LOCK_FILE, LOCK_LINE) +#define rw_try_upgrade(rw) _rw_try_upgrade((rw), LOCK_FILE, LOCK_LINE) +#define rw_try_wlock(rw) _rw_try_wlock((rw), LOCK_FILE, LOCK_LINE) +#define rw_downgrade(rw) _rw_downgrade((rw), LOCK_FILE, LOCK_LINE) +#define rw_unlock(rw) do { \ + if (rw_wowned(rw)) \ + rw_wunlock(rw); \ + else \ + rw_runlock(rw); \ +} while (0) +#define rw_sleep(chan, rw, pri, wmesg, timo) \ + _sleep((chan), &(rw)->lock_object, (pri), (wmesg), \ + tick_sbt * (timo), 0, C_HARDCLOCK) + +#define rw_initialized(rw) lock_initialized(&(rw)->lock_object) + +struct rw_args { + void *ra_rw; + const char *ra_desc; + int ra_flags; +}; + +#define RW_SYSINIT_FLAGS(name, rw, desc, flags) \ + static struct rw_args name##_args = { \ + (rw), \ + (desc), \ + (flags), \ + }; \ + SYSINIT(name##_rw_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + rw_sysinit, &name##_args); \ + SYSUNINIT(name##_rw_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + _rw_destroy, __DEVOLATILE(void *, &(rw)->rw_lock)) + +#define RW_SYSINIT(name, rw, desc) RW_SYSINIT_FLAGS(name, rw, desc, 0) + +/* + * Options passed to rw_init_flags(). + */ +#define RW_DUPOK 0x01 +#define RW_NOPROFILE 0x02 +#define RW_NOWITNESS 0x04 +#define RW_QUIET 0x08 +#define RW_RECURSE 0x10 +#define RW_NEW 0x20 + +/* + * The INVARIANTS-enabled rw_assert() functionality. + * + * The constants need to be defined for INVARIANT_SUPPORT infrastructure + * support as _rw_assert() itself uses them and the latter implies that + * _rw_assert() must build. + */ +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define RA_LOCKED LA_LOCKED +#define RA_RLOCKED LA_SLOCKED +#define RA_WLOCKED LA_XLOCKED +#define RA_UNLOCKED LA_UNLOCKED +#define RA_RECURSED LA_RECURSED +#define RA_NOTRECURSED LA_NOTRECURSED +#endif + +#ifdef INVARIANTS +#define rw_assert(rw, what) _rw_assert((rw), (what), LOCK_FILE, LOCK_LINE) +#else +#define rw_assert(rw, what) +#endif + +#endif /* _KERNEL */ +#endif /* !_SYS_RWLOCK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sbuf.h b/lib/libc/include/any-freebsd-any/sys/sbuf.h new file mode 100644 index 000000000000..a3b0a179c268 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sbuf.h @@ -0,0 +1,117 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000-2008 Poul-Henning Kamp + * Copyright (c) 2000-2008 Dag-Erling Coïdan Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SBUF_H_ +#define _SYS_SBUF_H_ + +#include + +struct sbuf; +typedef int (sbuf_drain_func)(void *, const char *, int); + +/* + * Structure definition + */ +struct sbuf { + char *s_buf; /* storage buffer */ + sbuf_drain_func *s_drain_func; /* drain function */ + void *s_drain_arg; /* user-supplied drain argument */ + int s_error; /* current error code */ + ssize_t s_size; /* size of storage buffer */ + ssize_t s_len; /* current length of string */ +#define SBUF_FIXEDLEN 0x00000000 /* fixed length buffer (default) */ +#define SBUF_AUTOEXTEND 0x00000001 /* automatically extend buffer */ +#define SBUF_INCLUDENUL 0x00000002 /* nulterm byte is counted in len */ +#define SBUF_DRAINTOEOR 0x00000004 /* use section 0 as drain EOR marker */ +#define SBUF_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */ +#define SBUF_DYNAMIC 0x00010000 /* s_buf must be freed */ +#define SBUF_FINISHED 0x00020000 /* set by sbuf_finish() */ +#define SBUF_DYNSTRUCT 0x00080000 /* sbuf must be freed */ +#define SBUF_INSECTION 0x00100000 /* set by sbuf_start_section() */ + int s_flags; /* flags */ + ssize_t s_sect_len; /* current length of section */ + ssize_t s_rec_off; /* current record start offset */ +}; + +#ifndef HD_COLUMN_MASK +#define HD_COLUMN_MASK 0xff +#define HD_DELIM_MASK 0xff00 +#define HD_OMIT_COUNT (1 << 16) +#define HD_OMIT_HEX (1 << 17) +#define HD_OMIT_CHARS (1 << 18) +#endif /* HD_COLUMN_MASK */ + +__BEGIN_DECLS +/* + * API functions + */ +struct sbuf *sbuf_new(struct sbuf *, char *, int, int); +#define sbuf_new_auto() \ + sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND) +int sbuf_get_flags(struct sbuf *); +void sbuf_clear_flags(struct sbuf *, int); +void sbuf_set_flags(struct sbuf *, int); +void sbuf_clear(struct sbuf *); +int sbuf_setpos(struct sbuf *, ssize_t); +int sbuf_bcat(struct sbuf *, const void *, size_t); +int sbuf_bcpy(struct sbuf *, const void *, size_t); +int sbuf_cat(struct sbuf *, const char *); +int sbuf_cpy(struct sbuf *, const char *); +int sbuf_printf(struct sbuf *, const char *, ...) + __printflike(2, 3); +int sbuf_vprintf(struct sbuf *, const char *, __va_list) + __printflike(2, 0); +int sbuf_putc(struct sbuf *, int); +void sbuf_set_drain(struct sbuf *, sbuf_drain_func *, void *); +int sbuf_trim(struct sbuf *); +int sbuf_error(const struct sbuf *); +int sbuf_finish(struct sbuf *); +char *sbuf_data(struct sbuf *); +ssize_t sbuf_len(struct sbuf *); +int sbuf_done(const struct sbuf *); +void sbuf_delete(struct sbuf *); +void sbuf_start_section(struct sbuf *, ssize_t *); +ssize_t sbuf_end_section(struct sbuf *, ssize_t, size_t, int); +void sbuf_hexdump(struct sbuf *, const void *, int, const char *, + int); +int sbuf_count_drain(void *arg, const char *data, int len); +void sbuf_putbuf(struct sbuf *); + +#ifdef _KERNEL +struct uio; +struct sbuf *sbuf_uionew(struct sbuf *, struct uio *, int *); +int sbuf_bcopyin(struct sbuf *, const void *, size_t); +int sbuf_copyin(struct sbuf *, const void *, size_t); +#endif +__END_DECLS + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/sched.h b/lib/libc/include/any-freebsd-any/sys/sched.h new file mode 100644 index 000000000000..99d6e0f63dd9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sched.h @@ -0,0 +1,266 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1996, 1997 + * HD Associates, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by HD Associates, Inc + * and Jukka Antero Ukkonen. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 2002-2008, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SCHED_H_ +#define _SCHED_H_ + +#ifdef _KERNEL +/* + * General scheduling info. + * + * sched_load: + * Total runnable non-ithread threads in the system. + * + * sched_runnable: + * Runnable threads for this processor. + */ +int sched_load(void); +int sched_rr_interval(void); +int sched_runnable(void); + +/* + * Proc related scheduling hooks. + */ +void sched_exit(struct proc *p, struct thread *childtd); +void sched_fork(struct thread *td, struct thread *childtd); +void sched_fork_exit(struct thread *td); +void sched_class(struct thread *td, int class); +void sched_nice(struct proc *p, int nice); + +/* + * Threads are switched in and out, block on resources, have temporary + * priorities inherited from their procs, and use up cpu time. + */ +void sched_exit_thread(struct thread *td, struct thread *child); +u_int sched_estcpu(struct thread *td); +void sched_fork_thread(struct thread *td, struct thread *child); +void sched_lend_prio(struct thread *td, u_char prio); +void sched_lend_user_prio(struct thread *td, u_char pri); +fixpt_t sched_pctcpu(struct thread *td); +void sched_prio(struct thread *td, u_char prio); +void sched_sleep(struct thread *td, int prio); +void sched_switch(struct thread *td, struct thread *newtd, int flags); +void sched_throw(struct thread *td); +void sched_unlend_prio(struct thread *td, u_char prio); +void sched_user_prio(struct thread *td, u_char prio); +void sched_userret_slowpath(struct thread *td); +void sched_wakeup(struct thread *td); +#ifdef RACCT +#ifdef SCHED_4BSD +fixpt_t sched_pctcpu_delta(struct thread *td); +#endif +#endif + +static inline void +sched_userret(struct thread *td) +{ + + /* + * XXX we cheat slightly on the locking here to avoid locking in + * the usual case. Setting td_priority here is essentially an + * incomplete workaround for not setting it properly elsewhere. + * Now that some interrupt handlers are threads, not setting it + * properly elsewhere can clobber it in the window between setting + * it here and returning to user mode, so don't waste time setting + * it perfectly here. + */ + KASSERT((td->td_flags & TDF_BORROWING) == 0, + ("thread with borrowed priority returning to userland")); + if (__predict_false(td->td_priority != td->td_user_pri)) + sched_userret_slowpath(td); +} + +/* + * Threads are moved on and off of run queues + */ +void sched_add(struct thread *td, int flags); +void sched_clock(struct thread *td); +void sched_preempt(struct thread *td); +void sched_rem(struct thread *td); +void sched_relinquish(struct thread *td); +struct thread *sched_choose(void); +void sched_idletd(void *); + +/* + * Binding makes cpu affinity permanent while pinning is used to temporarily + * hold a thread on a particular CPU. + */ +void sched_bind(struct thread *td, int cpu); +static __inline void sched_pin(void); +void sched_unbind(struct thread *td); +static __inline void sched_unpin(void); +int sched_is_bound(struct thread *td); +void sched_affinity(struct thread *td); + +/* + * These procedures tell the process data structure allocation code how + * many bytes to actually allocate. + */ +int sched_sizeof_proc(void); +int sched_sizeof_thread(void); + +/* + * This routine provides a consistent thread name for use with KTR graphing + * functions. + */ +char *sched_tdname(struct thread *td); +#ifdef KTR +void sched_clear_tdname(struct thread *td); +#endif + +static __inline void +sched_pin(void) +{ + curthread->td_pinned++; + __compiler_membar(); +} + +static __inline void +sched_unpin(void) +{ + __compiler_membar(); + curthread->td_pinned--; +} + +/* sched_add arguments (formerly setrunqueue) */ +#define SRQ_BORING 0x0000 /* No special circumstances. */ +#define SRQ_YIELDING 0x0001 /* We are yielding (from mi_switch). */ +#define SRQ_OURSELF 0x0002 /* It is ourself (from mi_switch). */ +#define SRQ_INTR 0x0004 /* It is probably urgent. */ +#define SRQ_PREEMPTED 0x0008 /* has been preempted.. be kind */ +#define SRQ_BORROWING 0x0010 /* Priority updated due to prio_lend */ + +/* Scheduler stats. */ +#ifdef SCHED_STATS +DPCPU_DECLARE(long, sched_switch_stats[SWT_COUNT]); + +#define SCHED_STAT_DEFINE_VAR(name, ptr, descr) \ +static void name ## _add_proc(void *dummy __unused) \ +{ \ + \ + SYSCTL_ADD_PROC(NULL, \ + SYSCTL_STATIC_CHILDREN(_kern_sched_stats), OID_AUTO, \ + #name, CTLTYPE_LONG|CTLFLAG_RD|CTLFLAG_MPSAFE, \ + ptr, 0, sysctl_dpcpu_long, "LU", descr); \ +} \ +SYSINIT(name, SI_SUB_LAST, SI_ORDER_MIDDLE, name ## _add_proc, NULL); + +#define SCHED_STAT_DEFINE(name, descr) \ + DPCPU_DEFINE(unsigned long, name); \ + SCHED_STAT_DEFINE_VAR(name, &DPCPU_NAME(name), descr) +/* + * Sched stats are always incremented in critical sections so no atomic + * is necesssary to increment them. + */ +#define SCHED_STAT_INC(var) DPCPU_GET(var)++; +#else +#define SCHED_STAT_DEFINE_VAR(name, descr, ptr) +#define SCHED_STAT_DEFINE(name, descr) +#define SCHED_STAT_INC(var) (void)0 +#endif + +/* + * Fixup scheduler state for proc0 and thread0 + */ +void schedinit(void); +#endif /* _KERNEL */ + +/* POSIX 1003.1b Process Scheduling */ + +/* + * POSIX scheduling policies + */ +#define SCHED_FIFO 1 +#define SCHED_OTHER 2 +#define SCHED_RR 3 + +struct sched_param { + int sched_priority; +}; + +/* + * POSIX scheduling declarations for userland. + */ +#ifndef _KERNEL +#include +#include +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +__BEGIN_DECLS +int sched_get_priority_max(int); +int sched_get_priority_min(int); +int sched_getparam(pid_t, struct sched_param *); +int sched_getscheduler(pid_t); +int sched_rr_get_interval(pid_t, struct timespec *); +int sched_setparam(pid_t, const struct sched_param *); +int sched_setscheduler(pid_t, int, const struct sched_param *); +int sched_yield(void); +__END_DECLS + +#endif +#endif /* !_SCHED_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sdt.h b/lib/libc/include/any-freebsd-any/sys/sdt.h new file mode 100644 index 000000000000..424a0e3a0ded --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sdt.h @@ -0,0 +1,431 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 2006-2008 John Birrell + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Statically Defined Tracing (SDT) definitions. + * + */ + +#ifndef _SYS_SDT_H +#define _SYS_SDT_H + +#ifndef _KERNEL + +#define _DTRACE_VERSION 1 + +#define DTRACE_PROBE(prov, name) { \ + extern void __dtrace_##prov##___##name(void); \ + __dtrace_##prov##___##name(); \ +} + +#define DTRACE_PROBE1(prov, name, arg1) { \ + extern void __dtrace_##prov##___##name(unsigned long); \ + __dtrace_##prov##___##name((unsigned long)arg1); \ +} + +#define DTRACE_PROBE2(prov, name, arg1, arg2) { \ + extern void __dtrace_##prov##___##name(unsigned long, \ + unsigned long); \ + __dtrace_##prov##___##name((unsigned long)arg1, \ + (unsigned long)arg2); \ +} + +#define DTRACE_PROBE3(prov, name, arg1, arg2, arg3) { \ + extern void __dtrace_##prov##___##name(unsigned long, \ + unsigned long, unsigned long); \ + __dtrace_##prov##___##name((unsigned long)arg1, \ + (unsigned long)arg2, (unsigned long)arg3); \ +} + +#define DTRACE_PROBE4(prov, name, arg1, arg2, arg3, arg4) { \ + extern void __dtrace_##prov##___##name(unsigned long, \ + unsigned long, unsigned long, unsigned long); \ + __dtrace_##prov##___##name((unsigned long)arg1, \ + (unsigned long)arg2, (unsigned long)arg3, \ + (unsigned long)arg4); \ +} + +#define DTRACE_PROBE5(prov, name, arg1, arg2, arg3, arg4, arg5) { \ + extern void __dtrace_##prov##___##name(unsigned long, \ + unsigned long, unsigned long, unsigned long, unsigned long);\ + __dtrace_##prov##___##name((unsigned long)arg1, \ + (unsigned long)arg2, (unsigned long)arg3, \ + (unsigned long)arg4, (unsigned long)arg5); \ +} + +#else /* _KERNEL */ + +#include +#include + +extern volatile bool sdt_probes_enabled; + +#ifndef KDTRACE_HOOKS + +#define SDT_PROVIDER_DEFINE(prov) +#define SDT_PROVIDER_DECLARE(prov) +#define SDT_PROBE_DEFINE(prov, mod, func, name) +#define SDT_PROBE_DECLARE(prov, mod, func, name) +#define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) +#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype) + +#define SDT_PROBE_DEFINE0(prov, mod, func, name) +#define SDT_PROBE_DEFINE1(prov, mod, func, name, arg0) +#define SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1) +#define SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2) +#define SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3) +#define SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) +#define SDT_PROBE_DEFINE6(prov, mod, func, name, arg0, arg1, arg2, \ + arg3, arg4, arg5) +#define SDT_PROBE_DEFINE7(prov, mod, func, name, arg0, arg1, arg2, \ + arg3, arg4, arg5, arg6) + +#define SDT_PROBE0(prov, mod, func, name) +#define SDT_PROBE1(prov, mod, func, name, arg0) +#define SDT_PROBE2(prov, mod, func, name, arg0, arg1) +#define SDT_PROBE3(prov, mod, func, name, arg0, arg1, arg2) +#define SDT_PROBE4(prov, mod, func, name, arg0, arg1, arg2, arg3) +#define SDT_PROBE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) +#define SDT_PROBE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5) +#define SDT_PROBE7(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5, \ + arg6) + +#define SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name) +#define SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, arg0, xarg0) +#define SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1) +#define SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2) +#define SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3) +#define SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4) +#define SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5) +#define SDT_PROBE_DEFINE7_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5, arg6, \ + xarg6) + +#define DTRACE_PROBE(name) +#define DTRACE_PROBE1(name, type0, arg0) +#define DTRACE_PROBE2(name, type0, arg0, type1, arg1) +#define DTRACE_PROBE3(name, type0, arg0, type1, arg1, type2, arg2) +#define DTRACE_PROBE4(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3) +#define DTRACE_PROBE5(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3,\ + type4, arg4) + +#else + +SET_DECLARE(sdt_providers_set, struct sdt_provider); +SET_DECLARE(sdt_probes_set, struct sdt_probe); +SET_DECLARE(sdt_argtypes_set, struct sdt_argtype); + +#define SDT_PROVIDER_DEFINE(prov) \ + struct sdt_provider sdt_provider_##prov[1] = { \ + { #prov, { NULL, NULL }, 0, 0 } \ + }; \ + DATA_SET(sdt_providers_set, sdt_provider_##prov); + +#define SDT_PROVIDER_DECLARE(prov) \ + extern struct sdt_provider sdt_provider_##prov[1] + +#define SDT_PROBE_DEFINE(prov, mod, func, name) \ + struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1] = { \ + { sizeof(struct sdt_probe), sdt_provider_##prov, \ + { NULL, NULL }, { NULL, NULL }, #mod, #func, #name, 0, 0, \ + NULL } \ + }; \ + DATA_SET(sdt_probes_set, sdt_##prov##_##mod##_##func##_##name); + +#define SDT_PROBE_DECLARE(prov, mod, func, name) \ + extern struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1] + +#define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) do { \ + if (__predict_false(sdt_probes_enabled)) { \ + if (__predict_false(sdt_##prov##_##mod##_##func##_##name->id)) \ + (*sdt_probe_func)(sdt_##prov##_##mod##_##func##_##name->id, \ + (uintptr_t) arg0, (uintptr_t) arg1, (uintptr_t) arg2, \ + (uintptr_t) arg3, (uintptr_t) arg4); \ + } \ +} while (0) + +#define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype) \ + static struct sdt_argtype sdta_##prov##_##mod##_##func##_##name##num[1] \ + = { { num, type, xtype, { NULL, NULL }, \ + sdt_##prov##_##mod##_##func##_##name } \ + }; \ + DATA_SET(sdt_argtypes_set, sdta_##prov##_##mod##_##func##_##name##num); + +#define SDT_PROBE_DEFINE0(prov, mod, func, name) \ + SDT_PROBE_DEFINE(prov, mod, func, name) + +#define SDT_PROBE_DEFINE1(prov, mod, func, name, arg0) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL) + +#define SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL) + +#define SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2)\ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL) + +#define SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL) + +#define SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL) + +#define SDT_PROBE_DEFINE6(prov, mod, func, name, arg0, arg1, arg2, arg3,\ + arg4, arg5) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, NULL) + +#define SDT_PROBE_DEFINE7(prov, mod, func, name, arg0, arg1, arg2, arg3,\ + arg4, arg5, arg6) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, NULL); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 6, arg6, NULL) + +#define SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name) \ + SDT_PROBE_DEFINE(prov, mod, func, name) + +#define SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, arg0, xarg0) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0) + +#define SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1) + +#define SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2) + +#define SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3) + +#define SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4) + +#define SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, xarg5) + +#define SDT_PROBE_DEFINE7_XLATE(prov, mod, func, name, arg0, xarg0, \ + arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5, arg6, \ + xarg6) \ + SDT_PROBE_DEFINE(prov, mod, func, name); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, xarg5); \ + SDT_PROBE_ARGTYPE(prov, mod, func, name, 6, arg6, xarg6) + +#define SDT_PROBE0(prov, mod, func, name) \ + SDT_PROBE(prov, mod, func, name, 0, 0, 0, 0, 0) +#define SDT_PROBE1(prov, mod, func, name, arg0) \ + SDT_PROBE(prov, mod, func, name, arg0, 0, 0, 0, 0) +#define SDT_PROBE2(prov, mod, func, name, arg0, arg1) \ + SDT_PROBE(prov, mod, func, name, arg0, arg1, 0, 0, 0) +#define SDT_PROBE3(prov, mod, func, name, arg0, arg1, arg2) \ + SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, 0, 0) +#define SDT_PROBE4(prov, mod, func, name, arg0, arg1, arg2, arg3) \ + SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, 0) +#define SDT_PROBE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \ + SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) +#define SDT_PROBE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5) \ + do { \ + if (sdt_##prov##_##mod##_##func##_##name->id) \ + (*(void (*)(uint32_t, uintptr_t, uintptr_t, uintptr_t, \ + uintptr_t, uintptr_t, uintptr_t))sdt_probe_func)( \ + sdt_##prov##_##mod##_##func##_##name->id, \ + (uintptr_t)arg0, (uintptr_t)arg1, (uintptr_t)arg2, \ + (uintptr_t)arg3, (uintptr_t)arg4, (uintptr_t)arg5);\ + } while (0) +#define SDT_PROBE7(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5, \ + arg6) \ + do { \ + if (sdt_##prov##_##mod##_##func##_##name->id) \ + (*(void (*)(uint32_t, uintptr_t, uintptr_t, uintptr_t, \ + uintptr_t, uintptr_t, uintptr_t, uintptr_t)) \ + sdt_probe_func)( \ + sdt_##prov##_##mod##_##func##_##name->id, \ + (uintptr_t)arg0, (uintptr_t)arg1, (uintptr_t)arg2, \ + (uintptr_t)arg3, (uintptr_t)arg4, (uintptr_t)arg5, \ + (uintptr_t)arg6); \ + } while (0) + +#define DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, arg4) do { \ + static SDT_PROBE_DEFINE(sdt, , , name); \ + SDT_PROBE(sdt, , , name, arg0, arg1, arg2, arg3, arg4); +#define DTRACE_PROBE_IMPL_END } while (0) + +#define DTRACE_PROBE(name) \ + DTRACE_PROBE_IMPL_START(name, 0, 0, 0, 0, 0) \ + DTRACE_PROBE_IMPL_END + +#define DTRACE_PROBE1(name, type0, arg0) \ + DTRACE_PROBE_IMPL_START(name, arg0, 0, 0, 0, 0) \ + SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL); \ + DTRACE_PROBE_IMPL_END + +#define DTRACE_PROBE2(name, type0, arg0, type1, arg1) \ + DTRACE_PROBE_IMPL_START(name, arg0, arg1, 0, 0, 0) \ + SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL); \ + DTRACE_PROBE_IMPL_END + +#define DTRACE_PROBE3(name, type0, arg0, type1, arg1, type2, arg2) \ + DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, 0, 0) \ + SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL); \ + DTRACE_PROBE_IMPL_END + +#define DTRACE_PROBE4(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \ + DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, 0) \ + SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 3, #type3, NULL); \ + DTRACE_PROBE_IMPL_END + +#define DTRACE_PROBE5(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4) \ + DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, arg4) \ + SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 3, #type3, NULL); \ + SDT_PROBE_ARGTYPE(sdt, , , name, 4, #type4, NULL); \ + DTRACE_PROBE_IMPL_END + +#endif /* KDTRACE_HOOKS */ + +/* + * This type definition must match that of dtrace_probe. It is defined this + * way to avoid having to rely on CDDL code. + */ +typedef void (*sdt_probe_func_t)(uint32_t, uintptr_t arg0, uintptr_t arg1, + uintptr_t arg2, uintptr_t arg3, uintptr_t arg4); + +/* + * The 'sdt' provider will set it to dtrace_probe when it loads. + */ +extern sdt_probe_func_t sdt_probe_func; + +struct sdt_probe; +struct sdt_provider; +struct linker_file; + +struct sdt_argtype { + int ndx; /* Argument index. */ + const char *type; /* Argument type string. */ + const char *xtype; /* Translated argument type. */ + TAILQ_ENTRY(sdt_argtype) + argtype_entry; /* Argument type list entry. */ + struct sdt_probe *probe; /* Ptr to the probe structure. */ +}; + +struct sdt_probe { + int version; /* Set to sizeof(struct sdt_probe). */ + struct sdt_provider *prov; /* Ptr to the provider structure. */ + TAILQ_ENTRY(sdt_probe) + probe_entry; /* SDT probe list entry. */ + TAILQ_HEAD(, sdt_argtype) argtype_list; + const char *mod; + const char *func; + const char *name; + id_t id; /* DTrace probe ID. */ + int n_args; /* Number of arguments. */ + struct linker_file *sdtp_lf; /* Module in which we're defined. */ +}; + +struct sdt_provider { + char *name; /* Provider name. */ + TAILQ_ENTRY(sdt_provider) + prov_entry; /* SDT provider list entry. */ + uintptr_t id; /* DTrace provider ID. */ + int sdt_refs; /* Number of module references. */ +}; + +void sdt_probe_stub(uint32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, + uintptr_t); + +SDT_PROVIDER_DECLARE(sdt); + +#endif /* _KERNEL */ + +#endif /* _SYS_SDT_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/select.h b/lib/libc/include/any-freebsd-any/sys/select.h new file mode 100644 index 000000000000..15d59cbc68dd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/select.h @@ -0,0 +1,110 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SELECT_H_ +#define _SYS_SELECT_H_ + +#include +#include + +#include +#include +#include + +typedef unsigned long __fd_mask; +#if __BSD_VISIBLE +typedef __fd_mask fd_mask; +#endif + +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif + +/* + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024 +#endif + +#define _NFDBITS (sizeof(__fd_mask) * 8) /* bits per mask */ +#if __BSD_VISIBLE +#define NFDBITS _NFDBITS +#endif + +#ifndef _howmany +#define _howmany(x, y) (((x) + ((y) - 1)) / (y)) +#endif + +typedef struct fd_set { + __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)]; +} fd_set; +#if __BSD_VISIBLE +#define fds_bits __fds_bits +#endif + +#define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS)) +#define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n)) +#if __BSD_VISIBLE +#define FD_COPY(f, t) (void)(*(t) = *(f)) +#endif +#define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0) +#define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n)) +#define FD_ZERO(p) do { \ + fd_set *_p; \ + __size_t _n; \ + \ + _p = (p); \ + _n = _howmany(FD_SETSIZE, _NFDBITS); \ + while (_n > 0) \ + _p->__fds_bits[--_n] = 0; \ +} while (0) + +#ifndef _KERNEL + +__BEGIN_DECLS +int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, + const struct timespec *__restrict, const sigset_t *__restrict); +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED +/* XXX missing restrict type-qualifier */ +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* _SYS_SELECT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/selinfo.h b/lib/libc/include/any-freebsd-any/sys/selinfo.h new file mode 100644 index 000000000000..c5f3ad6b80a4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/selinfo.h @@ -0,0 +1,63 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)select.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_SELINFO_H_ +#define _SYS_SELINFO_H_ + +#include /* for struct klist */ + +struct selfd; +TAILQ_HEAD(selfdlist, selfd); + +/* + * Used to maintain information about processes that wish to be + * notified when I/O becomes possible. + */ +struct selinfo { + struct selfdlist si_tdlist; /* List of sleeping threads. */ + struct knlist si_note; /* kernel note list */ + struct mtx *si_mtx; /* Lock for tdlist. */ +}; + +#define SEL_WAITING(si) (!TAILQ_EMPTY(&(si)->si_tdlist)) + +#ifdef _KERNEL +void seldrain(struct selinfo *sip); +void selrecord(struct thread *selector, struct selinfo *sip); +void selwakeup(struct selinfo *sip); +void selwakeuppri(struct selinfo *sip, int pri); +void seltdfini(struct thread *td); +#endif + +#endif /* !_SYS_SELINFO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sem.h b/lib/libc/include/any-freebsd-any/sys/sem.h new file mode 100644 index 000000000000..bf1e31e4aca1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sem.h @@ -0,0 +1,159 @@ +/* $FreeBSD$ */ +/* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ + +/* + * SVID compatible sem.h file + * + * Author: Daniel Boulet + */ + +#ifndef _SYS_SEM_H_ +#define _SYS_SEM_H_ + +#ifdef _WANT_SYSVSEM_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) +struct semid_ds_old { + struct ipc_perm_old sem_perm; /* operation permission struct */ + struct sem *__sem_base; /* pointer to first semaphore in set */ + unsigned short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + long sem_pad1; /* SVABI/386 says I need this here */ + time_t sem_ctime; /* last change time */ + /* Times measured in secs since */ + /* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */ + long sem_pad2; /* SVABI/386 says I need this here */ + long sem_pad3[4]; /* SVABI/386 says I need this here */ +}; +#endif + +struct semid_ds { + struct ipc_perm sem_perm; /* operation permission struct */ + struct sem *__sem_base; /* pointer to first semaphore in set */ + unsigned short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + time_t sem_ctime; /* last change time */ + /* Times measured in secs since */ + /* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */ +}; + +/* + * semop's sops parameter structure + */ +struct sembuf { + unsigned short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +}; +#define SEM_UNDO 010000 + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \ + defined(_WANT_SEMUN_OLD) +union semun_old { + int val; /* value for SETVAL */ + struct semid_ds_old *buf; /* buffer for IPC_STAT & IPC_SET */ + unsigned short *array; /* array for GETALL & SETALL */ +}; +#endif + +#if defined(_KERNEL) || defined(_WANT_SEMUN) +/* + * semctl's arg parameter structure + */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + unsigned short *array; /* array for GETALL & SETALL */ +}; +#endif + +/* + * commands for semctl + */ +#define GETNCNT 3 /* Return the value of semncnt {READ} */ +#define GETPID 4 /* Return the value of sempid {READ} */ +#define GETVAL 5 /* Return the value of semval {READ} */ +#define GETALL 6 /* Return semvals into arg.array {READ} */ +#define GETZCNT 7 /* Return the value of semzcnt {READ} */ +#define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ +#define SETALL 9 /* Set semvals from arg.array {ALTER} */ +#define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ +#define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ + +/* + * Permissions + */ +#define SEM_A IPC_W /* alter permission */ +#define SEM_R IPC_R /* read permission */ + +#if defined(_KERNEL) || defined(_WANT_SYSVSEM_INTERNALS) +/* + * semaphore info struct + */ +struct seminfo { + int semmni; /* # of semaphore identifiers */ + int semmns; /* # of semaphores in system */ + int semmnu; /* # of undo structures in system */ + int semmsl; /* max # of semaphores per id */ + int semopm; /* max # of operations per semop call */ + int semume; /* max # of undo entries per process */ + int semusz; /* size in bytes of undo structure */ + int semvmx; /* semaphore maximum value */ + int semaem; /* adjust on exit max value */ +}; + +/* + * Kernel wrapper for the user-level structure + */ +struct semid_kernel { + struct semid_ds u; + struct label *label; /* MAC framework label */ + struct ucred *cred; /* creator's credentials */ +}; + +/* internal "mode" bits */ +#define SEM_ALLOC 01000 /* semaphore is allocated */ +#define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ +#endif + +#ifdef _KERNEL +extern struct seminfo seminfo; +/* + * Process sem_undo vectors at proc exit. + */ +void semexit(struct proc *p); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +#if __BSD_VISIBLE +int semsys(int, ...); +#endif +int semctl(int, int, int, ...); +int semget(key_t, int, int); +int semop(int, struct sembuf *, size_t); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SEM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sema.h b/lib/libc/include/any-freebsd-any/sys/sema.h new file mode 100644 index 000000000000..3b91c921c46a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sema.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 2001 Jason Evans . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SEMA_H_ +#define _SYS_SEMA_H_ + +#include +#include +#include +#include + +struct sema { + struct mtx sema_mtx; /* General protection lock. */ + struct cv sema_cv; /* Waiters. */ + int sema_waiters; /* Number of waiters. */ + int sema_value; /* Semaphore value. */ +}; + +#ifdef _KERNEL +void sema_init(struct sema *sema, int value, const char *description); +void sema_destroy(struct sema *sema); +void _sema_post(struct sema *sema, const char *file, int line); +void _sema_wait(struct sema *sema, const char *file, int line); +int _sema_timedwait(struct sema *sema, int timo, const char *file, int + line); +int _sema_trywait(struct sema *sema, const char *file, int line); +int sema_value(struct sema *sema); + +#define sema_post(sema) _sema_post((sema), LOCK_FILE, LOCK_LINE) +#define sema_wait(sema) _sema_wait((sema), LOCK_FILE, LOCK_LINE) +#define sema_timedwait(sema, timo) \ + _sema_timedwait((sema), (timo), LOCK_FILE, LOCK_LINE) +#define sema_trywait(sema) _sema_trywait((sema), LOCK_FILE, LOCK_LINE) + +#endif /* _KERNEL */ +#endif /* _SYS_SEMA_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/seq.h b/lib/libc/include/any-freebsd-any/sys/seq.h new file mode 100644 index 000000000000..5a1f7cffb7f2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/seq.h @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 2014 Mateusz Guzik + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SEQ_H_ +#define _SYS_SEQ_H_ + +#ifdef _KERNEL +#include +#endif +#include + +/* + * seq_t may be included in structs visible to userspace + */ +typedef uint32_t seq_t; + +#ifdef _KERNEL + +/* + * seq allows readers and writers to work with a consistent snapshot. Modifying + * operations must be enclosed within a transaction delineated by + * seq_write_beg/seq_write_end. The trick works by having the writer increment + * the sequence number twice, at the beginning and end of the transaction. + * The reader detects that the sequence number has not changed between its start + * and end, and that the sequence number is even, to validate consistency. + * + * Some fencing (both hard fencing and compiler barriers) may be needed, + * depending on the cpu. Modern AMD cpus provide strong enough guarantees to not + * require any fencing by the reader or writer. + * + * Example usage: + * + * writers: + * lock_exclusive(&obj->lock); + * seq_write_begin(&obj->seq); + * obj->var1 = ...; + * obj->var2 = ...; + * seq_write_end(&obj->seq); + * unlock_exclusive(&obj->lock); + * + * readers: + * int var1, var2; + * seq_t seq; + * + * for (;;) { + * seq = seq_read(&obj->seq); + * var1 = obj->var1; + * var2 = obj->var2; + * if (seq_consistent(&obj->seq, seq)) + * break; + * } + * ..... + * + * Writers may not block or sleep in any way. + * + * There are 2 minor caveats in this implementation: + * + * 1. There is no guarantee of progress. That is, a large number of writers can + * interfere with the execution of the readers and cause the code to live-lock + * in a loop trying to acquire a consistent snapshot. + * + * 2. If the reader loops long enough, the counter may overflow and eventually + * wrap back to its initial value, fooling the reader into accepting the + * snapshot. Given that this needs 4 billion transactional writes across a + * single contended reader, it is unlikely to ever happen. + */ + +/* A hack to get MPASS macro */ +#include + +#include + +static __inline bool +seq_in_modify(seq_t seqp) +{ + + return (seqp & 1); +} + +static __inline void +seq_write_begin(seq_t *seqp) +{ + + critical_enter(); + MPASS(!seq_in_modify(*seqp)); + *seqp += 1; + atomic_thread_fence_rel(); +} + +static __inline void +seq_write_end(seq_t *seqp) +{ + + atomic_store_rel_int(seqp, *seqp + 1); + MPASS(!seq_in_modify(*seqp)); + critical_exit(); +} + +static __inline seq_t +seq_load(const seq_t *seqp) +{ + seq_t ret; + + for (;;) { + ret = atomic_load_acq_int(__DECONST(seq_t *, seqp)); + if (seq_in_modify(ret)) { + cpu_spinwait(); + continue; + } + break; + } + + return (ret); +} + +static __inline seq_t +seq_consistent_nomb(const seq_t *seqp, seq_t oldseq) +{ + + return (*seqp == oldseq); +} + +static __inline seq_t +seq_consistent(const seq_t *seqp, seq_t oldseq) +{ + + atomic_thread_fence_acq(); + return (seq_consistent_nomb(seqp, oldseq)); +} + +#endif /* _KERNEL */ +#endif /* _SYS_SEQ_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/serial.h b/lib/libc/include/any-freebsd-any/sys/serial.h new file mode 100644 index 000000000000..3293ebdab931 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/serial.h @@ -0,0 +1,94 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file contains definitions which pertain to serial ports as such, + * (both async and sync), but which do not necessarily have anything to + * do with tty processing. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SERIAL_H_ +#define _SYS_SERIAL_H_ + + +/* + * Indentification of modem control signals. These definitions match + * the TIOCMGET definitions in shifted a bit down, and + * that identity is enforced with CTASSERT at the bottom of kern/tty.c + * Both the modem bits and delta bits must fit in 16 bit. + */ +#define SER_DTR 0x0001 /* data terminal ready */ +#define SER_RTS 0x0002 /* request to send */ +#define SER_STX 0x0004 /* secondary transmit */ +#define SER_SRX 0x0008 /* secondary receive */ +#define SER_CTS 0x0010 /* clear to send */ +#define SER_DCD 0x0020 /* data carrier detect */ +#define SER_RI 0x0040 /* ring indicate */ +#define SER_DSR 0x0080 /* data set ready */ + +#define SER_MASK_STATE 0x00ff + +/* Delta bits, used to indicate which signals should/was affected */ +#define SER_DELTA(x) ((x) << 8) + +#define SER_DDTR SER_DELTA(SER_DTR) +#define SER_DRTS SER_DELTA(SER_RTS) +#define SER_DSTX SER_DELTA(SER_STX) +#define SER_DSRX SER_DELTA(SER_SRX) +#define SER_DCTS SER_DELTA(SER_CTS) +#define SER_DDCD SER_DELTA(SER_DCD) +#define SER_DRI SER_DELTA(SER_RI) +#define SER_DDSR SER_DELTA(SER_DSR) + +#define SER_MASK_DELTA SER_DELTA(SER_MASK_STATE) + +#ifdef _KERNEL +/* + * Specification of interrupt sources typical for serial ports. These are + * useful when some umbrella driver like scc(4) has enough knowledge of + * the hardware to obtain the set of pending interrupts but does not itself + * handle the interrupt. Each interrupt source can be given an interrupt + * resource for which inferior drivers can install handlers. The lower 16 + * bits are kept free for the signals above. + */ +#define SER_INT_OVERRUN 0x010000 +#define SER_INT_BREAK 0x020000 +#define SER_INT_RXREADY 0x040000 +#define SER_INT_SIGCHG 0x080000 +#define SER_INT_TXIDLE 0x100000 + +#define SER_INT_MASK 0xff0000 +#define SER_INT_SIGMASK (SER_MASK_DELTA | SER_MASK_STATE) + +#ifndef LOCORE +typedef int serdev_intr_t(void*); +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_SERIAL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sf_buf.h b/lib/libc/include/any-freebsd-any/sys/sf_buf.h new file mode 100644 index 000000000000..b4ea671a2d23 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sf_buf.h @@ -0,0 +1,196 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 Gleb Smirnoff + * Copyright (c) 2003-2004 Alan L. Cox + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SF_BUF_H_ +#define _SYS_SF_BUF_H_ + +struct sfstat { /* sendfile statistics */ + uint64_t sf_syscalls; /* times sendfile was called */ + uint64_t sf_noiocnt; /* times sendfile didn't require I/O */ + uint64_t sf_iocnt; /* times sendfile had to do disk I/O */ + uint64_t sf_pages_read; /* pages read as part of a request */ + uint64_t sf_pages_valid; /* pages were valid for a request */ + uint64_t sf_rhpages_requested; /* readahead pages requested */ + uint64_t sf_rhpages_read; /* readahead pages read */ + uint64_t sf_busy; /* times aborted on a busy page */ + uint64_t sf_allocfail; /* times sfbuf allocation failed */ + uint64_t sf_allocwait; /* times sfbuf allocation had to wait */ + uint64_t sf_pages_bogus; /* times bogus page was used */ +}; + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#include + +/* + * Sf_bufs, or sendfile(2) buffers provide a vm_page that is mapped + * into kernel address space. Note, that they aren't used only + * by sendfile(2)! + * + * Sf_bufs could be implemented as a feature of vm_page_t, but that + * would require growth of the structure. That's why they are implemented + * as a separate hash indexed by vm_page address. Implementation lives in + * kern/subr_sfbuf.c. Meanwhile, most 64-bit machines have a physical map, + * so they don't require this hash at all, thus ignore subr_sfbuf.c. + * + * Different 32-bit architectures demand different requirements on sf_buf + * hash and functions. They request features in machine/vmparam.h, which + * enable parts of this file. They can also optionally provide helpers in + * machine/sf_buf.h + * + * Defines are: + * SFBUF This machine requires sf_buf hash. + * subr_sfbuf.c should be compiled. + * SFBUF_CPUSET This machine can perform SFB_CPUPRIVATE mappings, + * that do no invalidate cache on the rest of CPUs. + * SFBUF_NOMD This machine doesn't have machine/sf_buf.h + * + * SFBUF_MAP This machine provides its own sf_buf_map() and + * sf_buf_unmap(). + * SFBUF_PROCESS_PAGE This machine provides sf_buf_process_page() + * function. + */ + +#ifdef SFBUF +#if defined(SMP) && defined(SFBUF_CPUSET) +#include +#endif +#include + +struct sf_buf { + LIST_ENTRY(sf_buf) list_entry; /* list of buffers */ + TAILQ_ENTRY(sf_buf) free_entry; /* list of buffers */ + vm_page_t m; /* currently mapped page */ + vm_offset_t kva; /* va of mapping */ + int ref_count; /* usage of this mapping */ +#if defined(SMP) && defined(SFBUF_CPUSET) + cpuset_t cpumask; /* where mapping is valid */ +#endif +}; +#else /* ! SFBUF */ +struct sf_buf; +#endif /* SFBUF */ + +#ifndef SFBUF_NOMD +#include +#endif + +#ifdef SFBUF +struct sf_buf *sf_buf_alloc(struct vm_page *, int); +void sf_buf_free(struct sf_buf *); +void sf_buf_ref(struct sf_buf *); + +static inline vm_offset_t +sf_buf_kva(struct sf_buf *sf) +{ + if (PMAP_HAS_DMAP) + return (PHYS_TO_DMAP(VM_PAGE_TO_PHYS((vm_page_t)sf))); + + return (sf->kva); +} + +static inline vm_page_t +sf_buf_page(struct sf_buf *sf) +{ + if (PMAP_HAS_DMAP) + return ((vm_page_t)sf); + + return (sf->m); +} + +#ifndef SFBUF_MAP +#include + +static inline void +sf_buf_map(struct sf_buf *sf, int flags) +{ + + pmap_qenter(sf->kva, &sf->m, 1); +} + +static inline int +sf_buf_unmap(struct sf_buf *sf) +{ + + return (0); +} +#endif /* SFBUF_MAP */ + +#if defined(SMP) && defined(SFBUF_CPUSET) +void sf_buf_shootdown(struct sf_buf *, int); +#endif + +#ifdef SFBUF_PROCESS_PAGE +boolean_t sf_buf_process_page(vm_page_t, void (*)(struct sf_buf *)); +#endif + +#else /* ! SFBUF */ + +static inline struct sf_buf * +sf_buf_alloc(struct vm_page *m, int pri) +{ + + return ((struct sf_buf *)m); +} + +static inline void +sf_buf_free(struct sf_buf *sf) +{ +} + +static inline void +sf_buf_ref(struct sf_buf *sf) +{ +} +#endif /* SFBUF */ + +/* + * Options to sf_buf_alloc() are specified through its flags argument. This + * argument's value should be the result of a bitwise or'ing of one or more + * of the following values. + */ +#define SFB_CATCH 1 /* Check signals if the allocation + sleeps. */ +#define SFB_CPUPRIVATE 2 /* Create a CPU private mapping. */ +#define SFB_DEFAULT 0 +#define SFB_NOWAIT 4 /* Return NULL if all bufs are used. */ + +extern counter_u64_t sfstat[sizeof(struct sfstat) / sizeof(uint64_t)]; +#define SFSTAT_ADD(name, val) \ + counter_u64_add(sfstat[offsetof(struct sfstat, name) / sizeof(uint64_t)],\ + (val)) +#define SFSTAT_INC(name) SFSTAT_ADD(name, 1) +#endif /* _KERNEL */ +#endif /* !_SYS_SF_BUF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sglist.h b/lib/libc/include/any-freebsd-any/sys/sglist.h new file mode 100644 index 000000000000..5674416c07af --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sglist.h @@ -0,0 +1,113 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2008 Yahoo!, Inc. + * All rights reserved. + * Written by: John Baldwin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * A scatter/gather list describes a group of physical address ranges. + * Each physical address range consists of a starting address and a + * length. + */ + +#ifndef __SGLIST_H__ +#define __SGLIST_H__ + +#include + +struct sglist_seg { + vm_paddr_t ss_paddr; + size_t ss_len; +}; + +struct sglist { + struct sglist_seg *sg_segs; + u_int sg_refs; + u_short sg_nseg; + u_short sg_maxseg; +}; + +struct bio; +struct mbuf; +struct uio; + +static __inline void +sglist_init(struct sglist *sg, u_short maxsegs, struct sglist_seg *segs) +{ + + sg->sg_segs = segs; + sg->sg_nseg = 0; + sg->sg_maxseg = maxsegs; + refcount_init(&sg->sg_refs, 1); +} + +static __inline void +sglist_reset(struct sglist *sg) +{ + + sg->sg_nseg = 0; +} + +static __inline struct sglist * +sglist_hold(struct sglist *sg) +{ + + refcount_acquire(&sg->sg_refs); + return (sg); +} + +struct sglist *sglist_alloc(int nsegs, int mflags); +int sglist_append(struct sglist *sg, void *buf, size_t len); +int sglist_append_bio(struct sglist *sg, struct bio *bp); +int sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); +int sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, + size_t len); +int sglist_append_sglist(struct sglist *sg, struct sglist *source, + size_t offset, size_t length); +int sglist_append_uio(struct sglist *sg, struct uio *uio); +int sglist_append_user(struct sglist *sg, void *buf, size_t len, + struct thread *td); +int sglist_append_vmpages(struct sglist *sg, vm_page_t *m, size_t pgoff, + size_t len); +struct sglist *sglist_build(void *buf, size_t len, int mflags); +struct sglist *sglist_clone(struct sglist *sg, int mflags); +int sglist_consume_uio(struct sglist *sg, struct uio *uio, size_t resid); +int sglist_count(void *buf, size_t len); +int sglist_count_vmpages(vm_page_t *m, size_t pgoff, size_t len); +void sglist_free(struct sglist *sg); +int sglist_join(struct sglist *first, struct sglist *second); +size_t sglist_length(struct sglist *sg); +int sglist_slice(struct sglist *original, struct sglist **slice, + size_t offset, size_t length, int mflags); +int sglist_split(struct sglist *original, struct sglist **head, + size_t length, int mflags); + +#endif /* !__SGLIST_H__ */ diff --git a/lib/libc/include/any-freebsd-any/sys/shm.h b/lib/libc/include/any-freebsd-any/sys/shm.h new file mode 100644 index 000000000000..07eff28b7a50 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/shm.h @@ -0,0 +1,180 @@ +/* $FreeBSD$ */ +/* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1994 Adam Glass + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Adam Glass. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * As defined+described in "X/Open System Interfaces and Headers" + * Issue 4, p. XXX + */ + +#ifndef _SYS_SHM_H_ +#define _SYS_SHM_H_ + +#include +#ifdef _WANT_SYSVSHM_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif +#include +#include + +#include + +#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ +#define SHM_RND 020000 /* Round attach address to SHMLBA */ +#define SHM_REMAP 030000 /* Unmap before mapping */ +#define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ + +/* "official" access mode definitions; somewhat braindead since you have + to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ +#define SHM_R (IPC_R) +#define SHM_W (IPC_W) + +/* predefine tbd *LOCK shmctl commands */ +#define SHM_LOCK 11 +#define SHM_UNLOCK 12 + +/* ipcs shmctl commands for Linux compatibility */ +#define SHM_STAT 13 +#define SHM_INFO 14 + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ + defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) +struct shmid_ds_old { + struct ipc_perm_old shm_perm; /* operation permission structure */ + int shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shared memory op */ + pid_t shm_cpid; /* process ID of creator */ + short shm_nattch; /* number of current attaches */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ + void *shm_internal; /* sysv stupidity */ +}; +#endif + +typedef unsigned int shmatt_t; + +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permission structure */ + size_t shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shared memory op */ + pid_t shm_cpid; /* process ID of creator */ + shmatt_t shm_nattch; /* number of current attaches */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ +}; + +#if defined(_KERNEL) || defined(_WANT_SYSVSHM_INTERNALS) +/* + * System 5 style catch-all structure for shared memory constants that + * might be of interest to user programs. Do we really want/need this? + */ +struct shminfo { + u_long shmmax; /* max shared memory segment size (bytes) */ + u_long shmmin; /* max shared memory segment size (bytes) */ + u_long shmmni; /* max number of shared memory identifiers */ + u_long shmseg; /* max shared memory segments per process */ + u_long shmall; /* max amount of shared memory (pages) */ +}; + +struct vm_object; + +/* + * Add a kernel wrapper to the shmid_ds struct so that private info (like the + * MAC label) can be added to it, without changing the user interface. + */ +struct shmid_kernel { + struct shmid_ds u; + struct vm_object *object; + struct label *label; /* MAC label */ + struct ucred *cred; /* creator's credendials */ +}; +#endif + +struct shm_info { + int used_ids; + unsigned long shm_tot; + unsigned long shm_rss; + unsigned long shm_swp; + unsigned long swap_attempts; + unsigned long swap_successes; +}; + +#ifdef _KERNEL +struct proc; +struct vmspace; + +extern struct shminfo shminfo; + +void shmexit(struct vmspace *); +void shmfork(struct proc *, struct proc *); + +#else /* !_KERNEL */ + +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +#if __BSD_VISIBLE +int shmsys(int, ...); +#endif +void *shmat(int, const void *, int); +int shmget(key_t, size_t, int); +int shmctl(int, int, struct shmid_ds *); +int shmdt(const void *); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_SHM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sigio.h b/lib/libc/include/any-freebsd-any/sys/sigio.h new file mode 100644 index 000000000000..0a4369e07056 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sigio.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_SIGIO_H_ +#define _SYS_SIGIO_H_ + +/* + * This structure holds the information needed to send a SIGIO or + * a SIGURG signal to a process or process group when new data arrives + * on a device or socket. The structure is placed on an SLIST belonging + * to the proc or pgrp so that the entire list may be revoked when the + * process exits or the process group disappears. + * + * (c) const + * (pg) locked by either the process or process group lock + */ +struct sigio { + union { + struct proc *siu_proc; /* (c) process to receive SIGIO/SIGURG */ + struct pgrp *siu_pgrp; /* (c) process group to receive ... */ + } sio_u; + SLIST_ENTRY(sigio) sio_pgsigio; /* (pg) sigio's for process or group */ + struct sigio **sio_myref; /* (c) location of the pointer that holds + * the reference to this structure */ + struct ucred *sio_ucred; /* (c) current credentials */ + pid_t sio_pgid; /* (c) pgid for signals */ +}; +#define sio_proc sio_u.siu_proc +#define sio_pgrp sio_u.siu_pgrp + +SLIST_HEAD(sigiolst, sigio); + +pid_t fgetown(struct sigio **sigiop); +int fsetown(pid_t pgid, struct sigio **sigiop); +void funsetown(struct sigio **sigiop); +void funsetownlst(struct sigiolst *sigiolst); + +#endif /* _SYS_SIGIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/signal.h b/lib/libc/include/any-freebsd-any/sys/signal.h new file mode 100644 index 000000000000..8b45a521c3ee --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/signal.h @@ -0,0 +1,514 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + * $FreeBSD$ + */ + +#ifndef _SYS_SIGNAL_H_ +#define _SYS_SIGNAL_H_ + +#include +#include +#include + +#include /* __MINSIGSTKSZ */ +#include /* sig_atomic_t; trap codes; sigcontext */ + +#if __POSIX_VISIBLE >= 200809 + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#endif /* __POSIX_VISIBLE >= 200809 */ + +/* + * System defined signals. + */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGHUP 1 /* hangup */ +#endif +#define SIGINT 2 /* interrupt */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGQUIT 3 /* quit */ +#endif +#define SIGILL 4 /* illegal instr. (not reset when caught) */ +#if __XSI_VISIBLE +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#endif +#define SIGABRT 6 /* abort() */ +#if __BSD_VISIBLE +#define SIGIOT SIGABRT /* compatibility */ +#define SIGEMT 7 /* EMT instruction */ +#endif +#define SIGFPE 8 /* floating point exception */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#endif +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIGBUS 10 /* bus error */ +#endif +#define SIGSEGV 11 /* segmentation violation */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIGSYS 12 /* non-existent system call invoked */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#endif +#define SIGTERM 15 /* software termination signal from kill */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIGURG 16 /* urgent condition on IO channel */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN if (tp->t_local<OSTOP) */ +#endif +#if __BSD_VISIBLE +#define SIGIO 23 /* input/output possible signal */ +#endif +#if __XSI_VISIBLE +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#endif +#if __BSD_VISIBLE +#define SIGWINCH 28 /* window size changes */ +#define SIGINFO 29 /* information request */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#endif +#if __BSD_VISIBLE +#define SIGTHR 32 /* reserved by thread library. */ +#define SIGLWP SIGTHR +#define SIGLIBRT 33 /* reserved by real-time library. */ +#endif + +#define SIGRTMIN 65 +#define SIGRTMAX 126 + +#define SIG_DFL ((__sighandler_t *)0) +#define SIG_IGN ((__sighandler_t *)1) +#define SIG_ERR ((__sighandler_t *)-1) +/* #define SIG_CATCH ((__sighandler_t *)2) See signalvar.h */ +#define SIG_HOLD ((__sighandler_t *)3) + +/* + * Type of a signal handling function. + * + * Language spec sez signal handlers take exactly one arg, even though we + * actually supply three. Ugh! + * + * We don't try to hide the difference by leaving out the args because + * that would cause warnings about conformant programs. Nonconformant + * programs can avoid the warnings by casting to (__sighandler_t *) or + * sig_t before calling signal() or assigning to sa_handler or sv_handler. + * + * The kernel should reverse the cast before calling the function. It + * has no way to do this, but on most machines 1-arg and 3-arg functions + * have the same calling protocol so there is no problem in practice. + * A bit in sa_flags could be used to specify the number of args. + */ +typedef void __sighandler_t(int); + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif +#endif + +#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE >= 500 +union sigval { + /* Members as suggested by Annex C of POSIX 1003.1b. */ + int sival_int; + void *sival_ptr; + /* 6.0 compatibility */ + int sigval_int; + void *sigval_ptr; +}; + +#if defined(_WANT_LWPINFO32) || (defined(_KERNEL) && defined(__LP64__)) +union sigval32 { + int sival_int; + uint32_t sival_ptr; + /* 6.0 compatibility */ + int sigval_int; + uint32_t sigval_ptr; +}; +#endif +#endif + +#if __POSIX_VISIBLE >= 199309 + +struct pthread_attr; + +struct sigevent { + int sigev_notify; /* Notification type */ + int sigev_signo; /* Signal number */ + union sigval sigev_value; /* Signal value */ + union { + __lwpid_t _threadid; + struct { + void (*_function)(union sigval); + struct pthread_attr **_attribute; + } _sigev_thread; + unsigned short _kevent_flags; + long __spare__[8]; + } _sigev_un; +}; + +#if __BSD_VISIBLE +#define sigev_notify_kqueue sigev_signo +#define sigev_notify_kevent_flags _sigev_un._kevent_flags +#define sigev_notify_thread_id _sigev_un._threadid +#endif +#define sigev_notify_function _sigev_un._sigev_thread._function +#define sigev_notify_attributes _sigev_un._sigev_thread._attribute + +#define SIGEV_NONE 0 /* No async notification. */ +#define SIGEV_SIGNAL 1 /* Generate a queued signal. */ +#define SIGEV_THREAD 2 /* Call back from another pthread. */ +#if __BSD_VISIBLE +#define SIGEV_KEVENT 3 /* Generate a kevent. */ +#define SIGEV_THREAD_ID 4 /* Send signal to a kernel thread. */ +#endif + +#endif /* __POSIX_VISIBLE >= 199309 */ + +#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE +typedef struct __siginfo { + int si_signo; /* signal number */ + int si_errno; /* errno association */ + /* + * Cause of signal, one of the SI_ macros or signal-specific + * values, i.e. one of the FPE_... values for SIGFPE. This + * value is equivalent to the second argument to an old-style + * FreeBSD signal handler. + */ + int si_code; /* signal code */ + __pid_t si_pid; /* sending process */ + __uid_t si_uid; /* sender's ruid */ + int si_status; /* exit value */ + void *si_addr; /* faulting instruction */ + union sigval si_value; /* signal value */ + union { + struct { + int _trapno;/* machine specific trap code */ + } _fault; + struct { + int _timerid; + int _overrun; + } _timer; + struct { + int _mqd; + } _mesgq; + struct { + long _band; /* band event for SIGPOLL */ + } _poll; /* was this ever used ? */ + struct { + long __spare1__; + int __spare2__[7]; + } __spare__; + } _reason; +} siginfo_t; + +#define si_trapno _reason._fault._trapno +#define si_timerid _reason._timer._timerid +#define si_overrun _reason._timer._overrun +#define si_mqd _reason._mesgq._mqd +#define si_band _reason._poll._band + +#if defined(_WANT_LWPINFO32) || (defined(_KERNEL) && defined(__LP64__)) +struct siginfo32 { + int si_signo; /* signal number */ + int si_errno; /* errno association */ + int si_code; /* signal code */ + __pid_t si_pid; /* sending process */ + __uid_t si_uid; /* sender's ruid */ + int si_status; /* exit value */ + uint32_t si_addr; /* faulting instruction */ + union sigval32 si_value; /* signal value */ + union { + struct { + int _trapno;/* machine specific trap code */ + } _fault; + struct { + int _timerid; + int _overrun; + } _timer; + struct { + int _mqd; + } _mesgq; + struct { + int32_t _band; /* band event for SIGPOLL */ + } _poll; /* was this ever used ? */ + struct { + int32_t __spare1__; + int __spare2__[7]; + } __spare__; + } _reason; +}; +#endif + +/** si_code **/ +/* codes for SIGILL */ +#define ILL_ILLOPC 1 /* Illegal opcode. */ +#define ILL_ILLOPN 2 /* Illegal operand. */ +#define ILL_ILLADR 3 /* Illegal addressing mode. */ +#define ILL_ILLTRP 4 /* Illegal trap. */ +#define ILL_PRVOPC 5 /* Privileged opcode. */ +#define ILL_PRVREG 6 /* Privileged register. */ +#define ILL_COPROC 7 /* Coprocessor error. */ +#define ILL_BADSTK 8 /* Internal stack error. */ + +/* codes for SIGBUS */ +#define BUS_ADRALN 1 /* Invalid address alignment. */ +#define BUS_ADRERR 2 /* Nonexistent physical address. */ +#define BUS_OBJERR 3 /* Object-specific hardware error. */ +#define BUS_OOMERR 100 /* Non-standard: No memory. */ + +/* codes for SIGSEGV */ +#define SEGV_MAPERR 1 /* Address not mapped to object. */ +#define SEGV_ACCERR 2 /* Invalid permissions for mapped */ + /* object. */ +#define SEGV_PKUERR 100 /* x86: PKU violation */ + +/* codes for SIGFPE */ +#define FPE_INTOVF 1 /* Integer overflow. */ +#define FPE_INTDIV 2 /* Integer divide by zero. */ +#define FPE_FLTDIV 3 /* Floating point divide by zero. */ +#define FPE_FLTOVF 4 /* Floating point overflow. */ +#define FPE_FLTUND 5 /* Floating point underflow. */ +#define FPE_FLTRES 6 /* Floating point inexact result. */ +#define FPE_FLTINV 7 /* Invalid floating point operation. */ +#define FPE_FLTSUB 8 /* Subscript out of range. */ + +/* codes for SIGTRAP */ +#define TRAP_BRKPT 1 /* Process breakpoint. */ +#define TRAP_TRACE 2 /* Process trace trap. */ +#define TRAP_DTRACE 3 /* DTrace induced trap. */ +#define TRAP_CAP 4 /* Capabilities protective trap. */ + +/* codes for SIGCHLD */ +#define CLD_EXITED 1 /* Child has exited */ +#define CLD_KILLED 2 /* Child has terminated abnormally but */ + /* did not create a core file */ +#define CLD_DUMPED 3 /* Child has terminated abnormally and */ + /* created a core file */ +#define CLD_TRAPPED 4 /* Traced child has trapped */ +#define CLD_STOPPED 5 /* Child has stopped */ +#define CLD_CONTINUED 6 /* Stopped child has continued */ + +/* codes for SIGPOLL */ +#define POLL_IN 1 /* Data input available */ +#define POLL_OUT 2 /* Output buffers available */ +#define POLL_MSG 3 /* Input message available */ +#define POLL_ERR 4 /* I/O Error */ +#define POLL_PRI 5 /* High priority input available */ +#define POLL_HUP 6 /* Device disconnected */ + +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +struct __siginfo; + +/* + * Signal vector "template" used in sigaction call. + */ +struct sigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, struct __siginfo *, void *); + } __sigaction_u; /* signal handler */ + int sa_flags; /* see signal options below */ + sigset_t sa_mask; /* signal mask to apply */ +}; + +#define sa_handler __sigaction_u.__sa_handler +#endif + +#if __XSI_VISIBLE +/* If SA_SIGINFO is set, sa_sigaction must be used instead of sa_handler. */ +#define sa_sigaction __sigaction_u.__sa_sigaction +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ +#endif /* __POSIX_VISIBLE || __XSI_VISIBLE */ + +#if __XSI_VISIBLE +#define SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define SA_RESTART 0x0002 /* restart system call on signal return */ +#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ +#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ +#define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */ +#define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */ +#endif + +#if __BSD_VISIBLE +#define NSIG 32 /* number of old signals (counting 0) */ +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SI_NOINFO 0 /* No signal info besides si_signo. */ +#define SI_USER 0x10001 /* Signal sent by kill(). */ +#define SI_QUEUE 0x10002 /* Signal sent by the sigqueue(). */ +#define SI_TIMER 0x10003 /* Signal generated by expiration of */ + /* a timer set by timer_settime(). */ +#define SI_ASYNCIO 0x10004 /* Signal generated by completion of */ + /* an asynchronous I/O request.*/ +#define SI_MESGQ 0x10005 /* Signal generated by arrival of a */ + /* message on an empty message queue. */ +#define SI_KERNEL 0x10006 +#define SI_LWP 0x10007 /* Signal sent by thr_kill */ +#endif +#if __BSD_VISIBLE +#define SI_UNDEFINED 0 +#endif + +#if __BSD_VISIBLE +typedef __sighandler_t *sig_t; /* type of pointer to a signal function */ +typedef void __siginfohandler_t(int, struct __siginfo *, void *); +#endif + +#if __XSI_VISIBLE +#if __BSD_VISIBLE +#define __stack_t sigaltstack +#endif +typedef struct __stack_t stack_t; + +#define SS_ONSTACK 0x0001 /* take signal on alternate stack */ +#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ +#define MINSIGSTKSZ __MINSIGSTKSZ /* minimum stack size */ +#define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ +#endif + +/* + * Structure used in sigaltstack call. Its definition is always + * needed for __ucontext. If __BSD_VISIBLE is defined, the structure + * tag is actually sigaltstack. + */ +struct __stack_t { + void *ss_sp; /* signal stack base */ + __size_t ss_size; /* signal stack length */ + int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ +}; + +#if __BSD_VISIBLE +/* + * 4.3 compatibility: + * Signal vector "template" used in sigvec call. + */ +struct sigvec { + __sighandler_t *sv_handler; /* signal handler */ + int sv_mask; /* signal mask to apply */ + int sv_flags; /* see signal options below */ +}; + +#define SV_ONSTACK SA_ONSTACK +#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ +#define SV_RESETHAND SA_RESETHAND +#define SV_NODEFER SA_NODEFER +#define SV_NOCLDSTOP SA_NOCLDSTOP +#define SV_SIGINFO SA_SIGINFO +#define sv_onstack sv_flags /* isn't compatibility wonderful! */ +#endif + +/* Keep this in one place only */ +#if defined(_KERNEL) && defined(COMPAT_43) && \ + !defined(__i386__) +struct osigcontext { + int _not_used; +}; +#endif + +#if __XSI_VISIBLE +/* + * Structure used in sigstack call. + */ +struct sigstack { + void *ss_sp; /* signal stack pointer */ + int ss_onstack; /* current status */ +}; +#endif + +#if __BSD_VISIBLE || __POSIX_VISIBLE > 0 && __POSIX_VISIBLE <= 200112 +/* + * Macro for converting signal number to a mask suitable for + * sigblock(). + */ +#define sigmask(m) (1 << ((m)-1)) +#endif + +#if __BSD_VISIBLE +#define BADSIG SIG_ERR +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +/* + * Flags for sigprocmask: + */ +#define SIG_BLOCK 1 /* block specified signal set */ +#define SIG_UNBLOCK 2 /* unblock specified signal set */ +#define SIG_SETMASK 3 /* set specified signal set */ +#endif + +/* + * For historical reasons; programs expect signal's return value to be + * defined by . + */ +__BEGIN_DECLS +__sighandler_t *signal(int, __sighandler_t *); +__END_DECLS + +#endif /* !_SYS_SIGNAL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/signalvar.h b/lib/libc/include/any-freebsd-any/sys/signalvar.h new file mode 100644 index 000000000000..ed82ff123209 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/signalvar.h @@ -0,0 +1,404 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 + * $FreeBSD$ + */ + +#ifndef _SYS_SIGNALVAR_H_ +#define _SYS_SIGNALVAR_H_ + +#include +#include +#include +#include + +/* + * Kernel signal definitions and data structures. + */ + +/* + * Logical process signal actions and state, needed only within the process + * The mapping between sigacts and proc structures is 1:1 except for rfork() + * processes masquerading as threads which use one structure for the whole + * group. All members are locked by the included mutex. The reference count + * and mutex must be last for the bcopy in sigacts_copy() to work. + */ +struct sigacts { + sig_t ps_sigact[_SIG_MAXSIG]; /* Disposition of signals. */ + sigset_t ps_catchmask[_SIG_MAXSIG]; /* Signals to be blocked. */ + sigset_t ps_sigonstack; /* Signals to take on sigstack. */ + sigset_t ps_sigintr; /* Signals that interrupt syscalls. */ + sigset_t ps_sigreset; /* Signals that reset when caught. */ + sigset_t ps_signodefer; /* Signals not masked while handled. */ + sigset_t ps_siginfo; /* Signals that want SA_SIGINFO args. */ + sigset_t ps_sigignore; /* Signals being ignored. */ + sigset_t ps_sigcatch; /* Signals being caught by user. */ + sigset_t ps_freebsd4; /* Signals using freebsd4 ucontext. */ + sigset_t ps_osigset; /* Signals using <= 3.x osigset_t. */ + sigset_t ps_usertramp; /* SunOS compat; libc sigtramp. XXX */ + int ps_flag; + u_int ps_refcnt; + struct mtx ps_mtx; +}; + +#define PS_NOCLDWAIT 0x0001 /* No zombies if child dies */ +#define PS_NOCLDSTOP 0x0002 /* No SIGCHLD when children stop. */ +#define PS_CLDSIGIGN 0x0004 /* The SIGCHLD handler is SIG_IGN. */ + +#ifdef _KERNEL + +#ifdef COMPAT_43 +typedef struct { + struct osigcontext si_sc; + int si_signo; + int si_code; + union sigval si_value; +} osiginfo_t; + +struct osigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, osiginfo_t *, void *); + } __sigaction_u; /* signal handler */ + osigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; + +typedef void __osiginfohandler_t(int, osiginfo_t *, void *); +#endif /* COMPAT_43 */ + +/* additional signal action values, used only temporarily/internally */ +#define SIG_CATCH ((__sighandler_t *)2) +/* #define SIG_HOLD ((__sighandler_t *)3) See signal.h */ + +/* + * get signal action for process and signal; currently only for current process + */ +#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) + +#endif /* _KERNEL */ + +/* + * sigset_t manipulation macros. + */ +#define SIGADDSET(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)) + +#define SIGDELSET(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)) + +#define SIGEMPTYSET(set) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set).__bits[__i] = 0; \ + } while (0) + +#define SIGFILLSET(set) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set).__bits[__i] = ~0U; \ + } while (0) + +#define SIGISMEMBER(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) + +#define SIGISEMPTY(set) (__sigisempty(&(set))) +#define SIGNOTEMPTY(set) (!__sigisempty(&(set))) + +#define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2))) +#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) + +#define SIGSETOR(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] |= (set2).__bits[__i]; \ + } while (0) + +#define SIGSETAND(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] &= (set2).__bits[__i]; \ + } while (0) + +#define SIGSETNAND(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] &= ~(set2).__bits[__i]; \ + } while (0) + +#define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) +#define SIGSETOLD(set, oset) ((set).__bits[0] = (oset)) + +#define SIG_CANTMASK(set) \ + SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) + +#define SIG_STOPSIGMASK(set) \ + SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ + SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) + +#define SIG_CONTSIGMASK(set) \ + SIGDELSET(set, SIGCONT) + +#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) + +#define SIG2OSIG(sig, osig) (osig = (sig).__bits[0]) +#define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig + +static __inline int +__sigisempty(sigset_t *set) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set->__bits[i]) + return (0); + } + return (1); +} + +static __inline int +__sigseteq(sigset_t *set1, sigset_t *set2) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set1->__bits[i] != set2->__bits[i]) + return (0); + } + return (1); +} + +#ifdef COMPAT_FREEBSD6 +struct osigevent { + int sigev_notify; /* Notification type */ + union { + int __sigev_signo; /* Signal number */ + int __sigev_notify_kqueue; + } __sigev_u; + union sigval sigev_value; /* Signal value */ +}; +#endif + +typedef struct ksiginfo { + TAILQ_ENTRY(ksiginfo) ksi_link; + siginfo_t ksi_info; + int ksi_flags; + struct sigqueue *ksi_sigq; +} ksiginfo_t; + +#define ksi_signo ksi_info.si_signo +#define ksi_errno ksi_info.si_errno +#define ksi_code ksi_info.si_code +#define ksi_pid ksi_info.si_pid +#define ksi_uid ksi_info.si_uid +#define ksi_status ksi_info.si_status +#define ksi_addr ksi_info.si_addr +#define ksi_value ksi_info.si_value +#define ksi_band ksi_info.si_band +#define ksi_trapno ksi_info.si_trapno +#define ksi_overrun ksi_info.si_overrun +#define ksi_timerid ksi_info.si_timerid +#define ksi_mqd ksi_info.si_mqd + +/* bits for ksi_flags */ +#define KSI_TRAP 0x01 /* Generated by trap. */ +#define KSI_EXT 0x02 /* Externally managed ksi. */ +#define KSI_INS 0x04 /* Directly insert ksi, not the copy */ +#define KSI_SIGQ 0x08 /* Generated by sigqueue, might ret EAGAIN. */ +#define KSI_HEAD 0x10 /* Insert into head, not tail. */ +#define KSI_PTRACE 0x20 /* Generated by ptrace. */ +#define KSI_COPYMASK (KSI_TRAP | KSI_SIGQ | KSI_PTRACE) + +#define KSI_ONQ(ksi) ((ksi)->ksi_sigq != NULL) + +typedef struct sigqueue { + sigset_t sq_signals; /* All pending signals. */ + sigset_t sq_kill; /* Legacy depth 1 queue. */ + sigset_t sq_ptrace; /* Depth 1 queue for ptrace(2). */ + TAILQ_HEAD(, ksiginfo) sq_list;/* Queued signal info. */ + struct proc *sq_proc; + int sq_flags; +} sigqueue_t; + +/* Flags for ksi_flags */ +#define SQ_INIT 0x01 + +#ifdef _KERNEL + +/* Return nonzero if process p has an unmasked pending signal. */ +#define SIGPENDING(td) \ + ((!SIGISEMPTY((td)->td_siglist) && \ + !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask)) || \ + (!SIGISEMPTY((td)->td_proc->p_siglist) && \ + !sigsetmasked(&(td)->td_proc->p_siglist, &(td)->td_sigmask))) +/* + * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This + * is an optimized version of SIGISEMPTY() on a temporary variable + * containing SIGSETNAND(*set, *mask). + */ +static __inline int +sigsetmasked(sigset_t *set, sigset_t *mask) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set->__bits[i] & ~mask->__bits[i]) + return (0); + } + return (1); +} + +#define ksiginfo_init(ksi) \ +do { \ + bzero(ksi, sizeof(ksiginfo_t)); \ +} while(0) + +#define ksiginfo_init_trap(ksi) \ +do { \ + ksiginfo_t *kp = ksi; \ + bzero(kp, sizeof(ksiginfo_t)); \ + kp->ksi_flags |= KSI_TRAP; \ +} while(0) + +static __inline void +ksiginfo_copy(ksiginfo_t *src, ksiginfo_t *dst) +{ + (dst)->ksi_info = src->ksi_info; + (dst)->ksi_flags = (src->ksi_flags & KSI_COPYMASK); +} + +static __inline void +ksiginfo_set_sigev(ksiginfo_t *dst, struct sigevent *sigev) +{ + dst->ksi_signo = sigev->sigev_signo; + dst->ksi_value = sigev->sigev_value; +} + +struct pgrp; +struct proc; +struct sigio; +struct thread; + +/* + * Lock the pointers for a sigio object in the underlying objects of + * a file descriptor. + */ +#define SIGIO_LOCK() mtx_lock(&sigio_lock) +#define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock) +#define SIGIO_UNLOCK() mtx_unlock(&sigio_lock) +#define SIGIO_LOCKED() mtx_owned(&sigio_lock) +#define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type) + +extern struct mtx sigio_lock; + +/* Flags for kern_sigprocmask(). */ +#define SIGPROCMASK_OLD 0x0001 +#define SIGPROCMASK_PROC_LOCKED 0x0002 +#define SIGPROCMASK_PS_LOCKED 0x0004 + +/* + * Modes for sigdeferstop(). Manages behaviour of + * thread_suspend_check() in the region delimited by + * sigdeferstop()/sigallowstop(). Must be restored to + * SIGDEFERSTOP_OFF before returning to userspace. + */ +#define SIGDEFERSTOP_NOP 0 /* continue doing whatever is done now */ +#define SIGDEFERSTOP_OFF 1 /* stop ignoring STOPs */ +#define SIGDEFERSTOP_SILENT 2 /* silently ignore STOPs */ +#define SIGDEFERSTOP_EINTR 3 /* ignore STOPs, return EINTR */ +#define SIGDEFERSTOP_ERESTART 4 /* ignore STOPs, return ERESTART */ + +#define SIGDEFERSTOP_VAL_NCHG (-1) /* placeholder indicating no state change */ +int sigdeferstop_impl(int mode); +void sigallowstop_impl(int prev); + +static inline int +sigdeferstop(int mode) +{ + + if (__predict_true(mode == SIGDEFERSTOP_NOP)) + return (SIGDEFERSTOP_VAL_NCHG); + return (sigdeferstop_impl(mode)); +} + +static inline void +sigallowstop(int prev) +{ + + if (__predict_true(prev == SIGDEFERSTOP_VAL_NCHG)) + return; + sigallowstop_impl(prev); +} + +int cursig(struct thread *td); +void execsigs(struct proc *p); +void gsignal(int pgid, int sig, ksiginfo_t *ksi); +void killproc(struct proc *p, char *why); +ksiginfo_t * ksiginfo_alloc(int wait); +void ksiginfo_free(ksiginfo_t *ksi); +int pksignal(struct proc *p, int sig, ksiginfo_t *ksi); +void pgsigio(struct sigio **sigiop, int sig, int checkctty); +void pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi); +int postsig(int sig); +void kern_psignal(struct proc *p, int sig); +int ptracestop(struct thread *td, int sig, ksiginfo_t *si); +void sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *retmask); +struct sigacts *sigacts_alloc(void); +void sigacts_copy(struct sigacts *dest, struct sigacts *src); +void sigacts_free(struct sigacts *ps); +struct sigacts *sigacts_hold(struct sigacts *ps); +int sigacts_shared(struct sigacts *ps); +void sig_drop_caught(struct proc *p); +void sigexit(struct thread *td, int sig) __dead2; +int sigev_findtd(struct proc *p, struct sigevent *sigev, struct thread **); +int sig_ffs(sigset_t *set); +void siginit(struct proc *p); +void signotify(struct thread *td); +void sigqueue_delete(struct sigqueue *queue, int sig); +void sigqueue_delete_proc(struct proc *p, int sig); +void sigqueue_flush(struct sigqueue *queue); +void sigqueue_init(struct sigqueue *queue, struct proc *p); +void sigqueue_take(ksiginfo_t *ksi); +void tdksignal(struct thread *td, int sig, ksiginfo_t *ksi); +int tdsendsignal(struct proc *p, struct thread *td, int sig, + ksiginfo_t *ksi); +void tdsigcleanup(struct thread *td); +void tdsignal(struct thread *td, int sig); +void trapsignal(struct thread *td, ksiginfo_t *ksi); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SIGNALVAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sleepqueue.h b/lib/libc/include/any-freebsd-any/sys/sleepqueue.h new file mode 100644 index 000000000000..fa16e414be27 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sleepqueue.h @@ -0,0 +1,123 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SLEEPQUEUE_H_ +#define _SYS_SLEEPQUEUE_H_ + +/* + * Sleep queue interface. Sleep/wakeup, condition variables, and sx + * locks use a sleep queue for the queue of threads blocked on a sleep + * channel. + * + * A thread calls sleepq_lock() to lock the sleep queue chain associated + * with a given wait channel. A thread can then call call sleepq_add() to + * add themself onto a sleep queue and call one of the sleepq_wait() + * functions to actually go to sleep. If a thread needs to abort a sleep + * operation it should call sleepq_release() to unlock the associated sleep + * queue chain lock. If the thread also needs to remove itself from a queue + * it just enqueued itself on, it can use sleepq_remove() instead. + * + * If the thread only wishes to sleep for a limited amount of time, it can + * call sleepq_set_timeout() after sleepq_add() to setup a timeout. It + * should then use one of the sleepq_timedwait() functions to block. + * + * A thread is normally resumed from a sleep queue by either the + * sleepq_signal() or sleepq_broadcast() functions. Sleepq_signal() wakes + * the thread with the highest priority that is sleeping on the specified + * wait channel. Sleepq_broadcast() wakes all threads that are sleeping + * on the specified wait channel. A thread sleeping in an interruptible + * sleep can be interrupted by calling sleepq_abort(). A thread can also + * be removed from a specified sleep queue using the sleepq_remove() + * function. Note that the sleep queue chain must first be locked via + * sleepq_lock() before calling sleepq_abort(), sleepq_broadcast(), or + * sleepq_signal(). These routines each return a boolean that will be true + * if at least one swapped-out thread was resumed. In that case, the caller + * is responsible for waking up the swapper by calling kick_proc0() after + * releasing the sleep queue chain lock. + * + * Each thread allocates a sleep queue at thread creation via sleepq_alloc() + * and releases it at thread destruction via sleepq_free(). Note that + * a sleep queue is not tied to a specific thread and that the sleep queue + * released at thread destruction may not be the same sleep queue that the + * thread allocated when it was created. + * + * XXX: Some other parts of the kernel such as ithread sleeping may end up + * using this interface as well (death to TDI_IWAIT!) + */ + +struct lock_object; +struct sleepqueue; +struct thread; + +#ifdef _KERNEL + +#define SLEEPQ_TYPE 0x0ff /* Mask of sleep queue types. */ +#define SLEEPQ_SLEEP 0x00 /* Used by sleep/wakeup. */ +#define SLEEPQ_CONDVAR 0x01 /* Used for a cv. */ +#define SLEEPQ_PAUSE 0x02 /* Used by pause. */ +#define SLEEPQ_SX 0x03 /* Used by an sx lock. */ +#define SLEEPQ_LK 0x04 /* Used by a lockmgr. */ +#define SLEEPQ_INTERRUPTIBLE 0x100 /* Sleep is interruptible. */ +#define SLEEPQ_UNFAIR 0x200 /* Unfair wakeup order. */ + +void init_sleepqueues(void); +int sleepq_abort(struct thread *td, int intrval); +void sleepq_add(void *wchan, struct lock_object *lock, const char *wmesg, + int flags, int queue); +struct sleepqueue *sleepq_alloc(void); +int sleepq_broadcast(void *wchan, int flags, int pri, int queue); +void sleepq_chains_remove_matching(bool (*matches)(struct thread *)); +void sleepq_free(struct sleepqueue *sq); +void sleepq_lock(void *wchan); +struct sleepqueue *sleepq_lookup(void *wchan); +void sleepq_release(void *wchan); +void sleepq_remove(struct thread *td, void *wchan); +int sleepq_remove_matching(struct sleepqueue *sq, int queue, + bool (*matches)(struct thread *), int pri); +int sleepq_signal(void *wchan, int flags, int pri, int queue); +void sleepq_set_timeout_sbt(void *wchan, sbintime_t sbt, + sbintime_t pr, int flags); +#define sleepq_set_timeout(wchan, timo) \ + sleepq_set_timeout_sbt((wchan), tick_sbt * (timo), 0, C_HARDCLOCK) +u_int sleepq_sleepcnt(void *wchan, int queue); +int sleepq_timedwait(void *wchan, int pri); +int sleepq_timedwait_sig(void *wchan, int pri); +int sleepq_type(void *wchan); +void sleepq_wait(void *wchan, int pri); +int sleepq_wait_sig(void *wchan, int pri); + +#ifdef STACK +struct sbuf; +int sleepq_sbuf_print_stacks(struct sbuf *sb, void *wchan, int queue, + int *count_stacks_printed); +#endif + +#endif /* _KERNEL */ +#endif /* !_SYS_SLEEPQUEUE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/slicer.h b/lib/libc/include/any-freebsd-any/sys/slicer.h new file mode 100644 index 000000000000..675b5acc2dd7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/slicer.h @@ -0,0 +1,66 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Semihalf. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _FLASH_SLICER_H_ +#define _FLASH_SLICER_H_ + +#include + +#define FLASH_SLICES_MAX_NUM 8 +#define FLASH_SLICES_MAX_NAME_LEN (32 + 1) + +#define FLASH_SLICES_FLAG_NONE 0 +#define FLASH_SLICES_FLAG_RO 1 /* Read only */ + +#define FLASH_SLICES_FMT "%ss.%s" + +struct flash_slice { + off_t base; + off_t size; + const char *label; + unsigned int flags; +}; + +#ifdef _KERNEL + +typedef int (*flash_slicer_t)(device_t dev, const char *provider, + struct flash_slice *slices, int *slices_num); + +#define FLASH_SLICES_TYPE_NAND 0 +#define FLASH_SLICES_TYPE_CFI 1 +#define FLASH_SLICES_TYPE_SPI 2 +#define FLASH_SLICES_TYPE_MMC 3 + +/* Use NULL and set force to true for deregistering a slicer */ +void flash_register_slicer(flash_slicer_t slicer, u_int type, bool force); + +#endif /* _KERNEL */ + +#endif /* _FLASH_SLICER_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/smp.h b/lib/libc/include/any-freebsd-any/sys/smp.h new file mode 100644 index 000000000000..c80bc879a7b4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/smp.h @@ -0,0 +1,279 @@ +/*- + * SPDX-License-Identifier: Beerware + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + */ + +#ifndef _SYS_SMP_H_ +#define _SYS_SMP_H_ + +#ifdef _KERNEL + +#ifndef LOCORE + +#include +#include + +/* + * Types of nodes in the topological tree. + */ +typedef enum { + /* No node has this type; can be used in topo API calls. */ + TOPO_TYPE_DUMMY, + /* Processing unit aka computing unit aka logical CPU. */ + TOPO_TYPE_PU, + /* Physical subdivision of a package. */ + TOPO_TYPE_CORE, + /* CPU L1/L2/L3 cache. */ + TOPO_TYPE_CACHE, + /* Package aka chip, equivalent to socket. */ + TOPO_TYPE_PKG, + /* NUMA node. */ + TOPO_TYPE_NODE, + /* Other logical or physical grouping of PUs. */ + /* E.g. PUs on the same dye, or PUs sharing an FPU. */ + TOPO_TYPE_GROUP, + /* The whole system. */ + TOPO_TYPE_SYSTEM +} topo_node_type; + +/* Hardware indenitifier of a topology component. */ +typedef unsigned int hwid_t; +/* Logical CPU idenitifier. */ +typedef int cpuid_t; + +/* A node in the topology. */ +struct topo_node { + struct topo_node *parent; + TAILQ_HEAD(topo_children, topo_node) children; + TAILQ_ENTRY(topo_node) siblings; + cpuset_t cpuset; + topo_node_type type; + uintptr_t subtype; + hwid_t hwid; + cpuid_t id; + int nchildren; + int cpu_count; +}; + +/* + * Scheduling topology of a NUMA or SMP system. + * + * The top level topology is an array of pointers to groups. Each group + * contains a bitmask of cpus in its group or subgroups. It may also + * contain a pointer to an array of child groups. + * + * The bitmasks at non leaf groups may be used by consumers who support + * a smaller depth than the hardware provides. + * + * The topology may be omitted by systems where all CPUs are equal. + */ + +struct cpu_group { + struct cpu_group *cg_parent; /* Our parent group. */ + struct cpu_group *cg_child; /* Optional children groups. */ + cpuset_t cg_mask; /* Mask of cpus in this group. */ + int32_t cg_count; /* Count of cpus in this group. */ + int16_t cg_children; /* Number of children groups. */ + int8_t cg_level; /* Shared cache level. */ + int8_t cg_flags; /* Traversal modifiers. */ +}; + +typedef struct cpu_group *cpu_group_t; + +/* + * Defines common resources for CPUs in the group. The highest level + * resource should be used when multiple are shared. + */ +#define CG_SHARE_NONE 0 +#define CG_SHARE_L1 1 +#define CG_SHARE_L2 2 +#define CG_SHARE_L3 3 + +#define MAX_CACHE_LEVELS CG_SHARE_L3 + +/* + * Behavior modifiers for load balancing and affinity. + */ +#define CG_FLAG_HTT 0x01 /* Schedule the alternate core last. */ +#define CG_FLAG_SMT 0x02 /* New age htt, less crippled. */ +#define CG_FLAG_THREAD (CG_FLAG_HTT | CG_FLAG_SMT) /* Any threading. */ + +/* + * Convenience routines for building and traversing topologies. + */ +#ifdef SMP +void topo_init_node(struct topo_node *node); +void topo_init_root(struct topo_node *root); +struct topo_node * topo_add_node_by_hwid(struct topo_node *parent, int hwid, + topo_node_type type, uintptr_t subtype); +struct topo_node * topo_find_node_by_hwid(struct topo_node *parent, int hwid, + topo_node_type type, uintptr_t subtype); +void topo_promote_child(struct topo_node *child); +struct topo_node * topo_next_node(struct topo_node *top, + struct topo_node *node); +struct topo_node * topo_next_nonchild_node(struct topo_node *top, + struct topo_node *node); +void topo_set_pu_id(struct topo_node *node, cpuid_t id); + +enum topo_level { + TOPO_LEVEL_PKG = 0, + /* + * Some systems have useful sub-package core organizations. On these, + * a package has one or more subgroups. Each subgroup contains one or + * more cache groups (cores that share a last level cache). + */ + TOPO_LEVEL_GROUP, + TOPO_LEVEL_CACHEGROUP, + TOPO_LEVEL_CORE, + TOPO_LEVEL_THREAD, + TOPO_LEVEL_COUNT /* Must be last */ +}; +struct topo_analysis { + int entities[TOPO_LEVEL_COUNT]; +}; +int topo_analyze(struct topo_node *topo_root, int all, + struct topo_analysis *results); + +#define TOPO_FOREACH(i, root) \ + for (i = root; i != NULL; i = topo_next_node(root, i)) + +struct cpu_group *smp_topo(void); +struct cpu_group *smp_topo_alloc(u_int count); +struct cpu_group *smp_topo_none(void); +struct cpu_group *smp_topo_1level(int l1share, int l1count, int l1flags); +struct cpu_group *smp_topo_2level(int l2share, int l2count, int l1share, + int l1count, int l1flags); +struct cpu_group *smp_topo_find(struct cpu_group *top, int cpu); + +extern void (*cpustop_restartfunc)(void); +extern int smp_cpus; +/* The suspend/resume cpusets are x86 only, but minimize ifdefs. */ +extern volatile cpuset_t resuming_cpus; /* woken up cpus in suspend pen */ +extern volatile cpuset_t started_cpus; /* cpus to let out of stop pen */ +extern volatile cpuset_t stopped_cpus; /* cpus in stop pen */ +extern volatile cpuset_t suspended_cpus; /* cpus [near] sleeping in susp pen */ +extern volatile cpuset_t toresume_cpus; /* cpus to let out of suspend pen */ +extern cpuset_t hlt_cpus_mask; /* XXX 'mask' is detail in old impl */ +extern cpuset_t logical_cpus_mask; +#endif /* SMP */ + +extern u_int mp_maxid; +extern int mp_maxcpus; +extern int mp_ncores; +extern int mp_ncpus; +extern volatile int smp_started; +extern int smp_threads_per_core; + +extern cpuset_t all_cpus; +extern cpuset_t cpuset_domain[MAXMEMDOM]; /* CPUs in each NUMA domain. */ + +/* + * Macro allowing us to determine whether a CPU is absent at any given + * time, thus permitting us to configure sparse maps of cpuid-dependent + * (per-CPU) structures. + */ +#define CPU_ABSENT(x_cpu) (!CPU_ISSET(x_cpu, &all_cpus)) + +/* + * Macros to iterate over non-absent CPUs. CPU_FOREACH() takes an + * integer iterator and iterates over the available set of CPUs. + * CPU_FIRST() returns the id of the first non-absent CPU. CPU_NEXT() + * returns the id of the next non-absent CPU. It will wrap back to + * CPU_FIRST() once the end of the list is reached. The iterators are + * currently implemented via inline functions. + */ +#define CPU_FOREACH(i) \ + for ((i) = 0; (i) <= mp_maxid; (i)++) \ + if (!CPU_ABSENT((i))) + +static __inline int +cpu_first(void) +{ + int i; + + for (i = 0;; i++) + if (!CPU_ABSENT(i)) + return (i); +} + +static __inline int +cpu_next(int i) +{ + + for (;;) { + i++; + if (i > mp_maxid) + i = 0; + if (!CPU_ABSENT(i)) + return (i); + } +} + +#define CPU_FIRST() cpu_first() +#define CPU_NEXT(i) cpu_next((i)) + +#ifdef SMP +/* + * Machine dependent functions used to initialize MP support. + * + * The cpu_mp_probe() should check to see if MP support is present and return + * zero if it is not or non-zero if it is. If MP support is present, then + * cpu_mp_start() will be called so that MP can be enabled. This function + * should do things such as startup secondary processors. It should also + * setup mp_ncpus, all_cpus, and smp_cpus. It should also ensure that + * smp_started is initialized at the appropriate time. + * Once cpu_mp_start() returns, machine independent MP startup code will be + * executed and a simple message will be output to the console. Finally, + * cpu_mp_announce() will be called so that machine dependent messages about + * the MP support may be output to the console if desired. + * + * The cpu_setmaxid() function is called very early during the boot process + * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs + * that other subsystems may use. If a platform is not able to determine + * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1. + */ +struct thread; + +struct cpu_group *cpu_topo(void); +void cpu_mp_announce(void); +int cpu_mp_probe(void); +void cpu_mp_setmaxid(void); +void cpu_mp_start(void); + +void forward_signal(struct thread *); +int restart_cpus(cpuset_t); +int stop_cpus(cpuset_t); +int stop_cpus_hard(cpuset_t); +#if defined(__amd64__) || defined(__i386__) +int suspend_cpus(cpuset_t); +int resume_cpus(cpuset_t); +#endif + +void smp_rendezvous_action(void); +extern struct mtx smp_ipi_mtx; + +#endif /* SMP */ + +int quiesce_all_cpus(const char *, int); +int quiesce_cpus(cpuset_t, const char *, int); +void smp_no_rendezvous_barrier(void *); +void smp_rendezvous(void (*)(void *), + void (*)(void *), + void (*)(void *), + void *arg); +void smp_rendezvous_cpus(cpuset_t, + void (*)(void *), + void (*)(void *), + void (*)(void *), + void *arg); +#endif /* !LOCORE */ +#endif /* _KERNEL */ +#endif /* _SYS_SMP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/snoop.h b/lib/libc/include/any-freebsd-any/sys/snoop.h new file mode 100644 index 000000000000..b25aa494ff8e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/snoop.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 1995 Ugen J.S.Antsilevich + * + * Redistribution and use in source forms, with and without modification, + * are permitted provided that this entire comment appears intact. + * + * Redistribution in binary form may occur without any restrictions. + * Obviously, it would be nice if you gave credit where credit is due + * but requiring it would be too onerous. + * + * This software is provided ``AS IS'' without any warranties of any kind. + * + * Snoop stuff. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SNOOP_H_ +#define _SYS_SNOOP_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * These are snoop io controls + * SNPSTTY accepts a file descriptor as input. + */ + +#define SNPSTTY _IOW('T', 90, int) +#define SNPGTTY _IOR('T', 89, dev_t) + +/* + * These values would be returned by FIONREAD ioctl + * instead of number of characters in buffer in case + * of specific errors. + */ +#define SNP_OFLOW -1 +#define SNP_TTYCLOSE -2 +#define SNP_DETACH -3 + +#endif /* !_SYS_SNOOP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sockbuf.h b/lib/libc/include/any-freebsd-any/sys/sockbuf.h new file mode 100644 index 000000000000..1ba261efe0c2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sockbuf.h @@ -0,0 +1,254 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 + * + * $FreeBSD$ + */ +#ifndef _SYS_SOCKBUF_H_ +#define _SYS_SOCKBUF_H_ + +/* + * Constants for sb_flags field of struct sockbuf/xsockbuf. + */ +#define SB_WAIT 0x04 /* someone is waiting for data/space */ +#define SB_SEL 0x08 /* someone is selecting */ +#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ +#define SB_UPCALL 0x20 /* someone wants an upcall */ +#define SB_NOINTR 0x40 /* operations not interruptible */ +#define SB_AIO 0x80 /* AIO operations queued */ +#define SB_KNOTE 0x100 /* kernel note attached */ +#define SB_NOCOALESCE 0x200 /* don't coalesce new data into existing mbufs */ +#define SB_IN_TOE 0x400 /* socket buffer is in the middle of an operation */ +#define SB_AUTOSIZE 0x800 /* automatically size socket buffer */ +#define SB_STOP 0x1000 /* backpressure indicator */ +#define SB_AIO_RUNNING 0x2000 /* AIO operation running */ + +#define SBS_CANTSENDMORE 0x0010 /* can't send more data to peer */ +#define SBS_CANTRCVMORE 0x0020 /* can't receive more data from peer */ +#define SBS_RCVATMARK 0x0040 /* at mark on input */ + +#if defined(_KERNEL) || defined(_WANT_SOCKET) +#include +#include +#include +#include + +#define SB_MAX (2*1024*1024) /* default for max chars in sockbuf */ + +struct mbuf; +struct sockaddr; +struct socket; +struct thread; +struct selinfo; + +/* + * Variables for socket buffering. + * + * Locking key to struct sockbuf: + * (a) locked by SOCKBUF_LOCK(). + */ +struct sockbuf { + struct mtx sb_mtx; /* sockbuf lock */ + struct sx sb_sx; /* prevent I/O interlacing */ + struct selinfo *sb_sel; /* process selecting read/write */ + short sb_state; /* (a) socket state on sockbuf */ +#define sb_startzero sb_mb + struct mbuf *sb_mb; /* (a) the mbuf chain */ + struct mbuf *sb_mbtail; /* (a) the last mbuf in the chain */ + struct mbuf *sb_lastrecord; /* (a) first mbuf of last + * record in socket buffer */ + struct mbuf *sb_sndptr; /* (a) pointer into mbuf chain */ + struct mbuf *sb_fnrdy; /* (a) pointer to first not ready buffer */ + u_int sb_sndptroff; /* (a) byte offset of ptr into chain */ + u_int sb_acc; /* (a) available chars in buffer */ + u_int sb_ccc; /* (a) claimed chars in buffer */ + u_int sb_hiwat; /* (a) max actual char count */ + u_int sb_mbcnt; /* (a) chars of mbufs used */ + u_int sb_mcnt; /* (a) number of mbufs in buffer */ + u_int sb_ccnt; /* (a) number of clusters in buffer */ + u_int sb_mbmax; /* (a) max chars of mbufs to use */ + u_int sb_ctl; /* (a) non-data chars in buffer */ + int sb_lowat; /* (a) low water mark */ + sbintime_t sb_timeo; /* (a) timeout for read/write */ + short sb_flags; /* (a) flags, see below */ + int (*sb_upcall)(struct socket *, void *, int); /* (a) */ + void *sb_upcallarg; /* (a) */ + TAILQ_HEAD(, kaiocb) sb_aiojobq; /* (a) pending AIO ops */ + struct task sb_aiotask; /* AIO task */ +}; + +#endif /* defined(_KERNEL) || defined(_WANT_SOCKET) */ +#ifdef _KERNEL + +/* + * Per-socket buffer mutex used to protect most fields in the socket + * buffer. + */ +#define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx) +#define SOCKBUF_LOCK_INIT(_sb, _name) \ + mtx_init(SOCKBUF_MTX(_sb), _name, NULL, MTX_DEF) +#define SOCKBUF_LOCK_DESTROY(_sb) mtx_destroy(SOCKBUF_MTX(_sb)) +#define SOCKBUF_LOCK(_sb) mtx_lock(SOCKBUF_MTX(_sb)) +#define SOCKBUF_OWNED(_sb) mtx_owned(SOCKBUF_MTX(_sb)) +#define SOCKBUF_UNLOCK(_sb) mtx_unlock(SOCKBUF_MTX(_sb)) +#define SOCKBUF_LOCK_ASSERT(_sb) mtx_assert(SOCKBUF_MTX(_sb), MA_OWNED) +#define SOCKBUF_UNLOCK_ASSERT(_sb) mtx_assert(SOCKBUF_MTX(_sb), MA_NOTOWNED) + +/* + * Socket buffer private mbuf(9) flags. + */ +#define M_NOTREADY M_PROTO1 /* m_data not populated yet */ +#define M_BLOCKED M_PROTO2 /* M_NOTREADY in front of m */ +#define M_NOTAVAIL (M_NOTREADY | M_BLOCKED) + +void sbappend(struct sockbuf *sb, struct mbuf *m, int flags); +void sbappend_locked(struct sockbuf *sb, struct mbuf *m, int flags); +void sbappendstream(struct sockbuf *sb, struct mbuf *m, int flags); +void sbappendstream_locked(struct sockbuf *sb, struct mbuf *m, int flags); +int sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa, + struct mbuf *m0, struct mbuf *control); +int sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa, + struct mbuf *m0, struct mbuf *control); +int sbappendaddr_nospacecheck_locked(struct sockbuf *sb, + const struct sockaddr *asa, struct mbuf *m0, struct mbuf *control); +void sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, + struct mbuf *control, int flags); +void sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0, + struct mbuf *control, int flags); +void sbappendrecord(struct sockbuf *sb, struct mbuf *m0); +void sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0); +void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n); +struct mbuf * + sbcreatecontrol(caddr_t p, int size, int type, int level); +void sbdestroy(struct sockbuf *sb, struct socket *so); +void sbdrop(struct sockbuf *sb, int len); +void sbdrop_locked(struct sockbuf *sb, int len); +struct mbuf * + sbcut_locked(struct sockbuf *sb, int len); +void sbdroprecord(struct sockbuf *sb); +void sbdroprecord_locked(struct sockbuf *sb); +void sbflush(struct sockbuf *sb); +void sbflush_locked(struct sockbuf *sb); +void sbrelease(struct sockbuf *sb, struct socket *so); +void sbrelease_internal(struct sockbuf *sb, struct socket *so); +void sbrelease_locked(struct sockbuf *sb, struct socket *so); +int sbsetopt(struct socket *so, int cmd, u_long cc); +int sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, + struct thread *td); +struct mbuf * + sbsndptr(struct sockbuf *sb, u_int off, u_int len, u_int *moff); +struct mbuf * + sbsndptr_noadv(struct sockbuf *sb, u_int off, u_int *moff); +void + sbsndptr_adv(struct sockbuf *sb, struct mbuf *mb, u_int len); +struct mbuf * + sbsndmbuf(struct sockbuf *sb, u_int off, u_int *moff); +int sbwait(struct sockbuf *sb); +int sblock(struct sockbuf *sb, int flags); +void sbunlock(struct sockbuf *sb); +void sballoc(struct sockbuf *, struct mbuf *); +void sbfree(struct sockbuf *, struct mbuf *); +int sbready(struct sockbuf *, struct mbuf *, int); + +/* + * Return how much data is available to be taken out of socket + * buffer right now. + */ +static inline u_int +sbavail(struct sockbuf *sb) +{ + +#if 0 + SOCKBUF_LOCK_ASSERT(sb); +#endif + return (sb->sb_acc); +} + +/* + * Return how much data sits there in the socket buffer + * It might be that some data is not yet ready to be read. + */ +static inline u_int +sbused(struct sockbuf *sb) +{ + +#if 0 + SOCKBUF_LOCK_ASSERT(sb); +#endif + return (sb->sb_ccc); +} + +/* + * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? + * This is problematical if the fields are unsigned, as the space might + * still be negative (ccc > hiwat or mbcnt > mbmax). + */ +static inline long +sbspace(struct sockbuf *sb) +{ + int bleft, mleft; /* size should match sockbuf fields */ + +#if 0 + SOCKBUF_LOCK_ASSERT(sb); +#endif + + if (sb->sb_flags & SB_STOP) + return(0); + + bleft = sb->sb_hiwat - sb->sb_ccc; + mleft = sb->sb_mbmax - sb->sb_mbcnt; + + return ((bleft < mleft) ? bleft : mleft); +} + +#define SB_EMPTY_FIXUP(sb) do { \ + if ((sb)->sb_mb == NULL) { \ + (sb)->sb_mbtail = NULL; \ + (sb)->sb_lastrecord = NULL; \ + } \ +} while (/*CONSTCOND*/0) + +#ifdef SOCKBUF_DEBUG +void sblastrecordchk(struct sockbuf *, const char *, int); +void sblastmbufchk(struct sockbuf *, const char *, int); +void sbcheck(struct sockbuf *, const char *, int); +#define SBLASTRECORDCHK(sb) sblastrecordchk((sb), __FILE__, __LINE__) +#define SBLASTMBUFCHK(sb) sblastmbufchk((sb), __FILE__, __LINE__) +#define SBCHECK(sb) sbcheck((sb), __FILE__, __LINE__) +#else +#define SBLASTRECORDCHK(sb) do {} while (0) +#define SBLASTMBUFCHK(sb) do {} while (0) +#define SBCHECK(sb) do {} while (0) +#endif /* SOCKBUF_DEBUG */ + +#endif /* _KERNEL */ + +#endif /* _SYS_SOCKBUF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/socket.h b/lib/libc/include/any-freebsd-any/sys/socket.h new file mode 100644 index 000000000000..eaad9b1bacdb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/socket.h @@ -0,0 +1,731 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socket.h 8.4 (Berkeley) 2/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include +#include +#include +#include + +/* + * Definitions related to sockets: types, address families, options. + */ + +/* + * Data types. + */ +#if __BSD_VISIBLE +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif +#endif + +#ifndef _SA_FAMILY_T_DECLARED +typedef __sa_family_t sa_family_t; +#define _SA_FAMILY_T_DECLARED +#endif + +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#if __BSD_VISIBLE +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINTPTR_T_DECLARED +typedef __uintptr_t uintptr_t; +#define _UINTPTR_T_DECLARED +#endif + +/* + * Types + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#if __BSD_VISIBLE +#define SOCK_RDM 4 /* reliably-delivered message */ +#endif +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ + +#if __BSD_VISIBLE +/* + * Creation flags, OR'ed into socket() and socketpair() type argument. + */ +#define SOCK_CLOEXEC 0x10000000 +#define SOCK_NONBLOCK 0x20000000 +#ifdef _KERNEL +/* + * Flags for accept1(), kern_accept4() and solisten_dequeue, in addition + * to SOCK_CLOEXEC and SOCK_NONBLOCK. + */ +#define ACCEPT4_INHERIT 0x1 +#define ACCEPT4_COMPAT 0x2 +#endif /* _KERNEL */ +#endif /* __BSD_VISIBLE */ + +/* + * Option flags per-socket. + */ +#define SO_DEBUG 0x00000001 /* turn on debugging info recording */ +#define SO_ACCEPTCONN 0x00000002 /* socket has had listen() */ +#define SO_REUSEADDR 0x00000004 /* allow local address reuse */ +#define SO_KEEPALIVE 0x00000008 /* keep connections alive */ +#define SO_DONTROUTE 0x00000010 /* just use interface addresses */ +#define SO_BROADCAST 0x00000020 /* permit sending of broadcast msgs */ +#if __BSD_VISIBLE +#define SO_USELOOPBACK 0x00000040 /* bypass hardware when possible */ +#endif +#define SO_LINGER 0x00000080 /* linger on close if data present */ +#define SO_OOBINLINE 0x00000100 /* leave received OOB data in line */ +#if __BSD_VISIBLE +#define SO_REUSEPORT 0x00000200 /* allow local address & port reuse */ +#define SO_TIMESTAMP 0x00000400 /* timestamp received dgram traffic */ +#define SO_NOSIGPIPE 0x00000800 /* no SIGPIPE from EPIPE */ +#define SO_ACCEPTFILTER 0x00001000 /* there is an accept filter */ +#define SO_BINTIME 0x00002000 /* timestamp received dgram traffic */ +#endif +#define SO_NO_OFFLOAD 0x00004000 /* socket cannot be offloaded */ +#define SO_NO_DDP 0x00008000 /* disable direct data placement */ +#define SO_REUSEPORT_LB 0x00010000 /* reuse with load balancing */ + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#if __BSD_VISIBLE +#define SO_LABEL 0x1009 /* socket's MAC label */ +#define SO_PEERLABEL 0x1010 /* socket's peer's MAC label */ +#define SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */ +#define SO_LISTENQLEN 0x1012 /* socket's complete queue length */ +#define SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue length */ +#define SO_SETFIB 0x1014 /* use this FIB to route */ +#define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */ +#define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */ +#define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */ +#define SO_TS_CLOCK 0x1017 /* clock type used for SO_TIMESTAMP */ +#define SO_MAX_PACING_RATE 0x1018 /* socket's max TX pacing rate (Linux name) */ +#define SO_DOMAIN 0x1019 /* get socket domain */ +#endif + +#if __BSD_VISIBLE +#define SO_TS_REALTIME_MICRO 0 /* microsecond resolution, realtime */ +#define SO_TS_BINTIME 1 /* sub-nanosecond resolution, realtime */ +#define SO_TS_REALTIME 2 /* nanosecond resolution, realtime */ +#define SO_TS_MONOTONIC 3 /* nanosecond resolution, monotonic */ +#define SO_TS_DEFAULT SO_TS_REALTIME_MICRO +#define SO_TS_CLOCK_MAX SO_TS_MONOTONIC +#endif + +/* + * Space reserved for new socket options added by third-party vendors. + * This range applies to all socket option levels. New socket options + * in FreeBSD should always use an option value less than SO_VENDOR. + */ +#if __BSD_VISIBLE +#define SO_VENDOR 0x80000000 +#endif + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time */ +}; + +#if __BSD_VISIBLE +struct accept_filter_arg { + char af_name[16]; + char af_arg[256-16]; +}; +#endif + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xffff /* options for socket level */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#if __BSD_VISIBLE +#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */ +#endif +#define AF_UNIX 1 /* standardized name for AF_LOCAL */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#if __BSD_VISIBLE +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NETBIOS 6 /* SMB protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* European computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_SIP 24 /* Simple Internet Protocol */ +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define pseudo_AF_KEY 27 /* Internal key-management function */ +#endif +#define AF_INET6 28 /* IPv6 */ +#if __BSD_VISIBLE +#define AF_NATM 29 /* native ATM access */ +#define AF_ATM 30 /* ATM */ +#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers + * in interface output routine + */ +#define AF_NETGRAPH 32 /* Netgraph sockets */ +#define AF_SLOW 33 /* 802.3ad slow protocol */ +#define AF_SCLUSTER 34 /* Sitara cluster protocol */ +#define AF_ARP 35 +#define AF_BLUETOOTH 36 /* Bluetooth sockets */ +#define AF_IEEE80211 37 /* IEEE 802.11 protocol */ +#define AF_INET_SDP 40 /* OFED Socket Direct Protocol ipv4 */ +#define AF_INET6_SDP 42 /* OFED Socket Direct Protocol ipv6 */ +#define AF_MAX 42 +/* + * When allocating a new AF_ constant, please only allocate + * even numbered constants for FreeBSD until 134 as odd numbered AF_ + * constants 39-133 are now reserved for vendors. + */ +#define AF_VENDOR00 39 +#define AF_VENDOR01 41 +#define AF_VENDOR02 43 +#define AF_VENDOR03 45 +#define AF_VENDOR04 47 +#define AF_VENDOR05 49 +#define AF_VENDOR06 51 +#define AF_VENDOR07 53 +#define AF_VENDOR08 55 +#define AF_VENDOR09 57 +#define AF_VENDOR10 59 +#define AF_VENDOR11 61 +#define AF_VENDOR12 63 +#define AF_VENDOR13 65 +#define AF_VENDOR14 67 +#define AF_VENDOR15 69 +#define AF_VENDOR16 71 +#define AF_VENDOR17 73 +#define AF_VENDOR18 75 +#define AF_VENDOR19 77 +#define AF_VENDOR20 79 +#define AF_VENDOR21 81 +#define AF_VENDOR22 83 +#define AF_VENDOR23 85 +#define AF_VENDOR24 87 +#define AF_VENDOR25 89 +#define AF_VENDOR26 91 +#define AF_VENDOR27 93 +#define AF_VENDOR28 95 +#define AF_VENDOR29 97 +#define AF_VENDOR30 99 +#define AF_VENDOR31 101 +#define AF_VENDOR32 103 +#define AF_VENDOR33 105 +#define AF_VENDOR34 107 +#define AF_VENDOR35 109 +#define AF_VENDOR36 111 +#define AF_VENDOR37 113 +#define AF_VENDOR38 115 +#define AF_VENDOR39 117 +#define AF_VENDOR40 119 +#define AF_VENDOR41 121 +#define AF_VENDOR42 123 +#define AF_VENDOR43 125 +#define AF_VENDOR44 127 +#define AF_VENDOR45 129 +#define AF_VENDOR46 131 +#define AF_VENDOR47 133 +#endif + +/* + * Structure used by kernel to store most + * addresses. + */ +struct sockaddr { + unsigned char sa_len; /* total length */ + sa_family_t sa_family; /* address family */ + char sa_data[14]; /* actually longer; address value */ +}; +#if __BSD_VISIBLE +#define SOCK_MAXADDRLEN 255 /* longest possible addresses */ + +/* + * Structure used by kernel to pass protocol + * information in raw sockets. + */ +struct sockproto { + unsigned short sp_family; /* address family */ + unsigned short sp_protocol; /* protocol */ +}; +#endif + +#include + +#if __BSD_VISIBLE +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX PF_LOCAL /* backward compatibility */ +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NETBIOS AF_NETBIOS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_SIP AF_SIP +#define PF_IPX AF_IPX +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#define PF_ISDN AF_ISDN +#define PF_KEY pseudo_AF_KEY +#define PF_INET6 AF_INET6 +#define PF_NATM AF_NATM +#define PF_ATM AF_ATM +#define PF_NETGRAPH AF_NETGRAPH +#define PF_SLOW AF_SLOW +#define PF_SCLUSTER AF_SCLUSTER +#define PF_ARP AF_ARP +#define PF_BLUETOOTH AF_BLUETOOTH +#define PF_IEEE80211 AF_IEEE80211 +#define PF_INET_SDP AF_INET_SDP +#define PF_INET6_SDP AF_INET6_SDP + +#define PF_MAX AF_MAX + +/* + * Definitions for network related sysctl, CTL_NET. + * + * Second level is protocol family. + * Third level is protocol number. + * + * Further levels are defined by the individual families. + */ + +/* + * PF_ROUTE - Routing table + * + * Three additional levels are defined: + * Fourth: address family, 0 is wildcard + * Fifth: type of info, defined below + * Sixth: flag(s) to mask with for NET_RT_FLAGS + */ +#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ +#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ +#define NET_RT_IFLIST 3 /* survey interface list */ +#define NET_RT_IFMALIST 4 /* return multicast address list */ +#define NET_RT_IFLISTL 5 /* Survey interface list, using 'l'en + * versions of msghdr structs. */ +#endif /* __BSD_VISIBLE */ + +/* + * Maximum queue length specifiable by listen. + */ +#define SOMAXCONN 128 + +/* + * Message header for recvmsg and sendmsg calls. + * Used value-result for recvmsg, value only for sendmsg. + */ +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; + +#define MSG_OOB 0x00000001 /* process out-of-band data */ +#define MSG_PEEK 0x00000002 /* peek at incoming message */ +#define MSG_DONTROUTE 0x00000004 /* send without using routing tables */ +#define MSG_EOR 0x00000008 /* data completes record */ +#define MSG_TRUNC 0x00000010 /* data discarded before delivery */ +#define MSG_CTRUNC 0x00000020 /* control data lost before delivery */ +#define MSG_WAITALL 0x00000040 /* wait for full request or error */ +#if __BSD_VISIBLE +#define MSG_DONTWAIT 0x00000080 /* this message should be nonblocking */ +#define MSG_EOF 0x00000100 /* data completes connection */ +/* 0x00000200 unused */ +/* 0x00000400 unused */ +/* 0x00000800 unused */ +/* 0x00001000 unused */ +#define MSG_NOTIFICATION 0x00002000 /* SCTP notification */ +#define MSG_NBIO 0x00004000 /* FIONBIO mode, used by fifofs */ +#define MSG_COMPAT 0x00008000 /* used in sendit() */ +#endif +#ifdef _KERNEL +#define MSG_SOCALLBCK 0x00010000 /* for use by socket callbacks - soreceive (TCP) */ +#endif +#if __POSIX_VISIBLE >= 200809 +#define MSG_NOSIGNAL 0x00020000 /* do not generate SIGPIPE on EOF */ +#endif +#if __BSD_VISIBLE +#define MSG_CMSG_CLOEXEC 0x00040000 /* make received fds close-on-exec */ +#define MSG_WAITFORONE 0x00080000 /* for recvmmsg() */ +#endif +#ifdef _KERNEL +#define MSG_MORETOCOME 0x00100000 /* additional data pending */ +#endif + +/* + * Header for ancillary data objects in msg_control buffer. + * Used for additional information with/about a datagram + * not expressible by flags. The format is a sequence + * of message elements headed by cmsghdr structures. + */ +struct cmsghdr { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; + +#if __BSD_VISIBLE +/* + * While we may have more groups than this, the cmsgcred struct must + * be able to fit in an mbuf and we have historically supported a + * maximum of 16 groups. +*/ +#define CMGROUP_MAX 16 + +/* + * Credentials structure, used to verify the identity of a peer + * process that has sent us a message. This is allocated by the + * peer process but filled in by the kernel. This prevents the + * peer from lying about its identity. (Note that cmcred_groups[0] + * is the effective GID.) + */ +struct cmsgcred { + pid_t cmcred_pid; /* PID of sending process */ + uid_t cmcred_uid; /* real UID of sending process */ + uid_t cmcred_euid; /* effective UID of sending process */ + gid_t cmcred_gid; /* real GID of sending process */ + short cmcred_ngroups; /* number or groups */ + gid_t cmcred_groups[CMGROUP_MAX]; /* groups */ +}; + +/* + * Socket credentials. + */ +struct sockcred { + uid_t sc_uid; /* real user id */ + uid_t sc_euid; /* effective user id */ + gid_t sc_gid; /* real group id */ + gid_t sc_egid; /* effective group id */ + int sc_ngroups; /* number of supplemental groups */ + gid_t sc_groups[1]; /* variable length */ +}; + +/* + * Compute size of a sockcred structure with groups. + */ +#define SOCKCREDSIZE(ngrps) \ + (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1))) + +#endif /* __BSD_VISIBLE */ + +/* given pointer to struct cmsghdr, return pointer to data */ +#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ + _ALIGN(sizeof(struct cmsghdr))) + +/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ +#define CMSG_NXTHDR(mhdr, cmsg) \ + ((char *)(cmsg) == (char *)0 ? CMSG_FIRSTHDR(mhdr) : \ + ((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \ + _ALIGN(sizeof(struct cmsghdr)) > \ + (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)0 : \ + (struct cmsghdr *)(void *)((char *)(cmsg) + \ + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len))) + +/* + * RFC 2292 requires to check msg_controllen, in case that the kernel returns + * an empty list for some reasons. + */ +#define CMSG_FIRSTHDR(mhdr) \ + ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)0) + +#if __BSD_VISIBLE +/* RFC 2292 additions */ +#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l)) +#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l)) +#endif + +#ifdef _KERNEL +#define CMSG_ALIGN(n) _ALIGN(n) +#endif + +/* "Socket"-level control message types: */ +#define SCM_RIGHTS 0x01 /* access rights (array of int) */ +#if __BSD_VISIBLE +#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ +#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */ +#define SCM_BINTIME 0x04 /* timestamp (struct bintime) */ +#define SCM_REALTIME 0x05 /* timestamp (struct timespec) */ +#define SCM_MONOTONIC 0x06 /* timestamp (struct timespec) */ +#define SCM_TIME_INFO 0x07 /* timestamp info */ + +struct sock_timestamp_info { + __uint32_t st_info_flags; + __uint32_t st_info_pad0; + __uint64_t st_info_rsv[7]; +}; + +#define ST_INFO_HW 0x0001 /* SCM_TIMESTAMP was hw */ +#define ST_INFO_HW_HPREC 0x0002 /* SCM_TIMESTAMP was hw-assisted + on entrance */ +#endif + +#if __BSD_VISIBLE +/* + * 4.3 compat sockaddr, move to compat file later + */ +struct osockaddr { + unsigned short sa_family; /* address family */ + char sa_data[14]; /* up to 14 bytes of direct address */ +}; + +/* + * 4.3-compat message header (move to compat file later). + */ +struct omsghdr { + char *msg_name; /* optional address */ + int msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + int msg_iovlen; /* # elements in msg_iov */ + char *msg_accrights; /* access rights sent/received */ + int msg_accrightslen; +}; +#endif + +/* + * howto arguments for shutdown(2), specified by Posix.1g. + */ +#define SHUT_RD 0 /* shut down the reading side */ +#define SHUT_WR 1 /* shut down the writing side */ +#define SHUT_RDWR 2 /* shut down both sides */ + +#if __BSD_VISIBLE +/* for SCTP */ +/* we cheat and use the SHUT_XX defines for these */ +#define PRU_FLUSH_RD SHUT_RD +#define PRU_FLUSH_WR SHUT_WR +#define PRU_FLUSH_RDWR SHUT_RDWR +#endif + + +#if __BSD_VISIBLE +/* + * sendfile(2) header/trailer struct + */ +struct sf_hdtr { + struct iovec *headers; /* pointer to an array of header struct iovec's */ + int hdr_cnt; /* number of header iovec's */ + struct iovec *trailers; /* pointer to an array of trailer struct iovec's */ + int trl_cnt; /* number of trailer iovec's */ +}; + +/* + * Sendfile-specific flag(s) + */ +#define SF_NODISKIO 0x00000001 +#define SF_MNOWAIT 0x00000002 /* obsolete */ +#define SF_SYNC 0x00000004 +#define SF_USER_READAHEAD 0x00000008 +#define SF_NOCACHE 0x00000010 +#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags)) + +#ifdef _KERNEL +#define SF_READAHEAD(flags) ((flags) >> 16) +#endif /* _KERNEL */ + +/* + * Sendmmsg/recvmmsg specific structure(s) + */ +struct mmsghdr { + struct msghdr msg_hdr; /* message header */ + ssize_t msg_len; /* message length */ +}; +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +#if __BSD_VISIBLE +int accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int); +int bindat(int, int, const struct sockaddr *, socklen_t); +int connectat(int, int, const struct sockaddr *, socklen_t); +#endif +int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict); +int listen(int, int); +ssize_t recv(int, void *, size_t, int); +ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict); +ssize_t recvmsg(int, struct msghdr *, int); +#if __BSD_VISIBLE +struct timespec; +ssize_t recvmmsg(int, struct mmsghdr * __restrict, size_t, int, + const struct timespec * __restrict); +#endif +ssize_t send(int, const void *, size_t, int); +ssize_t sendto(int, const void *, + size_t, int, const struct sockaddr *, socklen_t); +ssize_t sendmsg(int, const struct msghdr *, int); +#if __BSD_VISIBLE +int sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int); +ssize_t sendmmsg(int, struct mmsghdr * __restrict, size_t, int); +int setfib(int); +#endif +int setsockopt(int, int, int, const void *, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int *); +__END_DECLS + +#endif /* !_KERNEL */ + +#ifdef _KERNEL +struct socket; + +struct tcpcb *so_sototcpcb(struct socket *so); +struct inpcb *so_sotoinpcb(struct socket *so); +struct sockbuf *so_sockbuf_snd(struct socket *); +struct sockbuf *so_sockbuf_rcv(struct socket *); + +int so_state_get(const struct socket *); +void so_state_set(struct socket *, int); + +int so_options_get(const struct socket *); +void so_options_set(struct socket *, int); + +int so_error_get(const struct socket *); +void so_error_set(struct socket *, int); + +int so_linger_get(const struct socket *); +void so_linger_set(struct socket *, int); + +struct protosw *so_protosw_get(const struct socket *); +void so_protosw_set(struct socket *, struct protosw *); + +void so_sorwakeup_locked(struct socket *so); +void so_sowwakeup_locked(struct socket *so); + +void so_sorwakeup(struct socket *so); +void so_sowwakeup(struct socket *so); + +void so_lock(struct socket *so); +void so_unlock(struct socket *so); + +#endif /* _KERNEL */ +#endif /* !_SYS_SOCKET_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/socketvar.h b/lib/libc/include/any-freebsd-any/sys/socketvar.h new file mode 100644 index 000000000000..99d8839f8beb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/socketvar.h @@ -0,0 +1,538 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 + * + * $FreeBSD$ + */ + +#ifndef _SYS_SOCKETVAR_H_ +#define _SYS_SOCKETVAR_H_ + +/* + * Socket generation count type. Also used in xinpcb, xtcpcb, xunpcb. + */ +typedef uint64_t so_gen_t; + +#if defined(_KERNEL) || defined(_WANT_SOCKET) +#include /* for TAILQ macros */ +#include /* for struct selinfo */ +#include +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +struct vnet; + +/* + * Kernel structure per socket. + * Contains send and receive buffer queues, + * handle on protocol and pointer to protocol + * private data and error information. + */ +typedef int so_upcall_t(struct socket *, void *, int); +typedef void so_dtor_t(struct socket *); + +struct socket; + +enum socket_qstate { + SQ_NONE = 0, + SQ_INCOMP = 0x0800, /* on sol_incomp */ + SQ_COMP = 0x1000, /* on sol_comp */ +}; + +/*- + * Locking key to struct socket: + * (a) constant after allocation, no locking required. + * (b) locked by SOCK_LOCK(so). + * (cr) locked by SOCKBUF_LOCK(&so->so_rcv). + * (cs) locked by SOCKBUF_LOCK(&so->so_snd). + * (e) locked by SOLISTEN_LOCK() of corresponding listening socket. + * (f) not locked since integer reads/writes are atomic. + * (g) used only as a sleep/wakeup address, no value. + * (h) locked by global mutex so_global_mtx. + */ +TAILQ_HEAD(accept_queue, socket); +struct socket { + struct mtx so_lock; + volatile u_int so_count; /* (b / refcount) */ + struct selinfo so_rdsel; /* (b/cr) for so_rcv/so_comp */ + struct selinfo so_wrsel; /* (b/cs) for so_snd */ + short so_type; /* (a) generic type, see socket.h */ + int so_options; /* (b) from socket call, see socket.h */ + short so_linger; /* time to linger close(2) */ + short so_state; /* (b) internal state flags SS_* */ + void *so_pcb; /* protocol control block */ + struct vnet *so_vnet; /* (a) network stack instance */ + struct protosw *so_proto; /* (a) protocol handle */ + short so_timeo; /* (g) connection timeout */ + u_short so_error; /* (f) error affecting connection */ + struct sigio *so_sigio; /* [sg] information for async I/O or + out of band data (SIGURG) */ + struct ucred *so_cred; /* (a) user credentials */ + struct label *so_label; /* (b) MAC label for socket */ + /* NB: generation count must not be first. */ + so_gen_t so_gencnt; /* (h) generation count */ + void *so_emuldata; /* (b) private data for emulators */ + so_dtor_t *so_dtor; /* (b) optional destructor */ + struct osd osd; /* Object Specific extensions */ + /* + * so_fibnum, so_user_cookie and friends can be used to attach + * some user-specified metadata to a socket, which then can be + * used by the kernel for various actions. + * so_user_cookie is used by ipfw/dummynet. + */ + int so_fibnum; /* routing domain for this socket */ + uint32_t so_user_cookie; + + int so_ts_clock; /* type of the clock used for timestamps */ + uint32_t so_max_pacing_rate; /* (f) TX rate limit in bytes/s */ + union { + /* Regular (data flow) socket. */ + struct { + /* (cr, cs) Receive and send buffers. */ + struct sockbuf so_rcv, so_snd; + + /* (e) Our place on accept queue. */ + TAILQ_ENTRY(socket) so_list; + struct socket *so_listen; /* (b) */ + enum socket_qstate so_qstate; /* (b) */ + /* (b) cached MAC label for peer */ + struct label *so_peerlabel; + u_long so_oobmark; /* chars to oob mark */ + }; + /* + * Listening socket, where accepts occur, is so_listen in all + * subsidiary sockets. If so_listen is NULL, socket is not + * related to an accept. For a listening socket itself + * sol_incomp queues partially completed connections, while + * sol_comp is a queue of connections ready to be accepted. + * If a connection is aborted and it has so_listen set, then + * it has to be pulled out of either sol_incomp or sol_comp. + * We allow connections to queue up based on current queue + * lengths and limit on number of queued connections for this + * socket. + */ + struct { + /* (e) queue of partial unaccepted connections */ + struct accept_queue sol_incomp; + /* (e) queue of complete unaccepted connections */ + struct accept_queue sol_comp; + u_int sol_qlen; /* (e) sol_comp length */ + u_int sol_incqlen; /* (e) sol_incomp length */ + u_int sol_qlimit; /* (e) queue limit */ + + /* accept_filter(9) optional data */ + struct accept_filter *sol_accept_filter; + void *sol_accept_filter_arg; /* saved filter args */ + char *sol_accept_filter_str; /* saved user args */ + + /* Optional upcall, for kernel socket. */ + so_upcall_t *sol_upcall; /* (e) */ + void *sol_upcallarg; /* (e) */ + + /* Socket buffer parameters, to be copied to + * dataflow sockets, accepted from this one. */ + int sol_sbrcv_lowat; + int sol_sbsnd_lowat; + u_int sol_sbrcv_hiwat; + u_int sol_sbsnd_hiwat; + short sol_sbrcv_flags; + short sol_sbsnd_flags; + sbintime_t sol_sbrcv_timeo; + sbintime_t sol_sbsnd_timeo; + }; + }; +}; +#endif /* defined(_KERNEL) || defined(_WANT_SOCKET) */ + +/* + * Socket state bits. + * + * Historically, this bits were all kept in the so_state field. For + * locking reasons, they are now in multiple fields, as they are + * locked differently. so_state maintains basic socket state protected + * by the socket lock. so_qstate holds information about the socket + * accept queues. Each socket buffer also has a state field holding + * information relevant to that socket buffer (can't send, rcv). Many + * fields will be read without locks to improve performance and avoid + * lock order issues. However, this approach must be used with caution. + */ +#define SS_NOFDREF 0x0001 /* no file table ref any more */ +#define SS_ISCONNECTED 0x0002 /* socket connected to a peer */ +#define SS_ISCONNECTING 0x0004 /* in process of connecting to peer */ +#define SS_ISDISCONNECTING 0x0008 /* in process of disconnecting */ +#define SS_NBIO 0x0100 /* non-blocking ops */ +#define SS_ASYNC 0x0200 /* async i/o notify */ +#define SS_ISCONFIRMING 0x0400 /* deciding to accept connection req */ +#define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */ + +/* + * Protocols can mark a socket as SS_PROTOREF to indicate that, following + * pru_detach, they still want the socket to persist, and will free it + * themselves when they are done. Protocols should only ever call sofree() + * following setting this flag in pru_detach(), and never otherwise, as + * sofree() bypasses socket reference counting. + */ +#define SS_PROTOREF 0x4000 /* strong protocol reference */ + +#ifdef _KERNEL + +#define SOCK_MTX(so) &(so)->so_lock +#define SOCK_LOCK(so) mtx_lock(&(so)->so_lock) +#define SOCK_OWNED(so) mtx_owned(&(so)->so_lock) +#define SOCK_UNLOCK(so) mtx_unlock(&(so)->so_lock) +#define SOCK_LOCK_ASSERT(so) mtx_assert(&(so)->so_lock, MA_OWNED) +#define SOCK_UNLOCK_ASSERT(so) mtx_assert(&(so)->so_lock, MA_NOTOWNED) + +#define SOLISTENING(sol) (((sol)->so_options & SO_ACCEPTCONN) != 0) +#define SOLISTEN_LOCK(sol) do { \ + mtx_lock(&(sol)->so_lock); \ + KASSERT(SOLISTENING(sol), \ + ("%s: %p not listening", __func__, (sol))); \ +} while (0) +#define SOLISTEN_TRYLOCK(sol) mtx_trylock(&(sol)->so_lock) +#define SOLISTEN_UNLOCK(sol) do { \ + KASSERT(SOLISTENING(sol), \ + ("%s: %p not listening", __func__, (sol))); \ + mtx_unlock(&(sol)->so_lock); \ +} while (0) +#define SOLISTEN_LOCK_ASSERT(sol) do { \ + mtx_assert(&(sol)->so_lock, MA_OWNED); \ + KASSERT(SOLISTENING(sol), \ + ("%s: %p not listening", __func__, (sol))); \ +} while (0) + +/* + * Macros for sockets and socket buffering. + */ + +/* + * Flags to sblock(). + */ +#define SBL_WAIT 0x00000001 /* Wait if not immediately available. */ +#define SBL_NOINTR 0x00000002 /* Force non-interruptible sleep. */ +#define SBL_VALID (SBL_WAIT | SBL_NOINTR) + +/* + * Do we need to notify the other side when I/O is possible? + */ +#define sb_notify(sb) (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \ + SB_UPCALL | SB_AIO | SB_KNOTE)) != 0) + +/* do we have to send all at once on a socket? */ +#define sosendallatonce(so) \ + ((so)->so_proto->pr_flags & PR_ATOMIC) + +/* can we read something from so? */ +#define soreadabledata(so) \ + (sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || (so)->so_error) +#define soreadable(so) \ + (soreadabledata(so) || ((so)->so_rcv.sb_state & SBS_CANTRCVMORE)) + +/* can we write something to so? */ +#define sowriteable(so) \ + ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \ + (((so)->so_state&SS_ISCONNECTED) || \ + ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \ + ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \ + (so)->so_error) + +/* + * soref()/sorele() ref-count the socket structure. + * soref() may be called without owning socket lock, but in that case a + * caller must own something that holds socket, and so_count must be not 0. + * Note that you must still explicitly close the socket, but the last ref + * count will free the structure. + */ +#define soref(so) refcount_acquire(&(so)->so_count) +#define sorele(so) do { \ + SOCK_LOCK_ASSERT(so); \ + if (refcount_release(&(so)->so_count)) \ + sofree(so); \ + else \ + SOCK_UNLOCK(so); \ +} while (0) + +/* + * In sorwakeup() and sowwakeup(), acquire the socket buffer lock to + * avoid a non-atomic test-and-wakeup. However, sowakeup is + * responsible for releasing the lock if it is called. We unlock only + * if we don't call into sowakeup. If any code is introduced that + * directly invokes the underlying sowakeup() primitives, it must + * maintain the same semantics. + */ +#define sorwakeup_locked(so) do { \ + SOCKBUF_LOCK_ASSERT(&(so)->so_rcv); \ + if (sb_notify(&(so)->so_rcv)) \ + sowakeup((so), &(so)->so_rcv); \ + else \ + SOCKBUF_UNLOCK(&(so)->so_rcv); \ +} while (0) + +#define sorwakeup(so) do { \ + SOCKBUF_LOCK(&(so)->so_rcv); \ + sorwakeup_locked(so); \ +} while (0) + +#define sowwakeup_locked(so) do { \ + SOCKBUF_LOCK_ASSERT(&(so)->so_snd); \ + if (sb_notify(&(so)->so_snd)) \ + sowakeup((so), &(so)->so_snd); \ + else \ + SOCKBUF_UNLOCK(&(so)->so_snd); \ +} while (0) + +#define sowwakeup(so) do { \ + SOCKBUF_LOCK(&(so)->so_snd); \ + sowwakeup_locked(so); \ +} while (0) + +struct accept_filter { + char accf_name[16]; + int (*accf_callback) + (struct socket *so, void *arg, int waitflag); + void * (*accf_create) + (struct socket *so, char *arg); + void (*accf_destroy) + (struct socket *so); + SLIST_ENTRY(accept_filter) accf_next; +}; + +#define ACCEPT_FILTER_DEFINE(modname, filtname, cb, create, destroy, ver) \ + static struct accept_filter modname##_filter = { \ + .accf_name = filtname, \ + .accf_callback = cb, \ + .accf_create = create, \ + .accf_destroy = destroy, \ + }; \ + static moduledata_t modname##_mod = { \ + .name = __XSTRING(modname), \ + .evhand = accept_filt_generic_mod_event, \ + .priv = &modname##_filter, \ + }; \ + DECLARE_MODULE(modname, modname##_mod, SI_SUB_DRIVERS, \ + SI_ORDER_MIDDLE); \ + MODULE_VERSION(modname, ver) + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_ACCF); +MALLOC_DECLARE(M_PCB); +MALLOC_DECLARE(M_SONAME); +#endif + +/* + * Socket specific helper hook point identifiers + * Do not leave holes in the sequence, hook registration is a loop. + */ +#define HHOOK_SOCKET_OPT 0 +#define HHOOK_SOCKET_CREATE 1 +#define HHOOK_SOCKET_RCV 2 +#define HHOOK_SOCKET_SND 3 +#define HHOOK_FILT_SOREAD 4 +#define HHOOK_FILT_SOWRITE 5 +#define HHOOK_SOCKET_CLOSE 6 +#define HHOOK_SOCKET_LAST HHOOK_SOCKET_CLOSE + +struct socket_hhook_data { + struct socket *so; + struct mbuf *m; + void *hctx; /* hook point specific data*/ + int status; +}; + +extern int maxsockets; +extern u_long sb_max; +extern so_gen_t so_gencnt; + +struct file; +struct filecaps; +struct filedesc; +struct mbuf; +struct sockaddr; +struct ucred; +struct uio; + +/* 'which' values for socket upcalls. */ +#define SO_RCV 1 +#define SO_SND 2 + +/* Return values for socket upcalls. */ +#define SU_OK 0 +#define SU_ISCONNECTED 1 + +/* + * From uipc_socket and friends + */ +int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len); +int getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp, + struct file **fpp, u_int *fflagp, struct filecaps *havecaps); +void soabort(struct socket *so); +int soaccept(struct socket *so, struct sockaddr **nam); +void soaio_enqueue(struct task *task); +void soaio_rcv(void *context, int pending); +void soaio_snd(void *context, int pending); +int socheckuid(struct socket *so, uid_t uid); +int sobind(struct socket *so, struct sockaddr *nam, struct thread *td); +int sobindat(int fd, struct socket *so, struct sockaddr *nam, + struct thread *td); +int soclose(struct socket *so); +int soconnect(struct socket *so, struct sockaddr *nam, struct thread *td); +int soconnectat(int fd, struct socket *so, struct sockaddr *nam, + struct thread *td); +int soconnect2(struct socket *so1, struct socket *so2); +int socreate(int dom, struct socket **aso, int type, int proto, + struct ucred *cred, struct thread *td); +int sodisconnect(struct socket *so); +void sodtor_set(struct socket *, so_dtor_t *); +struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags); +void sofree(struct socket *so); +void sohasoutofband(struct socket *so); +int solisten(struct socket *so, int backlog, struct thread *td); +void solisten_proto(struct socket *so, int backlog); +int solisten_proto_check(struct socket *so); +int solisten_dequeue(struct socket *, struct socket **, int); +struct socket * + sonewconn(struct socket *head, int connstatus); +struct socket * + sopeeloff(struct socket *); +int sopoll(struct socket *so, int events, struct ucred *active_cred, + struct thread *td); +int sopoll_generic(struct socket *so, int events, + struct ucred *active_cred, struct thread *td); +int soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio, + struct mbuf **mp0, struct mbuf **controlp, int *flagsp); +int soreceive_stream(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); +int soreceive_dgram(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); +int soreceive_generic(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); +int soreserve(struct socket *so, u_long sndcc, u_long rcvcc); +void sorflush(struct socket *so); +int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, + struct mbuf *top, struct mbuf *control, int flags, + struct thread *td); +int sosend_dgram(struct socket *so, struct sockaddr *addr, + struct uio *uio, struct mbuf *top, struct mbuf *control, + int flags, struct thread *td); +int sosend_generic(struct socket *so, struct sockaddr *addr, + struct uio *uio, struct mbuf *top, struct mbuf *control, + int flags, struct thread *td); +int soshutdown(struct socket *so, int how); +void soupcall_clear(struct socket *, int); +void soupcall_set(struct socket *, int, so_upcall_t, void *); +void solisten_upcall_set(struct socket *, so_upcall_t, void *); +void sowakeup(struct socket *so, struct sockbuf *sb); +void sowakeup_aio(struct socket *so, struct sockbuf *sb); +void solisten_wakeup(struct socket *); +int selsocket(struct socket *so, int events, struct timeval *tv, + struct thread *td); +void soisconnected(struct socket *so); +void soisconnecting(struct socket *so); +void soisdisconnected(struct socket *so); +void soisdisconnecting(struct socket *so); +void socantrcvmore(struct socket *so); +void socantrcvmore_locked(struct socket *so); +void socantsendmore(struct socket *so); +void socantsendmore_locked(struct socket *so); + +/* + * Accept filter functions (duh). + */ +int accept_filt_add(struct accept_filter *filt); +int accept_filt_del(char *name); +struct accept_filter *accept_filt_get(char *name); +#ifdef ACCEPT_FILTER_MOD +#ifdef SYSCTL_DECL +SYSCTL_DECL(_net_inet_accf); +#endif +int accept_filt_generic_mod_event(module_t mod, int event, void *data); +#endif + +#endif /* _KERNEL */ + +/* + * Structure to export socket from kernel to utilities, via sysctl(3). + */ +struct xsocket { + ksize_t xso_len; /* length of this structure */ + kvaddr_t xso_so; /* kernel address of struct socket */ + kvaddr_t so_pcb; /* kernel address of struct inpcb */ + uint64_t so_oobmark; + int64_t so_spare64[8]; + int32_t xso_protocol; + int32_t xso_family; + uint32_t so_qlen; + uint32_t so_incqlen; + uint32_t so_qlimit; + pid_t so_pgid; + uid_t so_uid; + int32_t so_spare32[8]; + int16_t so_type; + int16_t so_options; + int16_t so_linger; + int16_t so_state; + int16_t so_timeo; + uint16_t so_error; + struct xsockbuf { + uint32_t sb_cc; + uint32_t sb_hiwat; + uint32_t sb_mbcnt; + uint32_t sb_mcnt; + uint32_t sb_ccnt; + uint32_t sb_mbmax; + int32_t sb_lowat; + int32_t sb_timeo; + int16_t sb_flags; + } so_rcv, so_snd; +}; + +#ifdef _KERNEL +void sotoxsocket(struct socket *so, struct xsocket *xso); +void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb); +#endif + +/* + * Socket buffer state bits. Exported via libprocstat(3). + */ +#define SBS_CANTSENDMORE 0x0010 /* can't send more data to peer */ +#define SBS_CANTRCVMORE 0x0020 /* can't receive more data from peer */ +#define SBS_RCVATMARK 0x0040 /* at mark on input */ + +#endif /* !_SYS_SOCKETVAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sockio.h b/lib/libc/include/any-freebsd-any/sys/sockio.h new file mode 100644 index 000000000000..447e2c884028 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sockio.h @@ -0,0 +1,148 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)sockio.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS_SOCKIO_H_ +#define _SYS_SOCKIO_H_ + +#include + +/* Socket ioctl's. */ +#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ +#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ + +/* SIOCADDRT _IOW('r', 10, struct ortentry) 4.3BSD */ +/* SIOCDELRT _IOW('r', 11, struct ortentry) 4.3BSD */ +#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */ +#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */ + +#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ +/* OSIOCGIFADDR _IOWR('i', 13, struct ifreq) 4.3BSD */ +#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ +#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ +/* OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) 4.3BSD */ +#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ +#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ +#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ +/* OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) 4.3BSD */ +#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ +#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ +/* OSIOCGIFCONF _IOWR('i', 20, struct ifconf) 4.3BSD */ +#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ +/* OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) 4.3BSD */ +#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ +#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ +#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ +#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ +#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ +#define OSIOCAIFADDR _IOW('i', 26, struct oifaliasreq) /* FreeBSD 9.x */ +/* SIOCALIFADDR _IOW('i', 27, struct if_laddrreq) KAME */ +/* SIOCGLIFADDR _IOWR('i', 28, struct if_laddrreq) KAME */ +/* SIOCDLIFADDR _IOW('i', 29, struct if_laddrreq) KAME */ +#define SIOCSIFCAP _IOW('i', 30, struct ifreq) /* set IF features */ +#define SIOCGIFCAP _IOWR('i', 31, struct ifreq) /* get IF features */ +#define SIOCGIFINDEX _IOWR('i', 32, struct ifreq) /* get IF index */ +#define SIOCGIFMAC _IOWR('i', 38, struct ifreq) /* get IF MAC label */ +#define SIOCSIFMAC _IOW('i', 39, struct ifreq) /* set IF MAC label */ +#define SIOCSIFNAME _IOW('i', 40, struct ifreq) /* set IF name */ +#define SIOCSIFDESCR _IOW('i', 41, struct ifreq) /* set ifnet descr */ +#define SIOCGIFDESCR _IOWR('i', 42, struct ifreq) /* get ifnet descr */ +#define SIOCAIFADDR _IOW('i', 43, struct ifaliasreq)/* add/chg IF alias */ + +#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ +#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ +#define SIOCGIFMTU _IOWR('i', 51, struct ifreq) /* get IF mtu */ +#define SIOCSIFMTU _IOW('i', 52, struct ifreq) /* set IF mtu */ +#define SIOCGIFPHYS _IOWR('i', 53, struct ifreq) /* get IF wire */ +#define SIOCSIFPHYS _IOW('i', 54, struct ifreq) /* set IF wire */ +#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ +#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */ +#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */ + +#define SIOCGIFSTATUS _IOWR('i', 59, struct ifstat) /* get IF status */ +#define SIOCSIFLLADDR _IOW('i', 60, struct ifreq) /* set linklevel addr */ +#define SIOCGI2C _IOWR('i', 61, struct ifreq) /* get I2C data */ +#define SIOCGHWADDR _IOWR('i', 62, struct ifreq) /* get hardware lladdr */ + +#define SIOCSIFPHYADDR _IOW('i', 70, struct ifaliasreq) /* set gif address */ +#define SIOCGIFPSRCADDR _IOWR('i', 71, struct ifreq) /* get gif psrc addr */ +#define SIOCGIFPDSTADDR _IOWR('i', 72, struct ifreq) /* get gif pdst addr */ +#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */ +/* SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) KAME */ +/* SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) KAME */ + +#define SIOCGPRIVATE_0 _IOWR('i', 80, struct ifreq) /* device private 0 */ +#define SIOCGPRIVATE_1 _IOWR('i', 81, struct ifreq) /* device private 1 */ + +#define SIOCSIFVNET _IOWR('i', 90, struct ifreq) /* move IF jail/vnet */ +#define SIOCSIFRVNET _IOWR('i', 91, struct ifreq) /* reclaim vnet IF */ + +#define SIOCGIFFIB _IOWR('i', 92, struct ifreq) /* get IF fib */ +#define SIOCSIFFIB _IOW('i', 93, struct ifreq) /* set IF fib */ + +#define SIOCGTUNFIB _IOWR('i', 94, struct ifreq) /* get tunnel fib */ +#define SIOCSTUNFIB _IOW('i', 95, struct ifreq) /* set tunnel fib */ + +#define SIOCSDRVSPEC _IOW('i', 123, struct ifdrv) /* set driver-specific + parameters */ +#define SIOCGDRVSPEC _IOWR('i', 123, struct ifdrv) /* get driver-specific + parameters */ + +#define SIOCIFCREATE _IOWR('i', 122, struct ifreq) /* create clone if */ +#define SIOCIFCREATE2 _IOWR('i', 124, struct ifreq) /* create clone if */ +#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */ +#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */ + +#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */ +#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */ +#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */ +#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */ +#define SIOCGIFXMEDIA _IOWR('i', 139, struct ifmediareq) /* get net xmedia */ + +#define SIOCGIFRSSKEY _IOWR('i', 150, struct ifrsskey)/* get RSS key */ +#define SIOCGIFRSSHASH _IOWR('i', 151, struct ifrsshash)/* get the current RSS + type/func settings */ + +#define SIOCGLANPCP _IOWR('i', 152, struct ifreq) /* Get (V)LAN PCP */ +#define SIOCSLANPCP _IOW('i', 153, struct ifreq) /* Set (V)LAN PCP */ + +#define SIOCGIFDOWNREASON _IOWR('i', 154, struct ifdownreason) + +#endif /* !_SYS_SOCKIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sockopt.h b/lib/libc/include/any-freebsd-any/sys/sockopt.h new file mode 100644 index 000000000000..e7cc6cf0657c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sockopt.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 + * + * $FreeBSD$ + */ +#ifndef _SYS_SOCKOPT_H_ +#define _SYS_SOCKOPT_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + + +struct thread; +struct socket; + +/* + * Argument structure for sosetopt et seq. This is in the KERNEL + * section because it will never be visible to user code. + */ +enum sopt_dir { SOPT_GET, SOPT_SET }; + +struct sockopt { + enum sopt_dir sopt_dir; /* is this a get or a set? */ + int sopt_level; /* second arg of [gs]etsockopt */ + int sopt_name; /* third arg of [gs]etsockopt */ + void *sopt_val; /* fourth arg of [gs]etsockopt */ + size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */ + struct thread *sopt_td; /* calling thread or null if kernel */ +}; + +int sosetopt(struct socket *so, struct sockopt *sopt); +int sogetopt(struct socket *so, struct sockopt *sopt); +int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen); +int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len); +int soopt_getm(struct sockopt *sopt, struct mbuf **mp); +int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m); +int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m); +int accept_filt_getopt(struct socket *, struct sockopt *); +int accept_filt_setopt(struct socket *, struct sockopt *); +int so_setsockopt(struct socket *so, int level, int optname, + void *optval, size_t optlen); + +#endif /* _SYS_SOCKOPT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/soundcard.h b/lib/libc/include/any-freebsd-any/sys/soundcard.h new file mode 100644 index 000000000000..2410fe110aac --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/soundcard.h @@ -0,0 +1,2006 @@ +/* + * soundcard.h + */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright by Hannu Savolainen 1993 / 4Front Technologies 1993-2006 + * Modified for the new FreeBSD sound driver by Luigi Rizzo, 1997 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Unless coordinating changes with 4Front Technologies, do NOT make any + * modifications to ioctl commands, types, etc. that would break + * compatibility with the OSS API. + */ + +#ifndef _SYS_SOUNDCARD_H_ +#define _SYS_SOUNDCARD_H_ + /* + * If you make modifications to this file, please contact me before + * distributing the modified version. There is already enough + * diversity in the world. + * + * Regards, + * Hannu Savolainen + * hannu@voxware.pp.fi + * + ********************************************************************** + * PS. The Hacker's Guide to VoxWare available from + * nic.funet.fi:pub/Linux/ALPHA/sound. The file is + * snd-sdk-doc-0.1.ps.gz (gzipped postscript). It contains + * some useful information about programming with VoxWare. + * (NOTE! The pub/Linux/ALPHA/ directories are hidden. You have + * to cd inside them before the files are accessible.) + ********************************************************************** + */ + +/* + * SOUND_VERSION is only used by the voxware driver. Hopefully apps + * should not depend on it, but rather look at the capabilities + * of the driver in the kernel! + */ +#define SOUND_VERSION 301 +#define VOXWARE /* does this have any use ? */ + +/* + * Supported card ID numbers (Should be somewhere else? We keep + * them here just for compativility with the old driver, but these + * constants are of little or no use). + */ + +#define SNDCARD_ADLIB 1 +#define SNDCARD_SB 2 +#define SNDCARD_PAS 3 +#define SNDCARD_GUS 4 +#define SNDCARD_MPU401 5 +#define SNDCARD_SB16 6 +#define SNDCARD_SB16MIDI 7 +#define SNDCARD_UART6850 8 +#define SNDCARD_GUS16 9 +#define SNDCARD_MSS 10 +#define SNDCARD_PSS 11 +#define SNDCARD_SSCAPE 12 +#define SNDCARD_PSS_MPU 13 +#define SNDCARD_PSS_MSS 14 +#define SNDCARD_SSCAPE_MSS 15 +#define SNDCARD_TRXPRO 16 +#define SNDCARD_TRXPRO_SB 17 +#define SNDCARD_TRXPRO_MPU 18 +#define SNDCARD_MAD16 19 +#define SNDCARD_MAD16_MPU 20 +#define SNDCARD_CS4232 21 +#define SNDCARD_CS4232_MPU 22 +#define SNDCARD_MAUI 23 +#define SNDCARD_PSEUDO_MSS 24 +#define SNDCARD_AWE32 25 +#define SNDCARD_NSS 26 +#define SNDCARD_UART16550 27 +#define SNDCARD_OPL 28 + +#include +#include +#ifndef _IOWR +#include +#endif /* !_IOWR */ + +/* + * The first part of this file contains the new FreeBSD sound ioctl + * interface. Tries to minimize the number of different ioctls, and + * to be reasonably general. + * + * 970821: some of the new calls have not been implemented yet. + */ + +/* + * the following three calls extend the generic file descriptor + * interface. AIONWRITE is the dual of FIONREAD, i.e. returns the max + * number of bytes for a write operation to be non-blocking. + * + * AIOGSIZE/AIOSSIZE are used to change the behaviour of the device, + * from a character device (default) to a block device. In block mode, + * (not to be confused with blocking mode) the main difference for the + * application is that select() will return only when a complete + * block can be read/written to the device, whereas in character mode + * select will return true when one byte can be exchanged. For audio + * devices, character mode makes select almost useless since one byte + * will always be ready by the next sample time (which is often only a + * handful of microseconds away). + * Use a size of 0 or 1 to return to character mode. + */ +#define AIONWRITE _IOR('A', 10, int) /* get # bytes to write */ +struct snd_size { + int play_size; + int rec_size; +}; +#define AIOGSIZE _IOR('A', 11, struct snd_size)/* read current blocksize */ +#define AIOSSIZE _IOWR('A', 11, struct snd_size) /* sets blocksize */ + +/* + * The following constants define supported audio formats. The + * encoding follows voxware conventions, i.e. 1 bit for each supported + * format. We extend it by using bit 31 (RO) to indicate full-duplex + * capability, and bit 29 (RO) to indicate that the card supports/ + * needs different formats on capture & playback channels. + * Bit 29 (RW) is used to indicate/ask stereo. + * + * The number of bits required to store the sample is: + * o 4 bits for the IDA ADPCM format, + * o 8 bits for 8-bit formats, mu-law and A-law, + * o 16 bits for the 16-bit formats, and + * o 32 bits for the 24/32-bit formats. + * o undefined for the MPEG audio format. + */ + +#define AFMT_QUERY 0x00000000 /* Return current format */ +#define AFMT_MU_LAW 0x00000001 /* Logarithmic mu-law */ +#define AFMT_A_LAW 0x00000002 /* Logarithmic A-law */ +#define AFMT_IMA_ADPCM 0x00000004 /* A 4:1 compressed format where 16-bit + * squence represented using the + * the average 4 bits per sample */ +#define AFMT_U8 0x00000008 /* Unsigned 8-bit */ +#define AFMT_S16_LE 0x00000010 /* Little endian signed 16-bit */ +#define AFMT_S16_BE 0x00000020 /* Big endian signed 16-bit */ +#define AFMT_S8 0x00000040 /* Signed 8-bit */ +#define AFMT_U16_LE 0x00000080 /* Little endian unsigned 16-bit */ +#define AFMT_U16_BE 0x00000100 /* Big endian unsigned 16-bit */ +#define AFMT_MPEG 0x00000200 /* MPEG MP2/MP3 audio */ +#define AFMT_AC3 0x00000400 /* Dolby Digital AC3 */ + +/* + * 32-bit formats below used for 24-bit audio data where the data is stored + * in the 24 most significant bits and the least significant bits are not used + * (should be set to 0). + */ +#define AFMT_S32_LE 0x00001000 /* Little endian signed 32-bit */ +#define AFMT_S32_BE 0x00002000 /* Big endian signed 32-bit */ +#define AFMT_U32_LE 0x00004000 /* Little endian unsigned 32-bit */ +#define AFMT_U32_BE 0x00008000 /* Big endian unsigned 32-bit */ +#define AFMT_S24_LE 0x00010000 /* Little endian signed 24-bit */ +#define AFMT_S24_BE 0x00020000 /* Big endian signed 24-bit */ +#define AFMT_U24_LE 0x00040000 /* Little endian unsigned 24-bit */ +#define AFMT_U24_BE 0x00080000 /* Big endian unsigned 24-bit */ + +/* Machine dependent AFMT_* definitions. */ +#if BYTE_ORDER == LITTLE_ENDIAN +#define AFMT_S16_NE AFMT_S16_LE +#define AFMT_S24_NE AFMT_S24_LE +#define AFMT_S32_NE AFMT_S32_LE +#define AFMT_U16_NE AFMT_U16_LE +#define AFMT_U24_NE AFMT_U24_LE +#define AFMT_U32_NE AFMT_U32_LE +#define AFMT_S16_OE AFMT_S16_BE +#define AFMT_S24_OE AFMT_S24_BE +#define AFMT_S32_OE AFMT_S32_BE +#define AFMT_U16_OE AFMT_U16_BE +#define AFMT_U24_OE AFMT_U24_BE +#define AFMT_U32_OE AFMT_U32_BE +#else +#define AFMT_S16_OE AFMT_S16_LE +#define AFMT_S24_OE AFMT_S24_LE +#define AFMT_S32_OE AFMT_S32_LE +#define AFMT_U16_OE AFMT_U16_LE +#define AFMT_U24_OE AFMT_U24_LE +#define AFMT_U32_OE AFMT_U32_LE +#define AFMT_S16_NE AFMT_S16_BE +#define AFMT_S24_NE AFMT_S24_BE +#define AFMT_S32_NE AFMT_S32_BE +#define AFMT_U16_NE AFMT_U16_BE +#define AFMT_U24_NE AFMT_U24_BE +#define AFMT_U32_NE AFMT_U32_BE +#endif + +#define AFMT_STEREO 0x10000000 /* can do/want stereo */ + +/* + * the following are really capabilities + */ +#define AFMT_WEIRD 0x20000000 /* weird hardware... */ + /* + * AFMT_WEIRD reports that the hardware might need to operate + * with different formats in the playback and capture + * channels when operating in full duplex. + * As an example, SoundBlaster16 cards only support U8 in one + * direction and S16 in the other one, and applications should + * be aware of this limitation. + */ +#define AFMT_FULLDUPLEX 0x80000000 /* can do full duplex */ + +/* + * The following structure is used to get/set format and sampling rate. + * While it would be better to have things such as stereo, bits per + * sample, endiannes, etc split in different variables, it turns out + * that formats are not that many, and not all combinations are possible. + * So we followed the Voxware approach of associating one bit to each + * format. + */ + +typedef struct _snd_chan_param { + u_long play_rate; /* sampling rate */ + u_long rec_rate; /* sampling rate */ + u_long play_format; /* everything describing the format */ + u_long rec_format; /* everything describing the format */ +} snd_chan_param; +#define AIOGFMT _IOR('f', 12, snd_chan_param) /* get format */ +#define AIOSFMT _IOWR('f', 12, snd_chan_param) /* sets format */ + +/* + * The following structure is used to get/set the mixer setting. + * Up to 32 mixers are supported, each one with up to 32 channels. + */ +typedef struct _snd_mix_param { + u_char subdev; /* which output */ + u_char line; /* which input */ + u_char left,right; /* volumes, 0..255, 0 = mute */ +} snd_mix_param ; + +/* XXX AIOGMIX, AIOSMIX not implemented yet */ +#define AIOGMIX _IOWR('A', 13, snd_mix_param) /* return mixer status */ +#define AIOSMIX _IOWR('A', 14, snd_mix_param) /* sets mixer status */ + +/* + * channel specifiers used in AIOSTOP and AIOSYNC + */ +#define AIOSYNC_PLAY 0x1 /* play chan */ +#define AIOSYNC_CAPTURE 0x2 /* capture chan */ +/* AIOSTOP stop & flush a channel, returns the residual count */ +#define AIOSTOP _IOWR ('A', 15, int) + +/* alternate method used to notify the sync condition */ +#define AIOSYNC_SIGNAL 0x100 +#define AIOSYNC_SELECT 0x200 + +/* what the 'pos' field refers to */ +#define AIOSYNC_READY 0x400 +#define AIOSYNC_FREE 0x800 + +typedef struct _snd_sync_parm { + long chan ; /* play or capture channel, plus modifier */ + long pos; +} snd_sync_parm; +#define AIOSYNC _IOWR ('A', 15, snd_sync_parm) /* misc. synchronization */ + +/* + * The following is used to return device capabilities. If the structure + * passed to the ioctl is zeroed, default values are returned for rate + * and formats, a bitmap of available mixers is returned, and values + * (inputs, different levels) for the first one are returned. + * + * If formats, mixers, inputs are instantiated, then detailed info + * are returned depending on the call. + */ +typedef struct _snd_capabilities { + u_long rate_min, rate_max; /* min-max sampling rate */ + u_long formats; + u_long bufsize; /* DMA buffer size */ + u_long mixers; /* bitmap of available mixers */ + u_long inputs; /* bitmap of available inputs (per mixer) */ + u_short left, right; /* how many levels are supported */ +} snd_capabilities; +#define AIOGCAP _IOWR('A', 15, snd_capabilities) /* get capabilities */ + +/* + * here is the old (Voxware) ioctl interface + */ + +/* + * IOCTL Commands for /dev/sequencer + */ + +#define SNDCTL_SEQ_RESET _IO ('Q', 0) +#define SNDCTL_SEQ_SYNC _IO ('Q', 1) +#define SNDCTL_SYNTH_INFO _IOWR('Q', 2, struct synth_info) +#define SNDCTL_SEQ_CTRLRATE _IOWR('Q', 3, int) /* Set/get timer res.(hz) */ +#define SNDCTL_SEQ_GETOUTCOUNT _IOR ('Q', 4, int) +#define SNDCTL_SEQ_GETINCOUNT _IOR ('Q', 5, int) +#define SNDCTL_SEQ_PERCMODE _IOW ('Q', 6, int) +#define SNDCTL_FM_LOAD_INSTR _IOW ('Q', 7, struct sbi_instrument) /* Valid for FM only */ +#define SNDCTL_SEQ_TESTMIDI _IOW ('Q', 8, int) +#define SNDCTL_SEQ_RESETSAMPLES _IOW ('Q', 9, int) +#define SNDCTL_SEQ_NRSYNTHS _IOR ('Q',10, int) +#define SNDCTL_SEQ_NRMIDIS _IOR ('Q',11, int) +#define SNDCTL_MIDI_INFO _IOWR('Q',12, struct midi_info) +#define SNDCTL_SEQ_THRESHOLD _IOW ('Q',13, int) +#define SNDCTL_SEQ_TRESHOLD SNDCTL_SEQ_THRESHOLD /* there was once a typo */ +#define SNDCTL_SYNTH_MEMAVL _IOWR('Q',14, int) /* in=dev#, out=memsize */ +#define SNDCTL_FM_4OP_ENABLE _IOW ('Q',15, int) /* in=dev# */ +#define SNDCTL_PMGR_ACCESS _IOWR('Q',16, struct patmgr_info) +#define SNDCTL_SEQ_PANIC _IO ('Q',17) +#define SNDCTL_SEQ_OUTOFBAND _IOW ('Q',18, struct seq_event_rec) +#define SNDCTL_SEQ_GETTIME _IOR ('Q',19, int) + +struct seq_event_rec { + u_char arr[8]; +}; + +#define SNDCTL_TMR_TIMEBASE _IOWR('T', 1, int) +#define SNDCTL_TMR_START _IO ('T', 2) +#define SNDCTL_TMR_STOP _IO ('T', 3) +#define SNDCTL_TMR_CONTINUE _IO ('T', 4) +#define SNDCTL_TMR_TEMPO _IOWR('T', 5, int) +#define SNDCTL_TMR_SOURCE _IOWR('T', 6, int) +# define TMR_INTERNAL 0x00000001 +# define TMR_EXTERNAL 0x00000002 +# define TMR_MODE_MIDI 0x00000010 +# define TMR_MODE_FSK 0x00000020 +# define TMR_MODE_CLS 0x00000040 +# define TMR_MODE_SMPTE 0x00000080 +#define SNDCTL_TMR_METRONOME _IOW ('T', 7, int) +#define SNDCTL_TMR_SELECT _IOW ('T', 8, int) + +/* + * Endian aware patch key generation algorithm. + */ + +#if defined(_AIX) || defined(AIX) +# define _PATCHKEY(id) (0xfd00|id) +#else +# define _PATCHKEY(id) ((id<<8)|0xfd) +#endif + +/* + * Sample loading mechanism for internal synthesizers (/dev/sequencer) + * The following patch_info structure has been designed to support + * Gravis UltraSound. It tries to be universal format for uploading + * sample based patches but is probably too limited. + */ + +struct patch_info { +/* u_short key; Use GUS_PATCH here */ + short key; /* Use GUS_PATCH here */ +#define GUS_PATCH _PATCHKEY(0x04) +#define OBSOLETE_GUS_PATCH _PATCHKEY(0x02) + + short device_no; /* Synthesizer number */ + short instr_no; /* Midi pgm# */ + + u_long mode; +/* + * The least significant byte has the same format than the GUS .PAT + * files + */ +#define WAVE_16_BITS 0x01 /* bit 0 = 8 or 16 bit wave data. */ +#define WAVE_UNSIGNED 0x02 /* bit 1 = Signed - Unsigned data. */ +#define WAVE_LOOPING 0x04 /* bit 2 = looping enabled-1. */ +#define WAVE_BIDIR_LOOP 0x08 /* bit 3 = Set is bidirectional looping. */ +#define WAVE_LOOP_BACK 0x10 /* bit 4 = Set is looping backward. */ +#define WAVE_SUSTAIN_ON 0x20 /* bit 5 = Turn sustaining on. (Env. pts. 3)*/ +#define WAVE_ENVELOPES 0x40 /* bit 6 = Enable envelopes - 1 */ + /* (use the env_rate/env_offs fields). */ +/* Linux specific bits */ +#define WAVE_VIBRATO 0x00010000 /* The vibrato info is valid */ +#define WAVE_TREMOLO 0x00020000 /* The tremolo info is valid */ +#define WAVE_SCALE 0x00040000 /* The scaling info is valid */ +/* Other bits must be zeroed */ + + long len; /* Size of the wave data in bytes */ + long loop_start, loop_end; /* Byte offsets from the beginning */ + +/* + * The base_freq and base_note fields are used when computing the + * playback speed for a note. The base_note defines the tone frequency + * which is heard if the sample is played using the base_freq as the + * playback speed. + * + * The low_note and high_note fields define the minimum and maximum note + * frequencies for which this sample is valid. It is possible to define + * more than one samples for an instrument number at the same time. The + * low_note and high_note fields are used to select the most suitable one. + * + * The fields base_note, high_note and low_note should contain + * the note frequency multiplied by 1000. For example value for the + * middle A is 440*1000. + */ + + u_int base_freq; + u_long base_note; + u_long high_note; + u_long low_note; + int panning; /* -128=left, 127=right */ + int detuning; + +/* New fields introduced in version 1.99.5 */ + + /* Envelope. Enabled by mode bit WAVE_ENVELOPES */ + u_char env_rate[ 6 ]; /* GUS HW ramping rate */ + u_char env_offset[ 6 ]; /* 255 == 100% */ + + /* + * The tremolo, vibrato and scale info are not supported yet. + * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or + * WAVE_SCALE + */ + + u_char tremolo_sweep; + u_char tremolo_rate; + u_char tremolo_depth; + + u_char vibrato_sweep; + u_char vibrato_rate; + u_char vibrato_depth; + + int scale_frequency; + u_int scale_factor; /* from 0 to 2048 or 0 to 2 */ + + int volume; + int spare[4]; + char data[1]; /* The waveform data starts here */ +}; + +struct sysex_info { + short key; /* Use GUS_PATCH here */ +#define SYSEX_PATCH _PATCHKEY(0x05) +#define MAUI_PATCH _PATCHKEY(0x06) + short device_no; /* Synthesizer number */ + long len; /* Size of the sysex data in bytes */ + u_char data[1]; /* Sysex data starts here */ +}; + +/* + * Patch management interface (/dev/sequencer, /dev/patmgr#) + * Don't use these calls if you want to maintain compatibility with + * the future versions of the driver. + */ + +#define PS_NO_PATCHES 0 /* No patch support on device */ +#define PS_MGR_NOT_OK 1 /* Plain patch support (no mgr) */ +#define PS_MGR_OK 2 /* Patch manager supported */ +#define PS_MANAGED 3 /* Patch manager running */ + +#define SNDCTL_PMGR_IFACE _IOWR('P', 1, struct patmgr_info) + +/* + * The patmgr_info is a fixed size structure which is used for two + * different purposes. The intended use is for communication between + * the application using /dev/sequencer and the patch manager daemon + * associated with a synthesizer device (ioctl(SNDCTL_PMGR_ACCESS)). + * + * This structure is also used with ioctl(SNDCTL_PGMR_IFACE) which allows + * a patch manager daemon to read and write device parameters. This + * ioctl available through /dev/sequencer also. Avoid using it since it's + * extremely hardware dependent. In addition access trough /dev/sequencer + * may confuse the patch manager daemon. + */ + +struct patmgr_info { /* Note! size must be < 4k since kmalloc() is used */ + u_long key; /* Don't worry. Reserved for communication + between the patch manager and the driver. */ +#define PM_K_EVENT 1 /* Event from the /dev/sequencer driver */ +#define PM_K_COMMAND 2 /* Request from an application */ +#define PM_K_RESPONSE 3 /* From patmgr to application */ +#define PM_ERROR 4 /* Error returned by the patmgr */ + int device; + int command; + +/* + * Commands 0x000 to 0xfff reserved for patch manager programs + */ +#define PM_GET_DEVTYPE 1 /* Returns type of the patch mgr interface of dev */ +#define PMTYPE_FM2 1 /* 2 OP fm */ +#define PMTYPE_FM4 2 /* Mixed 4 or 2 op FM (OPL-3) */ +#define PMTYPE_WAVE 3 /* Wave table synthesizer (GUS) */ +#define PM_GET_NRPGM 2 /* Returns max # of midi programs in parm1 */ +#define PM_GET_PGMMAP 3 /* Returns map of loaded midi programs in data8 */ +#define PM_GET_PGM_PATCHES 4 /* Return list of patches of a program (parm1) */ +#define PM_GET_PATCH 5 /* Return patch header of patch parm1 */ +#define PM_SET_PATCH 6 /* Set patch header of patch parm1 */ +#define PM_READ_PATCH 7 /* Read patch (wave) data */ +#define PM_WRITE_PATCH 8 /* Write patch (wave) data */ + +/* + * Commands 0x1000 to 0xffff are for communication between the patch manager + * and the client + */ +#define _PM_LOAD_PATCH 0x100 + +/* + * Commands above 0xffff reserved for device specific use + */ + + long parm1; + long parm2; + long parm3; + + union { + u_char data8[4000]; + u_short data16[2000]; + u_long data32[1000]; + struct patch_info patch; + } data; +}; + +/* + * When a patch manager daemon is present, it will be informed by the + * driver when something important happens. For example when the + * /dev/sequencer is opened or closed. A record with key == PM_K_EVENT is + * returned. The command field contains the event type: + */ +#define PM_E_OPENED 1 /* /dev/sequencer opened */ +#define PM_E_CLOSED 2 /* /dev/sequencer closed */ +#define PM_E_PATCH_RESET 3 /* SNDCTL_RESETSAMPLES called */ +#define PM_E_PATCH_LOADED 4 /* A patch has been loaded by appl */ + +/* + * /dev/sequencer input events. + * + * The data written to the /dev/sequencer is a stream of events. Events + * are records of 4 or 8 bytes. The first byte defines the size. + * Any number of events can be written with a write call. There + * is a set of macros for sending these events. Use these macros if you + * want to maximize portability of your program. + * + * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events. + * (All input events are currently 4 bytes long. Be prepared to support + * 8 byte events also. If you receive any event having first byte >= 128, + * it's a 8 byte event. + * + * The events are documented at the end of this file. + * + * Normal events (4 bytes) + * There is also a 8 byte version of most of the 4 byte events. The + * 8 byte one is recommended. + */ +#define SEQ_NOTEOFF 0 +#define SEQ_FMNOTEOFF SEQ_NOTEOFF /* Just old name */ +#define SEQ_NOTEON 1 +#define SEQ_FMNOTEON SEQ_NOTEON +#define SEQ_WAIT TMR_WAIT_ABS +#define SEQ_PGMCHANGE 3 +#define SEQ_FMPGMCHANGE SEQ_PGMCHANGE +#define SEQ_SYNCTIMER TMR_START +#define SEQ_MIDIPUTC 5 +#define SEQ_DRUMON 6 /*** OBSOLETE ***/ +#define SEQ_DRUMOFF 7 /*** OBSOLETE ***/ +#define SEQ_ECHO TMR_ECHO /* For synching programs with output */ +#define SEQ_AFTERTOUCH 9 +#define SEQ_CONTROLLER 10 + +/* + * Midi controller numbers + * + * Controllers 0 to 31 (0x00 to 0x1f) and 32 to 63 (0x20 to 0x3f) + * are continuous controllers. + * In the MIDI 1.0 these controllers are sent using two messages. + * Controller numbers 0 to 31 are used to send the MSB and the + * controller numbers 32 to 63 are for the LSB. Note that just 7 bits + * are used in MIDI bytes. + */ + +#define CTL_BANK_SELECT 0x00 +#define CTL_MODWHEEL 0x01 +#define CTL_BREATH 0x02 +/* undefined 0x03 */ +#define CTL_FOOT 0x04 +#define CTL_PORTAMENTO_TIME 0x05 +#define CTL_DATA_ENTRY 0x06 +#define CTL_MAIN_VOLUME 0x07 +#define CTL_BALANCE 0x08 +/* undefined 0x09 */ +#define CTL_PAN 0x0a +#define CTL_EXPRESSION 0x0b +/* undefined 0x0c - 0x0f */ +#define CTL_GENERAL_PURPOSE1 0x10 +#define CTL_GENERAL_PURPOSE2 0x11 +#define CTL_GENERAL_PURPOSE3 0x12 +#define CTL_GENERAL_PURPOSE4 0x13 +/* undefined 0x14 - 0x1f */ + +/* undefined 0x20 */ + +/* + * The controller numbers 0x21 to 0x3f are reserved for the + * least significant bytes of the controllers 0x00 to 0x1f. + * These controllers are not recognised by the driver. + * + * Controllers 64 to 69 (0x40 to 0x45) are on/off switches. + * 0=OFF and 127=ON (intermediate values are possible) + */ +#define CTL_DAMPER_PEDAL 0x40 +#define CTL_SUSTAIN CTL_DAMPER_PEDAL /* Alias */ +#define CTL_HOLD CTL_DAMPER_PEDAL /* Alias */ +#define CTL_PORTAMENTO 0x41 +#define CTL_SOSTENUTO 0x42 +#define CTL_SOFT_PEDAL 0x43 +/* undefined 0x44 */ +#define CTL_HOLD2 0x45 +/* undefined 0x46 - 0x4f */ + +#define CTL_GENERAL_PURPOSE5 0x50 +#define CTL_GENERAL_PURPOSE6 0x51 +#define CTL_GENERAL_PURPOSE7 0x52 +#define CTL_GENERAL_PURPOSE8 0x53 +/* undefined 0x54 - 0x5a */ +#define CTL_EXT_EFF_DEPTH 0x5b +#define CTL_TREMOLO_DEPTH 0x5c +#define CTL_CHORUS_DEPTH 0x5d +#define CTL_DETUNE_DEPTH 0x5e +#define CTL_CELESTE_DEPTH CTL_DETUNE_DEPTH /* Alias for the above one */ +#define CTL_PHASER_DEPTH 0x5f +#define CTL_DATA_INCREMENT 0x60 +#define CTL_DATA_DECREMENT 0x61 +#define CTL_NONREG_PARM_NUM_LSB 0x62 +#define CTL_NONREG_PARM_NUM_MSB 0x63 +#define CTL_REGIST_PARM_NUM_LSB 0x64 +#define CTL_REGIST_PARM_NUM_MSB 0x65 +/* undefined 0x66 - 0x78 */ +/* reserved 0x79 - 0x7f */ + +/* Pseudo controllers (not midi compatible) */ +#define CTRL_PITCH_BENDER 255 +#define CTRL_PITCH_BENDER_RANGE 254 +#define CTRL_EXPRESSION 253 /* Obsolete */ +#define CTRL_MAIN_VOLUME 252 /* Obsolete */ + +#define SEQ_BALANCE 11 +#define SEQ_VOLMODE 12 + +/* + * Volume mode decides how volumes are used + */ + +#define VOL_METHOD_ADAGIO 1 +#define VOL_METHOD_LINEAR 2 + +/* + * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as + * input events. + */ + +/* + * Event codes 0xf0 to 0xfc are reserved for future extensions. + */ + +#define SEQ_FULLSIZE 0xfd /* Long events */ +/* + * SEQ_FULLSIZE events are used for loading patches/samples to the + * synthesizer devices. These events are passed directly to the driver + * of the associated synthesizer device. There is no limit to the size + * of the extended events. These events are not queued but executed + * immediately when the write() is called (execution can take several + * seconds of time). + * + * When a SEQ_FULLSIZE message is written to the device, it must + * be written using exactly one write() call. Other events cannot + * be mixed to the same write. + * + * For FM synths (YM3812/OPL3) use struct sbi_instrument and write + * it to the /dev/sequencer. Don't write other data together with + * the instrument structure Set the key field of the structure to + * FM_PATCH. The device field is used to route the patch to the + * corresponding device. + * + * For Gravis UltraSound use struct patch_info. Initialize the key field + * to GUS_PATCH. + */ +#define SEQ_PRIVATE 0xfe /* Low level HW dependent events (8 bytes) */ +#define SEQ_EXTENDED 0xff /* Extended events (8 bytes) OBSOLETE */ + +/* + * Record for FM patches + */ + +typedef u_char sbi_instr_data[32]; + +struct sbi_instrument { + u_short key; /* FM_PATCH or OPL3_PATCH */ +#define FM_PATCH _PATCHKEY(0x01) +#define OPL3_PATCH _PATCHKEY(0x03) + short device; /* Synth# (0-4) */ + int channel; /* Program# to be initialized */ + sbi_instr_data operators; /* Reg. settings for operator cells + * (.SBI format) */ +}; + +struct synth_info { /* Read only */ + char name[30]; + int device; /* 0-N. INITIALIZE BEFORE CALLING */ + int synth_type; +#define SYNTH_TYPE_FM 0 +#define SYNTH_TYPE_SAMPLE 1 +#define SYNTH_TYPE_MIDI 2 /* Midi interface */ + + int synth_subtype; +#define FM_TYPE_ADLIB 0x00 +#define FM_TYPE_OPL3 0x01 +#define MIDI_TYPE_MPU401 0x401 + +#define SAMPLE_TYPE_BASIC 0x10 +#define SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC +#define SAMPLE_TYPE_AWE32 0x20 + + int perc_mode; /* No longer supported */ + int nr_voices; + int nr_drums; /* Obsolete field */ + int instr_bank_size; + u_long capabilities; +#define SYNTH_CAP_PERCMODE 0x00000001 /* No longer used */ +#define SYNTH_CAP_OPL3 0x00000002 /* Set if OPL3 supported */ +#define SYNTH_CAP_INPUT 0x00000004 /* Input (MIDI) device */ + int dummies[19]; /* Reserve space */ +}; + +struct sound_timer_info { + char name[32]; + int caps; +}; + +struct midi_info { + char name[30]; + int device; /* 0-N. INITIALIZE BEFORE CALLING */ + u_long capabilities; /* To be defined later */ + int dev_type; + int dummies[18]; /* Reserve space */ +}; + +/* + * ioctl commands for the /dev/midi## + */ +typedef struct { + u_char cmd; + char nr_args, nr_returns; + u_char data[30]; +} mpu_command_rec; + +#define SNDCTL_MIDI_PRETIME _IOWR('m', 0, int) +#define SNDCTL_MIDI_MPUMODE _IOWR('m', 1, int) +#define SNDCTL_MIDI_MPUCMD _IOWR('m', 2, mpu_command_rec) +#define MIOSPASSTHRU _IOWR('m', 3, int) +#define MIOGPASSTHRU _IOWR('m', 4, int) + +/* + * IOCTL commands for /dev/dsp and /dev/audio + */ + +#define SNDCTL_DSP_HALT _IO ('P', 0) +#define SNDCTL_DSP_RESET SNDCTL_DSP_HALT +#define SNDCTL_DSP_SYNC _IO ('P', 1) +#define SNDCTL_DSP_SPEED _IOWR('P', 2, int) +#define SNDCTL_DSP_STEREO _IOWR('P', 3, int) +#define SNDCTL_DSP_GETBLKSIZE _IOR('P', 4, int) +#define SNDCTL_DSP_SETBLKSIZE _IOW('P', 4, int) +#define SNDCTL_DSP_SETFMT _IOWR('P',5, int) /* Selects ONE fmt*/ + +/* + * SOUND_PCM_WRITE_CHANNELS is not that different + * from SNDCTL_DSP_STEREO + */ +#define SOUND_PCM_WRITE_CHANNELS _IOWR('P', 6, int) +#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS +#define SOUND_PCM_WRITE_FILTER _IOWR('P', 7, int) +#define SNDCTL_DSP_POST _IO ('P', 8) + +/* + * SNDCTL_DSP_SETBLKSIZE and the following two calls mostly do + * the same thing, i.e. set the block size used in DMA transfers. + */ +#define SNDCTL_DSP_SUBDIVIDE _IOWR('P', 9, int) +#define SNDCTL_DSP_SETFRAGMENT _IOWR('P',10, int) + + +#define SNDCTL_DSP_GETFMTS _IOR ('P',11, int) /* Returns a mask */ +/* + * Buffer status queries. + */ +typedef struct audio_buf_info { + int fragments; /* # of avail. frags (partly used ones not counted) */ + int fragstotal; /* Total # of fragments allocated */ + int fragsize; /* Size of a fragment in bytes */ + + int bytes; /* Avail. space in bytes (includes partly used fragments) */ + /* Note! 'bytes' could be more than fragments*fragsize */ +} audio_buf_info; + +#define SNDCTL_DSP_GETOSPACE _IOR ('P',12, audio_buf_info) +#define SNDCTL_DSP_GETISPACE _IOR ('P',13, audio_buf_info) + +/* + * SNDCTL_DSP_NONBLOCK is the same (but less powerful, since the + * action cannot be undone) of FIONBIO. The same can be achieved + * by opening the device with O_NDELAY + */ +#define SNDCTL_DSP_NONBLOCK _IO ('P',14) + +#define SNDCTL_DSP_GETCAPS _IOR ('P',15, int) +# define PCM_CAP_REVISION 0x000000ff /* Bits for revision level (0 to 255) */ +# define PCM_CAP_DUPLEX 0x00000100 /* Full duplex record/playback */ +# define PCM_CAP_REALTIME 0x00000200 /* Not in use */ +# define PCM_CAP_BATCH 0x00000400 /* Device has some kind of */ + /* internal buffers which may */ + /* cause some delays and */ + /* decrease precision of timing */ +# define PCM_CAP_COPROC 0x00000800 /* Has a coprocessor */ + /* Sometimes it's a DSP */ + /* but usually not */ +# define PCM_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */ +# define PCM_CAP_MMAP 0x00002000 /* Supports mmap() */ +# define PCM_CAP_MULTI 0x00004000 /* Supports multiple open */ +# define PCM_CAP_BIND 0x00008000 /* Supports binding to front/rear/center/lfe */ +# define PCM_CAP_INPUT 0x00010000 /* Supports recording */ +# define PCM_CAP_OUTPUT 0x00020000 /* Supports playback */ +# define PCM_CAP_VIRTUAL 0x00040000 /* Virtual device */ +/* 0x00040000 and 0x00080000 reserved for future use */ + +/* Analog/digital control capabilities */ +# define PCM_CAP_ANALOGOUT 0x00100000 +# define PCM_CAP_ANALOGIN 0x00200000 +# define PCM_CAP_DIGITALOUT 0x00400000 +# define PCM_CAP_DIGITALIN 0x00800000 +# define PCM_CAP_ADMASK 0x00f00000 +/* + * NOTE! (capabilities & PCM_CAP_ADMASK)==0 means just that the + * digital/analog interface control features are not supported by the + * device/driver. However the device still supports analog, digital or + * both inputs/outputs (depending on the device). See the OSS Programmer's + * Guide for full details. + */ +# define PCM_CAP_SPECIAL 0x01000000 /* Not for ordinary "multimedia" use */ +# define PCM_CAP_SHADOW 0x00000000 /* OBSOLETE */ + +/* + * Preferred channel usage. These bits can be used to + * give recommendations to the application. Used by few drivers. + * For example if ((caps & DSP_CH_MASK) == DSP_CH_MONO) means that + * the device works best in mono mode. However it doesn't necessarily mean + * that the device cannot be used in stereo. These bits should only be used + * by special applications such as multi track hard disk recorders to find + * out the initial setup. However the user should be able to override this + * selection. + * + * To find out which modes are actually supported the application should + * try to select them using SNDCTL_DSP_CHANNELS. + */ +# define DSP_CH_MASK 0x06000000 /* Mask */ +# define DSP_CH_ANY 0x00000000 /* No preferred mode */ +# define DSP_CH_MONO 0x02000000 +# define DSP_CH_STEREO 0x04000000 +# define DSP_CH_MULTI 0x06000000 /* More than two channels */ + +# define PCM_CAP_HIDDEN 0x08000000 /* Hidden device */ +# define PCM_CAP_FREERATE 0x10000000 +# define PCM_CAP_MODEM 0x20000000 /* Modem device */ +# define PCM_CAP_DEFAULT 0x40000000 /* "Default" device */ + +/* + * The PCM_CAP_* capability names were known as DSP_CAP_* prior OSS 4.0 + * so it's necessary to define the older names too. + */ +#define DSP_CAP_ADMASK PCM_CAP_ADMASK +#define DSP_CAP_ANALOGIN PCM_CAP_ANALOGIN +#define DSP_CAP_ANALOGOUT PCM_CAP_ANALOGOUT +#define DSP_CAP_BATCH PCM_CAP_BATCH +#define DSP_CAP_BIND PCM_CAP_BIND +#define DSP_CAP_COPROC PCM_CAP_COPROC +#define DSP_CAP_DEFAULT PCM_CAP_DEFAULT +#define DSP_CAP_DIGITALIN PCM_CAP_DIGITALIN +#define DSP_CAP_DIGITALOUT PCM_CAP_DIGITALOUT +#define DSP_CAP_DUPLEX PCM_CAP_DUPLEX +#define DSP_CAP_FREERATE PCM_CAP_FREERATE +#define DSP_CAP_HIDDEN PCM_CAP_HIDDEN +#define DSP_CAP_INPUT PCM_CAP_INPUT +#define DSP_CAP_MMAP PCM_CAP_MMAP +#define DSP_CAP_MODEM PCM_CAP_MODEM +#define DSP_CAP_MULTI PCM_CAP_MULTI +#define DSP_CAP_OUTPUT PCM_CAP_OUTPUT +#define DSP_CAP_REALTIME PCM_CAP_REALTIME +#define DSP_CAP_REVISION PCM_CAP_REVISION +#define DSP_CAP_SHADOW PCM_CAP_SHADOW +#define DSP_CAP_TRIGGER PCM_CAP_TRIGGER +#define DSP_CAP_VIRTUAL PCM_CAP_VIRTUAL + +/* + * What do these function do ? + */ +#define SNDCTL_DSP_GETTRIGGER _IOR ('P',16, int) +#define SNDCTL_DSP_SETTRIGGER _IOW ('P',16, int) +#define PCM_ENABLE_INPUT 0x00000001 +#define PCM_ENABLE_OUTPUT 0x00000002 + +typedef struct count_info { + int bytes; /* Total # of bytes processed */ + int blocks; /* # of fragment transitions since last time */ + int ptr; /* Current DMA pointer value */ +} count_info; + +/* + * GETIPTR and GETISPACE are not that different... same for out. + */ +#define SNDCTL_DSP_GETIPTR _IOR ('P',17, count_info) +#define SNDCTL_DSP_GETOPTR _IOR ('P',18, count_info) + +typedef struct buffmem_desc { + caddr_t buffer; + int size; +} buffmem_desc; + +#define SNDCTL_DSP_MAPINBUF _IOR ('P', 19, buffmem_desc) +#define SNDCTL_DSP_MAPOUTBUF _IOR ('P', 20, buffmem_desc) +#define SNDCTL_DSP_SETSYNCRO _IO ('P', 21) +#define SNDCTL_DSP_SETDUPLEX _IO ('P', 22) +#define SNDCTL_DSP_GETODELAY _IOR ('P', 23, int) + +/* + * I guess these are the readonly version of the same + * functions that exist above as SNDCTL_DSP_... + */ +#define SOUND_PCM_READ_RATE _IOR ('P', 2, int) +#define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int) +#define SOUND_PCM_READ_BITS _IOR ('P', 5, int) +#define SOUND_PCM_READ_FILTER _IOR ('P', 7, int) + +/* + * ioctl calls to be used in communication with coprocessors and + * DSP chips. + */ + +typedef struct copr_buffer { + int command; /* Set to 0 if not used */ + int flags; +#define CPF_NONE 0x0000 +#define CPF_FIRST 0x0001 /* First block */ +#define CPF_LAST 0x0002 /* Last block */ + int len; + int offs; /* If required by the device (0 if not used) */ + + u_char data[4000]; /* NOTE! 4000 is not 4k */ +} copr_buffer; + +typedef struct copr_debug_buf { + int command; /* Used internally. Set to 0 */ + int parm1; + int parm2; + int flags; + int len; /* Length of data in bytes */ +} copr_debug_buf; + +typedef struct copr_msg { + int len; + u_char data[4000]; +} copr_msg; + +#define SNDCTL_COPR_RESET _IO ('C', 0) +#define SNDCTL_COPR_LOAD _IOWR('C', 1, copr_buffer) +#define SNDCTL_COPR_RDATA _IOWR('C', 2, copr_debug_buf) +#define SNDCTL_COPR_RCODE _IOWR('C', 3, copr_debug_buf) +#define SNDCTL_COPR_WDATA _IOW ('C', 4, copr_debug_buf) +#define SNDCTL_COPR_WCODE _IOW ('C', 5, copr_debug_buf) +#define SNDCTL_COPR_RUN _IOWR('C', 6, copr_debug_buf) +#define SNDCTL_COPR_HALT _IOWR('C', 7, copr_debug_buf) +#define SNDCTL_COPR_SENDMSG _IOW ('C', 8, copr_msg) +#define SNDCTL_COPR_RCVMSG _IOR ('C', 9, copr_msg) + +/* + * IOCTL commands for /dev/mixer + */ + +/* + * Mixer devices + * + * There can be up to 20 different analog mixer channels. The + * SOUND_MIXER_NRDEVICES gives the currently supported maximum. + * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells + * the devices supported by the particular mixer. + */ + +#define SOUND_MIXER_NRDEVICES 25 +#define SOUND_MIXER_VOLUME 0 /* Master output level */ +#define SOUND_MIXER_BASS 1 /* Treble level of all output channels */ +#define SOUND_MIXER_TREBLE 2 /* Bass level of all output channels */ +#define SOUND_MIXER_SYNTH 3 /* Volume of synthesier input */ +#define SOUND_MIXER_PCM 4 /* Output level for the audio device */ +#define SOUND_MIXER_SPEAKER 5 /* Output level for the PC speaker + * signals */ +#define SOUND_MIXER_LINE 6 /* Volume level for the line in jack */ +#define SOUND_MIXER_MIC 7 /* Volume for the signal coming from + * the microphone jack */ +#define SOUND_MIXER_CD 8 /* Volume level for the input signal + * connected to the CD audio input */ +#define SOUND_MIXER_IMIX 9 /* Recording monitor. It controls the + * output volume of the selected + * recording sources while recording */ +#define SOUND_MIXER_ALTPCM 10 /* Volume of the alternative codec + * device */ +#define SOUND_MIXER_RECLEV 11 /* Global recording level */ +#define SOUND_MIXER_IGAIN 12 /* Input gain */ +#define SOUND_MIXER_OGAIN 13 /* Output gain */ +/* + * The AD1848 codec and compatibles have three line level inputs + * (line, aux1 and aux2). Since each card manufacturer have assigned + * different meanings to these inputs, it's inpractical to assign + * specific meanings (line, cd, synth etc.) to them. + */ +#define SOUND_MIXER_LINE1 14 /* Input source 1 (aux1) */ +#define SOUND_MIXER_LINE2 15 /* Input source 2 (aux2) */ +#define SOUND_MIXER_LINE3 16 /* Input source 3 (line) */ +#define SOUND_MIXER_DIGITAL1 17 /* Digital (input) 1 */ +#define SOUND_MIXER_DIGITAL2 18 /* Digital (input) 2 */ +#define SOUND_MIXER_DIGITAL3 19 /* Digital (input) 3 */ +#define SOUND_MIXER_PHONEIN 20 /* Phone input */ +#define SOUND_MIXER_PHONEOUT 21 /* Phone output */ +#define SOUND_MIXER_VIDEO 22 /* Video/TV (audio) in */ +#define SOUND_MIXER_RADIO 23 /* Radio in */ +#define SOUND_MIXER_MONITOR 24 /* Monitor (usually mic) volume */ + + +/* + * Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) + * Not counted to SOUND_MIXER_NRDEVICES, but use the same number space + */ +#define SOUND_ONOFF_MIN 28 +#define SOUND_ONOFF_MAX 30 +#define SOUND_MIXER_MUTE 28 /* 0 or 1 */ +#define SOUND_MIXER_ENHANCE 29 /* Enhanced stereo (0, 40, 60 or 80) */ +#define SOUND_MIXER_LOUD 30 /* 0 or 1 */ + +/* Note! Number 31 cannot be used since the sign bit is reserved */ +#define SOUND_MIXER_NONE 31 + +#define SOUND_DEVICE_LABELS { \ + "Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \ + "Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \ + "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \ + "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"} + +#define SOUND_DEVICE_NAMES { \ + "vol", "bass", "treble", "synth", "pcm", "speaker", "line", \ + "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \ + "line1", "line2", "line3", "dig1", "dig2", "dig3", \ + "phin", "phout", "video", "radio", "monitor"} + +/* Device bitmask identifiers */ + +#define SOUND_MIXER_RECSRC 0xff /* 1 bit per recording source */ +#define SOUND_MIXER_DEVMASK 0xfe /* 1 bit per supported device */ +#define SOUND_MIXER_RECMASK 0xfd /* 1 bit per supp. recording source */ +#define SOUND_MIXER_CAPS 0xfc +#define SOUND_CAP_EXCL_INPUT 0x00000001 /* Only 1 rec. src at a time */ +#define SOUND_MIXER_STEREODEVS 0xfb /* Mixer channels supporting stereo */ + +/* Device mask bits */ + +#define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME) +#define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS) +#define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE) +#define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH) +#define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM) +#define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER) +#define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE) +#define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC) +#define SOUND_MASK_CD (1 << SOUND_MIXER_CD) +#define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX) +#define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM) +#define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV) +#define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN) +#define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN) +#define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1) +#define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2) +#define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3) +#define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1) +#define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2) +#define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3) +#define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN) +#define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT) +#define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO) +#define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO) +#define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR) + +/* Obsolete macros */ +#define SOUND_MASK_MUTE (1 << SOUND_MIXER_MUTE) +#define SOUND_MASK_ENHANCE (1 << SOUND_MIXER_ENHANCE) +#define SOUND_MASK_LOUD (1 << SOUND_MIXER_LOUD) + +#define MIXER_READ(dev) _IOR('M', dev, int) +#define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS) +#define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM) +#define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE) +#define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC) +#define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD) +#define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX) +#define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1) +#define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2) +#define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3) +#define SOUND_MIXER_READ_DIGITAL1 MIXER_READ(SOUND_MIXER_DIGITAL1) +#define SOUND_MIXER_READ_DIGITAL2 MIXER_READ(SOUND_MIXER_DIGITAL2) +#define SOUND_MIXER_READ_DIGITAL3 MIXER_READ(SOUND_MIXER_DIGITAL3) +#define SOUND_MIXER_READ_PHONEIN MIXER_READ(SOUND_MIXER_PHONEIN) +#define SOUND_MIXER_READ_PHONEOUT MIXER_READ(SOUND_MIXER_PHONEOUT) +#define SOUND_MIXER_READ_RADIO MIXER_READ(SOUND_MIXER_RADIO) +#define SOUND_MIXER_READ_VIDEO MIXER_READ(SOUND_MIXER_VIDEO) +#define SOUND_MIXER_READ_MONITOR MIXER_READ(SOUND_MIXER_MONITOR) + +/* Obsolete macros */ +#define SOUND_MIXER_READ_MUTE MIXER_READ(SOUND_MIXER_MUTE) +#define SOUND_MIXER_READ_ENHANCE MIXER_READ(SOUND_MIXER_ENHANCE) +#define SOUND_MIXER_READ_LOUD MIXER_READ(SOUND_MIXER_LOUD) + +#define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC) +#define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK) +#define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK) +#define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS) +#define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS) + +#define MIXER_WRITE(dev) _IOWR('M', dev, int) +#define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS) +#define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM) +#define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE) +#define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC) +#define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD) +#define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX) +#define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1) +#define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2) +#define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3) +#define SOUND_MIXER_WRITE_DIGITAL1 MIXER_WRITE(SOUND_MIXER_DIGITAL1) +#define SOUND_MIXER_WRITE_DIGITAL2 MIXER_WRITE(SOUND_MIXER_DIGITAL2) +#define SOUND_MIXER_WRITE_DIGITAL3 MIXER_WRITE(SOUND_MIXER_DIGITAL3) +#define SOUND_MIXER_WRITE_PHONEIN MIXER_WRITE(SOUND_MIXER_PHONEIN) +#define SOUND_MIXER_WRITE_PHONEOUT MIXER_WRITE(SOUND_MIXER_PHONEOUT) +#define SOUND_MIXER_WRITE_RADIO MIXER_WRITE(SOUND_MIXER_RADIO) +#define SOUND_MIXER_WRITE_VIDEO MIXER_WRITE(SOUND_MIXER_VIDEO) +#define SOUND_MIXER_WRITE_MONITOR MIXER_WRITE(SOUND_MIXER_MONITOR) + +#define SOUND_MIXER_WRITE_MUTE MIXER_WRITE(SOUND_MIXER_MUTE) +#define SOUND_MIXER_WRITE_ENHANCE MIXER_WRITE(SOUND_MIXER_ENHANCE) +#define SOUND_MIXER_WRITE_LOUD MIXER_WRITE(SOUND_MIXER_LOUD) + +#define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC) + +typedef struct mixer_info { + char id[16]; + char name[32]; + int modify_counter; + int fillers[10]; +} mixer_info; + +#define SOUND_MIXER_INFO _IOR('M', 101, mixer_info) + +#define LEFT_CHN 0 +#define RIGHT_CHN 1 + +/* + * Level 2 event types for /dev/sequencer + */ + +/* + * The 4 most significant bits of byte 0 specify the class of + * the event: + * + * 0x8X = system level events, + * 0x9X = device/port specific events, event[1] = device/port, + * The last 4 bits give the subtype: + * 0x02 = Channel event (event[3] = chn). + * 0x01 = note event (event[4] = note). + * (0x01 is not used alone but always with bit 0x02). + * event[2] = MIDI message code (0x80=note off etc.) + * + */ + +#define EV_SEQ_LOCAL 0x80 +#define EV_TIMING 0x81 +#define EV_CHN_COMMON 0x92 +#define EV_CHN_VOICE 0x93 +#define EV_SYSEX 0x94 +/* + * Event types 200 to 220 are reserved for application use. + * These numbers will not be used by the driver. + */ + +/* + * Events for event type EV_CHN_VOICE + */ + +#define MIDI_NOTEOFF 0x80 +#define MIDI_NOTEON 0x90 +#define MIDI_KEY_PRESSURE 0xA0 + +/* + * Events for event type EV_CHN_COMMON + */ + +#define MIDI_CTL_CHANGE 0xB0 +#define MIDI_PGM_CHANGE 0xC0 +#define MIDI_CHN_PRESSURE 0xD0 +#define MIDI_PITCH_BEND 0xE0 + +#define MIDI_SYSTEM_PREFIX 0xF0 + +/* + * Timer event types + */ +#define TMR_WAIT_REL 1 /* Time relative to the prev time */ +#define TMR_WAIT_ABS 2 /* Absolute time since TMR_START */ +#define TMR_STOP 3 +#define TMR_START 4 +#define TMR_CONTINUE 5 +#define TMR_TEMPO 6 +#define TMR_ECHO 8 +#define TMR_CLOCK 9 /* MIDI clock */ +#define TMR_SPP 10 /* Song position pointer */ +#define TMR_TIMESIG 11 /* Time signature */ + +/* + * Local event types + */ +#define LOCL_STARTAUDIO 1 + +#if !defined(_KERNEL) || defined(USE_SEQ_MACROS) +/* + * Some convenience macros to simplify programming of the + * /dev/sequencer interface + * + * These macros define the API which should be used when possible. + */ + +#ifndef USE_SIMPLE_MACROS +void seqbuf_dump(void); /* This function must be provided by programs */ + +/* Sample seqbuf_dump() implementation: + * + * SEQ_DEFINEBUF (2048); -- Defines a buffer for 2048 bytes + * + * int seqfd; -- The file descriptor for /dev/sequencer. + * + * void + * seqbuf_dump () + * { + * if (_seqbufptr) + * if (write (seqfd, _seqbuf, _seqbufptr) == -1) + * { + * perror ("write /dev/sequencer"); + * exit (-1); + * } + * _seqbufptr = 0; + * } + */ + +#define SEQ_DEFINEBUF(len) \ + u_char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0 +#define SEQ_USE_EXTBUF() \ + extern u_char _seqbuf[]; \ + extern int _seqbuflen;extern int _seqbufptr +#define SEQ_DECLAREBUF() SEQ_USE_EXTBUF() +#define SEQ_PM_DEFINES struct patmgr_info _pm_info +#define _SEQ_NEEDBUF(len) \ + if ((_seqbufptr+(len)) > _seqbuflen) \ + seqbuf_dump() +#define _SEQ_ADVBUF(len) _seqbufptr += len +#define SEQ_DUMPBUF seqbuf_dump +#else +/* + * This variation of the sequencer macros is used just to format one event + * using fixed buffer. + * + * The program using the macro library must define the following macros before + * using this library. + * + * #define _seqbuf name of the buffer (u_char[]) + * #define _SEQ_ADVBUF(len) If the applic needs to know the exact + * size of the event, this macro can be used. + * Otherwise this must be defined as empty. + * #define _seqbufptr Define the name of index variable or 0 if + * not required. + */ +#define _SEQ_NEEDBUF(len) /* empty */ +#endif + +#define PM_LOAD_PATCH(dev, bank, pgm) \ + (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \ + _pm_info.device=dev, _pm_info.data.data8[0]=pgm, \ + _pm_info.parm1 = bank, _pm_info.parm2 = 1, \ + ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info)) +#define PM_LOAD_PATCHES(dev, bank, pgm) \ + (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \ + _pm_info.device=dev, bcopy( pgm, _pm_info.data.data8, 128), \ + _pm_info.parm1 = bank, _pm_info.parm2 = 128, \ + ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info)) + +#define SEQ_VOLUME_MODE(dev, mode) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = SEQ_EXTENDED;\ + _seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\ + _seqbuf[_seqbufptr+2] = (dev);\ + _seqbuf[_seqbufptr+3] = (mode);\ + _seqbuf[_seqbufptr+4] = 0;\ + _seqbuf[_seqbufptr+5] = 0;\ + _seqbuf[_seqbufptr+6] = 0;\ + _seqbuf[_seqbufptr+7] = 0;\ + _SEQ_ADVBUF(8);} + +/* + * Midi voice messages + */ + +#define _CHN_VOICE(dev, event, chn, note, parm) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_CHN_VOICE;\ + _seqbuf[_seqbufptr+1] = (dev);\ + _seqbuf[_seqbufptr+2] = (event);\ + _seqbuf[_seqbufptr+3] = (chn);\ + _seqbuf[_seqbufptr+4] = (note);\ + _seqbuf[_seqbufptr+5] = (parm);\ + _seqbuf[_seqbufptr+6] = (0);\ + _seqbuf[_seqbufptr+7] = 0;\ + _SEQ_ADVBUF(8);} + +#define SEQ_START_NOTE(dev, chn, note, vol) \ + _CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol) + +#define SEQ_STOP_NOTE(dev, chn, note, vol) \ + _CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol) + +#define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \ + _CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure) + +/* + * Midi channel messages + */ + +#define _CHN_COMMON(dev, event, chn, p1, p2, w14) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_CHN_COMMON;\ + _seqbuf[_seqbufptr+1] = (dev);\ + _seqbuf[_seqbufptr+2] = (event);\ + _seqbuf[_seqbufptr+3] = (chn);\ + _seqbuf[_seqbufptr+4] = (p1);\ + _seqbuf[_seqbufptr+5] = (p2);\ + *(short *)&_seqbuf[_seqbufptr+6] = (w14);\ + _SEQ_ADVBUF(8);} +/* + * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits + * sending any MIDI bytes but it's absolutely not possible. Trying to do + * so _will_ cause problems with MPU401 intelligent mode). + * + * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be + * sent by calling SEQ_SYSEX() several times (there must be no other events + * between them). First sysex fragment must have 0xf0 in the first byte + * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte + * between these sysex start and end markers cannot be larger than 0x7f. Also + * lengths of each fragments (except the last one) must be 6. + * + * Breaking the above rules may work with some MIDI ports but is likely to + * cause fatal problems with some other devices (such as MPU401). + */ +#define SEQ_SYSEX(dev, buf, len) { \ + int i, l=(len); if (l>6)l=6;\ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_SYSEX;\ + for(i=0;i + +struct spigen_transfer { + struct iovec st_command; /* master to slave */ + struct iovec st_data; /* slave to master and/or master to slave */ +}; + +struct spigen_transfer_mmapped { + size_t stm_command_length; /* at offset 0 in mmap(2) area */ + size_t stm_data_length; /* at offset stm_command_length */ +}; + +#define SPIGENIOC_BASE 'S' +#define SPIGENIOC_TRANSFER _IOW(SPIGENIOC_BASE, 0, \ + struct spigen_transfer) +#define SPIGENIOC_TRANSFER_MMAPPED _IOW(SPIGENIOC_BASE, 1, \ + struct spigen_transfer_mmapped) +#define SPIGENIOC_GET_CLOCK_SPEED _IOR(SPIGENIOC_BASE, 2, uint32_t) +#define SPIGENIOC_SET_CLOCK_SPEED _IOW(SPIGENIOC_BASE, 3, uint32_t) +#define SPIGENIOC_GET_SPI_MODE _IOR(SPIGENIOC_BASE, 4, uint32_t) +#define SPIGENIOC_SET_SPI_MODE _IOW(SPIGENIOC_BASE, 5, uint32_t) + +#endif /* !_SYS_SPIGENIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/stack.h b/lib/libc/include/any-freebsd-any/sys/stack.h new file mode 100644 index 000000000000..150641e2327f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/stack.h @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 Antoine Brodin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_STACK_H_ +#define _SYS_STACK_H_ + +#include + +struct sbuf; + +/* MI Routines. */ +struct stack *stack_create(int); +void stack_destroy(struct stack *); +int stack_put(struct stack *, vm_offset_t); +void stack_copy(const struct stack *, struct stack *); +void stack_zero(struct stack *); +void stack_print(const struct stack *); +void stack_print_ddb(const struct stack *); +void stack_print_short(const struct stack *); +void stack_print_short_ddb(const struct stack *); +void stack_sbuf_print(struct sbuf *, const struct stack *); +void stack_sbuf_print_ddb(struct sbuf *, const struct stack *); +#ifdef KTR +void stack_ktr(u_int, const char *, int, const struct stack *, + u_int, int); +#define CTRSTACK(m, st, depth, cheap) do { \ + if (KTR_COMPILE & (m)) \ + stack_ktr((m), __FILE__, __LINE__, st, depth, cheap); \ + } while(0) +#else +#define CTRSTACK(m, st, depth, cheap) +#endif + +/* MD Routines. */ +struct thread; +void stack_save(struct stack *); +void stack_save_td(struct stack *, struct thread *); +int stack_save_td_running(struct stack *, struct thread *); + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/stat.h b/lib/libc/include/any-freebsd-any/sys/stat.h new file mode 100644 index 000000000000..df9cbd4489cf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/stat.h @@ -0,0 +1,404 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stat.h 8.12 (Berkeley) 6/16/95 + * $FreeBSD$ + */ + +#ifndef _SYS_STAT_H_ +#define _SYS_STAT_H_ + +#include +#include +#include + +#ifndef _BLKSIZE_T_DECLARED +typedef __blksize_t blksize_t; +#define _BLKSIZE_T_DECLARED +#endif + +#ifndef _BLKCNT_T_DECLARED +typedef __blkcnt_t blkcnt_t; +#define _BLKCNT_T_DECLARED +#endif + +#ifndef _DEV_T_DECLARED +typedef __dev_t dev_t; +#define _DEV_T_DECLARED +#endif + +#ifndef _FFLAGS_T_DECLARED +typedef __fflags_t fflags_t; +#define _FFLAGS_T_DECLARED +#endif + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; +#define _INO_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _NLINK_T_DECLARED +typedef __nlink_t nlink_t; +#define _NLINK_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#if !defined(_KERNEL) && __BSD_VISIBLE +/* + * XXX We get miscellaneous namespace pollution with this. + */ +#include +#endif + +#ifdef _KERNEL +struct ostat { + __uint16_t st_dev; /* inode's device */ + __uint32_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + __uint16_t st_nlink; /* number of hard links */ + __uint16_t st_uid; /* user ID of the file's owner */ + __uint16_t st_gid; /* group ID of the file's group */ + __uint16_t st_rdev; /* device type */ + __int32_t st_size; /* file size, in bytes */ + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ + __int32_t st_blksize; /* optimal blocksize for I/O */ + __int32_t st_blocks; /* blocks allocated for file */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ +}; +#endif + +#if defined(_WANT_FREEBSD11_STAT) || defined(_KERNEL) +struct freebsd11_stat { + __uint32_t st_dev; /* inode's device */ + __uint32_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + __uint16_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __uint32_t st_rdev; /* device type */ + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + __int32_t st_lspare; + struct timespec st_birthtim; /* time of file creation */ + /* + * Explicitly pad st_birthtim to 16 bytes so that the size of + * struct stat is backwards compatible. We use bitfields instead + * of an array of chars so that this doesn't require a C99 compiler + * to compile if the size of the padding is 0. We use 2 bitfields + * to cover up to 64 bits on 32-bit machines. We assume that + * CHAR_BIT is 8... + */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); +}; +#endif /* _WANT_FREEBSD11_STAT || _KERNEL */ + +#if defined(__i386__) +#define __STAT_TIME_T_EXT 1 +#endif + +struct stat { + dev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + nlink_t st_nlink; /* number of hard links */ + mode_t st_mode; /* inode protection mode */ + __int16_t st_padding0; + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __int32_t st_padding1; + dev_t st_rdev; /* device type */ +#ifdef __STAT_TIME_T_EXT + __int32_t st_atim_ext; +#endif + struct timespec st_atim; /* time of last access */ +#ifdef __STAT_TIME_T_EXT + __int32_t st_mtim_ext; +#endif + struct timespec st_mtim; /* time of last data modification */ +#ifdef __STAT_TIME_T_EXT + __int32_t st_ctim_ext; +#endif + struct timespec st_ctim; /* time of last file status change */ +#ifdef __STAT_TIME_T_EXT + __int32_t st_btim_ext; +#endif + struct timespec st_birthtim; /* time of file creation */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint64_t st_gen; /* file generation number */ + __uint64_t st_spare[10]; +}; + +#ifdef _KERNEL +struct nstat { + __uint32_t st_dev; /* inode's device */ + __uint32_t st_ino; /* inode's number */ + __uint32_t st_mode; /* inode protection mode */ + __uint32_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __uint32_t st_rdev; /* device type */ + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + struct timespec st_birthtim; /* time of file creation */ + /* + * See comment in the definition of struct freebsd11_stat + * above about the following padding. + */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); +}; +#endif + +#ifndef _KERNEL +#define st_atime st_atim.tv_sec +#define st_mtime st_mtim.tv_sec +#define st_ctime st_ctim.tv_sec +#if __BSD_VISIBLE +#define st_birthtime st_birthtim.tv_sec +#endif + +/* For compatibility. */ +#if __BSD_VISIBLE +#define st_atimespec st_atim +#define st_mtimespec st_mtim +#define st_ctimespec st_ctim +#define st_birthtimespec st_birthtim +#endif +#endif /* !_KERNEL */ + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#if __BSD_VISIBLE +#define S_ISTXT 0001000 /* sticky bit */ +#endif + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#if __BSD_VISIBLE +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#endif + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#if __XSI_VISIBLE +#define S_IFMT 0170000 /* type of file mask */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#endif +#if __BSD_VISIBLE +#define S_IFWHT 0160000 /* whiteout */ +#endif + +#define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */ +#define S_ISCHR(m) (((m) & 0170000) == 0020000) /* char special */ +#define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */ +#define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */ +#define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */ +#if __POSIX_VISIBLE >= 200112 +#define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */ +#define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */ +#endif +#if __BSD_VISIBLE +#define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */ +#endif + +#if __BSD_VISIBLE +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ + /* 7777 */ +#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) + /* 0666 */ +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) + +#define S_BLKSIZE 512 /* block size used in the stat struct */ + +/* + * Definitions of flags stored in file flags word. + * + * Super-user and owner changeable flags. + */ +#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ +#define UF_NODUMP 0x00000001 /* do not dump file */ +#define UF_IMMUTABLE 0x00000002 /* file may not be changed */ +#define UF_APPEND 0x00000004 /* writes to file may only append */ +#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ +#define UF_NOUNLINK 0x00000010 /* file may not be removed or renamed */ +/* + * These two bits are defined in MacOS X. They are not currently used in + * FreeBSD. + */ +#if 0 +#define UF_COMPRESSED 0x00000020 /* file is compressed */ +#define UF_TRACKED 0x00000040 /* renames and deletes are tracked */ +#endif + +#define UF_SYSTEM 0x00000080 /* Windows system file bit */ +#define UF_SPARSE 0x00000100 /* sparse file */ +#define UF_OFFLINE 0x00000200 /* file is offline */ +#define UF_REPARSE 0x00000400 /* Windows reparse point file bit */ +#define UF_ARCHIVE 0x00000800 /* file needs to be archived */ +#define UF_READONLY 0x00001000 /* Windows readonly file bit */ +/* This is the same as the MacOS X definition of UF_HIDDEN. */ +#define UF_HIDDEN 0x00008000 /* file is hidden */ + +/* + * Super-user changeable flags. + */ +#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ +#define SF_ARCHIVED 0x00010000 /* file is archived */ +#define SF_IMMUTABLE 0x00020000 /* file may not be changed */ +#define SF_APPEND 0x00040000 /* writes to file may only append */ +#define SF_NOUNLINK 0x00100000 /* file may not be removed or renamed */ +#define SF_SNAPSHOT 0x00200000 /* snapshot inode */ + +#ifdef _KERNEL +/* + * Shorthand abbreviations of above. + */ +#define OPAQUE (UF_OPAQUE) +#define APPEND (UF_APPEND | SF_APPEND) +#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) +#define NOUNLINK (UF_NOUNLINK | SF_NOUNLINK) +#endif + +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +#define UTIME_NOW -1 +#define UTIME_OMIT -2 +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +#if __BSD_VISIBLE +int chflags(const char *, unsigned long); +int chflagsat(int, const char *, unsigned long, int); +#endif +int chmod(const char *, mode_t); +#if __BSD_VISIBLE +int fchflags(int, unsigned long); +#endif +#if __POSIX_VISIBLE >= 200112 +int fchmod(int, mode_t); +#endif +#if __POSIX_VISIBLE >= 200809 +int fchmodat(int, const char *, mode_t, int); +int futimens(int fd, const struct timespec times[2]); +int utimensat(int fd, const char *path, const struct timespec times[2], + int flag); +#endif +int fstat(int, struct stat *); +#if __BSD_VISIBLE +int lchflags(const char *, unsigned long); +int lchmod(const char *, mode_t); +#endif +#if __POSIX_VISIBLE >= 200112 +int lstat(const char * __restrict, struct stat * __restrict); +#endif +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +#if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE +int mknod(const char *, mode_t, dev_t); +#define _MKNOD_DECLARED +#endif +int stat(const char * __restrict, struct stat * __restrict); +mode_t umask(mode_t); +#if __POSIX_VISIBLE >= 200809 +int fstatat(int, const char *, struct stat *, int); +int mkdirat(int, const char *, mode_t); +int mkfifoat(int, const char *, mode_t); +#endif +#if __XSI_VISIBLE >= 700 +int mknodat(int, const char *, mode_t, dev_t); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_STAT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/statvfs.h b/lib/libc/include/any-freebsd-any/sys/statvfs.h new file mode 100644 index 000000000000..24fd8e02f6a6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/statvfs.h @@ -0,0 +1,81 @@ +/*- + * Copyright 2002 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_STATVFS_H_ +#define _SYS_STATVFS_H_ + +#include +#include + +/* + * POSIX says we must define the fsblkcnt_t and fsfilcnt_t types here. + * Note that these must be unsigned integer types, so we have to be + * careful in converting the signed statfs members to the unsigned + * statvfs members. (Well, actually, we don't -- see below -- but + * a quality implementation should.) + */ +#ifndef _FSBLKCNT_T_DECLARED /* always declared together */ +typedef __fsblkcnt_t fsblkcnt_t; +typedef __fsfilcnt_t fsfilcnt_t; +#define _FSBLKCNT_T_DECLARED +#endif + +/* + * The difference between `avail' and `free' is that `avail' represents + * space available to unprivileged processes, whereas `free' includes all + * unallocated space, including that reserved for privileged processes. + * Or at least, that's the most useful interpretation. (According to + * the letter of the standard, this entire interface is completely + * unspecified!) + */ +struct statvfs { + fsblkcnt_t f_bavail; /* Number of blocks */ + fsblkcnt_t f_bfree; + fsblkcnt_t f_blocks; + fsfilcnt_t f_favail; /* Number of files (e.g., inodes) */ + fsfilcnt_t f_ffree; + fsfilcnt_t f_files; + unsigned long f_bsize; /* Size of blocks counted above */ + unsigned long f_flag; + unsigned long f_frsize; /* Size of fragments */ + unsigned long f_fsid; /* Not meaningful */ + unsigned long f_namemax; /* Same as pathconf(_PC_NAME_MAX) */ +}; + +/* flag bits for f_flag: */ +#define ST_RDONLY 0x1 +#define ST_NOSUID 0x2 + +__BEGIN_DECLS +int fstatvfs(int, struct statvfs *); +int statvfs(const char *__restrict, struct statvfs *__restrict); +__END_DECLS +#endif /* _SYS_STATVFS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/stdatomic.h b/lib/libc/include/any-freebsd-any/sys/stdatomic.h new file mode 100644 index 000000000000..cac36fa6adf6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/stdatomic.h @@ -0,0 +1,410 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 Ed Schouten + * David Chisnall + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _STDATOMIC_H_ +#define _STDATOMIC_H_ + +#include +#include + +#if __has_extension(c_atomic) || __has_extension(cxx_atomic) +#define __CLANG_ATOMICS +#elif __GNUC_PREREQ__(4, 7) +#define __GNUC_ATOMICS +#elif defined(__GNUC__) +#define __SYNC_ATOMICS +#else +#error "stdatomic.h does not support your compiler" +#endif + +/* + * 7.17.1 Atomic lock-free macros. + */ + +#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE +#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE +#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE +#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE +#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE +#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE +#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_INT_LOCK_FREE +#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_LONG_LOCK_FREE +#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE +#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE +#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE +#endif + +/* + * 7.17.2 Initialization. + */ + +#if defined(__CLANG_ATOMICS) +#define ATOMIC_VAR_INIT(value) (value) +#define atomic_init(obj, value) __c11_atomic_init(obj, value) +#else +#define ATOMIC_VAR_INIT(value) { .__val = (value) } +#define atomic_init(obj, value) ((void)((obj)->__val = (value))) +#endif + +/* + * Clang and recent GCC both provide predefined macros for the memory + * orderings. If we are using a compiler that doesn't define them, use the + * clang values - these will be ignored in the fallback path. + */ + +#ifndef __ATOMIC_RELAXED +#define __ATOMIC_RELAXED 0 +#endif +#ifndef __ATOMIC_CONSUME +#define __ATOMIC_CONSUME 1 +#endif +#ifndef __ATOMIC_ACQUIRE +#define __ATOMIC_ACQUIRE 2 +#endif +#ifndef __ATOMIC_RELEASE +#define __ATOMIC_RELEASE 3 +#endif +#ifndef __ATOMIC_ACQ_REL +#define __ATOMIC_ACQ_REL 4 +#endif +#ifndef __ATOMIC_SEQ_CST +#define __ATOMIC_SEQ_CST 5 +#endif + +/* + * 7.17.3 Order and consistency. + * + * The memory_order_* constants that denote the barrier behaviour of the + * atomic operations. + */ + +typedef enum { + memory_order_relaxed = __ATOMIC_RELAXED, + memory_order_consume = __ATOMIC_CONSUME, + memory_order_acquire = __ATOMIC_ACQUIRE, + memory_order_release = __ATOMIC_RELEASE, + memory_order_acq_rel = __ATOMIC_ACQ_REL, + memory_order_seq_cst = __ATOMIC_SEQ_CST +} memory_order; + +/* + * 7.17.4 Fences. + */ + +static __inline void +atomic_thread_fence(memory_order __order __unused) +{ + +#ifdef __CLANG_ATOMICS + __c11_atomic_thread_fence(__order); +#elif defined(__GNUC_ATOMICS) + __atomic_thread_fence(__order); +#else + __sync_synchronize(); +#endif +} + +static __inline void +atomic_signal_fence(memory_order __order __unused) +{ + +#ifdef __CLANG_ATOMICS + __c11_atomic_signal_fence(__order); +#elif defined(__GNUC_ATOMICS) + __atomic_signal_fence(__order); +#else + __asm volatile ("" ::: "memory"); +#endif +} + +/* + * 7.17.5 Lock-free property. + */ + +#if defined(_KERNEL) +/* Atomics in kernelspace are always lock-free. */ +#define atomic_is_lock_free(obj) \ + ((void)(obj), (_Bool)1) +#elif defined(__CLANG_ATOMICS) || defined(__GNUC_ATOMICS) +#define atomic_is_lock_free(obj) \ + __atomic_is_lock_free(sizeof(*(obj)), obj) +#else +#define atomic_is_lock_free(obj) \ + ((void)(obj), sizeof((obj)->__val) <= sizeof(void *)) +#endif + +/* + * 7.17.6 Atomic integer types. + */ + +typedef _Atomic(_Bool) atomic_bool; +typedef _Atomic(char) atomic_char; +typedef _Atomic(signed char) atomic_schar; +typedef _Atomic(unsigned char) atomic_uchar; +typedef _Atomic(short) atomic_short; +typedef _Atomic(unsigned short) atomic_ushort; +typedef _Atomic(int) atomic_int; +typedef _Atomic(unsigned int) atomic_uint; +typedef _Atomic(long) atomic_long; +typedef _Atomic(unsigned long) atomic_ulong; +typedef _Atomic(long long) atomic_llong; +typedef _Atomic(unsigned long long) atomic_ullong; +typedef _Atomic(__char16_t) atomic_char16_t; +typedef _Atomic(__char32_t) atomic_char32_t; +typedef _Atomic(___wchar_t) atomic_wchar_t; +typedef _Atomic(__int_least8_t) atomic_int_least8_t; +typedef _Atomic(__uint_least8_t) atomic_uint_least8_t; +typedef _Atomic(__int_least16_t) atomic_int_least16_t; +typedef _Atomic(__uint_least16_t) atomic_uint_least16_t; +typedef _Atomic(__int_least32_t) atomic_int_least32_t; +typedef _Atomic(__uint_least32_t) atomic_uint_least32_t; +typedef _Atomic(__int_least64_t) atomic_int_least64_t; +typedef _Atomic(__uint_least64_t) atomic_uint_least64_t; +typedef _Atomic(__int_fast8_t) atomic_int_fast8_t; +typedef _Atomic(__uint_fast8_t) atomic_uint_fast8_t; +typedef _Atomic(__int_fast16_t) atomic_int_fast16_t; +typedef _Atomic(__uint_fast16_t) atomic_uint_fast16_t; +typedef _Atomic(__int_fast32_t) atomic_int_fast32_t; +typedef _Atomic(__uint_fast32_t) atomic_uint_fast32_t; +typedef _Atomic(__int_fast64_t) atomic_int_fast64_t; +typedef _Atomic(__uint_fast64_t) atomic_uint_fast64_t; +typedef _Atomic(__intptr_t) atomic_intptr_t; +typedef _Atomic(__uintptr_t) atomic_uintptr_t; +typedef _Atomic(__size_t) atomic_size_t; +typedef _Atomic(__ptrdiff_t) atomic_ptrdiff_t; +typedef _Atomic(__intmax_t) atomic_intmax_t; +typedef _Atomic(__uintmax_t) atomic_uintmax_t; + +/* + * 7.17.7 Operations on atomic types. + */ + +/* + * Compiler-specific operations. + */ + +#if defined(__CLANG_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_strong(object, expected, desired, \ + success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_weak(object, expected, desired, \ + success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __c11_atomic_exchange(object, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __c11_atomic_fetch_add(object, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __c11_atomic_fetch_and(object, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __c11_atomic_fetch_or(object, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __c11_atomic_fetch_sub(object, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __c11_atomic_fetch_xor(object, operand, order) +#define atomic_load_explicit(object, order) \ + __c11_atomic_load(object, order) +#define atomic_store_explicit(object, desired, order) \ + __c11_atomic_store(object, desired, order) +#elif defined(__GNUC_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(object, expected, \ + desired, 0, success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(object, expected, \ + desired, 1, success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __atomic_exchange_n(object, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __atomic_fetch_add(object, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __atomic_fetch_and(object, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __atomic_fetch_or(object, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __atomic_fetch_sub(object, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __atomic_fetch_xor(object, operand, order) +#define atomic_load_explicit(object, order) \ + __atomic_load_n(object, order) +#define atomic_store_explicit(object, desired, order) \ + __atomic_store_n(object, desired, order) +#else +#define __atomic_apply_stride(object, operand) \ + (((__typeof__((object)->__val))0) + (operand)) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) __extension__ ({ \ + __typeof__(expected) __ep = (expected); \ + __typeof__(*__ep) __e = *__ep; \ + (void)(success); (void)(failure); \ + (_Bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val, \ + __e, desired)) == __e); \ +}) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) +#if __has_builtin(__sync_swap) +/* Clang provides a full-barrier atomic exchange - use it if available. */ +#define atomic_exchange_explicit(object, desired, order) \ + ((void)(order), __sync_swap(&(object)->__val, desired)) +#else +/* + * __sync_lock_test_and_set() is only an acquire barrier in theory (although in + * practice it is usually a full barrier) so we need an explicit barrier before + * it. + */ +#define atomic_exchange_explicit(object, desired, order) \ +__extension__ ({ \ + __typeof__(object) __o = (object); \ + __typeof__(desired) __d = (desired); \ + (void)(order); \ + __sync_synchronize(); \ + __sync_lock_test_and_set(&(__o)->__val, __d); \ +}) +#endif +#define atomic_fetch_add_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_add(&(object)->__val, \ + __atomic_apply_stride(object, operand))) +#define atomic_fetch_and_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_and(&(object)->__val, operand)) +#define atomic_fetch_or_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_or(&(object)->__val, operand)) +#define atomic_fetch_sub_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_sub(&(object)->__val, \ + __atomic_apply_stride(object, operand))) +#define atomic_fetch_xor_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_xor(&(object)->__val, operand)) +#define atomic_load_explicit(object, order) \ + ((void)(order), __sync_fetch_and_add(&(object)->__val, 0)) +#define atomic_store_explicit(object, desired, order) \ + ((void)atomic_exchange_explicit(object, desired, order)) +#endif + +/* + * Convenience functions. + * + * Don't provide these in kernel space. In kernel space, we should be + * disciplined enough to always provide explicit barriers. + */ + +#ifndef _KERNEL +#define atomic_compare_exchange_strong(object, expected, desired) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_compare_exchange_weak(object, expected, desired) \ + atomic_compare_exchange_weak_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_exchange(object, desired) \ + atomic_exchange_explicit(object, desired, memory_order_seq_cst) +#define atomic_fetch_add(object, operand) \ + atomic_fetch_add_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_and(object, operand) \ + atomic_fetch_and_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_or(object, operand) \ + atomic_fetch_or_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_sub(object, operand) \ + atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_xor(object, operand) \ + atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst) +#define atomic_load(object) \ + atomic_load_explicit(object, memory_order_seq_cst) +#define atomic_store(object, desired) \ + atomic_store_explicit(object, desired, memory_order_seq_cst) +#endif /* !_KERNEL */ + +/* + * 7.17.8 Atomic flag type and operations. + * + * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some + * kind of compiler built-in type we could use? + */ + +typedef struct { + atomic_bool __flag; +} atomic_flag; + +#define ATOMIC_FLAG_INIT { ATOMIC_VAR_INIT(0) } + +static __inline _Bool +atomic_flag_test_and_set_explicit(volatile atomic_flag *__object, + memory_order __order) +{ + return (atomic_exchange_explicit(&__object->__flag, 1, __order)); +} + +static __inline void +atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order) +{ + + atomic_store_explicit(&__object->__flag, 0, __order); +} + +#ifndef _KERNEL +static __inline _Bool +atomic_flag_test_and_set(volatile atomic_flag *__object) +{ + + return (atomic_flag_test_and_set_explicit(__object, + memory_order_seq_cst)); +} + +static __inline void +atomic_flag_clear(volatile atomic_flag *__object) +{ + + atomic_flag_clear_explicit(__object, memory_order_seq_cst); +} +#endif /* !_KERNEL */ + +#endif /* !_STDATOMIC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/stddef.h b/lib/libc/include/any-freebsd-any/sys/stddef.h new file mode 100644 index 000000000000..eeff767bbf20 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/stddef.h @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Maxime Henrion + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_STDDEF_H_ +#define _SYS_STDDEF_H_ + +#include +#include +#include + +#ifndef _PTRDIFF_T_DECLARED +typedef __ptrdiff_t ptrdiff_t; +#define _PTRDIFF_T_DECLARED +#endif + +#define offsetof(type, field) __offsetof(type, field) + +#endif /* !_SYS_STDDEF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/stdint.h b/lib/libc/include/any-freebsd-any/sys/stdint.h new file mode 100644 index 000000000000..e951ac3c5df8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/stdint.h @@ -0,0 +1,78 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#include +#include + +typedef __int_least8_t int_least8_t; +typedef __int_least16_t int_least16_t; +typedef __int_least32_t int_least32_t; +typedef __int_least64_t int_least64_t; + +typedef __uint_least8_t uint_least8_t; +typedef __uint_least16_t uint_least16_t; +typedef __uint_least32_t uint_least32_t; +typedef __uint_least64_t uint_least64_t; + +typedef __int_fast8_t int_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __int_fast64_t int_fast64_t; + +typedef __uint_fast8_t uint_fast8_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __uint_fast64_t uint_fast64_t; + +/* GNU and Darwin define this and people seem to think it's portable */ +#if defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) +#define __WORDSIZE 64 +#else +#define __WORDSIZE 32 +#endif + +/* Limits of wchar_t. */ +#define WCHAR_MIN __WCHAR_MIN +#define WCHAR_MAX __WCHAR_MAX + +#if __EXT1_VISIBLE +/* ISO/IEC 9899:2011 K.3.4.4 */ +#ifndef RSIZE_MAX +#define RSIZE_MAX (SIZE_MAX >> 1) +#endif +#endif /* __EXT1_VISIBLE */ + +#endif /* !_SYS_STDINT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sun_disklabel.h b/lib/libc/include/any-freebsd-any/sys/sun_disklabel.h new file mode 100644 index 000000000000..942e1d3d11c2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sun_disklabel.h @@ -0,0 +1,125 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2004,2005 Joerg Wunsch + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)sun_disklabel.h 8.1 (Berkeley) 6/11/93 + * $NetBSD: disklabel.h,v 1.2 1998/08/22 14:55:28 mrg Exp $ + * + * $FreeBSD$ + */ + +#ifndef _SYS_SUN_DISKLABEL_H_ +#define _SYS_SUN_DISKLABEL_H_ + +/* + * SunOS/Solaris disk label layout (partial). + * + * Suns disk label format contains a lot of historical baggage which we + * ignore entirely. The structure below contains the relevant bits and the + * _enc/_dec functions encode/decode only these fields. + */ + +#define SUN_DKMAGIC 55998 +#define SUN_NPART 8 +#define SUN_RAWPART 2 +#define SUN_SIZE 512 +#define SUN_VTOC_VERSION 1 +#define SUN_VTOC_SANE 0x600DDEEE /* SVR4-compatible VTOC is "sane". */ +#define SUN_VOLNAME_LEN 8 +/* + * XXX: I am actually not sure if this should be "16 sectors" or "8192 bytes". + * XXX: Considering that Sun went to the effort of getting 512 byte compatible + * XXX: CDROM drives produced my guess is that Sun computers stand little or + * XXX: even no chance of running, much less booting on !=512 byte media. + * XXX: Define this is in terms of bytes since that is easier for us. + */ +#define SUN_BOOTSIZE 8192 + +/* partition info */ +struct sun_dkpart { + u_int32_t sdkp_cyloffset; /* starting cylinder */ + u_int32_t sdkp_nsectors; /* number of sectors */ +}; + +struct sun_vtoc_info { + u_int16_t svtoc_tag; /* partition tag */ + u_int16_t svtoc_flag; /* partition flags */ +}; + +/* known partition tag values */ +#define VTOC_UNASSIGNED 0x00 +#define VTOC_BOOT 0x01 +#define VTOC_ROOT 0x02 +#define VTOC_SWAP 0x03 +#define VTOC_USR 0x04 +#define VTOC_BACKUP 0x05 /* "c" partition, covers entire disk */ +#define VTOC_STAND 0x06 +#define VTOC_VAR 0x07 +#define VTOC_HOME 0x08 +#define VTOC_ALTSCTR 0x09 /* alternate sector partition */ +#define VTOC_CACHE 0x0a /* Solaris cachefs partition */ +#define VTOC_VXVM_PUB 0x0e /* VxVM public region */ +#define VTOC_VXVM_PRIV 0x0f /* VxVM private region */ + +/* VTOC partition flags */ +#define VTOC_UNMNT 0x01 /* unmountable partition */ +#define VTOC_RONLY 0x10 /* partition is read/only */ + +struct sun_disklabel { + char sl_text[128]; + + /* SVR4 VTOC information */ + u_int32_t sl_vtoc_vers; /* == SUN_VTOC_VERSION */ + char sl_vtoc_volname[SUN_VOLNAME_LEN]; + u_int16_t sl_vtoc_nparts; /* == SUN_NPART */ + struct sun_vtoc_info sl_vtoc_map[SUN_NPART]; /* partition tag/flag */ + u_int32_t sl_vtoc_sane; /* == SUN_VTOC_SANE */ + + /* Sun label information */ + u_int16_t sl_rpm; /* rotational speed */ + u_int16_t sl_pcylinders; /* number of physical cyls */ + u_int16_t sl_sparespercyl; /* spare sectors per cylinder */ + u_int16_t sl_interleave; /* interleave factor */ + u_int16_t sl_ncylinders; /* data cylinders */ + u_int16_t sl_acylinders; /* alternate cylinders */ + u_int16_t sl_ntracks; /* tracks per cylinder */ + u_int16_t sl_nsectors; /* sectors per track */ + struct sun_dkpart sl_part[SUN_NPART]; /* partition layout */ + u_int16_t sl_magic; /* == SUN_DKMAGIC */ +}; + +int sunlabel_dec(void const *pp, struct sun_disklabel *sl); +void sunlabel_enc(void *pp, struct sun_disklabel *sl); + +#endif /* _SYS_SUN_DISKLABEL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sx.h b/lib/libc/include/any-freebsd-any/sys/sx.h new file mode 100644 index 000000000000..817f0f97d38c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sx.h @@ -0,0 +1,304 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2007 Attilio Rao + * Copyright (c) 2001 Jason Evans + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SX_H_ +#define _SYS_SX_H_ + +#include +#include + +#ifdef _KERNEL +#include +#include +#include +#include +#endif + +/* + * In general, the sx locks and rwlocks use very similar algorithms. + * The main difference in the implementations is how threads are + * blocked when a lock is unavailable. For this, sx locks use sleep + * queues which do not support priority propagation, and rwlocks use + * turnstiles which do. + * + * The sx_lock field consists of several fields. The low bit + * indicates if the lock is locked with a shared or exclusive lock. A + * value of 0 indicates an exclusive lock, and a value of 1 indicates + * a shared lock. Bit 1 is a boolean indicating if there are any + * threads waiting for a shared lock. Bit 2 is a boolean indicating + * if there are any threads waiting for an exclusive lock. Bit 3 is a + * boolean indicating if an exclusive lock is recursively held. The + * rest of the variable's definition is dependent on the value of the + * first bit. For an exclusive lock, it is a pointer to the thread + * holding the lock, similar to the mtx_lock field of mutexes. For + * shared locks, it is a count of read locks that are held. + * + * When the lock is not locked by any thread, it is encoded as a + * shared lock with zero waiters. + */ + +#define SX_LOCK_SHARED 0x01 +#define SX_LOCK_SHARED_WAITERS 0x02 +#define SX_LOCK_EXCLUSIVE_WAITERS 0x04 +#define SX_LOCK_WRITE_SPINNER 0x08 +#define SX_LOCK_RECURSED 0x10 +#define SX_LOCK_FLAGMASK \ + (SX_LOCK_SHARED | SX_LOCK_SHARED_WAITERS | \ + SX_LOCK_EXCLUSIVE_WAITERS | SX_LOCK_RECURSED | SX_LOCK_WRITE_SPINNER) +#define SX_LOCK_WAITERS (SX_LOCK_SHARED_WAITERS | SX_LOCK_EXCLUSIVE_WAITERS) + +#define SX_OWNER(x) ((x) & ~SX_LOCK_FLAGMASK) +#define SX_SHARERS_SHIFT 5 +#define SX_SHARERS(x) (SX_OWNER(x) >> SX_SHARERS_SHIFT) +#define SX_SHARERS_LOCK(x) \ + ((x) << SX_SHARERS_SHIFT | SX_LOCK_SHARED) +#define SX_ONE_SHARER (1 << SX_SHARERS_SHIFT) + +#define SX_LOCK_UNLOCKED SX_SHARERS_LOCK(0) +#define SX_LOCK_DESTROYED \ + (SX_LOCK_SHARED_WAITERS | SX_LOCK_EXCLUSIVE_WAITERS) + +#ifdef _KERNEL + +#define sx_recurse lock_object.lo_data + +#define SX_READ_VALUE(sx) ((sx)->sx_lock) + +#define lv_sx_owner(v) \ + ((v & SX_LOCK_SHARED) ? NULL : (struct thread *)SX_OWNER(v)) + +/* + * Function prototipes. Routines that start with an underscore are not part + * of the public interface and are wrappered with a macro. + */ +void sx_sysinit(void *arg); +#define sx_init(sx, desc) sx_init_flags((sx), (desc), 0) +void sx_init_flags(struct sx *sx, const char *description, int opts); +void sx_destroy(struct sx *sx); +int sx_try_slock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF); +int sx_try_slock_(struct sx *sx, const char *file, int line); +int sx_try_xlock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF); +int sx_try_xlock_(struct sx *sx, const char *file, int line); +int sx_try_upgrade_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF); +int sx_try_upgrade_(struct sx *sx, const char *file, int line); +void sx_downgrade_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF); +void sx_downgrade_(struct sx *sx, const char *file, int line); +int _sx_slock_int(struct sx *sx, int opts LOCK_FILE_LINE_ARG_DEF); +int _sx_slock(struct sx *sx, int opts, const char *file, int line); +int _sx_xlock(struct sx *sx, int opts, const char *file, int line); +void _sx_sunlock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF); +void _sx_sunlock(struct sx *sx, const char *file, int line); +void _sx_xunlock(struct sx *sx, const char *file, int line); +int _sx_xlock_hard(struct sx *sx, uintptr_t x, int opts LOCK_FILE_LINE_ARG_DEF); +void _sx_xunlock_hard(struct sx *sx, uintptr_t x LOCK_FILE_LINE_ARG_DEF); +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +void _sx_assert(const struct sx *sx, int what, const char *file, int line); +#endif +#ifdef DDB +int sx_chain(struct thread *td, struct thread **ownerp); +#endif + +struct sx_args { + struct sx *sa_sx; + const char *sa_desc; + int sa_flags; +}; + +#define SX_SYSINIT_FLAGS(name, sxa, desc, flags) \ + static struct sx_args name##_args = { \ + (sxa), \ + (desc), \ + (flags) \ + }; \ + SYSINIT(name##_sx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + sx_sysinit, &name##_args); \ + SYSUNINIT(name##_sx_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + sx_destroy, (sxa)) + +#define SX_SYSINIT(name, sxa, desc) SX_SYSINIT_FLAGS(name, sxa, desc, 0) + +/* + * Full lock operations that are suitable to be inlined in non-debug kernels. + * If the lock can't be acquired or released trivially then the work is + * deferred to 'tougher' functions. + */ + +#if (LOCK_DEBUG == 0) +/* Acquire an exclusive lock. */ +static __inline int +__sx_xlock(struct sx *sx, struct thread *td, int opts, const char *file, + int line) +{ + uintptr_t tid = (uintptr_t)td; + uintptr_t v = SX_LOCK_UNLOCKED; + int error = 0; + + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(sx__acquire) || + !atomic_fcmpset_acq_ptr(&sx->sx_lock, &v, tid))) + error = _sx_xlock_hard(sx, v, opts); + + return (error); +} + +/* Release an exclusive lock. */ +static __inline void +__sx_xunlock(struct sx *sx, struct thread *td, const char *file, int line) +{ + uintptr_t x = (uintptr_t)td; + + if (__predict_false(LOCKSTAT_PROFILE_ENABLED(sx__release) || + !atomic_fcmpset_rel_ptr(&sx->sx_lock, &x, SX_LOCK_UNLOCKED))) + _sx_xunlock_hard(sx, x); +} +#endif + +/* + * Public interface for lock operations. + */ +#ifndef LOCK_DEBUG +#error "LOCK_DEBUG not defined, include before " +#endif +#if (LOCK_DEBUG > 0) || defined(SX_NOINLINE) +#define sx_xlock_(sx, file, line) \ + (void)_sx_xlock((sx), 0, (file), (line)) +#define sx_xlock_sig_(sx, file, line) \ + _sx_xlock((sx), SX_INTERRUPTIBLE, (file), (line)) +#define sx_xunlock_(sx, file, line) \ + _sx_xunlock((sx), (file), (line)) +#else +#define sx_xlock_(sx, file, line) \ + (void)__sx_xlock((sx), curthread, 0, (file), (line)) +#define sx_xlock_sig_(sx, file, line) \ + __sx_xlock((sx), curthread, SX_INTERRUPTIBLE, (file), (line)) +#define sx_xunlock_(sx, file, line) \ + __sx_xunlock((sx), curthread, (file), (line)) +#endif /* LOCK_DEBUG > 0 || SX_NOINLINE */ +#if (LOCK_DEBUG > 0) +#define sx_slock_(sx, file, line) \ + (void)_sx_slock((sx), 0, (file), (line)) +#define sx_slock_sig_(sx, file, line) \ + _sx_slock((sx), SX_INTERRUPTIBLE, (file) , (line)) +#define sx_sunlock_(sx, file, line) \ + _sx_sunlock((sx), (file), (line)) +#define sx_try_slock(sx) sx_try_slock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_xlock(sx) sx_try_xlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_upgrade(sx) sx_try_upgrade_((sx), LOCK_FILE, LOCK_LINE) +#define sx_downgrade(sx) sx_downgrade_((sx), LOCK_FILE, LOCK_LINE) +#else +#define sx_slock_(sx, file, line) \ + (void)_sx_slock_int((sx), 0) +#define sx_slock_sig_(sx, file, line) \ + _sx_slock_int((sx), SX_INTERRUPTIBLE) +#define sx_sunlock_(sx, file, line) \ + _sx_sunlock_int((sx)) +#define sx_try_slock(sx) sx_try_slock_int((sx)) +#define sx_try_xlock(sx) sx_try_xlock_int((sx)) +#define sx_try_upgrade(sx) sx_try_upgrade_int((sx)) +#define sx_downgrade(sx) sx_downgrade_int((sx)) +#endif +#ifdef INVARIANTS +#define sx_assert_(sx, what, file, line) \ + _sx_assert((sx), (what), (file), (line)) +#else +#define sx_assert_(sx, what, file, line) (void)0 +#endif + +#define sx_xlock(sx) sx_xlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_xlock_sig(sx) sx_xlock_sig_((sx), LOCK_FILE, LOCK_LINE) +#define sx_xunlock(sx) sx_xunlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_slock(sx) sx_slock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_slock_sig(sx) sx_slock_sig_((sx), LOCK_FILE, LOCK_LINE) +#define sx_sunlock(sx) sx_sunlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_assert(sx, what) sx_assert_((sx), (what), __FILE__, __LINE__) + +/* + * Return a pointer to the owning thread if the lock is exclusively + * locked. + */ +#define sx_xholder(sx) \ + ((sx)->sx_lock & SX_LOCK_SHARED ? NULL : \ + (struct thread *)SX_OWNER((sx)->sx_lock)) + +#define sx_xlocked(sx) \ + (((sx)->sx_lock & ~(SX_LOCK_FLAGMASK & ~SX_LOCK_SHARED)) == \ + (uintptr_t)curthread) + +#define sx_unlock_(sx, file, line) do { \ + if (sx_xlocked(sx)) \ + sx_xunlock_(sx, file, line); \ + else \ + sx_sunlock_(sx, file, line); \ +} while (0) + +#define sx_unlock(sx) sx_unlock_((sx), LOCK_FILE, LOCK_LINE) + +#define sx_sleep(chan, sx, pri, wmesg, timo) \ + _sleep((chan), &(sx)->lock_object, (pri), (wmesg), \ + tick_sbt * (timo), 0, C_HARDCLOCK) + +/* + * Options passed to sx_init_flags(). + */ +#define SX_DUPOK 0x01 +#define SX_NOPROFILE 0x02 +#define SX_NOWITNESS 0x04 +#define SX_QUIET 0x08 +#define SX_NOADAPTIVE 0x10 +#define SX_RECURSE 0x20 +#define SX_NEW 0x40 + +/* + * Options passed to sx_*lock_hard(). + */ +#define SX_INTERRUPTIBLE 0x40 + +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define SA_LOCKED LA_LOCKED +#define SA_SLOCKED LA_SLOCKED +#define SA_XLOCKED LA_XLOCKED +#define SA_UNLOCKED LA_UNLOCKED +#define SA_RECURSED LA_RECURSED +#define SA_NOTRECURSED LA_NOTRECURSED + +/* Backwards compatibility. */ +#define SX_LOCKED LA_LOCKED +#define SX_SLOCKED LA_SLOCKED +#define SX_XLOCKED LA_XLOCKED +#define SX_UNLOCKED LA_UNLOCKED +#define SX_RECURSED LA_RECURSED +#define SX_NOTRECURSED LA_NOTRECURSED +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_SX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/syscall.h b/lib/libc/include/any-freebsd-any/sys/syscall.h new file mode 100644 index 000000000000..43e352dd288d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/syscall.h @@ -0,0 +1,508 @@ +/* + * System call numbers. + * + * DO NOT EDIT-- this file is automatically @generated. + * $FreeBSD$ + */ + +#define SYS_syscall 0 +#define SYS_exit 1 +#define SYS_fork 2 +#define SYS_read 3 +#define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 +#define SYS_wait4 7 + /* 8 is old creat */ +#define SYS_link 9 +#define SYS_unlink 10 + /* 11 is obsolete execv */ +#define SYS_chdir 12 +#define SYS_fchdir 13 +#define SYS_freebsd11_mknod 14 +#define SYS_chmod 15 +#define SYS_chown 16 +#define SYS_break 17 + /* 18 is freebsd4 getfsstat */ + /* 19 is old lseek */ +#define SYS_getpid 20 +#define SYS_mount 21 +#define SYS_unmount 22 +#define SYS_setuid 23 +#define SYS_getuid 24 +#define SYS_geteuid 25 +#define SYS_ptrace 26 +#define SYS_recvmsg 27 +#define SYS_sendmsg 28 +#define SYS_recvfrom 29 +#define SYS_accept 30 +#define SYS_getpeername 31 +#define SYS_getsockname 32 +#define SYS_access 33 +#define SYS_chflags 34 +#define SYS_fchflags 35 +#define SYS_sync 36 +#define SYS_kill 37 + /* 38 is old stat */ +#define SYS_getppid 39 + /* 40 is old lstat */ +#define SYS_dup 41 +#define SYS_freebsd10_pipe 42 +#define SYS_getegid 43 +#define SYS_profil 44 +#define SYS_ktrace 45 + /* 46 is old sigaction */ +#define SYS_getgid 47 + /* 48 is old sigprocmask */ +#define SYS_getlogin 49 +#define SYS_setlogin 50 +#define SYS_acct 51 + /* 52 is old sigpending */ +#define SYS_sigaltstack 53 +#define SYS_ioctl 54 +#define SYS_reboot 55 +#define SYS_revoke 56 +#define SYS_symlink 57 +#define SYS_readlink 58 +#define SYS_execve 59 +#define SYS_umask 60 +#define SYS_chroot 61 + /* 62 is old fstat */ + /* 63 is old getkerninfo */ + /* 64 is old getpagesize */ +#define SYS_msync 65 +#define SYS_vfork 66 + /* 67 is obsolete vread */ + /* 68 is obsolete vwrite */ +#define SYS_sbrk 69 +#define SYS_sstk 70 + /* 71 is old mmap */ +#define SYS_freebsd11_vadvise 72 +#define SYS_munmap 73 +#define SYS_mprotect 74 +#define SYS_madvise 75 + /* 76 is obsolete vhangup */ + /* 77 is obsolete vlimit */ +#define SYS_mincore 78 +#define SYS_getgroups 79 +#define SYS_setgroups 80 +#define SYS_getpgrp 81 +#define SYS_setpgid 82 +#define SYS_setitimer 83 + /* 84 is old wait */ +#define SYS_swapon 85 +#define SYS_getitimer 86 + /* 87 is old gethostname */ + /* 88 is old sethostname */ +#define SYS_getdtablesize 89 +#define SYS_dup2 90 +#define SYS_fcntl 92 +#define SYS_select 93 +#define SYS_fsync 95 +#define SYS_setpriority 96 +#define SYS_socket 97 +#define SYS_connect 98 + /* 99 is old accept */ +#define SYS_getpriority 100 + /* 101 is old send */ + /* 102 is old recv */ + /* 103 is old sigreturn */ +#define SYS_bind 104 +#define SYS_setsockopt 105 +#define SYS_listen 106 + /* 107 is obsolete vtimes */ + /* 108 is old sigvec */ + /* 109 is old sigblock */ + /* 110 is old sigsetmask */ + /* 111 is old sigsuspend */ + /* 112 is old sigstack */ + /* 113 is old recvmsg */ + /* 114 is old sendmsg */ + /* 115 is obsolete vtrace */ +#define SYS_gettimeofday 116 +#define SYS_getrusage 117 +#define SYS_getsockopt 118 +#define SYS_readv 120 +#define SYS_writev 121 +#define SYS_settimeofday 122 +#define SYS_fchown 123 +#define SYS_fchmod 124 + /* 125 is old recvfrom */ +#define SYS_setreuid 126 +#define SYS_setregid 127 +#define SYS_rename 128 + /* 129 is old truncate */ + /* 130 is old ftruncate */ +#define SYS_flock 131 +#define SYS_mkfifo 132 +#define SYS_sendto 133 +#define SYS_shutdown 134 +#define SYS_socketpair 135 +#define SYS_mkdir 136 +#define SYS_rmdir 137 +#define SYS_utimes 138 + /* 139 is obsolete 4.2 sigreturn */ +#define SYS_adjtime 140 + /* 141 is old getpeername */ + /* 142 is old gethostid */ + /* 143 is old sethostid */ + /* 144 is old getrlimit */ + /* 145 is old setrlimit */ + /* 146 is old killpg */ +#define SYS_setsid 147 +#define SYS_quotactl 148 + /* 149 is old quota */ + /* 150 is old getsockname */ +#define SYS_nlm_syscall 154 +#define SYS_nfssvc 155 + /* 156 is old getdirentries */ + /* 157 is freebsd4 statfs */ + /* 158 is freebsd4 fstatfs */ +#define SYS_lgetfh 160 +#define SYS_getfh 161 + /* 162 is freebsd4 getdomainname */ + /* 163 is freebsd4 setdomainname */ + /* 164 is freebsd4 uname */ +#define SYS_sysarch 165 +#define SYS_rtprio 166 +#define SYS_semsys 169 +#define SYS_msgsys 170 +#define SYS_shmsys 171 + /* 173 is freebsd6 pread */ + /* 174 is freebsd6 pwrite */ +#define SYS_setfib 175 +#define SYS_ntp_adjtime 176 +#define SYS_setgid 181 +#define SYS_setegid 182 +#define SYS_seteuid 183 + /* 184 is obsolete lfs_bmapv */ + /* 185 is obsolete lfs_markv */ + /* 186 is obsolete lfs_segclean */ + /* 187 is obsolete lfs_segwait */ +#define SYS_freebsd11_stat 188 +#define SYS_freebsd11_fstat 189 +#define SYS_freebsd11_lstat 190 +#define SYS_pathconf 191 +#define SYS_fpathconf 192 +#define SYS_getrlimit 194 +#define SYS_setrlimit 195 +#define SYS_freebsd11_getdirentries 196 + /* 197 is freebsd6 mmap */ +#define SYS___syscall 198 + /* 199 is freebsd6 lseek */ + /* 200 is freebsd6 truncate */ + /* 201 is freebsd6 ftruncate */ +#define SYS___sysctl 202 +#define SYS_mlock 203 +#define SYS_munlock 204 +#define SYS_undelete 205 +#define SYS_futimes 206 +#define SYS_getpgid 207 +#define SYS_poll 209 +#define SYS_freebsd7___semctl 220 +#define SYS_semget 221 +#define SYS_semop 222 + /* 223 is obsolete semconfig */ +#define SYS_freebsd7_msgctl 224 +#define SYS_msgget 225 +#define SYS_msgsnd 226 +#define SYS_msgrcv 227 +#define SYS_shmat 228 +#define SYS_freebsd7_shmctl 229 +#define SYS_shmdt 230 +#define SYS_shmget 231 +#define SYS_clock_gettime 232 +#define SYS_clock_settime 233 +#define SYS_clock_getres 234 +#define SYS_ktimer_create 235 +#define SYS_ktimer_delete 236 +#define SYS_ktimer_settime 237 +#define SYS_ktimer_gettime 238 +#define SYS_ktimer_getoverrun 239 +#define SYS_nanosleep 240 +#define SYS_ffclock_getcounter 241 +#define SYS_ffclock_setestimate 242 +#define SYS_ffclock_getestimate 243 +#define SYS_clock_nanosleep 244 +#define SYS_clock_getcpuclockid2 247 +#define SYS_ntp_gettime 248 +#define SYS_minherit 250 +#define SYS_rfork 251 + /* 252 is obsolete openbsd_poll */ +#define SYS_issetugid 253 +#define SYS_lchown 254 +#define SYS_aio_read 255 +#define SYS_aio_write 256 +#define SYS_lio_listio 257 +#define SYS_freebsd11_getdents 272 +#define SYS_lchmod 274 + /* 275 is obsolete netbsd_lchown */ +#define SYS_lutimes 276 + /* 277 is obsolete netbsd_msync */ +#define SYS_freebsd11_nstat 278 +#define SYS_freebsd11_nfstat 279 +#define SYS_freebsd11_nlstat 280 +#define SYS_preadv 289 +#define SYS_pwritev 290 + /* 297 is freebsd4 fhstatfs */ +#define SYS_fhopen 298 +#define SYS_freebsd11_fhstat 299 +#define SYS_modnext 300 +#define SYS_modstat 301 +#define SYS_modfnext 302 +#define SYS_modfind 303 +#define SYS_kldload 304 +#define SYS_kldunload 305 +#define SYS_kldfind 306 +#define SYS_kldnext 307 +#define SYS_kldstat 308 +#define SYS_kldfirstmod 309 +#define SYS_getsid 310 +#define SYS_setresuid 311 +#define SYS_setresgid 312 + /* 313 is obsolete signanosleep */ +#define SYS_aio_return 314 +#define SYS_aio_suspend 315 +#define SYS_aio_cancel 316 +#define SYS_aio_error 317 + /* 318 is freebsd6 aio_read */ + /* 319 is freebsd6 aio_write */ + /* 320 is freebsd6 lio_listio */ +#define SYS_yield 321 + /* 322 is obsolete thr_sleep */ + /* 323 is obsolete thr_wakeup */ +#define SYS_mlockall 324 +#define SYS_munlockall 325 +#define SYS___getcwd 326 +#define SYS_sched_setparam 327 +#define SYS_sched_getparam 328 +#define SYS_sched_setscheduler 329 +#define SYS_sched_getscheduler 330 +#define SYS_sched_yield 331 +#define SYS_sched_get_priority_max 332 +#define SYS_sched_get_priority_min 333 +#define SYS_sched_rr_get_interval 334 +#define SYS_utrace 335 + /* 336 is freebsd4 sendfile */ +#define SYS_kldsym 337 +#define SYS_jail 338 +#define SYS_nnpfs_syscall 339 +#define SYS_sigprocmask 340 +#define SYS_sigsuspend 341 + /* 342 is freebsd4 sigaction */ +#define SYS_sigpending 343 + /* 344 is freebsd4 sigreturn */ +#define SYS_sigtimedwait 345 +#define SYS_sigwaitinfo 346 +#define SYS___acl_get_file 347 +#define SYS___acl_set_file 348 +#define SYS___acl_get_fd 349 +#define SYS___acl_set_fd 350 +#define SYS___acl_delete_file 351 +#define SYS___acl_delete_fd 352 +#define SYS___acl_aclcheck_file 353 +#define SYS___acl_aclcheck_fd 354 +#define SYS_extattrctl 355 +#define SYS_extattr_set_file 356 +#define SYS_extattr_get_file 357 +#define SYS_extattr_delete_file 358 +#define SYS_aio_waitcomplete 359 +#define SYS_getresuid 360 +#define SYS_getresgid 361 +#define SYS_kqueue 362 +#define SYS_freebsd11_kevent 363 + /* 364 is obsolete __cap_get_proc */ + /* 365 is obsolete __cap_set_proc */ + /* 366 is obsolete __cap_get_fd */ + /* 367 is obsolete __cap_get_file */ + /* 368 is obsolete __cap_set_fd */ + /* 369 is obsolete __cap_set_file */ +#define SYS_extattr_set_fd 371 +#define SYS_extattr_get_fd 372 +#define SYS_extattr_delete_fd 373 +#define SYS___setugid 374 + /* 375 is obsolete nfsclnt */ +#define SYS_eaccess 376 +#define SYS_afs3_syscall 377 +#define SYS_nmount 378 + /* 379 is obsolete kse_exit */ + /* 380 is obsolete kse_wakeup */ + /* 381 is obsolete kse_create */ + /* 382 is obsolete kse_thr_interrupt */ + /* 383 is obsolete kse_release */ +#define SYS___mac_get_proc 384 +#define SYS___mac_set_proc 385 +#define SYS___mac_get_fd 386 +#define SYS___mac_get_file 387 +#define SYS___mac_set_fd 388 +#define SYS___mac_set_file 389 +#define SYS_kenv 390 +#define SYS_lchflags 391 +#define SYS_uuidgen 392 +#define SYS_sendfile 393 +#define SYS_mac_syscall 394 +#define SYS_freebsd11_getfsstat 395 +#define SYS_freebsd11_statfs 396 +#define SYS_freebsd11_fstatfs 397 +#define SYS_freebsd11_fhstatfs 398 +#define SYS_ksem_close 400 +#define SYS_ksem_post 401 +#define SYS_ksem_wait 402 +#define SYS_ksem_trywait 403 +#define SYS_ksem_init 404 +#define SYS_ksem_open 405 +#define SYS_ksem_unlink 406 +#define SYS_ksem_getvalue 407 +#define SYS_ksem_destroy 408 +#define SYS___mac_get_pid 409 +#define SYS___mac_get_link 410 +#define SYS___mac_set_link 411 +#define SYS_extattr_set_link 412 +#define SYS_extattr_get_link 413 +#define SYS_extattr_delete_link 414 +#define SYS___mac_execve 415 +#define SYS_sigaction 416 +#define SYS_sigreturn 417 +#define SYS_getcontext 421 +#define SYS_setcontext 422 +#define SYS_swapcontext 423 +#define SYS_swapoff 424 +#define SYS___acl_get_link 425 +#define SYS___acl_set_link 426 +#define SYS___acl_delete_link 427 +#define SYS___acl_aclcheck_link 428 +#define SYS_sigwait 429 +#define SYS_thr_create 430 +#define SYS_thr_exit 431 +#define SYS_thr_self 432 +#define SYS_thr_kill 433 +#define SYS_jail_attach 436 +#define SYS_extattr_list_fd 437 +#define SYS_extattr_list_file 438 +#define SYS_extattr_list_link 439 + /* 440 is obsolete kse_switchin */ +#define SYS_ksem_timedwait 441 +#define SYS_thr_suspend 442 +#define SYS_thr_wake 443 +#define SYS_kldunloadf 444 +#define SYS_audit 445 +#define SYS_auditon 446 +#define SYS_getauid 447 +#define SYS_setauid 448 +#define SYS_getaudit 449 +#define SYS_setaudit 450 +#define SYS_getaudit_addr 451 +#define SYS_setaudit_addr 452 +#define SYS_auditctl 453 +#define SYS__umtx_op 454 +#define SYS_thr_new 455 +#define SYS_sigqueue 456 +#define SYS_kmq_open 457 +#define SYS_kmq_setattr 458 +#define SYS_kmq_timedreceive 459 +#define SYS_kmq_timedsend 460 +#define SYS_kmq_notify 461 +#define SYS_kmq_unlink 462 +#define SYS_abort2 463 +#define SYS_thr_set_name 464 +#define SYS_aio_fsync 465 +#define SYS_rtprio_thread 466 +#define SYS_sctp_peeloff 471 +#define SYS_sctp_generic_sendmsg 472 +#define SYS_sctp_generic_sendmsg_iov 473 +#define SYS_sctp_generic_recvmsg 474 +#define SYS_pread 475 +#define SYS_pwrite 476 +#define SYS_mmap 477 +#define SYS_lseek 478 +#define SYS_truncate 479 +#define SYS_ftruncate 480 +#define SYS_thr_kill2 481 +#define SYS_shm_open 482 +#define SYS_shm_unlink 483 +#define SYS_cpuset 484 +#define SYS_cpuset_setid 485 +#define SYS_cpuset_getid 486 +#define SYS_cpuset_getaffinity 487 +#define SYS_cpuset_setaffinity 488 +#define SYS_faccessat 489 +#define SYS_fchmodat 490 +#define SYS_fchownat 491 +#define SYS_fexecve 492 +#define SYS_freebsd11_fstatat 493 +#define SYS_futimesat 494 +#define SYS_linkat 495 +#define SYS_mkdirat 496 +#define SYS_mkfifoat 497 +#define SYS_freebsd11_mknodat 498 +#define SYS_openat 499 +#define SYS_readlinkat 500 +#define SYS_renameat 501 +#define SYS_symlinkat 502 +#define SYS_unlinkat 503 +#define SYS_posix_openpt 504 +#define SYS_gssd_syscall 505 +#define SYS_jail_get 506 +#define SYS_jail_set 507 +#define SYS_jail_remove 508 +#define SYS_closefrom 509 +#define SYS___semctl 510 +#define SYS_msgctl 511 +#define SYS_shmctl 512 +#define SYS_lpathconf 513 + /* 514 is obsolete cap_new */ +#define SYS___cap_rights_get 515 +#define SYS_cap_enter 516 +#define SYS_cap_getmode 517 +#define SYS_pdfork 518 +#define SYS_pdkill 519 +#define SYS_pdgetpid 520 +#define SYS_pselect 522 +#define SYS_getloginclass 523 +#define SYS_setloginclass 524 +#define SYS_rctl_get_racct 525 +#define SYS_rctl_get_rules 526 +#define SYS_rctl_get_limits 527 +#define SYS_rctl_add_rule 528 +#define SYS_rctl_remove_rule 529 +#define SYS_posix_fallocate 530 +#define SYS_posix_fadvise 531 +#define SYS_wait6 532 +#define SYS_cap_rights_limit 533 +#define SYS_cap_ioctls_limit 534 +#define SYS_cap_ioctls_get 535 +#define SYS_cap_fcntls_limit 536 +#define SYS_cap_fcntls_get 537 +#define SYS_bindat 538 +#define SYS_connectat 539 +#define SYS_chflagsat 540 +#define SYS_accept4 541 +#define SYS_pipe2 542 +#define SYS_aio_mlock 543 +#define SYS_procctl 544 +#define SYS_ppoll 545 +#define SYS_futimens 546 +#define SYS_utimensat 547 + /* 548 is obsolete numa_getaffinity */ + /* 549 is obsolete numa_setaffinity */ +#define SYS_fdatasync 550 +#define SYS_fstat 551 +#define SYS_fstatat 552 +#define SYS_fhstat 553 +#define SYS_getdirentries 554 +#define SYS_statfs 555 +#define SYS_fstatfs 556 +#define SYS_getfsstat 557 +#define SYS_fhstatfs 558 +#define SYS_mknodat 559 +#define SYS_kevent 560 +#define SYS_cpuset_getdomain 561 +#define SYS_cpuset_setdomain 562 +#define SYS_getrandom 563 +#define SYS_getfhat 564 +#define SYS_fhlink 565 +#define SYS_fhlinkat 566 +#define SYS_fhreadlink 567 +#define SYS___sysctlbyname 570 +#define SYS_close_range 575 +#define SYS_MAXSYSCALL 576 diff --git a/lib/libc/include/any-freebsd-any/sys/syscall.mk b/lib/libc/include/any-freebsd-any/sys/syscall.mk new file mode 100644 index 000000000000..f5e213d6f70e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/syscall.mk @@ -0,0 +1,413 @@ +# FreeBSD system call object files. +# DO NOT EDIT-- this file is automatically @generated. +# $FreeBSD$ +MIASM = \ + syscall.o \ + exit.o \ + fork.o \ + read.o \ + write.o \ + open.o \ + close.o \ + wait4.o \ + link.o \ + unlink.o \ + chdir.o \ + fchdir.o \ + freebsd11_mknod.o \ + chmod.o \ + chown.o \ + break.o \ + getpid.o \ + mount.o \ + unmount.o \ + setuid.o \ + getuid.o \ + geteuid.o \ + ptrace.o \ + recvmsg.o \ + sendmsg.o \ + recvfrom.o \ + accept.o \ + getpeername.o \ + getsockname.o \ + access.o \ + chflags.o \ + fchflags.o \ + sync.o \ + kill.o \ + getppid.o \ + dup.o \ + freebsd10_pipe.o \ + getegid.o \ + profil.o \ + ktrace.o \ + getgid.o \ + getlogin.o \ + setlogin.o \ + acct.o \ + sigaltstack.o \ + ioctl.o \ + reboot.o \ + revoke.o \ + symlink.o \ + readlink.o \ + execve.o \ + umask.o \ + chroot.o \ + msync.o \ + vfork.o \ + sbrk.o \ + sstk.o \ + freebsd11_vadvise.o \ + munmap.o \ + mprotect.o \ + madvise.o \ + mincore.o \ + getgroups.o \ + setgroups.o \ + getpgrp.o \ + setpgid.o \ + setitimer.o \ + swapon.o \ + getitimer.o \ + getdtablesize.o \ + dup2.o \ + fcntl.o \ + select.o \ + fsync.o \ + setpriority.o \ + socket.o \ + connect.o \ + getpriority.o \ + bind.o \ + setsockopt.o \ + listen.o \ + gettimeofday.o \ + getrusage.o \ + getsockopt.o \ + readv.o \ + writev.o \ + settimeofday.o \ + fchown.o \ + fchmod.o \ + setreuid.o \ + setregid.o \ + rename.o \ + flock.o \ + mkfifo.o \ + sendto.o \ + shutdown.o \ + socketpair.o \ + mkdir.o \ + rmdir.o \ + utimes.o \ + adjtime.o \ + setsid.o \ + quotactl.o \ + nlm_syscall.o \ + nfssvc.o \ + lgetfh.o \ + getfh.o \ + sysarch.o \ + rtprio.o \ + semsys.o \ + msgsys.o \ + shmsys.o \ + setfib.o \ + ntp_adjtime.o \ + setgid.o \ + setegid.o \ + seteuid.o \ + freebsd11_stat.o \ + freebsd11_fstat.o \ + freebsd11_lstat.o \ + pathconf.o \ + fpathconf.o \ + getrlimit.o \ + setrlimit.o \ + freebsd11_getdirentries.o \ + __syscall.o \ + __sysctl.o \ + mlock.o \ + munlock.o \ + undelete.o \ + futimes.o \ + getpgid.o \ + poll.o \ + freebsd7___semctl.o \ + semget.o \ + semop.o \ + freebsd7_msgctl.o \ + msgget.o \ + msgsnd.o \ + msgrcv.o \ + shmat.o \ + freebsd7_shmctl.o \ + shmdt.o \ + shmget.o \ + clock_gettime.o \ + clock_settime.o \ + clock_getres.o \ + ktimer_create.o \ + ktimer_delete.o \ + ktimer_settime.o \ + ktimer_gettime.o \ + ktimer_getoverrun.o \ + nanosleep.o \ + ffclock_getcounter.o \ + ffclock_setestimate.o \ + ffclock_getestimate.o \ + clock_nanosleep.o \ + clock_getcpuclockid2.o \ + ntp_gettime.o \ + minherit.o \ + rfork.o \ + issetugid.o \ + lchown.o \ + aio_read.o \ + aio_write.o \ + lio_listio.o \ + freebsd11_getdents.o \ + lchmod.o \ + lutimes.o \ + freebsd11_nstat.o \ + freebsd11_nfstat.o \ + freebsd11_nlstat.o \ + preadv.o \ + pwritev.o \ + fhopen.o \ + freebsd11_fhstat.o \ + modnext.o \ + modstat.o \ + modfnext.o \ + modfind.o \ + kldload.o \ + kldunload.o \ + kldfind.o \ + kldnext.o \ + kldstat.o \ + kldfirstmod.o \ + getsid.o \ + setresuid.o \ + setresgid.o \ + aio_return.o \ + aio_suspend.o \ + aio_cancel.o \ + aio_error.o \ + yield.o \ + mlockall.o \ + munlockall.o \ + __getcwd.o \ + sched_setparam.o \ + sched_getparam.o \ + sched_setscheduler.o \ + sched_getscheduler.o \ + sched_yield.o \ + sched_get_priority_max.o \ + sched_get_priority_min.o \ + sched_rr_get_interval.o \ + utrace.o \ + kldsym.o \ + jail.o \ + nnpfs_syscall.o \ + sigprocmask.o \ + sigsuspend.o \ + sigpending.o \ + sigtimedwait.o \ + sigwaitinfo.o \ + __acl_get_file.o \ + __acl_set_file.o \ + __acl_get_fd.o \ + __acl_set_fd.o \ + __acl_delete_file.o \ + __acl_delete_fd.o \ + __acl_aclcheck_file.o \ + __acl_aclcheck_fd.o \ + extattrctl.o \ + extattr_set_file.o \ + extattr_get_file.o \ + extattr_delete_file.o \ + aio_waitcomplete.o \ + getresuid.o \ + getresgid.o \ + kqueue.o \ + freebsd11_kevent.o \ + extattr_set_fd.o \ + extattr_get_fd.o \ + extattr_delete_fd.o \ + __setugid.o \ + eaccess.o \ + afs3_syscall.o \ + nmount.o \ + __mac_get_proc.o \ + __mac_set_proc.o \ + __mac_get_fd.o \ + __mac_get_file.o \ + __mac_set_fd.o \ + __mac_set_file.o \ + kenv.o \ + lchflags.o \ + uuidgen.o \ + sendfile.o \ + mac_syscall.o \ + freebsd11_getfsstat.o \ + freebsd11_statfs.o \ + freebsd11_fstatfs.o \ + freebsd11_fhstatfs.o \ + ksem_close.o \ + ksem_post.o \ + ksem_wait.o \ + ksem_trywait.o \ + ksem_init.o \ + ksem_open.o \ + ksem_unlink.o \ + ksem_getvalue.o \ + ksem_destroy.o \ + __mac_get_pid.o \ + __mac_get_link.o \ + __mac_set_link.o \ + extattr_set_link.o \ + extattr_get_link.o \ + extattr_delete_link.o \ + __mac_execve.o \ + sigaction.o \ + sigreturn.o \ + getcontext.o \ + setcontext.o \ + swapcontext.o \ + swapoff.o \ + __acl_get_link.o \ + __acl_set_link.o \ + __acl_delete_link.o \ + __acl_aclcheck_link.o \ + sigwait.o \ + thr_create.o \ + thr_exit.o \ + thr_self.o \ + thr_kill.o \ + jail_attach.o \ + extattr_list_fd.o \ + extattr_list_file.o \ + extattr_list_link.o \ + ksem_timedwait.o \ + thr_suspend.o \ + thr_wake.o \ + kldunloadf.o \ + audit.o \ + auditon.o \ + getauid.o \ + setauid.o \ + getaudit.o \ + setaudit.o \ + getaudit_addr.o \ + setaudit_addr.o \ + auditctl.o \ + _umtx_op.o \ + thr_new.o \ + sigqueue.o \ + kmq_open.o \ + kmq_setattr.o \ + kmq_timedreceive.o \ + kmq_timedsend.o \ + kmq_notify.o \ + kmq_unlink.o \ + abort2.o \ + thr_set_name.o \ + aio_fsync.o \ + rtprio_thread.o \ + sctp_peeloff.o \ + sctp_generic_sendmsg.o \ + sctp_generic_sendmsg_iov.o \ + sctp_generic_recvmsg.o \ + pread.o \ + pwrite.o \ + mmap.o \ + lseek.o \ + truncate.o \ + ftruncate.o \ + thr_kill2.o \ + shm_open.o \ + shm_unlink.o \ + cpuset.o \ + cpuset_setid.o \ + cpuset_getid.o \ + cpuset_getaffinity.o \ + cpuset_setaffinity.o \ + faccessat.o \ + fchmodat.o \ + fchownat.o \ + fexecve.o \ + freebsd11_fstatat.o \ + futimesat.o \ + linkat.o \ + mkdirat.o \ + mkfifoat.o \ + freebsd11_mknodat.o \ + openat.o \ + readlinkat.o \ + renameat.o \ + symlinkat.o \ + unlinkat.o \ + posix_openpt.o \ + gssd_syscall.o \ + jail_get.o \ + jail_set.o \ + jail_remove.o \ + closefrom.o \ + __semctl.o \ + msgctl.o \ + shmctl.o \ + lpathconf.o \ + __cap_rights_get.o \ + cap_enter.o \ + cap_getmode.o \ + pdfork.o \ + pdkill.o \ + pdgetpid.o \ + pselect.o \ + getloginclass.o \ + setloginclass.o \ + rctl_get_racct.o \ + rctl_get_rules.o \ + rctl_get_limits.o \ + rctl_add_rule.o \ + rctl_remove_rule.o \ + posix_fallocate.o \ + posix_fadvise.o \ + wait6.o \ + cap_rights_limit.o \ + cap_ioctls_limit.o \ + cap_ioctls_get.o \ + cap_fcntls_limit.o \ + cap_fcntls_get.o \ + bindat.o \ + connectat.o \ + chflagsat.o \ + accept4.o \ + pipe2.o \ + aio_mlock.o \ + procctl.o \ + ppoll.o \ + futimens.o \ + utimensat.o \ + fdatasync.o \ + fstat.o \ + fstatat.o \ + fhstat.o \ + getdirentries.o \ + statfs.o \ + fstatfs.o \ + getfsstat.o \ + fhstatfs.o \ + mknodat.o \ + kevent.o \ + cpuset_getdomain.o \ + cpuset_setdomain.o \ + getrandom.o \ + getfhat.o \ + fhlink.o \ + fhlinkat.o \ + fhreadlink.o \ + __sysctlbyname.o \ + close_range.o diff --git a/lib/libc/include/any-freebsd-any/sys/syscallsubr.h b/lib/libc/include/any-freebsd-any/sys/syscallsubr.h new file mode 100644 index 000000000000..3e57813f56c1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/syscallsubr.h @@ -0,0 +1,322 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Ian Dowse. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SYSCALLSUBR_H_ +#define _SYS_SYSCALLSUBR_H_ + +#include +#include +#include +#include +#include +#include +#include + +struct __wrusage; +struct file; +struct filecaps; +enum idtype; +struct itimerval; +struct image_args; +struct jail; +struct kevent; +struct kevent_copyops; +struct kld_file_stat; +struct ksiginfo; +struct mbuf; +struct msghdr; +struct msqid_ds; +struct pollfd; +struct ogetdirentries_args; +struct rlimit; +struct rusage; +struct sched_param; +union semun; +struct sockaddr; +struct stat; +struct thr_param; +struct uio; + +typedef int (*mmap_check_fp_fn)(struct file *, int, int, int); + +int kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, + size_t buflen, size_t path_max); +int kern_accept(struct thread *td, int s, struct sockaddr **name, + socklen_t *namelen, struct file **fp); +int kern_accept4(struct thread *td, int s, struct sockaddr **name, + socklen_t *namelen, int flags, struct file **fp); +int kern_accessat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, int flags, int mode); +int kern_adjtime(struct thread *td, struct timeval *delta, + struct timeval *olddelta); +int kern_alternate_path(struct thread *td, const char *prefix, const char *path, + enum uio_seg pathseg, char **pathbuf, int create, int dirfd); +int kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa); +int kern_break(struct thread *td, uintptr_t *addr); +int kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds, + size_t ncmds); +int kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights); +int kern_chdir(struct thread *td, char *path, enum uio_seg pathseg); +int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id); +int kern_clock_getres(struct thread *td, clockid_t clock_id, + struct timespec *ts); +int kern_clock_gettime(struct thread *td, clockid_t clock_id, + struct timespec *ats); +int kern_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags, + const struct timespec *rqtp, struct timespec *rmtp); +int kern_clock_settime(struct thread *td, clockid_t clock_id, + struct timespec *ats); +void kern_thread_cputime(struct thread *targettd, struct timespec *ats); +void kern_process_cputime(struct proc *targetp, struct timespec *ats); +int kern_close_range(struct thread *td, u_int lowfd, u_int highfd); +int kern_close(struct thread *td, int fd); +int kern_connectat(struct thread *td, int dirfd, int fd, + struct sockaddr *sa); +int kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *maskp); +int kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, size_t cpusetsize, + const cpuset_t *maskp); +int kern_cpuset_getdomain(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, size_t domainsetsize, + domainset_t *maskp, int *policyp); +int kern_cpuset_setdomain(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, size_t domainsetsize, + const domainset_t *maskp, int policy); +int kern_cpuset_getid(struct thread *td, cpulevel_t level, + cpuwhich_t which, id_t id, cpusetid_t *setid); +int kern_cpuset_setid(struct thread *td, cpuwhich_t which, + id_t id, cpusetid_t setid); +int kern_dup(struct thread *td, u_int mode, int flags, int old, int new); +int kern_execve(struct thread *td, struct image_args *args, + struct mac *mac_p); +int kern_fchmodat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, mode_t mode, int flag); +int kern_fchownat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, int uid, int gid, int flag); +int kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg); +int kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg); +int kern_fhstat(struct thread *td, fhandle_t fh, struct stat *buf); +int kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf); +int kern_fpathconf(struct thread *td, int fd, int name, long *valuep); +int kern_fstat(struct thread *td, int fd, struct stat *sbp); +int kern_fstatfs(struct thread *td, int fd, struct statfs *buf); +int kern_fsync(struct thread *td, int fd, bool fullsync); +int kern_ftruncate(struct thread *td, int fd, off_t length); +int kern_futimes(struct thread *td, int fd, struct timeval *tptr, + enum uio_seg tptrseg); +int kern_futimens(struct thread *td, int fd, struct timespec *tptr, + enum uio_seg tptrseg); +int kern_getdirentries(struct thread *td, int fd, char *buf, size_t count, + off_t *basep, ssize_t *residp, enum uio_seg bufseg); +int kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, + size_t *countp, enum uio_seg bufseg, int mode); +int kern_getitimer(struct thread *, u_int, struct itimerval *); +int kern_getppid(struct thread *); +int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, + socklen_t *alen); +int kern_getrusage(struct thread *td, int who, struct rusage *rup); +int kern_getsockname(struct thread *td, int fd, struct sockaddr **sa, + socklen_t *alen); +int kern_getsockopt(struct thread *td, int s, int level, int name, + void *optval, enum uio_seg valseg, socklen_t *valsize); +int kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data); +int kern_jail(struct thread *td, struct jail *j); +int kern_jail_get(struct thread *td, struct uio *options, int flags); +int kern_jail_set(struct thread *td, struct uio *options, int flags); +int kern_kevent(struct thread *td, int fd, int nchanges, int nevents, + struct kevent_copyops *k_ops, const struct timespec *timeout); +int kern_kevent_anonymous(struct thread *td, int nevents, + struct kevent_copyops *k_ops); +int kern_kevent_fp(struct thread *td, struct file *fp, int nchanges, + int nevents, struct kevent_copyops *k_ops, + const struct timespec *timeout); +int kern_kqueue(struct thread *td, int flags, struct filecaps *fcaps); +int kern_kldload(struct thread *td, const char *file, int *fileid); +int kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat); +int kern_kldunload(struct thread *td, int fileid, int flags); +int kern_linkat(struct thread *td, int fd1, int fd2, char *path1, + char *path2, enum uio_seg segflg, int follow); +int kern_listen(struct thread *td, int s, int backlog); +int kern_lseek(struct thread *td, int fd, off_t offset, int whence); +int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg, + struct timeval *tptr, enum uio_seg tptrseg); +int kern_madvise(struct thread *td, uintptr_t addr, size_t len, int behav); +int kern_mincore(struct thread *td, uintptr_t addr, size_t len, char *vec); +int kern_minherit(struct thread *td, uintptr_t addr, size_t len, + int inherit); +int kern_mkdirat(struct thread *td, int fd, char *path, + enum uio_seg segflg, int mode); +int kern_mkfifoat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, int mode); +int kern_mknodat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, int mode, dev_t dev); +int kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr, + size_t len); +int kern_mmap(struct thread *td, uintptr_t addr, size_t size, int prot, + int flags, int fd, off_t pos); +int kern_mmap_fpcheck(struct thread *td, uintptr_t addr, size_t len, + int prot, int flags, int fd, off_t pos, + mmap_check_fp_fn check_fp_fn); +int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, int prot); +int kern_msgctl(struct thread *, int, int, struct msqid_ds *); +int kern_msgrcv(struct thread *, int, void *, size_t, long, int, long *); +int kern_msgsnd(struct thread *, int, const void *, size_t, int, long); +int kern_msync(struct thread *td, uintptr_t addr, size_t size, int flags); +int kern_munlock(struct thread *td, uintptr_t addr, size_t size); +int kern_munmap(struct thread *td, uintptr_t addr, size_t size); +int kern_nanosleep(struct thread *td, struct timespec *rqt, + struct timespec *rmt); +int kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap, + long *ploff); +int kern_openat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, int flags, int mode); +int kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg, + int name, u_long flags, long *valuep); +int kern_pipe(struct thread *td, int fildes[2], int flags, + struct filecaps *fcaps1, struct filecaps *fcaps2); +int kern_poll(struct thread *td, struct pollfd *fds, u_int nfds, + struct timespec *tsp, sigset_t *uset); +int kern_posix_error(struct thread *td, int error); +int kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len, + int advice); +int kern_posix_fallocate(struct thread *td, int fd, off_t offset, + off_t len); +int kern_procctl(struct thread *td, enum idtype idtype, id_t id, int com, + void *data); +int kern_pread(struct thread *td, int fd, void *buf, size_t nbyte, + off_t offset); +int kern_preadv(struct thread *td, int fd, struct uio *auio, off_t offset); +int kern_pselect(struct thread *td, int nd, fd_set *in, fd_set *ou, + fd_set *ex, struct timeval *tvp, sigset_t *uset, int abi_nfdbits); +int kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, + int data); +int kern_pwrite(struct thread *td, int fd, const void *buf, size_t nbyte, + off_t offset); +int kern_pwritev(struct thread *td, int fd, struct uio *auio, off_t offset); +int kern_readlinkat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, char *buf, enum uio_seg bufseg, size_t count); +int kern_readv(struct thread *td, int fd, struct uio *auio); +int kern_recvit(struct thread *td, int s, struct msghdr *mp, + enum uio_seg fromseg, struct mbuf **controlp); +int kern_renameat(struct thread *td, int oldfd, char *old, int newfd, + char *new, enum uio_seg pathseg); +int kern_rmdirat(struct thread *td, int fd, char *path, + enum uio_seg pathseg); +int kern_sched_getparam(struct thread *td, struct thread *targettd, + struct sched_param *param); +int kern_sched_getscheduler(struct thread *td, struct thread *targettd, + int *policy); +int kern_sched_setparam(struct thread *td, struct thread *targettd, + struct sched_param *param); +int kern_sched_setscheduler(struct thread *td, struct thread *targettd, + int policy, struct sched_param *param); +int kern_sched_rr_get_interval(struct thread *td, pid_t pid, + struct timespec *ts); +int kern_sched_rr_get_interval_td(struct thread *td, struct thread *targettd, + struct timespec *ts); +int kern_semctl(struct thread *td, int semid, int semnum, int cmd, + union semun *arg, register_t *rval); +int kern_select(struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou, + fd_set *fd_ex, struct timeval *tvp, int abi_nfdbits); +int kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, + struct mbuf *control, enum uio_seg segflg); +int kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups); +int kern_setitimer(struct thread *, u_int, struct itimerval *, + struct itimerval *); +int kern_setrlimit(struct thread *, u_int, struct rlimit *); +int kern_setsockopt(struct thread *td, int s, int level, int name, + void *optval, enum uio_seg valseg, socklen_t valsize); +int kern_settimeofday(struct thread *td, struct timeval *tv, + struct timezone *tzp); +int kern_shm_open(struct thread *td, const char *userpath, int flags, + mode_t mode, struct filecaps *fcaps); +int kern_shmat(struct thread *td, int shmid, const void *shmaddr, + int shmflg); +int kern_shmctl(struct thread *td, int shmid, int cmd, void *buf, + size_t *bufsz); +int kern_shutdown(struct thread *td, int s, int how); +int kern_sigaction(struct thread *td, int sig, const struct sigaction *act, + struct sigaction *oact, int flags); +int kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss); +int kern_sigprocmask(struct thread *td, int how, + sigset_t *set, sigset_t *oset, int flags); +int kern_sigsuspend(struct thread *td, sigset_t mask); +int kern_sigtimedwait(struct thread *td, sigset_t waitset, + struct ksiginfo *ksi, struct timespec *timeout); +int kern_sigqueue(struct thread *td, pid_t pid, int signum, + union sigval *value); +int kern_socket(struct thread *td, int domain, int type, int protocol); +int kern_statat(struct thread *td, int flag, int fd, char *path, + enum uio_seg pathseg, struct stat *sbp, + void (*hook)(struct vnode *vp, struct stat *sbp)); +int kern_statfs(struct thread *td, char *path, enum uio_seg pathseg, + struct statfs *buf); +int kern_symlinkat(struct thread *td, char *path1, int fd, char *path2, + enum uio_seg segflg); +int kern_ktimer_create(struct thread *td, clockid_t clock_id, + struct sigevent *evp, int *timerid, int preset_id); +int kern_ktimer_delete(struct thread *, int); +int kern_ktimer_settime(struct thread *td, int timer_id, int flags, + struct itimerspec *val, struct itimerspec *oval); +int kern_ktimer_gettime(struct thread *td, int timer_id, + struct itimerspec *val); +int kern_ktimer_getoverrun(struct thread *td, int timer_id); +int kern_thr_alloc(struct proc *, int pages, struct thread **); +int kern_thr_exit(struct thread *td); +int kern_thr_new(struct thread *td, struct thr_param *param); +int kern_thr_suspend(struct thread *td, struct timespec *tsp); +int kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, + off_t length); +int kern_unlinkat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, ino_t oldinum); +int kern_utimesat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, struct timeval *tptr, enum uio_seg tptrseg); +int kern_utimensat(struct thread *td, int fd, char *path, + enum uio_seg pathseg, struct timespec *tptr, enum uio_seg tptrseg, + int follow); +int kern_wait(struct thread *td, pid_t pid, int *status, int options, + struct rusage *rup); +int kern_wait6(struct thread *td, enum idtype idtype, id_t id, int *status, + int options, struct __wrusage *wrup, siginfo_t *sip); +int kern_writev(struct thread *td, int fd, struct uio *auio); +int kern_socketpair(struct thread *td, int domain, int type, int protocol, + int *rsv); + +/* flags for kern_sigaction */ +#define KSA_OSIGSET 0x0001 /* uses osigact_t */ +#define KSA_FREEBSD4 0x0002 /* uses ucontext4 */ + +struct freebsd11_dirent; + +int freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int + count, long *basep, void (*func)(struct freebsd11_dirent *)); + +#endif /* !_SYS_SYSCALLSUBR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sysctl.h b/lib/libc/include/any-freebsd-any/sys/sysctl.h new file mode 100644 index 000000000000..9019bffeec1e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sysctl.h @@ -0,0 +1,1122 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Karels at Berkeley Software Design, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_SYSCTL_H_ +#define _SYS_SYSCTL_H_ + +#ifdef _KERNEL +#include +#endif + +struct thread; +/* + * Definitions for sysctl call. The sysctl call uses a hierarchical name + * for objects that can be examined or modified. The name is expressed as + * a sequence of integers. Like a file path name, the meaning of each + * component depends on its place in the hierarchy. The top-level and kern + * identifiers are defined here, and other identifiers are defined in the + * respective subsystem header files. + */ + +#define CTL_MAXNAME 24 /* largest number of components supported */ + +/* + * Each subsystem defined by sysctl defines a list of variables + * for that subsystem. Each name is either a node with further + * levels defined below it, or it is a leaf of some particular + * type given below. Each sysctl level defines a set of name/type + * pairs to be used by sysctl(8) in manipulating the subsystem. + */ +struct ctlname { + char *ctl_name; /* subsystem name */ + int ctl_type; /* type of name */ +}; + +#define CTLTYPE 0xf /* mask for the type */ +#define CTLTYPE_NODE 1 /* name is a node */ +#define CTLTYPE_INT 2 /* name describes an integer */ +#define CTLTYPE_STRING 3 /* name describes a string */ +#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */ +#define CTLTYPE_OPAQUE 5 /* name describes a structure */ +#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */ +#define CTLTYPE_UINT 6 /* name describes an unsigned integer */ +#define CTLTYPE_LONG 7 /* name describes a long */ +#define CTLTYPE_ULONG 8 /* name describes an unsigned long */ +#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */ +#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */ +#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */ +#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */ +#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */ +#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */ +#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */ + +#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */ +#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */ +#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR) +#define CTLFLAG_DORMANT 0x20000000 /* This sysctl is not active yet */ +#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */ +#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */ +#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */ +#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */ +#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */ +#define CTLMASK_SECURE 0x00F00000 /* Secure level */ +#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */ +#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN) +#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN) +#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */ +#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */ +#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */ +#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */ +#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */ +#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */ +#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */ +#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR) + +/* + * Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1. + * + * Secure when the securelevel is raised to at least N. + */ +#define CTLSHIFT_SECURE 20 +#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE)) +#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE)) +#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE)) + +/* + * USE THIS instead of a hardwired number from the categories below + * to get dynamically assigned sysctl entries using the linker-set + * technology. This is the way nearly all new sysctl variables should + * be implemented. + * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); + */ +#define OID_AUTO (-1) + +/* + * The starting number for dynamically-assigned entries. WARNING! + * ALL static sysctl entries should have numbers LESS than this! + */ +#define CTL_AUTO_START 0x100 + +#ifdef _KERNEL +#include + +#ifdef KLD_MODULE +/* XXX allow overspecification of type in external kernel modules */ +#define SYSCTL_CT_ASSERT_MASK CTLTYPE +#else +#define SYSCTL_CT_ASSERT_MASK 0 +#endif + +#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \ + intmax_t arg2, struct sysctl_req *req + +/* definitions for sysctl_req 'lock' member */ +#define REQ_UNWIRED 1 +#define REQ_WIRED 2 + +/* definitions for sysctl_req 'flags' member */ +#if defined(__aarch64__) || defined(__amd64__) || defined(__powerpc64__) ||\ + (defined(__mips__) && defined(__mips_n64)) +#define SCTL_MASK32 1 /* 32 bit emulation */ +#endif + +/* + * This describes the access space for a sysctl request. This is needed + * so that we can use the interface from the kernel or from user-space. + */ +struct sysctl_req { + struct thread *td; /* used for access checking */ + int lock; /* wiring state */ + void *oldptr; + size_t oldlen; + size_t oldidx; + int (*oldfunc)(struct sysctl_req *, const void *, size_t); + void *newptr; + size_t newlen; + size_t newidx; + int (*newfunc)(struct sysctl_req *, void *, size_t); + size_t validlen; + int flags; +}; + +SLIST_HEAD(sysctl_oid_list, sysctl_oid); + +/* + * This describes one "oid" in the MIB tree. Potentially more nodes can + * be hidden behind it, expanded by the handler. + */ +struct sysctl_oid { + struct sysctl_oid_list oid_children; + struct sysctl_oid_list *oid_parent; + SLIST_ENTRY(sysctl_oid) oid_link; + int oid_number; + u_int oid_kind; + void *oid_arg1; + intmax_t oid_arg2; + const char *oid_name; + int (*oid_handler)(SYSCTL_HANDLER_ARGS); + const char *oid_fmt; + int oid_refcnt; + u_int oid_running; + const char *oid_descr; + const char *oid_label; +}; + +#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) +#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l) +#define SYSCTL_OUT_STR(r, p) (r->oldfunc)(r, p, strlen(p) + 1) + +int sysctl_handle_bool(SYSCTL_HANDLER_ARGS); +int sysctl_handle_8(SYSCTL_HANDLER_ARGS); +int sysctl_handle_16(SYSCTL_HANDLER_ARGS); +int sysctl_handle_32(SYSCTL_HANDLER_ARGS); +int sysctl_handle_64(SYSCTL_HANDLER_ARGS); +int sysctl_handle_int(SYSCTL_HANDLER_ARGS); +int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS); +int sysctl_handle_long(SYSCTL_HANDLER_ARGS); +int sysctl_handle_string(SYSCTL_HANDLER_ARGS); +int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS); +int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS); +int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS); + +int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS); +int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS); + +int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS); + +int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS); +int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS); +int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS); + +/* + * These functions are used to add/remove an oid from the mib. + */ +void sysctl_register_oid(struct sysctl_oid *oidp); +void sysctl_register_disabled_oid(struct sysctl_oid *oidp); +void sysctl_enable_oid(struct sysctl_oid *oidp); +void sysctl_unregister_oid(struct sysctl_oid *oidp); + +/* Declare a static oid to allow child oids to be added to it. */ +#define SYSCTL_DECL(name) \ + extern struct sysctl_oid sysctl__##name + +/* Hide these in macros. */ +#define SYSCTL_CHILDREN(oid_ptr) (&(oid_ptr)->oid_children) +#define SYSCTL_PARENT(oid_ptr) \ + (((oid_ptr)->oid_parent != &sysctl__children) ? \ + __containerof((oid_ptr)->oid_parent, struct sysctl_oid, \ + oid_children) : (struct sysctl_oid *)NULL) +#define SYSCTL_STATIC_CHILDREN(oid_name) (&sysctl__##oid_name.oid_children) + +/* === Structs and macros related to context handling. === */ + +/* All dynamically created sysctls can be tracked in a context list. */ +struct sysctl_ctx_entry { + struct sysctl_oid *entry; + TAILQ_ENTRY(sysctl_ctx_entry) link; +}; + +TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); + +#define SYSCTL_NODE_CHILDREN(parent, name) \ + sysctl__##parent##_##name.oid_children + +#ifndef NO_SYSCTL_DESCR +#define __DESCR(d) d +#else +#define __DESCR(d) "" +#endif + +/* This macro is only for internal use */ +#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ + struct sysctl_oid id = { \ + .oid_parent = (parent_child_head), \ + .oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \ + .oid_number = (nbr), \ + .oid_kind = (kind), \ + .oid_arg1 = (a1), \ + .oid_arg2 = (a2), \ + .oid_name = (name), \ + .oid_handler = (handler), \ + .oid_fmt = (fmt), \ + .oid_descr = __DESCR(descr), \ + .oid_label = (label), \ + }; \ + DATA_SET(sysctl_set, id) + +/* This constructs a static "raw" MIB oid. */ +#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ + SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, \ + handler, fmt, descr, NULL) + +#define SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ + static SYSCTL_OID_RAW(sysctl__##parent##_##name, \ + SYSCTL_CHILDREN(&sysctl__##parent), \ + nbr, #name, kind, a1, a2, handler, fmt, descr, label) + +/* This constructs a global "raw" MIB oid. */ +#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ + SYSCTL_OID_RAW(sysctl__##parent##_##name, \ + SYSCTL_CHILDREN(&sysctl__##parent), \ + nbr, #name, kind, a1, a2, handler, fmt, descr, label) + +#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr), NULL) + +/* This constructs a root node from which other nodes can hang. */ +#define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \ + SYSCTL_OID_RAW(sysctl___##name, &sysctl__children, \ + nbr, #name, CTLTYPE_NODE|(access), NULL, 0, \ + handler, "N", descr, NULL); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) + +/* This constructs a node from which other oids can hang. */ +#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ + SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL) + +#define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \ + SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \ + NULL, 0, handler, "N", descr, label); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) + +#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ + SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \ + handler, descr, NULL) + +#define SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \ +({ \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ + NULL, 0, handler, "N", __DESCR(descr), label); \ +}) + +#define SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr) \ +({ \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ + sysctl_add_oid(ctx, &sysctl__children, nbr, name, \ + CTLTYPE_NODE|(access), \ + NULL, 0, handler, "N", __DESCR(descr), NULL); \ +}) + +/* Oid for a string. len can be 0 to indicate '\0' termination. */ +#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \ + arg, len, sysctl_handle_string, "A", descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING) + +#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \ +({ \ + char *__arg = (arg); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ + __arg, len, sysctl_handle_string, "A", __DESCR(descr), \ + NULL); \ +}) + +/* Oid for a constant '\0' terminated string. */ +#define SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \ + __DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \ + CTASSERT(!(access & CTLFLAG_WR)); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING) + +#define SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \ +({ \ + char *__arg = __DECONST(char *, arg); \ + CTASSERT(!(access & CTLFLAG_WR)); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ + __arg, 0, sysctl_handle_string, "A", __DESCR(descr), \ + NULL); \ +}) + +/* Oid for a bool. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_BOOL_PTR ((bool *)NULL) +#define SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_bool, "CU", descr); \ + CTASSERT(((access) & CTLTYPE) == 0 && \ + sizeof(bool) == sizeof(*(ptr))) + +#define SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + bool *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr), \ + NULL); \ +}) + +/* Oid for a signed 8-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_S8_PTR ((int8_t *)NULL) +#define SYSCTL_S8(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_8, "C", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \ + sizeof(int8_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + int8_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned 8-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_U8_PTR ((uint8_t *)NULL) +#define SYSCTL_U8(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_8, "CU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \ + sizeof(uint8_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + uint8_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL); \ +}) + +/* Oid for a signed 16-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_S16_PTR ((int16_t *)NULL) +#define SYSCTL_S16(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_16, "S", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \ + sizeof(int16_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + int16_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned 16-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_U16_PTR ((uint16_t *)NULL) +#define SYSCTL_U16(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_16, "SU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \ + sizeof(uint16_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + uint16_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL); \ +}) + +/* Oid for a signed 32-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_S32_PTR ((int32_t *)NULL) +#define SYSCTL_S32(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_32, "I", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \ + sizeof(int32_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + int32_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned 32-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_U32_PTR ((uint32_t *)NULL) +#define SYSCTL_U32(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_32, "IU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \ + sizeof(uint32_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + uint32_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL); \ +}) + +/* Oid for a signed 64-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_S64_PTR ((int64_t *)NULL) +#define SYSCTL_S64(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_64, "Q", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \ + sizeof(int64_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + int64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned 64-bit int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_U64_PTR ((uint64_t *)NULL) +#define SYSCTL_U64(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_64, "QU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ + sizeof(uint64_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + uint64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ +}) + +/* Oid for an int. If ptr is SYSCTL_NULL_INT_PTR, val is returned. */ +#define SYSCTL_NULL_INT_PTR ((int *)NULL) +#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL) + +#define SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \ + SYSCTL_OID_WITH_LABEL(parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_int, "I", descr, label); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \ + sizeof(int) == sizeof(*(ptr))) + +#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + int *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned int. If ptr is NULL, val is returned. */ +#define SYSCTL_NULL_UINT_PTR ((unsigned *)NULL) +#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_int, "IU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \ + sizeof(unsigned) == sizeof(*(ptr))) + +#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \ +({ \ + unsigned *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ + __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL); \ +}) + +/* Oid for a long. The pointer must be non NULL. */ +#define SYSCTL_NULL_LONG_PTR ((long *)NULL) +#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_long, "L", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \ + sizeof(long) == sizeof(*(ptr))) + +#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + long *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL); \ +}) + +/* Oid for an unsigned long. The pointer must be non NULL. */ +#define SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL) +#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_long, "LU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) && \ + sizeof(unsigned long) == sizeof(*(ptr))) + +#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + unsigned long *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL); \ +}) + +/* Oid for a quad. The pointer must be non NULL. */ +#define SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL) +#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_64, "Q", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \ + sizeof(int64_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + int64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ +}) + +#define SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL) +#define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_64, "QU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ + sizeof(uint64_t) == sizeof(*(ptr))) + +#define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + uint64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ +}) + +/* Oid for a CPU dependent variable */ +#define SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + struct sysctl_oid *__ret; \ + CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) || \ + sizeof(unsigned) == sizeof(*(ptr))) && \ + ((access) & CTLTYPE) == 0); \ + if (sizeof(uint64_t) == sizeof(*(ptr))) { \ + __ret = sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + (ptr), 0, sysctl_handle_64, "QU", \ + __DESCR(descr), NULL); \ + } else { \ + __ret = sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ + (ptr), 0, sysctl_handle_int, "IU", \ + __DESCR(descr), NULL); \ + } \ + __ret; \ +}) + +/* Oid for a 64-bit unsigned counter(9). The pointer must be non NULL. */ +#define SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + (ptr), 0, sysctl_handle_counter_u64, "QU", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ + sizeof(counter_u64_t) == sizeof(*(ptr)) && \ + sizeof(uint64_t) == sizeof(**(ptr))) + +#define SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + counter_u64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr), \ + NULL); \ +}) + +/* Oid for an array of counter(9)s. The pointer and length must be non zero. */ +#define SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ + (ptr), (len), sysctl_handle_counter_u64_array, "S", descr); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) && \ + sizeof(counter_u64_t) == sizeof(*(ptr)) && \ + sizeof(uint64_t) == sizeof(**(ptr))) + +#define SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access, \ + ptr, len, descr) \ +({ \ + counter_u64_t *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ + __ptr, len, sysctl_handle_counter_u64_array, "S", \ + __DESCR(descr), NULL); \ +}) + +/* Oid for an opaque object. Specified by a pointer and a length. */ +#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, len, sysctl_handle_opaque, fmt, descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) + +#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \ +({ \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL); \ +}) + +/* Oid for a struct. Specified by a pointer and a type. */ +#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, sizeof(struct type), sysctl_handle_opaque, \ + "S," #type, descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) + +#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \ +({ \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + (ptr), sizeof(struct type), \ + sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL); \ +}) + +/* Oid for a procedure. Specified by a pointer and an arg. */ +#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ + SYSCTL_OID(parent, nbr, name, (access), \ + ptr, arg, handler, fmt, descr); \ + CTASSERT(((access) & CTLTYPE) != 0) + +#define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ +({ \ + CTASSERT(((access) & CTLTYPE) != 0); \ + sysctl_add_oid(ctx, parent, nbr, name, (access), \ + (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL); \ +}) + +/* Oid to handle limits on uma(9) zone specified by pointer. */ +#define SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ + (ptr), 0, sysctl_handle_uma_zone_max, "I", descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) + +#define SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + uma_zone_t __ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ + __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr), \ + NULL); \ +}) + +/* Oid to obtain current use of uma(9) zone specified by pointer. */ +#define SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ + (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) + +#define SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + uma_zone_t __ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ + __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr), \ + NULL); \ +}) + +/* OID expressing a struct timeval as seconds */ +#define SYSCTL_TIMEVAL_SEC(parent, nbr, name, access, ptr, descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ + (ptr), 0, sysctl_sec_to_timeval, "I", descr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) +#define SYSCTL_ADD_TIMEVAL_SEC(ctx, parent, nbr, name, access, ptr, descr) \ +({ \ + struct timeval *__ptr = (ptr); \ + CTASSERT(((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ + sysctl_add_oid(ctx, parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ + __ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr), \ + NULL); \ +}) + +/* + * A macro to generate a read-only sysctl to indicate the presence of optional + * kernel features. + */ +#define FEATURE(name, desc) \ + SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \ + CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature") + +#endif /* _KERNEL */ + +/* + * Top-level identifiers + */ +#define CTL_SYSCTL 0 /* "magic" numbers */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +#define CTL_VFS 3 /* filesystem, mount type is next */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +#define CTL_USER 8 /* user-level */ +#define CTL_P1003_1B 9 /* POSIX 1003.1B */ + +/* + * CTL_SYSCTL identifiers + */ +#define CTL_SYSCTL_DEBUG 0 /* printf all nodes */ +#define CTL_SYSCTL_NAME 1 /* string name of OID */ +#define CTL_SYSCTL_NEXT 2 /* next OID */ +#define CTL_SYSCTL_NAME2OID 3 /* int array of name */ +#define CTL_SYSCTL_OIDFMT 4 /* OID's kind and format */ +#define CTL_SYSCTL_OIDDESCR 5 /* OID's description */ +#define CTL_SYSCTL_OIDLABEL 6 /* aggregation label */ + +/* + * CTL_KERN identifiers + */ +#define KERN_OSTYPE 1 /* string: system version */ +#define KERN_OSRELEASE 2 /* string: system release */ +#define KERN_OSREV 3 /* int: system revision */ +#define KERN_VERSION 4 /* string: compile time info */ +#define KERN_MAXVNODES 5 /* int: max vnodes */ +#define KERN_MAXPROC 6 /* int: max processes */ +#define KERN_MAXFILES 7 /* int: max open files */ +#define KERN_ARGMAX 8 /* int: max arguments to exec */ +#define KERN_SECURELVL 9 /* int: system security level */ +#define KERN_HOSTNAME 10 /* string: hostname */ +#define KERN_HOSTID 11 /* int: host identifier */ +#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ +#define KERN_VNODE 13 /* struct: vnode structures */ +#define KERN_PROC 14 /* struct: process entries */ +#define KERN_FILE 15 /* struct: file entries */ +#define KERN_PROF 16 /* node: kernel profiling info */ +#define KERN_POSIX1 17 /* int: POSIX.1 version */ +#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ +#define KERN_JOB_CONTROL 19 /* int: is job control available */ +#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ +#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ +#define KERN_NISDOMAINNAME 22 /* string: YP domain name */ +#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */ +#define KERN_OSRELDATE 24 /* int: kernel release date */ +#define KERN_NTP_PLL 25 /* node: NTP PLL control */ +#define KERN_BOOTFILE 26 /* string: name of booted kernel */ +#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */ +#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */ +#define KERN_DUMPDEV 29 /* struct cdev *: device to dump on */ +#define KERN_IPC 30 /* node: anything related to IPC */ +#define KERN_DUMMY 31 /* unused */ +#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */ +#define KERN_USRSTACK 33 /* int: address of USRSTACK */ +#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */ +#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */ +#define KERN_HOSTUUID 36 /* string: host UUID identifier */ +#define KERN_ARND 37 /* int: from arc4rand() */ +#define KERN_MAXPHYS 38 /* int: MAXPHYS value */ +/* + * KERN_PROC subtypes + */ +#define KERN_PROC_ALL 0 /* everything */ +#define KERN_PROC_PID 1 /* by process id */ +#define KERN_PROC_PGRP 2 /* by process group id */ +#define KERN_PROC_SESSION 3 /* by session of pid */ +#define KERN_PROC_TTY 4 /* by controlling tty */ +#define KERN_PROC_UID 5 /* by effective uid */ +#define KERN_PROC_RUID 6 /* by real uid */ +#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */ +#define KERN_PROC_PROC 8 /* only return procs */ +#define KERN_PROC_SV_NAME 9 /* get syscall vector name */ +#define KERN_PROC_RGID 10 /* by real group id */ +#define KERN_PROC_GID 11 /* by effective group id */ +#define KERN_PROC_PATHNAME 12 /* path to executable */ +#define KERN_PROC_OVMMAP 13 /* Old VM map entries for process */ +#define KERN_PROC_OFILEDESC 14 /* Old file descriptors for process */ +#define KERN_PROC_KSTACK 15 /* Kernel stacks for process */ +#define KERN_PROC_INC_THREAD 0x10 /* + * modifier for pid, pgrp, tty, + * uid, ruid, gid, rgid and proc + * This effectively uses 16-31 + */ +#define KERN_PROC_VMMAP 32 /* VM map entries for process */ +#define KERN_PROC_FILEDESC 33 /* File descriptors for process */ +#define KERN_PROC_GROUPS 34 /* process groups */ +#define KERN_PROC_ENV 35 /* get environment */ +#define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */ +#define KERN_PROC_RLIMIT 37 /* process resource limits */ +#define KERN_PROC_PS_STRINGS 38 /* get ps_strings location */ +#define KERN_PROC_UMASK 39 /* process umask */ +#define KERN_PROC_OSREL 40 /* osreldate for process binary */ +#define KERN_PROC_SIGTRAMP 41 /* signal trampoline location */ +#define KERN_PROC_CWD 42 /* process current working directory */ +#define KERN_PROC_NFDS 43 /* number of open file descriptors */ + +/* + * KERN_IPC identifiers + */ +#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */ +#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */ +#define KIPC_SOMAXCONN 3 /* int: max length of connection q */ +#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */ +#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */ +#define KIPC_MAX_HDR 6 /* int: max total length of headers */ +#define KIPC_MAX_DATALEN 7 /* int: max length of data? */ + +/* + * CTL_HW identifiers + */ +#define HW_MACHINE 1 /* string: machine class */ +#define HW_MODEL 2 /* string: specific machine model */ +#define HW_NCPU 3 /* int: number of cpus */ +#define HW_BYTEORDER 4 /* int: machine byte order */ +#define HW_PHYSMEM 5 /* int: total memory */ +#define HW_USERMEM 6 /* int: non-kernel memory */ +#define HW_PAGESIZE 7 /* int: software page size */ +#define HW_DISKNAMES 8 /* strings: disk drive names */ +#define HW_DISKSTATS 9 /* struct: diskstats[] */ +#define HW_FLOATINGPT 10 /* int: has HW floating point? */ +#define HW_MACHINE_ARCH 11 /* string: machine architecture */ +#define HW_REALMEM 12 /* int: 'real' memory */ + +/* + * CTL_USER definitions + */ +#define USER_CS_PATH 1 /* string: _CS_PATH */ +#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ +#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ +#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ +#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ +#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ +#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ +#define USER_LINE_MAX 8 /* int: LINE_MAX */ +#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ +#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ +#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ +#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ +#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ +#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ +#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ +#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ +#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ +#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ +#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ +#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ + +#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */ +#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */ +#define CTL_P1003_1B_MEMLOCK 3 /* boolean */ +#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */ +#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */ +#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */ +#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */ +#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */ +#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */ +#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */ +#define CTL_P1003_1B_FSYNC 11 /* boolean */ +#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */ +#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */ +#define CTL_P1003_1B_TIMERS 14 /* boolean */ +#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */ +#define CTL_P1003_1B_AIO_MAX 16 /* int */ +#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */ +#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */ +#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */ +#define CTL_P1003_1B_PAGESIZE 20 /* int */ +#define CTL_P1003_1B_RTSIG_MAX 21 /* int */ +#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */ +#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */ +#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */ +#define CTL_P1003_1B_TIMER_MAX 25 /* int */ + +#define CTL_P1003_1B_MAXID 26 + +#ifdef _KERNEL + +/* + * Declare some common oids. + */ +extern struct sysctl_oid_list sysctl__children; +SYSCTL_DECL(_kern); +SYSCTL_DECL(_kern_features); +SYSCTL_DECL(_kern_ipc); +SYSCTL_DECL(_kern_proc); +SYSCTL_DECL(_kern_sched); +SYSCTL_DECL(_kern_sched_stats); +SYSCTL_DECL(_sysctl); +SYSCTL_DECL(_vm); +SYSCTL_DECL(_vm_stats); +SYSCTL_DECL(_vm_stats_misc); +SYSCTL_DECL(_vfs); +SYSCTL_DECL(_net); +SYSCTL_DECL(_debug); +SYSCTL_DECL(_debug_sizeof); +SYSCTL_DECL(_dev); +SYSCTL_DECL(_hw); +SYSCTL_DECL(_hw_bus); +SYSCTL_DECL(_hw_bus_devices); +SYSCTL_DECL(_hw_bus_info); +SYSCTL_DECL(_machdep); +SYSCTL_DECL(_machdep_mitigations); +SYSCTL_DECL(_user); +SYSCTL_DECL(_compat); +SYSCTL_DECL(_regression); +SYSCTL_DECL(_security); +SYSCTL_DECL(_security_bsd); + +extern char machine[]; +extern char osrelease[]; +extern char ostype[]; +extern char kern_ident[]; + +/* Dynamic oid handling */ +struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, + struct sysctl_oid_list *parent, int nbr, const char *name, int kind, + void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS), + const char *fmt, const char *descr, const char *label); +int sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del, + int recurse); +void sysctl_rename_oid(struct sysctl_oid *oidp, const char *name); +int sysctl_move_oid(struct sysctl_oid *oidp, + struct sysctl_oid_list *parent); +int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse); +int sysctl_ctx_init(struct sysctl_ctx_list *clist); +int sysctl_ctx_free(struct sysctl_ctx_list *clist); +struct sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); +struct sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); +int sysctl_ctx_entry_del(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); + +int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old, + size_t *oldlenp, void *new, size_t newlen, size_t *retval, + int flags); +int kernel_sysctlbyname(struct thread *td, char *name, void *old, + size_t *oldlenp, void *new, size_t newlen, size_t *retval, + int flags); +int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, + size_t *oldlenp, int inkernel, void *new, size_t newlen, + size_t *retval, int flags); +int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, + int *nindx, struct sysctl_req *req); +void sysctl_wlock(void); +void sysctl_wunlock(void); +int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len); +int kern___sysctlbyname(struct thread *td, const char *name, + size_t namelen, void *old, size_t *oldlenp, void *new, + size_t newlen, size_t *retval, int flags, bool inkernel); + +struct sbuf; +struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int, + struct sysctl_req *); +#else /* !_KERNEL */ +#include + +__BEGIN_DECLS +int sysctl(const int *, u_int, void *, size_t *, const void *, size_t); +int sysctlbyname(const char *, void *, size_t *, const void *, size_t); +int sysctlnametomib(const char *, int *, size_t *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_SYSCTL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/sysent.h b/lib/libc/include/any-freebsd-any/sys/sysent.h new file mode 100644 index 000000000000..d1d9e99b9b7a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sysent.h @@ -0,0 +1,327 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1988, 1991 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SYSENT_H_ +#define _SYS_SYSENT_H_ + +#include + +struct rlimit; +struct sysent; +struct thread; +struct ksiginfo; +struct syscall_args; + +enum systrace_probe_t { + SYSTRACE_ENTRY, + SYSTRACE_RETURN, +}; + +typedef int sy_call_t(struct thread *, void *); + +typedef void (*systrace_probe_func_t)(struct syscall_args *, + enum systrace_probe_t, int); +typedef void (*systrace_args_func_t)(int, void *, uint64_t *, int *); + +#ifdef _KERNEL +extern bool systrace_enabled; +#endif +extern systrace_probe_func_t systrace_probe_func; + +struct sysent { /* system call table */ + int sy_narg; /* number of arguments */ + sy_call_t *sy_call; /* implementing function */ + au_event_t sy_auevent; /* audit event associated with syscall */ + systrace_args_func_t sy_systrace_args_func; + /* optional argument conversion function. */ + u_int32_t sy_entry; /* DTrace entry ID for systrace. */ + u_int32_t sy_return; /* DTrace return ID for systrace. */ + u_int32_t sy_flags; /* General flags for system calls. */ + u_int32_t sy_thrcnt; +}; + +/* + * A system call is permitted in capability mode. + */ +#define SYF_CAPENABLED 0x00000001 + +#define SY_THR_FLAGMASK 0x7 +#define SY_THR_STATIC 0x1 +#define SY_THR_DRAINING 0x2 +#define SY_THR_ABSENT 0x4 +#define SY_THR_INCR 0x8 + +#ifdef KLD_MODULE +#define SY_THR_STATIC_KLD 0 +#else +#define SY_THR_STATIC_KLD SY_THR_STATIC +#endif + +struct image_params; +struct __sigset; +struct trapframe; +struct vnode; + +struct sysentvec { + int sv_size; /* number of entries */ + struct sysent *sv_table; /* pointer to sysent */ + u_int sv_mask; /* optional mask to index */ + int sv_errsize; /* size of errno translation table */ + const int *sv_errtbl; /* errno translation table */ + int (*sv_transtrap)(int, int); + /* translate trap-to-signal mapping */ + int (*sv_fixup)(register_t **, struct image_params *); + /* stack fixup function */ + void (*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *); + /* send signal */ + char *sv_sigcode; /* start of sigtramp code */ + int *sv_szsigcode; /* size of sigtramp code */ + char *sv_name; /* name of binary type */ + int (*sv_coredump)(struct thread *, struct vnode *, off_t, int); + /* function to dump core, or NULL */ + int (*sv_imgact_try)(struct image_params *); + void (*sv_stackgap)(struct image_params *, u_long *); + int sv_minsigstksz; /* minimum signal stack size */ + int sv_pagesize; /* spare / no longer used */ + vm_offset_t sv_minuser; /* VM_MIN_ADDRESS */ + vm_offset_t sv_maxuser; /* VM_MAXUSER_ADDRESS */ + vm_offset_t sv_usrstack; /* USRSTACK */ + vm_offset_t sv_psstrings; /* PS_STRINGS */ + int sv_stackprot; /* vm protection for stack */ + register_t *(*sv_copyout_strings)(struct image_params *); + void (*sv_setregs)(struct thread *, struct image_params *, + u_long); + void (*sv_fixlimit)(struct rlimit *, int); + u_long *sv_maxssiz; + u_int sv_flags; + void (*sv_set_syscall_retval)(struct thread *, int); + int (*sv_fetch_syscall_args)(struct thread *); + const char **sv_syscallnames; + vm_offset_t sv_timekeep_base; + vm_offset_t sv_shared_page_base; + vm_offset_t sv_shared_page_len; + vm_offset_t sv_sigcode_base; + void *sv_shared_page_obj; + void (*sv_schedtail)(struct thread *); + void (*sv_thread_detach)(struct thread *); + int (*sv_trap)(struct thread *); + u_long *sv_hwcap; /* Value passed in AT_HWCAP. */ + u_long *sv_hwcap2; /* Value passed in AT_HWCAP2. */ +}; + +#define SV_ILP32 0x000100 /* 32-bit executable. */ +#define SV_LP64 0x000200 /* 64-bit executable. */ +#define SV_IA32 0x004000 /* Intel 32-bit executable. */ +#define SV_AOUT 0x008000 /* a.out executable. */ +#define SV_SHP 0x010000 /* Shared page. */ +#define SV_CAPSICUM 0x020000 /* Force cap_enter() on startup. */ +#define SV_TIMEKEEP 0x040000 /* Shared page timehands. */ +#define SV_ASLR 0x080000 /* ASLR allowed. */ + +#define SV_ABI_MASK 0xff +#define SV_ABI_ERRNO(p, e) ((p)->p_sysent->sv_errsize <= 0 ? e : \ + ((e) >= (p)->p_sysent->sv_errsize ? -1 : (p)->p_sysent->sv_errtbl[e])) +#define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x)) +#define SV_PROC_ABI(p) ((p)->p_sysent->sv_flags & SV_ABI_MASK) +#define SV_CURPROC_FLAG(x) SV_PROC_FLAG(curproc, x) +#define SV_CURPROC_ABI() SV_PROC_ABI(curproc) +/* same as ELFOSABI_XXX, to prevent header pollution */ +#define SV_ABI_LINUX 3 +#define SV_ABI_FREEBSD 9 +#define SV_ABI_CLOUDABI 17 +#define SV_ABI_UNDEF 255 + +#ifdef _KERNEL +extern struct sysentvec aout_sysvec; +extern struct sysent sysent[]; +extern const char *syscallnames[]; + +#if defined(__amd64__) +extern int i386_read_exec; +#endif + +#define NO_SYSCALL (-1) + +struct module; + +struct syscall_module_data { + int (*chainevh)(struct module *, int, void *); /* next handler */ + void *chainarg; /* arg for next event handler */ + int *offset; /* offset into sysent */ + struct sysent *new_sysent; /* new sysent */ + struct sysent old_sysent; /* old sysent */ + int flags; /* flags for syscall_register */ +}; + +/* separate initialization vector so it can be used in a substructure */ +#define SYSENT_INIT_VALS(_syscallname) { \ + .sy_narg = (sizeof(struct _syscallname ## _args ) \ + / sizeof(register_t)), \ + .sy_call = (sy_call_t *)&sys_##_syscallname, \ + .sy_auevent = SYS_AUE_##_syscallname, \ + .sy_systrace_args_func = NULL, \ + .sy_entry = 0, \ + .sy_return = 0, \ + .sy_flags = 0, \ + .sy_thrcnt = 0 \ +} + +#define MAKE_SYSENT(syscallname) \ +static struct sysent syscallname##_sysent = SYSENT_INIT_VALS(syscallname); + +#define MAKE_SYSENT_COMPAT(syscallname) \ +static struct sysent syscallname##_sysent = { \ + (sizeof(struct syscallname ## _args ) \ + / sizeof(register_t)), \ + (sy_call_t *)& syscallname, \ + SYS_AUE_##syscallname \ +} + +#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg) \ +static struct syscall_module_data name##_syscall_mod = { \ + evh, arg, offset, new_sysent, { 0, NULL, AUE_NULL } \ +}; \ + \ +static moduledata_t name##_mod = { \ + "sys/" #name, \ + syscall_module_handler, \ + &name##_syscall_mod \ +}; \ +DECLARE_MODULE(name, name##_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE) + +#define SYSCALL_MODULE_HELPER(syscallname) \ +static int syscallname##_syscall = SYS_##syscallname; \ +MAKE_SYSENT(syscallname); \ +SYSCALL_MODULE(syscallname, \ + & syscallname##_syscall, & syscallname##_sysent, \ + NULL, NULL) + +#define SYSCALL_MODULE_PRESENT(syscallname) \ + (sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmnosys && \ + sysent[SYS_##syscallname].sy_call != (sy_call_t *)lkmressys) + +/* + * Syscall registration helpers with resource allocation handling. + */ +struct syscall_helper_data { + struct sysent new_sysent; + struct sysent old_sysent; + int syscall_no; + int registered; +}; +#define SYSCALL_INIT_HELPER_F(syscallname, flags) { \ + .new_sysent = { \ + .sy_narg = (sizeof(struct syscallname ## _args ) \ + / sizeof(register_t)), \ + .sy_call = (sy_call_t *)& sys_ ## syscallname, \ + .sy_auevent = SYS_AUE_##syscallname, \ + .sy_flags = (flags) \ + }, \ + .syscall_no = SYS_##syscallname \ +} +#define SYSCALL_INIT_HELPER_COMPAT_F(syscallname, flags) { \ + .new_sysent = { \ + .sy_narg = (sizeof(struct syscallname ## _args ) \ + / sizeof(register_t)), \ + .sy_call = (sy_call_t *)& syscallname, \ + .sy_auevent = SYS_AUE_##syscallname, \ + .sy_flags = (flags) \ + }, \ + .syscall_no = SYS_##syscallname \ +} +#define SYSCALL_INIT_HELPER(syscallname) \ + SYSCALL_INIT_HELPER_F(syscallname, 0) +#define SYSCALL_INIT_HELPER_COMPAT(syscallname) \ + SYSCALL_INIT_HELPER_COMPAT_F(syscallname, 0) +#define SYSCALL_INIT_LAST { \ + .syscall_no = NO_SYSCALL \ +} + +int syscall_module_handler(struct module *mod, int what, void *arg); +int syscall_helper_register(struct syscall_helper_data *sd, int flags); +int syscall_helper_unregister(struct syscall_helper_data *sd); +/* Implementation, exposed for COMPAT code */ +int kern_syscall_register(struct sysent *sysents, int *offset, + struct sysent *new_sysent, struct sysent *old_sysent, int flags); +int kern_syscall_deregister(struct sysent *sysents, int offset, + const struct sysent *old_sysent); +int kern_syscall_module_handler(struct sysent *sysents, + struct module *mod, int what, void *arg); +int kern_syscall_helper_register(struct sysent *sysents, + struct syscall_helper_data *sd, int flags); +int kern_syscall_helper_unregister(struct sysent *sysents, + struct syscall_helper_data *sd); + +struct proc; +const char *syscallname(struct proc *p, u_int code); + +/* Special purpose system call functions. */ +struct nosys_args; + +int lkmnosys(struct thread *, struct nosys_args *); +int lkmressys(struct thread *, struct nosys_args *); + +int _syscall_thread_enter(struct thread *td, struct sysent *se); +void _syscall_thread_exit(struct thread *td, struct sysent *se); + +static inline int +syscall_thread_enter(struct thread *td, struct sysent *se) +{ + + if (__predict_true((se->sy_thrcnt & SY_THR_STATIC) != 0)) + return (0); + return (_syscall_thread_enter(td, se)); +} + +static inline void +syscall_thread_exit(struct thread *td, struct sysent *se) +{ + + if (__predict_true((se->sy_thrcnt & SY_THR_STATIC) != 0)) + return; + _syscall_thread_exit(td, se); +} + +int shared_page_alloc(int size, int align); +int shared_page_fill(int size, int align, const void *data); +void shared_page_write(int base, int size, const void *data); +void exec_sysvec_init(void *param); +void exec_inittk(void); + +#define INIT_SYSENTVEC(name, sv) \ + SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \ + (sysinit_cfunc_t)exec_sysvec_init, sv); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SYSENT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/syslimits.h b/lib/libc/include/any-freebsd-any/sys/syslimits.h new file mode 100644 index 000000000000..b330ae7f0e27 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/syslimits.h @@ -0,0 +1,81 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_SYSLIMITS_H_ +#define _SYS_SYSLIMITS_H_ + +#if !defined(_STANDALONE) && !defined(_KERNEL) && !defined(_LIMITS_H_) && !defined(_SYS_PARAM_H_) +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif +#ifdef __CC_SUPPORTS_WARNING +#warning "No user-serviceable parts inside." +#endif +#endif + +/* + * Do not add any new variables here. (See the comment at the end of + * the file for why.) + */ +#ifndef __ILP32__ +#define ARG_MAX (2 * 256 * 1024) /* max bytes for an exec function */ +#else +#define ARG_MAX (256 * 1024) /* max bytes for KVA-starved archs */ +#endif +#ifndef CHILD_MAX +#define CHILD_MAX 40 /* max simultaneous processes */ +#endif +#define MAX_CANON 255 /* max bytes in term canon input line */ +#define MAX_INPUT 255 /* max bytes in terminal input */ +#define NAME_MAX 255 /* max bytes in a file name */ +#ifndef NGROUPS_MAX +#define NGROUPS_MAX 1023 /* max supplemental group id's */ +#endif +#ifndef OPEN_MAX +#define OPEN_MAX 64 /* max open files per process */ +#endif +#define PATH_MAX 1024 /* max bytes in pathname */ +#define PIPE_BUF 512 /* max bytes for atomic pipe writes */ +#define IOV_MAX 1024 /* max elements in i/o vector */ + +/* + * We leave the following values undefined to force applications to either + * assume conservative values or call sysconf() to get the current value. + * + * HOST_NAME_MAX + * + * (We should do this for most of the values currently defined here, + * but many programs are not prepared to deal with this yet.) + */ +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/syslog.h b/lib/libc/include/any-freebsd-any/sys/syslog.h new file mode 100644 index 000000000000..071b68427105 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/syslog.h @@ -0,0 +1,205 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/var/run/log" +#define _PATH_LOG_PRIV "/var/run/logpriv" +#define _PATH_OLDLOG "/dev/log" /* backward compatibility */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) ((fac) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0) +typedef struct _code { + const char *c_name; + int c_val; +} CODE; + +static const CODE prioritynames[] = { + { "alert", LOG_ALERT, }, + { "crit", LOG_CRIT, }, + { "debug", LOG_DEBUG, }, + { "emerg", LOG_EMERG, }, + { "err", LOG_ERR, }, + { "error", LOG_ERR, }, /* DEPRECATED */ + { "info", LOG_INFO, }, + { "none", INTERNAL_NOPRI, }, /* INTERNAL */ + { "notice", LOG_NOTICE, }, + { "panic", LOG_EMERG, }, /* DEPRECATED */ + { "warn", LOG_WARNING, }, /* DEPRECATED */ + { "warning", LOG_WARNING, }, + { NULL, -1, } +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* authorization messages (private) */ + /* Facility #10 clashes in DEC UNIX, where */ + /* it's defined as LOG_MEGASAFE for AdvFS */ + /* event logging. */ +#define LOG_FTP (11<<3) /* ftp daemon */ +#define LOG_NTP (12<<3) /* NTP subsystem */ +#define LOG_SECURITY (13<<3) /* security subsystems (firewalling, etc.) */ +#define LOG_CONSOLE (14<<3) /* /dev/console output */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +static const CODE facilitynames[] = { + { "auth", LOG_AUTH, }, + { "authpriv", LOG_AUTHPRIV, }, + { "console", LOG_CONSOLE, }, + { "cron", LOG_CRON, }, + { "daemon", LOG_DAEMON, }, + { "ftp", LOG_FTP, }, + { "kern", LOG_KERN, }, + { "lpr", LOG_LPR, }, + { "mail", LOG_MAIL, }, + { "mark", INTERNAL_MARK, }, /* INTERNAL */ + { "news", LOG_NEWS, }, + { "ntp", LOG_NTP, }, + { "security", LOG_SECURITY, }, + { "syslog", LOG_SYSLOG, }, + { "user", LOG_USER, }, + { "uucp", LOG_UUCP, }, + { "local0", LOG_LOCAL0, }, + { "local1", LOG_LOCAL1, }, + { "local2", LOG_LOCAL2, }, + { "local3", LOG_LOCAL3, }, + { "local4", LOG_LOCAL4, }, + { "local5", LOG_LOCAL5, }, + { "local6", LOG_LOCAL6, }, + { "local7", LOG_LOCAL7, }, + { NULL, -1, } +}; +#endif + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifdef _KERNEL + +#else /* not _KERNEL */ + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) __printflike(2, 3); +#if __BSD_VISIBLE +void vsyslog(int, const char *, __va_list) __printflike(2, 0); +#endif +__END_DECLS + +#endif /* !_KERNEL */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/sysproto.h b/lib/libc/include/any-freebsd-any/sys/sysproto.h new file mode 100644 index 000000000000..41e805fd0409 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/sysproto.h @@ -0,0 +1,3100 @@ +/* + * System call prototypes. + * + * DO NOT EDIT-- this file is automatically @generated. + * $FreeBSD$ + */ + +#ifndef _SYS_SYSPROTO_H_ +#define _SYS_SYSPROTO_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct proc; + +struct thread; + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define PADL_(t) 0 +#define PADR_(t) PAD_(t) +#else +#define PADL_(t) PAD_(t) +#define PADR_(t) 0 +#endif + +struct nosys_args { + register_t dummy; +}; +struct sys_exit_args { + char rval_l_[PADL_(int)]; int rval; char rval_r_[PADR_(int)]; +}; +struct fork_args { + register_t dummy; +}; +struct read_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; +}; +struct write_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; +}; +struct open_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct close_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct wait4_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)]; + char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)]; + char rusage_l_[PADL_(struct rusage *)]; struct rusage * rusage; char rusage_r_[PADR_(struct rusage *)]; +}; +struct link_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char link_l_[PADL_(char *)]; char * link; char link_r_[PADR_(char *)]; +}; +struct unlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct chdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct fchdir_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct chmod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct chown_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct break_args { + char nsize_l_[PADL_(char *)]; char * nsize; char nsize_r_[PADR_(char *)]; +}; +struct getpid_args { + register_t dummy; +}; +struct mount_args { + char type_l_[PADL_(char *)]; char * type; char type_r_[PADR_(char *)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)]; +}; +struct unmount_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct setuid_args { + char uid_l_[PADL_(uid_t)]; uid_t uid; char uid_r_[PADR_(uid_t)]; +}; +struct getuid_args { + register_t dummy; +}; +struct geteuid_args { + register_t dummy; +}; +struct ptrace_args { + char req_l_[PADL_(int)]; int req; char req_r_[PADR_(int)]; + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char data_l_[PADL_(int)]; int data; char data_r_[PADR_(int)]; +}; +struct recvmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct sendmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct recvfrom_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char from_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict from; char from_r_[PADR_(struct sockaddr *__restrict)]; + char fromlenaddr_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *__restrict)]; +}; +struct accept_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)]; + char anamelen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict anamelen; char anamelen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct getpeername_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)]; + char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct getsockname_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)]; + char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct access_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char amode_l_[PADL_(int)]; int amode; char amode_r_[PADR_(int)]; +}; +struct chflags_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(u_long)]; u_long flags; char flags_r_[PADR_(u_long)]; +}; +struct fchflags_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char flags_l_[PADL_(u_long)]; u_long flags; char flags_r_[PADR_(u_long)]; +}; +struct sync_args { + register_t dummy; +}; +struct kill_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; +}; +struct getppid_args { + register_t dummy; +}; +struct dup_args { + char fd_l_[PADL_(u_int)]; u_int fd; char fd_r_[PADR_(u_int)]; +}; +struct freebsd10_pipe_args { + register_t dummy; +}; +struct getegid_args { + register_t dummy; +}; +struct profil_args { + char samples_l_[PADL_(caddr_t)]; caddr_t samples; char samples_r_[PADR_(caddr_t)]; + char size_l_[PADL_(size_t)]; size_t size; char size_r_[PADR_(size_t)]; + char offset_l_[PADL_(size_t)]; size_t offset; char offset_r_[PADR_(size_t)]; + char scale_l_[PADL_(u_int)]; u_int scale; char scale_r_[PADR_(u_int)]; +}; +struct ktrace_args { + char fname_l_[PADL_(const char *)]; const char * fname; char fname_r_[PADR_(const char *)]; + char ops_l_[PADL_(int)]; int ops; char ops_r_[PADR_(int)]; + char facs_l_[PADL_(int)]; int facs; char facs_r_[PADR_(int)]; + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; +}; +struct getgid_args { + register_t dummy; +}; +struct getlogin_args { + char namebuf_l_[PADL_(char *)]; char * namebuf; char namebuf_r_[PADR_(char *)]; + char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)]; +}; +struct setlogin_args { + char namebuf_l_[PADL_(char *)]; char * namebuf; char namebuf_r_[PADR_(char *)]; +}; +struct acct_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct osigpending_args { + register_t dummy; +}; +struct sigaltstack_args { + char ss_l_[PADL_(stack_t *)]; stack_t * ss; char ss_r_[PADR_(stack_t *)]; + char oss_l_[PADL_(stack_t *)]; stack_t * oss; char oss_r_[PADR_(stack_t *)]; +}; +struct ioctl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char com_l_[PADL_(u_long)]; u_long com; char com_r_[PADR_(u_long)]; + char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)]; +}; +struct reboot_args { + char opt_l_[PADL_(int)]; int opt; char opt_r_[PADR_(int)]; +}; +struct revoke_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct symlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char link_l_[PADL_(char *)]; char * link; char link_r_[PADR_(char *)]; +}; +struct readlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(size_t)]; size_t count; char count_r_[PADR_(size_t)]; +}; +struct execve_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char argv_l_[PADL_(char **)]; char ** argv; char argv_r_[PADR_(char **)]; + char envv_l_[PADL_(char **)]; char ** envv; char envv_r_[PADR_(char **)]; +}; +struct umask_args { + char newmask_l_[PADL_(int)]; int newmask; char newmask_r_[PADR_(int)]; +}; +struct chroot_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct getpagesize_args { + register_t dummy; +}; +struct msync_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct vfork_args { + register_t dummy; +}; +struct sbrk_args { + char incr_l_[PADL_(int)]; int incr; char incr_r_[PADR_(int)]; +}; +struct sstk_args { + char incr_l_[PADL_(int)]; int incr; char incr_r_[PADR_(int)]; +}; +struct munmap_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct mprotect_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; +}; +struct madvise_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char behav_l_[PADL_(int)]; int behav; char behav_r_[PADR_(int)]; +}; +struct mincore_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char vec_l_[PADL_(char *)]; char * vec; char vec_r_[PADR_(char *)]; +}; +struct getgroups_args { + char gidsetsize_l_[PADL_(u_int)]; u_int gidsetsize; char gidsetsize_r_[PADR_(u_int)]; + char gidset_l_[PADL_(gid_t *)]; gid_t * gidset; char gidset_r_[PADR_(gid_t *)]; +}; +struct setgroups_args { + char gidsetsize_l_[PADL_(u_int)]; u_int gidsetsize; char gidsetsize_r_[PADR_(u_int)]; + char gidset_l_[PADL_(gid_t *)]; gid_t * gidset; char gidset_r_[PADR_(gid_t *)]; +}; +struct getpgrp_args { + register_t dummy; +}; +struct setpgid_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char pgid_l_[PADL_(int)]; int pgid; char pgid_r_[PADR_(int)]; +}; +struct setitimer_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char itv_l_[PADL_(struct itimerval *)]; struct itimerval * itv; char itv_r_[PADR_(struct itimerval *)]; + char oitv_l_[PADL_(struct itimerval *)]; struct itimerval * oitv; char oitv_r_[PADR_(struct itimerval *)]; +}; +struct owait_args { + register_t dummy; +}; +struct swapon_args { + char name_l_[PADL_(char *)]; char * name; char name_r_[PADR_(char *)]; +}; +struct getitimer_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char itv_l_[PADL_(struct itimerval *)]; struct itimerval * itv; char itv_r_[PADR_(struct itimerval *)]; +}; +struct getdtablesize_args { + register_t dummy; +}; +struct dup2_args { + char from_l_[PADL_(u_int)]; u_int from; char from_r_[PADR_(u_int)]; + char to_l_[PADL_(u_int)]; u_int to; char to_r_[PADR_(u_int)]; +}; +struct fcntl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(long)]; long arg; char arg_r_[PADR_(long)]; +}; +struct select_args { + char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)]; + char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)]; + char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)]; + char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)]; + char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)]; +}; +struct fsync_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct setpriority_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; + char prio_l_[PADL_(int)]; int prio; char prio_r_[PADR_(int)]; +}; +struct socket_args { + char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)]; + char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)]; + char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)]; +}; +struct connect_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct getpriority_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; +}; +struct bind_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct setsockopt_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; + char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)]; + char valsize_l_[PADL_(int)]; int valsize; char valsize_r_[PADR_(int)]; +}; +struct listen_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char backlog_l_[PADL_(int)]; int backlog; char backlog_r_[PADR_(int)]; +}; +struct gettimeofday_args { + char tp_l_[PADL_(struct timeval *)]; struct timeval * tp; char tp_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; +}; +struct getrusage_args { + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; + char rusage_l_[PADL_(struct rusage *)]; struct rusage * rusage; char rusage_r_[PADR_(struct rusage *)]; +}; +struct getsockopt_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; + char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)]; + char avalsize_l_[PADL_(int *)]; int * avalsize; char avalsize_r_[PADR_(int *)]; +}; +struct readv_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; +}; +struct writev_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; +}; +struct settimeofday_args { + char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; +}; +struct fchown_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct fchmod_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct setreuid_args { + char ruid_l_[PADL_(int)]; int ruid; char ruid_r_[PADR_(int)]; + char euid_l_[PADL_(int)]; int euid; char euid_r_[PADR_(int)]; +}; +struct setregid_args { + char rgid_l_[PADL_(int)]; int rgid; char rgid_r_[PADR_(int)]; + char egid_l_[PADL_(int)]; int egid; char egid_r_[PADR_(int)]; +}; +struct rename_args { + char from_l_[PADL_(char *)]; char * from; char from_r_[PADR_(char *)]; + char to_l_[PADL_(char *)]; char * to; char to_r_[PADR_(char *)]; +}; +struct flock_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct mkfifo_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct sendto_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)]; + char tolen_l_[PADL_(int)]; int tolen; char tolen_r_[PADR_(int)]; +}; +struct shutdown_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct socketpair_args { + char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)]; + char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)]; + char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)]; + char rsv_l_[PADL_(int *)]; int * rsv; char rsv_r_[PADR_(int *)]; +}; +struct mkdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct rmdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct utimes_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct adjtime_args { + char delta_l_[PADL_(struct timeval *)]; struct timeval * delta; char delta_r_[PADR_(struct timeval *)]; + char olddelta_l_[PADL_(struct timeval *)]; struct timeval * olddelta; char olddelta_r_[PADR_(struct timeval *)]; +}; +struct ogethostid_args { + register_t dummy; +}; +struct setsid_args { + register_t dummy; +}; +struct quotactl_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char arg_l_[PADL_(caddr_t)]; caddr_t arg; char arg_r_[PADR_(caddr_t)]; +}; +struct oquota_args { + register_t dummy; +}; +struct nlm_syscall_args { + char debug_level_l_[PADL_(int)]; int debug_level; char debug_level_r_[PADR_(int)]; + char grace_period_l_[PADL_(int)]; int grace_period; char grace_period_r_[PADR_(int)]; + char addr_count_l_[PADL_(int)]; int addr_count; char addr_count_r_[PADR_(int)]; + char addrs_l_[PADL_(char **)]; char ** addrs; char addrs_r_[PADR_(char **)]; +}; +struct nfssvc_args { + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; + char argp_l_[PADL_(caddr_t)]; caddr_t argp; char argp_r_[PADR_(caddr_t)]; +}; +struct lgetfh_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; +}; +struct getfh_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; +}; +struct sysarch_args { + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char parms_l_[PADL_(char *)]; char * parms; char parms_r_[PADR_(char *)]; +}; +struct rtprio_args { + char function_l_[PADL_(int)]; int function; char function_r_[PADR_(int)]; + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char rtp_l_[PADL_(struct rtprio *)]; struct rtprio * rtp; char rtp_r_[PADR_(struct rtprio *)]; +}; +struct semsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; + char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)]; +}; +struct msgsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; + char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)]; + char a6_l_[PADL_(int)]; int a6; char a6_r_[PADR_(int)]; +}; +struct shmsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; +}; +struct setfib_args { + char fibnum_l_[PADL_(int)]; int fibnum; char fibnum_r_[PADR_(int)]; +}; +struct ntp_adjtime_args { + char tp_l_[PADL_(struct timex *)]; struct timex * tp; char tp_r_[PADR_(struct timex *)]; +}; +struct setgid_args { + char gid_l_[PADL_(gid_t)]; gid_t gid; char gid_r_[PADR_(gid_t)]; +}; +struct setegid_args { + char egid_l_[PADL_(gid_t)]; gid_t egid; char egid_r_[PADR_(gid_t)]; +}; +struct seteuid_args { + char euid_l_[PADL_(uid_t)]; uid_t euid; char euid_r_[PADR_(uid_t)]; +}; +struct pathconf_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; +}; +struct fpathconf_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; +}; +struct __getrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct rlimit *)]; struct rlimit * rlp; char rlp_r_[PADR_(struct rlimit *)]; +}; +struct __setrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct rlimit *)]; struct rlimit * rlp; char rlp_r_[PADR_(struct rlimit *)]; +}; +struct sysctl_args { + char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)]; + char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)]; + char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)]; + char oldlenp_l_[PADL_(size_t *)]; size_t * oldlenp; char oldlenp_r_[PADR_(size_t *)]; + char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)]; + char newlen_l_[PADL_(size_t)]; size_t newlen; char newlen_r_[PADR_(size_t)]; +}; +struct mlock_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct munlock_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct undelete_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct futimes_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct getpgid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct poll_args { + char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)]; + char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)]; + char timeout_l_[PADL_(int)]; int timeout; char timeout_r_[PADR_(int)]; +}; +struct semget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char nsems_l_[PADL_(int)]; int nsems; char nsems_r_[PADR_(int)]; + char semflg_l_[PADL_(int)]; int semflg; char semflg_r_[PADR_(int)]; +}; +struct semop_args { + char semid_l_[PADL_(int)]; int semid; char semid_r_[PADR_(int)]; + char sops_l_[PADL_(struct sembuf *)]; struct sembuf * sops; char sops_r_[PADR_(struct sembuf *)]; + char nsops_l_[PADL_(size_t)]; size_t nsops; char nsops_r_[PADR_(size_t)]; +}; +struct msgget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct msgsnd_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char msgp_l_[PADL_(const void *)]; const void * msgp; char msgp_r_[PADR_(const void *)]; + char msgsz_l_[PADL_(size_t)]; size_t msgsz; char msgsz_r_[PADR_(size_t)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct msgrcv_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char msgp_l_[PADL_(void *)]; void * msgp; char msgp_r_[PADR_(void *)]; + char msgsz_l_[PADL_(size_t)]; size_t msgsz; char msgsz_r_[PADR_(size_t)]; + char msgtyp_l_[PADL_(long)]; long msgtyp; char msgtyp_r_[PADR_(long)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct shmat_args { + char shmid_l_[PADL_(int)]; int shmid; char shmid_r_[PADR_(int)]; + char shmaddr_l_[PADL_(const void *)]; const void * shmaddr; char shmaddr_r_[PADR_(const void *)]; + char shmflg_l_[PADL_(int)]; int shmflg; char shmflg_r_[PADR_(int)]; +}; +struct shmdt_args { + char shmaddr_l_[PADL_(const void *)]; const void * shmaddr; char shmaddr_r_[PADR_(const void *)]; +}; +struct shmget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char size_l_[PADL_(size_t)]; size_t size; char size_r_[PADR_(size_t)]; + char shmflg_l_[PADL_(int)]; int shmflg; char shmflg_r_[PADR_(int)]; +}; +struct clock_gettime_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(struct timespec *)]; struct timespec * tp; char tp_r_[PADR_(struct timespec *)]; +}; +struct clock_settime_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(const struct timespec *)]; const struct timespec * tp; char tp_r_[PADR_(const struct timespec *)]; +}; +struct clock_getres_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(struct timespec *)]; struct timespec * tp; char tp_r_[PADR_(struct timespec *)]; +}; +struct ktimer_create_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char evp_l_[PADL_(struct sigevent *)]; struct sigevent * evp; char evp_r_[PADR_(struct sigevent *)]; + char timerid_l_[PADL_(int *)]; int * timerid; char timerid_r_[PADR_(int *)]; +}; +struct ktimer_delete_args { + char timerid_l_[PADL_(int)]; int timerid; char timerid_r_[PADR_(int)]; +}; +struct ktimer_settime_args { + char timerid_l_[PADL_(int)]; int timerid; char timerid_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char value_l_[PADL_(const struct itimerspec *)]; const struct itimerspec * value; char value_r_[PADR_(const struct itimerspec *)]; + char ovalue_l_[PADL_(struct itimerspec *)]; struct itimerspec * ovalue; char ovalue_r_[PADR_(struct itimerspec *)]; +}; +struct ktimer_gettime_args { + char timerid_l_[PADL_(int)]; int timerid; char timerid_r_[PADR_(int)]; + char value_l_[PADL_(struct itimerspec *)]; struct itimerspec * value; char value_r_[PADR_(struct itimerspec *)]; +}; +struct ktimer_getoverrun_args { + char timerid_l_[PADL_(int)]; int timerid; char timerid_r_[PADR_(int)]; +}; +struct nanosleep_args { + char rqtp_l_[PADL_(const struct timespec *)]; const struct timespec * rqtp; char rqtp_r_[PADR_(const struct timespec *)]; + char rmtp_l_[PADL_(struct timespec *)]; struct timespec * rmtp; char rmtp_r_[PADR_(struct timespec *)]; +}; +struct ffclock_getcounter_args { + char ffcount_l_[PADL_(ffcounter *)]; ffcounter * ffcount; char ffcount_r_[PADR_(ffcounter *)]; +}; +struct ffclock_setestimate_args { + char cest_l_[PADL_(struct ffclock_estimate *)]; struct ffclock_estimate * cest; char cest_r_[PADR_(struct ffclock_estimate *)]; +}; +struct ffclock_getestimate_args { + char cest_l_[PADL_(struct ffclock_estimate *)]; struct ffclock_estimate * cest; char cest_r_[PADR_(struct ffclock_estimate *)]; +}; +struct clock_nanosleep_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char rqtp_l_[PADL_(const struct timespec *)]; const struct timespec * rqtp; char rqtp_r_[PADR_(const struct timespec *)]; + char rmtp_l_[PADL_(struct timespec *)]; struct timespec * rmtp; char rmtp_r_[PADR_(struct timespec *)]; +}; +struct clock_getcpuclockid2_args { + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char clock_id_l_[PADL_(clockid_t *)]; clockid_t * clock_id; char clock_id_r_[PADR_(clockid_t *)]; +}; +struct ntp_gettime_args { + char ntvp_l_[PADL_(struct ntptimeval *)]; struct ntptimeval * ntvp; char ntvp_r_[PADR_(struct ntptimeval *)]; +}; +struct minherit_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char inherit_l_[PADL_(int)]; int inherit; char inherit_r_[PADR_(int)]; +}; +struct rfork_args { + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct issetugid_args { + register_t dummy; +}; +struct lchown_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct aio_read_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_write_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct lio_listio_args { + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + char acb_list_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * acb_list; char acb_list_r_[PADR_(struct aiocb *const *)]; + char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)]; + char sig_l_[PADL_(struct sigevent *)]; struct sigevent * sig; char sig_r_[PADR_(struct sigevent *)]; +}; +struct lchmod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct lutimes_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct preadv_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct pwritev_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct fhopen_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct modnext_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; +}; +struct modstat_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; + char stat_l_[PADL_(struct module_stat *)]; struct module_stat * stat; char stat_r_[PADR_(struct module_stat *)]; +}; +struct modfnext_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; +}; +struct modfind_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct kldload_args { + char file_l_[PADL_(const char *)]; const char * file; char file_r_[PADR_(const char *)]; +}; +struct kldunload_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct kldfind_args { + char file_l_[PADL_(const char *)]; const char * file; char file_r_[PADR_(const char *)]; +}; +struct kldnext_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct kldstat_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; + char stat_l_[PADL_(struct kld_file_stat *)]; struct kld_file_stat * stat; char stat_r_[PADR_(struct kld_file_stat *)]; +}; +struct kldfirstmod_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct getsid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct setresuid_args { + char ruid_l_[PADL_(uid_t)]; uid_t ruid; char ruid_r_[PADR_(uid_t)]; + char euid_l_[PADL_(uid_t)]; uid_t euid; char euid_r_[PADR_(uid_t)]; + char suid_l_[PADL_(uid_t)]; uid_t suid; char suid_r_[PADR_(uid_t)]; +}; +struct setresgid_args { + char rgid_l_[PADL_(gid_t)]; gid_t rgid; char rgid_r_[PADR_(gid_t)]; + char egid_l_[PADL_(gid_t)]; gid_t egid; char egid_r_[PADR_(gid_t)]; + char sgid_l_[PADL_(gid_t)]; gid_t sgid; char sgid_r_[PADR_(gid_t)]; +}; +struct aio_return_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_suspend_args { + char aiocbp_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * aiocbp; char aiocbp_r_[PADR_(struct aiocb *const *)]; + char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct aio_cancel_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_error_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct yield_args { + register_t dummy; +}; +struct mlockall_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct munlockall_args { + register_t dummy; +}; +struct __getcwd_args { + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char buflen_l_[PADL_(size_t)]; size_t buflen; char buflen_r_[PADR_(size_t)]; +}; +struct sched_setparam_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char param_l_[PADL_(const struct sched_param *)]; const struct sched_param * param; char param_r_[PADR_(const struct sched_param *)]; +}; +struct sched_getparam_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char param_l_[PADL_(struct sched_param *)]; struct sched_param * param; char param_r_[PADR_(struct sched_param *)]; +}; +struct sched_setscheduler_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; + char param_l_[PADL_(const struct sched_param *)]; const struct sched_param * param; char param_r_[PADR_(const struct sched_param *)]; +}; +struct sched_getscheduler_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct sched_yield_args { + register_t dummy; +}; +struct sched_get_priority_max_args { + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; +}; +struct sched_get_priority_min_args { + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; +}; +struct sched_rr_get_interval_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char interval_l_[PADL_(struct timespec *)]; struct timespec * interval; char interval_r_[PADR_(struct timespec *)]; +}; +struct utrace_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct kldsym_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; +}; +struct jail_args { + char jail_l_[PADL_(struct jail *)]; struct jail * jail; char jail_r_[PADR_(struct jail *)]; +}; +struct nnpfs_syscall_args { + char operation_l_[PADL_(int)]; int operation; char operation_r_[PADR_(int)]; + char a_pathP_l_[PADL_(char *)]; char * a_pathP; char a_pathP_r_[PADR_(char *)]; + char a_opcode_l_[PADL_(int)]; int a_opcode; char a_opcode_r_[PADR_(int)]; + char a_paramsP_l_[PADL_(void *)]; void * a_paramsP; char a_paramsP_r_[PADR_(void *)]; + char a_followSymlinks_l_[PADL_(int)]; int a_followSymlinks; char a_followSymlinks_r_[PADR_(int)]; +}; +struct sigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char oset_l_[PADL_(sigset_t *)]; sigset_t * oset; char oset_r_[PADR_(sigset_t *)]; +}; +struct sigsuspend_args { + char sigmask_l_[PADL_(const sigset_t *)]; const sigset_t * sigmask; char sigmask_r_[PADR_(const sigset_t *)]; +}; +struct sigpending_args { + char set_l_[PADL_(sigset_t *)]; sigset_t * set; char set_r_[PADR_(sigset_t *)]; +}; +struct sigtimedwait_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char info_l_[PADL_(siginfo_t *)]; siginfo_t * info; char info_r_[PADR_(siginfo_t *)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct sigwaitinfo_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char info_l_[PADL_(siginfo_t *)]; siginfo_t * info; char info_r_[PADR_(siginfo_t *)]; +}; +struct __acl_get_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_get_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_delete_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_delete_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_aclcheck_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_aclcheck_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct extattrctl_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char filename_l_[PADL_(const char *)]; const char * filename; char filename_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct extattr_set_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct aio_waitcomplete_args { + char aiocbp_l_[PADL_(struct aiocb **)]; struct aiocb ** aiocbp; char aiocbp_r_[PADR_(struct aiocb **)]; + char timeout_l_[PADL_(struct timespec *)]; struct timespec * timeout; char timeout_r_[PADR_(struct timespec *)]; +}; +struct getresuid_args { + char ruid_l_[PADL_(uid_t *)]; uid_t * ruid; char ruid_r_[PADR_(uid_t *)]; + char euid_l_[PADL_(uid_t *)]; uid_t * euid; char euid_r_[PADR_(uid_t *)]; + char suid_l_[PADL_(uid_t *)]; uid_t * suid; char suid_r_[PADR_(uid_t *)]; +}; +struct getresgid_args { + char rgid_l_[PADL_(gid_t *)]; gid_t * rgid; char rgid_r_[PADR_(gid_t *)]; + char egid_l_[PADL_(gid_t *)]; gid_t * egid; char egid_r_[PADR_(gid_t *)]; + char sgid_l_[PADL_(gid_t *)]; gid_t * sgid; char sgid_r_[PADR_(gid_t *)]; +}; +struct kqueue_args { + register_t dummy; +}; +struct extattr_set_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct __setugid_args { + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct eaccess_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char amode_l_[PADL_(int)]; int amode; char amode_r_[PADR_(int)]; +}; +struct afs3_syscall_args { + char syscall_l_[PADL_(long)]; long syscall; char syscall_r_[PADR_(long)]; + char parm1_l_[PADL_(long)]; long parm1; char parm1_r_[PADR_(long)]; + char parm2_l_[PADL_(long)]; long parm2; char parm2_r_[PADR_(long)]; + char parm3_l_[PADL_(long)]; long parm3; char parm3_r_[PADR_(long)]; + char parm4_l_[PADL_(long)]; long parm4; char parm4_r_[PADR_(long)]; + char parm5_l_[PADL_(long)]; long parm5; char parm5_r_[PADR_(long)]; + char parm6_l_[PADL_(long)]; long parm6; char parm6_r_[PADR_(long)]; +}; +struct nmount_args { + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(unsigned int)]; unsigned int iovcnt; char iovcnt_r_[PADR_(unsigned int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct __mac_get_proc_args { + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_proc_args { + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_file_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_file_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct kenv_args { + char what_l_[PADL_(int)]; int what; char what_r_[PADR_(int)]; + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; + char value_l_[PADL_(char *)]; char * value; char value_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct lchflags_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(u_long)]; u_long flags; char flags_r_[PADR_(u_long)]; +}; +struct uuidgen_args { + char store_l_[PADL_(struct uuid *)]; struct uuid * store; char store_r_[PADR_(struct uuid *)]; + char count_l_[PADL_(int)]; int count; char count_r_[PADR_(int)]; +}; +struct sendfile_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; + char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)]; + char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct mac_syscall_args { + char policy_l_[PADL_(const char *)]; const char * policy; char policy_r_[PADR_(const char *)]; + char call_l_[PADL_(int)]; int call; char call_r_[PADR_(int)]; + char arg_l_[PADL_(void *)]; void * arg; char arg_r_[PADR_(void *)]; +}; +struct ksem_close_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_post_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_wait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_trywait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_init_args { + char idp_l_[PADL_(semid_t *)]; semid_t * idp; char idp_r_[PADR_(semid_t *)]; + char value_l_[PADL_(unsigned int)]; unsigned int value; char value_r_[PADR_(unsigned int)]; +}; +struct ksem_open_args { + char idp_l_[PADL_(semid_t *)]; semid_t * idp; char idp_r_[PADR_(semid_t *)]; + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; + char oflag_l_[PADL_(int)]; int oflag; char oflag_r_[PADR_(int)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char value_l_[PADL_(unsigned int)]; unsigned int value; char value_r_[PADR_(unsigned int)]; +}; +struct ksem_unlink_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct ksem_getvalue_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; + char val_l_[PADL_(int *)]; int * val; char val_r_[PADR_(int *)]; +}; +struct ksem_destroy_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct __mac_get_pid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_link_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_link_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct extattr_set_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct __mac_execve_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char argv_l_[PADL_(char **)]; char ** argv; char argv_r_[PADR_(char **)]; + char envv_l_[PADL_(char **)]; char ** envv; char envv_r_[PADR_(char **)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct sigaction_args { + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; + char act_l_[PADL_(const struct sigaction *)]; const struct sigaction * act; char act_r_[PADR_(const struct sigaction *)]; + char oact_l_[PADL_(struct sigaction *)]; struct sigaction * oact; char oact_r_[PADR_(struct sigaction *)]; +}; +struct sigreturn_args { + char sigcntxp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * sigcntxp; char sigcntxp_r_[PADR_(const struct __ucontext *)]; +}; +struct getcontext_args { + char ucp_l_[PADL_(struct __ucontext *)]; struct __ucontext * ucp; char ucp_r_[PADR_(struct __ucontext *)]; +}; +struct setcontext_args { + char ucp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * ucp; char ucp_r_[PADR_(const struct __ucontext *)]; +}; +struct swapcontext_args { + char oucp_l_[PADL_(struct __ucontext *)]; struct __ucontext * oucp; char oucp_r_[PADR_(struct __ucontext *)]; + char ucp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * ucp; char ucp_r_[PADR_(const struct __ucontext *)]; +}; +struct swapoff_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct __acl_get_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_delete_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_aclcheck_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct sigwait_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char sig_l_[PADL_(int *)]; int * sig; char sig_r_[PADR_(int *)]; +}; +struct thr_create_args { + char ctx_l_[PADL_(ucontext_t *)]; ucontext_t * ctx; char ctx_r_[PADR_(ucontext_t *)]; + char id_l_[PADL_(long *)]; long * id; char id_r_[PADR_(long *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct thr_exit_args { + char state_l_[PADL_(long *)]; long * state; char state_r_[PADR_(long *)]; +}; +struct thr_self_args { + char id_l_[PADL_(long *)]; long * id; char id_r_[PADR_(long *)]; +}; +struct thr_kill_args { + char id_l_[PADL_(long)]; long id; char id_r_[PADR_(long)]; + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; +}; +struct jail_attach_args { + char jid_l_[PADL_(int)]; int jid; char jid_r_[PADR_(int)]; +}; +struct extattr_list_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_list_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_list_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct ksem_timedwait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; + char abstime_l_[PADL_(const struct timespec *)]; const struct timespec * abstime; char abstime_r_[PADR_(const struct timespec *)]; +}; +struct thr_suspend_args { + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct thr_wake_args { + char id_l_[PADL_(long)]; long id; char id_r_[PADR_(long)]; +}; +struct kldunloadf_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct audit_args { + char record_l_[PADL_(const void *)]; const void * record; char record_r_[PADR_(const void *)]; + char length_l_[PADL_(u_int)]; u_int length; char length_r_[PADR_(u_int)]; +}; +struct auditon_args { + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char length_l_[PADL_(u_int)]; u_int length; char length_r_[PADR_(u_int)]; +}; +struct getauid_args { + char auid_l_[PADL_(uid_t *)]; uid_t * auid; char auid_r_[PADR_(uid_t *)]; +}; +struct setauid_args { + char auid_l_[PADL_(uid_t *)]; uid_t * auid; char auid_r_[PADR_(uid_t *)]; +}; +struct getaudit_args { + char auditinfo_l_[PADL_(struct auditinfo *)]; struct auditinfo * auditinfo; char auditinfo_r_[PADR_(struct auditinfo *)]; +}; +struct setaudit_args { + char auditinfo_l_[PADL_(struct auditinfo *)]; struct auditinfo * auditinfo; char auditinfo_r_[PADR_(struct auditinfo *)]; +}; +struct getaudit_addr_args { + char auditinfo_addr_l_[PADL_(struct auditinfo_addr *)]; struct auditinfo_addr * auditinfo_addr; char auditinfo_addr_r_[PADR_(struct auditinfo_addr *)]; + char length_l_[PADL_(u_int)]; u_int length; char length_r_[PADR_(u_int)]; +}; +struct setaudit_addr_args { + char auditinfo_addr_l_[PADL_(struct auditinfo_addr *)]; struct auditinfo_addr * auditinfo_addr; char auditinfo_addr_r_[PADR_(struct auditinfo_addr *)]; + char length_l_[PADL_(u_int)]; u_int length; char length_r_[PADR_(u_int)]; +}; +struct auditctl_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct _umtx_op_args { + char obj_l_[PADL_(void *)]; void * obj; char obj_r_[PADR_(void *)]; + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char val_l_[PADL_(u_long)]; u_long val; char val_r_[PADR_(u_long)]; + char uaddr1_l_[PADL_(void *)]; void * uaddr1; char uaddr1_r_[PADR_(void *)]; + char uaddr2_l_[PADL_(void *)]; void * uaddr2; char uaddr2_r_[PADR_(void *)]; +}; +struct thr_new_args { + char param_l_[PADL_(struct thr_param *)]; struct thr_param * param; char param_r_[PADR_(struct thr_param *)]; + char param_size_l_[PADL_(int)]; int param_size; char param_size_r_[PADR_(int)]; +}; +struct sigqueue_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; + char value_l_[PADL_(void *)]; void * value; char value_r_[PADR_(void *)]; +}; +struct kmq_open_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char attr_l_[PADL_(const struct mq_attr *)]; const struct mq_attr * attr; char attr_r_[PADR_(const struct mq_attr *)]; +}; +struct kmq_setattr_args { + char mqd_l_[PADL_(int)]; int mqd; char mqd_r_[PADR_(int)]; + char attr_l_[PADL_(const struct mq_attr *)]; const struct mq_attr * attr; char attr_r_[PADR_(const struct mq_attr *)]; + char oattr_l_[PADL_(struct mq_attr *)]; struct mq_attr * oattr; char oattr_r_[PADR_(struct mq_attr *)]; +}; +struct kmq_timedreceive_args { + char mqd_l_[PADL_(int)]; int mqd; char mqd_r_[PADR_(int)]; + char msg_ptr_l_[PADL_(char *)]; char * msg_ptr; char msg_ptr_r_[PADR_(char *)]; + char msg_len_l_[PADL_(size_t)]; size_t msg_len; char msg_len_r_[PADR_(size_t)]; + char msg_prio_l_[PADL_(unsigned *)]; unsigned * msg_prio; char msg_prio_r_[PADR_(unsigned *)]; + char abs_timeout_l_[PADL_(const struct timespec *)]; const struct timespec * abs_timeout; char abs_timeout_r_[PADR_(const struct timespec *)]; +}; +struct kmq_timedsend_args { + char mqd_l_[PADL_(int)]; int mqd; char mqd_r_[PADR_(int)]; + char msg_ptr_l_[PADL_(const char *)]; const char * msg_ptr; char msg_ptr_r_[PADR_(const char *)]; + char msg_len_l_[PADL_(size_t)]; size_t msg_len; char msg_len_r_[PADR_(size_t)]; + char msg_prio_l_[PADL_(unsigned)]; unsigned msg_prio; char msg_prio_r_[PADR_(unsigned)]; + char abs_timeout_l_[PADL_(const struct timespec *)]; const struct timespec * abs_timeout; char abs_timeout_r_[PADR_(const struct timespec *)]; +}; +struct kmq_notify_args { + char mqd_l_[PADL_(int)]; int mqd; char mqd_r_[PADR_(int)]; + char sigev_l_[PADL_(const struct sigevent *)]; const struct sigevent * sigev; char sigev_r_[PADR_(const struct sigevent *)]; +}; +struct kmq_unlink_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; +}; +struct abort2_args { + char why_l_[PADL_(const char *)]; const char * why; char why_r_[PADR_(const char *)]; + char nargs_l_[PADL_(int)]; int nargs; char nargs_r_[PADR_(int)]; + char args_l_[PADL_(void **)]; void ** args; char args_r_[PADR_(void **)]; +}; +struct thr_set_name_args { + char id_l_[PADL_(long)]; long id; char id_r_[PADR_(long)]; + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct aio_fsync_args { + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct rtprio_thread_args { + char function_l_[PADL_(int)]; int function; char function_r_[PADR_(int)]; + char lwpid_l_[PADL_(lwpid_t)]; lwpid_t lwpid; char lwpid_r_[PADR_(lwpid_t)]; + char rtp_l_[PADL_(struct rtprio *)]; struct rtprio * rtp; char rtp_r_[PADR_(struct rtprio *)]; +}; +struct sctp_peeloff_args { + char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)]; + char name_l_[PADL_(uint32_t)]; uint32_t name; char name_r_[PADR_(uint32_t)]; +}; +struct sctp_generic_sendmsg_args { + char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)]; + char msg_l_[PADL_(caddr_t)]; caddr_t msg; char msg_r_[PADR_(caddr_t)]; + char mlen_l_[PADL_(int)]; int mlen; char mlen_r_[PADR_(int)]; + char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)]; + char tolen_l_[PADL_(__socklen_t)]; __socklen_t tolen; char tolen_r_[PADR_(__socklen_t)]; + char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct sctp_generic_sendmsg_iov_args { + char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)]; + char iov_l_[PADL_(struct iovec *)]; struct iovec * iov; char iov_r_[PADR_(struct iovec *)]; + char iovlen_l_[PADL_(int)]; int iovlen; char iovlen_r_[PADR_(int)]; + char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)]; + char tolen_l_[PADL_(__socklen_t)]; __socklen_t tolen; char tolen_r_[PADR_(__socklen_t)]; + char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct sctp_generic_recvmsg_args { + char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)]; + char iov_l_[PADL_(struct iovec *)]; struct iovec * iov; char iov_r_[PADR_(struct iovec *)]; + char iovlen_l_[PADL_(int)]; int iovlen; char iovlen_r_[PADR_(int)]; + char from_l_[PADL_(struct sockaddr *)]; struct sockaddr * from; char from_r_[PADR_(struct sockaddr *)]; + char fromlenaddr_l_[PADL_(__socklen_t *)]; __socklen_t * fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *)]; + char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)]; + char msg_flags_l_[PADL_(int *)]; int * msg_flags; char msg_flags_r_[PADR_(int *)]; +}; +struct pread_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct pwrite_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct mmap_args { + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pos_l_[PADL_(off_t)]; off_t pos; char pos_r_[PADR_(off_t)]; +}; +struct lseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; +}; +struct truncate_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct ftruncate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct thr_kill2_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char id_l_[PADL_(long)]; long id; char id_r_[PADR_(long)]; + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; +}; +struct shm_open_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct shm_unlink_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; +}; +struct cpuset_args { + char setid_l_[PADL_(cpusetid_t *)]; cpusetid_t * setid; char setid_r_[PADR_(cpusetid_t *)]; +}; +struct cpuset_setid_args { + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char setid_l_[PADL_(cpusetid_t)]; cpusetid_t setid; char setid_r_[PADR_(cpusetid_t)]; +}; +struct cpuset_getid_args { + char level_l_[PADL_(cpulevel_t)]; cpulevel_t level; char level_r_[PADR_(cpulevel_t)]; + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char setid_l_[PADL_(cpusetid_t *)]; cpusetid_t * setid; char setid_r_[PADR_(cpusetid_t *)]; +}; +struct cpuset_getaffinity_args { + char level_l_[PADL_(cpulevel_t)]; cpulevel_t level; char level_r_[PADR_(cpulevel_t)]; + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char cpusetsize_l_[PADL_(size_t)]; size_t cpusetsize; char cpusetsize_r_[PADR_(size_t)]; + char mask_l_[PADL_(cpuset_t *)]; cpuset_t * mask; char mask_r_[PADR_(cpuset_t *)]; +}; +struct cpuset_setaffinity_args { + char level_l_[PADL_(cpulevel_t)]; cpulevel_t level; char level_r_[PADR_(cpulevel_t)]; + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char cpusetsize_l_[PADL_(size_t)]; size_t cpusetsize; char cpusetsize_r_[PADR_(size_t)]; + char mask_l_[PADL_(const cpuset_t *)]; const cpuset_t * mask; char mask_r_[PADR_(const cpuset_t *)]; +}; +struct faccessat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char amode_l_[PADL_(int)]; int amode; char amode_r_[PADR_(int)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct fchmodat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct fchownat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char uid_l_[PADL_(uid_t)]; uid_t uid; char uid_r_[PADR_(uid_t)]; + char gid_l_[PADL_(gid_t)]; gid_t gid; char gid_r_[PADR_(gid_t)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct fexecve_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char argv_l_[PADL_(char **)]; char ** argv; char argv_r_[PADR_(char **)]; + char envv_l_[PADL_(char **)]; char ** envv; char envv_r_[PADR_(char **)]; +}; +struct futimesat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char times_l_[PADL_(struct timeval *)]; struct timeval * times; char times_r_[PADR_(struct timeval *)]; +}; +struct linkat_args { + char fd1_l_[PADL_(int)]; int fd1; char fd1_r_[PADR_(int)]; + char path1_l_[PADL_(char *)]; char * path1; char path1_r_[PADR_(char *)]; + char fd2_l_[PADL_(int)]; int fd2; char fd2_r_[PADR_(int)]; + char path2_l_[PADL_(char *)]; char * path2; char path2_r_[PADR_(char *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct mkdirat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct mkfifoat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct openat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct readlinkat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char bufsize_l_[PADL_(size_t)]; size_t bufsize; char bufsize_r_[PADR_(size_t)]; +}; +struct renameat_args { + char oldfd_l_[PADL_(int)]; int oldfd; char oldfd_r_[PADR_(int)]; + char old_l_[PADL_(char *)]; char * old; char old_r_[PADR_(char *)]; + char newfd_l_[PADL_(int)]; int newfd; char newfd_r_[PADR_(int)]; + char new_l_[PADL_(char *)]; char * new; char new_r_[PADR_(char *)]; +}; +struct symlinkat_args { + char path1_l_[PADL_(char *)]; char * path1; char path1_r_[PADR_(char *)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path2_l_[PADL_(char *)]; char * path2; char path2_r_[PADR_(char *)]; +}; +struct unlinkat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct posix_openpt_args { + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct gssd_syscall_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct jail_get_args { + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(unsigned int)]; unsigned int iovcnt; char iovcnt_r_[PADR_(unsigned int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct jail_set_args { + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(unsigned int)]; unsigned int iovcnt; char iovcnt_r_[PADR_(unsigned int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct jail_remove_args { + char jid_l_[PADL_(int)]; int jid; char jid_r_[PADR_(int)]; +}; +struct closefrom_args { + char lowfd_l_[PADL_(int)]; int lowfd; char lowfd_r_[PADR_(int)]; +}; +struct __semctl_args { + char semid_l_[PADL_(int)]; int semid; char semid_r_[PADR_(int)]; + char semnum_l_[PADL_(int)]; int semnum; char semnum_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(union semun *)]; union semun * arg; char arg_r_[PADR_(union semun *)]; +}; +struct msgctl_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct msqid_ds *)]; struct msqid_ds * buf; char buf_r_[PADR_(struct msqid_ds *)]; +}; +struct shmctl_args { + char shmid_l_[PADL_(int)]; int shmid; char shmid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct shmid_ds *)]; struct shmid_ds * buf; char buf_r_[PADR_(struct shmid_ds *)]; +}; +struct lpathconf_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; +}; +struct __cap_rights_get_args { + char version_l_[PADL_(int)]; int version; char version_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char rightsp_l_[PADL_(cap_rights_t *)]; cap_rights_t * rightsp; char rightsp_r_[PADR_(cap_rights_t *)]; +}; +struct cap_enter_args { + register_t dummy; +}; +struct cap_getmode_args { + char modep_l_[PADL_(u_int *)]; u_int * modep; char modep_r_[PADR_(u_int *)]; +}; +struct pdfork_args { + char fdp_l_[PADL_(int *)]; int * fdp; char fdp_r_[PADR_(int *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct pdkill_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; +}; +struct pdgetpid_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pidp_l_[PADL_(pid_t *)]; pid_t * pidp; char pidp_r_[PADR_(pid_t *)]; +}; +struct pselect_args { + char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)]; + char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)]; + char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)]; + char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)]; + char ts_l_[PADL_(const struct timespec *)]; const struct timespec * ts; char ts_r_[PADR_(const struct timespec *)]; + char sm_l_[PADL_(const sigset_t *)]; const sigset_t * sm; char sm_r_[PADR_(const sigset_t *)]; +}; +struct getloginclass_args { + char namebuf_l_[PADL_(char *)]; char * namebuf; char namebuf_r_[PADR_(char *)]; + char namelen_l_[PADL_(size_t)]; size_t namelen; char namelen_r_[PADR_(size_t)]; +}; +struct setloginclass_args { + char namebuf_l_[PADL_(const char *)]; const char * namebuf; char namebuf_r_[PADR_(const char *)]; +}; +struct rctl_get_racct_args { + char inbufp_l_[PADL_(const void *)]; const void * inbufp; char inbufp_r_[PADR_(const void *)]; + char inbuflen_l_[PADL_(size_t)]; size_t inbuflen; char inbuflen_r_[PADR_(size_t)]; + char outbufp_l_[PADL_(void *)]; void * outbufp; char outbufp_r_[PADR_(void *)]; + char outbuflen_l_[PADL_(size_t)]; size_t outbuflen; char outbuflen_r_[PADR_(size_t)]; +}; +struct rctl_get_rules_args { + char inbufp_l_[PADL_(const void *)]; const void * inbufp; char inbufp_r_[PADR_(const void *)]; + char inbuflen_l_[PADL_(size_t)]; size_t inbuflen; char inbuflen_r_[PADR_(size_t)]; + char outbufp_l_[PADL_(void *)]; void * outbufp; char outbufp_r_[PADR_(void *)]; + char outbuflen_l_[PADL_(size_t)]; size_t outbuflen; char outbuflen_r_[PADR_(size_t)]; +}; +struct rctl_get_limits_args { + char inbufp_l_[PADL_(const void *)]; const void * inbufp; char inbufp_r_[PADR_(const void *)]; + char inbuflen_l_[PADL_(size_t)]; size_t inbuflen; char inbuflen_r_[PADR_(size_t)]; + char outbufp_l_[PADL_(void *)]; void * outbufp; char outbufp_r_[PADR_(void *)]; + char outbuflen_l_[PADL_(size_t)]; size_t outbuflen; char outbuflen_r_[PADR_(size_t)]; +}; +struct rctl_add_rule_args { + char inbufp_l_[PADL_(const void *)]; const void * inbufp; char inbufp_r_[PADR_(const void *)]; + char inbuflen_l_[PADL_(size_t)]; size_t inbuflen; char inbuflen_r_[PADR_(size_t)]; + char outbufp_l_[PADL_(void *)]; void * outbufp; char outbufp_r_[PADR_(void *)]; + char outbuflen_l_[PADL_(size_t)]; size_t outbuflen; char outbuflen_r_[PADR_(size_t)]; +}; +struct rctl_remove_rule_args { + char inbufp_l_[PADL_(const void *)]; const void * inbufp; char inbufp_r_[PADR_(const void *)]; + char inbuflen_l_[PADL_(size_t)]; size_t inbuflen; char inbuflen_r_[PADR_(size_t)]; + char outbufp_l_[PADL_(void *)]; void * outbufp; char outbufp_r_[PADR_(void *)]; + char outbuflen_l_[PADL_(size_t)]; size_t outbuflen; char outbuflen_r_[PADR_(size_t)]; +}; +struct posix_fallocate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char len_l_[PADL_(off_t)]; off_t len; char len_r_[PADR_(off_t)]; +}; +struct posix_fadvise_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char len_l_[PADL_(off_t)]; off_t len; char len_r_[PADR_(off_t)]; + char advice_l_[PADL_(int)]; int advice; char advice_r_[PADR_(int)]; +}; +struct wait6_args { + char idtype_l_[PADL_(idtype_t)]; idtype_t idtype; char idtype_r_[PADR_(idtype_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)]; + char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)]; + char wrusage_l_[PADL_(struct __wrusage *)]; struct __wrusage * wrusage; char wrusage_r_[PADR_(struct __wrusage *)]; + char info_l_[PADL_(siginfo_t *)]; siginfo_t * info; char info_r_[PADR_(siginfo_t *)]; +}; +struct cap_rights_limit_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char rightsp_l_[PADL_(cap_rights_t *)]; cap_rights_t * rightsp; char rightsp_r_[PADR_(cap_rights_t *)]; +}; +struct cap_ioctls_limit_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char cmds_l_[PADL_(const u_long *)]; const u_long * cmds; char cmds_r_[PADR_(const u_long *)]; + char ncmds_l_[PADL_(size_t)]; size_t ncmds; char ncmds_r_[PADR_(size_t)]; +}; +struct cap_ioctls_get_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char cmds_l_[PADL_(u_long *)]; u_long * cmds; char cmds_r_[PADR_(u_long *)]; + char maxcmds_l_[PADL_(size_t)]; size_t maxcmds; char maxcmds_r_[PADR_(size_t)]; +}; +struct cap_fcntls_limit_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char fcntlrights_l_[PADL_(uint32_t)]; uint32_t fcntlrights; char fcntlrights_r_[PADR_(uint32_t)]; +}; +struct cap_fcntls_get_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char fcntlrightsp_l_[PADL_(uint32_t *)]; uint32_t * fcntlrightsp; char fcntlrightsp_r_[PADR_(uint32_t *)]; +}; +struct bindat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct connectat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct chflagsat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(u_long)]; u_long flags; char flags_r_[PADR_(u_long)]; + char atflag_l_[PADL_(int)]; int atflag; char atflag_r_[PADR_(int)]; +}; +struct accept4_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)]; + char anamelen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict anamelen; char anamelen_r_[PADR_(__socklen_t *__restrict)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct pipe2_args { + char fildes_l_[PADL_(int *)]; int * fildes; char fildes_r_[PADR_(int *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct aio_mlock_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct procctl_args { + char idtype_l_[PADL_(idtype_t)]; idtype_t idtype; char idtype_r_[PADR_(idtype_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char com_l_[PADL_(int)]; int com; char com_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; +}; +struct ppoll_args { + char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)]; + char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)]; + char ts_l_[PADL_(const struct timespec *)]; const struct timespec * ts; char ts_r_[PADR_(const struct timespec *)]; + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; +}; +struct futimens_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char times_l_[PADL_(struct timespec *)]; struct timespec * times; char times_r_[PADR_(struct timespec *)]; +}; +struct utimensat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char times_l_[PADL_(struct timespec *)]; struct timespec * times; char times_r_[PADR_(struct timespec *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct fdatasync_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct fstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct stat *)]; struct stat * sb; char sb_r_[PADR_(struct stat *)]; +}; +struct fstatat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct stat *)]; struct stat * buf; char buf_r_[PADR_(struct stat *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct fhstat_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char sb_l_[PADL_(struct stat *)]; struct stat * sb; char sb_r_[PADR_(struct stat *)]; +}; +struct getdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(size_t)]; size_t count; char count_r_[PADR_(size_t)]; + char basep_l_[PADL_(off_t *)]; off_t * basep; char basep_r_[PADR_(off_t *)]; +}; +struct statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct getfsstat_args { + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; + char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct fhstatfs_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct mknodat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char dev_l_[PADL_(dev_t)]; dev_t dev; char dev_r_[PADR_(dev_t)]; +}; +struct kevent_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char changelist_l_[PADL_(struct kevent *)]; struct kevent * changelist; char changelist_r_[PADR_(struct kevent *)]; + char nchanges_l_[PADL_(int)]; int nchanges; char nchanges_r_[PADR_(int)]; + char eventlist_l_[PADL_(struct kevent *)]; struct kevent * eventlist; char eventlist_r_[PADR_(struct kevent *)]; + char nevents_l_[PADL_(int)]; int nevents; char nevents_r_[PADR_(int)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct cpuset_getdomain_args { + char level_l_[PADL_(cpulevel_t)]; cpulevel_t level; char level_r_[PADR_(cpulevel_t)]; + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char domainsetsize_l_[PADL_(size_t)]; size_t domainsetsize; char domainsetsize_r_[PADR_(size_t)]; + char mask_l_[PADL_(domainset_t *)]; domainset_t * mask; char mask_r_[PADR_(domainset_t *)]; + char policy_l_[PADL_(int *)]; int * policy; char policy_r_[PADR_(int *)]; +}; +struct cpuset_setdomain_args { + char level_l_[PADL_(cpulevel_t)]; cpulevel_t level; char level_r_[PADR_(cpulevel_t)]; + char which_l_[PADL_(cpuwhich_t)]; cpuwhich_t which; char which_r_[PADR_(cpuwhich_t)]; + char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)]; + char domainsetsize_l_[PADL_(size_t)]; size_t domainsetsize; char domainsetsize_r_[PADR_(size_t)]; + char mask_l_[PADL_(domainset_t *)]; domainset_t * mask; char mask_r_[PADR_(domainset_t *)]; + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; +}; +struct getrandom_args { + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char buflen_l_[PADL_(size_t)]; size_t buflen; char buflen_r_[PADR_(size_t)]; + char flags_l_[PADL_(unsigned int)]; unsigned int flags; char flags_r_[PADR_(unsigned int)]; +}; +struct getfhat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct fhlink_args { + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; + char to_l_[PADL_(const char *)]; const char * to; char to_r_[PADR_(const char *)]; +}; +struct fhlinkat_args { + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; + char tofd_l_[PADL_(int)]; int tofd; char tofd_r_[PADR_(int)]; + char to_l_[PADL_(const char *)]; const char * to; char to_r_[PADR_(const char *)]; +}; +struct fhreadlink_args { + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char bufsize_l_[PADL_(size_t)]; size_t bufsize; char bufsize_r_[PADR_(size_t)]; +}; +struct __sysctlbyname_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; + char namelen_l_[PADL_(size_t)]; size_t namelen; char namelen_r_[PADR_(size_t)]; + char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)]; + char oldlenp_l_[PADL_(size_t *)]; size_t * oldlenp; char oldlenp_r_[PADR_(size_t *)]; + char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)]; + char newlen_l_[PADL_(size_t)]; size_t newlen; char newlen_r_[PADR_(size_t)]; +}; +struct close_range_args { + char lowfd_l_[PADL_(u_int)]; u_int lowfd; char lowfd_r_[PADR_(u_int)]; + char highfd_l_[PADL_(u_int)]; u_int highfd; char highfd_r_[PADR_(u_int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +int nosys(struct thread *, struct nosys_args *); +void sys_sys_exit(struct thread *, struct sys_exit_args *); +int sys_fork(struct thread *, struct fork_args *); +int sys_read(struct thread *, struct read_args *); +int sys_write(struct thread *, struct write_args *); +int sys_open(struct thread *, struct open_args *); +int sys_close(struct thread *, struct close_args *); +int sys_wait4(struct thread *, struct wait4_args *); +int sys_link(struct thread *, struct link_args *); +int sys_unlink(struct thread *, struct unlink_args *); +int sys_chdir(struct thread *, struct chdir_args *); +int sys_fchdir(struct thread *, struct fchdir_args *); +int sys_chmod(struct thread *, struct chmod_args *); +int sys_chown(struct thread *, struct chown_args *); +int sys_break(struct thread *, struct break_args *); +int sys_getpid(struct thread *, struct getpid_args *); +int sys_mount(struct thread *, struct mount_args *); +int sys_unmount(struct thread *, struct unmount_args *); +int sys_setuid(struct thread *, struct setuid_args *); +int sys_getuid(struct thread *, struct getuid_args *); +int sys_geteuid(struct thread *, struct geteuid_args *); +int sys_ptrace(struct thread *, struct ptrace_args *); +int sys_recvmsg(struct thread *, struct recvmsg_args *); +int sys_sendmsg(struct thread *, struct sendmsg_args *); +int sys_recvfrom(struct thread *, struct recvfrom_args *); +int sys_accept(struct thread *, struct accept_args *); +int sys_getpeername(struct thread *, struct getpeername_args *); +int sys_getsockname(struct thread *, struct getsockname_args *); +int sys_access(struct thread *, struct access_args *); +int sys_chflags(struct thread *, struct chflags_args *); +int sys_fchflags(struct thread *, struct fchflags_args *); +int sys_sync(struct thread *, struct sync_args *); +int sys_kill(struct thread *, struct kill_args *); +int sys_getppid(struct thread *, struct getppid_args *); +int sys_dup(struct thread *, struct dup_args *); +int sys_getegid(struct thread *, struct getegid_args *); +int sys_profil(struct thread *, struct profil_args *); +int sys_ktrace(struct thread *, struct ktrace_args *); +int sys_getgid(struct thread *, struct getgid_args *); +int sys_getlogin(struct thread *, struct getlogin_args *); +int sys_setlogin(struct thread *, struct setlogin_args *); +int sys_acct(struct thread *, struct acct_args *); +int sys_sigaltstack(struct thread *, struct sigaltstack_args *); +int sys_ioctl(struct thread *, struct ioctl_args *); +int sys_reboot(struct thread *, struct reboot_args *); +int sys_revoke(struct thread *, struct revoke_args *); +int sys_symlink(struct thread *, struct symlink_args *); +int sys_readlink(struct thread *, struct readlink_args *); +int sys_execve(struct thread *, struct execve_args *); +int sys_umask(struct thread *, struct umask_args *); +int sys_chroot(struct thread *, struct chroot_args *); +int sys_msync(struct thread *, struct msync_args *); +int sys_vfork(struct thread *, struct vfork_args *); +int sys_sbrk(struct thread *, struct sbrk_args *); +int sys_sstk(struct thread *, struct sstk_args *); +int sys_munmap(struct thread *, struct munmap_args *); +int sys_mprotect(struct thread *, struct mprotect_args *); +int sys_madvise(struct thread *, struct madvise_args *); +int sys_mincore(struct thread *, struct mincore_args *); +int sys_getgroups(struct thread *, struct getgroups_args *); +int sys_setgroups(struct thread *, struct setgroups_args *); +int sys_getpgrp(struct thread *, struct getpgrp_args *); +int sys_setpgid(struct thread *, struct setpgid_args *); +int sys_setitimer(struct thread *, struct setitimer_args *); +int sys_swapon(struct thread *, struct swapon_args *); +int sys_getitimer(struct thread *, struct getitimer_args *); +int sys_getdtablesize(struct thread *, struct getdtablesize_args *); +int sys_dup2(struct thread *, struct dup2_args *); +int sys_fcntl(struct thread *, struct fcntl_args *); +int sys_select(struct thread *, struct select_args *); +int sys_fsync(struct thread *, struct fsync_args *); +int sys_setpriority(struct thread *, struct setpriority_args *); +int sys_socket(struct thread *, struct socket_args *); +int sys_connect(struct thread *, struct connect_args *); +int sys_getpriority(struct thread *, struct getpriority_args *); +int sys_bind(struct thread *, struct bind_args *); +int sys_setsockopt(struct thread *, struct setsockopt_args *); +int sys_listen(struct thread *, struct listen_args *); +int sys_gettimeofday(struct thread *, struct gettimeofday_args *); +int sys_getrusage(struct thread *, struct getrusage_args *); +int sys_getsockopt(struct thread *, struct getsockopt_args *); +int sys_readv(struct thread *, struct readv_args *); +int sys_writev(struct thread *, struct writev_args *); +int sys_settimeofday(struct thread *, struct settimeofday_args *); +int sys_fchown(struct thread *, struct fchown_args *); +int sys_fchmod(struct thread *, struct fchmod_args *); +int sys_setreuid(struct thread *, struct setreuid_args *); +int sys_setregid(struct thread *, struct setregid_args *); +int sys_rename(struct thread *, struct rename_args *); +int sys_flock(struct thread *, struct flock_args *); +int sys_mkfifo(struct thread *, struct mkfifo_args *); +int sys_sendto(struct thread *, struct sendto_args *); +int sys_shutdown(struct thread *, struct shutdown_args *); +int sys_socketpair(struct thread *, struct socketpair_args *); +int sys_mkdir(struct thread *, struct mkdir_args *); +int sys_rmdir(struct thread *, struct rmdir_args *); +int sys_utimes(struct thread *, struct utimes_args *); +int sys_adjtime(struct thread *, struct adjtime_args *); +int sys_setsid(struct thread *, struct setsid_args *); +int sys_quotactl(struct thread *, struct quotactl_args *); +int sys_nlm_syscall(struct thread *, struct nlm_syscall_args *); +int sys_nfssvc(struct thread *, struct nfssvc_args *); +int sys_lgetfh(struct thread *, struct lgetfh_args *); +int sys_getfh(struct thread *, struct getfh_args *); +int sysarch(struct thread *, struct sysarch_args *); +int sys_rtprio(struct thread *, struct rtprio_args *); +int sys_semsys(struct thread *, struct semsys_args *); +int sys_msgsys(struct thread *, struct msgsys_args *); +int sys_shmsys(struct thread *, struct shmsys_args *); +int sys_setfib(struct thread *, struct setfib_args *); +int sys_ntp_adjtime(struct thread *, struct ntp_adjtime_args *); +int sys_setgid(struct thread *, struct setgid_args *); +int sys_setegid(struct thread *, struct setegid_args *); +int sys_seteuid(struct thread *, struct seteuid_args *); +int sys_pathconf(struct thread *, struct pathconf_args *); +int sys_fpathconf(struct thread *, struct fpathconf_args *); +int sys_getrlimit(struct thread *, struct __getrlimit_args *); +int sys_setrlimit(struct thread *, struct __setrlimit_args *); +int sys___sysctl(struct thread *, struct sysctl_args *); +int sys_mlock(struct thread *, struct mlock_args *); +int sys_munlock(struct thread *, struct munlock_args *); +int sys_undelete(struct thread *, struct undelete_args *); +int sys_futimes(struct thread *, struct futimes_args *); +int sys_getpgid(struct thread *, struct getpgid_args *); +int sys_poll(struct thread *, struct poll_args *); +int sys_semget(struct thread *, struct semget_args *); +int sys_semop(struct thread *, struct semop_args *); +int sys_msgget(struct thread *, struct msgget_args *); +int sys_msgsnd(struct thread *, struct msgsnd_args *); +int sys_msgrcv(struct thread *, struct msgrcv_args *); +int sys_shmat(struct thread *, struct shmat_args *); +int sys_shmdt(struct thread *, struct shmdt_args *); +int sys_shmget(struct thread *, struct shmget_args *); +int sys_clock_gettime(struct thread *, struct clock_gettime_args *); +int sys_clock_settime(struct thread *, struct clock_settime_args *); +int sys_clock_getres(struct thread *, struct clock_getres_args *); +int sys_ktimer_create(struct thread *, struct ktimer_create_args *); +int sys_ktimer_delete(struct thread *, struct ktimer_delete_args *); +int sys_ktimer_settime(struct thread *, struct ktimer_settime_args *); +int sys_ktimer_gettime(struct thread *, struct ktimer_gettime_args *); +int sys_ktimer_getoverrun(struct thread *, struct ktimer_getoverrun_args *); +int sys_nanosleep(struct thread *, struct nanosleep_args *); +int sys_ffclock_getcounter(struct thread *, struct ffclock_getcounter_args *); +int sys_ffclock_setestimate(struct thread *, struct ffclock_setestimate_args *); +int sys_ffclock_getestimate(struct thread *, struct ffclock_getestimate_args *); +int sys_clock_nanosleep(struct thread *, struct clock_nanosleep_args *); +int sys_clock_getcpuclockid2(struct thread *, struct clock_getcpuclockid2_args *); +int sys_ntp_gettime(struct thread *, struct ntp_gettime_args *); +int sys_minherit(struct thread *, struct minherit_args *); +int sys_rfork(struct thread *, struct rfork_args *); +int sys_issetugid(struct thread *, struct issetugid_args *); +int sys_lchown(struct thread *, struct lchown_args *); +int sys_aio_read(struct thread *, struct aio_read_args *); +int sys_aio_write(struct thread *, struct aio_write_args *); +int sys_lio_listio(struct thread *, struct lio_listio_args *); +int sys_lchmod(struct thread *, struct lchmod_args *); +int sys_lutimes(struct thread *, struct lutimes_args *); +int sys_preadv(struct thread *, struct preadv_args *); +int sys_pwritev(struct thread *, struct pwritev_args *); +int sys_fhopen(struct thread *, struct fhopen_args *); +int sys_modnext(struct thread *, struct modnext_args *); +int sys_modstat(struct thread *, struct modstat_args *); +int sys_modfnext(struct thread *, struct modfnext_args *); +int sys_modfind(struct thread *, struct modfind_args *); +int sys_kldload(struct thread *, struct kldload_args *); +int sys_kldunload(struct thread *, struct kldunload_args *); +int sys_kldfind(struct thread *, struct kldfind_args *); +int sys_kldnext(struct thread *, struct kldnext_args *); +int sys_kldstat(struct thread *, struct kldstat_args *); +int sys_kldfirstmod(struct thread *, struct kldfirstmod_args *); +int sys_getsid(struct thread *, struct getsid_args *); +int sys_setresuid(struct thread *, struct setresuid_args *); +int sys_setresgid(struct thread *, struct setresgid_args *); +int sys_aio_return(struct thread *, struct aio_return_args *); +int sys_aio_suspend(struct thread *, struct aio_suspend_args *); +int sys_aio_cancel(struct thread *, struct aio_cancel_args *); +int sys_aio_error(struct thread *, struct aio_error_args *); +int sys_yield(struct thread *, struct yield_args *); +int sys_mlockall(struct thread *, struct mlockall_args *); +int sys_munlockall(struct thread *, struct munlockall_args *); +int sys___getcwd(struct thread *, struct __getcwd_args *); +int sys_sched_setparam(struct thread *, struct sched_setparam_args *); +int sys_sched_getparam(struct thread *, struct sched_getparam_args *); +int sys_sched_setscheduler(struct thread *, struct sched_setscheduler_args *); +int sys_sched_getscheduler(struct thread *, struct sched_getscheduler_args *); +int sys_sched_yield(struct thread *, struct sched_yield_args *); +int sys_sched_get_priority_max(struct thread *, struct sched_get_priority_max_args *); +int sys_sched_get_priority_min(struct thread *, struct sched_get_priority_min_args *); +int sys_sched_rr_get_interval(struct thread *, struct sched_rr_get_interval_args *); +int sys_utrace(struct thread *, struct utrace_args *); +int sys_kldsym(struct thread *, struct kldsym_args *); +int sys_jail(struct thread *, struct jail_args *); +int sys_nnpfs_syscall(struct thread *, struct nnpfs_syscall_args *); +int sys_sigprocmask(struct thread *, struct sigprocmask_args *); +int sys_sigsuspend(struct thread *, struct sigsuspend_args *); +int sys_sigpending(struct thread *, struct sigpending_args *); +int sys_sigtimedwait(struct thread *, struct sigtimedwait_args *); +int sys_sigwaitinfo(struct thread *, struct sigwaitinfo_args *); +int sys___acl_get_file(struct thread *, struct __acl_get_file_args *); +int sys___acl_set_file(struct thread *, struct __acl_set_file_args *); +int sys___acl_get_fd(struct thread *, struct __acl_get_fd_args *); +int sys___acl_set_fd(struct thread *, struct __acl_set_fd_args *); +int sys___acl_delete_file(struct thread *, struct __acl_delete_file_args *); +int sys___acl_delete_fd(struct thread *, struct __acl_delete_fd_args *); +int sys___acl_aclcheck_file(struct thread *, struct __acl_aclcheck_file_args *); +int sys___acl_aclcheck_fd(struct thread *, struct __acl_aclcheck_fd_args *); +int sys_extattrctl(struct thread *, struct extattrctl_args *); +int sys_extattr_set_file(struct thread *, struct extattr_set_file_args *); +int sys_extattr_get_file(struct thread *, struct extattr_get_file_args *); +int sys_extattr_delete_file(struct thread *, struct extattr_delete_file_args *); +int sys_aio_waitcomplete(struct thread *, struct aio_waitcomplete_args *); +int sys_getresuid(struct thread *, struct getresuid_args *); +int sys_getresgid(struct thread *, struct getresgid_args *); +int sys_kqueue(struct thread *, struct kqueue_args *); +int sys_extattr_set_fd(struct thread *, struct extattr_set_fd_args *); +int sys_extattr_get_fd(struct thread *, struct extattr_get_fd_args *); +int sys_extattr_delete_fd(struct thread *, struct extattr_delete_fd_args *); +int sys___setugid(struct thread *, struct __setugid_args *); +int sys_eaccess(struct thread *, struct eaccess_args *); +int sys_afs3_syscall(struct thread *, struct afs3_syscall_args *); +int sys_nmount(struct thread *, struct nmount_args *); +int sys___mac_get_proc(struct thread *, struct __mac_get_proc_args *); +int sys___mac_set_proc(struct thread *, struct __mac_set_proc_args *); +int sys___mac_get_fd(struct thread *, struct __mac_get_fd_args *); +int sys___mac_get_file(struct thread *, struct __mac_get_file_args *); +int sys___mac_set_fd(struct thread *, struct __mac_set_fd_args *); +int sys___mac_set_file(struct thread *, struct __mac_set_file_args *); +int sys_kenv(struct thread *, struct kenv_args *); +int sys_lchflags(struct thread *, struct lchflags_args *); +int sys_uuidgen(struct thread *, struct uuidgen_args *); +int sys_sendfile(struct thread *, struct sendfile_args *); +int sys_mac_syscall(struct thread *, struct mac_syscall_args *); +int sys_ksem_close(struct thread *, struct ksem_close_args *); +int sys_ksem_post(struct thread *, struct ksem_post_args *); +int sys_ksem_wait(struct thread *, struct ksem_wait_args *); +int sys_ksem_trywait(struct thread *, struct ksem_trywait_args *); +int sys_ksem_init(struct thread *, struct ksem_init_args *); +int sys_ksem_open(struct thread *, struct ksem_open_args *); +int sys_ksem_unlink(struct thread *, struct ksem_unlink_args *); +int sys_ksem_getvalue(struct thread *, struct ksem_getvalue_args *); +int sys_ksem_destroy(struct thread *, struct ksem_destroy_args *); +int sys___mac_get_pid(struct thread *, struct __mac_get_pid_args *); +int sys___mac_get_link(struct thread *, struct __mac_get_link_args *); +int sys___mac_set_link(struct thread *, struct __mac_set_link_args *); +int sys_extattr_set_link(struct thread *, struct extattr_set_link_args *); +int sys_extattr_get_link(struct thread *, struct extattr_get_link_args *); +int sys_extattr_delete_link(struct thread *, struct extattr_delete_link_args *); +int sys___mac_execve(struct thread *, struct __mac_execve_args *); +int sys_sigaction(struct thread *, struct sigaction_args *); +int sys_sigreturn(struct thread *, struct sigreturn_args *); +int sys_getcontext(struct thread *, struct getcontext_args *); +int sys_setcontext(struct thread *, struct setcontext_args *); +int sys_swapcontext(struct thread *, struct swapcontext_args *); +int sys_swapoff(struct thread *, struct swapoff_args *); +int sys___acl_get_link(struct thread *, struct __acl_get_link_args *); +int sys___acl_set_link(struct thread *, struct __acl_set_link_args *); +int sys___acl_delete_link(struct thread *, struct __acl_delete_link_args *); +int sys___acl_aclcheck_link(struct thread *, struct __acl_aclcheck_link_args *); +int sys_sigwait(struct thread *, struct sigwait_args *); +int sys_thr_create(struct thread *, struct thr_create_args *); +int sys_thr_exit(struct thread *, struct thr_exit_args *); +int sys_thr_self(struct thread *, struct thr_self_args *); +int sys_thr_kill(struct thread *, struct thr_kill_args *); +int sys_jail_attach(struct thread *, struct jail_attach_args *); +int sys_extattr_list_fd(struct thread *, struct extattr_list_fd_args *); +int sys_extattr_list_file(struct thread *, struct extattr_list_file_args *); +int sys_extattr_list_link(struct thread *, struct extattr_list_link_args *); +int sys_ksem_timedwait(struct thread *, struct ksem_timedwait_args *); +int sys_thr_suspend(struct thread *, struct thr_suspend_args *); +int sys_thr_wake(struct thread *, struct thr_wake_args *); +int sys_kldunloadf(struct thread *, struct kldunloadf_args *); +int sys_audit(struct thread *, struct audit_args *); +int sys_auditon(struct thread *, struct auditon_args *); +int sys_getauid(struct thread *, struct getauid_args *); +int sys_setauid(struct thread *, struct setauid_args *); +int sys_getaudit(struct thread *, struct getaudit_args *); +int sys_setaudit(struct thread *, struct setaudit_args *); +int sys_getaudit_addr(struct thread *, struct getaudit_addr_args *); +int sys_setaudit_addr(struct thread *, struct setaudit_addr_args *); +int sys_auditctl(struct thread *, struct auditctl_args *); +int sys__umtx_op(struct thread *, struct _umtx_op_args *); +int sys_thr_new(struct thread *, struct thr_new_args *); +int sys_sigqueue(struct thread *, struct sigqueue_args *); +int sys_kmq_open(struct thread *, struct kmq_open_args *); +int sys_kmq_setattr(struct thread *, struct kmq_setattr_args *); +int sys_kmq_timedreceive(struct thread *, struct kmq_timedreceive_args *); +int sys_kmq_timedsend(struct thread *, struct kmq_timedsend_args *); +int sys_kmq_notify(struct thread *, struct kmq_notify_args *); +int sys_kmq_unlink(struct thread *, struct kmq_unlink_args *); +int sys_abort2(struct thread *, struct abort2_args *); +int sys_thr_set_name(struct thread *, struct thr_set_name_args *); +int sys_aio_fsync(struct thread *, struct aio_fsync_args *); +int sys_rtprio_thread(struct thread *, struct rtprio_thread_args *); +int sys_sctp_peeloff(struct thread *, struct sctp_peeloff_args *); +int sys_sctp_generic_sendmsg(struct thread *, struct sctp_generic_sendmsg_args *); +int sys_sctp_generic_sendmsg_iov(struct thread *, struct sctp_generic_sendmsg_iov_args *); +int sys_sctp_generic_recvmsg(struct thread *, struct sctp_generic_recvmsg_args *); +int sys_pread(struct thread *, struct pread_args *); +int sys_pwrite(struct thread *, struct pwrite_args *); +int sys_mmap(struct thread *, struct mmap_args *); +int sys_lseek(struct thread *, struct lseek_args *); +int sys_truncate(struct thread *, struct truncate_args *); +int sys_ftruncate(struct thread *, struct ftruncate_args *); +int sys_thr_kill2(struct thread *, struct thr_kill2_args *); +int sys_shm_open(struct thread *, struct shm_open_args *); +int sys_shm_unlink(struct thread *, struct shm_unlink_args *); +int sys_cpuset(struct thread *, struct cpuset_args *); +int sys_cpuset_setid(struct thread *, struct cpuset_setid_args *); +int sys_cpuset_getid(struct thread *, struct cpuset_getid_args *); +int sys_cpuset_getaffinity(struct thread *, struct cpuset_getaffinity_args *); +int sys_cpuset_setaffinity(struct thread *, struct cpuset_setaffinity_args *); +int sys_faccessat(struct thread *, struct faccessat_args *); +int sys_fchmodat(struct thread *, struct fchmodat_args *); +int sys_fchownat(struct thread *, struct fchownat_args *); +int sys_fexecve(struct thread *, struct fexecve_args *); +int sys_futimesat(struct thread *, struct futimesat_args *); +int sys_linkat(struct thread *, struct linkat_args *); +int sys_mkdirat(struct thread *, struct mkdirat_args *); +int sys_mkfifoat(struct thread *, struct mkfifoat_args *); +int sys_openat(struct thread *, struct openat_args *); +int sys_readlinkat(struct thread *, struct readlinkat_args *); +int sys_renameat(struct thread *, struct renameat_args *); +int sys_symlinkat(struct thread *, struct symlinkat_args *); +int sys_unlinkat(struct thread *, struct unlinkat_args *); +int sys_posix_openpt(struct thread *, struct posix_openpt_args *); +int sys_gssd_syscall(struct thread *, struct gssd_syscall_args *); +int sys_jail_get(struct thread *, struct jail_get_args *); +int sys_jail_set(struct thread *, struct jail_set_args *); +int sys_jail_remove(struct thread *, struct jail_remove_args *); +int sys_closefrom(struct thread *, struct closefrom_args *); +int sys___semctl(struct thread *, struct __semctl_args *); +int sys_msgctl(struct thread *, struct msgctl_args *); +int sys_shmctl(struct thread *, struct shmctl_args *); +int sys_lpathconf(struct thread *, struct lpathconf_args *); +int sys___cap_rights_get(struct thread *, struct __cap_rights_get_args *); +int sys_cap_enter(struct thread *, struct cap_enter_args *); +int sys_cap_getmode(struct thread *, struct cap_getmode_args *); +int sys_pdfork(struct thread *, struct pdfork_args *); +int sys_pdkill(struct thread *, struct pdkill_args *); +int sys_pdgetpid(struct thread *, struct pdgetpid_args *); +int sys_pselect(struct thread *, struct pselect_args *); +int sys_getloginclass(struct thread *, struct getloginclass_args *); +int sys_setloginclass(struct thread *, struct setloginclass_args *); +int sys_rctl_get_racct(struct thread *, struct rctl_get_racct_args *); +int sys_rctl_get_rules(struct thread *, struct rctl_get_rules_args *); +int sys_rctl_get_limits(struct thread *, struct rctl_get_limits_args *); +int sys_rctl_add_rule(struct thread *, struct rctl_add_rule_args *); +int sys_rctl_remove_rule(struct thread *, struct rctl_remove_rule_args *); +int sys_posix_fallocate(struct thread *, struct posix_fallocate_args *); +int sys_posix_fadvise(struct thread *, struct posix_fadvise_args *); +int sys_wait6(struct thread *, struct wait6_args *); +int sys_cap_rights_limit(struct thread *, struct cap_rights_limit_args *); +int sys_cap_ioctls_limit(struct thread *, struct cap_ioctls_limit_args *); +int sys_cap_ioctls_get(struct thread *, struct cap_ioctls_get_args *); +int sys_cap_fcntls_limit(struct thread *, struct cap_fcntls_limit_args *); +int sys_cap_fcntls_get(struct thread *, struct cap_fcntls_get_args *); +int sys_bindat(struct thread *, struct bindat_args *); +int sys_connectat(struct thread *, struct connectat_args *); +int sys_chflagsat(struct thread *, struct chflagsat_args *); +int sys_accept4(struct thread *, struct accept4_args *); +int sys_pipe2(struct thread *, struct pipe2_args *); +int sys_aio_mlock(struct thread *, struct aio_mlock_args *); +int sys_procctl(struct thread *, struct procctl_args *); +int sys_ppoll(struct thread *, struct ppoll_args *); +int sys_futimens(struct thread *, struct futimens_args *); +int sys_utimensat(struct thread *, struct utimensat_args *); +int sys_fdatasync(struct thread *, struct fdatasync_args *); +int sys_fstat(struct thread *, struct fstat_args *); +int sys_fstatat(struct thread *, struct fstatat_args *); +int sys_fhstat(struct thread *, struct fhstat_args *); +int sys_getdirentries(struct thread *, struct getdirentries_args *); +int sys_statfs(struct thread *, struct statfs_args *); +int sys_fstatfs(struct thread *, struct fstatfs_args *); +int sys_getfsstat(struct thread *, struct getfsstat_args *); +int sys_fhstatfs(struct thread *, struct fhstatfs_args *); +int sys_mknodat(struct thread *, struct mknodat_args *); +int sys_kevent(struct thread *, struct kevent_args *); +int sys_cpuset_getdomain(struct thread *, struct cpuset_getdomain_args *); +int sys_cpuset_setdomain(struct thread *, struct cpuset_setdomain_args *); +int sys_getrandom(struct thread *, struct getrandom_args *); +int sys_getfhat(struct thread *, struct getfhat_args *); +int sys_fhlink(struct thread *, struct fhlink_args *); +int sys_fhlinkat(struct thread *, struct fhlinkat_args *); +int sys_fhreadlink(struct thread *, struct fhreadlink_args *); +int sys___sysctlbyname(struct thread *, struct __sysctlbyname_args *); +int sys_close_range(struct thread *, struct close_range_args *); + +#ifdef COMPAT_43 + +struct ocreat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct olseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char offset_l_[PADL_(long)]; long offset; char offset_r_[PADR_(long)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; +}; +struct ostat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct ostat *)]; struct ostat * ub; char ub_r_[PADR_(struct ostat *)]; +}; +struct olstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct ostat *)]; struct ostat * ub; char ub_r_[PADR_(struct ostat *)]; +}; +struct osigaction_args { + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; + char nsa_l_[PADL_(struct osigaction *)]; struct osigaction * nsa; char nsa_r_[PADR_(struct osigaction *)]; + char osa_l_[PADL_(struct osigaction *)]; struct osigaction * osa; char osa_r_[PADR_(struct osigaction *)]; +}; +struct osigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char mask_l_[PADL_(osigset_t)]; osigset_t mask; char mask_r_[PADR_(osigset_t)]; +}; +struct ofstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct ostat *)]; struct ostat * sb; char sb_r_[PADR_(struct ostat *)]; +}; +struct getkerninfo_args { + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char where_l_[PADL_(char *)]; char * where; char where_r_[PADR_(char *)]; + char size_l_[PADL_(size_t *)]; size_t * size; char size_r_[PADR_(size_t *)]; + char arg_l_[PADL_(int)]; int arg; char arg_r_[PADR_(int)]; +}; +struct ommap_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pos_l_[PADL_(long)]; long pos; char pos_r_[PADR_(long)]; +}; +struct gethostname_args { + char hostname_l_[PADL_(char *)]; char * hostname; char hostname_r_[PADR_(char *)]; + char len_l_[PADL_(u_int)]; u_int len; char len_r_[PADR_(u_int)]; +}; +struct sethostname_args { + char hostname_l_[PADL_(char *)]; char * hostname; char hostname_r_[PADR_(char *)]; + char len_l_[PADL_(u_int)]; u_int len; char len_r_[PADR_(u_int)]; +}; +struct osend_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct orecv_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct osigreturn_args { + char sigcntxp_l_[PADL_(struct osigcontext *)]; struct osigcontext * sigcntxp; char sigcntxp_r_[PADR_(struct osigcontext *)]; +}; +struct osigvec_args { + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; + char nsv_l_[PADL_(struct sigvec *)]; struct sigvec * nsv; char nsv_r_[PADR_(struct sigvec *)]; + char osv_l_[PADL_(struct sigvec *)]; struct sigvec * osv; char osv_r_[PADR_(struct sigvec *)]; +}; +struct osigblock_args { + char mask_l_[PADL_(int)]; int mask; char mask_r_[PADR_(int)]; +}; +struct osigsetmask_args { + char mask_l_[PADL_(int)]; int mask; char mask_r_[PADR_(int)]; +}; +struct osigsuspend_args { + char mask_l_[PADL_(osigset_t)]; osigset_t mask; char mask_r_[PADR_(osigset_t)]; +}; +struct osigstack_args { + char nss_l_[PADL_(struct sigstack *)]; struct sigstack * nss; char nss_r_[PADR_(struct sigstack *)]; + char oss_l_[PADL_(struct sigstack *)]; struct sigstack * oss; char oss_r_[PADR_(struct sigstack *)]; +}; +struct orecvmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct omsghdr *)]; struct omsghdr * msg; char msg_r_[PADR_(struct omsghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct osendmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(caddr_t)]; caddr_t msg; char msg_r_[PADR_(caddr_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct otruncate_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char length_l_[PADL_(long)]; long length; char length_r_[PADR_(long)]; +}; +struct oftruncate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char length_l_[PADL_(long)]; long length; char length_r_[PADR_(long)]; +}; +struct ogetpeername_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(caddr_t)]; caddr_t asa; char asa_r_[PADR_(caddr_t)]; + char alen_l_[PADL_(int *)]; int * alen; char alen_r_[PADR_(int *)]; +}; +struct osethostid_args { + char hostid_l_[PADL_(long)]; long hostid; char hostid_r_[PADR_(long)]; +}; +struct ogetrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct orlimit *)]; struct orlimit * rlp; char rlp_r_[PADR_(struct orlimit *)]; +}; +struct osetrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct orlimit *)]; struct orlimit * rlp; char rlp_r_[PADR_(struct orlimit *)]; +}; +struct okillpg_args { + char pgid_l_[PADL_(int)]; int pgid; char pgid_r_[PADR_(int)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; +}; +struct ogetdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(u_int)]; u_int count; char count_r_[PADR_(u_int)]; + char basep_l_[PADL_(long *)]; long * basep; char basep_r_[PADR_(long *)]; +}; +int ocreat(struct thread *, struct ocreat_args *); +int olseek(struct thread *, struct olseek_args *); +int ostat(struct thread *, struct ostat_args *); +int olstat(struct thread *, struct olstat_args *); +int osigaction(struct thread *, struct osigaction_args *); +int osigprocmask(struct thread *, struct osigprocmask_args *); +int osigpending(struct thread *, struct osigpending_args *); +int ofstat(struct thread *, struct ofstat_args *); +int ogetkerninfo(struct thread *, struct getkerninfo_args *); +int ogetpagesize(struct thread *, struct getpagesize_args *); +int ommap(struct thread *, struct ommap_args *); +int owait(struct thread *, struct owait_args *); +int ogethostname(struct thread *, struct gethostname_args *); +int osethostname(struct thread *, struct sethostname_args *); +int oaccept(struct thread *, struct accept_args *); +int osend(struct thread *, struct osend_args *); +int orecv(struct thread *, struct orecv_args *); +int osigreturn(struct thread *, struct osigreturn_args *); +int osigvec(struct thread *, struct osigvec_args *); +int osigblock(struct thread *, struct osigblock_args *); +int osigsetmask(struct thread *, struct osigsetmask_args *); +int osigsuspend(struct thread *, struct osigsuspend_args *); +int osigstack(struct thread *, struct osigstack_args *); +int orecvmsg(struct thread *, struct orecvmsg_args *); +int osendmsg(struct thread *, struct osendmsg_args *); +int orecvfrom(struct thread *, struct recvfrom_args *); +int otruncate(struct thread *, struct otruncate_args *); +int oftruncate(struct thread *, struct oftruncate_args *); +int ogetpeername(struct thread *, struct ogetpeername_args *); +int ogethostid(struct thread *, struct ogethostid_args *); +int osethostid(struct thread *, struct osethostid_args *); +int ogetrlimit(struct thread *, struct ogetrlimit_args *); +int osetrlimit(struct thread *, struct osetrlimit_args *); +int okillpg(struct thread *, struct okillpg_args *); +int oquota(struct thread *, struct oquota_args *); +int ogetsockname(struct thread *, struct getsockname_args *); +int ogetdirentries(struct thread *, struct ogetdirentries_args *); + +#endif /* COMPAT_43 */ + + +#ifdef COMPAT_FREEBSD4 + +struct freebsd4_getfsstat_args { + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; + char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct freebsd4_statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_getdomainname_args { + char domainname_l_[PADL_(char *)]; char * domainname; char domainname_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct freebsd4_setdomainname_args { + char domainname_l_[PADL_(char *)]; char * domainname; char domainname_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct freebsd4_uname_args { + char name_l_[PADL_(struct utsname *)]; struct utsname * name; char name_r_[PADR_(struct utsname *)]; +}; +struct freebsd4_fhstatfs_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_sendfile_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; + char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)]; + char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct freebsd4_sigaction_args { + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; + char act_l_[PADL_(const struct sigaction *)]; const struct sigaction * act; char act_r_[PADR_(const struct sigaction *)]; + char oact_l_[PADL_(struct sigaction *)]; struct sigaction * oact; char oact_r_[PADR_(struct sigaction *)]; +}; +struct freebsd4_sigreturn_args { + char sigcntxp_l_[PADL_(const struct ucontext4 *)]; const struct ucontext4 * sigcntxp; char sigcntxp_r_[PADR_(const struct ucontext4 *)]; +}; +int freebsd4_getfsstat(struct thread *, struct freebsd4_getfsstat_args *); +int freebsd4_statfs(struct thread *, struct freebsd4_statfs_args *); +int freebsd4_fstatfs(struct thread *, struct freebsd4_fstatfs_args *); +int freebsd4_getdomainname(struct thread *, struct freebsd4_getdomainname_args *); +int freebsd4_setdomainname(struct thread *, struct freebsd4_setdomainname_args *); +int freebsd4_uname(struct thread *, struct freebsd4_uname_args *); +int freebsd4_fhstatfs(struct thread *, struct freebsd4_fhstatfs_args *); +int freebsd4_sendfile(struct thread *, struct freebsd4_sendfile_args *); +int freebsd4_sigaction(struct thread *, struct freebsd4_sigaction_args *); +int freebsd4_sigreturn(struct thread *, struct freebsd4_sigreturn_args *); + +#endif /* COMPAT_FREEBSD4 */ + + +#ifdef COMPAT_FREEBSD6 + +struct freebsd6_pread_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct freebsd6_pwrite_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct freebsd6_mmap_args { + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char pos_l_[PADL_(off_t)]; off_t pos; char pos_r_[PADR_(off_t)]; +}; +struct freebsd6_lseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; +}; +struct freebsd6_truncate_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct freebsd6_ftruncate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct freebsd6_aio_read_args { + char aiocbp_l_[PADL_(struct oaiocb *)]; struct oaiocb * aiocbp; char aiocbp_r_[PADR_(struct oaiocb *)]; +}; +struct freebsd6_aio_write_args { + char aiocbp_l_[PADL_(struct oaiocb *)]; struct oaiocb * aiocbp; char aiocbp_r_[PADR_(struct oaiocb *)]; +}; +struct freebsd6_lio_listio_args { + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + char acb_list_l_[PADL_(struct oaiocb *const *)]; struct oaiocb *const * acb_list; char acb_list_r_[PADR_(struct oaiocb *const *)]; + char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)]; + char sig_l_[PADL_(struct osigevent *)]; struct osigevent * sig; char sig_r_[PADR_(struct osigevent *)]; +}; +int freebsd6_pread(struct thread *, struct freebsd6_pread_args *); +int freebsd6_pwrite(struct thread *, struct freebsd6_pwrite_args *); +int freebsd6_mmap(struct thread *, struct freebsd6_mmap_args *); +int freebsd6_lseek(struct thread *, struct freebsd6_lseek_args *); +int freebsd6_truncate(struct thread *, struct freebsd6_truncate_args *); +int freebsd6_ftruncate(struct thread *, struct freebsd6_ftruncate_args *); +int freebsd6_aio_read(struct thread *, struct freebsd6_aio_read_args *); +int freebsd6_aio_write(struct thread *, struct freebsd6_aio_write_args *); +int freebsd6_lio_listio(struct thread *, struct freebsd6_lio_listio_args *); + +#endif /* COMPAT_FREEBSD6 */ + + +#ifdef COMPAT_FREEBSD7 + +struct freebsd7___semctl_args { + char semid_l_[PADL_(int)]; int semid; char semid_r_[PADR_(int)]; + char semnum_l_[PADL_(int)]; int semnum; char semnum_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(union semun_old *)]; union semun_old * arg; char arg_r_[PADR_(union semun_old *)]; +}; +struct freebsd7_msgctl_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct msqid_ds_old *)]; struct msqid_ds_old * buf; char buf_r_[PADR_(struct msqid_ds_old *)]; +}; +struct freebsd7_shmctl_args { + char shmid_l_[PADL_(int)]; int shmid; char shmid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct shmid_ds_old *)]; struct shmid_ds_old * buf; char buf_r_[PADR_(struct shmid_ds_old *)]; +}; +int freebsd7___semctl(struct thread *, struct freebsd7___semctl_args *); +int freebsd7_msgctl(struct thread *, struct freebsd7_msgctl_args *); +int freebsd7_shmctl(struct thread *, struct freebsd7_shmctl_args *); + +#endif /* COMPAT_FREEBSD7 */ + + +#ifdef COMPAT_FREEBSD10 + +int freebsd10_pipe(struct thread *, struct freebsd10_pipe_args *); + +#endif /* COMPAT_FREEBSD10 */ + + +#ifdef COMPAT_FREEBSD11 + +struct freebsd11_mknod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + char dev_l_[PADL_(uint32_t)]; uint32_t dev; char dev_r_[PADR_(uint32_t)]; +}; +struct freebsd11_vadvise_args { + char anom_l_[PADL_(int)]; int anom; char anom_r_[PADR_(int)]; +}; +struct freebsd11_stat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct freebsd11_stat *)]; struct freebsd11_stat * ub; char ub_r_[PADR_(struct freebsd11_stat *)]; +}; +struct freebsd11_fstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct freebsd11_stat *)]; struct freebsd11_stat * sb; char sb_r_[PADR_(struct freebsd11_stat *)]; +}; +struct freebsd11_lstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct freebsd11_stat *)]; struct freebsd11_stat * ub; char ub_r_[PADR_(struct freebsd11_stat *)]; +}; +struct freebsd11_getdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(u_int)]; u_int count; char count_r_[PADR_(u_int)]; + char basep_l_[PADL_(long *)]; long * basep; char basep_r_[PADR_(long *)]; +}; +struct freebsd11_getdents_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(size_t)]; size_t count; char count_r_[PADR_(size_t)]; +}; +struct freebsd11_nstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct nstat *)]; struct nstat * ub; char ub_r_[PADR_(struct nstat *)]; +}; +struct freebsd11_nfstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct nstat *)]; struct nstat * sb; char sb_r_[PADR_(struct nstat *)]; +}; +struct freebsd11_nlstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct nstat *)]; struct nstat * ub; char ub_r_[PADR_(struct nstat *)]; +}; +struct freebsd11_fhstat_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char sb_l_[PADL_(struct freebsd11_stat *)]; struct freebsd11_stat * sb; char sb_r_[PADR_(struct freebsd11_stat *)]; +}; +struct freebsd11_kevent_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char changelist_l_[PADL_(struct kevent_freebsd11 *)]; struct kevent_freebsd11 * changelist; char changelist_r_[PADR_(struct kevent_freebsd11 *)]; + char nchanges_l_[PADL_(int)]; int nchanges; char nchanges_r_[PADR_(int)]; + char eventlist_l_[PADL_(struct kevent_freebsd11 *)]; struct kevent_freebsd11 * eventlist; char eventlist_r_[PADR_(struct kevent_freebsd11 *)]; + char nevents_l_[PADL_(int)]; int nevents; char nevents_r_[PADR_(int)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct freebsd11_getfsstat_args { + char buf_l_[PADL_(struct freebsd11_statfs *)]; struct freebsd11_statfs * buf; char buf_r_[PADR_(struct freebsd11_statfs *)]; + char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct freebsd11_statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct freebsd11_statfs *)]; struct freebsd11_statfs * buf; char buf_r_[PADR_(struct freebsd11_statfs *)]; +}; +struct freebsd11_fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct freebsd11_statfs *)]; struct freebsd11_statfs * buf; char buf_r_[PADR_(struct freebsd11_statfs *)]; +}; +struct freebsd11_fhstatfs_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char buf_l_[PADL_(struct freebsd11_statfs *)]; struct freebsd11_statfs * buf; char buf_r_[PADR_(struct freebsd11_statfs *)]; +}; +struct freebsd11_fstatat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct freebsd11_stat *)]; struct freebsd11_stat * buf; char buf_r_[PADR_(struct freebsd11_stat *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct freebsd11_mknodat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char dev_l_[PADL_(uint32_t)]; uint32_t dev; char dev_r_[PADR_(uint32_t)]; +}; +int freebsd11_mknod(struct thread *, struct freebsd11_mknod_args *); +int freebsd11_vadvise(struct thread *, struct freebsd11_vadvise_args *); +int freebsd11_stat(struct thread *, struct freebsd11_stat_args *); +int freebsd11_fstat(struct thread *, struct freebsd11_fstat_args *); +int freebsd11_lstat(struct thread *, struct freebsd11_lstat_args *); +int freebsd11_getdirentries(struct thread *, struct freebsd11_getdirentries_args *); +int freebsd11_getdents(struct thread *, struct freebsd11_getdents_args *); +int freebsd11_nstat(struct thread *, struct freebsd11_nstat_args *); +int freebsd11_nfstat(struct thread *, struct freebsd11_nfstat_args *); +int freebsd11_nlstat(struct thread *, struct freebsd11_nlstat_args *); +int freebsd11_fhstat(struct thread *, struct freebsd11_fhstat_args *); +int freebsd11_kevent(struct thread *, struct freebsd11_kevent_args *); +int freebsd11_getfsstat(struct thread *, struct freebsd11_getfsstat_args *); +int freebsd11_statfs(struct thread *, struct freebsd11_statfs_args *); +int freebsd11_fstatfs(struct thread *, struct freebsd11_fstatfs_args *); +int freebsd11_fhstatfs(struct thread *, struct freebsd11_fhstatfs_args *); +int freebsd11_fstatat(struct thread *, struct freebsd11_fstatat_args *); +int freebsd11_mknodat(struct thread *, struct freebsd11_mknodat_args *); + +#endif /* COMPAT_FREEBSD11 */ + +#define SYS_AUE_syscall AUE_NULL +#define SYS_AUE_exit AUE_EXIT +#define SYS_AUE_fork AUE_FORK +#define SYS_AUE_read AUE_READ +#define SYS_AUE_write AUE_WRITE +#define SYS_AUE_open AUE_OPEN_RWTC +#define SYS_AUE_close AUE_CLOSE +#define SYS_AUE_wait4 AUE_WAIT4 +#define SYS_AUE_ocreat AUE_CREAT +#define SYS_AUE_link AUE_LINK +#define SYS_AUE_unlink AUE_UNLINK +#define SYS_AUE_chdir AUE_CHDIR +#define SYS_AUE_fchdir AUE_FCHDIR +#define SYS_AUE_freebsd11_mknod AUE_MKNOD +#define SYS_AUE_chmod AUE_CHMOD +#define SYS_AUE_chown AUE_CHOWN +#define SYS_AUE_break AUE_NULL +#define SYS_AUE_freebsd4_getfsstat AUE_GETFSSTAT +#define SYS_AUE_olseek AUE_LSEEK +#define SYS_AUE_getpid AUE_GETPID +#define SYS_AUE_mount AUE_MOUNT +#define SYS_AUE_unmount AUE_UMOUNT +#define SYS_AUE_setuid AUE_SETUID +#define SYS_AUE_getuid AUE_GETUID +#define SYS_AUE_geteuid AUE_GETEUID +#define SYS_AUE_ptrace AUE_PTRACE +#define SYS_AUE_recvmsg AUE_RECVMSG +#define SYS_AUE_sendmsg AUE_SENDMSG +#define SYS_AUE_recvfrom AUE_RECVFROM +#define SYS_AUE_accept AUE_ACCEPT +#define SYS_AUE_getpeername AUE_GETPEERNAME +#define SYS_AUE_getsockname AUE_GETSOCKNAME +#define SYS_AUE_access AUE_ACCESS +#define SYS_AUE_chflags AUE_CHFLAGS +#define SYS_AUE_fchflags AUE_FCHFLAGS +#define SYS_AUE_sync AUE_SYNC +#define SYS_AUE_kill AUE_KILL +#define SYS_AUE_ostat AUE_STAT +#define SYS_AUE_getppid AUE_GETPPID +#define SYS_AUE_olstat AUE_LSTAT +#define SYS_AUE_dup AUE_DUP +#define SYS_AUE_freebsd10_pipe AUE_PIPE +#define SYS_AUE_getegid AUE_GETEGID +#define SYS_AUE_profil AUE_PROFILE +#define SYS_AUE_ktrace AUE_KTRACE +#define SYS_AUE_osigaction AUE_SIGACTION +#define SYS_AUE_getgid AUE_GETGID +#define SYS_AUE_osigprocmask AUE_SIGPROCMASK +#define SYS_AUE_getlogin AUE_GETLOGIN +#define SYS_AUE_setlogin AUE_SETLOGIN +#define SYS_AUE_acct AUE_ACCT +#define SYS_AUE_osigpending AUE_SIGPENDING +#define SYS_AUE_sigaltstack AUE_SIGALTSTACK +#define SYS_AUE_ioctl AUE_IOCTL +#define SYS_AUE_reboot AUE_REBOOT +#define SYS_AUE_revoke AUE_REVOKE +#define SYS_AUE_symlink AUE_SYMLINK +#define SYS_AUE_readlink AUE_READLINK +#define SYS_AUE_execve AUE_EXECVE +#define SYS_AUE_umask AUE_UMASK +#define SYS_AUE_chroot AUE_CHROOT +#define SYS_AUE_ofstat AUE_FSTAT +#define SYS_AUE_ogetkerninfo AUE_NULL +#define SYS_AUE_ogetpagesize AUE_NULL +#define SYS_AUE_msync AUE_MSYNC +#define SYS_AUE_vfork AUE_VFORK +#define SYS_AUE_sbrk AUE_SBRK +#define SYS_AUE_sstk AUE_SSTK +#define SYS_AUE_ommap AUE_MMAP +#define SYS_AUE_freebsd11_vadvise AUE_O_VADVISE +#define SYS_AUE_munmap AUE_MUNMAP +#define SYS_AUE_mprotect AUE_MPROTECT +#define SYS_AUE_madvise AUE_MADVISE +#define SYS_AUE_mincore AUE_MINCORE +#define SYS_AUE_getgroups AUE_GETGROUPS +#define SYS_AUE_setgroups AUE_SETGROUPS +#define SYS_AUE_getpgrp AUE_GETPGRP +#define SYS_AUE_setpgid AUE_SETPGRP +#define SYS_AUE_setitimer AUE_SETITIMER +#define SYS_AUE_owait AUE_WAIT4 +#define SYS_AUE_swapon AUE_SWAPON +#define SYS_AUE_getitimer AUE_GETITIMER +#define SYS_AUE_ogethostname AUE_SYSCTL +#define SYS_AUE_osethostname AUE_SYSCTL +#define SYS_AUE_getdtablesize AUE_GETDTABLESIZE +#define SYS_AUE_dup2 AUE_DUP2 +#define SYS_AUE_fcntl AUE_FCNTL +#define SYS_AUE_select AUE_SELECT +#define SYS_AUE_fsync AUE_FSYNC +#define SYS_AUE_setpriority AUE_SETPRIORITY +#define SYS_AUE_socket AUE_SOCKET +#define SYS_AUE_connect AUE_CONNECT +#define SYS_AUE_oaccept AUE_ACCEPT +#define SYS_AUE_getpriority AUE_GETPRIORITY +#define SYS_AUE_osend AUE_SEND +#define SYS_AUE_orecv AUE_RECV +#define SYS_AUE_osigreturn AUE_SIGRETURN +#define SYS_AUE_bind AUE_BIND +#define SYS_AUE_setsockopt AUE_SETSOCKOPT +#define SYS_AUE_listen AUE_LISTEN +#define SYS_AUE_osigvec AUE_NULL +#define SYS_AUE_osigblock AUE_NULL +#define SYS_AUE_osigsetmask AUE_NULL +#define SYS_AUE_osigsuspend AUE_NULL +#define SYS_AUE_osigstack AUE_NULL +#define SYS_AUE_orecvmsg AUE_RECVMSG +#define SYS_AUE_osendmsg AUE_SENDMSG +#define SYS_AUE_gettimeofday AUE_GETTIMEOFDAY +#define SYS_AUE_getrusage AUE_GETRUSAGE +#define SYS_AUE_getsockopt AUE_GETSOCKOPT +#define SYS_AUE_readv AUE_READV +#define SYS_AUE_writev AUE_WRITEV +#define SYS_AUE_settimeofday AUE_SETTIMEOFDAY +#define SYS_AUE_fchown AUE_FCHOWN +#define SYS_AUE_fchmod AUE_FCHMOD +#define SYS_AUE_orecvfrom AUE_RECVFROM +#define SYS_AUE_setreuid AUE_SETREUID +#define SYS_AUE_setregid AUE_SETREGID +#define SYS_AUE_rename AUE_RENAME +#define SYS_AUE_otruncate AUE_TRUNCATE +#define SYS_AUE_oftruncate AUE_FTRUNCATE +#define SYS_AUE_flock AUE_FLOCK +#define SYS_AUE_mkfifo AUE_MKFIFO +#define SYS_AUE_sendto AUE_SENDTO +#define SYS_AUE_shutdown AUE_SHUTDOWN +#define SYS_AUE_socketpair AUE_SOCKETPAIR +#define SYS_AUE_mkdir AUE_MKDIR +#define SYS_AUE_rmdir AUE_RMDIR +#define SYS_AUE_utimes AUE_UTIMES +#define SYS_AUE_adjtime AUE_ADJTIME +#define SYS_AUE_ogetpeername AUE_GETPEERNAME +#define SYS_AUE_ogethostid AUE_SYSCTL +#define SYS_AUE_osethostid AUE_SYSCTL +#define SYS_AUE_ogetrlimit AUE_GETRLIMIT +#define SYS_AUE_osetrlimit AUE_SETRLIMIT +#define SYS_AUE_okillpg AUE_KILLPG +#define SYS_AUE_setsid AUE_SETSID +#define SYS_AUE_quotactl AUE_QUOTACTL +#define SYS_AUE_oquota AUE_O_QUOTA +#define SYS_AUE_ogetsockname AUE_GETSOCKNAME +#define SYS_AUE_nlm_syscall AUE_NULL +#define SYS_AUE_nfssvc AUE_NFS_SVC +#define SYS_AUE_ogetdirentries AUE_GETDIRENTRIES +#define SYS_AUE_freebsd4_statfs AUE_STATFS +#define SYS_AUE_freebsd4_fstatfs AUE_FSTATFS +#define SYS_AUE_lgetfh AUE_LGETFH +#define SYS_AUE_getfh AUE_NFS_GETFH +#define SYS_AUE_freebsd4_getdomainname AUE_SYSCTL +#define SYS_AUE_freebsd4_setdomainname AUE_SYSCTL +#define SYS_AUE_freebsd4_uname AUE_NULL +#define SYS_AUE_sysarch AUE_SYSARCH +#define SYS_AUE_rtprio AUE_RTPRIO +#define SYS_AUE_semsys AUE_SEMSYS +#define SYS_AUE_msgsys AUE_MSGSYS +#define SYS_AUE_shmsys AUE_SHMSYS +#define SYS_AUE_freebsd6_pread AUE_PREAD +#define SYS_AUE_freebsd6_pwrite AUE_PWRITE +#define SYS_AUE_setfib AUE_SETFIB +#define SYS_AUE_ntp_adjtime AUE_NTP_ADJTIME +#define SYS_AUE_setgid AUE_SETGID +#define SYS_AUE_setegid AUE_SETEGID +#define SYS_AUE_seteuid AUE_SETEUID +#define SYS_AUE_freebsd11_stat AUE_STAT +#define SYS_AUE_freebsd11_fstat AUE_FSTAT +#define SYS_AUE_freebsd11_lstat AUE_LSTAT +#define SYS_AUE_pathconf AUE_PATHCONF +#define SYS_AUE_fpathconf AUE_FPATHCONF +#define SYS_AUE_getrlimit AUE_GETRLIMIT +#define SYS_AUE_setrlimit AUE_SETRLIMIT +#define SYS_AUE_freebsd11_getdirentries AUE_GETDIRENTRIES +#define SYS_AUE_freebsd6_mmap AUE_MMAP +#define SYS_AUE_freebsd6_lseek AUE_LSEEK +#define SYS_AUE_freebsd6_truncate AUE_TRUNCATE +#define SYS_AUE_freebsd6_ftruncate AUE_FTRUNCATE +#define SYS_AUE___sysctl AUE_SYSCTL +#define SYS_AUE_mlock AUE_MLOCK +#define SYS_AUE_munlock AUE_MUNLOCK +#define SYS_AUE_undelete AUE_UNDELETE +#define SYS_AUE_futimes AUE_FUTIMES +#define SYS_AUE_getpgid AUE_GETPGID +#define SYS_AUE_poll AUE_POLL +#define SYS_AUE_freebsd7___semctl AUE_SEMCTL +#define SYS_AUE_semget AUE_SEMGET +#define SYS_AUE_semop AUE_SEMOP +#define SYS_AUE_freebsd7_msgctl AUE_MSGCTL +#define SYS_AUE_msgget AUE_MSGGET +#define SYS_AUE_msgsnd AUE_MSGSND +#define SYS_AUE_msgrcv AUE_MSGRCV +#define SYS_AUE_shmat AUE_SHMAT +#define SYS_AUE_freebsd7_shmctl AUE_SHMCTL +#define SYS_AUE_shmdt AUE_SHMDT +#define SYS_AUE_shmget AUE_SHMGET +#define SYS_AUE_clock_gettime AUE_NULL +#define SYS_AUE_clock_settime AUE_CLOCK_SETTIME +#define SYS_AUE_clock_getres AUE_NULL +#define SYS_AUE_ktimer_create AUE_NULL +#define SYS_AUE_ktimer_delete AUE_NULL +#define SYS_AUE_ktimer_settime AUE_NULL +#define SYS_AUE_ktimer_gettime AUE_NULL +#define SYS_AUE_ktimer_getoverrun AUE_NULL +#define SYS_AUE_nanosleep AUE_NULL +#define SYS_AUE_ffclock_getcounter AUE_NULL +#define SYS_AUE_ffclock_setestimate AUE_NULL +#define SYS_AUE_ffclock_getestimate AUE_NULL +#define SYS_AUE_clock_nanosleep AUE_NULL +#define SYS_AUE_clock_getcpuclockid2 AUE_NULL +#define SYS_AUE_ntp_gettime AUE_NULL +#define SYS_AUE_minherit AUE_MINHERIT +#define SYS_AUE_rfork AUE_RFORK +#define SYS_AUE_issetugid AUE_ISSETUGID +#define SYS_AUE_lchown AUE_LCHOWN +#define SYS_AUE_aio_read AUE_AIO_READ +#define SYS_AUE_aio_write AUE_AIO_WRITE +#define SYS_AUE_lio_listio AUE_LIO_LISTIO +#define SYS_AUE_freebsd11_getdents AUE_O_GETDENTS +#define SYS_AUE_lchmod AUE_LCHMOD +#define SYS_AUE_lutimes AUE_LUTIMES +#define SYS_AUE_freebsd11_nstat AUE_STAT +#define SYS_AUE_freebsd11_nfstat AUE_FSTAT +#define SYS_AUE_freebsd11_nlstat AUE_LSTAT +#define SYS_AUE_preadv AUE_PREADV +#define SYS_AUE_pwritev AUE_PWRITEV +#define SYS_AUE_freebsd4_fhstatfs AUE_FHSTATFS +#define SYS_AUE_fhopen AUE_FHOPEN +#define SYS_AUE_freebsd11_fhstat AUE_FHSTAT +#define SYS_AUE_modnext AUE_NULL +#define SYS_AUE_modstat AUE_NULL +#define SYS_AUE_modfnext AUE_NULL +#define SYS_AUE_modfind AUE_NULL +#define SYS_AUE_kldload AUE_MODLOAD +#define SYS_AUE_kldunload AUE_MODUNLOAD +#define SYS_AUE_kldfind AUE_NULL +#define SYS_AUE_kldnext AUE_NULL +#define SYS_AUE_kldstat AUE_NULL +#define SYS_AUE_kldfirstmod AUE_NULL +#define SYS_AUE_getsid AUE_GETSID +#define SYS_AUE_setresuid AUE_SETRESUID +#define SYS_AUE_setresgid AUE_SETRESGID +#define SYS_AUE_aio_return AUE_AIO_RETURN +#define SYS_AUE_aio_suspend AUE_AIO_SUSPEND +#define SYS_AUE_aio_cancel AUE_AIO_CANCEL +#define SYS_AUE_aio_error AUE_AIO_ERROR +#define SYS_AUE_freebsd6_aio_read AUE_AIO_READ +#define SYS_AUE_freebsd6_aio_write AUE_AIO_WRITE +#define SYS_AUE_freebsd6_lio_listio AUE_LIO_LISTIO +#define SYS_AUE_yield AUE_NULL +#define SYS_AUE_mlockall AUE_MLOCKALL +#define SYS_AUE_munlockall AUE_MUNLOCKALL +#define SYS_AUE___getcwd AUE_GETCWD +#define SYS_AUE_sched_setparam AUE_NULL +#define SYS_AUE_sched_getparam AUE_NULL +#define SYS_AUE_sched_setscheduler AUE_NULL +#define SYS_AUE_sched_getscheduler AUE_NULL +#define SYS_AUE_sched_yield AUE_NULL +#define SYS_AUE_sched_get_priority_max AUE_NULL +#define SYS_AUE_sched_get_priority_min AUE_NULL +#define SYS_AUE_sched_rr_get_interval AUE_NULL +#define SYS_AUE_utrace AUE_NULL +#define SYS_AUE_freebsd4_sendfile AUE_SENDFILE +#define SYS_AUE_kldsym AUE_NULL +#define SYS_AUE_jail AUE_JAIL +#define SYS_AUE_nnpfs_syscall AUE_NULL +#define SYS_AUE_sigprocmask AUE_SIGPROCMASK +#define SYS_AUE_sigsuspend AUE_SIGSUSPEND +#define SYS_AUE_freebsd4_sigaction AUE_SIGACTION +#define SYS_AUE_sigpending AUE_SIGPENDING +#define SYS_AUE_freebsd4_sigreturn AUE_SIGRETURN +#define SYS_AUE_sigtimedwait AUE_SIGWAIT +#define SYS_AUE_sigwaitinfo AUE_NULL +#define SYS_AUE___acl_get_file AUE_ACL_GET_FILE +#define SYS_AUE___acl_set_file AUE_ACL_SET_FILE +#define SYS_AUE___acl_get_fd AUE_ACL_GET_FD +#define SYS_AUE___acl_set_fd AUE_ACL_SET_FD +#define SYS_AUE___acl_delete_file AUE_ACL_DELETE_FILE +#define SYS_AUE___acl_delete_fd AUE_ACL_DELETE_FD +#define SYS_AUE___acl_aclcheck_file AUE_ACL_CHECK_FILE +#define SYS_AUE___acl_aclcheck_fd AUE_ACL_CHECK_FD +#define SYS_AUE_extattrctl AUE_EXTATTRCTL +#define SYS_AUE_extattr_set_file AUE_EXTATTR_SET_FILE +#define SYS_AUE_extattr_get_file AUE_EXTATTR_GET_FILE +#define SYS_AUE_extattr_delete_file AUE_EXTATTR_DELETE_FILE +#define SYS_AUE_aio_waitcomplete AUE_AIO_WAITCOMPLETE +#define SYS_AUE_getresuid AUE_GETRESUID +#define SYS_AUE_getresgid AUE_GETRESGID +#define SYS_AUE_kqueue AUE_KQUEUE +#define SYS_AUE_freebsd11_kevent AUE_KEVENT +#define SYS_AUE_extattr_set_fd AUE_EXTATTR_SET_FD +#define SYS_AUE_extattr_get_fd AUE_EXTATTR_GET_FD +#define SYS_AUE_extattr_delete_fd AUE_EXTATTR_DELETE_FD +#define SYS_AUE___setugid AUE_SETUGID +#define SYS_AUE_eaccess AUE_EACCESS +#define SYS_AUE_afs3_syscall AUE_NULL +#define SYS_AUE_nmount AUE_NMOUNT +#define SYS_AUE___mac_get_proc AUE_NULL +#define SYS_AUE___mac_set_proc AUE_NULL +#define SYS_AUE___mac_get_fd AUE_NULL +#define SYS_AUE___mac_get_file AUE_NULL +#define SYS_AUE___mac_set_fd AUE_NULL +#define SYS_AUE___mac_set_file AUE_NULL +#define SYS_AUE_kenv AUE_NULL +#define SYS_AUE_lchflags AUE_LCHFLAGS +#define SYS_AUE_uuidgen AUE_NULL +#define SYS_AUE_sendfile AUE_SENDFILE +#define SYS_AUE_mac_syscall AUE_NULL +#define SYS_AUE_freebsd11_getfsstat AUE_GETFSSTAT +#define SYS_AUE_freebsd11_statfs AUE_STATFS +#define SYS_AUE_freebsd11_fstatfs AUE_FSTATFS +#define SYS_AUE_freebsd11_fhstatfs AUE_FHSTATFS +#define SYS_AUE_ksem_close AUE_SEMCLOSE +#define SYS_AUE_ksem_post AUE_SEMPOST +#define SYS_AUE_ksem_wait AUE_SEMWAIT +#define SYS_AUE_ksem_trywait AUE_SEMTRYWAIT +#define SYS_AUE_ksem_init AUE_SEMINIT +#define SYS_AUE_ksem_open AUE_SEMOPEN +#define SYS_AUE_ksem_unlink AUE_SEMUNLINK +#define SYS_AUE_ksem_getvalue AUE_SEMGETVALUE +#define SYS_AUE_ksem_destroy AUE_SEMDESTROY +#define SYS_AUE___mac_get_pid AUE_NULL +#define SYS_AUE___mac_get_link AUE_NULL +#define SYS_AUE___mac_set_link AUE_NULL +#define SYS_AUE_extattr_set_link AUE_EXTATTR_SET_LINK +#define SYS_AUE_extattr_get_link AUE_EXTATTR_GET_LINK +#define SYS_AUE_extattr_delete_link AUE_EXTATTR_DELETE_LINK +#define SYS_AUE___mac_execve AUE_NULL +#define SYS_AUE_sigaction AUE_SIGACTION +#define SYS_AUE_sigreturn AUE_SIGRETURN +#define SYS_AUE_getcontext AUE_NULL +#define SYS_AUE_setcontext AUE_NULL +#define SYS_AUE_swapcontext AUE_NULL +#define SYS_AUE_swapoff AUE_SWAPOFF +#define SYS_AUE___acl_get_link AUE_ACL_GET_LINK +#define SYS_AUE___acl_set_link AUE_ACL_SET_LINK +#define SYS_AUE___acl_delete_link AUE_ACL_DELETE_LINK +#define SYS_AUE___acl_aclcheck_link AUE_ACL_CHECK_LINK +#define SYS_AUE_sigwait AUE_SIGWAIT +#define SYS_AUE_thr_create AUE_THR_CREATE +#define SYS_AUE_thr_exit AUE_THR_EXIT +#define SYS_AUE_thr_self AUE_NULL +#define SYS_AUE_thr_kill AUE_THR_KILL +#define SYS_AUE_jail_attach AUE_JAIL_ATTACH +#define SYS_AUE_extattr_list_fd AUE_EXTATTR_LIST_FD +#define SYS_AUE_extattr_list_file AUE_EXTATTR_LIST_FILE +#define SYS_AUE_extattr_list_link AUE_EXTATTR_LIST_LINK +#define SYS_AUE_ksem_timedwait AUE_SEMWAIT +#define SYS_AUE_thr_suspend AUE_NULL +#define SYS_AUE_thr_wake AUE_NULL +#define SYS_AUE_kldunloadf AUE_MODUNLOAD +#define SYS_AUE_audit AUE_AUDIT +#define SYS_AUE_auditon AUE_AUDITON +#define SYS_AUE_getauid AUE_GETAUID +#define SYS_AUE_setauid AUE_SETAUID +#define SYS_AUE_getaudit AUE_GETAUDIT +#define SYS_AUE_setaudit AUE_SETAUDIT +#define SYS_AUE_getaudit_addr AUE_GETAUDIT_ADDR +#define SYS_AUE_setaudit_addr AUE_SETAUDIT_ADDR +#define SYS_AUE_auditctl AUE_AUDITCTL +#define SYS_AUE__umtx_op AUE_NULL +#define SYS_AUE_thr_new AUE_THR_NEW +#define SYS_AUE_sigqueue AUE_NULL +#define SYS_AUE_kmq_open AUE_MQ_OPEN +#define SYS_AUE_kmq_setattr AUE_MQ_SETATTR +#define SYS_AUE_kmq_timedreceive AUE_MQ_TIMEDRECEIVE +#define SYS_AUE_kmq_timedsend AUE_MQ_TIMEDSEND +#define SYS_AUE_kmq_notify AUE_MQ_NOTIFY +#define SYS_AUE_kmq_unlink AUE_MQ_UNLINK +#define SYS_AUE_abort2 AUE_NULL +#define SYS_AUE_thr_set_name AUE_NULL +#define SYS_AUE_aio_fsync AUE_AIO_FSYNC +#define SYS_AUE_rtprio_thread AUE_RTPRIO +#define SYS_AUE_sctp_peeloff AUE_SCTP_PEELOFF +#define SYS_AUE_sctp_generic_sendmsg AUE_SCTP_GENERIC_SENDMSG +#define SYS_AUE_sctp_generic_sendmsg_iov AUE_SCTP_GENERIC_SENDMSG_IOV +#define SYS_AUE_sctp_generic_recvmsg AUE_SCTP_GENERIC_RECVMSG +#define SYS_AUE_pread AUE_PREAD +#define SYS_AUE_pwrite AUE_PWRITE +#define SYS_AUE_mmap AUE_MMAP +#define SYS_AUE_lseek AUE_LSEEK +#define SYS_AUE_truncate AUE_TRUNCATE +#define SYS_AUE_ftruncate AUE_FTRUNCATE +#define SYS_AUE_thr_kill2 AUE_THR_KILL2 +#define SYS_AUE_shm_open AUE_SHMOPEN +#define SYS_AUE_shm_unlink AUE_SHMUNLINK +#define SYS_AUE_cpuset AUE_NULL +#define SYS_AUE_cpuset_setid AUE_NULL +#define SYS_AUE_cpuset_getid AUE_NULL +#define SYS_AUE_cpuset_getaffinity AUE_NULL +#define SYS_AUE_cpuset_setaffinity AUE_NULL +#define SYS_AUE_faccessat AUE_FACCESSAT +#define SYS_AUE_fchmodat AUE_FCHMODAT +#define SYS_AUE_fchownat AUE_FCHOWNAT +#define SYS_AUE_fexecve AUE_FEXECVE +#define SYS_AUE_freebsd11_fstatat AUE_FSTATAT +#define SYS_AUE_futimesat AUE_FUTIMESAT +#define SYS_AUE_linkat AUE_LINKAT +#define SYS_AUE_mkdirat AUE_MKDIRAT +#define SYS_AUE_mkfifoat AUE_MKFIFOAT +#define SYS_AUE_freebsd11_mknodat AUE_MKNODAT +#define SYS_AUE_openat AUE_OPENAT_RWTC +#define SYS_AUE_readlinkat AUE_READLINKAT +#define SYS_AUE_renameat AUE_RENAMEAT +#define SYS_AUE_symlinkat AUE_SYMLINKAT +#define SYS_AUE_unlinkat AUE_UNLINKAT +#define SYS_AUE_posix_openpt AUE_POSIX_OPENPT +#define SYS_AUE_gssd_syscall AUE_NULL +#define SYS_AUE_jail_get AUE_JAIL_GET +#define SYS_AUE_jail_set AUE_JAIL_SET +#define SYS_AUE_jail_remove AUE_JAIL_REMOVE +#define SYS_AUE_closefrom AUE_CLOSEFROM +#define SYS_AUE___semctl AUE_SEMCTL +#define SYS_AUE_msgctl AUE_MSGCTL +#define SYS_AUE_shmctl AUE_SHMCTL +#define SYS_AUE_lpathconf AUE_LPATHCONF +#define SYS_AUE___cap_rights_get AUE_CAP_RIGHTS_GET +#define SYS_AUE_cap_enter AUE_CAP_ENTER +#define SYS_AUE_cap_getmode AUE_CAP_GETMODE +#define SYS_AUE_pdfork AUE_PDFORK +#define SYS_AUE_pdkill AUE_PDKILL +#define SYS_AUE_pdgetpid AUE_PDGETPID +#define SYS_AUE_pselect AUE_SELECT +#define SYS_AUE_getloginclass AUE_GETLOGINCLASS +#define SYS_AUE_setloginclass AUE_SETLOGINCLASS +#define SYS_AUE_rctl_get_racct AUE_NULL +#define SYS_AUE_rctl_get_rules AUE_NULL +#define SYS_AUE_rctl_get_limits AUE_NULL +#define SYS_AUE_rctl_add_rule AUE_NULL +#define SYS_AUE_rctl_remove_rule AUE_NULL +#define SYS_AUE_posix_fallocate AUE_POSIX_FALLOCATE +#define SYS_AUE_posix_fadvise AUE_POSIX_FADVISE +#define SYS_AUE_wait6 AUE_WAIT6 +#define SYS_AUE_cap_rights_limit AUE_CAP_RIGHTS_LIMIT +#define SYS_AUE_cap_ioctls_limit AUE_CAP_IOCTLS_LIMIT +#define SYS_AUE_cap_ioctls_get AUE_CAP_IOCTLS_GET +#define SYS_AUE_cap_fcntls_limit AUE_CAP_FCNTLS_LIMIT +#define SYS_AUE_cap_fcntls_get AUE_CAP_FCNTLS_GET +#define SYS_AUE_bindat AUE_BINDAT +#define SYS_AUE_connectat AUE_CONNECTAT +#define SYS_AUE_chflagsat AUE_CHFLAGSAT +#define SYS_AUE_accept4 AUE_ACCEPT +#define SYS_AUE_pipe2 AUE_PIPE +#define SYS_AUE_aio_mlock AUE_AIO_MLOCK +#define SYS_AUE_procctl AUE_PROCCTL +#define SYS_AUE_ppoll AUE_POLL +#define SYS_AUE_futimens AUE_FUTIMES +#define SYS_AUE_utimensat AUE_FUTIMESAT +#define SYS_AUE_fdatasync AUE_FSYNC +#define SYS_AUE_fstat AUE_FSTAT +#define SYS_AUE_fstatat AUE_FSTATAT +#define SYS_AUE_fhstat AUE_FHSTAT +#define SYS_AUE_getdirentries AUE_GETDIRENTRIES +#define SYS_AUE_statfs AUE_STATFS +#define SYS_AUE_fstatfs AUE_FSTATFS +#define SYS_AUE_getfsstat AUE_GETFSSTAT +#define SYS_AUE_fhstatfs AUE_FHSTATFS +#define SYS_AUE_mknodat AUE_MKNODAT +#define SYS_AUE_kevent AUE_KEVENT +#define SYS_AUE_cpuset_getdomain AUE_NULL +#define SYS_AUE_cpuset_setdomain AUE_NULL +#define SYS_AUE_getrandom AUE_NULL +#define SYS_AUE_getfhat AUE_NULL +#define SYS_AUE_fhlink AUE_NULL +#define SYS_AUE_fhlinkat AUE_NULL +#define SYS_AUE_fhreadlink AUE_NULL +#define SYS_AUE___sysctlbyname AUE_SYSCTL +#define SYS_AUE_close_range AUE_CLOSERANGE + +#undef PAD_ +#undef PADL_ +#undef PADR_ + +#endif /* !_SYS_SYSPROTO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/systm.h b/lib/libc/include/any-freebsd-any/sys/systm.h new file mode 100644 index 000000000000..37dd13654971 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/systm.h @@ -0,0 +1,588 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)systm.h 8.7 (Berkeley) 3/29/95 + * $FreeBSD$ + */ + +#ifndef _SYS_SYSTM_H_ +#define _SYS_SYSTM_H_ + +#include +#include +#include +#include +#include +#include /* for people using printf mainly */ + +__NULLABILITY_PRAGMA_PUSH + +extern int cold; /* nonzero if we are doing a cold boot */ +extern int suspend_blocked; /* block suspend due to pending shutdown */ +extern int rebooting; /* kern_reboot() has been called. */ +extern const char *panicstr; /* panic message */ +extern char version[]; /* system version */ +extern char compiler_version[]; /* compiler version */ +extern char copyright[]; /* system copyright */ +extern int kstack_pages; /* number of kernel stack pages */ + +extern u_long pagesizes[]; /* supported page sizes */ +extern long physmem; /* physical memory */ +extern long realmem; /* 'real' memory */ + +extern char *rootdevnames[2]; /* names of possible root devices */ + +extern int boothowto; /* reboot flags, from console subsystem */ +extern int bootverbose; /* nonzero to print verbose messages */ + +extern int maxusers; /* system tune hint */ +extern int ngroups_max; /* max # of supplemental groups */ +extern int vm_guest; /* Running as virtual machine guest? */ + +/* + * Detected virtual machine guest types. The intention is to expand + * and/or add to the VM_GUEST_VM type if specific VM functionality is + * ever implemented (e.g. vendor-specific paravirtualization features). + * Keep in sync with vm_guest_sysctl_names[]. + */ +enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV, + VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_LAST }; + +/* + * These functions need to be declared before the KASSERT macro is invoked in + * !KASSERT_PANIC_OPTIONAL builds, so their declarations are sort of out of + * place compared to other function definitions in this header. On the other + * hand, this header is a bit disorganized anyway. + */ +void panic(const char *, ...) __dead2 __printflike(1, 2); +void vpanic(const char *, __va_list) __dead2 __printflike(1, 0); + +#if defined(WITNESS) || defined(INVARIANT_SUPPORT) +#ifdef KASSERT_PANIC_OPTIONAL +void kassert_panic(const char *fmt, ...) __printflike(1, 2); +#else +#define kassert_panic panic +#endif +#endif + +#ifdef INVARIANTS /* The option is always available */ +#define KASSERT(exp,msg) do { \ + if (__predict_false(!(exp))) \ + kassert_panic msg; \ +} while (0) +#define VNASSERT(exp, vp, msg) do { \ + if (__predict_false(!(exp))) { \ + vn_printf(vp, "VNASSERT failed\n"); \ + kassert_panic msg; \ + } \ +} while (0) +#define __assert_unreachable() \ + panic("executing segment marked as unreachable at %s:%d (%s)\n", \ + __FILE__, __LINE__, __func__) +#else +#define KASSERT(exp,msg) do { \ +} while (0) + +#define VNASSERT(exp, vp, msg) do { \ +} while (0) +#define __assert_unreachable() __unreachable() +#endif + +#ifndef CTASSERT /* Allow lint to override */ +#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") +#endif + +#if defined(_KERNEL) +#include /* MAXCPU */ +#include /* curthread */ +#include +#endif + +/* + * Assert that a pointer can be loaded from memory atomically. + * + * This assertion enforces stronger alignment than necessary. For example, + * on some architectures, atomicity for unaligned loads will depend on + * whether or not the load spans multiple cache lines. + */ +#define ASSERT_ATOMIC_LOAD_PTR(var, msg) \ + KASSERT(sizeof(var) == sizeof(void *) && \ + ((uintptr_t)&(var) & (sizeof(void *) - 1)) == 0, msg) + +/* + * Assert that a thread is in critical(9) section. + */ +#define CRITICAL_ASSERT(td) \ + KASSERT((td)->td_critnest >= 1, ("Not in critical section")); + +/* + * If we have already panic'd and this is the thread that called + * panic(), then don't block on any mutexes but silently succeed. + * Otherwise, the kernel will deadlock since the scheduler isn't + * going to run the thread that holds any lock we need. + */ +#define SCHEDULER_STOPPED_TD(td) ({ \ + MPASS((td) == curthread); \ + __predict_false((td)->td_stopsched); \ +}) +#define SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread) + +/* + * Align variables. + */ +#define __read_mostly __section(".data.read_mostly") +#define __read_frequently __section(".data.read_frequently") +#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ + __section(".data.exclusive_cache_line") +/* + * XXX the hints declarations are even more misplaced than most declarations + * in this file, since they are needed in one file (per arch) and only used + * in two files. + * XXX most of these variables should be const. + */ +extern int osreldate; +extern bool dynamic_kenv; +extern struct mtx kenv_lock; +extern char *kern_envp; +extern char *md_envp; +extern char static_env[]; +extern char static_hints[]; /* by config for now */ + +extern char **kenvp; + +extern const void *zero_region; /* address space maps to a zeroed page */ + +extern int unmapped_buf_allowed; + +#ifdef __LP64__ +#define IOSIZE_MAX iosize_max() +#define DEVFS_IOSIZE_MAX devfs_iosize_max() +#else +#define IOSIZE_MAX SSIZE_MAX +#define DEVFS_IOSIZE_MAX SSIZE_MAX +#endif + +/* + * General function declarations. + */ + +struct inpcb; +struct lock_object; +struct malloc_type; +struct mtx; +struct proc; +struct socket; +struct thread; +struct tty; +struct ucred; +struct uio; +struct _jmp_buf; +struct trapframe; +struct eventtimer; + +int setjmp(struct _jmp_buf *) __returns_twice; +void longjmp(struct _jmp_buf *, int) __dead2; +int dumpstatus(vm_offset_t addr, off_t count); +int nullop(void); +int eopnotsupp(void); +int ureadc(int, struct uio *); +void hashdestroy(void *, struct malloc_type *, u_long); +void *hashinit(int count, struct malloc_type *type, u_long *hashmask); +void *hashinit_flags(int count, struct malloc_type *type, + u_long *hashmask, int flags); +#define HASH_NOWAIT 0x00000001 +#define HASH_WAITOK 0x00000002 + +void *phashinit(int count, struct malloc_type *type, u_long *nentries); +void *phashinit_flags(int count, struct malloc_type *type, u_long *nentries, + int flags); +void g_waitidle(void); + +void cpu_boot(int); +void cpu_flush_dcache(void *, size_t); +void cpu_rootconf(void); +void critical_enter_KBI(void); +void critical_exit_KBI(void); +void critical_exit_preempt(void); +void init_param1(void); +void init_param2(long physpages); +void init_static_kenv(char *, size_t); +void tablefull(const char *); + +#if defined(KLD_MODULE) || defined(KTR_CRITICAL) || !defined(_KERNEL) || defined(GENOFFSET) +#define critical_enter() critical_enter_KBI() +#define critical_exit() critical_exit_KBI() +#else +static __inline void +critical_enter(void) +{ + struct thread_lite *td; + + td = (struct thread_lite *)curthread; + td->td_critnest++; + __compiler_membar(); +} + +static __inline void +critical_exit(void) +{ + struct thread_lite *td; + + td = (struct thread_lite *)curthread; + KASSERT(td->td_critnest != 0, + ("critical_exit: td_critnest == 0")); + __compiler_membar(); + td->td_critnest--; + __compiler_membar(); + if (__predict_false(td->td_owepreempt)) + critical_exit_preempt(); + +} +#endif + + +#ifdef EARLY_PRINTF +typedef void early_putc_t(int ch); +extern early_putc_t *early_putc; +#endif +int kvprintf(char const *, void (*)(int, void*), void *, int, + __va_list) __printflike(1, 0); +void log(int, const char *, ...) __printflike(2, 3); +void log_console(struct uio *); +void vlog(int, const char *, __va_list) __printflike(2, 0); +int asprintf(char **ret, struct malloc_type *mtp, const char *format, + ...) __printflike(3, 4); +int printf(const char *, ...) __printflike(1, 2); +int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); +int sprintf(char *buf, const char *, ...) __printflike(2, 3); +int uprintf(const char *, ...) __printflike(1, 2); +int vprintf(const char *, __va_list) __printflike(1, 0); +int vasprintf(char **ret, struct malloc_type *mtp, const char *format, + __va_list ap) __printflike(3, 0); +int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); +int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0); +int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0); +int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); +int sscanf(const char *, char const * _Nonnull, ...) __scanflike(2, 3); +int vsscanf(const char * _Nonnull, char const * _Nonnull, __va_list) __scanflike(2, 0); +long strtol(const char *, char **, int); +u_long strtoul(const char *, char **, int); +quad_t strtoq(const char *, char **, int); +u_quad_t strtouq(const char *, char **, int); +void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4); +void vtprintf(struct proc *, int, const char *, __va_list) __printflike(3, 0); +void hexdump(const void *ptr, int length, const char *hdr, int flags); +#define HD_COLUMN_MASK 0xff +#define HD_DELIM_MASK 0xff00 +#define HD_OMIT_COUNT (1 << 16) +#define HD_OMIT_HEX (1 << 17) +#define HD_OMIT_CHARS (1 << 18) + +#define ovbcopy(f, t, l) bcopy((f), (t), (l)) +void bcopy(const void * _Nonnull from, void * _Nonnull to, size_t len); +#define bcopy(from, to, len) __builtin_memmove((to), (from), (len)) +void bzero(void * _Nonnull buf, size_t len); +#define bzero(buf, len) __builtin_memset((buf), 0, (len)) +void explicit_bzero(void * _Nonnull, size_t); +int bcmp(const void *b1, const void *b2, size_t len); +#define bcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) + +void *memset(void * _Nonnull buf, int c, size_t len); +#define memset(buf, c, len) __builtin_memset((buf), (c), (len)) +void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len); +#define memcpy(to, from, len) __builtin_memcpy((to), (from), (len)) +void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n); +#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) +int memcmp(const void *b1, const void *b2, size_t len); +#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) + +void *memset_early(void * _Nonnull buf, int c, size_t len); +#define bzero_early(buf, len) memset_early((buf), 0, (len)) +void *memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len); +void *memmove_early(void * _Nonnull dest, const void * _Nonnull src, size_t n); +#define bcopy_early(from, to, len) memmove_early((to), (from), (len)) + +int copystr(const void * _Nonnull __restrict kfaddr, + void * _Nonnull __restrict kdaddr, size_t len, + size_t * __restrict lencopied); +int copyinstr(const void * __restrict udaddr, + void * _Nonnull __restrict kaddr, size_t len, + size_t * __restrict lencopied); +int copyin(const void * __restrict udaddr, + void * _Nonnull __restrict kaddr, size_t len); +int copyin_nofault(const void * __restrict udaddr, + void * _Nonnull __restrict kaddr, size_t len); +int copyout(const void * _Nonnull __restrict kaddr, + void * __restrict udaddr, size_t len); +int copyout_nofault(const void * _Nonnull __restrict kaddr, + void * __restrict udaddr, size_t len); + +int fubyte(volatile const void *base); +long fuword(volatile const void *base); +int fuword16(volatile const void *base); +int32_t fuword32(volatile const void *base); +int64_t fuword64(volatile const void *base); +int fueword(volatile const void *base, long *val); +int fueword32(volatile const void *base, int32_t *val); +int fueword64(volatile const void *base, int64_t *val); +int subyte(volatile void *base, int byte); +int suword(volatile void *base, long word); +int suword16(volatile void *base, int word); +int suword32(volatile void *base, int32_t word); +int suword64(volatile void *base, int64_t word); +uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval); +u_long casuword(volatile u_long *p, u_long oldval, u_long newval); +int casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp, + uint32_t newval); +int casueword(volatile u_long *p, u_long oldval, u_long *oldvalp, + u_long newval); + +void realitexpire(void *); + +int sysbeep(int hertz, int period); + +void hardclock(int cnt, int usermode); +void hardclock_sync(int cpu); +void softclock(void *); +void statclock(int cnt, int usermode); +void profclock(int cnt, int usermode, uintfptr_t pc); + +int hardclockintr(void); + +void startprofclock(struct proc *); +void stopprofclock(struct proc *); +void cpu_startprofclock(void); +void cpu_stopprofclock(void); +void suspendclock(void); +void resumeclock(void); +sbintime_t cpu_idleclock(void); +void cpu_activeclock(void); +void cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt); +void cpu_et_frequency(struct eventtimer *et, uint64_t newfreq); +extern int cpu_disable_c2_sleep; +extern int cpu_disable_c3_sleep; + +char *kern_getenv(const char *name); +void freeenv(char *env); +int getenv_int(const char *name, int *data); +int getenv_uint(const char *name, unsigned int *data); +int getenv_long(const char *name, long *data); +int getenv_ulong(const char *name, unsigned long *data); +int getenv_string(const char *name, char *data, int size); +int getenv_int64(const char *name, int64_t *data); +int getenv_uint64(const char *name, uint64_t *data); +int getenv_quad(const char *name, quad_t *data); +int kern_setenv(const char *name, const char *value); +int kern_unsetenv(const char *name); +int testenv(const char *name); + +int getenv_array(const char *name, void *data, int size, int *psize, + int type_size, bool allow_signed); +#define GETENV_UNSIGNED false /* negative numbers not allowed */ +#define GETENV_SIGNED true /* negative numbers allowed */ + +typedef uint64_t (cpu_tick_f)(void); +void set_cputicker(cpu_tick_f *func, uint64_t freq, unsigned var); +extern cpu_tick_f *cpu_ticks; +uint64_t cpu_tickrate(void); +uint64_t cputick2usec(uint64_t tick); + +#ifdef APM_FIXUP_CALLTODO +struct timeval; +void adjust_timeout_calltodo(struct timeval *time_change); +#endif /* APM_FIXUP_CALLTODO */ + +#include + +/* Initialize the world */ +void consinit(void); +void cpu_initclocks(void); +void cpu_initclocks_bsp(void); +void cpu_initclocks_ap(void); +void usrinfoinit(void); + +/* Finalize the world */ +void kern_reboot(int) __dead2; +void shutdown_nice(int); + +/* Timeouts */ +typedef void timeout_t(void *); /* timeout function type */ +#define CALLOUT_HANDLE_INITIALIZER(handle) \ + { NULL } + +void callout_handle_init(struct callout_handle *); +struct callout_handle timeout(timeout_t *, void *, int); +void untimeout(timeout_t *, void *, struct callout_handle); + +/* Stubs for obsolete functions that used to be for interrupt management */ +static __inline intrmask_t splbio(void) { return 0; } +static __inline intrmask_t splcam(void) { return 0; } +static __inline intrmask_t splclock(void) { return 0; } +static __inline intrmask_t splhigh(void) { return 0; } +static __inline intrmask_t splimp(void) { return 0; } +static __inline intrmask_t splnet(void) { return 0; } +static __inline intrmask_t spltty(void) { return 0; } +static __inline void splx(intrmask_t ipl __unused) { return; } + +/* + * Common `proc' functions are declared here so that proc.h can be included + * less often. + */ +int _sleep(void * _Nonnull chan, struct lock_object *lock, int pri, + const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags); +#define msleep(chan, mtx, pri, wmesg, timo) \ + _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), \ + tick_sbt * (timo), 0, C_HARDCLOCK) +#define msleep_sbt(chan, mtx, pri, wmesg, bt, pr, flags) \ + _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (bt), (pr), \ + (flags)) +int msleep_spin_sbt(void * _Nonnull chan, struct mtx *mtx, + const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags); +#define msleep_spin(chan, mtx, wmesg, timo) \ + msleep_spin_sbt((chan), (mtx), (wmesg), tick_sbt * (timo), \ + 0, C_HARDCLOCK) +int pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, + int flags); +#define pause(wmesg, timo) \ + pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK) +#define pause_sig(wmesg, timo) \ + pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK | C_CATCH) +#define tsleep(chan, pri, wmesg, timo) \ + _sleep((chan), NULL, (pri), (wmesg), tick_sbt * (timo), \ + 0, C_HARDCLOCK) +#define tsleep_sbt(chan, pri, wmesg, bt, pr, flags) \ + _sleep((chan), NULL, (pri), (wmesg), (bt), (pr), (flags)) +void wakeup(void * chan); +void wakeup_one(void * chan); +void wakeup_any(void * chan); + +/* + * Common `struct cdev *' stuff are declared here to avoid #include poisoning + */ + +struct cdev; +dev_t dev2udev(struct cdev *x); +const char *devtoname(struct cdev *cdev); + +#ifdef __LP64__ +size_t devfs_iosize_max(void); +size_t iosize_max(void); +#endif + +int poll_no_poll(int events); + +/* XXX: Should be void nanodelay(u_int nsec); */ +void DELAY(int usec); + +/* Root mount holdback API */ +struct root_hold_token { + int flags; + const char *who; + TAILQ_ENTRY(root_hold_token) list; +}; + +struct root_hold_token *root_mount_hold(const char *identifier); +void root_mount_hold_token(const char *identifier, struct root_hold_token *h); +void root_mount_rel(struct root_hold_token *h); +int root_mounted(void); + + +/* + * Unit number allocation API. (kern/subr_unit.c) + */ +struct unrhdr; +struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex); +void init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex); +void delete_unrhdr(struct unrhdr *uh); +void clear_unrhdr(struct unrhdr *uh); +void clean_unrhdr(struct unrhdr *uh); +void clean_unrhdrl(struct unrhdr *uh); +int alloc_unr(struct unrhdr *uh); +int alloc_unr_specific(struct unrhdr *uh, u_int item); +int alloc_unrl(struct unrhdr *uh); +void free_unr(struct unrhdr *uh, u_int item); + +#ifndef __LP64__ +#define UNR64_LOCKED +#endif + +struct unrhdr64 { + uint64_t counter; +}; + +static __inline void +new_unrhdr64(struct unrhdr64 *unr64, uint64_t low) +{ + + unr64->counter = low; +} + +#ifdef UNR64_LOCKED +uint64_t alloc_unr64(struct unrhdr64 *); +#else +static __inline uint64_t +alloc_unr64(struct unrhdr64 *unr64) +{ + + return (atomic_fetchadd_64(&unr64->counter, 1)); +} +#endif + +void intr_prof_stack_use(struct thread *td, struct trapframe *frame); + +void counted_warning(unsigned *counter, const char *msg); + +/* + * APIs to manage deprecation and obsolescence. + */ +struct device; +void _gone_in(int major, const char *msg); +void _gone_in_dev(struct device *dev, int major, const char *msg); +#ifdef NO_OBSOLETE_CODE +#define __gone_ok(m, msg) \ + _Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)), \ + "Obsolete code" msg); +#else +#define __gone_ok(m, msg) +#endif +#define gone_in(major, msg) __gone_ok(major, msg) _gone_in(major, msg) +#define gone_in_dev(dev, major, msg) __gone_ok(major, msg) _gone_in_dev(dev, major, msg) +#define gone_by_fcp101_dev(dev) \ + gone_in_dev((dev), 13, \ + "see https://github.com/freebsd/fcp/blob/master/fcp-0101.md") + +__NULLABILITY_PRAGMA_POP + +#endif /* !_SYS_SYSTM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/taskqueue.h b/lib/libc/include/any-freebsd-any/sys/taskqueue.h new file mode 100644 index 000000000000..3f7ff1f529a7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/taskqueue.h @@ -0,0 +1,217 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TASKQUEUE_H_ +#define _SYS_TASKQUEUE_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +#include +#include +#include +#include + +struct taskqueue; +struct taskqgroup; +struct proc; +struct thread; + +struct timeout_task { + struct taskqueue *q; + struct task t; + struct callout c; + int f; +}; + +enum taskqueue_callback_type { + TASKQUEUE_CALLBACK_TYPE_INIT, + TASKQUEUE_CALLBACK_TYPE_SHUTDOWN, +}; +#define TASKQUEUE_CALLBACK_TYPE_MIN TASKQUEUE_CALLBACK_TYPE_INIT +#define TASKQUEUE_CALLBACK_TYPE_MAX TASKQUEUE_CALLBACK_TYPE_SHUTDOWN +#define TASKQUEUE_NUM_CALLBACKS TASKQUEUE_CALLBACK_TYPE_MAX + 1 +#define TASKQUEUE_NAMELEN 32 + +typedef void (*taskqueue_callback_fn)(void *context); + +/* + * A notification callback function which is called from + * taskqueue_enqueue(). The context argument is given in the call to + * taskqueue_create(). This function would normally be used to allow the + * queue to arrange to run itself later (e.g., by scheduling a software + * interrupt or waking a kernel thread). + */ +typedef void (*taskqueue_enqueue_fn)(void *context); + +struct taskqueue *taskqueue_create(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, + void *context); +int taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, + const char *name, ...) __printflike(4, 5); +int taskqueue_start_threads_in_proc(struct taskqueue **tqp, int count, + int pri, struct proc *p, const char *name, ...) __printflike(5, 6); +int taskqueue_start_threads_cpuset(struct taskqueue **tqp, int count, + int pri, cpuset_t *mask, const char *name, ...) __printflike(5, 6); +int taskqueue_enqueue(struct taskqueue *queue, struct task *task); +int taskqueue_enqueue_timeout(struct taskqueue *queue, + struct timeout_task *timeout_task, int ticks); +int taskqueue_enqueue_timeout_sbt(struct taskqueue *queue, + struct timeout_task *timeout_task, sbintime_t sbt, sbintime_t pr, + int flags); +int taskqueue_poll_is_busy(struct taskqueue *queue, struct task *task); +int taskqueue_cancel(struct taskqueue *queue, struct task *task, + u_int *pendp); +int taskqueue_cancel_timeout(struct taskqueue *queue, + struct timeout_task *timeout_task, u_int *pendp); +void taskqueue_drain(struct taskqueue *queue, struct task *task); +void taskqueue_drain_timeout(struct taskqueue *queue, + struct timeout_task *timeout_task); +void taskqueue_drain_all(struct taskqueue *queue); +void taskqueue_quiesce(struct taskqueue *queue); +void taskqueue_free(struct taskqueue *queue); +void taskqueue_run(struct taskqueue *queue); +void taskqueue_block(struct taskqueue *queue); +void taskqueue_unblock(struct taskqueue *queue); +int taskqueue_member(struct taskqueue *queue, struct thread *td); +void taskqueue_set_callback(struct taskqueue *queue, + enum taskqueue_callback_type cb_type, + taskqueue_callback_fn callback, void *context); + +#define TASK_INITIALIZER(priority, func, context) \ + { .ta_pending = 0, \ + .ta_priority = (priority), \ + .ta_func = (func), \ + .ta_context = (context) } + +/* + * Functions for dedicated thread taskqueues + */ +void taskqueue_thread_loop(void *arg); +void taskqueue_thread_enqueue(void *context); + +/* + * Initialise a task structure. + */ +#define TASK_INIT(task, priority, func, context) do { \ + (task)->ta_pending = 0; \ + (task)->ta_priority = (priority); \ + (task)->ta_func = (func); \ + (task)->ta_context = (context); \ +} while (0) + +void _timeout_task_init(struct taskqueue *queue, + struct timeout_task *timeout_task, int priority, task_fn_t func, + void *context); +#define TIMEOUT_TASK_INIT(queue, timeout_task, priority, func, context) \ + _timeout_task_init(queue, timeout_task, priority, func, context); + +/* + * Declare a reference to a taskqueue. + */ +#define TASKQUEUE_DECLARE(name) \ +extern struct taskqueue *taskqueue_##name + +/* + * Define and initialise a global taskqueue that uses sleep mutexes. + */ +#define TASKQUEUE_DEFINE(name, enqueue, context, init) \ + \ +struct taskqueue *taskqueue_##name; \ + \ +static void \ +taskqueue_define_##name(void *arg) \ +{ \ + taskqueue_##name = \ + taskqueue_create(#name, M_WAITOK, (enqueue), (context)); \ + init; \ +} \ + \ +SYSINIT(taskqueue_##name, SI_SUB_TASKQ, SI_ORDER_SECOND, \ + taskqueue_define_##name, NULL); \ + \ +struct __hack +#define TASKQUEUE_DEFINE_THREAD(name) \ +TASKQUEUE_DEFINE(name, taskqueue_thread_enqueue, &taskqueue_##name, \ + taskqueue_start_threads(&taskqueue_##name, 1, PWAIT, \ + "%s taskq", #name)) + +/* + * Define and initialise a global taskqueue that uses spin mutexes. + */ +#define TASKQUEUE_FAST_DEFINE(name, enqueue, context, init) \ + \ +struct taskqueue *taskqueue_##name; \ + \ +static void \ +taskqueue_define_##name(void *arg) \ +{ \ + taskqueue_##name = \ + taskqueue_create_fast(#name, M_WAITOK, (enqueue), \ + (context)); \ + init; \ +} \ + \ +SYSINIT(taskqueue_##name, SI_SUB_TASKQ, SI_ORDER_SECOND, \ + taskqueue_define_##name, NULL); \ + \ +struct __hack +#define TASKQUEUE_FAST_DEFINE_THREAD(name) \ +TASKQUEUE_FAST_DEFINE(name, taskqueue_thread_enqueue, \ + &taskqueue_##name, taskqueue_start_threads(&taskqueue_##name \ + 1, PWAIT, "%s taskq", #name)) + +/* + * These queues are serviced by software interrupt handlers. To enqueue + * a task, call taskqueue_enqueue(taskqueue_swi, &task) or + * taskqueue_enqueue(taskqueue_swi_giant, &task). + */ +TASKQUEUE_DECLARE(swi_giant); +TASKQUEUE_DECLARE(swi); + +/* + * This queue is serviced by a kernel thread. To enqueue a task, call + * taskqueue_enqueue(taskqueue_thread, &task). + */ +TASKQUEUE_DECLARE(thread); + +/* + * Queue for swi handlers dispatched from fast interrupt handlers. + * These are necessarily different from the above because the queue + * must be locked with spinlocks since sleep mutex's cannot be used + * from a fast interrupt handler context. + */ +TASKQUEUE_DECLARE(fast); +struct taskqueue *taskqueue_create_fast(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, + void *context); + +#endif /* !_SYS_TASKQUEUE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/terminal.h b/lib/libc/include/any-freebsd-any/sys/terminal.h new file mode 100644 index 000000000000..dc78cca5394e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/terminal.h @@ -0,0 +1,240 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Ed Schouten under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TERMINAL_H_ +#define _SYS_TERMINAL_H_ + +#include +#include +#include +#include +#include +#include + +#include + +#include "opt_syscons.h" +#include "opt_teken.h" + +struct terminal; +struct thread; +struct tty; + +/* + * The terminal layer is an abstraction on top of the TTY layer and the + * console interface. It can be used by system console drivers to + * easily interact with the kernel console and TTYs. + * + * Terminals contain terminal emulators, which means console drivers + * don't need to implement their own terminal emulator. The terminal + * emulator deals with UTF-8 exclusively. This means that term_char_t, + * the data type used to store input/output characters will always + * contain Unicode codepoints. + * + * To save memory usage, the top bits of term_char_t will contain other + * attributes, like colors. Right now term_char_t is composed as + * follows: + * + * Bits Meaning + * 0-20: Character value + * 21-25: Bold, underline, blink, reverse, right part of CJK fullwidth character + * 26-28: Foreground color + * 29-31: Background color + */ + +typedef uint32_t term_char_t; +#define TCHAR_CHARACTER(c) ((c) & 0x1fffff) +#define TCHAR_FORMAT(c) (((c) >> 21) & 0x1f) +#define TCHAR_FGCOLOR(c) (((c) >> 26) & 0x7) +#define TCHAR_BGCOLOR(c) (((c) >> 29) & 0x7) + +typedef teken_attr_t term_attr_t; + +typedef teken_color_t term_color_t; +#define TCOLOR_FG(c) (((c) & 0x7) << 26) +#define TCOLOR_BG(c) (((c) & 0x7) << 29) +#define TCOLOR_LIGHT(c) ((c) | 0x8) +#define TCOLOR_DARK(c) ((c) & ~0x8) + +#define TFORMAT(c) (((c) & 0x1f) << 21) + +/* syscons(4) compatible color attributes for foreground text */ +#define FG_BLACK TCOLOR_FG(TC_BLACK) +#define FG_BLUE TCOLOR_FG(TC_BLUE) +#define FG_GREEN TCOLOR_FG(TC_GREEN) +#define FG_CYAN TCOLOR_FG(TC_CYAN) +#define FG_RED TCOLOR_FG(TC_RED) +#define FG_MAGENTA TCOLOR_FG(TC_MAGENTA) +#define FG_BROWN TCOLOR_FG(TC_BROWN) +#define FG_LIGHTGREY TCOLOR_FG(TC_WHITE) +#define FG_DARKGREY (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLACK)) +#define FG_LIGHTBLUE (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLUE)) +#define FG_LIGHTGREEN (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_GREEN)) +#define FG_LIGHTCYAN (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_CYAN)) +#define FG_LIGHTRED (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_RED)) +#define FG_LIGHTMAGENTA (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_MAGENTA)) +#define FG_YELLOW (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BROWN)) +#define FG_WHITE (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_WHITE)) +#define FG_BLINK TFORMAT(TF_BLINK) + +/* syscons(4) compatible color attributes for text background */ +#define BG_BLACK TCOLOR_BG(TC_BLACK) +#define BG_BLUE TCOLOR_BG(TC_BLUE) +#define BG_GREEN TCOLOR_BG(TC_GREEN) +#define BG_CYAN TCOLOR_BG(TC_CYAN) +#define BG_RED TCOLOR_BG(TC_RED) +#define BG_MAGENTA TCOLOR_BG(TC_MAGENTA) +#define BG_BROWN TCOLOR_BG(TC_BROWN) +#define BG_LIGHTGREY TCOLOR_BG(TC_WHITE) +#define BG_DARKGREY (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLACK)) +#define BG_LIGHTBLUE (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLUE)) +#define BG_LIGHTGREEN (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_GREEN)) +#define BG_LIGHTCYAN (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_CYAN)) +#define BG_LIGHTRED (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_RED)) +#define BG_LIGHTMAGENTA (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_MAGENTA)) +#define BG_YELLOW (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BROWN)) +#define BG_WHITE (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_WHITE)) + +#ifndef TERMINAL_NORM_ATTR +#ifdef SC_NORM_ATTR +#define TERMINAL_NORM_ATTR SC_NORM_ATTR +#else +#define TERMINAL_NORM_ATTR (FG_LIGHTGREY | BG_BLACK) +#endif +#endif + +#ifndef TERMINAL_KERN_ATTR +#ifdef SC_KERNEL_CONS_ATTR +#define TERMINAL_KERN_ATTR SC_KERNEL_CONS_ATTR +#else +#define TERMINAL_KERN_ATTR (FG_WHITE | BG_BLACK) +#endif +#endif + +typedef teken_pos_t term_pos_t; +typedef teken_rect_t term_rect_t; + +typedef void tc_cursor_t(struct terminal *tm, const term_pos_t *p); +typedef void tc_putchar_t(struct terminal *tm, const term_pos_t *p, + term_char_t c); +typedef void tc_fill_t(struct terminal *tm, const term_rect_t *r, + term_char_t c); +typedef void tc_copy_t(struct terminal *tm, const term_rect_t *r, + const term_pos_t *p); +typedef void tc_pre_input_t(struct terminal *tm); +typedef void tc_post_input_t(struct terminal *tm); +typedef void tc_param_t(struct terminal *tm, int cmd, unsigned int arg); +typedef void tc_done_t(struct terminal *tm); + +typedef void tc_cnprobe_t(struct terminal *tm, struct consdev *cd); +typedef int tc_cngetc_t(struct terminal *tm); + +typedef void tc_cngrab_t(struct terminal *tm); +typedef void tc_cnungrab_t(struct terminal *tm); + +typedef void tc_opened_t(struct terminal *tm, int opened); +typedef int tc_ioctl_t(struct terminal *tm, u_long cmd, caddr_t data, + struct thread *td); +typedef int tc_mmap_t(struct terminal *tm, vm_ooffset_t offset, + vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr); +typedef void tc_bell_t(struct terminal *tm); + +struct terminal_class { + /* Terminal emulator. */ + tc_cursor_t *tc_cursor; + tc_putchar_t *tc_putchar; + tc_fill_t *tc_fill; + tc_copy_t *tc_copy; + tc_pre_input_t *tc_pre_input; + tc_post_input_t *tc_post_input; + tc_param_t *tc_param; + tc_done_t *tc_done; + + /* Low-level console interface. */ + tc_cnprobe_t *tc_cnprobe; + tc_cngetc_t *tc_cngetc; + + /* DDB & panic handling. */ + tc_cngrab_t *tc_cngrab; + tc_cnungrab_t *tc_cnungrab; + + /* Misc. */ + tc_opened_t *tc_opened; + tc_ioctl_t *tc_ioctl; + tc_mmap_t *tc_mmap; + tc_bell_t *tc_bell; +}; + +struct terminal { + const struct terminal_class *tm_class; + void *tm_softc; + struct mtx tm_mtx; + struct tty *tm_tty; + teken_t tm_emulator; + struct winsize tm_winsize; + unsigned int tm_flags; +#define TF_MUTE 0x1 /* Drop incoming data. */ +#define TF_BELL 0x2 /* Bell needs to be sent. */ +#define TF_CONS 0x4 /* Console device (needs spinlock). */ + struct consdev *consdev; +}; + +#ifdef _KERNEL + +struct terminal *terminal_alloc(const struct terminal_class *tc, void *softc); +void terminal_maketty(struct terminal *tm, const char *fmt, ...); +void terminal_set_cursor(struct terminal *tm, const term_pos_t *pos); +void terminal_set_winsize_blank(struct terminal *tm, + const struct winsize *size, int blank, const term_attr_t *attr); +void terminal_set_winsize(struct terminal *tm, const struct winsize *size); +void terminal_mute(struct terminal *tm, int yes); +void terminal_input_char(struct terminal *tm, term_char_t c); +void terminal_input_raw(struct terminal *tm, char c); +void terminal_input_special(struct terminal *tm, unsigned int k); + +void termcn_cnregister(struct terminal *tm); + +/* Kernel console helper interface. */ +extern const struct consdev_ops termcn_cnops; + +#define TERMINAL_DECLARE_EARLY(name, class, softc) \ + static struct terminal name = { \ + .tm_class = &class, \ + .tm_softc = softc, \ + .tm_flags = TF_CONS, \ + }; \ + CONSOLE_DEVICE(name ## _consdev, termcn_cnops, &name) + +#endif /* _KERNEL */ + +#endif /* !_SYS_TERMINAL_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/termios.h b/lib/libc/include/any-freebsd-any/sys/termios.h new file mode 100644 index 000000000000..e5bacf46550f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/termios.h @@ -0,0 +1,5 @@ +/* $FreeBSD$ */ +#ifdef __GNUC__ +#warning "this file includes which is deprecated, use instead" +#endif +#include diff --git a/lib/libc/include/any-freebsd-any/sys/thr.h b/lib/libc/include/any-freebsd-any/sys/thr.h new file mode 100644 index 000000000000..c00b8b25a9f4 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/thr.h @@ -0,0 +1,87 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS_THR_H_ +#define _SYS_THR_H_ + +#include +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +/* Create the thread in the suspended state. */ +#define THR_SUSPENDED 0x0001 +/* Create the system scope thread. */ +#define THR_SYSTEM_SCOPE 0x0002 + +struct thr_param { + void (*start_func)(void *); /* thread entry function. */ + void *arg; /* argument for entry function. */ + char *stack_base; /* stack base address. */ + size_t stack_size; /* stack size. */ + char *tls_base; /* tls base address. */ + size_t tls_size; /* tls size. */ + long *child_tid; /* address to store new TID. */ + long *parent_tid; /* parent accesses the new TID here. */ + int flags; /* thread flags. */ + struct rtprio *rtp; /* Real-time scheduling priority */ + void *spare[3]; /* TODO: cpu affinity mask etc. */ +}; + +/* + * See pthread_* + */ +#ifndef _KERNEL +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +__BEGIN_DECLS +int thr_create(ucontext_t *ctx, long *id, int flags); +int thr_new(struct thr_param *param, int param_size); +int thr_self(long *id); +void thr_exit(long *state); +int thr_kill(long id, int sig); +int thr_kill2(pid_t pid, long id, int sig); +int thr_suspend(const struct timespec *timeout); +int thr_wake(long id); +int thr_set_name(long id, const char *name); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* ! _SYS_THR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/tiio.h b/lib/libc/include/any-freebsd-any/sys/tiio.h new file mode 100644 index 000000000000..e1123905236d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/tiio.h @@ -0,0 +1,335 @@ +/*- + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-4-Clause) + * + * Copyright (c) 1999, 2000 Kenneth D. Merry. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * The ti_stats structure below is from code with the following copyright, + * and originally comes from the Alteon firmware documentation. + */ +/* + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * from: if_tireg.h,v 1.8 1999/07/23 18:46:24 wpaul Exp $ + */ + +#ifndef _SYS_TIIO_H_ +#define _SYS_TIIO_H_ + +#include + +/* + * Tigon statistics counters. + */ +struct ti_stats { + /* + * MAC stats, taken from RFC 1643, ethernet-like MIB + */ + volatile u_int32_t dot3StatsAlignmentErrors; /* 0 */ + volatile u_int32_t dot3StatsFCSErrors; /* 1 */ + volatile u_int32_t dot3StatsSingleCollisionFrames; /* 2 */ + volatile u_int32_t dot3StatsMultipleCollisionFrames; /* 3 */ + volatile u_int32_t dot3StatsSQETestErrors; /* 4 */ + volatile u_int32_t dot3StatsDeferredTransmissions; /* 5 */ + volatile u_int32_t dot3StatsLateCollisions; /* 6 */ + volatile u_int32_t dot3StatsExcessiveCollisions; /* 7 */ + volatile u_int32_t dot3StatsInternalMacTransmitErrors; /* 8 */ + volatile u_int32_t dot3StatsCarrierSenseErrors; /* 9 */ + volatile u_int32_t dot3StatsFrameTooLongs; /* 10 */ + volatile u_int32_t dot3StatsInternalMacReceiveErrors; /* 11 */ + /* + * interface stats, taken from RFC 1213, MIB-II, interfaces group + */ + volatile u_int32_t ifIndex; /* 12 */ + volatile u_int32_t ifType; /* 13 */ + volatile u_int32_t ifMtu; /* 14 */ + volatile u_int32_t ifSpeed; /* 15 */ + volatile u_int32_t ifAdminStatus; /* 16 */ +#define IF_ADMIN_STATUS_UP 1 +#define IF_ADMIN_STATUS_DOWN 2 +#define IF_ADMIN_STATUS_TESTING 3 + volatile u_int32_t ifOperStatus; /* 17 */ +#define IF_OPER_STATUS_UP 1 +#define IF_OPER_STATUS_DOWN 2 +#define IF_OPER_STATUS_TESTING 3 +#define IF_OPER_STATUS_UNKNOWN 4 +#define IF_OPER_STATUS_DORMANT 5 + volatile u_int32_t ifLastChange; /* 18 */ + volatile u_int32_t ifInDiscards; /* 19 */ + volatile u_int32_t ifInErrors; /* 20 */ + volatile u_int32_t ifInUnknownProtos; /* 21 */ + volatile u_int32_t ifOutDiscards; /* 22 */ + volatile u_int32_t ifOutErrors; /* 23 */ + volatile u_int32_t ifOutQLen; /* deprecated */ /* 24 */ + volatile u_int8_t ifPhysAddress[8]; /* 8 bytes */ /* 25 - 26 */ + volatile u_int8_t ifDescr[32]; /* 27 - 34 */ + u_int32_t alignIt; /* align to 64 bit for u_int64_ts following */ + /* + * more interface stats, taken from RFC 1573, MIB-IIupdate, + * interfaces group + */ + volatile u_int64_t ifHCInOctets; /* 36 - 37 */ + volatile u_int64_t ifHCInUcastPkts; /* 38 - 39 */ + volatile u_int64_t ifHCInMulticastPkts; /* 40 - 41 */ + volatile u_int64_t ifHCInBroadcastPkts; /* 42 - 43 */ + volatile u_int64_t ifHCOutOctets; /* 44 - 45 */ + volatile u_int64_t ifHCOutUcastPkts; /* 46 - 47 */ + volatile u_int64_t ifHCOutMulticastPkts; /* 48 - 49 */ + volatile u_int64_t ifHCOutBroadcastPkts; /* 50 - 51 */ + volatile u_int32_t ifLinkUpDownTrapEnable; /* 52 */ + volatile u_int32_t ifHighSpeed; /* 53 */ + volatile u_int32_t ifPromiscuousMode; /* 54 */ + volatile u_int32_t ifConnectorPresent; /* follow link state 55 */ + /* + * Host Commands + */ + volatile u_int32_t nicCmdsHostState; /* 56 */ + volatile u_int32_t nicCmdsFDRFiltering; /* 57 */ + volatile u_int32_t nicCmdsSetRecvProdIndex; /* 58 */ + volatile u_int32_t nicCmdsUpdateGencommStats; /* 59 */ + volatile u_int32_t nicCmdsResetJumboRing; /* 60 */ + volatile u_int32_t nicCmdsAddMCastAddr; /* 61 */ + volatile u_int32_t nicCmdsDelMCastAddr; /* 62 */ + volatile u_int32_t nicCmdsSetPromiscMode; /* 63 */ + volatile u_int32_t nicCmdsLinkNegotiate; /* 64 */ + volatile u_int32_t nicCmdsSetMACAddr; /* 65 */ + volatile u_int32_t nicCmdsClearProfile; /* 66 */ + volatile u_int32_t nicCmdsSetMulticastMode; /* 67 */ + volatile u_int32_t nicCmdsClearStats; /* 68 */ + volatile u_int32_t nicCmdsSetRecvJumboProdIndex; /* 69 */ + volatile u_int32_t nicCmdsSetRecvMiniProdIndex; /* 70 */ + volatile u_int32_t nicCmdsRefreshStats; /* 71 */ + volatile u_int32_t nicCmdsUnknown; /* 72 */ + /* + * NIC Events + */ + volatile u_int32_t nicEventsNICFirmwareOperational; /* 73 */ + volatile u_int32_t nicEventsStatsUpdated; /* 74 */ + volatile u_int32_t nicEventsLinkStateChanged; /* 75 */ + volatile u_int32_t nicEventsError; /* 76 */ + volatile u_int32_t nicEventsMCastListUpdated; /* 77 */ + volatile u_int32_t nicEventsResetJumboRing; /* 78 */ + /* + * Ring manipulation + */ + volatile u_int32_t nicRingSetSendProdIndex; /* 79 */ + volatile u_int32_t nicRingSetSendConsIndex; /* 80 */ + volatile u_int32_t nicRingSetRecvReturnProdIndex; /* 81 */ + /* + * Interrupts + */ + volatile u_int32_t nicInterrupts; /* 82 */ + volatile u_int32_t nicAvoidedInterrupts; /* 83 */ + /* + * BD Coalessing Thresholds + */ + volatile u_int32_t nicEventThresholdHit; /* 84 */ + volatile u_int32_t nicSendThresholdHit; /* 85 */ + volatile u_int32_t nicRecvThresholdHit; /* 86 */ + /* + * DMA Attentions + */ + volatile u_int32_t nicDmaRdOverrun; /* 87 */ + volatile u_int32_t nicDmaRdUnderrun; /* 88 */ + volatile u_int32_t nicDmaWrOverrun; /* 89 */ + volatile u_int32_t nicDmaWrUnderrun; /* 90 */ + volatile u_int32_t nicDmaWrMasterAborts; /* 91 */ + volatile u_int32_t nicDmaRdMasterAborts; /* 92 */ + /* + * NIC Resources + */ + volatile u_int32_t nicDmaWriteRingFull; /* 93 */ + volatile u_int32_t nicDmaReadRingFull; /* 94 */ + volatile u_int32_t nicEventRingFull; /* 95 */ + volatile u_int32_t nicEventProducerRingFull; /* 96 */ + volatile u_int32_t nicTxMacDescrRingFull; /* 97 */ + volatile u_int32_t nicOutOfTxBufSpaceFrameRetry; /* 98 */ + volatile u_int32_t nicNoMoreWrDMADescriptors; /* 99 */ + volatile u_int32_t nicNoMoreRxBDs; /* 100 */ + volatile u_int32_t nicNoSpaceInReturnRing; /* 101 */ + volatile u_int32_t nicSendBDs; /* current count 102 */ + volatile u_int32_t nicRecvBDs; /* current count 103 */ + volatile u_int32_t nicJumboRecvBDs; /* current count 104 */ + volatile u_int32_t nicMiniRecvBDs; /* current count 105 */ + volatile u_int32_t nicTotalRecvBDs; /* current count 106 */ + volatile u_int32_t nicTotalSendBDs; /* current count 107 */ + volatile u_int32_t nicJumboSpillOver; /* 108 */ + volatile u_int32_t nicSbusHangCleared; /* 109 */ + volatile u_int32_t nicEnqEventDelayed; /* 110 */ + /* + * Stats from MAC rx completion + */ + volatile u_int32_t nicMacRxLateColls; /* 111 */ + volatile u_int32_t nicMacRxLinkLostDuringPkt; /* 112 */ + volatile u_int32_t nicMacRxPhyDecodeErr; /* 113 */ + volatile u_int32_t nicMacRxMacAbort; /* 114 */ + volatile u_int32_t nicMacRxTruncNoResources; /* 115 */ + /* + * Stats from the mac_stats area + */ + volatile u_int32_t nicMacRxDropUla; /* 116 */ + volatile u_int32_t nicMacRxDropMcast; /* 117 */ + volatile u_int32_t nicMacRxFlowControl; /* 118 */ + volatile u_int32_t nicMacRxDropSpace; /* 119 */ + volatile u_int32_t nicMacRxColls; /* 120 */ + /* + * MAC RX Attentions + */ + volatile u_int32_t nicMacRxTotalAttns; /* 121 */ + volatile u_int32_t nicMacRxLinkAttns; /* 122 */ + volatile u_int32_t nicMacRxSyncAttns; /* 123 */ + volatile u_int32_t nicMacRxConfigAttns; /* 124 */ + volatile u_int32_t nicMacReset; /* 125 */ + volatile u_int32_t nicMacRxBufDescrAttns; /* 126 */ + volatile u_int32_t nicMacRxBufAttns; /* 127 */ + volatile u_int32_t nicMacRxZeroFrameCleanup; /* 128 */ + volatile u_int32_t nicMacRxOneFrameCleanup; /* 129 */ + volatile u_int32_t nicMacRxMultipleFrameCleanup; /* 130 */ + volatile u_int32_t nicMacRxTimerCleanup; /* 131 */ + volatile u_int32_t nicMacRxDmaCleanup; /* 132 */ + /* + * Stats from the mac_stats area + */ + volatile u_int32_t nicMacTxCollisionHistogram[15]; /* 133 */ + /* + * MAC TX Attentions + */ + volatile u_int32_t nicMacTxTotalAttns; /* 134 */ + /* + * NIC Profile + */ + volatile u_int32_t nicProfile[32]; /* 135 */ + /* + * Pat to 1024 bytes. + */ + u_int32_t pad[75]; +}; + +struct tg_reg { + u_int32_t data; + u_int32_t addr; +}; + +struct tg_mem { + u_int32_t tgAddr; + caddr_t userAddr; + int len; +}; + + +typedef enum { + TI_PARAM_NONE = 0x00, + TI_PARAM_STAT_TICKS = 0x01, + TI_PARAM_RX_COAL_TICKS = 0x02, + TI_PARAM_TX_COAL_TICKS = 0x04, + TI_PARAM_RX_COAL_BDS = 0x08, + TI_PARAM_TX_COAL_BDS = 0x10, + TI_PARAM_TX_BUF_RATIO = 0x20, + TI_PARAM_ALL = 0x2f +} ti_param_mask; + +struct ti_params { + u_int32_t ti_stat_ticks; + u_int32_t ti_rx_coal_ticks; + u_int32_t ti_tx_coal_ticks; + u_int32_t ti_rx_max_coal_bds; + u_int32_t ti_tx_max_coal_bds; + u_int32_t ti_tx_buf_ratio; + ti_param_mask param_mask; +}; + +typedef enum { + TI_TRACE_TYPE_NONE = 0x00000000, + TI_TRACE_TYPE_SEND = 0x00000001, + TI_TRACE_TYPE_RECV = 0x00000002, + TI_TRACE_TYPE_DMA = 0x00000004, + TI_TRACE_TYPE_EVENT = 0x00000008, + TI_TRACE_TYPE_COMMAND = 0x00000010, + TI_TRACE_TYPE_MAC = 0x00000020, + TI_TRACE_TYPE_STATS = 0x00000040, + TI_TRACE_TYPE_TIMER = 0x00000080, + TI_TRACE_TYPE_DISP = 0x00000100, + TI_TRACE_TYPE_MAILBOX = 0x00000200, + TI_TRACE_TYPE_RECV_BD = 0x00000400, + TI_TRACE_TYPE_LNK_PHY = 0x00000800, + TI_TRACE_TYPE_LNK_NEG = 0x00001000, + TI_TRACE_LEVEL_1 = 0x10000000, + TI_TRACE_LEVEL_2 = 0x20000000 +} ti_trace_type; + +struct ti_trace_buf { + u_long *buf; + int buf_len; + int fill_len; + u_long cur_trace_ptr; +}; + +#define TIIOCGETSTATS _IOR('T', 1, struct ti_stats) +#define TIIOCGETPARAMS _IOR('T', 2, struct ti_params) +#define TIIOCSETPARAMS _IOW('T', 3, struct ti_params) +#define TIIOCSETTRACE _IOW('T', 11, ti_trace_type) +#define TIIOCGETTRACE _IOWR('T', 12, struct ti_trace_buf) + +/* + * Taken from Alteon's altioctl.h. Alteon's ioctl numbers 1-6 aren't + * used by the FreeBSD driver. + */ +#define ALT_ATTACH _IO('a', 7) +#define ALT_READ_TG_MEM _IOWR('a', 10, struct tg_mem) +#define ALT_WRITE_TG_MEM _IOWR('a', 11, struct tg_mem) +#define ALT_READ_TG_REG _IOWR('a', 12, struct tg_reg) +#define ALT_WRITE_TG_REG _IOWR('a', 13, struct tg_reg) + +#endif /* _SYS_TIIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/time.h b/lib/libc/include/any-freebsd-any/sys/time.h new file mode 100644 index 000000000000..fb55bfefd85e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/time.h @@ -0,0 +1,631 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * $FreeBSD$ + */ + +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include +#include + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +#if __BSD_VISIBLE +struct bintime { + time_t sec; + uint64_t frac; +}; + +static __inline void +bintime_addx(struct bintime *_bt, uint64_t _x) +{ + uint64_t _u; + + _u = _bt->frac; + _bt->frac += _x; + if (_u > _bt->frac) + _bt->sec++; +} + +static __inline void +bintime_add(struct bintime *_bt, const struct bintime *_bt2) +{ + uint64_t _u; + + _u = _bt->frac; + _bt->frac += _bt2->frac; + if (_u > _bt->frac) + _bt->sec++; + _bt->sec += _bt2->sec; +} + +static __inline void +bintime_sub(struct bintime *_bt, const struct bintime *_bt2) +{ + uint64_t _u; + + _u = _bt->frac; + _bt->frac -= _bt2->frac; + if (_u < _bt->frac) + _bt->sec--; + _bt->sec -= _bt2->sec; +} + +static __inline void +bintime_mul(struct bintime *_bt, u_int _x) +{ + uint64_t _p1, _p2; + + _p1 = (_bt->frac & 0xffffffffull) * _x; + _p2 = (_bt->frac >> 32) * _x + (_p1 >> 32); + _bt->sec *= _x; + _bt->sec += (_p2 >> 32); + _bt->frac = (_p2 << 32) | (_p1 & 0xffffffffull); +} + +static __inline void +bintime_shift(struct bintime *_bt, int _exp) +{ + + if (_exp > 0) { + _bt->sec <<= _exp; + _bt->sec |= _bt->frac >> (64 - _exp); + _bt->frac <<= _exp; + } else if (_exp < 0) { + _bt->frac >>= -_exp; + _bt->frac |= (uint64_t)_bt->sec << (64 + _exp); + _bt->sec >>= -_exp; + } +} + +#define bintime_clear(a) ((a)->sec = (a)->frac = 0) +#define bintime_isset(a) ((a)->sec || (a)->frac) +#define bintime_cmp(a, b, cmp) \ + (((a)->sec == (b)->sec) ? \ + ((a)->frac cmp (b)->frac) : \ + ((a)->sec cmp (b)->sec)) + +#define SBT_1S ((sbintime_t)1 << 32) +#define SBT_1M (SBT_1S * 60) +#define SBT_1MS (SBT_1S / 1000) +#define SBT_1US (SBT_1S / 1000000) +#define SBT_1NS (SBT_1S / 1000000000) /* beware rounding, see nstosbt() */ +#define SBT_MAX 0x7fffffffffffffffLL + +static __inline int +sbintime_getsec(sbintime_t _sbt) +{ + + return (_sbt >> 32); +} + +static __inline sbintime_t +bttosbt(const struct bintime _bt) +{ + + return (((sbintime_t)_bt.sec << 32) + (_bt.frac >> 32)); +} + +static __inline struct bintime +sbttobt(sbintime_t _sbt) +{ + struct bintime _bt; + + _bt.sec = _sbt >> 32; + _bt.frac = _sbt << 32; + return (_bt); +} + +/* + * Decimal<->sbt conversions. Multiplying or dividing by SBT_1NS results in + * large roundoff errors which sbttons() and nstosbt() avoid. Millisecond and + * microsecond functions are also provided for completeness. + * + * These functions return the smallest sbt larger or equal to the + * number of seconds requested so that sbttoX(Xtosbt(y)) == y. Unlike + * top of second computations below, which require that we tick at the + * top of second, these need to be rounded up so we do whatever for at + * least as long as requested. + * + * The naive computation we'd do is this + * ((unit * 2^64 / SIFACTOR) + 2^32-1) >> 32 + * However, that overflows. Instead, we compute + * ((unit * 2^63 / SIFACTOR) + 2^31-1) >> 32 + * and use pre-computed constants that are the ceil of the 2^63 / SIFACTOR + * term to ensure we are using exactly the right constant. We use the lesser + * evil of ull rather than a uint64_t cast to ensure we have well defined + * right shift semantics. With these changes, we get all the ns, us and ms + * conversions back and forth right. + * Note: This file is used for both kernel and userland includes, so we can't + * rely on KASSERT being defined, nor can we pollute the namespace by including + * assert.h. + */ +static __inline int64_t +sbttons(sbintime_t _sbt) +{ + uint64_t ns; + +#ifdef KASSERT + KASSERT(_sbt >= 0, ("Negative values illegal for sbttons: %jx", _sbt)); +#endif + ns = _sbt; + if (ns >= SBT_1S) + ns = (ns >> 32) * 1000000000; + else + ns = 0; + + return (ns + (1000000000 * (_sbt & 0xffffffffu) >> 32)); +} + +static __inline sbintime_t +nstosbt(int64_t _ns) +{ + sbintime_t sb = 0; + +#ifdef KASSERT + KASSERT(_ns >= 0, ("Negative values illegal for nstosbt: %jd", _ns)); +#endif + if (_ns >= SBT_1S) { + sb = (_ns / 1000000000) * SBT_1S; + _ns = _ns % 1000000000; + } + /* 9223372037 = ceil(2^63 / 1000000000) */ + sb += ((_ns * 9223372037ull) + 0x7fffffff) >> 31; + return (sb); +} + +static __inline int64_t +sbttous(sbintime_t _sbt) +{ + + return ((1000000 * _sbt) >> 32); +} + +static __inline sbintime_t +ustosbt(int64_t _us) +{ + sbintime_t sb = 0; + +#ifdef KASSERT + KASSERT(_us >= 0, ("Negative values illegal for ustosbt: %jd", _us)); +#endif + if (_us >= SBT_1S) { + sb = (_us / 1000000) * SBT_1S; + _us = _us % 1000000; + } + /* 9223372036855 = ceil(2^63 / 1000000) */ + sb += ((_us * 9223372036855ull) + 0x7fffffff) >> 31; + return (sb); +} + +static __inline int64_t +sbttoms(sbintime_t _sbt) +{ + + return ((1000 * _sbt) >> 32); +} + +static __inline sbintime_t +mstosbt(int64_t _ms) +{ + sbintime_t sb = 0; + +#ifdef KASSERT + KASSERT(_ms >= 0, ("Negative values illegal for mstosbt: %jd", _ms)); +#endif + if (_ms >= SBT_1S) { + sb = (_ms / 1000) * SBT_1S; + _ms = _ms % 1000; + } + /* 9223372036854776 = ceil(2^63 / 1000) */ + sb += ((_ms * 9223372036854776ull) + 0x7fffffff) >> 31; + return (sb); +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static __inline void +bintime2timespec(const struct bintime *_bt, struct timespec *_ts) +{ + + _ts->tv_sec = _bt->sec; + _ts->tv_nsec = ((uint64_t)1000000000 * + (uint32_t)(_bt->frac >> 32)) >> 32; +} + +static __inline void +timespec2bintime(const struct timespec *_ts, struct bintime *_bt) +{ + + _bt->sec = _ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + _bt->frac = _ts->tv_nsec * (uint64_t)18446744073LL; +} + +static __inline void +bintime2timeval(const struct bintime *_bt, struct timeval *_tv) +{ + + _tv->tv_sec = _bt->sec; + _tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(_bt->frac >> 32)) >> 32; +} + +static __inline void +timeval2bintime(const struct timeval *_tv, struct bintime *_bt) +{ + + _bt->sec = _tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + _bt->frac = _tv->tv_usec * (uint64_t)18446744073709LL; +} + +static __inline struct timespec +sbttots(sbintime_t _sbt) +{ + struct timespec _ts; + + _ts.tv_sec = _sbt >> 32; + _ts.tv_nsec = sbttons((uint32_t)_sbt); + return (_ts); +} + +static __inline sbintime_t +tstosbt(struct timespec _ts) +{ + + return (((sbintime_t)_ts.tv_sec << 32) + nstosbt(_ts.tv_nsec)); +} + +static __inline struct timeval +sbttotv(sbintime_t _sbt) +{ + struct timeval _tv; + + _tv.tv_sec = _sbt >> 32; + _tv.tv_usec = sbttous((uint32_t)_sbt); + return (_tv); +} + +static __inline sbintime_t +tvtosbt(struct timeval _tv) +{ + + return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec)); +} +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +/* + * Simple macros to convert ticks to milliseconds + * or microseconds and vice-versa. The answer + * will always be at least 1. Note the return + * value is a uint32_t however we step up the + * operations to 64 bit to avoid any overflow/underflow + * problems. + */ +#define TICKS_2_MSEC(t) max(1, (uint32_t)(hz == 1000) ? \ + (t) : (((uint64_t)(t) * (uint64_t)1000)/(uint64_t)hz)) +#define TICKS_2_USEC(t) max(1, (uint32_t)(hz == 1000) ? \ + ((t) * 1000) : (((uint64_t)(t) * (uint64_t)1000000)/(uint64_t)hz)) +#define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \ + (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000)) +#define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \ + ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000)) + +#endif +/* Operations on timespecs */ +#define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) +#define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) +#define timespeccmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) + +#ifdef _KERNEL + +/* Operations on timevals. */ + +#define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timevalcmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + +/* timevaladd and timevalsub are not inlined */ + +#endif /* _KERNEL */ + +#ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */ + +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +/* + * Getkerninfo clock information structure + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int spare; + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; + +/* These macros are also in time.h. */ +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif +#ifndef CLOCK_VIRTUAL +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 +#endif +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 4 +#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ +#define CLOCK_SECOND 13 /* FreeBSD-specific. */ +#define CLOCK_THREAD_CPUTIME_ID 14 +#define CLOCK_PROCESS_CPUTIME_ID 15 +#endif + +#ifndef TIMER_ABSTIME +#define TIMER_RELTIME 0x0 /* relative timer */ +#define TIMER_ABSTIME 0x1 /* absolute timer */ +#endif + +#if __BSD_VISIBLE +#define CPUCLOCK_WHICH_PID 0 +#define CPUCLOCK_WHICH_TID 1 +#endif + +#ifdef _KERNEL + +/* + * Kernel to clock driver interface. + */ +void inittodr(time_t base); +void resettodr(void); + +extern volatile time_t time_second; +extern volatile time_t time_uptime; +extern struct bintime tc_tick_bt; +extern sbintime_t tc_tick_sbt; +extern struct bintime tick_bt; +extern sbintime_t tick_sbt; +extern int tc_precexp; +extern int tc_timepercentage; +extern struct bintime bt_timethreshold; +extern struct bintime bt_tickthreshold; +extern sbintime_t sbt_timethreshold; +extern sbintime_t sbt_tickthreshold; + +extern volatile int rtc_generation; + +/* + * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() + * + * Functions without the "get" prefix returns the best timestamp + * we can produce in the given format. + * + * "bin" == struct bintime == seconds + 64 bit fraction of seconds. + * "nano" == struct timespec == seconds + nanoseconds. + * "micro" == struct timeval == seconds + microseconds. + * + * Functions containing "up" returns time relative to boot and + * should be used for calculating time intervals. + * + * Functions without "up" returns UTC time. + * + * Functions with the "get" prefix returns a less precise result + * much faster than the functions without "get" prefix and should + * be used where a precision of 1/hz seconds is acceptable or where + * performance is priority. (NB: "precision", _not_ "resolution" !) + */ + +void binuptime(struct bintime *bt); +void nanouptime(struct timespec *tsp); +void microuptime(struct timeval *tvp); + +static __inline sbintime_t +sbinuptime(void) +{ + struct bintime _bt; + + binuptime(&_bt); + return (bttosbt(_bt)); +} + +void bintime(struct bintime *bt); +void nanotime(struct timespec *tsp); +void microtime(struct timeval *tvp); + +void getbinuptime(struct bintime *bt); +void getnanouptime(struct timespec *tsp); +void getmicrouptime(struct timeval *tvp); + +static __inline sbintime_t +getsbinuptime(void) +{ + struct bintime _bt; + + getbinuptime(&_bt); + return (bttosbt(_bt)); +} + +void getbintime(struct bintime *bt); +void getnanotime(struct timespec *tsp); +void getmicrotime(struct timeval *tvp); + +void getboottime(struct timeval *boottime); +void getboottimebin(struct bintime *boottimebin); + +/* Other functions */ +int itimerdecr(struct itimerval *itp, int usec); +int itimerfix(struct timeval *tv); +int ppsratecheck(struct timeval *, int *, int); +int ratecheck(struct timeval *, const struct timeval *); +void timevaladd(struct timeval *t1, const struct timeval *t2); +void timevalsub(struct timeval *t1, const struct timeval *t2); +int tvtohz(struct timeval *tv); + +#define TC_DEFAULTPERC 5 + +#define BT2FREQ(bt) \ + (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \ + ((bt)->frac >> 1)) + +#define SBT2FREQ(sbt) ((SBT_1S + ((sbt) >> 1)) / (sbt)) + +#define FREQ2BT(freq, bt) \ +{ \ + (bt)->sec = 0; \ + (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ +} + +#define TIMESEL(sbt, sbt2) \ + (((sbt2) >= sbt_timethreshold) ? \ + ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0)) + +#else /* !_KERNEL */ +#include + +#include +#include + +__BEGIN_DECLS +int setitimer(int, const struct itimerval *, struct itimerval *); +int utimes(const char *, const struct timeval *); + +#if __BSD_VISIBLE +int adjtime(const struct timeval *, struct timeval *); +int clock_getcpuclockid2(id_t, int, clockid_t *); +int futimes(int, const struct timeval *); +int futimesat(int, const char *, const struct timeval [2]); +int lutimes(const char *, const struct timeval *); +int settimeofday(const struct timeval *, const struct timezone *); +#endif + +#if __XSI_VISIBLE +int getitimer(int, struct itimerval *); +int gettimeofday(struct timeval *, struct timezone *); +#endif + +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_TIME_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timeb.h b/lib/libc/include/any-freebsd-any/sys/timeb.h new file mode 100644 index 000000000000..001ec3b5cfaf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timeb.h @@ -0,0 +1,70 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)timeb.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_TIMEB_H_ +#define _SYS_TIMEB_H_ + +#ifdef __GNUC__ +#warning "this file includes which is deprecated" +#endif + +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +/* The ftime(2) system call structure -- deprecated. */ +struct timeb { + time_t time; /* seconds since the Epoch */ + unsigned short millitm; /* + milliseconds since the Epoch */ + short timezone; /* minutes west of CUT */ + short dstflag; /* DST == non-zero */ +}; + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +int ftime(struct timeb *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_TIMEB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timeet.h b/lib/libc/include/any-freebsd-any/sys/timeet.h new file mode 100644 index 000000000000..dc43337d176a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timeet.h @@ -0,0 +1,108 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010-2013 Alexander Motin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TIMEEC_H_ +#define _SYS_TIMEEC_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +#include +#include +#include +#include + +/* + * `struct eventtimer' is the interface between the hardware which implements + * a event timer and the MI code which uses this to receive time events. + */ + +struct eventtimer; +typedef int et_start_t(struct eventtimer *et, + sbintime_t first, sbintime_t period); +typedef int et_stop_t(struct eventtimer *et); +typedef void et_event_cb_t(struct eventtimer *et, void *arg); +typedef int et_deregister_cb_t(struct eventtimer *et, void *arg); + +struct eventtimer { + SLIST_ENTRY(eventtimer) et_all; + /* Pointer to the next event timer. */ + const char *et_name; + /* Name of the event timer. */ + int et_flags; + /* Set of capabilities flags: */ +#define ET_FLAGS_PERIODIC 1 +#define ET_FLAGS_ONESHOT 2 +#define ET_FLAGS_PERCPU 4 +#define ET_FLAGS_C3STOP 8 +#define ET_FLAGS_POW2DIV 16 + int et_quality; + /* + * Used to determine if this timecounter is better than + * another timecounter. Higher means better. + */ + int et_active; + u_int64_t et_frequency; + /* Base frequency in Hz. */ + sbintime_t et_min_period; + sbintime_t et_max_period; + et_start_t *et_start; + et_stop_t *et_stop; + et_event_cb_t *et_event_cb; + et_deregister_cb_t *et_deregister_cb; + void *et_arg; + void *et_priv; + struct sysctl_oid *et_sysctl; + /* Pointer to the event timer's private parts. */ +}; + +extern struct mtx et_eventtimers_mtx; +#define ET_LOCK() mtx_lock(&et_eventtimers_mtx) +#define ET_UNLOCK() mtx_unlock(&et_eventtimers_mtx) + +/* Driver API */ +int et_register(struct eventtimer *et); +int et_deregister(struct eventtimer *et); +void et_change_frequency(struct eventtimer *et, uint64_t newfreq); +/* Consumer API */ +struct eventtimer *et_find(const char *name, int check, int want); +int et_init(struct eventtimer *et, et_event_cb_t *event, + et_deregister_cb_t *deregister, void *arg); +int et_start(struct eventtimer *et, sbintime_t first, sbintime_t period); +int et_stop(struct eventtimer *et); +int et_ban(struct eventtimer *et); +int et_free(struct eventtimer *et); + +#ifdef SYSCTL_DECL +SYSCTL_DECL(_kern_eventtimer); +#endif +#endif /* !_SYS_TIMETC_H_ */ + diff --git a/lib/libc/include/any-freebsd-any/sys/timeffc.h b/lib/libc/include/any-freebsd-any/sys/timeffc.h new file mode 100644 index 000000000000..493a212b3f96 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timeffc.h @@ -0,0 +1,391 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 The University of Melbourne + * All rights reserved. + * + * This software was developed by Julien Ridoux at the University of Melbourne + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TIMEFF_H_ +#define _SYS_TIMEFF_H_ + +#include + +/* + * Feed-forward clock estimate + * Holds time mark as a ffcounter and conversion to bintime based on current + * timecounter period and offset estimate passed by the synchronization daemon. + * Provides time of last daemon update, clock status and bound on error. + */ +struct ffclock_estimate { + struct bintime update_time; /* Time of last estimates update. */ + ffcounter update_ffcount; /* Counter value at last update. */ + ffcounter leapsec_next; /* Counter value of next leap second. */ + uint64_t period; /* Estimate of counter period. */ + uint32_t errb_abs; /* Bound on absolute clock error [ns]. */ + uint32_t errb_rate; /* Bound on counter rate error [ps/s]. */ + uint32_t status; /* Clock status. */ + int16_t leapsec_total; /* All leap seconds seen so far. */ + int8_t leapsec; /* Next leap second (in {-1,0,1}). */ +}; + +#if __BSD_VISIBLE +#ifdef _KERNEL + +/* Define the kern.sysclock sysctl tree. */ +SYSCTL_DECL(_kern_sysclock); + +/* Define the kern.sysclock.ffclock sysctl tree. */ +SYSCTL_DECL(_kern_sysclock_ffclock); + +/* + * Index into the sysclocks array for obtaining the ASCII name of a particular + * sysclock. + */ +#define SYSCLOCK_FBCK 0 +#define SYSCLOCK_FFWD 1 +extern int sysclock_active; + +/* + * Parameters of counter characterisation required by feed-forward algorithms. + */ +#define FFCLOCK_SKM_SCALE 1024 + +/* + * Feed-forward clock status + */ +#define FFCLOCK_STA_UNSYNC 1 +#define FFCLOCK_STA_WARMUP 2 + +/* + * Flags for use by sysclock_snap2bintime() and various ffclock_ functions to + * control how the timecounter hardware is read and how the hardware snapshot is + * converted into absolute time. + * {FB|FF}CLOCK_FAST: Do not read the hardware counter, instead using the + * value at last tick. The time returned has a resolution + * of the kernel tick timer (1/hz [s]). + * FFCLOCK_LERP: Linear interpolation of ffclock time to guarantee + * monotonic time. + * FFCLOCK_LEAPSEC: Include leap seconds. + * {FB|FF}CLOCK_UPTIME: Time stamp should be relative to system boot, not epoch. + */ +#define FFCLOCK_FAST 0x00000001 +#define FFCLOCK_LERP 0x00000002 +#define FFCLOCK_LEAPSEC 0x00000004 +#define FFCLOCK_UPTIME 0x00000008 +#define FFCLOCK_MASK 0x0000ffff + +#define FBCLOCK_FAST 0x00010000 /* Currently unused. */ +#define FBCLOCK_UPTIME 0x00020000 +#define FBCLOCK_MASK 0xffff0000 + +/* + * Feedback clock specific info structure. The feedback clock's estimation of + * clock error is an absolute figure determined by the NTP algorithm. The status + * is determined by the userland daemon. + */ +struct fbclock_info { + struct bintime error; + struct bintime tick_time; + uint64_t th_scale; + int status; +}; + +/* + * Feed-forward clock specific info structure. The feed-forward clock's + * estimation of clock error is an upper bound, which although potentially + * looser than the feedback clock equivalent, is much more reliable. The status + * is determined by the userland daemon. + */ +struct ffclock_info { + struct bintime error; + struct bintime tick_time; + struct bintime tick_time_lerp; + uint64_t period; + uint64_t period_lerp; + int leapsec_adjustment; + int status; +}; + +/* + * Snapshot of system clocks and related information. Holds time read from each + * clock based on a single read of the active hardware timecounter, as well as + * respective clock information such as error estimates and the ffcounter value + * at the time of the read. + */ +struct sysclock_snap { + struct fbclock_info fb_info; + struct ffclock_info ff_info; + ffcounter ffcount; + unsigned int delta; + int sysclock_active; +}; + +/* Take a snapshot of the system clocks and related information. */ +void sysclock_getsnapshot(struct sysclock_snap *clock_snap, int fast); + +/* Convert a timestamp from the selected system clock into bintime. */ +int sysclock_snap2bintime(struct sysclock_snap *cs, struct bintime *bt, + int whichclock, uint32_t flags); + +/* Resets feed-forward clock from RTC */ +void ffclock_reset_clock(struct timespec *ts); + +/* + * Return the current value of the feed-forward clock counter. Essential to + * measure time interval in counter units. If a fast timecounter is used by the + * system, may also allow fast but accurate timestamping. + */ +void ffclock_read_counter(ffcounter *ffcount); + +/* + * Retrieve feed-forward counter value and time of last kernel tick. This + * accepts the FFCLOCK_LERP flag. + */ +void ffclock_last_tick(ffcounter *ffcount, struct bintime *bt, uint32_t flags); + +/* + * Low level routines to convert a counter timestamp into absolute time and a + * counter timestamp interval into an interval in seconds. The absolute time + * conversion accepts the FFCLOCK_LERP flag. + */ +void ffclock_convert_abs(ffcounter ffcount, struct bintime *bt, uint32_t flags); +void ffclock_convert_diff(ffcounter ffdelta, struct bintime *bt); + +/* + * Feed-forward clock routines. + * + * These functions rely on the timecounters and ffclock_estimates stored in + * fftimehands. Note that the error_bound parameter is not the error of the + * clock but an upper bound on the error of the absolute time or time interval + * returned. + * + * ffclock_abstime(): retrieves current time as counter value and convert this + * timestamp in seconds. The value (in seconds) of the converted timestamp + * depends on the flags passed: for a given counter value, different + * conversions are possible. Different clock models can be selected by + * combining flags (for example (FFCLOCK_LERP|FFCLOCK_UPTIME) produces + * linearly interpolated uptime). + * ffclock_difftime(): computes a time interval in seconds based on an interval + * measured in ffcounter units. This should be the preferred way to measure + * small time intervals very accurately. + */ +void ffclock_abstime(ffcounter *ffcount, struct bintime *bt, + struct bintime *error_bound, uint32_t flags); +void ffclock_difftime(ffcounter ffdelta, struct bintime *bt, + struct bintime *error_bound); + +/* + * Wrapper routines to return current absolute time using the feed-forward + * clock. These functions are named after those defined in , which + * contains a description of the original ones. + */ +void ffclock_bintime(struct bintime *bt); +void ffclock_nanotime(struct timespec *tsp); +void ffclock_microtime(struct timeval *tvp); + +void ffclock_getbintime(struct bintime *bt); +void ffclock_getnanotime(struct timespec *tsp); +void ffclock_getmicrotime(struct timeval *tvp); + +void ffclock_binuptime(struct bintime *bt); +void ffclock_nanouptime(struct timespec *tsp); +void ffclock_microuptime(struct timeval *tvp); + +void ffclock_getbinuptime(struct bintime *bt); +void ffclock_getnanouptime(struct timespec *tsp); +void ffclock_getmicrouptime(struct timeval *tvp); + +/* + * Wrapper routines to convert a time interval specified in ffcounter units into + * seconds using the current feed-forward clock estimates. + */ +void ffclock_bindifftime(ffcounter ffdelta, struct bintime *bt); +void ffclock_nanodifftime(ffcounter ffdelta, struct timespec *tsp); +void ffclock_microdifftime(ffcounter ffdelta, struct timeval *tvp); + +/* + * When FFCLOCK is enabled in the kernel, [get]{bin,nano,micro}[up]time() become + * wrappers around equivalent feedback or feed-forward functions. Provide access + * outside of kern_tc.c to the feedback clock equivalent functions for + * specialised use i.e. these are not for general consumption. + */ +void fbclock_bintime(struct bintime *bt); +void fbclock_nanotime(struct timespec *tsp); +void fbclock_microtime(struct timeval *tvp); + +void fbclock_getbintime(struct bintime *bt); +void fbclock_getnanotime(struct timespec *tsp); +void fbclock_getmicrotime(struct timeval *tvp); + +void fbclock_binuptime(struct bintime *bt); +void fbclock_nanouptime(struct timespec *tsp); +void fbclock_microuptime(struct timeval *tvp); + +void fbclock_getbinuptime(struct bintime *bt); +void fbclock_getnanouptime(struct timespec *tsp); +void fbclock_getmicrouptime(struct timeval *tvp); + +/* + * Public system clock wrapper API which allows consumers to select which clock + * to obtain time from, independent of the current default system clock. These + * wrappers should be used instead of directly calling the underlying fbclock_ + * or ffclock_ functions. + */ +static inline void +bintime_fromclock(struct bintime *bt, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_bintime(bt); + else + fbclock_bintime(bt); +} + +static inline void +nanotime_fromclock(struct timespec *tsp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_nanotime(tsp); + else + fbclock_nanotime(tsp); +} + +static inline void +microtime_fromclock(struct timeval *tvp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_microtime(tvp); + else + fbclock_microtime(tvp); +} + +static inline void +getbintime_fromclock(struct bintime *bt, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getbintime(bt); + else + fbclock_getbintime(bt); +} + +static inline void +getnanotime_fromclock(struct timespec *tsp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getnanotime(tsp); + else + fbclock_getnanotime(tsp); +} + +static inline void +getmicrotime_fromclock(struct timeval *tvp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getmicrotime(tvp); + else + fbclock_getmicrotime(tvp); +} + +static inline void +binuptime_fromclock(struct bintime *bt, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_binuptime(bt); + else + fbclock_binuptime(bt); +} + +static inline void +nanouptime_fromclock(struct timespec *tsp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_nanouptime(tsp); + else + fbclock_nanouptime(tsp); +} + +static inline void +microuptime_fromclock(struct timeval *tvp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_microuptime(tvp); + else + fbclock_microuptime(tvp); +} + +static inline void +getbinuptime_fromclock(struct bintime *bt, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getbinuptime(bt); + else + fbclock_getbinuptime(bt); +} + +static inline void +getnanouptime_fromclock(struct timespec *tsp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getnanouptime(tsp); + else + fbclock_getnanouptime(tsp); +} + +static inline void +getmicrouptime_fromclock(struct timeval *tvp, int whichclock) +{ + + if (whichclock == SYSCLOCK_FFWD) + ffclock_getmicrouptime(tvp); + else + fbclock_getmicrouptime(tvp); +} + +#else /* !_KERNEL */ + +/* Feed-Forward Clock system calls. */ +__BEGIN_DECLS +int ffclock_getcounter(ffcounter *ffcount); +int ffclock_getestimate(struct ffclock_estimate *cest); +int ffclock_setestimate(struct ffclock_estimate *cest); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* __BSD_VISIBLE */ +#endif /* _SYS_TIMEFF_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timepps.h b/lib/libc/include/any-freebsd-any/sys/timepps.h new file mode 100644 index 000000000000..99ea2207be35 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timepps.h @@ -0,0 +1,268 @@ +/*- + * SPDX-License-Identifier: Beerware + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Julien Ridoux at the University + * of Melbourne under sponsorship from the FreeBSD Foundation. + * + * $FreeBSD$ + * + * The is a FreeBSD version of the RFC 2783 API for Pulse Per Second + * timing interfaces. + */ + +#ifndef _SYS_TIMEPPS_H_ +#define _SYS_TIMEPPS_H_ + +#include +#include +#include + +#define PPS_API_VERS_1 1 + +typedef int pps_handle_t; + +typedef unsigned pps_seq_t; + +typedef struct ntp_fp { + unsigned int integral; + unsigned int fractional; +} ntp_fp_t; + +typedef union pps_timeu { + struct timespec tspec; + ntp_fp_t ntpfp; + unsigned long longpad[3]; +} pps_timeu_t; + +typedef struct { + pps_seq_t assert_sequence; /* assert event seq # */ + pps_seq_t clear_sequence; /* clear event seq # */ + pps_timeu_t assert_tu; + pps_timeu_t clear_tu; + int current_mode; /* current mode bits */ +} pps_info_t; + +typedef struct { + pps_seq_t assert_sequence; /* assert event seq # */ + pps_seq_t clear_sequence; /* clear event seq # */ + pps_timeu_t assert_tu; + pps_timeu_t clear_tu; + ffcounter assert_ffcount; /* ffcounter on assert event */ + ffcounter clear_ffcount; /* ffcounter on clear event */ + int current_mode; /* current mode bits */ +} pps_info_ffc_t; + +#define assert_timestamp assert_tu.tspec +#define clear_timestamp clear_tu.tspec + +#define assert_timestamp_ntpfp assert_tu.ntpfp +#define clear_timestamp_ntpfp clear_tu.ntpfp + +typedef struct { + int api_version; /* API version # */ + int mode; /* mode bits */ + pps_timeu_t assert_off_tu; + pps_timeu_t clear_off_tu; +} pps_params_t; + +#define assert_offset assert_off_tu.tspec +#define clear_offset clear_off_tu.tspec + +#define assert_offset_ntpfp assert_off_tu.ntpfp +#define clear_offset_ntpfp clear_off_tu.ntpfp + + +#define PPS_CAPTUREASSERT 0x01 +#define PPS_CAPTURECLEAR 0x02 +#define PPS_CAPTUREBOTH 0x03 + +#define PPS_OFFSETASSERT 0x10 +#define PPS_OFFSETCLEAR 0x20 + +#define PPS_ECHOASSERT 0x40 +#define PPS_ECHOCLEAR 0x80 + +#define PPS_CANWAIT 0x100 +#define PPS_CANPOLL 0x200 + +#define PPS_TSFMT_TSPEC 0x1000 +#define PPS_TSFMT_NTPFP 0x2000 + +#define PPS_TSCLK_FBCK 0x10000 +#define PPS_TSCLK_FFWD 0x20000 +#define PPS_TSCLK_MASK 0x30000 + +#define PPS_KC_HARDPPS 0 +#define PPS_KC_HARDPPS_PLL 1 +#define PPS_KC_HARDPPS_FLL 2 + +struct pps_fetch_args { + int tsformat; + pps_info_t pps_info_buf; + struct timespec timeout; +}; + +struct pps_fetch_ffc_args { + int tsformat; + pps_info_ffc_t pps_info_buf_ffc; + struct timespec timeout; +}; + +struct pps_kcbind_args { + int kernel_consumer; + int edge; + int tsformat; +}; + +#define PPS_IOC_CREATE _IO('1', 1) +#define PPS_IOC_DESTROY _IO('1', 2) +#define PPS_IOC_SETPARAMS _IOW('1', 3, pps_params_t) +#define PPS_IOC_GETPARAMS _IOR('1', 4, pps_params_t) +#define PPS_IOC_GETCAP _IOR('1', 5, int) +#define PPS_IOC_FETCH _IOWR('1', 6, struct pps_fetch_args) +#define PPS_IOC_KCBIND _IOW('1', 7, struct pps_kcbind_args) +#define PPS_IOC_FETCH_FFCOUNTER _IOWR('1', 8, struct pps_fetch_ffc_args) + +#ifdef _KERNEL + +struct mtx; + +#define KCMODE_EDGEMASK 0x03 +#define KCMODE_ABIFLAG 0x80000000 /* Internal use: abi-aware driver. */ + +#define PPS_ABI_VERSION 1 + +#define PPSFLAG_MTX_SPIN 0x01 /* Driver mtx is MTX_SPIN type. */ + +struct pps_state { + /* Capture information. */ + struct timehands *capth; + struct fftimehands *capffth; + unsigned capgen; + unsigned capcount; + + /* State information. */ + pps_params_t ppsparam; + pps_info_t ppsinfo; + pps_info_ffc_t ppsinfo_ffc; + int kcmode; + int ppscap; + struct timecounter *ppstc; + unsigned ppscount[3]; + /* + * The following fields are valid if the driver calls pps_init_abi(). + */ + uint16_t driver_abi; /* Driver sets before pps_init_abi(). */ + uint16_t kernel_abi; /* Kernel sets during pps_init_abi(). */ + struct mtx *driver_mtx; /* Optional, valid if non-NULL. */ + uint32_t flags; +}; + +void pps_capture(struct pps_state *pps); +void pps_event(struct pps_state *pps, int event); +void pps_init(struct pps_state *pps); +void pps_init_abi(struct pps_state *pps); +int pps_ioctl(unsigned long cmd, caddr_t data, struct pps_state *pps); +void hardpps(struct timespec *tsp, long nsec); + +#else /* !_KERNEL */ + +static __inline int +time_pps_create(int filedes, pps_handle_t *handle) +{ + int error; + + *handle = -1; + error = ioctl(filedes, PPS_IOC_CREATE, 0); + if (error < 0) + return (-1); + *handle = filedes; + return (0); +} + +static __inline int +time_pps_destroy(pps_handle_t handle) +{ + return (ioctl(handle, PPS_IOC_DESTROY, 0)); +} + +static __inline int +time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams) +{ + return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams)); +} + +static __inline int +time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams) +{ + return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams)); +} + +static __inline int +time_pps_getcap(pps_handle_t handle, int *mode) +{ + return (ioctl(handle, PPS_IOC_GETCAP, mode)); +} + +static __inline int +time_pps_fetch(pps_handle_t handle, const int tsformat, + pps_info_t *ppsinfobuf, const struct timespec *timeout) +{ + int error; + struct pps_fetch_args arg; + + arg.tsformat = tsformat; + if (timeout == NULL) { + arg.timeout.tv_sec = -1; + arg.timeout.tv_nsec = -1; + } else + arg.timeout = *timeout; + error = ioctl(handle, PPS_IOC_FETCH, &arg); + *ppsinfobuf = arg.pps_info_buf; + return (error); +} + +static __inline int +time_pps_fetch_ffc(pps_handle_t handle, const int tsformat, + pps_info_ffc_t *ppsinfobuf, const struct timespec *timeout) +{ + struct pps_fetch_ffc_args arg; + int error; + + arg.tsformat = tsformat; + if (timeout == NULL) { + arg.timeout.tv_sec = -1; + arg.timeout.tv_nsec = -1; + } else { + arg.timeout = *timeout; + } + error = ioctl(handle, PPS_IOC_FETCH_FFCOUNTER, &arg); + *ppsinfobuf = arg.pps_info_buf_ffc; + return (error); +} + +static __inline int +time_pps_kcbind(pps_handle_t handle, const int kernel_consumer, + const int edge, const int tsformat) +{ + struct pps_kcbind_args arg; + + arg.kernel_consumer = kernel_consumer; + arg.edge = edge; + arg.tsformat = tsformat; + return (ioctl(handle, PPS_IOC_KCBIND, &arg)); +} + +#endif /* KERNEL */ + +#endif /* !_SYS_TIMEPPS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timers.h b/lib/libc/include/any-freebsd-any/sys/timers.h new file mode 100644 index 000000000000..01956bd3caaa --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timers.h @@ -0,0 +1,119 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2005 David Xu + * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Description : Basic timers header. + */ + +#ifndef _SYS_TIMERS_H_ +#define _SYS_TIMERS_H_ + +#include + +#ifdef _KERNEL +/* + * Structures used to manage POSIX timers in a process. + */ +struct itimer { + struct mtx it_mtx; + struct sigevent it_sigev; + struct itimerspec it_time; + struct proc *it_proc; + int it_flags; + int it_usecount; + int it_overrun; /* Overruns currently accumulating */ + int it_overrun_last; /* Overruns associated w/ a delivery */ + int it_clockid; + int it_timerid; + ksiginfo_t it_ksi; + union { + /* realtime */ + struct { + struct callout it_callout; + } _rt; + + /* cpu timer */ + struct { + LIST_ENTRY(itimer) it_link; + TAILQ_ENTRY(itimer) it_worklink; + int it_active; + int it_cflags; + } _cpu; + } _data; +}; + +#define it_callout _data._rt.it_callout +#define it_link _data._cpu.it_link +#define it_active _data._cpu.it_active +#define it_worklink _data._cpu.it_worklink +#define it_cflags _data._cpu.it_cflags + +#define ITF_DELETING 0x01 +#define ITF_WANTED 0x02 + +#define ITCF_ONWORKLIST 0x01 + +#define TIMER_MAX 32 + +#define ITIMER_LOCK(it) mtx_lock(&(it)->it_mtx) +#define ITIMER_UNLOCK(it) mtx_unlock(&(it)->it_mtx) + +LIST_HEAD(itimerlist, itimer); + +struct itimers { + struct itimerlist its_virtual; + struct itimerlist its_prof; + TAILQ_HEAD(, itimer) its_worklist; + struct itimer *its_timers[TIMER_MAX]; +}; + +struct kclock { + int (*timer_create)(struct itimer *timer); + int (*timer_settime)(struct itimer * timer, int flags, + struct itimerspec * new_value, + struct itimerspec * old_value); + int (*timer_delete)(struct itimer * timer); + int (*timer_gettime)(struct itimer * timer, + struct itimerspec * cur_value); + void (*event_hook)(struct proc *p, clockid_t clock_id, int event); +}; + +/* Event values for event_hook() */ +#define ITIMER_EV_EXEC 0 +#define ITIMER_EV_EXIT 1 + +int itimer_accept(struct proc *p, int tid, ksiginfo_t *ksi); +#endif +#endif /* !_SYS_TIMERS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/times.h b/lib/libc/include/any-freebsd-any/sys/times.h new file mode 100644 index 000000000000..0c690e5635fc --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/times.h @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)times.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +#ifndef _SYS_TIMES_H_ +#define _SYS_TIMES_H_ + +#include + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +clock_t times(struct tms *); +__END_DECLS +#endif +#endif /* !_SYS_TIMES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timespec.h b/lib/libc/include/any-freebsd-any/sys/timespec.h new file mode 100644 index 000000000000..fa3812a08388 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timespec.h @@ -0,0 +1,65 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD$ + */ + +#ifndef _SYS_TIMESPEC_H_ +#define _SYS_TIMESPEC_H_ + +#include +#include + +#if __BSD_VISIBLE +#define TIMEVAL_TO_TIMESPEC(tv, ts) \ + do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ + } while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) \ + do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ + } while (0) + +#endif /* __BSD_VISIBLE */ + +/* + * Structure defined by POSIX.1b to be like a itimerval, but with + * timespecs. Used in the timer_*() system calls. + */ +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; + +#endif /* _SYS_TIMESPEC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timetc.h b/lib/libc/include/any-freebsd-any/sys/timetc.h new file mode 100644 index 000000000000..55f61af4c46c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timetc.h @@ -0,0 +1,99 @@ +/*- + * SPDX-License-Identifier: Beerware + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + */ + +#ifndef _SYS_TIMETC_H_ +#define _SYS_TIMETC_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +/*- + * `struct timecounter' is the interface between the hardware which implements + * a timecounter and the MI code which uses this to keep track of time. + * + * A timecounter is a binary counter which has two properties: + * * it runs at a fixed, known frequency. + * * it has sufficient bits to not roll over in less than approximately + * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta, + * for some indeterminate value of delta.) + */ + +struct timecounter; +struct vdso_timehands; +struct vdso_timehands32; +typedef u_int timecounter_get_t(struct timecounter *); +typedef void timecounter_pps_t(struct timecounter *); +typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *, + struct timecounter *); +typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *, + struct timecounter *); + +struct timecounter { + timecounter_get_t *tc_get_timecount; + /* + * This function reads the counter. It is not required to + * mask any unimplemented bits out, as long as they are + * constant. + */ + timecounter_pps_t *tc_poll_pps; + /* + * This function is optional. It will be called whenever the + * timecounter is rewound, and is intended to check for PPS + * events. Normal hardware does not need it but timecounters + * which latch PPS in hardware (like sys/pci/xrpu.c) do. + */ + u_int tc_counter_mask; + /* This mask should mask off any unimplemented bits. */ + uint64_t tc_frequency; + /* Frequency of the counter in Hz. */ + const char *tc_name; + /* Name of the timecounter. */ + int tc_quality; + /* + * Used to determine if this timecounter is better than + * another timecounter higher means better. Negative + * means "only use at explicit request". + */ + u_int tc_flags; +#define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */ +#define TC_FLAGS_SUSPEND_SAFE 2 /* + * Timer functional across + * suspend/resume. + */ + + void *tc_priv; + /* Pointer to the timecounter's private parts. */ + struct timecounter *tc_next; + /* Pointer to the next timecounter. */ + timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands; + timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32; +}; + +extern struct timecounter *timecounter; +extern int tc_min_ticktock_freq; /* + * Minimal tc_ticktock() call frequency, + * required to handle counter wraps. + */ + +u_int64_t tc_getfrequency(void); +void tc_init(struct timecounter *tc); +void tc_setclock(struct timespec *ts); +void tc_ticktock(int cnt); +void cpu_tick_calibration(void); + +#ifdef SYSCTL_DECL +SYSCTL_DECL(_kern_timecounter); +#endif + +#endif /* !_SYS_TIMETC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/timex.h b/lib/libc/include/any-freebsd-any/sys/timex.h new file mode 100644 index 000000000000..4fa5735e2d45 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/timex.h @@ -0,0 +1,171 @@ +/*- + *********************************************************************** + * * + * Copyright (c) David L. Mills 1993-2001 * + * Copyright (c) Poul-Henning Kamp 2000-2001 * + * * + * Permission to use, copy, modify, and distribute this software and * + * its documentation for any purpose and without fee is hereby * + * granted, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission * + * notice appear in supporting documentation, and that the name * + * University of Delaware not be used in advertising or publicity * + * pertaining to distribution of the software without specific, * + * written prior permission. The University of Delaware makes no * + * representations about the suitability this software for any * + * purpose. It is provided "as is" without express or implied * + * warranty. * + * * + *********************************************************************** + * + * $FreeBSD$ + * + * This header file defines the Network Time Protocol (NTP) interfaces + * for user and daemon application programs. + * + * This file was originally created 17 Sep 93 by David L. Mills, Professor + * of University of Delaware, building on work which had already been ongoing + * for a decade and a half at that point in time. + * + * In 2000 the APIs got a upgrade from microseconds to nanoseconds, + * a joint work between Poul-Henning Kamp and David L. Mills. + * + */ + +#ifndef _SYS_TIMEX_H_ +#define _SYS_TIMEX_H_ 1 + +#define NTP_API 4 /* NTP API version */ + +#ifdef __FreeBSD__ +#include +#endif /* __FreeBSD__ */ + +/* + * The following defines establish the performance envelope of the + * kernel discipline loop. Phase or frequency errors greater than + * NAXPHASE or MAXFREQ are clamped to these maxima. For update intervals + * less than MINSEC, the loop always operates in PLL mode; while, for + * update intervals greater than MAXSEC, the loop always operates in FLL + * mode. Between these two limits the operating mode is selected by the + * STA_FLL bit in the status word. + */ + +#define MAXPHASE 500000000L /* max phase error (ns) */ +#define MAXFREQ 500000L /* max freq error (ns/s) */ +#define MINSEC 256 /* min FLL update interval (s) */ +#define MAXSEC 2048 /* max PLL update interval (s) */ +#define NANOSECOND 1000000000L /* nanoseconds in one second */ +#define SCALE_PPM (65536 / 1000) /* crude ns/s to scaled PPM */ +#define MAXTC 10 /* max time constant */ + +/* + * Control mode codes (timex.modes) + */ +#define MOD_OFFSET 0x0001 /* set time offset */ +#define MOD_FREQUENCY 0x0002 /* set frequency offset */ +#define MOD_MAXERROR 0x0004 /* set maximum time error */ +#define MOD_ESTERROR 0x0008 /* set estimated time error */ +#define MOD_STATUS 0x0010 /* set clock status bits */ +#define MOD_TIMECONST 0x0020 /* set PLL time constant */ +#define MOD_PPSMAX 0x0040 /* set PPS maximum averaging time */ +#define MOD_TAI 0x0080 /* set TAI offset */ +#define MOD_MICRO 0x1000 /* select microsecond resolution */ +#define MOD_NANO 0x2000 /* select nanosecond resolution */ +#define MOD_CLKB 0x4000 /* select clock B */ +#define MOD_CLKA 0x8000 /* select clock A */ + +/* + * Status codes (timex.status) + */ +#define STA_PLL 0x0001 /* enable PLL updates (rw) */ +#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */ +#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */ +#define STA_FLL 0x0008 /* enable FLL mode (rw) */ +#define STA_INS 0x0010 /* insert leap (rw) */ +#define STA_DEL 0x0020 /* delete leap (rw) */ +#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */ +#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */ +#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */ +#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */ +#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */ +#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */ +#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */ +#define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */ +#define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */ +#define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */ + +#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ + STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) + +/* + * Clock states (ntptimeval.time_state) + */ +#define TIME_OK 0 /* no leap second warning */ +#define TIME_INS 1 /* insert leap second warning */ +#define TIME_DEL 2 /* delete leap second warning */ +#define TIME_OOP 3 /* leap second in progress */ +#define TIME_WAIT 4 /* leap second has occurred */ +#define TIME_ERROR 5 /* error (see status word) */ + +/* + * NTP user interface -- ntp_gettime(2) - used to read kernel clock values + */ +struct ntptimeval { + struct timespec time; /* current time (ns) (ro) */ + long maxerror; /* maximum error (us) (ro) */ + long esterror; /* estimated error (us) (ro) */ + long tai; /* TAI offset */ + int time_state; /* time status */ +}; + +/* + * NTP daemon interface -- ntp_adjtime(2) -- used to discipline CPU clock + * oscillator and control/determine status. + * + * Note: The offset, precision and jitter members are in microseconds if + * STA_NANO is zero and nanoseconds if not. + */ +struct timex { + unsigned int modes; /* clock mode bits (wo) */ + long offset; /* time offset (ns/us) (rw) */ + long freq; /* frequency offset (scaled PPM) (rw) */ + long maxerror; /* maximum error (us) (rw) */ + long esterror; /* estimated error (us) (rw) */ + int status; /* clock status bits (rw) */ + long constant; /* poll interval (log2 s) (rw) */ + long precision; /* clock precision (ns/us) (ro) */ + long tolerance; /* clock frequency tolerance (scaled + * PPM) (ro) */ + /* + * The following read-only structure members are implemented + * only if the PPS signal discipline is configured in the + * kernel. They are included in all configurations to insure + * portability. + */ + long ppsfreq; /* PPS frequency (scaled PPM) (ro) */ + long jitter; /* PPS jitter (ns/us) (ro) */ + int shift; /* interval duration (s) (shift) (ro) */ + long stabil; /* PPS stability (scaled PPM) (ro) */ + long jitcnt; /* jitter limit exceeded (ro) */ + long calcnt; /* calibration intervals (ro) */ + long errcnt; /* calibration errors (ro) */ + long stbcnt; /* stability limit exceeded (ro) */ +}; + +#ifdef __FreeBSD__ + +#ifdef _KERNEL +void ntp_update_second(int64_t *adjustment, time_t *newsec); +#else /* !_KERNEL */ +#include + +__BEGIN_DECLS +int ntp_adjtime(struct timex *); +int ntp_gettime(struct ntptimeval *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* __FreeBSD__ */ + +#endif /* !_SYS_TIMEX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/tree.h b/lib/libc/include/any-freebsd-any/sys/tree.h new file mode 100644 index 000000000000..539afb42b90d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/tree.h @@ -0,0 +1,803 @@ +/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 2002 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +#include + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ + RB_PROTOTYPE_INSERT_COLOR(name, type, attr); \ + RB_PROTOTYPE_REMOVE_COLOR(name, type, attr); \ + RB_PROTOTYPE_INSERT(name, type, attr); \ + RB_PROTOTYPE_REMOVE(name, type, attr); \ + RB_PROTOTYPE_FIND(name, type, attr); \ + RB_PROTOTYPE_NFIND(name, type, attr); \ + RB_PROTOTYPE_NEXT(name, type, attr); \ + RB_PROTOTYPE_PREV(name, type, attr); \ + RB_PROTOTYPE_MINMAX(name, type, attr); +#define RB_PROTOTYPE_INSERT_COLOR(name, type, attr) \ + attr void name##_RB_INSERT_COLOR(struct name *, struct type *) +#define RB_PROTOTYPE_REMOVE_COLOR(name, type, attr) \ + attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *) +#define RB_PROTOTYPE_REMOVE(name, type, attr) \ + attr struct type *name##_RB_REMOVE(struct name *, struct type *) +#define RB_PROTOTYPE_INSERT(name, type, attr) \ + attr struct type *name##_RB_INSERT(struct name *, struct type *) +#define RB_PROTOTYPE_FIND(name, type, attr) \ + attr struct type *name##_RB_FIND(struct name *, struct type *) +#define RB_PROTOTYPE_NFIND(name, type, attr) \ + attr struct type *name##_RB_NFIND(struct name *, struct type *) +#define RB_PROTOTYPE_NEXT(name, type, attr) \ + attr struct type *name##_RB_NEXT(struct type *) +#define RB_PROTOTYPE_PREV(name, type, attr) \ + attr struct type *name##_RB_PREV(struct type *) +#define RB_PROTOTYPE_MINMAX(name, type, attr) \ + attr struct type *name##_RB_MINMAX(struct name *, int) + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ + RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ + RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ + RB_GENERATE_INSERT(name, type, field, cmp, attr) \ + RB_GENERATE_REMOVE(name, type, field, attr) \ + RB_GENERATE_FIND(name, type, field, cmp, attr) \ + RB_GENERATE_NFIND(name, type, field, cmp, attr) \ + RB_GENERATE_NEXT(name, type, field, attr) \ + RB_GENERATE_PREV(name, type, field, attr) \ + RB_GENERATE_MINMAX(name, type, field, attr) + +#define RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} + +#define RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} + +#define RB_GENERATE_REMOVE(name, type, field, attr) \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + +#define RB_GENERATE_INSERT(name, type, field, cmp, attr) \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} + +#define RB_GENERATE_FIND(name, type, field, cmp, attr) \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} + +#define RB_GENERATE_NFIND(name, type, field, cmp, attr) \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} + +#define RB_GENERATE_NEXT(name, type, field, attr) \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} + +#define RB_GENERATE_PREV(name, type, field, attr) \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} + +#define RB_GENERATE_MINMAX(name, type, field, attr) \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#endif /* _SYS_TREE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/tslog.h b/lib/libc/include/any-freebsd-any/sys/tslog.h new file mode 100644 index 000000000000..4b2971e4e643 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/tslog.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2017 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _TSLOG_H_ +#define _TSLOG_H_ + +#ifdef TSLOG +#include +#include +#endif + +#define TS_ENTER 0 +#define TS_EXIT 1 +#define TS_THREAD 2 +#define TS_EVENT 3 + +#define TSENTER() TSRAW(curthread, TS_ENTER, __func__, NULL) +#define TSENTER2(x) TSRAW(curthread, TS_ENTER, __func__, x) +#define TSEXIT() TSRAW(curthread, TS_EXIT, __func__, NULL) +#define TSEXIT2(x) TSRAW(curthread, TS_EXIT, __func__, x) +#define TSTHREAD(td, x) TSRAW(td, TS_THREAD, x, NULL) +#define TSEVENT(x) TSRAW(curthread, TS_EVENT, x, NULL) +#define TSEVENT2(x, y) TSRAW(curthread, TS_EVENT, x, y) +#define TSLINE() TSEVENT2(__FILE__, __XSTRING(__LINE__)) +#define TSWAIT(x) TSEVENT2("WAIT", x); +#define TSUNWAIT(x) TSEVENT2("UNWAIT", x); +#define TSHOLD(x) TSEVENT2("HOLD", x); +#define TSRELEASE(x) TSEVENT2("RELEASE", x); + +#ifdef TSLOG +#define TSRAW(a, b, c, d) tslog(a, b, c, d) +void tslog(void *, int, const char *, const char *); +#else +#define TSRAW(a, b, c, d) /* Timestamp logging disabled */ +#endif + +#endif /* _TSLOG_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/tty.h b/lib/libc/include/any-freebsd-any/sys/tty.h new file mode 100644 index 000000000000..f4dc079a6adf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/tty.h @@ -0,0 +1,233 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Portions of this software were developed under sponsorship from Snow + * B.V., the Netherlands. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TTY_H_ +#define _SYS_TTY_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct cdev; +struct file; +struct pgrp; +struct session; +struct ucred; + +struct ttydevsw; + +/* + * Per-TTY structure, containing buffers, etc. + * + * List of locks + * (t) locked by t_mtx + * (l) locked by tty_list_sx + * (c) const until freeing + */ +struct tty { + struct mtx *t_mtx; /* TTY lock. */ + struct mtx t_mtxobj; /* Per-TTY lock (when not borrowing). */ + TAILQ_ENTRY(tty) t_list; /* (l) TTY list entry. */ + int t_drainwait; /* (t) TIOCDRAIN timeout seconds. */ + unsigned int t_flags; /* (t) Terminal option flags. */ +/* Keep flags in sync with db_show_tty and pstat(8). */ +#define TF_NOPREFIX 0x00001 /* Don't prepend "tty" to device name. */ +#define TF_INITLOCK 0x00002 /* Create init/lock state devices. */ +#define TF_CALLOUT 0x00004 /* Create "cua" devices. */ +#define TF_OPENED_IN 0x00008 /* "tty" node is in use. */ +#define TF_OPENED_OUT 0x00010 /* "cua" node is in use. */ +#define TF_OPENED_CONS 0x00020 /* Device in use as console. */ +#define TF_OPENED (TF_OPENED_IN|TF_OPENED_OUT|TF_OPENED_CONS) +#define TF_GONE 0x00040 /* Device node is gone. */ +#define TF_OPENCLOSE 0x00080 /* Device is in open()/close(). */ +#define TF_ASYNC 0x00100 /* Asynchronous I/O enabled. */ +#define TF_LITERAL 0x00200 /* Accept the next character literally. */ +#define TF_HIWAT_IN 0x00400 /* We've reached the input watermark. */ +#define TF_HIWAT_OUT 0x00800 /* We've reached the output watermark. */ +#define TF_HIWAT (TF_HIWAT_IN|TF_HIWAT_OUT) +#define TF_STOPPED 0x01000 /* Output flow control - stopped. */ +#define TF_EXCLUDE 0x02000 /* Exclusive access. */ +#define TF_BYPASS 0x04000 /* Optimized input path. */ +#define TF_ZOMBIE 0x08000 /* Modem disconnect received. */ +#define TF_HOOK 0x10000 /* TTY has hook attached. */ +#define TF_BUSY_IN 0x20000 /* Process busy in read() -- not supported. */ +#define TF_BUSY_OUT 0x40000 /* Process busy in write(). */ +#define TF_BUSY (TF_BUSY_IN|TF_BUSY_OUT) + unsigned int t_revokecnt; /* (t) revoke() count. */ + + /* Buffering mechanisms. */ + struct ttyinq t_inq; /* (t) Input queue. */ + size_t t_inlow; /* (t) Input low watermark. */ + struct ttyoutq t_outq; /* (t) Output queue. */ + size_t t_outlow; /* (t) Output low watermark. */ + + /* Sleeping mechanisms. */ + struct cv t_inwait; /* (t) Input wait queue. */ + struct cv t_outwait; /* (t) Output wait queue. */ + struct cv t_outserwait; /* (t) Serial output wait queue. */ + struct cv t_bgwait; /* (t) Background wait queue. */ + struct cv t_dcdwait; /* (t) Carrier Detect wait queue. */ + + /* Polling mechanisms. */ + struct selinfo t_inpoll; /* (t) Input poll queue. */ + struct selinfo t_outpoll; /* (t) Output poll queue. */ + struct sigio *t_sigio; /* (t) Asynchronous I/O. */ + + struct termios t_termios; /* (t) I/O processing flags. */ + struct winsize t_winsize; /* (t) Window size. */ + unsigned int t_column; /* (t) Current cursor position. */ + unsigned int t_writepos; /* (t) Where input was interrupted. */ + int t_compatflags; /* (t) COMPAT_43TTY flags. */ + + /* Init/lock-state devices. */ + struct termios t_termios_init_in; /* tty%s.init. */ + struct termios t_termios_lock_in; /* tty%s.lock. */ + struct termios t_termios_init_out; /* cua%s.init. */ + struct termios t_termios_lock_out; /* cua%s.lock. */ + + struct ttydevsw *t_devsw; /* (c) Driver hooks. */ + struct ttyhook *t_hook; /* (t) Capture/inject hook. */ + + /* Process signal delivery. */ + struct pgrp *t_pgrp; /* (t) Foreground process group. */ + struct session *t_session; /* (t) Associated session. */ + unsigned int t_sessioncnt; /* (t) Backpointing sessions. */ + + void *t_devswsoftc; /* (c) Soft config, for drivers. */ + void *t_hooksoftc; /* (t) Soft config, for hooks. */ + struct cdev *t_dev; /* (c) Primary character device. */ +}; + +/* + * Userland version of struct tty, for sysctl kern.ttys + */ +struct xtty { + size_t xt_size; /* Structure size. */ + size_t xt_insize; /* Input queue size. */ + size_t xt_incc; /* Canonicalized characters. */ + size_t xt_inlc; /* Input line charaters. */ + size_t xt_inlow; /* Input low watermark. */ + size_t xt_outsize; /* Output queue size. */ + size_t xt_outcc; /* Output queue usage. */ + size_t xt_outlow; /* Output low watermark. */ + unsigned int xt_column; /* Current column position. */ + pid_t xt_pgid; /* Foreground process group. */ + pid_t xt_sid; /* Session. */ + unsigned int xt_flags; /* Terminal option flags. */ + uint32_t xt_dev; /* Userland device. XXXKIB truncated */ +}; + +#ifdef _KERNEL + +/* Used to distinguish between normal, callout, lock and init devices. */ +#define TTYUNIT_INIT 0x1 +#define TTYUNIT_LOCK 0x2 +#define TTYUNIT_CALLOUT 0x4 + +/* Allocation and deallocation. */ +struct tty *tty_alloc(struct ttydevsw *tsw, void *softc); +struct tty *tty_alloc_mutex(struct ttydevsw *tsw, void *softc, struct mtx *mtx); +void tty_rel_pgrp(struct tty *tp, struct pgrp *pgrp); +void tty_rel_sess(struct tty *tp, struct session *sess); +void tty_rel_gone(struct tty *tp); + +#define tty_lock(tp) mtx_lock((tp)->t_mtx) +#define tty_unlock(tp) mtx_unlock((tp)->t_mtx) +#define tty_lock_owned(tp) mtx_owned((tp)->t_mtx) +#define tty_assert_locked(tp) mtx_assert((tp)->t_mtx, MA_OWNED) +#define tty_getlock(tp) ((tp)->t_mtx) + +/* XXX Should migrate users to tty_assert_locked! */ +#define tty_lock_assert(tp, ma) mtx_assert((tp)->t_mtx, (ma)) + +/* Device node creation. */ +int tty_makedevf(struct tty *tp, struct ucred *cred, int flags, + const char *fmt, ...) __printflike(4, 5); +#define TTYMK_CLONING 0x1 +#define tty_makedev(tp, cred, fmt, ...) \ + (void )tty_makedevf((tp), (cred), 0, (fmt), ## __VA_ARGS__) +#define tty_makealias(tp,fmt,...) \ + make_dev_alias((tp)->t_dev, fmt, ## __VA_ARGS__) + +/* Signalling processes. */ +void tty_signal_sessleader(struct tty *tp, int signal); +void tty_signal_pgrp(struct tty *tp, int signal); +/* Waking up readers/writers. */ +int tty_wait(struct tty *tp, struct cv *cv); +int tty_wait_background(struct tty *tp, struct thread *td, int sig); +int tty_timedwait(struct tty *tp, struct cv *cv, int timo); +void tty_wakeup(struct tty *tp, int flags); + +/* System messages. */ +int tty_checkoutq(struct tty *tp); +int tty_putchar(struct tty *tp, char c); + +int tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, + struct thread *td); +int tty_ioctl_compat(struct tty *tp, u_long cmd, caddr_t data, + int fflag, struct thread *td); +void tty_set_winsize(struct tty *tp, const struct winsize *wsz); +void tty_init_console(struct tty *tp, speed_t speed); +void tty_flush(struct tty *tp, int flags); +void tty_hiwat_in_block(struct tty *tp); +void tty_hiwat_in_unblock(struct tty *tp); +dev_t tty_udev(struct tty *tp); +#define tty_opened(tp) ((tp)->t_flags & TF_OPENED) +#define tty_gone(tp) ((tp)->t_flags & TF_GONE) +#define tty_softc(tp) ((tp)->t_devswsoftc) +#define tty_devname(tp) devtoname((tp)->t_dev) + +/* Status line printing. */ +void tty_info(struct tty *tp); + +/* /dev/console selection. */ +void ttyconsdev_select(const char *name); + +/* Pseudo-terminal hooks. */ +int pts_alloc(int fflags, struct thread *td, struct file *fp); +int pts_alloc_external(int fd, struct thread *td, struct file *fp, + struct cdev *dev, const char *name); + +/* Drivers and line disciplines also need to call these. */ +#include +#include +#include +#endif /* _KERNEL */ + +#endif /* !_SYS_TTY_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttycom.h b/lib/libc/include/any-freebsd-any/sys/ttycom.h new file mode 100644 index 000000000000..5aabb074a009 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttycom.h @@ -0,0 +1,147 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ttycom.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _SYS_TTYCOM_H_ +#define _SYS_TTYCOM_H_ + +#include + +/* + * Tty ioctl's except for those supported only for backwards compatibility + * with the old tty driver. + */ + +/* + * Window/terminal size structure. This information is stored by the kernel + * in order to provide a consistent interface, but is not used by the kernel. + */ +struct winsize { + unsigned short ws_row; /* rows, in characters */ + unsigned short ws_col; /* columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, pixels */ + unsigned short ws_ypixel; /* vertical size, pixels */ +}; + + /* 0-2 compat */ + /* 3-7 unused */ + /* 8-10 compat */ + /* 11-12 unused */ +#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */ +#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */ +#define TIOCGPTN _IOR('t', 15, int) /* Get pts number. */ +#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ + /* 17-18 compat */ +#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */ +#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ +#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ +#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ + /* 23-25 unused */ +#define TIOCGETD _IOR('t', 26, int) /* get line discipline */ +#define TIOCSETD _IOW('t', 27, int) /* set line discipline */ +#define TIOCPTMASTER _IO('t', 28) /* pts master validation */ + /* 29-85 unused */ +#define TIOCGDRAINWAIT _IOR('t', 86, int) /* get ttywait timeout */ +#define TIOCSDRAINWAIT _IOW('t', 87, int) /* set ttywait timeout */ + /* 88 unused */ + /* 89-91 conflicts: tun and tap */ +#define TIOCTIMESTAMP _IOR('t', 89, struct timeval) /* enable/get timestamp + * of last input event */ +#define TIOCMGDTRWAIT _IOR('t', 90, int) /* modem: get wait on close */ +#define TIOCMSDTRWAIT _IOW('t', 91, int) /* modem: set wait on close */ + /* 92-93 tun and tap */ + /* 94-97 conflicts: tun and tap */ +#define TIOCDRAIN _IO('t', 94) /* wait till output drained */ +#define TIOCSIG _IOWINT('t', 95) /* pty: generate signal */ +#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ +#define TIOCSCTTY _IO('t', 97) /* become controlling tty */ +#define TIOCCONS _IOW('t', 98, int) /* become virtual console */ +#define TIOCGSID _IOR('t', 99, int) /* get session id */ + /* 100 unused */ +#define TIOCSTAT _IO('t', 101) /* simulate ^T status message */ +#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ +#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ +#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ +#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ + /* 105 unused */ +#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ +#define TIOCM_LE 0001 /* line enable */ +#define TIOCM_DTR 0002 /* data terminal ready */ +#define TIOCM_RTS 0004 /* request to send */ +#define TIOCM_ST 0010 /* secondary transmit */ +#define TIOCM_SR 0020 /* secondary receive */ +#define TIOCM_CTS 0040 /* clear to send */ +#define TIOCM_DCD 0100 /* data carrier detect */ +#define TIOCM_RI 0200 /* ring indicate */ +#define TIOCM_DSR 0400 /* data set ready */ +#define TIOCM_CD TIOCM_DCD +#define TIOCM_CAR TIOCM_DCD +#define TIOCM_RNG TIOCM_RI +#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ +#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ +#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ +#define TIOCSTART _IO('t', 110) /* start output, like ^Q */ +#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ +#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ +#define TIOCPKT_DATA 0x00 /* data packet */ +#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define TIOCPKT_STOP 0x04 /* stop output */ +#define TIOCPKT_START 0x08 /* start output */ +#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ +#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ +#define TIOCNOTTY _IO('t', 113) /* void tty association */ +#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */ +#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ + /* 116-117 compat */ +#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ +#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ +#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */ +#define TIOCSDTR _IO('t', 121) /* set data terminal ready */ +#define TIOCCBRK _IO('t', 122) /* clear break bit */ +#define TIOCSBRK _IO('t', 123) /* set break bit */ + /* 124-127 compat */ + +#define TTYDISC 0 /* termios tty line discipline */ +#define SLIPDISC 4 /* serial IP discipline */ +#define PPPDISC 5 /* PPP discipline */ +#define NETGRAPHDISC 6 /* Netgraph tty node discipline */ +#define H4DISC 7 /* Netgraph Bluetooth H4 discipline */ + +#endif /* !_SYS_TTYCOM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttydefaults.h b/lib/libc/include/any-freebsd-any/sys/ttydefaults.h new file mode 100644 index 000000000000..c269c56fd23f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttydefaults.h @@ -0,0 +1,113 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD$ + */ + +/* + * System wide defaults for terminal state. + */ +#ifndef _SYS_TTYDEFAULTS_H_ +#define _SYS_TTYDEFAULTS_H_ + +/* + * Defaults on "first" open. + */ +#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR) +#define TTYDEF_LFLAG_NOECHO (ICANON | ISIG | IEXTEN) +#define TTYDEF_LFLAG_ECHO (TTYDEF_LFLAG_NOECHO \ + | ECHO | ECHOE | ECHOKE | ECHOCTL) +#define TTYDEF_LFLAG TTYDEF_LFLAG_ECHO +#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) +#define TTYDEF_SPEED (B9600) + +/* + * Control Character Defaults + */ +/* + * XXX: A lot of code uses lowercase characters, but control-character + * conversion is actually only valid when applied to uppercase + * characters. We just treat lowercase characters as if they were + * inserted as uppercase. + */ +#define CTRL(x) ((x) >= 'a' && (x) <= 'z' ? \ + ((x) - 'a' + 1) : (((x) - 'A' + 1) & 0x7f)) +#define CEOF CTRL('D') +#define CEOL 0xff /* XXX avoid _POSIX_VDISABLE */ +#define CERASE CTRL('?') +#define CERASE2 CTRL('H') +#define CINTR CTRL('C') +#define CSTATUS CTRL('T') +#define CKILL CTRL('U') +#define CMIN 1 +#define CQUIT CTRL('\\') +#define CSUSP CTRL('Z') +#define CTIME 0 +#define CDSUSP CTRL('Y') +#define CSTART CTRL('Q') +#define CSTOP CTRL('S') +#define CLNEXT CTRL('V') +#define CDISCARD CTRL('O') +#define CWERASE CTRL('W') +#define CREPRINT CTRL('R') +#define CEOT CEOF +/* compat */ +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD + +/* PROTECTED INCLUSION ENDS HERE */ +#endif /* !_SYS_TTYDEFAULTS_H_ */ + +/* + * #define TTYDEFCHARS to include an array of default control characters. + */ +#ifdef TTYDEFCHARS + +#include +#include + +static const cc_t ttydefchars[] = { + CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, CERASE2, CINTR, + CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, CDISCARD, CMIN, CTIME, + CSTATUS, _POSIX_VDISABLE +}; +_Static_assert(sizeof(ttydefchars) / sizeof(cc_t) == NCCS, + "Size of ttydefchars does not match NCCS"); + +#undef TTYDEFCHARS +#endif /* TTYDEFCHARS */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttydevsw.h b/lib/libc/include/any-freebsd-any/sys/ttydevsw.h new file mode 100644 index 000000000000..d6b544e80323 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttydevsw.h @@ -0,0 +1,211 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Portions of this software were developed under sponsorship from Snow + * B.V., the Netherlands. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TTYDEVSW_H_ +#define _SYS_TTYDEVSW_H_ + +#ifndef _SYS_TTY_H_ +#error "can only be included through " +#endif /* !_SYS_TTY_H_ */ + +/* + * Driver routines that are called from the line discipline to adjust + * hardware parameters and such. + */ +typedef int tsw_open_t(struct tty *tp); +typedef void tsw_close_t(struct tty *tp); +typedef void tsw_outwakeup_t(struct tty *tp); +typedef void tsw_inwakeup_t(struct tty *tp); +typedef int tsw_ioctl_t(struct tty *tp, u_long cmd, caddr_t data, + struct thread *td); +typedef int tsw_cioctl_t(struct tty *tp, int unit, u_long cmd, caddr_t data, + struct thread *td); +typedef int tsw_param_t(struct tty *tp, struct termios *t); +typedef int tsw_modem_t(struct tty *tp, int sigon, int sigoff); +typedef int tsw_mmap_t(struct tty *tp, vm_ooffset_t offset, + vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr); +typedef void tsw_pktnotify_t(struct tty *tp, char event); +typedef void tsw_free_t(void *softc); +typedef bool tsw_busy_t(struct tty *tp); + +struct ttydevsw { + unsigned int tsw_flags; /* Default TTY flags. */ + + tsw_open_t *tsw_open; /* Device opening. */ + tsw_close_t *tsw_close; /* Device closure. */ + + tsw_outwakeup_t *tsw_outwakeup; /* Output available. */ + tsw_inwakeup_t *tsw_inwakeup; /* Input can be stored again. */ + + tsw_ioctl_t *tsw_ioctl; /* ioctl() hooks. */ + tsw_cioctl_t *tsw_cioctl; /* ioctl() on control devices. */ + tsw_param_t *tsw_param; /* TIOCSETA device parameter setting. */ + tsw_modem_t *tsw_modem; /* Modem sigon/sigoff. */ + + tsw_mmap_t *tsw_mmap; /* mmap() hooks. */ + tsw_pktnotify_t *tsw_pktnotify; /* TIOCPKT events. */ + + tsw_free_t *tsw_free; /* Destructor. */ + + tsw_busy_t *tsw_busy; /* Draining output. */ + + void *tsw_spare[3]; /* For future use. */ +}; + +static __inline int +ttydevsw_open(struct tty *tp) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_open(tp)); +} + +static __inline void +ttydevsw_close(struct tty *tp) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + tp->t_devsw->tsw_close(tp); +} + +static __inline void +ttydevsw_outwakeup(struct tty *tp) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + /* Prevent spurious wakeups. */ + if (ttydisc_getc_poll(tp) == 0) + return; + + tp->t_devsw->tsw_outwakeup(tp); +} + +static __inline void +ttydevsw_inwakeup(struct tty *tp) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + /* Prevent spurious wakeups. */ + if (tp->t_flags & TF_HIWAT_IN) + return; + + tp->t_devsw->tsw_inwakeup(tp); +} + +static __inline int +ttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_ioctl(tp, cmd, data, td)); +} + +static __inline int +ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, + struct thread *td) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td)); +} + +static __inline int +ttydevsw_param(struct tty *tp, struct termios *t) +{ + + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_param(tp, t)); +} + +static __inline int +ttydevsw_modem(struct tty *tp, int sigon, int sigoff) +{ + + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_modem(tp, sigon, sigoff)); +} + +static __inline int +ttydevsw_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, + int nprot, vm_memattr_t *memattr) +{ + + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_mmap(tp, offset, paddr, nprot, memattr)); +} + +static __inline void +ttydevsw_pktnotify(struct tty *tp, char event) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + tp->t_devsw->tsw_pktnotify(tp, event); +} + +static __inline void +ttydevsw_free(struct tty *tp) +{ + + MPASS(tty_gone(tp)); + + tp->t_devsw->tsw_free(tty_softc(tp)); +} + +static __inline bool +ttydevsw_busy(struct tty *tp) +{ + + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return (tp->t_devsw->tsw_busy(tp)); +} + +#endif /* !_SYS_TTYDEVSW_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttydisc.h b/lib/libc/include/any-freebsd-any/sys/ttydisc.h new file mode 100644 index 000000000000..295a92c36842 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttydisc.h @@ -0,0 +1,89 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Portions of this software were developed under sponsorship from Snow + * B.V., the Netherlands. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TTYDISC_H_ +#define _SYS_TTYDISC_H_ + +#ifndef _SYS_TTY_H_ +#error "can only be included through " +#endif /* !_SYS_TTY_H_ */ + +struct cv; +struct thread; +struct tty; +struct uio; + +/* Top half routines. */ +void ttydisc_open(struct tty *tp); +void ttydisc_close(struct tty *tp); +int ttydisc_read(struct tty *tp, struct uio *uio, int ioflag); +int ttydisc_write(struct tty *tp, struct uio *uio, int ioflag); +void ttydisc_optimize(struct tty *tp); + +/* Bottom half routines. */ +void ttydisc_modem(struct tty *tp, int open); +#define ttydisc_can_bypass(tp) ((tp)->t_flags & TF_BYPASS) +int ttydisc_rint(struct tty *tp, char c, int flags); +size_t ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len); +size_t ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len); +void ttydisc_rint_done(struct tty *tp); +size_t ttydisc_rint_poll(struct tty *tp); +size_t ttydisc_getc(struct tty *tp, void *buf, size_t len); +int ttydisc_getc_uio(struct tty *tp, struct uio *uio); +size_t ttydisc_getc_poll(struct tty *tp); + +/* Error codes for ttydisc_rint(). */ +#define TRE_FRAMING 0x01 +#define TRE_PARITY 0x02 +#define TRE_OVERRUN 0x04 +#define TRE_BREAK 0x08 + +static __inline size_t +ttydisc_read_poll(struct tty *tp) +{ + + tty_assert_locked(tp); + + return ttyinq_bytescanonicalized(&tp->t_inq); +} + +static __inline size_t +ttydisc_write_poll(struct tty *tp) +{ + + tty_assert_locked(tp); + + return ttyoutq_bytesleft(&tp->t_outq); +} + +#endif /* !_SYS_TTYDISC_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttyhook.h b/lib/libc/include/any-freebsd-any/sys/ttyhook.h new file mode 100644 index 000000000000..e4bd7ac53d1b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttyhook.h @@ -0,0 +1,149 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TTYHOOK_H_ +#define _SYS_TTYHOOK_H_ + +#ifndef _SYS_TTY_H_ +#error "can only be included through " +#endif /* !_SYS_TTY_H_ */ + +struct tty; + +/* + * Hooks interface, which allows to capture and inject traffic into the + * input and output paths of a TTY. + */ + +typedef int th_rint_t(struct tty *tp, char c, int flags); +typedef size_t th_rint_bypass_t(struct tty *tp, const void *buf, size_t len); +typedef void th_rint_done_t(struct tty *tp); +typedef size_t th_rint_poll_t(struct tty *tp); + +typedef size_t th_getc_inject_t(struct tty *tp, void *buf, size_t len); +typedef void th_getc_capture_t(struct tty *tp, const void *buf, size_t len); +typedef size_t th_getc_poll_t(struct tty *tp); + +typedef void th_close_t(struct tty *tp); + +struct ttyhook { + /* Character input. */ + th_rint_t *th_rint; + th_rint_bypass_t *th_rint_bypass; + th_rint_done_t *th_rint_done; + th_rint_poll_t *th_rint_poll; + + /* Character output. */ + th_getc_inject_t *th_getc_inject; + th_getc_capture_t *th_getc_capture; + th_getc_poll_t *th_getc_poll; + + th_close_t *th_close; +}; + +int ttyhook_register(struct tty **, struct proc *, int, + struct ttyhook *, void *); +void ttyhook_unregister(struct tty *); +#define ttyhook_softc(tp) ((tp)->t_hooksoftc) +#define ttyhook_hashook(tp,hook) ((tp)->t_hook != NULL && \ + (tp)->t_hook->th_ ## hook != NULL) + +static __inline int +ttyhook_rint(struct tty *tp, char c, int flags) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return tp->t_hook->th_rint(tp, c, flags); +} + +static __inline size_t +ttyhook_rint_bypass(struct tty *tp, const void *buf, size_t len) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return tp->t_hook->th_rint_bypass(tp, buf, len); +} + +static __inline void +ttyhook_rint_done(struct tty *tp) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + tp->t_hook->th_rint_done(tp); +} + +static __inline size_t +ttyhook_rint_poll(struct tty *tp) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return tp->t_hook->th_rint_poll(tp); +} + +static __inline size_t +ttyhook_getc_inject(struct tty *tp, void *buf, size_t len) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return tp->t_hook->th_getc_inject(tp, buf, len); +} + +static __inline void +ttyhook_getc_capture(struct tty *tp, const void *buf, size_t len) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + tp->t_hook->th_getc_capture(tp, buf, len); +} + +static __inline size_t +ttyhook_getc_poll(struct tty *tp) +{ + tty_assert_locked(tp); + MPASS(!tty_gone(tp)); + + return tp->t_hook->th_getc_poll(tp); +} + +static __inline void +ttyhook_close(struct tty *tp) +{ + tty_assert_locked(tp); + + tp->t_hook->th_close(tp); +} + +#endif /* !_SYS_TTYHOOK_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ttyqueue.h b/lib/libc/include/any-freebsd-any/sys/ttyqueue.h new file mode 100644 index 000000000000..c1ddaa42b41b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ttyqueue.h @@ -0,0 +1,180 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Portions of this software were developed under sponsorship from Snow + * B.V., the Netherlands. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TTYQUEUE_H_ +#define _SYS_TTYQUEUE_H_ + +#ifndef _SYS_TTY_H_ +#error "can only be included through " +#endif /* !_SYS_TTY_H_ */ + +struct tty; +struct ttyinq_block; +struct ttyoutq_block; +struct uio; + +/* Data input queue. */ +struct ttyinq { + struct ttyinq_block *ti_firstblock; + struct ttyinq_block *ti_startblock; + struct ttyinq_block *ti_reprintblock; + struct ttyinq_block *ti_lastblock; + unsigned int ti_begin; + unsigned int ti_linestart; + unsigned int ti_reprint; + unsigned int ti_end; + unsigned int ti_nblocks; + unsigned int ti_quota; +}; +#define TTYINQ_DATASIZE 128 + +/* Data output queue. */ +struct ttyoutq { + struct ttyoutq_block *to_firstblock; + struct ttyoutq_block *to_lastblock; + unsigned int to_begin; + unsigned int to_end; + unsigned int to_nblocks; + unsigned int to_quota; +}; +#define TTYOUTQ_DATASIZE (256 - sizeof(struct ttyoutq_block *)) + +#ifdef _KERNEL +/* Input queue handling routines. */ +int ttyinq_setsize(struct ttyinq *ti, struct tty *tp, size_t len); +void ttyinq_free(struct ttyinq *ti); +int ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio, + size_t readlen, size_t flushlen); +size_t ttyinq_write(struct ttyinq *ti, const void *buf, size_t len, + int quote); +int ttyinq_write_nofrag(struct ttyinq *ti, const void *buf, size_t len, + int quote); +void ttyinq_canonicalize(struct ttyinq *ti); +size_t ttyinq_findchar(struct ttyinq *ti, const char *breakc, size_t maxlen, + char *lastc); +void ttyinq_flush(struct ttyinq *ti); +int ttyinq_peekchar(struct ttyinq *ti, char *c, int *quote); +void ttyinq_unputchar(struct ttyinq *ti); +void ttyinq_reprintpos_set(struct ttyinq *ti); +void ttyinq_reprintpos_reset(struct ttyinq *ti); + +static __inline size_t +ttyinq_getsize(struct ttyinq *ti) +{ + return (ti->ti_nblocks * TTYINQ_DATASIZE); +} + +static __inline size_t +ttyinq_getallocatedsize(struct ttyinq *ti) +{ + + return (ti->ti_quota * TTYINQ_DATASIZE); +} + +static __inline size_t +ttyinq_bytesleft(struct ttyinq *ti) +{ + size_t len; + + /* Make sure the usage never exceeds the length. */ + len = ti->ti_nblocks * TTYINQ_DATASIZE; + MPASS(len >= ti->ti_end); + + return (len - ti->ti_end); +} + +static __inline size_t +ttyinq_bytescanonicalized(struct ttyinq *ti) +{ + MPASS(ti->ti_begin <= ti->ti_linestart); + + return (ti->ti_linestart - ti->ti_begin); +} + +static __inline size_t +ttyinq_bytesline(struct ttyinq *ti) +{ + MPASS(ti->ti_linestart <= ti->ti_end); + + return (ti->ti_end - ti->ti_linestart); +} + +/* Input buffer iteration. */ +typedef void ttyinq_line_iterator_t(void *data, char c, int flags); +void ttyinq_line_iterate_from_linestart(struct ttyinq *ti, + ttyinq_line_iterator_t *iterator, void *data); +void ttyinq_line_iterate_from_reprintpos(struct ttyinq *ti, + ttyinq_line_iterator_t *iterator, void *data); + +/* Output queue handling routines. */ +void ttyoutq_flush(struct ttyoutq *to); +int ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t len); +void ttyoutq_free(struct ttyoutq *to); +size_t ttyoutq_read(struct ttyoutq *to, void *buf, size_t len); +int ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio); +size_t ttyoutq_write(struct ttyoutq *to, const void *buf, size_t len); +int ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t len); + +static __inline size_t +ttyoutq_getsize(struct ttyoutq *to) +{ + return (to->to_nblocks * TTYOUTQ_DATASIZE); +} + +static __inline size_t +ttyoutq_getallocatedsize(struct ttyoutq *to) +{ + + return (to->to_quota * TTYOUTQ_DATASIZE); +} + +static __inline size_t +ttyoutq_bytesleft(struct ttyoutq *to) +{ + size_t len; + + /* Make sure the usage never exceeds the length. */ + len = to->to_nblocks * TTYOUTQ_DATASIZE; + MPASS(len >= to->to_end); + + return (len - to->to_end); +} + +static __inline size_t +ttyoutq_bytesused(struct ttyoutq *to) +{ + return (to->to_end - to->to_begin); +} +#endif /* _KERNEL */ + +#endif /* !_SYS_TTYQUEUE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/turnstile.h b/lib/libc/include/any-freebsd-any/sys/turnstile.h new file mode 100644 index 000000000000..7a93f30fc7e2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/turnstile.h @@ -0,0 +1,108 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_TURNSTILE_H_ +#define _SYS_TURNSTILE_H_ + +/* + * Turnstile interface. Non-sleepable locks use a turnstile for the + * queue of threads blocked on them when they are contested. Each + * turnstile contains two sub-queues: one for threads waiting for a + * shared, or read, lock, and one for threads waiting for an + * exclusive, or write, lock. + * + * A thread calls turnstile_chain_lock() to lock the turnstile chain + * associated with a given lock. A thread calls turnstile_wait() when + * the lock is contested to be put on the queue and block. If a thread + * calls turnstile_trywait() and decides to retry a lock operation instead + * of blocking, it should call turnstile_cancel() to unlock the associated + * turnstile chain lock. + * + * When a lock is released, the thread calls turnstile_lookup() to look + * up the turnstile associated with the given lock in the hash table. Then + * it calls either turnstile_signal() or turnstile_broadcast() to mark + * blocked threads for a pending wakeup. turnstile_signal() marks the + * highest priority blocked thread while turnstile_broadcast() marks all + * blocked threads. The turnstile_signal() function returns true if the + * turnstile became empty as a result. After the higher level code finishes + * releasing the lock, turnstile_unpend() must be called to wake up the + * pending thread(s) and give up ownership of the turnstile. + * + * Alternatively, if a thread wishes to relinquish ownership of a lock + * without waking up any waiters, it may call turnstile_disown(). + * + * When a lock is acquired that already has at least one thread contested + * on it, the new owner of the lock must claim ownership of the turnstile + * via turnstile_claim(). + * + * Each thread allocates a turnstile at thread creation via turnstile_alloc() + * and releases it at thread destruction via turnstile_free(). Note that + * a turnstile is not tied to a specific thread and that the turnstile + * released at thread destruction may not be the same turnstile that the + * thread allocated when it was created. + * + * The highest priority thread blocked on a specified queue of a + * turnstile can be obtained via turnstile_head(). A given queue can + * also be queried to see if it is empty via turnstile_empty(). + */ + +struct lock_object; +struct thread; +struct turnstile; + +#ifdef _KERNEL + +/* Which queue to block on or which queue to wakeup one or more threads from. */ +#define TS_EXCLUSIVE_QUEUE 0 +#define TS_SHARED_QUEUE 1 + +void init_turnstiles(void); +void turnstile_adjust(struct thread *, u_char); +struct turnstile *turnstile_alloc(void); +void turnstile_broadcast(struct turnstile *, int); +void turnstile_cancel(struct turnstile *); +void turnstile_chain_lock(struct lock_object *); +void turnstile_chain_unlock(struct lock_object *); +void turnstile_claim(struct turnstile *); +void turnstile_disown(struct turnstile *); +int turnstile_empty(struct turnstile *ts, int queue); +void turnstile_free(struct turnstile *); +struct thread *turnstile_head(struct turnstile *, int); +struct turnstile *turnstile_lookup(struct lock_object *); +int turnstile_signal(struct turnstile *, int); +struct turnstile *turnstile_trywait(struct lock_object *); +void turnstile_unpend(struct turnstile *); +void turnstile_wait(struct turnstile *, struct thread *, int); +bool turnstile_lock(struct turnstile *, struct lock_object **, + struct thread **); +void turnstile_unlock(struct turnstile *, struct lock_object *); +void turnstile_assert(struct turnstile *); +#endif /* _KERNEL */ +#endif /* _SYS_TURNSTILE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/types.h b/lib/libc/include/any-freebsd-any/sys/types.h new file mode 100644 index 000000000000..0b8887912509 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/types.h @@ -0,0 +1,437 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 8.6 (Berkeley) 2/19/95 + * $FreeBSD$ + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include + +/* Machine type dependent parameters. */ +#include +#include + +#include + +#if __BSD_VISIBLE +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; +#ifndef _KERNEL +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +#endif +#endif + +/* + * XXX POSIX sized integrals that should appear only in . + */ +#include + +typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; + +typedef __uint64_t u_quad_t; /* quads (deprecated) */ +typedef __int64_t quad_t; +typedef quad_t * qaddr_t; + +typedef char * caddr_t; /* core address */ +typedef const char * c_caddr_t; /* core address, pointer to const */ + +#ifndef _BLKSIZE_T_DECLARED +typedef __blksize_t blksize_t; +#define _BLKSIZE_T_DECLARED +#endif + +typedef __cpuwhich_t cpuwhich_t; +typedef __cpulevel_t cpulevel_t; +typedef __cpusetid_t cpusetid_t; + +#ifndef _BLKCNT_T_DECLARED +typedef __blkcnt_t blkcnt_t; +#define _BLKCNT_T_DECLARED +#endif + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +#ifndef _CLOCKID_T_DECLARED +typedef __clockid_t clockid_t; +#define _CLOCKID_T_DECLARED +#endif + +typedef __critical_t critical_t; /* Critical section value */ +typedef __daddr_t daddr_t; /* disk address */ + +#ifndef _DEV_T_DECLARED +typedef __dev_t dev_t; /* device number or struct cdev */ +#define _DEV_T_DECLARED +#endif + +#ifndef _FFLAGS_T_DECLARED +typedef __fflags_t fflags_t; /* file flags */ +#define _FFLAGS_T_DECLARED +#endif + +typedef __fixpt_t fixpt_t; /* fixed point number */ + +#ifndef _FSBLKCNT_T_DECLARED /* for statvfs() */ +typedef __fsblkcnt_t fsblkcnt_t; +typedef __fsfilcnt_t fsfilcnt_t; +#define _FSBLKCNT_T_DECLARED +#endif + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; /* group id */ +#define _GID_T_DECLARED +#endif + +#ifndef _IN_ADDR_T_DECLARED +typedef __uint32_t in_addr_t; /* base type for internet address */ +#define _IN_ADDR_T_DECLARED +#endif + +#ifndef _IN_PORT_T_DECLARED +typedef __uint16_t in_port_t; +#define _IN_PORT_T_DECLARED +#endif + +#ifndef _ID_T_DECLARED +typedef __id_t id_t; /* can hold a uid_t or pid_t */ +#define _ID_T_DECLARED +#endif + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; /* inode number */ +#define _INO_T_DECLARED +#endif + +#ifndef _KEY_T_DECLARED +typedef __key_t key_t; /* IPC key (for Sys V IPC) */ +#define _KEY_T_DECLARED +#endif + +#ifndef _LWPID_T_DECLARED +typedef __lwpid_t lwpid_t; /* Thread ID (a.k.a. LWP) */ +#define _LWPID_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; /* permissions */ +#define _MODE_T_DECLARED +#endif + +#ifndef _ACCMODE_T_DECLARED +typedef __accmode_t accmode_t; /* access permissions */ +#define _ACCMODE_T_DECLARED +#endif + +#ifndef _NLINK_T_DECLARED +typedef __nlink_t nlink_t; /* link count */ +#define _NLINK_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; /* file offset */ +#define _OFF_T_DECLARED +#endif + +#ifndef _OFF64_T_DECLARED +typedef __off64_t off64_t; /* file offset (alias) */ +#define _OFF64_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; /* process id */ +#define _PID_T_DECLARED +#endif + +typedef __register_t register_t; + +#ifndef _RLIM_T_DECLARED +typedef __rlim_t rlim_t; /* resource limit */ +#define _RLIM_T_DECLARED +#endif + +typedef __int64_t sbintime_t; + +typedef __segsz_t segsz_t; /* segment size (in pages) */ + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; /* microseconds (signed) */ +#define _SUSECONDS_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _TIMER_T_DECLARED +typedef __timer_t timer_t; +#define _TIMER_T_DECLARED +#endif + +#ifndef _MQD_T_DECLARED +typedef __mqd_t mqd_t; +#define _MQD_T_DECLARED +#endif + +typedef __u_register_t u_register_t; + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; /* user id */ +#define _UID_T_DECLARED +#endif + +#ifndef _USECONDS_T_DECLARED +typedef __useconds_t useconds_t; /* microseconds (unsigned) */ +#define _USECONDS_T_DECLARED +#endif + +#ifndef _CAP_IOCTL_T_DECLARED +#define _CAP_IOCTL_T_DECLARED +typedef unsigned long cap_ioctl_t; +#endif + +#ifndef _CAP_RIGHTS_T_DECLARED +#define _CAP_RIGHTS_T_DECLARED +struct cap_rights; + +typedef struct cap_rights cap_rights_t; +#endif + +/* + * Types suitable for exporting size and pointers (as virtual addresses) + * from the kernel independent of native word size. These should be + * used in place of size_t and (u)intptr_t in structs which contain such + * types that are shared with userspace. + */ +typedef __uint64_t kvaddr_t; +typedef __uint64_t ksize_t; + +typedef __vm_offset_t vm_offset_t; +typedef __uint64_t vm_ooffset_t; +typedef __vm_paddr_t vm_paddr_t; +typedef __uint64_t vm_pindex_t; +typedef __vm_size_t vm_size_t; + +typedef __rman_res_t rman_res_t; + +#ifdef _KERNEL +typedef int boolean_t; +typedef struct device *device_t; +typedef __intfptr_t intfptr_t; + +/* + * XXX this is fixed width for historical reasons. It should have had type + * __int_fast32_t. Fixed-width types should not be used unless binary + * compatibility is essential. Least-width types should be used even less + * since they provide smaller benefits. + * + * XXX should be MD. + * + * XXX this is bogus in -current, but still used for spl*(). + */ +typedef __uint32_t intrmask_t; /* Interrupt mask (spl, xxx_imask...) */ + +typedef __uintfptr_t uintfptr_t; +typedef __uint64_t uoff_t; +typedef char vm_memattr_t; /* memory attribute codes */ +typedef struct vm_page *vm_page_t; + +#if !defined(__bool_true_false_are_defined) && !defined(__cplusplus) +#define __bool_true_false_are_defined 1 +#define false 0 +#define true 1 +#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 && !defined(__INTEL_COMPILER) +typedef int _Bool; +#endif +typedef _Bool bool; +#endif /* !__bool_true_false_are_defined && !__cplusplus */ + +#define offsetof(type, field) __offsetof(type, field) + +#endif /* _KERNEL */ + +/* + * The following are all things that really shouldn't exist in this header, + * since its purpose is to provide typedefs, not miscellaneous doodads. + */ + +#ifdef __POPCNT__ +#define __bitcount64(x) __builtin_popcountll((__uint64_t)(x)) +#define __bitcount32(x) __builtin_popcount((__uint32_t)(x)) +#define __bitcount16(x) __builtin_popcount((__uint16_t)(x)) +#define __bitcountl(x) __builtin_popcountl((unsigned long)(x)) +#define __bitcount(x) __builtin_popcount((unsigned int)(x)) +#else +/* + * Population count algorithm using SWAR approach + * - "SIMD Within A Register". + */ +static __inline __uint16_t +__bitcount16(__uint16_t _x) +{ + + _x = (_x & 0x5555) + ((_x & 0xaaaa) >> 1); + _x = (_x & 0x3333) + ((_x & 0xcccc) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f; + _x = (_x + (_x >> 8)) & 0x00ff; + return (_x); +} + +static __inline __uint32_t +__bitcount32(__uint32_t _x) +{ + + _x = (_x & 0x55555555) + ((_x & 0xaaaaaaaa) >> 1); + _x = (_x & 0x33333333) + ((_x & 0xcccccccc) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f0f0f; + _x = (_x + (_x >> 8)); + _x = (_x + (_x >> 16)) & 0x000000ff; + return (_x); +} + +#ifdef __LP64__ +static __inline __uint64_t +__bitcount64(__uint64_t _x) +{ + + _x = (_x & 0x5555555555555555) + ((_x & 0xaaaaaaaaaaaaaaaa) >> 1); + _x = (_x & 0x3333333333333333) + ((_x & 0xcccccccccccccccc) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0f; + _x = (_x + (_x >> 8)); + _x = (_x + (_x >> 16)); + _x = (_x + (_x >> 32)) & 0x000000ff; + return (_x); +} + +#define __bitcountl(x) __bitcount64((unsigned long)(x)) +#else +static __inline __uint64_t +__bitcount64(__uint64_t _x) +{ + + return (__bitcount32(_x >> 32) + __bitcount32(_x)); +} + +#define __bitcountl(x) __bitcount32((unsigned long)(x)) +#endif +#define __bitcount(x) __bitcount32((unsigned int)(x)) +#endif + +#if __BSD_VISIBLE + +#include + +/* + * The major and minor numbers are encoded in dev_t as MMMmmmMm (where + * letters correspond to bytes). The encoding of the lower 4 bytes is + * constrained by compatibility with 16-bit and 32-bit dev_t's. The + * encoding of of the upper 4 bytes is the least unnatural one consistent + * with this and other constraints. Also, the decoding of the m bytes by + * minor() is unnatural to maximize compatibility subject to not discarding + * bits. The upper m byte is shifted into the position of the lower M byte + * instead of shifting 3 upper m bytes to close the gap. Compatibility for + * minor() is achieved iff the upper m byte is 0. + */ +#define major(d) __major(d) +static __inline int +__major(dev_t _d) +{ + return (((_d >> 32) & 0xffffff00) | ((_d >> 8) & 0xff)); +} +#define minor(d) __minor(d) +static __inline int +__minor(dev_t _d) +{ + return (((_d >> 24) & 0xff00) | (_d & 0xffff00ff)); +} +#define makedev(M, m) __makedev((M), (m)) +static __inline dev_t +__makedev(int _M, int _m) +{ + return (((dev_t)(_M & 0xffffff00) << 32) | ((_M & 0xff) << 8) | + ((dev_t)(_m & 0xff00) << 24) | (_m & 0xffff00ff)); +} + +/* + * These declarations belong elsewhere, but are repeated here and in + * to give broken programs a better chance of working with + * 64-bit off_t's. + */ +#ifndef _KERNEL +__BEGIN_DECLS +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, off_t); +#endif +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +off_t lseek(int, off_t, int); +#endif +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void * mmap(void *, size_t, int, int, int, off_t); +#endif +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, off_t); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS_TYPES_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ucontext.h b/lib/libc/include/any-freebsd-any/sys/ucontext.h new file mode 100644 index 000000000000..1a1f7b7ccbdb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ucontext.h @@ -0,0 +1,92 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_UCONTEXT_H_ +#define _SYS_UCONTEXT_H_ + +#include +#include +#include + +#define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ + +#if defined(_KERNEL) && defined(COMPAT_FREEBSD4) +#if defined(__i386__) +struct ucontext4 { + sigset_t uc_sigmask; + struct mcontext4 uc_mcontext; + struct ucontext4 *uc_link; + stack_t uc_stack; + int __spare__[8]; +}; +#else /* __i386__ */ +#define ucontext4 ucontext +#endif /* __i386__ */ +#endif /* _KERNEL */ + +#ifndef _KERNEL + +__BEGIN_DECLS + +int getcontext(ucontext_t *) __returns_twice; +ucontext_t *getcontextx(void); +int setcontext(const ucontext_t *); +void makecontext(ucontext_t *, void (*)(void), int, ...); +int signalcontext(ucontext_t *, int, __sighandler_t *); +int swapcontext(ucontext_t *, const ucontext_t *); + +#if __BSD_VISIBLE +int __getcontextx_size(void); +int __fillcontextx(char *ctx) __returns_twice; +int __fillcontextx2(char *ctx); +#endif + +__END_DECLS + +#else /* _KERNEL */ + +struct thread; + +/* + * Flags for get_mcontext(). The low order 4 bits (i.e a mask of 0x0f) are + * reserved for use by machine independent code. All other bits are for use + * by machine dependent code. + */ +#define GET_MC_CLEAR_RET 1 + +/* Machine-dependent functions: */ +int get_mcontext(struct thread *, mcontext_t *, int); +int set_mcontext(struct thread *, mcontext_t *); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_UCONTEXT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/ucred.h b/lib/libc/include/any-freebsd-any/sys/ucred.h new file mode 100644 index 000000000000..e2e0c998bff8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/ucred.h @@ -0,0 +1,121 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ucred.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#ifndef _SYS_UCRED_H_ +#define _SYS_UCRED_H_ + +#include + +struct loginclass; + +#define XU_NGROUPS 16 + +/* + * Credentials. + * + * Please do not inspect cr_uid directly to determine superuserness. The + * priv(9) interface should be used to check for privilege. + */ +#if defined(_KERNEL) || defined(_WANT_UCRED) +struct ucred { + u_int cr_ref; /* reference count */ +#define cr_startcopy cr_uid + uid_t cr_uid; /* effective user id */ + uid_t cr_ruid; /* real user id */ + uid_t cr_svuid; /* saved user id */ + int cr_ngroups; /* number of groups */ + gid_t cr_rgid; /* real group id */ + gid_t cr_svgid; /* saved group id */ + struct uidinfo *cr_uidinfo; /* per euid resource consumption */ + struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */ + struct prison *cr_prison; /* jail(2) */ + struct loginclass *cr_loginclass; /* login class */ + u_int cr_flags; /* credential flags */ + void *cr_pspare2[2]; /* general use 2 */ +#define cr_endcopy cr_label + struct label *cr_label; /* MAC label */ + struct auditinfo_addr cr_audit; /* Audit properties. */ + gid_t *cr_groups; /* groups */ + int cr_agroups; /* Available groups */ + gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */ +}; +#define NOCRED ((struct ucred *)0) /* no credential available */ +#define FSCRED ((struct ucred *)-1) /* filesystem credential */ +#endif /* _KERNEL || _WANT_UCRED */ + +/* + * Flags for cr_flags. + */ +#define CRED_FLAG_CAPMODE 0x00000001 /* In capability mode. */ + +/* + * This is the external representation of struct ucred. + */ +struct xucred { + u_int cr_version; /* structure layout version */ + uid_t cr_uid; /* effective user id */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[XU_NGROUPS]; /* groups */ + void *_cr_unused1; /* compatibility with old ucred */ +}; +#define XUCRED_VERSION 0 + +/* This can be used for both ucred and xucred structures. */ +#define cr_gid cr_groups[0] + +#ifdef _KERNEL +struct proc; +struct thread; + +void change_egid(struct ucred *newcred, gid_t egid); +void change_euid(struct ucred *newcred, struct uidinfo *euip); +void change_rgid(struct ucred *newcred, gid_t rgid); +void change_ruid(struct ucred *newcred, struct uidinfo *ruip); +void change_svgid(struct ucred *newcred, gid_t svgid); +void change_svuid(struct ucred *newcred, uid_t svuid); +void crcopy(struct ucred *dest, struct ucred *src); +struct ucred *crcopysafe(struct proc *p, struct ucred *cr); +struct ucred *crdup(struct ucred *cr); +void crextend(struct ucred *cr, int n); +void proc_set_cred_init(struct proc *p, struct ucred *cr); +struct ucred *proc_set_cred(struct proc *p, struct ucred *cr); +void crfree(struct ucred *cr); +struct ucred *crget(void); +struct ucred *crhold(struct ucred *cr); +void cru2x(struct ucred *cr, struct xucred *xcr); +void crsetgroups(struct ucred *cr, int n, gid_t *groups); +int groupmember(gid_t gid, struct ucred *cred); +#endif /* _KERNEL */ + +#endif /* !_SYS_UCRED_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/uio.h b/lib/libc/include/any-freebsd-any/sys/uio.h new file mode 100644 index 000000000000..33398dba99e6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/uio.h @@ -0,0 +1,118 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + * $FreeBSD$ + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include +#include +#include + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifdef _KERNEL + +struct uio { + struct iovec *uio_iov; /* scatter/gather list */ + int uio_iovcnt; /* length of scatter/gather list */ + off_t uio_offset; /* offset in target object */ + ssize_t uio_resid; /* remaining bytes to process */ + enum uio_seg uio_segflg; /* address space */ + enum uio_rw uio_rw; /* operation */ + struct thread *uio_td; /* owner */ +}; + +/* + * Limits + * + * N.B.: UIO_MAXIOV must be no less than IOV_MAX from + * which in turn must be no less than _XOPEN_IOV_MAX from . If + * we ever make this tunable (probably pointless), then IOV_MAX should be + * removed from and applications would be expected to use + * sysconf(3) to find out the correct value, or else assume the worst + * (_XOPEN_IOV_MAX). Perhaps UIO_MAXIOV should be simply defined as + * IOV_MAX. + */ +#define UIO_MAXIOV 1024 /* max 1K of iov's */ + +struct vm_object; +struct vm_page; +struct bus_dma_segment; + +struct uio *cloneuio(struct uio *uiop); +int copyinfrom(const void * __restrict src, void * __restrict dst, + size_t len, int seg); +int copyiniov(const struct iovec *iovp, u_int iovcnt, struct iovec **iov, + int error); +int copyinstrfrom(const void * __restrict src, void * __restrict dst, + size_t len, size_t * __restrict copied, int seg); +int copyinuio(const struct iovec *iovp, u_int iovcnt, struct uio **uiop); +int copyout_map(struct thread *td, vm_offset_t *addr, size_t sz); +int copyout_unmap(struct thread *td, vm_offset_t addr, size_t sz); +int physcopyin(void *src, vm_paddr_t dst, size_t len); +int physcopyout(vm_paddr_t src, void *dst, size_t len); +int physcopyin_vlist(struct bus_dma_segment *src, off_t offset, + vm_paddr_t dst, size_t len); +int physcopyout_vlist(vm_paddr_t src, struct bus_dma_segment *dst, + off_t offset, size_t len); +int uiomove(void *cp, int n, struct uio *uio); +int uiomove_frombuf(void *buf, int buflen, struct uio *uio); +int uiomove_fromphys(struct vm_page *ma[], vm_offset_t offset, int n, + struct uio *uio); +int uiomove_nofault(void *cp, int n, struct uio *uio); +int uiomove_object(struct vm_object *obj, off_t obj_size, struct uio *uio); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); +#if __BSD_VISIBLE +ssize_t preadv(int, const struct iovec *, int, off_t); +ssize_t pwritev(int, const struct iovec *, int, off_t); +#endif +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_UIO_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/umtx.h b/lib/libc/include/any-freebsd-any/sys/umtx.h new file mode 100644 index 000000000000..a99b1b83c4bb --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/umtx.h @@ -0,0 +1,202 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002, Jeffrey Roberson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _SYS_UMTX_H_ +#define _SYS_UMTX_H_ + +#include + +/* Common lock flags */ +#define USYNC_PROCESS_SHARED 0x0001 /* Process shared sync objs */ + +/* umutex flags */ +#define UMUTEX_PRIO_INHERIT 0x0004 /* Priority inherited mutex */ +#define UMUTEX_PRIO_PROTECT 0x0008 /* Priority protect mutex */ +#define UMUTEX_ROBUST 0x0010 /* Robust mutex */ +#define UMUTEX_NONCONSISTENT 0x0020 /* Robust locked but not consistent */ + +/* + * The umutex.m_lock values and bits. The m_owner is the word which + * serves as the lock. Its high bit is the contention indicator and + * rest of bits records the owner TID. TIDs values start with PID_MAX + * + 2 and end by INT32_MAX. The low range [1..PID_MAX] is guaranteed + * to be useable as the special markers. + */ +#define UMUTEX_UNOWNED 0x0 +#define UMUTEX_CONTESTED 0x80000000U +#define UMUTEX_RB_OWNERDEAD (UMUTEX_CONTESTED | 0x10) +#define UMUTEX_RB_NOTRECOV (UMUTEX_CONTESTED | 0x11) + +/* urwlock flags */ +#define URWLOCK_PREFER_READER 0x0002 + +#define URWLOCK_WRITE_OWNER 0x80000000U +#define URWLOCK_WRITE_WAITERS 0x40000000U +#define URWLOCK_READ_WAITERS 0x20000000U +#define URWLOCK_MAX_READERS 0x1fffffffU +#define URWLOCK_READER_COUNT(c) ((c) & URWLOCK_MAX_READERS) + +/* _usem flags */ +#define SEM_NAMED 0x0002 + +/* _usem2 count field */ +#define USEM_HAS_WAITERS 0x80000000U +#define USEM_MAX_COUNT 0x7fffffffU +#define USEM_COUNT(c) ((c) & USEM_MAX_COUNT) + +/* op code for _umtx_op */ +#define UMTX_OP_RESERVED0 0 +#define UMTX_OP_RESERVED1 1 +#define UMTX_OP_WAIT 2 +#define UMTX_OP_WAKE 3 +#define UMTX_OP_MUTEX_TRYLOCK 4 +#define UMTX_OP_MUTEX_LOCK 5 +#define UMTX_OP_MUTEX_UNLOCK 6 +#define UMTX_OP_SET_CEILING 7 +#define UMTX_OP_CV_WAIT 8 +#define UMTX_OP_CV_SIGNAL 9 +#define UMTX_OP_CV_BROADCAST 10 +#define UMTX_OP_WAIT_UINT 11 +#define UMTX_OP_RW_RDLOCK 12 +#define UMTX_OP_RW_WRLOCK 13 +#define UMTX_OP_RW_UNLOCK 14 +#define UMTX_OP_WAIT_UINT_PRIVATE 15 +#define UMTX_OP_WAKE_PRIVATE 16 +#define UMTX_OP_MUTEX_WAIT 17 +#define UMTX_OP_MUTEX_WAKE 18 /* deprecated */ +#define UMTX_OP_SEM_WAIT 19 /* deprecated */ +#define UMTX_OP_SEM_WAKE 20 /* deprecated */ +#define UMTX_OP_NWAKE_PRIVATE 21 +#define UMTX_OP_MUTEX_WAKE2 22 +#define UMTX_OP_SEM2_WAIT 23 +#define UMTX_OP_SEM2_WAKE 24 +#define UMTX_OP_SHM 25 +#define UMTX_OP_ROBUST_LISTS 26 + +/* Flags for UMTX_OP_CV_WAIT */ +#define CVWAIT_CHECK_UNPARKING 0x01 +#define CVWAIT_ABSTIME 0x02 +#define CVWAIT_CLOCKID 0x04 + +#define UMTX_ABSTIME 0x01 + +#define UMTX_CHECK_UNPARKING CVWAIT_CHECK_UNPARKING + +/* Flags for UMTX_OP_SHM */ +#define UMTX_SHM_CREAT 0x0001 +#define UMTX_SHM_LOOKUP 0x0002 +#define UMTX_SHM_DESTROY 0x0004 +#define UMTX_SHM_ALIVE 0x0008 + +struct umtx_robust_lists_params { + uintptr_t robust_list_offset; + uintptr_t robust_priv_list_offset; + uintptr_t robust_inact_offset; +}; + +#ifndef _KERNEL + +__BEGIN_DECLS + +int _umtx_op(void *obj, int op, u_long val, void *uaddr, void *uaddr2); + +__END_DECLS + +#else + +/* + * The umtx_key structure is used by both the Linux futex code and the + * umtx implementation to map userland addresses to unique keys. + */ + +enum { + TYPE_SIMPLE_WAIT, + TYPE_CV, + TYPE_SEM, + TYPE_SIMPLE_LOCK, + TYPE_NORMAL_UMUTEX, + TYPE_PI_UMUTEX, + TYPE_PP_UMUTEX, + TYPE_RWLOCK, + TYPE_FUTEX, + TYPE_SHM, + TYPE_PI_ROBUST_UMUTEX, + TYPE_PP_ROBUST_UMUTEX, +}; + +/* Key to represent a unique userland synchronous object */ +struct umtx_key { + int hash; + int type; + int shared; + union { + struct { + struct vm_object *object; + uintptr_t offset; + } shared; + struct { + struct vmspace *vs; + uintptr_t addr; + } private; + struct { + void *a; + uintptr_t b; + } both; + } info; +}; + +#define THREAD_SHARE 0 +#define PROCESS_SHARE 1 +#define AUTO_SHARE 2 + +struct thread; + +static inline int +umtx_key_match(const struct umtx_key *k1, const struct umtx_key *k2) +{ + return (k1->type == k2->type && + k1->info.both.a == k2->info.both.a && + k1->info.both.b == k2->info.both.b); +} + +int umtx_copyin_timeout(const void *, struct timespec *); +int umtx_key_get(const void *, int, int, struct umtx_key *); +void umtx_key_release(struct umtx_key *); +struct umtx_q *umtxq_alloc(void); +void umtxq_free(struct umtx_q *); +int kern_umtx_wake(struct thread *, void *, int, int); +void umtx_pi_adjust(struct thread *, u_char); +void umtx_thread_init(struct thread *); +void umtx_thread_fini(struct thread *); +void umtx_thread_alloc(struct thread *); +void umtx_thread_exit(struct thread *); +#endif /* !_KERNEL */ +#endif /* !_SYS_UMTX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/un.h b/lib/libc/include/any-freebsd-any/sys/un.h new file mode 100644 index 000000000000..d9605ae1893e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/un.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)un.h 8.3 (Berkeley) 2/19/95 + * $FreeBSD$ + */ + +#ifndef _SYS_UN_H_ +#define _SYS_UN_H_ + +#include +#include + +#ifndef _SA_FAMILY_T_DECLARED +typedef __sa_family_t sa_family_t; +#define _SA_FAMILY_T_DECLARED +#endif + +/* + * Definitions for UNIX IPC domain. + */ +struct sockaddr_un { + unsigned char sun_len; /* sockaddr len including null */ + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[104]; /* path name (gag) */ +}; + +#if __BSD_VISIBLE + +#define SOL_LOCAL 0 /* Options for local socket */ + +/* Socket options. */ +#define LOCAL_PEERCRED 1 /* retrieve peer credentials */ +#define LOCAL_CREDS 2 /* pass credentials to receiver */ +#define LOCAL_CONNWAIT 4 /* connects block until accepted */ + +/* Start of reserved space for third-party socket options. */ +#define LOCAL_VENDOR SO_VENDOR + +#ifndef _KERNEL + +/* actual length of an initialized sockaddr_un */ +#define SUN_LEN(su) \ + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) + +#endif /* !_KERNEL */ + +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS_UN_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/unistd.h b/lib/libc/include/any-freebsd-any/sys/unistd.h new file mode 100644 index 000000000000..3b3de3aa33bc --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/unistd.h @@ -0,0 +1,202 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unistd.h 8.2 (Berkeley) 1/7/94 + * $FreeBSD$ + */ + +#ifndef _SYS_UNISTD_H_ +#define _SYS_UNISTD_H_ + +#include + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. Those options which are implemented (or not) entirely + * in user mode are defined in . Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_ADVISORY_INFO 200112L +#define _POSIX_ASYNCHRONOUS_IO 200112L +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCK_SELECTION (-1) +#define _POSIX_CPUTIME 200112L +#define _POSIX_FSYNC 200112L +#define _POSIX_IPV6 0 +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES 200112L +#define _POSIX_MEMLOCK (-1) +#define _POSIX_MEMLOCK_RANGE 200112L +#define _POSIX_MEMORY_PROTECTION 200112L +#define _POSIX_MESSAGE_PASSING 200112L +#define _POSIX_MONOTONIC_CLOCK 200112L +#define _POSIX_NO_TRUNC 1 +#define _POSIX_PRIORITIZED_IO (-1) +#define _POSIX_PRIORITY_SCHEDULING 0 +#define _POSIX_RAW_SOCKETS 200112L +#define _POSIX_REALTIME_SIGNALS 200112L +#define _POSIX_SEMAPHORES 200112L +#define _POSIX_SHARED_MEMORY_OBJECTS 200112L +#define _POSIX_SPORADIC_SERVER (-1) +#define _POSIX_SYNCHRONIZED_IO (-1) +#define _POSIX_TIMEOUTS 200112L +#define _POSIX_TIMERS 200112L +#define _POSIX_TYPED_MEMORY_OBJECTS (-1) +#define _POSIX_VDISABLE 0xff + +#if __XSI_VISIBLE +#define _XOPEN_SHM 1 +#define _XOPEN_STREAMS (-1) +#endif + +/* + * Although we have saved user/group IDs, we do not use them in setuid + * as described in POSIX 1003.1, because the feature does not work for + * root. We use the saved IDs in seteuid/setegid, which are not currently + * part of the POSIX 1003.1 specification. XXX revisit for 1003.1-2001 + * as this is now mandatory. + */ +#ifdef _NOT_AVAILABLE +#define _POSIX_SAVED_IDS 1 /* saved set-user-ID and set-group-ID */ +#endif + +/* Define the POSIX.1 version we target for compliance. */ +#define _POSIX_VERSION 200112L + +/* access function */ +#define F_OK 0 /* test for existence of file */ +#define X_OK 0x01 /* test for execute or search permission */ +#define W_OK 0x02 /* test for write permission */ +#define R_OK 0x04 /* test for read permission */ + +/* whence values for lseek(2) */ +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif +#if __BSD_VISIBLE +#define SEEK_DATA 3 /* set file offset to next data past offset */ +#define SEEK_HOLE 4 /* set file offset to next hole past offset */ +#endif + +#ifndef _POSIX_SOURCE +/* whence values for lseek(2); renamed by POSIX 1003.1 */ +#define L_SET SEEK_SET +#define L_INCR SEEK_CUR +#define L_XTND SEEK_END +#endif + +/* configurable pathname variables */ +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_CHOWN_RESTRICTED 7 +#define _PC_NO_TRUNC 8 +#define _PC_VDISABLE 9 + +#if __POSIX_VISIBLE >= 199309 +#define _PC_ASYNC_IO 53 +#define _PC_PRIO_IO 54 +#define _PC_SYNC_IO 55 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _PC_ALLOC_SIZE_MIN 10 +#define _PC_FILESIZEBITS 12 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_SYMLINK_MAX 18 +#endif + +#if __BSD_VISIBLE +#define _PC_ACL_EXTENDED 59 +#define _PC_ACL_PATH_MAX 60 +#define _PC_CAP_PRESENT 61 +#define _PC_INF_PRESENT 62 +#define _PC_MAC_PRESENT 63 +#define _PC_ACL_NFS4 64 +#endif + +/* From OpenSolaris, used by SEEK_DATA/SEEK_HOLE. */ +#define _PC_MIN_HOLE_SIZE 21 + +#if __BSD_VISIBLE +/* + * rfork() options. + * + * XXX currently, some operations without RFPROC set are not supported. + */ +#define RFNAMEG (1<<0) /* UNIMPL new plan9 `name space' */ +#define RFENVG (1<<1) /* UNIMPL copy plan9 `env space' */ +#define RFFDG (1<<2) /* copy fd table */ +#define RFNOTEG (1<<3) /* UNIMPL create new plan9 `note group' */ +#define RFPROC (1<<4) /* change child (else changes curproc) */ +#define RFMEM (1<<5) /* share `address space' */ +#define RFNOWAIT (1<<6) /* give child to init */ +#define RFCNAMEG (1<<10) /* UNIMPL zero plan9 `name space' */ +#define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ +#define RFCFDG (1<<12) /* close all fds, zero fd table */ +#define RFTHREAD (1<<13) /* enable kernel thread support */ +#define RFSIGSHARE (1<<14) /* share signal handlers */ +#define RFLINUXTHPN (1<<16) /* do linux clone exit parent notification */ +#define RFSTOPPED (1<<17) /* leave child in a stopped state */ +#define RFHIGHPID (1<<18) /* use a pid higher than 10 (idleproc) */ +#define RFTSIGZMB (1<<19) /* select signal for exit parent notification */ +#define RFTSIGSHIFT 20 /* selected signal number is in bits 20-27 */ +#define RFTSIGMASK 0xFF +#define RFTSIGNUM(flags) (((flags) >> RFTSIGSHIFT) & RFTSIGMASK) +#define RFTSIGFLAGS(signum) ((signum) << RFTSIGSHIFT) +#define RFPROCDESC (1<<28) /* return a process descriptor */ +/* kernel: parent sleeps until child exits (vfork) */ +#define RFPPWAIT (1<<31) +/* user: vfork(2) semantics, clear signals */ +#define RFSPAWN (1U<<31) +#define RFFLAGS (RFFDG | RFPROC | RFMEM | RFNOWAIT | RFCFDG | \ + RFTHREAD | RFSIGSHARE | RFLINUXTHPN | RFSTOPPED | RFHIGHPID | RFTSIGZMB | \ + RFPROCDESC | RFSPAWN | RFPPWAIT) +#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC) + +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS_UNISTD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/unpcb.h b/lib/libc/include/any-freebsd-any/sys/unpcb.h new file mode 100644 index 000000000000..f1e5f5f26625 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/unpcb.h @@ -0,0 +1,177 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unpcb.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _SYS_UNPCB_H_ +#define _SYS_UNPCB_H_ + +typedef uint64_t unp_gen_t; + +#if defined(_KERNEL) || defined(_WANT_UNPCB) +#include +#include + +/* + * Protocol control block for an active + * instance of a UNIX internal protocol. + * + * A socket may be associated with a vnode in the + * filesystem. If so, the unp_vnode pointer holds + * a reference count to this vnode, which should be irele'd + * when the socket goes away. + * + * A socket may be connected to another socket, in which + * case the control block of the socket to which it is connected + * is given by unp_conn. + * + * A socket may be referenced by a number of sockets (e.g. several + * sockets may be connected to a datagram socket.) These sockets + * are in a linked list starting with unp_refs, linked through + * unp_nextref and null-terminated. Note that a socket may be referenced + * by a number of other sockets and may also reference a socket (not + * necessarily one which is referencing it). This generates + * the need for unp_refs and unp_nextref to be separate fields. + * + * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt + * so that changes in the sockbuf may be computed to modify + * back pressure on the sender accordingly. + */ +LIST_HEAD(unp_head, unpcb); + +struct unpcb { + /* Cache line 1 */ + struct mtx unp_mtx; /* mutex */ + struct unpcb *unp_conn; /* control block of connected socket */ + volatile u_int unp_refcount; + short unp_flags; /* flags */ + short unp_gcflag; /* Garbage collector flags. */ + struct sockaddr_un *unp_addr; /* bound address of socket */ + struct socket *unp_socket; /* pointer back to socket */ + /* Cache line 2 */ + struct vnode *unp_vnode; /* if associated with file */ + struct xucred unp_peercred; /* peer credentials, if applicable */ + LIST_ENTRY(unpcb) unp_reflink; /* link in unp_refs list */ + LIST_ENTRY(unpcb) unp_link; /* glue on list of all PCBs */ + struct unp_head unp_refs; /* referencing socket linked list */ + unp_gen_t unp_gencnt; /* generation count of this instance */ + struct file *unp_file; /* back-pointer to file for gc. */ + u_int unp_msgcount; /* references from message queue */ + ino_t unp_ino; /* fake inode number */ +} __aligned(CACHE_LINE_SIZE); + +/* + * Flags in unp_flags. + * + * UNP_HAVEPC - indicates that the unp_peercred member is filled in + * and is really the credentials of the connected peer. This is used + * to determine whether the contents should be sent to the user or + * not. + */ +#define UNP_HAVEPC 0x001 +#define UNP_WANTCRED 0x004 /* credentials wanted */ +#define UNP_CONNWAIT 0x008 /* connect blocks until accepted */ + +/* + * These flags are used to handle non-atomicity in connect() and bind() + * operations on a socket: in particular, to avoid races between multiple + * threads or processes operating simultaneously on the same socket. + */ +#define UNP_CONNECTING 0x010 /* Currently connecting. */ +#define UNP_BINDING 0x020 /* Currently binding. */ + +/* + * Flags in unp_gcflag. + */ +#define UNPGC_REF 0x1 /* unpcb has external ref. */ +#define UNPGC_DEAD 0x2 /* unpcb might be dead. */ +#define UNPGC_SCANNED 0x4 /* Has been scanned. */ +#define UNPGC_IGNORE_RIGHTS 0x8 /* Attached rights are freed */ + +#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb)) + +#endif /* _KERNEL || _WANT_UNPCB */ + +/* + * UNPCB structure exported to user-land via sysctl(3). + * + * Fields prefixed with "xu_" are unique to the export structure, and fields + * with "unp_" or other prefixes match corresponding fields of 'struct unpcb'. + * + * Legend: + * (s) - used by userland utilities in src + * (p) - used by utilities in ports + * (3) - is known to be used by third party software not in ports + * (n) - no known usage + * + * Evil hack: declare only if sys/socketvar.h have been included. + */ +#ifdef _SYS_SOCKETVAR_H_ +struct xunpcb { + ksize_t xu_len; /* length of this structure */ + kvaddr_t xu_unpp; /* to help netstat, fstat */ + kvaddr_t unp_vnode; /* (s) */ + kvaddr_t unp_conn; /* (s) */ + kvaddr_t xu_firstref; /* (s) */ + kvaddr_t xu_nextref; /* (s) */ + unp_gen_t unp_gencnt; /* (s) */ + int64_t xu_spare64[8]; + int32_t xu_spare32[8]; + union { + struct sockaddr_un xu_addr; /* our bound address */ + char xu_dummy1[256]; + }; + union { + struct sockaddr_un xu_caddr; /* their bound address */ + char xu_dummy2[256]; + }; + struct xsocket xu_socket; +} __aligned(MAX(8, sizeof(void *))); + +struct xunpgen { + ksize_t xug_len; + u_int xug_count; + unp_gen_t xug_gen; + so_gen_t xug_sogen; +} __aligned(8);; +#endif /* _SYS_SOCKETVAR_H_ */ + +#if defined(_KERNEL) +struct thread; + +/* In uipc_userreq.c */ +void +unp_copy_peercred(struct thread *td, struct unpcb *client_unp, + struct unpcb *server_unp, struct unpcb *listen_unp); +#endif + +#endif /* _SYS_UNPCB_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/user.h b/lib/libc/include/any-freebsd-any/sys/user.h new file mode 100644 index 000000000000..75661257528b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/user.h @@ -0,0 +1,614 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. + * Copyright (c) 2007 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)user.h 8.2 (Berkeley) 9/23/93 + * $FreeBSD$ + */ + +#ifndef _SYS_USER_H_ +#define _SYS_USER_H_ + +#include +#ifndef _KERNEL +/* stuff that *used* to be included by user.h, or is now needed */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* XXX */ +#include /* XXX */ +#include /* XXX */ +#include /* XXX */ +#endif /* !_KERNEL */ +#ifndef _SYS_RESOURCEVAR_H_ +#include +#endif +#ifndef _SYS_SIGNALVAR_H_ +#include +#endif +#ifndef _SYS_SOCKET_VAR_H_ +#include +#endif +#include + +/* + * KERN_PROC subtype ops return arrays of selected proc structure entries: + * + * This struct includes several arrays of spare space, with different arrays + * for different standard C-types. When adding new variables to this struct, + * the space for byte-aligned data should be taken from the ki_sparestring, + * pointers from ki_spareptrs, word-aligned data from ki_spareints, and + * doubleword-aligned data from ki_sparelongs. Make sure the space for new + * variables come from the array which matches the size and alignment of + * those variables on ALL hardware platforms, and then adjust the appropriate + * KI_NSPARE_* value(s) to match. + * + * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all + * platforms after you have added new variables. Note that if you change + * the value of KINFO_PROC_SIZE, then many userland programs will stop + * working until they are recompiled! + * + * Once you have added the new field, you will need to add code to initialize + * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and + * function kvm_proclist in lib/libkvm/kvm_proc.c . + */ +#define KI_NSPARE_INT 2 +#define KI_NSPARE_LONG 12 +#define KI_NSPARE_PTR 6 + +#ifndef _KERNEL +#ifndef KINFO_PROC_SIZE +#error "Unknown architecture" +#endif +#endif /* !_KERNEL */ + +#define WMESGLEN 8 /* size of returned wchan message */ +#define LOCKNAMELEN 8 /* size of returned lock name */ +#define TDNAMLEN 16 /* size of returned thread name */ +#define COMMLEN 19 /* size of returned ki_comm name */ +#define KI_EMULNAMELEN 16 /* size of returned ki_emul */ +#define KI_NGROUPS 16 /* number of groups in ki_groups */ +#define LOGNAMELEN 17 /* size of returned ki_login */ +#define LOGINCLASSLEN 17 /* size of returned ki_loginclass */ + +#ifndef BURN_BRIDGES +#define OCOMMLEN TDNAMLEN +#define ki_ocomm ki_tdname +#endif + +/* Flags for the process credential. */ +#define KI_CRF_CAPABILITY_MODE 0x00000001 +/* + * Steal a bit from ki_cr_flags to indicate that the cred had more than + * KI_NGROUPS groups. + */ +#define KI_CRF_GRP_OVERFLOW 0x80000000 + +struct kinfo_proc { + int ki_structsize; /* size of this structure */ + int ki_layout; /* reserved: layout identifier */ + struct pargs *ki_args; /* address of command arguments */ + struct proc *ki_paddr; /* address of proc */ + struct user *ki_addr; /* kernel virtual addr of u-area */ + struct vnode *ki_tracep; /* pointer to trace file */ + struct vnode *ki_textvp; /* pointer to executable file */ + struct filedesc *ki_fd; /* pointer to open file info */ + struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */ + void *ki_wchan; /* sleep address */ + pid_t ki_pid; /* Process identifier */ + pid_t ki_ppid; /* parent process id */ + pid_t ki_pgid; /* process group id */ + pid_t ki_tpgid; /* tty process group id */ + pid_t ki_sid; /* Process session ID */ + pid_t ki_tsid; /* Terminal session ID */ + short ki_jobc; /* job control counter */ + short ki_spare_short1; /* unused (just here for alignment) */ + uint32_t ki_tdev_freebsd11; /* controlling tty dev */ + sigset_t ki_siglist; /* Signals arrived but not delivered */ + sigset_t ki_sigmask; /* Current signal mask */ + sigset_t ki_sigignore; /* Signals being ignored */ + sigset_t ki_sigcatch; /* Signals being caught by user */ + uid_t ki_uid; /* effective user id */ + uid_t ki_ruid; /* Real user id */ + uid_t ki_svuid; /* Saved effective user id */ + gid_t ki_rgid; /* Real group id */ + gid_t ki_svgid; /* Saved effective group id */ + short ki_ngroups; /* number of groups */ + short ki_spare_short2; /* unused (just here for alignment) */ + gid_t ki_groups[KI_NGROUPS]; /* groups */ + vm_size_t ki_size; /* virtual size */ + segsz_t ki_rssize; /* current resident set size in pages */ + segsz_t ki_swrss; /* resident set size before last swap */ + segsz_t ki_tsize; /* text size (pages) XXX */ + segsz_t ki_dsize; /* data size (pages) XXX */ + segsz_t ki_ssize; /* stack size (pages) */ + u_short ki_xstat; /* Exit status for wait & stop signal */ + u_short ki_acflag; /* Accounting flags */ + fixpt_t ki_pctcpu; /* %cpu for process during ki_swtime */ + u_int ki_estcpu; /* Time averaged value of ki_cpticks */ + u_int ki_slptime; /* Time since last blocked */ + u_int ki_swtime; /* Time swapped in or out */ + u_int ki_cow; /* number of copy-on-write faults */ + u_int64_t ki_runtime; /* Real time in microsec */ + struct timeval ki_start; /* starting time */ + struct timeval ki_childtime; /* time used by process children */ + long ki_flag; /* P_* flags */ + long ki_kiflag; /* KI_* flags (below) */ + int ki_traceflag; /* Kernel trace points */ + char ki_stat; /* S* process status */ + signed char ki_nice; /* Process "nice" value */ + char ki_lock; /* Process lock (prevent swap) count */ + char ki_rqindex; /* Run queue index */ + u_char ki_oncpu_old; /* Which cpu we are on (legacy) */ + u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */ + char ki_tdname[TDNAMLEN+1]; /* thread name */ + char ki_wmesg[WMESGLEN+1]; /* wchan message */ + char ki_login[LOGNAMELEN+1]; /* setlogin name */ + char ki_lockname[LOCKNAMELEN+1]; /* lock name */ + char ki_comm[COMMLEN+1]; /* command name */ + char ki_emul[KI_EMULNAMELEN+1]; /* emulation name */ + char ki_loginclass[LOGINCLASSLEN+1]; /* login class */ + char ki_moretdname[MAXCOMLEN-TDNAMLEN+1]; /* more thread name */ + /* + * When adding new variables, take space for char-strings from the + * front of ki_sparestrings, and ints from the end of ki_spareints. + * That way the spare room from both arrays will remain contiguous. + */ + char ki_sparestrings[46]; /* spare string space */ + int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */ + uint64_t ki_tdev; /* controlling tty dev */ + int ki_oncpu; /* Which cpu we are on */ + int ki_lastcpu; /* Last cpu we were on */ + int ki_tracer; /* Pid of tracing process */ + int ki_flag2; /* P2_* flags */ + int ki_fibnum; /* Default FIB number */ + u_int ki_cr_flags; /* Credential flags */ + int ki_jid; /* Process jail ID */ + int ki_numthreads; /* XXXKSE number of threads in total */ + lwpid_t ki_tid; /* XXXKSE thread id */ + struct priority ki_pri; /* process priority */ + struct rusage ki_rusage; /* process rusage statistics */ + /* XXX - most fields in ki_rusage_ch are not (yet) filled in */ + struct rusage ki_rusage_ch; /* rusage of children processes */ + struct pcb *ki_pcb; /* kernel virtual addr of pcb */ + void *ki_kstack; /* kernel virtual addr of stack */ + void *ki_udata; /* User convenience pointer */ + struct thread *ki_tdaddr; /* address of thread */ + /* + * When adding new variables, take space for pointers from the + * front of ki_spareptrs, and longs from the end of ki_sparelongs. + * That way the spare room from both arrays will remain contiguous. + */ + void *ki_spareptrs[KI_NSPARE_PTR]; /* spare room for growth */ + long ki_sparelongs[KI_NSPARE_LONG]; /* spare room for growth */ + long ki_sflag; /* PS_* flags */ + long ki_tdflags; /* XXXKSE kthread flag */ +}; +void fill_kinfo_proc(struct proc *, struct kinfo_proc *); +/* XXX - the following two defines are temporary */ +#define ki_childstime ki_rusage_ch.ru_stime +#define ki_childutime ki_rusage_ch.ru_utime + +/* + * Legacy PS_ flag. This moved to p_flag but is maintained for + * compatibility. + */ +#define PS_INMEM 0x00001 /* Loaded into memory. */ + +/* ki_sessflag values */ +#define KI_CTTY 0x00000001 /* controlling tty vnode active */ +#define KI_SLEADER 0x00000002 /* session leader */ +#define KI_LOCKBLOCK 0x00000004 /* proc blocked on lock ki_lockname */ + +/* + * This used to be the per-process structure containing data that + * isn't needed in core when the process is swapped out, but now it + * remains only for the benefit of a.out core dumps. + */ +struct user { + struct pstats u_stats; /* *p_stats */ + struct kinfo_proc u_kproc; /* eproc */ +}; + +/* + * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor + * array of another process. + */ +#define KF_ATTR_VALID 0x0001 + +#define KF_TYPE_NONE 0 +#define KF_TYPE_VNODE 1 +#define KF_TYPE_SOCKET 2 +#define KF_TYPE_PIPE 3 +#define KF_TYPE_FIFO 4 +#define KF_TYPE_KQUEUE 5 +#define KF_TYPE_CRYPTO 6 +#define KF_TYPE_MQUEUE 7 +#define KF_TYPE_SHM 8 +#define KF_TYPE_SEM 9 +#define KF_TYPE_PTS 10 +#define KF_TYPE_PROCDESC 11 +#define KF_TYPE_DEV 12 +#define KF_TYPE_UNKNOWN 255 + +#define KF_VTYPE_VNON 0 +#define KF_VTYPE_VREG 1 +#define KF_VTYPE_VDIR 2 +#define KF_VTYPE_VBLK 3 +#define KF_VTYPE_VCHR 4 +#define KF_VTYPE_VLNK 5 +#define KF_VTYPE_VSOCK 6 +#define KF_VTYPE_VFIFO 7 +#define KF_VTYPE_VBAD 8 +#define KF_VTYPE_UNKNOWN 255 + +#define KF_FD_TYPE_CWD -1 /* Current working directory */ +#define KF_FD_TYPE_ROOT -2 /* Root directory */ +#define KF_FD_TYPE_JAIL -3 /* Jail directory */ +#define KF_FD_TYPE_TRACE -4 /* Ktrace vnode */ +#define KF_FD_TYPE_TEXT -5 /* Text vnode */ +#define KF_FD_TYPE_CTTY -6 /* Controlling terminal */ + +#define KF_FLAG_READ 0x00000001 +#define KF_FLAG_WRITE 0x00000002 +#define KF_FLAG_APPEND 0x00000004 +#define KF_FLAG_ASYNC 0x00000008 +#define KF_FLAG_FSYNC 0x00000010 +#define KF_FLAG_NONBLOCK 0x00000020 +#define KF_FLAG_DIRECT 0x00000040 +#define KF_FLAG_HASLOCK 0x00000080 +#define KF_FLAG_SHLOCK 0x00000100 +#define KF_FLAG_EXLOCK 0x00000200 +#define KF_FLAG_NOFOLLOW 0x00000400 +#define KF_FLAG_CREAT 0x00000800 +#define KF_FLAG_TRUNC 0x00001000 +#define KF_FLAG_EXCL 0x00002000 +#define KF_FLAG_EXEC 0x00004000 + +/* + * Old format. Has variable hidden padding due to alignment. + * This is a compatibility hack for pre-build 7.1 packages. + */ +#if defined(__amd64__) +#define KINFO_OFILE_SIZE 1328 +#endif +#if defined(__i386__) +#define KINFO_OFILE_SIZE 1324 +#endif + +struct kinfo_ofile { + int kf_structsize; /* Size of kinfo_file. */ + int kf_type; /* Descriptor type. */ + int kf_fd; /* Array index. */ + int kf_ref_count; /* Reference count. */ + int kf_flags; /* Flags. */ + /* XXX Hidden alignment padding here on amd64 */ + off_t kf_offset; /* Seek location. */ + int kf_vnode_type; /* Vnode type. */ + int kf_sock_domain; /* Socket domain. */ + int kf_sock_type; /* Socket type. */ + int kf_sock_protocol; /* Socket protocol. */ + char kf_path[PATH_MAX]; /* Path to file, if any. */ + struct sockaddr_storage kf_sa_local; /* Socket address. */ + struct sockaddr_storage kf_sa_peer; /* Peer address. */ +}; + +#if defined(__amd64__) || defined(__i386__) +/* + * This size should never be changed. If you really need to, you must provide + * backward ABI compatibility by allocating a new sysctl MIB that will return + * the new structure. The current structure has to be returned by the current + * sysctl MIB. See how it is done for the kinfo_ofile structure. + */ +#define KINFO_FILE_SIZE 1392 +#endif + +struct kinfo_file { + int kf_structsize; /* Variable size of record. */ + int kf_type; /* Descriptor type. */ + int kf_fd; /* Array index. */ + int kf_ref_count; /* Reference count. */ + int kf_flags; /* Flags. */ + int kf_pad0; /* Round to 64 bit alignment. */ + int64_t kf_offset; /* Seek location. */ + union { + struct { + /* API compatiblity with FreeBSD < 12. */ + int kf_vnode_type; + int kf_sock_domain; + int kf_sock_type; + int kf_sock_protocol; + struct sockaddr_storage kf_sa_local; + struct sockaddr_storage kf_sa_peer; + }; + union { + struct { + /* Sendq size */ + uint32_t kf_sock_sendq; + /* Socket domain. */ + int kf_sock_domain0; + /* Socket type. */ + int kf_sock_type0; + /* Socket protocol. */ + int kf_sock_protocol0; + /* Socket address. */ + struct sockaddr_storage kf_sa_local; + /* Peer address. */ + struct sockaddr_storage kf_sa_peer; + /* Address of so_pcb. */ + uint64_t kf_sock_pcb; + /* Address of inp_ppcb. */ + uint64_t kf_sock_inpcb; + /* Address of unp_conn. */ + uint64_t kf_sock_unpconn; + /* Send buffer state. */ + uint16_t kf_sock_snd_sb_state; + /* Receive buffer state. */ + uint16_t kf_sock_rcv_sb_state; + /* Recvq size. */ + uint32_t kf_sock_recvq; + } kf_sock; + struct { + /* Vnode type. */ + int kf_file_type; + /* Space for future use */ + int kf_spareint[3]; + uint64_t kf_spareint64[30]; + /* Vnode filesystem id. */ + uint64_t kf_file_fsid; + /* File device. */ + uint64_t kf_file_rdev; + /* Global file id. */ + uint64_t kf_file_fileid; + /* File size. */ + uint64_t kf_file_size; + /* Vnode filesystem id, FreeBSD 11 compat. */ + uint32_t kf_file_fsid_freebsd11; + /* File device, FreeBSD 11 compat. */ + uint32_t kf_file_rdev_freebsd11; + /* File mode. */ + uint16_t kf_file_mode; + /* Round to 64 bit alignment. */ + uint16_t kf_file_pad0; + uint32_t kf_file_pad1; + } kf_file; + struct { + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; + uint32_t kf_sem_value; + uint16_t kf_sem_mode; + } kf_sem; + struct { + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; + uint64_t kf_pipe_addr; + uint64_t kf_pipe_peer; + uint32_t kf_pipe_buffer_cnt; + /* Round to 64 bit alignment. */ + uint32_t kf_pipe_pad0[3]; + } kf_pipe; + struct { + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; + uint32_t kf_pts_dev_freebsd11; + uint32_t kf_pts_pad0; + uint64_t kf_pts_dev; + /* Round to 64 bit alignment. */ + uint32_t kf_pts_pad1[4]; + } kf_pts; + struct { + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; + pid_t kf_pid; + } kf_proc; + } kf_un; + }; + uint16_t kf_status; /* Status flags. */ + uint16_t kf_pad1; /* Round to 32 bit alignment. */ + int _kf_ispare0; /* Space for more stuff. */ + cap_rights_t kf_cap_rights; /* Capability rights. */ + uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */ + /* Truncated before copyout in sysctl */ + char kf_path[PATH_MAX]; /* Path to file, if any. */ +}; + +/* + * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of + * another process as a series of entries. + */ +#define KVME_TYPE_NONE 0 +#define KVME_TYPE_DEFAULT 1 +#define KVME_TYPE_VNODE 2 +#define KVME_TYPE_SWAP 3 +#define KVME_TYPE_DEVICE 4 +#define KVME_TYPE_PHYS 5 +#define KVME_TYPE_DEAD 6 +#define KVME_TYPE_SG 7 +#define KVME_TYPE_MGTDEVICE 8 +#define KVME_TYPE_UNKNOWN 255 + +#define KVME_PROT_READ 0x00000001 +#define KVME_PROT_WRITE 0x00000002 +#define KVME_PROT_EXEC 0x00000004 + +#define KVME_FLAG_COW 0x00000001 +#define KVME_FLAG_NEEDS_COPY 0x00000002 +#define KVME_FLAG_NOCOREDUMP 0x00000004 +#define KVME_FLAG_SUPER 0x00000008 +#define KVME_FLAG_GROWS_UP 0x00000010 +#define KVME_FLAG_GROWS_DOWN 0x00000020 +#define KVME_FLAG_USER_WIRED 0x00000040 + +#if defined(__amd64__) +#define KINFO_OVMENTRY_SIZE 1168 +#endif +#if defined(__i386__) +#define KINFO_OVMENTRY_SIZE 1128 +#endif + +struct kinfo_ovmentry { + int kve_structsize; /* Size of kinfo_vmmapentry. */ + int kve_type; /* Type of map entry. */ + void *kve_start; /* Starting address. */ + void *kve_end; /* Finishing address. */ + int kve_flags; /* Flags on map entry. */ + int kve_resident; /* Number of resident pages. */ + int kve_private_resident; /* Number of private pages. */ + int kve_protection; /* Protection bitmask. */ + int kve_ref_count; /* VM obj ref count. */ + int kve_shadow_count; /* VM obj shadow count. */ + char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ + void *_kve_pspare[8]; /* Space for more stuff. */ + off_t kve_offset; /* Mapping offset in object */ + uint64_t kve_fileid; /* inode number if vnode */ + uint32_t kve_fsid; /* dev_t of vnode location */ + int _kve_ispare[3]; /* Space for more stuff. */ +}; + +#if defined(__amd64__) || defined(__i386__) +#define KINFO_VMENTRY_SIZE 1160 +#endif + +struct kinfo_vmentry { + int kve_structsize; /* Variable size of record. */ + int kve_type; /* Type of map entry. */ + uint64_t kve_start; /* Starting address. */ + uint64_t kve_end; /* Finishing address. */ + uint64_t kve_offset; /* Mapping offset in object */ + uint64_t kve_vn_fileid; /* inode number if vnode */ + uint32_t kve_vn_fsid_freebsd11; /* dev_t of vnode location */ + int kve_flags; /* Flags on map entry. */ + int kve_resident; /* Number of resident pages. */ + int kve_private_resident; /* Number of private pages. */ + int kve_protection; /* Protection bitmask. */ + int kve_ref_count; /* VM obj ref count. */ + int kve_shadow_count; /* VM obj shadow count. */ + int kve_vn_type; /* Vnode type. */ + uint64_t kve_vn_size; /* File size. */ + uint32_t kve_vn_rdev_freebsd11; /* Device id if device. */ + uint16_t kve_vn_mode; /* File mode. */ + uint16_t kve_status; /* Status flags. */ + uint64_t kve_vn_fsid; /* dev_t of vnode location */ + uint64_t kve_vn_rdev; /* Device id if device. */ + int _kve_ispare[8]; /* Space for more stuff. */ + /* Truncated before copyout in sysctl */ + char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ +}; + +/* + * The "vm.objects" sysctl provides a list of all VM objects in the system + * via an array of these entries. + */ +struct kinfo_vmobject { + int kvo_structsize; /* Variable size of record. */ + int kvo_type; /* Object type: KVME_TYPE_*. */ + uint64_t kvo_size; /* Object size in pages. */ + uint64_t kvo_vn_fileid; /* inode number if vnode. */ + uint32_t kvo_vn_fsid_freebsd11; /* dev_t of vnode location. */ + int kvo_ref_count; /* Reference count. */ + int kvo_shadow_count; /* Shadow count. */ + int kvo_memattr; /* Memory attribute. */ + uint64_t kvo_resident; /* Number of resident pages. */ + uint64_t kvo_active; /* Number of active pages. */ + uint64_t kvo_inactive; /* Number of inactive pages. */ + uint64_t kvo_vn_fsid; + uint64_t _kvo_qspare[7]; + uint32_t _kvo_ispare[8]; + char kvo_path[PATH_MAX]; /* Pathname, if any. */ +}; + +/* + * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of + * another process as a series of entries. Each stack is represented by a + * series of symbol names and offsets as generated by stack_sbuf_print(9). + */ +#define KKST_MAXLEN 1024 + +#define KKST_STATE_STACKOK 0 /* Stack is valid. */ +#define KKST_STATE_SWAPPED 1 /* Stack swapped out. */ +#define KKST_STATE_RUNNING 2 /* Stack ephemeral. */ + +#if defined(__amd64__) || defined(__i386__) +#define KINFO_KSTACK_SIZE 1096 +#endif + +struct kinfo_kstack { + lwpid_t kkst_tid; /* ID of thread. */ + int kkst_state; /* Validity of stack. */ + char kkst_trace[KKST_MAXLEN]; /* String representing stack. */ + int _kkst_ispare[16]; /* Space for more stuff. */ +}; + +struct kinfo_sigtramp { + void *ksigtramp_start; + void *ksigtramp_end; + void *ksigtramp_spare[4]; +}; + +#ifdef _KERNEL +/* Flags for kern_proc_out function. */ +#define KERN_PROC_NOTHREADS 0x1 +#define KERN_PROC_MASK32 0x2 + +/* Flags for kern_proc_filedesc_out. */ +#define KERN_FILEDESC_PACK_KINFO 0x00000001U + +/* Flags for kern_proc_vmmap_out. */ +#define KERN_VMMAP_PACK_KINFO 0x00000001U +struct sbuf; + +/* + * The kern_proc out functions are helper functions to dump process + * miscellaneous kinfo structures to sbuf. The main consumers are KERN_PROC + * sysctls but they may also be used by other kernel subsystems. + * + * The functions manipulate the process locking state and expect the process + * to be locked on enter. On return the process is unlocked. + */ + +int kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, + int flags); +int kern_proc_cwd_out(struct proc *p, struct sbuf *sb, ssize_t maxlen); +int kern_proc_out(struct proc *p, struct sbuf *sb, int flags); +int kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, + int flags); + +int vntype_to_kinfo(int vtype); +void pack_kinfo(struct kinfo_file *kif); +#endif /* !_KERNEL */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/utsname.h b/lib/libc/include/any-freebsd-any/sys/utsname.h new file mode 100644 index 000000000000..27d3c25e42a3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/utsname.h @@ -0,0 +1,71 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)utsname.h 8.1 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H + +#ifdef _KERNEL +#define SYS_NMLN 32 /* uname(2) for the FreeBSD 1.1 ABI. */ +#endif + +#ifndef SYS_NMLN +#define SYS_NMLN 256 /* User can override. */ +#endif + +struct utsname { + char sysname[SYS_NMLN]; /* Name of this OS. */ + char nodename[SYS_NMLN]; /* Name of this network node. */ + char release[SYS_NMLN]; /* Release level. */ + char version[SYS_NMLN]; /* Version level. */ + char machine[SYS_NMLN]; /* Hardware type. */ +}; + +#include + +#ifndef _KERNEL +__BEGIN_DECLS +int __xuname(int, void *); /* Variable record size. */ +__END_DECLS + +static __inline int +uname(struct utsname *name) +{ + return __xuname(SYS_NMLN, (void *)name); +} +#endif /* _KERNEL */ + +#endif /* !_SYS_UTSNAME_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/uuid.h b/lib/libc/include/any-freebsd-any/sys/uuid.h new file mode 100644 index 000000000000..95050d0f8d20 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/uuid.h @@ -0,0 +1,101 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_UUID_H_ +#define _SYS_UUID_H_ + +#include + +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +}; + +#ifdef _KERNEL + +#define UUID_NODE_LEN _UUID_NODE_LEN + +struct sbuf; + +struct uuid *kern_uuidgen(struct uuid *, size_t); + +int uuid_ether_add(const uint8_t *); +int uuid_ether_del(const uint8_t *); + +int snprintf_uuid(char *, size_t, struct uuid *); +int printf_uuid(struct uuid *); +int sbuf_printf_uuid(struct sbuf *, struct uuid *); + +/* + * validate_uuid will, with no flags passed, validate only the format of the + * passed in UUID. Flags below are available to give it part of or all of the + * functionality that parse_uuid has traditionally had: acknowledging an empty + * string as valid, and checking the semantics of the UUID as well. + */ +int validate_uuid(const char *, size_t, struct uuid *, int); +int parse_uuid(const char *, struct uuid *); + +/* Flags to validate_uuid(). */ +#define VUUIDF_EMPTYOK 0x0001 +#define VUUIDF_CHECKSEMANTICS 0x0002 + +int uuidcmp(const struct uuid *, const struct uuid *); + +void be_uuid_dec(void const *buf, struct uuid *uuid); +void be_uuid_enc(void *buf, struct uuid const *uuid); +void le_uuid_dec(void const *buf, struct uuid *uuid); +void le_uuid_enc(void *buf, struct uuid const *uuid); + +#else /* _KERNEL */ + +/* XXX namespace pollution? */ +typedef struct uuid uuid_t; + +__BEGIN_DECLS +int uuidgen(struct uuid *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* _SYS_UUID_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/vdso.h b/lib/libc/include/any-freebsd-any/sys/vdso.h new file mode 100644 index 000000000000..b645e5356c84 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/vdso.h @@ -0,0 +1,136 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 2012 Konstantin Belousov . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_VDSO_H +#define _SYS_VDSO_H + +#include +#include + +struct vdso_timehands { + uint32_t th_algo; + uint32_t th_gen; + uint64_t th_scale; + uint32_t th_offset_count; + uint32_t th_counter_mask; + struct bintime th_offset; + struct bintime th_boottime; + VDSO_TIMEHANDS_MD +}; + +struct vdso_timekeep { + uint32_t tk_ver; + uint32_t tk_enabled; + uint32_t tk_current; + struct vdso_timehands tk_th[]; +}; + +#define VDSO_TK_CURRENT_BUSY 0xffffffff +#define VDSO_TK_VER_1 0x1 +#define VDSO_TK_VER_CURR VDSO_TK_VER_1 +#define VDSO_TH_ALGO_1 0x1 +#define VDSO_TH_ALGO_2 0x2 +#define VDSO_TH_ALGO_3 0x3 +#define VDSO_TH_ALGO_4 0x4 + +#ifndef _KERNEL + +struct timespec; +struct timeval; +struct timezone; + +int __vdso_clock_gettime(clockid_t clock_id, struct timespec *ts); +int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); +int __vdso_gettc(const struct vdso_timehands *vdso_th, u_int *tc); +int __vdso_gettimekeep(struct vdso_timekeep **tk); + +#endif + +#ifdef _KERNEL + +struct timecounter; + +struct vdso_sv_tk { + int sv_timekeep_off; + int sv_timekeep_curr; + uint32_t sv_timekeep_gen; +}; + +void timekeep_push_vdso(void); + +uint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th); + +/* + * The cpu_fill_vdso_timehands() function should fill MD-part of the + * struct vdso_timehands, which is both machine- and + * timecounter-depended. The return value should be 1 if fast + * userspace timecounter is enabled by hardware, and 0 otherwise. The + * global sysctl enable override is handled by machine-independed code + * after cpu_fill_vdso_timehands() call is made. + */ +uint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th, + struct timecounter *tc); + +struct vdso_sv_tk *alloc_sv_tk(void); + +#define VDSO_TH_NUM 4 + +#ifdef COMPAT_FREEBSD32 +struct bintime32 { + uint32_t sec; + uint32_t frac[2]; +}; + +struct vdso_timehands32 { + uint32_t th_algo; + uint32_t th_gen; + uint32_t th_scale[2]; + uint32_t th_offset_count; + uint32_t th_counter_mask; + struct bintime32 th_offset; + struct bintime32 th_boottime; + VDSO_TIMEHANDS_MD32 +}; + +struct vdso_timekeep32 { + uint32_t tk_ver; + uint32_t tk_enabled; + uint32_t tk_current; + struct vdso_timehands32 tk_th[]; +}; + +uint32_t tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32); +uint32_t cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32, + struct timecounter *tc); +struct vdso_sv_tk *alloc_sv_tk_compat32(void); + +#endif +#endif + +#endif diff --git a/lib/libc/include/any-freebsd-any/sys/vmem.h b/lib/libc/include/any-freebsd-any/sys/vmem.h new file mode 100644 index 000000000000..e74d1e3fe803 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/vmem.h @@ -0,0 +1,145 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c)2006 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* From $NetBSD: vmem.h,v 1.20 2013/01/29 21:26:24 para Exp $ */ + +/* $FreeBSD$ */ + +#ifndef _SYS_VMEM_H_ +#define _SYS_VMEM_H_ + +#include + +#ifdef _KERNEL + +typedef struct vmem vmem_t; + +typedef uintptr_t vmem_addr_t; +typedef size_t vmem_size_t; + +#define VMEM_ADDR_MIN 0 +#define VMEM_ADDR_QCACHE_MIN 1 +#define VMEM_ADDR_MAX (~(vmem_addr_t)0) + +typedef int (vmem_import_t)(void *, vmem_size_t, int, vmem_addr_t *); +typedef void (vmem_release_t)(void *, vmem_addr_t, vmem_size_t); +typedef void (vmem_reclaim_t)(vmem_t *, int); + +/* + * Create a vmem: + * name - Name of the region + * base - Initial span start (optional) + * size - Initial span size + * quantum - Natural unit of allocation (ie PAGE_SIZE, 1, etc) + * qcache_max - Maximum size to quantum cache. This creates a UMA + * cache for each multiple of quantum up to qcache_max. + * flags - M_* flags + */ +vmem_t *vmem_create(const char *name, vmem_addr_t base, + vmem_size_t size, vmem_size_t quantum, vmem_size_t qcache_max, int flags); +vmem_t *vmem_init(vmem_t *vm, const char *name, vmem_addr_t base, + vmem_size_t size, vmem_size_t quantum, vmem_size_t qcache_max, int flags); +void vmem_destroy(vmem_t *); + +/* + * Set callbacks for bringing in dynamic regions: + * importfn - Backing store import routine. + * releasefn - Backing store release routine. + * arg - Backing store argument + * import_quantum - Size to import from backing store + */ + +void vmem_set_import(vmem_t *vm, vmem_import_t *importfn, + vmem_release_t *releasefn, void *arg, vmem_size_t import_quantum); + +/* + * Set a limit on the total size of a vmem. + */ + +void vmem_set_limit(vmem_t *vm, vmem_size_t limit); + +/* + * Set a callback for reclaiming memory when space is exhausted: + */ +void vmem_set_reclaim(vmem_t *vm, vmem_reclaim_t *reclaimfn); + +/* + * Allocate and free linear regions from a vmem. Must specify + * BESTFIT or FIRSTFIT. Free is non-blocking. These routines + * respect the quantum caches. + */ +int vmem_alloc(vmem_t *vm, vmem_size_t size, int flags, vmem_addr_t *addrp); +void vmem_free(vmem_t *vm, vmem_addr_t addr, vmem_size_t size); + +/* + * Constrained allocate and free routines. These bypass the quantum cache. + * size - Size in units of 1, not quantum. + * align - Required alignment of the start of region + * phase - Offset from alignment + * nocross - Illegal boundary + * minaddr - Minimum allowed address for last byte + * maxaddr - Maximum allowed address for first byte + * flags - M_* flags + * addrp - result + */ +int vmem_xalloc(vmem_t *vm, vmem_size_t size, vmem_size_t align, + vmem_size_t phase, vmem_size_t nocross, vmem_addr_t minaddr, + vmem_addr_t maxaddr, int flags, vmem_addr_t *addrp); +void vmem_xfree(vmem_t *vm, vmem_addr_t addr, vmem_size_t size); + +/* + * Add a static region to a vmem after create. This won't be freed + * until the vmem is destroyed. + */ +int vmem_add(vmem_t *vm, vmem_addr_t addr, vmem_size_t size, int flags); + +/* + * Given roundup size to the vmem's native quantum size. + */ +vmem_size_t vmem_roundup_size(vmem_t *vm, vmem_size_t size); + +/* + * Report vmem utilization according to the requested type. + */ +vmem_size_t vmem_size(vmem_t *vm, int typemask); + +void vmem_whatis(vmem_addr_t addr, int (*fn)(const char *, ...) + __printflike(1, 2)); +void vmem_print(vmem_addr_t addr, const char *, int (*fn)(const char *, ...) + __printflike(1, 2)); +void vmem_printall(const char *, int (*fn)(const char *, ...) + __printflike(1, 2)); +void vmem_startup(void); + +/* vmem_size typemask */ +#define VMEM_ALLOC 0x01 +#define VMEM_FREE 0x02 +#define VMEM_MAXFREE 0x10 + +#endif /* _KERNEL */ + +#endif /* !_SYS_VMEM_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/vmmeter.h b/lib/libc/include/any-freebsd-any/sys/vmmeter.h new file mode 100644 index 000000000000..3714a06983bf --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/vmmeter.h @@ -0,0 +1,238 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_VMMETER_H_ +#define _SYS_VMMETER_H_ + +/* + * This value is used by ps(1) to change sleep state flag from 'S' to + * 'I' and by the sched process to set the alarm clock. + */ +#define MAXSLP 20 + +struct vmtotal { + uint64_t t_vm; /* total virtual memory */ + uint64_t t_avm; /* active virtual memory */ + uint64_t t_rm; /* total real memory in use */ + uint64_t t_arm; /* active real memory */ + uint64_t t_vmshr; /* shared virtual memory */ + uint64_t t_avmshr; /* active shared virtual memory */ + uint64_t t_rmshr; /* shared real memory */ + uint64_t t_armshr; /* active shared real memory */ + uint64_t t_free; /* free memory pages */ + int16_t t_rq; /* length of the run queue */ + int16_t t_dw; /* threads in ``disk wait'' (neg + priority) */ + int16_t t_pw; /* threads in page wait */ + int16_t t_sl; /* threads sleeping in core */ + int16_t t_sw; /* swapped out runnable/short + block threads */ + uint16_t t_pad[3]; +}; + +#if defined(_KERNEL) || defined(_WANT_VMMETER) +#include + +#ifdef _KERNEL +#define VMMETER_ALIGNED __aligned(CACHE_LINE_SIZE) +#else +#define VMMETER_ALIGNED +#endif + +/* + * System wide statistics counters. + * Locking: + * c - constant after initialization + * p - uses counter(9) + */ +struct vmmeter { + /* + * General system activity. + */ + counter_u64_t v_swtch; /* (p) context switches */ + counter_u64_t v_trap; /* (p) calls to trap */ + counter_u64_t v_syscall; /* (p) calls to syscall() */ + counter_u64_t v_intr; /* (p) device interrupts */ + counter_u64_t v_soft; /* (p) software interrupts */ + /* + * Virtual memory activity. + */ + counter_u64_t v_vm_faults; /* (p) address memory faults */ + counter_u64_t v_io_faults; /* (p) page faults requiring I/O */ + counter_u64_t v_cow_faults; /* (p) copy-on-writes faults */ + counter_u64_t v_cow_optim; /* (p) optimized COW faults */ + counter_u64_t v_zfod; /* (p) pages zero filled on demand */ + counter_u64_t v_ozfod; /* (p) optimized zero fill pages */ + counter_u64_t v_swapin; /* (p) swap pager pageins */ + counter_u64_t v_swapout; /* (p) swap pager pageouts */ + counter_u64_t v_swappgsin; /* (p) swap pager pages paged in */ + counter_u64_t v_swappgsout; /* (p) swap pager pages paged out */ + counter_u64_t v_vnodein; /* (p) vnode pager pageins */ + counter_u64_t v_vnodeout; /* (p) vnode pager pageouts */ + counter_u64_t v_vnodepgsin; /* (p) vnode_pager pages paged in */ + counter_u64_t v_vnodepgsout; /* (p) vnode pager pages paged out */ + counter_u64_t v_intrans; /* (p) intransit blocking page faults */ + counter_u64_t v_reactivated; /* (p) reactivated by the pagedaemon */ + counter_u64_t v_pdwakeups; /* (p) times daemon has awaken */ + counter_u64_t v_pdpages; /* (p) pages analyzed by daemon */ + counter_u64_t v_pdshortfalls; /* (p) page reclamation shortfalls */ + + counter_u64_t v_dfree; /* (p) pages freed by daemon */ + counter_u64_t v_pfree; /* (p) pages freed by processes */ + counter_u64_t v_tfree; /* (p) total pages freed */ + /* + * Fork/vfork/rfork activity. + */ + counter_u64_t v_forks; /* (p) fork() calls */ + counter_u64_t v_vforks; /* (p) vfork() calls */ + counter_u64_t v_rforks; /* (p) rfork() calls */ + counter_u64_t v_kthreads; /* (p) fork() calls by kernel */ + counter_u64_t v_forkpages; /* (p) pages affected by fork() */ + counter_u64_t v_vforkpages; /* (p) pages affected by vfork() */ + counter_u64_t v_rforkpages; /* (p) pages affected by rfork() */ + counter_u64_t v_kthreadpages; /* (p) ... and by kernel fork() */ + counter_u64_t v_wire_count; /* (p) pages wired down */ +#define VM_METER_NCOUNTERS \ + (offsetof(struct vmmeter, v_page_size) / sizeof(counter_u64_t)) + /* + * Distribution of page usages. + */ + u_int v_page_size; /* (c) page size in bytes */ + u_int v_page_count; /* (c) total number of pages in system */ + u_int v_free_reserved; /* (c) pages reserved for deadlock */ + u_int v_free_target; /* (c) pages desired free */ + u_int v_free_min; /* (c) pages desired free */ + u_int v_inactive_target; /* (c) pages desired inactive */ + u_int v_pageout_free_min; /* (c) min pages reserved for kernel */ + u_int v_interrupt_free_min; /* (c) reserved pages for int code */ + u_int v_free_severe; /* (c) severe page depletion point */ +}; +#endif /* _KERNEL || _WANT_VMMETER */ + +#ifdef _KERNEL + +#include + +extern struct vmmeter vm_cnt; +extern domainset_t all_domains; +extern domainset_t vm_min_domains; +extern domainset_t vm_severe_domains; + +#define VM_CNT_ADD(var, x) counter_u64_add(vm_cnt.var, x) +#define VM_CNT_INC(var) VM_CNT_ADD(var, 1) +#define VM_CNT_FETCH(var) counter_u64_fetch(vm_cnt.var) + +extern u_long vm_user_wire_count; + +static inline void +vm_wire_add(int cnt) +{ + + VM_CNT_ADD(v_wire_count, cnt); +} + +static inline void +vm_wire_sub(int cnt) +{ + + VM_CNT_ADD(v_wire_count, -cnt); +} + +u_int vm_free_count(void); +static inline u_int +vm_wire_count(void) +{ + + return (VM_CNT_FETCH(v_wire_count)); +} + +/* + * Return TRUE if we are under our severe low-free-pages threshold + * + * These routines are typically used at the user<->system interface to determine + * whether we need to block in order to avoid a low memory deadlock. + */ +static inline int +vm_page_count_severe(void) +{ + + return (!DOMAINSET_EMPTY(&vm_severe_domains)); +} + +static inline int +vm_page_count_severe_domain(int domain) +{ + + return (DOMAINSET_ISSET(domain, &vm_severe_domains)); +} + +static inline int +vm_page_count_severe_set(const domainset_t *mask) +{ + + return (DOMAINSET_SUBSET(&vm_severe_domains, mask)); +} + +/* + * Return TRUE if we are under our minimum low-free-pages threshold. + * + * These routines are typically used within the system to determine whether + * we can execute potentially very expensive code in terms of memory. It + * is also used by the pageout daemon to calculate when to sleep, when + * to wake waiters up, and when (after making a pass) to become more + * desperate. + */ +static inline int +vm_page_count_min(void) +{ + + return (!DOMAINSET_EMPTY(&vm_min_domains)); +} + +static inline int +vm_page_count_min_domain(int domain) +{ + + return (DOMAINSET_ISSET(domain, &vm_min_domains)); +} + +static inline int +vm_page_count_min_set(const domainset_t *mask) +{ + + return (DOMAINSET_SUBSET(&vm_min_domains, mask)); +} + +#endif /* _KERNEL */ +#endif /* _SYS_VMMETER_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/vnode.h b/lib/libc/include/any-freebsd-any/sys/vnode.h new file mode 100644 index 000000000000..9f442baf7c00 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/vnode.h @@ -0,0 +1,928 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)vnode.h 8.7 (Berkeley) 2/4/94 + * $FreeBSD$ + */ + +#ifndef _SYS_VNODE_H_ +#define _SYS_VNODE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The vnode is the focus of all file activity in UNIX. There is a + * unique vnode allocated for each active file, each current directory, + * each mounted-on file, text file, and the root. + */ + +/* + * Vnode types. VNON means no type. + */ +enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, + VMARKER }; + +/* + * Each underlying filesystem allocates its own private area and hangs + * it from v_data. If non-null, this area is freed in getnewvnode(). + */ + +struct namecache; + +struct vpollinfo { + struct mtx vpi_lock; /* lock to protect below */ + struct selinfo vpi_selinfo; /* identity of poller(s) */ + short vpi_events; /* what they are looking for */ + short vpi_revents; /* what has happened */ +}; + +/* + * Reading or writing any of these items requires holding the appropriate lock. + * + * Lock reference: + * c - namecache mutex + * i - interlock + * l - mp mnt_listmtx or freelist mutex + * I - updated with atomics, 0->1 and 1->0 transitions with interlock held + * m - mount point interlock + * p - pollinfo lock + * u - Only a reference to the vnode is needed to read. + * v - vnode lock + * + * Vnodes may be found on many lists. The general way to deal with operating + * on a vnode that is on a list is: + * 1) Lock the list and find the vnode. + * 2) Lock interlock so that the vnode does not go away. + * 3) Unlock the list to avoid lock order reversals. + * 4) vget with LK_INTERLOCK and check for ENOENT, or + * 5) Check for DOOMED if the vnode lock is not required. + * 6) Perform your operation, then vput(). + */ + +#if defined(_KERNEL) || defined(_KVM_VNODE) + +struct vnode { + /* + * Fields which define the identity of the vnode. These fields are + * owned by the filesystem (XXX: and vgone() ?) + */ + const char *v_tag; /* u type of underlying data */ + struct vop_vector *v_op; /* u vnode operations vector */ + void *v_data; /* u private data for fs */ + + /* + * Filesystem instance stuff + */ + struct mount *v_mount; /* u ptr to vfs we are in */ + TAILQ_ENTRY(vnode) v_nmntvnodes; /* m vnodes for mount point */ + + /* + * Type specific fields, only one applies to any given vnode. + */ + union { + struct mount *v_mountedhere; /* v ptr to mountpoint (VDIR) */ + struct unpcb *v_unpcb; /* v unix domain net (VSOCK) */ + struct cdev *v_rdev; /* v device (VCHR, VBLK) */ + struct fifoinfo *v_fifoinfo; /* v fifo (VFIFO) */ + }; + + /* + * vfs_hash: (mount + inode) -> vnode hash. The hash value + * itself is grouped with other int fields, to avoid padding. + */ + LIST_ENTRY(vnode) v_hashlist; + + /* + * VFS_namecache stuff + */ + LIST_HEAD(, namecache) v_cache_src; /* c Cache entries from us */ + TAILQ_HEAD(, namecache) v_cache_dst; /* c Cache entries to us */ + struct namecache *v_cache_dd; /* c Cache entry for .. vnode */ + + /* + * Locking + */ + struct lock v_lock; /* u (if fs don't have one) */ + struct mtx v_interlock; /* lock for "i" things */ + struct lock *v_vnlock; /* u pointer to vnode lock */ + + /* + * The machinery of being a vnode + */ + TAILQ_ENTRY(vnode) v_actfreelist; /* l vnode active/free lists */ + struct bufobj v_bufobj; /* * Buffer cache object */ + + /* + * Hooks for various subsystems and features. + */ + struct vpollinfo *v_pollinfo; /* i Poll events, p for *v_pi */ + struct label *v_label; /* MAC label for vnode */ + struct lockf *v_lockf; /* Byte-level advisory lock list */ + struct rangelock v_rl; /* Byte-range lock */ + + /* + * clustering stuff + */ + daddr_t v_cstart; /* v start block of cluster */ + daddr_t v_lasta; /* v last allocation */ + daddr_t v_lastw; /* v last write */ + int v_clen; /* v length of cur. cluster */ + + u_int v_holdcnt; /* I prevents recycling. */ + u_int v_usecount; /* I ref count of users */ + u_int v_iflag; /* i vnode flags (see below) */ + u_int v_vflag; /* v vnode flags */ + u_int v_mflag; /* l mnt-specific vnode flags */ + int v_writecount; /* I ref count of writers or + (negative) text users */ + u_int v_hash; + enum vtype v_type; /* u vnode type */ +}; + +#endif /* defined(_KERNEL) || defined(_KVM_VNODE) */ + +#define bo2vnode(bo) __containerof((bo), struct vnode, v_bufobj) + +/* XXX: These are temporary to avoid a source sweep at this time */ +#define v_object v_bufobj.bo_object + +/* + * Userland version of struct vnode, for sysctl. + */ +struct xvnode { + size_t xv_size; /* sizeof(struct xvnode) */ + void *xv_vnode; /* address of real vnode */ + u_long xv_flag; /* vnode vflags */ + int xv_usecount; /* reference count of users */ + int xv_writecount; /* reference count of writers */ + int xv_holdcnt; /* page & buffer references */ + u_long xv_id; /* capability identifier */ + void *xv_mount; /* address of parent mount */ + long xv_numoutput; /* num of writes in progress */ + enum vtype xv_type; /* vnode type */ + union { + void *xvu_socket; /* unpcb, if VSOCK */ + void *xvu_fifo; /* fifo, if VFIFO */ + dev_t xvu_rdev; /* maj/min, if VBLK/VCHR */ + struct { + dev_t xvu_dev; /* device, if VDIR/VREG/VLNK */ + ino_t xvu_ino; /* id, if VDIR/VREG/VLNK */ + } xv_uns; + } xv_un; +}; +#define xv_socket xv_un.xvu_socket +#define xv_fifo xv_un.xvu_fifo +#define xv_rdev xv_un.xvu_rdev +#define xv_dev xv_un.xv_uns.xvu_dev +#define xv_ino xv_un.xv_uns.xvu_ino + +/* We don't need to lock the knlist */ +#define VN_KNLIST_EMPTY(vp) ((vp)->v_pollinfo == NULL || \ + KNLIST_EMPTY(&(vp)->v_pollinfo->vpi_selinfo.si_note)) + +#define VN_KNOTE(vp, b, a) \ + do { \ + if (!VN_KNLIST_EMPTY(vp)) \ + KNOTE(&vp->v_pollinfo->vpi_selinfo.si_note, (b), \ + (a) | KNF_NOKQLOCK); \ + } while (0) +#define VN_KNOTE_LOCKED(vp, b) VN_KNOTE(vp, b, KNF_LISTLOCKED) +#define VN_KNOTE_UNLOCKED(vp, b) VN_KNOTE(vp, b, 0) + +/* + * Vnode flags. + * VI flags are protected by interlock and live in v_iflag + * VV flags are protected by the vnode lock and live in v_vflag + * + * VI_DOOMED is doubly protected by the interlock and vnode lock. Both + * are required for writing but the status may be checked with either. + */ +#define VI_TEXT_REF 0x0001 /* Text ref grabbed use ref */ +#define VI_MOUNT 0x0020 /* Mount in progress */ +#define VI_DOOMED 0x0080 /* This vnode is being recycled */ +#define VI_FREE 0x0100 /* This vnode is on the freelist */ +#define VI_ACTIVE 0x0200 /* This vnode is on the active list */ +#define VI_DOINGINACT 0x0800 /* VOP_INACTIVE is in progress */ +#define VI_OWEINACT 0x1000 /* Need to call inactive */ + +#define VV_ROOT 0x0001 /* root of its filesystem */ +#define VV_ISTTY 0x0002 /* vnode represents a tty */ +#define VV_NOSYNC 0x0004 /* unlinked, stop syncing */ +#define VV_ETERNALDEV 0x0008 /* device that is never destroyed */ +#define VV_CACHEDLABEL 0x0010 /* Vnode has valid cached MAC label */ +#define VV_VMSIZEVNLOCK 0x0020 /* object size check requires vnode lock */ +#define VV_COPYONWRITE 0x0040 /* vnode is doing copy-on-write */ +#define VV_SYSTEM 0x0080 /* vnode being used by kernel */ +#define VV_PROCDEP 0x0100 /* vnode is process dependent */ +#define VV_NOKNOTE 0x0200 /* don't activate knotes on this vnode */ +#define VV_DELETED 0x0400 /* should be removed */ +#define VV_MD 0x0800 /* vnode backs the md device */ +#define VV_FORCEINSMQ 0x1000 /* force the insmntque to succeed */ +#define VV_READLINK 0x2000 /* fdescfs linux vnode */ + +#define VMP_TMPMNTFREELIST 0x0001 /* Vnode is on mnt's tmp free list */ + +/* + * Vnode attributes. A field value of VNOVAL represents a field whose value + * is unavailable (getattr) or which is not to be changed (setattr). + */ +struct vattr { + enum vtype va_type; /* vnode type (for create) */ + u_short va_mode; /* files access mode and type */ + u_short va_padding0; + uid_t va_uid; /* owner user id */ + gid_t va_gid; /* owner group id */ + nlink_t va_nlink; /* number of references to file */ + dev_t va_fsid; /* filesystem id */ + ino_t va_fileid; /* file id */ + u_quad_t va_size; /* file size in bytes */ + long va_blocksize; /* blocksize preferred for i/o */ + struct timespec va_atime; /* time of last access */ + struct timespec va_mtime; /* time of last modification */ + struct timespec va_ctime; /* time file changed */ + struct timespec va_birthtime; /* time file created */ + u_long va_gen; /* generation number of file */ + u_long va_flags; /* flags defined for file */ + dev_t va_rdev; /* device the special file represents */ + u_quad_t va_bytes; /* bytes of disk space held by file */ + u_quad_t va_filerev; /* file modification number */ + u_int va_vaflags; /* operations flags, see below */ + long va_spare; /* remain quad aligned */ +}; + +/* + * Flags for va_vaflags. + */ +#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ +#define VA_EXCLUSIVE 0x02 /* exclusive create request */ +#define VA_SYNC 0x04 /* O_SYNC truncation */ + +/* + * Flags for ioflag. (high 16 bits used to ask for read-ahead and + * help with write clustering) + * NB: IO_NDELAY and IO_DIRECT are linked to fcntl.h + */ +#define IO_UNIT 0x0001 /* do I/O as atomic unit */ +#define IO_APPEND 0x0002 /* append write to end */ +#define IO_NDELAY 0x0004 /* FNDELAY flag set in file table */ +#define IO_NODELOCKED 0x0008 /* underlying node already locked */ +#define IO_ASYNC 0x0010 /* bawrite rather then bdwrite */ +#define IO_VMIO 0x0020 /* data already in VMIO space */ +#define IO_INVAL 0x0040 /* invalidate after I/O */ +#define IO_SYNC 0x0080 /* do I/O synchronously */ +#define IO_DIRECT 0x0100 /* attempt to bypass buffer cache */ +#define IO_NOREUSE 0x0200 /* VMIO data won't be reused */ +#define IO_EXT 0x0400 /* operate on external attributes */ +#define IO_NORMAL 0x0800 /* operate on regular data */ +#define IO_NOMACCHECK 0x1000 /* MAC checks unnecessary */ +#define IO_BUFLOCKED 0x2000 /* ffs flag; indir buf is locked */ +#define IO_RANGELOCKED 0x4000 /* range locked */ + +#define IO_SEQMAX 0x7F /* seq heuristic max value */ +#define IO_SEQSHIFT 16 /* seq heuristic in upper 16 bits */ + +/* + * Flags for accmode_t. + */ +#define VEXEC 000000000100 /* execute/search permission */ +#define VWRITE 000000000200 /* write permission */ +#define VREAD 000000000400 /* read permission */ +#define VADMIN 000000010000 /* being the file owner */ +#define VAPPEND 000000040000 /* permission to write/append */ +/* + * VEXPLICIT_DENY makes VOP_ACCESSX(9) return EPERM or EACCES only + * if permission was denied explicitly, by a "deny" rule in NFSv4 ACL, + * and 0 otherwise. This never happens with ordinary unix access rights + * or POSIX.1e ACLs. Obviously, VEXPLICIT_DENY must be OR-ed with + * some other V* constant. + */ +#define VEXPLICIT_DENY 000000100000 +#define VREAD_NAMED_ATTRS 000000200000 /* not used */ +#define VWRITE_NAMED_ATTRS 000000400000 /* not used */ +#define VDELETE_CHILD 000001000000 +#define VREAD_ATTRIBUTES 000002000000 /* permission to stat(2) */ +#define VWRITE_ATTRIBUTES 000004000000 /* change {m,c,a}time */ +#define VDELETE 000010000000 +#define VREAD_ACL 000020000000 /* read ACL and file mode */ +#define VWRITE_ACL 000040000000 /* change ACL and/or file mode */ +#define VWRITE_OWNER 000100000000 /* change file owner */ +#define VSYNCHRONIZE 000200000000 /* not used */ +#define VCREAT 000400000000 /* creating new file */ +#define VVERIFY 001000000000 /* verification required */ + +/* + * Permissions that were traditionally granted only to the file owner. + */ +#define VADMIN_PERMS (VADMIN | VWRITE_ATTRIBUTES | VWRITE_ACL | \ + VWRITE_OWNER) + +/* + * Permissions that were traditionally granted to everyone. + */ +#define VSTAT_PERMS (VREAD_ATTRIBUTES | VREAD_ACL) + +/* + * Permissions that allow to change the state of the file in any way. + */ +#define VMODIFY_PERMS (VWRITE | VAPPEND | VADMIN_PERMS | VDELETE_CHILD | \ + VDELETE) + +/* + * Token indicating no attribute value yet assigned. + */ +#define VNOVAL (-1) + +/* + * LK_TIMELOCK timeout for vnode locks (used mainly by the pageout daemon) + */ +#define VLKTIMEOUT (hz / 20 + 1) + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_VNODE); +#endif + +extern u_int ncsizefactor; + +/* + * Convert between vnode types and inode formats (since POSIX.1 + * defines mode word of stat structure in terms of inode formats). + */ +extern enum vtype iftovt_tab[]; +extern int vttoif_tab[]; +#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) +#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) +#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) + +/* + * Flags to various vnode functions. + */ +#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ +#define FORCECLOSE 0x0002 /* vflush: force file closure */ +#define WRITECLOSE 0x0004 /* vflush: only close writable files */ +#define EARLYFLUSH 0x0008 /* vflush: early call for ffs_flushfiles */ +#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ +#define V_ALT 0x0002 /* vinvalbuf: invalidate only alternate bufs */ +#define V_NORMAL 0x0004 /* vinvalbuf: invalidate only regular bufs */ +#define V_CLEANONLY 0x0008 /* vinvalbuf: invalidate only clean bufs */ +#define V_VMIO 0x0010 /* vinvalbuf: called during pageout */ +#define V_ALLOWCLEAN 0x0020 /* vinvalbuf: allow clean buffers after flush */ +#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ +#define V_WAIT 0x0001 /* vn_start_write: sleep for suspend */ +#define V_NOWAIT 0x0002 /* vn_start_write: don't sleep for suspend */ +#define V_XSLEEP 0x0004 /* vn_start_write: just return after sleep */ +#define V_MNTREF 0x0010 /* vn_start_write: mp is already ref-ed */ + +#define VR_START_WRITE 0x0001 /* vfs_write_resume: start write atomically */ +#define VR_NO_SUSPCLR 0x0002 /* vfs_write_resume: do not clear suspension */ + +#define VS_SKIP_UNMOUNT 0x0001 /* vfs_write_suspend: fail if the + filesystem is being unmounted */ + +#define VREF(vp) vref(vp) + +#ifdef DIAGNOSTIC +#define VATTR_NULL(vap) vattr_null(vap) +#else +#define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */ +#endif /* DIAGNOSTIC */ + +#define NULLVP ((struct vnode *)NULL) + +/* + * Global vnode data. + */ +extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ +extern struct mount *rootdevmp; /* "/dev" mount */ +extern int desiredvnodes; /* number of vnodes desired */ +extern struct uma_zone *namei_zone; +extern struct vattr va_null; /* predefined null vattr structure */ + +#define VI_LOCK(vp) mtx_lock(&(vp)->v_interlock) +#define VI_LOCK_FLAGS(vp, flags) mtx_lock_flags(&(vp)->v_interlock, (flags)) +#define VI_TRYLOCK(vp) mtx_trylock(&(vp)->v_interlock) +#define VI_UNLOCK(vp) mtx_unlock(&(vp)->v_interlock) +#define VI_MTX(vp) (&(vp)->v_interlock) + +#define VN_LOCK_AREC(vp) lockallowrecurse((vp)->v_vnlock) +#define VN_LOCK_ASHARE(vp) lockallowshare((vp)->v_vnlock) +#define VN_LOCK_DSHARE(vp) lockdisableshare((vp)->v_vnlock) + +#endif /* _KERNEL */ + +/* + * Mods for extensibility. + */ + +/* + * Flags for vdesc_flags: + */ +#define VDESC_MAX_VPS 16 +/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ +#define VDESC_VP0_WILLRELE 0x0001 +#define VDESC_VP1_WILLRELE 0x0002 +#define VDESC_VP2_WILLRELE 0x0004 +#define VDESC_VP3_WILLRELE 0x0008 +#define VDESC_NOMAP_VPP 0x0100 +#define VDESC_VPP_WILLRELE 0x0200 + +/* + * A generic structure. + * This can be used by bypass routines to identify generic arguments. + */ +struct vop_generic_args { + struct vnodeop_desc *a_desc; + /* other random data follows, presumably */ +}; + +typedef int vop_bypass_t(struct vop_generic_args *); + +/* + * VDESC_NO_OFFSET is used to identify the end of the offset list + * and in places where no such field exists. + */ +#define VDESC_NO_OFFSET -1 + +/* + * This structure describes the vnode operation taking place. + */ +struct vnodeop_desc { + char *vdesc_name; /* a readable name for debugging */ + int vdesc_flags; /* VDESC_* flags */ + vop_bypass_t *vdesc_call; /* Function to call */ + + /* + * These ops are used by bypass routines to map and locate arguments. + * Creds and procs are not needed in bypass routines, but sometimes + * they are useful to (for example) transport layers. + * Nameidata is useful because it has a cred in it. + */ + int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ + int vdesc_vpp_offset; /* return vpp location */ + int vdesc_cred_offset; /* cred location, if any */ + int vdesc_thread_offset; /* thread location, if any */ + int vdesc_componentname_offset; /* if any */ +}; + +#ifdef _KERNEL +/* + * A list of all the operation descs. + */ +extern struct vnodeop_desc *vnodeop_descs[]; + +#define VOPARG_OFFSETOF(s_type, field) __offsetof(s_type, field) +#define VOPARG_OFFSETTO(s_type, s_offset, struct_p) \ + ((s_type)(((char*)(struct_p)) + (s_offset))) + + +#ifdef DEBUG_VFS_LOCKS +/* + * Support code to aid in debugging VFS locking problems. Not totally + * reliable since if the thread sleeps between changing the lock + * state and checking it with the assert, some other thread could + * change the state. They are good enough for debugging a single + * filesystem using a single-threaded test. Note that the unreliability is + * limited to false negatives; efforts were made to ensure that false + * positives cannot occur. + */ +void assert_vi_locked(struct vnode *vp, const char *str); +void assert_vi_unlocked(struct vnode *vp, const char *str); +void assert_vop_elocked(struct vnode *vp, const char *str); +void assert_vop_locked(struct vnode *vp, const char *str); +void assert_vop_unlocked(struct vnode *vp, const char *str); + +#define ASSERT_VI_LOCKED(vp, str) assert_vi_locked((vp), (str)) +#define ASSERT_VI_UNLOCKED(vp, str) assert_vi_unlocked((vp), (str)) +#define ASSERT_VOP_ELOCKED(vp, str) assert_vop_elocked((vp), (str)) +#define ASSERT_VOP_LOCKED(vp, str) assert_vop_locked((vp), (str)) +#define ASSERT_VOP_UNLOCKED(vp, str) assert_vop_unlocked((vp), (str)) + +#else /* !DEBUG_VFS_LOCKS */ + +#define ASSERT_VI_LOCKED(vp, str) ((void)0) +#define ASSERT_VI_UNLOCKED(vp, str) ((void)0) +#define ASSERT_VOP_ELOCKED(vp, str) ((void)0) +#define ASSERT_VOP_LOCKED(vp, str) ((void)0) +#define ASSERT_VOP_UNLOCKED(vp, str) ((void)0) +#endif /* DEBUG_VFS_LOCKS */ + + +/* + * This call works for vnodes in the kernel. + */ +#define VCALL(c) ((c)->a_desc->vdesc_call(c)) + +#define DOINGASYNC(vp) \ + (((vp)->v_mount->mnt_kern_flag & MNTK_ASYNC) != 0 && \ + ((curthread->td_pflags & TDP_SYNCIO) == 0)) + +/* + * VMIO support inline + */ + +extern int vmiodirenable; + +static __inline int +vn_canvmio(struct vnode *vp) +{ + if (vp && (vp->v_type == VREG || (vmiodirenable && vp->v_type == VDIR))) + return(TRUE); + return(FALSE); +} + +/* + * Finally, include the default set of vnode operations. + */ +typedef void vop_getpages_iodone_t(void *, vm_page_t *, int, int); +#include "vnode_if.h" + +/* vn_open_flags */ +#define VN_OPEN_NOAUDIT 0x00000001 +#define VN_OPEN_NOCAPCHECK 0x00000002 +#define VN_OPEN_NAMECACHE 0x00000004 +#define VN_OPEN_INVFS 0x00000008 + +/* + * Public vnode manipulation functions. + */ +struct componentname; +struct file; +struct mount; +struct nameidata; +struct ostat; +struct freebsd11_stat; +struct thread; +struct proc; +struct stat; +struct nstat; +struct ucred; +struct uio; +struct vattr; +struct vfsops; +struct vnode; + +typedef int (*vn_get_ino_t)(struct mount *, void *, int, struct vnode **); + +int bnoreuselist(struct bufv *bufv, struct bufobj *bo, daddr_t startn, + daddr_t endn); +/* cache_* may belong in namei.h. */ +void cache_changesize(int newhashsize); +#define cache_enter(dvp, vp, cnp) \ + cache_enter_time(dvp, vp, cnp, NULL, NULL) +void cache_enter_time(struct vnode *dvp, struct vnode *vp, + struct componentname *cnp, struct timespec *tsp, + struct timespec *dtsp); +int cache_lookup(struct vnode *dvp, struct vnode **vpp, + struct componentname *cnp, struct timespec *tsp, int *ticksp); +void cache_purge(struct vnode *vp); +void cache_purge_negative(struct vnode *vp); +void cache_purgevfs(struct mount *mp, bool force); +int change_dir(struct vnode *vp, struct thread *td); +void cvtstat(struct stat *st, struct ostat *ost); +void freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb); +int freebsd11_cvtstat(struct stat *st, struct freebsd11_stat *ost); +int getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops, + struct vnode **vpp); +void getnewvnode_reserve(u_int count); +void getnewvnode_drop_reserve(void); +int insmntque1(struct vnode *vp, struct mount *mp, + void (*dtr)(struct vnode *, void *), void *dtr_arg); +int insmntque(struct vnode *vp, struct mount *mp); +u_quad_t init_va_filerev(void); +int speedup_syncer(void); +int vn_vptocnp(struct vnode **vp, struct ucred *cred, char *buf, + u_int *buflen); +int vn_fullpath(struct thread *td, struct vnode *vn, + char **retbuf, char **freebuf); +int vn_fullpath_global(struct thread *td, struct vnode *vn, + char **retbuf, char **freebuf); +struct vnode * + vn_dir_dd_ino(struct vnode *vp); +int vn_commname(struct vnode *vn, char *buf, u_int buflen); +int vn_path_to_global_path(struct thread *td, struct vnode *vp, + char *path, u_int pathlen); +int vaccess(enum vtype type, mode_t file_mode, uid_t file_uid, + gid_t file_gid, accmode_t accmode, struct ucred *cred, + int *privused); +int vaccess_acl_nfs4(enum vtype type, uid_t file_uid, gid_t file_gid, + struct acl *aclp, accmode_t accmode, struct ucred *cred, + int *privused); +int vaccess_acl_posix1e(enum vtype type, uid_t file_uid, + gid_t file_gid, struct acl *acl, accmode_t accmode, + struct ucred *cred, int *privused); +void vattr_null(struct vattr *vap); +int vcount(struct vnode *vp); +#define vdrop(vp) _vdrop((vp), 0) +#define vdropl(vp) _vdrop((vp), 1) +void _vdrop(struct vnode *, bool); +int vflush(struct mount *mp, int rootrefs, int flags, struct thread *td); +int vget(struct vnode *vp, int lockflag, struct thread *td); +void vgone(struct vnode *vp); +#define vhold(vp) _vhold((vp), 0) +#define vholdl(vp) _vhold((vp), 1) +void _vhold(struct vnode *, bool); +void vinactive(struct vnode *, struct thread *); +int vinvalbuf(struct vnode *vp, int save, int slpflag, int slptimeo); +int vtruncbuf(struct vnode *vp, off_t length, int blksize); +void v_inval_buf_range(struct vnode *vp, daddr_t startlbn, daddr_t endlbn, + int blksize); +void vunref(struct vnode *); +void vn_printf(struct vnode *vp, const char *fmt, ...) __printflike(2,3); +int vrecycle(struct vnode *vp); +int vrecyclel(struct vnode *vp); +int vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, + struct ucred *cred); +int vn_close(struct vnode *vp, + int flags, struct ucred *file_cred, struct thread *td); +void vn_finished_write(struct mount *mp); +void vn_finished_secondary_write(struct mount *mp); +int vn_fsync_buf(struct vnode *vp, int waitfor); +int vn_isdisk(struct vnode *vp, int *errp); +int _vn_lock(struct vnode *vp, int flags, char *file, int line); +#define vn_lock(vp, flags) _vn_lock(vp, flags, __FILE__, __LINE__) +int vn_open(struct nameidata *ndp, int *flagp, int cmode, struct file *fp); +int vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, + u_int vn_open_flags, struct ucred *cred, struct file *fp); +int vn_open_vnode(struct vnode *vp, int fmode, struct ucred *cred, + struct thread *td, struct file *fp); +void vn_pages_remove(struct vnode *vp, vm_pindex_t start, vm_pindex_t end); +int vn_pollrecord(struct vnode *vp, struct thread *p, int events); +int vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, + int len, off_t offset, enum uio_seg segflg, int ioflg, + struct ucred *active_cred, struct ucred *file_cred, ssize_t *aresid, + struct thread *td); +int vn_rdwr_inchunks(enum uio_rw rw, struct vnode *vp, void *base, + size_t len, off_t offset, enum uio_seg segflg, int ioflg, + struct ucred *active_cred, struct ucred *file_cred, size_t *aresid, + struct thread *td); +int vn_rlimit_fsize(const struct vnode *vn, const struct uio *uio, + struct thread *td); +int vn_stat(struct vnode *vp, struct stat *sb, struct ucred *active_cred, + struct ucred *file_cred, struct thread *td); +int vn_start_write(struct vnode *vp, struct mount **mpp, int flags); +int vn_start_secondary_write(struct vnode *vp, struct mount **mpp, + int flags); +int vn_writechk(struct vnode *vp); +int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, int *buflen, char *buf, struct thread *td); +int vn_extattr_set(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, int buflen, char *buf, struct thread *td); +int vn_extattr_rm(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, struct thread *td); +int vn_vget_ino(struct vnode *vp, ino_t ino, int lkflags, + struct vnode **rvp); +int vn_vget_ino_gen(struct vnode *vp, vn_get_ino_t alloc, + void *alloc_arg, int lkflags, struct vnode **rvp); +int vn_utimes_perm(struct vnode *vp, struct vattr *vap, + struct ucred *cred, struct thread *td); + +int vn_io_fault_uiomove(char *data, int xfersize, struct uio *uio); +int vn_io_fault_pgmove(vm_page_t ma[], vm_offset_t offset, int xfersize, + struct uio *uio); + +#define vn_rangelock_unlock(vp, cookie) \ + rangelock_unlock(&(vp)->v_rl, (cookie), VI_MTX(vp)) +#define vn_rangelock_unlock_range(vp, cookie, start, end) \ + rangelock_unlock_range(&(vp)->v_rl, (cookie), (start), (end), \ + VI_MTX(vp)) +#define vn_rangelock_rlock(vp, start, end) \ + rangelock_rlock(&(vp)->v_rl, (start), (end), VI_MTX(vp)) +#define vn_rangelock_wlock(vp, start, end) \ + rangelock_wlock(&(vp)->v_rl, (start), (end), VI_MTX(vp)) + +int vfs_cache_lookup(struct vop_lookup_args *ap); +void vfs_timestamp(struct timespec *); +void vfs_write_resume(struct mount *mp, int flags); +int vfs_write_suspend(struct mount *mp, int flags); +int vfs_write_suspend_umnt(struct mount *mp); +void vnlru_free(int, struct vfsops *); +int vop_stdbmap(struct vop_bmap_args *); +int vop_stdfdatasync_buf(struct vop_fdatasync_args *); +int vop_stdfsync(struct vop_fsync_args *); +int vop_stdgetwritemount(struct vop_getwritemount_args *); +int vop_stdgetpages(struct vop_getpages_args *); +int vop_stdinactive(struct vop_inactive_args *); +int vop_stdislocked(struct vop_islocked_args *); +int vop_stdkqfilter(struct vop_kqfilter_args *); +int vop_stdlock(struct vop_lock1_args *); +int vop_stdputpages(struct vop_putpages_args *); +int vop_stdunlock(struct vop_unlock_args *); +int vop_nopoll(struct vop_poll_args *); +int vop_stdaccess(struct vop_access_args *ap); +int vop_stdaccessx(struct vop_accessx_args *ap); +int vop_stdadvise(struct vop_advise_args *ap); +int vop_stdadvlock(struct vop_advlock_args *ap); +int vop_stdadvlockasync(struct vop_advlockasync_args *ap); +int vop_stdadvlockpurge(struct vop_advlockpurge_args *ap); +int vop_stdallocate(struct vop_allocate_args *ap); +int vop_stdset_text(struct vop_set_text_args *ap); +int vop_stdpathconf(struct vop_pathconf_args *); +int vop_stdpoll(struct vop_poll_args *); +int vop_stdvptocnp(struct vop_vptocnp_args *ap); +int vop_stdvptofh(struct vop_vptofh_args *ap); +int vop_stdunp_bind(struct vop_unp_bind_args *ap); +int vop_stdunp_connect(struct vop_unp_connect_args *ap); +int vop_stdunp_detach(struct vop_unp_detach_args *ap); +int vop_eopnotsupp(struct vop_generic_args *ap); +int vop_ebadf(struct vop_generic_args *ap); +int vop_einval(struct vop_generic_args *ap); +int vop_enoent(struct vop_generic_args *ap); +int vop_enotty(struct vop_generic_args *ap); +int vop_null(struct vop_generic_args *ap); +int vop_panic(struct vop_generic_args *ap); +int dead_poll(struct vop_poll_args *ap); +int dead_read(struct vop_read_args *ap); +int dead_write(struct vop_write_args *ap); + +/* These are called from within the actual VOPS. */ +void vop_close_post(void *a, int rc); +void vop_create_post(void *a, int rc); +void vop_deleteextattr_post(void *a, int rc); +void vop_link_post(void *a, int rc); +void vop_lookup_post(void *a, int rc); +void vop_lookup_pre(void *a); +void vop_mkdir_post(void *a, int rc); +void vop_mknod_post(void *a, int rc); +void vop_open_post(void *a, int rc); +void vop_read_post(void *a, int rc); +void vop_readdir_post(void *a, int rc); +void vop_reclaim_post(void *a, int rc); +void vop_remove_post(void *a, int rc); +void vop_rename_post(void *a, int rc); +void vop_rename_pre(void *a); +void vop_rmdir_post(void *a, int rc); +void vop_setattr_post(void *a, int rc); +void vop_setextattr_post(void *a, int rc); +void vop_symlink_post(void *a, int rc); + +#ifdef DEBUG_VFS_LOCKS +void vop_strategy_pre(void *a); +void vop_lock_pre(void *a); +void vop_lock_post(void *a, int rc); +void vop_unlock_post(void *a, int rc); +void vop_unlock_pre(void *a); +#else +#define vop_strategy_pre(x) do { } while (0) +#define vop_lock_pre(x) do { } while (0) +#define vop_lock_post(x, y) do { } while (0) +#define vop_unlock_post(x, y) do { } while (0) +#define vop_unlock_pre(x) do { } while (0) +#endif + +void vop_rename_fail(struct vop_rename_args *ap); + +#define VOP_WRITE_PRE(ap) \ + struct vattr va; \ + int error; \ + off_t osize, ooffset, noffset; \ + \ + osize = ooffset = noffset = 0; \ + if (!VN_KNLIST_EMPTY((ap)->a_vp)) { \ + error = VOP_GETATTR((ap)->a_vp, &va, (ap)->a_cred); \ + if (error) \ + return (error); \ + ooffset = (ap)->a_uio->uio_offset; \ + osize = (off_t)va.va_size; \ + } + +#define VOP_WRITE_POST(ap, ret) \ + noffset = (ap)->a_uio->uio_offset; \ + if (noffset > ooffset && !VN_KNLIST_EMPTY((ap)->a_vp)) { \ + VFS_KNOTE_LOCKED((ap)->a_vp, NOTE_WRITE \ + | (noffset > osize ? NOTE_EXTEND : 0)); \ + } + +#define VOP_LOCK(vp, flags) VOP_LOCK1(vp, flags, __FILE__, __LINE__) + +#ifdef INVARIANTS +#define VOP_ADD_WRITECOUNT_CHECKED(vp, cnt) \ +do { \ + int error_; \ + \ + error_ = VOP_ADD_WRITECOUNT((vp), (cnt)); \ + VNASSERT(error_ == 0, (vp), ("VOP_ADD_WRITECOUNT returned %d", \ + error_)); \ +} while (0) +#define VOP_SET_TEXT_CHECKED(vp) \ +do { \ + int error_; \ + \ + error_ = VOP_SET_TEXT((vp)); \ + VNASSERT(error_ == 0, (vp), ("VOP_SET_TEXT returned %d", \ + error_)); \ +} while (0) +#define VOP_UNSET_TEXT_CHECKED(vp) \ +do { \ + int error_; \ + \ + error_ = VOP_UNSET_TEXT((vp)); \ + VNASSERT(error_ == 0, (vp), ("VOP_UNSET_TEXT returned %d", \ + error_)); \ +} while (0) +#else +#define VOP_ADD_WRITECOUNT_CHECKED(vp, cnt) VOP_ADD_WRITECOUNT((vp), (cnt)) +#define VOP_SET_TEXT_CHECKED(vp) VOP_SET_TEXT((vp)) +#define VOP_UNSET_TEXT_CHECKED(vp) VOP_UNSET_TEXT((vp)) +#endif + +void vput(struct vnode *vp); +void vrele(struct vnode *vp); +void vref(struct vnode *vp); +void vrefl(struct vnode *vp); +void vrefact(struct vnode *vp); +int vrefcnt(struct vnode *vp); +void v_addpollinfo(struct vnode *vp); + +int vnode_create_vobject(struct vnode *vp, off_t size, struct thread *td); +void vnode_destroy_vobject(struct vnode *vp); + +extern struct vop_vector fifo_specops; +extern struct vop_vector dead_vnodeops; +extern struct vop_vector default_vnodeops; + +#define VOP_PANIC ((void*)(uintptr_t)vop_panic) +#define VOP_NULL ((void*)(uintptr_t)vop_null) +#define VOP_EBADF ((void*)(uintptr_t)vop_ebadf) +#define VOP_ENOTTY ((void*)(uintptr_t)vop_enotty) +#define VOP_EINVAL ((void*)(uintptr_t)vop_einval) +#define VOP_ENOENT ((void*)(uintptr_t)vop_enoent) +#define VOP_EOPNOTSUPP ((void*)(uintptr_t)vop_eopnotsupp) + +/* fifo_vnops.c */ +int fifo_printinfo(struct vnode *); + +/* vfs_hash.c */ +typedef int vfs_hash_cmp_t(struct vnode *vp, void *arg); + +void vfs_hash_changesize(int newhashsize); +int vfs_hash_get(const struct mount *mp, u_int hash, int flags, + struct thread *td, struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg); +u_int vfs_hash_index(struct vnode *vp); +int vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td, + struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg); +void vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td, + struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg); +void vfs_hash_rehash(struct vnode *vp, u_int hash); +void vfs_hash_remove(struct vnode *vp); + +int vfs_kqfilter(struct vop_kqfilter_args *); +void vfs_mark_atime(struct vnode *vp, struct ucred *cred); +struct dirent; +int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off); + +int vfs_unixify_accmode(accmode_t *accmode); + +void vfs_unp_reclaim(struct vnode *vp); + +int setfmode(struct thread *td, struct ucred *cred, struct vnode *vp, int mode); +int setfown(struct thread *td, struct ucred *cred, struct vnode *vp, uid_t uid, + gid_t gid); +int vn_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, + struct thread *td); +int vn_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, + struct thread *td); + +void vn_fsid(struct vnode *vp, struct vattr *va); + +int vn_dir_check_exec(struct vnode *vp, struct componentname *cnp); + +#endif /* _KERNEL */ + +#endif /* !_SYS_VNODE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/vtoc.h b/lib/libc/include/any-freebsd-any/sys/vtoc.h new file mode 100644 index 000000000000..85b5fb6d6614 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/vtoc.h @@ -0,0 +1,5 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ +#include diff --git a/lib/libc/include/any-freebsd-any/sys/wait.h b/lib/libc/include/any-freebsd-any/sys/wait.h new file mode 100644 index 000000000000..e34faef3d803 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/wait.h @@ -0,0 +1,176 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)wait.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD$ + */ + +#ifndef _SYS_WAIT_H_ +#define _SYS_WAIT_H_ + +#include + +/* + * This file holds definitions relevant to the wait4 system call and the + * alternate interfaces that use it (wait, wait3, waitpid). + */ + +/* + * Macros to test the exit status returned by wait and extract the relevant + * values. + */ +#if __BSD_VISIBLE +#define WCOREFLAG 0200 +#endif +#define _W_INT(i) (i) + +#define _WSTATUS(x) (_W_INT(x) & 0177) +#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ +#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) +#define WSTOPSIG(x) (_W_INT(x) >> 8) +#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0 && (x) != 0x13) +#define WTERMSIG(x) (_WSTATUS(x)) +#define WIFEXITED(x) (_WSTATUS(x) == 0) +#define WEXITSTATUS(x) (_W_INT(x) >> 8) +#define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */ +#if __BSD_VISIBLE +#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) + +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) +#endif + +/* + * Option bits for the third argument of wait4. WNOHANG causes the + * wait to not hang if there are no stopped or terminated processes, rather + * returning an error indication in this case (pid==0). WUNTRACED + * indicates that the caller should receive status about untraced children + * which stop due to signals. If children are stopped and a wait without + * this option is done, it is as though they were still running... nothing + * about them is returned. WNOWAIT only request information about zombie, + * leaving the proc around, available for later waits. + */ +#define WNOHANG 1 /* Don't hang in wait. */ +#define WUNTRACED 2 /* Tell about stopped, untraced children. */ +#define WSTOPPED WUNTRACED /* SUS compatibility */ +#define WCONTINUED 4 /* Report a job control continued process. */ +#define WNOWAIT 8 /* Poll only. Don't delete the proc entry. */ +#define WEXITED 16 /* Wait for exited processes. */ +#define WTRAPPED 32 /* Wait for a process to hit a trap or + a breakpoint. */ + +#if __BSD_VISIBLE +#define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */ +#endif + +#ifndef _IDTYPE_T_DECLARED +typedef enum +#if __BSD_VISIBLE + idtype /* pollutes XPG4.2 namespace */ +#endif + { + /* + * These names were mostly lifted from Solaris source code and + * still use Solaris style naming to avoid breaking any + * OpenSolaris code which has been ported to FreeBSD. There + * is no clear FreeBSD counterpart for all of the names, but + * some have a clear correspondence to FreeBSD entities. + * + * The numerical values are kept synchronized with the Solaris + * values. + */ + P_PID, /* A process identifier. */ + P_PPID, /* A parent process identifier. */ + P_PGID, /* A process group identifier. */ + P_SID, /* A session identifier. */ + P_CID, /* A scheduling class identifier. */ + P_UID, /* A user identifier. */ + P_GID, /* A group identifier. */ + P_ALL, /* All processes. */ + P_LWPID, /* An LWP identifier. */ + P_TASKID, /* A task identifier. */ + P_PROJID, /* A project identifier. */ + P_POOLID, /* A pool identifier. */ + P_JAILID, /* A zone identifier. */ + P_CTID, /* A (process) contract identifier. */ + P_CPUID, /* CPU identifier. */ + P_PSETID /* Processor set identifier. */ +} idtype_t; /* The type of id_t we are using. */ + +#if __BSD_VISIBLE +#define P_ZONEID P_JAILID +#endif +#define _IDTYPE_T_DECLARED +#endif + +/* + * Tokens for special values of the "pid" parameter to wait4. + * Extended struct __wrusage to collect rusage for both the target + * process and its children within one wait6() call. + */ +#if __BSD_VISIBLE +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ +#endif /* __BSD_VISIBLE */ + +#if defined(_KERNEL) || defined(_WANT_KW_EXITCODE) + +/* + * Clamp the return code to the low 8 bits from full 32 bit value. + * Should be used in kernel to construct the wait(2)-compatible process + * status to usermode. + */ +#define KW_EXITCODE(ret, sig) W_EXITCODE((ret) & 0xff, (sig)) + +#endif /* _KERNEL || _WANT_KW_EXITCODE */ + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +struct __siginfo; +pid_t wait(int *); +pid_t waitpid(pid_t, int *, int); +#if __POSIX_VISIBLE >= 200112 +int waitid(idtype_t, id_t, struct __siginfo *, int); +#endif +#if __BSD_VISIBLE +struct rusage; +struct __wrusage; +pid_t wait3(int *, int, struct rusage *); +pid_t wait4(pid_t, int *, int, struct rusage *); +pid_t wait6(idtype_t, id_t, int *, int, struct __wrusage *, + struct __siginfo *); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_WAIT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/sys/watchdog.h b/lib/libc/include/any-freebsd-any/sys/watchdog.h new file mode 100644 index 000000000000..191456a4acf2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/watchdog.h @@ -0,0 +1,125 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 Poul-Henning Kamp + * Copyright (c) 2013 iXsystems.com, + * author: Alfred Perlstein + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _SYS_WATCHDOG_H +#define _SYS_WATCHDOG_H + +#include + +#define _PATH_WATCHDOG "fido" + +#define WDIOCPATPAT _IOW('W', 42, u_int) /* pat the watchdog */ +#define WDIOC_SETTIMEOUT _IOW('W', 43, int) /* set/reset the timer */ +#define WDIOC_GETTIMEOUT _IOR('W', 44, int) /* get total timeout */ +#define WDIOC_GETTIMELEFT _IOR('W', 45, int) /* get time left */ +#define WDIOC_GETPRETIMEOUT _IOR('W', 46, int) /* get the pre-timeout */ +#define WDIOC_SETPRETIMEOUT _IOW('W', 47, int) /* set the pre-timeout */ +/* set the action when a pre-timeout occurs see: WD_SOFT_* */ +#define WDIOC_SETPRETIMEOUTACT _IOW('W', 48, int) + +/* use software watchdog instead of hardware */ +#define WDIOC_SETSOFT _IOW('W', 49, int) +#define WDIOC_SETSOFTTIMEOUTACT _IOW('W', 50, int) + +#define WD_ACTIVE 0x8000000 + /* + * Watchdog reset, timeout set to value in WD_INTERVAL field. + * The kernel will arm the watchdog and unless the userland + * program calls WDIOCPATPAT again before the timer expires + * the system will reinitialize. + */ + +#define WD_PASSIVE 0x0400000 + /* + * Set the watchdog in passive mode. + * The kernel will chose an appropriate timeout duration and + * periodically reset the timer provided everything looks all + * right to the kernel. + */ + +#define WD_LASTVAL 0x0200000 + /* + * Use the already last used timeout value. + * The kernel will use as timeout the last valid timeout provided. + */ + +#define WD_INTERVAL 0x00000ff + /* + * Mask for duration bits. + * The watchdog will have a nominal patience of 2^N * nanoseconds. + * Example: N == 30 gives a patience of 2^30 nanoseconds ~= 1 second. + * NB: Expect variance in the +/- 10-20% range. + */ + +/* Handy macros for humans not used to power of two nanoseconds */ +#define WD_TO_NEVER 0 +#define WD_TO_1MS 20 +#define WD_TO_125MS 27 +#define WD_TO_250MS 28 +#define WD_TO_500MS 29 +#define WD_TO_1SEC 30 +#define WD_TO_2SEC 31 +#define WD_TO_4SEC 32 +#define WD_TO_8SEC 33 +#define WD_TO_16SEC 34 +#define WD_TO_32SEC 35 +#define WD_TO_64SEC 36 +#define WD_TO_128SEC 37 + +/* action on pre-timeout trigger */ +#define WD_SOFT_PANIC 0x01 /* panic */ +#define WD_SOFT_DDB 0x02 /* enter debugger */ +#define WD_SOFT_LOG 0x04 /* log(9) */ +#define WD_SOFT_PRINTF 0x08 /* printf(9) */ +#define WD_SOFT_MASK 0x0f /* all of the above */ + +#ifdef _KERNEL + +#include + +typedef void (*watchdog_fn)(void *, u_int, int *); + +EVENTHANDLER_DECLARE(watchdog_list, watchdog_fn); + +u_int wdog_kern_last_timeout(void); +int wdog_kern_pat(u_int utim); + +/* + * The following function pointer is used to attach a software watchdog + * if no hardware watchdog has been attached, and if the software module + * has initialized the function pointer. + */ + +extern void (*wdog_software_attach)(void); +#endif + +#endif /* _SYS_WATCHDOG_H */ diff --git a/lib/libc/include/any-freebsd-any/sys/zlib.h b/lib/libc/include/any-freebsd-any/sys/zlib.h new file mode 100644 index 000000000000..89dad6abdecc --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sys/zlib.h @@ -0,0 +1,1020 @@ +/* $FreeBSD$ */ + +/* + * This file is derived from zlib.h and zconf.h from the zlib-1.0.4 + * distribution by Jean-loup Gailly and Mark Adler, with some additions + * by Paul Mackerras to aid in implementing Deflate compression and + * decompression for PPP packets. + */ + +/* + * ==FILEVERSION 971127== + * + * This marker is used by the Linux installation script to determine + * whether an up-to-date version of this file is already installed. + */ + + +/* +++ zlib.h */ +/*- + SPDX-License-Identifier: BSD-3-Clause + + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.0.4, Jul 24th, 1996. + + Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + gzip@prep.ai.mit.edu madler@alumni.caltech.edu +*/ +/* + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef _ZLIB_H +#define _ZLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* +++ zconf.h */ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-1996 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */ + +#ifndef _ZCONF_H +#define _ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + */ +#ifdef Z_PREFIX +# define deflateInit_ z_deflateInit_ +# define deflate z_deflate +# define deflateEnd z_deflateEnd +# define inflateInit_ z_inflateInit_ +# define inflate z_inflate +# define inflateEnd z_inflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateSetDictionary z_deflateSetDictionary +# define deflateCopy z_deflateCopy +# define deflateReset z_deflateReset +# define deflateParams z_deflateParams +# define inflateInit2_ z_inflateInit2_ +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateReset z_inflateReset +# define compress z_compress +# define uncompress z_uncompress +# define adler32 z_adler32 +#if 0 +# define crc32 z_crc32 +# define get_crc_table z_get_crc_table +#endif + +# define Byte z_Byte +# define uInt z_uInt +# define uLong z_uLong +# define Bytef z_Bytef +# define charf z_charf +# define intf z_intf +# define uIntf z_uIntf +# define uLongf z_uLongf +# define voidpf z_voidpf +# define voidp z_voidp +#endif + +#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) +# define WIN32 +#endif +#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(__i386__) +# ifndef __32BIT__ +# define __32BIT__ +# endif +#endif +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#if defined(MSDOS) && !defined(__32BIT__) +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) +# define STDC +#endif +#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC) +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2 */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + 1 << (windowBits+2) + 1 << (memLevel+9) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR __far +# else +# define FAR far +# endif +#endif +#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) +# ifndef __32BIT__ +# define SMALL_MEDIUM +# define FAR __far +# endif +#endif +#ifndef FAR +# define FAR +#endif + +typedef unsigned char Byte; /* 8 bits */ +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#if defined(__BORLANDC__) && defined(SMALL_MEDIUM) + /* Borland C/C++ ignores FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + + +/* Compile with -DZLIB_DLL for Windows DLL support */ +#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL) +# include +# define EXPORT WINAPI +#else +# define EXPORT +#endif + +#endif /* _ZCONF_H */ +/* --- zconf.h */ + +#define ZLIB_VERSION "1.0.4P" + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms may be added later and will have the same + stream interface. + + For compression the application must provide the output buffer and + may optionally provide the input buffer for optimization. For decompression, + the application must provide the input buffer and may optionally provide + the output buffer for optimization. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The library does not install any signal handler. It is recommended to + add at least a handler for SIGSEGV when decompressing; the library checks + the consistency of the input data whenever possible but may go nuts + for some forms of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: ascii or binary */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_PACKET_FLUSH 2 +#define Z_SYNC_FLUSH 3 +#define Z_FULL_FLUSH 4 +#define Z_FINISH 5 +/* Allowed flush values; see deflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_ASCII 1 +#define Z_UNKNOWN 2 +/* Possible values of the data_type field */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + /* basic functions */ + +extern const char * EXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. + */ + +/* +extern int EXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. + If zalloc and zfree are set to Z_NULL, deflateInit updates them to + use default allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at + all (the input data is simply copied a block at a time). + Z_DEFAULT_COMPRESSION requests a default compromise between speed and + compression (currently equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if level is not a valid compression level, + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). + msg is set to null if there is no error message. deflateInit does not + perform any compression: this will be done by deflate(). +*/ + + +extern int EXPORT deflate OF((z_streamp strm, int flush)); +/* + Performs one or both of the following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression + block is terminated and flushed to the output buffer so that the + decompressor can get all input data available so far. For method 9, a future + variant on method 8, the current block will be flushed but not terminated. + Z_SYNC_FLUSH has the same effect as partial flush except that the compressed + output is byte aligned (the compressor can clear its internal bit buffer) + and the current block is always terminated; this can be useful if the + compressor has to be restarted from scratch after an interruption (in which + case the internal state of the compressor may be lost). + If flush is set to Z_FULL_FLUSH, the compression block is terminated, a + special marker is output and the compression dictionary is discarded; this + is useful to allow the decompressor to synchronize if one compressed block + has been damaged (see inflateSync below). Flushing degrades compression and + so should be used only when necessary. Using Z_FULL_FLUSH too often can + seriously degrade the compression. If deflate returns with avail_out == 0, + this function must be called again with the same value of the flush + parameter and more output space (updated avail_out), until the flush is + complete (deflate returns with non-zero avail_out). + + If the parameter flush is set to Z_PACKET_FLUSH, the compression + block is terminated, and a zero-length stored block is output, + omitting the length bytes (the effect of this is that the 3-bit type + code 000 for a stored block is output, and the output is then + byte-aligned). This is designed for use at the end of a PPP packet. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + 0.1% larger than avail_in plus 12 bytes. If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() may update data_type if it can make a good guess about + the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. +*/ + + +extern int EXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +extern int EXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, inflateInit updates them to use default + allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_VERSION_ERROR if the zlib library version is incompatible + with the version assumed by the caller. msg is set to null if there is no + error message. inflateInit does not perform any decompression: this will be + done by inflate(). +*/ + +#if defined(__FreeBSD__) && defined(_KERNEL) +#define inflate _zlib104_inflate /* FreeBSD already has an inflate :-( */ +#endif + +extern int EXPORT inflate OF((z_streamp strm, int flush)); +/* + Performs one or both of the following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH, + inflate flushes as much output as possible to the output buffer. The + flushing behavior of inflate is not specified for values of the flush + parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the + current implementation actually flushes as much output as possible + anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data + has been consumed, it is expecting to see the length field of a stored + block; if not, it returns Z_DATA_ERROR. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster routine + may be used for the single inflate() call. + + inflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if the end of the + compressed data has been reached and all uncompressed output has been + produced, Z_NEED_DICT if a preset dictionary is needed at this point (see + inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted, + Z_STREAM_ERROR if the stream structure was inconsistent (for example if + next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in + the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the + application may then call inflateSync to look for a good compression block. + In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the + dictionary chosen by the compressor. +*/ + + +extern int EXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +extern int EXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by + the caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. (Method 9 will allow a 64K history buffer and + partial block flushes.) + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library (the value 16 will be allowed for method 9). Larger + values of this parameter result in better compression at the expense of + memory usage. The default value is 15 if deflateInit is used instead. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but + is slow and reduces compression ratio; memLevel=9 uses maximum memory + for optimal speed. The default value is 8. See zconf.h for total memory + usage as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match). Filtered data consists mostly of small values with a + somewhat random distribution. In this case, the compression algorithm is + tuned to compress them better. The effect of Z_FILTERED is to force more + Huffman coding and less string matching; it is somewhat intermediate + between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects + the compression ratio but not the correctness of the compressed output even + if it is not set appropriately. + + If next_in is not null, the library will use this buffer to hold also + some history information; the buffer must either hold the entire input + data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in + is null, the library will allocate its own history buffer (and leave next_in + null). next_out need not be provided here but must be provided by the + application for the next call of deflate(). + + If the history buffer is provided by the application, next_in must + must never be changed by the application since the compressor maintains + information inside this buffer from call to call; the application + must provide more input only by increasing avail_in. next_in is always + reset by the library in this case. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was + not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as + an invalid method). msg is set to null if there is no error message. + deflateInit2 does not perform any compression: this will be done by + deflate(). +*/ + +extern int EXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary (history buffer) from the given + byte sequence without producing any compressed output. This function must + be called immediately after deflateInit or deflateInit2, before any call + of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and + can be predicted with good accuracy; the data can then be compressed better + than with the default empty dictionary. In this version of the library, + only the last 32K bytes of the dictionary are used. + Upon return of this function, strm->adler is set to the Adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state + is inconsistent (for example if deflate has already been called for this + stream). deflateSetDictionary does not perform any compression: this will + be done by deflate(). +*/ + +extern int EXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. If + the source stream is using an application-supplied history buffer, a new + buffer is allocated for the destination stream. The compressed output + buffer is always application-supplied. It's the responsibility of the + application to provide the correct values of next_out and avail_out for the + next call of deflate. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +extern int EXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); +/* + Dynamically update the compression level and compression strategy. + This can be used to switch between compression and straight copy of + the input data, or to switch to a different kind of input data requiring + a different strategy. If the compression level is changed, the input + available so far is compressed with the old level (and may be flushed); + the new level will take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ + +extern int EXPORT deflateOutputPending OF((z_streamp strm)); +/* + Returns the number of bytes of output which are immediately + available from the compressor (i.e. without any further input + or flush). +*/ + +/* +extern int EXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with more compression options. The + fields next_out, zalloc, zfree and opaque must be initialized before by + the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library (the value 16 will be allowed soon). The + default value is 15 if inflateInit is used instead. If a compressed stream + with a larger window size is given as input, inflate() will return with + the error code Z_DATA_ERROR instead of trying to allocate a larger window. + + If next_out is not null, the library will use this buffer for the history + buffer; the buffer must either be large enough to hold the entire output + data, or have at least 1< +#else +#include "zlib.h" +#endif + +#ifdef _KERNEL +/* Assume this is a *BSD or SVR4 kernel */ +#include +#include +#include +#include +#include +#include +#include +# define HAVE_MEMCPY + +#else +#if defined(__KERNEL__) +/* Assume this is a Linux kernel */ +#include +#define HAVE_MEMCPY + +#else /* not kernel */ + +#if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS) +# include +# include +#else + extern int errno; +#endif +#ifdef STDC +# include +# include +#endif +#endif /* __KERNEL__ */ +#endif /* _KERNEL */ + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (const char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#ifdef MSDOS +# define OS_CODE 0x00 +# ifdef __TURBOC__ +# include +# else /* MSC or DJGPP */ +# include +# endif +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +#endif + +#ifdef WIN32 /* Window 95 & Windows NT */ +# define OS_CODE 0x0b +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define FOPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef MACOS +# define OS_CODE 0x07 +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0F +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + + /* Common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef FOPEN +# define FOPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#ifdef HAVE_STRERROR + extern char *strerror OF((int)); +# define zstrerror(errnum) strerror(errnum) +#else +# define zstrerror(errnum) "" +#endif + +#if defined(pyr) +# define NO_MEMCPY +#endif +#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + extern void zmemcpy OF((Bytef* dest, Bytef* source, uInt len)); + extern int zmemcmp OF((Bytef* s1, Bytef* s2, uInt len)); + extern void zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG_ZLIB +# include +# ifndef verbose +# define verbose 0 +# endif + extern void z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) fprintf x +# define Tracev(x) {if (verbose) fprintf x ;} +# define Tracevv(x) {if (verbose>1) fprintf x ;} +# define Tracec(c,x) {if (verbose && (c)) fprintf x ;} +# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + + +typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len)); + +voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); +void zcfree OF((voidpf opaque, voidpf ptr)); + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* _Z_UTIL_H */ diff --git a/lib/libc/include/any-freebsd-any/sysexits.h b/lib/libc/include/any-freebsd-any/sysexits.h new file mode 100644 index 000000000000..5e414f24ce8d --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sysexits.h @@ -0,0 +1,118 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD$ + */ + +#ifndef _SYSEXITS_H_ +#define _SYSEXITS_H_ + +/* + * SYSEXITS.H -- Exit status codes for system programs. + * + * This include file attempts to categorize possible error + * exit statuses for system programs, notably delivermail + * and the Berkeley network. + * + * Error numbers begin at EX__BASE to reduce the possibility of + * clashing with other exit statuses that random programs may + * already return. The meaning of the codes is approximately + * as follows: + * + * EX_USAGE -- The command was used incorrectly, e.g., with + * the wrong number of arguments, a bad flag, a bad + * syntax in a parameter, or whatever. + * EX_DATAERR -- The input data was incorrect in some way. + * This should only be used for user's data & not + * system files. + * EX_NOINPUT -- An input file (not a system file) did not + * exist or was not readable. This could also include + * errors like "No message" to a mailer (if it cared + * to catch it). + * EX_NOUSER -- The user specified did not exist. This might + * be used for mail addresses or remote logins. + * EX_NOHOST -- The host specified did not exist. This is used + * in mail addresses or network requests. + * EX_UNAVAILABLE -- A service is unavailable. This can occur + * if a support program or file does not exist. This + * can also be used as a catchall message when something + * you wanted to do doesn't work, but you don't know + * why. + * EX_SOFTWARE -- An internal software error has been detected. + * This should be limited to non-operating system related + * errors as possible. + * EX_OSERR -- An operating system error has been detected. + * This is intended to be used for such things as "cannot + * fork", "cannot create pipe", or the like. It includes + * things like getuid returning a user that does not + * exist in the passwd file. + * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, + * etc.) does not exist, cannot be opened, or has some + * sort of error (e.g., syntax error). + * EX_CANTCREAT -- A (user specified) output file cannot be + * created. + * EX_IOERR -- An error occurred while doing I/O on some file. + * EX_TEMPFAIL -- temporary failure, indicating something that + * is not really an error. In sendmail, this means + * that a mailer (e.g.) could not create a connection, + * and the request should be reattempted later. + * EX_PROTOCOL -- the remote system returned something that + * was "not possible" during a protocol exchange. + * EX_NOPERM -- You did not have sufficient permission to + * perform the operation. This is not intended for + * file system problems, which should use NOINPUT or + * CANTCREAT, but rather for higher level permissions. + */ + +#define EX_OK 0 /* successful termination */ + +#define EX__BASE 64 /* base value for error messages */ + +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ + +#define EX__MAX 78 /* maximum listed value */ + +#endif /* !_SYSEXITS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/syslog.h b/lib/libc/include/any-freebsd-any/syslog.h new file mode 120000 index 000000000000..11b106a17973 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/syslog.h @@ -0,0 +1 @@ +sys/syslog.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/tar.h b/lib/libc/include/any-freebsd-any/tar.h new file mode 100644 index 000000000000..3d54476520e6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/tar.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)tar.h 8.2 (Berkeley) 1/4/94 + * + * $FreeBSD$ + */ + +#ifndef _TAR_H +#define _TAR_H + +#define TMAGIC "ustar" /* ustar and a null */ +#define TMAGLEN 6 +#define TVERSION "00" /* 00 and no null */ +#define TVERSLEN 2 + +/* Values used in typeflag field */ +#define REGTYPE '0' /* Regular file */ +#define AREGTYPE '\0' /* Regular file */ +#define LNKTYPE '1' /* Link */ +#define SYMTYPE '2' /* Reserved */ +#define CHRTYPE '3' /* Character special */ +#define BLKTYPE '4' /* Block special */ +#define DIRTYPE '5' /* Directory */ +#define FIFOTYPE '6' /* FIFO special */ +#define CONTTYPE '7' /* Reserved */ + +/* Bits used in the mode field - values in octal */ +#define TSUID 04000 /* Set UID on execution */ +#define TSGID 02000 /* Set GID on execution */ +#define TSVTX 01000 /* Reserved */ + /* File permissions */ +#define TUREAD 00400 /* Read by owner */ +#define TUWRITE 00200 /* Write by owner */ +#define TUEXEC 00100 /* Execute/Search by owner */ +#define TGREAD 00040 /* Read by group */ +#define TGWRITE 00020 /* Write by group */ +#define TGEXEC 00010 /* Execute/Search by group */ +#define TOREAD 00004 /* Read by other */ +#define TOWRITE 00002 /* Write by other */ +#define TOEXEC 00001 /* Execute/Search by other */ + +#endif diff --git a/lib/libc/include/any-freebsd-any/termios.h b/lib/libc/include/any-freebsd-any/termios.h new file mode 100644 index 000000000000..ce31d447f60a --- /dev/null +++ b/lib/libc/include/any-freebsd-any/termios.h @@ -0,0 +1,103 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + * $FreeBSD$ + */ + +#ifndef _TERMIOS_H_ +#define _TERMIOS_H_ + +#include +#include +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#if __BSD_VISIBLE +#define OXTABS TAB3 +#define MDMBUF CCAR_OFLOW +#endif + +#if __BSD_VISIBLE +#define CCEQ(val, c) ((c) == (val) && (val) != _POSIX_VDISABLE) +#endif + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#if __BSD_VISIBLE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#if __POSIX_VISIBLE >= 200112 +pid_t tcgetsid(int); +#endif +#if __BSD_VISIBLE +int tcsetsid(int, pid_t); + +void cfmakeraw(struct termios *); +void cfmakesane(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif +__END_DECLS + +#endif /* !_TERMIOS_H_ */ + +#if __BSD_VISIBLE +#include +#include +#endif diff --git a/lib/libc/include/any-freebsd-any/tgmath.h b/lib/libc/include/any-freebsd-any/tgmath.h new file mode 100644 index 000000000000..bf7a61c5f320 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/tgmath.h @@ -0,0 +1,212 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Stefan Farfeleder. + * All rights reserved. + * + * Copyright (c) 2012 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _TGMATH_H_ +#define _TGMATH_H_ + +#include +#include + +/* + * This implementation of uses the two following macros, + * which are based on the macros described in C11 proposal N1404: + * __tg_impl_simple(x, y, z, fnl, fn, fnf, ...) + * Invokes fnl() if the corresponding real type of x, y or z is long + * double, fn() if it is double or any has an integer type, and fnf() + * otherwise. + * __tg_impl_full(x, y, cfnl, cfn, cfnf, fnl, fn, fnf, ...) + * Invokes [c]fnl() if the corresponding real type of x or y is long + * double, [c]fn() if it is double or any has an integer type, and + * [c]fnf() otherwise. The function with the 'c' prefix is called if + * any of x or y is a complex number. + * Both macros call the chosen function with all additional arguments passed + * to them, as given by __VA_ARGS__. + * + * Note that these macros cannot be implemented with C's ?: operator, + * because the return type of the whole expression would incorrectly be long + * double complex regardless of the argument types. + * + * The structure of the C11 implementation of these macros can in + * principle be reused for non-C11 compilers, but due to an integer + * promotion bug for complex types in GCC 4.2, simply let non-C11 + * compilers use an inefficient yet reliable version. + */ + +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + __has_extension(c_generic_selections) +#define __tg_generic(x, cfnl, cfn, cfnf, fnl, fn, fnf) \ + _Generic(x, \ + long double _Complex: cfnl, \ + double _Complex: cfn, \ + float _Complex: cfnf, \ + long double: fnl, \ + default: fn, \ + float: fnf \ + ) +#define __tg_type(x) \ + __tg_generic(x, (long double _Complex)0, (double _Complex)0, \ + (float _Complex)0, (long double)0, (double)0, (float)0) +#define __tg_impl_simple(x, y, z, fnl, fn, fnf, ...) \ + __tg_generic( \ + __tg_type(x) + __tg_type(y) + __tg_type(z), \ + fnl, fn, fnf, fnl, fn, fnf)(__VA_ARGS__) +#define __tg_impl_full(x, y, cfnl, cfn, cfnf, fnl, fn, fnf, ...) \ + __tg_generic( \ + __tg_type(x) + __tg_type(y), \ + cfnl, cfn, cfnf, fnl, fn, fnf)(__VA_ARGS__) +#elif defined(__generic) +#define __tg_generic_simple(x, fnl, fn, fnf) \ + __generic(x, long double _Complex, fnl, \ + __generic(x, double _Complex, fn, \ + __generic(x, float _Complex, fnf, \ + __generic(x, long double, fnl, \ + __generic(x, float, fnf, fn))))) +#define __tg_impl_simple(x, y, z, fnl, fn, fnf, ...) \ + __tg_generic_simple(x, \ + __tg_generic_simple(y, \ + __tg_generic_simple(z, fnl, fnl, fnl), \ + __tg_generic_simple(z, fnl, fnl, fnl), \ + __tg_generic_simple(z, fnl, fnl, fnl)), \ + __tg_generic_simple(y, \ + __tg_generic_simple(z, fnl, fnl, fnl), \ + __tg_generic_simple(z, fnl, fn , fn ), \ + __tg_generic_simple(z, fnl, fn , fn )), \ + __tg_generic_simple(y, \ + __tg_generic_simple(z, fnl, fnl, fnl), \ + __tg_generic_simple(z, fnl, fn , fn ), \ + __tg_generic_simple(z, fnl, fn , fnf)))(__VA_ARGS__) +#define __tg_generic_full(x, cfnl, cfn, cfnf, fnl, fn, fnf) \ + __generic(x, long double _Complex, cfnl, \ + __generic(x, double _Complex, cfn, \ + __generic(x, float _Complex, cfnf, \ + __generic(x, long double, fnl, \ + __generic(x, float, fnf, fn))))) +#define __tg_impl_full(x, y, cfnl, cfn, cfnf, fnl, fn, fnf, ...) \ + __tg_generic_full(x, \ + __tg_generic_full(y, cfnl, cfnl, cfnl, cfnl, cfnl, cfnl), \ + __tg_generic_full(y, cfnl, cfn , cfn , cfnl, cfn , cfn ), \ + __tg_generic_full(y, cfnl, cfn , cfnf, cfnl, cfn , cfnf), \ + __tg_generic_full(y, cfnl, cfnl, cfnl, fnl , fnl , fnl ), \ + __tg_generic_full(y, cfnl, cfn , cfn , fnl , fn , fn ), \ + __tg_generic_full(y, cfnl, cfn , cfnf, fnl , fn , fnf )) \ + (__VA_ARGS__) +#else +#error " not implemented for this compiler" +#endif + +/* Macros to save lots of repetition below */ +#define __tg_simple(x, fn) \ + __tg_impl_simple(x, x, x, fn##l, fn, fn##f, x) +#define __tg_simple2(x, y, fn) \ + __tg_impl_simple(x, x, y, fn##l, fn, fn##f, x, y) +#define __tg_simple3(x, y, z, fn) \ + __tg_impl_simple(x, y, z, fn##l, fn, fn##f, x, y, z) +#define __tg_simplev(x, fn, ...) \ + __tg_impl_simple(x, x, x, fn##l, fn, fn##f, __VA_ARGS__) +#define __tg_full(x, fn) \ + __tg_impl_full(x, x, c##fn##l, c##fn, c##fn##f, fn##l, fn, fn##f, x) +#define __tg_full2(x, y, fn) \ + __tg_impl_full(x, y, c##fn##l, c##fn, c##fn##f, fn##l, fn, fn##f, x, y) + +/* 7.22#4 -- These macros expand to real or complex functions, depending on + * the type of their arguments. */ +#define acos(x) __tg_full(x, acos) +#define asin(x) __tg_full(x, asin) +#define atan(x) __tg_full(x, atan) +#define acosh(x) __tg_full(x, acosh) +#define asinh(x) __tg_full(x, asinh) +#define atanh(x) __tg_full(x, atanh) +#define cos(x) __tg_full(x, cos) +#define sin(x) __tg_full(x, sin) +#define tan(x) __tg_full(x, tan) +#define cosh(x) __tg_full(x, cosh) +#define sinh(x) __tg_full(x, sinh) +#define tanh(x) __tg_full(x, tanh) +#define exp(x) __tg_full(x, exp) +#define log(x) __tg_full(x, log) +#define pow(x, y) __tg_full2(x, y, pow) +#define sqrt(x) __tg_full(x, sqrt) + +/* "The corresponding type-generic macro for fabs and cabs is fabs." */ +#define fabs(x) __tg_impl_full(x, x, cabsl, cabs, cabsf, \ + fabsl, fabs, fabsf, x) + +/* 7.22#5 -- These macros are only defined for arguments with real type. */ +#define atan2(x, y) __tg_simple2(x, y, atan2) +#define cbrt(x) __tg_simple(x, cbrt) +#define ceil(x) __tg_simple(x, ceil) +#define copysign(x, y) __tg_simple2(x, y, copysign) +#define erf(x) __tg_simple(x, erf) +#define erfc(x) __tg_simple(x, erfc) +#define exp2(x) __tg_simple(x, exp2) +#define expm1(x) __tg_simple(x, expm1) +#define fdim(x, y) __tg_simple2(x, y, fdim) +#define floor(x) __tg_simple(x, floor) +#define fma(x, y, z) __tg_simple3(x, y, z, fma) +#define fmax(x, y) __tg_simple2(x, y, fmax) +#define fmin(x, y) __tg_simple2(x, y, fmin) +#define fmod(x, y) __tg_simple2(x, y, fmod) +#define frexp(x, y) __tg_simplev(x, frexp, x, y) +#define hypot(x, y) __tg_simple2(x, y, hypot) +#define ilogb(x) __tg_simple(x, ilogb) +#define ldexp(x, y) __tg_simplev(x, ldexp, x, y) +#define lgamma(x) __tg_simple(x, lgamma) +#define llrint(x) __tg_simple(x, llrint) +#define llround(x) __tg_simple(x, llround) +#define log10(x) __tg_simple(x, log10) +#define log1p(x) __tg_simple(x, log1p) +#define log2(x) __tg_simple(x, log2) +#define logb(x) __tg_simple(x, logb) +#define lrint(x) __tg_simple(x, lrint) +#define lround(x) __tg_simple(x, lround) +#define nearbyint(x) __tg_simple(x, nearbyint) +#define nextafter(x, y) __tg_simple2(x, y, nextafter) +#define nexttoward(x, y) __tg_simplev(x, nexttoward, x, y) +#define remainder(x, y) __tg_simple2(x, y, remainder) +#define remquo(x, y, z) __tg_impl_simple(x, x, y, remquol, remquo, \ + remquof, x, y, z) +#define rint(x) __tg_simple(x, rint) +#define round(x) __tg_simple(x, round) +#define scalbn(x, y) __tg_simplev(x, scalbn, x, y) +#define scalbln(x, y) __tg_simplev(x, scalbln, x, y) +#define tgamma(x) __tg_simple(x, tgamma) +#define trunc(x) __tg_simple(x, trunc) + +/* 7.22#6 -- These macros always expand to complex functions. */ +#define carg(x) __tg_simple(x, carg) +#define cimag(x) __tg_simple(x, cimag) +#define conj(x) __tg_simple(x, conj) +#define cproj(x) __tg_simple(x, cproj) +#define creal(x) __tg_simple(x, creal) + +#endif /* !_TGMATH_H_ */ diff --git a/lib/libc/include/any-freebsd-any/time.h b/lib/libc/include/any-freebsd-any/time.h new file mode 100644 index 000000000000..2a9bcb6a1107 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/time.h @@ -0,0 +1,222 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.3 (Berkeley) 1/21/94 + */ + +/* + * $FreeBSD$ + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include +#include +#include + +#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE +/* + * Frequency of the clock ticks reported by times(). Deprecated - use + * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.) + */ +#define CLK_TCK 128 +#endif + +/* Frequency of the clock ticks reported by clock(). */ +#define CLOCKS_PER_SEC 128 + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if __POSIX_VISIBLE >= 199309 +/* + * New in POSIX 1003.1b-1993. + */ +#ifndef _CLOCKID_T_DECLARED +typedef __clockid_t clockid_t; +#define _CLOCKID_T_DECLARED +#endif + +#ifndef _TIMER_T_DECLARED +typedef __timer_t timer_t; +#define _TIMER_T_DECLARED +#endif + +#include +#endif /* __POSIX_VISIBLE >= 199309 */ + +#if __POSIX_VISIBLE >= 200112 +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif +#endif + +/* These macros are also in sys/time.h. */ +#if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199506 +#define CLOCK_REALTIME 0 +#endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 199506 */ +#if !defined(CLOCK_VIRTUAL) && __BSD_VISIBLE +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 +#endif /* !defined(CLOCK_VIRTUAL) && __BSD_VISIBLE */ +#if !defined(CLOCK_MONOTONIC) && __POSIX_VISIBLE >= 200112 +#define CLOCK_MONOTONIC 4 +#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ +#define CLOCK_SECOND 13 /* FreeBSD-specific. */ +#define CLOCK_THREAD_CPUTIME_ID 14 +#define CLOCK_PROCESS_CPUTIME_ID 15 +#endif /* !defined(CLOCK_MONOTONIC) && __POSIX_VISIBLE >= 200112 */ + +#if __BSD_VISIBLE +#define TIMER_RELTIME 0x0 /* relative timer */ +#endif +#if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199506 +#define TIMER_ABSTIME 0x1 /* absolute timer */ +#endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 199506 */ + +struct tm { + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Savings Time flag */ + long tm_gmtoff; /* offset from UTC in seconds */ + char *tm_zone; /* timezone abbreviation */ +}; + +#if __POSIX_VISIBLE +extern char *tzname[]; +#endif + +__BEGIN_DECLS +char *asctime(const struct tm *); +clock_t clock(void); +char *ctime(const time_t *); +#ifndef _STANDALONE +double difftime(time_t, time_t); +#endif +/* XXX missing: getdate() */ +struct tm *gmtime(const time_t *); +struct tm *localtime(const time_t *); +time_t mktime(struct tm *); +size_t strftime(char * __restrict, size_t, const char * __restrict, + const struct tm * __restrict); +time_t time(time_t *); +#if __POSIX_VISIBLE >= 200112 +struct sigevent; +int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict); +int timer_delete(timer_t); +int timer_gettime(timer_t, struct itimerspec *); +int timer_getoverrun(timer_t); +int timer_settime(timer_t, int, const struct itimerspec *__restrict, + struct itimerspec *__restrict); +#endif +#if __POSIX_VISIBLE +void tzset(void); +#endif + +#if __POSIX_VISIBLE >= 199309 +int clock_getres(clockid_t, struct timespec *); +int clock_gettime(clockid_t, struct timespec *); +int clock_settime(clockid_t, const struct timespec *); +int nanosleep(const struct timespec *, struct timespec *); +#endif /* __POSIX_VISIBLE >= 199309 */ + +#if __POSIX_VISIBLE >= 200112 +int clock_getcpuclockid(pid_t, clockid_t *); +int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); +#endif + +#if __POSIX_VISIBLE >= 199506 +char *asctime_r(const struct tm *, char *); +char *ctime_r(const time_t *, char *); +struct tm *gmtime_r(const time_t *, struct tm *); +struct tm *localtime_r(const time_t *, struct tm *); +#endif + +#if __XSI_VISIBLE +char *strptime(const char * __restrict, const char * __restrict, + struct tm * __restrict); +#endif + +#if __BSD_VISIBLE +char *timezone(int, int); /* XXX XSI conflict */ +void tzsetwall(void); +time_t timelocal(struct tm * const); +time_t timegm(struct tm * const); +int timer_oshandle_np(timer_t timerid); +time_t time2posix(time_t t); +time_t posix2time(time_t t); +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif + +#if defined(__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2011 || \ + (defined(__cplusplus) && __cplusplus >= 201703) +#include +/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */ +#define TIME_UTC 1 /* time elapsed since epoch */ +int timespec_get(struct timespec *ts, int base); +#endif + +__END_DECLS + +#endif /* !_TIME_H_ */ diff --git a/lib/libc/include/any-freebsd-any/timeconv.h b/lib/libc/include/any-freebsd-any/timeconv.h new file mode 100644 index 000000000000..1298cc238e57 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/timeconv.h @@ -0,0 +1,63 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.3 (Berkeley) 1/21/94 + */ + +/* + * $FreeBSD$ + */ + +#ifndef _TIMECONV_H_ +#define _TIMECONV_H_ + +#include +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +time_t _time32_to_time(__int32_t t32); +__int32_t _time_to_time32(time_t t); +time_t _time64_to_time(__int64_t t64); +__int64_t _time_to_time64(time_t t); +long _time_to_long(time_t t); +time_t _long_to_time(long tlong); +int _time_to_int(time_t t); +time_t _int_to_time(int tint); + +#endif /* _TIMECONV_H_ */ diff --git a/lib/libc/include/any-freebsd-any/timers.h b/lib/libc/include/any-freebsd-any/timers.h new file mode 100644 index 000000000000..20f95759e26b --- /dev/null +++ b/lib/libc/include/any-freebsd-any/timers.h @@ -0,0 +1,47 @@ +/* ==== timers.h ============================================================ + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Description : Basic timers header. + * + * 1.00 94/06/13 proven + * -Started coding this file. + */ + +#ifndef _TIMERS_H_ +#define _TIMERS_H_ + +#include + +#endif diff --git a/lib/libc/include/any-freebsd-any/ttyent.h b/lib/libc/include/any-freebsd-any/ttyent.h new file mode 100644 index 000000000000..a98fbdffb86f --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ttyent.h @@ -0,0 +1,79 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ttyent.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _TTYENT_H_ +#define _TTYENT_H_ + +#define _PATH_TTYS "/etc/ttys" + +#define _TTYS_OFF "off" +#define _TTYS_ON "on" +#define _TTYS_ONIFCONSOLE "onifconsole" +#define _TTYS_ONIFEXISTS "onifexists" +#define _TTYS_SECURE "secure" +#define _TTYS_INSECURE "insecure" +#define _TTYS_WINDOW "window" +#define _TTYS_GROUP "group" +#define _TTYS_NOGROUP "none" +#define _TTYS_DIALUP "dialup" +#define _TTYS_NETWORK "network" + +struct ttyent { + char *ty_name; /* terminal device name */ + char *ty_getty; /* command to execute, usually getty */ + char *ty_type; /* terminal type for termcap */ +#define TTY_ON 0x01 /* enable logins (start ty_getty program) */ +#define TTY_SECURE 0x02 /* allow uid of 0 to login */ +#define TTY_DIALUP 0x04 /* is a dialup tty */ +#define TTY_NETWORK 0x08 /* is a network tty */ +#define TTY_IFEXISTS 0x10 /* configured as "onifexists" */ +#define TTY_IFCONSOLE 0x20 /* configured as "onifconsole" */ + int ty_status; /* status flags */ + char *ty_window; /* command to start up window manager */ + char *ty_comment; /* comment field */ + char *ty_group; /* tty group */ +}; + +#include + +__BEGIN_DECLS +struct ttyent *getttyent(void); +struct ttyent *getttynam(const char *); +int setttyent(void); +int endttyent(void); +int isdialuptty(const char *); +int isnettty(const char *); +__END_DECLS + +#endif /* !_TTYENT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/uchar.h b/lib/libc/include/any-freebsd-any/uchar.h new file mode 100644 index 000000000000..a84a58b3a2dd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/uchar.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _UCHAR_H_ +#define _UCHAR_H_ + +#include +#include + +#ifndef _CHAR16_T_DECLARED +typedef __char16_t char16_t; +#define _CHAR16_T_DECLARED +#endif + +#ifndef _CHAR32_T_DECLARED +typedef __char32_t char32_t; +#define _CHAR32_T_DECLARED +#endif + +#ifndef _MBSTATE_T_DECLARED +typedef __mbstate_t mbstate_t; +#define _MBSTATE_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +size_t c16rtomb(char * __restrict, char16_t, mbstate_t * __restrict); +size_t c32rtomb(char * __restrict, char32_t, mbstate_t * __restrict); +size_t mbrtoc16(char16_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +size_t mbrtoc32(char32_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +#if __BSD_VISIBLE || defined(_XLOCALE_H_) +#include +#endif +__END_DECLS + +#endif /* !_UCHAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/ulimit.h b/lib/libc/include/any-freebsd-any/ulimit.h new file mode 100644 index 000000000000..2579a5201518 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ulimit.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Kyle Martin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ULIMIT_H_ +#define _ULIMIT_H_ + +#include + +#define UL_GETFSIZE 1 +#define UL_SETFSIZE 2 + +__BEGIN_DECLS +long ulimit(int, ...); +__END_DECLS + +#endif /* !_ULIMIT_H_ */ diff --git a/lib/libc/include/any-freebsd-any/unistd.h b/lib/libc/include/any-freebsd-any/unistd.h new file mode 100644 index 000000000000..82a2e31e34e8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/unistd.h @@ -0,0 +1,595 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unistd.h 8.12 (Berkeley) 4/27/95 + * $FreeBSD$ + */ + +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include +#include /* XXX adds too much pollution. */ +#include +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#ifndef _USECONDS_T_DECLARED +typedef __useconds_t useconds_t; +#define _USECONDS_T_DECLARED +#endif + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_ULOCK 0 /* unlock locked section */ +#define F_LOCK 1 /* lock a section for exclusive use */ +#define F_TLOCK 2 /* test and lock a section for exclusive use */ +#define F_TEST 3 /* test a section for locks by other procs */ +#endif + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. This list includes those options which are exclusively + * implemented (or not) in user mode. Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_BARRIERS 200112L +#define _POSIX_CPUTIME 200112L +#define _POSIX_READER_WRITER_LOCKS 200112L +#define _POSIX_REGEXP 1 +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN 200112L +#define _POSIX_SPIN_LOCKS 200112L +#define _POSIX_THREAD_ATTR_STACKADDR 200112L +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L +#define _POSIX_THREAD_CPUTIME 200112L +#define _POSIX_THREAD_PRIO_INHERIT 200112L +#define _POSIX_THREAD_PRIO_PROTECT 200112L +#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L +#define _POSIX_THREAD_PROCESS_SHARED 200112L +#define _POSIX_THREAD_SAFE_FUNCTIONS -1 +#define _POSIX_THREAD_SPORADIC_SERVER -1 +#define _POSIX_THREADS 200112L +#define _POSIX_TRACE -1 +#define _POSIX_TRACE_EVENT_FILTER -1 +#define _POSIX_TRACE_INHERIT -1 +#define _POSIX_TRACE_LOG -1 +#define _POSIX2_C_BIND 200112L /* mandatory */ +#define _POSIX2_C_DEV -1 /* need c99 utility */ +#define _POSIX2_CHAR_TERM 1 +#define _POSIX2_FORT_DEV -1 /* need fort77 utility */ +#define _POSIX2_FORT_RUN 200112L +#define _POSIX2_LOCALEDEF -1 +#define _POSIX2_PBS -1 +#define _POSIX2_PBS_ACCOUNTING -1 +#define _POSIX2_PBS_CHECKPOINT -1 +#define _POSIX2_PBS_LOCATE -1 +#define _POSIX2_PBS_MESSAGE -1 +#define _POSIX2_PBS_TRACK -1 +#define _POSIX2_SW_DEV -1 /* XXX ??? */ +#define _POSIX2_UPE 200112L +#define _V6_ILP32_OFF32 -1 +#define _V6_ILP32_OFFBIG 0 +#define _V6_LP64_OFF64 0 +#define _V6_LPBIG_OFFBIG -1 + +#if __XSI_VISIBLE +#define _XOPEN_CRYPT -1 /* XXX ??? */ +#define _XOPEN_ENH_I18N -1 /* mandatory in XSI */ +#define _XOPEN_LEGACY -1 +#define _XOPEN_REALTIME -1 +#define _XOPEN_REALTIME_THREADS -1 +#define _XOPEN_UNIX -1 +#endif + +/* Define the POSIX.2 version we target for compliance. */ +#define _POSIX2_VERSION 199212L + +/* + * POSIX-style system configuration variable accessors (for the + * sysconf function). The kernel does not directly implement the + * sysconf() interface; rather, a C library stub translates references + * to sysconf() into calls to sysctl() using a giant switch statement. + * Those that are marked `user' are implemented entirely in the C + * library and never query the kernel. pathconf() is implemented + * directly by the kernel so those are not defined here. + */ +#define _SC_ARG_MAX 1 +#define _SC_CHILD_MAX 2 +#define _SC_CLK_TCK 3 +#define _SC_NGROUPS_MAX 4 +#define _SC_OPEN_MAX 5 +#define _SC_JOB_CONTROL 6 +#define _SC_SAVED_IDS 7 +#define _SC_VERSION 8 +#define _SC_BC_BASE_MAX 9 /* user */ +#define _SC_BC_DIM_MAX 10 /* user */ +#define _SC_BC_SCALE_MAX 11 /* user */ +#define _SC_BC_STRING_MAX 12 /* user */ +#define _SC_COLL_WEIGHTS_MAX 13 /* user */ +#define _SC_EXPR_NEST_MAX 14 /* user */ +#define _SC_LINE_MAX 15 /* user */ +#define _SC_RE_DUP_MAX 16 /* user */ +#define _SC_2_VERSION 17 /* user */ +#define _SC_2_C_BIND 18 /* user */ +#define _SC_2_C_DEV 19 /* user */ +#define _SC_2_CHAR_TERM 20 /* user */ +#define _SC_2_FORT_DEV 21 /* user */ +#define _SC_2_FORT_RUN 22 /* user */ +#define _SC_2_LOCALEDEF 23 /* user */ +#define _SC_2_SW_DEV 24 /* user */ +#define _SC_2_UPE 25 /* user */ +#define _SC_STREAM_MAX 26 /* user */ +#define _SC_TZNAME_MAX 27 /* user */ + +#if __POSIX_VISIBLE >= 199309 +#define _SC_ASYNCHRONOUS_IO 28 +#define _SC_MAPPED_FILES 29 +#define _SC_MEMLOCK 30 +#define _SC_MEMLOCK_RANGE 31 +#define _SC_MEMORY_PROTECTION 32 +#define _SC_MESSAGE_PASSING 33 +#define _SC_PRIORITIZED_IO 34 +#define _SC_PRIORITY_SCHEDULING 35 +#define _SC_REALTIME_SIGNALS 36 +#define _SC_SEMAPHORES 37 +#define _SC_FSYNC 38 +#define _SC_SHARED_MEMORY_OBJECTS 39 +#define _SC_SYNCHRONIZED_IO 40 +#define _SC_TIMERS 41 +#define _SC_AIO_LISTIO_MAX 42 +#define _SC_AIO_MAX 43 +#define _SC_AIO_PRIO_DELTA_MAX 44 +#define _SC_DELAYTIMER_MAX 45 +#define _SC_MQ_OPEN_MAX 46 +#define _SC_PAGESIZE 47 +#define _SC_RTSIG_MAX 48 +#define _SC_SEM_NSEMS_MAX 49 +#define _SC_SEM_VALUE_MAX 50 +#define _SC_SIGQUEUE_MAX 51 +#define _SC_TIMER_MAX 52 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _SC_2_PBS 59 /* user */ +#define _SC_2_PBS_ACCOUNTING 60 /* user */ +#define _SC_2_PBS_CHECKPOINT 61 /* user */ +#define _SC_2_PBS_LOCATE 62 /* user */ +#define _SC_2_PBS_MESSAGE 63 /* user */ +#define _SC_2_PBS_TRACK 64 /* user */ +#define _SC_ADVISORY_INFO 65 +#define _SC_BARRIERS 66 /* user */ +#define _SC_CLOCK_SELECTION 67 +#define _SC_CPUTIME 68 +#define _SC_FILE_LOCKING 69 +#define _SC_GETGR_R_SIZE_MAX 70 /* user */ +#define _SC_GETPW_R_SIZE_MAX 71 /* user */ +#define _SC_HOST_NAME_MAX 72 +#define _SC_LOGIN_NAME_MAX 73 +#define _SC_MONOTONIC_CLOCK 74 +#define _SC_MQ_PRIO_MAX 75 +#define _SC_READER_WRITER_LOCKS 76 /* user */ +#define _SC_REGEXP 77 /* user */ +#define _SC_SHELL 78 /* user */ +#define _SC_SPAWN 79 /* user */ +#define _SC_SPIN_LOCKS 80 /* user */ +#define _SC_SPORADIC_SERVER 81 +#define _SC_THREAD_ATTR_STACKADDR 82 /* user */ +#define _SC_THREAD_ATTR_STACKSIZE 83 /* user */ +#define _SC_THREAD_CPUTIME 84 /* user */ +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 85 /* user */ +#define _SC_THREAD_KEYS_MAX 86 /* user */ +#define _SC_THREAD_PRIO_INHERIT 87 /* user */ +#define _SC_THREAD_PRIO_PROTECT 88 /* user */ +#define _SC_THREAD_PRIORITY_SCHEDULING 89 /* user */ +#define _SC_THREAD_PROCESS_SHARED 90 /* user */ +#define _SC_THREAD_SAFE_FUNCTIONS 91 /* user */ +#define _SC_THREAD_SPORADIC_SERVER 92 /* user */ +#define _SC_THREAD_STACK_MIN 93 /* user */ +#define _SC_THREAD_THREADS_MAX 94 /* user */ +#define _SC_TIMEOUTS 95 /* user */ +#define _SC_THREADS 96 /* user */ +#define _SC_TRACE 97 /* user */ +#define _SC_TRACE_EVENT_FILTER 98 /* user */ +#define _SC_TRACE_INHERIT 99 /* user */ +#define _SC_TRACE_LOG 100 /* user */ +#define _SC_TTY_NAME_MAX 101 /* user */ +#define _SC_TYPED_MEMORY_OBJECTS 102 +#define _SC_V6_ILP32_OFF32 103 /* user */ +#define _SC_V6_ILP32_OFFBIG 104 /* user */ +#define _SC_V6_LP64_OFF64 105 /* user */ +#define _SC_V6_LPBIG_OFFBIG 106 /* user */ +#define _SC_IPV6 118 +#define _SC_RAW_SOCKETS 119 +#define _SC_SYMLOOP_MAX 120 +#endif + +#if __XSI_VISIBLE +#define _SC_ATEXIT_MAX 107 /* user */ +#define _SC_IOV_MAX 56 +#define _SC_PAGE_SIZE _SC_PAGESIZE +#define _SC_XOPEN_CRYPT 108 /* user */ +#define _SC_XOPEN_ENH_I18N 109 /* user */ +#define _SC_XOPEN_LEGACY 110 /* user */ +#define _SC_XOPEN_REALTIME 111 +#define _SC_XOPEN_REALTIME_THREADS 112 +#define _SC_XOPEN_SHM 113 +#define _SC_XOPEN_STREAMS 114 +#define _SC_XOPEN_UNIX 115 +#define _SC_XOPEN_VERSION 116 +#define _SC_XOPEN_XCU_VERSION 117 /* user */ +#endif + +#if __BSD_VISIBLE +#define _SC_NPROCESSORS_CONF 57 +#define _SC_NPROCESSORS_ONLN 58 +#define _SC_CPUSET_SIZE 122 +#endif + +/* Extensions found in Solaris and Linux. */ +#define _SC_PHYS_PAGES 121 + +/* Keys for the confstr(3) function. */ +#if __POSIX_VISIBLE >= 199209 +#define _CS_PATH 1 /* default value of PATH */ +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 4 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 8 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 9 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 10 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 11 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 12 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 13 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14 +#endif + +__BEGIN_DECLS +/* 1003.1-1990 */ +void _exit(int) __dead2; +int access(const char *, int); +unsigned int alarm(unsigned int); +int chdir(const char *); +int chown(const char *, uid_t, gid_t); +int close(int); +void closefrom(int); +int dup(int); +int dup2(int, int); +int execl(const char *, const char *, ...) __null_sentinel; +int execle(const char *, const char *, ...); +int execlp(const char *, const char *, ...) __null_sentinel; +int execv(const char *, char * const *); +int execve(const char *, char * const *, char * const *); +int execvp(const char *, char * const *); +pid_t fork(void); +long fpathconf(int, int); +char *getcwd(char *, size_t); +gid_t getegid(void); +uid_t geteuid(void); +gid_t getgid(void); +int getgroups(int, gid_t []); +char *getlogin(void); +pid_t getpgrp(void); +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +int isatty(int); +int link(const char *, const char *); +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +off_t lseek(int, off_t, int); +#endif +long pathconf(const char *, int); +int pause(void); +int pipe(int *); +ssize_t read(int, void *, size_t); +int rmdir(const char *); +int setgid(gid_t); +int setpgid(pid_t, pid_t); +pid_t setsid(void); +int setuid(uid_t); +unsigned int sleep(unsigned int); +long sysconf(int); +pid_t tcgetpgrp(int); +int tcsetpgrp(int, pid_t); +char *ttyname(int); +int ttyname_r(int, char *, size_t); +int unlink(const char *); +ssize_t write(int, const void *, size_t); + +/* 1003.2-1992 */ +#if __POSIX_VISIBLE >= 199209 || __XSI_VISIBLE +size_t confstr(int, char *, size_t); +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +#endif /* _GETOPT_DECLARED */ +#endif + +/* ISO/IEC 9945-1: 1996 */ +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE +int fsync(int); +int fdatasync(int); + +/* + * ftruncate() was in the POSIX Realtime Extension (it's used for shared + * memory), but truncate() was not. + */ +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, off_t); +#endif +#endif + +#if __POSIX_VISIBLE >= 199506 +int getlogin_r(char *, size_t); +#endif + +/* 1003.1-2001 */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +int fchown(int, uid_t, gid_t); +ssize_t readlink(const char * __restrict, char * __restrict, size_t); +#endif +#if __POSIX_VISIBLE >= 200112 +int gethostname(char *, size_t); +int setegid(gid_t); +int seteuid(uid_t); +#endif + +/* 1003.1-2008 */ +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE +int getsid(pid_t _pid); +int fchdir(int); +int getpgid(pid_t _pid); +int lchown(const char *, uid_t, gid_t); +ssize_t pread(int, void *, size_t, off_t); +ssize_t pwrite(int, const void *, size_t, off_t); + +/* See comment at ftruncate() above. */ +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, off_t); +#endif +#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +int faccessat(int, const char *, int, int); +int fchownat(int, const char *, uid_t, gid_t, int); +int fexecve(int, char *const [], char *const []); +int linkat(int, const char *, int, const char *, int); +ssize_t readlinkat(int, const char * __restrict, char * __restrict, size_t); +int symlinkat(const char *, int, const char *); +int unlinkat(int, const char *, int); +#endif /* __POSIX_VISIBLE >= 200809 */ + +/* + * symlink() was originally in POSIX.1a, which was withdrawn after + * being overtaken by events (1003.1-2001). It was in XPG4.2, and of + * course has been in BSD since 4.2. + */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 402 +int symlink(const char * __restrict, const char * __restrict); +#endif + +/* X/Open System Interfaces */ +#if __XSI_VISIBLE +char *crypt(const char *, const char *); +long gethostid(void); +int lockf(int, int, off_t); +int nice(int); +int setregid(gid_t, gid_t); +int setreuid(uid_t, uid_t); + +#ifndef _SWAB_DECLARED +#define _SWAB_DECLARED +void swab(const void * __restrict, void * __restrict, ssize_t); +#endif /* _SWAB_DECLARED */ + +void sync(void); + +#endif /* __XSI_VISIBLE */ + +#if (__XSI_VISIBLE && __XSI_VISIBLE <= 500) || __BSD_VISIBLE +int brk(const void *); +int chroot(const char *); +int getdtablesize(void); +int getpagesize(void) __pure2; +char *getpass(const char *); +void *sbrk(intptr_t); +#endif + +#if (__XSI_VISIBLE && __XSI_VISIBLE <= 600) || __BSD_VISIBLE +char *getwd(char *); /* obsoleted by getcwd() */ +useconds_t + ualarm(useconds_t, useconds_t); +int usleep(useconds_t); +pid_t vfork(void) __returns_twice; +#endif + +#if __BSD_VISIBLE +struct timeval; /* select(2) */ + +struct crypt_data { + int initialized; /* For compatibility with glibc. */ + char __buf[256]; /* Buffer returned by crypt_r(). */ +}; + +int acct(const char *); +int async_daemon(void); +int check_utility_compat(const char *); +int close_range(unsigned int, unsigned int, int); +const char * + crypt_get_format(void); +char *crypt_r(const char *, const char *, struct crypt_data *); +int crypt_set_format(const char *); +int dup3(int, int, int); +int eaccess(const char *, int); +void endusershell(void); +int exect(const char *, char * const *, char * const *); +int execvP(const char *, const char *, char * const *); +int feature_present(const char *); +char *fflagstostr(u_long); +int getdomainname(char *, int); +int getentropy(void *, size_t); +int getgrouplist(const char *, gid_t, gid_t *, int *); +int getloginclass(char *, size_t); +mode_t getmode(const void *, mode_t); +int getosreldate(void); +int getpeereid(int, uid_t *, gid_t *); +int getresgid(gid_t *, gid_t *, gid_t *); +int getresuid(uid_t *, uid_t *, uid_t *); +char *getusershell(void); +int initgroups(const char *, gid_t); +int iruserok(unsigned long, int, const char *, const char *); +int iruserok_sa(const void *, int, int, const char *, const char *); +int issetugid(void); +void __FreeBSD_libc_enter_restricted_mode(void); +long lpathconf(const char *, int); +#ifndef _MKDTEMP_DECLARED +char *mkdtemp(char *); +#define _MKDTEMP_DECLARED +#endif +#ifndef _MKNOD_DECLARED +int mknod(const char *, mode_t, dev_t); +#define _MKNOD_DECLARED +#endif +#ifndef _MKSTEMP_DECLARED +int mkstemp(char *); +#define _MKSTEMP_DECLARED +#endif +int mkstemps(char *, int); +#ifndef _MKTEMP_DECLARED +char *mktemp(char *); +#define _MKTEMP_DECLARED +#endif +int nfssvc(int, void *); +int nlm_syscall(int, int, int, char **); +int pipe2(int *, int); +int profil(char *, size_t, vm_offset_t, int); +int rcmd(char **, int, const char *, const char *, const char *, int *); +int rcmd_af(char **, int, const char *, + const char *, const char *, int *, int); +int rcmdsh(char **, int, const char *, + const char *, const char *, const char *); +char *re_comp(const char *); +int re_exec(const char *); +int reboot(int); +int revoke(const char *); +pid_t rfork(int) __returns_twice; +pid_t rfork_thread(int, void *, int (*)(void *), void *); +int rresvport(int *); +int rresvport_af(int *, int); +int ruserok(const char *, int, const char *, const char *); +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif +int setdomainname(const char *, int); +int setgroups(int, const gid_t *); +void sethostid(long); +int sethostname(const char *, int); +int setlogin(const char *); +int setloginclass(const char *); +void *setmode(const char *); +int setpgrp(pid_t, pid_t); /* obsoleted by setpgid() */ +void setproctitle(const char *_fmt, ...) __printf0like(1, 2); +void setproctitle_fast(const char *_fmt, ...) __printf0like(1, 2); +int setresgid(gid_t, gid_t, gid_t); +int setresuid(uid_t, uid_t, uid_t); +int setrgid(gid_t); +int setruid(uid_t); +void setusershell(void); +int strtofflags(char **, u_long *, u_long *); +int swapon(const char *); +int swapoff(const char *); +int syscall(int, ...); +off_t __syscall(quad_t, ...); +int undelete(const char *); +int unwhiteout(const char *); +void *valloc(size_t); /* obsoleted by malloc() */ + +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED +extern int optreset; /* getopt(3) external variable */ +#endif +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_UNISTD_H_ */ diff --git a/lib/libc/include/any-freebsd-any/unwind.h b/lib/libc/include/any-freebsd-any/unwind.h new file mode 100644 index 000000000000..5a07fd819f50 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/unwind.h @@ -0,0 +1,160 @@ +/* $FreeBSD$ */ + +/*- + libunwind - a platform-independent unwind library + + SPDX-License-Identifier: ISC + + Copyright (C) 2003 Hewlett-Packard Co + Contributed by David Mosberger-Tang + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _UNWIND_H +#define _UNWIND_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Minimal interface as per C++ ABI draft standard: + + http://www.codesourcery.com/cxx-abi/abi-eh.html */ + +typedef enum + { + _URC_NO_REASON = 0, + _URC_FOREIGN_EXCEPTION_CAUGHT = 1, + _URC_FATAL_PHASE2_ERROR = 2, + _URC_FATAL_PHASE1_ERROR = 3, + _URC_NORMAL_STOP = 4, + _URC_END_OF_STACK = 5, + _URC_HANDLER_FOUND = 6, + _URC_INSTALL_CONTEXT = 7, + _URC_CONTINUE_UNWIND = 8 + } +_Unwind_Reason_Code; + +typedef int _Unwind_Action; + +#define _UA_SEARCH_PHASE 1 +#define _UA_CLEANUP_PHASE 2 +#define _UA_HANDLER_FRAME 4 +#define _UA_FORCE_UNWIND 8 + +struct _Unwind_Context; /* opaque data-structure */ +struct _Unwind_Exception; /* forward-declaration */ + +typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, + struct _Unwind_Exception *); + +typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action, + __int64_t, + struct _Unwind_Exception *, + struct _Unwind_Context *, + void *); + +/* The C++ ABI requires exception_class, private_1, and private_2 to + be of type uint64 and the entire structure to be + double-word-aligned, but that seems a bit overly IA-64-specific. + Using "unsigned long" instead should give us the desired effect on + IA-64, while being more general. */ +struct _Unwind_Exception + { + __int64_t exception_class; + _Unwind_Exception_Cleanup_Fn exception_cleanup; + unsigned long private_1; + unsigned long private_2; + }; + +extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); +extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, + _Unwind_Stop_Fn, void *); +extern void _Unwind_Resume (struct _Unwind_Exception *); +extern void _Unwind_DeleteException (struct _Unwind_Exception *); +extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int); +extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long); +extern unsigned long _Unwind_GetIP (struct _Unwind_Context *); +extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *); +extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long); +extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*); +extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *); + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + +/* Callback for _Unwind_Backtrace(). The backtrace stops immediately + if the callback returns any value other than _URC_NO_REASON. */ +typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, + void *); + +/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why + _UA_END_OF_STACK exists. */ +# define _UA_END_OF_STACK 16 + +/* If the unwind was initiated due to a forced unwind, resume that + operation, else re-raise the exception. This is used by + __cxa_rethrow(). */ +extern _Unwind_Reason_Code + _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); + +/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why + _Unwind_GetBSP() exists. */ +extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *); + +/* Return the "canonical frame address" for the given context. + This is used by NPTL... */ +extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *); + +/* Return the base-address for data references. */ +extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *); + +/* Return the base-address for text references. */ +extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *); + +/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any + cleanup. The first frame for which the callback is invoked is the + one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace() + returns _URC_END_OF_STACK when the backtrace stopped due to + reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it + stops for any other reason. */ +extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); + +/* Find the start-address of the procedure containing the specified IP + or NULL if it cannot be found (e.g., because the function has no + unwind info). Note: there is not necessarily a one-to-one + correspondence between source-level functions and procedures: some + functions don't have unwind-info and others are split into multiple + procedures. */ +extern void *_Unwind_FindEnclosingFunction (void *); + +/* See also Linux Standard Base Spec: + http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */ + +#endif /* _GNU_SOURCE || _BSD_SOURCE */ + +#ifdef __cplusplus +}; +#endif + +#endif /* _UNWIND_H */ diff --git a/lib/libc/include/any-freebsd-any/utime.h b/lib/libc/include/any-freebsd-any/utime.h new file mode 100644 index 000000000000..ec1d28b93e31 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/utime.h @@ -0,0 +1,55 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)utime.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD$ + */ + +#ifndef _UTIME_H_ +#define _UTIME_H_ + +#include +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct utimbuf { + time_t actime; /* Access time */ + time_t modtime; /* Modification time */ +}; + +__BEGIN_DECLS +int utime(const char *, const struct utimbuf *); +__END_DECLS + +#endif /* !_UTIME_H_ */ diff --git a/lib/libc/include/any-freebsd-any/utmpx.h b/lib/libc/include/any-freebsd-any/utmpx.h new file mode 100644 index 000000000000..b71d9638d81e --- /dev/null +++ b/lib/libc/include/any-freebsd-any/utmpx.h @@ -0,0 +1,90 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2010 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _UTMPX_H_ +#define _UTMPX_H_ + +#include +#include +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +struct utmpx { + short ut_type; /* Type of entry. */ + struct timeval ut_tv; /* Time entry was made. */ + char ut_id[8]; /* Record identifier. */ + pid_t ut_pid; /* Process ID. */ + char ut_user[32]; /* User login name. */ + char ut_line[16]; /* Device name. */ +#if __BSD_VISIBLE + char ut_host[128]; /* Remote hostname. */ +#else + char __ut_host[128]; +#endif + char __ut_spare[64]; +}; + +#define EMPTY 0 /* No valid user accounting information. */ +#define BOOT_TIME 1 /* Time of system boot. */ +#define OLD_TIME 2 /* Time when system clock changed. */ +#define NEW_TIME 3 /* Time after system clock changed. */ +#define USER_PROCESS 4 /* A process. */ +#define INIT_PROCESS 5 /* A process spawned by the init process. */ +#define LOGIN_PROCESS 6 /* The session leader of a logged-in user. */ +#define DEAD_PROCESS 7 /* A session leader who has exited. */ +#if __BSD_VISIBLE +#define SHUTDOWN_TIME 8 /* Time of system shutdown. */ +#endif + +#if __BSD_VISIBLE +#define UTXDB_ACTIVE 0 /* Active login sessions. */ +#define UTXDB_LASTLOGIN 1 /* Last login sessions. */ +#define UTXDB_LOG 2 /* Log indexed by time. */ +#endif + +__BEGIN_DECLS +void endutxent(void); +struct utmpx *getutxent(void); +struct utmpx *getutxid(const struct utmpx *); +struct utmpx *getutxline(const struct utmpx *); +struct utmpx *pututxline(const struct utmpx *); +void setutxent(void); + +#if __BSD_VISIBLE +struct utmpx *getutxuser(const char *); +int setutxdb(int, const char *); +#endif +__END_DECLS + +#endif /* !_UTMPX_H_ */ diff --git a/lib/libc/include/any-freebsd-any/uuid.h b/lib/libc/include/any-freebsd-any/uuid.h new file mode 100644 index 000000000000..8056acaf7157 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/uuid.h @@ -0,0 +1,65 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002,2005 Marcel Moolenaar + * Copyright (c) 2002 Hiten Mahesh Pandya + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _UUID_H_ +#define _UUID_H_ + +#include +#include + +/* + * This implementation mostly conforms to the DCE 1.1 specification. + * See Also: + * uuidgen(1), uuidgen(2), uuid(3) + */ + +/* Status codes returned by the functions. */ +#define uuid_s_ok 0 +#define uuid_s_bad_version 1 +#define uuid_s_invalid_string_uuid 2 +#define uuid_s_no_memory 3 + +__BEGIN_DECLS +int32_t uuid_compare(const uuid_t *, const uuid_t *, uint32_t *); +void uuid_create(uuid_t *, uint32_t *); +void uuid_create_nil(uuid_t *, uint32_t *); +int32_t uuid_equal(const uuid_t *, const uuid_t *, uint32_t *); +void uuid_from_string(const char *, uuid_t *, uint32_t *); +uint16_t uuid_hash(const uuid_t *, uint32_t *); +int32_t uuid_is_nil(const uuid_t *, uint32_t *); +void uuid_to_string(const uuid_t *, char **, uint32_t *); +void uuid_enc_le(void *, const uuid_t *); +void uuid_dec_le(const void *, uuid_t *); +void uuid_enc_be(void *, const uuid_t *); +void uuid_dec_be(const void *, uuid_t *); +__END_DECLS + +#endif /* _UUID_H_ */ diff --git a/lib/libc/include/any-freebsd-any/varargs.h b/lib/libc/include/any-freebsd-any/varargs.h new file mode 100644 index 000000000000..a5d59f46ddf1 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/varargs.h @@ -0,0 +1,37 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 Alexander Kabaev + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _VARARGS_H_ +#define _VARARGS_H_ + +#error " is obsolete." +#error "Change your code to use instead." + +#endif /* !_VARARGS_H_ */ diff --git a/lib/libc/include/any-freebsd-any/wchar.h b/lib/libc/include/any-freebsd-any/wchar.h new file mode 100644 index 000000000000..1c9d232d47e3 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/wchar.h @@ -0,0 +1,241 @@ +/*- + * SPDX-License-Identifier: (BSD-2-Clause AND BSD-2-Clause-NetBSD) + * + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/*- + * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: wchar.h,v 1.8 2000/12/22 05:31:42 itojun Exp $ + */ + +#ifndef _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include +#include +#include +#include <_ctype.h> + +#ifndef _MBSTATE_T_DECLARED +typedef __mbstate_t mbstate_t; +#define _MBSTATE_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE +#ifndef _VA_LIST_DECLARED +typedef __va_list va_list; +#define _VA_LIST_DECLARED +#endif +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef ___wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +#ifndef _WINT_T_DECLARED +typedef __wint_t wint_t; +#define _WINT_T_DECLARED +#endif + +#define WCHAR_MIN __WCHAR_MIN +#define WCHAR_MAX __WCHAR_MAX + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +#ifndef _STDFILE_DECLARED +#define _STDFILE_DECLARED +typedef struct __sFILE FILE; +#endif +struct tm; + +__BEGIN_DECLS +wint_t btowc(int); +wint_t fgetwc(FILE *); +wchar_t * + fgetws(wchar_t * __restrict, int, FILE * __restrict); +wint_t fputwc(wchar_t, FILE *); +int fputws(const wchar_t * __restrict, FILE * __restrict); +int fwide(FILE *, int); +int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...); +int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...); +wint_t getwc(FILE *); +wint_t getwchar(void); +size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); +size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int mbsinit(const mbstate_t *); +size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + mbstate_t * __restrict); +wint_t putwc(wchar_t, FILE *); +wint_t putwchar(wchar_t); +int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, + ...); +int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); +wint_t ungetwc(wint_t, FILE *); +int vfwprintf(FILE * __restrict, const wchar_t * __restrict, + __va_list); +int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, + __va_list); +int vwprintf(const wchar_t * __restrict, __va_list); +size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); +wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); +wchar_t *wcschr(const wchar_t *, wchar_t) __pure; +int wcscmp(const wchar_t *, const wchar_t *) __pure; +int wcscoll(const wchar_t *, const wchar_t *); +wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); +size_t wcscspn(const wchar_t *, const wchar_t *) __pure; +size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict, + const struct tm * __restrict); +size_t wcslen(const wchar_t *) __pure; +wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, + size_t); +int wcsncmp(const wchar_t *, const wchar_t *, size_t) __pure; +wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, size_t); +wchar_t *wcspbrk(const wchar_t *, const wchar_t *) __pure; +wchar_t *wcsrchr(const wchar_t *, wchar_t) __pure; +size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + mbstate_t * __restrict); +size_t wcsspn(const wchar_t *, const wchar_t *) __pure; +wchar_t *wcsstr(const wchar_t * __restrict, const wchar_t * __restrict) + __pure; +size_t wcsxfrm(wchar_t * __restrict, const wchar_t * __restrict, size_t); +int wctob(wint_t); +double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); +wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, + wchar_t ** __restrict); +long wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int); +unsigned long + wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int); +wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) __pure; +int wmemcmp(const wchar_t *, const wchar_t *, size_t) __pure; +wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); +wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); +wchar_t *wmemset(wchar_t *, wchar_t, size_t); +int wprintf(const wchar_t * __restrict, ...); +int wscanf(const wchar_t * __restrict, ...); + +#ifndef _STDSTREAM_DECLARED +extern FILE *__stdinp; +extern FILE *__stdoutp; +extern FILE *__stderrp; +#define _STDSTREAM_DECLARED +#endif + +#define getwc(fp) fgetwc(fp) +#define getwchar() fgetwc(__stdinp) +#define putwc(wc, fp) fputwc(wc, fp) +#define putwchar(wc) fputwc(wc, __stdoutp) + +#if __ISO_C_VISIBLE >= 1999 +int vfwscanf(FILE * __restrict, const wchar_t * __restrict, + __va_list); +int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, + __va_list); +int vwscanf(const wchar_t * __restrict, __va_list); +float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); +long double + wcstold(const wchar_t * __restrict, wchar_t ** __restrict); +#ifdef __LONG_LONG_SUPPORTED +/* LONGLONG */ +long long + wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int); +/* LONGLONG */ +unsigned long long + wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int); +#endif +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#if __XSI_VISIBLE +int wcswidth(const wchar_t *, size_t); +int wcwidth(wchar_t); +#define wcwidth(_c) __wcwidth(_c) +#endif + +#if __POSIX_VISIBLE >= 200809 +size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + size_t, mbstate_t * __restrict); +FILE *open_wmemstream(wchar_t **, size_t *); +wchar_t *wcpcpy(wchar_t * __restrict, const wchar_t * __restrict); +wchar_t *wcpncpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); +wchar_t *wcsdup(const wchar_t *) __malloc_like; +int wcscasecmp(const wchar_t *, const wchar_t *); +int wcsncasecmp(const wchar_t *, const wchar_t *, size_t n); +size_t wcsnlen(const wchar_t *, size_t) __pure; +size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + size_t, mbstate_t * __restrict); +#endif + +#if __BSD_VISIBLE +wchar_t *fgetwln(FILE * __restrict, size_t * __restrict); +size_t wcslcat(wchar_t *, const wchar_t *, size_t); +size_t wcslcpy(wchar_t *, const wchar_t *, size_t); +#endif + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#include +#endif +__END_DECLS + +#endif /* !_WCHAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/wctype.h b/lib/libc/include/any-freebsd-any/wctype.h new file mode 100644 index 000000000000..5882615ce048 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/wctype.h @@ -0,0 +1,127 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp + * $NetBSD: wctype.h,v 1.3 2000/12/22 14:16:16 itojun Exp $ + * $FreeBSD$ + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#include +#include + +#include <_ctype.h> + +#ifndef _WCTRANS_T +typedef int wctrans_t; +#define _WCTRANS_T +#endif + +#ifndef _WCTYPE_T +typedef unsigned long wctype_t; +#define _WCTYPE_T +#endif + +#ifndef _WINT_T_DECLARED +typedef __wint_t wint_t; +#define _WINT_T_DECLARED +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +__BEGIN_DECLS +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswctype(wint_t, wctype_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswprint(wint_t); +int iswpunct(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); +wint_t towctrans(wint_t, wctrans_t); +wint_t towlower(wint_t); +wint_t towupper(wint_t); +wctrans_t + wctrans(const char *); +wctype_t + wctype(const char *); + +#if __BSD_VISIBLE +wint_t iswascii(wint_t); +wint_t iswhexnumber(wint_t); +wint_t iswideogram(wint_t); +wint_t iswnumber(wint_t); +wint_t iswphonogram(wint_t); +wint_t iswrune(wint_t); +wint_t iswspecial(wint_t); +wint_t nextwctype(wint_t, wctype_t); +#endif + +#if __POSIX_VISIBLE >= 200809 +#define _XLOCALE_WCTYPES 1 +#include +#endif /* __POSIX_VISIBLE >= 200809 */ +__END_DECLS + +#ifndef __cplusplus +#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D|_CTYPE_N) +#define iswalpha(wc) __istype((wc), _CTYPE_A) +#define iswblank(wc) __istype((wc), _CTYPE_B) +#define iswcntrl(wc) __istype((wc), _CTYPE_C) +#define iswctype(wc, charclass) __istype((wc), (charclass)) +#define iswdigit(wc) __istype((wc), _CTYPE_D) +#define iswgraph(wc) __istype((wc), _CTYPE_G) +#define iswlower(wc) __istype((wc), _CTYPE_L) +#define iswprint(wc) __istype((wc), _CTYPE_R) +#define iswpunct(wc) __istype((wc), _CTYPE_P) +#define iswspace(wc) __istype((wc), _CTYPE_S) +#define iswupper(wc) __istype((wc), _CTYPE_U) +#define iswxdigit(wc) __istype((wc), _CTYPE_X) +#define towlower(wc) __tolower(wc) +#define towupper(wc) __toupper(wc) + +#if __BSD_VISIBLE +#define iswascii(wc) (((wc) & ~0x7F) == 0) +#define iswhexnumber(wc) __istype((wc), _CTYPE_X) /* alias of iswxdigit */ +#define iswideogram(wc) __istype((wc), _CTYPE_I) +#define iswnumber(wc) __istype((wc), _CTYPE_D|_CTYPE_N) +#define iswphonogram(wc) __istype((wc), _CTYPE_Q) +#define iswrune(wc) __istype((wc), 0xFFFFFF00L) +#define iswspecial(wc) __istype((wc), _CTYPE_T) +#endif /* __BSD_VISIBLE */ +#endif /* __cplusplus */ + +#endif /* _WCTYPE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/wordexp.h b/lib/libc/include/any-freebsd-any/wordexp.h new file mode 100644 index 000000000000..bda6ff542fb7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/wordexp.h @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _WORDEXP_H_ +#define _WORDEXP_H_ + +#include +#include + +#if __XSI_VISIBLE && !defined(_SIZE_T_DECLARED) +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct { + __size_t we_wordc; /* count of words matched */ + char **we_wordv; /* pointer to list of words */ + __size_t we_offs; /* slots to reserve in we_wordv */ + char *we_strings; /* storage for wordv strings */ + __size_t we_nbytes; /* size of we_strings */ +} wordexp_t; + +/* + * Flags for wordexp(). + */ +#define WRDE_APPEND 0x1 /* append to previously generated */ +#define WRDE_DOOFFS 0x2 /* we_offs member is valid */ +#define WRDE_NOCMD 0x4 /* disallow command substitution */ +#define WRDE_REUSE 0x8 /* reuse wordexp_t */ +#define WRDE_SHOWERR 0x10 /* don't redirect stderr to /dev/null */ +#define WRDE_UNDEF 0x20 /* disallow undefined shell vars */ + +/* + * Return values from wordexp(). + */ +#define WRDE_BADCHAR 1 /* unquoted special character */ +#define WRDE_BADVAL 2 /* undefined variable */ +#define WRDE_CMDSUB 3 /* command substitution not allowed */ +#define WRDE_NOSPACE 4 /* no memory for result */ +#if __XSI_VISIBLE +#define WRDE_NOSYS 5 /* obsolete, reserved */ +#endif +#define WRDE_SYNTAX 6 /* shell syntax error */ + +__BEGIN_DECLS +int wordexp(const char * __restrict, wordexp_t * __restrict, int); +void wordfree(wordexp_t *); +__END_DECLS + +#endif /* !_WORDEXP_H_ */ diff --git a/lib/libc/include/any-freebsd-any/xlocale.h b/lib/libc/include/any-freebsd-any/xlocale.h new file mode 100644 index 000000000000..647c43b315c9 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale.h @@ -0,0 +1,87 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _XLOCALE_H_ +#define _XLOCALE_H_ + +#include +__BEGIN_DECLS +#include + +#ifdef _STRING_H_ +#include +#endif + +#ifdef _INTTYPES_H_ +#include +#endif + +#ifdef _MONETARY_H_ +#include +#endif + +#ifdef _STDLIB_H_ +#include +#endif + +#ifdef _TIME_H_ +#include +#endif + +#ifdef _LANGINFO_H_ +#include +#endif + +#ifdef _CTYPE_H_ +#include +#endif + +#ifdef _WCTYPE_H_ +#define _XLOCALE_WCTYPES 1 +#include +#endif + +#ifdef _STDIO_H_ +#include +#endif + +#ifdef _WCHAR_H_ +#include +#endif + + + +struct lconv *localeconv_l(locale_t); +__END_DECLS + +#endif diff --git a/lib/libc/include/any-freebsd-any/xlocale/_ctype.h b/lib/libc/include/any-freebsd-any/xlocale/_ctype.h new file mode 100644 index 000000000000..bf4da73f58bd --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_ctype.h @@ -0,0 +1,205 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +#if (defined(_XLOCALE_WCTYPES) && !defined(_XLOCALE_WCTYPE_H)) || \ + (!defined(_XLOCALE_WCTYPES) && !defined(_XLOCALE_CTYPE_H)) + +#ifdef _XLOCALE_WCTYPES +#define _XLOCALE_WCTYPE_H +#else +#define _XLOCALE_CTYPE_H +#endif + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +#ifndef _XLOCALE_RUN_FUNCTIONS_DEFINED +#define _XLOCALE_RUN_FUNCTIONS_DEFINED 1 +unsigned long ___runetype_l(__ct_rune_t, locale_t) __pure; +__ct_rune_t ___tolower_l(__ct_rune_t, locale_t) __pure; +__ct_rune_t ___toupper_l(__ct_rune_t, locale_t) __pure; +_RuneLocale *__runes_for_locale(locale_t, int*); +#endif + +#ifndef _XLOCALE_INLINE +#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__) +/* GNU89 inline has nonstandard semantics. */ +#define _XLOCALE_INLINE extern __inline +#else +/* Hack to work around people who define inline away */ +#ifdef inline +#define _XLOCALE_INLINE static __inline +#else +/* Define with C++ / C99 compatible semantics */ +#define _XLOCALE_INLINE inline +#endif +#endif +#endif /* _XLOCALE_INLINE */ + +#ifdef _XLOCALE_WCTYPES +_XLOCALE_INLINE int +__maskrune_l(__ct_rune_t __c, unsigned long __f, locale_t __loc); +_XLOCALE_INLINE int +__istype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc); + +_XLOCALE_INLINE int +__maskrune_l(__ct_rune_t __c, unsigned long __f, locale_t __loc) +{ + int __limit; + _RuneLocale *runes = __runes_for_locale(__loc, &__limit); + return ((__c < 0 || __c >= _CACHED_RUNES) ? ___runetype_l(__c, __loc) : + runes->__runetype[__c]) & __f; +} + +_XLOCALE_INLINE int +__istype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc) +{ + return (!!__maskrune_l(__c, __f, __loc)); +} + +#define XLOCALE_ISCTYPE(fname, cat) \ + _XLOCALE_INLINE int isw##fname##_l(int, locale_t);\ + _XLOCALE_INLINE int isw##fname##_l(int __c, locale_t __l)\ + { return __istype_l(__c, cat, __l); } +#else +_XLOCALE_INLINE int +__sbmaskrune_l(__ct_rune_t __c, unsigned long __f, locale_t __loc); +_XLOCALE_INLINE int +__sbistype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc); + +_XLOCALE_INLINE int +__sbmaskrune_l(__ct_rune_t __c, unsigned long __f, locale_t __loc) +{ + int __limit; + _RuneLocale *runes = __runes_for_locale(__loc, &__limit); + return (__c < 0 || __c >= __limit) ? 0 : + runes->__runetype[__c] & __f; +} + +_XLOCALE_INLINE int +__sbistype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc) +{ + return (!!__sbmaskrune_l(__c, __f, __loc)); +} + +#define XLOCALE_ISCTYPE(__fname, __cat) \ + _XLOCALE_INLINE int is##__fname##_l(int, locale_t); \ + _XLOCALE_INLINE int is##__fname##_l(int __c, locale_t __l)\ + { return __sbistype_l(__c, __cat, __l); } +#endif + +XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D|_CTYPE_N) +XLOCALE_ISCTYPE(alpha, _CTYPE_A) +XLOCALE_ISCTYPE(blank, _CTYPE_B) +XLOCALE_ISCTYPE(cntrl, _CTYPE_C) +XLOCALE_ISCTYPE(digit, _CTYPE_D) +XLOCALE_ISCTYPE(graph, _CTYPE_G) +XLOCALE_ISCTYPE(hexnumber, _CTYPE_X) +XLOCALE_ISCTYPE(ideogram, _CTYPE_I) +XLOCALE_ISCTYPE(lower, _CTYPE_L) +XLOCALE_ISCTYPE(number, _CTYPE_D|_CTYPE_N) +XLOCALE_ISCTYPE(phonogram, _CTYPE_Q) +XLOCALE_ISCTYPE(print, _CTYPE_R) +XLOCALE_ISCTYPE(punct, _CTYPE_P) +XLOCALE_ISCTYPE(rune, 0xFFFFFF00L) +XLOCALE_ISCTYPE(space, _CTYPE_S) +XLOCALE_ISCTYPE(special, _CTYPE_T) +XLOCALE_ISCTYPE(upper, _CTYPE_U) +XLOCALE_ISCTYPE(xdigit, _CTYPE_X) +#undef XLOCALE_ISCTYPE + +#ifdef _XLOCALE_WCTYPES +_XLOCALE_INLINE int towlower_l(int, locale_t); +_XLOCALE_INLINE int __wcwidth_l(__ct_rune_t, locale_t); +_XLOCALE_INLINE int towupper_l(int, locale_t); + +_XLOCALE_INLINE int towlower_l(int __c, locale_t __l) +{ + int __limit; + _RuneLocale *__runes = __runes_for_locale(__l, &__limit); + return (__c < 0 || __c >= _CACHED_RUNES) ? ___tolower_l(__c, __l) : + __runes->__maplower[__c]; +} +_XLOCALE_INLINE int towupper_l(int __c, locale_t __l) +{ + int __limit; + _RuneLocale *__runes = __runes_for_locale(__l, &__limit); + return (__c < 0 || __c >= _CACHED_RUNES) ? ___toupper_l(__c, __l) : + __runes->__mapupper[__c]; +} +_XLOCALE_INLINE int +__wcwidth_l(__ct_rune_t _c, locale_t __l) +{ + unsigned int _x; + + if (_c == 0) + return (0); + _x = (unsigned int)__maskrune_l(_c, _CTYPE_SWM|_CTYPE_R, __l); + if ((_x & _CTYPE_SWM) != 0) + return ((_x & _CTYPE_SWM) >> _CTYPE_SWS); + return ((_x & _CTYPE_R) != 0 ? 1 : -1); +} +int iswctype_l(wint_t __wc, wctype_t __charclass, locale_t __l); +wctype_t wctype_l(const char *property, locale_t __l); +wint_t towctrans_l(wint_t __wc, wctrans_t desc, locale_t __l); +wint_t nextwctype_l(wint_t __wc, wctype_t wct, locale_t __l); +wctrans_t wctrans_l(const char *__charclass, locale_t __l); +#undef _XLOCALE_WCTYPES +#else +_XLOCALE_INLINE int digittoint_l(int, locale_t); +_XLOCALE_INLINE int tolower_l(int, locale_t); +_XLOCALE_INLINE int toupper_l(int, locale_t); + +_XLOCALE_INLINE int digittoint_l(int __c, locale_t __l) +{ return __sbmaskrune_l((__c), 0xFF, __l); } + +_XLOCALE_INLINE int tolower_l(int __c, locale_t __l) +{ + int __limit; + _RuneLocale *__runes = __runes_for_locale(__l, &__limit); + return (__c < 0 || __c >= __limit) ? __c : + __runes->__maplower[__c]; +} +_XLOCALE_INLINE int toupper_l(int __c, locale_t __l) +{ + int __limit; + _RuneLocale *__runes = __runes_for_locale(__l, &__limit); + return (__c < 0 || __c >= __limit) ? __c : + __runes->__mapupper[__c]; +} +#endif +#endif /* (defined(_XLOCALE_WCTYPES) && !defined(_XLOCALE_WCTYPE_H)) || \ + (!defined(_XLOCALE_WCTYPES) && !defined(_XLOCALE_CTYPE_H)) */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_inttypes.h b/lib/libc/include/any-freebsd-any/xlocale/_inttypes.h new file mode 100644 index 000000000000..2617f5ef17d7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_inttypes.h @@ -0,0 +1,46 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +/* + * Extended locale versions of the locale-aware functions from inttypes.h. + * Include before to expose these. + */ +intmax_t strtoimax_l(const char * __restrict, char ** __restrict, + int, locale_t); +uintmax_t strtoumax_l(const char * __restrict, char ** __restrict, int, + locale_t); +intmax_t wcstoimax_l(const wchar_t * __restrict, wchar_t ** __restrict, + int , locale_t); +uintmax_t wcstoumax_l(const wchar_t * __restrict, wchar_t ** __restrict, + int, locale_t); diff --git a/lib/libc/include/any-freebsd-any/xlocale/_langinfo.h b/lib/libc/include/any-freebsd-any/xlocale/_langinfo.h new file mode 100644 index 000000000000..0d44394dff23 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_langinfo.h @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _XLOCALE_LANGINFO_H +#define _XLOCALE_LANGINFO_H + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +char *nl_langinfo_l(nl_item, locale_t); + +#endif /* _XLOCALE_LANGINFO_H */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_locale.h b/lib/libc/include/any-freebsd-any/xlocale/_locale.h new file mode 100644 index 000000000000..a4e04f082fa8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_locale.h @@ -0,0 +1,59 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _XLOCALE_LOCALE_H +#define _XLOCALE_LOCALE_H + +/* Bit shifting order of LC_*_MASK should match XLC_* and LC_* order. */ +#define LC_COLLATE_MASK (1<<0) +#define LC_CTYPE_MASK (1<<1) +#define LC_MONETARY_MASK (1<<2) +#define LC_NUMERIC_MASK (1<<3) +#define LC_TIME_MASK (1<<4) +#define LC_MESSAGES_MASK (1<<5) +#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | \ + LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK) +#define LC_GLOBAL_LOCALE ((locale_t)-1) + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +locale_t duplocale(locale_t base); +void freelocale(locale_t loc); +locale_t newlocale(int mask, const char *locale, locale_t base); +const char *querylocale(int mask, locale_t loc); +locale_t uselocale(locale_t loc); + +#endif /* _XLOCALE_LOCALE_H */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_monetary.h b/lib/libc/include/any-freebsd-any/xlocale/_monetary.h new file mode 100644 index 000000000000..3cfc86b1f1a7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_monetary.h @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +#ifndef _XLOCALE_MONETARY_H +#define _XLOCALE_MONETARY_H + +ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) + __strfmonlike(4, 5); + +#endif /* _XLOCALE_MONETARY_H */ +#endif /* __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_stdio.h b/lib/libc/include/any-freebsd-any/xlocale/_stdio.h new file mode 100644 index 000000000000..2d4f6f5e2423 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_stdio.h @@ -0,0 +1,66 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +int asprintf_l(char **, locale_t, const char *, ...) __printflike(3, 4); +int dprintf_l(int, locale_t, const char * __restrict, ...) + __printflike(3, 4); +int fprintf_l(FILE * __restrict, locale_t, const char * __restrict, ...) + __printflike(3, 4); +int fscanf_l(FILE * __restrict, locale_t, const char * __restrict, ...) + __scanflike(3, 4); +int printf_l(locale_t, const char * __restrict, ...) __printflike(2, 3); +int scanf_l(locale_t, const char * __restrict, ...) __scanflike(2, 3); +int snprintf_l(char * __restrict, size_t, locale_t, + const char * __restrict, ...) __printflike(4, 5); +int sprintf_l(char * __restrict, locale_t, const char * __restrict, ...) + __printflike(3, 4); +int sscanf_l(const char * __restrict, locale_t, const char * __restrict, + ...) __scanflike(3, 4); +int vfprintf_l(FILE * __restrict, locale_t, const char * __restrict, + __va_list) __printflike(3, 0); +int vprintf_l(locale_t, const char * __restrict, __va_list) + __printflike(2, 0); +int vsprintf_l(char * __restrict, locale_t, const char * __restrict, + __va_list) __printflike(3, 0); +int vfscanf_l(FILE * __restrict, locale_t, const char * __restrict, + __va_list) __scanflike(3, 0); +int vscanf_l(locale_t, const char * __restrict, __va_list) + __scanflike(2, 0); +int vsnprintf_l(char * __restrict, size_t, locale_t, + const char * __restrict, __va_list) __printflike(4, 0); +int vsscanf_l(const char * __restrict, locale_t, const char * __restrict, + __va_list) __scanflike(3, 0); +int vdprintf_l(int, locale_t, const char * __restrict, __va_list) + __printflike(3, 0); +int vasprintf_l(char **, locale_t, const char *, __va_list) + __printflike(3, 0); diff --git a/lib/libc/include/any-freebsd-any/xlocale/_stdlib.h b/lib/libc/include/any-freebsd-any/xlocale/_stdlib.h new file mode 100644 index 000000000000..c4e5a0ca662c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_stdlib.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Extended locale versions of the locale-aware functions from stdlib.h. + * + * Include before to expose these. + */ +double atof_l(const char *, locale_t); +int atoi_l(const char *, locale_t); +long atol_l(const char *, locale_t); +long long atoll_l(const char *, locale_t); +int mblen_l(const char *, size_t, locale_t); +size_t mbstowcs_l(wchar_t * __restrict, + const char * __restrict, size_t, locale_t); +int mbtowc_l(wchar_t * __restrict, + const char * __restrict, size_t, locale_t); +double strtod_l(const char *, char **, locale_t); +float strtof_l(const char *, char **, locale_t); +long strtol_l(const char *, char **, int, locale_t); +long double strtold_l(const char *, char **, locale_t); +long long strtoll_l(const char *, char **, int, locale_t); +unsigned long strtoul_l(const char *, char **, int, locale_t); +unsigned long long strtoull_l(const char *, char **, int, locale_t); +size_t wcstombs_l(char * __restrict, + const wchar_t * __restrict, size_t, locale_t); +int wctomb_l(char *, wchar_t, locale_t); + +int ___mb_cur_max_l(locale_t); +#define MB_CUR_MAX_L(x) ((size_t)___mb_cur_max_l(x)) + diff --git a/lib/libc/include/any-freebsd-any/xlocale/_string.h b/lib/libc/include/any-freebsd-any/xlocale/_string.h new file mode 100644 index 000000000000..7fdad7562860 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_string.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +/* + * This file is included from both string.h and xlocale.h. We need to expose + * the declarations unconditionally if we are included from xlocale.h, but only + * if we are in POSIX2008 mode if included from string.h. + */ + +#ifndef _XLOCALE_STRING1_H +#define _XLOCALE_STRING1_H + +/* + * POSIX2008 functions + */ +int strcoll_l(const char *, const char *, locale_t); +size_t strxfrm_l(char *, const char *, size_t, locale_t); +#endif /* _XLOCALE_STRING1_H */ + +/* + * xlocale extensions + */ +#ifdef _XLOCALE_H_ +#ifndef _XLOCALE_STRING2_H +#define _XLOCALE_STRING2_H +char *strcasestr_l(const char *, const char *, locale_t); + +#endif /* _XLOCALE_STRING2_H */ +#endif /* _XLOCALE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_strings.h b/lib/libc/include/any-freebsd-any/xlocale/_strings.h new file mode 100644 index 000000000000..da1cff3e7077 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_strings.h @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +/* + * This file is included from both strings.h and xlocale.h. We need to expose + * the declarations unconditionally if we are included from xlocale.h, but only + * if we are in POSIX2008 mode if included from string.h. + */ + +#ifndef _XLOCALE_STRINGS1_H +#define _XLOCALE_STRINGS1_H + +/* + * POSIX2008 functions + */ +int strcasecmp_l(const char *, const char *, locale_t); +int strncasecmp_l(const char *, const char *, size_t, locale_t); +#endif /* _XLOCALE_STRINGS1_H */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_time.h b/lib/libc/include/any-freebsd-any/xlocale/_time.h new file mode 100644 index 000000000000..4b47b1aea1ff --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_time.h @@ -0,0 +1,60 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +/* + * This file is included from both locale.h and xlocale.h. We need to expose + * the declarations unconditionally if we are included from xlocale.h, but only + * if we are in POSIX2008 mode if included from locale.h. + */ +#ifndef _XLOCALE_LOCALE1_H +#define _XLOCALE_LOCALE1_H + +size_t strftime_l(char * __restrict, size_t, const char * __restrict, + const struct tm * __restrict, locale_t) __strftimelike(3, 0); + +#endif /* _XLOCALE_LOCALE1_H */ + +#ifdef _XLOCALE_H_ +#ifndef _XLOCALE_LOCALE2_H +#define _XLOCALE_LOCALE2_H + +char *strptime_l(const char * __restrict, const char * __restrict, + struct tm * __restrict, locale_t); + +#endif /* _XLOCALE_LOCALE2_H */ +#endif /* _XLOCALE_H_ */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_uchar.h b/lib/libc/include/any-freebsd-any/xlocale/_uchar.h new file mode 100644 index 000000000000..0c6ed09373f2 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_uchar.h @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +#ifndef _XLOCALE_UCHAR_H_ +#define _XLOCALE_UCHAR_H_ + +size_t c16rtomb_l(char * __restrict, char16_t, mbstate_t * __restrict, + locale_t); +size_t c32rtomb_l(char * __restrict, char32_t, mbstate_t * __restrict, + locale_t); +size_t mbrtoc16_l(char16_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict, locale_t); +size_t mbrtoc32_l(char32_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict, locale_t); + +#endif /* _XLOCALE_UCHAR_H_ */ diff --git a/lib/libc/include/any-freebsd-any/xlocale/_wchar.h b/lib/libc/include/any-freebsd-any/xlocale/_wchar.h new file mode 100644 index 000000000000..3a7261354f84 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/xlocale/_wchar.h @@ -0,0 +1,135 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011, 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by David Chisnall under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LOCALE_T_DEFINED +#define _LOCALE_T_DEFINED +typedef struct _xlocale *locale_t; +#endif + +#ifndef _XLOCALE_WCHAR1_H +#define _XLOCALE_WCHAR1_H +int wcscasecmp_l(const wchar_t *, const wchar_t *, + locale_t); +int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, + locale_t); +int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); +size_t wcsxfrm_l(wchar_t * __restrict, + const wchar_t * __restrict, size_t, locale_t); + +#endif /* _XLOCALE_WCHAR1_H */ + +/* + * Only declare the non-POSIX functions if we're included from xlocale.h. + */ + +#ifdef _XLOCALE_H_ +#ifndef _XLOCALE_WCHAR2_H +#define _XLOCALE_WCHAR2_H + +wint_t btowc_l(int, locale_t); +wint_t fgetwc_l(FILE *, locale_t); +wchar_t *fgetws_l(wchar_t * __restrict, int, FILE * __restrict, + locale_t); +wint_t fputwc_l(wchar_t, FILE *, locale_t); +int fputws_l(const wchar_t * __restrict, FILE * __restrict, + locale_t); +int fwprintf_l(FILE * __restrict, locale_t, + const wchar_t * __restrict, ...); +int fwscanf_l(FILE * __restrict, locale_t, + const wchar_t * __restrict, ...); +wint_t getwc_l(FILE *, locale_t); +wint_t getwchar_l(locale_t); +size_t mbrlen_l(const char * __restrict, size_t, + mbstate_t * __restrict, locale_t); +size_t mbrtowc_l(wchar_t * __restrict, + const char * __restrict, size_t, + mbstate_t * __restrict, locale_t); +int mbsinit_l(const mbstate_t *, locale_t); +size_t mbsrtowcs_l(wchar_t * __restrict, + const char ** __restrict, size_t, + mbstate_t * __restrict, locale_t); +wint_t putwc_l(wchar_t, FILE *, locale_t); +wint_t putwchar_l(wchar_t, locale_t); +int swprintf_l(wchar_t * __restrict, size_t n, locale_t, + const wchar_t * __restrict, ...); +int swscanf_l(const wchar_t * __restrict, locale_t, + const wchar_t * __restrict, ...); +wint_t ungetwc_l(wint_t, FILE *, locale_t); +int vfwprintf_l(FILE * __restrict, locale_t, + const wchar_t * __restrict, __va_list); +int vswprintf_l(wchar_t * __restrict, size_t n, locale_t, + const wchar_t * __restrict, __va_list); +int vwprintf_l(locale_t, const wchar_t * __restrict, + __va_list); +size_t wcrtomb_l(char * __restrict, wchar_t, + mbstate_t * __restrict, locale_t); +size_t wcsftime_l(wchar_t * __restrict, size_t, + const wchar_t * __restrict, + const struct tm * __restrict, locale_t); +size_t wcsrtombs_l(char * __restrict, + const wchar_t ** __restrict, size_t, + mbstate_t * __restrict, locale_t); +double wcstod_l(const wchar_t * __restrict, + wchar_t ** __restrict, locale_t); +long wcstol_l(const wchar_t * __restrict, + wchar_t ** __restrict, int, locale_t); +unsigned long wcstoul_l(const wchar_t * __restrict, + wchar_t ** __restrict, int, locale_t); +int wcswidth_l(const wchar_t *, size_t, locale_t); +int wctob_l(wint_t, locale_t); +int wcwidth_l(wchar_t, locale_t); +int wprintf_l(locale_t, const wchar_t * __restrict, ...); +int wscanf_l(locale_t, const wchar_t * __restrict, ...); +int vfwscanf_l(FILE * __restrict, locale_t, + const wchar_t * __restrict, __va_list); +int vswscanf_l(const wchar_t * __restrict, locale_t, + const wchar_t *__restrict, __va_list); +int vwscanf_l(locale_t, const wchar_t * __restrict, + __va_list); +float wcstof_l(const wchar_t * __restrict, + wchar_t ** __restrict, locale_t); +long double wcstold_l(const wchar_t * __restrict, + wchar_t ** __restrict, locale_t); +long long wcstoll_l(const wchar_t * __restrict, + wchar_t ** __restrict, int, locale_t); +unsigned long long wcstoull_l(const wchar_t * __restrict, + wchar_t ** __restrict, int, locale_t); +size_t mbsnrtowcs_l(wchar_t * __restrict, + const char ** __restrict, size_t, size_t, + mbstate_t * __restrict, locale_t); +size_t wcsnrtombs_l(char * __restrict, + const wchar_t ** __restrict, size_t, size_t, + mbstate_t * __restrict, locale_t); + +#endif /* _XLOCALE_WCHAR_H */ +#endif /* _XLOCALE_H_ */ From 010de1fece4920ec88d44239c2a2ba041e95281f Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 22 Mar 2021 00:21:55 -0700 Subject: [PATCH 2/5] freebsd: add x86_64 specific libc headers --- .../x86_64-freebsd-any/machine/_align.h | 6 + .../include/x86_64-freebsd-any/machine/_bus.h | 48 + .../x86_64-freebsd-any/machine/_inttypes.h | 6 + .../x86_64-freebsd-any/machine/_limits.h | 6 + .../x86_64-freebsd-any/machine/_stdint.h | 6 + .../x86_64-freebsd-any/machine/_types.h | 6 + .../machine/acpica_machdep.h | 6 + .../x86_64-freebsd-any/machine/apm_bios.h | 6 + .../include/x86_64-freebsd-any/machine/asm.h | 101 ++ .../x86_64-freebsd-any/machine/asmacros.h | 322 +++++ .../x86_64-freebsd-any/machine/atomic.h | 682 ++++++++++ .../include/x86_64-freebsd-any/machine/bus.h | 6 + .../x86_64-freebsd-any/machine/bus_dma.h | 36 + .../x86_64-freebsd-any/machine/clock.h | 46 + .../x86_64-freebsd-any/machine/counter.h | 92 ++ .../include/x86_64-freebsd-any/machine/cpu.h | 102 ++ .../x86_64-freebsd-any/machine/cpufunc.h | 1048 +++++++++++++++ .../x86_64-freebsd-any/machine/cputypes.h | 6 + .../x86_64-freebsd-any/machine/db_machdep.h | 86 ++ .../include/x86_64-freebsd-any/machine/dump.h | 6 + .../include/x86_64-freebsd-any/machine/efi.h | 78 ++ .../include/x86_64-freebsd-any/machine/elf.h | 6 + .../x86_64-freebsd-any/machine/endian.h | 6 + .../include/x86_64-freebsd-any/machine/exec.h | 40 + .../include/x86_64-freebsd-any/machine/fdt.h | 6 + .../x86_64-freebsd-any/machine/float.h | 6 + .../machine/floatingpoint.h | 45 + .../include/x86_64-freebsd-any/machine/fpu.h | 95 ++ .../x86_64-freebsd-any/machine/frame.h | 50 + .../x86_64-freebsd-any/machine/gdb_machdep.h | 56 + .../x86_64-freebsd-any/machine/ieeefp.h | 311 +++++ .../x86_64-freebsd-any/machine/in_cksum.h | 86 ++ .../x86_64-freebsd-any/machine/intr_machdep.h | 45 + .../x86_64-freebsd-any/machine/iodev.h | 48 + .../include/x86_64-freebsd-any/machine/kdb.h | 61 + .../x86_64-freebsd-any/machine/limits.h | 46 + .../x86_64-freebsd-any/machine/md_var.h | 91 ++ .../x86_64-freebsd-any/machine/memdev.h | 42 + .../x86_64-freebsd-any/machine/metadata.h | 6 + .../x86_64-freebsd-any/machine/minidump.h | 48 + .../x86_64-freebsd-any/machine/mp_watchdog.h | 36 + .../x86_64-freebsd-any/machine/nexusvar.h | 45 + .../include/x86_64-freebsd-any/machine/npx.h | 6 + .../x86_64-freebsd-any/machine/ofw_machdep.h | 6 + .../x86_64-freebsd-any/machine/param.h | 161 +++ .../x86_64-freebsd-any/machine/pc/bios.h | 126 ++ .../x86_64-freebsd-any/machine/pc/display.h | 45 + .../include/x86_64-freebsd-any/machine/pcb.h | 139 ++ .../x86_64-freebsd-any/machine/pci_cfgreg.h | 6 + .../include/x86_64-freebsd-any/machine/pcpu.h | 234 ++++ .../x86_64-freebsd-any/machine/pcpu_aux.h | 62 + .../include/x86_64-freebsd-any/machine/pmap.h | 507 ++++++++ .../x86_64-freebsd-any/machine/pmc_mdep.h | 139 ++ .../x86_64-freebsd-any/machine/ppireg.h | 51 + .../include/x86_64-freebsd-any/machine/proc.h | 122 ++ .../x86_64-freebsd-any/machine/procctl.h | 6 + .../x86_64-freebsd-any/machine/profile.h | 199 +++ .../include/x86_64-freebsd-any/machine/psl.h | 6 + .../x86_64-freebsd-any/machine/ptrace.h | 6 + .../x86_64-freebsd-any/machine/pvclock.h | 6 + .../include/x86_64-freebsd-any/machine/reg.h | 6 + .../x86_64-freebsd-any/machine/reloc.h | 51 + .../x86_64-freebsd-any/machine/resource.h | 47 + .../include/x86_64-freebsd-any/machine/runq.h | 48 + .../x86_64-freebsd-any/machine/segments.h | 108 ++ .../x86_64-freebsd-any/machine/setjmp.h | 6 + .../x86_64-freebsd-any/machine/sf_buf.h | 53 + .../include/x86_64-freebsd-any/machine/sgx.h | 64 + .../x86_64-freebsd-any/machine/sgxreg.h | 155 +++ .../x86_64-freebsd-any/machine/sigframe.h | 6 + .../x86_64-freebsd-any/machine/signal.h | 6 + .../include/x86_64-freebsd-any/machine/smp.h | 68 + .../x86_64-freebsd-any/machine/specialreg.h | 6 + .../x86_64-freebsd-any/machine/stack.h | 6 + .../x86_64-freebsd-any/machine/stdarg.h | 6 + .../x86_64-freebsd-any/machine/sysarch.h | 6 + .../x86_64-freebsd-any/machine/timerreg.h | 56 + .../include/x86_64-freebsd-any/machine/trap.h | 6 + .../include/x86_64-freebsd-any/machine/tss.h | 72 ++ .../x86_64-freebsd-any/machine/ucontext.h | 6 + .../include/x86_64-freebsd-any/machine/vdso.h | 6 + .../include/x86_64-freebsd-any/machine/vm.h | 47 + .../include/x86_64-freebsd-any/machine/vmm.h | 708 ++++++++++ .../x86_64-freebsd-any/machine/vmm_dev.h | 425 +++++++ .../machine/vmm_instruction_emul.h | 125 ++ .../x86_64-freebsd-any/machine/vmparam.h | 243 ++++ .../machine/xen/hypercall.h | 432 +++++++ .../machine/xen/synch_bitops.h | 129 ++ .../x86_64-freebsd-any/machine/xen/xen-os.h | 6 + .../include/x86_64-freebsd-any/x86/_align.h | 54 + .../x86_64-freebsd-any/x86/_inttypes.h | 223 ++++ .../include/x86_64-freebsd-any/x86/_limits.h | 103 ++ .../include/x86_64-freebsd-any/x86/_stdint.h | 193 +++ .../include/x86_64-freebsd-any/x86/_types.h | 150 +++ .../x86_64-freebsd-any/x86/acpica_machdep.h | 91 ++ .../include/x86_64-freebsd-any/x86/apicreg.h | 550 ++++++++ .../include/x86_64-freebsd-any/x86/apicvar.h | 493 +++++++ .../include/x86_64-freebsd-any/x86/apm_bios.h | 264 ++++ lib/libc/include/x86_64-freebsd-any/x86/bus.h | 1109 ++++++++++++++++ .../include/x86_64-freebsd-any/x86/bus_dma.h | 201 +++ .../x86_64-freebsd-any/x86/busdma_impl.h | 101 ++ .../include/x86_64-freebsd-any/x86/cputypes.h | 50 + .../include/x86_64-freebsd-any/x86/dump.h | 87 ++ lib/libc/include/x86_64-freebsd-any/x86/elf.h | 223 ++++ .../include/x86_64-freebsd-any/x86/endian.h | 133 ++ lib/libc/include/x86_64-freebsd-any/x86/fdt.h | 38 + .../include/x86_64-freebsd-any/x86/float.h | 100 ++ lib/libc/include/x86_64-freebsd-any/x86/fpu.h | 217 ++++ .../include/x86_64-freebsd-any/x86/frame.h | 160 +++ .../include/x86_64-freebsd-any/x86/ifunc.h | 50 + .../include/x86_64-freebsd-any/x86/init.h | 60 + .../x86_64-freebsd-any/x86/intr_machdep.h | 180 +++ .../x86_64-freebsd-any/x86/legacyvar.h | 73 ++ lib/libc/include/x86_64-freebsd-any/x86/mca.h | 58 + .../include/x86_64-freebsd-any/x86/metadata.h | 57 + .../include/x86_64-freebsd-any/x86/mptable.h | 206 +++ .../x86_64-freebsd-any/x86/ofw_machdep.h | 44 + .../x86_64-freebsd-any/x86/pci_cfgreg.h | 71 ++ .../include/x86_64-freebsd-any/x86/procctl.h | 43 + lib/libc/include/x86_64-freebsd-any/x86/psl.h | 94 ++ .../include/x86_64-freebsd-any/x86/ptrace.h | 67 + .../include/x86_64-freebsd-any/x86/pvclock.h | 59 + lib/libc/include/x86_64-freebsd-any/x86/reg.h | 269 ++++ .../include/x86_64-freebsd-any/x86/segments.h | 276 ++++ .../include/x86_64-freebsd-any/x86/setjmp.h | 52 + .../include/x86_64-freebsd-any/x86/sigframe.h | 74 ++ .../include/x86_64-freebsd-any/x86/signal.h | 165 +++ .../x86_64-freebsd-any/x86/specialreg.h | 1133 +++++++++++++++++ .../include/x86_64-freebsd-any/x86/stack.h | 61 + .../include/x86_64-freebsd-any/x86/stdarg.h | 39 + .../include/x86_64-freebsd-any/x86/sysarch.h | 167 +++ .../include/x86_64-freebsd-any/x86/trap.h | 72 ++ .../include/x86_64-freebsd-any/x86/ucode.h | 68 + .../include/x86_64-freebsd-any/x86/ucontext.h | 167 +++ .../include/x86_64-freebsd-any/x86/vdso.h | 53 + .../include/x86_64-freebsd-any/x86/vmware.h | 52 + .../include/x86_64-freebsd-any/x86/x86_smp.h | 119 ++ .../include/x86_64-freebsd-any/x86/x86_var.h | 169 +++ .../x86_64-freebsd-any/x86/xen/xen-os.h | 38 + 139 files changed, 17182 insertions(+) create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_align.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_bus.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_inttypes.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_limits.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_stdint.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/_types.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/acpica_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/apm_bios.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/asm.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/asmacros.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/atomic.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/bus.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/bus_dma.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/clock.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/counter.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/cpu.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/cpufunc.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/cputypes.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/db_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/dump.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/efi.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/elf.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/endian.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/exec.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/fdt.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/float.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/floatingpoint.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/fpu.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/frame.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/gdb_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/ieeefp.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/in_cksum.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/intr_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/iodev.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/kdb.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/limits.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/md_var.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/memdev.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/metadata.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/minidump.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/mp_watchdog.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/nexusvar.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/npx.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/ofw_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/param.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pc/bios.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pc/display.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pcb.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pci_cfgreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pcpu.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pcpu_aux.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pmap.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pmc_mdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/ppireg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/proc.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/procctl.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/profile.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/psl.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/ptrace.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/pvclock.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/reg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/reloc.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/resource.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/runq.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/segments.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/setjmp.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/sf_buf.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/sgx.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/sgxreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/sigframe.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/signal.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/smp.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/specialreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/stack.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/stdarg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/sysarch.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/timerreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/trap.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/tss.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/ucontext.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vdso.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vm.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vmm.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vmm_dev.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vmm_instruction_emul.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/vmparam.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/xen/hypercall.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/xen/synch_bitops.h create mode 100644 lib/libc/include/x86_64-freebsd-any/machine/xen/xen-os.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/_align.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/_inttypes.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/_limits.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/_stdint.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/_types.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/acpica_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/apicreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/apicvar.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/apm_bios.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/bus.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/bus_dma.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/busdma_impl.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/cputypes.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/dump.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/elf.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/endian.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/fdt.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/float.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/fpu.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/frame.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/ifunc.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/init.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/intr_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/legacyvar.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/mca.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/metadata.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/mptable.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/ofw_machdep.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/pci_cfgreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/procctl.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/psl.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/ptrace.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/pvclock.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/reg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/segments.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/setjmp.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/sigframe.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/signal.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/specialreg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/stack.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/stdarg.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/sysarch.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/trap.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/ucode.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/ucontext.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/vdso.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/vmware.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/x86_smp.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/x86_var.h create mode 100644 lib/libc/include/x86_64-freebsd-any/x86/xen/xen-os.h diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_align.h b/lib/libc/include/x86_64-freebsd-any/machine/_align.h new file mode 100644 index 000000000000..28c4669ad258 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_align.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_bus.h b/lib/libc/include/x86_64-freebsd-any/machine/_bus.h new file mode 100644 index 000000000000..73482b452e65 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_bus.h @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 M. Warner Losh. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef AMD64_INCLUDE__BUS_H +#define AMD64_INCLUDE__BUS_H + +/* + * Bus address and size types + */ +typedef uint64_t bus_addr_t; +typedef uint64_t bus_size_t; + +/* + * Access methods for bus resources and address space. + */ +typedef uint64_t bus_space_tag_t; +typedef uint64_t bus_space_handle_t; + +#endif /* AMD64_INCLUDE__BUS_H */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_inttypes.h b/lib/libc/include/x86_64-freebsd-any/machine/_inttypes.h new file mode 100644 index 000000000000..40107cd74a71 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_inttypes.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_limits.h b/lib/libc/include/x86_64-freebsd-any/machine/_limits.h new file mode 100644 index 000000000000..3c7365bb4ed1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_limits.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_stdint.h b/lib/libc/include/x86_64-freebsd-any/machine/_stdint.h new file mode 100644 index 000000000000..db1affc0770c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_stdint.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/_types.h b/lib/libc/include/x86_64-freebsd-any/machine/_types.h new file mode 100644 index 000000000000..26803672ff6f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/_types.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/acpica_machdep.h b/lib/libc/include/x86_64-freebsd-any/machine/acpica_machdep.h new file mode 100644 index 000000000000..1ae3d5865dba --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/acpica_machdep.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/apm_bios.h b/lib/libc/include/x86_64-freebsd-any/machine/apm_bios.h new file mode 100644 index 000000000000..9cc0eeeaf6fd --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/apm_bios.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/asm.h b/lib/libc/include/x86_64-freebsd-any/machine/asm.h new file mode 100644 index 000000000000..bebc4df3d2c5 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/asm.h @@ -0,0 +1,101 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)DEFS.h 5.1 (Berkeley) 4/23/90 + * $FreeBSD$ + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#include + +#ifdef PIC +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOTPCREL(%rip) +#else +#define PIC_PLT(x) x +#endif + +/* + * CNAME and HIDENAME manage the relationship between symbol names in C + * and the equivalent assembly language names. CNAME is given a name as + * it would be used in a C program. It expands to the equivalent assembly + * language name. HIDENAME is given an assembly-language name, and expands + * to a possibly-modified form that will be invisible to C programs. + */ +#define CNAME(csym) csym +#define HIDENAME(asmsym) .asmsym + +#define _START_ENTRY .text; .p2align 4,0x90 + +#define _ENTRY(x) _START_ENTRY; \ + .globl CNAME(x); .type CNAME(x),@function; CNAME(x): + +#ifdef PROF +#define ALTENTRY(x) _ENTRY(x); \ + pushq %rbp; movq %rsp,%rbp; \ + call PIC_PLT(HIDENAME(mcount)); \ + popq %rbp; \ + jmp 9f +#define ENTRY(x) _ENTRY(x); \ + pushq %rbp; movq %rsp,%rbp; \ + call PIC_PLT(HIDENAME(mcount)); \ + popq %rbp; \ + 9: +#else +#define ALTENTRY(x) _ENTRY(x) +#define ENTRY(x) _ENTRY(x) +#endif + +#define END(x) .size x, . - x +/* + * WEAK_REFERENCE(): create a weak reference alias from sym. + * The macro is not a general asm macro that takes arbitrary names, + * but one that takes only C names. It does the non-null name + * translation inside the macro. + */ +#define WEAK_REFERENCE(sym, alias) \ + .weak CNAME(alias); \ + .equ CNAME(alias),CNAME(sym) + +#define RCSID(x) .text; .asciz x + +#undef __FBSDID +#if !defined(STRIP_FBSDID) +#define __FBSDID(s) .ident s +#else +#define __FBSDID(s) /* nothing */ +#endif /* !STRIP_FBSDID */ + +#endif /* !_MACHINE_ASM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/asmacros.h b/lib/libc/include/x86_64-freebsd-any/machine/asmacros.h new file mode 100644 index 000000000000..b8541bed310c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/asmacros.h @@ -0,0 +1,322 @@ +/* -*- mode: asm -*- */ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993 The Regents of the University of California. + * All rights reserved. + * + * Copyright (c) 2018 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by + * Konstantin Belousov under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_ASMACROS_H_ +#define _MACHINE_ASMACROS_H_ + +#include + +/* XXX too much duplication in various asm*.h's. */ + +/* + * CNAME is used to manage the relationship between symbol names in C + * and the equivalent assembly language names. CNAME is given a name as + * it would be used in a C program. It expands to the equivalent assembly + * language name. + */ +#define CNAME(csym) csym + +#define ALIGN_DATA .p2align 3 /* 8 byte alignment, zero filled */ +#ifdef GPROF +#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ +#else +#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ +#endif +#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ + +#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \ + .type CNAME(name),@function; CNAME(name): +#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) +#define NON_GPROF_RET .byte 0xc3 /* opcode for `ret' */ + +#define END(name) .size name, . - name + +#ifdef GPROF +/* + * __mcount is like [.]mcount except that doesn't require its caller to set + * up a frame pointer. It must be called before pushing anything onto the + * stack. gcc should eventually generate code to call __mcount in most + * cases. This would make -pg in combination with -fomit-frame-pointer + * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to + * allow profiling before setting up the frame pointer, but this is + * inadequate for good handling of special cases, e.g., -fpic works best + * with profiling after the prologue. + * + * [.]mexitcount is a new function to support non-statistical profiling if an + * accurate clock is available. For C sources, calls to it are generated + * by the FreeBSD extension `-mprofiler-epilogue' to gcc. It is best to + * call [.]mexitcount at the end of a function like the MEXITCOUNT macro does, + * but gcc currently generates calls to it at the start of the epilogue to + * avoid problems with -fpic. + * + * [.]mcount and __mcount may clobber the call-used registers and %ef. + * [.]mexitcount may clobber %ecx and %ef. + * + * Cross-jumping makes non-statistical profiling timing more complicated. + * It is handled in many cases by calling [.]mexitcount before jumping. It + * is handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL(). + * It is handled for some fault-handling jumps by not sharing the exit + * routine. + * + * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to + * the main entry point. Note that alt entries are counted twice. They + * have to be counted as ordinary entries for gprof to get the call times + * right for the ordinary entries. + * + * High local labels are used in macros to avoid clashes with local labels + * in functions. + * + * Ordinary `ret' is used instead of a macro `RET' because there are a lot + * of `ret's. 0xc3 is the opcode for `ret' (`#define ret ... ret' can't + * be used because this file is sometimes preprocessed in traditional mode). + * `ret' clobbers eflags but this doesn't matter. + */ +#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f +#define CROSSJUMP(jtrue, label, jfalse) \ + jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8: +#define CROSSJUMPTARGET(label) \ + ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label +#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT +#define FAKE_MCOUNT(caller) pushq caller ; call __mcount ; popq %rcx +#define MCOUNT call __mcount +#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT +#ifdef GUPROF +#define MEXITCOUNT call .mexitcount +#define ret MEXITCOUNT ; NON_GPROF_RET +#else +#define MEXITCOUNT +#endif + +#else /* !GPROF */ +/* + * ALTENTRY() has to align because it is before a corresponding ENTRY(). + * ENTRY() has to align to because there may be no ALTENTRY() before it. + * If there is a previous ALTENTRY() then the alignment code for ENTRY() + * is empty. + */ +#define ALTENTRY(name) GEN_ENTRY(name) +#define CROSSJUMP(jtrue, label, jfalse) jtrue label +#define CROSSJUMPTARGET(label) +#define ENTRY(name) GEN_ENTRY(name) +#define FAKE_MCOUNT(caller) +#define MCOUNT +#define MCOUNT_LABEL(name) +#define MEXITCOUNT +#endif /* GPROF */ + +/* + * Convenience for adding frame pointers to hand-coded ASM. Useful for + * DTrace, HWPMC, and KDB. + */ +#define PUSH_FRAME_POINTER \ + pushq %rbp ; \ + movq %rsp, %rbp ; +#define POP_FRAME_POINTER \ + popq %rbp + +#ifdef LOCORE +/* + * Access per-CPU data. + */ +#define PCPU(member) %gs:PC_ ## member +#define PCPU_ADDR(member, reg) \ + movq %gs:PC_PRVSPACE, reg ; \ + addq $PC_ ## member, reg + +/* + * Convenience macro for declaring interrupt entry points. + */ +#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ + .type __CONCAT(X,name),@function; __CONCAT(X,name): + + .macro SAVE_SEGS + movw %fs,TF_FS(%rsp) + movw %gs,TF_GS(%rsp) + movw %es,TF_ES(%rsp) + movw %ds,TF_DS(%rsp) + .endm + + .macro MOVE_STACKS qw + .L.offset=0 + .rept \qw + movq .L.offset(%rsp),%rdx + movq %rdx,.L.offset(%rax) + .L.offset=.L.offset+8 + .endr + .endm + + .macro PTI_UUENTRY has_err + movq PCPU(KCR3),%rax + movq %rax,%cr3 + movq PCPU(RSP0),%rax + subq $PTI_SIZE - 8 * (1 - \has_err),%rax + MOVE_STACKS ((PTI_SIZE / 8) - 1 + \has_err) + movq %rax,%rsp + popq %rdx + popq %rax + .endm + + .macro PTI_UENTRY has_err + swapgs + lfence + cmpq $~0,PCPU(UCR3) + je 1f + pushq %rax + pushq %rdx + PTI_UUENTRY \has_err +1: + .endm + + .macro PTI_ENTRY name, contk, contu, has_err=0 + ALIGN_TEXT + .globl X\name\()_pti + .type X\name\()_pti,@function +X\name\()_pti: + /* %rax, %rdx, and possibly err are not yet pushed */ + testb $SEL_RPL_MASK,PTI_CS-PTI_ERR-((1-\has_err)*8)(%rsp) + jz \contk + PTI_UENTRY \has_err + jmp \contu + .endm + + .macro PTI_INTRENTRY vec_name + SUPERALIGN_TEXT + .globl X\vec_name\()_pti + .type X\vec_name\()_pti,@function +X\vec_name\()_pti: + testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* err, %rax, %rdx not pushed */ + jz .L\vec_name\()_u + PTI_UENTRY has_err=0 + jmp .L\vec_name\()_u + .endm + + .macro INTR_PUSH_FRAME vec_name + SUPERALIGN_TEXT + .globl X\vec_name + .type X\vec_name,@function +X\vec_name: + testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* come from kernel? */ + jz .L\vec_name\()_u /* Yes, dont swapgs again */ + swapgs +.L\vec_name\()_u: + lfence + subq $TF_RIP,%rsp /* skip dummy tf_err and tf_trapno */ + movq %rdi,TF_RDI(%rsp) + movq %rsi,TF_RSI(%rsp) + movq %rdx,TF_RDX(%rsp) + movq %rcx,TF_RCX(%rsp) + movq %r8,TF_R8(%rsp) + movq %r9,TF_R9(%rsp) + movq %rax,TF_RAX(%rsp) + movq %rbx,TF_RBX(%rsp) + movq %rbp,TF_RBP(%rsp) + movq %r10,TF_R10(%rsp) + movq %r11,TF_R11(%rsp) + movq %r12,TF_R12(%rsp) + movq %r13,TF_R13(%rsp) + movq %r14,TF_R14(%rsp) + movq %r15,TF_R15(%rsp) + SAVE_SEGS + movl $TF_HASSEGS,TF_FLAGS(%rsp) + pushfq + andq $~(PSL_D|PSL_AC),(%rsp) + popfq + testb $SEL_RPL_MASK,TF_CS(%rsp) /* come from kernel ? */ + jz 1f /* yes, leave PCB_FULL_IRET alone */ + movq PCPU(CURPCB),%r8 + andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) + call handle_ibrs_entry +1: + .endm + + .macro INTR_HANDLER vec_name + .text + PTI_INTRENTRY \vec_name + INTR_PUSH_FRAME \vec_name + .endm + + .macro RESTORE_REGS + movq TF_RDI(%rsp),%rdi + movq TF_RSI(%rsp),%rsi + movq TF_RDX(%rsp),%rdx + movq TF_RCX(%rsp),%rcx + movq TF_R8(%rsp),%r8 + movq TF_R9(%rsp),%r9 + movq TF_RAX(%rsp),%rax + movq TF_RBX(%rsp),%rbx + movq TF_RBP(%rsp),%rbp + movq TF_R10(%rsp),%r10 + movq TF_R11(%rsp),%r11 + movq TF_R12(%rsp),%r12 + movq TF_R13(%rsp),%r13 + movq TF_R14(%rsp),%r14 + movq TF_R15(%rsp),%r15 + .endm + +#endif /* LOCORE */ + +#ifdef __STDC__ +#define ELFNOTE(name, type, desctype, descdata...) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz #name ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#else /* !__STDC__, i.e. -traditional */ +#define ELFNOTE(name, type, desctype, descdata) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz "name" ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#endif /* __STDC__ */ + +#endif /* !_MACHINE_ASMACROS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/atomic.h b/lib/libc/include/x86_64-freebsd-any/machine/atomic.h new file mode 100644 index 000000000000..000d13aa135a --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/atomic.h @@ -0,0 +1,682 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +/* + * To express interprocessor (as opposed to processor and device) memory + * ordering constraints, use the atomic_*() functions with acquire and release + * semantics rather than the *mb() functions. An architecture's memory + * ordering (or memory consistency) model governs the order in which a + * program's accesses to different locations may be performed by an + * implementation of that architecture. In general, for memory regions + * defined as writeback cacheable, the memory ordering implemented by amd64 + * processors preserves the program ordering of a load followed by a load, a + * load followed by a store, and a store followed by a store. Only a store + * followed by a load to a different memory location may be reordered. + * Therefore, except for special cases, like non-temporal memory accesses or + * memory regions defined as write combining, the memory ordering effects + * provided by the sfence instruction in the wmb() function and the lfence + * instruction in the rmb() function are redundant. In contrast, the + * atomic_*() functions with acquire and release semantics do not perform + * redundant instructions for ordinary cases of interprocessor memory + * ordering on any architecture. + */ +#define mb() __asm __volatile("mfence;" : : : "memory") +#define wmb() __asm __volatile("sfence;" : : : "memory") +#define rmb() __asm __volatile("lfence;" : : : "memory") + +#include + +/* + * Various simple operations on memory, each of which is atomic in the + * presence of interrupts and multiple processors. + * + * atomic_set_char(P, V) (*(u_char *)(P) |= (V)) + * atomic_clear_char(P, V) (*(u_char *)(P) &= ~(V)) + * atomic_add_char(P, V) (*(u_char *)(P) += (V)) + * atomic_subtract_char(P, V) (*(u_char *)(P) -= (V)) + * + * atomic_set_short(P, V) (*(u_short *)(P) |= (V)) + * atomic_clear_short(P, V) (*(u_short *)(P) &= ~(V)) + * atomic_add_short(P, V) (*(u_short *)(P) += (V)) + * atomic_subtract_short(P, V) (*(u_short *)(P) -= (V)) + * + * atomic_set_int(P, V) (*(u_int *)(P) |= (V)) + * atomic_clear_int(P, V) (*(u_int *)(P) &= ~(V)) + * atomic_add_int(P, V) (*(u_int *)(P) += (V)) + * atomic_subtract_int(P, V) (*(u_int *)(P) -= (V)) + * atomic_swap_int(P, V) (return (*(u_int *)(P)); *(u_int *)(P) = (V);) + * atomic_readandclear_int(P) (return (*(u_int *)(P)); *(u_int *)(P) = 0;) + * + * atomic_set_long(P, V) (*(u_long *)(P) |= (V)) + * atomic_clear_long(P, V) (*(u_long *)(P) &= ~(V)) + * atomic_add_long(P, V) (*(u_long *)(P) += (V)) + * atomic_subtract_long(P, V) (*(u_long *)(P) -= (V)) + * atomic_swap_long(P, V) (return (*(u_long *)(P)); *(u_long *)(P) = (V);) + * atomic_readandclear_long(P) (return (*(u_long *)(P)); *(u_long *)(P) = 0;) + */ + +/* + * The above functions are expanded inline in the statically-linked + * kernel. Lock prefixes are generated if an SMP kernel is being + * built. + * + * Kernel modules call real functions which are built into the kernel. + * This allows kernel modules to be portable between UP and SMP systems. + */ +#if !defined(__GNUCLIKE_ASM) +#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ +void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \ +void atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +int atomic_cmpset_char(volatile u_char *dst, u_char expect, u_char src); +int atomic_cmpset_short(volatile u_short *dst, u_short expect, u_short src); +int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src); +int atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src); +int atomic_fcmpset_char(volatile u_char *dst, u_char *expect, u_char src); +int atomic_fcmpset_short(volatile u_short *dst, u_short *expect, + u_short src); +int atomic_fcmpset_int(volatile u_int *dst, u_int *expect, u_int src); +int atomic_fcmpset_long(volatile u_long *dst, u_long *expect, u_long src); +u_int atomic_fetchadd_int(volatile u_int *p, u_int v); +u_long atomic_fetchadd_long(volatile u_long *p, u_long v); +int atomic_testandset_int(volatile u_int *p, u_int v); +int atomic_testandset_long(volatile u_long *p, u_int v); +int atomic_testandclear_int(volatile u_int *p, u_int v); +int atomic_testandclear_long(volatile u_long *p, u_int v); +void atomic_thread_fence_acq(void); +void atomic_thread_fence_acq_rel(void); +void atomic_thread_fence_rel(void); +void atomic_thread_fence_seq_cst(void); + +#define ATOMIC_LOAD(TYPE) \ +u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p) +#define ATOMIC_STORE(TYPE) \ +void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +#else /* !KLD_MODULE && __GNUCLIKE_ASM */ + +/* + * For userland, always use lock prefixes so that the binaries will run + * on both SMP and !SMP systems. + */ +#if defined(SMP) || !defined(_KERNEL) || defined(KLD_MODULE) +#define MPLOCKED "lock ; " +#else +#define MPLOCKED +#endif + +/* + * The assembly is volatilized to avoid code chunk removal by the compiler. + * GCC aggressively reorders operations and memory clobbering is necessary + * in order to avoid that for memory barriers. + */ +#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ +static __inline void \ +atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ +{ \ + __asm __volatile(MPLOCKED OP \ + : "+m" (*p) \ + : CONS (V) \ + : "cc"); \ +} \ + \ +static __inline void \ +atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ +{ \ + __asm __volatile(MPLOCKED OP \ + : "+m" (*p) \ + : CONS (V) \ + : "memory", "cc"); \ +} \ +struct __hack + +/* + * Atomic compare and set, used by the mutex functions. + * + * cmpset: + * if (*dst == expect) + * *dst = src + * + * fcmpset: + * if (*dst == *expect) + * *dst = src + * else + * *expect = *dst + * + * Returns 0 on failure, non-zero on success. + */ +#define ATOMIC_CMPSET(TYPE) \ +static __inline int \ +atomic_cmpset_##TYPE(volatile u_##TYPE *dst, u_##TYPE expect, u_##TYPE src) \ +{ \ + u_char res; \ + \ + __asm __volatile( \ + " " MPLOCKED " " \ + " cmpxchg %3,%1 ; " \ + " sete %0 ; " \ + "# atomic_cmpset_" #TYPE " " \ + : "=q" (res), /* 0 */ \ + "+m" (*dst), /* 1 */ \ + "+a" (expect) /* 2 */ \ + : "r" (src) /* 3 */ \ + : "memory", "cc"); \ + return (res); \ +} \ + \ +static __inline int \ +atomic_fcmpset_##TYPE(volatile u_##TYPE *dst, u_##TYPE *expect, u_##TYPE src) \ +{ \ + u_char res; \ + \ + __asm __volatile( \ + " " MPLOCKED " " \ + " cmpxchg %3,%1 ; " \ + " sete %0 ; " \ + "# atomic_fcmpset_" #TYPE " " \ + : "=q" (res), /* 0 */ \ + "+m" (*dst), /* 1 */ \ + "+a" (*expect) /* 2 */ \ + : "r" (src) /* 3 */ \ + : "memory", "cc"); \ + return (res); \ +} + +ATOMIC_CMPSET(char); +ATOMIC_CMPSET(short); +ATOMIC_CMPSET(int); +ATOMIC_CMPSET(long); + +/* + * Atomically add the value of v to the integer pointed to by p and return + * the previous value of *p. + */ +static __inline u_int +atomic_fetchadd_int(volatile u_int *p, u_int v) +{ + + __asm __volatile( + " " MPLOCKED " " + " xaddl %0,%1 ; " + "# atomic_fetchadd_int" + : "+r" (v), /* 0 */ + "+m" (*p) /* 1 */ + : : "cc"); + return (v); +} + +/* + * Atomically add the value of v to the long integer pointed to by p and return + * the previous value of *p. + */ +static __inline u_long +atomic_fetchadd_long(volatile u_long *p, u_long v) +{ + + __asm __volatile( + " " MPLOCKED " " + " xaddq %0,%1 ; " + "# atomic_fetchadd_long" + : "+r" (v), /* 0 */ + "+m" (*p) /* 1 */ + : : "cc"); + return (v); +} + +static __inline int +atomic_testandset_int(volatile u_int *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btsl %2,%1 ; " + " setc %0 ; " + "# atomic_testandset_int" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Ir" (v & 0x1f) /* 2 */ + : "cc"); + return (res); +} + +static __inline int +atomic_testandset_long(volatile u_long *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btsq %2,%1 ; " + " setc %0 ; " + "# atomic_testandset_long" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Jr" ((u_long)(v & 0x3f)) /* 2 */ + : "cc"); + return (res); +} + +static __inline int +atomic_testandclear_int(volatile u_int *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btrl %2,%1 ; " + " setc %0 ; " + "# atomic_testandclear_int" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Ir" (v & 0x1f) /* 2 */ + : "cc"); + return (res); +} + +static __inline int +atomic_testandclear_long(volatile u_long *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btrq %2,%1 ; " + " setc %0 ; " + "# atomic_testandclear_long" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Jr" ((u_long)(v & 0x3f)) /* 2 */ + : "cc"); + return (res); +} + +/* + * We assume that a = b will do atomic loads and stores. Due to the + * IA32 memory model, a simple store guarantees release semantics. + * + * However, a load may pass a store if they are performed on distinct + * addresses, so we need a Store/Load barrier for sequentially + * consistent fences in SMP kernels. We use "lock addl $0,mem" for a + * Store/Load barrier, as recommended by the AMD Software Optimization + * Guide, and not mfence. To avoid false data dependencies, we use a + * special address for "mem". In the kernel, we use a private per-cpu + * cache line. In user space, we use a word in the stack's red zone + * (-8(%rsp)). + * + * For UP kernels, however, the memory of the single processor is + * always consistent, so we only need to stop the compiler from + * reordering accesses in a way that violates the semantics of acquire + * and release. + */ + +#if defined(_KERNEL) + +/* + * OFFSETOF_MONITORBUF == __pcpu_offset(pc_monitorbuf). + * + * The open-coded number is used instead of the symbolic expression to + * avoid a dependency on sys/pcpu.h in machine/atomic.h consumers. + * An assertion in amd64/vm_machdep.c ensures that the value is correct. + */ +#define OFFSETOF_MONITORBUF 0x100 + +#if defined(SMP) || defined(KLD_MODULE) +static __inline void +__storeload_barrier(void) +{ + + __asm __volatile("lock; addl $0,%%gs:%0" + : "+m" (*(u_int *)OFFSETOF_MONITORBUF) : : "memory", "cc"); +} +#else /* _KERNEL && UP */ +static __inline void +__storeload_barrier(void) +{ + + __compiler_membar(); +} +#endif /* SMP */ +#else /* !_KERNEL */ +static __inline void +__storeload_barrier(void) +{ + + __asm __volatile("lock; addl $0,-8(%%rsp)" : : : "memory", "cc"); +} +#endif /* _KERNEL*/ + +#define ATOMIC_LOAD(TYPE) \ +static __inline u_##TYPE \ +atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ +{ \ + u_##TYPE res; \ + \ + res = *p; \ + __compiler_membar(); \ + return (res); \ +} \ +struct __hack + +#define ATOMIC_STORE(TYPE) \ +static __inline void \ +atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) \ +{ \ + \ + __compiler_membar(); \ + *p = v; \ +} \ +struct __hack + +static __inline void +atomic_thread_fence_acq(void) +{ + + __compiler_membar(); +} + +static __inline void +atomic_thread_fence_rel(void) +{ + + __compiler_membar(); +} + +static __inline void +atomic_thread_fence_acq_rel(void) +{ + + __compiler_membar(); +} + +static __inline void +atomic_thread_fence_seq_cst(void) +{ + + __storeload_barrier(); +} + +#endif /* KLD_MODULE || !__GNUCLIKE_ASM */ + +ATOMIC_ASM(set, char, "orb %b1,%0", "iq", v); +ATOMIC_ASM(clear, char, "andb %b1,%0", "iq", ~v); +ATOMIC_ASM(add, char, "addb %b1,%0", "iq", v); +ATOMIC_ASM(subtract, char, "subb %b1,%0", "iq", v); + +ATOMIC_ASM(set, short, "orw %w1,%0", "ir", v); +ATOMIC_ASM(clear, short, "andw %w1,%0", "ir", ~v); +ATOMIC_ASM(add, short, "addw %w1,%0", "ir", v); +ATOMIC_ASM(subtract, short, "subw %w1,%0", "ir", v); + +ATOMIC_ASM(set, int, "orl %1,%0", "ir", v); +ATOMIC_ASM(clear, int, "andl %1,%0", "ir", ~v); +ATOMIC_ASM(add, int, "addl %1,%0", "ir", v); +ATOMIC_ASM(subtract, int, "subl %1,%0", "ir", v); + +ATOMIC_ASM(set, long, "orq %1,%0", "er", v); +ATOMIC_ASM(clear, long, "andq %1,%0", "er", ~v); +ATOMIC_ASM(add, long, "addq %1,%0", "er", v); +ATOMIC_ASM(subtract, long, "subq %1,%0", "er", v); + +#define ATOMIC_LOADSTORE(TYPE) \ + ATOMIC_LOAD(TYPE); \ + ATOMIC_STORE(TYPE) + +ATOMIC_LOADSTORE(char); +ATOMIC_LOADSTORE(short); +ATOMIC_LOADSTORE(int); +ATOMIC_LOADSTORE(long); + +#undef ATOMIC_ASM +#undef ATOMIC_LOAD +#undef ATOMIC_STORE +#undef ATOMIC_LOADSTORE +#ifndef WANT_FUNCTIONS + +/* Read the current value and store a new value in the destination. */ +#ifdef __GNUCLIKE_ASM + +static __inline u_int +atomic_swap_int(volatile u_int *p, u_int v) +{ + + __asm __volatile( + " xchgl %1,%0 ; " + "# atomic_swap_int" + : "+r" (v), /* 0 */ + "+m" (*p)); /* 1 */ + return (v); +} + +static __inline u_long +atomic_swap_long(volatile u_long *p, u_long v) +{ + + __asm __volatile( + " xchgq %1,%0 ; " + "# atomic_swap_long" + : "+r" (v), /* 0 */ + "+m" (*p)); /* 1 */ + return (v); +} + +#else /* !__GNUCLIKE_ASM */ + +u_int atomic_swap_int(volatile u_int *p, u_int v); +u_long atomic_swap_long(volatile u_long *p, u_long v); + +#endif /* __GNUCLIKE_ASM */ + +#define atomic_set_acq_char atomic_set_barr_char +#define atomic_set_rel_char atomic_set_barr_char +#define atomic_clear_acq_char atomic_clear_barr_char +#define atomic_clear_rel_char atomic_clear_barr_char +#define atomic_add_acq_char atomic_add_barr_char +#define atomic_add_rel_char atomic_add_barr_char +#define atomic_subtract_acq_char atomic_subtract_barr_char +#define atomic_subtract_rel_char atomic_subtract_barr_char +#define atomic_cmpset_acq_char atomic_cmpset_char +#define atomic_cmpset_rel_char atomic_cmpset_char +#define atomic_fcmpset_acq_char atomic_fcmpset_char +#define atomic_fcmpset_rel_char atomic_fcmpset_char + +#define atomic_set_acq_short atomic_set_barr_short +#define atomic_set_rel_short atomic_set_barr_short +#define atomic_clear_acq_short atomic_clear_barr_short +#define atomic_clear_rel_short atomic_clear_barr_short +#define atomic_add_acq_short atomic_add_barr_short +#define atomic_add_rel_short atomic_add_barr_short +#define atomic_subtract_acq_short atomic_subtract_barr_short +#define atomic_subtract_rel_short atomic_subtract_barr_short +#define atomic_cmpset_acq_short atomic_cmpset_short +#define atomic_cmpset_rel_short atomic_cmpset_short +#define atomic_fcmpset_acq_short atomic_fcmpset_short +#define atomic_fcmpset_rel_short atomic_fcmpset_short + +#define atomic_set_acq_int atomic_set_barr_int +#define atomic_set_rel_int atomic_set_barr_int +#define atomic_clear_acq_int atomic_clear_barr_int +#define atomic_clear_rel_int atomic_clear_barr_int +#define atomic_add_acq_int atomic_add_barr_int +#define atomic_add_rel_int atomic_add_barr_int +#define atomic_subtract_acq_int atomic_subtract_barr_int +#define atomic_subtract_rel_int atomic_subtract_barr_int +#define atomic_cmpset_acq_int atomic_cmpset_int +#define atomic_cmpset_rel_int atomic_cmpset_int +#define atomic_fcmpset_acq_int atomic_fcmpset_int +#define atomic_fcmpset_rel_int atomic_fcmpset_int + +#define atomic_set_acq_long atomic_set_barr_long +#define atomic_set_rel_long atomic_set_barr_long +#define atomic_clear_acq_long atomic_clear_barr_long +#define atomic_clear_rel_long atomic_clear_barr_long +#define atomic_add_acq_long atomic_add_barr_long +#define atomic_add_rel_long atomic_add_barr_long +#define atomic_subtract_acq_long atomic_subtract_barr_long +#define atomic_subtract_rel_long atomic_subtract_barr_long +#define atomic_cmpset_acq_long atomic_cmpset_long +#define atomic_cmpset_rel_long atomic_cmpset_long +#define atomic_fcmpset_acq_long atomic_fcmpset_long +#define atomic_fcmpset_rel_long atomic_fcmpset_long + +#define atomic_readandclear_int(p) atomic_swap_int(p, 0) +#define atomic_readandclear_long(p) atomic_swap_long(p, 0) + +/* Operations on 8-bit bytes. */ +#define atomic_set_8 atomic_set_char +#define atomic_set_acq_8 atomic_set_acq_char +#define atomic_set_rel_8 atomic_set_rel_char +#define atomic_clear_8 atomic_clear_char +#define atomic_clear_acq_8 atomic_clear_acq_char +#define atomic_clear_rel_8 atomic_clear_rel_char +#define atomic_add_8 atomic_add_char +#define atomic_add_acq_8 atomic_add_acq_char +#define atomic_add_rel_8 atomic_add_rel_char +#define atomic_subtract_8 atomic_subtract_char +#define atomic_subtract_acq_8 atomic_subtract_acq_char +#define atomic_subtract_rel_8 atomic_subtract_rel_char +#define atomic_load_acq_8 atomic_load_acq_char +#define atomic_store_rel_8 atomic_store_rel_char +#define atomic_cmpset_8 atomic_cmpset_char +#define atomic_cmpset_acq_8 atomic_cmpset_acq_char +#define atomic_cmpset_rel_8 atomic_cmpset_rel_char +#define atomic_fcmpset_8 atomic_fcmpset_char +#define atomic_fcmpset_acq_8 atomic_fcmpset_acq_char +#define atomic_fcmpset_rel_8 atomic_fcmpset_rel_char + +/* Operations on 16-bit words. */ +#define atomic_set_16 atomic_set_short +#define atomic_set_acq_16 atomic_set_acq_short +#define atomic_set_rel_16 atomic_set_rel_short +#define atomic_clear_16 atomic_clear_short +#define atomic_clear_acq_16 atomic_clear_acq_short +#define atomic_clear_rel_16 atomic_clear_rel_short +#define atomic_add_16 atomic_add_short +#define atomic_add_acq_16 atomic_add_acq_short +#define atomic_add_rel_16 atomic_add_rel_short +#define atomic_subtract_16 atomic_subtract_short +#define atomic_subtract_acq_16 atomic_subtract_acq_short +#define atomic_subtract_rel_16 atomic_subtract_rel_short +#define atomic_load_acq_16 atomic_load_acq_short +#define atomic_store_rel_16 atomic_store_rel_short +#define atomic_cmpset_16 atomic_cmpset_short +#define atomic_cmpset_acq_16 atomic_cmpset_acq_short +#define atomic_cmpset_rel_16 atomic_cmpset_rel_short +#define atomic_fcmpset_16 atomic_fcmpset_short +#define atomic_fcmpset_acq_16 atomic_fcmpset_acq_short +#define atomic_fcmpset_rel_16 atomic_fcmpset_rel_short + +/* Operations on 32-bit double words. */ +#define atomic_set_32 atomic_set_int +#define atomic_set_acq_32 atomic_set_acq_int +#define atomic_set_rel_32 atomic_set_rel_int +#define atomic_clear_32 atomic_clear_int +#define atomic_clear_acq_32 atomic_clear_acq_int +#define atomic_clear_rel_32 atomic_clear_rel_int +#define atomic_add_32 atomic_add_int +#define atomic_add_acq_32 atomic_add_acq_int +#define atomic_add_rel_32 atomic_add_rel_int +#define atomic_subtract_32 atomic_subtract_int +#define atomic_subtract_acq_32 atomic_subtract_acq_int +#define atomic_subtract_rel_32 atomic_subtract_rel_int +#define atomic_load_acq_32 atomic_load_acq_int +#define atomic_store_rel_32 atomic_store_rel_int +#define atomic_cmpset_32 atomic_cmpset_int +#define atomic_cmpset_acq_32 atomic_cmpset_acq_int +#define atomic_cmpset_rel_32 atomic_cmpset_rel_int +#define atomic_fcmpset_32 atomic_fcmpset_int +#define atomic_fcmpset_acq_32 atomic_fcmpset_acq_int +#define atomic_fcmpset_rel_32 atomic_fcmpset_rel_int +#define atomic_swap_32 atomic_swap_int +#define atomic_readandclear_32 atomic_readandclear_int +#define atomic_fetchadd_32 atomic_fetchadd_int +#define atomic_testandset_32 atomic_testandset_int +#define atomic_testandclear_32 atomic_testandclear_int + +/* Operations on 64-bit quad words. */ +#define atomic_set_64 atomic_set_long +#define atomic_set_acq_64 atomic_set_acq_long +#define atomic_set_rel_64 atomic_set_rel_long +#define atomic_clear_64 atomic_clear_long +#define atomic_clear_acq_64 atomic_clear_acq_long +#define atomic_clear_rel_64 atomic_clear_rel_long +#define atomic_add_64 atomic_add_long +#define atomic_add_acq_64 atomic_add_acq_long +#define atomic_add_rel_64 atomic_add_rel_long +#define atomic_subtract_64 atomic_subtract_long +#define atomic_subtract_acq_64 atomic_subtract_acq_long +#define atomic_subtract_rel_64 atomic_subtract_rel_long +#define atomic_load_acq_64 atomic_load_acq_long +#define atomic_store_rel_64 atomic_store_rel_long +#define atomic_cmpset_64 atomic_cmpset_long +#define atomic_cmpset_acq_64 atomic_cmpset_acq_long +#define atomic_cmpset_rel_64 atomic_cmpset_rel_long +#define atomic_fcmpset_64 atomic_fcmpset_long +#define atomic_fcmpset_acq_64 atomic_fcmpset_acq_long +#define atomic_fcmpset_rel_64 atomic_fcmpset_rel_long +#define atomic_swap_64 atomic_swap_long +#define atomic_readandclear_64 atomic_readandclear_long +#define atomic_fetchadd_64 atomic_fetchadd_long +#define atomic_testandset_64 atomic_testandset_long +#define atomic_testandclear_64 atomic_testandclear_long + +/* Operations on pointers. */ +#define atomic_set_ptr atomic_set_long +#define atomic_set_acq_ptr atomic_set_acq_long +#define atomic_set_rel_ptr atomic_set_rel_long +#define atomic_clear_ptr atomic_clear_long +#define atomic_clear_acq_ptr atomic_clear_acq_long +#define atomic_clear_rel_ptr atomic_clear_rel_long +#define atomic_add_ptr atomic_add_long +#define atomic_add_acq_ptr atomic_add_acq_long +#define atomic_add_rel_ptr atomic_add_rel_long +#define atomic_subtract_ptr atomic_subtract_long +#define atomic_subtract_acq_ptr atomic_subtract_acq_long +#define atomic_subtract_rel_ptr atomic_subtract_rel_long +#define atomic_load_acq_ptr atomic_load_acq_long +#define atomic_store_rel_ptr atomic_store_rel_long +#define atomic_cmpset_ptr atomic_cmpset_long +#define atomic_cmpset_acq_ptr atomic_cmpset_acq_long +#define atomic_cmpset_rel_ptr atomic_cmpset_rel_long +#define atomic_fcmpset_ptr atomic_fcmpset_long +#define atomic_fcmpset_acq_ptr atomic_fcmpset_acq_long +#define atomic_fcmpset_rel_ptr atomic_fcmpset_rel_long +#define atomic_swap_ptr atomic_swap_long +#define atomic_readandclear_ptr atomic_readandclear_long + +#endif /* !WANT_FUNCTIONS */ + +#endif /* !_MACHINE_ATOMIC_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/bus.h b/lib/libc/include/x86_64-freebsd-any/machine/bus.h new file mode 100644 index 000000000000..f1af2cf6168c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/bus.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/bus_dma.h b/lib/libc/include/x86_64-freebsd-any/machine/bus_dma.h new file mode 100644 index 000000000000..26d71888d328 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/bus_dma.h @@ -0,0 +1,36 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2005 Scott Long + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _AMD64_BUS_DMA_H_ +#define _AMD64_BUS_DMA_H_ + +#include + +#endif /* _AMD64_BUS_DMA_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/clock.h b/lib/libc/include/x86_64-freebsd-any/machine/clock.h new file mode 100644 index 000000000000..86a4541568ed --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/clock.h @@ -0,0 +1,46 @@ +/*- + * Kernel interface to machine-dependent clock driver. + * Garrett Wollman, September 1994. + * This file is in the public domain. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_CLOCK_H_ +#define _MACHINE_CLOCK_H_ + +#ifdef _KERNEL +/* + * i386 to clock driver interface. + * XXX large parts of the driver and its interface are misplaced. + */ +extern int clkintr_pending; +extern u_int i8254_freq; +extern int i8254_max_count; +extern uint64_t tsc_freq; +extern int tsc_is_invariant; +extern int tsc_perf_stat; +#ifdef SMP +extern int smp_tsc; +#endif + +void i8254_init(void); +void i8254_delay(int); +void clock_init(void); + +/* + * Driver to clock driver interface. + */ + +void startrtclock(void); +void init_TSC(void); +void resume_TSC(void); + +#define HAS_TIMER_SPKR 1 +int timer_spkr_acquire(void); +int timer_spkr_release(void); +void timer_spkr_setfreq(int freq); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CLOCK_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/counter.h b/lib/libc/include/x86_64-freebsd-any/machine/counter.h new file mode 100644 index 000000000000..cc0e74064a5f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/counter.h @@ -0,0 +1,92 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __MACHINE_COUNTER_H__ +#define __MACHINE_COUNTER_H__ + +#include + +#define EARLY_COUNTER &temp_bsp_pcpu.pc_early_dummy_counter + +#define counter_enter() do {} while (0) +#define counter_exit() do {} while (0) + +#ifdef IN_SUBR_COUNTER_C +static inline uint64_t +counter_u64_read_one(uint64_t *p, int cpu) +{ + + return (*(uint64_t *)((char *)p + UMA_PCPU_ALLOC_SIZE * cpu)); +} + +static inline uint64_t +counter_u64_fetch_inline(uint64_t *p) +{ + uint64_t r; + int i; + + r = 0; + CPU_FOREACH(i) + r += counter_u64_read_one((uint64_t *)p, i); + + return (r); +} + +static void +counter_u64_zero_one_cpu(void *arg) +{ + + *((uint64_t *)((char *)arg + UMA_PCPU_ALLOC_SIZE * + PCPU_GET(cpuid))) = 0; +} + +static inline void +counter_u64_zero_inline(counter_u64_t c) +{ + + smp_rendezvous(smp_no_rendezvous_barrier, counter_u64_zero_one_cpu, + smp_no_rendezvous_barrier, c); +} +#endif + +#define counter_u64_add_protected(c, i) counter_u64_add(c, i) + +static inline void +counter_u64_add(counter_u64_t c, int64_t inc) +{ + + KASSERT(IS_BSP() || c != EARLY_COUNTER, ("EARLY_COUNTER used on AP")); + __asm __volatile("addq\t%1,%%gs:(%0)" + : + : "r" ((char *)c - (char *)&__pcpu[0]), "ri" (inc) + : "memory", "cc"); +} + +#endif /* ! __MACHINE_COUNTER_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/cpu.h b/lib/libc/include/x86_64-freebsd-any/machine/cpu.h new file mode 100644 index 000000000000..1b8a552d3e7c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/cpu.h @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to i386 cpu support. + */ +#include +#include +#include + +#define cpu_exec(p) /* nothing */ +#define cpu_swapin(p) /* nothing */ +#define cpu_getstack(td) ((td)->td_frame->tf_rsp) +#define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap)) +#define cpu_spinwait() ia32_pause() + +#define TRAPF_USERMODE(framep) \ + (ISPL((framep)->tf_cs) == SEL_UPL) +#define TRAPF_PC(framep) ((framep)->tf_rip) + +#ifdef _KERNEL +/* + * Struct containing pointers to CPU management functions whose + * implementation is run time selectable. Selection can be made, + * for example, based on detection of a particular CPU variant or + * hypervisor environment. + */ +struct cpu_ops { + void (*cpu_init)(void); + void (*cpu_resume)(void); +}; + +extern struct cpu_ops cpu_ops; +extern char brwsection[]; +extern char btext[]; +extern char _end[]; +extern char etext[]; + +/* Resume hook for VMM. */ +extern void (*vmm_resume_p)(void); + +void cpu_halt(void); +void cpu_lock_delay(void); +void cpu_reset(void); +void fork_trampoline(void); +void swi_vm(void *); + +/* + * Return contents of in-cpu fast counter as a sort of "bogo-time" + * for random-harvesting purposes. + */ +static __inline u_int64_t +get_cyclecount(void) +{ + + return (rdtsc()); +} + +#define MEMSET_EARLY_FUNC memset_std +#define MEMCPY_EARLY_FUNC memcpy_std +#define MEMMOVE_EARLY_FUNC memmove_std + +#endif + +#endif /* !_MACHINE_CPU_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/cpufunc.h b/lib/libc/include/x86_64-freebsd-any/machine/cpufunc.h new file mode 100644 index 000000000000..2a03d9b61941 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/cpufunc.h @@ -0,0 +1,1048 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1993 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Functions to provide access to special i386 instructions. + * This in included in sys/systm.h, and that file should be + * used in preference to this. + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +struct region_descriptor; + +#define readb(va) (*(volatile uint8_t *) (va)) +#define readw(va) (*(volatile uint16_t *) (va)) +#define readl(va) (*(volatile uint32_t *) (va)) +#define readq(va) (*(volatile uint64_t *) (va)) + +#define writeb(va, d) (*(volatile uint8_t *) (va) = (d)) +#define writew(va, d) (*(volatile uint16_t *) (va) = (d)) +#define writel(va, d) (*(volatile uint32_t *) (va) = (d)) +#define writeq(va, d) (*(volatile uint64_t *) (va) = (d)) + +#if defined(__GNUCLIKE_ASM) && defined(__CC_SUPPORTS___INLINE) + +static __inline void +breakpoint(void) +{ + __asm __volatile("int $3"); +} + +static __inline __pure2 u_int +bsfl(u_int mask) +{ + u_int result; + + __asm __volatile("bsfl %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline __pure2 u_long +bsfq(u_long mask) +{ + u_long result; + + __asm __volatile("bsfq %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline __pure2 u_int +bsrl(u_int mask) +{ + u_int result; + + __asm __volatile("bsrl %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline __pure2 u_long +bsrq(u_long mask) +{ + u_long result; + + __asm __volatile("bsrq %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline void +clflush(u_long addr) +{ + + __asm __volatile("clflush %0" : : "m" (*(char *)addr)); +} + +static __inline void +clflushopt(u_long addr) +{ + + __asm __volatile(".byte 0x66;clflush %0" : : "m" (*(char *)addr)); +} + +static __inline void +clwb(u_long addr) +{ + + __asm __volatile("clwb %0" : : "m" (*(char *)addr)); +} + +static __inline void +clts(void) +{ + + __asm __volatile("clts"); +} + +static __inline void +disable_intr(void) +{ + __asm __volatile("cli" : : : "memory"); +} + +static __inline void +do_cpuid(u_int ax, u_int *p) +{ + __asm __volatile("cpuid" + : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) + : "0" (ax)); +} + +static __inline void +cpuid_count(u_int ax, u_int cx, u_int *p) +{ + __asm __volatile("cpuid" + : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) + : "0" (ax), "c" (cx)); +} + +static __inline void +enable_intr(void) +{ + __asm __volatile("sti"); +} + +#ifdef _KERNEL + +#define HAVE_INLINE_FFS +#define ffs(x) __builtin_ffs(x) + +#define HAVE_INLINE_FFSL + +static __inline __pure2 int +ffsl(long mask) +{ + + return (__builtin_ffsl(mask)); +} + +#define HAVE_INLINE_FFSLL + +static __inline __pure2 int +ffsll(long long mask) +{ + return (ffsl((long)mask)); +} + +#define HAVE_INLINE_FLS + +static __inline __pure2 int +fls(int mask) +{ + return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1); +} + +#define HAVE_INLINE_FLSL + +static __inline __pure2 int +flsl(long mask) +{ + return (mask == 0 ? mask : (int)bsrq((u_long)mask) + 1); +} + +#define HAVE_INLINE_FLSLL + +static __inline __pure2 int +flsll(long long mask) +{ + return (flsl((long)mask)); +} + +#endif /* _KERNEL */ + +static __inline void +halt(void) +{ + __asm __volatile("hlt"); +} + +static __inline u_char +inb(u_int port) +{ + u_char data; + + __asm __volatile("inb %w1, %0" : "=a" (data) : "Nd" (port)); + return (data); +} + +static __inline u_int +inl(u_int port) +{ + u_int data; + + __asm __volatile("inl %w1, %0" : "=a" (data) : "Nd" (port)); + return (data); +} + +static __inline void +insb(u_int port, void *addr, size_t count) +{ + __asm __volatile("cld; rep; insb" + : "+D" (addr), "+c" (count) + : "d" (port) + : "memory"); +} + +static __inline void +insw(u_int port, void *addr, size_t count) +{ + __asm __volatile("cld; rep; insw" + : "+D" (addr), "+c" (count) + : "d" (port) + : "memory"); +} + +static __inline void +insl(u_int port, void *addr, size_t count) +{ + __asm __volatile("cld; rep; insl" + : "+D" (addr), "+c" (count) + : "d" (port) + : "memory"); +} + +static __inline void +invd(void) +{ + __asm __volatile("invd"); +} + +static __inline u_short +inw(u_int port) +{ + u_short data; + + __asm __volatile("inw %w1, %0" : "=a" (data) : "Nd" (port)); + return (data); +} + +static __inline void +outb(u_int port, u_char data) +{ + __asm __volatile("outb %0, %w1" : : "a" (data), "Nd" (port)); +} + +static __inline void +outl(u_int port, u_int data) +{ + __asm __volatile("outl %0, %w1" : : "a" (data), "Nd" (port)); +} + +static __inline void +outsb(u_int port, const void *addr, size_t count) +{ + __asm __volatile("cld; rep; outsb" + : "+S" (addr), "+c" (count) + : "d" (port)); +} + +static __inline void +outsw(u_int port, const void *addr, size_t count) +{ + __asm __volatile("cld; rep; outsw" + : "+S" (addr), "+c" (count) + : "d" (port)); +} + +static __inline void +outsl(u_int port, const void *addr, size_t count) +{ + __asm __volatile("cld; rep; outsl" + : "+S" (addr), "+c" (count) + : "d" (port)); +} + +static __inline void +outw(u_int port, u_short data) +{ + __asm __volatile("outw %0, %w1" : : "a" (data), "Nd" (port)); +} + +static __inline u_long +popcntq(u_long mask) +{ + u_long result; + + __asm __volatile("popcntq %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline void +lfence(void) +{ + + __asm __volatile("lfence" : : : "memory"); +} + +static __inline void +mfence(void) +{ + + __asm __volatile("mfence" : : : "memory"); +} + +static __inline void +sfence(void) +{ + + __asm __volatile("sfence" : : : "memory"); +} + +static __inline void +ia32_pause(void) +{ + __asm __volatile("pause"); +} + +static __inline u_long +read_rflags(void) +{ + u_long rf; + + __asm __volatile("pushfq; popq %0" : "=r" (rf)); + return (rf); +} + +static __inline uint64_t +rdmsr(u_int msr) +{ + uint32_t low, high; + + __asm __volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); + return (low | ((uint64_t)high << 32)); +} + +static __inline uint32_t +rdmsr32(u_int msr) +{ + uint32_t low; + + __asm __volatile("rdmsr" : "=a" (low) : "c" (msr) : "rdx"); + return (low); +} + +static __inline uint64_t +rdpmc(u_int pmc) +{ + uint32_t low, high; + + __asm __volatile("rdpmc" : "=a" (low), "=d" (high) : "c" (pmc)); + return (low | ((uint64_t)high << 32)); +} + +static __inline uint64_t +rdtsc(void) +{ + uint32_t low, high; + + __asm __volatile("rdtsc" : "=a" (low), "=d" (high)); + return (low | ((uint64_t)high << 32)); +} + +static __inline uint64_t +rdtscp(void) +{ + uint32_t low, high; + + __asm __volatile("rdtscp" : "=a" (low), "=d" (high) : : "ecx"); + return (low | ((uint64_t)high << 32)); +} + +static __inline uint32_t +rdtsc32(void) +{ + uint32_t rv; + + __asm __volatile("rdtsc" : "=a" (rv) : : "edx"); + return (rv); +} + +static __inline void +wbinvd(void) +{ + __asm __volatile("wbinvd"); +} + +static __inline void +write_rflags(u_long rf) +{ + __asm __volatile("pushq %0; popfq" : : "r" (rf)); +} + +static __inline void +wrmsr(u_int msr, uint64_t newval) +{ + uint32_t low, high; + + low = newval; + high = newval >> 32; + __asm __volatile("wrmsr" : : "a" (low), "d" (high), "c" (msr)); +} + +static __inline void +load_cr0(u_long data) +{ + + __asm __volatile("movq %0,%%cr0" : : "r" (data)); +} + +static __inline u_long +rcr0(void) +{ + u_long data; + + __asm __volatile("movq %%cr0,%0" : "=r" (data)); + return (data); +} + +static __inline u_long +rcr2(void) +{ + u_long data; + + __asm __volatile("movq %%cr2,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_cr3(u_long data) +{ + + __asm __volatile("movq %0,%%cr3" : : "r" (data) : "memory"); +} + +static __inline u_long +rcr3(void) +{ + u_long data; + + __asm __volatile("movq %%cr3,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_cr4(u_long data) +{ + __asm __volatile("movq %0,%%cr4" : : "r" (data)); +} + +static __inline u_long +rcr4(void) +{ + u_long data; + + __asm __volatile("movq %%cr4,%0" : "=r" (data)); + return (data); +} + +static __inline u_long +rxcr(u_int reg) +{ + u_int low, high; + + __asm __volatile("xgetbv" : "=a" (low), "=d" (high) : "c" (reg)); + return (low | ((uint64_t)high << 32)); +} + +static __inline void +load_xcr(u_int reg, u_long val) +{ + u_int low, high; + + low = val; + high = val >> 32; + __asm __volatile("xsetbv" : : "c" (reg), "a" (low), "d" (high)); +} + +/* + * Global TLB flush (except for thise for pages marked PG_G) + */ +static __inline void +invltlb(void) +{ + + load_cr3(rcr3()); +} + +#ifndef CR4_PGE +#define CR4_PGE 0x00000080 /* Page global enable */ +#endif + +/* + * Perform the guaranteed invalidation of all TLB entries. This + * includes the global entries, and entries in all PCIDs, not only the + * current context. The function works both on non-PCID CPUs and CPUs + * with the PCID turned off or on. See IA-32 SDM Vol. 3a 4.10.4.1 + * Operations that Invalidate TLBs and Paging-Structure Caches. + */ +static __inline void +invltlb_glob(void) +{ + uint64_t cr4; + + cr4 = rcr4(); + load_cr4(cr4 & ~CR4_PGE); + /* + * Although preemption at this point could be detrimental to + * performance, it would not lead to an error. PG_G is simply + * ignored if CR4.PGE is clear. Moreover, in case this block + * is re-entered, the load_cr4() either above or below will + * modify CR4.PGE flushing the TLB. + */ + load_cr4(cr4 | CR4_PGE); +} + +/* + * TLB flush for an individual page (even if it has PG_G). + * Only works on 486+ CPUs (i386 does not have PG_G). + */ +static __inline void +invlpg(u_long addr) +{ + + __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory"); +} + +#define INVPCID_ADDR 0 +#define INVPCID_CTX 1 +#define INVPCID_CTXGLOB 2 +#define INVPCID_ALLCTX 3 + +struct invpcid_descr { + uint64_t pcid:12 __packed; + uint64_t pad:52 __packed; + uint64_t addr; +} __packed; + +static __inline void +invpcid(struct invpcid_descr *d, int type) +{ + + __asm __volatile("invpcid (%0),%1" + : : "r" (d), "r" ((u_long)type) : "memory"); +} + +static __inline u_short +rfs(void) +{ + u_short sel; + __asm __volatile("movw %%fs,%0" : "=rm" (sel)); + return (sel); +} + +static __inline u_short +rgs(void) +{ + u_short sel; + __asm __volatile("movw %%gs,%0" : "=rm" (sel)); + return (sel); +} + +static __inline u_short +rss(void) +{ + u_short sel; + __asm __volatile("movw %%ss,%0" : "=rm" (sel)); + return (sel); +} + +static __inline void +load_ds(u_short sel) +{ + __asm __volatile("movw %0,%%ds" : : "rm" (sel)); +} + +static __inline void +load_es(u_short sel) +{ + __asm __volatile("movw %0,%%es" : : "rm" (sel)); +} + +static __inline void +cpu_monitor(const void *addr, u_long extensions, u_int hints) +{ + + __asm __volatile("monitor" + : : "a" (addr), "c" (extensions), "d" (hints)); +} + +static __inline void +cpu_mwait(u_long extensions, u_int hints) +{ + + __asm __volatile("mwait" : : "a" (hints), "c" (extensions)); +} + +static __inline uint32_t +rdpkru(void) +{ + uint32_t res; + + __asm __volatile("rdpkru" : "=a" (res) : "c" (0) : "edx"); + return (res); +} + +static __inline void +wrpkru(uint32_t mask) +{ + + __asm __volatile("wrpkru" : : "a" (mask), "c" (0), "d" (0)); +} + +#ifdef _KERNEL +/* This is defined in but is too painful to get to */ +#ifndef MSR_FSBASE +#define MSR_FSBASE 0xc0000100 +#endif +static __inline void +load_fs(u_short sel) +{ + /* Preserve the fsbase value across the selector load */ + __asm __volatile("rdmsr; movw %0,%%fs; wrmsr" + : : "rm" (sel), "c" (MSR_FSBASE) : "eax", "edx"); +} + +#ifndef MSR_GSBASE +#define MSR_GSBASE 0xc0000101 +#endif +static __inline void +load_gs(u_short sel) +{ + /* + * Preserve the gsbase value across the selector load. + * Note that we have to disable interrupts because the gsbase + * being trashed happens to be the kernel gsbase at the time. + */ + __asm __volatile("pushfq; cli; rdmsr; movw %0,%%gs; wrmsr; popfq" + : : "rm" (sel), "c" (MSR_GSBASE) : "eax", "edx"); +} +#else +/* Usable by userland */ +static __inline void +load_fs(u_short sel) +{ + __asm __volatile("movw %0,%%fs" : : "rm" (sel)); +} + +static __inline void +load_gs(u_short sel) +{ + __asm __volatile("movw %0,%%gs" : : "rm" (sel)); +} +#endif + +static __inline uint64_t +rdfsbase(void) +{ + uint64_t x; + + __asm __volatile("rdfsbase %0" : "=r" (x)); + return (x); +} + +static __inline void +wrfsbase(uint64_t x) +{ + + __asm __volatile("wrfsbase %0" : : "r" (x)); +} + +static __inline uint64_t +rdgsbase(void) +{ + uint64_t x; + + __asm __volatile("rdgsbase %0" : "=r" (x)); + return (x); +} + +static __inline void +wrgsbase(uint64_t x) +{ + + __asm __volatile("wrgsbase %0" : : "r" (x)); +} + +static __inline void +bare_lgdt(struct region_descriptor *addr) +{ + __asm __volatile("lgdt (%0)" : : "r" (addr)); +} + +static __inline void +sgdt(struct region_descriptor *addr) +{ + char *loc; + + loc = (char *)addr; + __asm __volatile("sgdt %0" : "=m" (*loc) : : "memory"); +} + +static __inline void +lidt(struct region_descriptor *addr) +{ + __asm __volatile("lidt (%0)" : : "r" (addr)); +} + +static __inline void +sidt(struct region_descriptor *addr) +{ + char *loc; + + loc = (char *)addr; + __asm __volatile("sidt %0" : "=m" (*loc) : : "memory"); +} + +static __inline void +lldt(u_short sel) +{ + __asm __volatile("lldt %0" : : "r" (sel)); +} + +static __inline u_short +sldt(void) +{ + u_short sel; + + __asm __volatile("sldt %0" : "=r" (sel)); + return (sel); +} + +static __inline void +ltr(u_short sel) +{ + __asm __volatile("ltr %0" : : "r" (sel)); +} + +static __inline uint32_t +read_tr(void) +{ + u_short sel; + + __asm __volatile("str %0" : "=r" (sel)); + return (sel); +} + +static __inline uint64_t +rdr0(void) +{ + uint64_t data; + __asm __volatile("movq %%dr0,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr0(uint64_t dr0) +{ + __asm __volatile("movq %0,%%dr0" : : "r" (dr0)); +} + +static __inline uint64_t +rdr1(void) +{ + uint64_t data; + __asm __volatile("movq %%dr1,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr1(uint64_t dr1) +{ + __asm __volatile("movq %0,%%dr1" : : "r" (dr1)); +} + +static __inline uint64_t +rdr2(void) +{ + uint64_t data; + __asm __volatile("movq %%dr2,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr2(uint64_t dr2) +{ + __asm __volatile("movq %0,%%dr2" : : "r" (dr2)); +} + +static __inline uint64_t +rdr3(void) +{ + uint64_t data; + __asm __volatile("movq %%dr3,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr3(uint64_t dr3) +{ + __asm __volatile("movq %0,%%dr3" : : "r" (dr3)); +} + +static __inline uint64_t +rdr6(void) +{ + uint64_t data; + __asm __volatile("movq %%dr6,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr6(uint64_t dr6) +{ + __asm __volatile("movq %0,%%dr6" : : "r" (dr6)); +} + +static __inline uint64_t +rdr7(void) +{ + uint64_t data; + __asm __volatile("movq %%dr7,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr7(uint64_t dr7) +{ + __asm __volatile("movq %0,%%dr7" : : "r" (dr7)); +} + +static __inline register_t +intr_disable(void) +{ + register_t rflags; + + rflags = read_rflags(); + disable_intr(); + return (rflags); +} + +static __inline void +intr_restore(register_t rflags) +{ + write_rflags(rflags); +} + +static __inline void +stac(void) +{ + + __asm __volatile("stac" : : : "cc"); +} + +static __inline void +clac(void) +{ + + __asm __volatile("clac" : : : "cc"); +} + +enum { + SGX_ECREATE = 0x0, + SGX_EADD = 0x1, + SGX_EINIT = 0x2, + SGX_EREMOVE = 0x3, + SGX_EDGBRD = 0x4, + SGX_EDGBWR = 0x5, + SGX_EEXTEND = 0x6, + SGX_ELDU = 0x8, + SGX_EBLOCK = 0x9, + SGX_EPA = 0xA, + SGX_EWB = 0xB, + SGX_ETRACK = 0xC, +}; + +enum { + SGX_PT_SECS = 0x00, + SGX_PT_TCS = 0x01, + SGX_PT_REG = 0x02, + SGX_PT_VA = 0x03, + SGX_PT_TRIM = 0x04, +}; + +int sgx_encls(uint32_t eax, uint64_t rbx, uint64_t rcx, uint64_t rdx); + +static __inline int +sgx_ecreate(void *pginfo, void *secs) +{ + + return (sgx_encls(SGX_ECREATE, (uint64_t)pginfo, + (uint64_t)secs, 0)); +} + +static __inline int +sgx_eadd(void *pginfo, void *epc) +{ + + return (sgx_encls(SGX_EADD, (uint64_t)pginfo, + (uint64_t)epc, 0)); +} + +static __inline int +sgx_einit(void *sigstruct, void *secs, void *einittoken) +{ + + return (sgx_encls(SGX_EINIT, (uint64_t)sigstruct, + (uint64_t)secs, (uint64_t)einittoken)); +} + +static __inline int +sgx_eextend(void *secs, void *epc) +{ + + return (sgx_encls(SGX_EEXTEND, (uint64_t)secs, + (uint64_t)epc, 0)); +} + +static __inline int +sgx_epa(void *epc) +{ + + return (sgx_encls(SGX_EPA, SGX_PT_VA, (uint64_t)epc, 0)); +} + +static __inline int +sgx_eldu(uint64_t rbx, uint64_t rcx, + uint64_t rdx) +{ + + return (sgx_encls(SGX_ELDU, rbx, rcx, rdx)); +} + +static __inline int +sgx_eremove(void *epc) +{ + + return (sgx_encls(SGX_EREMOVE, 0, (uint64_t)epc, 0)); +} + +#else /* !(__GNUCLIKE_ASM && __CC_SUPPORTS___INLINE) */ + +int breakpoint(void); +u_int bsfl(u_int mask); +u_int bsrl(u_int mask); +void clflush(u_long addr); +void clts(void); +void cpuid_count(u_int ax, u_int cx, u_int *p); +void disable_intr(void); +void do_cpuid(u_int ax, u_int *p); +void enable_intr(void); +void halt(void); +void ia32_pause(void); +u_char inb(u_int port); +u_int inl(u_int port); +void insb(u_int port, void *addr, size_t count); +void insl(u_int port, void *addr, size_t count); +void insw(u_int port, void *addr, size_t count); +register_t intr_disable(void); +void intr_restore(register_t rf); +void invd(void); +void invlpg(u_int addr); +void invltlb(void); +u_short inw(u_int port); +void lidt(struct region_descriptor *addr); +void lldt(u_short sel); +void load_cr0(u_long cr0); +void load_cr3(u_long cr3); +void load_cr4(u_long cr4); +void load_dr0(uint64_t dr0); +void load_dr1(uint64_t dr1); +void load_dr2(uint64_t dr2); +void load_dr3(uint64_t dr3); +void load_dr6(uint64_t dr6); +void load_dr7(uint64_t dr7); +void load_fs(u_short sel); +void load_gs(u_short sel); +void ltr(u_short sel); +void outb(u_int port, u_char data); +void outl(u_int port, u_int data); +void outsb(u_int port, const void *addr, size_t count); +void outsl(u_int port, const void *addr, size_t count); +void outsw(u_int port, const void *addr, size_t count); +void outw(u_int port, u_short data); +u_long rcr0(void); +u_long rcr2(void); +u_long rcr3(void); +u_long rcr4(void); +uint64_t rdmsr(u_int msr); +uint32_t rdmsr32(u_int msr); +uint64_t rdpmc(u_int pmc); +uint64_t rdr0(void); +uint64_t rdr1(void); +uint64_t rdr2(void); +uint64_t rdr3(void); +uint64_t rdr6(void); +uint64_t rdr7(void); +uint64_t rdtsc(void); +u_long read_rflags(void); +u_int rfs(void); +u_int rgs(void); +void wbinvd(void); +void write_rflags(u_int rf); +void wrmsr(u_int msr, uint64_t newval); + +#endif /* __GNUCLIKE_ASM && __CC_SUPPORTS___INLINE */ + +void reset_dbregs(void); + +#ifdef _KERNEL +int rdmsr_safe(u_int msr, uint64_t *val); +int wrmsr_safe(u_int msr, uint64_t newval); +#endif + +#endif /* !_MACHINE_CPUFUNC_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/cputypes.h b/lib/libc/include/x86_64-freebsd-any/machine/cputypes.h new file mode 100644 index 000000000000..31c8e41a3159 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/cputypes.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/db_machdep.h b/lib/libc/include/x86_64-freebsd-any/machine/db_machdep.h new file mode 100644 index 000000000000..c88c281ff9a6 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/db_machdep.h @@ -0,0 +1,86 @@ +/*- + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include + +typedef vm_offset_t db_addr_t; /* address - unsigned */ +typedef long db_expr_t; /* expression - signed */ + +#define PC_REGS() ((db_addr_t)kdb_thrctx->pcb_rip) + +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define BKPT_SKIP \ +do { \ + kdb_frame->tf_rip += 1; \ + kdb_thrctx->pcb_rip += 1; \ +} while(0) + +#define FIXUP_PC_AFTER_BREAK \ +do { \ + kdb_frame->tf_rip -= 1; \ + kdb_thrctx->pcb_rip -= 1; \ +} while(0); + +#define db_clear_single_step kdb_cpu_clear_singlestep +#define db_set_single_step kdb_cpu_set_singlestep + +/* + * The debug exception type is copied from %dr6 to 'code' and used to + * disambiguate single step traps. Watchpoints have no special support. + * Our hardware breakpoints are not well integrated with ddb and are too + * different from watchpoints. ddb treats them as unknown traps with + * unknown addresses and doesn't turn them off while it is running. + */ +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +#define IS_SSTEP_TRAP(type, code) \ + ((type) == T_TRCTRAP && (code) & DBREG_DR6_BS) +#define IS_WATCHPOINT_TRAP(type, code) 0 + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define i_calli(ins) (((ins)&0xff) == I_CALLI && ((ins)&0x3800) == 0x1000) +#define I_RET 0xc3 +#define I_IRET 0xcf +#define i_rex(ins) (((ins) & 0xff) == 0x41 || ((ins) & 0xff) == 0x43) + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || i_calli(ins) || \ + (i_calli((ins) >> 8) && i_rex(ins))) +#define inst_load(ins) 0 +#define inst_store(ins) 0 + +#endif /* !_MACHINE_DB_MACHDEP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/dump.h b/lib/libc/include/x86_64-freebsd-any/machine/dump.h new file mode 100644 index 000000000000..815942d0d967 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/dump.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/efi.h b/lib/libc/include/x86_64-freebsd-any/machine/efi.h new file mode 100644 index 000000000000..e630a338c17e --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/efi.h @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2016 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __AMD64_INCLUDE_EFI_H_ +#define __AMD64_INCLUDE_EFI_H_ + +/* + * XXX: from gcc 6.2 manual: + * Note, the ms_abi attribute for Microsoft Windows 64-bit targets + * currently requires the -maccumulate-outgoing-args option. + * + * Avoid EFIABI_ATTR declarations for compilers that don't support it. + * GCC support began in version 4.4. + */ +#if defined(__clang__) || defined(__GNUC__) && \ + (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4) +#define EFIABI_ATTR __attribute__((ms_abi)) +#endif + +#ifdef _KERNEL +#include + +#define EFI_TIME_LOCK() mtx_lock(&atrtc_time_lock) +#define EFI_TIME_UNLOCK() mtx_unlock(&atrtc_time_lock) +#define EFI_TIME_OWNED() mtx_assert(&atrtc_time_lock, MA_OWNED) + +#define EFI_RT_HANDLE_FAULTS_DEFAULT 1 +#endif + +struct efirt_callinfo { + const char *ec_name; + register_t ec_efi_status; + register_t ec_fptr; + register_t ec_argcnt; + register_t ec_arg1; + register_t ec_arg2; + register_t ec_arg3; + register_t ec_arg4; + register_t ec_arg5; + register_t ec_rbx; + register_t ec_rsp; + register_t ec_rbp; + register_t ec_r12; + register_t ec_r13; + register_t ec_r14; + register_t ec_r15; + register_t ec_rflags; +}; + +#endif /* __AMD64_INCLUDE_EFI_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/elf.h b/lib/libc/include/x86_64-freebsd-any/machine/elf.h new file mode 100644 index 000000000000..f9323775dc24 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/elf.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/endian.h b/lib/libc/include/x86_64-freebsd-any/machine/endian.h new file mode 100644 index 000000000000..2ad27a9069b9 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/endian.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/exec.h b/lib/libc/include/x86_64-freebsd-any/machine/exec.h new file mode 100644 index 000000000000..099ea263e202 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/exec.h @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)exec.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _MACHINE_EXEC_H_ +#define _MACHINE_EXEC_H_ + +#define __LDPGSZ 4096 + +#endif /* !_MACHINE_EXEC_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/fdt.h b/lib/libc/include/x86_64-freebsd-any/machine/fdt.h new file mode 100644 index 000000000000..1a0351442890 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/fdt.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/float.h b/lib/libc/include/x86_64-freebsd-any/machine/float.h new file mode 100644 index 000000000000..4759963566ab --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/float.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/floatingpoint.h b/lib/libc/include/x86_64-freebsd-any/machine/floatingpoint.h new file mode 100644 index 000000000000..b7c154743d0c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/floatingpoint.h @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1993 Andrew Moore, Talke Studio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#) floatingpoint.h 1.0 (Berkeley) 9/23/93 + * $FreeBSD$ + */ + +#ifndef _FLOATINGPOINT_H_ +#define _FLOATINGPOINT_H_ + +#include +#include + +#endif /* !_FLOATINGPOINT_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/fpu.h b/lib/libc/include/x86_64-freebsd-any/machine/fpu.h new file mode 100644 index 000000000000..6b9782e7207b --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/fpu.h @@ -0,0 +1,95 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +/* + * Floating Point Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _MACHINE_FPU_H_ +#define _MACHINE_FPU_H_ + +#include + +#ifdef _KERNEL + +struct fpu_kern_ctx; + +#define PCB_USER_FPU(pcb) (((pcb)->pcb_flags & PCB_KERNFPU) == 0) + +#define XSAVE_AREA_ALIGN 64 + +void fpudna(void); +void fpudrop(void); +void fpuexit(struct thread *td); +int fpuformat(void); +int fpugetregs(struct thread *td); +void fpuinit(void); +void fpurestore(void *addr); +void fpuresume(void *addr); +void fpusave(void *addr); +int fpusetregs(struct thread *td, struct savefpu *addr, + char *xfpustate, size_t xfpustate_size); +int fpusetxstate(struct thread *td, char *xfpustate, + size_t xfpustate_size); +void fpususpend(void *addr); +int fputrap_sse(void); +int fputrap_x87(void); +void fpuuserinited(struct thread *td); +struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags); +void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx); +void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, + u_int flags); +int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx); +int fpu_kern_thread(u_int flags); +int is_fpu_kern_thread(u_int flags); + +struct savefpu *fpu_save_area_alloc(void); +void fpu_save_area_free(struct savefpu *fsa); +void fpu_save_area_reset(struct savefpu *fsa); + +/* + * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread(). + */ +#define FPU_KERN_NORMAL 0x0000 +#define FPU_KERN_NOWAIT 0x0001 +#define FPU_KERN_KTHR 0x0002 +#define FPU_KERN_NOCTX 0x0004 + +#endif + +#endif /* !_MACHINE_FPU_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/frame.h b/lib/libc/include/x86_64-freebsd-any/machine/frame.h new file mode 100644 index 000000000000..f0a6fcf5bc9c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/frame.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _AMD64_FRAME_H +#define _AMD64_FRAME_H + +#include + +struct pti_frame { + register_t pti_rdx; + register_t pti_rax; + register_t pti_err; + register_t pti_rip; + register_t pti_cs; + register_t pti_rflags; + register_t pti_rsp; + register_t pti_ss; +}; + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/machine/gdb_machdep.h b/lib/libc/include/x86_64-freebsd-any/machine/gdb_machdep.h new file mode 100644 index 000000000000..6ad8b01d00ca --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/gdb_machdep.h @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_GDB_MACHDEP_H_ +#define _MACHINE_GDB_MACHDEP_H_ + +#define GDB_BUFSZ (GDB_NREGS * 16) +#define GDB_NREGS 56 +#define GDB_REG_PC 16 + +static __inline size_t +gdb_cpu_regsz(int regnum) +{ + return ((regnum > 16 && regnum < 24) ? 4 : 8); +} + +static __inline int +gdb_cpu_query(void) +{ + return (0); +} + +void *gdb_begin_write(void); +void *gdb_cpu_getreg(int, size_t *); +void gdb_cpu_setreg(int, void *); +int gdb_cpu_signal(int, int); +void gdb_end_write(void *); + +#endif /* !_MACHINE_GDB_MACHDEP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/ieeefp.h b/lib/libc/include/x86_64-freebsd-any/machine/ieeefp.h new file mode 100644 index 000000000000..b2423eb00ed3 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/ieeefp.h @@ -0,0 +1,311 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1990 Andrew Moore, Talke Studio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93 + * $FreeBSD$ + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +/* + * Deprecated historical FPU control interface + * + * IEEE floating point type, constant and function definitions. + * XXX: {FP,SSE}*FLD and {FP,SSE}*OFF are undocumented pollution. + */ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +/* + * Rounding modes. + */ +typedef enum { + FP_RN=0, /* round to nearest */ + FP_RM, /* round down towards minus infinity */ + FP_RP, /* round up towards plus infinity */ + FP_RZ /* truncate */ +} fp_rnd_t; + +/* + * Precision (i.e., rounding precision) modes. + */ +typedef enum { + FP_PS=0, /* 24 bit (single-precision) */ + FP_PRS, /* reserved */ + FP_PD, /* 53 bit (double-precision) */ + FP_PE /* 64 bit (extended-precision) */ +} fp_prec_t; + +#define fp_except_t int + +/* + * Exception bit masks. + */ +#define FP_X_INV 0x01 /* invalid operation */ +#define FP_X_DNML 0x02 /* denormal */ +#define FP_X_DZ 0x04 /* zero divide */ +#define FP_X_OFL 0x08 /* overflow */ +#define FP_X_UFL 0x10 /* underflow */ +#define FP_X_IMP 0x20 /* (im)precision */ +#define FP_X_STK 0x40 /* stack fault */ + +/* + * FPU control word bit-field masks. + */ +#define FP_MSKS_FLD 0x3f /* exception masks field */ +#define FP_PRC_FLD 0x300 /* precision control field */ +#define FP_RND_FLD 0xc00 /* rounding control field */ + +/* + * FPU status word bit-field masks. + */ +#define FP_STKY_FLD 0x3f /* sticky flags field */ + +/* + * SSE mxcsr register bit-field masks. + */ +#define SSE_STKY_FLD 0x3f /* exception flags */ +#define SSE_DAZ_FLD 0x40 /* Denormals are zero */ +#define SSE_MSKS_FLD 0x1f80 /* exception masks field */ +#define SSE_RND_FLD 0x6000 /* rounding control */ +#define SSE_FZ_FLD 0x8000 /* flush to zero on underflow */ + +/* + * FPU control word bit-field offsets (shift counts). + */ +#define FP_MSKS_OFF 0 /* exception masks offset */ +#define FP_PRC_OFF 8 /* precision control offset */ +#define FP_RND_OFF 10 /* rounding control offset */ + +/* + * FPU status word bit-field offsets (shift counts). + */ +#define FP_STKY_OFF 0 /* sticky flags offset */ + +/* + * SSE mxcsr register bit-field offsets (shift counts). + */ +#define SSE_STKY_OFF 0 /* exception flags offset */ +#define SSE_DAZ_OFF 6 /* DAZ exception mask offset */ +#define SSE_MSKS_OFF 7 /* other exception masks offset */ +#define SSE_RND_OFF 13 /* rounding control offset */ +#define SSE_FZ_OFF 15 /* flush to zero offset */ + +#ifdef __GNUCLIKE_ASM + +#define __fldcw(addr) __asm __volatile("fldcw %0" : : "m" (*(addr))) +#define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) +#define __fnclex() __asm __volatile("fnclex") +#define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) +#define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) +#define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) +#define __ldmxcsr(addr) __asm __volatile("ldmxcsr %0" : : "m" (*(addr))) +#define __stmxcsr(addr) __asm __volatile("stmxcsr %0" : "=m" (*(addr))) + +/* + * Load the control word. Be careful not to trap if there is a currently + * unmasked exception (ones that will become freshly unmasked are not a + * problem). This case must be handled by a save/restore of the + * environment or even of the full x87 state. Accessing the environment + * is very inefficient, so only do it when necessary. + */ +static __inline void +__fnldcw(unsigned short _cw, unsigned short _newcw) +{ + struct { + unsigned _cw; + unsigned _other[6]; + } _env; + unsigned short _sw; + + if ((_cw & FP_MSKS_FLD) != FP_MSKS_FLD) { + __fnstsw(&_sw); + if (((_sw & ~_cw) & FP_STKY_FLD) != 0) { + __fnstenv(&_env); + _env._cw = _newcw; + __fldenv(&_env); + return; + } + } + __fldcw(&_newcw); +} + +/* + * General notes about conflicting SSE vs FP status bits. + * This code assumes that software will not fiddle with the control + * bits of the SSE and x87 in such a way to get them out of sync and + * still expect this to work. Break this at your peril. + * Because I based this on the i386 port, the x87 state is used for + * the fpget*() functions, and is shadowed into the SSE state for + * the fpset*() functions. For dual source fpget*() functions, I + * merge the two together. I think. + */ + +static __inline fp_rnd_t +__fpgetround(void) +{ + unsigned short _cw; + + __fnstcw(&_cw); + return ((fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF)); +} + +static __inline fp_rnd_t +__fpsetround(fp_rnd_t _m) +{ + fp_rnd_t _p; + unsigned _mxcsr; + unsigned short _cw, _newcw; + + __fnstcw(&_cw); + _p = (fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF); + _newcw = _cw & ~FP_RND_FLD; + _newcw |= (_m << FP_RND_OFF) & FP_RND_FLD; + __fnldcw(_cw, _newcw); + __stmxcsr(&_mxcsr); + _mxcsr &= ~SSE_RND_FLD; + _mxcsr |= (_m << SSE_RND_OFF) & SSE_RND_FLD; + __ldmxcsr(&_mxcsr); + return (_p); +} + +/* + * Get or set the rounding precision for x87 arithmetic operations. + * There is no equivalent SSE mode or control. + */ + +static __inline fp_prec_t +__fpgetprec(void) +{ + unsigned short _cw; + + __fnstcw(&_cw); + return ((fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF)); +} + +static __inline fp_prec_t +__fpsetprec(fp_prec_t _m) +{ + fp_prec_t _p; + unsigned short _cw, _newcw; + + __fnstcw(&_cw); + _p = (fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF); + _newcw = _cw & ~FP_PRC_FLD; + _newcw |= (_m << FP_PRC_OFF) & FP_PRC_FLD; + __fnldcw(_cw, _newcw); + return (_p); +} + +/* + * Get or set the exception mask. + * Note that the x87 mask bits are inverted by the API -- a mask bit of 1 + * means disable for x87 and SSE, but for fp*mask() it means enable. + */ + +static __inline fp_except_t +__fpgetmask(void) +{ + unsigned short _cw; + + __fnstcw(&_cw); + return ((~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF); +} + +static __inline fp_except_t +__fpsetmask(fp_except_t _m) +{ + fp_except_t _p; + unsigned _mxcsr; + unsigned short _cw, _newcw; + + __fnstcw(&_cw); + _p = (~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF; + _newcw = _cw & ~FP_MSKS_FLD; + _newcw |= (~_m << FP_MSKS_OFF) & FP_MSKS_FLD; + __fnldcw(_cw, _newcw); + __stmxcsr(&_mxcsr); + /* XXX should we clear non-ieee SSE_DAZ_FLD and SSE_FZ_FLD ? */ + _mxcsr &= ~SSE_MSKS_FLD; + _mxcsr |= (~_m << SSE_MSKS_OFF) & SSE_MSKS_FLD; + __ldmxcsr(&_mxcsr); + return (_p); +} + +static __inline fp_except_t +__fpgetsticky(void) +{ + unsigned _ex, _mxcsr; + unsigned short _sw; + + __fnstsw(&_sw); + _ex = (_sw & FP_STKY_FLD) >> FP_STKY_OFF; + __stmxcsr(&_mxcsr); + _ex |= (_mxcsr & SSE_STKY_FLD) >> SSE_STKY_OFF; + return ((fp_except_t)_ex); +} + +#endif /* __GNUCLIKE_ASM */ + +#if !defined(__IEEEFP_NOINLINES__) && defined(__GNUCLIKE_ASM) + +#define fpgetmask() __fpgetmask() +#define fpgetprec() __fpgetprec() +#define fpgetround() __fpgetround() +#define fpgetsticky() __fpgetsticky() +#define fpsetmask(m) __fpsetmask(m) +#define fpsetprec(m) __fpsetprec(m) +#define fpsetround(m) __fpsetround(m) + +#else /* !(!__IEEEFP_NOINLINES__ && __GNUCLIKE_ASM) */ + +/* Augment the userland declarations. */ +__BEGIN_DECLS +extern fp_rnd_t fpgetround(void); +extern fp_rnd_t fpsetround(fp_rnd_t); +extern fp_except_t fpgetmask(void); +extern fp_except_t fpsetmask(fp_except_t); +extern fp_except_t fpgetsticky(void); +extern fp_except_t fpsetsticky(fp_except_t); +fp_prec_t fpgetprec(void); +fp_prec_t fpsetprec(fp_prec_t); +__END_DECLS + +#endif /* !__IEEEFP_NOINLINES__ && __GNUCLIKE_ASM */ + +#endif /* !_MACHINE_IEEEFP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/in_cksum.h b/lib/libc/include/x86_64-freebsd-any/machine/in_cksum.h new file mode 100644 index 000000000000..79d30cafbc90 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/in_cksum.h @@ -0,0 +1,86 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from tahoe: in_cksum.c 1.2 86/01/05 + * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 + * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp + * $FreeBSD$ + */ + +#ifndef _MACHINE_IN_CKSUM_H_ +#define _MACHINE_IN_CKSUM_H_ 1 + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +#include + +#define in_cksum(m, len) in_cksum_skip(m, len, 0) + +#if defined(IPVERSION) && (IPVERSION == 4) +/* + * It it useful to have an Internet checksum routine which is inlineable + * and optimized specifically for the task of computing IP header checksums + * in the normal case (where there are no options and the header length is + * therefore always exactly five 32-bit words. + */ +#ifdef __CC_SUPPORTS___INLINE + +static __inline void +in_cksum_update(struct ip *ip) +{ + int __tmpsum; + __tmpsum = (int)ntohs(ip->ip_sum) + 256; + ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); +} + +#else + +#define in_cksum_update(ip) \ + do { \ + int __tmpsum; \ + __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ + ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ + } while(0) + +#endif +#endif + +#ifdef _KERNEL +#if defined(IPVERSION) && (IPVERSION == 4) +u_int in_cksum_hdr(const struct ip *ip); +#endif +u_short in_addword(u_short sum, u_short b); +u_short in_pseudo(u_int sum, u_int b, u_int c); +u_short in_cksum_skip(struct mbuf *m, int len, int skip); +#endif + +#endif /* _MACHINE_IN_CKSUM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/intr_machdep.h b/lib/libc/include/x86_64-freebsd-any/machine/intr_machdep.h new file mode 100644 index 000000000000..4101cdb8abd3 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/intr_machdep.h @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __MACHINE_INTR_MACHDEP_H__ +#define __MACHINE_INTR_MACHDEP_H__ + +#include + +/* + * The following data structure holds per-cpu data, and is placed just + * above the top of the space used for the NMI and MC# stacks. + */ +struct nmi_pcpu { + register_t np_pcpu; + register_t __padding; /* pad to 16 bytes */ +}; + +#endif /* !__MACHINE_INTR_MACHDEP_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/iodev.h b/lib/libc/include/x86_64-freebsd-any/machine/iodev.h new file mode 100644 index 000000000000..5aced158609e --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/iodev.h @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Mark R V Murray + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _MACHINE_IODEV_H_ +#define _MACHINE_IODEV_H_ + +#ifdef _KERNEL +#include + +#define iodev_read_1 inb +#define iodev_read_2 inw +#define iodev_read_4 inl +#define iodev_write_1 outb +#define iodev_write_2 outw +#define iodev_write_4 outl + +int iodev_open(struct thread *td); +int iodev_close(struct thread *td); +int iodev_ioctl(u_long cmd, caddr_t data); + +#endif /* _KERNEL */ +#endif /* _MACHINE_IODEV_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/kdb.h b/lib/libc/include/x86_64-freebsd-any/machine/kdb.h new file mode 100644 index 000000000000..2fb158622eb4 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/kdb.h @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_KDB_H_ +#define _MACHINE_KDB_H_ + +#include +#include + +#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid] + +static __inline void +kdb_cpu_clear_singlestep(void) +{ + kdb_frame->tf_rflags &= ~PSL_T; +} + +static __inline void +kdb_cpu_set_singlestep(void) +{ + kdb_frame->tf_rflags |= PSL_T; +} + +static __inline void +kdb_cpu_sync_icache(unsigned char *addr, size_t size) +{ +} + +static __inline void +kdb_cpu_trap(int type, int code) +{ +} + +#endif /* _MACHINE_KDB_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/limits.h b/lib/libc/include/x86_64-freebsd-any/machine/limits.h new file mode 100644 index 000000000000..5a7b831b3089 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/limits.h @@ -0,0 +1,46 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#ifdef __CC_SUPPORTS_WARNING +#warning "machine/limits.h is deprecated. Include sys/limits.h instead." +#endif + +#include + +#endif /* !_MACHINE_LIMITS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/md_var.h b/lib/libc/include/x86_64-freebsd-any/machine/md_var.h new file mode 100644 index 000000000000..8d866fee846a --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/md_var.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1995 Bruce D. Evans. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_MD_VAR_H_ +#define _MACHINE_MD_VAR_H_ + +#include + +extern uint64_t *vm_page_dump; +extern int hw_lower_amd64_sharedpage; +extern int hw_ibrs_disable; +extern int hw_ssb_disable; +extern int nmi_flush_l1d_sw; +extern int syscall_ret_l1d_flush_mode; + +extern vm_paddr_t intel_graphics_stolen_base; +extern vm_paddr_t intel_graphics_stolen_size; + +/* + * The file "conf/ldscript.amd64" defines the symbol "kernphys". Its + * value is the physical address at which the kernel is loaded. + */ +extern char kernphys[]; + +struct savefpu; +struct sysentvec; + +void amd64_conf_fast_syscall(void); +void amd64_db_resume_dbreg(void); +void amd64_lower_shared_page(struct sysentvec *); +void amd64_bsp_pcpu_init1(struct pcpu *pc); +void amd64_bsp_pcpu_init2(uint64_t rsp0); +void amd64_bsp_ist_init(struct pcpu *pc); +void amd64_syscall(struct thread *td, int traced); +void amd64_syscall_ret_flush_l1d(int error); +void amd64_syscall_ret_flush_l1d_recalc(void); +void doreti_iret(void) __asm(__STRING(doreti_iret)); +void doreti_iret_fault(void) __asm(__STRING(doreti_iret_fault)); +void flush_l1d_sw_abi(void); +void ld_ds(void) __asm(__STRING(ld_ds)); +void ld_es(void) __asm(__STRING(ld_es)); +void ld_fs(void) __asm(__STRING(ld_fs)); +void ld_gs(void) __asm(__STRING(ld_gs)); +void ld_fsbase(void) __asm(__STRING(ld_fsbase)); +void ld_gsbase(void) __asm(__STRING(ld_gsbase)); +void ds_load_fault(void) __asm(__STRING(ds_load_fault)); +void es_load_fault(void) __asm(__STRING(es_load_fault)); +void fs_load_fault(void) __asm(__STRING(fs_load_fault)); +void gs_load_fault(void) __asm(__STRING(gs_load_fault)); +void fsbase_load_fault(void) __asm(__STRING(fsbase_load_fault)); +void gsbase_load_fault(void) __asm(__STRING(gsbase_load_fault)); +void fpstate_drop(struct thread *td); +void pagezero(void *addr); +void setidt(int idx, alias_for_inthand_t *func, int typ, int dpl, int ist); +void sse2_pagezero(void *addr); +void set_top_of_stack_td(struct thread *td); +struct savefpu *get_pcb_user_save_td(struct thread *td); +struct savefpu *get_pcb_user_save_pcb(struct pcb *pcb); +void pci_early_quirks(void); + +#endif /* !_MACHINE_MD_VAR_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/memdev.h b/lib/libc/include/x86_64-freebsd-any/machine/memdev.h new file mode 100644 index 000000000000..41e34da79264 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/memdev.h @@ -0,0 +1,42 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Mark R V Murray + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_MEMDEV_H_ +#define _MACHINE_MEMDEV_H_ + +#define CDEV_MINOR_MEM 0 +#define CDEV_MINOR_KMEM 1 + +d_open_t memopen; +d_read_t memrw; +d_ioctl_t memioctl; +d_mmap_t memmmap; + +#endif /* _MACHINE_MEMDEV_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/metadata.h b/lib/libc/include/x86_64-freebsd-any/machine/metadata.h new file mode 100644 index 000000000000..98d0272fd4cc --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/metadata.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/minidump.h b/lib/libc/include/x86_64-freebsd-any/machine/minidump.h new file mode 100644 index 000000000000..21bbdadc99dc --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/minidump.h @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2006 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_MINIDUMP_H_ +#define _MACHINE_MINIDUMP_H_ 1 + +#define MINIDUMP_MAGIC "minidump FreeBSD/amd64" +#define MINIDUMP_VERSION 2 + +struct minidumphdr { + char magic[24]; + uint32_t version; + uint32_t msgbufsize; + uint32_t bitmapsize; + uint32_t pmapsize; + uint64_t kernbase; + uint64_t dmapbase; + uint64_t dmapend; +}; + +#endif /* _MACHINE_MINIDUMP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/mp_watchdog.h b/lib/libc/include/x86_64-freebsd-any/machine/mp_watchdog.h new file mode 100644 index 000000000000..e1fc0742ee1e --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/mp_watchdog.h @@ -0,0 +1,36 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2004 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_MP_WATCHDOG_H_ +#define _MACHINE_MP_WATCHDOG_H_ + +void ap_watchdog(u_int cpuid); + +#endif /* !_MACHINE_MP_WATCHDOG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/nexusvar.h b/lib/libc/include/x86_64-freebsd-any/machine/nexusvar.h new file mode 100644 index 000000000000..c39a686b4937 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/nexusvar.h @@ -0,0 +1,45 @@ +/*- + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_NEXUSVAR_H_ +#define _MACHINE_NEXUSVAR_H_ + +struct nexus_device { + struct resource_list nx_resources; +}; + +DECLARE_CLASS(nexus_driver); + +extern struct rman irq_rman, drq_rman, port_rman, mem_rman; + +void nexus_init_resources(void); + +#endif /* !_MACHINE_NEXUSVAR_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/npx.h b/lib/libc/include/x86_64-freebsd-any/machine/npx.h new file mode 100644 index 000000000000..ec70f1c368a1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/npx.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/ofw_machdep.h b/lib/libc/include/x86_64-freebsd-any/machine/ofw_machdep.h new file mode 100644 index 000000000000..4457f85908c2 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/ofw_machdep.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/param.h b/lib/libc/include/x86_64-freebsd-any/machine/param.h new file mode 100644 index 000000000000..86f7e08d9725 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/param.h @@ -0,0 +1,161 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)param.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD$ + */ + + +#ifndef _AMD64_INCLUDE_PARAM_H_ +#define _AMD64_INCLUDE_PARAM_H_ + +#include + +/* + * Machine dependent constants for AMD64. + */ + + +#define __HAVE_ACPI +#define __PCI_REROUTE_INTERRUPT + +#ifndef MACHINE +#define MACHINE "amd64" +#endif +#ifndef MACHINE_ARCH +#define MACHINE_ARCH "amd64" +#endif +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "i386" +#endif + +#if defined(SMP) || defined(KLD_MODULE) +#ifndef MAXCPU +#define MAXCPU 256 +#endif +#else +#define MAXCPU 1 +#endif + +#ifndef MAXMEMDOM +#define MAXMEMDOM 8 +#endif + +#define ALIGNBYTES _ALIGNBYTES +#define ALIGN(p) _ALIGN(p) +/* + * ALIGNED_POINTER is a boolean macro that checks whether an address + * is valid to fetch data elements of type t from on this architecture. + * This does not reflect the optimal alignment, just the possibility + * (within reasonable limits). + */ +#define ALIGNED_POINTER(p, t) 1 + +/* + * CACHE_LINE_SIZE is the compile-time maximum cache line size for an + * architecture. It should be used with appropriate caution. + */ +#define CACHE_LINE_SHIFT 6 +#define CACHE_LINE_SIZE (1 << CACHE_LINE_SHIFT) + +/* Size of the level 1 page table units */ +#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) +#define NPTEPGSHIFT 9 /* LOG2(NPTEPG) */ +#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ +#define PAGE_SIZE (1<> PAGE_SHIFT) +#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT) + +#define amd64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT) +#define amd64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT) + +#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024)) + +#define INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < DMAP_MAX_ADDRESS) \ + || ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS)) + +#ifdef SMP +#define SC_TABLESIZE 1024 /* Must be power of 2. */ +#endif + +#endif /* !_AMD64_INCLUDE_PARAM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pc/bios.h b/lib/libc/include/x86_64-freebsd-any/machine/pc/bios.h new file mode 100644 index 000000000000..7534b5111299 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pc/bios.h @@ -0,0 +1,126 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997 Michael Smith + * Copyright (c) 1998 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_PC_BIOS_H_ +#define _MACHINE_PC_BIOS_H_ + +/* + * Int 15:E820 'SMAP' structure + */ +#define SMAP_SIG 0x534D4150 /* 'SMAP' */ + +#define SMAP_TYPE_MEMORY 1 +#define SMAP_TYPE_RESERVED 2 +#define SMAP_TYPE_ACPI_RECLAIM 3 +#define SMAP_TYPE_ACPI_NVS 4 +#define SMAP_TYPE_ACPI_ERROR 5 +#define SMAP_TYPE_DISABLED 6 +#define SMAP_TYPE_PMEM 7 +#define SMAP_TYPE_PRAM 12 + +#define SMAP_XATTR_ENABLED 0x00000001 +#define SMAP_XATTR_NON_VOLATILE 0x00000002 +#define SMAP_XATTR_MASK (SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE) + +struct bios_smap { + u_int64_t base; + u_int64_t length; + u_int32_t type; +} __packed; + +/* Structure extended to include extended attribute field in ACPI 3.0. */ +struct bios_smap_xattr { + u_int64_t base; + u_int64_t length; + u_int32_t type; + u_int32_t xattr; +} __packed; + +/* + * System Management BIOS + */ +#define SMBIOS_START 0xf0000 +#define SMBIOS_STEP 0x10 +#define SMBIOS_OFF 0 +#define SMBIOS_LEN 4 +#define SMBIOS_SIG "_SM_" + +struct smbios_eps { + uint8_t anchor_string[4]; /* '_SM_' */ + uint8_t checksum; + uint8_t length; + uint8_t major_version; + uint8_t minor_version; + uint16_t maximum_structure_size; + uint8_t entry_point_revision; + uint8_t formatted_area[5]; + uint8_t intermediate_anchor_string[5]; /* '_DMI_' */ + uint8_t intermediate_checksum; + uint16_t structure_table_length; + uint32_t structure_table_address; + uint16_t number_structures; + uint8_t BCD_revision; +}; + +struct smbios_structure_header { + uint8_t type; + uint8_t length; + uint16_t handle; +}; + +#ifdef _KERNEL +#define BIOS_PADDRTOVADDR(x) ((x) + KERNBASE) +#define BIOS_VADDRTOPADDR(x) ((x) - KERNBASE) + +struct bios_oem_signature { + char * anchor; /* search anchor string in BIOS memory */ + size_t offset; /* offset from anchor (may be negative) */ + size_t totlen; /* total length of BIOS string to copy */ +} __packed; + +struct bios_oem_range { + u_int from; /* shouldn't be below 0xe0000 */ + u_int to; /* shouldn't be above 0xfffff */ +} __packed; + +struct bios_oem { + struct bios_oem_range range; + struct bios_oem_signature signature[]; +} __packed; + +int bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen); +uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen, + int sigofs); +void bios_add_smap_entries(struct bios_smap *smapbase, u_int32_t smapsize, + vm_paddr_t *physmap, int *physmap_idx); +#endif + +#endif /* _MACHINE_PC_BIOS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pc/display.h b/lib/libc/include/x86_64-freebsd-any/machine/pc/display.h new file mode 100644 index 000000000000..cd2d5ff35b73 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pc/display.h @@ -0,0 +1,45 @@ +/* + * IBM PC display definitions + * + * $FreeBSD$ + */ + +/* Color attributes for foreground text */ + +#define FG_BLACK 0 +#define FG_BLUE 1 +#define FG_GREEN 2 +#define FG_CYAN 3 +#define FG_RED 4 +#define FG_MAGENTA 5 +#define FG_BROWN 6 +#define FG_LIGHTGREY 7 +#define FG_DARKGREY 8 +#define FG_LIGHTBLUE 9 +#define FG_LIGHTGREEN 10 +#define FG_LIGHTCYAN 11 +#define FG_LIGHTRED 12 +#define FG_LIGHTMAGENTA 13 +#define FG_YELLOW 14 +#define FG_WHITE 15 +#define FG_BLINK 0x80 + +/* Color attributes for text background */ + +#define BG_BLACK 0x00 +#define BG_BLUE 0x10 +#define BG_GREEN 0x20 +#define BG_CYAN 0x30 +#define BG_RED 0x40 +#define BG_MAGENTA 0x50 +#define BG_BROWN 0x60 +#define BG_LIGHTGREY 0x70 + +/* Monochrome attributes for foreground text */ + +#define FG_UNDERLINE 0x01 +#define FG_INTENSE 0x08 + +/* Monochrome attributes for text background */ + +#define BG_INTENSE 0x10 diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pcb.h b/lib/libc/include/x86_64-freebsd-any/machine/pcb.h new file mode 100644 index 000000000000..8800b355c9a1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pcb.h @@ -0,0 +1,139 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)pcb.h 5.10 (Berkeley) 5/12/91 + * $FreeBSD$ + */ + +#ifndef _AMD64_PCB_H_ +#define _AMD64_PCB_H_ + +/* + * AMD64 process control block + */ +#include +#include + +#ifdef __amd64__ +/* + * NB: The fields marked with (*) are used by kernel debuggers. Their + * ABI should be preserved. + */ +struct pcb { + register_t pcb_r15; /* (*) */ + register_t pcb_r14; /* (*) */ + register_t pcb_r13; /* (*) */ + register_t pcb_r12; /* (*) */ + register_t pcb_rbp; /* (*) */ + register_t pcb_rsp; /* (*) */ + register_t pcb_rbx; /* (*) */ + register_t pcb_rip; /* (*) */ + register_t pcb_fsbase; + register_t pcb_gsbase; + register_t pcb_kgsbase; + register_t pcb_cr0; + register_t pcb_cr2; + register_t pcb_cr3; + register_t pcb_cr4; + register_t pcb_dr0; + register_t pcb_dr1; + register_t pcb_dr2; + register_t pcb_dr3; + register_t pcb_dr6; + register_t pcb_dr7; + + struct region_descriptor pcb_gdt; + struct region_descriptor pcb_idt; + struct region_descriptor pcb_ldt; + uint16_t pcb_tr; + + u_int pcb_flags; +#define PCB_FULL_IRET 0x01 /* full iret is required */ +#define PCB_DBREGS 0x02 /* process using debug registers */ +#define PCB_KERNFPU 0x04 /* kernel uses fpu */ +#define PCB_FPUINITDONE 0x08 /* fpu state is initialized */ +#define PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */ +#define PCB_32BIT 0x40 /* process has 32 bit context (segs etc) */ +#define PCB_FPUNOSAVE 0x80 /* no save area for current FPU ctx */ + + uint16_t pcb_initial_fpucw; + + /* copyin/out fault recovery */ + caddr_t pcb_onfault; + + uint64_t pcb_saved_ucr3; + + /* local tss, with i/o bitmap; NULL for common */ + struct amd64tss *pcb_tssp; + + /* model specific registers */ + register_t pcb_efer; + register_t pcb_star; + register_t pcb_lstar; + register_t pcb_cstar; + register_t pcb_sfmask; + + struct savefpu *pcb_save; + + uint64_t pcb_pad[5]; +}; + +/* Per-CPU state saved during suspend and resume. */ +struct susppcb { + struct pcb sp_pcb; + + /* fpu context for suspend/resume */ + void *sp_fpususpend; +}; +#else /* 32bit */ +struct pcb { + uint64_t pcb_dummy[40]; +}; +#endif + +#ifdef _KERNEL +struct trapframe; + +void clear_pcb_flags(struct pcb *pcb, const u_int flags); +void makectx(struct trapframe *, struct pcb *); +void set_pcb_flags(struct pcb *pcb, const u_int flags); +void set_pcb_flags_raw(struct pcb *pcb, const u_int flags); +int savectx(struct pcb *) __returns_twice; +void resumectx(struct pcb *); + +/* Ensure that pcb_gsbase and pcb_fsbase are up to date */ +#define update_pcb_bases(pcb) set_pcb_flags((pcb), PCB_FULL_IRET) +#endif + +#endif /* _AMD64_PCB_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pci_cfgreg.h b/lib/libc/include/x86_64-freebsd-any/machine/pci_cfgreg.h new file mode 100644 index 000000000000..717d5cc39fba --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pci_cfgreg.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pcpu.h b/lib/libc/include/x86_64-freebsd-any/machine/pcpu.h new file mode 100644 index 000000000000..fde64936f9f8 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pcpu.h @@ -0,0 +1,234 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_PCPU_H_ +#define _MACHINE_PCPU_H_ + +#ifndef _SYS_CDEFS_H_ +#error "sys/cdefs.h is a prerequisite for this file" +#endif + +#define PC_PTI_STACK_SZ 16 +/* + * The SMP parts are setup in pmap.c and locore.s for the BSP, and + * mp_machdep.c sets up the data for the AP's to "see" when they awake. + * The reason for doing it via a struct is so that an array of pointers + * to each CPU's data can be set up for things like "check curproc on all + * other processors" + */ +#define PCPU_MD_FIELDS \ + char pc_monitorbuf[128] __aligned(128); /* cache line */ \ + struct pcpu *pc_prvspace; /* Self-reference */ \ + struct pmap *pc_curpmap; \ + struct amd64tss *pc_tssp; /* TSS segment active on CPU */ \ + struct amd64tss *pc_commontssp;/* Common TSS for the CPU */ \ + uint64_t pc_kcr3; \ + uint64_t pc_ucr3; \ + uint64_t pc_saved_ucr3; \ + register_t pc_rsp0; \ + register_t pc_scratch_rsp; /* User %rsp in syscall */ \ + register_t pc_scratch_rax; \ + u_int pc_apic_id; \ + u_int pc_acpi_id; /* ACPI CPU id */ \ + /* Pointer to the CPU %fs descriptor */ \ + struct user_segment_descriptor *pc_fs32p; \ + /* Pointer to the CPU %gs descriptor */ \ + struct user_segment_descriptor *pc_gs32p; \ + /* Pointer to the CPU LDT descriptor */ \ + struct system_segment_descriptor *pc_ldt; \ + /* Pointer to the CPU TSS descriptor */ \ + struct system_segment_descriptor *pc_tss; \ + uint64_t pc_pm_save_cnt; \ + u_int pc_cmci_mask; /* MCx banks for CMCI */ \ + uint64_t pc_dbreg[16]; /* ddb debugging regs */ \ + uint64_t pc_pti_stack[PC_PTI_STACK_SZ]; \ + register_t pc_pti_rsp0; \ + int pc_dbreg_cmd; /* ddb debugging reg cmd */ \ + u_int pc_vcpu_id; /* Xen vCPU ID */ \ + uint32_t pc_pcid_next; \ + uint32_t pc_pcid_gen; \ + uint32_t pc_smp_tlb_done; /* TLB op acknowledgement */ \ + uint32_t pc_ibpb_set; \ + void *pc_mds_buf; \ + void *pc_mds_buf64; \ + uint32_t pc_pad[2]; \ + uint8_t pc_mds_tmp[64]; \ + char __pad[3176] /* pad to UMA_PCPU_ALLOC_SIZE */ + +#define PC_DBREG_CMD_NONE 0 +#define PC_DBREG_CMD_LOAD 1 + +#ifdef _KERNEL + +#if defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) + +/* + * Evaluates to the byte offset of the per-cpu variable name. + */ +#define __pcpu_offset(name) \ + __offsetof(struct pcpu, name) + +/* + * Evaluates to the type of the per-cpu variable name. + */ +#define __pcpu_type(name) \ + __typeof(((struct pcpu *)0)->name) + +/* + * Evaluates to the address of the per-cpu variable name. + */ +#define __PCPU_PTR(name) __extension__ ({ \ + __pcpu_type(name) *__p; \ + \ + __asm __volatile("movq %%gs:%1,%0; addq %2,%0" \ + : "=r" (__p) \ + : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace))), \ + "i" (__pcpu_offset(name))); \ + \ + __p; \ +}) + +/* + * Evaluates to the value of the per-cpu variable name. + */ +#define __PCPU_GET(name) __extension__ ({ \ + __pcpu_type(name) __res; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + if (sizeof(__res) == 1 || sizeof(__res) == 2 || \ + sizeof(__res) == 4 || sizeof(__res) == 8) { \ + __asm __volatile("mov %%gs:%1,%0" \ + : "=r" (__s) \ + : "m" (*(struct __s *)(__pcpu_offset(name)))); \ + *(struct __s *)(void *)&__res = __s; \ + } else { \ + __res = *__PCPU_PTR(name); \ + } \ + __res; \ +}) + +/* + * Adds the value to the per-cpu counter name. The implementation + * must be atomic with respect to interrupts. + */ +#define __PCPU_ADD(name, val) do { \ + __pcpu_type(name) __val; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + __val = (val); \ + if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ + sizeof(__val) == 4 || sizeof(__val) == 8) { \ + __s = *(struct __s *)(void *)&__val; \ + __asm __volatile("add %1,%%gs:%0" \ + : "=m" (*(struct __s *)(__pcpu_offset(name))) \ + : "r" (__s)); \ + } else \ + *__PCPU_PTR(name) += __val; \ +} while (0) + +/* + * Increments the value of the per-cpu counter name. The implementation + * must be atomic with respect to interrupts. + */ +#define __PCPU_INC(name) do { \ + CTASSERT(sizeof(__pcpu_type(name)) == 1 || \ + sizeof(__pcpu_type(name)) == 2 || \ + sizeof(__pcpu_type(name)) == 4 || \ + sizeof(__pcpu_type(name)) == 8); \ + if (sizeof(__pcpu_type(name)) == 1) { \ + __asm __volatile("incb %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 2) { \ + __asm __volatile("incw %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 4) { \ + __asm __volatile("incl %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 8) { \ + __asm __volatile("incq %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } \ +} while (0) + +/* + * Sets the value of the per-cpu variable name to value val. + */ +#define __PCPU_SET(name, val) { \ + __pcpu_type(name) __val; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + __val = (val); \ + if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ + sizeof(__val) == 4 || sizeof(__val) == 8) { \ + __s = *(struct __s *)(void *)&__val; \ + __asm __volatile("mov %1,%%gs:%0" \ + : "=m" (*(struct __s *)(__pcpu_offset(name))) \ + : "r" (__s)); \ + } else { \ + *__PCPU_PTR(name) = __val; \ + } \ +} + +#define get_pcpu() __extension__ ({ \ + struct pcpu *__pc; \ + \ + __asm __volatile("movq %%gs:%1,%0" \ + : "=r" (__pc) \ + : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace)))); \ + __pc; \ +}) + +#define PCPU_GET(member) __PCPU_GET(pc_ ## member) +#define PCPU_ADD(member, val) __PCPU_ADD(pc_ ## member, val) +#define PCPU_INC(member) __PCPU_INC(pc_ ## member) +#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) +#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) + +#define IS_BSP() (PCPU_GET(cpuid) == 0) + +#else /* !__GNUCLIKE_ASM || !__GNUCLIKE___TYPEOF */ + +#error "this file needs to be ported to your compiler" + +#endif /* __GNUCLIKE_ASM && __GNUCLIKE___TYPEOF */ + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PCPU_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pcpu_aux.h b/lib/libc/include/x86_64-freebsd-any/machine/pcpu_aux.h new file mode 100644 index 000000000000..50dfa30fbf5b --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pcpu_aux.h @@ -0,0 +1,62 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 The FreeBSD Foundation + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_PCPU_AUX_H_ +#define _MACHINE_PCPU_AUX_H_ + +#ifndef _KERNEL +#error "Not for userspace" +#endif + +#ifndef _SYS_PCPU_H_ +#error "Do not include machine/pcpu_aux.h directly" +#endif + +/* Required for counters(9) to work on x86. */ +_Static_assert(sizeof(struct pcpu) == UMA_PCPU_ALLOC_SIZE, "fix pcpu size"); + +extern struct pcpu *__pcpu; +extern struct pcpu temp_bsp_pcpu; + +static __inline __pure2 struct thread * +__curthread(void) +{ + struct thread *td; + + __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (offsetof(struct pcpu, + pc_curthread))); + return (td); +} +#define curthread (__curthread()) +#define curpcb (&curthread->td_md.md_pcb) + +#endif /* _MACHINE_PCPU_AUX_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pmap.h b/lib/libc/include/x86_64-freebsd-any/machine/pmap.h new file mode 100644 index 000000000000..9589cfd46f1b --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pmap.h @@ -0,0 +1,507 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1991 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and William Jolitz of UUNET Technologies Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Derived from hp300 version by Mike Hibler, this version by William + * Jolitz uses a recursive map [a pde points to the page directory] to + * map the page tables using the pagetables themselves. This is done to + * reduce the impact on kernel virtual memory for lots of sparse address + * space, and to reduce the cost of memory to each process. + * + * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +/* + * Page-directory and page-table entries follow this format, with a few + * of the fields not present here and there, depending on a lot of things. + */ + /* ---- Intel Nomenclature ---- */ +#define X86_PG_V 0x001 /* P Valid */ +#define X86_PG_RW 0x002 /* R/W Read/Write */ +#define X86_PG_U 0x004 /* U/S User/Supervisor */ +#define X86_PG_NC_PWT 0x008 /* PWT Write through */ +#define X86_PG_NC_PCD 0x010 /* PCD Cache disable */ +#define X86_PG_A 0x020 /* A Accessed */ +#define X86_PG_M 0x040 /* D Dirty */ +#define X86_PG_PS 0x080 /* PS Page size (0=4k,1=2M) */ +#define X86_PG_PTE_PAT 0x080 /* PAT PAT index */ +#define X86_PG_G 0x100 /* G Global */ +#define X86_PG_AVAIL1 0x200 /* / Available for system */ +#define X86_PG_AVAIL2 0x400 /* < programmers use */ +#define X86_PG_AVAIL3 0x800 /* \ */ +#define X86_PG_PDE_PAT 0x1000 /* PAT PAT index */ +#define X86_PG_PKU(idx) ((pt_entry_t)idx << 59) +#define X86_PG_NX (1ul<<63) /* No-execute */ +#define X86_PG_AVAIL(x) (1ul << (x)) + +/* Page level cache control fields used to determine the PAT type */ +#define X86_PG_PDE_CACHE (X86_PG_PDE_PAT | X86_PG_NC_PWT | X86_PG_NC_PCD) +#define X86_PG_PTE_CACHE (X86_PG_PTE_PAT | X86_PG_NC_PWT | X86_PG_NC_PCD) + +/* Protection keys indexes */ +#define PMAP_MAX_PKRU_IDX 0xf +#define X86_PG_PKU_MASK X86_PG_PKU(PMAP_MAX_PKRU_IDX) + +/* + * Intel extended page table (EPT) bit definitions. + */ +#define EPT_PG_READ 0x001 /* R Read */ +#define EPT_PG_WRITE 0x002 /* W Write */ +#define EPT_PG_EXECUTE 0x004 /* X Execute */ +#define EPT_PG_IGNORE_PAT 0x040 /* IPAT Ignore PAT */ +#define EPT_PG_PS 0x080 /* PS Page size */ +#define EPT_PG_A 0x100 /* A Accessed */ +#define EPT_PG_M 0x200 /* D Dirty */ +#define EPT_PG_MEMORY_TYPE(x) ((x) << 3) /* MT Memory Type */ + +/* + * Define the PG_xx macros in terms of the bits on x86 PTEs. + */ +#define PG_V X86_PG_V +#define PG_RW X86_PG_RW +#define PG_U X86_PG_U +#define PG_NC_PWT X86_PG_NC_PWT +#define PG_NC_PCD X86_PG_NC_PCD +#define PG_A X86_PG_A +#define PG_M X86_PG_M +#define PG_PS X86_PG_PS +#define PG_PTE_PAT X86_PG_PTE_PAT +#define PG_G X86_PG_G +#define PG_AVAIL1 X86_PG_AVAIL1 +#define PG_AVAIL2 X86_PG_AVAIL2 +#define PG_AVAIL3 X86_PG_AVAIL3 +#define PG_PDE_PAT X86_PG_PDE_PAT +#define PG_NX X86_PG_NX +#define PG_PDE_CACHE X86_PG_PDE_CACHE +#define PG_PTE_CACHE X86_PG_PTE_CACHE + +/* Our various interpretations of the above */ +#define PG_W X86_PG_AVAIL3 /* "Wired" pseudoflag */ +#define PG_MANAGED X86_PG_AVAIL2 +#define EPT_PG_EMUL_V X86_PG_AVAIL(52) +#define EPT_PG_EMUL_RW X86_PG_AVAIL(53) +#define PG_PROMOTED X86_PG_AVAIL(54) /* PDE only */ +#define PG_FRAME (0x000ffffffffff000ul) +#define PG_PS_FRAME (0x000fffffffe00000ul) +#define PG_PS_PDP_FRAME (0x000fffffc0000000ul) + +/* + * Promotion to a 2MB (PDE) page mapping requires that the corresponding 4KB + * (PTE) page mappings have identical settings for the following fields: + */ +#define PG_PTE_PROMOTE (PG_NX | PG_MANAGED | PG_W | PG_G | PG_PTE_CACHE | \ + PG_M | PG_A | PG_U | PG_RW | PG_V | PG_PKU_MASK) + +/* + * Page Protection Exception bits + */ + +#define PGEX_P 0x01 /* Protection violation vs. not present */ +#define PGEX_W 0x02 /* during a Write cycle */ +#define PGEX_U 0x04 /* access from User mode (UPL) */ +#define PGEX_RSV 0x08 /* reserved PTE field is non-zero */ +#define PGEX_I 0x10 /* during an instruction fetch */ +#define PGEX_PK 0x20 /* protection key violation */ +#define PGEX_SGX 0x8000 /* SGX-related */ + +/* + * undef the PG_xx macros that define bits in the regular x86 PTEs that + * have a different position in nested PTEs. This is done when compiling + * code that needs to be aware of the differences between regular x86 and + * nested PTEs. + * + * The appropriate bitmask will be calculated at runtime based on the pmap + * type. + */ +#ifdef AMD64_NPT_AWARE +#undef PG_AVAIL1 /* X86_PG_AVAIL1 aliases with EPT_PG_M */ +#undef PG_G +#undef PG_A +#undef PG_M +#undef PG_PDE_PAT +#undef PG_PDE_CACHE +#undef PG_PTE_PAT +#undef PG_PTE_CACHE +#undef PG_RW +#undef PG_V +#endif + +/* + * Pte related macros. This is complicated by having to deal with + * the sign extension of the 48th bit. + */ +#define KVADDR(l4, l3, l2, l1) ( \ + ((unsigned long)-1 << 47) | \ + ((unsigned long)(l4) << PML4SHIFT) | \ + ((unsigned long)(l3) << PDPSHIFT) | \ + ((unsigned long)(l2) << PDRSHIFT) | \ + ((unsigned long)(l1) << PAGE_SHIFT)) + +#define UVADDR(l4, l3, l2, l1) ( \ + ((unsigned long)(l4) << PML4SHIFT) | \ + ((unsigned long)(l3) << PDPSHIFT) | \ + ((unsigned long)(l2) << PDRSHIFT) | \ + ((unsigned long)(l1) << PAGE_SHIFT)) + +/* + * Number of kernel PML4 slots. Can be anywhere from 1 to 64 or so, + * but setting it larger than NDMPML4E makes no sense. + * + * Each slot provides .5 TB of kernel virtual space. + */ +#define NKPML4E 4 + +#define NUPML4E (NPML4EPG/2) /* number of userland PML4 pages */ +#define NUPDPE (NUPML4E*NPDPEPG)/* number of userland PDP pages */ +#define NUPDE (NUPDPE*NPDEPG) /* number of userland PD entries */ + +/* + * NDMPML4E is the maximum number of PML4 entries that will be + * used to implement the direct map. It must be a power of two, + * and should generally exceed NKPML4E. The maximum possible + * value is 64; using 128 will make the direct map intrude into + * the recursive page table map. + */ +#define NDMPML4E 8 + +/* + * These values control the layout of virtual memory. The starting address + * of the direct map, which is controlled by DMPML4I, must be a multiple of + * its size. (See the PHYS_TO_DMAP() and DMAP_TO_PHYS() macros.) + * + * Note: KPML4I is the index of the (single) level 4 page that maps + * the KVA that holds KERNBASE, while KPML4BASE is the index of the + * first level 4 page that maps VM_MIN_KERNEL_ADDRESS. If NKPML4E + * is 1, these are the same, otherwise KPML4BASE < KPML4I and extra + * level 4 PDEs are needed to map from VM_MIN_KERNEL_ADDRESS up to + * KERNBASE. + * + * (KPML4I combines with KPDPI to choose where KERNBASE starts. + * Or, in other words, KPML4I provides bits 39..47 of KERNBASE, + * and KPDPI provides bits 30..38.) + */ +#define PML4PML4I (NPML4EPG/2) /* Index of recursive pml4 mapping */ + +#define KPML4BASE (NPML4EPG-NKPML4E) /* KVM at highest addresses */ +#define DMPML4I rounddown(KPML4BASE-NDMPML4E, NDMPML4E) /* Below KVM */ + +#define KPML4I (NPML4EPG-1) +#define KPDPI (NPDPEPG-2) /* kernbase at -2GB */ + +/* Large map: index of the first and max last pml4 entry */ +#define LMSPML4I (PML4PML4I + 1) +#define LMEPML4I (DMPML4I - 1) + +/* + * XXX doesn't really belong here I guess... + */ +#define ISA_HOLE_START 0xa0000 +#define ISA_HOLE_LENGTH (0x100000-ISA_HOLE_START) + +#define PMAP_PCID_NONE 0xffffffff +#define PMAP_PCID_KERN 0 +#define PMAP_PCID_OVERMAX 0x1000 +#define PMAP_PCID_OVERMAX_KERN 0x800 +#define PMAP_PCID_USER_PT 0x800 + +#define PMAP_NO_CR3 (~0UL) + +#ifndef LOCORE + +#include +#include +#include +#include +#include +#include + +#include + +typedef u_int64_t pd_entry_t; +typedef u_int64_t pt_entry_t; +typedef u_int64_t pdp_entry_t; +typedef u_int64_t pml4_entry_t; + +/* + * Address of current address space page table maps and directories. + */ +#ifdef _KERNEL +#define addr_PTmap (KVADDR(PML4PML4I, 0, 0, 0)) +#define addr_PDmap (KVADDR(PML4PML4I, PML4PML4I, 0, 0)) +#define addr_PDPmap (KVADDR(PML4PML4I, PML4PML4I, PML4PML4I, 0)) +#define addr_PML4map (KVADDR(PML4PML4I, PML4PML4I, PML4PML4I, PML4PML4I)) +#define addr_PML4pml4e (addr_PML4map + (PML4PML4I * sizeof(pml4_entry_t))) +#define PTmap ((pt_entry_t *)(addr_PTmap)) +#define PDmap ((pd_entry_t *)(addr_PDmap)) +#define PDPmap ((pd_entry_t *)(addr_PDPmap)) +#define PML4map ((pd_entry_t *)(addr_PML4map)) +#define PML4pml4e ((pd_entry_t *)(addr_PML4pml4e)) + +extern int nkpt; /* Initial number of kernel page tables */ +extern u_int64_t KPDPphys; /* physical address of kernel level 3 */ +extern u_int64_t KPML4phys; /* physical address of kernel level 4 */ + +/* + * virtual address to page table entry and + * to physical address. + * Note: these work recursively, thus vtopte of a pte will give + * the corresponding pde that in turn maps it. + */ +pt_entry_t *vtopte(vm_offset_t); +#define vtophys(va) pmap_kextract(((vm_offset_t) (va))) + +#define pte_load_store(ptep, pte) atomic_swap_long(ptep, pte) +#define pte_load_clear(ptep) atomic_swap_long(ptep, 0) +#define pte_store(ptep, pte) do { \ + *(u_long *)(ptep) = (u_long)(pte); \ +} while (0) +#define pte_clear(ptep) pte_store(ptep, 0) + +#define pde_store(pdep, pde) pte_store(pdep, pde) + +extern pt_entry_t pg_nx; + +#endif /* _KERNEL */ + +/* + * Pmap stuff + */ +struct pv_entry; +struct pv_chunk; + +/* + * Locks + * (p) PV list lock + */ +struct md_page { + TAILQ_HEAD(, pv_entry) pv_list; /* (p) */ + int pv_gen; /* (p) */ + int pat_mode; +}; + +enum pmap_type { + PT_X86, /* regular x86 page tables */ + PT_EPT, /* Intel's nested page tables */ + PT_RVI, /* AMD's nested page tables */ +}; + +struct pmap_pcids { + uint32_t pm_pcid; + uint32_t pm_gen; +}; + +/* + * The kernel virtual address (KVA) of the level 4 page table page is always + * within the direct map (DMAP) region. + */ +struct pmap { + struct mtx pm_mtx; + pml4_entry_t *pm_pml4; /* KVA of level 4 page table */ + pml4_entry_t *pm_pml4u; /* KVA of user l4 page table */ + uint64_t pm_cr3; + uint64_t pm_ucr3; + TAILQ_HEAD(,pv_chunk) pm_pvchunk; /* list of mappings in pmap */ + cpuset_t pm_active; /* active on cpus */ + enum pmap_type pm_type; /* regular or nested tables */ + struct pmap_statistics pm_stats; /* pmap statistics */ + struct vm_radix pm_root; /* spare page table pages */ + long pm_eptgen; /* EPT pmap generation id */ + int pm_flags; + struct pmap_pcids pm_pcids[MAXCPU]; + struct rangeset pm_pkru; +}; + +/* flags */ +#define PMAP_NESTED_IPIMASK 0xff +#define PMAP_PDE_SUPERPAGE (1 << 8) /* supports 2MB superpages */ +#define PMAP_EMULATE_AD_BITS (1 << 9) /* needs A/D bits emulation */ +#define PMAP_SUPPORTS_EXEC_ONLY (1 << 10) /* execute only mappings ok */ + +typedef struct pmap *pmap_t; + +#ifdef _KERNEL +extern struct pmap kernel_pmap_store; +#define kernel_pmap (&kernel_pmap_store) + +#define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) +#define PMAP_LOCK_ASSERT(pmap, type) \ + mtx_assert(&(pmap)->pm_mtx, (type)) +#define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) +#define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ + NULL, MTX_DEF | MTX_DUPOK) +#define PMAP_LOCKED(pmap) mtx_owned(&(pmap)->pm_mtx) +#define PMAP_MTX(pmap) (&(pmap)->pm_mtx) +#define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) +#define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) + +int pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, int flags); +int pmap_emulate_accessed_dirty(pmap_t pmap, vm_offset_t va, int ftype); +#endif + +/* + * For each vm_page_t, there is a list of all currently valid virtual + * mappings of that page. An entry is a pv_entry_t, the list is pv_list. + */ +typedef struct pv_entry { + vm_offset_t pv_va; /* virtual address for mapping */ + TAILQ_ENTRY(pv_entry) pv_next; +} *pv_entry_t; + +/* + * pv_entries are allocated in chunks per-process. This avoids the + * need to track per-pmap assignments. + */ +#define _NPCM 3 +#define _NPCPV 168 +#define PV_CHUNK_HEADER \ + pmap_t pc_pmap; \ + TAILQ_ENTRY(pv_chunk) pc_list; \ + uint64_t pc_map[_NPCM]; /* bitmap; 1 = free */ \ + TAILQ_ENTRY(pv_chunk) pc_lru; + +struct pv_chunk_header { + PV_CHUNK_HEADER +}; + +struct pv_chunk { + PV_CHUNK_HEADER + struct pv_entry pc_pventry[_NPCPV]; +}; + +#ifdef _KERNEL + +extern caddr_t CADDR1; +extern pt_entry_t *CMAP1; +extern vm_paddr_t phys_avail[]; +extern vm_paddr_t dump_avail[]; +extern vm_offset_t virtual_avail; +extern vm_offset_t virtual_end; +extern vm_paddr_t dmaplimit; +extern int pmap_pcid_enabled; +extern int invpcid_works; + +#define pmap_page_get_memattr(m) ((vm_memattr_t)(m)->md.pat_mode) +#define pmap_page_is_write_mapped(m) (((m)->aflags & PGA_WRITEABLE) != 0) +#define pmap_unmapbios(va, sz) pmap_unmapdev((va), (sz)) + +struct thread; + +void pmap_activate_boot(pmap_t pmap); +void pmap_activate_sw(struct thread *); +void pmap_allow_2m_x_ept_recalculate(void); +void pmap_bootstrap(vm_paddr_t *); +int pmap_cache_bits(pmap_t pmap, int mode, boolean_t is_pde); +int pmap_change_attr(vm_offset_t, vm_size_t, int); +int pmap_change_prot(vm_offset_t, vm_size_t, vm_prot_t); +void pmap_demote_DMAP(vm_paddr_t base, vm_size_t len, boolean_t invalidate); +void pmap_flush_cache_range(vm_offset_t, vm_offset_t); +void pmap_flush_cache_phys_range(vm_paddr_t, vm_paddr_t, vm_memattr_t); +void pmap_init_pat(void); +void pmap_kenter(vm_offset_t va, vm_paddr_t pa); +void *pmap_kenter_temporary(vm_paddr_t pa, int i); +vm_paddr_t pmap_kextract(vm_offset_t); +void pmap_kremove(vm_offset_t); +int pmap_large_map(vm_paddr_t, vm_size_t, void **, vm_memattr_t); +void pmap_large_map_wb(void *sva, vm_size_t len); +void pmap_large_unmap(void *sva, vm_size_t len); +void *pmap_mapbios(vm_paddr_t, vm_size_t); +void *pmap_mapdev(vm_paddr_t, vm_size_t); +void *pmap_mapdev_attr(vm_paddr_t, vm_size_t, int); +void *pmap_mapdev_pciecfg(vm_paddr_t pa, vm_size_t size); +bool pmap_not_in_di(void); +boolean_t pmap_page_is_mapped(vm_page_t m); +void pmap_page_set_memattr(vm_page_t m, vm_memattr_t ma); +void pmap_pinit_pml4(vm_page_t); +bool pmap_ps_enabled(pmap_t pmap); +void pmap_unmapdev(vm_offset_t, vm_size_t); +void pmap_invalidate_page(pmap_t, vm_offset_t); +void pmap_invalidate_range(pmap_t, vm_offset_t, vm_offset_t); +void pmap_invalidate_all(pmap_t); +void pmap_invalidate_cache(void); +void pmap_invalidate_cache_pages(vm_page_t *pages, int count); +void pmap_invalidate_cache_range(vm_offset_t sva, vm_offset_t eva); +void pmap_force_invalidate_cache_range(vm_offset_t sva, vm_offset_t eva); +void pmap_get_mapping(pmap_t pmap, vm_offset_t va, uint64_t *ptr, int *num); +boolean_t pmap_map_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); +void pmap_unmap_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); +void pmap_pti_add_kva(vm_offset_t sva, vm_offset_t eva, bool exec); +void pmap_pti_remove_kva(vm_offset_t sva, vm_offset_t eva); +void pmap_pti_pcid_invalidate(uint64_t ucr3, uint64_t kcr3); +void pmap_pti_pcid_invlpg(uint64_t ucr3, uint64_t kcr3, vm_offset_t va); +void pmap_pti_pcid_invlrng(uint64_t ucr3, uint64_t kcr3, vm_offset_t sva, + vm_offset_t eva); +int pmap_pkru_clear(pmap_t pmap, vm_offset_t sva, vm_offset_t eva); +int pmap_pkru_set(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, + u_int keyidx, int flags); +void pmap_thread_init_invl_gen(struct thread *td); +int pmap_vmspace_copy(pmap_t dst_pmap, pmap_t src_pmap); +#endif /* _KERNEL */ + +/* Return various clipped indexes for a given VA */ +static __inline vm_pindex_t +pmap_pte_index(vm_offset_t va) +{ + + return ((va >> PAGE_SHIFT) & ((1ul << NPTEPGSHIFT) - 1)); +} + +static __inline vm_pindex_t +pmap_pde_index(vm_offset_t va) +{ + + return ((va >> PDRSHIFT) & ((1ul << NPDEPGSHIFT) - 1)); +} + +static __inline vm_pindex_t +pmap_pdpe_index(vm_offset_t va) +{ + + return ((va >> PDPSHIFT) & ((1ul << NPDPEPGSHIFT) - 1)); +} + +static __inline vm_pindex_t +pmap_pml4e_index(vm_offset_t va) +{ + + return ((va >> PML4SHIFT) & ((1ul << NPML4EPGSHIFT) - 1)); +} + +#endif /* !LOCORE */ + +#endif /* !_MACHINE_PMAP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pmc_mdep.h b/lib/libc/include/x86_64-freebsd-any/machine/pmc_mdep.h new file mode 100644 index 000000000000..026a9ae2e669 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pmc_mdep.h @@ -0,0 +1,139 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003-2008 Joseph Koshy + * Copyright (c) 2007 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by A. Joseph Koshy under + * sponsorship from the FreeBSD Foundation and Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* Machine dependent interfaces */ + +#ifndef _MACHINE_PMC_MDEP_H +#define _MACHINE_PMC_MDEP_H 1 + +#ifdef _KERNEL +struct pmc_mdep; +#endif + +#include +#include +#include +#include + +/* + * Intel processors implementing V2 and later of the Intel performance + * measurement architecture have PMCs of the following classes: TSC, + * IAF, IAP, UCF and UCP. + */ +#define PMC_MDEP_CLASS_INDEX_TSC 1 +#define PMC_MDEP_CLASS_INDEX_K8 2 +#define PMC_MDEP_CLASS_INDEX_P4 2 +#define PMC_MDEP_CLASS_INDEX_IAP 2 +#define PMC_MDEP_CLASS_INDEX_IAF 3 +#define PMC_MDEP_CLASS_INDEX_UCP 4 +#define PMC_MDEP_CLASS_INDEX_UCF 5 + +/* + * On the amd64 platform we support the following PMCs. + * + * TSC The timestamp counter + * K8 AMD Athlon64 and Opteron PMCs in 64 bit mode. + * PIV Intel P4/HTT and P4/EMT64 + * IAP Intel Core/Core2/Atom CPUs in 64 bits mode. + * IAF Intel fixed-function PMCs in Core2 and later CPUs. + * UCP Intel Uncore programmable PMCs. + * UCF Intel Uncore fixed-function PMCs. + */ + +union pmc_md_op_pmcallocate { + struct pmc_md_amd_op_pmcallocate pm_amd; + struct pmc_md_iap_op_pmcallocate pm_iap; + struct pmc_md_ucf_op_pmcallocate pm_ucf; + struct pmc_md_ucp_op_pmcallocate pm_ucp; + uint64_t __pad[4]; +}; + +/* Logging */ +#define PMCLOG_READADDR PMCLOG_READ64 +#define PMCLOG_EMITADDR PMCLOG_EMIT64 + +#ifdef _KERNEL + +union pmc_md_pmc { + struct pmc_md_amd_pmc pm_amd; + struct pmc_md_iaf_pmc pm_iaf; + struct pmc_md_iap_pmc pm_iap; + struct pmc_md_ucf_pmc pm_ucf; + struct pmc_md_ucp_pmc pm_ucp; +}; + +#define PMC_TRAPFRAME_TO_PC(TF) ((TF)->tf_rip) +#define PMC_TRAPFRAME_TO_FP(TF) ((TF)->tf_rbp) +#define PMC_TRAPFRAME_TO_USER_SP(TF) ((TF)->tf_rsp) +#define PMC_TRAPFRAME_TO_KERNEL_SP(TF) ((TF)->tf_rsp) + +#define PMC_AT_FUNCTION_PROLOGUE_PUSH_BP(I) \ + (((I) & 0xffffffff) == 0xe5894855) /* pushq %rbp; movq %rsp,%rbp */ +#define PMC_AT_FUNCTION_PROLOGUE_MOV_SP_BP(I) \ + (((I) & 0x00ffffff) == 0x00e58948) /* movq %rsp,%rbp */ +#define PMC_AT_FUNCTION_EPILOGUE_RET(I) \ + (((I) & 0xFF) == 0xC3) /* ret */ + +#define PMC_IN_TRAP_HANDLER(PC) \ + ((PC) >= (uintptr_t) start_exceptions && \ + (PC) < (uintptr_t) end_exceptions) + +#define PMC_IN_KERNEL_STACK(S,START,END) \ + ((S) >= (START) && (S) < (END)) +#define PMC_IN_KERNEL(va) INKERNEL(va) + +#define PMC_IN_USERSPACE(va) ((va) <= VM_MAXUSER_ADDRESS) + +/* Build a fake kernel trapframe from current instruction pointer. */ +#define PMC_FAKE_TRAPFRAME(TF) \ + do { \ + (TF)->tf_cs = 0; (TF)->tf_rflags = 0; \ + __asm __volatile("movq %%rbp,%0" : "=r" ((TF)->tf_rbp)); \ + __asm __volatile("movq %%rsp,%0" : "=r" ((TF)->tf_rsp)); \ + __asm __volatile("call 1f \n\t1: pop %0" : "=r"((TF)->tf_rip)); \ + } while (0) + +/* + * Prototypes + */ + +void start_exceptions(void), end_exceptions(void); + +struct pmc_mdep *pmc_amd_initialize(void); +void pmc_amd_finalize(struct pmc_mdep *_md); +struct pmc_mdep *pmc_intel_initialize(void); +void pmc_intel_finalize(struct pmc_mdep *_md); + +#endif /* _KERNEL */ +#endif /* _MACHINE_PMC_MDEP_H */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/ppireg.h b/lib/libc/include/x86_64-freebsd-any/machine/ppireg.h new file mode 100644 index 000000000000..9794504da499 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/ppireg.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 2005 TAKAHASHI Yoshihiro. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_PPIREG_H_ +#define _MACHINE_PPIREG_H_ + +#ifdef _KERNEL + +#define IO_PPI 0x61 /* Programmable Peripheral Interface */ + +/* + * PPI speaker control values + */ + +#define PIT_ENABLETMR2 0x01 /* Enable timer/counter 2 */ +#define PIT_SPKRDATA 0x02 /* Direct to speaker */ + +#define PIT_SPKR (PIT_ENABLETMR2 | PIT_SPKRDATA) + +#define ppi_spkr_on() outb(IO_PPI, inb(IO_PPI) | PIT_SPKR) +#define ppi_spkr_off() outb(IO_PPI, inb(IO_PPI) & ~PIT_SPKR) + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PPIREG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/proc.h b/lib/libc/include/x86_64-freebsd-any/machine/proc.h new file mode 100644 index 000000000000..b95792977707 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/proc.h @@ -0,0 +1,122 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)proc.h 7.1 (Berkeley) 5/15/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_PROC_H_ +#define _MACHINE_PROC_H_ + +#include +#include +#include + +/* + * List of locks + * c - proc lock + * k - only accessed by curthread + * pp - pmap.c:invl_gen_mtx + */ + +struct proc_ldt { + caddr_t ldt_base; + int ldt_refcnt; +}; + +#define PMAP_INVL_GEN_NEXT_INVALID 0x1ULL +struct pmap_invl_gen { + u_long gen; /* (k) */ + union { + LIST_ENTRY(pmap_invl_gen) link; /* (pp) */ + struct { + struct pmap_invl_gen *next; + u_char saved_pri; + }; + }; +} __aligned(16); + +/* + * Machine-dependent part of the proc structure for AMD64. + */ +struct mdthread { + int md_spinlock_count; /* (k) */ + register_t md_saved_flags; /* (k) */ + register_t md_spurflt_addr; /* (k) Spurious page fault address. */ + struct pmap_invl_gen md_invl_gen; + register_t md_efirt_tmp; /* (k) */ + int md_efirt_dis_pf; /* (k) */ + struct pcb md_pcb; + vm_offset_t md_stack_base; +}; + +struct mdproc { + struct proc_ldt *md_ldt; /* (t) per-process ldt */ + struct system_segment_descriptor md_ldt_sd; +}; + +#define P_MD_KPTI 0x00000001 /* Enable KPTI on exec */ + +#define KINFO_PROC_SIZE 1088 +#define KINFO_PROC32_SIZE 768 + +struct syscall_args { + u_int code; + struct sysent *callp; + register_t args[8]; + int narg; +}; + +#ifdef _KERNEL + +/* Get the current kernel thread stack usage. */ +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE; \ + (used) = (char *)td->td_kstack + \ + td->td_kstack_pages * PAGE_SIZE - \ + (char *)&td; \ +} while (0) + +struct proc_ldt *user_ldt_alloc(struct proc *, int); +void user_ldt_free(struct thread *); +struct sysarch_args; +int sysarch_ldt(struct thread *td, struct sysarch_args *uap, int uap_space); +int amd64_set_ldt_data(struct thread *td, int start, int num, + struct user_segment_descriptor *descs); + +extern struct mtx dt_lock; +extern int max_ldt_segment; + +#define NARGREGS 6 + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PROC_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/procctl.h b/lib/libc/include/x86_64-freebsd-any/machine/procctl.h new file mode 100644 index 000000000000..4a6bcc712046 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/procctl.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/profile.h b/lib/libc/include/x86_64-freebsd-any/machine/profile.h new file mode 100644 index 000000000000..2e19918cfb76 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/profile.h @@ -0,0 +1,199 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _MACHINE_PROFILE_H_ +#define _MACHINE_PROFILE_H_ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +#ifdef _KERNEL + +/* + * Config generates something to tell the compiler to align functions on 16 + * byte boundaries. A strict alignment is good for keeping the tables small. + */ +#define FUNCTION_ALIGNMENT 16 + +/* + * The kernel uses assembler stubs instead of unportable inlines. + * This is mainly to save a little time when profiling is not enabled, + * which is the usual case for the kernel. + */ +#define _MCOUNT_DECL void mcount +#define MCOUNT + +#ifdef GUPROF +#define MCOUNT_DECL(s) +#define MCOUNT_ENTER(s) +#define MCOUNT_EXIT(s) +#ifdef __GNUCLIKE_ASM +#define MCOUNT_OVERHEAD(label) \ + __asm __volatile("pushq %0; call __mcount; popq %%rcx" \ + : \ + : "i" (label) \ + : "cx", "r10", "r11", "memory") +#define MEXITCOUNT_OVERHEAD() \ + __asm __volatile("call .mexitcount; 1:" \ + : : \ + : "r10", "r11", "memory") +#define MEXITCOUNT_OVERHEAD_GETLABEL(labelp) \ + __asm __volatile("movq $1b,%0" : "=rm" (labelp)) +#else +#error this file needs to be ported to your compiler +#endif /* !__GNUCLIKE_ASM */ +#else /* !GUPROF */ +#define MCOUNT_DECL(s) register_t s; +#ifdef SMP +extern int mcount_lock; +#define MCOUNT_ENTER(s) { s = intr_disable(); \ + while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1)) \ + /* nothing */ ; } +#define MCOUNT_EXIT(s) { atomic_store_rel_int(&mcount_lock, 0); \ + intr_restore(s); } +#else +#define MCOUNT_ENTER(s) { s = intr_disable(); } +#define MCOUNT_EXIT(s) (intr_restore(s)) +#endif +#endif /* GUPROF */ + +void bintr(void); +void btrap(void); +void eintr(void); +void user(void); + +#define MCOUNT_FROMPC_USER(pc) \ + ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc) + +#define MCOUNT_FROMPC_INTR(pc) \ + ((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \ + ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \ + (uintfptr_t)btrap) : ~0UL) + +#else /* !_KERNEL */ + +#define FUNCTION_ALIGNMENT 4 + +#define _MCOUNT_DECL \ +static void _mcount(uintfptr_t frompc, uintfptr_t selfpc) __used; \ +static void _mcount + +#ifdef __GNUCLIKE_ASM +#define MCOUNT __asm(" \n\ + .text \n\ + .p2align 4,0x90 \n\ + .globl .mcount \n\ + .type .mcount,@function \n\ +.mcount: \n\ + pushq %rdi \n\ + pushq %rsi \n\ + pushq %rdx \n\ + pushq %rcx \n\ + pushq %r8 \n\ + pushq %r9 \n\ + pushq %rax \n\ + movq 8(%rbp),%rdi \n\ + movq 7*8(%rsp),%rsi \n\ + call _mcount \n\ + popq %rax \n\ + popq %r9 \n\ + popq %r8 \n\ + popq %rcx \n\ + popq %rdx \n\ + popq %rsi \n\ + popq %rdi \n\ + ret \n\ + .size .mcount, . - .mcount"); +#if 0 +/* + * We could use this, except it doesn't preserve the registers that were + * being passed with arguments to the function that we were inserted + * into. I've left it here as documentation of what the code above is + * supposed to do. + */ +#define MCOUNT \ +void \ +mcount() \ +{ \ + uintfptr_t selfpc, frompc; \ + /* \ + * Find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * selfpc = pc pushed by call to mcount \ + */ \ + __asm("movq 8(%%rbp),%0" : "=r" (selfpc)); \ + /* \ + * frompc = pc pushed by call to mcount's caller. \ + * The caller's stack frame has already been built, so %rbp is \ + * the caller's frame pointer. The caller's raddr is in the \ + * caller's frame following the caller's caller's frame pointer.\ + */ \ + __asm("movq (%%rbp),%0" : "=r" (frompc)); \ + frompc = ((uintfptr_t *)frompc)[1]; \ + _mcount(frompc, selfpc); \ +} +#endif +#else /* !__GNUCLIKE_ASM */ +#define MCOUNT +#endif /* __GNUCLIKE_ASM */ + +typedef u_long uintfptr_t; + +#endif /* _KERNEL */ + +/* + * An unsigned integral type that can hold non-negative difference between + * function pointers. + */ +typedef u_long fptrdiff_t; + +#ifdef _KERNEL + +void mcount(uintfptr_t frompc, uintfptr_t selfpc); + +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +#ifdef __GNUCLIKE_ASM +void mcount(void) __asm(".mcount"); +#endif +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PROFILE_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/psl.h b/lib/libc/include/x86_64-freebsd-any/machine/psl.h new file mode 100644 index 000000000000..4d945a1ebbaf --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/psl.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/ptrace.h b/lib/libc/include/x86_64-freebsd-any/machine/ptrace.h new file mode 100644 index 000000000000..bf86754d8f45 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/ptrace.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/pvclock.h b/lib/libc/include/x86_64-freebsd-any/machine/pvclock.h new file mode 100644 index 000000000000..f01fac695ae5 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/pvclock.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/reg.h b/lib/libc/include/x86_64-freebsd-any/machine/reg.h new file mode 100644 index 000000000000..f6fb2bc6578f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/reg.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/reloc.h b/lib/libc/include/x86_64-freebsd-any/machine/reloc.h new file mode 100644 index 000000000000..ea5ed128ef86 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/reloc.h @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)reloc.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD$ + */ + +#ifndef _I386_MACHINE_RELOC_H_ +#define _I386_MACHINE_RELOC_H_ + +/* Relocation format. */ +struct relocation_info { + int r_address; /* offset in text or data segment */ + unsigned int r_symbolnum : 24, /* ordinal number of add symbol */ + r_pcrel : 1, /* 1 if value should be pc-relative */ + r_length : 2, /* log base 2 of value's width */ + r_extern : 1, /* 1 if need to add symbol to value */ + r_baserel : 1, /* linkage table relative */ + r_jmptable : 1, /* relocate to jump table */ + r_relative : 1, /* load address relative */ + r_copy : 1; /* run time copy */ +}; + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/machine/resource.h b/lib/libc/include/x86_64-freebsd-any/machine/resource.h new file mode 100644 index 000000000000..dfcc902a7316 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/resource.h @@ -0,0 +1,47 @@ +/* $FreeBSD$ */ +/*- + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE_RESOURCE_H_ +#define _MACHINE_RESOURCE_H_ 1 + +/* + * Definitions of resource types for Intel Architecture machines + * with support for legacy ISA devices and drivers. + */ + +#define SYS_RES_IRQ 1 /* interrupt lines */ +#define SYS_RES_DRQ 2 /* isa dma lines */ +#define SYS_RES_MEMORY 3 /* i/o memory */ +#define SYS_RES_IOPORT 4 /* i/o ports */ +#ifdef NEW_PCIB +#define PCI_RES_BUS 5 /* PCI bus numbers */ +#endif + +#endif /* !_MACHINE_RESOURCE_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/runq.h b/lib/libc/include/x86_64-freebsd-any/machine/runq.h new file mode 100644 index 000000000000..c3e26ff57432 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/runq.h @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2001 Jake Burkholder + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_RUNQ_H_ +#define _MACHINE_RUNQ_H_ + +#define RQB_LEN (1) /* Number of priority status words. */ +#define RQB_L2BPW (6) /* Log2(sizeof(rqb_word_t) * NBBY)). */ +#define RQB_BPW (1<> RQB_L2BPW) + +#define RQB_FFS(word) (bsfq(word)) + +/* + * Type of run queue status word. + */ +typedef u_int64_t rqb_word_t; + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/machine/segments.h b/lib/libc/include/x86_64-freebsd-any/machine/segments.h new file mode 100644 index 000000000000..9bf28863cac8 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/segments.h @@ -0,0 +1,108 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1990 William F. Jolitz + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * AMD64 Segmentation Data Structures and definitions + */ + +#include + +/* + * System segment descriptors (128 bit wide) + */ +struct system_segment_descriptor { + u_int64_t sd_lolimit:16; /* segment extent (lsb) */ + u_int64_t sd_lobase:24; /* segment base address (lsb) */ + u_int64_t sd_type:5; /* segment type */ + u_int64_t sd_dpl:2; /* segment descriptor priority level */ + u_int64_t sd_p:1; /* segment descriptor present */ + u_int64_t sd_hilimit:4; /* segment extent (msb) */ + u_int64_t sd_xx0:3; /* unused */ + u_int64_t sd_gran:1; /* limit granularity (byte/page units)*/ + u_int64_t sd_hibase:40 __packed;/* segment base address (msb) */ + u_int64_t sd_xx1:8; + u_int64_t sd_mbz:5; /* MUST be zero */ + u_int64_t sd_xx2:19; +} __packed; + +/* + * Software definitions are in this convenient format, + * which are translated into inconvenient segment descriptors + * when needed to be used by the 386 hardware + */ + +struct soft_segment_descriptor { + unsigned long ssd_base; /* segment base address */ + unsigned long ssd_limit; /* segment extent */ + unsigned long ssd_type:5; /* segment type */ + unsigned long ssd_dpl:2; /* segment descriptor priority level */ + unsigned long ssd_p:1; /* segment descriptor present */ + unsigned long ssd_long:1; /* long mode (for %cs) */ + unsigned long ssd_def32:1; /* default 32 vs 16 bit size */ + unsigned long ssd_gran:1; /* limit granularity (byte/page units)*/ +} __packed; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + uint64_t rd_limit:16; /* segment extent */ + uint64_t rd_base:64 __packed; /* base address */ +} __packed; + +#ifdef _KERNEL +extern struct user_segment_descriptor gdt[]; +extern struct soft_segment_descriptor gdt_segs[]; +extern struct gate_descriptor *idt; +extern struct region_descriptor r_idt; + +void lgdt(struct region_descriptor *rdp); +void sdtossd(struct user_segment_descriptor *sdp, + struct soft_segment_descriptor *ssdp); +void ssdtosd(struct soft_segment_descriptor *ssdp, + struct user_segment_descriptor *sdp); +void ssdtosyssd(struct soft_segment_descriptor *ssdp, + struct system_segment_descriptor *sdp); +void update_gdt_gsbase(struct thread *td, uint32_t base); +void update_gdt_fsbase(struct thread *td, uint32_t base); +#endif /* _KERNEL */ + +#endif /* !_MACHINE_SEGMENTS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/setjmp.h b/lib/libc/include/x86_64-freebsd-any/machine/setjmp.h new file mode 100644 index 000000000000..c4101a77fd64 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/setjmp.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/sf_buf.h b/lib/libc/include/x86_64-freebsd-any/machine/sf_buf.h new file mode 100644 index 000000000000..216dfe8d411b --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/sf_buf.h @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003, 2005 Alan L. Cox + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_SF_BUF_H_ +#define _MACHINE_SF_BUF_H_ + +/* + * On this machine, the only purpose for which sf_buf is used is to implement + * an opaque pointer required by the machine-independent parts of the kernel. + * That pointer references the vm_page that is "mapped" by the sf_buf. The + * actual mapping is provided by the direct virtual-to-physical mapping. + */ +static inline vm_offset_t +sf_buf_kva(struct sf_buf *sf) +{ + + return (PHYS_TO_DMAP(VM_PAGE_TO_PHYS((vm_page_t)sf))); +} + +static inline vm_page_t +sf_buf_page(struct sf_buf *sf) +{ + + return ((vm_page_t)sf); +} +#endif /* !_MACHINE_SF_BUF_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/sgx.h b/lib/libc/include/x86_64-freebsd-any/machine/sgx.h new file mode 100644 index 000000000000..2fa646ff2ad5 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/sgx.h @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2017 Ruslan Bukin + * All rights reserved. + * + * This software was developed by BAE Systems, the University of Cambridge + * Computer Laboratory, and Memorial University under DARPA/AFRL contract + * FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing + * (TC) research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* User-visible header. */ + +#ifndef _MACHINE_SGX_H_ +#define _MACHINE_SGX_H_ + +#define SGX_MAGIC 0xA4 +#define SGX_IOC_ENCLAVE_CREATE \ + _IOW(SGX_MAGIC, 0x00, struct sgx_enclave_create) +#define SGX_IOC_ENCLAVE_ADD_PAGE \ + _IOW(SGX_MAGIC, 0x01, struct sgx_enclave_add_page) +#define SGX_IOC_ENCLAVE_INIT \ + _IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init) + +struct sgx_enclave_create { + uint64_t src; +} __packed; + +struct sgx_enclave_add_page { + uint64_t addr; + uint64_t src; + uint64_t secinfo; + uint16_t mrmask; +} __packed; + +struct sgx_enclave_init { + uint64_t addr; + uint64_t sigstruct; + uint64_t einittoken; +} __packed; + +#endif /* !_MACHINE_SGX_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/sgxreg.h b/lib/libc/include/x86_64-freebsd-any/machine/sgxreg.h new file mode 100644 index 000000000000..c1c25ceedf26 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/sgxreg.h @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2017 Ruslan Bukin + * All rights reserved. + * + * This software was developed by BAE Systems, the University of Cambridge + * Computer Laboratory, and Memorial University under DARPA/AFRL contract + * FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing + * (TC) research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* Machine-defined variables. */ + +#ifndef _MACHINE_SGXREG_H_ +#define _MACHINE_SGXREG_H_ + +/* Error codes. */ +#define SGX_SUCCESS 0 +#define SGX_INVALID_SIG_STRUCT 1 /* EINIT */ +#define SGX_INVALID_ATTRIBUTE 2 /* EINIT, EGETKEY */ +#define SGX_BLSTATE 3 /* EBLOCK */ +#define SGX_INVALID_MEASUREMENT 4 /* EINIT */ +#define SGX_NOTBLOCKABLE 5 /* EBLOCK */ +#define SGX_PG_INVLD 6 /* EBLOCK */ +#define SGX_LOCKFAIL 7 /* EBLOCK, EMODPR, EMODT */ +#define SGX_INVALID_SIGNATURE 8 /* EINIT */ +#define SGX_MAC_COMPARE_FAIL 9 /* ELDB, ELDU */ +#define SGX_PAGE_NOT_BLOCKED 10 /* EWB */ +#define SGX_NOT_TRACKED 11 /* EWB, EACCEPT */ +#define SGX_VA_SLOT_OCCUPIED 12 /* EWB */ +#define SGX_CHILD_PRESENT 13 /* EWB, EREMOVE */ +#define SGX_ENCLAVE_ACT 14 /* EREMOVE */ +#define SGX_ENTRYEPOCH_LOCKED 15 /* EBLOCK */ +#define SGX_INVALID_EINIT_TOKEN 16 /* EINIT */ +#define SGX_PREV_TRK_INCMPL 17 /* ETRACK */ +#define SGX_PG_IS_SECS 18 /* EBLOCK */ +#define SGX_PAGE_ATTRIBUTES_MISMATCH 19 /* EACCEPT, EACCEPTCOPY */ +#define SGX_PAGE_NOT_MODIFIABLE 20 /* EMODPR, EMODT */ +#define SGX_INVALID_CPUSVN 32 /* EINIT, EGETKEY */ +#define SGX_INVALID_ISVSVN 64 /* EGETKEY */ +#define SGX_UNMASKED_EVENT 128 /* EINIT */ +#define SGX_INVALID_KEYNAME 256 /* EGETKEY */ + +/* + * 2.10 Page Information (PAGEINFO) + * PAGEINFO is an architectural data structure that is used as a parameter + * to the EPC-management instructions. It requires 32-Byte alignment. + */ +struct page_info { + uint64_t linaddr; + uint64_t srcpge; + union { + struct secinfo *secinfo; + uint64_t pcmd; + }; + uint64_t secs; +} __aligned(32); + +/* + * 2.11 Security Information (SECINFO) + * The SECINFO data structure holds meta-data about an enclave page. + */ +struct secinfo { + uint64_t flags; +#define SECINFO_FLAGS_PT_S 8 /* Page type shift */ +#define SECINFO_FLAGS_PT_M (0xff << SECINFO_FLAGS_PT_S) + uint64_t reserved[7]; +} __aligned(64); + +/* + * 2.7.1 ATTRIBUTES + * The ATTRIBUTES data structure is comprised of bit-granular fields that + * are used in the SECS, CPUID enumeration, the REPORT and the KEYREQUEST + * structures. + */ +struct secs_attr { + uint8_t reserved1: 1; + uint8_t debug: 1; + uint8_t mode64bit: 1; + uint8_t reserved2: 1; + uint8_t provisionkey: 1; + uint8_t einittokenkey: 1; + uint8_t reserved3: 2; +#define SECS_ATTR_RSV4_SIZE 7 + uint8_t reserved4[SECS_ATTR_RSV4_SIZE]; + uint64_t xfrm; /* X-Feature Request Mask */ +}; + +/* + * 2.7 SGX Enclave Control Structure (SECS) + * The SECS data structure requires 4K-Bytes alignment. + */ +struct secs { + uint64_t size; + uint64_t base; + uint32_t ssa_frame_size; + uint32_t misc_select; +#define SECS_RSV1_SIZE 24 + uint8_t reserved1[SECS_RSV1_SIZE]; + struct secs_attr attributes; + uint8_t mr_enclave[32]; +#define SECS_RSV2_SIZE 32 + uint8_t reserved2[SECS_RSV2_SIZE]; + uint8_t mr_signer[32]; +#define SECS_RSV3_SIZE 96 + uint8_t reserved3[SECS_RSV3_SIZE]; + uint16_t isv_prod_id; + uint16_t isv_svn; +#define SECS_RSV4_SIZE 3836 + uint8_t reserved4[SECS_RSV4_SIZE]; +}; + +/* + * 2.8 Thread Control Structure (TCS) + * Each executing thread in the enclave is associated with a + * Thread Control Structure. It requires 4K-Bytes alignment. + */ +struct tcs { + uint64_t reserved1; + uint64_t flags; + uint64_t ossa; + uint32_t cssa; + uint32_t nssa; + uint64_t oentry; + uint64_t reserved2; + uint64_t ofsbasgx; + uint64_t ogsbasgx; + uint32_t fslimit; + uint32_t gslimit; + uint64_t reserved3[503]; +}; + +#endif /* !_MACHINE_SGXREG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/sigframe.h b/lib/libc/include/x86_64-freebsd-any/machine/sigframe.h new file mode 100644 index 000000000000..d5cdb56289af --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/sigframe.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/signal.h b/lib/libc/include/x86_64-freebsd-any/machine/signal.h new file mode 100644 index 000000000000..db9fe6ad597e --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/signal.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/smp.h b/lib/libc/include/x86_64-freebsd-any/machine/smp.h new file mode 100644 index 000000000000..2cff69ce680d --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/smp.h @@ -0,0 +1,68 @@ +/*- + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + * + */ + +#ifndef _MACHINE_SMP_H_ +#define _MACHINE_SMP_H_ + +#ifdef _KERNEL + +#ifdef SMP + +#ifndef LOCORE + +#include + +/* global symbols in mpboot.S */ +extern char mptramp_start[]; +extern u_int32_t mptramp_pagetables; + +/* IPI handlers */ +inthand_t + IDTVEC(justreturn), /* interrupt CPU with minimum overhead */ + IDTVEC(justreturn1_pti), + IDTVEC(invltlb_pti), + IDTVEC(invltlb_pcid_pti), + IDTVEC(invltlb_pcid), /* TLB shootdowns - global, pcid */ + IDTVEC(invltlb_invpcid_pti_pti), + IDTVEC(invltlb_invpcid_nopti), + IDTVEC(invlpg_pti), + IDTVEC(invlpg_invpcid_pti), + IDTVEC(invlpg_invpcid), + IDTVEC(invlpg_pcid_pti), + IDTVEC(invlpg_pcid), + IDTVEC(invlrng_pti), + IDTVEC(invlrng_invpcid_pti), + IDTVEC(invlrng_invpcid), + IDTVEC(invlrng_pcid_pti), + IDTVEC(invlrng_pcid), + IDTVEC(invlcache_pti), + IDTVEC(ipi_intr_bitmap_handler_pti), + IDTVEC(ipi_swi_pti), + IDTVEC(cpustop_pti), + IDTVEC(cpususpend_pti), + IDTVEC(rendezvous_pti); + +void invltlb_pcid_handler(void); +void invltlb_invpcid_handler(void); +void invltlb_invpcid_pti_handler(void); +void invlpg_invpcid_handler(void); +void invlpg_pcid_handler(void); +void invlrng_invpcid_handler(void); +void invlrng_pcid_handler(void); +int native_start_all_aps(void); +void mp_bootaddress(vm_paddr_t *, unsigned int *); + +#endif /* !LOCORE */ +#endif /* SMP */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_SMP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/specialreg.h b/lib/libc/include/x86_64-freebsd-any/machine/specialreg.h new file mode 100644 index 000000000000..aace4bfd62e9 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/specialreg.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/stack.h b/lib/libc/include/x86_64-freebsd-any/machine/stack.h new file mode 100644 index 000000000000..091ae33893d4 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/stack.h @@ -0,0 +1,6 @@ +/* + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/stdarg.h b/lib/libc/include/x86_64-freebsd-any/machine/stdarg.h new file mode 100644 index 000000000000..1f80090356a9 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/stdarg.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/sysarch.h b/lib/libc/include/x86_64-freebsd-any/machine/sysarch.h new file mode 100644 index 000000000000..cd380d43b074 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/sysarch.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/timerreg.h b/lib/libc/include/x86_64-freebsd-any/machine/timerreg.h new file mode 100644 index 000000000000..77e6cad5775d --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/timerreg.h @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 2005 TAKAHASHI Yoshihiro. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * The outputs of the three timers are connected as follows: + * + * timer 0 -> irq 0 + * timer 1 -> dma chan 0 (for dram refresh) + * timer 2 -> speaker (via keyboard controller) + * + * Timer 0 is used to call hardclock. + * Timer 2 is used to generate console beeps. + */ + +#ifndef _MACHINE_TIMERREG_H_ +#define _MACHINE_TIMERREG_H_ + +#ifdef _KERNEL + +#include + +#define IO_TIMER1 0x40 /* 8253 Timer #1 */ +#define TIMER_CNTR0 (IO_TIMER1 + TIMER_REG_CNTR0) +#define TIMER_CNTR1 (IO_TIMER1 + TIMER_REG_CNTR1) +#define TIMER_CNTR2 (IO_TIMER1 + TIMER_REG_CNTR2) +#define TIMER_MODE (IO_TIMER1 + TIMER_REG_MODE) + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TIMERREG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/trap.h b/lib/libc/include/x86_64-freebsd-any/machine/trap.h new file mode 100644 index 000000000000..4d950771dcc1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/trap.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/tss.h b/lib/libc/include/x86_64-freebsd-any/machine/tss.h new file mode 100644 index 000000000000..a31763769175 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/tss.h @@ -0,0 +1,72 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)tss.h 5.4 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_TSS_H_ +#define _MACHINE_TSS_H_ 1 + +/* + * amd64 Context Data Type + * + * The alignment is pretty messed up here due to reuse of the original 32 bit + * fields. It might be worth trying to set the tss on a +4 byte offset to + * make the 64 bit fields aligned in practice. + */ +struct amd64tss { + u_int32_t tss_rsvd0; + u_int64_t tss_rsp0 __packed; /* kernel stack pointer ring 0 */ + u_int64_t tss_rsp1 __packed; /* kernel stack pointer ring 1 */ + u_int64_t tss_rsp2 __packed; /* kernel stack pointer ring 2 */ + u_int32_t tss_rsvd1; + u_int32_t tss_rsvd2; + u_int64_t tss_ist1 __packed; /* Interrupt stack table 1 */ + u_int64_t tss_ist2 __packed; /* Interrupt stack table 2 */ + u_int64_t tss_ist3 __packed; /* Interrupt stack table 3 */ + u_int64_t tss_ist4 __packed; /* Interrupt stack table 4 */ + u_int64_t tss_ist5 __packed; /* Interrupt stack table 5 */ + u_int64_t tss_ist6 __packed; /* Interrupt stack table 6 */ + u_int64_t tss_ist7 __packed; /* Interrupt stack table 7 */ + u_int32_t tss_rsvd3; + u_int32_t tss_rsvd4; + u_int16_t tss_rsvd5; + u_int16_t tss_iobase; /* io bitmap offset */ +}; + +#ifdef _KERNEL +extern struct amd64tss common_tss[]; +#endif + +#endif /* _MACHINE_TSS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/ucontext.h b/lib/libc/include/x86_64-freebsd-any/machine/ucontext.h new file mode 100644 index 000000000000..aea80e3845ac --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/ucontext.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vdso.h b/lib/libc/include/x86_64-freebsd-any/machine/vdso.h new file mode 100644 index 000000000000..b81c455a92a5 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vdso.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vm.h b/lib/libc/include/x86_64-freebsd-any/machine/vm.h new file mode 100644 index 000000000000..2e9c30da9936 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vm.h @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 Hudson River Trading LLC + * Written by: John H. Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_VM_H_ +#define _MACHINE_VM_H_ + +#include + +/* Memory attributes. */ +#define VM_MEMATTR_UNCACHEABLE ((vm_memattr_t)PAT_UNCACHEABLE) +#define VM_MEMATTR_WRITE_COMBINING ((vm_memattr_t)PAT_WRITE_COMBINING) +#define VM_MEMATTR_WRITE_THROUGH ((vm_memattr_t)PAT_WRITE_THROUGH) +#define VM_MEMATTR_WRITE_PROTECTED ((vm_memattr_t)PAT_WRITE_PROTECTED) +#define VM_MEMATTR_WRITE_BACK ((vm_memattr_t)PAT_WRITE_BACK) +#define VM_MEMATTR_WEAK_UNCACHEABLE ((vm_memattr_t)PAT_UNCACHED) + +#define VM_MEMATTR_DEFAULT VM_MEMATTR_WRITE_BACK + +#endif /* !_MACHINE_VM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vmm.h b/lib/libc/include/x86_64-freebsd-any/machine/vmm.h new file mode 100644 index 000000000000..08c179075b55 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vmm.h @@ -0,0 +1,708 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _VMM_H_ +#define _VMM_H_ + +#include +#include + +#ifdef _KERNEL +SDT_PROVIDER_DECLARE(vmm); +#endif + +enum vm_suspend_how { + VM_SUSPEND_NONE, + VM_SUSPEND_RESET, + VM_SUSPEND_POWEROFF, + VM_SUSPEND_HALT, + VM_SUSPEND_TRIPLEFAULT, + VM_SUSPEND_LAST +}; + +/* + * Identifiers for architecturally defined registers. + */ +enum vm_reg_name { + VM_REG_GUEST_RAX, + VM_REG_GUEST_RBX, + VM_REG_GUEST_RCX, + VM_REG_GUEST_RDX, + VM_REG_GUEST_RSI, + VM_REG_GUEST_RDI, + VM_REG_GUEST_RBP, + VM_REG_GUEST_R8, + VM_REG_GUEST_R9, + VM_REG_GUEST_R10, + VM_REG_GUEST_R11, + VM_REG_GUEST_R12, + VM_REG_GUEST_R13, + VM_REG_GUEST_R14, + VM_REG_GUEST_R15, + VM_REG_GUEST_CR0, + VM_REG_GUEST_CR3, + VM_REG_GUEST_CR4, + VM_REG_GUEST_DR7, + VM_REG_GUEST_RSP, + VM_REG_GUEST_RIP, + VM_REG_GUEST_RFLAGS, + VM_REG_GUEST_ES, + VM_REG_GUEST_CS, + VM_REG_GUEST_SS, + VM_REG_GUEST_DS, + VM_REG_GUEST_FS, + VM_REG_GUEST_GS, + VM_REG_GUEST_LDTR, + VM_REG_GUEST_TR, + VM_REG_GUEST_IDTR, + VM_REG_GUEST_GDTR, + VM_REG_GUEST_EFER, + VM_REG_GUEST_CR2, + VM_REG_GUEST_PDPTE0, + VM_REG_GUEST_PDPTE1, + VM_REG_GUEST_PDPTE2, + VM_REG_GUEST_PDPTE3, + VM_REG_GUEST_INTR_SHADOW, + VM_REG_GUEST_DR0, + VM_REG_GUEST_DR1, + VM_REG_GUEST_DR2, + VM_REG_GUEST_DR3, + VM_REG_GUEST_DR6, + VM_REG_GUEST_ENTRY_INST_LENGTH, + VM_REG_LAST +}; + +enum x2apic_state { + X2APIC_DISABLED, + X2APIC_ENABLED, + X2APIC_STATE_LAST +}; + +#define VM_INTINFO_VECTOR(info) ((info) & 0xff) +#define VM_INTINFO_DEL_ERRCODE 0x800 +#define VM_INTINFO_RSVD 0x7ffff000 +#define VM_INTINFO_VALID 0x80000000 +#define VM_INTINFO_TYPE 0x700 +#define VM_INTINFO_HWINTR (0 << 8) +#define VM_INTINFO_NMI (2 << 8) +#define VM_INTINFO_HWEXCEPTION (3 << 8) +#define VM_INTINFO_SWINTR (4 << 8) + +#ifdef _KERNEL + +#define VM_MAX_NAMELEN 32 + +struct vm; +struct vm_exception; +struct seg_desc; +struct vm_exit; +struct vm_run; +struct vhpet; +struct vioapic; +struct vlapic; +struct vmspace; +struct vm_object; +struct vm_guest_paging; +struct pmap; + +struct vm_eventinfo { + void *rptr; /* rendezvous cookie */ + int *sptr; /* suspend cookie */ + int *iptr; /* reqidle cookie */ +}; + +typedef int (*vmm_init_func_t)(int ipinum); +typedef int (*vmm_cleanup_func_t)(void); +typedef void (*vmm_resume_func_t)(void); +typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap); +typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip, + struct pmap *pmap, struct vm_eventinfo *info); +typedef void (*vmi_cleanup_func_t)(void *vmi); +typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num, + uint64_t *retval); +typedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num, + uint64_t val); +typedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num, + struct seg_desc *desc); +typedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num, + struct seg_desc *desc); +typedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval); +typedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val); +typedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max); +typedef void (*vmi_vmspace_free)(struct vmspace *vmspace); +typedef struct vlapic * (*vmi_vlapic_init)(void *vmi, int vcpu); +typedef void (*vmi_vlapic_cleanup)(void *vmi, struct vlapic *vlapic); + +struct vmm_ops { + vmm_init_func_t init; /* module wide initialization */ + vmm_cleanup_func_t cleanup; + vmm_resume_func_t resume; + + vmi_init_func_t vminit; /* vm-specific initialization */ + vmi_run_func_t vmrun; + vmi_cleanup_func_t vmcleanup; + vmi_get_register_t vmgetreg; + vmi_set_register_t vmsetreg; + vmi_get_desc_t vmgetdesc; + vmi_set_desc_t vmsetdesc; + vmi_get_cap_t vmgetcap; + vmi_set_cap_t vmsetcap; + vmi_vmspace_alloc vmspace_alloc; + vmi_vmspace_free vmspace_free; + vmi_vlapic_init vlapic_init; + vmi_vlapic_cleanup vlapic_cleanup; +}; + +extern struct vmm_ops vmm_ops_intel; +extern struct vmm_ops vmm_ops_amd; + +int vm_create(const char *name, struct vm **retvm); +void vm_destroy(struct vm *vm); +int vm_reinit(struct vm *vm); +const char *vm_name(struct vm *vm); +uint16_t vm_get_maxcpus(struct vm *vm); +void vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores, + uint16_t *threads, uint16_t *maxcpus); +int vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores, + uint16_t threads, uint16_t maxcpus); + +/* + * APIs that modify the guest memory map require all vcpus to be frozen. + */ +int vm_mmap_memseg(struct vm *vm, vm_paddr_t gpa, int segid, vm_ooffset_t off, + size_t len, int prot, int flags); +int vm_alloc_memseg(struct vm *vm, int ident, size_t len, bool sysmem); +void vm_free_memseg(struct vm *vm, int ident); +int vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa); +int vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len); +int vm_assign_pptdev(struct vm *vm, int bus, int slot, int func); +int vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func); + +/* + * APIs that inspect the guest memory map require only a *single* vcpu to + * be frozen. This acts like a read lock on the guest memory map since any + * modification requires *all* vcpus to be frozen. + */ +int vm_mmap_getnext(struct vm *vm, vm_paddr_t *gpa, int *segid, + vm_ooffset_t *segoff, size_t *len, int *prot, int *flags); +int vm_get_memseg(struct vm *vm, int ident, size_t *len, bool *sysmem, + struct vm_object **objptr); +vm_paddr_t vmm_sysmem_maxaddr(struct vm *vm); +void *vm_gpa_hold(struct vm *, int vcpuid, vm_paddr_t gpa, size_t len, + int prot, void **cookie); +void vm_gpa_release(void *cookie); +bool vm_mem_allocated(struct vm *vm, int vcpuid, vm_paddr_t gpa); + +int vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval); +int vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val); +int vm_get_seg_desc(struct vm *vm, int vcpu, int reg, + struct seg_desc *ret_desc); +int vm_set_seg_desc(struct vm *vm, int vcpu, int reg, + struct seg_desc *desc); +int vm_run(struct vm *vm, struct vm_run *vmrun); +int vm_suspend(struct vm *vm, enum vm_suspend_how how); +int vm_inject_nmi(struct vm *vm, int vcpu); +int vm_nmi_pending(struct vm *vm, int vcpuid); +void vm_nmi_clear(struct vm *vm, int vcpuid); +int vm_inject_extint(struct vm *vm, int vcpu); +int vm_extint_pending(struct vm *vm, int vcpuid); +void vm_extint_clear(struct vm *vm, int vcpuid); +struct vlapic *vm_lapic(struct vm *vm, int cpu); +struct vioapic *vm_ioapic(struct vm *vm); +struct vhpet *vm_hpet(struct vm *vm); +int vm_get_capability(struct vm *vm, int vcpu, int type, int *val); +int vm_set_capability(struct vm *vm, int vcpu, int type, int val); +int vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state); +int vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state); +int vm_apicid2vcpuid(struct vm *vm, int apicid); +int vm_activate_cpu(struct vm *vm, int vcpu); +int vm_suspend_cpu(struct vm *vm, int vcpu); +int vm_resume_cpu(struct vm *vm, int vcpu); +struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid); +void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip); +void vm_exit_debug(struct vm *vm, int vcpuid, uint64_t rip); +void vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip); +void vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip); +void vm_exit_reqidle(struct vm *vm, int vcpuid, uint64_t rip); + +#ifdef _SYS__CPUSET_H_ +/* + * Rendezvous all vcpus specified in 'dest' and execute 'func(arg)'. + * The rendezvous 'func(arg)' is not allowed to do anything that will + * cause the thread to be put to sleep. + * + * If the rendezvous is being initiated from a vcpu context then the + * 'vcpuid' must refer to that vcpu, otherwise it should be set to -1. + * + * The caller cannot hold any locks when initiating the rendezvous. + * + * The implementation of this API may cause vcpus other than those specified + * by 'dest' to be stalled. The caller should not rely on any vcpus making + * forward progress when the rendezvous is in progress. + */ +typedef void (*vm_rendezvous_func_t)(struct vm *vm, int vcpuid, void *arg); +int vm_smp_rendezvous(struct vm *vm, int vcpuid, cpuset_t dest, + vm_rendezvous_func_t func, void *arg); +cpuset_t vm_active_cpus(struct vm *vm); +cpuset_t vm_debug_cpus(struct vm *vm); +cpuset_t vm_suspended_cpus(struct vm *vm); +#endif /* _SYS__CPUSET_H_ */ + +static __inline int +vcpu_rendezvous_pending(struct vm_eventinfo *info) +{ + + return (*((uintptr_t *)(info->rptr)) != 0); +} + +static __inline int +vcpu_suspended(struct vm_eventinfo *info) +{ + + return (*info->sptr); +} + +static __inline int +vcpu_reqidle(struct vm_eventinfo *info) +{ + + return (*info->iptr); +} + +int vcpu_debugged(struct vm *vm, int vcpuid); + +/* + * Return true if device indicated by bus/slot/func is supposed to be a + * pci passthrough device. + * + * Return false otherwise. + */ +bool vmm_is_pptdev(int bus, int slot, int func); + +void *vm_iommu_domain(struct vm *vm); + +enum vcpu_state { + VCPU_IDLE, + VCPU_FROZEN, + VCPU_RUNNING, + VCPU_SLEEPING, +}; + +int vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state, + bool from_idle); +enum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu); + +static int __inline +vcpu_is_running(struct vm *vm, int vcpu, int *hostcpu) +{ + return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING); +} + +#ifdef _SYS_PROC_H_ +static int __inline +vcpu_should_yield(struct vm *vm, int vcpu) +{ + + if (curthread->td_flags & (TDF_ASTPENDING | TDF_NEEDRESCHED)) + return (1); + else if (curthread->td_owepreempt) + return (1); + else + return (0); +} +#endif + +void *vcpu_stats(struct vm *vm, int vcpu); +void vcpu_notify_event(struct vm *vm, int vcpuid, bool lapic_intr); +struct vmspace *vm_get_vmspace(struct vm *vm); +struct vatpic *vm_atpic(struct vm *vm); +struct vatpit *vm_atpit(struct vm *vm); +struct vpmtmr *vm_pmtmr(struct vm *vm); +struct vrtc *vm_rtc(struct vm *vm); + +/* + * Inject exception 'vector' into the guest vcpu. This function returns 0 on + * success and non-zero on failure. + * + * Wrapper functions like 'vm_inject_gp()' should be preferred to calling + * this function directly because they enforce the trap-like or fault-like + * behavior of an exception. + * + * This function should only be called in the context of the thread that is + * executing this vcpu. + */ +int vm_inject_exception(struct vm *vm, int vcpuid, int vector, int err_valid, + uint32_t errcode, int restart_instruction); + +/* + * This function is called after a VM-exit that occurred during exception or + * interrupt delivery through the IDT. The format of 'intinfo' is described + * in Figure 15-1, "EXITINTINFO for All Intercepts", APM, Vol 2. + * + * If a VM-exit handler completes the event delivery successfully then it + * should call vm_exit_intinfo() to extinguish the pending event. For e.g., + * if the task switch emulation is triggered via a task gate then it should + * call this function with 'intinfo=0' to indicate that the external event + * is not pending anymore. + * + * Return value is 0 on success and non-zero on failure. + */ +int vm_exit_intinfo(struct vm *vm, int vcpuid, uint64_t intinfo); + +/* + * This function is called before every VM-entry to retrieve a pending + * event that should be injected into the guest. This function combines + * nested events into a double or triple fault. + * + * Returns 0 if there are no events that need to be injected into the guest + * and non-zero otherwise. + */ +int vm_entry_intinfo(struct vm *vm, int vcpuid, uint64_t *info); + +int vm_get_intinfo(struct vm *vm, int vcpuid, uint64_t *info1, uint64_t *info2); + +enum vm_reg_name vm_segment_name(int seg_encoding); + +struct vm_copyinfo { + uint64_t gpa; + size_t len; + void *hva; + void *cookie; +}; + +/* + * Set up 'copyinfo[]' to copy to/from guest linear address space starting + * at 'gla' and 'len' bytes long. The 'prot' should be set to PROT_READ for + * a copyin or PROT_WRITE for a copyout. + * + * retval is_fault Interpretation + * 0 0 Success + * 0 1 An exception was injected into the guest + * EFAULT N/A Unrecoverable error + * + * The 'copyinfo[]' can be passed to 'vm_copyin()' or 'vm_copyout()' only if + * the return value is 0. The 'copyinfo[]' resources should be freed by calling + * 'vm_copy_teardown()' after the copy is done. + */ +int vm_copy_setup(struct vm *vm, int vcpuid, struct vm_guest_paging *paging, + uint64_t gla, size_t len, int prot, struct vm_copyinfo *copyinfo, + int num_copyinfo, int *is_fault); +void vm_copy_teardown(struct vm *vm, int vcpuid, struct vm_copyinfo *copyinfo, + int num_copyinfo); +void vm_copyin(struct vm *vm, int vcpuid, struct vm_copyinfo *copyinfo, + void *kaddr, size_t len); +void vm_copyout(struct vm *vm, int vcpuid, const void *kaddr, + struct vm_copyinfo *copyinfo, size_t len); + +int vcpu_trace_exceptions(struct vm *vm, int vcpuid); +#endif /* KERNEL */ + +#define VM_MAXCPU 16 /* maximum virtual cpus */ + +/* + * Identifiers for optional vmm capabilities + */ +enum vm_cap_type { + VM_CAP_HALT_EXIT, + VM_CAP_MTRAP_EXIT, + VM_CAP_PAUSE_EXIT, + VM_CAP_UNRESTRICTED_GUEST, + VM_CAP_ENABLE_INVPCID, + VM_CAP_BPT_EXIT, + VM_CAP_MAX +}; + +enum vm_intr_trigger { + EDGE_TRIGGER, + LEVEL_TRIGGER +}; + +/* + * The 'access' field has the format specified in Table 21-2 of the Intel + * Architecture Manual vol 3b. + * + * XXX The contents of the 'access' field are architecturally defined except + * bit 16 - Segment Unusable. + */ +struct seg_desc { + uint64_t base; + uint32_t limit; + uint32_t access; +}; +#define SEG_DESC_TYPE(access) ((access) & 0x001f) +#define SEG_DESC_DPL(access) (((access) >> 5) & 0x3) +#define SEG_DESC_PRESENT(access) (((access) & 0x0080) ? 1 : 0) +#define SEG_DESC_DEF32(access) (((access) & 0x4000) ? 1 : 0) +#define SEG_DESC_GRANULARITY(access) (((access) & 0x8000) ? 1 : 0) +#define SEG_DESC_UNUSABLE(access) (((access) & 0x10000) ? 1 : 0) + +enum vm_cpu_mode { + CPU_MODE_REAL, + CPU_MODE_PROTECTED, + CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */ + CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */ +}; + +enum vm_paging_mode { + PAGING_MODE_FLAT, + PAGING_MODE_32, + PAGING_MODE_PAE, + PAGING_MODE_64, +}; + +struct vm_guest_paging { + uint64_t cr3; + int cpl; + enum vm_cpu_mode cpu_mode; + enum vm_paging_mode paging_mode; +}; + +/* + * The data structures 'vie' and 'vie_op' are meant to be opaque to the + * consumers of instruction decoding. The only reason why their contents + * need to be exposed is because they are part of the 'vm_exit' structure. + */ +struct vie_op { + uint8_t op_byte; /* actual opcode byte */ + uint8_t op_type; /* type of operation (e.g. MOV) */ + uint16_t op_flags; +}; + +#define VIE_INST_SIZE 15 +struct vie { + uint8_t inst[VIE_INST_SIZE]; /* instruction bytes */ + uint8_t num_valid; /* size of the instruction */ + uint8_t num_processed; + + uint8_t addrsize:4, opsize:4; /* address and operand sizes */ + uint8_t rex_w:1, /* REX prefix */ + rex_r:1, + rex_x:1, + rex_b:1, + rex_present:1, + repz_present:1, /* REP/REPE/REPZ prefix */ + repnz_present:1, /* REPNE/REPNZ prefix */ + opsize_override:1, /* Operand size override */ + addrsize_override:1, /* Address size override */ + segment_override:1; /* Segment override */ + + uint8_t mod:2, /* ModRM byte */ + reg:4, + rm:4; + + uint8_t ss:2, /* SIB byte */ + index:4, + base:4; + + uint8_t disp_bytes; + uint8_t imm_bytes; + + uint8_t scale; + int base_register; /* VM_REG_GUEST_xyz */ + int index_register; /* VM_REG_GUEST_xyz */ + int segment_register; /* VM_REG_GUEST_xyz */ + + int64_t displacement; /* optional addr displacement */ + int64_t immediate; /* optional immediate operand */ + + uint8_t decoded; /* set to 1 if successfully decoded */ + + struct vie_op op; /* opcode description */ +}; + +enum vm_exitcode { + VM_EXITCODE_INOUT, + VM_EXITCODE_VMX, + VM_EXITCODE_BOGUS, + VM_EXITCODE_RDMSR, + VM_EXITCODE_WRMSR, + VM_EXITCODE_HLT, + VM_EXITCODE_MTRAP, + VM_EXITCODE_PAUSE, + VM_EXITCODE_PAGING, + VM_EXITCODE_INST_EMUL, + VM_EXITCODE_SPINUP_AP, + VM_EXITCODE_DEPRECATED1, /* used to be SPINDOWN_CPU */ + VM_EXITCODE_RENDEZVOUS, + VM_EXITCODE_IOAPIC_EOI, + VM_EXITCODE_SUSPENDED, + VM_EXITCODE_INOUT_STR, + VM_EXITCODE_TASK_SWITCH, + VM_EXITCODE_MONITOR, + VM_EXITCODE_MWAIT, + VM_EXITCODE_SVM, + VM_EXITCODE_REQIDLE, + VM_EXITCODE_DEBUG, + VM_EXITCODE_VMINSN, + VM_EXITCODE_BPT, + VM_EXITCODE_MAX +}; + +struct vm_inout { + uint16_t bytes:3; /* 1 or 2 or 4 */ + uint16_t in:1; + uint16_t string:1; + uint16_t rep:1; + uint16_t port; + uint32_t eax; /* valid for out */ +}; + +struct vm_inout_str { + struct vm_inout inout; /* must be the first element */ + struct vm_guest_paging paging; + uint64_t rflags; + uint64_t cr0; + uint64_t index; + uint64_t count; /* rep=1 (%rcx), rep=0 (1) */ + int addrsize; + enum vm_reg_name seg_name; + struct seg_desc seg_desc; +}; + +enum task_switch_reason { + TSR_CALL, + TSR_IRET, + TSR_JMP, + TSR_IDT_GATE, /* task gate in IDT */ +}; + +struct vm_task_switch { + uint16_t tsssel; /* new TSS selector */ + int ext; /* task switch due to external event */ + uint32_t errcode; + int errcode_valid; /* push 'errcode' on the new stack */ + enum task_switch_reason reason; + struct vm_guest_paging paging; +}; + +struct vm_exit { + enum vm_exitcode exitcode; + int inst_length; /* 0 means unknown */ + uint64_t rip; + union { + struct vm_inout inout; + struct vm_inout_str inout_str; + struct { + uint64_t gpa; + int fault_type; + } paging; + struct { + uint64_t gpa; + uint64_t gla; + uint64_t cs_base; + int cs_d; /* CS.D */ + struct vm_guest_paging paging; + struct vie vie; + } inst_emul; + /* + * VMX specific payload. Used when there is no "better" + * exitcode to represent the VM-exit. + */ + struct { + int status; /* vmx inst status */ + /* + * 'exit_reason' and 'exit_qualification' are valid + * only if 'status' is zero. + */ + uint32_t exit_reason; + uint64_t exit_qualification; + /* + * 'inst_error' and 'inst_type' are valid + * only if 'status' is non-zero. + */ + int inst_type; + int inst_error; + } vmx; + /* + * SVM specific payload. + */ + struct { + uint64_t exitcode; + uint64_t exitinfo1; + uint64_t exitinfo2; + } svm; + struct { + int inst_length; + } bpt; + struct { + uint32_t code; /* ecx value */ + uint64_t wval; + } msr; + struct { + int vcpu; + uint64_t rip; + } spinup_ap; + struct { + uint64_t rflags; + uint64_t intr_status; + } hlt; + struct { + int vector; + } ioapic_eoi; + struct { + enum vm_suspend_how how; + } suspended; + struct vm_task_switch task_switch; + } u; +}; + +/* APIs to inject faults into the guest */ +void vm_inject_fault(void *vm, int vcpuid, int vector, int errcode_valid, + int errcode); + +static __inline void +vm_inject_ud(void *vm, int vcpuid) +{ + vm_inject_fault(vm, vcpuid, IDT_UD, 0, 0); +} + +static __inline void +vm_inject_gp(void *vm, int vcpuid) +{ + vm_inject_fault(vm, vcpuid, IDT_GP, 1, 0); +} + +static __inline void +vm_inject_ac(void *vm, int vcpuid, int errcode) +{ + vm_inject_fault(vm, vcpuid, IDT_AC, 1, errcode); +} + +static __inline void +vm_inject_ss(void *vm, int vcpuid, int errcode) +{ + vm_inject_fault(vm, vcpuid, IDT_SS, 1, errcode); +} + +void vm_inject_pf(void *vm, int vcpuid, int error_code, uint64_t cr2); + +int vm_restart_instruction(void *vm, int vcpuid); + +#endif /* _VMM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vmm_dev.h b/lib/libc/include/x86_64-freebsd-any/machine/vmm_dev.h new file mode 100644 index 000000000000..d77320dcaef7 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vmm_dev.h @@ -0,0 +1,425 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _VMM_DEV_H_ +#define _VMM_DEV_H_ + +#ifdef _KERNEL +void vmmdev_init(void); +int vmmdev_cleanup(void); +#endif + +struct vm_memmap { + vm_paddr_t gpa; + int segid; /* memory segment */ + vm_ooffset_t segoff; /* offset into memory segment */ + size_t len; /* mmap length */ + int prot; /* RWX */ + int flags; +}; +#define VM_MEMMAP_F_WIRED 0x01 +#define VM_MEMMAP_F_IOMMU 0x02 + +#define VM_MEMSEG_NAME(m) ((m)->name[0] != '\0' ? (m)->name : NULL) +struct vm_memseg { + int segid; + size_t len; + char name[SPECNAMELEN + 1]; +}; + +struct vm_register { + int cpuid; + int regnum; /* enum vm_reg_name */ + uint64_t regval; +}; + +struct vm_seg_desc { /* data or code segment */ + int cpuid; + int regnum; /* enum vm_reg_name */ + struct seg_desc desc; +}; + +struct vm_register_set { + int cpuid; + unsigned int count; + const int *regnums; /* enum vm_reg_name */ + uint64_t *regvals; +}; + +struct vm_run { + int cpuid; + struct vm_exit vm_exit; +}; + +struct vm_exception { + int cpuid; + int vector; + uint32_t error_code; + int error_code_valid; + int restart_instruction; +}; + +struct vm_lapic_msi { + uint64_t msg; + uint64_t addr; +}; + +struct vm_lapic_irq { + int cpuid; + int vector; +}; + +struct vm_ioapic_irq { + int irq; +}; + +struct vm_isa_irq { + int atpic_irq; + int ioapic_irq; +}; + +struct vm_isa_irq_trigger { + int atpic_irq; + enum vm_intr_trigger trigger; +}; + +struct vm_capability { + int cpuid; + enum vm_cap_type captype; + int capval; + int allcpus; +}; + +struct vm_pptdev { + int bus; + int slot; + int func; +}; + +struct vm_pptdev_mmio { + int bus; + int slot; + int func; + vm_paddr_t gpa; + vm_paddr_t hpa; + size_t len; +}; + +struct vm_pptdev_msi { + int vcpu; + int bus; + int slot; + int func; + int numvec; /* 0 means disabled */ + uint64_t msg; + uint64_t addr; +}; + +struct vm_pptdev_msix { + int vcpu; + int bus; + int slot; + int func; + int idx; + uint64_t msg; + uint32_t vector_control; + uint64_t addr; +}; + +struct vm_nmi { + int cpuid; +}; + +#define MAX_VM_STATS 64 +struct vm_stats { + int cpuid; /* in */ + int num_entries; /* out */ + struct timeval tv; + uint64_t statbuf[MAX_VM_STATS]; +}; + +struct vm_stat_desc { + int index; /* in */ + char desc[128]; /* out */ +}; + +struct vm_x2apic { + int cpuid; + enum x2apic_state state; +}; + +struct vm_gpa_pte { + uint64_t gpa; /* in */ + uint64_t pte[4]; /* out */ + int ptenum; +}; + +struct vm_hpet_cap { + uint32_t capabilities; /* lower 32 bits of HPET capabilities */ +}; + +struct vm_suspend { + enum vm_suspend_how how; +}; + +struct vm_gla2gpa { + int vcpuid; /* inputs */ + int prot; /* PROT_READ or PROT_WRITE */ + uint64_t gla; + struct vm_guest_paging paging; + int fault; /* outputs */ + uint64_t gpa; +}; + +struct vm_activate_cpu { + int vcpuid; +}; + +struct vm_cpuset { + int which; + int cpusetsize; + cpuset_t *cpus; +}; +#define VM_ACTIVE_CPUS 0 +#define VM_SUSPENDED_CPUS 1 +#define VM_DEBUG_CPUS 2 + +struct vm_intinfo { + int vcpuid; + uint64_t info1; + uint64_t info2; +}; + +struct vm_rtc_time { + time_t secs; +}; + +struct vm_rtc_data { + int offset; + uint8_t value; +}; + +struct vm_cpu_topology { + uint16_t sockets; + uint16_t cores; + uint16_t threads; + uint16_t maxcpus; +}; + +enum { + /* general routines */ + IOCNUM_ABIVERS = 0, + IOCNUM_RUN = 1, + IOCNUM_SET_CAPABILITY = 2, + IOCNUM_GET_CAPABILITY = 3, + IOCNUM_SUSPEND = 4, + IOCNUM_REINIT = 5, + + /* memory apis */ + IOCNUM_MAP_MEMORY = 10, /* deprecated */ + IOCNUM_GET_MEMORY_SEG = 11, /* deprecated */ + IOCNUM_GET_GPA_PMAP = 12, + IOCNUM_GLA2GPA = 13, + IOCNUM_ALLOC_MEMSEG = 14, + IOCNUM_GET_MEMSEG = 15, + IOCNUM_MMAP_MEMSEG = 16, + IOCNUM_MMAP_GETNEXT = 17, + IOCNUM_GLA2GPA_NOFAULT = 18, + + /* register/state accessors */ + IOCNUM_SET_REGISTER = 20, + IOCNUM_GET_REGISTER = 21, + IOCNUM_SET_SEGMENT_DESCRIPTOR = 22, + IOCNUM_GET_SEGMENT_DESCRIPTOR = 23, + IOCNUM_SET_REGISTER_SET = 24, + IOCNUM_GET_REGISTER_SET = 25, + + /* interrupt injection */ + IOCNUM_GET_INTINFO = 28, + IOCNUM_SET_INTINFO = 29, + IOCNUM_INJECT_EXCEPTION = 30, + IOCNUM_LAPIC_IRQ = 31, + IOCNUM_INJECT_NMI = 32, + IOCNUM_IOAPIC_ASSERT_IRQ = 33, + IOCNUM_IOAPIC_DEASSERT_IRQ = 34, + IOCNUM_IOAPIC_PULSE_IRQ = 35, + IOCNUM_LAPIC_MSI = 36, + IOCNUM_LAPIC_LOCAL_IRQ = 37, + IOCNUM_IOAPIC_PINCOUNT = 38, + IOCNUM_RESTART_INSTRUCTION = 39, + + /* PCI pass-thru */ + IOCNUM_BIND_PPTDEV = 40, + IOCNUM_UNBIND_PPTDEV = 41, + IOCNUM_MAP_PPTDEV_MMIO = 42, + IOCNUM_PPTDEV_MSI = 43, + IOCNUM_PPTDEV_MSIX = 44, + + /* statistics */ + IOCNUM_VM_STATS = 50, + IOCNUM_VM_STAT_DESC = 51, + + /* kernel device state */ + IOCNUM_SET_X2APIC_STATE = 60, + IOCNUM_GET_X2APIC_STATE = 61, + IOCNUM_GET_HPET_CAPABILITIES = 62, + + /* CPU Topology */ + IOCNUM_SET_TOPOLOGY = 63, + IOCNUM_GET_TOPOLOGY = 64, + + /* legacy interrupt injection */ + IOCNUM_ISA_ASSERT_IRQ = 80, + IOCNUM_ISA_DEASSERT_IRQ = 81, + IOCNUM_ISA_PULSE_IRQ = 82, + IOCNUM_ISA_SET_IRQ_TRIGGER = 83, + + /* vm_cpuset */ + IOCNUM_ACTIVATE_CPU = 90, + IOCNUM_GET_CPUSET = 91, + IOCNUM_SUSPEND_CPU = 92, + IOCNUM_RESUME_CPU = 93, + + /* RTC */ + IOCNUM_RTC_READ = 100, + IOCNUM_RTC_WRITE = 101, + IOCNUM_RTC_SETTIME = 102, + IOCNUM_RTC_GETTIME = 103, +}; + +#define VM_RUN \ + _IOWR('v', IOCNUM_RUN, struct vm_run) +#define VM_SUSPEND \ + _IOW('v', IOCNUM_SUSPEND, struct vm_suspend) +#define VM_REINIT \ + _IO('v', IOCNUM_REINIT) +#define VM_ALLOC_MEMSEG \ + _IOW('v', IOCNUM_ALLOC_MEMSEG, struct vm_memseg) +#define VM_GET_MEMSEG \ + _IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg) +#define VM_MMAP_MEMSEG \ + _IOW('v', IOCNUM_MMAP_MEMSEG, struct vm_memmap) +#define VM_MMAP_GETNEXT \ + _IOWR('v', IOCNUM_MMAP_GETNEXT, struct vm_memmap) +#define VM_SET_REGISTER \ + _IOW('v', IOCNUM_SET_REGISTER, struct vm_register) +#define VM_GET_REGISTER \ + _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register) +#define VM_SET_SEGMENT_DESCRIPTOR \ + _IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) +#define VM_GET_SEGMENT_DESCRIPTOR \ + _IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) +#define VM_SET_REGISTER_SET \ + _IOW('v', IOCNUM_SET_REGISTER_SET, struct vm_register_set) +#define VM_GET_REGISTER_SET \ + _IOWR('v', IOCNUM_GET_REGISTER_SET, struct vm_register_set) +#define VM_INJECT_EXCEPTION \ + _IOW('v', IOCNUM_INJECT_EXCEPTION, struct vm_exception) +#define VM_LAPIC_IRQ \ + _IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq) +#define VM_LAPIC_LOCAL_IRQ \ + _IOW('v', IOCNUM_LAPIC_LOCAL_IRQ, struct vm_lapic_irq) +#define VM_LAPIC_MSI \ + _IOW('v', IOCNUM_LAPIC_MSI, struct vm_lapic_msi) +#define VM_IOAPIC_ASSERT_IRQ \ + _IOW('v', IOCNUM_IOAPIC_ASSERT_IRQ, struct vm_ioapic_irq) +#define VM_IOAPIC_DEASSERT_IRQ \ + _IOW('v', IOCNUM_IOAPIC_DEASSERT_IRQ, struct vm_ioapic_irq) +#define VM_IOAPIC_PULSE_IRQ \ + _IOW('v', IOCNUM_IOAPIC_PULSE_IRQ, struct vm_ioapic_irq) +#define VM_IOAPIC_PINCOUNT \ + _IOR('v', IOCNUM_IOAPIC_PINCOUNT, int) +#define VM_ISA_ASSERT_IRQ \ + _IOW('v', IOCNUM_ISA_ASSERT_IRQ, struct vm_isa_irq) +#define VM_ISA_DEASSERT_IRQ \ + _IOW('v', IOCNUM_ISA_DEASSERT_IRQ, struct vm_isa_irq) +#define VM_ISA_PULSE_IRQ \ + _IOW('v', IOCNUM_ISA_PULSE_IRQ, struct vm_isa_irq) +#define VM_ISA_SET_IRQ_TRIGGER \ + _IOW('v', IOCNUM_ISA_SET_IRQ_TRIGGER, struct vm_isa_irq_trigger) +#define VM_SET_CAPABILITY \ + _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability) +#define VM_GET_CAPABILITY \ + _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability) +#define VM_BIND_PPTDEV \ + _IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev) +#define VM_UNBIND_PPTDEV \ + _IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev) +#define VM_MAP_PPTDEV_MMIO \ + _IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio) +#define VM_PPTDEV_MSI \ + _IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi) +#define VM_PPTDEV_MSIX \ + _IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix) +#define VM_INJECT_NMI \ + _IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi) +#define VM_STATS \ + _IOWR('v', IOCNUM_VM_STATS, struct vm_stats) +#define VM_STAT_DESC \ + _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc) +#define VM_SET_X2APIC_STATE \ + _IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic) +#define VM_GET_X2APIC_STATE \ + _IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic) +#define VM_GET_HPET_CAPABILITIES \ + _IOR('v', IOCNUM_GET_HPET_CAPABILITIES, struct vm_hpet_cap) +#define VM_SET_TOPOLOGY \ + _IOW('v', IOCNUM_SET_TOPOLOGY, struct vm_cpu_topology) +#define VM_GET_TOPOLOGY \ + _IOR('v', IOCNUM_GET_TOPOLOGY, struct vm_cpu_topology) +#define VM_GET_GPA_PMAP \ + _IOWR('v', IOCNUM_GET_GPA_PMAP, struct vm_gpa_pte) +#define VM_GLA2GPA \ + _IOWR('v', IOCNUM_GLA2GPA, struct vm_gla2gpa) +#define VM_GLA2GPA_NOFAULT \ + _IOWR('v', IOCNUM_GLA2GPA_NOFAULT, struct vm_gla2gpa) +#define VM_ACTIVATE_CPU \ + _IOW('v', IOCNUM_ACTIVATE_CPU, struct vm_activate_cpu) +#define VM_GET_CPUS \ + _IOW('v', IOCNUM_GET_CPUSET, struct vm_cpuset) +#define VM_SUSPEND_CPU \ + _IOW('v', IOCNUM_SUSPEND_CPU, struct vm_activate_cpu) +#define VM_RESUME_CPU \ + _IOW('v', IOCNUM_RESUME_CPU, struct vm_activate_cpu) +#define VM_SET_INTINFO \ + _IOW('v', IOCNUM_SET_INTINFO, struct vm_intinfo) +#define VM_GET_INTINFO \ + _IOWR('v', IOCNUM_GET_INTINFO, struct vm_intinfo) +#define VM_RTC_WRITE \ + _IOW('v', IOCNUM_RTC_WRITE, struct vm_rtc_data) +#define VM_RTC_READ \ + _IOWR('v', IOCNUM_RTC_READ, struct vm_rtc_data) +#define VM_RTC_SETTIME \ + _IOW('v', IOCNUM_RTC_SETTIME, struct vm_rtc_time) +#define VM_RTC_GETTIME \ + _IOR('v', IOCNUM_RTC_GETTIME, struct vm_rtc_time) +#define VM_RESTART_INSTRUCTION \ + _IOW('v', IOCNUM_RESTART_INSTRUCTION, int) +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vmm_instruction_emul.h b/lib/libc/include/x86_64-freebsd-any/machine/vmm_instruction_emul.h new file mode 100644 index 000000000000..bca2a02e286c --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vmm_instruction_emul.h @@ -0,0 +1,125 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2012 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _VMM_INSTRUCTION_EMUL_H_ +#define _VMM_INSTRUCTION_EMUL_H_ + +#include + +/* + * Callback functions to read and write memory regions. + */ +typedef int (*mem_region_read_t)(void *vm, int cpuid, uint64_t gpa, + uint64_t *rval, int rsize, void *arg); + +typedef int (*mem_region_write_t)(void *vm, int cpuid, uint64_t gpa, + uint64_t wval, int wsize, void *arg); + +/* + * Emulate the decoded 'vie' instruction. + * + * The callbacks 'mrr' and 'mrw' emulate reads and writes to the memory region + * containing 'gpa'. 'mrarg' is an opaque argument that is passed into the + * callback functions. + * + * 'void *vm' should be 'struct vm *' when called from kernel context and + * 'struct vmctx *' when called from user context. + * s + */ +int vmm_emulate_instruction(void *vm, int cpuid, uint64_t gpa, struct vie *vie, + struct vm_guest_paging *paging, mem_region_read_t mrr, + mem_region_write_t mrw, void *mrarg); + +int vie_update_register(void *vm, int vcpuid, enum vm_reg_name reg, + uint64_t val, int size); + +/* + * Returns 1 if an alignment check exception should be injected and 0 otherwise. + */ +int vie_alignment_check(int cpl, int operand_size, uint64_t cr0, + uint64_t rflags, uint64_t gla); + +/* Returns 1 if the 'gla' is not canonical and 0 otherwise. */ +int vie_canonical_check(enum vm_cpu_mode cpu_mode, uint64_t gla); + +uint64_t vie_size2mask(int size); + +int vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum vm_reg_name seg, + struct seg_desc *desc, uint64_t off, int length, int addrsize, int prot, + uint64_t *gla); + +#ifdef _KERNEL +/* + * APIs to fetch and decode the instruction from nested page fault handler. + * + * 'vie' must be initialized before calling 'vmm_fetch_instruction()' + */ +int vmm_fetch_instruction(struct vm *vm, int cpuid, + struct vm_guest_paging *guest_paging, + uint64_t rip, int inst_length, struct vie *vie, + int *is_fault); + +/* + * Translate the guest linear address 'gla' to a guest physical address. + * + * retval is_fault Interpretation + * 0 0 'gpa' contains result of the translation + * 0 1 An exception was injected into the guest + * EFAULT N/A An unrecoverable hypervisor error occurred + */ +int vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging, + uint64_t gla, int prot, uint64_t *gpa, int *is_fault); + +/* + * Like vm_gla2gpa, but no exceptions are injected into the guest and + * PTEs are not changed. + */ +int vm_gla2gpa_nofault(struct vm *vm, int vcpuid, struct vm_guest_paging *paging, + uint64_t gla, int prot, uint64_t *gpa, int *is_fault); + +void vie_init(struct vie *vie, const char *inst_bytes, int inst_length); + +/* + * Decode the instruction fetched into 'vie' so it can be emulated. + * + * 'gla' is the guest linear address provided by the hardware assist + * that caused the nested page table fault. It is used to verify that + * the software instruction decoding is in agreement with the hardware. + * + * Some hardware assists do not provide the 'gla' to the hypervisor. + * To skip the 'gla' verification for this or any other reason pass + * in VIE_INVALID_GLA instead. + */ +#define VIE_INVALID_GLA (1UL << 63) /* a non-canonical address */ +int vmm_decode_instruction(struct vm *vm, int cpuid, uint64_t gla, + enum vm_cpu_mode cpu_mode, int csd, struct vie *vie); +#endif /* _KERNEL */ + +#endif /* _VMM_INSTRUCTION_EMUL_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/vmparam.h b/lib/libc/include/x86_64-freebsd-any/machine/vmparam.h new file mode 100644 index 000000000000..22f75c1bf272 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/vmparam.h @@ -0,0 +1,243 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 1994 John S. Dyson + * All rights reserved. + * Copyright (c) 2003 Peter Wemm + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * $FreeBSD$ + */ + + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ 1 + +/* + * Machine dependent constants for AMD64. + */ + +/* + * Virtual memory related constants, all in bytes + */ +#define MAXTSIZ (32768UL*1024*1024) /* max text size */ +#ifndef DFLDSIZ +#define DFLDSIZ (32768UL*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (32768UL*1024*1024) /* max data size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (8UL*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (512UL*1024*1024) /* max stack size */ +#endif +#ifndef SGROWSIZ +#define SGROWSIZ (128UL*1024) /* amount to grow stack */ +#endif + +/* + * We provide a machine specific single page allocator through the use + * of the direct mapped segment. This uses 2MB pages for reduced + * TLB pressure. + */ +#define UMA_MD_SMALL_ALLOC + +/* + * The physical address space is densely populated. + */ +#define VM_PHYSSEG_DENSE + +/* + * The number of PHYSSEG entries must be one greater than the number + * of phys_avail entries because the phys_avail entry that spans the + * largest physical address that is accessible by ISA DMA is split + * into two PHYSSEG entries. + */ +#define VM_PHYSSEG_MAX 63 + +/* + * Create two free page pools: VM_FREEPOOL_DEFAULT is the default pool + * from which physical pages are allocated and VM_FREEPOOL_DIRECT is + * the pool from which physical pages for page tables and small UMA + * objects are allocated. + */ +#define VM_NFREEPOOL 2 +#define VM_FREEPOOL_DEFAULT 0 +#define VM_FREEPOOL_DIRECT 1 + +/* + * Create up to three free page lists: VM_FREELIST_DMA32 is for physical pages + * that have physical addresses below 4G but are not accessible by ISA DMA, + * and VM_FREELIST_ISADMA is for physical pages that are accessible by ISA + * DMA. + */ +#define VM_NFREELIST 3 +#define VM_FREELIST_DEFAULT 0 +#define VM_FREELIST_DMA32 1 +#define VM_FREELIST_LOWMEM 2 + +#define VM_LOWMEM_BOUNDARY (16 << 20) /* 16MB ISA DMA limit */ + +/* + * Create the DMA32 free list only if the number of physical pages above + * physical address 4G is at least 16M, which amounts to 64GB of physical + * memory. + */ +#define VM_DMA32_NPAGES_THRESHOLD 16777216 + +/* + * An allocation size of 16MB is supported in order to optimize the + * use of the direct map by UMA. Specifically, a cache line contains + * at most 8 PDEs, collectively mapping 16MB of physical memory. By + * reducing the number of distinct 16MB "pages" that are used by UMA, + * the physical memory allocator reduces the likelihood of both 2MB + * page TLB misses and cache misses caused by 2MB page TLB misses. + */ +#define VM_NFREEORDER 13 + +/* + * Enable superpage reservations: 1 level. + */ +#ifndef VM_NRESERVLEVEL +#define VM_NRESERVLEVEL 1 +#endif + +/* + * Level 0 reservations consist of 512 pages. + */ +#ifndef VM_LEVEL_0_ORDER +#define VM_LEVEL_0_ORDER 9 +#endif + +#ifdef SMP +#define PA_LOCK_COUNT 256 +#endif + +/* + * Virtual addresses of things. Derived from the page directory and + * page table indexes from pmap.h for precision. + * + * 0x0000000000000000 - 0x00007fffffffffff user map + * 0x0000800000000000 - 0xffff7fffffffffff does not exist (hole) + * 0xffff800000000000 - 0xffff804020100fff recursive page table (512GB slot) + * 0xffff804020100fff - 0xffff807fffffffff unused + * 0xffff808000000000 - 0xffff847fffffffff large map (can be tuned up) + * 0xffff848000000000 - 0xfffff7ffffffffff unused (large map extends there) + * 0xfffff80000000000 - 0xfffffbffffffffff 4TB direct map + * 0xfffffc0000000000 - 0xfffffdffffffffff unused + * 0xfffffe0000000000 - 0xffffffffffffffff 2TB kernel map + * + * Within the kernel map: + * + * 0xffffffff80000000 KERNBASE + */ + +#define VM_MIN_KERNEL_ADDRESS KVADDR(KPML4BASE, 0, 0, 0) +#define VM_MAX_KERNEL_ADDRESS KVADDR(KPML4BASE + NKPML4E - 1, \ + NPDPEPG-1, NPDEPG-1, NPTEPG-1) + +#define DMAP_MIN_ADDRESS KVADDR(DMPML4I, 0, 0, 0) +#define DMAP_MAX_ADDRESS KVADDR(DMPML4I + NDMPML4E, 0, 0, 0) + +#define LARGEMAP_MIN_ADDRESS KVADDR(LMSPML4I, 0, 0, 0) +#define LARGEMAP_MAX_ADDRESS KVADDR(LMEPML4I + 1, 0, 0, 0) + +#define KERNBASE KVADDR(KPML4I, KPDPI, 0, 0) + +#define UPT_MAX_ADDRESS KVADDR(PML4PML4I, PML4PML4I, PML4PML4I, PML4PML4I) +#define UPT_MIN_ADDRESS KVADDR(PML4PML4I, 0, 0, 0) + +#define VM_MAXUSER_ADDRESS UVADDR(NUPML4E, 0, 0, 0) + +#define SHAREDPAGE (VM_MAXUSER_ADDRESS - PAGE_SIZE) +#define USRSTACK SHAREDPAGE + +#define VM_MAX_ADDRESS UPT_MAX_ADDRESS +#define VM_MIN_ADDRESS (0) + +/* + * XXX Allowing dmaplimit == 0 is a temporary workaround for vt(4) efifb's + * early use of PHYS_TO_DMAP before the mapping is actually setup. This works + * because the result is not actually accessed until later, but the early + * vt fb startup needs to be reworked. + */ +#define PMAP_HAS_DMAP 1 +#define PHYS_TO_DMAP(x) ({ \ + KASSERT(dmaplimit == 0 || (x) < dmaplimit, \ + ("physical address %#jx not covered by the DMAP", \ + (uintmax_t)x)); \ + (x) | DMAP_MIN_ADDRESS; }) + +#define DMAP_TO_PHYS(x) ({ \ + KASSERT((x) < (DMAP_MIN_ADDRESS + dmaplimit) && \ + (x) >= DMAP_MIN_ADDRESS, \ + ("virtual address %#jx not covered by the DMAP", \ + (uintmax_t)x)); \ + (x) & ~DMAP_MIN_ADDRESS; }) + +/* + * How many physical pages per kmem arena virtual page. + */ +#ifndef VM_KMEM_SIZE_SCALE +#define VM_KMEM_SIZE_SCALE (1) +#endif + +/* + * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the + * kernel map. + */ +#ifndef VM_KMEM_SIZE_MAX +#define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \ + VM_MIN_KERNEL_ADDRESS + 1) * 3 / 5) +#endif + +/* initial pagein size of beginning of executable file */ +#ifndef VM_INITIAL_PAGEIN +#define VM_INITIAL_PAGEIN 16 +#endif + +#define ZERO_REGION_SIZE (2 * 1024 * 1024) /* 2MB */ + +/* + * Use a fairly large batch size since we expect amd64 systems to have lots of + * memory. + */ +#define VM_BATCHQUEUE_SIZE 31 + +#endif /* _MACHINE_VMPARAM_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/xen/hypercall.h b/lib/libc/include/x86_64-freebsd-any/machine/xen/hypercall.h new file mode 100644 index 000000000000..e427bbf4d43f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/xen/hypercall.h @@ -0,0 +1,432 @@ +/****************************************************************************** + * hypercall.h + * + * FreeBSD-specific hypervisor handling. + * + * Copyright (c) 2002-2004, K A Fraser + * + * 64-bit updates: + * Benjamin Liu + * Jun Nakajima + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * $FreeBSD$ + */ + +#ifndef __MACHINE_XEN_HYPERCALL_H__ +#define __MACHINE_XEN_HYPERCALL_H__ + +#include + +#ifndef __XEN_HYPERVISOR_H__ +# error "please don't include this file directly" +#endif + +extern char *hypercall_page; + +#define __STR(x) #x +#define STR(x) __STR(x) +#define ENOXENSYS 38 +#define CONFIG_XEN_COMPAT 0x030002 +#define __must_check + +#define HYPERCALL_STR(name) \ + "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" + +#define _hypercall0(type, name) \ +({ \ + type __res; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res) \ + : \ + : "memory" ); \ + __res; \ +}) + +#define _hypercall1(type, name, a1) \ +({ \ + type __res; \ + long __ign1; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1) \ + : "1" ((long)(a1)) \ + : "memory" ); \ + __res; \ +}) + +#define _hypercall2(type, name, a1, a2) \ +({ \ + type __res; \ + long __ign1, __ign2; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)) \ + : "memory" ); \ + __res; \ +}) + +#define _hypercall3(type, name, a1, a2, a3) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ +}) + +#define _hypercall4(type, name, a1, a2, a3, a4) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + register long __arg4 __asm__("r10") = (long)(a4); \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3), "+r" (__arg4) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ +}) + +#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + register long __arg4 __asm__("r10") = (long)(a4); \ + register long __arg5 __asm__("r8") = (long)(a5); \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3), "+r" (__arg4), "+r" (__arg5) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ +}) + +static inline int +privcmd_hypercall(long op, long a1, long a2, long a3, long a4, long a5) +{ + int __res; + long __ign1, __ign2, __ign3; + register long __arg4 __asm__("r10") = (long)(a4); + register long __arg5 __asm__("r8") = (long)(a5); + long __call = (long)&hypercall_page + (op * 32); + + __asm__ volatile ( + "call *%[call]" + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), + "=d" (__ign3), "+r" (__arg4), "+r" (__arg5) + : "1" ((long)(a1)), "2" ((long)(a2)), + "3" ((long)(a3)), [call] "a" (__call) + : "memory" ); + + return (__res); +} + +static inline int __must_check +HYPERVISOR_set_trap_table( + const trap_info_t *table) +{ + return _hypercall1(int, set_trap_table, table); +} + +static inline int __must_check +HYPERVISOR_mmu_update( + mmu_update_t *req, unsigned int count, unsigned int *success_count, + domid_t domid) +{ + return _hypercall4(int, mmu_update, req, count, success_count, domid); +} + +static inline int __must_check +HYPERVISOR_mmuext_op( + struct mmuext_op *op, unsigned int count, unsigned int *success_count, + domid_t domid) +{ + return _hypercall4(int, mmuext_op, op, count, success_count, domid); +} + +static inline int __must_check +HYPERVISOR_set_gdt( + unsigned long *frame_list, unsigned int entries) +{ + return _hypercall2(int, set_gdt, frame_list, entries); +} + +static inline int __must_check +HYPERVISOR_stack_switch( + unsigned long ss, unsigned long esp) +{ + return _hypercall2(int, stack_switch, ss, esp); +} + +static inline int __must_check +HYPERVISOR_set_callbacks( + unsigned long event_address, unsigned long failsafe_address, + unsigned long syscall_address) +{ + return _hypercall3(int, set_callbacks, + event_address, failsafe_address, syscall_address); +} + +static inline int +HYPERVISOR_fpu_taskswitch( + int set) +{ + return _hypercall1(int, fpu_taskswitch, set); +} + +static inline int __must_check +HYPERVISOR_sched_op_compat( + int cmd, unsigned long arg) +{ + return _hypercall2(int, sched_op_compat, cmd, arg); +} + +static inline int __must_check +HYPERVISOR_sched_op( + int cmd, void *arg) +{ + return _hypercall2(int, sched_op, cmd, arg); +} + +static inline long __must_check +HYPERVISOR_set_timer_op( + uint64_t timeout) +{ + return _hypercall1(long, set_timer_op, timeout); +} + +static inline int __must_check +HYPERVISOR_platform_op( + struct xen_platform_op *platform_op) +{ + platform_op->interface_version = XENPF_INTERFACE_VERSION; + return _hypercall1(int, platform_op, platform_op); +} + +static inline int __must_check +HYPERVISOR_set_debugreg( + unsigned int reg, unsigned long value) +{ + return _hypercall2(int, set_debugreg, reg, value); +} + +static inline unsigned long __must_check +HYPERVISOR_get_debugreg( + unsigned int reg) +{ + return _hypercall1(unsigned long, get_debugreg, reg); +} + +static inline int __must_check +HYPERVISOR_update_descriptor( + unsigned long ma, unsigned long word) +{ + return _hypercall2(int, update_descriptor, ma, word); +} + +static inline int __must_check +HYPERVISOR_memory_op( + unsigned int cmd, void *arg) +{ + return _hypercall2(int, memory_op, cmd, arg); +} + +static inline int __must_check +HYPERVISOR_multicall( + multicall_entry_t *call_list, unsigned int nr_calls) +{ + return _hypercall2(int, multicall, call_list, nr_calls); +} + +static inline int __must_check +HYPERVISOR_update_va_mapping( + unsigned long va, uint64_t new_val, unsigned long flags) +{ + return _hypercall3(int, update_va_mapping, va, new_val, flags); +} + +static inline int __must_check +HYPERVISOR_event_channel_op( + int cmd, void *arg) +{ + int rc = _hypercall2(int, event_channel_op, cmd, arg); + +#if CONFIG_XEN_COMPAT <= 0x030002 + if (__predict_false(rc == -ENOXENSYS)) { + struct evtchn_op op; + op.cmd = cmd; + memcpy(&op.u, arg, sizeof(op.u)); + rc = _hypercall1(int, event_channel_op_compat, &op); + memcpy(arg, &op.u, sizeof(op.u)); + } +#endif + + return rc; +} + +static inline int __must_check +HYPERVISOR_xen_version( + int cmd, void *arg) +{ + return _hypercall2(int, xen_version, cmd, arg); +} + +static inline int __must_check +HYPERVISOR_console_io( + int cmd, unsigned int count, const char *str) +{ + return _hypercall3(int, console_io, cmd, count, str); +} + +static inline int __must_check +HYPERVISOR_physdev_op( + int cmd, void *arg) +{ + int rc = _hypercall2(int, physdev_op, cmd, arg); + +#if CONFIG_XEN_COMPAT <= 0x030002 + if (__predict_false(rc == -ENOXENSYS)) { + struct physdev_op op; + op.cmd = cmd; + memcpy(&op.u, arg, sizeof(op.u)); + rc = _hypercall1(int, physdev_op_compat, &op); + memcpy(arg, &op.u, sizeof(op.u)); + } +#endif + + return rc; +} + +static inline int __must_check +HYPERVISOR_grant_table_op( + unsigned int cmd, void *uop, unsigned int count) +{ + return _hypercall3(int, grant_table_op, cmd, uop, count); +} + +static inline int __must_check +HYPERVISOR_update_va_mapping_otherdomain( + unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid) +{ + return _hypercall4(int, update_va_mapping_otherdomain, va, + new_val, flags, domid); +} + +static inline int __must_check +HYPERVISOR_vm_assist( + unsigned int cmd, unsigned int type) +{ + return _hypercall2(int, vm_assist, cmd, type); +} + +static inline int __must_check +HYPERVISOR_vcpu_op( + int cmd, unsigned int vcpuid, void *extra_args) +{ + return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); +} + +static inline int __must_check +HYPERVISOR_set_segment_base( + int reg, unsigned long value) +{ + return _hypercall2(int, set_segment_base, reg, value); +} + +static inline int __must_check +HYPERVISOR_suspend( + unsigned long srec) +{ + struct sched_shutdown sched_shutdown = { + .reason = SHUTDOWN_suspend + }; + + int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown, + &sched_shutdown, srec); + +#if CONFIG_XEN_COMPAT <= 0x030002 + if (rc == -ENOXENSYS) + rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); +#endif + + return rc; +} + +#if CONFIG_XEN_COMPAT <= 0x030002 +static inline int +HYPERVISOR_nmi_op( + unsigned long op, void *arg) +{ + return _hypercall2(int, nmi_op, op, arg); +} +#endif + +#ifndef CONFIG_XEN +static inline unsigned long __must_check +HYPERVISOR_hvm_op( + int op, void *arg) +{ + return _hypercall2(unsigned long, hvm_op, op, arg); +} +#endif + +static inline int __must_check +HYPERVISOR_callback_op( + int cmd, const void *arg) +{ + return _hypercall2(int, callback_op, cmd, arg); +} + +static inline int __must_check +HYPERVISOR_xenoprof_op( + int op, void *arg) +{ + return _hypercall2(int, xenoprof_op, op, arg); +} + +static inline int __must_check +HYPERVISOR_kexec_op( + unsigned long op, void *args) +{ + return _hypercall2(int, kexec_op, op, args); +} + +#undef __must_check + +#endif /* __MACHINE_XEN_HYPERCALL_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/xen/synch_bitops.h b/lib/libc/include/x86_64-freebsd-any/machine/xen/synch_bitops.h new file mode 100644 index 000000000000..746687aa91bd --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/xen/synch_bitops.h @@ -0,0 +1,129 @@ +#ifndef __XEN_SYNCH_BITOPS_H__ +#define __XEN_SYNCH_BITOPS_H__ + +/* + * Copyright 1992, Linus Torvalds. + * Heavily modified to provide guaranteed strong synchronisation + * when communicating with Xen or other guest OSes running on other CPUs. + */ + + +#define ADDR (*(volatile long *) addr) + +static __inline__ void synch_set_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__ ( + "lock btsl %1,%0" + : "=m" (ADDR) : "Ir" (nr) : "memory" ); +} + +static __inline__ void synch_clear_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__ ( + "lock btrl %1,%0" + : "=m" (ADDR) : "Ir" (nr) : "memory" ); +} + +static __inline__ void synch_change_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__ ( + "lock btcl %1,%0" + : "=m" (ADDR) : "Ir" (nr) : "memory" ); +} + +static __inline__ int synch_test_and_set_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "lock btsl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); + return oldbit; +} + +static __inline__ int synch_test_and_clear_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "lock btrl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); + return oldbit; +} + +static __inline__ int synch_test_and_change_bit(int nr, volatile void * addr) +{ + int oldbit; + + __asm__ __volatile__ ( + "lock btcl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); + return oldbit; +} + +struct __synch_xchg_dummy { unsigned long a[100]; }; +#define __synch_xg(x) ((volatile struct __synch_xchg_dummy *)(x)) + +#define synch_cmpxchg(ptr, old, new) \ +((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\ + (unsigned long)(old), \ + (unsigned long)(new), \ + sizeof(*(ptr)))) + +static inline unsigned long __synch_cmpxchg(volatile void *ptr, + unsigned long old, + unsigned long new, int size) +{ + unsigned long prev; + switch (size) { + case 1: + __asm__ __volatile__("lock; cmpxchgb %b1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 2: + __asm__ __volatile__("lock; cmpxchgw %w1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 4: + __asm__ __volatile__("lock; cmpxchgl %k1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 8: + __asm__ __volatile__("lock; cmpxchgq %1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + } + return old; +} + +static __inline__ int synch_const_test_bit(int nr, const volatile void * addr) +{ + return ((1UL << (nr & 31)) & + (((const volatile unsigned int *) addr)[nr >> 5])) != 0; +} + +static __inline__ int synch_var_test_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "btl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit) : "m" (ADDR), "Ir" (nr) ); + return oldbit; +} + +#define synch_test_bit(nr,addr) \ +(__builtin_constant_p(nr) ? \ + synch_const_test_bit((nr),(addr)) : \ + synch_var_test_bit((nr),(addr))) + +#endif /* __XEN_SYNCH_BITOPS_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/machine/xen/xen-os.h b/lib/libc/include/x86_64-freebsd-any/machine/xen/xen-os.h new file mode 100644 index 000000000000..1490e59c2f9d --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/machine/xen/xen-os.h @@ -0,0 +1,6 @@ +/*- + * This file is in the public domain. + */ +/* $FreeBSD$ */ + +#include diff --git a/lib/libc/include/x86_64-freebsd-any/x86/_align.h b/lib/libc/include/x86_64-freebsd-any/x86/_align.h new file mode 100644 index 000000000000..efb8d59bb70f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/_align.h @@ -0,0 +1,54 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2001 David E. O'Brien + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)param.h 5.8 (Berkeley) 6/28/91 + * $FreeBSD$ + */ + +#ifndef _X86_INCLUDE__ALIGN_H_ +#define _X86_INCLUDE__ALIGN_H_ + +/* + * Round p (pointer or byte index) up to a correctly-aligned value + * for all data types (int, long, ...). The result is unsigned int + * and must be cast to any desired pointer type. + */ +#define _ALIGNBYTES (sizeof(__register_t) - 1) +#define _ALIGN(p) (((__uintptr_t)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) + +#endif /* !_X86_INCLUDE__ALIGN_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/_inttypes.h b/lib/libc/include/x86_64-freebsd-any/x86/_inttypes.h new file mode 100644 index 000000000000..043fbdc82689 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/_inttypes.h @@ -0,0 +1,223 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * From: $NetBSD: int_fmtio.h,v 1.2 2001/04/26 16:25:21 kleink Exp $ + * $FreeBSD$ + */ + +#ifndef _MACHINE_INTTYPES_H_ +#define _MACHINE_INTTYPES_H_ + +/* + * Macros for format specifiers. + */ + +#ifdef __LP64__ +#define __PRI64 "l" +#define __PRIptr "l" +#else +#define __PRI64 "ll" +#define __PRIptr +#endif + +/* fprintf(3) macros for signed integers. */ + +#define PRId8 "d" /* int8_t */ +#define PRId16 "d" /* int16_t */ +#define PRId32 "d" /* int32_t */ +#define PRId64 __PRI64"d" /* int64_t */ +#define PRIdLEAST8 "d" /* int_least8_t */ +#define PRIdLEAST16 "d" /* int_least16_t */ +#define PRIdLEAST32 "d" /* int_least32_t */ +#define PRIdLEAST64 __PRI64"d" /* int_least64_t */ +#define PRIdFAST8 "d" /* int_fast8_t */ +#define PRIdFAST16 "d" /* int_fast16_t */ +#define PRIdFAST32 "d" /* int_fast32_t */ +#define PRIdFAST64 __PRI64"d" /* int_fast64_t */ +#define PRIdMAX "jd" /* intmax_t */ +#define PRIdPTR __PRIptr"d" /* intptr_t */ + +#define PRIi8 "i" /* int8_t */ +#define PRIi16 "i" /* int16_t */ +#define PRIi32 "i" /* int32_t */ +#define PRIi64 __PRI64"i" /* int64_t */ +#define PRIiLEAST8 "i" /* int_least8_t */ +#define PRIiLEAST16 "i" /* int_least16_t */ +#define PRIiLEAST32 "i" /* int_least32_t */ +#define PRIiLEAST64 __PRI64"i" /* int_least64_t */ +#define PRIiFAST8 "i" /* int_fast8_t */ +#define PRIiFAST16 "i" /* int_fast16_t */ +#define PRIiFAST32 "i" /* int_fast32_t */ +#define PRIiFAST64 __PRI64"i" /* int_fast64_t */ +#define PRIiMAX "ji" /* intmax_t */ +#define PRIiPTR __PRIptr"i" /* intptr_t */ + +/* fprintf(3) macros for unsigned integers. */ + +#define PRIo8 "o" /* uint8_t */ +#define PRIo16 "o" /* uint16_t */ +#define PRIo32 "o" /* uint32_t */ +#define PRIo64 __PRI64"o" /* uint64_t */ +#define PRIoLEAST8 "o" /* uint_least8_t */ +#define PRIoLEAST16 "o" /* uint_least16_t */ +#define PRIoLEAST32 "o" /* uint_least32_t */ +#define PRIoLEAST64 __PRI64"o" /* uint_least64_t */ +#define PRIoFAST8 "o" /* uint_fast8_t */ +#define PRIoFAST16 "o" /* uint_fast16_t */ +#define PRIoFAST32 "o" /* uint_fast32_t */ +#define PRIoFAST64 __PRI64"o" /* uint_fast64_t */ +#define PRIoMAX "jo" /* uintmax_t */ +#define PRIoPTR __PRIptr"o" /* uintptr_t */ + +#define PRIu8 "u" /* uint8_t */ +#define PRIu16 "u" /* uint16_t */ +#define PRIu32 "u" /* uint32_t */ +#define PRIu64 __PRI64"u" /* uint64_t */ +#define PRIuLEAST8 "u" /* uint_least8_t */ +#define PRIuLEAST16 "u" /* uint_least16_t */ +#define PRIuLEAST32 "u" /* uint_least32_t */ +#define PRIuLEAST64 __PRI64"u" /* uint_least64_t */ +#define PRIuFAST8 "u" /* uint_fast8_t */ +#define PRIuFAST16 "u" /* uint_fast16_t */ +#define PRIuFAST32 "u" /* uint_fast32_t */ +#define PRIuFAST64 __PRI64"u" /* uint_fast64_t */ +#define PRIuMAX "ju" /* uintmax_t */ +#define PRIuPTR __PRIptr"u" /* uintptr_t */ + +#define PRIx8 "x" /* uint8_t */ +#define PRIx16 "x" /* uint16_t */ +#define PRIx32 "x" /* uint32_t */ +#define PRIx64 __PRI64"x" /* uint64_t */ +#define PRIxLEAST8 "x" /* uint_least8_t */ +#define PRIxLEAST16 "x" /* uint_least16_t */ +#define PRIxLEAST32 "x" /* uint_least32_t */ +#define PRIxLEAST64 __PRI64"x" /* uint_least64_t */ +#define PRIxFAST8 "x" /* uint_fast8_t */ +#define PRIxFAST16 "x" /* uint_fast16_t */ +#define PRIxFAST32 "x" /* uint_fast32_t */ +#define PRIxFAST64 __PRI64"x" /* uint_fast64_t */ +#define PRIxMAX "jx" /* uintmax_t */ +#define PRIxPTR __PRIptr"x" /* uintptr_t */ + +#define PRIX8 "X" /* uint8_t */ +#define PRIX16 "X" /* uint16_t */ +#define PRIX32 "X" /* uint32_t */ +#define PRIX64 __PRI64"X" /* uint64_t */ +#define PRIXLEAST8 "X" /* uint_least8_t */ +#define PRIXLEAST16 "X" /* uint_least16_t */ +#define PRIXLEAST32 "X" /* uint_least32_t */ +#define PRIXLEAST64 __PRI64"X" /* uint_least64_t */ +#define PRIXFAST8 "X" /* uint_fast8_t */ +#define PRIXFAST16 "X" /* uint_fast16_t */ +#define PRIXFAST32 "X" /* uint_fast32_t */ +#define PRIXFAST64 __PRI64"X" /* uint_fast64_t */ +#define PRIXMAX "jX" /* uintmax_t */ +#define PRIXPTR __PRIptr"X" /* uintptr_t */ + +/* fscanf(3) macros for signed integers. */ + +#define SCNd8 "hhd" /* int8_t */ +#define SCNd16 "hd" /* int16_t */ +#define SCNd32 "d" /* int32_t */ +#define SCNd64 __PRI64"d" /* int64_t */ +#define SCNdLEAST8 "hhd" /* int_least8_t */ +#define SCNdLEAST16 "hd" /* int_least16_t */ +#define SCNdLEAST32 "d" /* int_least32_t */ +#define SCNdLEAST64 __PRI64"d" /* int_least64_t */ +#define SCNdFAST8 "d" /* int_fast8_t */ +#define SCNdFAST16 "d" /* int_fast16_t */ +#define SCNdFAST32 "d" /* int_fast32_t */ +#define SCNdFAST64 __PRI64"d" /* int_fast64_t */ +#define SCNdMAX "jd" /* intmax_t */ +#define SCNdPTR __PRIptr"d" /* intptr_t */ + +#define SCNi8 "hhi" /* int8_t */ +#define SCNi16 "hi" /* int16_t */ +#define SCNi32 "i" /* int32_t */ +#define SCNi64 __PRI64"i" /* int64_t */ +#define SCNiLEAST8 "hhi" /* int_least8_t */ +#define SCNiLEAST16 "hi" /* int_least16_t */ +#define SCNiLEAST32 "i" /* int_least32_t */ +#define SCNiLEAST64 __PRI64"i" /* int_least64_t */ +#define SCNiFAST8 "i" /* int_fast8_t */ +#define SCNiFAST16 "i" /* int_fast16_t */ +#define SCNiFAST32 "i" /* int_fast32_t */ +#define SCNiFAST64 __PRI64"i" /* int_fast64_t */ +#define SCNiMAX "ji" /* intmax_t */ +#define SCNiPTR __PRIptr"i" /* intptr_t */ + +/* fscanf(3) macros for unsigned integers. */ + +#define SCNo8 "hho" /* uint8_t */ +#define SCNo16 "ho" /* uint16_t */ +#define SCNo32 "o" /* uint32_t */ +#define SCNo64 __PRI64"o" /* uint64_t */ +#define SCNoLEAST8 "hho" /* uint_least8_t */ +#define SCNoLEAST16 "ho" /* uint_least16_t */ +#define SCNoLEAST32 "o" /* uint_least32_t */ +#define SCNoLEAST64 __PRI64"o" /* uint_least64_t */ +#define SCNoFAST8 "o" /* uint_fast8_t */ +#define SCNoFAST16 "o" /* uint_fast16_t */ +#define SCNoFAST32 "o" /* uint_fast32_t */ +#define SCNoFAST64 __PRI64"o" /* uint_fast64_t */ +#define SCNoMAX "jo" /* uintmax_t */ +#define SCNoPTR __PRIptr"o" /* uintptr_t */ + +#define SCNu8 "hhu" /* uint8_t */ +#define SCNu16 "hu" /* uint16_t */ +#define SCNu32 "u" /* uint32_t */ +#define SCNu64 __PRI64"u" /* uint64_t */ +#define SCNuLEAST8 "hhu" /* uint_least8_t */ +#define SCNuLEAST16 "hu" /* uint_least16_t */ +#define SCNuLEAST32 "u" /* uint_least32_t */ +#define SCNuLEAST64 __PRI64"u" /* uint_least64_t */ +#define SCNuFAST8 "u" /* uint_fast8_t */ +#define SCNuFAST16 "u" /* uint_fast16_t */ +#define SCNuFAST32 "u" /* uint_fast32_t */ +#define SCNuFAST64 __PRI64"u" /* uint_fast64_t */ +#define SCNuMAX "ju" /* uintmax_t */ +#define SCNuPTR __PRIptr"u" /* uintptr_t */ + +#define SCNx8 "hhx" /* uint8_t */ +#define SCNx16 "hx" /* uint16_t */ +#define SCNx32 "x" /* uint32_t */ +#define SCNx64 __PRI64"x" /* uint64_t */ +#define SCNxLEAST8 "hhx" /* uint_least8_t */ +#define SCNxLEAST16 "hx" /* uint_least16_t */ +#define SCNxLEAST32 "x" /* uint_least32_t */ +#define SCNxLEAST64 __PRI64"x" /* uint_least64_t */ +#define SCNxFAST8 "x" /* uint_fast8_t */ +#define SCNxFAST16 "x" /* uint_fast16_t */ +#define SCNxFAST32 "x" /* uint_fast32_t */ +#define SCNxFAST64 __PRI64"x" /* uint_fast64_t */ +#define SCNxMAX "jx" /* uintmax_t */ +#define SCNxPTR __PRIptr"x" /* uintptr_t */ + +#endif /* !_MACHINE_INTTYPES_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/_limits.h b/lib/libc/include/x86_64-freebsd-any/x86/_limits.h new file mode 100644 index 000000000000..84efd436a089 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/_limits.h @@ -0,0 +1,103 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + * $FreeBSD$ + */ + +#ifndef _MACHINE__LIMITS_H_ +#define _MACHINE__LIMITS_H_ + +/* + * According to ANSI (section 2.2.4.2), the values below must be usable by + * #if preprocessing directives. Additionally, the expression must have the + * same type as would an expression that is an object of the corresponding + * type converted according to the integral promotions. The subtraction for + * INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an + * unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2). + */ + +#define __CHAR_BIT 8 /* number of bits in a char */ + +#define __SCHAR_MAX 0x7f /* max value for a signed char */ +#define __SCHAR_MIN (-0x7f - 1) /* min value for a signed char */ + +#define __UCHAR_MAX 0xff /* max value for an unsigned char */ + +#define __USHRT_MAX 0xffff /* max value for an unsigned short */ +#define __SHRT_MAX 0x7fff /* max value for a short */ +#define __SHRT_MIN (-0x7fff - 1) /* min value for a short */ + +#define __UINT_MAX 0xffffffff /* max value for an unsigned int */ +#define __INT_MAX 0x7fffffff /* max value for an int */ +#define __INT_MIN (-0x7fffffff - 1) /* min value for an int */ + +#ifdef __LP64__ +#define __ULONG_MAX 0xffffffffffffffff /* max for an unsigned long */ +#define __LONG_MAX 0x7fffffffffffffff /* max for a long */ +#define __LONG_MIN (-0x7fffffffffffffff - 1) /* min for a long */ +#else +#define __ULONG_MAX 0xffffffffUL +#define __LONG_MAX 0x7fffffffL +#define __LONG_MIN (-0x7fffffffL - 1) +#endif + + /* max value for an unsigned long long */ +#define __ULLONG_MAX 0xffffffffffffffffULL +#define __LLONG_MAX 0x7fffffffffffffffLL /* max value for a long long */ +#define __LLONG_MIN (-0x7fffffffffffffffLL - 1) /* min for a long long */ + +#ifdef __LP64__ +#define __SSIZE_MAX __LONG_MAX /* max value for a ssize_t */ +#define __SIZE_T_MAX __ULONG_MAX /* max value for a size_t */ +#define __OFF_MAX __LONG_MAX /* max value for an off_t */ +#define __OFF_MIN __LONG_MIN /* min value for an off_t */ +/* Quads and longs are the same on the amd64. Ensure they stay in sync. */ +#define __UQUAD_MAX __ULONG_MAX /* max value for a uquad_t */ +#define __QUAD_MAX __LONG_MAX /* max value for a quad_t */ +#define __QUAD_MIN __LONG_MIN /* min value for a quad_t */ +#define __LONG_BIT 64 +#else +#define __SSIZE_MAX __INT_MAX +#define __SIZE_T_MAX __UINT_MAX +#define __OFF_MAX __LLONG_MAX +#define __OFF_MIN __LLONG_MIN +#define __UQUAD_MAX __ULLONG_MAX +#define __QUAD_MAX __LLONG_MAX +#define __QUAD_MIN __LLONG_MIN +#define __LONG_BIT 32 +#endif + +#define __WORD_BIT 32 + +/* Minimum signal stack size. */ +#define __MINSIGSTKSZ (512 * 4) + +#endif /* !_MACHINE__LIMITS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/_stdint.h b/lib/libc/include/x86_64-freebsd-any/x86/_stdint.h new file mode 100644 index 000000000000..1607db0de9b6 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/_stdint.h @@ -0,0 +1,193 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2001, 2002 Mike Barcroft + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE__STDINT_H_ +#define _MACHINE__STDINT_H_ + +#include + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) + +#define INT8_C(c) (c) +#define INT16_C(c) (c) +#define INT32_C(c) (c) + +#define UINT8_C(c) (c) +#define UINT16_C(c) (c) +#define UINT32_C(c) (c ## U) + +#ifdef __LP64__ +#define INT64_C(c) (c ## L) +#define UINT64_C(c) (c ## UL) +#else +#define INT64_C(c) (c ## LL) +#define UINT64_C(c) (c ## ULL) +#endif + +#define INTMAX_C(c) INT64_C(c) +#define UINTMAX_C(c) UINT64_C(c) + +#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */ + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) + +/* + * ISO/IEC 9899:1999 + * 7.18.2.1 Limits of exact-width integer types + */ +#define INT8_MIN (-0x7f-1) +#define INT16_MIN (-0x7fff-1) +#define INT32_MIN (-0x7fffffff-1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU + +#ifdef __LP64__ +#define INT64_MIN (-0x7fffffffffffffff-1) +#define INT64_MAX 0x7fffffffffffffff +#define UINT64_MAX 0xffffffffffffffff +#else +#define INT64_MIN (-0x7fffffffffffffffLL-1) +#define INT64_MAX 0x7fffffffffffffffLL +#define UINT64_MAX 0xffffffffffffffffULL +#endif + +/* + * ISO/IEC 9899:1999 + * 7.18.2.2 Limits of minimum-width integer types + */ +/* Minimum values of minimum-width signed integer types. */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +/* Maximum values of minimum-width signed integer types. */ +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +/* Maximum values of minimum-width unsigned integer types. */ +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.2.3 Limits of fastest minimum-width integer types + */ +/* Minimum values of fastest minimum-width signed integer types. */ +#define INT_FAST8_MIN INT32_MIN +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MIN INT64_MIN + +/* Maximum values of fastest minimum-width signed integer types. */ +#define INT_FAST8_MAX INT32_MAX +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MAX INT64_MAX + +/* Maximum values of fastest minimum-width unsigned integer types. */ +#define UINT_FAST8_MAX UINT32_MAX +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.2.4 Limits of integer types capable of holding object pointers + */ +#ifdef __LP64__ +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX +#else +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX +#endif + +/* + * ISO/IEC 9899:1999 + * 7.18.2.5 Limits of greatest-width integer types + */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.3 Limits of other integer types + */ +#ifdef __LP64__ +/* Limits of ptrdiff_t. */ +#define PTRDIFF_MIN INT64_MIN +#define PTRDIFF_MAX INT64_MAX + +/* Limits of sig_atomic_t. */ +#define SIG_ATOMIC_MIN __LONG_MIN +#define SIG_ATOMIC_MAX __LONG_MAX + +/* Limit of size_t. */ +#define SIZE_MAX UINT64_MAX +#else +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX +#define SIZE_MAX UINT32_MAX +#endif + +/* Limits of wint_t. */ +#define WINT_MIN INT32_MIN +#define WINT_MAX INT32_MAX + +#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */ + +#endif /* !_MACHINE__STDINT_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/_types.h b/lib/libc/include/x86_64-freebsd-any/x86/_types.h new file mode 100644 index 000000000000..2c7301dd857f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/_types.h @@ -0,0 +1,150 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 2002 Mike Barcroft + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * From: @(#)ansi.h 8.2 (Berkeley) 1/4/94 + * From: @(#)types.h 8.3 (Berkeley) 1/5/94 + * $FreeBSD$ + */ + +#ifndef _MACHINE__TYPES_H_ +#define _MACHINE__TYPES_H_ + +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + +#include + +#define __NO_STRICT_ALIGNMENT + +/* + * Basic types upon which most other types are built. + */ +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef short __int16_t; +typedef unsigned short __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; +#ifdef __LP64__ +typedef long __int64_t; +typedef unsigned long __uint64_t; +#else +__extension__ +typedef long long __int64_t; +__extension__ +typedef unsigned long long __uint64_t; +#endif + +/* + * Standard type definitions. + */ +#ifdef __LP64__ +typedef __int32_t __clock_t; /* clock()... */ +typedef __int64_t __critical_t; +#ifndef _STANDALONE +typedef double __double_t; +typedef float __float_t; +#endif +typedef __int64_t __intfptr_t; +typedef __int64_t __intptr_t; +#else +typedef unsigned long __clock_t; +typedef __int32_t __critical_t; +#ifndef _STANDALONE +typedef long double __double_t; +typedef long double __float_t; +#endif +typedef __int32_t __intfptr_t; +typedef __int32_t __intptr_t; +#endif +typedef __int64_t __intmax_t; +typedef __int32_t __int_fast8_t; +typedef __int32_t __int_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __int64_t __int_fast64_t; +typedef __int8_t __int_least8_t; +typedef __int16_t __int_least16_t; +typedef __int32_t __int_least32_t; +typedef __int64_t __int_least64_t; +#ifdef __LP64__ +typedef __int64_t __ptrdiff_t; /* ptr1 - ptr2 */ +typedef __int64_t __register_t; +typedef __int64_t __segsz_t; /* segment size (in pages) */ +typedef __uint64_t __size_t; /* sizeof() */ +typedef __int64_t __ssize_t; /* byte count or error */ +typedef __int64_t __time_t; /* time()... */ +typedef __uint64_t __uintfptr_t; +typedef __uint64_t __uintptr_t; +#else +typedef __int32_t __ptrdiff_t; +typedef __int32_t __register_t; +typedef __int32_t __segsz_t; +typedef __uint32_t __size_t; +typedef __int32_t __ssize_t; +typedef __int32_t __time_t; +typedef __uint32_t __uintfptr_t; +typedef __uint32_t __uintptr_t; +#endif +typedef __uint64_t __uintmax_t; +typedef __uint32_t __uint_fast8_t; +typedef __uint32_t __uint_fast16_t; +typedef __uint32_t __uint_fast32_t; +typedef __uint64_t __uint_fast64_t; +typedef __uint8_t __uint_least8_t; +typedef __uint16_t __uint_least16_t; +typedef __uint32_t __uint_least32_t; +typedef __uint64_t __uint_least64_t; +#ifdef __LP64__ +typedef __uint64_t __u_register_t; +typedef __uint64_t __vm_offset_t; +typedef __uint64_t __vm_paddr_t; +typedef __uint64_t __vm_size_t; +#else +typedef __uint32_t __u_register_t; +typedef __uint32_t __vm_offset_t; +#ifdef PAE +typedef __uint64_t __vm_paddr_t; +#else +typedef __uint32_t __vm_paddr_t; +#endif +typedef __uint32_t __vm_size_t; +#endif +typedef int ___wchar_t; + +#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */ +#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */ + +#endif /* !_MACHINE__TYPES_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/acpica_machdep.h b/lib/libc/include/x86_64-freebsd-any/x86/acpica_machdep.h new file mode 100644 index 000000000000..05e8711c16fa --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/acpica_machdep.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2002 Mitsuru IWASAKI + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/****************************************************************************** + * + * Name: acpica_machdep.h - arch-specific defines, etc. + * $Revision$ + * + *****************************************************************************/ + +#ifndef __ACPICA_MACHDEP_H__ +#define __ACPICA_MACHDEP_H__ + +#ifdef _KERNEL +/* + * Calling conventions: + * + * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads) + * ACPI_EXTERNAL_XFACE - External ACPI interfaces + * ACPI_INTERNAL_XFACE - Internal ACPI interfaces + * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces + */ +#define ACPI_SYSTEM_XFACE +#define ACPI_EXTERNAL_XFACE +#define ACPI_INTERNAL_XFACE +#define ACPI_INTERNAL_VAR_XFACE + +/* Asm macros */ + +#define ACPI_ASM_MACROS +#define BREAKPOINT3 +#define ACPI_DISABLE_IRQS() disable_intr() +#define ACPI_ENABLE_IRQS() enable_intr() + +#define ACPI_FLUSH_CPU_CACHE() wbinvd() + +/* Section 5.2.10.1: global lock acquire/release functions */ +int acpi_acquire_global_lock(volatile uint32_t *); +int acpi_release_global_lock(volatile uint32_t *); +#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) do { \ + (Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock)); \ +} while (0) +#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) do { \ + (Acq) = acpi_release_global_lock(&((GLptr)->GlobalLock)); \ +} while (0) + +enum intr_trigger; +enum intr_polarity; + +void acpi_SetDefaultIntrModel(int model); +void acpi_cpu_c1(void); +void acpi_cpu_idle_mwait(uint32_t mwait_hint); +void *acpi_map_table(vm_paddr_t pa, const char *sig); +void acpi_unmap_table(void *table); +vm_paddr_t acpi_find_table(const char *sig); +void madt_parse_interrupt_values(void *entry, + enum intr_trigger *trig, enum intr_polarity *pol); + +extern int madt_found_sci_override; +extern int (*apei_nmi)(void); + +#endif /* _KERNEL */ + +#endif /* __ACPICA_MACHDEP_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/apicreg.h b/lib/libc/include/x86_64-freebsd-any/x86/apicreg.h new file mode 100644 index 000000000000..d0173e2ecaf8 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/apicreg.h @@ -0,0 +1,550 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996, by Peter Wemm and Steve Passe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_APICREG_H_ +#define _X86_APICREG_H_ + +/* + * Local && I/O APIC definitions. + */ + +/* + * Pentium P54C+ Built-in APIC + * (Advanced programmable Interrupt Controller) + * + * Base Address of Built-in APIC in memory location + * is 0xfee00000. + * + * Map of APIC Registers: + * + * Offset (hex) Description Read/Write state + * 000 Reserved + * 010 Reserved + * 020 ID Local APIC ID R/W + * 030 VER Local APIC Version R + * 040 Reserved + * 050 Reserved + * 060 Reserved + * 070 Reserved + * 080 Task Priority Register R/W + * 090 Arbitration Priority Register R + * 0A0 Processor Priority Register R + * 0B0 EOI Register W + * 0C0 RRR Remote read R + * 0D0 Logical Destination R/W + * 0E0 Destination Format Register 0..27 R; 28..31 R/W + * 0F0 SVR Spurious Interrupt Vector Reg. 0..3 R; 4..9 R/W + * 100 ISR 000-031 R + * 110 ISR 032-063 R + * 120 ISR 064-095 R + * 130 ISR 095-128 R + * 140 ISR 128-159 R + * 150 ISR 160-191 R + * 160 ISR 192-223 R + * 170 ISR 224-255 R + * 180 TMR 000-031 R + * 190 TMR 032-063 R + * 1A0 TMR 064-095 R + * 1B0 TMR 095-128 R + * 1C0 TMR 128-159 R + * 1D0 TMR 160-191 R + * 1E0 TMR 192-223 R + * 1F0 TMR 224-255 R + * 200 IRR 000-031 R + * 210 IRR 032-063 R + * 220 IRR 064-095 R + * 230 IRR 095-128 R + * 240 IRR 128-159 R + * 250 IRR 160-191 R + * 260 IRR 192-223 R + * 270 IRR 224-255 R + * 280 Error Status Register R + * 290 Reserved + * 2A0 Reserved + * 2B0 Reserved + * 2C0 Reserved + * 2D0 Reserved + * 2E0 Reserved + * 2F0 Local Vector Table (CMCI) R/W + * 300 ICR_LOW Interrupt Command Reg. (0-31) R/W + * 310 ICR_HI Interrupt Command Reg. (32-63) R/W + * 320 Local Vector Table (Timer) R/W + * 330 Local Vector Table (Thermal) R/W (PIV+) + * 340 Local Vector Table (Performance) R/W (P6+) + * 350 LVT1 Local Vector Table (LINT0) R/W + * 360 LVT2 Local Vector Table (LINT1) R/W + * 370 LVT3 Local Vector Table (ERROR) R/W + * 380 Initial Count Reg. for Timer R/W + * 390 Current Count of Timer R + * 3A0 Reserved + * 3B0 Reserved + * 3C0 Reserved + * 3D0 Reserved + * 3E0 Timer Divide Configuration Reg. R/W + * 3F0 Reserved + */ + + +/****************************************************************************** + * global defines, etc. + */ + + +/****************************************************************************** + * LOCAL APIC structure + */ + +#ifndef LOCORE +#include + +#define PAD3 int : 32; int : 32; int : 32 +#define PAD4 int : 32; int : 32; int : 32; int : 32 + +struct LAPIC { + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t id; PAD3; + u_int32_t version; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t tpr; PAD3; + u_int32_t apr; PAD3; + u_int32_t ppr; PAD3; + u_int32_t eoi; PAD3; + /* reserved */ PAD4; + u_int32_t ldr; PAD3; + u_int32_t dfr; PAD3; + u_int32_t svr; PAD3; + u_int32_t isr0; PAD3; + u_int32_t isr1; PAD3; + u_int32_t isr2; PAD3; + u_int32_t isr3; PAD3; + u_int32_t isr4; PAD3; + u_int32_t isr5; PAD3; + u_int32_t isr6; PAD3; + u_int32_t isr7; PAD3; + u_int32_t tmr0; PAD3; + u_int32_t tmr1; PAD3; + u_int32_t tmr2; PAD3; + u_int32_t tmr3; PAD3; + u_int32_t tmr4; PAD3; + u_int32_t tmr5; PAD3; + u_int32_t tmr6; PAD3; + u_int32_t tmr7; PAD3; + u_int32_t irr0; PAD3; + u_int32_t irr1; PAD3; + u_int32_t irr2; PAD3; + u_int32_t irr3; PAD3; + u_int32_t irr4; PAD3; + u_int32_t irr5; PAD3; + u_int32_t irr6; PAD3; + u_int32_t irr7; PAD3; + u_int32_t esr; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t lvt_cmci; PAD3; + u_int32_t icr_lo; PAD3; + u_int32_t icr_hi; PAD3; + u_int32_t lvt_timer; PAD3; + u_int32_t lvt_thermal; PAD3; + u_int32_t lvt_pcint; PAD3; + u_int32_t lvt_lint0; PAD3; + u_int32_t lvt_lint1; PAD3; + u_int32_t lvt_error; PAD3; + u_int32_t icr_timer; PAD3; + u_int32_t ccr_timer; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t dcr_timer; PAD3; + /* reserved */ PAD4; +}; + +typedef struct LAPIC lapic_t; + +enum LAPIC_REGISTERS { + LAPIC_ID = 0x2, + LAPIC_VERSION = 0x3, + LAPIC_TPR = 0x8, + LAPIC_APR = 0x9, + LAPIC_PPR = 0xa, + LAPIC_EOI = 0xb, + LAPIC_LDR = 0xd, + LAPIC_DFR = 0xe, /* Not in x2APIC */ + LAPIC_SVR = 0xf, + LAPIC_ISR0 = 0x10, + LAPIC_ISR1 = 0x11, + LAPIC_ISR2 = 0x12, + LAPIC_ISR3 = 0x13, + LAPIC_ISR4 = 0x14, + LAPIC_ISR5 = 0x15, + LAPIC_ISR6 = 0x16, + LAPIC_ISR7 = 0x17, + LAPIC_TMR0 = 0x18, + LAPIC_TMR1 = 0x19, + LAPIC_TMR2 = 0x1a, + LAPIC_TMR3 = 0x1b, + LAPIC_TMR4 = 0x1c, + LAPIC_TMR5 = 0x1d, + LAPIC_TMR6 = 0x1e, + LAPIC_TMR7 = 0x1f, + LAPIC_IRR0 = 0x20, + LAPIC_IRR1 = 0x21, + LAPIC_IRR2 = 0x22, + LAPIC_IRR3 = 0x23, + LAPIC_IRR4 = 0x24, + LAPIC_IRR5 = 0x25, + LAPIC_IRR6 = 0x26, + LAPIC_IRR7 = 0x27, + LAPIC_ESR = 0x28, + LAPIC_LVT_CMCI = 0x2f, + LAPIC_ICR_LO = 0x30, + LAPIC_ICR_HI = 0x31, /* Not in x2APIC */ + LAPIC_LVT_TIMER = 0x32, + LAPIC_LVT_THERMAL = 0x33, + LAPIC_LVT_PCINT = 0x34, + LAPIC_LVT_LINT0 = 0x35, + LAPIC_LVT_LINT1 = 0x36, + LAPIC_LVT_ERROR = 0x37, + LAPIC_ICR_TIMER = 0x38, + LAPIC_CCR_TIMER = 0x39, + LAPIC_DCR_TIMER = 0x3e, + LAPIC_SELF_IPI = 0x3f, /* Only in x2APIC */ + LAPIC_EXT_FEATURES = 0x40, /* AMD */ + LAPIC_EXT_CTRL = 0x41, /* AMD */ + LAPIC_EXT_SEOI = 0x42, /* AMD */ + LAPIC_EXT_IER0 = 0x48, /* AMD */ + LAPIC_EXT_IER1 = 0x49, /* AMD */ + LAPIC_EXT_IER2 = 0x4a, /* AMD */ + LAPIC_EXT_IER3 = 0x4b, /* AMD */ + LAPIC_EXT_IER4 = 0x4c, /* AMD */ + LAPIC_EXT_IER5 = 0x4d, /* AMD */ + LAPIC_EXT_IER6 = 0x4e, /* AMD */ + LAPIC_EXT_IER7 = 0x4f, /* AMD */ + LAPIC_EXT_LVT0 = 0x50, /* AMD */ + LAPIC_EXT_LVT1 = 0x51, /* AMD */ + LAPIC_EXT_LVT2 = 0x52, /* AMD */ + LAPIC_EXT_LVT3 = 0x53, /* AMD */ +}; + +#define LAPIC_MEM_MUL 0x10 + +/* + * Although some registers are available on AMD processors only, + * it's not a big waste to reserve them on all platforms. + * However, we need to watch out for this space being assigned for + * non-APIC purposes in the future processor models. + */ +#define LAPIC_MEM_REGION ((LAPIC_EXT_LVT3 + 1) * LAPIC_MEM_MUL) + +/****************************************************************************** + * I/O APIC structure + */ + +struct IOAPIC { + u_int32_t ioregsel; PAD3; + u_int32_t iowin; PAD3; +}; + +typedef struct IOAPIC ioapic_t; + +#undef PAD4 +#undef PAD3 + +#endif /* !LOCORE */ + + +/****************************************************************************** + * various code 'logical' values + */ + +/****************************************************************************** + * LOCAL APIC defines + */ + +/* default physical locations of LOCAL (CPU) APICs */ +#define DEFAULT_APIC_BASE 0xfee00000 + +/* constants relating to APIC ID registers */ +#define APIC_ID_MASK 0xff000000 +#define APIC_ID_SHIFT 24 +#define APIC_ID_CLUSTER 0xf0 +#define APIC_ID_CLUSTER_ID 0x0f +#define APIC_MAX_CLUSTER 0xe +#define APIC_MAX_INTRACLUSTER_ID 3 +#define APIC_ID_CLUSTER_SHIFT 4 + +/* fields in VER */ +#define APIC_VER_VERSION 0x000000ff +#define APIC_VER_MAXLVT 0x00ff0000 +#define MAXLVTSHIFT 16 +#define APIC_VER_EOI_SUPPRESSION 0x01000000 +#define APIC_VER_AMD_EXT_SPACE 0x80000000 + +/* fields in LDR */ +#define APIC_LDR_RESERVED 0x00ffffff + +/* fields in DFR */ +#define APIC_DFR_RESERVED 0x0fffffff +#define APIC_DFR_MODEL_MASK 0xf0000000 +#define APIC_DFR_MODEL_FLAT 0xf0000000 +#define APIC_DFR_MODEL_CLUSTER 0x00000000 + +/* fields in SVR */ +#define APIC_SVR_VECTOR 0x000000ff +#define APIC_SVR_VEC_PROG 0x000000f0 +#define APIC_SVR_VEC_FIX 0x0000000f +#define APIC_SVR_ENABLE 0x00000100 +# define APIC_SVR_SWDIS 0x00000000 +# define APIC_SVR_SWEN 0x00000100 +#define APIC_SVR_FOCUS 0x00000200 +# define APIC_SVR_FEN 0x00000000 +# define APIC_SVR_FDIS 0x00000200 +#define APIC_SVR_EOI_SUPPRESSION 0x00001000 + +/* fields in TPR */ +#define APIC_TPR_PRIO 0x000000ff +# define APIC_TPR_INT 0x000000f0 +# define APIC_TPR_SUB 0x0000000f + +/* fields in ESR */ +#define APIC_ESR_SEND_CS_ERROR 0x00000001 +#define APIC_ESR_RECEIVE_CS_ERROR 0x00000002 +#define APIC_ESR_SEND_ACCEPT 0x00000004 +#define APIC_ESR_RECEIVE_ACCEPT 0x00000008 +#define APIC_ESR_SEND_ILLEGAL_VECTOR 0x00000020 +#define APIC_ESR_RECEIVE_ILLEGAL_VECTOR 0x00000040 +#define APIC_ESR_ILLEGAL_REGISTER 0x00000080 + +/* fields in ICR_LOW */ +#define APIC_VECTOR_MASK 0x000000ff + +#define APIC_DELMODE_MASK 0x00000700 +# define APIC_DELMODE_FIXED 0x00000000 +# define APIC_DELMODE_LOWPRIO 0x00000100 +# define APIC_DELMODE_SMI 0x00000200 +# define APIC_DELMODE_RR 0x00000300 +# define APIC_DELMODE_NMI 0x00000400 +# define APIC_DELMODE_INIT 0x00000500 +# define APIC_DELMODE_STARTUP 0x00000600 +# define APIC_DELMODE_RESV 0x00000700 + +#define APIC_DESTMODE_MASK 0x00000800 +# define APIC_DESTMODE_PHY 0x00000000 +# define APIC_DESTMODE_LOG 0x00000800 + +#define APIC_DELSTAT_MASK 0x00001000 +# define APIC_DELSTAT_IDLE 0x00000000 +# define APIC_DELSTAT_PEND 0x00001000 + +#define APIC_RESV1_MASK 0x00002000 + +#define APIC_LEVEL_MASK 0x00004000 +# define APIC_LEVEL_DEASSERT 0x00000000 +# define APIC_LEVEL_ASSERT 0x00004000 + +#define APIC_TRIGMOD_MASK 0x00008000 +# define APIC_TRIGMOD_EDGE 0x00000000 +# define APIC_TRIGMOD_LEVEL 0x00008000 + +#define APIC_RRSTAT_MASK 0x00030000 +# define APIC_RRSTAT_INVALID 0x00000000 +# define APIC_RRSTAT_INPROG 0x00010000 +# define APIC_RRSTAT_VALID 0x00020000 +# define APIC_RRSTAT_RESV 0x00030000 + +#define APIC_DEST_MASK 0x000c0000 +# define APIC_DEST_DESTFLD 0x00000000 +# define APIC_DEST_SELF 0x00040000 +# define APIC_DEST_ALLISELF 0x00080000 +# define APIC_DEST_ALLESELF 0x000c0000 + +#define APIC_RESV2_MASK 0xfff00000 + +#define APIC_ICRLO_RESV_MASK (APIC_RESV1_MASK | APIC_RESV2_MASK) + +/* fields in LVT1/2 */ +#define APIC_LVT_VECTOR 0x000000ff +#define APIC_LVT_DM 0x00000700 +# define APIC_LVT_DM_FIXED 0x00000000 +# define APIC_LVT_DM_SMI 0x00000200 +# define APIC_LVT_DM_NMI 0x00000400 +# define APIC_LVT_DM_INIT 0x00000500 +# define APIC_LVT_DM_EXTINT 0x00000700 +#define APIC_LVT_DS 0x00001000 +#define APIC_LVT_IIPP 0x00002000 +#define APIC_LVT_IIPP_INTALO 0x00002000 +#define APIC_LVT_IIPP_INTAHI 0x00000000 +#define APIC_LVT_RIRR 0x00004000 +#define APIC_LVT_TM 0x00008000 +#define APIC_LVT_M 0x00010000 + + +/* fields in LVT Timer */ +#define APIC_LVTT_VECTOR 0x000000ff +#define APIC_LVTT_DS 0x00001000 +#define APIC_LVTT_M 0x00010000 +#define APIC_LVTT_TM 0x00060000 +# define APIC_LVTT_TM_ONE_SHOT 0x00000000 +# define APIC_LVTT_TM_PERIODIC 0x00020000 +# define APIC_LVTT_TM_TSCDLT 0x00040000 +# define APIC_LVTT_TM_RSRV 0x00060000 + +/* APIC timer current count */ +#define APIC_TIMER_MAX_COUNT 0xffffffff + +/* fields in TDCR */ +#define APIC_TDCR_2 0x00 +#define APIC_TDCR_4 0x01 +#define APIC_TDCR_8 0x02 +#define APIC_TDCR_16 0x03 +#define APIC_TDCR_32 0x08 +#define APIC_TDCR_64 0x09 +#define APIC_TDCR_128 0x0a +#define APIC_TDCR_1 0x0b + +/* Constants related to AMD Extended APIC Features Register */ +#define APIC_EXTF_ELVT_MASK 0x00ff0000 +#define APIC_EXTF_ELVT_SHIFT 16 +#define APIC_EXTF_EXTID_CAP 0x00000004 +#define APIC_EXTF_SEIO_CAP 0x00000002 +#define APIC_EXTF_IER_CAP 0x00000001 + +/* LVT table indices */ +#define APIC_LVT_LINT0 0 +#define APIC_LVT_LINT1 1 +#define APIC_LVT_TIMER 2 +#define APIC_LVT_ERROR 3 +#define APIC_LVT_PMC 4 +#define APIC_LVT_THERMAL 5 +#define APIC_LVT_CMCI 6 +#define APIC_LVT_MAX APIC_LVT_CMCI + +/* AMD extended LVT constants, seem to be assigned by fiat */ +#define APIC_ELVT_IBS 0 /* Instruction based sampling */ +#define APIC_ELVT_MCA 1 /* MCE thresholding */ +#define APIC_ELVT_DEI 2 /* Deferred error interrupt */ +#define APIC_ELVT_SBI 3 /* Sideband interface */ +#define APIC_ELVT_MAX APIC_ELVT_SBI + +/****************************************************************************** + * I/O APIC defines + */ + +/* default physical locations of an IO APIC */ +#define DEFAULT_IO_APIC_BASE 0xfec00000 + +/* window register offset */ +#define IOAPIC_WINDOW 0x10 +#define IOAPIC_EOIR 0x40 + +#define IOAPIC_WND_SIZE 0x50 + +/* indexes into IO APIC */ +#define IOAPIC_ID 0x00 +#define IOAPIC_VER 0x01 +#define IOAPIC_ARB 0x02 +#define IOAPIC_REDTBL 0x10 +#define IOAPIC_REDTBL0 IOAPIC_REDTBL +#define IOAPIC_REDTBL1 (IOAPIC_REDTBL+0x02) +#define IOAPIC_REDTBL2 (IOAPIC_REDTBL+0x04) +#define IOAPIC_REDTBL3 (IOAPIC_REDTBL+0x06) +#define IOAPIC_REDTBL4 (IOAPIC_REDTBL+0x08) +#define IOAPIC_REDTBL5 (IOAPIC_REDTBL+0x0a) +#define IOAPIC_REDTBL6 (IOAPIC_REDTBL+0x0c) +#define IOAPIC_REDTBL7 (IOAPIC_REDTBL+0x0e) +#define IOAPIC_REDTBL8 (IOAPIC_REDTBL+0x10) +#define IOAPIC_REDTBL9 (IOAPIC_REDTBL+0x12) +#define IOAPIC_REDTBL10 (IOAPIC_REDTBL+0x14) +#define IOAPIC_REDTBL11 (IOAPIC_REDTBL+0x16) +#define IOAPIC_REDTBL12 (IOAPIC_REDTBL+0x18) +#define IOAPIC_REDTBL13 (IOAPIC_REDTBL+0x1a) +#define IOAPIC_REDTBL14 (IOAPIC_REDTBL+0x1c) +#define IOAPIC_REDTBL15 (IOAPIC_REDTBL+0x1e) +#define IOAPIC_REDTBL16 (IOAPIC_REDTBL+0x20) +#define IOAPIC_REDTBL17 (IOAPIC_REDTBL+0x22) +#define IOAPIC_REDTBL18 (IOAPIC_REDTBL+0x24) +#define IOAPIC_REDTBL19 (IOAPIC_REDTBL+0x26) +#define IOAPIC_REDTBL20 (IOAPIC_REDTBL+0x28) +#define IOAPIC_REDTBL21 (IOAPIC_REDTBL+0x2a) +#define IOAPIC_REDTBL22 (IOAPIC_REDTBL+0x2c) +#define IOAPIC_REDTBL23 (IOAPIC_REDTBL+0x2e) + +/* fields in VER */ +#define IOART_VER_VERSION 0x000000ff +#define IOART_VER_MAXREDIR 0x00ff0000 +#define MAXREDIRSHIFT 16 + +/* + * fields in the IO APIC's redirection table entries + */ +#define IOART_DEST APIC_ID_MASK /* broadcast addr: all APICs */ + +#define IOART_RESV 0x00fe0000 /* reserved */ + +#define IOART_INTMASK 0x00010000 /* R/W: INTerrupt mask */ +# define IOART_INTMCLR 0x00000000 /* clear, allow INTs */ +# define IOART_INTMSET 0x00010000 /* set, inhibit INTs */ + +#define IOART_TRGRMOD 0x00008000 /* R/W: trigger mode */ +# define IOART_TRGREDG 0x00000000 /* edge */ +# define IOART_TRGRLVL 0x00008000 /* level */ + +#define IOART_REM_IRR 0x00004000 /* RO: remote IRR */ + +#define IOART_INTPOL 0x00002000 /* R/W: INT input pin polarity */ +# define IOART_INTAHI 0x00000000 /* active high */ +# define IOART_INTALO 0x00002000 /* active low */ + +#define IOART_DELIVS 0x00001000 /* RO: delivery status */ + +#define IOART_DESTMOD 0x00000800 /* R/W: destination mode */ +# define IOART_DESTPHY 0x00000000 /* physical */ +# define IOART_DESTLOG 0x00000800 /* logical */ + +#define IOART_DELMOD 0x00000700 /* R/W: delivery mode */ +# define IOART_DELFIXED 0x00000000 /* fixed */ +# define IOART_DELLOPRI 0x00000100 /* lowest priority */ +# define IOART_DELSMI 0x00000200 /* System Management INT */ +# define IOART_DELRSV1 0x00000300 /* reserved */ +# define IOART_DELNMI 0x00000400 /* NMI signal */ +# define IOART_DELINIT 0x00000500 /* INIT signal */ +# define IOART_DELRSV2 0x00000600 /* reserved */ +# define IOART_DELEXINT 0x00000700 /* External INTerrupt */ + +#define IOART_INTVEC 0x000000ff /* R/W: INTerrupt vector field */ + +#endif /* _X86_APICREG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/apicvar.h b/lib/libc/include/x86_64-freebsd-any/x86/apicvar.h new file mode 100644 index 000000000000..b399298e2c98 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/apicvar.h @@ -0,0 +1,493 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_APICVAR_H_ +#define _X86_APICVAR_H_ + +/* + * Local && I/O APIC variable definitions. + */ + +/* + * Layout of local APIC interrupt vectors: + * + * 0xff (255) +-------------+ + * | | 15 (Spurious / IPIs / Local Interrupts) + * 0xf0 (240) +-------------+ + * | | 14 (I/O Interrupts / Timer) + * 0xe0 (224) +-------------+ + * | | 13 (I/O Interrupts) + * 0xd0 (208) +-------------+ + * | | 12 (I/O Interrupts) + * 0xc0 (192) +-------------+ + * | | 11 (I/O Interrupts) + * 0xb0 (176) +-------------+ + * | | 10 (I/O Interrupts) + * 0xa0 (160) +-------------+ + * | | 9 (I/O Interrupts) + * 0x90 (144) +-------------+ + * | | 8 (I/O Interrupts / System Calls) + * 0x80 (128) +-------------+ + * | | 7 (I/O Interrupts) + * 0x70 (112) +-------------+ + * | | 6 (I/O Interrupts) + * 0x60 (96) +-------------+ + * | | 5 (I/O Interrupts) + * 0x50 (80) +-------------+ + * | | 4 (I/O Interrupts) + * 0x40 (64) +-------------+ + * | | 3 (I/O Interrupts) + * 0x30 (48) +-------------+ + * | | 2 (ATPIC Interrupts) + * 0x20 (32) +-------------+ + * | | 1 (Exceptions, traps, faults, etc.) + * 0x10 (16) +-------------+ + * | | 0 (Exceptions, traps, faults, etc.) + * 0x00 (0) +-------------+ + * + * Note: 0x80 needs to be handled specially and not allocated to an + * I/O device! + */ + +#define xAPIC_MAX_APIC_ID 0xfe +#define xAPIC_ID_ALL 0xff +#define MAX_APIC_ID 0x200 +#define APIC_ID_ALL 0xffffffff + +#define IOAPIC_MAX_ID xAPIC_MAX_APIC_ID + +/* I/O Interrupts are used for external devices such as ISA, PCI, etc. */ +#define APIC_IO_INTS (IDT_IO_INTS + 16) +#define APIC_NUM_IOINTS 191 + +/* The timer interrupt is used for clock handling and drives hardclock, etc. */ +#define APIC_TIMER_INT (APIC_IO_INTS + APIC_NUM_IOINTS) + +/* + ********************* !!! WARNING !!! ****************************** + * Each local apic has an interrupt receive fifo that is two entries deep + * for each interrupt priority class (higher 4 bits of interrupt vector). + * Once the fifo is full the APIC can no longer receive interrupts for this + * class and sending IPIs from other CPUs will be blocked. + * To avoid deadlocks there should be no more than two IPI interrupts + * pending at the same time. + * Currently this is guaranteed by dividing the IPIs in two groups that have + * each at most one IPI interrupt pending. The first group is protected by the + * smp_ipi_mtx and waits for the completion of the IPI (Only one IPI user + * at a time) The second group uses a single interrupt and a bitmap to avoid + * redundant IPI interrupts. + */ + +/* Interrupts for local APIC LVT entries other than the timer. */ +#define APIC_LOCAL_INTS 240 +#define APIC_ERROR_INT APIC_LOCAL_INTS +#define APIC_THERMAL_INT (APIC_LOCAL_INTS + 1) +#define APIC_CMC_INT (APIC_LOCAL_INTS + 2) +#define APIC_IPI_INTS (APIC_LOCAL_INTS + 3) + +#define IPI_RENDEZVOUS (APIC_IPI_INTS) /* Inter-CPU rendezvous. */ +#define IPI_INVLTLB (APIC_IPI_INTS + 1) /* TLB Shootdown IPIs */ +#define IPI_INVLPG (APIC_IPI_INTS + 2) +#define IPI_INVLRNG (APIC_IPI_INTS + 3) +#define IPI_INVLCACHE (APIC_IPI_INTS + 4) +/* Vector to handle bitmap based IPIs */ +#define IPI_BITMAP_VECTOR (APIC_IPI_INTS + 5) + +/* IPIs handled by IPI_BITMAP_VECTOR */ +#define IPI_AST 0 /* Generate software trap. */ +#define IPI_PREEMPT 1 +#define IPI_HARDCLOCK 2 +#define IPI_BITMAP_LAST IPI_HARDCLOCK +#define IPI_IS_BITMAPED(x) ((x) <= IPI_BITMAP_LAST) + +#define IPI_STOP (APIC_IPI_INTS + 6) /* Stop CPU until restarted. */ +#define IPI_SUSPEND (APIC_IPI_INTS + 7) /* Suspend CPU until restarted. */ +#define IPI_SWI (APIC_IPI_INTS + 8) /* Run clk_intr_event. */ +#define IPI_DYN_FIRST (APIC_IPI_INTS + 9) +#define IPI_DYN_LAST (253) /* IPIs allocated at runtime */ + +/* + * IPI_STOP_HARD does not need to occupy a slot in the IPI vector space since + * it is delivered using an NMI anyways. + */ +#define IPI_NMI_FIRST 254 +#define IPI_TRACE 254 /* Interrupt for tracing. */ +#define IPI_STOP_HARD 255 /* Stop CPU with a NMI. */ + +/* + * The spurious interrupt can share the priority class with the IPIs since + * it is not a normal interrupt. (Does not use the APIC's interrupt fifo) + */ +#define APIC_SPURIOUS_INT 255 + +#ifndef LOCORE + +#define APIC_IPI_DEST_SELF -1 +#define APIC_IPI_DEST_ALL -2 +#define APIC_IPI_DEST_OTHERS -3 + +#define APIC_BUS_UNKNOWN -1 +#define APIC_BUS_ISA 0 +#define APIC_BUS_EISA 1 +#define APIC_BUS_PCI 2 +#define APIC_BUS_MAX APIC_BUS_PCI + +#define IRQ_EXTINT -1 +#define IRQ_NMI -2 +#define IRQ_SMI -3 +#define IRQ_DISABLED -4 + +/* + * An APIC enumerator is a pseudo bus driver that enumerates APIC's including + * CPU's and I/O APIC's. + */ +struct apic_enumerator { + const char *apic_name; + int (*apic_probe)(void); + int (*apic_probe_cpus)(void); + int (*apic_setup_local)(void); + int (*apic_setup_io)(void); + SLIST_ENTRY(apic_enumerator) apic_next; +}; + +inthand_t + IDTVEC(apic_isr1), IDTVEC(apic_isr2), IDTVEC(apic_isr3), + IDTVEC(apic_isr4), IDTVEC(apic_isr5), IDTVEC(apic_isr6), + IDTVEC(apic_isr7), IDTVEC(cmcint), IDTVEC(errorint), + IDTVEC(spuriousint), IDTVEC(timerint), + IDTVEC(apic_isr1_pti), IDTVEC(apic_isr2_pti), IDTVEC(apic_isr3_pti), + IDTVEC(apic_isr4_pti), IDTVEC(apic_isr5_pti), IDTVEC(apic_isr6_pti), + IDTVEC(apic_isr7_pti), IDTVEC(cmcint_pti), IDTVEC(errorint_pti), + IDTVEC(spuriousint_pti), IDTVEC(timerint_pti); + +extern vm_paddr_t lapic_paddr; +extern int *apic_cpuids; + +void apic_register_enumerator(struct apic_enumerator *enumerator); +void *ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase); +int ioapic_disable_pin(void *cookie, u_int pin); +int ioapic_get_vector(void *cookie, u_int pin); +void ioapic_register(void *cookie); +int ioapic_remap_vector(void *cookie, u_int pin, int vector); +int ioapic_set_bus(void *cookie, u_int pin, int bus_type); +int ioapic_set_extint(void *cookie, u_int pin); +int ioapic_set_nmi(void *cookie, u_int pin); +int ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol); +int ioapic_set_triggermode(void *cookie, u_int pin, + enum intr_trigger trigger); +int ioapic_set_smi(void *cookie, u_int pin); + +/* + * Struct containing pointers to APIC functions whose + * implementation is run time selectable. + */ +struct apic_ops { + void (*create)(u_int, int); + void (*init)(vm_paddr_t); + void (*xapic_mode)(void); + bool (*is_x2apic)(void); + void (*setup)(int); + void (*dump)(const char *); + void (*disable)(void); + void (*eoi)(void); + int (*id)(void); + int (*intr_pending)(u_int); + void (*set_logical_id)(u_int, u_int, u_int); + u_int (*cpuid)(u_int); + + /* Vectors */ + u_int (*alloc_vector)(u_int, u_int); + u_int (*alloc_vectors)(u_int, u_int *, u_int, u_int); + void (*enable_vector)(u_int, u_int); + void (*disable_vector)(u_int, u_int); + void (*free_vector)(u_int, u_int, u_int); + + + /* PMC */ + int (*enable_pmc)(void); + void (*disable_pmc)(void); + void (*reenable_pmc)(void); + + /* CMC */ + void (*enable_cmc)(void); + + /* AMD ELVT */ + int (*enable_mca_elvt)(void); + + /* IPI */ + void (*ipi_raw)(register_t, u_int); + void (*ipi_vectored)(u_int, int); + int (*ipi_wait)(int); + int (*ipi_alloc)(inthand_t *ipifunc); + void (*ipi_free)(int vector); + + /* LVT */ + int (*set_lvt_mask)(u_int, u_int, u_char); + int (*set_lvt_mode)(u_int, u_int, u_int32_t); + int (*set_lvt_polarity)(u_int, u_int, enum intr_polarity); + int (*set_lvt_triggermode)(u_int, u_int, enum intr_trigger); +}; + +extern struct apic_ops apic_ops; + +static inline void +lapic_create(u_int apic_id, int boot_cpu) +{ + + apic_ops.create(apic_id, boot_cpu); +} + +static inline void +lapic_init(vm_paddr_t addr) +{ + + apic_ops.init(addr); +} + +static inline void +lapic_xapic_mode(void) +{ + + apic_ops.xapic_mode(); +} + +static inline bool +lapic_is_x2apic(void) +{ + + return (apic_ops.is_x2apic()); +} + +static inline void +lapic_setup(int boot) +{ + + apic_ops.setup(boot); +} + +static inline void +lapic_dump(const char *str) +{ + + apic_ops.dump(str); +} + +static inline void +lapic_disable(void) +{ + + apic_ops.disable(); +} + +static inline void +lapic_eoi(void) +{ + + apic_ops.eoi(); +} + +static inline int +lapic_id(void) +{ + + return (apic_ops.id()); +} + +static inline int +lapic_intr_pending(u_int vector) +{ + + return (apic_ops.intr_pending(vector)); +} + +/* XXX: UNUSED */ +static inline void +lapic_set_logical_id(u_int apic_id, u_int cluster, u_int cluster_id) +{ + + apic_ops.set_logical_id(apic_id, cluster, cluster_id); +} + +static inline u_int +apic_cpuid(u_int apic_id) +{ + + return (apic_ops.cpuid(apic_id)); +} + +static inline u_int +apic_alloc_vector(u_int apic_id, u_int irq) +{ + + return (apic_ops.alloc_vector(apic_id, irq)); +} + +static inline u_int +apic_alloc_vectors(u_int apic_id, u_int *irqs, u_int count, u_int align) +{ + + return (apic_ops.alloc_vectors(apic_id, irqs, count, align)); +} + +static inline void +apic_enable_vector(u_int apic_id, u_int vector) +{ + + apic_ops.enable_vector(apic_id, vector); +} + +static inline void +apic_disable_vector(u_int apic_id, u_int vector) +{ + + apic_ops.disable_vector(apic_id, vector); +} + +static inline void +apic_free_vector(u_int apic_id, u_int vector, u_int irq) +{ + + apic_ops.free_vector(apic_id, vector, irq); +} + +static inline int +lapic_enable_pmc(void) +{ + + return (apic_ops.enable_pmc()); +} + +static inline void +lapic_disable_pmc(void) +{ + + apic_ops.disable_pmc(); +} + +static inline void +lapic_reenable_pmc(void) +{ + + apic_ops.reenable_pmc(); +} + +static inline void +lapic_enable_cmc(void) +{ + + apic_ops.enable_cmc(); +} + +static inline int +lapic_enable_mca_elvt(void) +{ + + return (apic_ops.enable_mca_elvt()); +} + +static inline void +lapic_ipi_raw(register_t icrlo, u_int dest) +{ + + apic_ops.ipi_raw(icrlo, dest); +} + +static inline void +lapic_ipi_vectored(u_int vector, int dest) +{ + + apic_ops.ipi_vectored(vector, dest); +} + +static inline int +lapic_ipi_wait(int delay) +{ + + return (apic_ops.ipi_wait(delay)); +} + +static inline int +lapic_ipi_alloc(inthand_t *ipifunc) +{ + + return (apic_ops.ipi_alloc(ipifunc)); +} + +static inline void +lapic_ipi_free(int vector) +{ + + return (apic_ops.ipi_free(vector)); +} + +static inline int +lapic_set_lvt_mask(u_int apic_id, u_int lvt, u_char masked) +{ + + return (apic_ops.set_lvt_mask(apic_id, lvt, masked)); +} + +static inline int +lapic_set_lvt_mode(u_int apic_id, u_int lvt, u_int32_t mode) +{ + + return (apic_ops.set_lvt_mode(apic_id, lvt, mode)); +} + +static inline int +lapic_set_lvt_polarity(u_int apic_id, u_int lvt, enum intr_polarity pol) +{ + + return (apic_ops.set_lvt_polarity(apic_id, lvt, pol)); +} + +static inline int +lapic_set_lvt_triggermode(u_int apic_id, u_int lvt, enum intr_trigger trigger) +{ + + return (apic_ops.set_lvt_triggermode(apic_id, lvt, trigger)); +} + +void lapic_handle_cmc(void); +void lapic_handle_error(void); +void lapic_handle_intr(int vector, struct trapframe *frame); +void lapic_handle_timer(struct trapframe *frame); + +int ioapic_get_rid(u_int apic_id, uint16_t *ridp); + +extern int x2apic_mode; +extern int lapic_eoi_suppression; + +#ifdef _SYS_SYSCTL_H_ +SYSCTL_DECL(_hw_apic); +#endif + +#endif /* !LOCORE */ +#endif /* _X86_APICVAR_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/apm_bios.h b/lib/libc/include/x86_64-freebsd-any/x86/apm_bios.h new file mode 100644 index 000000000000..05bef867a2f1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/apm_bios.h @@ -0,0 +1,264 @@ +/*- + * APM (Advanced Power Management) BIOS Device Driver + * + * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * + * $FreeBSD$ + */ + +#ifndef _X86_APM_BIOS_H_ +#define _X86_APM_BIOS_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* BIOS id */ +#define APM_BIOS 0x53 +#define APM_INT 0x15 + +/* APM flags */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +/* APM initializer physical address */ +#define APM_OURADDR 0x00080000 + +/* APM functions */ +#define APM_INSTCHECK 0x00 +#define APM_REALCONNECT 0x01 +#define APM_PROT16CONNECT 0x02 +#define APM_PROT32CONNECT 0x03 +#define APM_DISCONNECT 0x04 +#define APM_CPUIDLE 0x05 +#define APM_CPUBUSY 0x06 +#define APM_SETPWSTATE 0x07 +#define APM_ENABLEDISABLEPM 0x08 +#define APM_RESTOREDEFAULT 0x09 +#define APM_GETPWSTATUS 0x0a +#define APM_GETPMEVENT 0x0b +#define APM_GETPWSTATE 0x0c +#define APM_ENABLEDISABLEDPM 0x0d +#define APM_DRVVERSION 0x0e +#define APM_ENGAGEDISENGAGEPM 0x0f +#define APM_GETCAPABILITIES 0x10 +#define APM_RESUMETIMER 0x11 +#define APM_RESUMEONRING 0x12 +#define APM_TIMERREQUESTS 0x13 +#define APM_OEMFUNC 0x80 + +/* error code */ +#define APME_OK 0x00 +#define APME_PMDISABLED 0x01 +#define APME_REALESTABLISHED 0x02 +#define APME_NOTCONNECTED 0x03 +#define APME_PROT16ESTABLISHED 0x05 +#define APME_PROT16NOTSUPPORTED 0x06 +#define APME_PROT32ESTABLISHED 0x07 +#define APME_PROT32NOTDUPPORTED 0x08 +#define APME_UNKNOWNDEVICEID 0x09 +#define APME_OUTOFRANGE 0x0a +#define APME_NOTENGAGED 0x0b +#define APME_CANTENTERSTATE 0x60 +#define APME_NOPMEVENT 0x80 +#define APME_NOAPMPRESENT 0x86 + + +/* device code */ +#define PMDV_APMBIOS 0x0000 +#define PMDV_ALLDEV 0x0001 +#define PMDV_DISP0 0x0100 +#define PMDV_DISP1 0x0101 +#define PMDV_DISPALL 0x01ff +#define PMDV_2NDSTORAGE0 0x0200 +#define PMDV_2NDSTORAGE1 0x0201 +#define PMDV_2NDSTORAGE2 0x0202 +#define PMDV_2NDSTORAGE3 0x0203 +#define PMDV_PARALLEL0 0x0300 +#define PMDV_PARALLEL1 0x0301 +#define PMDV_SERIAL0 0x0400 +#define PMDV_SERIAL1 0x0401 +#define PMDV_SERIAL2 0x0402 +#define PMDV_SERIAL3 0x0403 +#define PMDV_SERIAL4 0x0404 +#define PMDV_SERIAL5 0x0405 +#define PMDV_SERIAL6 0x0406 +#define PMDV_SERIAL7 0x0407 +#define PMDV_NET0 0x0500 +#define PMDV_NET1 0x0501 +#define PMDV_NET2 0x0502 +#define PMDV_NET3 0x0503 +#define PMDV_PCMCIA0 0x0600 +#define PMDV_PCMCIA1 0x0601 +#define PMDV_PCMCIA2 0x0602 +#define PMDV_PCMCIA3 0x0603 +/* 0x0700 - 0x7fff Reserved */ +#define PMDV_BATT_BASE 0x8000 +#define PMDV_BATT0 0x8001 +#define PMDV_BATT1 0x8002 +#define PMDV_BATT_ALL 0x80ff +/* 0x8100 - 0xdfff Reserved */ +/* 0xe000 - 0xefff OEM-defined power device IDs */ +/* 0xf000 - 0xffff Reserved */ + +/* Power state */ +#define PMST_APMENABLED 0x0000 +#define PMST_STANDBY 0x0001 +#define PMST_SUSPEND 0x0002 +#define PMST_OFF 0x0003 +#define PMST_LASTREQNOTIFY 0x0004 +#define PMST_LASTREQREJECT 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +#if !defined(ASSEMBLER) && !defined(INITIALIZER) + +/* C definitions */ +struct apmhook { + struct apmhook *ah_next; + int (*ah_fun)(void *ah_arg); + void *ah_arg; + const char *ah_name; + int ah_order; +}; +#define APM_HOOK_NONE (-1) +#define APM_HOOK_SUSPEND 0 +#define APM_HOOK_RESUME 1 +#define NAPM_HOOK 2 + +#ifdef _KERNEL + +void apm_suspend(int state); +struct apmhook *apm_hook_establish (int apmh, struct apmhook *); +void apm_hook_disestablish (int apmh, struct apmhook *); +void apm_cpu_idle(void); +void apm_cpu_busy(void); + +#endif + +#endif /* !ASSEMBLER && !INITIALIZER */ + +#define APM_MIN_ORDER 0x00 +#define APM_MID_ORDER 0x80 +#define APM_MAX_ORDER 0xff + +/* power management event code */ +#define PMEV_NOEVENT 0x0000 +#define PMEV_STANDBYREQ 0x0001 +#define PMEV_SUSPENDREQ 0x0002 +#define PMEV_NORMRESUME 0x0003 +#define PMEV_CRITRESUME 0x0004 +#define PMEV_BATTERYLOW 0x0005 +#define PMEV_POWERSTATECHANGE 0x0006 +#define PMEV_UPDATETIME 0x0007 +#define PMEV_CRITSUSPEND 0x0008 +#define PMEV_USERSTANDBYREQ 0x0009 +#define PMEV_USERSUSPENDREQ 0x000a +#define PMEV_STANDBYRESUME 0x000b +#define PMEV_CAPABILITIESCHANGE 0x000c +/* 0x000d - 0x00ff Reserved system events */ +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define PMEV_DEFAULT 0xffffffff /* used for customization */ + +#if !defined(ASSEMBLER) && !defined(INITIALIZER) + +/* + * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This + * is for backward compatibility with old executables. + */ +typedef struct apm_info_old { + u_int ai_major; /* APM major version */ + u_int ai_minor; /* APM minor version */ + u_int ai_acline; /* AC line status */ + u_int ai_batt_stat; /* Battery status */ + u_int ai_batt_life; /* Remaining battery life */ + u_int ai_status; /* Status of APM support (enabled/disabled) */ +} *apm_info_old_t; + +/* + * Structure returned by the APMIO_GETINFO ioctl. + * + * In the comments below, the parenthesized numbers indicate the minimum + * value of ai_infoversion for which each field is valid. + */ +typedef struct apm_info { + u_int ai_infoversion; /* Indicates which fields are valid */ + u_int ai_major; /* APM major version (0) */ + u_int ai_minor; /* APM minor version (0) */ + u_int ai_acline; /* AC line status (0) */ + u_int ai_batt_stat; /* Battery status (0) */ + u_int ai_batt_life; /* Remaining battery life in percent (0) */ + int ai_batt_time; /* Remaining battery time in seconds (0) */ + u_int ai_status; /* True if enabled (0) */ + u_int ai_batteries; /* Number of batteries (1) */ + u_int ai_capabilities;/* APM Capabilities (1) */ + u_int ai_spare[6]; /* For future expansion */ +} *apm_info_t; + +/* Battery flag */ +#define APM_BATT_HIGH 0x01 +#define APM_BATT_LOW 0x02 +#define APM_BATT_CRITICAL 0x04 +#define APM_BATT_CHARGING 0x08 +#define APM_BATT_NOT_PRESENT 0x10 +#define APM_BATT_NO_SYSTEM 0x80 + +typedef struct apm_pwstatus { + u_int ap_device; /* Device code of battery */ + u_int ap_acline; /* AC line status (0) */ + u_int ap_batt_stat; /* Battery status (0) */ + u_int ap_batt_flag; /* Battery flag (0) */ + u_int ap_batt_life; /* Remaining battery life in percent (0) */ + int ap_batt_time; /* Remaining battery time in seconds (0) */ +} *apm_pwstatus_t; + +struct apm_bios_arg { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; + uint32_t esi; + uint32_t edi; +}; + +struct apm_event_info { + u_int type; + u_int index; + u_int spare[8]; +}; + +#define APMIO_SUSPEND _IO('P', 1) +#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old) +#define APMIO_ENABLE _IO('P', 5) +#define APMIO_DISABLE _IO('P', 6) +#define APMIO_HALTCPU _IO('P', 7) +#define APMIO_NOTHALTCPU _IO('P', 8) +#define APMIO_DISPLAY _IOW('P', 9, int) +#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg) +#define APMIO_GETINFO _IOR('P', 11, struct apm_info) +#define APMIO_STANDBY _IO('P', 12) +#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus) +/* for /dev/apmctl */ +#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info) +#define APMIO_REJECTLASTREQ _IO('P', 101) + +#endif /* !ASSEMBLER && !INITIALIZER */ + +#endif /* !_X86_APM_BIOS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/bus.h b/lib/libc/include/x86_64-freebsd-any/x86/bus.h new file mode 100644 index 000000000000..2427ae512ccc --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/bus.h @@ -0,0 +1,1109 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause-NetBSDE + * + * Copyright (c) KATO Takenori, 1999. + * + * All rights reserved. Unpublished rights reserved under the copyright + * laws of Japan. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer as + * the first lines of this file unmodified. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _X86_BUS_H_ +#define _X86_BUS_H_ + +#include +#include + +#ifndef __GNUCLIKE_ASM +#error "no assembler code for your compiler" +#endif + +/* + * Values for the x86 bus space tag, not to be used directly by MI code. + */ +#define X86_BUS_SPACE_IO 0 /* space is i/o space */ +#define X86_BUS_SPACE_MEM 1 /* space is mem space */ + +#define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF +#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF +#if defined(__amd64__) +#define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFFULL +#else +#define BUS_SPACE_MAXSIZE 0xFFFFFFFF +#endif +#define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF +#define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF +#if defined(__amd64__) || defined(PAE) +#define BUS_SPACE_MAXADDR_48BIT 0xFFFFFFFFFFFFULL +#define BUS_SPACE_MAXADDR 0xFFFFFFFFFFFFFFFFULL +#else +#define BUS_SPACE_MAXADDR 0xFFFFFFFF +#endif + +#define BUS_SPACE_INVALID_DATA (~0) +#define BUS_SPACE_UNRESTRICTED (~0) + +/* + * Map a region of device bus space into CPU virtual address space. + */ + +int bus_space_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size, + int flags, bus_space_handle_t *bshp); + +/* + * Unmap a region of device bus space. + */ + +void bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t size); + +/* + * Get a new handle for a subregion of an already-mapped area of bus space. + */ + +static __inline int bus_space_subregion(bus_space_tag_t t, + bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, + bus_space_handle_t *nbshp); + +static __inline int +bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size __unused, + bus_space_handle_t *nbshp) +{ + + *nbshp = bsh + offset; + return (0); +} + +/* + * Allocate a region of memory that is accessible to devices in bus space. + */ + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); + +/* + * Free a region of bus space accessible memory. + */ + +static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +static __inline void +bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused, + bus_size_t size __unused) +{ +} + + +/* + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ +static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +#ifdef __amd64__ +static __inline uint64_t bus_space_read_8(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); +#endif + +static __inline u_int8_t +bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ + + if (tag == X86_BUS_SPACE_IO) + return (inb(handle + offset)); + return (*(volatile u_int8_t *)(handle + offset)); +} + +static __inline u_int16_t +bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ + + if (tag == X86_BUS_SPACE_IO) + return (inw(handle + offset)); + return (*(volatile u_int16_t *)(handle + offset)); +} + +static __inline u_int32_t +bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ + + if (tag == X86_BUS_SPACE_IO) + return (inl(handle + offset)); + return (*(volatile u_int32_t *)(handle + offset)); +} + +#ifdef __amd64__ +static __inline uint64_t +bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ + + if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */ + return (BUS_SPACE_INVALID_DATA); + return (*(volatile uint64_t *)(handle + offset)); +} +#endif + +/* + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ +static __inline void bus_space_read_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, + size_t count); + +static __inline void bus_space_read_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, + size_t count); + +static __inline void bus_space_read_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, + size_t count); + +static __inline void +bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + insb(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: movb (%2),%%al \n\ + stosb \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#endif + } +} + +static __inline void +bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + insw(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: movw (%2),%%ax \n\ + stosw \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#endif + } +} + +static __inline void +bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + insl(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: movl (%2),%%eax \n\ + stosl \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#endif + } +} + +#if 0 /* Cause a link error for bus_space_read_multi_8 */ +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! +#endif + +/* + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ +static __inline void bus_space_read_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, + size_t count); + +static __inline void bus_space_read_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, + size_t count); + +static __inline void bus_space_read_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, + size_t count); + + +static __inline void +bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: inb %w2,%%al \n\ + stosb \n\ + incl %2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsb" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: inw %w2,%%ax \n\ + stosw \n\ + addl $2,%2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsw" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: inl %w2,%%eax \n\ + stosl \n\ + addl $4,%2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsl" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#endif + } +} + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! +#endif + +/* + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + +static __inline void bus_space_write_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value); + +static __inline void bus_space_write_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value); + +static __inline void bus_space_write_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value); + +#ifdef __amd64__ +static __inline void bus_space_write_8(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, uint64_t value); +#endif + +static __inline void +bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value) +{ + + if (tag == X86_BUS_SPACE_IO) + outb(bsh + offset, value); + else + *(volatile u_int8_t *)(bsh + offset) = value; +} + +static __inline void +bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value) +{ + + if (tag == X86_BUS_SPACE_IO) + outw(bsh + offset, value); + else + *(volatile u_int16_t *)(bsh + offset) = value; +} + +static __inline void +bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value) +{ + + if (tag == X86_BUS_SPACE_IO) + outl(bsh + offset, value); + else + *(volatile u_int32_t *)(bsh + offset) = value; +} + +#ifdef __amd64__ +static __inline void +bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, uint64_t value) +{ + + if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */ + return; + else + *(volatile uint64_t *)(bsh + offset) = value; +} +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + +static __inline void bus_space_write_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int8_t *addr, + size_t count); +static __inline void bus_space_write_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int16_t *addr, + size_t count); + +static __inline void bus_space_write_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int32_t *addr, + size_t count); + +static __inline void +bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + outsb(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsb \n\ + movb %%al,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + outsw(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsw \n\ + movw %%ax,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) + outsl(bsh + offset, addr, count); + else { +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsl \n\ + movl %%eax,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#endif + } +} + +#if 0 /* Cause a link error for bus_space_write_multi_8 */ +#define bus_space_write_multi_8(t, h, o, a, c) \ + !!! bus_space_write_multi_8 unimplemented !!! +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + +static __inline void bus_space_write_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int8_t *addr, + size_t count); +static __inline void bus_space_write_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int16_t *addr, + size_t count); +static __inline void bus_space_write_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int32_t *addr, + size_t count); + +static __inline void +bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsb \n\ + outb %%al,%w0 \n\ + incl %0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsb" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsw \n\ + outw %%ax,%w0 \n\ + addl $2,%0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsw" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#endif + } +} + +static __inline void +bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ + + if (tag == X86_BUS_SPACE_IO) { + int _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + 1: lodsl \n\ + outl %%eax,%w0 \n\ + addl $4,%0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#endif + } else { + bus_space_handle_t _port_ = bsh + offset; +#ifdef __GNUCLIKE_ASM + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsl" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#endif + } +} + +#if 0 /* Cause a link error for bus_space_write_region_8 */ +#define bus_space_write_region_8 \ + !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + +static __inline void bus_space_set_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int8_t value, size_t count); +static __inline void bus_space_set_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int16_t value, size_t count); +static __inline void bus_space_set_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int32_t value, size_t count); + +static __inline void +bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + while (count--) + outb(addr, value); + else + while (count--) + *(volatile u_int8_t *)(addr) = value; +} + +static __inline void +bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + while (count--) + outw(addr, value); + else + while (count--) + *(volatile u_int16_t *)(addr) = value; +} + +static __inline void +bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + while (count--) + outl(addr, value); + else + while (count--) + *(volatile u_int32_t *)(addr) = value; +} + +#if 0 /* Cause a link error for bus_space_set_multi_8 */ +#define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!! +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + +static __inline void bus_space_set_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, + size_t count); +static __inline void bus_space_set_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, + size_t count); +static __inline void bus_space_set_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, + size_t count); + +static __inline void +bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + for (; count != 0; count--, addr++) + outb(addr, value); + else + for (; count != 0; count--, addr++) + *(volatile u_int8_t *)(addr) = value; +} + +static __inline void +bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + for (; count != 0; count--, addr += 2) + outw(addr, value); + else + for (; count != 0; count--, addr += 2) + *(volatile u_int16_t *)(addr) = value; +} + +static __inline void +bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + + if (tag == X86_BUS_SPACE_IO) + for (; count != 0; count--, addr += 4) + outl(addr, value); + else + for (; count != 0; count--, addr += 4) + *(volatile u_int32_t *)(addr) = value; +} + +#if 0 /* Cause a link error for bus_space_set_region_8 */ +#define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!! +#endif + +/* + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + +static __inline void bus_space_copy_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void bus_space_copy_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void bus_space_copy_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void +bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + + if (tag == X86_BUS_SPACE_IO) { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1++, addr2++) + outb(addr2, inb(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += (count - 1), addr2 += (count - 1); + count != 0; count--, addr1--, addr2--) + outb(addr2, inb(addr1)); + } + } else { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1++, addr2++) + *(volatile u_int8_t *)(addr2) = + *(volatile u_int8_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += (count - 1), addr2 += (count - 1); + count != 0; count--, addr1--, addr2--) + *(volatile u_int8_t *)(addr2) = + *(volatile u_int8_t *)(addr1); + } + } +} + +static __inline void +bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + + if (tag == X86_BUS_SPACE_IO) { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 2, addr2 += 2) + outw(addr2, inw(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1); + count != 0; count--, addr1 -= 2, addr2 -= 2) + outw(addr2, inw(addr1)); + } + } else { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 2, addr2 += 2) + *(volatile u_int16_t *)(addr2) = + *(volatile u_int16_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1); + count != 0; count--, addr1 -= 2, addr2 -= 2) + *(volatile u_int16_t *)(addr2) = + *(volatile u_int16_t *)(addr1); + } + } +} + +static __inline void +bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + + if (tag == X86_BUS_SPACE_IO) { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 4, addr2 += 4) + outl(addr2, inl(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1); + count != 0; count--, addr1 -= 4, addr2 -= 4) + outl(addr2, inl(addr1)); + } + } else { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 4, addr2 += 4) + *(volatile u_int32_t *)(addr2) = + *(volatile u_int32_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1); + count != 0; count--, addr1 -= 4, addr2 -= 4) + *(volatile u_int32_t *)(addr2) = + *(volatile u_int32_t *)(addr1); + } + } +} + +#if 0 /* Cause a link error for bus_space_copy_8 */ +#define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!! +#endif + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, + * bus_size_t offset, bus_size_t len, int flags); + * + * + * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than + * prevent reordering by the compiler; all Intel x86 processors currently + * retire operations outside the CPU in program order. + */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static __inline void +bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused, + bus_size_t offset __unused, bus_size_t len __unused, int flags) +{ +#ifdef __GNUCLIKE_ASM + if (flags & BUS_SPACE_BARRIER_READ) +#ifdef __amd64__ + __asm __volatile("lock; addl $0,0(%%rsp)" : : : "memory"); +#else + __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); +#endif + else + __compiler_membar(); +#endif +} + +#ifdef BUS_SPACE_NO_LEGACY +#undef inb +#undef outb +#define inb(a) compiler_error +#define inw(a) compiler_error +#define inl(a) compiler_error +#define outb(a, b) compiler_error +#define outw(a, b) compiler_error +#define outl(a, b) compiler_error +#endif + +#include + +/* + * Stream accesses are the same as normal accesses on x86; there are no + * supported bus systems with an endianess different from the host one. + */ +#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o)) +#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o)) +#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o)) + +#define bus_space_read_multi_stream_1(t, h, o, a, c) \ + bus_space_read_multi_1((t), (h), (o), (a), (c)) +#define bus_space_read_multi_stream_2(t, h, o, a, c) \ + bus_space_read_multi_2((t), (h), (o), (a), (c)) +#define bus_space_read_multi_stream_4(t, h, o, a, c) \ + bus_space_read_multi_4((t), (h), (o), (a), (c)) + +#define bus_space_write_stream_1(t, h, o, v) \ + bus_space_write_1((t), (h), (o), (v)) +#define bus_space_write_stream_2(t, h, o, v) \ + bus_space_write_2((t), (h), (o), (v)) +#define bus_space_write_stream_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + +#define bus_space_write_multi_stream_1(t, h, o, a, c) \ + bus_space_write_multi_1((t), (h), (o), (a), (c)) +#define bus_space_write_multi_stream_2(t, h, o, a, c) \ + bus_space_write_multi_2((t), (h), (o), (a), (c)) +#define bus_space_write_multi_stream_4(t, h, o, a, c) \ + bus_space_write_multi_4((t), (h), (o), (a), (c)) + +#define bus_space_set_multi_stream_1(t, h, o, v, c) \ + bus_space_set_multi_1((t), (h), (o), (v), (c)) +#define bus_space_set_multi_stream_2(t, h, o, v, c) \ + bus_space_set_multi_2((t), (h), (o), (v), (c)) +#define bus_space_set_multi_stream_4(t, h, o, v, c) \ + bus_space_set_multi_4((t), (h), (o), (v), (c)) + +#define bus_space_read_region_stream_1(t, h, o, a, c) \ + bus_space_read_region_1((t), (h), (o), (a), (c)) +#define bus_space_read_region_stream_2(t, h, o, a, c) \ + bus_space_read_region_2((t), (h), (o), (a), (c)) +#define bus_space_read_region_stream_4(t, h, o, a, c) \ + bus_space_read_region_4((t), (h), (o), (a), (c)) + +#define bus_space_write_region_stream_1(t, h, o, a, c) \ + bus_space_write_region_1((t), (h), (o), (a), (c)) +#define bus_space_write_region_stream_2(t, h, o, a, c) \ + bus_space_write_region_2((t), (h), (o), (a), (c)) +#define bus_space_write_region_stream_4(t, h, o, a, c) \ + bus_space_write_region_4((t), (h), (o), (a), (c)) + +#define bus_space_set_region_stream_1(t, h, o, v, c) \ + bus_space_set_region_1((t), (h), (o), (v), (c)) +#define bus_space_set_region_stream_2(t, h, o, v, c) \ + bus_space_set_region_2((t), (h), (o), (v), (c)) +#define bus_space_set_region_stream_4(t, h, o, v, c) \ + bus_space_set_region_4((t), (h), (o), (v), (c)) + +#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c)) + +#endif /* _X86_BUS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/bus_dma.h b/lib/libc/include/x86_64-freebsd-any/x86/bus_dma.h new file mode 100644 index 000000000000..5bb70419726a --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/bus_dma.h @@ -0,0 +1,201 @@ +/*- + * Copyright (c) 2017 Jason A. Harmening. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_BUS_DMA_H_ +#define _X86_BUS_DMA_H_ + +#define WANT_INLINE_DMAMAP +#include +#include + +#include + +/* + * Is DMA address 1:1 mapping of physical address + */ +static inline bool +bus_dma_id_mapped(bus_dma_tag_t dmat, vm_paddr_t buf, bus_size_t buflen) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->id_mapped(dmat, buf, buflen)); +} + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +static inline int +bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->map_create(dmat, flags, mapp)); +} + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +static inline int +bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->map_destroy(dmat, map)); +} + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints lited in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +static inline int +bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp)); +} + +/* + * Free a piece of memory and it's allociated dmamap, that was allocated + * via bus_dmamem_alloc. Make the same choice for free/contigfree. + */ +static inline void +bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + tc->impl->mem_free(dmat, vaddr, map); +} + +/* + * Release the mapping held by map. + */ +static inline void +bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + struct bus_dma_tag_common *tc; + + if (map != NULL) { + tc = (struct bus_dma_tag_common *)dmat; + tc->impl->map_unload(dmat, map); + } +} + +static inline void +bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op) +{ + struct bus_dma_tag_common *tc; + + if (map != NULL) { + tc = (struct bus_dma_tag_common *)dmat; + tc->impl->map_sync(dmat, map, op); + } +} + +/* + * Utility function to load a physical buffer. segp contains + * the starting segment on entrace, and the ending segment on exit. + */ +static inline int +_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf, + bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs, + segp)); +} + +static inline int +_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma, + bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs, + int *segp) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags, + segs, segp)); +} + +/* + * Utility function to load a linear buffer. segp contains + * the starting segment on entrace, and the ending segment on exit. + */ +static inline int +_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, struct pmap *pmap, int flags, bus_dma_segment_t *segs, + int *segp) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs, + segp)); +} + +static inline void +_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, + struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg) +{ + struct bus_dma_tag_common *tc; + + if (map != NULL) { + tc = (struct bus_dma_tag_common *)dmat; + tc->impl->map_waitok(dmat, map, mem, callback, callback_arg); + } +} + +static inline bus_dma_segment_t * +_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, + bus_dma_segment_t *segs, int nsegs, int error) +{ + struct bus_dma_tag_common *tc; + + tc = (struct bus_dma_tag_common *)dmat; + return (tc->impl->map_complete(dmat, map, segs, nsegs, error)); +} + +#ifdef _KERNEL +bool bus_dma_dmar_set_buswide(device_t dev); +int bus_dma_dmar_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, + vm_paddr_t start, vm_size_t length, int flags); +#endif + +#endif /* !_X86_BUS_DMA_H_ */ + diff --git a/lib/libc/include/x86_64-freebsd-any/x86/busdma_impl.h b/lib/libc/include/x86_64-freebsd-any/x86/busdma_impl.h new file mode 100644 index 000000000000..d91a72bb6c0d --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/busdma_impl.h @@ -0,0 +1,101 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_BUSDMA_IMPL_H +#define __X86_BUSDMA_IMPL_H + +struct bus_dma_tag_common { + struct bus_dma_impl *impl; + struct bus_dma_tag_common *parent; + bus_size_t alignment; + bus_addr_t boundary; + bus_addr_t lowaddr; + bus_addr_t highaddr; + bus_dma_filter_t *filter; + void *filterarg; + bus_size_t maxsize; + u_int nsegments; + bus_size_t maxsegsz; + int flags; + bus_dma_lock_t *lockfunc; + void *lockfuncarg; + int ref_count; + int domain; +}; + +struct bus_dma_impl { + int (*tag_create)(bus_dma_tag_t parent, + bus_size_t alignment, bus_addr_t boundary, bus_addr_t lowaddr, + bus_addr_t highaddr, bus_dma_filter_t *filter, + void *filterarg, bus_size_t maxsize, int nsegments, + bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat); + int (*tag_destroy)(bus_dma_tag_t dmat); + int (*tag_set_domain)(bus_dma_tag_t); + int (*map_create)(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); + int (*map_destroy)(bus_dma_tag_t dmat, bus_dmamap_t map); + int (*mem_alloc)(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp); + void (*mem_free)(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); + int (*load_ma)(bus_dma_tag_t dmat, bus_dmamap_t map, + struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags, + bus_dma_segment_t *segs, int *segp); + int (*load_phys)(bus_dma_tag_t dmat, bus_dmamap_t map, + vm_paddr_t buf, bus_size_t buflen, int flags, + bus_dma_segment_t *segs, int *segp); + int (*load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map, + void *buf, bus_size_t buflen, struct pmap *pmap, int flags, + bus_dma_segment_t *segs, int *segp); + void (*map_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map, + struct memdesc *mem, bus_dmamap_callback_t *callback, + void *callback_arg); + bus_dma_segment_t *(*map_complete)(bus_dma_tag_t dmat, bus_dmamap_t map, + bus_dma_segment_t *segs, int nsegs, int error); + void (*map_unload)(bus_dma_tag_t dmat, bus_dmamap_t map); + void (*map_sync)(bus_dma_tag_t dmat, bus_dmamap_t map, + bus_dmasync_op_t op); + bool (*id_mapped)(bus_dma_tag_t, vm_paddr_t, bus_size_t); +}; + +void bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op); +int bus_dma_run_filter(struct bus_dma_tag_common *dmat, vm_paddr_t paddr); +int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, + bus_size_t alignment, + bus_addr_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, + bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, + int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, size_t sz, void **dmat); + +extern struct bus_dma_impl bus_dma_bounce_impl; + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/cputypes.h b/lib/libc/include/x86_64-freebsd-any/x86/cputypes.h new file mode 100644 index 000000000000..eb9e3753d6f1 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/cputypes.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1993 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_CPUTYPES_H_ +#define _X86_CPUTYPES_H_ + +/* + * Vendors of processor. + */ +#define CPU_VENDOR_NSC 0x100b /* NSC */ +#define CPU_VENDOR_IBM 0x1014 /* IBM */ +#define CPU_VENDOR_AMD 0x1022 /* AMD */ +#define CPU_VENDOR_SIS 0x1039 /* SiS */ +#define CPU_VENDOR_UMC 0x1060 /* UMC */ +#define CPU_VENDOR_NEXGEN 0x1074 /* Nexgen */ +#define CPU_VENDOR_CYRIX 0x1078 /* Cyrix */ +#define CPU_VENDOR_IDT 0x111d /* Centaur/IDT/VIA */ +#define CPU_VENDOR_TRANSMETA 0x1279 /* Transmeta */ +#define CPU_VENDOR_INTEL 0x8086 /* Intel */ +#define CPU_VENDOR_RISE 0xdead2bad /* Rise */ +#define CPU_VENDOR_CENTAUR CPU_VENDOR_IDT +#define CPU_VENDOR_HYGON 0x1d94 /* Hygon */ + +#endif /* !_X86_CPUTYPES_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/dump.h b/lib/libc/include/x86_64-freebsd-any/x86/dump.h new file mode 100644 index 000000000000..91c72acb4e5b --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/dump.h @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2014 EMC Corp. + * Author: Conrad Meyer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_DUMP_H_ +#define _MACHINE_DUMP_H_ + +#ifdef __amd64__ +#define KERNELDUMP_ARCH_VERSION KERNELDUMP_AMD64_VERSION +#define EM_VALUE EM_X86_64 +#else +#define KERNELDUMP_ARCH_VERSION KERNELDUMP_I386_VERSION +#define EM_VALUE EM_386 +#endif + +/* 20 phys_avail entry pairs correspond to 10 pa's */ +#define DUMPSYS_MD_PA_NPAIRS 10 +#define DUMPSYS_NUM_AUX_HDRS 0 + +static inline void +dumpsys_pa_init(void) +{ + + dumpsys_gen_pa_init(); +} + +static inline struct dump_pa * +dumpsys_pa_next(struct dump_pa *p) +{ + + return (dumpsys_gen_pa_next(p)); +} + +static inline void +dumpsys_wbinv_all(void) +{ + + dumpsys_gen_wbinv_all(); +} + +static inline void +dumpsys_unmap_chunk(vm_paddr_t pa, size_t s, void *va) +{ + + dumpsys_gen_unmap_chunk(pa, s, va); +} + +static inline int +dumpsys_write_aux_headers(struct dumperinfo *di) +{ + + return (dumpsys_gen_write_aux_headers(di)); +} + +static inline int +dumpsys(struct dumperinfo *di) +{ + + return (dumpsys_generic(di)); +} + +#endif /* !_MACHINE_DUMP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/elf.h b/lib/libc/include/x86_64-freebsd-any/x86/elf.h new file mode 100644 index 000000000000..4501d88bab64 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/elf.h @@ -0,0 +1,223 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996-1997 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_ELF_H_ +#define _MACHINE_ELF_H_ 1 + +#if defined(__i386__) || defined(_MACHINE_ELF_WANT_32BIT) + +/* + * ELF definitions for the i386 architecture. + */ + +#include /* Definitions common to all 32 bit architectures. */ +#if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64 +#include /* Definitions common to all 64 bit architectures. */ +#endif + +#ifndef __ELF_WORD_SIZE +#define __ELF_WORD_SIZE 32 /* Used by */ +#endif + +#include + +#define ELF_ARCH EM_386 + +#define ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486) + +/* + * Auxiliary vector entries for passing information to the interpreter. + * + * The i386 supplement to the SVR4 ABI specification names this "auxv_t", + * but POSIX lays claim to all symbols ending with "_t". + */ + +typedef struct { /* Auxiliary vector entry on initial stack */ + int a_type; /* Entry type. */ + union { + long a_val; /* Integer value. */ + void *a_ptr; /* Address. */ + void (*a_fcn)(void); /* Function pointer (not used). */ + } a_un; +} Elf32_Auxinfo; + +#if __ELF_WORD_SIZE == 64 +/* Fake for amd64 loader support */ +typedef struct { + int fake; +} Elf64_Auxinfo; +#endif + +__ElfType(Auxinfo); + +/* Values for a_type. */ +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ +#define AT_NOTELF 10 /* Program is not ELF ?? */ +#define AT_UID 11 /* Real uid. */ +#define AT_EUID 12 /* Effective uid. */ +#define AT_GID 13 /* Real gid. */ +#define AT_EGID 14 /* Effective gid. */ +#define AT_EXECPATH 15 /* Path to the executable. */ +#define AT_CANARY 16 /* Canary for SSP. */ +#define AT_CANARYLEN 17 /* Length of the canary. */ +#define AT_OSRELDATE 18 /* OSRELDATE. */ +#define AT_NCPUS 19 /* Number of CPUs. */ +#define AT_PAGESIZES 20 /* Pagesizes. */ +#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */ +#define AT_TIMEKEEP 22 /* Pointer to timehands. */ +#define AT_STACKPROT 23 /* Initial stack protection. */ +#define AT_EHDRFLAGS 24 /* e_flags field from elf hdr */ +#define AT_HWCAP 25 /* CPU feature flags. */ +#define AT_HWCAP2 26 /* CPU feature flags 2. */ + +#define AT_COUNT 27 /* Count of defined aux entry types. */ + +/* + * Relocation types. + */ + +#define R_386_COUNT 38 /* Count of defined relocation types. */ + +/* Define "machine" characteristics */ +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_386 +#define ELF_TARG_VER 1 + +#define ET_DYN_LOAD_ADDR 0x01001000 + +#elif defined(__amd64__) + +/* + * ELF definitions for the AMD64 architecture. + */ + +#ifndef __ELF_WORD_SIZE +#define __ELF_WORD_SIZE 64 /* Used by */ +#endif +#include /* Definitions common to all 32 bit architectures. */ +#include /* Definitions common to all 64 bit architectures. */ +#include + +#define ELF_ARCH EM_X86_64 +#define ELF_ARCH32 EM_386 + +#define ELF_MACHINE_OK(x) ((x) == EM_X86_64) + +/* + * Auxiliary vector entries for passing information to the interpreter. + * + * The i386 supplement to the SVR4 ABI specification names this "auxv_t", + * but POSIX lays claim to all symbols ending with "_t". + */ +typedef struct { /* Auxiliary vector entry on initial stack */ + int a_type; /* Entry type. */ + union { + int a_val; /* Integer value. */ + } a_un; +} Elf32_Auxinfo; + + +typedef struct { /* Auxiliary vector entry on initial stack */ + long a_type; /* Entry type. */ + union { + long a_val; /* Integer value. */ + void *a_ptr; /* Address. */ + void (*a_fcn)(void); /* Function pointer (not used). */ + } a_un; +} Elf64_Auxinfo; + +__ElfType(Auxinfo); + +/* Values for a_type. */ +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ +#define AT_NOTELF 10 /* Program is not ELF ?? */ +#define AT_UID 11 /* Real uid. */ +#define AT_EUID 12 /* Effective uid. */ +#define AT_GID 13 /* Real gid. */ +#define AT_EGID 14 /* Effective gid. */ +#define AT_EXECPATH 15 /* Path to the executable. */ +#define AT_CANARY 16 /* Canary for SSP */ +#define AT_CANARYLEN 17 /* Length of the canary. */ +#define AT_OSRELDATE 18 /* OSRELDATE. */ +#define AT_NCPUS 19 /* Number of CPUs. */ +#define AT_PAGESIZES 20 /* Pagesizes. */ +#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */ +#define AT_TIMEKEEP 22 /* Pointer to timehands. */ +#define AT_STACKPROT 23 /* Initial stack protection. */ +#define AT_EHDRFLAGS 24 /* e_flags field from elf hdr */ +#define AT_HWCAP 25 /* CPU feature flags. */ +#define AT_HWCAP2 26 /* CPU feature flags 2. */ + +#define AT_COUNT 27 /* Count of defined aux entry types. */ + +/* + * Relocation types. + */ + +#define R_X86_64_COUNT 24 /* Count of defined relocation types. */ + +/* Define "machine" characteristics */ +#if __ELF_WORD_SIZE == 32 +#define ELF_TARG_CLASS ELFCLASS32 +#else +#define ELF_TARG_CLASS ELFCLASS64 +#endif +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_X86_64 +#define ELF_TARG_VER 1 + +#if __ELF_WORD_SIZE == 32 +#define ET_DYN_LOAD_ADDR 0x01001000 +#else +#define ET_DYN_LOAD_ADDR 0x01021000 +#endif + +#endif /* __i386__, __amd64__ */ + +#endif /* !_MACHINE_ELF_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/endian.h b/lib/libc/include/x86_64-freebsd-any/x86/endian.h new file mode 100644 index 000000000000..9c39f4fddf80 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/endian.h @@ -0,0 +1,133 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1991 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#include +#include + +/* + * Define the order of 32-bit words in 64-bit words. + */ +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 + +/* + * Definitions for byte order, according to byte significance from low + * address to high. + */ +#define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +/* + * Deprecated variants that don't have enough underscores to be useful in more + * strict namespaces. + */ +#if __BSD_VISIBLE +#define LITTLE_ENDIAN _LITTLE_ENDIAN +#define BIG_ENDIAN _BIG_ENDIAN +#define PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER +#endif + +#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8) +#define __bswap32_gen(x) \ + (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16)) +#define __bswap64_gen(x) \ + (((__uint64_t)__bswap32((x) & 0xffffffff) << 32) | __bswap32((x) >> 32)) + +#ifdef __GNUCLIKE_BUILTIN_CONSTANT_P +#define __bswap16(x) \ + ((__uint16_t)(__builtin_constant_p(x) ? \ + __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x))) +#define __bswap32(x) \ + (__builtin_constant_p(x) ? \ + __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x)) +#define __bswap64(x) \ + (__builtin_constant_p(x) ? \ + __bswap64_gen((__uint64_t)(x)) : __bswap64_var(x)) +#else +/* XXX these are broken for use in static initializers. */ +#define __bswap16(x) __bswap16_var(x) +#define __bswap32(x) __bswap32_var(x) +#define __bswap64(x) __bswap64_var(x) +#endif + +/* These are defined as functions to avoid multiple evaluation of x. */ + +static __inline __uint16_t +__bswap16_var(__uint16_t _x) +{ + + return (__bswap16_gen(_x)); +} + +static __inline __uint32_t +__bswap32_var(__uint32_t _x) +{ + +#ifdef __GNUCLIKE_ASM + __asm("bswap %0" : "+r" (_x)); + return (_x); +#else + return (__bswap32_gen(_x)); +#endif +} + +static __inline __uint64_t +__bswap64_var(__uint64_t _x) +{ + +#if defined(__amd64__) && defined(__GNUCLIKE_ASM) + __asm("bswap %0" : "+r" (_x)); + return (_x); +#else + /* + * It is important for the optimizations that the following is not + * really generic, but expands to 2 __bswap32_var()'s. + */ + return (__bswap64_gen(_x)); +#endif +} + +#define __htonl(x) __bswap32(x) +#define __htons(x) __bswap16(x) +#define __ntohl(x) __bswap32(x) +#define __ntohs(x) __bswap16(x) + +#endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/fdt.h b/lib/libc/include/x86_64-freebsd-any/x86/fdt.h new file mode 100644 index 000000000000..6db967d17d73 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/fdt.h @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_FDT_H_ +#define _MACHINE_FDT_H_ + +__BEGIN_DECLS +int x86_init_fdt(void); +__END_DECLS + +#endif /* _MACHINE_FDT_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/float.h b/lib/libc/include/x86_64-freebsd-any/x86/float.h new file mode 100644 index 000000000000..5d8c9737d298 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/float.h @@ -0,0 +1,100 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)float.h 7.1 (Berkeley) 5/8/90 + * $FreeBSD$ + */ + +#ifndef _MACHINE_FLOAT_H_ +#define _MACHINE_FLOAT_H_ 1 + +#include + +__BEGIN_DECLS +extern int __flt_rounds(void); +__END_DECLS + +#define FLT_RADIX 2 /* b */ +#define FLT_ROUNDS __flt_rounds() +#if __ISO_C_VISIBLE >= 1999 +#ifdef __LP64__ +#define FLT_EVAL_METHOD 0 /* no promotions */ +#else +#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ +#endif +#define DECIMAL_DIG 21 /* max precision in decimal digits */ +#endif + +#define FLT_MANT_DIG 24 /* p */ +#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define FLT_MIN_EXP (-125) /* emin */ +#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP 128 /* emax */ +#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ +#if __ISO_C_VISIBLE >= 2011 +#define FLT_TRUE_MIN 1.40129846E-45F /* b**(emin-p) */ +#define FLT_DECIMAL_DIG 9 /* ceil(1+p*log10(b)) */ +#define FLT_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_10_EXP 308 +#if __ISO_C_VISIBLE >= 2011 +#define DBL_TRUE_MIN 4.9406564584124654E-324 +#define DBL_DECIMAL_DIG 17 +#define DBL_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ + +#define LDBL_MANT_DIG 64 +#define LDBL_EPSILON 1.0842021724855044340E-19L +#define LDBL_DIG 18 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.3621031431120935063E-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.1897314953572317650E+4932L +#define LDBL_MAX_10_EXP 4932 +#if __ISO_C_VISIBLE >= 2011 +#define LDBL_TRUE_MIN 3.6451995318824746025E-4951L +#define LDBL_DECIMAL_DIG 21 +#define LDBL_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ + +#endif /* _MACHINE_FLOAT_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/fpu.h b/lib/libc/include/x86_64-freebsd-any/x86/fpu.h new file mode 100644 index 000000000000..313a03ea55c9 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/fpu.h @@ -0,0 +1,217 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +/* + * Floating Point Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _X86_FPU_H_ +#define _X86_FPU_H_ + +/* Environment information of floating point unit. */ +struct env87 { + int32_t en_cw; /* control word (16bits) */ + int32_t en_sw; /* status word (16bits) */ + int32_t en_tw; /* tag word (16bits) */ + int32_t en_fip; /* fp instruction pointer */ + uint16_t en_fcs; /* fp code segment selector */ + uint16_t en_opcode; /* opcode last executed (11 bits) */ + int32_t en_foo; /* fp operand offset */ + int32_t en_fos; /* fp operand segment selector */ +}; + +/* Contents of each x87 floating point accumulator. */ +struct fpacc87 { + uint8_t fp_bytes[10]; +}; + +/* Floating point context. (i386 fnsave/frstor) */ +struct save87 { + struct env87 sv_env; /* floating point control/status */ + struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ + uint8_t sv_pad0[4]; /* saved status word (now unused) */ + uint8_t sv_pad[64]; +}; + +/* Contents of each SSE extended accumulator. */ +struct xmmacc { + uint8_t xmm_bytes[16]; +}; + +/* Contents of the upper 16 bytes of each AVX extended accumulator. */ +struct ymmacc { + uint8_t ymm_bytes[16]; +}; + +/* Rename structs below depending on machine architecture. */ +#ifdef __i386__ +#define __envxmm32 envxmm +#else +#define __envxmm32 envxmm32 +#define __envxmm64 envxmm +#endif + +struct __envxmm32 { + uint16_t en_cw; /* control word (16bits) */ + uint16_t en_sw; /* status word (16bits) */ + uint16_t en_tw; /* tag word (16bits) */ + uint16_t en_opcode; /* opcode last executed (11 bits) */ + uint32_t en_fip; /* fp instruction pointer */ + uint16_t en_fcs; /* fp code segment selector */ + uint16_t en_pad0; /* padding */ + uint32_t en_foo; /* fp operand offset */ + uint16_t en_fos; /* fp operand segment selector */ + uint16_t en_pad1; /* padding */ + uint32_t en_mxcsr; /* SSE control/status register */ + uint32_t en_mxcsr_mask; /* valid bits in mxcsr */ +}; + +struct __envxmm64 { + uint16_t en_cw; /* control word (16bits) */ + uint16_t en_sw; /* status word (16bits) */ + uint8_t en_tw; /* tag word (8bits) */ + uint8_t en_zero; + uint16_t en_opcode; /* opcode last executed (11 bits ) */ + uint64_t en_rip; /* fp instruction pointer */ + uint64_t en_rdp; /* fp operand pointer */ + uint32_t en_mxcsr; /* SSE control/status register */ + uint32_t en_mxcsr_mask; /* valid bits in mxcsr */ +}; + +/* Floating point context. (i386 fxsave/fxrstor) */ +struct savexmm { + struct __envxmm32 sv_env; + struct { + struct fpacc87 fp_acc; + uint8_t fp_pad[6]; /* padding */ + } sv_fp[8]; + struct xmmacc sv_xmm[8]; + uint8_t sv_pad[224]; +} __aligned(16); + +#ifdef __i386__ +union savefpu { + struct save87 sv_87; + struct savexmm sv_xmm; +}; +#else +/* Floating point context. (amd64 fxsave/fxrstor) */ +struct savefpu { + struct __envxmm64 sv_env; + struct { + struct fpacc87 fp_acc; + uint8_t fp_pad[6]; /* padding */ + } sv_fp[8]; + struct xmmacc sv_xmm[16]; + uint8_t sv_pad[96]; +} __aligned(16); +#endif + +struct xstate_hdr { + uint64_t xstate_bv; + uint64_t xstate_xcomp_bv; + uint8_t xstate_rsrv0[8]; + uint8_t xstate_rsrv[40]; +}; +#define XSTATE_XCOMP_BV_COMPACT (1ULL << 63) + +struct savexmm_xstate { + struct xstate_hdr sx_hd; + struct ymmacc sx_ymm[16]; +}; + +struct savexmm_ymm { + struct __envxmm32 sv_env; + struct { + struct fpacc87 fp_acc; + int8_t fp_pad[6]; /* padding */ + } sv_fp[8]; + struct xmmacc sv_xmm[16]; + uint8_t sv_pad[96]; + struct savexmm_xstate sv_xstate; +} __aligned(64); + +struct savefpu_xstate { + struct xstate_hdr sx_hd; + struct ymmacc sx_ymm[16]; +}; + +struct savefpu_ymm { + struct __envxmm64 sv_env; + struct { + struct fpacc87 fp_acc; + int8_t fp_pad[6]; /* padding */ + } sv_fp[8]; + struct xmmacc sv_xmm[16]; + uint8_t sv_pad[96]; + struct savefpu_xstate sv_xstate; +} __aligned(64); + +#undef __envxmm32 +#undef __envxmm64 + +/* + * The hardware default control word for i387's and later coprocessors is + * 0x37F, giving: + * + * round to nearest + * 64-bit precision + * all exceptions masked. + * + * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc + * because of the difference between memory and fpu register stack arguments. + * If its using an intermediate fpu register, it has 80/64 bits to work + * with. If it uses memory, it has 64/53 bits to work with. However, + * gcc is aware of this and goes to a fair bit of trouble to make the + * best use of it. + * + * This is mostly academic for AMD64, because the ABI prefers the use + * SSE2 based math. For FreeBSD/amd64, we go with the default settings. + */ +#define __INITIAL_FPUCW__ 0x037F +#define __INITIAL_FPUCW_I386__ 0x127F +#define __INITIAL_NPXCW__ __INITIAL_FPUCW_I386__ +#define __INITIAL_MXCSR__ 0x1F80 +#define __INITIAL_MXCSR_MASK__ 0xFFBF + +/* + * The current value of %xcr0 is saved in the sv_pad[] field of the FPU + * state in the NT_X86_XSTATE note in core dumps. This offset is chosen + * to match the offset used by NT_X86_XSTATE in other systems. + */ +#define X86_XSTATE_XCR0_OFFSET 464 + +#endif /* !_X86_FPU_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/frame.h b/lib/libc/include/x86_64-freebsd-any/x86/frame.h new file mode 100644 index 000000000000..2ea09dfdc35f --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/frame.h @@ -0,0 +1,160 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ 1 + +/* + * System stack frames. + */ + +#ifdef __i386__ +/* + * Exception/Trap Stack Frame + */ + +struct trapframe { + int tf_fs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_ebp; + int tf_isp; + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_err; + int tf_eip; + int tf_cs; + int tf_eflags; + /* below only when crossing rings (user to kernel) */ + int tf_esp; + int tf_ss; +}; + +/* Superset of trap frame, for traps from virtual-8086 mode */ + +struct trapframe_vm86 { + int tf_fs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_ebp; + int tf_isp; + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_err; + int tf_eip; + int tf_cs; + int tf_eflags; + /* below only when crossing rings (user (including vm86) to kernel) */ + int tf_esp; + int tf_ss; + /* below only when crossing from vm86 mode to kernel */ + int tf_vm86_es; + int tf_vm86_ds; + int tf_vm86_fs; + int tf_vm86_gs; +}; + +/* + * This alias for the MI TRAPF_USERMODE() should be used when we don't + * care about user mode itself, but need to know if a frame has stack + * registers. The difference is only logical, but on i386 the logic + * for using TRAPF_USERMODE() is complicated by sometimes treating vm86 + * bioscall mode (which is a special ring 3 user mode) as kernel mode. + */ +#define TF_HAS_STACKREGS(tf) TRAPF_USERMODE(tf) +#endif /* __i386__ */ + +#ifdef __amd64__ +/* + * Exception/Trap Stack Frame + * + * The ordering of this is specifically so that we can take first 6 + * the syscall arguments directly from the beginning of the frame. + */ + +struct trapframe { + register_t tf_rdi; + register_t tf_rsi; + register_t tf_rdx; + register_t tf_rcx; + register_t tf_r8; + register_t tf_r9; + register_t tf_rax; + register_t tf_rbx; + register_t tf_rbp; + register_t tf_r10; + register_t tf_r11; + register_t tf_r12; + register_t tf_r13; + register_t tf_r14; + register_t tf_r15; + uint32_t tf_trapno; + uint16_t tf_fs; + uint16_t tf_gs; + register_t tf_addr; + uint32_t tf_flags; + uint16_t tf_es; + uint16_t tf_ds; + /* below portion defined in hardware */ + register_t tf_err; + register_t tf_rip; + register_t tf_cs; + register_t tf_rflags; + /* the amd64 frame always has the stack registers */ + register_t tf_rsp; + register_t tf_ss; +}; + +#define TF_HASSEGS 0x1 +#define TF_HASBASES 0x2 +#define TF_HASFPXSTATE 0x4 +#endif /* __amd64__ */ + +#endif /* _MACHINE_FRAME_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/ifunc.h b/lib/libc/include/x86_64-freebsd-any/x86/ifunc.h new file mode 100644 index 000000000000..38c82570770e --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/ifunc.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2015-2018 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_IFUNC_H +#define __X86_IFUNC_H + +#define DEFINE_IFUNC(qual, ret_type, name, args, resolver_qual) \ + resolver_qual ret_type (*name##_resolver(void))args __used; \ + qual ret_type name args __attribute__((ifunc(#name "_resolver"))); \ + resolver_qual ret_type (*name##_resolver(void))args + +#define DEFINE_UIFUNC(qual, ret_type, name, args, resolver_qual) \ + resolver_qual ret_type (*name##_resolver(uint32_t, uint32_t, \ + uint32_t, uint32_t))args __used; \ + qual ret_type name args __attribute__((ifunc(#name "_resolver"))); \ + resolver_qual ret_type (*name##_resolver( \ + uint32_t cpu_feature __unused, \ + uint32_t cpu_feature2 __unused, \ + uint32_t cpu_stdext_feature __unused, \ + uint32_t cpu_stdext_feature2 __unused))args + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/init.h b/lib/libc/include/x86_64-freebsd-any/x86/init.h new file mode 100644 index 000000000000..880cabaa9496 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/init.h @@ -0,0 +1,60 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Roger Pau Monné + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_INIT_H__ +#define __X86_INIT_H__ +/* + * Struct containing pointers to init functions whose + * implementation is run time selectable. Selection can be made, + * for example, based on detection of a BIOS variant or + * hypervisor environment. + */ +struct init_ops { + caddr_t (*parse_preload_data)(u_int64_t); + void (*early_clock_source_init)(void); + void (*early_delay)(int); + void (*parse_memmap)(caddr_t, vm_paddr_t *, int *); + void (*mp_bootaddress)(vm_paddr_t *, unsigned int *); + int (*start_all_aps)(void); + void (*msi_init)(void); +}; + +extern struct init_ops init_ops; + +/* Knob to disable acpi_cpu devices */ +extern bool acpi_cpu_disabled; + +/* Knob to disable acpi_hpet device */ +extern bool acpi_hpet_disabled; + +/* Knob to disable acpi_timer device */ +extern bool acpi_timer_disabled; + +#endif /* __X86_INIT_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/intr_machdep.h b/lib/libc/include/x86_64-freebsd-any/x86/intr_machdep.h new file mode 100644 index 000000000000..4818e9329df6 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/intr_machdep.h @@ -0,0 +1,180 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2003 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_INTR_MACHDEP_H__ +#define __X86_INTR_MACHDEP_H__ + +#ifdef _KERNEL + +/* + * Values used in determining the allocation of IRQ values among + * different types of I/O interrupts. These values are used as + * indices into a interrupt source array to map I/O interrupts to a + * device interrupt source whether it be a pin on an interrupt + * controller or an MSI interrupt. The 16 ISA IRQs are assigned fixed + * IDT vectors, but all other device interrupts allocate IDT vectors + * on demand. Currently we have 191 IDT vectors available for device + * interrupts on each CPU. On many systems with I/O APICs, a lot of + * the IRQs are not used, so the total number of IRQ values reserved + * can exceed the number of available IDT slots. + * + * The first 16 IRQs (0 - 15) are reserved for ISA IRQs. Interrupt + * pins on I/O APICs for non-ISA interrupts use IRQ values starting at + * IRQ 17. This layout matches the GSI numbering used by ACPI so that + * IRQ values returned by ACPI methods such as _CRS can be used + * directly by the ACPI bus driver. + * + * MSI interrupts allocate a block of interrupts starting at either + * the end of the I/O APIC range or 256, whichever is higher. When + * running under the Xen Hypervisor, an additional range of IRQ values + * are available for binding to event channel events. We use 256 as + * the minimum IRQ value for MSI interrupts to attempt to leave 255 + * unused since 255 is used in PCI to indicate an invalid INTx IRQ. + */ +#define MINIMUM_MSI_INT 256 + +extern u_int first_msi_irq; +extern u_int num_io_irqs; +extern u_int num_msi_irqs; + +/* + * Default base address for MSI messages on x86 platforms. + */ +#define MSI_INTEL_ADDR_BASE 0xfee00000 + +#ifndef LOCORE + +typedef void inthand_t(void); + +#define IDTVEC(name) __CONCAT(X,name) + +struct intsrc; + +/* + * Methods that a PIC provides to mask/unmask a given interrupt source, + * "turn on" the interrupt on the CPU side by setting up an IDT entry, and + * return the vector associated with this source. + */ +struct pic { + void (*pic_register_sources)(struct pic *); + void (*pic_enable_source)(struct intsrc *); + void (*pic_disable_source)(struct intsrc *, int); + void (*pic_eoi_source)(struct intsrc *); + void (*pic_enable_intr)(struct intsrc *); + void (*pic_disable_intr)(struct intsrc *); + int (*pic_vector)(struct intsrc *); + int (*pic_source_pending)(struct intsrc *); + void (*pic_suspend)(struct pic *); + void (*pic_resume)(struct pic *, bool suspend_cancelled); + int (*pic_config_intr)(struct intsrc *, enum intr_trigger, + enum intr_polarity); + int (*pic_assign_cpu)(struct intsrc *, u_int apic_id); + void (*pic_reprogram_pin)(struct intsrc *); + TAILQ_ENTRY(pic) pics; +}; + +/* Flags for pic_disable_source() */ +enum { + PIC_EOI, + PIC_NO_EOI, +}; + +/* + * An interrupt source. The upper-layer code uses the PIC methods to + * control a given source. The lower-layer PIC drivers can store additional + * private data in a given interrupt source such as an interrupt pin number + * or an I/O APIC pointer. + */ +struct intsrc { + struct pic *is_pic; + struct intr_event *is_event; + u_long *is_count; + u_long *is_straycount; + u_int is_index; + u_int is_handlers; + u_int is_domain; + u_int is_cpu; +}; + +struct trapframe; + +#ifdef SMP +extern cpuset_t intr_cpus; +#endif +extern struct mtx icu_lock; +extern int elcr_found; +#ifdef SMP +extern int msix_disable_migration; +#endif + +#ifndef DEV_ATPIC +void atpic_reset(void); +#endif +/* XXX: The elcr_* prototypes probably belong somewhere else. */ +int elcr_probe(void); +enum intr_trigger elcr_read_trigger(u_int irq); +void elcr_resume(void); +void elcr_write_trigger(u_int irq, enum intr_trigger trigger); +#ifdef SMP +void intr_add_cpu(u_int cpu); +#endif +int intr_add_handler(const char *name, int vector, driver_filter_t filter, + driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep, + int domain); +#ifdef SMP +int intr_bind(u_int vector, u_char cpu); +#endif +int intr_config_intr(int vector, enum intr_trigger trig, + enum intr_polarity pol); +int intr_describe(u_int vector, void *ih, const char *descr); +void intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame); +u_int intr_next_cpu(int domain); +struct intsrc *intr_lookup_source(int vector); +int intr_register_pic(struct pic *pic); +int intr_register_source(struct intsrc *isrc); +int intr_remove_handler(void *cookie); +void intr_resume(bool suspend_cancelled); +void intr_suspend(void); +void intr_reprogram(void); +void intrcnt_add(const char *name, u_long **countp); +void nexus_add_irq(u_long irq); +int msi_alloc(device_t dev, int count, int maxcount, int *irqs); +void msi_init(void); +int msi_map(int irq, uint64_t *addr, uint32_t *data); +int msi_release(int *irqs, int count); +int msix_alloc(device_t dev, int *irq); +int msix_release(int irq); +#ifdef XENHVM +void xen_intr_alloc_irqs(void); +#endif + +#endif /* !LOCORE */ +#endif /* _KERNEL */ +#endif /* !__X86_INTR_MACHDEP_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/legacyvar.h b/lib/libc/include/x86_64-freebsd-any/x86/legacyvar.h new file mode 100644 index 000000000000..f6e5814a3f97 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/legacyvar.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2000 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_LEGACYVAR_H_ +#define _X86_LEGACYVAR_H_ + +enum legacy_device_ivars { + LEGACY_IVAR_PCIDOMAIN, + LEGACY_IVAR_PCIBUS, + LEGACY_IVAR_PCISLOT, + LEGACY_IVAR_PCIFUNC +}; + +#define LEGACY_ACCESSOR(var, ivar, type) \ + __BUS_ACCESSOR(legacy, var, LEGACY, ivar, type) + +LEGACY_ACCESSOR(pcidomain, PCIDOMAIN, uint32_t) +LEGACY_ACCESSOR(pcibus, PCIBUS, uint32_t) +LEGACY_ACCESSOR(pcislot, PCISLOT, int) +LEGACY_ACCESSOR(pcifunc, PCIFUNC, int) + +#undef LEGACY_ACCESSOR + +int legacy_pcib_maxslots(device_t dev); +uint32_t legacy_pcib_read_config(device_t dev, u_int bus, u_int slot, + u_int func, u_int reg, int bytes); +int legacy_pcib_read_ivar(device_t dev, device_t child, int which, + uintptr_t *result); +void legacy_pcib_write_config(device_t dev, u_int bus, u_int slot, + u_int func, u_int reg, uint32_t data, int bytes); +int legacy_pcib_write_ivar(device_t dev, device_t child, int which, + uintptr_t value); +struct resource *legacy_pcib_alloc_resource(device_t dev, device_t child, + int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, + u_int flags); +int legacy_pcib_adjust_resource(device_t dev, device_t child, int type, + struct resource *r, rman_res_t start, rman_res_t end); +int legacy_pcib_release_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); +int legacy_pcib_alloc_msi(device_t pcib, device_t dev, int count, + int maxcount, int *irqs); +int legacy_pcib_alloc_msix(device_t pcib, device_t dev, int *irq); +int legacy_pcib_map_msi(device_t pcib, device_t dev, int irq, + uint64_t *addr, uint32_t *data); + +#endif /* !_X86_LEGACYVAR_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/mca.h b/lib/libc/include/x86_64-freebsd-any/x86/mca.h new file mode 100644 index 000000000000..9e582d413885 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/mca.h @@ -0,0 +1,58 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2009 Hudson River Trading LLC + * Written by: John H. Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __X86_MCA_H__ +#define __X86_MCA_H__ + +struct mca_record { + uint64_t mr_status; + uint64_t mr_addr; + uint64_t mr_misc; + uint64_t mr_tsc; + int mr_apic_id; + int mr_bank; + uint64_t mr_mcg_cap; + uint64_t mr_mcg_status; + int mr_cpu_id; + int mr_cpu_vendor_id; + int mr_cpu; +}; + +#ifdef _KERNEL + +void cmc_intr(void); +void mca_init(void); +void mca_intr(void); +void mca_resume(void); + +#endif + +#endif /* !__X86_MCA_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/metadata.h b/lib/libc/include/x86_64-freebsd-any/x86/metadata.h new file mode 100644 index 000000000000..e13eba0c7e48 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/metadata.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2003 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_METADATA_H_ +#define _MACHINE_METADATA_H_ + +#define MODINFOMD_SMAP 0x1001 +#define MODINFOMD_SMAP_XATTR 0x1002 +#define MODINFOMD_DTBP 0x1003 +#define MODINFOMD_EFI_MAP 0x1004 +#define MODINFOMD_EFI_FB 0x1005 +#define MODINFOMD_MODULEP 0x1006 + +struct efi_map_header { + uint64_t memory_size; + uint64_t descriptor_size; + uint32_t descriptor_version; +}; + +struct efi_fb { + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_stride; + uint32_t fb_mask_red; + uint32_t fb_mask_green; + uint32_t fb_mask_blue; + uint32_t fb_mask_reserved; +}; + +#endif /* !_MACHINE_METADATA_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/mptable.h b/lib/libc/include/x86_64-freebsd-any/x86/mptable.h new file mode 100644 index 000000000000..93b87181b15a --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/mptable.h @@ -0,0 +1,206 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1996, by Steve Passe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __MACHINE_MPTABLE_H__ +#define __MACHINE_MPTABLE_H__ + +enum busTypes { + NOBUS = 0, + CBUS = 1, + CBUSII = 2, + EISA = 3, + ISA = 6, + MCA = 9, + PCI = 13, + XPRESS = 18, + MAX_BUSTYPE = 18, + UNKNOWN_BUSTYPE = 0xff +}; + +/* MP Floating Pointer Structure */ +typedef struct MPFPS { + uint8_t signature[4]; + uint32_t pap; + uint8_t length; + uint8_t spec_rev; + uint8_t checksum; + uint8_t config_type; + uint8_t mpfb2; + uint8_t mpfb3; + uint8_t mpfb4; + uint8_t mpfb5; +} __packed *mpfps_t; + +#define MPFB2_IMCR_PRESENT 0x80 +#define MPFB2_MUL_CLK_SRCS 0x40 + +/* MP Configuration Table Header */ +typedef struct MPCTH { + uint8_t signature[4]; + uint16_t base_table_length; + uint8_t spec_rev; + uint8_t checksum; + uint8_t oem_id[8]; + uint8_t product_id[12]; + uint32_t oem_table_pointer; + uint16_t oem_table_size; + uint16_t entry_count; + uint32_t apic_address; + uint16_t extended_table_length; + uint8_t extended_table_checksum; + uint8_t reserved; +} __packed *mpcth_t; + +/* Base table entries */ + +#define MPCT_ENTRY_PROCESSOR 0 +#define MPCT_ENTRY_BUS 1 +#define MPCT_ENTRY_IOAPIC 2 +#define MPCT_ENTRY_INT 3 +#define MPCT_ENTRY_LOCAL_INT 4 + +typedef struct PROCENTRY { + uint8_t type; + uint8_t apic_id; + uint8_t apic_version; + uint8_t cpu_flags; + uint32_t cpu_signature; + uint32_t feature_flags; + uint32_t reserved1; + uint32_t reserved2; +} __packed *proc_entry_ptr; + +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + +typedef struct BUSENTRY { + uint8_t type; + uint8_t bus_id; + uint8_t bus_type[6]; +} __packed *bus_entry_ptr; + +typedef struct IOAPICENTRY { + uint8_t type; + uint8_t apic_id; + uint8_t apic_version; + uint8_t apic_flags; + uint32_t apic_address; +} __packed *io_apic_entry_ptr; + +#define IOAPICENTRY_FLAG_EN 0x01 + +typedef struct INTENTRY { + uint8_t type; + uint8_t int_type; + uint16_t int_flags; + uint8_t src_bus_id; + uint8_t src_bus_irq; + uint8_t dst_apic_id; + uint8_t dst_apic_int; +} __packed *int_entry_ptr; + +#define INTENTRY_TYPE_INT 0 +#define INTENTRY_TYPE_NMI 1 +#define INTENTRY_TYPE_SMI 2 +#define INTENTRY_TYPE_EXTINT 3 + +#define INTENTRY_FLAGS_POLARITY 0x3 +#define INTENTRY_FLAGS_POLARITY_CONFORM 0x0 +#define INTENTRY_FLAGS_POLARITY_ACTIVEHI 0x1 +#define INTENTRY_FLAGS_POLARITY_ACTIVELO 0x3 +#define INTENTRY_FLAGS_TRIGGER 0xc +#define INTENTRY_FLAGS_TRIGGER_CONFORM 0x0 +#define INTENTRY_FLAGS_TRIGGER_EDGE 0x4 +#define INTENTRY_FLAGS_TRIGGER_LEVEL 0xc + +/* Extended table entries */ + +typedef struct EXTENTRY { + uint8_t type; + uint8_t length; +} __packed *ext_entry_ptr; + +#define MPCT_EXTENTRY_SAS 0x80 +#define MPCT_EXTENTRY_BHD 0x81 +#define MPCT_EXTENTRY_CBASM 0x82 + +typedef struct SASENTRY { + uint8_t type; + uint8_t length; + uint8_t bus_id; + uint8_t address_type; + uint64_t address_base; + uint64_t address_length; +} __packed *sas_entry_ptr; + +#define SASENTRY_TYPE_IO 0 +#define SASENTRY_TYPE_MEMORY 1 +#define SASENTRY_TYPE_PREFETCH 2 + +typedef struct BHDENTRY { + uint8_t type; + uint8_t length; + uint8_t bus_id; + uint8_t bus_info; + uint8_t parent_bus; + uint8_t reserved[3]; +} __packed *bhd_entry_ptr; + +#define BHDENTRY_INFO_SUBTRACTIVE_DECODE 0x1 + +typedef struct CBASMENTRY { + uint8_t type; + uint8_t length; + uint8_t bus_id; + uint8_t address_mod; + uint32_t predefined_range; +} __packed *cbasm_entry_ptr; + +#define CBASMENTRY_ADDRESS_MOD_ADD 0x0 +#define CBASMENTRY_ADDRESS_MOD_SUBTRACT 0x1 + +#define CBASMENTRY_RANGE_ISA_IO 0 +#define CBASMENTRY_RANGE_VGA_IO 1 + +#ifdef _KERNEL +struct mptable_hostb_softc { +#ifdef NEW_PCIB + struct pcib_host_resources sc_host_res; + int sc_decodes_vga_io; + int sc_decodes_isa_io; +#endif +}; + +#ifdef NEW_PCIB +void mptable_pci_host_res_init(device_t pcib); +#endif +int mptable_pci_probe_table(int bus); +int mptable_pci_route_interrupt(device_t pcib, device_t dev, int pin); +#endif +#endif /* !__MACHINE_MPTABLE_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/ofw_machdep.h b/lib/libc/include/x86_64-freebsd-any/x86/ofw_machdep.h new file mode 100644 index 000000000000..69e1b98e1de7 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/ofw_machdep.h @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_OFW_MACHDEP_H_ +#define _MACHINE_OFW_MACHDEP_H_ + +#include +#include + +typedef uint32_t cell_t; + +struct mem_region { + vm_offset_t mr_start; + vm_size_t mr_size; +}; + +#endif /* _MACHINE_OFW_MACHDEP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/pci_cfgreg.h b/lib/libc/include/x86_64-freebsd-any/x86/pci_cfgreg.h new file mode 100644 index 000000000000..85d6485c47ed --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/pci_cfgreg.h @@ -0,0 +1,71 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1997, Stefan Esser + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef __X86_PCI_CFGREG_H__ +#define __X86_PCI_CFGREG_H__ + +#define CONF1_ADDR_PORT 0x0cf8 +#define CONF1_DATA_PORT 0x0cfc + +#define CONF1_ENABLE 0x80000000ul +#define CONF1_ENABLE_CHK 0x80000000ul +#define CONF1_ENABLE_MSK 0x7f000000ul +#define CONF1_ENABLE_CHK1 0xff000001ul +#define CONF1_ENABLE_MSK1 0x80000001ul +#define CONF1_ENABLE_RES1 0x80000000ul + +#define CONF2_ENABLE_PORT 0x0cf8 +#define CONF2_FORWARD_PORT 0x0cfa + +#define CONF2_ENABLE_CHK 0x0e +#define CONF2_ENABLE_RES 0x0e + +enum { + CFGMECH_NONE = 0, + CFGMECH_1, + CFGMECH_2, + CFGMECH_PCIE, +}; + +extern int cfgmech; + +rman_res_t hostb_alloc_start(int type, rman_res_t start, rman_res_t end, rman_res_t count); +int pcie_cfgregopen(uint64_t base, uint8_t minbus, uint8_t maxbus); +int pci_cfgregopen(void); +u_int32_t pci_cfgregread(int bus, int slot, int func, int reg, int bytes); +void pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes); +#ifdef __HAVE_PIR +void pci_pir_open(void); +int pci_pir_probe(int bus, int require_parse); +int pci_pir_route_interrupt(int bus, int device, int func, int pin); +#endif + +#endif /* !__X86_PCI_CFGREG_H__ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/procctl.h b/lib/libc/include/x86_64-freebsd-any/x86/procctl.h new file mode 100644 index 000000000000..8cb792189020 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/procctl.h @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 The FreeBSD Foundation + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_PROCCTL_H +#define _X86_PROCCTL_H + +#define PROC_KPTI_CTL (PROC_PROCCTL_MD_MIN + 0) +#define PROC_KPTI_STATUS (PROC_PROCCTL_MD_MIN + 1) + +#define PROC_KPTI_CTL_ENABLE_ON_EXEC 1 +#define PROC_KPTI_CTL_DISABLE_ON_EXEC 2 +#define PROC_KPTI_STATUS_ACTIVE 0x80000000 + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/psl.h b/lib/libc/include/x86_64-freebsd-any/x86/psl.h new file mode 100644 index 000000000000..c178821cc9a0 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/psl.h @@ -0,0 +1,94 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)psl.h 5.2 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry bit */ +#define PSL_PF 0x00000004 /* parity bit */ +#define PSL_AF 0x00000010 /* bcd carry bit */ +#define PSL_Z 0x00000040 /* zero bit */ +#define PSL_N 0x00000080 /* negative bit */ +#define PSL_T 0x00000100 /* trace enable bit */ +#define PSL_I 0x00000200 /* interrupt enable bit */ +#define PSL_D 0x00000400 /* string instruction direction bit */ +#define PSL_V 0x00000800 /* overflow bit */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task bit */ +#define PSL_RF 0x00010000 /* resume flag bit */ +#define PSL_VM 0x00020000 /* virtual 8086 mode bit */ +#define PSL_AC 0x00040000 /* alignment checking */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending */ +#define PSL_ID 0x00200000 /* identification bit */ + +/* + * The i486 manual says that we are not supposed to change reserved flags, + * but this is too much trouble since the reserved flags depend on the cpu + * and setting them to their historical values works in practice. + */ +#define PSL_RESERVED_DEFAULT 0x00000002 + +/* + * Initial flags for kernel and user mode. The kernel later inherits + * PSL_I and some other flags from user mode. + */ +#define PSL_KERNEL PSL_RESERVED_DEFAULT +#define PSL_USER (PSL_RESERVED_DEFAULT | PSL_I) + +/* + * Bits that can be changed in user mode on 486's. We allow these bits + * to be changed using ptrace(), sigreturn() and procfs. Setting PS_NT + * is undesirable but it may as well be allowed since users can inflict + * it on the kernel directly. Changes to PSL_AC are silently ignored on + * 386's. + * + * Users are allowed to change the privileged flag PSL_RF. The cpu sets PSL_RF + * in tf_eflags for faults. Debuggers should sometimes set it there too. + * tf_eflags is kept in the signal context during signal handling and there is + * no other place to remember it, so the PSL_RF bit may be corrupted by the + * signal handler without us knowing. Corruption of the PSL_RF bit at worst + * causes one more or one less debugger trap, so allowing it is fairly + * harmless. + */ +#define PSL_USERCHANGE (PSL_C | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_T \ + | PSL_D | PSL_V | PSL_NT | PSL_RF | PSL_AC | PSL_ID) + +#endif /* !_MACHINE_PSL_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/ptrace.h b/lib/libc/include/x86_64-freebsd-any/x86/ptrace.h new file mode 100644 index 000000000000..be02dff4daf5 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/ptrace.h @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ptrace.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _MACHINE_PTRACE_H_ +#define _MACHINE_PTRACE_H_ + +#define __HAVE_PTRACE_MACHDEP + +/* + * On amd64 (PT_FIRSTMACH + 0) and (PT_FIRSTMACH + 1) are old values for + * PT_GETXSTATE_OLD and PT_SETXSTATE_OLD. They should not be (re)used. + */ + +#ifdef __i386__ +#define PT_GETXMMREGS (PT_FIRSTMACH + 0) +#define PT_SETXMMREGS (PT_FIRSTMACH + 1) +#endif +#ifdef _KERNEL +#define PT_GETXSTATE_OLD (PT_FIRSTMACH + 2) +#define PT_SETXSTATE_OLD (PT_FIRSTMACH + 3) +#endif +#define PT_GETXSTATE_INFO (PT_FIRSTMACH + 4) +#define PT_GETXSTATE (PT_FIRSTMACH + 5) +#define PT_SETXSTATE (PT_FIRSTMACH + 6) +#define PT_GETFSBASE (PT_FIRSTMACH + 7) +#define PT_SETFSBASE (PT_FIRSTMACH + 8) +#define PT_GETGSBASE (PT_FIRSTMACH + 9) +#define PT_SETGSBASE (PT_FIRSTMACH + 10) + +/* Argument structure for PT_GETXSTATE_INFO. */ +struct ptrace_xstate_info { + uint64_t xsave_mask; + uint32_t xsave_len; +}; + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/pvclock.h b/lib/libc/include/x86_64-freebsd-any/x86/pvclock.h new file mode 100644 index 000000000000..402ffed810ca --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/pvclock.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2014, Bryan Venteicher + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef X86_PVCLOCK +#define X86_PVCLOCK + +struct pvclock_vcpu_time_info { + uint32_t version; + uint32_t pad0; + uint64_t tsc_timestamp; + uint64_t system_time; + uint32_t tsc_to_system_mul; + int8_t tsc_shift; + uint8_t flags; + uint8_t pad[2]; +}; + +#define PVCLOCK_FLAG_TSC_STABLE 0x01 +#define PVCLOCK_FLAG_GUEST_PASUED 0x02 + +struct pvclock_wall_clock { + uint32_t version; + uint32_t sec; + uint32_t nsec; +}; + +void pvclock_resume(void); +uint64_t pvclock_get_last_cycles(void); +uint64_t pvclock_tsc_freq(struct pvclock_vcpu_time_info *ti); +uint64_t pvclock_get_timecount(struct pvclock_vcpu_time_info *ti); +void pvclock_get_wallclock(struct pvclock_wall_clock *wc, + struct timespec *ts); + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/reg.h b/lib/libc/include/x86_64-freebsd-any/x86/reg.h new file mode 100644 index 000000000000..f82848192e67 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/reg.h @@ -0,0 +1,269 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm. + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)reg.h 5.5 (Berkeley) 1/18/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +#include + +#ifdef __i386__ +/* + * Indices for registers in `struct trapframe' and `struct regs'. + * + * This interface is deprecated. In the kernel, it is only used in FPU + * emulators to convert from register numbers encoded in instructions to + * register values. Everything else just accesses the relevant struct + * members. In userland, debuggers tend to abuse this interface since + * they don't understand that `struct regs' is a struct. I hope they have + * stopped accessing the registers in the trap frame via PT_{READ,WRITE}_U + * and we can stop supporting the user area soon. + */ +#define tFS (0) +#define tES (1) +#define tDS (2) +#define tEDI (3) +#define tESI (4) +#define tEBP (5) +#define tISP (6) +#define tEBX (7) +#define tEDX (8) +#define tECX (9) +#define tEAX (10) +#define tERR (12) +#define tEIP (13) +#define tCS (14) +#define tEFLAGS (15) +#define tESP (16) +#define tSS (17) + +/* + * Indices for registers in `struct regs' only. + * + * Some registers live in the pcb and are only in an "array" with the + * other registers in application interfaces that copy all the registers + * to or from a `struct regs'. + */ +#define tGS (18) +#endif /* __i386__ */ + +/* Rename the structs below depending on the machine architecture. */ +#ifdef __i386__ +#define __reg32 reg +#define __fpreg32 fpreg +#define __dbreg32 dbreg +#else +#define __reg32 reg32 +#define __reg64 reg +#define __fpreg32 fpreg32 +#define __fpreg64 fpreg +#define __dbreg32 dbreg32 +#define __dbreg64 dbreg +#define __HAVE_REG32 +#endif + +/* + * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS. + */ +struct __reg32 { + __uint32_t r_fs; + __uint32_t r_es; + __uint32_t r_ds; + __uint32_t r_edi; + __uint32_t r_esi; + __uint32_t r_ebp; + __uint32_t r_isp; + __uint32_t r_ebx; + __uint32_t r_edx; + __uint32_t r_ecx; + __uint32_t r_eax; + __uint32_t r_trapno; + __uint32_t r_err; + __uint32_t r_eip; + __uint32_t r_cs; + __uint32_t r_eflags; + __uint32_t r_esp; + __uint32_t r_ss; + __uint32_t r_gs; +}; + +struct __reg64 { + __int64_t r_r15; + __int64_t r_r14; + __int64_t r_r13; + __int64_t r_r12; + __int64_t r_r11; + __int64_t r_r10; + __int64_t r_r9; + __int64_t r_r8; + __int64_t r_rdi; + __int64_t r_rsi; + __int64_t r_rbp; + __int64_t r_rbx; + __int64_t r_rdx; + __int64_t r_rcx; + __int64_t r_rax; + __uint32_t r_trapno; + __uint16_t r_fs; + __uint16_t r_gs; + __uint32_t r_err; + __uint16_t r_es; + __uint16_t r_ds; + __int64_t r_rip; + __int64_t r_cs; + __int64_t r_rflags; + __int64_t r_rsp; + __int64_t r_ss; +}; + +/* + * Register set accessible via /proc/$pid/fpregs. + * + * XXX should get struct from fpu.h. Here we give a slightly + * simplified struct. This may be too much detail. Perhaps + * an array of unsigned longs is best. + */ +struct __fpreg32 { + __uint32_t fpr_env[7]; + __uint8_t fpr_acc[8][10]; + __uint32_t fpr_ex_sw; + __uint8_t fpr_pad[64]; +}; + +struct __fpreg64 { + __uint64_t fpr_env[4]; + __uint8_t fpr_acc[8][16]; + __uint8_t fpr_xacc[16][16]; + __uint64_t fpr_spare[12]; +}; + +/* + * Register set accessible via PT_GETXMMREGS (i386). + */ +struct xmmreg { + /* + * XXX should get struct from npx.h. Here we give a slightly + * simplified struct. This may be too much detail. Perhaps + * an array of unsigned longs is best. + */ + __uint32_t xmm_env[8]; + __uint8_t xmm_acc[8][16]; + __uint8_t xmm_reg[8][16]; + __uint8_t xmm_pad[224]; +}; + +/* + * Register set accessible via /proc/$pid/dbregs. + */ +struct __dbreg32 { + __uint32_t dr[8]; /* debug registers */ + /* Index 0-3: debug address registers */ + /* Index 4-5: reserved */ + /* Index 6: debug status */ + /* Index 7: debug control */ +}; + +struct __dbreg64 { + __uint64_t dr[16]; /* debug registers */ + /* Index 0-3: debug address registers */ + /* Index 4-5: reserved */ + /* Index 6: debug status */ + /* Index 7: debug control */ + /* Index 8-15: reserved */ +}; + +#define DBREG_DR6_RESERVED1 0xffff0ff0 +#define DBREG_DR6_BMASK 0x000f +#define DBREG_DR6_B(i) (1 << (i)) +#define DBREG_DR6_BD 0x2000 +#define DBREG_DR6_BS 0x4000 +#define DBREG_DR6_BT 0x8000 + +#define DBREG_DR7_RESERVED1 0x0400 +#define DBREG_DR7_LOCAL_ENABLE 0x01 +#define DBREG_DR7_GLOBAL_ENABLE 0x02 +#define DBREG_DR7_LEN_1 0x00 /* 1 byte length */ +#define DBREG_DR7_LEN_2 0x01 +#define DBREG_DR7_LEN_4 0x03 +#define DBREG_DR7_LEN_8 0x02 +#define DBREG_DR7_EXEC 0x00 /* break on execute */ +#define DBREG_DR7_WRONLY 0x01 /* break on write */ +#define DBREG_DR7_RDWR 0x03 /* break on read or write */ +#define DBREG_DR7_MASK(i) \ + ((__u_register_t)(0xf) << ((i) * 4 + 16) | 0x3 << (i) * 2) +#define DBREG_DR7_SET(i, len, access, enable) \ + ((__u_register_t)((len) << 2 | (access)) << ((i) * 4 + 16) | \ + (enable) << (i) * 2) +#define DBREG_DR7_GD 0x2000 +#define DBREG_DR7_ENABLED(d, i) (((d) & 0x3 << (i) * 2) != 0) +#define DBREG_DR7_ACCESS(d, i) ((d) >> ((i) * 4 + 16) & 0x3) +#define DBREG_DR7_LEN(d, i) ((d) >> ((i) * 4 + 18) & 0x3) + +#define DBREG_DRX(d,x) ((d)->dr[(x)]) /* reference dr0 - dr7 by + register number */ + +#undef __reg32 +#undef __reg64 +#undef __fpreg32 +#undef __fpreg64 +#undef __dbreg32 +#undef __dbreg64 + +#ifdef _KERNEL +struct thread; + +/* + * XXX these interfaces are MI, so they should be declared in a MI place. + */ +int fill_regs(struct thread *, struct reg *); +int fill_frame_regs(struct trapframe *, struct reg *); +int set_regs(struct thread *, struct reg *); +int fill_fpregs(struct thread *, struct fpreg *); +int set_fpregs(struct thread *, struct fpreg *); +int fill_dbregs(struct thread *, struct dbreg *); +int set_dbregs(struct thread *, struct dbreg *); +#ifdef COMPAT_FREEBSD32 +int fill_regs32(struct thread *, struct reg32 *); +int set_regs32(struct thread *, struct reg32 *); +int fill_fpregs32(struct thread *, struct fpreg32 *); +int set_fpregs32(struct thread *, struct fpreg32 *); +int fill_dbregs32(struct thread *, struct dbreg32 *); +int set_dbregs32(struct thread *, struct dbreg32 *); +#endif +#endif + +#endif /* !_MACHINE_REG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/segments.h b/lib/libc/include/x86_64-freebsd-any/x86/segments.h new file mode 100644 index 000000000000..01472b9c72ef --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/segments.h @@ -0,0 +1,276 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1989, 1990 William F. Jolitz + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _X86_SEGMENTS_H_ +#define _X86_SEGMENTS_H_ + +/* + * X86 Segmentation Data Structures and definitions + */ + +/* + * Selectors + */ +#define SEL_RPL_MASK 3 /* requester priv level */ +#define ISPL(s) ((s)&3) /* priority level of a selector */ +#define SEL_KPL 0 /* kernel priority level */ +#define SEL_UPL 3 /* user priority level */ +#define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ +#define IDXSEL(s) (((s)>>3) & 0x1fff) /* index of selector */ +#define LSEL(s,r) (((s)<<3) | SEL_LDT | r) /* a local selector */ +#define GSEL(s,r) (((s)<<3) | r) /* a global selector */ + +/* + * User segment descriptors (%cs, %ds etc for i386 apps. 64 bit wide) + * For long-mode apps, %cs only has the conforming bit in sd_type, the sd_dpl, + * sd_p, sd_l and sd_def32 which must be zero). %ds only has sd_p. + */ +struct segment_descriptor { + unsigned sd_lolimit:16; /* segment extent (lsb) */ + unsigned sd_lobase:24; /* segment base address (lsb) */ + unsigned sd_type:5; /* segment type */ + unsigned sd_dpl:2; /* segment descriptor priority level */ + unsigned sd_p:1; /* segment descriptor present */ + unsigned sd_hilimit:4; /* segment extent (msb) */ + unsigned sd_xx:2; /* unused */ + unsigned sd_def32:1; /* default 32 vs 16 bit size */ + unsigned sd_gran:1; /* limit granularity (byte/page units)*/ + unsigned sd_hibase:8; /* segment base address (msb) */ +} __packed; + +struct user_segment_descriptor { + unsigned sd_lolimit:16; /* segment extent (lsb) */ + unsigned sd_lobase:24; /* segment base address (lsb) */ + unsigned sd_type:5; /* segment type */ + unsigned sd_dpl:2; /* segment descriptor priority level */ + unsigned sd_p:1; /* segment descriptor present */ + unsigned sd_hilimit:4; /* segment extent (msb) */ + unsigned sd_xx:1; /* unused */ + unsigned sd_long:1; /* long mode (cs only) */ + unsigned sd_def32:1; /* default 32 vs 16 bit size */ + unsigned sd_gran:1; /* limit granularity (byte/page units)*/ + unsigned sd_hibase:8; /* segment base address (msb) */ +} __packed; + +#define USD_GETBASE(sd) (((sd)->sd_lobase) | (sd)->sd_hibase << 24) +#define USD_SETBASE(sd, b) (sd)->sd_lobase = (b); \ + (sd)->sd_hibase = ((b) >> 24); +#define USD_GETLIMIT(sd) (((sd)->sd_lolimit) | (sd)->sd_hilimit << 16) +#define USD_SETLIMIT(sd, l) (sd)->sd_lolimit = (l); \ + (sd)->sd_hilimit = ((l) >> 16); + +#ifdef __i386__ +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + unsigned gd_looffset:16; /* gate offset (lsb) */ + unsigned gd_selector:16; /* gate segment selector */ + unsigned gd_stkcpy:5; /* number of stack wds to cpy */ + unsigned gd_xx:3; /* unused */ + unsigned gd_type:5; /* segment type */ + unsigned gd_dpl:2; /* segment descriptor priority level */ + unsigned gd_p:1; /* segment descriptor present */ + unsigned gd_hioffset:16; /* gate offset (msb) */ +} __packed; + +/* + * Generic descriptor + */ +union descriptor { + struct segment_descriptor sd; + struct gate_descriptor gd; +}; +#else +/* + * Gate descriptors (e.g. indirect descriptors, trap, interrupt etc. 128 bit) + * Only interrupt and trap gates have gd_ist. + */ +struct gate_descriptor { + uint64_t gd_looffset:16; /* gate offset (lsb) */ + uint64_t gd_selector:16; /* gate segment selector */ + uint64_t gd_ist:3; /* IST table index */ + uint64_t gd_xx:5; /* unused */ + uint64_t gd_type:5; /* segment type */ + uint64_t gd_dpl:2; /* segment descriptor priority level */ + uint64_t gd_p:1; /* segment descriptor present */ + uint64_t gd_hioffset:48; /* gate offset (msb) */ + uint64_t sd_xx1:32; +} __packed; + +/* + * Generic descriptor + */ +union descriptor { + struct user_segment_descriptor sd; + struct gate_descriptor gd; +}; +#endif + + /* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSTSS 9 /* system available 64 bit TSS */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYSBSY 11 /* system busy 64 bit TSS */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSCGT 12 /* system 64 bit call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYSIGT 14 /* system 64 bit interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ +#define SDT_SYSTGT 15 /* system 64 bit trap gate */ + + /* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed*/ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* + * Size of IDT table + */ +#define NIDT 256 /* 32 reserved, 0x80 syscall, most are h/w */ +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define IDT_DE 0 /* #DE: Divide Error */ +#define IDT_DB 1 /* #DB: Debug */ +#define IDT_NMI 2 /* Nonmaskable External Interrupt */ +#define IDT_BP 3 /* #BP: Breakpoint */ +#define IDT_OF 4 /* #OF: Overflow */ +#define IDT_BR 5 /* #BR: Bound Range Exceeded */ +#define IDT_UD 6 /* #UD: Undefined/Invalid Opcode */ +#define IDT_NM 7 /* #NM: No Math Coprocessor */ +#define IDT_DF 8 /* #DF: Double Fault */ +#define IDT_FPUGP 9 /* Coprocessor Segment Overrun */ +#define IDT_TS 10 /* #TS: Invalid TSS */ +#define IDT_NP 11 /* #NP: Segment Not Present */ +#define IDT_SS 12 /* #SS: Stack Segment Fault */ +#define IDT_GP 13 /* #GP: General Protection Fault */ +#define IDT_PF 14 /* #PF: Page Fault */ +#define IDT_MF 16 /* #MF: FPU Floating-Point Error */ +#define IDT_AC 17 /* #AC: Alignment Check */ +#define IDT_MC 18 /* #MC: Machine Check */ +#define IDT_XF 19 /* #XF: SIMD Floating-Point Exception */ +#define IDT_IO_INTS NRSVIDT /* Base of IDT entries for I/O interrupts. */ +#define IDT_SYSCALL 0x80 /* System Call Interrupt Vector */ +#define IDT_DTRACE_RET 0x92 /* DTrace pid provider Interrupt Vector */ +#define IDT_EVTCHN 0x93 /* Xen HVM Event Channel Interrupt Vector */ + +#if defined(__i386__) +/* + * Entries in the Global Descriptor Table (GDT) + * Note that each 4 entries share a single 32 byte L1 cache line. + * Some of the fast syscall instructions require a specific order here. + */ +#define GNULL_SEL 0 /* Null Descriptor */ +#define GPRIV_SEL 1 /* SMP Per-Processor Private Data */ +#define GUFS_SEL 2 /* User %fs Descriptor (order critical: 1) */ +#define GUGS_SEL 3 /* User %gs Descriptor (order critical: 2) */ +#define GCODE_SEL 4 /* Kernel Code Descriptor (order critical: 1) */ +#define GDATA_SEL 5 /* Kernel Data Descriptor (order critical: 2) */ +#define GUCODE_SEL 6 /* User Code Descriptor (order critical: 3) */ +#define GUDATA_SEL 7 /* User Data Descriptor (order critical: 4) */ +#define GBIOSLOWMEM_SEL 8 /* BIOS low memory access (must be entry 8) */ +#define GPROC0_SEL 9 /* Task state process slot zero and up */ +#define GLDT_SEL 10 /* Default User LDT */ +#define GUSERLDT_SEL 11 /* User LDT */ +#define GPANIC_SEL 12 /* Task state to consider panic from */ +#define GBIOSCODE32_SEL 13 /* BIOS interface (32bit Code) */ +#define GBIOSCODE16_SEL 14 /* BIOS interface (16bit Code) */ +#define GBIOSDATA_SEL 15 /* BIOS interface (Data) */ +#define GBIOSUTIL_SEL 16 /* BIOS interface (Utility) */ +#define GBIOSARGS_SEL 17 /* BIOS interface (Arguments) */ +#define GNDIS_SEL 18 /* For the NDIS layer */ +#define NGDT 19 + +/* + * Entries in the Local Descriptor Table (LDT) + */ +#define LSYS5CALLS_SEL 0 /* forced by intel BCS */ +#define LSYS5SIGR_SEL 1 +#define LUCODE_SEL 3 +#define LUDATA_SEL 5 +#define NLDT (LUDATA_SEL + 1) + +#else /* !__i386__ */ +/* + * Entries in the Global Descriptor Table (GDT) + */ +#define GNULL_SEL 0 /* Null Descriptor */ +#define GNULL2_SEL 1 /* Null Descriptor */ +#define GUFS32_SEL 2 /* User 32 bit %fs Descriptor */ +#define GUGS32_SEL 3 /* User 32 bit %gs Descriptor */ +#define GCODE_SEL 4 /* Kernel Code Descriptor */ +#define GDATA_SEL 5 /* Kernel Data Descriptor */ +#define GUCODE32_SEL 6 /* User 32 bit code Descriptor */ +#define GUDATA_SEL 7 /* User 32/64 bit Data Descriptor */ +#define GUCODE_SEL 8 /* User 64 bit Code Descriptor */ +#define GPROC0_SEL 9 /* TSS for entering kernel etc */ +/* slot 10 is second half of GPROC0_SEL */ +#define GUSERLDT_SEL 11 /* LDT */ +/* slot 12 is second half of GUSERLDT_SEL */ +#define NGDT 13 +#endif /* __i386__ */ + +#endif /* !_X86_SEGMENTS_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/setjmp.h b/lib/libc/include/x86_64-freebsd-any/x86/setjmp.h new file mode 100644 index 000000000000..c453f9b755aa --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/setjmp.h @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1998 John Birrell . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_SETJMP_H_ +#define _MACHINE_SETJMP_H_ + +#include + +#define _JBLEN 12 /* Size of the jmp_buf on AMD64. */ + +/* + * jmp_buf and sigjmp_buf are encapsulated in different structs to force + * compile-time diagnostics for mismatches. The structs are the same + * internally to avoid some run-time errors for mismatches. + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE +typedef struct _sigjmp_buf { long _sjb[_JBLEN]; } sigjmp_buf[1]; +#endif + +typedef struct _jmp_buf { long _jb[_JBLEN]; } jmp_buf[1]; + +#endif /* !_MACHINE_SETJMP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/sigframe.h b/lib/libc/include/x86_64-freebsd-any/x86/sigframe.h new file mode 100644 index 000000000000..1b9dbd9d4f58 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/sigframe.h @@ -0,0 +1,74 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_SIGFRAME_H_ +#define _X86_SIGFRAME_H_ + +/* + * Signal frames, arguments passed to application signal handlers. + */ + +#ifdef __i386__ +struct sigframe { + /* + * The first four members may be used by applications. + * + * NOTE: The 4th argument is undocumented, ill commented + * on and seems to be somewhat BSD "standard". Handlers + * installed with sigvec may be using it. + */ + register_t sf_signum; + register_t sf_siginfo; /* code or pointer to sf_si */ + register_t sf_ucontext; /* points to sf_uc */ + register_t sf_addr; /* undocumented 4th arg */ + + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + ucontext_t sf_uc; /* = *sf_ucontext */ + siginfo_t sf_si; /* = *sf_siginfo (SA_SIGINFO case) */ +}; +#endif /* __i386__ */ + +#ifdef __amd64__ +struct sigframe { + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + ucontext_t sf_uc; /* = *sf_ucontext */ + siginfo_t sf_si; /* = *sf_siginfo (SA_SIGINFO case) */ +}; +#endif /* __amd64__ */ + +#endif /* _X86_SIGFRAME_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/signal.h b/lib/libc/include/x86_64-freebsd-any/x86/signal.h new file mode 100644 index 000000000000..553757c990df --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/signal.h @@ -0,0 +1,165 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2003 Peter Wemm. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD$ + */ + +#ifndef _X86_SIGNAL_H +#define _X86_SIGNAL_H 1 + +/* + * Machine-dependent signal definitions + */ + +#include +#include + +#ifdef __i386__ +typedef int sig_atomic_t; + +#if __BSD_VISIBLE +struct sigcontext { + struct __sigset sc_mask; /* signal mask to restore */ + int sc_onstack; /* sigstack state to restore */ + int sc_gs; /* machine state (struct trapframe) */ + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_isp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + int sc_trapno; + int sc_err; + int sc_eip; + int sc_cs; + int sc_efl; + int sc_esp; + int sc_ss; + int sc_len; /* sizeof(mcontext_t) */ + /* + * See and for + * the following fields. + */ + int sc_fpformat; + int sc_ownedfp; + int sc_flags; + int sc_fpstate[128] __aligned(16); + + int sc_fsbase; + int sc_gsbase; + + int sc_xfpustate; + int sc_xfpustate_len; + + int sc_spare2[4]; +}; + +#define sc_sp sc_esp +#define sc_fp sc_ebp +#define sc_pc sc_eip +#define sc_ps sc_efl +#define sc_eflags sc_efl + +#endif /* __BSD_VISIBLE */ +#endif /* __i386__ */ + +#ifdef __amd64__ +typedef long sig_atomic_t; + +#if __BSD_VISIBLE +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + * + * The sequence of the fields/registers after sc_mask in struct + * sigcontext must match those in mcontext_t and struct trapframe. + */ +struct sigcontext { + struct __sigset sc_mask; /* signal mask to restore */ + long sc_onstack; /* sigstack state to restore */ + long sc_rdi; /* machine state (struct trapframe) */ + long sc_rsi; + long sc_rdx; + long sc_rcx; + long sc_r8; + long sc_r9; + long sc_rax; + long sc_rbx; + long sc_rbp; + long sc_r10; + long sc_r11; + long sc_r12; + long sc_r13; + long sc_r14; + long sc_r15; + int sc_trapno; + short sc_fs; + short sc_gs; + long sc_addr; + int sc_flags; + short sc_es; + short sc_ds; + long sc_err; + long sc_rip; + long sc_cs; + long sc_rflags; + long sc_rsp; + long sc_ss; + long sc_len; /* sizeof(mcontext_t) */ + /* + * See and for the following + * fields. + */ + long sc_fpformat; + long sc_ownedfp; + long sc_fpstate[64] __aligned(16); + + long sc_fsbase; + long sc_gsbase; + + long sc_xfpustate; + long sc_xfpustate_len; + + long sc_spare[4]; +}; +#endif /* __BSD_VISIBLE */ +#endif /* __amd64__ */ + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/specialreg.h b/lib/libc/include/x86_64-freebsd-any/x86/specialreg.h new file mode 100644 index 000000000000..142d8baaaf30 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/specialreg.h @@ -0,0 +1,1133 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_SPECIALREG_H_ +#define _MACHINE_SPECIALREG_H_ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" (fpu) Present */ +#define CR0_EM 0x00000004 /* EMulate FPU instructions. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor page protect in + all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +#define CR3_PCID_SAVE 0x8000000000000000 +#define CR3_PCID_MASK 0xfff + +/* + * Bits in PPro special registers + */ +#define CR4_VME 0x00000001 /* Virtual 8086 mode extensions */ +#define CR4_PVI 0x00000002 /* Protected-mode virtual interrupts */ +#define CR4_TSD 0x00000004 /* Time stamp disable */ +#define CR4_DE 0x00000008 /* Debugging extensions */ +#define CR4_PSE 0x00000010 /* Page size extensions */ +#define CR4_PAE 0x00000020 /* Physical address extension */ +#define CR4_MCE 0x00000040 /* Machine check enable */ +#define CR4_PGE 0x00000080 /* Page global enable */ +#define CR4_PCE 0x00000100 /* Performance monitoring counter enable */ +#define CR4_FXSR 0x00000200 /* Fast FPU save/restore used by OS */ +#define CR4_XMM 0x00000400 /* enable SIMD/MMX2 to use except 16 */ +#define CR4_VMXE 0x00002000 /* enable VMX operation (Intel-specific) */ +#define CR4_FSGSBASE 0x00010000 /* Enable FS/GS BASE accessing instructions */ +#define CR4_PCIDE 0x00020000 /* Enable Context ID */ +#define CR4_XSAVE 0x00040000 /* XSETBV/XGETBV */ +#define CR4_SMEP 0x00100000 /* Supervisor-Mode Execution Prevention */ +#define CR4_SMAP 0x00200000 /* Supervisor-Mode Access Prevention */ +#define CR4_PKE 0x00400000 /* Protection Keys Enable */ + +/* + * Bits in AMD64 special registers. EFER is 64 bits wide. + */ +#define EFER_SCE 0x000000001 /* System Call Extensions (R/W) */ +#define EFER_LME 0x000000100 /* Long mode enable (R/W) */ +#define EFER_LMA 0x000000400 /* Long mode active (R) */ +#define EFER_NXE 0x000000800 /* PTE No-Execute bit enable (R/W) */ +#define EFER_SVM 0x000001000 /* SVM enable bit for AMD, reserved for Intel */ +#define EFER_LMSLE 0x000002000 /* Long Mode Segment Limit Enable */ +#define EFER_FFXSR 0x000004000 /* Fast FXSAVE/FSRSTOR */ +#define EFER_TCE 0x000008000 /* Translation Cache Extension */ + +/* + * Intel Extended Features registers + */ +#define XCR0 0 /* XFEATURE_ENABLED_MASK register */ + +#define XFEATURE_ENABLED_X87 0x00000001 +#define XFEATURE_ENABLED_SSE 0x00000002 +#define XFEATURE_ENABLED_YMM_HI128 0x00000004 +#define XFEATURE_ENABLED_AVX XFEATURE_ENABLED_YMM_HI128 +#define XFEATURE_ENABLED_BNDREGS 0x00000008 +#define XFEATURE_ENABLED_BNDCSR 0x00000010 +#define XFEATURE_ENABLED_OPMASK 0x00000020 +#define XFEATURE_ENABLED_ZMM_HI256 0x00000040 +#define XFEATURE_ENABLED_HI16_ZMM 0x00000080 + +#define XFEATURE_AVX \ + (XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE | XFEATURE_ENABLED_AVX) +#define XFEATURE_AVX512 \ + (XFEATURE_ENABLED_OPMASK | XFEATURE_ENABLED_ZMM_HI256 | \ + XFEATURE_ENABLED_HI16_ZMM) +#define XFEATURE_MPX \ + (XFEATURE_ENABLED_BNDREGS | XFEATURE_ENABLED_BNDCSR) + +/* + * CPUID instruction features register + */ +#define CPUID_FPU 0x00000001 +#define CPUID_VME 0x00000002 +#define CPUID_DE 0x00000004 +#define CPUID_PSE 0x00000008 +#define CPUID_TSC 0x00000010 +#define CPUID_MSR 0x00000020 +#define CPUID_PAE 0x00000040 +#define CPUID_MCE 0x00000080 +#define CPUID_CX8 0x00000100 +#define CPUID_APIC 0x00000200 +#define CPUID_B10 0x00000400 +#define CPUID_SEP 0x00000800 +#define CPUID_MTRR 0x00001000 +#define CPUID_PGE 0x00002000 +#define CPUID_MCA 0x00004000 +#define CPUID_CMOV 0x00008000 +#define CPUID_PAT 0x00010000 +#define CPUID_PSE36 0x00020000 +#define CPUID_PSN 0x00040000 +#define CPUID_CLFSH 0x00080000 +#define CPUID_B20 0x00100000 +#define CPUID_DS 0x00200000 +#define CPUID_ACPI 0x00400000 +#define CPUID_MMX 0x00800000 +#define CPUID_FXSR 0x01000000 +#define CPUID_SSE 0x02000000 +#define CPUID_XMM 0x02000000 +#define CPUID_SSE2 0x04000000 +#define CPUID_SS 0x08000000 +#define CPUID_HTT 0x10000000 +#define CPUID_TM 0x20000000 +#define CPUID_IA64 0x40000000 +#define CPUID_PBE 0x80000000 + +#define CPUID2_SSE3 0x00000001 +#define CPUID2_PCLMULQDQ 0x00000002 +#define CPUID2_DTES64 0x00000004 +#define CPUID2_MON 0x00000008 +#define CPUID2_DS_CPL 0x00000010 +#define CPUID2_VMX 0x00000020 +#define CPUID2_SMX 0x00000040 +#define CPUID2_EST 0x00000080 +#define CPUID2_TM2 0x00000100 +#define CPUID2_SSSE3 0x00000200 +#define CPUID2_CNXTID 0x00000400 +#define CPUID2_SDBG 0x00000800 +#define CPUID2_FMA 0x00001000 +#define CPUID2_CX16 0x00002000 +#define CPUID2_XTPR 0x00004000 +#define CPUID2_PDCM 0x00008000 +#define CPUID2_PCID 0x00020000 +#define CPUID2_DCA 0x00040000 +#define CPUID2_SSE41 0x00080000 +#define CPUID2_SSE42 0x00100000 +#define CPUID2_X2APIC 0x00200000 +#define CPUID2_MOVBE 0x00400000 +#define CPUID2_POPCNT 0x00800000 +#define CPUID2_TSCDLT 0x01000000 +#define CPUID2_AESNI 0x02000000 +#define CPUID2_XSAVE 0x04000000 +#define CPUID2_OSXSAVE 0x08000000 +#define CPUID2_AVX 0x10000000 +#define CPUID2_F16C 0x20000000 +#define CPUID2_RDRAND 0x40000000 +#define CPUID2_HV 0x80000000 + +/* + * Important bits in the Thermal and Power Management flags + * CPUID.6 EAX and ECX. + */ +#define CPUTPM1_SENSOR 0x00000001 +#define CPUTPM1_TURBO 0x00000002 +#define CPUTPM1_ARAT 0x00000004 +#define CPUTPM1_HWP 0x00000080 +#define CPUTPM1_HWP_NOTIFICATION 0x00000100 +#define CPUTPM1_HWP_ACTIVITY_WINDOW 0x00000200 +#define CPUTPM1_HWP_PERF_PREF 0x00000400 +#define CPUTPM1_HWP_PKG 0x00000800 +#define CPUTPM1_HWP_FLEXIBLE 0x00020000 +#define CPUTPM2_EFFREQ 0x00000001 + +/* Intel Processor Trace CPUID. */ + +/* Leaf 0 ebx. */ +#define CPUPT_CR3 (1 << 0) /* CR3 Filtering Support */ +#define CPUPT_PSB (1 << 1) /* Configurable PSB and Cycle-Accurate Mode Supported */ +#define CPUPT_IPF (1 << 2) /* IP Filtering and TraceStop supported */ +#define CPUPT_MTC (1 << 3) /* MTC Supported */ +#define CPUPT_PRW (1 << 4) /* PTWRITE Supported */ +#define CPUPT_PWR (1 << 5) /* Power Event Trace Supported */ + +/* Leaf 0 ecx. */ +#define CPUPT_TOPA (1 << 0) /* ToPA Output Supported */ +#define CPUPT_TOPA_MULTI (1 << 1) /* ToPA Tables Allow Multiple Output Entries */ +#define CPUPT_SINGLE (1 << 2) /* Single-Range Output Supported */ +#define CPUPT_TT_OUT (1 << 3) /* Output to Trace Transport Subsystem Supported */ +#define CPUPT_LINEAR_IP (1 << 31) /* IP Payloads are Linear IP, otherwise IP is effective */ + +/* Leaf 1 eax. */ +#define CPUPT_NADDR_S 0 /* Number of Address Ranges */ +#define CPUPT_NADDR_M (0x7 << CPUPT_NADDR_S) +#define CPUPT_MTC_BITMAP_S 16 /* Bitmap of supported MTC Period Encodings */ +#define CPUPT_MTC_BITMAP_M (0xffff << CPUPT_MTC_BITMAP_S) + +/* Leaf 1 ebx. */ +#define CPUPT_CT_BITMAP_S 0 /* Bitmap of supported Cycle Threshold values */ +#define CPUPT_CT_BITMAP_M (0xffff << CPUPT_CT_BITMAP_S) +#define CPUPT_PFE_BITMAP_S 16 /* Bitmap of supported Configurable PSB Frequency encoding */ +#define CPUPT_PFE_BITMAP_M (0xffff << CPUPT_PFE_BITMAP_S) + +/* + * Important bits in the AMD extended cpuid flags + */ +#define AMDID_SYSCALL 0x00000800 +#define AMDID_MP 0x00080000 +#define AMDID_NX 0x00100000 +#define AMDID_EXT_MMX 0x00400000 +#define AMDID_FFXSR 0x02000000 +#define AMDID_PAGE1GB 0x04000000 +#define AMDID_RDTSCP 0x08000000 +#define AMDID_LM 0x20000000 +#define AMDID_EXT_3DNOW 0x40000000 +#define AMDID_3DNOW 0x80000000 + +#define AMDID2_LAHF 0x00000001 +#define AMDID2_CMP 0x00000002 +#define AMDID2_SVM 0x00000004 +#define AMDID2_EXT_APIC 0x00000008 +#define AMDID2_CR8 0x00000010 +#define AMDID2_ABM 0x00000020 +#define AMDID2_SSE4A 0x00000040 +#define AMDID2_MAS 0x00000080 +#define AMDID2_PREFETCH 0x00000100 +#define AMDID2_OSVW 0x00000200 +#define AMDID2_IBS 0x00000400 +#define AMDID2_XOP 0x00000800 +#define AMDID2_SKINIT 0x00001000 +#define AMDID2_WDT 0x00002000 +#define AMDID2_LWP 0x00008000 +#define AMDID2_FMA4 0x00010000 +#define AMDID2_TCE 0x00020000 +#define AMDID2_NODE_ID 0x00080000 +#define AMDID2_TBM 0x00200000 +#define AMDID2_TOPOLOGY 0x00400000 +#define AMDID2_PCXC 0x00800000 +#define AMDID2_PNXC 0x01000000 +#define AMDID2_DBE 0x04000000 +#define AMDID2_PTSC 0x08000000 +#define AMDID2_PTSCEL2I 0x10000000 +#define AMDID2_MWAITX 0x20000000 + +/* + * CPUID instruction 1 eax info + */ +#define CPUID_STEPPING 0x0000000f +#define CPUID_MODEL 0x000000f0 +#define CPUID_FAMILY 0x00000f00 +#define CPUID_EXT_MODEL 0x000f0000 +#define CPUID_EXT_FAMILY 0x0ff00000 +#ifdef __i386__ +#define CPUID_TO_MODEL(id) \ + ((((id) & CPUID_MODEL) >> 4) | \ + ((((id) & CPUID_FAMILY) >= 0x600) ? \ + (((id) & CPUID_EXT_MODEL) >> 12) : 0)) +#define CPUID_TO_FAMILY(id) \ + ((((id) & CPUID_FAMILY) >> 8) + \ + ((((id) & CPUID_FAMILY) == 0xf00) ? \ + (((id) & CPUID_EXT_FAMILY) >> 20) : 0)) +#else +#define CPUID_TO_MODEL(id) \ + ((((id) & CPUID_MODEL) >> 4) | \ + (((id) & CPUID_EXT_MODEL) >> 12)) +#define CPUID_TO_FAMILY(id) \ + ((((id) & CPUID_FAMILY) >> 8) + \ + (((id) & CPUID_EXT_FAMILY) >> 20)) +#endif +#define CPUID_TO_STEPPING(id) ((id) & CPUID_STEPPING) + +/* + * CPUID instruction 1 ebx info + */ +#define CPUID_BRAND_INDEX 0x000000ff +#define CPUID_CLFUSH_SIZE 0x0000ff00 +#define CPUID_HTT_CORES 0x00ff0000 +#define CPUID_LOCAL_APIC_ID 0xff000000 + +/* + * CPUID instruction 5 info + */ +#define CPUID5_MON_MIN_SIZE 0x0000ffff /* eax */ +#define CPUID5_MON_MAX_SIZE 0x0000ffff /* ebx */ +#define CPUID5_MON_MWAIT_EXT 0x00000001 /* ecx */ +#define CPUID5_MWAIT_INTRBREAK 0x00000002 /* ecx */ + +/* + * MWAIT cpu power states. Lower 4 bits are sub-states. + */ +#define MWAIT_C0 0xf0 +#define MWAIT_C1 0x00 +#define MWAIT_C2 0x10 +#define MWAIT_C3 0x20 +#define MWAIT_C4 0x30 + +/* + * MWAIT extensions. + */ +/* Interrupt breaks MWAIT even when masked. */ +#define MWAIT_INTRBREAK 0x00000001 + +/* + * CPUID instruction 6 ecx info + */ +#define CPUID_PERF_STAT 0x00000001 +#define CPUID_PERF_BIAS 0x00000008 + +/* + * CPUID instruction 0xb ebx info. + */ +#define CPUID_TYPE_INVAL 0 +#define CPUID_TYPE_SMT 1 +#define CPUID_TYPE_CORE 2 + +/* + * CPUID instruction 0xd Processor Extended State Enumeration Sub-leaf 1 + */ +#define CPUID_EXTSTATE_XSAVEOPT 0x00000001 +#define CPUID_EXTSTATE_XSAVEC 0x00000002 +#define CPUID_EXTSTATE_XINUSE 0x00000004 +#define CPUID_EXTSTATE_XSAVES 0x00000008 + +/* + * AMD extended function 8000_0007h ebx info + */ +#define AMDRAS_MCA_OF_RECOV 0x00000001 +#define AMDRAS_SUCCOR 0x00000002 +#define AMDRAS_HW_ASSERT 0x00000004 +#define AMDRAS_SCALABLE_MCA 0x00000008 +#define AMDRAS_PFEH_SUPPORT 0x00000010 + +/* + * AMD extended function 8000_0007h edx info + */ +#define AMDPM_TS 0x00000001 +#define AMDPM_FID 0x00000002 +#define AMDPM_VID 0x00000004 +#define AMDPM_TTP 0x00000008 +#define AMDPM_TM 0x00000010 +#define AMDPM_STC 0x00000020 +#define AMDPM_100MHZ_STEPS 0x00000040 +#define AMDPM_HW_PSTATE 0x00000080 +#define AMDPM_TSC_INVARIANT 0x00000100 +#define AMDPM_CPB 0x00000200 + +/* + * AMD extended function 8000_0008h ebx info (amd_extended_feature_extensions) + */ +#define AMDFEID_CLZERO 0x00000001 +#define AMDFEID_IRPERF 0x00000002 +#define AMDFEID_XSAVEERPTR 0x00000004 + +/* + * AMD extended function 8000_0008h ecx info + */ +#define AMDID_CMP_CORES 0x000000ff +#define AMDID_COREID_SIZE 0x0000f000 +#define AMDID_COREID_SIZE_SHIFT 12 + +/* + * CPUID instruction 7 Structured Extended Features, leaf 0 ebx info + */ +#define CPUID_STDEXT_FSGSBASE 0x00000001 +#define CPUID_STDEXT_TSC_ADJUST 0x00000002 +#define CPUID_STDEXT_SGX 0x00000004 +#define CPUID_STDEXT_BMI1 0x00000008 +#define CPUID_STDEXT_HLE 0x00000010 +#define CPUID_STDEXT_AVX2 0x00000020 +#define CPUID_STDEXT_FDP_EXC 0x00000040 +#define CPUID_STDEXT_SMEP 0x00000080 +#define CPUID_STDEXT_BMI2 0x00000100 +#define CPUID_STDEXT_ERMS 0x00000200 +#define CPUID_STDEXT_INVPCID 0x00000400 +#define CPUID_STDEXT_RTM 0x00000800 +#define CPUID_STDEXT_PQM 0x00001000 +#define CPUID_STDEXT_NFPUSG 0x00002000 +#define CPUID_STDEXT_MPX 0x00004000 +#define CPUID_STDEXT_PQE 0x00008000 +#define CPUID_STDEXT_AVX512F 0x00010000 +#define CPUID_STDEXT_AVX512DQ 0x00020000 +#define CPUID_STDEXT_RDSEED 0x00040000 +#define CPUID_STDEXT_ADX 0x00080000 +#define CPUID_STDEXT_SMAP 0x00100000 +#define CPUID_STDEXT_AVX512IFMA 0x00200000 +#define CPUID_STDEXT_PCOMMIT 0x00400000 +#define CPUID_STDEXT_CLFLUSHOPT 0x00800000 +#define CPUID_STDEXT_CLWB 0x01000000 +#define CPUID_STDEXT_PROCTRACE 0x02000000 +#define CPUID_STDEXT_AVX512PF 0x04000000 +#define CPUID_STDEXT_AVX512ER 0x08000000 +#define CPUID_STDEXT_AVX512CD 0x10000000 +#define CPUID_STDEXT_SHA 0x20000000 +#define CPUID_STDEXT_AVX512BW 0x40000000 +#define CPUID_STDEXT_AVX512VL 0x80000000 + +/* + * CPUID instruction 7 Structured Extended Features, leaf 0 ecx info + */ +#define CPUID_STDEXT2_PREFETCHWT1 0x00000001 +#define CPUID_STDEXT2_AVX512VBMI 0x00000002 +#define CPUID_STDEXT2_UMIP 0x00000004 +#define CPUID_STDEXT2_PKU 0x00000008 +#define CPUID_STDEXT2_OSPKE 0x00000010 +#define CPUID_STDEXT2_WAITPKG 0x00000020 +#define CPUID_STDEXT2_AVX512VBMI2 0x00000040 +#define CPUID_STDEXT2_GFNI 0x00000100 +#define CPUID_STDEXT2_VAES 0x00000200 +#define CPUID_STDEXT2_VPCLMULQDQ 0x00000400 +#define CPUID_STDEXT2_AVX512VNNI 0x00000800 +#define CPUID_STDEXT2_AVX512BITALG 0x00001000 +#define CPUID_STDEXT2_AVX512VPOPCNTDQ 0x00004000 +#define CPUID_STDEXT2_RDPID 0x00400000 +#define CPUID_STDEXT2_CLDEMOTE 0x02000000 +#define CPUID_STDEXT2_MOVDIRI 0x08000000 +#define CPUID_STDEXT2_MOVDIRI64B 0x10000000 +#define CPUID_STDEXT2_ENQCMD 0x20000000 +#define CPUID_STDEXT2_SGXLC 0x40000000 + +/* + * CPUID instruction 7 Structured Extended Features, leaf 0 edx info + */ +#define CPUID_STDEXT3_AVX5124VNNIW 0x00000004 +#define CPUID_STDEXT3_AVX5124FMAPS 0x00000008 +#define CPUID_STDEXT3_AVX512VP2INTERSECT 0x00000100 +#define CPUID_STDEXT3_MCUOPT 0x00000200 +#define CPUID_STDEXT3_MD_CLEAR 0x00000400 +#define CPUID_STDEXT3_TSXFA 0x00002000 +#define CPUID_STDEXT3_PCONFIG 0x00040000 +#define CPUID_STDEXT3_IBPB 0x04000000 +#define CPUID_STDEXT3_STIBP 0x08000000 +#define CPUID_STDEXT3_L1D_FLUSH 0x10000000 +#define CPUID_STDEXT3_ARCH_CAP 0x20000000 +#define CPUID_STDEXT3_CORE_CAP 0x40000000 +#define CPUID_STDEXT3_SSBD 0x80000000 + +/* MSR IA32_ARCH_CAP(ABILITIES) bits */ +#define IA32_ARCH_CAP_RDCL_NO 0x00000001 +#define IA32_ARCH_CAP_IBRS_ALL 0x00000002 +#define IA32_ARCH_CAP_RSBA 0x00000004 +#define IA32_ARCH_CAP_SKIP_L1DFL_VMENTRY 0x00000008 +#define IA32_ARCH_CAP_SSB_NO 0x00000010 +#define IA32_ARCH_CAP_MDS_NO 0x00000020 +#define IA32_ARCH_CAP_IF_PSCHANGE_MC_NO 0x00000040 +#define IA32_ARCH_CAP_TSX_CTRL 0x00000080 +#define IA32_ARCH_CAP_TAA_NO 0x00000100 + +/* MSR IA32_TSX_CTRL bits */ +#define IA32_TSX_CTRL_RTM_DISABLE 0x00000001 +#define IA32_TSX_CTRL_TSX_CPUID_CLEAR 0x00000002 + +/* + * CPUID manufacturers identifiers + */ +#define AMD_VENDOR_ID "AuthenticAMD" +#define CENTAUR_VENDOR_ID "CentaurHauls" +#define CYRIX_VENDOR_ID "CyrixInstead" +#define INTEL_VENDOR_ID "GenuineIntel" +#define NEXGEN_VENDOR_ID "NexGenDriven" +#define NSC_VENDOR_ID "Geode by NSC" +#define RISE_VENDOR_ID "RiseRiseRise" +#define SIS_VENDOR_ID "SiS SiS SiS " +#define TRANSMETA_VENDOR_ID "GenuineTMx86" +#define UMC_VENDOR_ID "UMC UMC UMC " +#define HYGON_VENDOR_ID "HygonGenuine" + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 +#define MSR_P5_MC_TYPE 0x001 +#define MSR_TSC 0x010 +#define MSR_P5_CESR 0x011 +#define MSR_P5_CTR0 0x012 +#define MSR_P5_CTR1 0x013 +#define MSR_IA32_PLATFORM_ID 0x017 +#define MSR_APICBASE 0x01b +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a +#define MSR_IA32_SPEC_CTRL 0x048 +#define MSR_IA32_PRED_CMD 0x049 +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 +#define MSR_BBL_CR_D1 0x089 +#define MSR_BBL_CR_D2 0x08a +#define MSR_BIOS_SIGN 0x08b +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define MSR_PLATFORM_INFO 0x0ce +#define MSR_MPERF 0x0e7 +#define MSR_APERF 0x0e8 +#define MSR_IA32_EXT_CONFIG 0x0ee /* Undocumented. Core Solo/Duo only */ +#define MSR_MTRRcap 0x0fe +#define MSR_IA32_ARCH_CAP 0x10a +#define MSR_IA32_FLUSH_CMD 0x10b +#define MSR_TSX_FORCE_ABORT 0x10f +#define MSR_BBL_CR_ADDR 0x116 +#define MSR_BBL_CR_DECC 0x118 +#define MSR_BBL_CR_CTL 0x119 +#define MSR_BBL_CR_TRIG 0x11a +#define MSR_BBL_CR_BUSY 0x11b +#define MSR_BBL_CR_CTL3 0x11e +#define MSR_IA32_TSX_CTRL 0x122 +#define MSR_IA32_MCU_OPT_CTRL 0x123 +#define MSR_SYSENTER_CS_MSR 0x174 +#define MSR_SYSENTER_ESP_MSR 0x175 +#define MSR_SYSENTER_EIP_MSR 0x176 +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define MSR_EVNTSEL0 0x186 +#define MSR_EVNTSEL1 0x187 +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_IA32_MISC_ENABLE 0x1a0 +#define MSR_IA32_TEMPERATURE_TARGET 0x1a2 +#define MSR_TURBO_RATIO_LIMIT 0x1ad +#define MSR_TURBO_RATIO_LIMIT1 0x1ae +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRVarBase 0x200 +#define MSR_MTRR64kBase 0x250 +#define MSR_MTRR16kBase 0x258 +#define MSR_MTRR4kBase 0x268 +#define MSR_PAT 0x277 +#define MSR_MC0_CTL2 0x280 +#define MSR_MTRRdefType 0x2ff +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC3_CTL 0x40c +#define MSR_MC3_STATUS 0x40d +#define MSR_MC3_ADDR 0x40e +#define MSR_MC3_MISC 0x40f +#define MSR_MC4_CTL 0x410 +#define MSR_MC4_STATUS 0x411 +#define MSR_MC4_ADDR 0x412 +#define MSR_MC4_MISC 0x413 +#define MSR_RAPL_POWER_UNIT 0x606 +#define MSR_PKG_ENERGY_STATUS 0x611 +#define MSR_DRAM_ENERGY_STATUS 0x619 +#define MSR_PP0_ENERGY_STATUS 0x639 +#define MSR_PP1_ENERGY_STATUS 0x641 +#define MSR_PPERF 0x64e +#define MSR_TSC_DEADLINE 0x6e0 /* Writes are not serializing */ +#define MSR_IA32_PM_ENABLE 0x770 +#define MSR_IA32_HWP_CAPABILITIES 0x771 +#define MSR_IA32_HWP_REQUEST_PKG 0x772 +#define MSR_IA32_HWP_INTERRUPT 0x773 +#define MSR_IA32_HWP_REQUEST 0x774 +#define MSR_IA32_HWP_STATUS 0x777 + +/* + * VMX MSRs + */ +#define MSR_VMX_BASIC 0x480 +#define MSR_VMX_PINBASED_CTLS 0x481 +#define MSR_VMX_PROCBASED_CTLS 0x482 +#define MSR_VMX_EXIT_CTLS 0x483 +#define MSR_VMX_ENTRY_CTLS 0x484 +#define MSR_VMX_CR0_FIXED0 0x486 +#define MSR_VMX_CR0_FIXED1 0x487 +#define MSR_VMX_CR4_FIXED0 0x488 +#define MSR_VMX_CR4_FIXED1 0x489 +#define MSR_VMX_PROCBASED_CTLS2 0x48b +#define MSR_VMX_EPT_VPID_CAP 0x48c +#define MSR_VMX_TRUE_PINBASED_CTLS 0x48d +#define MSR_VMX_TRUE_PROCBASED_CTLS 0x48e +#define MSR_VMX_TRUE_EXIT_CTLS 0x48f +#define MSR_VMX_TRUE_ENTRY_CTLS 0x490 + +/* + * X2APIC MSRs. + * Writes are not serializing. + */ +#define MSR_APIC_000 0x800 +#define MSR_APIC_ID 0x802 +#define MSR_APIC_VERSION 0x803 +#define MSR_APIC_TPR 0x808 +#define MSR_APIC_EOI 0x80b +#define MSR_APIC_LDR 0x80d +#define MSR_APIC_SVR 0x80f +#define MSR_APIC_ISR0 0x810 +#define MSR_APIC_ISR1 0x811 +#define MSR_APIC_ISR2 0x812 +#define MSR_APIC_ISR3 0x813 +#define MSR_APIC_ISR4 0x814 +#define MSR_APIC_ISR5 0x815 +#define MSR_APIC_ISR6 0x816 +#define MSR_APIC_ISR7 0x817 +#define MSR_APIC_TMR0 0x818 +#define MSR_APIC_IRR0 0x820 +#define MSR_APIC_ESR 0x828 +#define MSR_APIC_LVT_CMCI 0x82F +#define MSR_APIC_ICR 0x830 +#define MSR_APIC_LVT_TIMER 0x832 +#define MSR_APIC_LVT_THERMAL 0x833 +#define MSR_APIC_LVT_PCINT 0x834 +#define MSR_APIC_LVT_LINT0 0x835 +#define MSR_APIC_LVT_LINT1 0x836 +#define MSR_APIC_LVT_ERROR 0x837 +#define MSR_APIC_ICR_TIMER 0x838 +#define MSR_APIC_CCR_TIMER 0x839 +#define MSR_APIC_DCR_TIMER 0x83e +#define MSR_APIC_SELF_IPI 0x83f + +#define MSR_IA32_XSS 0xda0 + +/* + * Intel Processor Trace (PT) MSRs. + */ +#define MSR_IA32_RTIT_OUTPUT_BASE 0x560 /* Trace Output Base Register (R/W) */ +#define MSR_IA32_RTIT_OUTPUT_MASK_PTRS 0x561 /* Trace Output Mask Pointers Register (R/W) */ +#define MSR_IA32_RTIT_CTL 0x570 /* Trace Control Register (R/W) */ +#define RTIT_CTL_TRACEEN (1 << 0) +#define RTIT_CTL_CYCEN (1 << 1) +#define RTIT_CTL_OS (1 << 2) +#define RTIT_CTL_USER (1 << 3) +#define RTIT_CTL_PWREVTEN (1 << 4) +#define RTIT_CTL_FUPONPTW (1 << 5) +#define RTIT_CTL_FABRICEN (1 << 6) +#define RTIT_CTL_CR3FILTER (1 << 7) +#define RTIT_CTL_TOPA (1 << 8) +#define RTIT_CTL_MTCEN (1 << 9) +#define RTIT_CTL_TSCEN (1 << 10) +#define RTIT_CTL_DISRETC (1 << 11) +#define RTIT_CTL_PTWEN (1 << 12) +#define RTIT_CTL_BRANCHEN (1 << 13) +#define RTIT_CTL_MTC_FREQ_S 14 +#define RTIT_CTL_MTC_FREQ(n) ((n) << RTIT_CTL_MTC_FREQ_S) +#define RTIT_CTL_MTC_FREQ_M (0xf << RTIT_CTL_MTC_FREQ_S) +#define RTIT_CTL_CYC_THRESH_S 19 +#define RTIT_CTL_CYC_THRESH_M (0xf << RTIT_CTL_CYC_THRESH_S) +#define RTIT_CTL_PSB_FREQ_S 24 +#define RTIT_CTL_PSB_FREQ_M (0xf << RTIT_CTL_PSB_FREQ_S) +#define RTIT_CTL_ADDR_CFG_S(n) (32 + (n) * 4) +#define RTIT_CTL_ADDR0_CFG_S 32 +#define RTIT_CTL_ADDR0_CFG_M (0xfULL << RTIT_CTL_ADDR0_CFG_S) +#define RTIT_CTL_ADDR1_CFG_S 36 +#define RTIT_CTL_ADDR1_CFG_M (0xfULL << RTIT_CTL_ADDR1_CFG_S) +#define RTIT_CTL_ADDR2_CFG_S 40 +#define RTIT_CTL_ADDR2_CFG_M (0xfULL << RTIT_CTL_ADDR2_CFG_S) +#define RTIT_CTL_ADDR3_CFG_S 44 +#define RTIT_CTL_ADDR3_CFG_M (0xfULL << RTIT_CTL_ADDR3_CFG_S) +#define MSR_IA32_RTIT_STATUS 0x571 /* Tracing Status Register (R/W) */ +#define RTIT_STATUS_FILTEREN (1 << 0) +#define RTIT_STATUS_CONTEXTEN (1 << 1) +#define RTIT_STATUS_TRIGGEREN (1 << 2) +#define RTIT_STATUS_ERROR (1 << 4) +#define RTIT_STATUS_STOPPED (1 << 5) +#define RTIT_STATUS_PACKETBYTECNT_S 32 +#define RTIT_STATUS_PACKETBYTECNT_M (0x1ffffULL << RTIT_STATUS_PACKETBYTECNT_S) +#define MSR_IA32_RTIT_CR3_MATCH 0x572 /* Trace Filter CR3 Match Register (R/W) */ +#define MSR_IA32_RTIT_ADDR_A(n) (0x580 + (n) * 2) +#define MSR_IA32_RTIT_ADDR_B(n) (0x581 + (n) * 2) +#define MSR_IA32_RTIT_ADDR0_A 0x580 /* Region 0 Start Address (R/W) */ +#define MSR_IA32_RTIT_ADDR0_B 0x581 /* Region 0 End Address (R/W) */ +#define MSR_IA32_RTIT_ADDR1_A 0x582 /* Region 1 Start Address (R/W) */ +#define MSR_IA32_RTIT_ADDR1_B 0x583 /* Region 1 End Address (R/W) */ +#define MSR_IA32_RTIT_ADDR2_A 0x584 /* Region 2 Start Address (R/W) */ +#define MSR_IA32_RTIT_ADDR2_B 0x585 /* Region 2 End Address (R/W) */ +#define MSR_IA32_RTIT_ADDR3_A 0x586 /* Region 3 Start Address (R/W) */ +#define MSR_IA32_RTIT_ADDR3_B 0x587 /* Region 3 End Address (R/W) */ + +/* Intel Processor Trace Table of Physical Addresses (ToPA). */ +#define TOPA_SIZE_S 6 +#define TOPA_SIZE_M (0xf << TOPA_SIZE_S) +#define TOPA_SIZE_4K (0 << TOPA_SIZE_S) +#define TOPA_SIZE_8K (1 << TOPA_SIZE_S) +#define TOPA_SIZE_16K (2 << TOPA_SIZE_S) +#define TOPA_SIZE_32K (3 << TOPA_SIZE_S) +#define TOPA_SIZE_64K (4 << TOPA_SIZE_S) +#define TOPA_SIZE_128K (5 << TOPA_SIZE_S) +#define TOPA_SIZE_256K (6 << TOPA_SIZE_S) +#define TOPA_SIZE_512K (7 << TOPA_SIZE_S) +#define TOPA_SIZE_1M (8 << TOPA_SIZE_S) +#define TOPA_SIZE_2M (9 << TOPA_SIZE_S) +#define TOPA_SIZE_4M (10 << TOPA_SIZE_S) +#define TOPA_SIZE_8M (11 << TOPA_SIZE_S) +#define TOPA_SIZE_16M (12 << TOPA_SIZE_S) +#define TOPA_SIZE_32M (13 << TOPA_SIZE_S) +#define TOPA_SIZE_64M (14 << TOPA_SIZE_S) +#define TOPA_SIZE_128M (15 << TOPA_SIZE_S) +#define TOPA_STOP (1 << 4) +#define TOPA_INT (1 << 2) +#define TOPA_END (1 << 0) + +/* + * Constants related to MSR's. + */ +#define APICBASE_RESERVED 0x000002ff +#define APICBASE_BSP 0x00000100 +#define APICBASE_X2APIC 0x00000400 +#define APICBASE_ENABLED 0x00000800 +#define APICBASE_ADDRESS 0xfffff000 + +/* MSR_IA32_FEATURE_CONTROL related */ +#define IA32_FEATURE_CONTROL_LOCK 0x01 /* lock bit */ +#define IA32_FEATURE_CONTROL_SMX_EN 0x02 /* enable VMX inside SMX */ +#define IA32_FEATURE_CONTROL_VMX_EN 0x04 /* enable VMX outside SMX */ + +/* MSR IA32_MISC_ENABLE */ +#define IA32_MISC_EN_FASTSTR 0x0000000000000001ULL +#define IA32_MISC_EN_ATCCE 0x0000000000000008ULL +#define IA32_MISC_EN_PERFMON 0x0000000000000080ULL +#define IA32_MISC_EN_PEBSU 0x0000000000001000ULL +#define IA32_MISC_EN_ESSTE 0x0000000000010000ULL +#define IA32_MISC_EN_MONE 0x0000000000040000ULL +#define IA32_MISC_EN_LIMCPUID 0x0000000000400000ULL +#define IA32_MISC_EN_xTPRD 0x0000000000800000ULL +#define IA32_MISC_EN_XDD 0x0000000400000000ULL + +/* + * IA32_SPEC_CTRL and IA32_PRED_CMD MSRs are described in the Intel' + * document 336996-001 Speculative Execution Side Channel Mitigations. + */ +/* MSR IA32_SPEC_CTRL */ +#define IA32_SPEC_CTRL_IBRS 0x00000001 +#define IA32_SPEC_CTRL_STIBP 0x00000002 +#define IA32_SPEC_CTRL_SSBD 0x00000004 + +/* MSR IA32_PRED_CMD */ +#define IA32_PRED_CMD_IBPB_BARRIER 0x0000000000000001ULL + +/* MSR IA32_FLUSH_CMD */ +#define IA32_FLUSH_CMD_L1D 0x00000001 + +/* MSR IA32_MCU_OPT_CTRL */ +#define IA32_RNGDS_MITG_DIS 0x00000001 + +/* MSR IA32_HWP_CAPABILITIES */ +#define IA32_HWP_CAPABILITIES_HIGHEST_PERFORMANCE(x) (((x) >> 0) & 0xff) +#define IA32_HWP_CAPABILITIES_GUARANTEED_PERFORMANCE(x) (((x) >> 8) & 0xff) +#define IA32_HWP_CAPABILITIES_EFFICIENT_PERFORMANCE(x) (((x) >> 16) & 0xff) +#define IA32_HWP_CAPABILITIES_LOWEST_PERFORMANCE(x) (((x) >> 24) & 0xff) + +/* MSR IA32_HWP_REQUEST */ +#define IA32_HWP_REQUEST_MINIMUM_VALID (1ULL << 63) +#define IA32_HWP_REQUEST_MAXIMUM_VALID (1ULL << 62) +#define IA32_HWP_REQUEST_DESIRED_VALID (1ULL << 61) +#define IA32_HWP_REQUEST_EPP_VALID (1ULL << 60) +#define IA32_HWP_REQUEST_ACTIVITY_WINDOW_VALID (1ULL << 59) +#define IA32_HWP_REQUEST_PACKAGE_CONTROL (1ULL << 42) +#define IA32_HWP_ACTIVITY_WINDOW (0x3ffULL << 32) +#define IA32_HWP_REQUEST_ENERGY_PERFORMANCE_PREFERENCE (0xffULL << 24) +#define IA32_HWP_DESIRED_PERFORMANCE (0xffULL << 16) +#define IA32_HWP_REQUEST_MAXIMUM_PERFORMANCE (0xffULL << 8) +#define IA32_HWP_MINIMUM_PERFORMANCE (0xffULL << 0) + +/* + * PAT modes. + */ +#define PAT_UNCACHEABLE 0x00 +#define PAT_WRITE_COMBINING 0x01 +#define PAT_WRITE_THROUGH 0x04 +#define PAT_WRITE_PROTECTED 0x05 +#define PAT_WRITE_BACK 0x06 +#define PAT_UNCACHED 0x07 +#define PAT_VALUE(i, m) ((long long)(m) << (8 * (i))) +#define PAT_MASK(i) PAT_VALUE(i, 0xff) + +/* + * Constants related to MTRRs + */ +#define MTRR_UNCACHEABLE 0x00 +#define MTRR_WRITE_COMBINING 0x01 +#define MTRR_WRITE_THROUGH 0x04 +#define MTRR_WRITE_PROTECTED 0x05 +#define MTRR_WRITE_BACK 0x06 +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 +#define MTRR_CAP_WC 0x0000000000000400 +#define MTRR_CAP_FIXED 0x0000000000000100 +#define MTRR_CAP_VCNT 0x00000000000000ff +#define MTRR_DEF_ENABLE 0x0000000000000800 +#define MTRR_DEF_FIXED_ENABLE 0x0000000000000400 +#define MTRR_DEF_TYPE 0x00000000000000ff +#define MTRR_PHYSBASE_PHYSBASE 0x000ffffffffff000 +#define MTRR_PHYSBASE_TYPE 0x00000000000000ff +#define MTRR_PHYSMASK_PHYSMASK 0x000ffffffffff000 +#define MTRR_PHYSMASK_VALID 0x0000000000000800 + +/* + * Cyrix configuration registers, accessible as IO ports. + */ +#define CCR0 0xc0 /* Configuration control register 0 */ +#define CCR0_NC0 0x01 /* First 64K of each 1M memory region is + non-cacheable */ +#define CCR0_NC1 0x02 /* 640K-1M region is non-cacheable */ +#define CCR0_A20M 0x04 /* Enables A20M# input pin */ +#define CCR0_KEN 0x08 /* Enables KEN# input pin */ +#define CCR0_FLUSH 0x10 /* Enables FLUSH# input pin */ +#define CCR0_BARB 0x20 /* Flushes internal cache when entering hold + state */ +#define CCR0_CO 0x40 /* Cache org: 1=direct mapped, 0=2x set + assoc */ +#define CCR0_SUSPEND 0x80 /* Enables SUSP# and SUSPA# pins */ + +#define CCR1 0xc1 /* Configuration control register 1 */ +#define CCR1_RPL 0x01 /* Enables RPLSET and RPLVAL# pins */ +#define CCR1_SMI 0x02 /* Enables SMM pins */ +#define CCR1_SMAC 0x04 /* System management memory access */ +#define CCR1_MMAC 0x08 /* Main memory access */ +#define CCR1_NO_LOCK 0x10 /* Negate LOCK# */ +#define CCR1_SM3 0x80 /* SMM address space address region 3 */ + +#define CCR2 0xc2 +#define CCR2_WB 0x02 /* Enables WB cache interface pins */ +#define CCR2_SADS 0x02 /* Slow ADS */ +#define CCR2_LOCK_NW 0x04 /* LOCK NW Bit */ +#define CCR2_SUSP_HLT 0x08 /* Suspend on HALT */ +#define CCR2_WT1 0x10 /* WT region 1 */ +#define CCR2_WPR1 0x10 /* Write-protect region 1 */ +#define CCR2_BARB 0x20 /* Flushes write-back cache when entering + hold state. */ +#define CCR2_BWRT 0x40 /* Enables burst write cycles */ +#define CCR2_USE_SUSP 0x80 /* Enables suspend pins */ + +#define CCR3 0xc3 +#define CCR3_SMILOCK 0x01 /* SMM register lock */ +#define CCR3_NMI 0x02 /* Enables NMI during SMM */ +#define CCR3_LINBRST 0x04 /* Linear address burst cycles */ +#define CCR3_SMMMODE 0x08 /* SMM Mode */ +#define CCR3_MAPEN0 0x10 /* Enables Map0 */ +#define CCR3_MAPEN1 0x20 /* Enables Map1 */ +#define CCR3_MAPEN2 0x40 /* Enables Map2 */ +#define CCR3_MAPEN3 0x80 /* Enables Map3 */ + +#define CCR4 0xe8 +#define CCR4_IOMASK 0x07 +#define CCR4_MEM 0x08 /* Enables momory bypassing */ +#define CCR4_DTE 0x10 /* Enables directory table entry cache */ +#define CCR4_FASTFPE 0x20 /* Fast FPU exception */ +#define CCR4_CPUID 0x80 /* Enables CPUID instruction */ + +#define CCR5 0xe9 +#define CCR5_WT_ALLOC 0x01 /* Write-through allocate */ +#define CCR5_SLOP 0x02 /* LOOP instruction slowed down */ +#define CCR5_LBR1 0x10 /* Local bus region 1 */ +#define CCR5_ARREN 0x20 /* Enables ARR region */ + +#define CCR6 0xea + +#define CCR7 0xeb + +/* Performance Control Register (5x86 only). */ +#define PCR0 0x20 +#define PCR0_RSTK 0x01 /* Enables return stack */ +#define PCR0_BTB 0x02 /* Enables branch target buffer */ +#define PCR0_LOOP 0x04 /* Enables loop */ +#define PCR0_AIS 0x08 /* Enables all instrcutions stalled to + serialize pipe. */ +#define PCR0_MLR 0x10 /* Enables reordering of misaligned loads */ +#define PCR0_BTBRT 0x40 /* Enables BTB test register. */ +#define PCR0_LSSER 0x80 /* Disable reorder */ + +/* Device Identification Registers */ +#define DIR0 0xfe +#define DIR1 0xff + +/* + * Machine Check register constants. + */ +#define MCG_CAP_COUNT 0x000000ff +#define MCG_CAP_CTL_P 0x00000100 +#define MCG_CAP_EXT_P 0x00000200 +#define MCG_CAP_CMCI_P 0x00000400 +#define MCG_CAP_TES_P 0x00000800 +#define MCG_CAP_EXT_CNT 0x00ff0000 +#define MCG_CAP_SER_P 0x01000000 +#define MCG_STATUS_RIPV 0x00000001 +#define MCG_STATUS_EIPV 0x00000002 +#define MCG_STATUS_MCIP 0x00000004 +#define MCG_CTL_ENABLE 0xffffffffffffffff +#define MCG_CTL_DISABLE 0x0000000000000000 +#define MSR_MC_CTL(x) (MSR_MC0_CTL + (x) * 4) +#define MSR_MC_STATUS(x) (MSR_MC0_STATUS + (x) * 4) +#define MSR_MC_ADDR(x) (MSR_MC0_ADDR + (x) * 4) +#define MSR_MC_MISC(x) (MSR_MC0_MISC + (x) * 4) +#define MSR_MC_CTL2(x) (MSR_MC0_CTL2 + (x)) /* If MCG_CAP_CMCI_P */ +#define MC_STATUS_MCA_ERROR 0x000000000000ffff +#define MC_STATUS_MODEL_ERROR 0x00000000ffff0000 +#define MC_STATUS_OTHER_INFO 0x01ffffff00000000 +#define MC_STATUS_COR_COUNT 0x001fffc000000000 /* If MCG_CAP_CMCI_P */ +#define MC_STATUS_TES_STATUS 0x0060000000000000 /* If MCG_CAP_TES_P */ +#define MC_STATUS_AR 0x0080000000000000 /* If MCG_CAP_TES_P */ +#define MC_STATUS_S 0x0100000000000000 /* If MCG_CAP_TES_P */ +#define MC_STATUS_PCC 0x0200000000000000 +#define MC_STATUS_ADDRV 0x0400000000000000 +#define MC_STATUS_MISCV 0x0800000000000000 +#define MC_STATUS_EN 0x1000000000000000 +#define MC_STATUS_UC 0x2000000000000000 +#define MC_STATUS_OVER 0x4000000000000000 +#define MC_STATUS_VAL 0x8000000000000000 +#define MC_MISC_RA_LSB 0x000000000000003f /* If MCG_CAP_SER_P */ +#define MC_MISC_ADDRESS_MODE 0x00000000000001c0 /* If MCG_CAP_SER_P */ +#define MC_CTL2_THRESHOLD 0x0000000000007fff +#define MC_CTL2_CMCI_EN 0x0000000040000000 +#define MC_AMDNB_BANK 4 +#define MC_MISC_AMD_VAL 0x8000000000000000 /* Counter presence valid */ +#define MC_MISC_AMD_CNTP 0x4000000000000000 /* Counter present */ +#define MC_MISC_AMD_LOCK 0x2000000000000000 /* Register locked */ +#define MC_MISC_AMD_INTP 0x1000000000000000 /* Int. type can generate interrupts */ +#define MC_MISC_AMD_LVT_MASK 0x00f0000000000000 /* Extended LVT offset */ +#define MC_MISC_AMD_LVT_SHIFT 52 +#define MC_MISC_AMD_CNTEN 0x0008000000000000 /* Counter enabled */ +#define MC_MISC_AMD_INT_MASK 0x0006000000000000 /* Interrupt type */ +#define MC_MISC_AMD_INT_LVT 0x0002000000000000 /* Interrupt via Extended LVT */ +#define MC_MISC_AMD_INT_SMI 0x0004000000000000 /* SMI */ +#define MC_MISC_AMD_OVERFLOW 0x0001000000000000 /* Counter overflow */ +#define MC_MISC_AMD_CNT_MASK 0x00000fff00000000 /* Counter value */ +#define MC_MISC_AMD_CNT_SHIFT 32 +#define MC_MISC_AMD_CNT_MAX 0xfff +#define MC_MISC_AMD_PTR_MASK 0x00000000ff000000 /* Pointer to additional registers */ +#define MC_MISC_AMD_PTR_SHIFT 24 + +/* + * The following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * The address region registers are used to specify the location and + * size for the eight address regions. + * + * ARRx + 0: A31-A24 of start address + * ARRx + 1: A23-A16 of start address + * ARRx + 2: A15-A12 of start address | ARR_SIZE_xx + */ +#define ARR0 0xc4 +#define ARR1 0xc7 +#define ARR2 0xca +#define ARR3 0xcd +#define ARR4 0xd0 +#define ARR5 0xd3 +#define ARR6 0xd6 +#define ARR7 0xd9 + +#define ARR_SIZE_0K 0 +#define ARR_SIZE_4K 1 +#define ARR_SIZE_8K 2 +#define ARR_SIZE_16K 3 +#define ARR_SIZE_32K 4 +#define ARR_SIZE_64K 5 +#define ARR_SIZE_128K 6 +#define ARR_SIZE_256K 7 +#define ARR_SIZE_512K 8 +#define ARR_SIZE_1M 9 +#define ARR_SIZE_2M 10 +#define ARR_SIZE_4M 11 +#define ARR_SIZE_8M 12 +#define ARR_SIZE_16M 13 +#define ARR_SIZE_32M 14 +#define ARR_SIZE_4G 15 + +/* + * The region control registers specify the attributes associated with + * the ARRx addres regions. + */ +#define RCR0 0xdc +#define RCR1 0xdd +#define RCR2 0xde +#define RCR3 0xdf +#define RCR4 0xe0 +#define RCR5 0xe1 +#define RCR6 0xe2 +#define RCR7 0xe3 + +#define RCR_RCD 0x01 /* Disables caching for ARRx (x = 0-6). */ +#define RCR_RCE 0x01 /* Enables caching for ARR7. */ +#define RCR_WWO 0x02 /* Weak write ordering. */ +#define RCR_WL 0x04 /* Weak locking. */ +#define RCR_WG 0x08 /* Write gathering. */ +#define RCR_WT 0x10 /* Write-through. */ +#define RCR_NLB 0x20 /* LBA# pin is not asserted. */ + +/* AMD Write Allocate Top-Of-Memory and Control Register */ +#define AMD_WT_ALLOC_TME 0x40000 /* top-of-memory enable */ +#define AMD_WT_ALLOC_PRE 0x20000 /* programmable range enable */ +#define AMD_WT_ALLOC_FRE 0x10000 /* fixed (A0000-FFFFF) range enable */ + +/* AMD64 MSR's */ +#define MSR_EFER 0xc0000080 /* extended features */ +#define MSR_STAR 0xc0000081 /* legacy mode SYSCALL target/cs/ss */ +#define MSR_LSTAR 0xc0000082 /* long mode SYSCALL target rip */ +#define MSR_CSTAR 0xc0000083 /* compat mode SYSCALL target rip */ +#define MSR_SF_MASK 0xc0000084 /* syscall flags mask */ +#define MSR_FSBASE 0xc0000100 /* base address of the %fs "segment" */ +#define MSR_GSBASE 0xc0000101 /* base address of the %gs "segment" */ +#define MSR_KGSBASE 0xc0000102 /* base address of the kernel %gs */ +#define MSR_TSC_AUX 0xc0000103 +#define MSR_PERFEVSEL0 0xc0010000 +#define MSR_PERFEVSEL1 0xc0010001 +#define MSR_PERFEVSEL2 0xc0010002 +#define MSR_PERFEVSEL3 0xc0010003 +#define MSR_K7_PERFCTR0 0xc0010004 +#define MSR_K7_PERFCTR1 0xc0010005 +#define MSR_K7_PERFCTR2 0xc0010006 +#define MSR_K7_PERFCTR3 0xc0010007 +#define MSR_SYSCFG 0xc0010010 +#define MSR_HWCR 0xc0010015 +#define MSR_IORRBASE0 0xc0010016 +#define MSR_IORRMASK0 0xc0010017 +#define MSR_IORRBASE1 0xc0010018 +#define MSR_IORRMASK1 0xc0010019 +#define MSR_TOP_MEM 0xc001001a /* boundary for ram below 4G */ +#define MSR_TOP_MEM2 0xc001001d /* boundary for ram above 4G */ +#define MSR_NB_CFG1 0xc001001f /* NB configuration 1 */ +#define MSR_K8_UCODE_UPDATE 0xc0010020 /* update microcode */ +#define MSR_MC0_CTL_MASK 0xc0010044 +#define MSR_P_STATE_LIMIT 0xc0010061 /* P-state Current Limit Register */ +#define MSR_P_STATE_CONTROL 0xc0010062 /* P-state Control Register */ +#define MSR_P_STATE_STATUS 0xc0010063 /* P-state Status Register */ +#define MSR_P_STATE_CONFIG(n) (0xc0010064 + (n)) /* P-state Config */ +#define MSR_SMM_ADDR 0xc0010112 /* SMM TSEG base address */ +#define MSR_SMM_MASK 0xc0010113 /* SMM TSEG address mask */ +#define MSR_VM_CR 0xc0010114 /* SVM: feature control */ +#define MSR_VM_HSAVE_PA 0xc0010117 /* SVM: host save area address */ +#define MSR_AMD_CPUID07 0xc0011002 /* CPUID 07 %ebx override */ +#define MSR_EXTFEATURES 0xc0011005 /* Extended CPUID Features override */ +#define MSR_LS_CFG 0xc0011020 +#define MSR_IC_CFG 0xc0011021 /* Instruction Cache Configuration */ + +/* MSR_VM_CR related */ +#define VM_CR_SVMDIS 0x10 /* SVM: disabled by BIOS */ + +/* VIA ACE crypto featureset: for via_feature_rng */ +#define VIA_HAS_RNG 1 /* cpu has RNG */ + +/* VIA ACE crypto featureset: for via_feature_xcrypt */ +#define VIA_HAS_AES 1 /* cpu has AES */ +#define VIA_HAS_SHA 2 /* cpu has SHA1 & SHA256 */ +#define VIA_HAS_MM 4 /* cpu has RSA instructions */ +#define VIA_HAS_AESCTR 8 /* cpu has AES-CTR instructions */ + +/* Centaur Extended Feature flags */ +#define VIA_CPUID_HAS_RNG 0x000004 +#define VIA_CPUID_DO_RNG 0x000008 +#define VIA_CPUID_HAS_ACE 0x000040 +#define VIA_CPUID_DO_ACE 0x000080 +#define VIA_CPUID_HAS_ACE2 0x000100 +#define VIA_CPUID_DO_ACE2 0x000200 +#define VIA_CPUID_HAS_PHE 0x000400 +#define VIA_CPUID_DO_PHE 0x000800 +#define VIA_CPUID_HAS_PMM 0x001000 +#define VIA_CPUID_DO_PMM 0x002000 + +/* VIA ACE xcrypt-* instruction context control options */ +#define VIA_CRYPT_CWLO_ROUND_M 0x0000000f +#define VIA_CRYPT_CWLO_ALG_M 0x00000070 +#define VIA_CRYPT_CWLO_ALG_AES 0x00000000 +#define VIA_CRYPT_CWLO_KEYGEN_M 0x00000080 +#define VIA_CRYPT_CWLO_KEYGEN_HW 0x00000000 +#define VIA_CRYPT_CWLO_KEYGEN_SW 0x00000080 +#define VIA_CRYPT_CWLO_NORMAL 0x00000000 +#define VIA_CRYPT_CWLO_INTERMEDIATE 0x00000100 +#define VIA_CRYPT_CWLO_ENCRYPT 0x00000000 +#define VIA_CRYPT_CWLO_DECRYPT 0x00000200 +#define VIA_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */ +#define VIA_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */ +#define VIA_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */ + +#endif /* !_MACHINE_SPECIALREG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/stack.h b/lib/libc/include/x86_64-freebsd-any/x86/stack.h new file mode 100644 index 000000000000..7f6930a58b37 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/stack.h @@ -0,0 +1,61 @@ +/*- + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD$ + */ + +#ifndef _X86_STACK_H +#define _X86_STACK_H + +/* + * Stack trace. + */ + +#ifdef __i386__ +struct i386_frame { + struct i386_frame *f_frame; + u_int f_retaddr; + u_int f_arg0; +}; +#endif + +#ifdef __amd64__ +struct amd64_frame { + struct amd64_frame *f_frame; + u_long f_retaddr; +}; + +struct i386_frame { + uint32_t f_frame; + uint32_t f_retaddr; + uint32_t f_arg0; +}; +#endif /* __amd64__ */ + +#ifdef _KERNEL +int stack_nmi_handler(struct trapframe *); +#endif + +#endif /* !_X86_STACK_H */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/stdarg.h b/lib/libc/include/x86_64-freebsd-any/x86/stdarg.h new file mode 100644 index 000000000000..acb526429ac2 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/stdarg.h @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2017 Poul-Henning Kamp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_STDARG_H_ +#define _MACHINE_STDARG_H_ + +#include + +#ifndef va_start + #error this file needs to be ported to your compiler +#endif + +#endif /* !_MACHINE_STDARG_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/sysarch.h b/lib/libc/include/x86_64-freebsd-any/x86/sysarch.h new file mode 100644 index 000000000000..eab87add66e0 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/sysarch.h @@ -0,0 +1,167 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1993 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Architecture specific syscalls (X86) + */ +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +#include + +#define I386_GET_LDT 0 +#define I386_SET_LDT 1 +#define LDT_AUTO_ALLOC 0xffffffff + /* I386_IOPL */ +#define I386_GET_IOPERM 3 +#define I386_SET_IOPERM 4 + /* xxxxx */ +#define I386_VM86 6 /* XXX Not implementable on amd64 */ +#define I386_GET_FSBASE 7 +#define I386_SET_FSBASE 8 +#define I386_GET_GSBASE 9 +#define I386_SET_GSBASE 10 +#define I386_GET_XFPUSTATE 11 +#define I386_SET_PKRU 12 +#define I386_CLEAR_PKRU 13 + +/* Leave space for 0-127 for to avoid translating syscalls */ +#define AMD64_GET_FSBASE 128 +#define AMD64_SET_FSBASE 129 +#define AMD64_GET_GSBASE 130 +#define AMD64_SET_GSBASE 131 +#define AMD64_GET_XFPUSTATE 132 +#define AMD64_SET_PKRU 133 +#define AMD64_CLEAR_PKRU 134 + +/* Flags for AMD64_SET_PKRU */ +#define AMD64_PKRU_EXCL 0x0001 +#define AMD64_PKRU_PERSIST 0x0002 + +struct i386_ioperm_args { + unsigned int start; + unsigned int length; + int enable; +}; + +#ifdef __i386__ +struct i386_ldt_args { + unsigned int start; + union descriptor *descs; + unsigned int num; +}; + +struct i386_vm86_args { + int sub_op; /* sub-operation to perform */ + char *sub_args; /* args */ +}; + +struct i386_get_xfpustate { + void *addr; + int len; +}; +#else +struct i386_ldt_args { + unsigned int start; + struct user_segment_descriptor *descs __packed; + unsigned int num; +}; + +struct i386_get_xfpustate { + unsigned int addr; + int len; +}; + +struct i386_set_pkru { + unsigned int addr; + unsigned int len; + unsigned int keyidx; + int flags; +}; + +struct amd64_get_xfpustate { + void *addr; + int len; +}; +#endif + +struct amd64_set_pkru { + void *addr; + unsigned long len; + unsigned int keyidx; + int flags; +}; + +#ifndef _KERNEL +union descriptor; +struct dbreg; + +__BEGIN_DECLS +int i386_get_ldt(int, union descriptor *, int); +int i386_set_ldt(int, union descriptor *, int); +int i386_get_ioperm(unsigned int, unsigned int *, int *); +int i386_set_ioperm(unsigned int, unsigned int, int); +int i386_vm86(int, void *); +int i386_get_fsbase(void **); +int i386_get_gsbase(void **); +int i386_set_fsbase(void *); +int i386_set_gsbase(void *); +int i386_set_watch(int, unsigned int, int, int, struct dbreg *); +int i386_clr_watch(int, struct dbreg *); +int amd64_get_fsbase(void **); +int amd64_get_gsbase(void **); +int amd64_set_fsbase(void *); +int amd64_set_gsbase(void *); +int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); +int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); +int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx, + int flag); +int x86_pkru_unprotect_range(void *addr, unsigned long len); +int sysarch(int, void *); +__END_DECLS +#else +struct thread; +union descriptor; + +int i386_get_ldt(struct thread *, struct i386_ldt_args *); +int i386_set_ldt(struct thread *, struct i386_ldt_args *, union descriptor *); +int i386_get_ioperm(struct thread *, struct i386_ioperm_args *); +int i386_set_ioperm(struct thread *, struct i386_ioperm_args *); +int amd64_get_ldt(struct thread *, struct i386_ldt_args *); +int amd64_set_ldt(struct thread *, struct i386_ldt_args *, + struct user_segment_descriptor *); +int amd64_get_ioperm(struct thread *, struct i386_ioperm_args *); +int amd64_set_ioperm(struct thread *, struct i386_ioperm_args *); +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/trap.h b/lib/libc/include/x86_64-freebsd-any/x86/trap.h new file mode 100644 index 000000000000..74c4522c02a8 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/trap.h @@ -0,0 +1,72 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)trap.h 5.4 (Berkeley) 5/9/91 + * $FreeBSD$ + */ + +#ifndef _MACHINE_TRAP_H_ +#define _MACHINE_TRAP_H_ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 1 /* privileged instruction */ +#define T_BPTFLT 3 /* breakpoint instruction */ +#define T_ARITHTRAP 6 /* arithmetic trap */ +#define T_PROTFLT 9 /* protection fault */ +#define T_TRCTRAP 10 /* debug exception (sic) */ +#define T_PAGEFLT 12 /* page fault */ +#define T_ALIGNFLT 14 /* alignment fault */ + +#define T_DIVIDE 18 /* integer divide fault */ +#define T_NMI 19 /* non-maskable trap */ +#define T_OFLOW 20 /* overflow trap */ +#define T_BOUND 21 /* bound instruction fault */ +#define T_DNA 22 /* device not available fault */ +#define T_DOUBLEFLT 23 /* double fault */ +#define T_FPOPFLT 24 /* fp coprocessor operand fetch fault */ +#define T_TSSFLT 25 /* invalid tss fault */ +#define T_SEGNPFLT 26 /* segment not present fault */ +#define T_STKFLT 27 /* stack fault */ +#define T_MCHK 28 /* machine check trap */ +#define T_XMMFLT 29 /* SIMD floating-point exception */ +#define T_RESERVED 30 /* reserved (unknown) */ +#define T_DTRACE_RET 32 /* DTrace pid return */ + +/* Trap's coming from user mode */ +#define T_USER 0x100 + +#endif /* !_MACHINE_TRAP_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/ucode.h b/lib/libc/include/x86_64-freebsd-any/x86/ucode.h new file mode 100644 index 000000000000..5c8868108930 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/ucode.h @@ -0,0 +1,68 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018 The FreeBSD Foundation + * + * This software was developed by Mark Johnston under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_UCODE_H_ +#define _MACHINE_UCODE_H_ + +struct ucode_intel_header { + uint32_t header_version; + int32_t update_revision; + uint32_t dat; + uint32_t processor_signature; + uint32_t checksum; + uint32_t loader_revision; + uint32_t processor_flags; +#define UCODE_INTEL_DEFAULT_DATA_SIZE 2000 + uint32_t data_size; + uint32_t total_size; + uint32_t reserved[3]; +}; + +struct ucode_intel_extsig_table { + uint32_t signature_count; + uint32_t signature_table_checksum; + uint32_t reserved[3]; + struct ucode_intel_extsig { + uint32_t processor_signature; + uint32_t processor_flags; + uint32_t checksum; + } entries[0]; +}; + +int ucode_intel_load(void *data, bool unsafe, + uint64_t *nrevp, uint64_t *orevp); +size_t ucode_load_bsp(uintptr_t free); +void ucode_load_ap(int cpu); +void ucode_reload(void); +void * ucode_update(void *data); + +#endif /* _MACHINE_UCODE_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/ucontext.h b/lib/libc/include/x86_64-freebsd-any/x86/ucontext.h new file mode 100644 index 000000000000..407ef43be9dc --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/ucontext.h @@ -0,0 +1,167 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2003 Peter Wemm + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_UCONTEXT_H_ +#define _X86_UCONTEXT_H_ + +#ifdef __i386__ +/* Keep _MC_* values similar to amd64 */ +#define _MC_HASSEGS 0x1 +#define _MC_HASBASES 0x2 +#define _MC_HASFPXSTATE 0x4 +#define _MC_FLAG_MASK (_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE) + +typedef struct __mcontext { + /* + * The definition of mcontext_t must match the layout of + * struct sigcontext after the sc_mask member. This is so + * that we can support sigcontext and ucontext_t at the same + * time. + */ + __register_t mc_onstack; /* XXX - sigcontext compat. */ + __register_t mc_gs; /* machine state (struct trapframe) */ + __register_t mc_fs; + __register_t mc_es; + __register_t mc_ds; + __register_t mc_edi; + __register_t mc_esi; + __register_t mc_ebp; + __register_t mc_isp; + __register_t mc_ebx; + __register_t mc_edx; + __register_t mc_ecx; + __register_t mc_eax; + __register_t mc_trapno; + __register_t mc_err; + __register_t mc_eip; + __register_t mc_cs; + __register_t mc_eflags; + __register_t mc_esp; + __register_t mc_ss; + + int mc_len; /* sizeof(mcontext_t) */ +#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ +#define _MC_FPFMT_387 0x10001 +#define _MC_FPFMT_XMM 0x10002 + int mc_fpformat; +#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ +#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ +#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ + int mc_ownedfp; + __register_t mc_flags; + /* + * See for the internals of mc_fpstate[]. + */ + int mc_fpstate[128] __aligned(16); + + __register_t mc_fsbase; + __register_t mc_gsbase; + + __register_t mc_xfpustate; + __register_t mc_xfpustate_len; + + int mc_spare2[4]; +} mcontext_t; +#endif /* __i386__ */ + +#ifdef __amd64__ +/* + * mc_flags bits. Shall be in sync with TF_XXX. + */ +#define _MC_HASSEGS 0x1 +#define _MC_HASBASES 0x2 +#define _MC_HASFPXSTATE 0x4 +#define _MC_FLAG_MASK (_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE) + +typedef struct __mcontext { + /* + * The definition of mcontext_t must match the layout of + * struct sigcontext after the sc_mask member. This is so + * that we can support sigcontext and ucontext_t at the same + * time. + */ + __register_t mc_onstack; /* XXX - sigcontext compat. */ + __register_t mc_rdi; /* machine state (struct trapframe) */ + __register_t mc_rsi; + __register_t mc_rdx; + __register_t mc_rcx; + __register_t mc_r8; + __register_t mc_r9; + __register_t mc_rax; + __register_t mc_rbx; + __register_t mc_rbp; + __register_t mc_r10; + __register_t mc_r11; + __register_t mc_r12; + __register_t mc_r13; + __register_t mc_r14; + __register_t mc_r15; + __uint32_t mc_trapno; + __uint16_t mc_fs; + __uint16_t mc_gs; + __register_t mc_addr; + __uint32_t mc_flags; + __uint16_t mc_es; + __uint16_t mc_ds; + __register_t mc_err; + __register_t mc_rip; + __register_t mc_cs; + __register_t mc_rflags; + __register_t mc_rsp; + __register_t mc_ss; + + long mc_len; /* sizeof(mcontext_t) */ + +#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ +#define _MC_FPFMT_XMM 0x10002 + long mc_fpformat; +#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ +#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ +#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ + long mc_ownedfp; + /* + * See for the internals of mc_fpstate[]. + */ + long mc_fpstate[64] __aligned(16); + + __register_t mc_fsbase; + __register_t mc_gsbase; + + __register_t mc_xfpustate; + __register_t mc_xfpustate_len; + + long mc_spare[4]; +} mcontext_t; +#endif /* __amd64__ */ + +#endif /* !_X86_UCONTEXT_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/vdso.h b/lib/libc/include/x86_64-freebsd-any/x86/vdso.h new file mode 100644 index 000000000000..97972c660dde --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/vdso.h @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 2012 Konstantin Belousov . + * Copyright 2016 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_VDSO_H +#define _X86_VDSO_H + +#define VDSO_TIMEHANDS_MD \ + uint32_t th_x86_shift; \ + uint32_t th_x86_hpet_idx; \ + uint32_t th_res[6]; + +#define VDSO_TH_ALGO_X86_TSC VDSO_TH_ALGO_1 +#define VDSO_TH_ALGO_X86_HPET VDSO_TH_ALGO_2 +#define VDSO_TH_ALGO_X86_HVTSC VDSO_TH_ALGO_3 /* Hyper-V ref. TSC */ + +#ifdef _KERNEL +#ifdef COMPAT_FREEBSD32 + +#define VDSO_TIMEHANDS_MD32 VDSO_TIMEHANDS_MD + +#endif +#endif +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/vmware.h b/lib/libc/include/x86_64-freebsd-any/x86/vmware.h new file mode 100644 index 000000000000..d3d7e2dca1da --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/vmware.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2011-2014 Jung-uk Kim + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_VMWARE_H_ +#define _X86_VMWARE_H_ + +#define VMW_HVMAGIC 0x564d5868 +#define VMW_HVPORT 0x5658 + +#define VMW_HVCMD_GETVERSION 10 +#define VMW_HVCMD_GETHZ 45 +#define VMW_HVCMD_GETVCPU_INFO 68 + +#define VMW_VCPUINFO_LEGACY_X2APIC (1 << 3) +#define VMW_VCPUINFO_VCPU_RESERVED (1 << 31) + +static __inline void +vmware_hvcall(u_int cmd, u_int *p) +{ + + __asm __volatile("inl %w3, %0" + : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) + : "0" (VMW_HVMAGIC), "1" (UINT_MAX), "2" (cmd), "3" (VMW_HVPORT) + : "memory"); +} + +#endif /* !_X86_VMWARE_H_ */ diff --git a/lib/libc/include/x86_64-freebsd-any/x86/x86_smp.h b/lib/libc/include/x86_64-freebsd-any/x86/x86_smp.h new file mode 100644 index 000000000000..9bb05d9038ab --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/x86_smp.h @@ -0,0 +1,119 @@ +/*- + * SPDX-License-Identifier: Beerware + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + * + */ + +#ifndef _X86_X86_SMP_H_ +#define _X86_X86_SMP_H_ + +#include +#include +#include +#include +#include + +struct pmap; + +/* global data in mp_x86.c */ +extern int mp_naps; +extern int boot_cpu_id; +extern struct pcb stoppcbs[]; +extern int cpu_apic_ids[]; +extern int bootAP; +extern void *dpcpu; +extern char *bootSTK; +extern void *bootstacks[]; +extern unsigned int boot_address; +extern unsigned int bootMP_size; +extern volatile u_int cpu_ipi_pending[]; +extern volatile int aps_ready; +extern struct mtx ap_boot_mtx; +extern int cpu_logical; +extern int cpu_cores; +extern volatile uint32_t smp_tlb_generation; +extern struct pmap *smp_tlb_pmap; +extern vm_offset_t smp_tlb_addr1, smp_tlb_addr2; +extern u_int xhits_gbl[]; +extern u_int xhits_pg[]; +extern u_int xhits_rng[]; +extern u_int ipi_global; +extern u_int ipi_page; +extern u_int ipi_range; +extern u_int ipi_range_size; + +extern int nmi_kdb_lock; +extern int nmi_is_broadcast; + +struct cpu_info { + int cpu_present:1; + int cpu_bsp:1; + int cpu_disabled:1; + int cpu_hyperthread:1; +}; +extern struct cpu_info *cpu_info; + +#ifdef COUNT_IPIS +extern u_long *ipi_invltlb_counts[MAXCPU]; +extern u_long *ipi_invlrng_counts[MAXCPU]; +extern u_long *ipi_invlpg_counts[MAXCPU]; +extern u_long *ipi_invlcache_counts[MAXCPU]; +extern u_long *ipi_rendezvous_counts[MAXCPU]; +#endif + +/* IPI handlers */ +inthand_t + IDTVEC(invltlb), /* TLB shootdowns - global */ + IDTVEC(invlpg), /* TLB shootdowns - 1 page */ + IDTVEC(invlrng), /* TLB shootdowns - page range */ + IDTVEC(invlcache), /* Write back and invalidate cache */ + IDTVEC(ipi_intr_bitmap_handler), /* Bitmap based IPIs */ + IDTVEC(ipi_swi), /* Runs delayed SWI */ + IDTVEC(cpustop), /* CPU stops & waits to be restarted */ + IDTVEC(cpususpend), /* CPU suspends & waits to be resumed */ + IDTVEC(rendezvous); /* handle CPU rendezvous */ + +typedef void (*smp_invl_cb_t)(struct pmap *, vm_offset_t addr1, + vm_offset_t addr2); + +/* functions in x86_mp.c */ +void assign_cpu_ids(void); +void cpu_add(u_int apic_id, char boot_cpu); +void cpustop_handler(void); +void cpususpend_handler(void); +void alloc_ap_trampoline(vm_paddr_t *physmap, unsigned int *physmap_idx); +void init_secondary_tail(void); +void invltlb_handler(void); +void invlpg_handler(void); +void invlrng_handler(void); +void invlcache_handler(void); +void init_secondary(void); +void ipi_startup(int apic_id, int vector); +void ipi_all_but_self(u_int ipi); +void ipi_bitmap_handler(struct trapframe frame); +void ipi_cpu(int cpu, u_int ipi); +int ipi_nmi_handler(void); +void ipi_swi_handler(struct trapframe frame); +void ipi_selected(cpuset_t cpus, u_int ipi); +void ipi_self_from_nmi(u_int vector); +void set_interrupt_apic_ids(void); +void smp_cache_flush(smp_invl_cb_t curcpu_cb); +void smp_masked_invlpg(cpuset_t mask, vm_offset_t addr, struct pmap *pmap, + smp_invl_cb_t curcpu_cb); +void smp_masked_invlpg_range(cpuset_t mask, vm_offset_t startva, + vm_offset_t endva, struct pmap *pmap, smp_invl_cb_t curcpu_cb); +void smp_masked_invltlb(cpuset_t mask, struct pmap *pmap, + smp_invl_cb_t curcpu_cb); +void mem_range_AP_init(void); +void topo_probe(void); +void ipi_send_cpu(int cpu, u_int ipi); + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/x86_var.h b/lib/libc/include/x86_64-freebsd-any/x86/x86_var.h new file mode 100644 index 000000000000..e6d5d088ebe7 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/x86_var.h @@ -0,0 +1,169 @@ +/*- + * Copyright (c) 1995 Bruce D. Evans. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _X86_X86_VAR_H_ +#define _X86_X86_VAR_H_ + +/* + * Miscellaneous machine-dependent declarations. + */ + +extern long Maxmem; +extern u_int basemem; +extern int busdma_swi_pending; +extern u_int cpu_exthigh; +extern u_int cpu_feature; +extern u_int cpu_feature2; +extern u_int amd_feature; +extern u_int amd_feature2; +extern u_int amd_rascap; +extern u_int amd_pminfo; +extern u_int amd_extended_feature_extensions; +extern u_int via_feature_rng; +extern u_int via_feature_xcrypt; +extern u_int cpu_clflush_line_size; +extern u_int cpu_stdext_feature; +extern u_int cpu_stdext_feature2; +extern u_int cpu_stdext_feature3; +extern uint64_t cpu_ia32_arch_caps; +extern u_int cpu_fxsr; +extern u_int cpu_high; +extern u_int cpu_id; +extern u_int cpu_max_ext_state_size; +extern u_int cpu_mxcsr_mask; +extern u_int cpu_procinfo; +extern u_int cpu_procinfo2; +extern char cpu_vendor[]; +extern u_int cpu_vendor_id; +extern u_int cpu_mon_mwait_flags; +extern u_int cpu_mon_min_size; +extern u_int cpu_mon_max_size; +extern u_int cpu_maxphyaddr; +extern char ctx_switch_xsave[]; +extern u_int hv_high; +extern char hv_vendor[]; +extern char kstack[]; +extern char sigcode[]; +extern int szsigcode; +extern int vm_page_dump_size; +extern int workaround_erratum383; +extern int _udatasel; +extern int _ucodesel; +extern int _ucode32sel; +extern int _ufssel; +extern int _ugssel; +extern int use_xsave; +extern uint64_t xsave_mask; +extern u_int max_apic_id; +extern int pti; +extern int hw_ibrs_ibpb_active; +extern int hw_mds_disable; +extern int hw_ssb_active; +extern int x86_taa_enable; +extern int cpu_flush_rsb_ctxsw; +extern int x86_rngds_mitg_enable; + +struct pcb; +struct thread; +struct reg; +struct fpreg; +struct dbreg; +struct dumperinfo; +struct trapframe; + +/* + * The interface type of the interrupt handler entry point cannot be + * expressed in C. Use simplest non-variadic function type as an + * approximation. + */ +typedef void alias_for_inthand_t(void); + +/* + * Returns the maximum physical address that can be used with the + * current system. + */ +static __inline vm_paddr_t +cpu_getmaxphyaddr(void) +{ +#if defined(__i386__) && !defined(PAE) + return (0xffffffff); +#else + return ((1ULL << cpu_maxphyaddr) - 1); +#endif +} + +bool acpi_get_fadt_bootflags(uint16_t *flagsp); +void *alloc_fpusave(int flags); +void busdma_swi(void); +bool cpu_mwait_usable(void); +void cpu_probe_amdc1e(void); +void cpu_setregs(void); +bool disable_wp(void); +void restore_wp(bool old_wp); +void dump_add_page(vm_paddr_t); +void dump_drop_page(vm_paddr_t); +void finishidentcpu(void); +void identify_cpu1(void); +void identify_cpu2(void); +void identify_cpu_fixup_bsp(void); +void identify_hypervisor(void); +void initializecpu(void); +void initializecpucache(void); +bool fix_cpuid(void); +void fillw(int /*u_short*/ pat, void *base, size_t cnt); +int is_physical_memory(vm_paddr_t addr); +int isa_nmi(int cd); +void handle_ibrs_entry(void); +void handle_ibrs_exit(void); +void hw_ibrs_recalculate(bool all_cpus); +void hw_mds_recalculate(void); +void hw_ssb_recalculate(bool all_cpus); +void x86_taa_recalculate(void); +void x86_rngds_mitg_recalculate(bool all_cpus); +void nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame); +void nmi_call_kdb_smp(u_int type, struct trapframe *frame); +void nmi_handle_intr(u_int type, struct trapframe *frame); +void pagecopy(void *from, void *to); +void printcpuinfo(void); +int pti_get_default(void); +int user_dbreg_trap(register_t dr6); +int minidumpsys(struct dumperinfo *); +struct pcb *get_pcb_td(struct thread *td); + +#define MSR_OP_ANDNOT 0x00000001 +#define MSR_OP_OR 0x00000002 +#define MSR_OP_WRITE 0x00000003 +#define MSR_OP_LOCAL 0x10000000 +#define MSR_OP_SCHED 0x20000000 +#define MSR_OP_RENDEZVOUS 0x30000000 +void x86_msr_op(u_int msr, u_int op, uint64_t arg1); + +#endif diff --git a/lib/libc/include/x86_64-freebsd-any/x86/xen/xen-os.h b/lib/libc/include/x86_64-freebsd-any/x86/xen/xen-os.h new file mode 100644 index 000000000000..115310520af0 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/x86/xen/xen-os.h @@ -0,0 +1,38 @@ +/***************************************************************************** + * x86/xen/xen-os.h + * + * Random collection of macros and definition + * + * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team) + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_X86_XEN_XEN_OS_H_ +#define _MACHINE_X86_XEN_XEN_OS_H_ + +/* Everything below this point is not included by assembler (.S) files. */ +#ifndef __ASSEMBLY__ + +#endif /* !__ASSEMBLY__ */ + +#endif /* _MACHINE_X86_XEN_XEN_OS_H_ */ From 48f84037e808edaf458077aa54e1c4c59476a3eb Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 22 Mar 2021 00:22:24 -0700 Subject: [PATCH 3/5] freebsd: add libc headers brought out to the top level --- lib/libc/include/any-freebsd-any/_semaphore.h | 1 + lib/libc/include/any-freebsd-any/aio.h | 1 + lib/libc/include/any-freebsd-any/errno.h | 1 + lib/libc/include/any-freebsd-any/fcntl.h | 1 + lib/libc/include/any-freebsd-any/linker_set.h | 1 + lib/libc/include/any-freebsd-any/poll.h | 1 + lib/libc/include/any-freebsd-any/sched.h | 1 + lib/libc/include/any-freebsd-any/stdatomic.h | 1 + lib/libc/include/any-freebsd-any/stdint.h | 1 + lib/libc/include/any-freebsd-any/ucontext.h | 1 + lib/libc/include/x86_64-freebsd-any/float.h | 1 + lib/libc/include/x86_64-freebsd-any/floatingpoint.h | 1 + lib/libc/include/x86_64-freebsd-any/stdarg.h | 1 + 13 files changed, 13 insertions(+) create mode 120000 lib/libc/include/any-freebsd-any/_semaphore.h create mode 120000 lib/libc/include/any-freebsd-any/aio.h create mode 120000 lib/libc/include/any-freebsd-any/errno.h create mode 120000 lib/libc/include/any-freebsd-any/fcntl.h create mode 120000 lib/libc/include/any-freebsd-any/linker_set.h create mode 120000 lib/libc/include/any-freebsd-any/poll.h create mode 120000 lib/libc/include/any-freebsd-any/sched.h create mode 120000 lib/libc/include/any-freebsd-any/stdatomic.h create mode 120000 lib/libc/include/any-freebsd-any/stdint.h create mode 120000 lib/libc/include/any-freebsd-any/ucontext.h create mode 120000 lib/libc/include/x86_64-freebsd-any/float.h create mode 120000 lib/libc/include/x86_64-freebsd-any/floatingpoint.h create mode 120000 lib/libc/include/x86_64-freebsd-any/stdarg.h diff --git a/lib/libc/include/any-freebsd-any/_semaphore.h b/lib/libc/include/any-freebsd-any/_semaphore.h new file mode 120000 index 000000000000..3de1c44f24b8 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/_semaphore.h @@ -0,0 +1 @@ +sys/_semaphore.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/aio.h b/lib/libc/include/any-freebsd-any/aio.h new file mode 120000 index 000000000000..f2c34b9c1810 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/aio.h @@ -0,0 +1 @@ +sys/aio.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/errno.h b/lib/libc/include/any-freebsd-any/errno.h new file mode 120000 index 000000000000..728006334d3c --- /dev/null +++ b/lib/libc/include/any-freebsd-any/errno.h @@ -0,0 +1 @@ +sys/errno.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/fcntl.h b/lib/libc/include/any-freebsd-any/fcntl.h new file mode 120000 index 000000000000..b5c3c644b575 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/fcntl.h @@ -0,0 +1 @@ +sys/fcntl.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/linker_set.h b/lib/libc/include/any-freebsd-any/linker_set.h new file mode 120000 index 000000000000..149454523689 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/linker_set.h @@ -0,0 +1 @@ +sys/linker_set.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/poll.h b/lib/libc/include/any-freebsd-any/poll.h new file mode 120000 index 000000000000..b235bad75599 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/poll.h @@ -0,0 +1 @@ +sys/poll.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/sched.h b/lib/libc/include/any-freebsd-any/sched.h new file mode 120000 index 000000000000..583d8e0bdd79 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/sched.h @@ -0,0 +1 @@ +sys/sched.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/stdatomic.h b/lib/libc/include/any-freebsd-any/stdatomic.h new file mode 120000 index 000000000000..eb9140457eb6 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdatomic.h @@ -0,0 +1 @@ +sys/stdatomic.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/stdint.h b/lib/libc/include/any-freebsd-any/stdint.h new file mode 120000 index 000000000000..a7a8003fe092 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/stdint.h @@ -0,0 +1 @@ +sys/stdint.h \ No newline at end of file diff --git a/lib/libc/include/any-freebsd-any/ucontext.h b/lib/libc/include/any-freebsd-any/ucontext.h new file mode 120000 index 000000000000..24d0b5c275d7 --- /dev/null +++ b/lib/libc/include/any-freebsd-any/ucontext.h @@ -0,0 +1 @@ +sys/ucontext.h \ No newline at end of file diff --git a/lib/libc/include/x86_64-freebsd-any/float.h b/lib/libc/include/x86_64-freebsd-any/float.h new file mode 120000 index 000000000000..4326e7f16dc4 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/float.h @@ -0,0 +1 @@ +machine/float.h \ No newline at end of file diff --git a/lib/libc/include/x86_64-freebsd-any/floatingpoint.h b/lib/libc/include/x86_64-freebsd-any/floatingpoint.h new file mode 120000 index 000000000000..b767db107566 --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/floatingpoint.h @@ -0,0 +1 @@ +machine/floatingpoint.h \ No newline at end of file diff --git a/lib/libc/include/x86_64-freebsd-any/stdarg.h b/lib/libc/include/x86_64-freebsd-any/stdarg.h new file mode 120000 index 000000000000..267018a5bd9a --- /dev/null +++ b/lib/libc/include/x86_64-freebsd-any/stdarg.h @@ -0,0 +1 @@ +machine/stdarg.h \ No newline at end of file From e8a04f56441736a106fb9ca05b39f8ed7a9cf538 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 22 Mar 2021 00:23:32 -0700 Subject: [PATCH 4/5] stage2: add x86_64-freebsd-gnu to available_libcs --- src/target.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/target.zig b/src/target.zig index 5a884271cca2..ae8b9c170dbe 100644 --- a/src/target.zig +++ b/src/target.zig @@ -51,6 +51,7 @@ pub const available_libcs = [_]ArchOsAbi{ .{ .arch = .sparc, .os = .linux, .abi = .gnu }, .{ .arch = .sparcv9, .os = .linux, .abi = .gnu }, .{ .arch = .wasm32, .os = .freestanding, .abi = .musl }, + .{ .arch = .x86_64, .os = .freebsd, .abi = .gnu }, .{ .arch = .x86_64, .os = .linux, .abi = .gnu }, .{ .arch = .x86_64, .os = .linux, .abi = .gnux32 }, .{ .arch = .x86_64, .os = .linux, .abi = .musl }, @@ -62,6 +63,7 @@ pub fn libCGenericName(target: std.Target) [:0]const u8 { switch (target.os.tag) { .windows => return "mingw", .macos, .ios, .tvos, .watchos => return "darwin", + .freebsd => return "bsd", else => {}, } switch (target.abi) { From bcbf94cf3b8716701e04ee5c6fba5454b9a9150a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 22 Mar 2021 00:24:17 -0700 Subject: [PATCH 5/5] std: os: add freebsd impl to getFdPath --- lib/std/os.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index 362a58f7fba7..abd475c197c4 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4405,6 +4405,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { }; return target; }, + .freebsd => unreachable, else => @compileError("querying for canonical path of a handle is unsupported on this host"), } }