summaryrefslogtreecommitdiffstats
path: root/private/os2/ssrtl/ntmap.c
blob: d2e0cf87fb14b2f4b86955f583d09f42dde6b605 (plain) (blame)
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    ntmap.c

Abstract:

    This module contains the functions to map NT values into OS/2 values
    and/or vice versa.  So far there are two functions defined:

        Or2MapStatus - maps NT Status Code into an OS/2 Error Code

        Or2MapProtectionToFlags - maps NT page protection flags into OS/2
                                  page protection flags

        Or2MapFlagsToProtection - maps OS/2 page protection flags into NT
                                  page protection flags

Author:

    Steve Wood (stevewo) 07-Jul-1990

Revision History:

--*/

#define INCL_OS2V20_MEMORY
#define INCL_OS2V20_ERRORS
#include "os2ssrtl.h"


APIRET
Or2MapStatus(
    IN NTSTATUS Status
    )
{
    //
    // Map all warning and error status codes to comparable OS/2 error codes.
    // Mappings that are defined, but probably incorrect, are marked with
    // FIX, FIX.  Mappings that are currently not defined are marked with
    // the ERROR_SS_UNKNOWN_STATUS symbol.  These later should be left as is
    // unless you know of a case where the status code is legitimate for the
    // OS/2 Subsystem and needs a defined mapping.
    //

    switch ( Status ) {
    case STATUS_SUCCESS:
        return( NO_ERROR);

    case STATUS_GUARD_PAGE_VIOLATION:
        return( ERROR_GUARDPAGE );

    case STATUS_DATATYPE_MISALIGNMENT:
        return( ERROR_NOACCESS );           // FIX, FIX - wait for new XCPT stuff

    case STATUS_BREAKPOINT:
    case STATUS_SINGLE_STEP:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_INTEGER_OVERFLOW:
        return( ERROR_ARITHMETIC_OVERFLOW );

    case STATUS_BUFFER_OVERFLOW:
        return( ERROR_BUFFER_OVERFLOW );

    case STATUS_NO_MORE_FILES:
        return( ERROR_NO_MORE_FILES );

    case STATUS_WAS_LOCKED:
    case STATUS_NOT_LOCKED:
    case STATUS_FILE_LOCK_CONFLICT:
    case STATUS_LOCK_NOT_GRANTED:
    case STATUS_RANGE_NOT_LOCKED:
    case STATUS_WAS_UNLOCKED:
        return( ERROR_LOCK_VIOLATION );

    case STATUS_NO_MORE_EAS:
        return( ERROR_NO_MORE_ITEMS );      // FIX, FIX - is this right?

    case STATUS_UNSUCCESSFUL:
        return( ERROR_GEN_FAILURE );

    case STATUS_NOT_IMPLEMENTED:
        return( ERROR_INVALID_FUNCTION );

    case STATUS_INVALID_INFO_CLASS:
    case STATUS_INFO_LENGTH_MISMATCH:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_ACCESS_VIOLATION:
        return( ERROR_PROTECTION_VIOLATION );           // FIX, FIX - wait for new XCPT stuff

    case STATUS_IN_PAGE_ERROR:
        return( ERROR_SWAPERROR );

    case STATUS_PAGEFILE_QUOTA:
        return( ERROR_NOT_ENOUGH_MEMORY );

    case STATUS_PAGEFILE_QUOTA_EXCEEDED:
        return( ERROR_SWAP_FILE_FULL );

    case STATUS_DISK_FULL:
    case STATUS_COMMITMENT_LIMIT:
        return( ERROR_DISK_FULL );

    case STATUS_INVALID_HANDLE:
    case STATUS_FILE_CLOSED:
    case STATUS_FILE_FORCED_CLOSED:
        return( ERROR_INVALID_HANDLE );

    case STATUS_BAD_INITIAL_STACK:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_BAD_INITIAL_PC:
        return( ERROR_BAD_EXE_FORMAT );     // FIX, FIX - should this be unknown?

    case STATUS_INVALID_CID:
    case STATUS_TIMER_NOT_CANCELED:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_INVALID_PARAMETER:
        return( ERROR_INVALID_PARAMETER );

    case STATUS_NO_SUCH_DEVICE:
        return( ERROR_INVALID_PATH );

    case STATUS_INVALID_DEVICE_REQUEST:
        return( ERROR_INVALID_FUNCTION );

    case STATUS_END_OF_FILE:
        return( ERROR_HANDLE_EOF );

    case STATUS_WRONG_VOLUME:
    case STATUS_UNRECOGNIZED_MEDIA:
    case STATUS_FILE_INVALID:
        return( ERROR_WRONG_DISK );

    case STATUS_NONEXISTENT_SECTOR:
        return( ERROR_SECTOR_NOT_FOUND );

    case STATUS_MORE_PROCESSING_REQUIRED:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_NO_MEMORY:
        return( ERROR_NOT_ENOUGH_MEMORY );

    case STATUS_NOT_MAPPED_VIEW:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_CONFLICTING_ADDRESSES:
    case STATUS_UNABLE_TO_FREE_VM:
    case STATUS_UNABLE_TO_DELETE_SECTION:
        return( ERROR_INVALID_ADDRESS );

    case STATUS_INVALID_SYSTEM_SERVICE:
        return( ERROR_INVALID_FUNCTION );

    case STATUS_ILLEGAL_INSTRUCTION:
        return( NO_ERROR );                 // FIX, FIX - wait for new XCPT stuff

    case STATUS_INVALID_LOCK_SEQUENCE:
    case STATUS_INVALID_VIEW_SIZE:
    case STATUS_INVALID_FILE_FOR_SECTION:
    case STATUS_ALREADY_COMMITTED:
    case STATUS_ACCESS_DENIED:
    case STATUS_CANNOT_DELETE:
    case STATUS_NOT_A_DIRECTORY:
        return( ERROR_ACCESS_DENIED );

    case STATUS_DIRECTORY_NOT_EMPTY:
        return( ERROR_CURRENT_DIRECTORY );

    case STATUS_BUFFER_TOO_SMALL:
        return( ERROR_INSUFFICIENT_BUFFER );

    case STATUS_OBJECT_TYPE_MISMATCH:
        return( ERROR_FILE_NOT_FOUND );     // FIX, FIX - is this bogus or not?

    case STATUS_NONCONTINUABLE_EXCEPTION:
    case STATUS_INVALID_DISPOSITION:
    case STATUS_UNWIND:
    case STATUS_BAD_STACK:
    case STATUS_INVALID_UNWIND_TARGET:
        return( NO_ERROR );                 // FIX, FIX - wait for new XCPT stuff

    case STATUS_PARITY_ERROR:
        return( NO_ERROR );                 // FIX, FIX - wait for new XCPT stuff

    case STATUS_UNABLE_TO_DECOMMIT_VM:
        return( ERROR_INVALID_ADDRESS );
        break;

    case STATUS_NOT_COMMITTED:
    case STATUS_INVALID_PORT_ATTRIBUTES:
    case STATUS_PORT_MESSAGE_TOO_LONG:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_INVALID_PARAMETER_MIX:
        return( ERROR_INVALID_PARAMETER );

    case STATUS_INVALID_QUOTA_LOWER:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_DISK_CORRUPT_ERROR:
        return( ERROR_NOT_DOS_DISK );       // FIX, FIX - is this the best choice?

    case STATUS_OBJECT_NAME_INVALID:
        return( ERROR_INVALID_NAME );

    case STATUS_OBJECT_PATH_NOT_FOUND:
    case STATUS_OBJECT_PATH_INVALID:
    case STATUS_OBJECT_PATH_SYNTAX_BAD:
    case STATUS_REDIRECTOR_NOT_STARTED:
        return( ERROR_PATH_NOT_FOUND );

    case STATUS_NOT_SUPPORTED:
        return( ERROR_NOT_SUPPORTED );

    case STATUS_REMOTE_NOT_LISTENING:
        return( ERROR_REM_NOT_LIST );

    case STATUS_DUPLICATE_NAME:
        return( ERROR_DUP_NAME );

    case STATUS_BAD_NETWORK_PATH:
        return( ERROR_BAD_NETPATH );

    case STATUS_NETWORK_BUSY:
        return( ERROR_NETWORK_BUSY );

    case STATUS_DEVICE_DOES_NOT_EXIST:
        return( ERROR_DEV_NOT_EXIST );

    case STATUS_TOO_MANY_COMMANDS:
        return( ERROR_TOO_MANY_CMDS );

    case STATUS_ADAPTER_HARDWARE_ERROR:
        return( ERROR_ADAP_HDW_ERR );

    case STATUS_INVALID_NETWORK_RESPONSE:
        return( ERROR_BAD_NET_RESP );

    case STATUS_UNEXPECTED_NETWORK_ERROR:
        return( ERROR_UNEXP_NET_ERR );

    case STATUS_BAD_REMOTE_ADAPTER:
        return( ERROR_BAD_REM_ADAP );

    case STATUS_OBJECT_NAME_NOT_FOUND:
    case STATUS_NO_SUCH_FILE:
    case STATUS_DLL_NOT_FOUND:
    case STATUS_FILE_IS_A_DIRECTORY:
    case STATUS_DELETE_PENDING:
        return( ERROR_FILE_NOT_FOUND );


    case STATUS_OBJECT_NAME_COLLISION:
        return( ERROR_FILE_EXISTS );

    case STATUS_INVALID_PIPE_STATE:
    case STATUS_PIPE_DISCONNECTED:
        return( ERROR_PIPE_NOT_CONNECTED );

    case STATUS_PIPE_BROKEN:
        return( ERROR_BROKEN_PIPE );

    case STATUS_BAD_NETWORK_NAME:
        return( ERROR_BAD_NET_NAME );

    case STATUS_VIRTUAL_CIRCUIT_CLOSED:
        return( ERROR_VC_DISCONNECTED );

    case STATUS_NET_WRITE_FAULT:
        return( ERROR_NET_WRITE_FAULT );

    case STATUS_PIPE_NOT_AVAILABLE:
        return( ERROR_PIPE_BUSY );

    case STATUS_PORT_DISCONNECTED:
    case STATUS_DEVICE_ALREADY_ATTACHED:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_DATA_OVERRUN:
    case STATUS_DATA_LATE_ERROR:
    case STATUS_DATA_ERROR:
         return( ERROR_BAD_LENGTH );        // FIX, FIX - is there a better choice?

    case STATUS_CRC_ERROR:
        return( ERROR_CRC );

    case STATUS_SECTION_TOO_BIG:
    case STATUS_PORT_CONNECTION_REFUSED:
    case STATUS_INVALID_PORT_HANDLE:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_SHARING_VIOLATION:
        return( ERROR_SHARING_VIOLATION );

    case STATUS_QUOTA_EXCEEDED:
        return( ERROR_NOT_ENOUGH_MEMORY );

    case STATUS_INVALID_PAGE_PROTECTION:
        return( ERROR_PMM_INVALID_FLAGS );

    case STATUS_MUTANT_NOT_OWNED:
        return( ERROR_NOT_OWNER );

    case STATUS_SEMAPHORE_LIMIT_EXCEEDED:
        return( ERROR_TOO_MANY_POSTS );

    case STATUS_PORT_ALREADY_SET:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_SECTION_NOT_IMAGE:
    case STATUS_SUSPEND_COUNT_EXCEEDED:
    case STATUS_THREAD_IS_TERMINATING:
    case STATUS_BAD_WORKING_SET_LIMIT:
    case STATUS_INCOMPATIBLE_FILE_MAP:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_SECTION_PROTECTION:
        return( ERROR_PMM_INVALID_FLAGS );

    case STATUS_EAS_NOT_SUPPORTED:
        return( ERROR_EAS_NOT_SUPPORTED );

    case STATUS_NONEXISTENT_EA_ENTRY:
        return( ERROR_INVALID_EA_NAME );

    case STATUS_EA_TOO_LARGE:
        return( ERROR_EA_LIST_TOO_LONG );

    case STATUS_EA_CORRUPT_ERROR:
        return( ERROR_EA_FILE_CORRUPT );

    case STATUS_CTL_FILE_NOT_SUPPORTED:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_UNKNOWN_REVISION:
    case STATUS_REVISION_MISMATCH:
    case STATUS_INVALID_OWNER:
    case STATUS_INVALID_PRIMARY_GROUP:
    case STATUS_NO_IMPERSONATION_TOKEN:
    case STATUS_CANT_DISABLE_MANDATORY:
    case STATUS_NO_LOGON_SERVERS:
    case STATUS_NO_SUCH_LOGON_SESSION:
    case STATUS_NO_SUCH_PRIVILEGE:
    case STATUS_PRIVILEGE_NOT_HELD:
    case STATUS_INVALID_ACCOUNT_NAME:
    case STATUS_USER_EXISTS:
    case STATUS_NO_SUCH_USER:
    case STATUS_GROUP_EXISTS:
    case STATUS_NO_SUCH_GROUP:
    case STATUS_SPECIAL_GROUP:
    case STATUS_MEMBER_IN_GROUP:
    case STATUS_MEMBER_NOT_IN_GROUP:
    case STATUS_LAST_ADMIN:
//        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );
        return( ERROR_ACCESS_DENIED );

    case STATUS_WRONG_PASSWORD:
        return( ERROR_INVALID_PASSWORD );

    case STATUS_ILL_FORMED_PASSWORD:
        return( ERROR_INVALID_PASSWORD );

    case STATUS_PASSWORD_RESTRICTION:
        return( ERROR_INVALID_PASSWORD );

    case STATUS_LOGON_FAILURE:
    case STATUS_ACCOUNT_RESTRICTION:
    case STATUS_INVALID_LOGON_HOURS:
    case STATUS_INVALID_WORKSTATION:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_PASSWORD_EXPIRED:
        return( ERROR_INVALID_PASSWORD );

    case STATUS_ACCOUNT_DISABLED:
    case STATUS_NONE_MAPPED:
    case STATUS_TOO_MANY_LUIDS_REQUESTED:
    case STATUS_LUIDS_EXHAUSTED:
    case STATUS_INVALID_SUB_AUTHORITY:
    case STATUS_INVALID_ACL:
    case STATUS_INVALID_SID:
    case STATUS_INVALID_SECURITY_DESCR:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_PROCEDURE_NOT_FOUND:
        return( ERROR_PROC_NOT_FOUND );

    case STATUS_INVALID_IMAGE_FORMAT:
        return( ERROR_BAD_EXE_FORMAT );

    case STATUS_INVALID_IMAGE_NE_FORMAT:
    case STATUS_INVALID_IMAGE_LE_FORMAT:
        return ( ERROR_BAD_FORMAT );

    case STATUS_NO_TOKEN:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_INVALID_EA_NAME:
        /*
           BUBUG: Some cases where NT expects STATUS_INVALID_EA_NAME instead -
                  see filio204, variation 1
        */
        return( ERROR_INVALID_EA_NAME );

    case STATUS_EA_LIST_INCONSISTENT:
        return( ERROR_EA_LIST_INCONSISTENT );

    case STATUS_NO_EAS_ON_FILE:
        return( ERROR_NEED_EAS_FOUND );     // FIX, FIX - is there a mapping?

    case STATUS_SERVER_DISABLED:
    case STATUS_SERVER_NOT_DISABLED:
    case STATUS_TOO_MANY_GUIDS_REQUESTED:
    case STATUS_GUIDS_EXHAUSTED:
    case STATUS_INVALID_ID_AUTHORITY:
    case STATUS_AGENTS_EXHAUSTED:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_INVALID_VOLUME_LABEL:
    case STATUS_SECTION_NOT_EXTENDED:
    case STATUS_NOT_MAPPED_DATA:

    case STATUS_RESOURCE_DATA_NOT_FOUND:
    case STATUS_RESOURCE_TYPE_NOT_FOUND:
    case STATUS_RESOURCE_NAME_NOT_FOUND:
        return( ERROR_INVALID_PARAMETER );

    case STATUS_ARRAY_BOUNDS_EXCEEDED:
    case STATUS_FLOAT_DENORMAL_OPERAND:
    case STATUS_FLOAT_DIVIDE_BY_ZERO:
    case STATUS_FLOAT_INEXACT_RESULT:
    case STATUS_FLOAT_INVALID_OPERATION:
    case STATUS_FLOAT_OVERFLOW:
    case STATUS_FLOAT_STACK_CHECK:
    case STATUS_FLOAT_UNDERFLOW:
    case STATUS_INTEGER_DIVIDE_BY_ZERO:
    case STATUS_PRIVILEGED_INSTRUCTION:
        return( NO_ERROR );                 // FIX, FIX - wait for new XCPT stuff

    case STATUS_TOO_MANY_PAGING_FILES:
    case STATUS_ALLOTTED_SPACE_EXCEEDED:
    case STATUS_INSUFFICIENT_RESOURCES:
        return( ERROR_NOT_ENOUGH_MEMORY );

    case STATUS_DFS_EXIT_PATH_FOUND:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );

    case STATUS_DEVICE_PAPER_EMPTY:
        return( ERROR_OUT_OF_PAPER );

    case STATUS_NO_MEDIA_IN_DEVICE:
    case STATUS_DEVICE_NOT_READY:
    case STATUS_DEVICE_POWERED_OFF:
    case STATUS_DEVICE_OFF_LINE:
    case STATUS_DEVICE_NOT_CONNECTED:
    case STATUS_DEVICE_POWER_FAILURE:
        return( ERROR_NOT_READY );

    case STATUS_MEDIA_WRITE_PROTECTED:
        return( ERROR_WRITE_PROTECT );

    case STATUS_DEVICE_DATA_ERROR:
         return( ERROR_BAD_LENGTH );        // FIX, FIX - is there a better choice?

    case STATUS_DEVICE_BUSY:
        return( ERROR_BUSY );               // FIX, FIX - is there a better choice?

    case STATUS_FREE_VM_NOT_AT_BASE:
    case STATUS_MEMORY_NOT_ALLOCATED:
        return( ERROR_INVALID_ADDRESS );

    case STATUS_IO_TIMEOUT:
        return( ERROR_SEM_TIMEOUT );

    case STATUS_INSTANCE_NOT_AVAILABLE:
        return( ERROR_PIPE_BUSY );

    case STATUS_NOT_SAME_DEVICE:
        return( ERROR_NOT_SAME_DEVICE );

    default:
        return( ERROR_SS_UNKNOWN_STATUS | (USHORT)Status );
    }
}


