xref: /freebsd/sys/xen/error.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * Copyright (c) 2014 Roger Pau Monné <royger@FreeBSD.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef __XEN_ERROR_H__
28 #define __XEN_ERROR_H__
29 
30 #include <contrib/xen/errno.h>
31 
32 /* Translation table */
33 static int xen_errors[] =
34 {
35 	[XEN_EPERM]		= EPERM,
36 	[XEN_ENOENT]		= ENOENT,
37 	[XEN_ESRCH]		= ESRCH,
38 	[XEN_EIO]		= EIO,
39 	[XEN_ENXIO]		= ENXIO,
40 	[XEN_E2BIG]		= E2BIG,
41 	[XEN_ENOEXEC]		= ENOEXEC,
42 	[XEN_EBADF]		= EBADF,
43 	[XEN_ECHILD]		= ECHILD,
44 	[XEN_EAGAIN]		= EAGAIN,
45 	[XEN_ENOMEM]		= ENOMEM,
46 	[XEN_EACCES]		= EACCES,
47 	[XEN_EFAULT]		= EFAULT,
48 	[XEN_EBUSY]		= EBUSY,
49 	[XEN_EEXIST]		= EEXIST,
50 	[XEN_EXDEV]		= EXDEV,
51 	[XEN_ENODEV]		= ENODEV,
52 	[XEN_EINVAL]		= EINVAL,
53 	[XEN_ENFILE]		= ENFILE,
54 	[XEN_EMFILE]		= EMFILE,
55 	[XEN_ENOSPC]		= ENOSPC,
56 	[XEN_EMLINK]		= EMLINK,
57 	[XEN_EDOM]		= EDOM,
58 	[XEN_ERANGE]		= ERANGE,
59 	[XEN_EDEADLK]		= EDEADLK,
60 	[XEN_ENAMETOOLONG]	= ENAMETOOLONG,
61 	[XEN_ENOLCK]		= ENOLCK,
62 	[XEN_ENOSYS]		= ENOSYS,
63 	[XEN_ENODATA]		= ENOENT,
64 	[XEN_ETIME]		= ETIMEDOUT,
65 	[XEN_EBADMSG]		= EBADMSG,
66 	[XEN_EOVERFLOW]		= EOVERFLOW,
67 	[XEN_EILSEQ]		= EILSEQ,
68 	[XEN_ENOTSOCK]		= ENOTSOCK,
69 	[XEN_EOPNOTSUPP]	= EOPNOTSUPP,
70 	[XEN_EADDRINUSE]	= EADDRINUSE,
71 	[XEN_EADDRNOTAVAIL]	= EADDRNOTAVAIL,
72 	[XEN_ENOBUFS]		= ENOBUFS,
73 	[XEN_EISCONN]		= EISCONN,
74 	[XEN_ENOTCONN]		= ENOTCONN,
75 	[XEN_ETIMEDOUT]		= ETIMEDOUT,
76 };
77 
78 static inline int
79 xen_translate_error(int error)
80 {
81 	int bsd_error;
82 
83 	KASSERT((error < 0), ("Value is not a valid Xen error code"));
84 
85 	if (-error >= nitems(xen_errors)) {
86 		/*
87 		 * We received an error value that cannot be translated,
88 		 * return EINVAL.
89 		 */
90 		return (EINVAL);
91 	}
92 
93 	bsd_error = xen_errors[-error];
94 	KASSERT((bsd_error != 0), ("Unknown Xen error code"));
95 
96 	return (bsd_error);
97 }
98 
99 #endif /* !__XEN_ERROR_H__ */
100