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