-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.c
583 lines (562 loc) · 16.3 KB
/
error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#include <stdio.h>
#include <3ds.h>
#include "common.h"
static const char* level_to_string(Result res) {
switch(R_LEVEL(res)) {
case RL_SUCCESS:
return "Success";
case RL_INFO:
return "Info";
case RL_FATAL:
return "Fatal";
case RL_RESET:
return "Reset";
case RL_REINITIALIZE:
return "Reinitialize";
case RL_USAGE:
return "Usage";
case RL_PERMANENT:
return "Permanent";
case RL_TEMPORARY:
return "Temporary";
case RL_STATUS:
return "Status";
default:
return "<unknown>";
}
}
static const char* summary_to_string(Result res) {
switch(R_SUMMARY(res)) {
case RS_SUCCESS:
return "Success";
case RS_NOP:
return "Nop";
case RS_WOULDBLOCK:
return "Would block";
case RS_OUTOFRESOURCE:
return "Out of resource";
case RS_NOTFOUND:
return "Not found";
case RS_INVALIDSTATE:
return "Invalid state";
case RS_NOTSUPPORTED:
return "Not supported";
case RS_INVALIDARG:
return "Invalid argument";
case RS_WRONGARG:
return "Wrong argument";
case RS_CANCELED:
return "Canceled";
case RS_STATUSCHANGED:
return "Status changed";
case RS_INTERNAL:
return "Internal";
default:
return "<unknown>";
}
}
static const char* module_to_string(Result res) {
switch(R_MODULE(res)) {
case RM_COMMON:
return "Common";
case RM_KERNEL:
return "Kernel";
case RM_UTIL:
return "Util";
case RM_FILE_SERVER:
return "File server";
case RM_LOADER_SERVER:
return "Loader server";
case RM_TCB:
return "TCB";
case RM_OS:
return "OS";
case RM_DBG:
return "DBG";
case RM_DMNT:
return "DMNT";
case RM_PDN:
return "PDN";
case RM_GSP:
return "GSP";
case RM_I2C:
return "I2C";
case RM_GPIO:
return "GPIO";
case RM_DD:
return "DD";
case RM_CODEC:
return "CODEC";
case RM_SPI:
return "SPI";
case RM_PXI:
return "PXI";
case RM_FS:
return "FS";
case RM_DI:
return "DI";
case RM_HID:
return "HID";
case RM_CAM:
return "CAM";
case RM_PI:
return "PI";
case RM_PM:
return "PM";
case RM_PM_LOW:
return "PMLOW";
case RM_FSI:
return "FSI";
case RM_SRV:
return "SRV";
case RM_NDM:
return "NDM";
case RM_NWM:
return "NWM";
case RM_SOC:
return "SOC";
case RM_LDR:
return "LDR";
case RM_ACC:
return "ACC";
case RM_ROMFS:
return "RomFS";
case RM_AM:
return "AM";
case RM_HIO:
return "HIO";
case RM_UPDATER:
return "Updater";
case RM_MIC:
return "MIC";
case RM_FND:
return "FND";
case RM_MP:
return "MP";
case RM_MPWL:
return "MPWL";
case RM_AC:
return "AC";
case RM_HTTP:
return "HTTP";
case RM_DSP:
return "DSP";
case RM_SND:
return "SND";
case RM_DLP:
return "DLP";
case RM_HIO_LOW:
return "HIOLOW";
case RM_CSND:
return "CSND";
case RM_SSL:
return "SSL";
case RM_AM_LOW:
return "AMLOW";
case RM_NEX:
return "NEX";
case RM_FRIENDS:
return "Friends";
case RM_RDT:
return "RDT";
case RM_APPLET:
return "Applet";
case RM_NIM:
return "NIM";
case RM_PTM:
return "PTM";
case RM_MIDI:
return "MIDI";
case RM_MC:
return "MC";
case RM_SWC:
return "SWC";
case RM_FATFS:
return "FatFS";
case RM_NGC:
return "NGC";
case RM_CARD:
return "CARD";
case RM_CARDNOR:
return "CARDNOR";
case RM_SDMC:
return "SDMC";
case RM_BOSS:
return "BOSS";
case RM_DBM:
return "DBM";
case RM_CONFIG:
return "Config";
case RM_PS:
return "PS";
case RM_CEC:
return "CEC";
case RM_IR:
return "IR";
case RM_UDS:
return "UDS";
case RM_PL:
return "PL";
case RM_CUP:
return "CUP";
case RM_GYROSCOPE:
return "Gyroscope";
case RM_MCU:
return "MCU";
case RM_NS:
return "NS";
case RM_NEWS:
return "NEWS";
case RM_RO:
return "RO";
case RM_GD:
return "GD";
case RM_CARD_SPI:
return "CARDSPI";
case RM_EC:
return "EC";
case RM_WEB_BROWSER:
return "Web browser";
case RM_TEST:
return "TEST";
case RM_ENC:
return "ENC";
case RM_PIA:
return "PIA";
case RM_ACT:
return "ACT";
case RM_VCTL:
return "VCTL";
case RM_OLV:
return "OLV";
case RM_NEIA:
return "NEIA";
case RM_NPNS:
return "NPNS";
case RM_AVD:
return "AVD";
case RM_L2B:
return "L2B";
case RM_MVD:
return "MVD";
case RM_NFC:
return "NFC";
case RM_UART:
return "UART";
case RM_SPM:
return "SPM";
case RM_QTM:
return "QTM";
case RM_NFP:
return "NFP";
case RM_APPLICATION:
return "Application";
default:
return "<unknown>";
}
}
static const char* description_to_string(Result res) {
int module = R_MODULE(res);
int description = R_DESCRIPTION(res);
switch(module) {
case RM_KERNEL:
switch(description) {
case 2:
return "Invalid DMA buffer memory permissions";
default:
break;
}
break;
case RM_OS:
switch(description) {
case 1:
return "Out of synchronization object";
case 2:
return "Out of shared memory objects";
case 9:
return "Out of session objects";
case 10:
return "Not enough memory for allocation";
case 20:
return "Wrong permissions for unprivileged access";
case 26:
return "Session closed by remote process";
case 47:
return "Invalid command header";
case 52:
return "Max port connections exceeded";
default:
break;
}
break;
case RM_FS:
switch(description) {
case 101:
return "Archive not mounted";
case 120:
return "Doesn't exist / Failed to open";
case 141:
return "Game card not inserted";
case 171:
return "Bus: Busy / Underrun";
case 172:
return "Bus: Illegal function";
case 190:
return "Already exists / Failed to create";
case 210:
return "Partition full";
case 230:
return "Illegal operation / File in use";
case 231:
return "Resource locked";
case 250:
return "FAT operation denied";
case 265:
return "Bus: Timeout";
case 331:
return "Bus error / TWL partition invalid";
case 332:
return "Bus: Stop bit error";
case 391:
return "Hash verification failure";
case 392:
return "RSA/Hash verification failure";
case 395:
return "Invalid RomFS or save data block hash";
case 630:
return "Archive permission denied";
case 702:
return "Invalid path / Inaccessible archive";
case 705:
return "Offset out of bounds";
case 721:
return "Reached file size limit";
case 760:
return "Unsupported operation";
case 761:
return "ExeFS read size mismatch";
default:
break;
}
break;
case RM_SRV:
switch(description) {
case 5:
return "Invalid service name length";
case 6:
return "Service access denied";
case 7:
return "String size mismatch";
default:
break;
}
break;
case RM_AM:
switch(description) {
case 4:
return "Wrong installation state";
case 37:
return "Invalid NCCH";
case 39:
return "Invalid or outdated title version";
case 41:
return "Error type 1";
case 43:
return "Database does not exist";
case 44:
return "Attempted to delete system title";
case 101:
return "Error type -1";
case 102:
return "Error type -2";
case 103:
return "Error type -3";
case 104:
return "Error type -4";
case 105:
return "Error type -5";
case 106:
return "Cert signature or hash check failed";
case 107:
return "Error type -7";
case 108:
return "Error type -8";
case 109:
return "Error type -9";
case 110:
return "Error type -10";
case 111:
return "Error type -11";
case 112:
return "Error type -12";
case 113:
return "Error type -13";
case 114:
return "Error type -14";
case 393:
return "Invalid database";
default:
break;
}
break;
case RM_HTTP:
switch(description) {
case 60:
return "Failed to verify TLS certificate";
case 70:
return "Network unavailable";
case 102:
return "Wrong context handle";
case 105:
return "Request timed out";
default:
break;
}
break;
case RM_SSL:
switch(description) {
case 20:
return "Untrusted RootCA";
case 54:
return "RootCertChain handle not found";
default:
break;
}
break;
case RM_SDMC:
switch(description) {
case 1:
return "Bus: Bit23 error";
case 2:
return "Bus: RX ready error";
case 3:
return "Bus: Bit28 error";
case 4:
return "Bus: Bit27 error";
default:
break;
}
break;
case RM_MVD:
switch(description) {
case 271:
return "Invalid configuration";
default:
break;
}
break;
case RM_NFC:
switch(description) {
case 512:
return "Invalid NFC state";
default:
break;
}
break;
case RM_QTM:
switch(description) {
case 8:
return "Camera busy";
default:
break;
}
break;
case RM_APPLICATION:
switch(res) {
case R_FBI_CANCELLED:
return "Operation cancelled";
case R_FBI_HTTP_RESPONSE_CODE:
return "HTTP request returned error";
case R_FBI_WRONG_SYSTEM:
return "Attempted to install an N3DS title on an O3DS";
case R_FBI_INVALID_ARGUMENT:
return "Invalid argument";
case R_FBI_THREAD_CREATE_FAILED:
return "Thread creation failed";
case R_FBI_PARSE_FAILED:
return "Parse failed";
case R_FBI_BAD_DATA:
return "Bad data";
case R_FBI_TOO_MANY_REDIRECTS:
return "Too many redirects";
default:
break;
}
default:
break;
}
switch(description) {
case RD_SUCCESS:
return "Success";
case RD_TIMEOUT:
return "Timeout";
case RD_OUT_OF_RANGE:
return "Out of range";
case RD_ALREADY_EXISTS:
return "Already exists";
case RD_CANCEL_REQUESTED:
return "Cancel requested";
case RD_NOT_FOUND:
return "Not found";
case RD_ALREADY_INITIALIZED:
return "Already initialized";
case RD_NOT_INITIALIZED:
return "Not initialized";
case RD_INVALID_HANDLE:
return "Invalid handle";
case RD_INVALID_POINTER:
return "Invalid pointer";
case RD_INVALID_ADDRESS:
return "Invalid address";
case RD_NOT_IMPLEMENTED:
return "Not implemented";
case RD_OUT_OF_MEMORY:
return "Out of memory";
case RD_MISALIGNED_SIZE:
return "Misaligned size";
case RD_MISALIGNED_ADDRESS:
return "Misaligned address";
case RD_BUSY:
return "Busy";
case RD_NO_DATA:
return "No data";
case RD_INVALID_COMBINATION:
return "Invalid combination";
case RD_INVALID_ENUM_VALUE:
return "Invalid enum value";
case RD_INVALID_SIZE:
return "Invalid size";
case RD_ALREADY_DONE:
return "Already done";
case RD_NOT_AUTHORIZED:
return "Not authorized";
case RD_TOO_LARGE:
return "Too large";
case RD_INVALID_SELECTION:
return "Invalid selection";
default:
return "<unknown>";
}
}
typedef union
{
struct
{
unsigned description : 10;
unsigned module : 8;
unsigned : 3;
unsigned summary : 6;
unsigned level : 5;
};
Result val;
} ctr_result_value;
void dump_result_value(Result val)
{
ctr_result_value res;
res.val = val;
printf("result : 0x%08lX\n", val);
printf("description : %s (%u)\n", description_to_string(res.val), res.description);
printf("module : %s (%u)\n", module_to_string(res.val), res.module);
printf("summary : %s (%u)\n", summary_to_string(res.val), res.summary);
printf("level : %s (%u)\n", level_to_string(res.val), res.level);
}