2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 #include <mach/boolean.h>
60 #include <mach/error.h>
61 #include <mach/mach_error.h>
66 static void do_compat(mach_error_t
*);
69 do_compat(mach_error_t
*org_err
)
71 mach_error_t err
= *org_err
;
74 * map old error numbers to
75 * to new error sys & subsystem
78 if ((-200 < err
) && (err
<= -100)) {
79 err
= -(err
+ 100) | IPC_SEND_MOD
;
80 } else if ((-300 < err
) && (err
<= -200)) {
81 err
= -(err
+ 200) | IPC_RCV_MOD
;
82 } else if ((-400 < err
) && (err
<= -300)) {
83 err
= -(err
+ 300) | MACH_IPC_MIG_MOD
;
84 } else if ((1000 <= err
) && (err
< 1100)) {
85 err
= (err
- 1000) | SERV_NETNAME_MOD
;
86 } else if ((1600 <= err
) && (err
< 1700)) {
87 err
= (err
- 1600) | SERV_ENV_MOD
;
88 } else if ((27600 <= err
) && (err
< 27700)) {
89 err
= (err
- 27600) | SERV_EXECD_MOD
;
96 err_sparse_mapit(int old
, const struct error_sparse_map
*map_table
, int mapcnt
)
98 boolean_t found
= FALSE
;
101 for (i
= 0; i
< mapcnt
; i
++) {
102 struct error_sparse_map entry
= map_table
[i
];
104 if (entry
.start
<= old
&& old
<= entry
.end
) {
105 ret
+= old
- entry
.start
;
109 ret
+= entry
.end
- entry
.start
+ 1;
112 return (found
)? ret
: INT_MAX
;
116 mach_error_type(mach_error_t err
)
118 const struct error_system
*sys_p
;
123 system
= err_get_system(err
);
124 sys_p
= &_mach_errors
[system
];
125 sub
= err_get_sub(err
);
127 if (system
<= err_max_system
&& sys_p
->map_table
) {
128 sub
= err_sparse_mapit(sub
, sys_p
->map_table
, sys_p
->map_count
);
131 if (system
> err_max_system
|| sub
>= sys_p
->max_sub
) {
132 return (char *)"(?/?)";
134 return (char *) (sys_p
->subsystem
[sub
].subsys_name
);
137 boolean_t mach_error_full_diag
= FALSE
;
139 __private_extern__
char *
140 mach_error_string_int(mach_error_t err
, boolean_t
*diag
)
142 const struct error_system
*sys_p
;
143 const struct error_subsystem
*sub_p
;
144 int sub
, system
, code
;
148 system
= err_get_system(err
);
149 sys_p
= &_mach_errors
[system
];
150 sub
= err_get_sub(err
);
151 code
= err_get_code(err
);
155 if (system
> err_max_system
) {
156 return (char *)"(?/?) unknown error system";
157 } else if (sys_p
->map_table
) {
158 sub
= err_sparse_mapit(sub
, sys_p
->map_table
, sys_p
->map_count
);
161 if (sub
>= sys_p
->max_sub
) {
162 return (char *)sys_p
->bad_sub
;
165 sub_p
= &sys_p
->subsystem
[sub
];
166 if (sub_p
->map_table
) {
167 code
= err_sparse_mapit(code
, sub_p
->map_table
, sub_p
->map_count
);
169 if (code
>= sub_p
->max_code
) {
170 return (char *)NO_SUCH_ERROR
;
173 *diag
= mach_error_full_diag
;
174 return (char *)sub_p
->codes
[code
];
178 mach_error_string(mach_error_t err
)
182 return mach_error_string_int( err
, &diag
);