xref: /freebsd/sys/xen/error.h (revision 4d846d26)
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  * $FreeBSD$
27  */
28 
29 #ifndef __XEN_ERROR_H__
30 #define __XEN_ERROR_H__
31 
32 #include <contrib/xen/errno.h>
33 
34 /* Translation table */
35 static int xen_errors[] =
36 {
37 	[XEN_EPERM]		= EPERM,
38 	[XEN_ENOENT]		= ENOENT,
39 	[XEN_ESRCH]		= ESRCH,
40 	[XEN_EIO]		= EIO,
41 	[XEN_ENXIO]		= ENXIO,
42 	[XEN_E2BIG]		= E2BIG,
43 	[XEN_ENOEXEC]		= ENOEXEC,
44 	[XEN_EBADF]		= EBADF,
45 	[XEN_ECHILD]		= ECHILD,
46 	[XEN_EAGAIN]		= EAGAIN,
47 	[XEN_ENOMEM]		= ENOMEM,
48 	[XEN_EACCES]		= EACCES,
49 	[XEN_EFAULT]		= EFAULT,
50 	[XEN_EBUSY]		= EBUSY,
51 	[XEN_EEXIST]		= EEXIST,
52 	[XEN_EXDEV]		= EXDEV,
53 	[XEN_ENODEV]		= ENODEV,
54 	[XEN_EINVAL]		= EINVAL,
55 	[XEN_ENFILE]		= ENFILE,
56 	[XEN_EMFILE]		= EMFILE,
57 	[XEN_ENOSPC]		= ENOSPC,
58 	[XEN_EMLINK]		= EMLINK,
59 	[XEN_EDOM]		= EDOM,
60 	[XEN_ERANGE]		= ERANGE,
61 	[XEN_EDEADLK]		= EDEADLK,
62 	[XEN_ENAMETOOLONG]	= ENAMETOOLONG,
63 	[XEN_ENOLCK]		= ENOLCK,
64 	[XEN_ENOSYS]		= ENOSYS,
65 	[XEN_ENODATA]		= ENOENT,
66 	[XEN_ETIME]		= ETIMEDOUT,
67 	[XEN_EBADMSG]		= EBADMSG,
68 	[XEN_EOVERFLOW]		= EOVERFLOW,
69 	[XEN_EILSEQ]		= EILSEQ,
70 	[XEN_ENOTSOCK]		= ENOTSOCK,
71 	[XEN_EOPNOTSUPP]	= EOPNOTSUPP,
72 	[XEN_EADDRINUSE]	= EADDRINUSE,
73 	[XEN_EADDRNOTAVAIL]	= EADDRNOTAVAIL,
74 	[XEN_ENOBUFS]		= ENOBUFS,
75 	[XEN_EISCONN]		= EISCONN,
76 	[XEN_ENOTCONN]		= ENOTCONN,
77 	[XEN_ETIMEDOUT]		= ETIMEDOUT,
78 };
79 
80 static inline int
81 xen_translate_error(int error)
82 {
83 	int bsd_error;
84 
85 	KASSERT((error < 0), ("Value is not a valid Xen error code"));
86 
87 	if (-error >= nitems(xen_errors)) {
88 		/*
89 		 * We received an error value that cannot be translated,
90 		 * return EINVAL.
91 		 */
92 		return (EINVAL);
93 	}
94 
95 	bsd_error = xen_errors[-error];
96 	KASSERT((bsd_error != 0), ("Unknown Xen error code"));
97 
98 	return (bsd_error);
99 }
100 
101 #endif /* !__XEN_ERROR_H__ */
102