1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  *
10  * As a special exception, you may use this file as part of a free software
11  * library without restriction.  Specifically, if other files instantiate
12  * templates or use macros or inline functions from this file, or you compile
13  * this file and link it with other files to produce an executable, this
14  * file does not by itself cause the resulting executable to be covered by
15  * the GNU General Public License.  This exception does not however
16  * invalidate any other reasons why the executable file might be covered by
17  * the GNU General Public License.
18  */
19 
20 #include <l4/sys/err.h>
21 #include <l4/sys/ipc.h>
22 
23 static char const *const _l4sys_errortab[L4_ERRNOMAX] = {
24     [L4_EOK]           = "OK",
25     [L4_EPERM]         = "Operation not permitted",
26     [L4_ENOENT]        = "No such object found",
27     [L4_EIO]           = "I/O error",
28     [L4_EAGAIN]        = "Try again",
29     [L4_ENOMEM]        = "Insufficient memory",
30     [L4_EACCESS]       = "Access not permitted",
31     [L4_EFAULT]        = "Invalid memory address",
32     [L4_EBUSY]         = "Function busy",
33     [L4_EEXIST]        = "Object exists",
34     [L4_ENODEV]        = "No such device",
35     [L4_EINVAL]        = "Invalid argument",
36     [L4_ERANGE]        = "Argument out of range",
37     [L4_ENAMETOOLONG]  = "Name too long",
38     [L4_ENOSYS]        = "Invalid request",
39     [L4_EBADPROTO]     = "Invalid protocol",
40     [L4_EADDRNOTAVAIL] = "Address not available"
41 };
42 
43 static char const *const _l4sys_ipc_errortab[L4_EIPC_HI - L4_EIPC_LO] = {
44     [0]                = "OK",
45     [L4_IPC_SETIMEOUT]     = "Send timeout",
46     [L4_IPC_RETIMEOUT]     = "Receive timeout",
47     [L4_IPC_ENOT_EXISTENT] = "Void capability invoked",
48     [L4_IPC_SECANCELED]    = "Send operation canceled",
49     [L4_IPC_RECANCELED]    = "Receive operation canceled",
50     [L4_IPC_SEMSGCUT]      = "Overflow during send operation",
51     [L4_IPC_REMSGCUT]      = "Overflow during receive operation",
52     [L4_IPC_SESNDPFTO]     = "Send page-fault timeout (send phase)",
53     [L4_IPC_RESNDPFTO]     = "Send page-fault timeout (receive phase)",
54     [L4_IPC_SERCVPFTO]     = "Receive page-fault timeout (send phase)",
55     [L4_IPC_RERCVPFTO]     = "Receive page-fault timeout (receive phase)",
56     [L4_IPC_SEABORTED]     = "Send operation aborted",
57     [L4_IPC_REABORTED]     = "Receive operation aborted",
58     [L4_IPC_SEMAPFAILED]   = "Map operation failed (send phase)",
59     [L4_IPC_REMAPFAILED]   = "Map operation failed (receive phase)"
60 };
61 
62 static char const *const _l4sys_ipc_errortab2[] = {
63     [L4_ENOREPLY     - 1000] = "Do not reply",
64     [L4_EMSGTOOSHORT - 1000] = "Message too short",
65     [L4_EMSGTOOLONG  - 1000] = "Message too long",
66     [L4_EMSGMISSARG  - 1000] = "Message is missing (an) argument(s)",
67 };
68 
l4sys_errtostr(long err)69 L4_CV char const *l4sys_errtostr(long err)
70 {
71   static_assert(L4_ENOREPLY    == 1000, "L4_ENOREPLY value change");
72   static_assert(L4_EMSGMISSARG == 1003, "L4_EMSGMISSARG value change");
73 
74   err = -err;
75   if (err >= 0 && err < L4_ERRNOMAX)
76     return _l4sys_errortab[err];
77   else if (err >= L4_EIPC_LO && err < L4_EIPC_HI)
78     return _l4sys_ipc_errortab[err - L4_EIPC_LO];
79   else if (err >= L4_ENOREPLY && err <= L4_EMSGMISSARG)
80     return _l4sys_ipc_errortab2[err - 1000];
81   else
82     return "bad, unknown runtime error";
83 }
84