1/*
2 * Copyright 1995-2026 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OPENSSL_E_OS2_H
11#define OPENSSL_E_OS2_H
12#pragma once
13
14#include <openssl/macros.h>
15#ifndef OPENSSL_NO_DEPRECATED_3_0
16#define HEADER_E_OS2_H
17#endif
18
19#include <openssl/opensslconf.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/******************************************************************************
26 * Detect operating systems. This probably needs completing.
27 * The result is that at least one OPENSSL_SYS_os macro should be defined.
28 * However, if none is defined, Unix is assumed.
29 **/
30
31#define OPENSSL_SYS_UNIX
32
33/* --------------------- Microsoft operating systems ---------------------- */
34
35/*
36 * Note that MSDOS actually denotes 32-bit environments running on top of
37 * MS-DOS, such as DJGPP one.
38 */
39#if defined(OPENSSL_SYS_MSDOS)
40#undef OPENSSL_SYS_UNIX
41#endif
42
43/*
44 * For 32 bit environment, there seems to be the CygWin environment and then
45 * all the others that try to do the same thing Microsoft does...
46 */
47/*
48 * UEFI lives here because it might be built with a Microsoft toolchain and
49 * we need to avoid the false positive match on Windows.
50 */
51#if defined(OPENSSL_SYS_UEFI)
52#undef OPENSSL_SYS_UNIX
53#elif defined(OPENSSL_SYS_UWIN)
54#undef OPENSSL_SYS_UNIX
55#define OPENSSL_SYS_WIN32_UWIN
56#else
57#if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN)
58#define OPENSSL_SYS_WIN32_CYGWIN
59#else
60#if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
61#undef OPENSSL_SYS_UNIX
62#if !defined(OPENSSL_SYS_WIN32)
63#define OPENSSL_SYS_WIN32
64#endif
65#endif
66#if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
67#undef OPENSSL_SYS_UNIX
68#if !defined(OPENSSL_SYS_WIN64)
69#define OPENSSL_SYS_WIN64
70#endif
71#endif
72#if defined(OPENSSL_SYS_WINNT)
73#undef OPENSSL_SYS_UNIX
74#endif
75#endif
76#endif
77
78/* Anything that tries to look like Microsoft is "Windows" */
79#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT)
80#undef OPENSSL_SYS_UNIX
81#define OPENSSL_SYS_WINDOWS
82#ifndef OPENSSL_SYS_MSDOS
83#define OPENSSL_SYS_MSDOS
84#endif
85#endif
86
87/*
88 * DLL settings. This part is a bit tough, because it's up to the
89 * application implementer how he or she will link the application, so it
90 * requires some macro to be used.
91 */
92#ifdef OPENSSL_SYS_WINDOWS
93#ifndef OPENSSL_OPT_WINDLL
94#if defined(_WINDLL) /* This is used when building OpenSSL to \
95 * indicate that DLL linkage should be used */
96#define OPENSSL_OPT_WINDLL
97#endif
98#endif
99#endif
100
101/* ------------------------------- OpenVMS -------------------------------- */
102#if defined(__VMS) || defined(VMS)
103#if !defined(OPENSSL_SYS_VMS)
104#undef OPENSSL_SYS_UNIX
105#define OPENSSL_SYS_VMS
106#endif
107#if defined(__DECC)
108#define OPENSSL_SYS_VMS_DECC
109#elif defined(__DECCXX)
110#define OPENSSL_SYS_VMS_DECC
111#define OPENSSL_SYS_VMS_DECCXX
112#else
113#define OPENSSL_SYS_VMS_NODECC
114#endif
115#endif
116
117/* -------------------------------- Unix ---------------------------------- */
118#ifdef OPENSSL_SYS_UNIX
119#if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
120#define OPENSSL_SYS_LINUX
121#endif
122#if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
123#define OPENSSL_SYS_AIX
124#endif
125#endif
126
127/* -------------------------------- VOS ----------------------------------- */
128#if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
129#define OPENSSL_SYS_VOS
130#ifdef __HPPA__
131#define OPENSSL_SYS_VOS_HPPA
132#endif
133#ifdef __IA32__
134#define OPENSSL_SYS_VOS_IA32
135#endif
136#endif
137
138/* ---------------------------- HP NonStop -------------------------------- */
139#ifdef __TANDEM
140#ifdef _STRING
141#include <strings.h>
142#endif
143#define OPENSSL_USE_BUILD_DATE
144#if defined(OPENSSL_THREADS) && defined(_SPT_MODEL_)
145#define SPT_THREAD_SIGNAL 1
146#define SPT_THREAD_AWARE 1
147#include <spthread.h>
148#elif defined(OPENSSL_THREADS) && defined(_PUT_MODEL_)
149#include <pthread.h>
150#endif
151#endif
152
153/**
154 * That's it for OS-specific stuff
155 *****************************************************************************/
156
157/*-
158 * OPENSSL_EXTERN is normally used to declare a symbol with possible extra
159 * attributes to handle its presence in a shared library.
160 * OPENSSL_EXPORT is used to define a symbol with extra possible attributes
161 * to make it visible in a shared library.
162 * Care needs to be taken when a header file is used both to declare and
163 * define symbols. Basically, for any library that exports some global
164 * variables, the following code must be present in the header file that
165 * declares them, before OPENSSL_EXTERN is used:
166 *
167 * #ifdef SOME_BUILD_FLAG_MACRO
168 * # undef OPENSSL_EXTERN
169 * # define OPENSSL_EXTERN OPENSSL_EXPORT
170 * #endif
171 *
172 * The default is to have OPENSSL_EXPORT and OPENSSL_EXTERN
173 * have some generally sensible values.
174 */
175
176#if defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
177#define OPENSSL_EXPORT extern __declspec(dllexport)
178#define OPENSSL_EXTERN extern __declspec(dllimport)
179#else
180#define OPENSSL_EXPORT extern
181#define OPENSSL_EXTERN extern
182#endif
183
184#if defined(UNUSEDRESULT_DEBUG)
185#define __owur __attribute__((__warn_unused_result__))
186#else
187#define __owur
188#endif
189
190/* Standard integer types */
191#define OPENSSL_NO_INTTYPES_H
192#define OPENSSL_NO_STDINT_H
193#if defined(OPENSSL_SYS_UEFI)
194typedef INT8 int8_t;
195typedef UINT8 uint8_t;
196typedef INT16 int16_t;
197typedef UINT16 uint16_t;
198typedef INT32 int32_t;
199typedef UINT32 uint32_t;
200typedef INT64 int64_t;
201typedef UINT64 uint64_t;
202typedef UINTN uintptr_t;
203#ifndef OSSL_SSIZE_MAX
204typedef INTN ossl_ssize_t;
205#define OSSL_SSIZE_MAX MAX_INTN
206#endif
207#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__osf__) || defined(__sgi) || defined(__hpux) || defined(OPENSSL_SYS_VMS) || defined(__OpenBSD__)
208#include <inttypes.h>
209#undef OPENSSL_NO_INTTYPES_H
210/* Because the specs say that inttypes.h includes stdint.h if present */
211#undef OPENSSL_NO_STDINT_H
212#elif defined(OPENSSL_SYS_TANDEM)
213#include <stdint.h>
214#include <sys/types.h>
215#else
216#include <stdint.h>
217#undef OPENSSL_NO_STDINT_H
218#endif
219
220#ifdef _WIN32
221#ifdef _WIN64
222typedef int64_t ossl_ssize_t;
223#define OSSL_SSIZE_MAX INT64_MAX
224#else
225typedef int ossl_ssize_t;
226#define OSSL_SSIZE_MAX INT_MAX
227#endif
228#endif
229
230#ifndef OSSL_SSIZE_MAX
231#include <sys/types.h>
232typedef ssize_t ossl_ssize_t;
233#if defined(SSIZE_MAX)
234#define OSSL_SSIZE_MAX SSIZE_MAX
235#elif defined(_POSIX_SSIZE_MAX)
236#define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
237#else
238#define OSSL_SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
239#endif
240#endif
241
242#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && defined(INTMAX_MAX) && defined(UINTMAX_MAX)
243typedef intmax_t ossl_intmax_t;
244typedef uintmax_t ossl_uintmax_t;
245#else
246/* Fall back to the largest we know we require and can handle */
247typedef int64_t ossl_intmax_t;
248typedef uint64_t ossl_uintmax_t;
249#endif
250
251/* ossl_inline: portable inline definition usable in public headers */
252#if !defined(inline) && !defined(__cplusplus)
253#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
254/* just use inline */
255#define ossl_inline inline
256#elif defined(__GNUC__)
257#define ossl_inline __inline__
258#elif defined(_MSC_VER)
259/*
260 * Visual Studio: inline is available in C++ only, however
261 * __inline is available for C, see
262 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
263 */
264#define ossl_inline __inline
265#else
266#define ossl_inline
267#endif
268#else
269#define ossl_inline inline
270#endif
271
272#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
273#define ossl_noreturn _Noreturn
274#elif defined(__GNUC__)
275#define ossl_noreturn __attribute__((noreturn))
276#else
277#define ossl_noreturn
278#endif
279
280/* ossl_unused: portable unused attribute for use in public headers */
281#if defined(__GNUC__)
282#define ossl_unused __attribute__((unused))
283#else
284#define ossl_unused
285#endif
286
287/*
288 * OPENSSL_NONSTRING: mark a char/unsigned char buffer object or struct field
289 * whose contents are not necessarily NUL terminated, so that misuse with C
290 * string functions (strlen(), strcpy(), "%s", ...) is diagnosed by compilers
291 * that support the attribute. It has no effect elsewhere.
292 */
293#if defined(__has_attribute)
294#if __has_attribute(nonstring)
295#define OPENSSL_NONSTRING __attribute__((nonstring))
296#else
297#define OPENSSL_NONSTRING
298#endif
299#else
300#define OPENSSL_NONSTRING
301#endif
302
303#ifdef __cplusplus
304}
305#endif
306#endif
307