The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
errno.h
Go to the documentation of this file.
1#pragma once
2
3#include "common/error.h"
4
5/**
6 * errno values the kernel returns to user space, negated (-EBADF). they
7 * are ABI: src/libc/include/errno.h has the same numbers. kernel code
8 * returns kerr_t inside the kernel and converts at the syscall boundary
9 * (kerr_to_errno); code that talks to user space directly (syscalls, ioctl
10 * handlers) uses these names, never bare numbers.
11 */
12
13#define ENOSYS 1 // function not implemented
14#define EBADF 2 // bad file descriptor
15#define EINVAL 3 // invalid argument
16#define ENOMEM 4 // not enough memory
17#define ENOENT 5 // no such file or directory
18#define EACCES 6 // permission denied
19#define EPIPE 7 // broken pipe
20#define ESPIPE 8 // invalid seek
21#define EEXIST 9 // file exists
22#define EISDIR 10 // is a directory
23#define ENOTDIR 11 // not a directory
24#define EMFILE 12 // too many open files
25#define ENFILE 13 // too many open files in system
26#define EIO 14 // i/o error
27#define ENOSPC 15 // no space left on device
28#define EBUSY 16 // resource busy
29#define ERANGE 17 // result too large
30#define EFAULT 18 // bad address
31#define ESRCH 19 // no such process
32#define ECHILD 20 // no child processes
33#define ENOBUFS 21 // no buffer space available
34#define ENOTTY 22 // inappropriate ioctl for device
35#define ENODEV 23 // no such device
36#define EINTR 24 // interrupted system call
37#define EAGAIN 25 // resource temporarily unavailable
38#define E2BIG 26 // argument list too long
39#define ENOEXEC 27 // exec format error
40#define ENOTEMPTY 28 // directory not empty
41#define EXDEV 29 // cross-device link
42#define ENAMETOOLONG 30 // file name too long
43#define EPERM 31 // operation not permitted
44#define ELOOP 32 // too many levels of symbolic links
45#define EROFS 33 // read-only file system
46#define ETIMEDOUT 34 // timed out
47#define ENOTSOCK 35 // not a socket
48#define EADDRINUSE 36 // address in use
49#define ECONNREFUSED 37 // connection refused
50#define EISCONN 38 // already connected
51#define ENOTCONN 39 // not connected
52#define EAFNOSUPPORT 40 // address family not supported
53#define EPROTONOSUPPORT 41 // protocol not supported
54#define EOPNOTSUPP 42 // operation not supported
55#define ECANCELED 43 // operation cancelled (programs use it; the kernel does not)
56#define EILSEQ 44 // not a character in UTF-8 (programs use it; the kernel does not)
57#define EMLINK 45 // too many links to a file
58#define EFBIG 46 // a file would be too large
59#define ENOLCK 47 // no locks left (flock)
60#define ENXIO 48 // no such device (a device node with none behind it)
61#define EDEADLK 49 // a lock that would never be free (the libc's own)
62#define EOVERFLOW 50 // a value too large for its type
63// the network
64#define EADDRNOTAVAIL 51 // address not available
65#define EDESTADDRREQ 52 // destination address required
66#define EMSGSIZE 53 // message too long
67#define ENETUNREACH 54 // network unreachable
68#define EHOSTUNREACH 55 // host unreachable
69#define ENOPROTOOPT 56 // protocol not available
70#define EPROTOTYPE 57 // wrong protocol type for socket
71#define ECONNRESET 58 // connection reset by peer
72#define ECONNABORTED 59 // connection aborted
73#define EINPROGRESS 60 // operation in progress
74#define EALREADY 61 // operation already in progress
75#define ENETDOWN 62 // network is down
76#define EPROTO 63 // protocol error
77
78#define EWOULDBLOCK EAGAIN
79
80// kernel internal, never seen by user space: a sleeping syscall was
81// interrupted by a signal. signal_deliver turns it into EINTR, or runs the
82// syscall again (SA_RESTART, or when no handler runs).
83#define ERESTARTSYS 512
84
85/**
86 * the errno for a kernel error, negated, for returning to user space.
87 * @param err the kernel error.
88 * @return 0 for KERR_OK, else a negative errno.
89 */
90static inline int32_t kerr_to_errno(kerr_t err)
91{
92 switch (err)
93 {
94 case KERR_OK: return 0;
95 case KERR_NOMEM: return -ENOMEM;
96 case KERR_IO: return -EIO;
97 case KERR_NOTFOUND: return -ENOENT;
98 case KERR_PERM: return -EACCES;
99 case KERR_INVAL: return -EINVAL;
100 case KERR_BUSY: return -EBUSY;
101 case KERR_NOSPC: return -ENOSPC;
102 case KERR_RANGE: return -ERANGE;
103 case KERR_EXIST: return -EEXIST;
104 case KERR_ISDIR: return -EISDIR;
105 case KERR_NOTDIR: return -ENOTDIR;
106 case KERR_PIPE: return -EPIPE;
107 case KERR_NOENT: return -ENOENT;
108 case KERR_FAULT: return -EFAULT;
109 case KERR_NOTEMPTY: return -ENOTEMPTY;
110 case KERR_LOOP: return -ELOOP;
111 case KERR_NOEXEC: return -ENOEXEC;
112 case KERR_FBIG: return -EFBIG;
113 }
114 return -EINVAL;
115}
kerr_t
unified kernel error codes.
Definition error.h:14
@ KERR_NOMEM
Definition error.h:16
@ KERR_NOTEMPTY
Definition error.h:30
@ KERR_RANGE
Definition error.h:23
@ KERR_NOTFOUND
Definition error.h:18
@ KERR_NOENT
Definition error.h:28
@ KERR_INVAL
Definition error.h:20
@ KERR_EXIST
Definition error.h:24
@ KERR_FAULT
Definition error.h:29
@ KERR_FBIG
Definition error.h:33
@ KERR_IO
Definition error.h:17
@ KERR_NOEXEC
Definition error.h:32
@ KERR_PIPE
Definition error.h:27
@ KERR_BUSY
Definition error.h:21
@ KERR_NOTDIR
Definition error.h:26
@ KERR_NOSPC
Definition error.h:22
@ KERR_LOOP
Definition error.h:31
@ KERR_ISDIR
Definition error.h:25
@ KERR_OK
Definition error.h:15
@ KERR_PERM
Definition error.h:19
#define ENOENT
Definition errno.h:16
#define ENOSPC
Definition errno.h:26
#define EEXIST
Definition errno.h:20
#define EINVAL
Definition errno.h:14
#define ELOOP
Definition errno.h:43
#define EFAULT
Definition errno.h:29
#define ENOEXEC
Definition errno.h:38
#define EPIPE
Definition errno.h:18
#define ENOMEM
Definition errno.h:15
#define EIO
Definition errno.h:25
#define EBUSY
Definition errno.h:27
#define ENOTDIR
Definition errno.h:22
#define ENOTEMPTY
Definition errno.h:39
#define ERANGE
Definition errno.h:28
#define EACCES
Definition errno.h:17
#define EISDIR
Definition errno.h:21
#define EFBIG
Definition errno.h:57
int int32_t
Definition stdint.h:14