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
;
95 err_sparse_mapit(int old
, const struct error_sparse_map
*map_table
, int mapcnt
)
97 boolean_t found
= FALSE
;
100 for (i
= 0; i
< mapcnt
; i
++) {
101 struct error_sparse_map entry
= map_table
[i
];
103 if (entry
.start
<= old
&& old
<= entry
.end
) {
104 ret
+= old
- entry
.start
;
108 ret
+= entry
.end
- entry
.start
+ 1;
111 return (found
)? ret
: INT_MAX
;
115 mach_error_type(mach_error_t err
)
117 const struct error_system
*sys_p
;
122 system
= err_get_system(err
);
123 sys_p
= &_mach_errors
[system
];
124 sub
= err_get_sub(err
);
126 if (system
<= err_max_system
&& sys_p
->map_table
)
127 sub
= err_sparse_mapit(sub
, sys_p
->map_table
, sys_p
->map_count
);
129 if (system
> err_max_system
|| sub
>= sys_p
->max_sub
)
130 return((char *)"(?/?)");
131 return (char *) (sys_p
->subsystem
[sub
].subsys_name
);
134 boolean_t mach_error_full_diag
= FALSE
;
136 __private_extern__
char *
137 mach_error_string_int(mach_error_t err
, boolean_t
*diag
)
139 const struct error_system
*sys_p
;
140 const struct error_subsystem
*sub_p
;
141 int sub
, system
, code
;
145 system
= err_get_system(err
);
146 sys_p
= &_mach_errors
[system
];
147 sub
= err_get_sub(err
);
148 code
= err_get_code(err
);
152 if (system
> err_max_system
)
153 return((char *)"(?/?) unknown error system");
154 else if (sys_p
->map_table
)
155 sub
= err_sparse_mapit(sub
, sys_p
->map_table
, sys_p
->map_count
);
157 if (sub
>= sys_p
->max_sub
)
158 return((char *)sys_p
->bad_sub
);
160 sub_p
= &sys_p
->subsystem
[sub
];
161 if (sub_p
->map_table
)
162 code
= err_sparse_mapit(code
, sub_p
->map_table
, sub_p
->map_count
);
163 if (code
>= sub_p
->max_code
)
164 return ((char *)NO_SUCH_ERROR
);
166 *diag
= mach_error_full_diag
;
167 return( (char *)sub_p
->codes
[code
] );
171 mach_error_string(mach_error_t err
)
175 return mach_error_string_int( err
, &diag
);