UCHAR Or2MapFlagsTable[ 8 ] = {
    0,                              // 0
    PAGE_READONLY,                  // PAG_READ
    PAGE_READWRITE,                 // PAG_WRITE
    PAGE_READWRITE,                 // PAG_READ | PAG_WRITE
    PAGE_EXECUTE,                   // PAG_EXECUTE
    PAGE_EXECUTE_READ,              // PAG_EXECUTE | PAG_READ
    PAGE_EXECUTE_READWRITE,         // PAG_EXECUTE | PAG_WRITE
    PAGE_EXECUTE_READWRITE          // PAG_EXECUTE | PAG_READ | PAG_WRITE
};

#if (PAG_EXECUTE | PAG_READ | PAG_WRITE) != 0x7
#error PAG_EXECUTE | PAG_READ | PAG_WRITE incorrectly defined.
#endif

UCHAR Or2MapProtectionTable[ 16 ] = {
    0,                              // 0                (0x0)
    0,                              // PAGE_NOACCESS    (0x1)
    PAG_READ,                       // PAGE_READONLY    (0x2)
    0,                              // 0                (0x3)
    PAG_READ | PAG_WRITE,           // PAGE_READWRITE   (0x4)
    0,                              // 0                (0x5)
    0,                              // 0                (0x6)
    0,                              // 0                (0x7)
    0,                              // PAGE_WRITECOPY   (0x8)
    0,                              // 0                (0x9)
    0,                              // 0                (0xA)
    0,                              // 0                (0xB)
    0,                              // 0                (0xC)
    0,                              // 0                (0xD)
    0,                              // 0                (0xE)
    0                               // 0                (0xF)
};

