Tomato 1.26
[tomato.git] / release / src / router / matrixssl / src / os / osLayer.h
blob00872198b208095cc66de0c148a9a7341f08863d
1 /*
2 * osLayer.h
3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
4 *
5 * Layered header for OS specific functions
6 * Contributors adding new OS support must implement all functions
7 * externed below.
8 */
9 /*
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 /******************************************************************************/
34 #ifndef _h_OS_LAYER
35 #define _h_OS_LAYER
36 #define _h_EXPORT_SYMBOLS
38 #include <stdio.h>
39 #include <stdlib.h>
41 #ifndef WINCE
42 #include <time.h>
43 #endif
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
49 /******************************************************************************/
51 #include "../../matrixCommon.h"
52 #include "psMalloc.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
66 #if WIN32 || WINCE
67 #include <windows.h>
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);
75 #elif LINUX
76 #include <pthread.h>
77 #include <string.h>
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);
84 #elif VXWORKS
85 #include "semLib.h"
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
107 #ifdef LINUX
109 On some *NIX versions such as MAC OS X 10.4, CLK_TCK has been deprecated
111 #ifndef CLK_TCK
112 #define CLK_TCK CLOCKS_PER_SEC
113 #endif /* CLK_TCK */
114 #endif /* LINUX */
116 #if defined(WIN32)
117 #include <windows.h>
118 typedef LARGE_INTEGER sslTime_t;
119 #elif VXWORKS
120 typedef struct {
121 long sec;
122 long usec;
123 } sslTime_t;
124 #elif (defined(USE_RDTSCLL_TIME) || defined(RDTSC))
125 typedef unsigned long long LARGE_INTEGER;
126 typedef LARGE_INTEGER sslTime_t;
127 #elif WINCE
128 #include <windows.h>
130 typedef LARGE_INTEGER sslTime_t;
131 #else
132 typedef struct {
133 long sec;
134 long usec;
135 } sslTime_t;
136 #endif
138 /******************************************************************************/
140 We define our own stat for CE.
142 #if WINCE
144 extern int32 stat(char *filename, struct stat *sbuf);
146 struct stat {
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();
159 #endif /* WINCE */
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.
179 #if DEBUG
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(); }
186 #else
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); }
192 #endif /* DEBUG */
194 #ifdef __cplusplus
196 #endif
198 #endif /* _h_OS_LAYER */
200 /******************************************************************************/