1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*++
6
7
8
9Module Name:
10
11 errorstrings.cpp
12
13Abstract:
14
15 Conversion of PAL error code to string
16
17Revision History:
18
19
20
21--*/
22
23#include "pal/palinternal.h"
24#include "errorstrings.h"
25
26struct ErrorString
27{
28 DWORD code;
29 LPCWSTR const string;
30};
31
32ErrorString palErrorStrings[] =
33{
34 { ERROR_SUCCESS, W("The operation completed successfully.\n") },
35 { ERROR_INVALID_FUNCTION, W("Incorrect function.\n") },
36 { ERROR_FILE_NOT_FOUND, W("The system cannot find the file specified.\n") },
37 { ERROR_PATH_NOT_FOUND, W("The system cannot find the path specified.\n") },
38 { ERROR_TOO_MANY_OPEN_FILES, W("The system cannot open the file.\n") },
39 { ERROR_ACCESS_DENIED, W("Access is denied.\n") },
40 { ERROR_INVALID_HANDLE, W("The handle is invalid.\n") },
41 { ERROR_NOT_ENOUGH_MEMORY, W("Not enough storage is available to process this command.\n") },
42 { ERROR_BAD_ENVIRONMENT, W("The environment is incorrect.\n") },
43 { ERROR_BAD_FORMAT, W("An attempt was made to load a program with an incorrect format.\n") },
44 { ERROR_INVALID_ACCESS, W("The access code is invalid.\n") },
45 { ERROR_INVALID_DATA, W("The data is invalid.\n") },
46 { ERROR_OUTOFMEMORY, W("Not enough storage is available to complete this operation.\n") },
47 { ERROR_INVALID_DRIVE, W("The system cannot find the drive specified.\n") },
48 { ERROR_NO_MORE_FILES, W("There are no more files.\n") },
49 { ERROR_WRITE_PROTECT, W("The media is write protected.\n") },
50 { ERROR_NOT_READY, W("The device is not ready.\n") },
51 { ERROR_BAD_COMMAND, W("The device does not recognize the command.\n") },
52 { ERROR_BAD_LENGTH, W("The program issued a command but the command length is incorrect.\n") },
53 { ERROR_WRITE_FAULT, W("The system cannot write to the specified device.\n") },
54 { ERROR_READ_FAULT, W("The system cannot read from the specified device.\n") },
55 { ERROR_GEN_FAILURE, W("A device attached to the system is not functioning.\n") },
56 { ERROR_SHARING_VIOLATION, W("The process cannot access the file because it is being used by another process.\n") },
57 { ERROR_LOCK_VIOLATION, W("The process cannot access the file because another process has locked a portion of the file.\n") },
58 { ERROR_SHARING_BUFFER_EXCEEDED, W("Too many files opened for sharing.\n") },
59 { ERROR_HANDLE_EOF, W("Reached the end of the file.\n") },
60 { ERROR_HANDLE_DISK_FULL, W("The disk is full.\n") },
61 { ERROR_NOT_SUPPORTED, W("The request is not supported.\n") },
62 { ERROR_DUP_NAME, W("A duplicate name exists on the network.\n") },
63 { ERROR_BAD_NETPATH, W("The network path was not found.\n") },
64 { ERROR_DEV_NOT_EXIST, W("The specified network resource or device is no longer available.\n") },
65 { ERROR_BAD_NET_NAME, W("The network name cannot be found.\n") },
66 { ERROR_FILE_EXISTS, W("The file exists.\n") },
67 { ERROR_CANNOT_MAKE, W("The directory or file cannot be created.\n") },
68 { ERROR_INVALID_PARAMETER, W("The parameter is incorrect.\n") },
69 { ERROR_NET_WRITE_FAULT, W("A write fault occurred on the network.\n") },
70 { ERROR_DRIVE_LOCKED, W("The disk is in use or locked by another process.\n") },
71 { ERROR_BROKEN_PIPE, W("The pipe has been ended.\n") },
72 { ERROR_OPEN_FAILED, W("The system cannot open the device or file specified.\n") },
73 { ERROR_BUFFER_OVERFLOW, W("The file name is too long.\n") },
74 { ERROR_DISK_FULL, W("There is not enough space on the disk.\n") },
75 { ERROR_CALL_NOT_IMPLEMENTED, W("This function is not supported on this system.\n") },
76 { ERROR_SEM_TIMEOUT, W("The semaphore timeout period has expired.\n") },
77 { ERROR_INSUFFICIENT_BUFFER, W("The data area passed to a system call is too small.\n") },
78 { ERROR_INVALID_NAME, W("The filename, directory name, or volume label syntax is incorrect.\n") },
79 { ERROR_MOD_NOT_FOUND, W("The specified module or one of its dependencies could not be found.\n") },
80 { ERROR_PROC_NOT_FOUND, W("The specified procedure could not be found.\n") },
81 { ERROR_WAIT_NO_CHILDREN, W("There are no child processes to wait for.\n") },
82 { ERROR_NEGATIVE_SEEK, W("An attempt was made to move the file pointer before the beginning of the file.\n") },
83 { ERROR_SEEK_ON_DEVICE, W("The file pointer cannot be set on the specified device or file.\n") },
84 { ERROR_DIR_NOT_EMPTY, W("The directory is not empty.\n") },
85 { ERROR_SIGNAL_REFUSED, W("The recipient process has refused the signal.\n") },
86 { ERROR_NOT_LOCKED, W("The segment is already unlocked.\n") },
87 { ERROR_BAD_PATHNAME, W("The specified path is invalid.\n") },
88 { ERROR_BUSY, W("The requested resource is in use.\n") },
89 { ERROR_INVALID_ORDINAL, W("The operating system cannot run %1.\n") },
90 { ERROR_ALREADY_EXISTS, W("Cannot create a file when that file already exists.\n") },
91 { ERROR_INVALID_EXE_SIGNATURE, W("Cannot run %1 in Win32 mode.\n") },
92 { ERROR_EXE_MARKED_INVALID, W("The operating system cannot run %1.\n") },
93 { ERROR_BAD_EXE_FORMAT, W("%1 is not a valid Win32 application.\n") },
94 { ERROR_ENVVAR_NOT_FOUND, W("The system could not find the environment option that was entered.\n") },
95 { ERROR_FILENAME_EXCED_RANGE, W("The filename or extension is too long.\n") },
96 { ERROR_PIPE_BUSY, W("All pipe instances are busy.\n") },
97 { ERROR_NO_DATA, W("The pipe is being closed\n")},
98 { ERROR_MORE_DATA, W("More data is available.\n") },
99 { ERROR_NO_MORE_ITEMS, W("No more data is available.\n") },
100 { ERROR_DIRECTORY, W("The directory name is invalid.\n") },
101 { ERROR_NOT_OWNER, W("Attempt to release mutex not owned by caller.\n") },
102 { ERROR_PARTIAL_COPY, W("Only part of a ReadProcessMemory or WriteProcessMemory request was completed.\n") },
103 { ERROR_INVALID_ADDRESS, W("Attempt to access invalid address.\n") },
104 { ERROR_ARITHMETIC_OVERFLOW, W("Arithmetic result exceeded 32 bits.\n") },
105 { ERROR_OPERATION_ABORTED, W("The I/O operation has been aborted because of either a thread exit or an application request.\n") },
106 { ERROR_IO_INCOMPLETE, W("Overlapped I/O event is not in a signaled state.\n") },
107 { ERROR_IO_PENDING, W("Overlapped I/O operation is in progress.\n") },
108 { ERROR_NOACCESS, W("Invalid access to memory location.\n") },
109 { ERROR_STACK_OVERFLOW, W("Recursion too deep; the stack overflowed.\n") },
110 { ERROR_INVALID_FLAGS, W("Invalid flags.\n") },
111 { ERROR_UNRECOGNIZED_VOLUME, W("The volume does not contain a recognized file system.\nPlease make sure that all required file system drivers are loaded and that the volume is not corrupted.\n") },
112 { ERROR_FILE_INVALID, W("The volume for a file has been externally altered so that the opened file is no longer valid.\n") },
113 { ERROR_PROCESS_ABORTED, W("The process terminated unexpectedly.\n") },
114 { ERROR_NO_UNICODE_TRANSLATION, W("No mapping for the Unicode character exists in the target multi-byte code page.\n") },
115 { ERROR_DLL_INIT_FAILED, W("A dynamic link library (DLL) initialization routine failed.\n") },
116 { ERROR_IO_DEVICE, W("The request could not be performed because of an I/O device error.\n") },
117 { ERROR_DISK_OPERATION_FAILED, W("While accessing the hard disk, a disk operation failed even after retries.\n") },
118 { ERROR_POSSIBLE_DEADLOCK, W("A potential deadlock condition has been detected.\n") },
119 { ERROR_TOO_MANY_LINKS, W("An attempt was made to create more links on a file than the file system supports.\n") },
120 { ERROR_INVALID_DLL, W("One of the library files needed to run this application is damaged.\n") },
121 { ERROR_DLL_NOT_FOUND, W("One of the library files needed to run this application cannot be found.\n") },
122 { ERROR_NOT_FOUND, W("Element not found.\n") },
123 { ERROR_CANCELLED, W("The operation was canceled by the user.\n") },
124 { ERROR_NOT_AUTHENTICATED, W("The operation being requested was not performed because the user has not been authenticated.\n") },
125 { ERROR_INTERNAL_ERROR, W("An internal error occurred.\n") },
126 { ERROR_FILE_CORRUPT, W("The file or directory is corrupted and unreadable.\n") },
127 { ERROR_DISK_CORRUPT, W("The disk structure is corrupted and unreadable.\n") },
128 { ERROR_WRONG_TARGET_NAME, W("Logon Failure: The target account name is incorrect.\n") },
129 { ERROR_NO_SYSTEM_RESOURCES, W("Insufficient system resources exist to complete the requested service.\n") },
130 { ERROR_COMMITMENT_LIMIT, W("The paging file is too small for this operation to complete.\n") },
131 { ERROR_TIMEOUT, W("This operation returned because the timeout period expired.\n") },
132 { ERROR_EVENTLOG_FILE_CORRUPT, W("The event log file is corrupted.\n") },
133 { ERROR_LOG_FILE_FULL, W("The event log file is full.\n") },
134 { ERROR_UNSUPPORTED_TYPE, W("Data of this type is not supported.\n") },
135 { RPC_S_INVALID_VERS_OPTION, W("The version option is invalid.\n") },
136 { ERROR_RESOURCE_DATA_NOT_FOUND, W("The specified image file did not contain a resource section.\n") },
137 { ERROR_RESOURCE_LANG_NOT_FOUND, W("The specified resource language ID cannot be found in the image file.\n") },
138 { ERROR_TAG_NOT_PRESENT, W("A required tag is not present.\n") }
139};
140
141int CompareErrorStrings(const void *a, const void *b)
142{
143 DWORD codeA = ((ErrorString *)a)->code;
144 DWORD codeB = ((ErrorString *)b)->code;
145
146 if (codeA < codeB)
147 {
148 return -1;
149 }
150 else if (codeA == codeB)
151 {
152 return 0;
153 }
154 else
155 {
156 return 1;
157 }
158}
159
160LPCWSTR GetPalErrorString(DWORD code)
161{
162 // Search the sorted set of resources for the ID we're interested in.
163 ErrorString searchEntry = {code, NULL};
164 ErrorString *stringEntry = (ErrorString *)bsearch(
165 &searchEntry,
166 palErrorStrings,
167 sizeof(palErrorStrings) / sizeof(palErrorStrings[0]),
168 sizeof(ErrorString),
169 CompareErrorStrings);
170
171 return (stringEntry != NULL) ? stringEntry->string : NULL;
172}
173