1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * This file essentially replicates NSPR's source for the functions that
4 * map system-specific error codes to NSPR error codes. We would use
5 * NSPR's functions, instead of duplicating them, but they're private.
6 * As long as SSL's server session cache code must do platform native I/O
7 * to accomplish its job, and NSPR's error mapping functions remain private,
8 * this code will continue to need to be replicated.
10 * This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this
12 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
20 * On Win32, we map three kinds of error codes:
21 * - GetLastError(): for Win32 functions
22 * - WSAGetLastError(): for Winsock functions
23 * - errno: for standard C library functions
25 * We do not check for WSAEINPROGRESS and WSAEINTR because we do not
26 * use blocking Winsock 1.1 calls.
28 * Except for the 'socket' call, we do not check for WSAEINITIALISED.
29 * It is assumed that if Winsock is not initialized, that fact will
30 * be detected at the time we create new sockets.
33 /* forward declaration. */
34 void nss_MD_win32_map_default_error(PRInt32 err
);
36 void nss_MD_win32_map_opendir_error(PRInt32 err
)
38 nss_MD_win32_map_default_error(err
);
41 void nss_MD_win32_map_closedir_error(PRInt32 err
)
43 nss_MD_win32_map_default_error(err
);
46 void nss_MD_win32_map_readdir_error(PRInt32 err
)
48 nss_MD_win32_map_default_error(err
);
51 void nss_MD_win32_map_delete_error(PRInt32 err
)
53 nss_MD_win32_map_default_error(err
);
56 /* The error code for stat() is in errno. */
57 void nss_MD_win32_map_stat_error(PRInt32 err
)
59 nss_MD_win32_map_default_error(err
);
62 void nss_MD_win32_map_fstat_error(PRInt32 err
)
64 nss_MD_win32_map_default_error(err
);
67 void nss_MD_win32_map_rename_error(PRInt32 err
)
69 nss_MD_win32_map_default_error(err
);
72 /* The error code for access() is in errno. */
73 void nss_MD_win32_map_access_error(PRInt32 err
)
75 nss_MD_win32_map_default_error(err
);
78 void nss_MD_win32_map_mkdir_error(PRInt32 err
)
80 nss_MD_win32_map_default_error(err
);
83 void nss_MD_win32_map_rmdir_error(PRInt32 err
)
85 nss_MD_win32_map_default_error(err
);
88 void nss_MD_win32_map_read_error(PRInt32 err
)
90 nss_MD_win32_map_default_error(err
);
93 void nss_MD_win32_map_transmitfile_error(PRInt32 err
)
95 nss_MD_win32_map_default_error(err
);
98 void nss_MD_win32_map_write_error(PRInt32 err
)
100 nss_MD_win32_map_default_error(err
);
103 void nss_MD_win32_map_lseek_error(PRInt32 err
)
105 nss_MD_win32_map_default_error(err
);
108 void nss_MD_win32_map_fsync_error(PRInt32 err
)
110 nss_MD_win32_map_default_error(err
);
114 * For both CloseHandle() and closesocket().
116 void nss_MD_win32_map_close_error(PRInt32 err
)
118 nss_MD_win32_map_default_error(err
);
121 void nss_MD_win32_map_socket_error(PRInt32 err
)
123 PR_ASSERT(err
!= WSANOTINITIALISED
);
124 nss_MD_win32_map_default_error(err
);
127 void nss_MD_win32_map_recv_error(PRInt32 err
)
129 nss_MD_win32_map_default_error(err
);
132 void nss_MD_win32_map_recvfrom_error(PRInt32 err
)
134 nss_MD_win32_map_default_error(err
);
137 void nss_MD_win32_map_send_error(PRInt32 err
)
141 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
142 default: nss_MD_win32_map_default_error(err
); return;
144 PR_SetError(prError
, err
);
147 void nss_MD_win32_map_sendto_error(PRInt32 err
)
151 case WSAEMSGSIZE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
152 default: nss_MD_win32_map_default_error(err
); return;
154 PR_SetError(prError
, err
);
157 void nss_MD_win32_map_accept_error(PRInt32 err
)
161 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
162 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
163 default: nss_MD_win32_map_default_error(err
); return;
165 PR_SetError(prError
, err
);
168 void nss_MD_win32_map_acceptex_error(PRInt32 err
)
170 nss_MD_win32_map_default_error(err
);
173 void nss_MD_win32_map_connect_error(PRInt32 err
)
177 case WSAEWOULDBLOCK
: prError
= PR_IN_PROGRESS_ERROR
; break;
178 case WSAEINVAL
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
179 case WSAETIMEDOUT
: prError
= PR_IO_TIMEOUT_ERROR
; break;
180 default: nss_MD_win32_map_default_error(err
); return;
182 PR_SetError(prError
, err
);
185 void nss_MD_win32_map_bind_error(PRInt32 err
)
189 case WSAEINVAL
: prError
= PR_SOCKET_ADDRESS_IS_BOUND_ERROR
; break;
190 default: nss_MD_win32_map_default_error(err
); return;
192 PR_SetError(prError
, err
);
195 void nss_MD_win32_map_listen_error(PRInt32 err
)
199 case WSAEOPNOTSUPP
: prError
= PR_NOT_TCP_SOCKET_ERROR
; break;
200 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
201 default: nss_MD_win32_map_default_error(err
); return;
203 PR_SetError(prError
, err
);
206 void nss_MD_win32_map_shutdown_error(PRInt32 err
)
208 nss_MD_win32_map_default_error(err
);
211 void nss_MD_win32_map_getsockname_error(PRInt32 err
)
215 case WSAEINVAL
: prError
= PR_INVALID_STATE_ERROR
; break;
216 default: nss_MD_win32_map_default_error(err
); return;
218 PR_SetError(prError
, err
);
221 void nss_MD_win32_map_getpeername_error(PRInt32 err
)
223 nss_MD_win32_map_default_error(err
);
226 void nss_MD_win32_map_getsockopt_error(PRInt32 err
)
228 nss_MD_win32_map_default_error(err
);
231 void nss_MD_win32_map_setsockopt_error(PRInt32 err
)
233 nss_MD_win32_map_default_error(err
);
236 void nss_MD_win32_map_open_error(PRInt32 err
)
238 nss_MD_win32_map_default_error(err
);
241 void nss_MD_win32_map_gethostname_error(PRInt32 err
)
243 nss_MD_win32_map_default_error(err
);
246 /* Win32 select() only works on sockets. So in this
247 ** context, WSAENOTSOCK is equivalent to EBADF on Unix.
249 void nss_MD_win32_map_select_error(PRInt32 err
)
253 case WSAENOTSOCK
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
254 default: nss_MD_win32_map_default_error(err
); return;
256 PR_SetError(prError
, err
);
259 void nss_MD_win32_map_lockf_error(PRInt32 err
)
261 nss_MD_win32_map_default_error(err
);
266 void nss_MD_win32_map_default_error(PRInt32 err
)
271 case EACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
272 case ENOENT
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
273 case ERROR_ACCESS_DENIED
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
274 case ERROR_ALREADY_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
275 case ERROR_DISK_CORRUPT
: prError
= PR_IO_ERROR
; break;
276 case ERROR_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
277 case ERROR_DISK_OPERATION_FAILED
: prError
= PR_IO_ERROR
; break;
278 case ERROR_DRIVE_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
279 case ERROR_FILENAME_EXCED_RANGE
: prError
= PR_NAME_TOO_LONG_ERROR
; break;
280 case ERROR_FILE_CORRUPT
: prError
= PR_IO_ERROR
; break;
281 case ERROR_FILE_EXISTS
: prError
= PR_FILE_EXISTS_ERROR
; break;
282 case ERROR_FILE_INVALID
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
283 #if ERROR_FILE_NOT_FOUND != ENOENT
284 case ERROR_FILE_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
286 case ERROR_HANDLE_DISK_FULL
: prError
= PR_NO_DEVICE_SPACE_ERROR
; break;
287 case ERROR_INVALID_ADDRESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
288 case ERROR_INVALID_HANDLE
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
289 case ERROR_INVALID_NAME
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
290 case ERROR_INVALID_PARAMETER
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
291 case ERROR_INVALID_USER_BUFFER
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
292 case ERROR_LOCKED
: prError
= PR_FILE_IS_LOCKED_ERROR
; break;
293 case ERROR_NETNAME_DELETED
: prError
= PR_CONNECT_RESET_ERROR
; break;
294 case ERROR_NOACCESS
: prError
= PR_ACCESS_FAULT_ERROR
; break;
295 case ERROR_NOT_ENOUGH_MEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
296 case ERROR_NOT_ENOUGH_QUOTA
: prError
= PR_OUT_OF_MEMORY_ERROR
; break;
297 case ERROR_NOT_READY
: prError
= PR_IO_ERROR
; break;
298 case ERROR_NO_MORE_FILES
: prError
= PR_NO_MORE_FILES_ERROR
; break;
299 case ERROR_OPEN_FAILED
: prError
= PR_IO_ERROR
; break;
300 case ERROR_OPEN_FILES
: prError
= PR_IO_ERROR
; break;
301 case ERROR_OUTOFMEMORY
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
302 case ERROR_PATH_BUSY
: prError
= PR_IO_ERROR
; break;
303 case ERROR_PATH_NOT_FOUND
: prError
= PR_FILE_NOT_FOUND_ERROR
; break;
304 case ERROR_SEEK_ON_DEVICE
: prError
= PR_IO_ERROR
; break;
305 case ERROR_SHARING_VIOLATION
: prError
= PR_FILE_IS_BUSY_ERROR
; break;
306 case ERROR_STACK_OVERFLOW
: prError
= PR_ACCESS_FAULT_ERROR
; break;
307 case ERROR_TOO_MANY_OPEN_FILES
: prError
= PR_SYS_DESC_TABLE_FULL_ERROR
; break;
308 case ERROR_WRITE_PROTECT
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
309 case WSAEACCES
: prError
= PR_NO_ACCESS_RIGHTS_ERROR
; break;
310 case WSAEADDRINUSE
: prError
= PR_ADDRESS_IN_USE_ERROR
; break;
311 case WSAEADDRNOTAVAIL
: prError
= PR_ADDRESS_NOT_AVAILABLE_ERROR
; break;
312 case WSAEAFNOSUPPORT
: prError
= PR_ADDRESS_NOT_SUPPORTED_ERROR
; break;
313 case WSAEALREADY
: prError
= PR_ALREADY_INITIATED_ERROR
; break;
314 case WSAEBADF
: prError
= PR_BAD_DESCRIPTOR_ERROR
; break;
315 case WSAECONNABORTED
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
316 case WSAECONNREFUSED
: prError
= PR_CONNECT_REFUSED_ERROR
; break;
317 case WSAECONNRESET
: prError
= PR_CONNECT_RESET_ERROR
; break;
318 case WSAEDESTADDRREQ
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
319 case WSAEFAULT
: prError
= PR_ACCESS_FAULT_ERROR
; break;
320 case WSAEHOSTUNREACH
: prError
= PR_HOST_UNREACHABLE_ERROR
; break;
321 case WSAEINVAL
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
322 case WSAEISCONN
: prError
= PR_IS_CONNECTED_ERROR
; break;
323 case WSAEMFILE
: prError
= PR_PROC_DESC_TABLE_FULL_ERROR
; break;
324 case WSAEMSGSIZE
: prError
= PR_BUFFER_OVERFLOW_ERROR
; break;
325 case WSAENETDOWN
: prError
= PR_NETWORK_DOWN_ERROR
; break;
326 case WSAENETRESET
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
327 case WSAENETUNREACH
: prError
= PR_NETWORK_UNREACHABLE_ERROR
; break;
328 case WSAENOBUFS
: prError
= PR_INSUFFICIENT_RESOURCES_ERROR
; break;
329 case WSAENOPROTOOPT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
330 case WSAENOTCONN
: prError
= PR_NOT_CONNECTED_ERROR
; break;
331 case WSAENOTSOCK
: prError
= PR_NOT_SOCKET_ERROR
; break;
332 case WSAEOPNOTSUPP
: prError
= PR_OPERATION_NOT_SUPPORTED_ERROR
; break;
333 case WSAEPROTONOSUPPORT
: prError
= PR_PROTOCOL_NOT_SUPPORTED_ERROR
; break;
334 case WSAEPROTOTYPE
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
335 case WSAESHUTDOWN
: prError
= PR_SOCKET_SHUTDOWN_ERROR
; break;
336 case WSAESOCKTNOSUPPORT
: prError
= PR_INVALID_ARGUMENT_ERROR
; break;
337 case WSAETIMEDOUT
: prError
= PR_CONNECT_ABORTED_ERROR
; break;
338 case WSAEWOULDBLOCK
: prError
= PR_WOULD_BLOCK_ERROR
; break;
339 default: prError
= PR_UNKNOWN_ERROR
; break;
341 PR_SetError(prError
, err
);