#if (PAGE_NOACCESS | PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY) != 0xF
#error PAGE_NOACCESS | PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY incorrectly defined.
#endif

#if (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) != 0xF0
#error PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY incorrectly defined.
#endif

APIRET
Or2MapFlagsToProtection(
    ULONG Flags,
    PULONG Protection
    )
{
    *Protection = Or2MapFlagsTable[ Flags & ( PAG_EXECUTE |
                                              PAG_READ |
                                              PAG_WRITE
                                            )
                                  ];
    if (*Protection == 0) {
        return( ERROR_INVALID_PARAMETER );
        }
    else {
        if (Flags & PAG_GUARD) {
            *Protection |= PAGE_GUARD;
            }

        return( NO_ERROR );
        }
}

APIRET
Or2MapProtectionToFlags(
    ULONG Protection,
    PULONG Flags
    )
{
    if (Protection & 0x0F) {
        *Flags = Or2MapProtectionTable[ Protection & 0x0F ];
        }
    else
    if (Protection & 0xF0) {
        *Flags = Or2MapProtectionTable[ (Protection & 0xF0) >> 4 ] |
                 PAG_EXECUTE;
        }
    else {
        *Flags = 0;
        }

    if (*Flags == 0) {
        return( ERROR_INVALID_PARAMETER );
        }
    else {
        if (Protection & PAGE_GUARD) {
            *Flags |= PAG_GUARD;
            }

        return( NO_ERROR );
        }
}

APIRET
Or2MapNtStatusToOs2Error(
    IN NTSTATUS Status,
    IN APIRET   DefaultRetCode
    )
{
    APIRET RetCode;

    RetCode = Or2MapStatus(Status);
    if ((RetCode & ERROR_SS_UNKNOWN_STATUS) == ERROR_SS_UNKNOWN_STATUS) {
#if DBG
        DbgPrint("OS2SSRTL: Or2MapNtStatusToOs2Error: Using default mapping: 0x%x => %d\n",
                  Status, DefaultRetCode);
#endif
        return DefaultRetCode;
    }
    return (RetCode);
}