1*27b03b36SApple OSS Distributions /*
2*27b03b36SApple OSS Distributions * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3*27b03b36SApple OSS Distributions *
4*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*27b03b36SApple OSS Distributions *
6*27b03b36SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*27b03b36SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*27b03b36SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*27b03b36SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*27b03b36SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*27b03b36SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*27b03b36SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*27b03b36SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*27b03b36SApple OSS Distributions *
15*27b03b36SApple OSS Distributions * Please obtain a copy of the License at
16*27b03b36SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*27b03b36SApple OSS Distributions *
18*27b03b36SApple OSS Distributions * The Original Code and all software distributed under the License are
19*27b03b36SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*27b03b36SApple OSS Distributions * Please see the License for the specific language governing rights and
24*27b03b36SApple OSS Distributions * limitations under the License.
25*27b03b36SApple OSS Distributions *
26*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*27b03b36SApple OSS Distributions */
28*27b03b36SApple OSS Distributions /*
29*27b03b36SApple OSS Distributions * @OSF_COPYRIGHT@
30*27b03b36SApple OSS Distributions */
31*27b03b36SApple OSS Distributions /*
32*27b03b36SApple OSS Distributions * Mach Operating System
33*27b03b36SApple OSS Distributions * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34*27b03b36SApple OSS Distributions * All Rights Reserved.
35*27b03b36SApple OSS Distributions *
36*27b03b36SApple OSS Distributions * Permission to use, copy, modify and distribute this software and its
37*27b03b36SApple OSS Distributions * documentation is hereby granted, provided that both the copyright
38*27b03b36SApple OSS Distributions * notice and this permission notice appear in all copies of the
39*27b03b36SApple OSS Distributions * software, derivative works or modified versions, and any portions
40*27b03b36SApple OSS Distributions * thereof, and that both notices appear in supporting documentation.
41*27b03b36SApple OSS Distributions *
42*27b03b36SApple OSS Distributions * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43*27b03b36SApple OSS Distributions * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44*27b03b36SApple OSS Distributions * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45*27b03b36SApple OSS Distributions *
46*27b03b36SApple OSS Distributions * Carnegie Mellon requests users of this software to return to
47*27b03b36SApple OSS Distributions *
48*27b03b36SApple OSS Distributions * Software Distribution Coordinator or [email protected]
49*27b03b36SApple OSS Distributions * School of Computer Science
50*27b03b36SApple OSS Distributions * Carnegie Mellon University
51*27b03b36SApple OSS Distributions * Pittsburgh PA 15213-3890
52*27b03b36SApple OSS Distributions *
53*27b03b36SApple OSS Distributions * any improvements or extensions that they make and grant Carnegie Mellon
54*27b03b36SApple OSS Distributions * the rights to redistribute these changes.
55*27b03b36SApple OSS Distributions */
56*27b03b36SApple OSS Distributions
57*27b03b36SApple OSS Distributions #include <limits.h>
58*27b03b36SApple OSS Distributions
59*27b03b36SApple OSS Distributions #include <mach/boolean.h>
60*27b03b36SApple OSS Distributions #include <mach/error.h>
61*27b03b36SApple OSS Distributions #include <mach/mach_error.h>
62*27b03b36SApple OSS Distributions
63*27b03b36SApple OSS Distributions #include "errorlib.h"
64*27b03b36SApple OSS Distributions #include "externs.h"
65*27b03b36SApple OSS Distributions
66*27b03b36SApple OSS Distributions static void do_compat(mach_error_t *);
67*27b03b36SApple OSS Distributions
68*27b03b36SApple OSS Distributions static void
do_compat(mach_error_t * org_err)69*27b03b36SApple OSS Distributions do_compat(mach_error_t *org_err)
70*27b03b36SApple OSS Distributions {
71*27b03b36SApple OSS Distributions mach_error_t err = *org_err;
72*27b03b36SApple OSS Distributions
73*27b03b36SApple OSS Distributions /*
74*27b03b36SApple OSS Distributions * map old error numbers to
75*27b03b36SApple OSS Distributions * to new error sys & subsystem
76*27b03b36SApple OSS Distributions */
77*27b03b36SApple OSS Distributions
78*27b03b36SApple OSS Distributions if ((-200 < err) && (err <= -100)) {
79*27b03b36SApple OSS Distributions err = -(err + 100) | IPC_SEND_MOD;
80*27b03b36SApple OSS Distributions } else if ((-300 < err) && (err <= -200)) {
81*27b03b36SApple OSS Distributions err = -(err + 200) | IPC_RCV_MOD;
82*27b03b36SApple OSS Distributions } else if ((-400 < err) && (err <= -300)) {
83*27b03b36SApple OSS Distributions err = -(err + 300) | MACH_IPC_MIG_MOD;
84*27b03b36SApple OSS Distributions } else if ((1000 <= err) && (err < 1100)) {
85*27b03b36SApple OSS Distributions err = (err - 1000) | SERV_NETNAME_MOD;
86*27b03b36SApple OSS Distributions } else if ((1600 <= err) && (err < 1700)) {
87*27b03b36SApple OSS Distributions err = (err - 1600) | SERV_ENV_MOD;
88*27b03b36SApple OSS Distributions } else if ((27600 <= err) && (err < 27700)) {
89*27b03b36SApple OSS Distributions err = (err - 27600) | SERV_EXECD_MOD;
90*27b03b36SApple OSS Distributions }
91*27b03b36SApple OSS Distributions
92*27b03b36SApple OSS Distributions *org_err = err;
93*27b03b36SApple OSS Distributions }
94*27b03b36SApple OSS Distributions
95*27b03b36SApple OSS Distributions static int
err_sparse_mapit(int old,const struct error_sparse_map * map_table,int mapcnt)96*27b03b36SApple OSS Distributions err_sparse_mapit(int old, const struct error_sparse_map *map_table, int mapcnt)
97*27b03b36SApple OSS Distributions {
98*27b03b36SApple OSS Distributions boolean_t found = FALSE;
99*27b03b36SApple OSS Distributions int ret = 0, i;
100*27b03b36SApple OSS Distributions
101*27b03b36SApple OSS Distributions for (i = 0; i < mapcnt; i++) {
102*27b03b36SApple OSS Distributions struct error_sparse_map entry = map_table[i];
103*27b03b36SApple OSS Distributions
104*27b03b36SApple OSS Distributions if (entry.start <= old && old <= entry.end) {
105*27b03b36SApple OSS Distributions ret += old - entry.start;
106*27b03b36SApple OSS Distributions found = TRUE;
107*27b03b36SApple OSS Distributions break;
108*27b03b36SApple OSS Distributions }
109*27b03b36SApple OSS Distributions ret += entry.end - entry.start + 1;
110*27b03b36SApple OSS Distributions }
111*27b03b36SApple OSS Distributions
112*27b03b36SApple OSS Distributions return (found)? ret : INT_MAX;
113*27b03b36SApple OSS Distributions }
114*27b03b36SApple OSS Distributions
115*27b03b36SApple OSS Distributions char *
mach_error_type(mach_error_t err)116*27b03b36SApple OSS Distributions mach_error_type(mach_error_t err)
117*27b03b36SApple OSS Distributions {
118*27b03b36SApple OSS Distributions const struct error_system *sys_p;
119*27b03b36SApple OSS Distributions int sub, system;
120*27b03b36SApple OSS Distributions
121*27b03b36SApple OSS Distributions do_compat( &err );
122*27b03b36SApple OSS Distributions
123*27b03b36SApple OSS Distributions system = err_get_system(err);
124*27b03b36SApple OSS Distributions sys_p = &_mach_errors[system];
125*27b03b36SApple OSS Distributions sub = err_get_sub(err);
126*27b03b36SApple OSS Distributions
127*27b03b36SApple OSS Distributions if (system <= err_max_system && sys_p->map_table) {
128*27b03b36SApple OSS Distributions sub = err_sparse_mapit(sub, sys_p->map_table, sys_p->map_count);
129*27b03b36SApple OSS Distributions }
130*27b03b36SApple OSS Distributions
131*27b03b36SApple OSS Distributions if (system > err_max_system || sub >= sys_p->max_sub) {
132*27b03b36SApple OSS Distributions return (char *)"(?/?)";
133*27b03b36SApple OSS Distributions }
134*27b03b36SApple OSS Distributions return (char *) (sys_p->subsystem[sub].subsys_name);
135*27b03b36SApple OSS Distributions }
136*27b03b36SApple OSS Distributions
137*27b03b36SApple OSS Distributions boolean_t mach_error_full_diag = FALSE;
138*27b03b36SApple OSS Distributions
139*27b03b36SApple OSS Distributions __private_extern__ char *
mach_error_string_int(mach_error_t err,boolean_t * diag)140*27b03b36SApple OSS Distributions mach_error_string_int(mach_error_t err, boolean_t *diag)
141*27b03b36SApple OSS Distributions {
142*27b03b36SApple OSS Distributions const struct error_system *sys_p;
143*27b03b36SApple OSS Distributions const struct error_subsystem *sub_p;
144*27b03b36SApple OSS Distributions int sub, system, code;
145*27b03b36SApple OSS Distributions
146*27b03b36SApple OSS Distributions do_compat( &err );
147*27b03b36SApple OSS Distributions
148*27b03b36SApple OSS Distributions system = err_get_system(err);
149*27b03b36SApple OSS Distributions sys_p = &_mach_errors[system];
150*27b03b36SApple OSS Distributions sub = err_get_sub(err);
151*27b03b36SApple OSS Distributions code = err_get_code(err);
152*27b03b36SApple OSS Distributions
153*27b03b36SApple OSS Distributions *diag = TRUE;
154*27b03b36SApple OSS Distributions
155*27b03b36SApple OSS Distributions if (system > err_max_system) {
156*27b03b36SApple OSS Distributions return (char *)"(?/?) unknown error system";
157*27b03b36SApple OSS Distributions } else if (sys_p->map_table) {
158*27b03b36SApple OSS Distributions sub = err_sparse_mapit(sub, sys_p->map_table, sys_p->map_count);
159*27b03b36SApple OSS Distributions }
160*27b03b36SApple OSS Distributions
161*27b03b36SApple OSS Distributions if (sub >= sys_p->max_sub) {
162*27b03b36SApple OSS Distributions return (char *)sys_p->bad_sub;
163*27b03b36SApple OSS Distributions }
164*27b03b36SApple OSS Distributions
165*27b03b36SApple OSS Distributions sub_p = &sys_p->subsystem[sub];
166*27b03b36SApple OSS Distributions if (sub_p->map_table) {
167*27b03b36SApple OSS Distributions code = err_sparse_mapit(code, sub_p->map_table, sub_p->map_count);
168*27b03b36SApple OSS Distributions }
169*27b03b36SApple OSS Distributions if (code >= sub_p->max_code) {
170*27b03b36SApple OSS Distributions return (char *)NO_SUCH_ERROR;
171*27b03b36SApple OSS Distributions }
172*27b03b36SApple OSS Distributions
173*27b03b36SApple OSS Distributions *diag = mach_error_full_diag;
174*27b03b36SApple OSS Distributions return (char *)sub_p->codes[code];
175*27b03b36SApple OSS Distributions }
176*27b03b36SApple OSS Distributions
177*27b03b36SApple OSS Distributions char *
mach_error_string(mach_error_t err)178*27b03b36SApple OSS Distributions mach_error_string(mach_error_t err)
179*27b03b36SApple OSS Distributions {
180*27b03b36SApple OSS Distributions boolean_t diag;
181*27b03b36SApple OSS Distributions
182*27b03b36SApple OSS Distributions return mach_error_string_int( err, &diag );
183*27b03b36SApple OSS Distributions }
184*27b03b36SApple OSS Distributions
185*27b03b36SApple OSS Distributions /* vim: set ts=4: */
186