13cab2bb3Spatrick //===-- sanitizer_freebsd.h -------------------------------------*- C++ -*-===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick //
93cab2bb3Spatrick // This file is a part of Sanitizer runtime. It contains FreeBSD-specific
103cab2bb3Spatrick // definitions.
113cab2bb3Spatrick //
123cab2bb3Spatrick //===----------------------------------------------------------------------===//
133cab2bb3Spatrick 
143cab2bb3Spatrick #ifndef SANITIZER_FREEBSD_H
153cab2bb3Spatrick #define SANITIZER_FREEBSD_H
163cab2bb3Spatrick 
173cab2bb3Spatrick #include "sanitizer_internal_defs.h"
183cab2bb3Spatrick 
193cab2bb3Spatrick // x86-64 FreeBSD 9.2 and older define 'ucontext_t' incorrectly in
203cab2bb3Spatrick // 32-bit mode.
213cab2bb3Spatrick #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32)
223cab2bb3Spatrick #include <osreldate.h>
233cab2bb3Spatrick #if __FreeBSD_version <= 902001  // v9.2
243cab2bb3Spatrick #include <link.h>
253cab2bb3Spatrick #include <sys/param.h>
263cab2bb3Spatrick #include <ucontext.h>
273cab2bb3Spatrick 
283cab2bb3Spatrick namespace __sanitizer {
293cab2bb3Spatrick 
303cab2bb3Spatrick typedef unsigned long long __xuint64_t;
313cab2bb3Spatrick 
323cab2bb3Spatrick typedef __int32_t __xregister_t;
333cab2bb3Spatrick 
343cab2bb3Spatrick typedef struct __xmcontext {
353cab2bb3Spatrick   __xregister_t mc_onstack;
363cab2bb3Spatrick   __xregister_t mc_gs;
373cab2bb3Spatrick   __xregister_t mc_fs;
383cab2bb3Spatrick   __xregister_t mc_es;
393cab2bb3Spatrick   __xregister_t mc_ds;
403cab2bb3Spatrick   __xregister_t mc_edi;
413cab2bb3Spatrick   __xregister_t mc_esi;
423cab2bb3Spatrick   __xregister_t mc_ebp;
433cab2bb3Spatrick   __xregister_t mc_isp;
443cab2bb3Spatrick   __xregister_t mc_ebx;
453cab2bb3Spatrick   __xregister_t mc_edx;
463cab2bb3Spatrick   __xregister_t mc_ecx;
473cab2bb3Spatrick   __xregister_t mc_eax;
483cab2bb3Spatrick   __xregister_t mc_trapno;
493cab2bb3Spatrick   __xregister_t mc_err;
503cab2bb3Spatrick   __xregister_t mc_eip;
513cab2bb3Spatrick   __xregister_t mc_cs;
523cab2bb3Spatrick   __xregister_t mc_eflags;
533cab2bb3Spatrick   __xregister_t mc_esp;
543cab2bb3Spatrick   __xregister_t mc_ss;
553cab2bb3Spatrick 
563cab2bb3Spatrick   int mc_len;
573cab2bb3Spatrick   int mc_fpformat;
583cab2bb3Spatrick   int mc_ownedfp;
593cab2bb3Spatrick   __xregister_t mc_flags;
603cab2bb3Spatrick 
613cab2bb3Spatrick   int mc_fpstate[128] __aligned(16);
623cab2bb3Spatrick   __xregister_t mc_fsbase;
633cab2bb3Spatrick   __xregister_t mc_gsbase;
643cab2bb3Spatrick   __xregister_t mc_xfpustate;
653cab2bb3Spatrick   __xregister_t mc_xfpustate_len;
663cab2bb3Spatrick 
673cab2bb3Spatrick   int mc_spare2[4];
683cab2bb3Spatrick } xmcontext_t;
693cab2bb3Spatrick 
703cab2bb3Spatrick typedef struct __xucontext {
713cab2bb3Spatrick   sigset_t uc_sigmask;
723cab2bb3Spatrick   xmcontext_t uc_mcontext;
733cab2bb3Spatrick 
743cab2bb3Spatrick   struct __ucontext *uc_link;
753cab2bb3Spatrick   stack_t uc_stack;
763cab2bb3Spatrick   int uc_flags;
773cab2bb3Spatrick   int __spare__[4];
783cab2bb3Spatrick } xucontext_t;
793cab2bb3Spatrick 
803cab2bb3Spatrick struct xkinfo_vmentry {
813cab2bb3Spatrick   int kve_structsize;
823cab2bb3Spatrick   int kve_type;
833cab2bb3Spatrick   __xuint64_t kve_start;
843cab2bb3Spatrick   __xuint64_t kve_end;
853cab2bb3Spatrick   __xuint64_t kve_offset;
863cab2bb3Spatrick   __xuint64_t kve_vn_fileid;
873cab2bb3Spatrick   __uint32_t kve_vn_fsid;
883cab2bb3Spatrick   int kve_flags;
893cab2bb3Spatrick   int kve_resident;
903cab2bb3Spatrick   int kve_private_resident;
913cab2bb3Spatrick   int kve_protection;
923cab2bb3Spatrick   int kve_ref_count;
933cab2bb3Spatrick   int kve_shadow_count;
943cab2bb3Spatrick   int kve_vn_type;
953cab2bb3Spatrick   __xuint64_t kve_vn_size;
963cab2bb3Spatrick   __uint32_t kve_vn_rdev;
973cab2bb3Spatrick   __uint16_t kve_vn_mode;
983cab2bb3Spatrick   __uint16_t kve_status;
993cab2bb3Spatrick   int _kve_ispare[12];
1003cab2bb3Spatrick   char kve_path[PATH_MAX];
1013cab2bb3Spatrick };
1023cab2bb3Spatrick 
1033cab2bb3Spatrick typedef struct {
1043cab2bb3Spatrick   __uint32_t p_type;
1053cab2bb3Spatrick   __uint32_t p_offset;
1063cab2bb3Spatrick   __uint32_t p_vaddr;
1073cab2bb3Spatrick   __uint32_t p_paddr;
1083cab2bb3Spatrick   __uint32_t p_filesz;
1093cab2bb3Spatrick   __uint32_t p_memsz;
1103cab2bb3Spatrick   __uint32_t p_flags;
1113cab2bb3Spatrick   __uint32_t p_align;
1123cab2bb3Spatrick } XElf32_Phdr;
1133cab2bb3Spatrick 
1143cab2bb3Spatrick struct xdl_phdr_info {
1153cab2bb3Spatrick   Elf_Addr dlpi_addr;
1163cab2bb3Spatrick   const char *dlpi_name;
1173cab2bb3Spatrick   const XElf32_Phdr *dlpi_phdr;
1183cab2bb3Spatrick   Elf_Half dlpi_phnum;
1193cab2bb3Spatrick   unsigned long long int dlpi_adds;
1203cab2bb3Spatrick   unsigned long long int dlpi_subs;
1213cab2bb3Spatrick   size_t dlpi_tls_modid;
1223cab2bb3Spatrick   void *dlpi_tls_data;
1233cab2bb3Spatrick };
1243cab2bb3Spatrick 
125*1f9cb04fSpatrick typedef int (*__xdl_iterate_hdr_callback)(struct xdl_phdr_info *, size_t,
126*1f9cb04fSpatrick                                           void *);
1273cab2bb3Spatrick typedef int xdl_iterate_phdr_t(__xdl_iterate_hdr_callback, void *);
1283cab2bb3Spatrick 
1293cab2bb3Spatrick #define xdl_iterate_phdr(callback, param) \
1303cab2bb3Spatrick   (((xdl_iterate_phdr_t *)dl_iterate_phdr)((callback), (param)))
1313cab2bb3Spatrick 
1323cab2bb3Spatrick }  // namespace __sanitizer
1333cab2bb3Spatrick 
1343cab2bb3Spatrick #endif  // __FreeBSD_version <= 902001
1353cab2bb3Spatrick #endif  // SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32)
1363cab2bb3Spatrick 
1373cab2bb3Spatrick #endif  // SANITIZER_FREEBSD_H
138