1 /* $NetBSD: mach_errno.c,v 1.15 2005/02/26 23:10:19 perry Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.15 2005/02/26 23:10:19 perry Exp $");
41
42 #include <sys/types.h>
43 #include <sys/systm.h>
44 #include <sys/null.h>
45 #include <sys/queue.h>
46 #include <sys/errno.h>
47
48 #include <compat/mach/mach_types.h>
49 #include <compat/mach/mach_message.h>
50 #include <compat/mach/mach_errno.h>
51
52 int native_to_mach_errno[] = {
53 MACH_KERN_SUCCESS, /* 0 */
54 MACH_KERN_PROTECTION_FAILURE, /* EPERM */
55 MACH_KERN_FAILURE, /* ENOENT */
56 MACH_KERN_FAILURE, /* ESRCH */
57 MACH_KERN_FAILURE, /* EINTR */
58 MACH_KERN_FAILURE, /* EIO */ /* 5 */
59 MACH_KERN_FAILURE, /* ENXIO */
60 MACH_KERN_FAILURE, /* E2BIG */
61 MACH_KERN_FAILURE, /* ENOEXEC */
62 MACH_KERN_FAILURE, /* EBADF */
63 MACH_KERN_FAILURE, /* ECHILD */ /* 10 */
64 MACH_KERN_FAILURE, /* EDEADLK */
65 MACH_KERN_NO_SPACE, /* ENOMEM */
66 MACH_KERN_FAILURE, /* EACCES */
67 MACH_KERN_INVALID_ADDRESS, /* EFAULT */
68 MACH_KERN_FAILURE, /* ENOTBLK */ /* 15 */
69 MACH_KERN_FAILURE, /* EBUSY */
70 MACH_KERN_FAILURE, /* EEXIST */
71 MACH_KERN_FAILURE, /* EXDEV */
72 MACH_KERN_FAILURE, /* ENODEV */
73 MACH_KERN_FAILURE, /* ENOTDIR */ /* 20 */
74 MACH_KERN_FAILURE, /* EISDIR */
75 MACH_KERN_INVALID_ARGUMENT, /* EINVAL */
76 MACH_KERN_FAILURE, /* ENFILE */
77 MACH_KERN_FAILURE, /* EMFILE */
78 MACH_KERN_FAILURE, /* ENOTTY */ /* 25 */
79 MACH_KERN_FAILURE, /* ETXTBSY */
80 MACH_KERN_FAILURE, /* EFBIG */
81 MACH_KERN_FAILURE, /* ENOSPC */
82 MACH_KERN_FAILURE, /* ESPIPE */
83 MACH_KERN_FAILURE, /* EROFS */ /* 30 */
84 MACH_KERN_FAILURE, /* EMLINK */
85 MACH_KERN_FAILURE, /* EPIPE */
86 MACH_KERN_FAILURE, /* EDOM */
87 MACH_KERN_FAILURE, /* ERANGE */
88 MACH_KERN_FAILURE, /* EAGAIN */ /* 35 */
89 MACH_KERN_FAILURE, /* EWOULDBLOCK */
90 MACH_KERN_FAILURE, /* EINPROGRESS */
91 MACH_KERN_FAILURE, /* EALREADY */
92 MACH_KERN_FAILURE, /* ENOTSOCK */
93 MACH_KERN_FAILURE, /* EDESTADDRREQ */ /* 40 */
94 MACH_KERN_FAILURE, /* EMSGSIZE */
95 MACH_KERN_FAILURE, /* EPROTOTYPE */
96 MACH_KERN_FAILURE, /* ENOPROTOOPT */
97 MACH_KERN_FAILURE, /* ESOCKTNOSUPPORT */
98 MACH_KERN_FAILURE, /* EOPNOTSUPP */ /* 45 */
99 MACH_KERN_FAILURE, /* EPFNOSUPPORT */
100 MACH_KERN_FAILURE, /* EAFNOSUPPORT */
101 MACH_KERN_FAILURE, /* EADDRINUSE */
102 MACH_KERN_FAILURE, /* EADDRNOTAVAIL */
103 MACH_KERN_FAILURE, /* ENETDOWN */ /* 50 */
104 MACH_KERN_FAILURE, /* ENETUNREACH */
105 MACH_KERN_FAILURE, /* ENETRESET */
106 MACH_KERN_FAILURE, /* ECONNABORTED */
107 MACH_KERN_FAILURE, /* ECONNRESET */
108 MACH_KERN_FAILURE, /* ENOBUFS */ /* 55 */
109 MACH_KERN_FAILURE, /* EISCONN */
110 MACH_KERN_FAILURE, /* ENOTCONN */
111 MACH_KERN_FAILURE, /* ESHUTDOWN */
112 MACH_KERN_FAILURE, /* ETOOMANYREFS */
113 MACH_KERN_FAILURE, /* ETIMEDOUT */ /* 60 */
114 MACH_KERN_FAILURE, /* ECONNREFUSED */
115 MACH_KERN_FAILURE, /* ELOOP */
116 MACH_KERN_FAILURE, /* ENAMETOOLONG */
117 MACH_KERN_FAILURE, /* EHOSTDOWN */
118 MACH_KERN_FAILURE, /* EHOSTUNREACH */ /* 65 */
119 MACH_KERN_FAILURE, /* ENOTEMPTY */
120 MACH_KERN_FAILURE, /* EPROCLIM */
121 MACH_KERN_FAILURE, /* EUSERS */
122 MACH_KERN_FAILURE, /* EDQUOT */
123 MACH_KERN_FAILURE, /* ESTALE */ /* 70 */
124 MACH_KERN_FAILURE, /* EREMOTE */
125 MACH_KERN_FAILURE, /* EBADRPC */
126 MACH_KERN_FAILURE, /* ERPCMISMATCH */
127 MACH_KERN_FAILURE, /* EPROGUNAVAIL */
128 MACH_KERN_FAILURE, /* EPROGMISMATCH */ /* 75 */
129 MACH_KERN_FAILURE, /* EPROCUNAVAIL */
130 MACH_KERN_FAILURE, /* ENOLCK */
131 MACH_KERN_FAILURE, /* ENOSYS */
132 MACH_KERN_FAILURE, /* EFTYPE */
133 MACH_KERN_FAILURE, /* EAUTH */ /* 80 */
134 MACH_KERN_FAILURE, /* ENEEDAUTH */
135 MACH_KERN_FAILURE, /* EIDRM */
136 MACH_KERN_FAILURE, /* ENOMSG */
137 MACH_KERN_FAILURE, /* EOVERFLOW */
138 MACH_KERN_FAILURE, /* EILSEQ */ /* 85 */
139 };
140
141 int
142 mach_msg_error(args, error)
143 struct mach_trap_args *args;
144 int error;
145 {
146 mach_msg_header_t *req = args->smsg;
147 mach_error_reply_t *rep = args->rmsg;
148 size_t *msglen = args->rsize;
149
150 *msglen = sizeof(*rep);
151 mach_set_header(rep, req, *msglen);
152
153 rep->rep_retval = native_to_mach_errno[error];
154
155 mach_set_trailer(rep, *msglen);
156
157 #ifdef DEBUG_MACH
158 if (error != 0)
159 printf("failure in kernel service %d (err %x, native %d)\n",
160 req->msgh_id, (int)rep->rep_retval, error);
161 #endif
162 return 0;
163 }
164
165 int
166 mach_iokit_error(args, error)
167 struct mach_trap_args *args;
168 int error;
169 {
170 mach_msg_header_t *req = args->smsg;
171 mach_error_reply_t *rep = args->rmsg;
172 size_t *msglen = args->rsize;
173
174 *msglen = sizeof(*rep);
175 mach_set_header(rep, req, *msglen);
176
177 rep->rep_retval = error;
178
179 #ifdef DEBUG_MACH
180 if (error != 0)
181 printf("failure in kernel service %d (Mach err %x)\n",
182 req->msgh_id, error);
183 #endif
184 mach_set_trailer(rep, *msglen);
185
186 return 0;
187 }
Cache object: f96c4e667fe97e8a38206f5eb0e7e3b8
|