3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
5 * Layered header for OS specific functions
6 * Contributors adding new OS support must implement all functions
10 * Copyright (c) PeerSec Networks, 2002-2009. All Rights Reserved.
11 * The latest version of this code is available at http://www.matrixssl.org
13 * This software is open source; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This General Public License does NOT permit incorporating this software
19 * into proprietary programs. If you are unable to comply with the GPL, a
20 * commercial license for this software may be purchased from PeerSec Networks
21 * at http://www.peersec.com
23 * This program is distributed in WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 * See the GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * http://www.gnu.org/copyleft/gpl.html
32 /******************************************************************************/
36 #define _h_EXPORT_SYMBOLS
49 /******************************************************************************/
51 #include "../../matrixCommon.h"
55 Functions defined at OS level
57 extern int32
sslOpenOsdep(void);
58 extern int32
sslCloseOsdep(void);
59 extern int32
sslGetEntropy(unsigned char *bytes
, int32 size
);
62 Defines to make library multithreading safe
64 #ifdef USE_MULTITHREADING
69 typedef CRITICAL_SECTION sslMutex_t
;
70 #define sslCreateMutex(M) InitializeCriticalSection((CRITICAL_SECTION *) M);
71 #define sslLockMutex(M) EnterCriticalSection((CRITICAL_SECTION *) M);
72 #define sslUnlockMutex(M) LeaveCriticalSection((CRITICAL_SECTION *) M);
73 #define sslDestroyMutex(M) DeleteCriticalSection((CRITICAL_SECTION *) M);
79 typedef pthread_mutex_t sslMutex_t
;
80 extern int32
sslCreateMutex(sslMutex_t
*mutex
);
81 extern int32
sslLockMutex(sslMutex_t
*mutex
);
82 extern int32
sslUnlockMutex(sslMutex_t
*mutex
);
83 extern void sslDestroyMutex(sslMutex_t
*mutex
);
87 typedef SEM_ID sslMutex_t
;
88 extern int32
sslCreateMutex(sslMutex_t
*mutex
);
89 extern int32
sslLockMutex(sslMutex_t
*mutex
);
90 extern int32
sslUnlockMutex(sslMutex_t
*mutex
);
91 extern void sslDestroyMutex(sslMutex_t
*mutex
);
92 #endif /* WIN32 || CE */
94 #else /* USE_MULTITHREADING */
95 typedef int32 sslMutex_t
;
96 #define sslCreateMutex(M)
97 #define sslLockMutex(M)
98 #define sslUnlockMutex(M)
99 #define sslDestroyMutex(M)
101 #endif /* USE_MULTITHREADING */
104 Make sslTime_t an opaque time value.
105 FUTURE - use high res time instead of time_t
109 On some *NIX versions such as MAC OS X 10.4, CLK_TCK has been deprecated
112 #define CLK_TCK CLOCKS_PER_SEC
118 typedef LARGE_INTEGER sslTime_t
;
124 #elif (defined(USE_RDTSCLL_TIME) || defined(RDTSC))
125 typedef unsigned long long LARGE_INTEGER
;
126 typedef LARGE_INTEGER sslTime_t
;
130 typedef LARGE_INTEGER sslTime_t
;
138 /******************************************************************************/
140 We define our own stat for CE.
144 extern int32
stat(char *filename
, struct stat
*sbuf
);
147 unsigned long st_size
; /* file size in bytes */
148 unsigned long st_mode
;
149 time_t st_atime
; /* time of last access */
150 time_t st_mtime
; /* time of last data modification */
151 time_t st_ctime
; /* time of last file status change */
154 #define S_IFREG 0100000
155 #define S_IFDIR 0040000
157 extern time_t time();
161 extern int32
sslInitMsecs(sslTime_t
*t
);
162 extern int32
sslCompareTime(sslTime_t a
, sslTime_t b
);
163 extern int32
sslDiffSecs(sslTime_t then
, sslTime_t now
);
164 extern long sslDiffMsecs(sslTime_t then
, sslTime_t now
);
167 /******************************************************************************/
169 Debugging functionality.
171 If DEBUG is defined matrixStrDebugMsg and matrixIntDebugMsg messages are
172 output to stdout, sslAsserts go to stderror and call psBreak.
174 In non-DEBUG builds matrixStrDebugMsg and matrixIntDebugMsg are
175 compiled out. sslAsserts still go to stderr, but psBreak is not called.
180 extern void psBreak(void);
181 extern void matrixStrDebugMsg(char *message
, char *arg
);
182 extern void matrixIntDebugMsg(char *message
, int32 arg
);
183 extern void matrixPtrDebugMsg(char *message
, void *arg
);
184 #define sslAssert(C) if (C) ; else \
185 {fprintf(stderr, "%s:%d sslAssert(%s)\n",__FILE__, __LINE__, #C); psBreak(); }
187 #define matrixStrDebugMsg(x, y)
188 #define matrixIntDebugMsg(x, y)
189 #define matrixPtrDebugMsg(x, y)
190 #define sslAssert(C) if (C) ; else \
191 {fprintf(stderr, "%s:%d sslAssert(%s)\n",__FILE__, __LINE__, #C); }
198 #endif /* _h_OS_LAYER */
200 /******************************************************************************/