1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
8 :
9 : #include "native_client/src/shared/platform/nacl_log.h"
10 :
11 14 : char const *NaClErrorString(NaClErrorCode errcode) {
12 14 : switch (errcode) {
13 : case LOAD_OK:
14 0 : return "Ok";
15 : case LOAD_STATUS_UNKNOWN:
16 0 : return "Load status unknown (load incomplete)";
17 : case LOAD_UNSUPPORTED_OS_PLATFORM:
18 0 : return "Operating system platform is not supported";
19 : case LOAD_DEP_UNSUPPORTED:
20 0 : return "Data Execution Prevention is required but is not supported";
21 : case LOAD_INTERNAL:
22 0 : return "Internal error";
23 : case LOAD_DUP_LOAD_MODULE: /* -R: nexe supplied by RPC, but only once! */
24 0 : return "Multiple LoadModule RPCs";
25 : case LOAD_DUP_START_MODULE: /* -X: implies StartModule RPC, but once! */
26 0 : return "Multiple StartModule RPCs";
27 : case LOAD_OPEN_ERROR:
28 2 : return "Cannot open NaCl module file";
29 : case LOAD_READ_ERROR:
30 0 : return "Cannot read file";
31 : case LOAD_TOO_MANY_PROG_HDRS:
32 0 : return "Too many program header entries in ELF file";
33 : case LOAD_BAD_PHENTSIZE:
34 0 : return "ELF program header size wrong";
35 : case LOAD_BAD_ELF_MAGIC:
36 0 : return "Bad ELF header magic number";
37 : case LOAD_NOT_32_BIT:
38 0 : return "Not a 32-bit ELF file";
39 : case LOAD_NOT_64_BIT:
40 0 : return "Not a 64-bit ELF file";
41 : case LOAD_BAD_ABI:
42 0 : return "ELF file has unexpected OS ABI";
43 : case LOAD_NOT_EXEC:
44 0 : return "ELF file type not executable";
45 : case LOAD_BAD_MACHINE:
46 0 : return "ELF file for wrong architecture";
47 : case LOAD_BAD_ELF_VERS:
48 0 : return "ELF version mismatch";
49 : case LOAD_TOO_MANY_SECT:
50 0 : return "Too many section headers";
51 : case LOAD_BAD_SECT:
52 0 : return "ELF bad sections";
53 : case LOAD_NO_MEMORY:
54 0 : return "Insufficient memory to load file";
55 : case LOAD_SECT_HDR:
56 0 : return "ELF section header string table load error";
57 : case LOAD_ADDR_SPACE_TOO_SMALL:
58 0 : return "Address space too small";
59 : case LOAD_ADDR_SPACE_TOO_BIG:
60 0 : return "Address space too big";
61 : case LOAD_DATA_OVERLAPS_STACK_SECTION:
62 2 : return ("Memory \"hole\" between end of BSS and start of stack"
63 : " is negative in size");
64 : case LOAD_RODATA_OVERLAPS_DATA:
65 2 : return "Read-only data segment overlaps data segment";
66 : case LOAD_DATA_NOT_LAST_SEGMENT:
67 2 : return "Data segment exists, but is not last segment";
68 : case LOAD_NO_DATA_BUT_RODATA_NOT_LAST_SEGMENT:
69 0 : return ("No data segment, read-only data segment exists,"
70 : " but is not last segment");
71 : case LOAD_TEXT_OVERLAPS_RODATA:
72 0 : return "Text segment overlaps rodata segment";
73 : case LOAD_TEXT_OVERLAPS_DATA:
74 0 : return "No rodata segment, and text segment overlaps data segment";
75 : case LOAD_BAD_RODATA_ALIGNMENT:
76 0 : return "The rodata segment is not properly aligned";
77 : case LOAD_BAD_DATA_ALIGNMENT:
78 0 : return "The data segment is not properly aligned";
79 : case LOAD_UNLOADABLE:
80 0 : return "Error during loading";
81 : case LOAD_BAD_ELF_TEXT:
82 0 : return "ELF file contains no text segment";
83 : case LOAD_TEXT_SEG_TOO_BIG:
84 0 : return "ELF file text segment too large";
85 : case LOAD_DATA_SEG_TOO_BIG:
86 0 : return "ELF file data segment(s) too large";
87 : case LOAD_MPROTECT_FAIL:
88 0 : return "Cannot protect pages";
89 : case LOAD_MADVISE_FAIL:
90 0 : return "Cannot release unused data segment";
91 : case LOAD_TOO_MANY_SYMBOL_STR:
92 0 : return "Malformed ELF file: too many string tables";
93 : case LOAD_SYMTAB_ENTRY_TOO_SMALL:
94 0 : return "Symbol table entry too small";
95 : case LOAD_NO_SYMTAB:
96 0 : return "No symbol table";
97 : case LOAD_NO_SYMTAB_STRINGS:
98 0 : return "No string table for symbols";
99 : case LOAD_SYMTAB_ENTRY:
100 0 : return "Error entering new symbol into symbol table";
101 : case LOAD_UNKNOWN_SYMBOL_TYPE:
102 0 : return "Unknown symbol type";
103 : case LOAD_SYMTAB_DUP:
104 0 : return "Duplicate entry in symbol table";
105 : case LOAD_REL_ERROR:
106 0 : return "Bad relocation read error";
107 : case LOAD_REL_UNIMPL:
108 0 : return "Relocation type unimplemented";
109 : case LOAD_UNDEF_SYMBOL:
110 0 : return "Undefined external symbol";
111 : case LOAD_BAD_SYMBOL_DATA:
112 0 : return "Bad symbol table data";
113 : case LOAD_BAD_FILE:
114 0 : return "ELF file not accessible";
115 : case LOAD_BAD_ENTRY:
116 0 : return "Bad program entry point address";
117 : case LOAD_SEGMENT_OUTSIDE_ADDRSPACE:
118 0 : return ("ELF executable contains a segment which lies outside"
119 : " the assigned address space");
120 : case LOAD_DUP_SEGMENT:
121 0 : return ("ELF executable contains a duplicate segment"
122 : " (please run objdump to see which)");
123 : case LOAD_SEGMENT_BAD_LOC:
124 0 : return "ELF executable text/rodata segment has wrong starting address";
125 : case LOAD_BAD_SEGMENT:
126 0 : return "ELF executable contains an unexpected/unallowed segment/flags";
127 : case LOAD_REQUIRED_SEG_MISSING:
128 0 : return "ELF executable missing a required segment (text)";
129 : case LOAD_SEGMENT_BAD_PARAM:
130 0 : return "ELF executable segment header parameter error";
131 : case LOAD_VALIDATION_FAILED:
132 2 : return "Validation failure. File violates Native Client safety rules.";
133 : case LOAD_UNIMPLEMENTED:
134 0 : return "Not implemented for this architecture.";
135 : case SRT_NO_SEG_SEL:
136 0 : return "Service Runtime: cannot allocate segment selector";
137 : case LOAD_BAD_EHSIZE:
138 0 : return "ELFCLASS64 file header has wrong e_ehsize value";
139 : case LOAD_EHDR_OVERFLOW:
140 0 : return "ELFCLASS64 file header has fields that overflow 32 bits";
141 : case LOAD_PHDR_OVERFLOW:
142 4 : return "ELFCLASS64 program header has fields that overflow 32 bits";
143 : case LOAD_UNSUPPORTED_CPU:
144 0 : return "CPU model is not supported";
145 : case LOAD_NO_MEMORY_FOR_DYNAMIC_TEXT:
146 0 : return "Insufficient memory to allocate dynamic text region";
147 : case LOAD_NO_MEMORY_FOR_ADDRESS_SPACE:
148 0 : return "Insufficient memory to allocate untrusted address space";
149 : case LOAD_CODE_SEGMENT_TOO_LARGE:
150 0 : return "ELF executable's code segment is larger than the "
151 : "arbitrary size limit imposed to mitigate spraying attacks";
152 : case NACL_ERROR_CODE_MAX:
153 : /* A bad error code, but part of the enum so we need to list it here. */
154 0 : break;
155 : }
156 :
157 : /*
158 : * do not use default case label, to make sure that the compiler
159 : * will generate a warning with -Wswitch-enum for new codes
160 : * introduced in nacl_error_codes.h for which there is no
161 : * corresponding entry here. instead, we pretend that fall-through
162 : * from the switch is possible. (otherwise -W complains control
163 : * reaches end of non-void function.)
164 : */
165 0 : return "BAD ERROR CODE";
166 14 : }
|