1 /* darwin.h -- common stuff for the Darwin stub loaders
2 
3    This file is part of the UPX executable compressor.
4 
5    Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer
6    Copyright (C) 1996-2020 Laszlo Molnar
7    All Rights Reserved.
8 
9    UPX and the UCL library are free software; you can redistribute them
10    and/or modify them under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of
12    the License, or (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; see the file COPYING.
21    If not, write to the Free Software Foundation, Inc.,
22    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24    Markus F.X.J. Oberhumer              Laszlo Molnar
25    <markus@oberhumer.com>               <ezerotven+github@gmail.com>
26  */
27 
28 
29 // NOTE:
30 //   to avoid endless problems with moving libc and kernel headers, this
31 //   section is now completely freestanding
32 
33 
34 #if defined(__GNUC__)
35 #  if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
36 #    define ACC_CC_GNUC         (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0))
37 #  elif defined(__GNUC_MINOR__)
38 #    define ACC_CC_GNUC         (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100)
39 #  else
40 #    define ACC_CC_GNUC         (__GNUC__ * 0x10000L)
41 #  endif
42 #endif
43 
44 #define ACC_UNUSED(var)         ((void) var)
45 
46 
47 /*************************************************************************
48 //
49 **************************************************************************/
50 
51 // <stddef.h>
52 typedef long ptrdiff_t;
53 typedef long ssize_t;
54 typedef unsigned long size_t;
55 // <stdint.h>
56 typedef unsigned char uint8_t;
57 typedef unsigned short uint16_t;
58 typedef int int32_t;
59 typedef unsigned uint32_t;
60 #if (ACC_CC_GNUC >= 0x020800ul)  /*{*/
61 #  if 64 == __WORDSIZE  /*{*/
62   typedef          long  int64_t;
63   typedef unsigned long uint64_t;
64 #  else  /*}{*/
65 __extension__ typedef          long long  int64_t;
66 __extension__ typedef unsigned long long uint64_t;
67 #  endif  /*}*/
68 #elif defined(_WIN32)  /*}{*/
69 typedef __int64 int64_t;
70 typedef unsigned __int64 uint64_t;
71 #else  /*}{*/
72 typedef long long int64_t;
73 typedef unsigned long long uint64_t;
74 #endif  /*}*/
75 typedef size_t uintptr_t;
76 
77 // XXX: restrict ourselves to 4GB for off_t.  Some versions of gcc
78 // have bugs in handling 64-bit integers (such as passing as argument
79 // the wrong registers) and it takes more code anyway.
80 // Adjust in system call wrappers, particularly mmap() and pread().
81 typedef unsigned off_t_upx_stub;
82 
83 // misc constants
84 
85 #define PAGE_MASK       (~0ul<<12)
86 #define PAGE_SIZE       (-PAGE_MASK)
87 
88 #define O_RDONLY        0
89 
90 
91 /*************************************************************************
92 // syscalls
93 **************************************************************************/
94 
95 int close(int);
96 void exit(int) __attribute__((__noreturn__,__nothrow__));
97 int mprotect(void *, size_t, int);
98 extern int munmap(char *, size_t);
99 int open(char const *, int, ...);
100 extern ssize_t write(int, char const *, size_t);
101 
102 
103 /*************************************************************************
104 // UPX stuff
105 **************************************************************************/
106 
107 #define UPX_MAGIC_LE32  0x21585055          // "UPX!"
108 
109 
110 #define nrv_byte unsigned char
111 typedef unsigned int nrv_uint;
112 
113 
114 #define CONST_CAST(type, var) \
115     ((type) ((uintptr_t) (var)))
116 
117 
118 #if !defined(__attribute_cdecl)
119 #if defined(__i386__)
120 #  if (ACC_CC_GNUC >= 0x030300)
121 #    define __attribute_cdecl   __attribute__((__cdecl__, __used__))
122 #  elif (ACC_CC_GNUC >= 0x020700)
123 #    define __attribute_cdecl   __attribute__((__cdecl__))
124 #  endif
125 #endif
126 #endif
127 #if !defined(__attribute_cdecl)
128 #  define __attribute_cdecl /*empty*/
129 #endif
130 
131 /* vim:set ts=4 sw=4 et: */
132