| 1 |
/* Copyright 2022, David Anderson |
| 2 |
This trivial set of defines is hereby placed in the public domain |
| 3 |
for all to use without restriction. |
| 4 |
*/ |
| 5 |
/* To enable printing with printf regardless of the |
| 6 |
actual underlying data type, we define the DW_PR_xxx macros. |
| 7 |
To ensure uses of DW_PR_DUx or DW_PR_DSx look the way you want |
| 8 |
ensure the DW_PR_XZEROS define as you want it. |
| 9 |
*/ |
| 10 |
#ifndef LIBDWARF_PRIVATE_H |
| 11 |
#define LIBDWARF_PRIVATE_H |
| 12 |
#define DW_PR_XZEROS "08" |
| 13 |
|
| 14 |
#if defined(_WIN32) && defined(_MSC_VER) |
| 15 |
#define DW_PR_DUx "I64x" |
| 16 |
#define DW_PR_DSx "I64x" |
| 17 |
#define DW_PR_DUu "I64u" |
| 18 |
#define DW_PR_DSd "I64d" |
| 19 |
#else |
| 20 |
#define DW_PR_DUx "llx" |
| 21 |
#define DW_PR_DSx "llx" |
| 22 |
#define DW_PR_DUu "llu" |
| 23 |
#define DW_PR_DSd "lld" |
| 24 |
#endif /* DW_PR defines */ |
| 25 |
|
| 26 |
#ifdef _MSC_VER /* Macro to select VS compiler */ |
| 27 |
#include <windows.h> |
| 28 |
typedef SSIZE_T ssize_t; |
| 29 |
#ifdef _WIN64 |
| 30 |
typedef long long off_t; |
| 31 |
#else |
| 32 |
typedef long off_t; |
| 33 |
#endif |
| 34 |
#endif /* _MSC_VER */ |
| 35 |
|
| 36 |
#ifndef TRUE |
| 37 |
#define TRUE 1 |
| 38 |
#endif /* TRUE */ |
| 39 |
#ifndef FALSE |
| 40 |
#define FALSE 0 |
| 41 |
#endif /* FALSE */ |
| 42 |
|
| 43 |
#define DWARF_HALF_SIZE 2 |
| 44 |
#define SIZEOFT16 2 |
| 45 |
#define SIZEOFT32 4 |
| 46 |
#define SIZEOFT64 8 |
| 47 |
|
| 48 |
#ifdef WORDS_BIGENDIAN |
| 49 |
#define ASNAR(func,t,s) \ |
| 50 |
do { \ |
| 51 |
unsigned tbyte = sizeof(t) - sizeof(s); \ |
| 52 |
(t) = 0; \ |
| 53 |
(func)(((char *)&(t))+tbyte ,&(s)[0],sizeof(s)); \ |
| 54 |
} while (0) |
| 55 |
#else /* LITTLE ENDIAN */ |
| 56 |
#define ASNAR(func,t,s) \ |
| 57 |
do { \ |
| 58 |
(t) = 0; \ |
| 59 |
(func)(&(t),&(s)[0],sizeof(s)); \ |
| 60 |
} while (0) |
| 61 |
#endif /* end LITTLE- BIG-ENDIAN */ |
| 62 |
|
| 63 |
/* The following actually assumes (as used here) |
| 64 |
that t is 8 bytes (integer) while s is |
| 65 |
also 8 bytes (Dwarf_Sig8 struct). |
| 66 |
Just slightly different from the ASNAR generally |
| 67 |
used in libdwarf. Unusable in |
| 68 |
libdwarfp because of _dwarf_error() here. */ |
| 69 |
#ifdef WORDS_BIGENDIAN |
| 70 |
#define ASNARL(t,s,l) \ |
| 71 |
do { \ |
| 72 |
unsigned tbyte = sizeof(t) - (l); \ |
| 73 |
if (sizeof(t) < (l)) { \ |
| 74 |
_dwarf_error(dbg,error,DW_DLE_XU_HASH_INDEX_ERROR); \ |
| 75 |
return DW_DLV_ERROR; \ |
| 76 |
} \ |
| 77 |
(t) = 0; \ |
| 78 |
dbg->de_copy_word(((char *)&(t))+tbyte ,&(s)[0],(l));\ |
| 79 |
} while (0) |
| 80 |
#else /* LITTLE ENDIAN */ |
| 81 |
#define ASNARL(t,s,l) \ |
| 82 |
do { \ |
| 83 |
(t) = 0; \ |
| 84 |
if (sizeof(t) < (l)) { \ |
| 85 |
_dwarf_error(dbg,error,DW_DLE_XU_HASH_INDEX_ERROR); \ |
| 86 |
return DW_DLV_ERROR; \ |
| 87 |
} \ |
| 88 |
dbg->de_copy_word(&(t),&(s)[0],(l)); \ |
| 89 |
} while (0) |
| 90 |
#endif /* end LITTLE- BIG-ENDIAN */ |
| 91 |
|
| 92 |
#ifdef WORDS_BIGENDIAN |
| 93 |
#define SIGN_EXTEND(dest, length) \ |
| 94 |
do { \ |
| 95 |
if (*(Dwarf_Sbyte *)((char *)&(dest) + \ |
| 96 |
sizeof(dest) - (length)) < 0) { \ |
| 97 |
memcpy((char *)&(dest), \ |
| 98 |
"\xff\xff\xff\xff\xff\xff\xff\xff", \ |
| 99 |
sizeof(dest) - (length)); \ |
| 100 |
} \ |
| 101 |
} while (0) |
| 102 |
#else /* LITTLE ENDIAN */ |
| 103 |
#define SIGN_EXTEND(dest, length) \ |
| 104 |
do { \ |
| 105 |
if (*(Dwarf_Sbyte *)((char *)&(dest)+ ((length)-1)) < 0) { \ |
| 106 |
memcpy((char *)&(dest)+(length), \ |
| 107 |
"\xff\xff\xff\xff\xff\xff\xff\xff", \ |
| 108 |
sizeof(dest) - (length)); \ |
| 109 |
} \ |
| 110 |
} while (0) |
| 111 |
#endif /* LITTLE ENDIAN */ |
| 112 |
|
| 113 |
#endif /* LIBDWARF_PRIVATE_H */ |