Home | History | Annotate | Download | only in syscall
      1 // Copyright 2013 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package syscall
      6 
      7 // TODO: generate with runtime/mknacl.sh, allow override with IRT.
      8 const (
      9 	sys_null                 = 1
     10 	sys_nameservice          = 2
     11 	sys_dup                  = 8
     12 	sys_dup2                 = 9
     13 	sys_open                 = 10
     14 	sys_close                = 11
     15 	sys_read                 = 12
     16 	sys_write                = 13
     17 	sys_lseek                = 14
     18 	sys_stat                 = 16
     19 	sys_fstat                = 17
     20 	sys_chmod                = 18
     21 	sys_isatty               = 19
     22 	sys_brk                  = 20
     23 	sys_mmap                 = 21
     24 	sys_munmap               = 22
     25 	sys_getdents             = 23
     26 	sys_mprotect             = 24
     27 	sys_list_mappings        = 25
     28 	sys_exit                 = 30
     29 	sys_getpid               = 31
     30 	sys_sched_yield          = 32
     31 	sys_sysconf              = 33
     32 	sys_gettimeofday         = 40
     33 	sys_clock                = 41
     34 	sys_nanosleep            = 42
     35 	sys_clock_getres         = 43
     36 	sys_clock_gettime        = 44
     37 	sys_mkdir                = 45
     38 	sys_rmdir                = 46
     39 	sys_chdir                = 47
     40 	sys_getcwd               = 48
     41 	sys_unlink               = 49
     42 	sys_imc_makeboundsock    = 60
     43 	sys_imc_accept           = 61
     44 	sys_imc_connect          = 62
     45 	sys_imc_sendmsg          = 63
     46 	sys_imc_recvmsg          = 64
     47 	sys_imc_mem_obj_create   = 65
     48 	sys_imc_socketpair       = 66
     49 	sys_mutex_create         = 70
     50 	sys_mutex_lock           = 71
     51 	sys_mutex_trylock        = 72
     52 	sys_mutex_unlock         = 73
     53 	sys_cond_create          = 74
     54 	sys_cond_wait            = 75
     55 	sys_cond_signal          = 76
     56 	sys_cond_broadcast       = 77
     57 	sys_cond_timed_wait_abs  = 79
     58 	sys_thread_create        = 80
     59 	sys_thread_exit          = 81
     60 	sys_tls_init             = 82
     61 	sys_thread_nice          = 83
     62 	sys_tls_get              = 84
     63 	sys_second_tls_set       = 85
     64 	sys_second_tls_get       = 86
     65 	sys_exception_handler    = 87
     66 	sys_exception_stack      = 88
     67 	sys_exception_clear_flag = 89
     68 	sys_sem_create           = 100
     69 	sys_sem_wait             = 101
     70 	sys_sem_post             = 102
     71 	sys_sem_get_value        = 103
     72 	sys_dyncode_create       = 104
     73 	sys_dyncode_modify       = 105
     74 	sys_dyncode_delete       = 106
     75 	sys_test_infoleak        = 109
     76 	sys_test_crash           = 110
     77 	sys_test_syscall_1       = 111
     78 	sys_test_syscall_2       = 112
     79 	sys_futex_wait_abs       = 120
     80 	sys_futex_wake           = 121
     81 	sys_pread                = 130
     82 	sys_pwrite               = 131
     83 	sys_truncate             = 140
     84 	sys_lstat                = 141
     85 	sys_link                 = 142
     86 	sys_rename               = 143
     87 	sys_symlink              = 144
     88 	sys_access               = 145
     89 	sys_readlink             = 146
     90 	sys_utimes               = 147
     91 	sys_get_random_bytes     = 150
     92 )
     93 
     94 // TODO: Auto-generate some day. (Hard-coded in binaries so not likely to change.)
     95 const (
     96 	// native_client/src/trusted/service_runtime/include/sys/errno.h
     97 	// The errors are mainly copied from Linux.
     98 	EPERM           Errno = 1       /* Operation not permitted */
     99 	ENOENT          Errno = 2       /* No such file or directory */
    100 	ESRCH           Errno = 3       /* No such process */
    101 	EINTR           Errno = 4       /* Interrupted system call */
    102 	EIO             Errno = 5       /* I/O error */
    103 	ENXIO           Errno = 6       /* No such device or address */
    104 	E2BIG           Errno = 7       /* Argument list too long */
    105 	ENOEXEC         Errno = 8       /* Exec format error */
    106 	EBADF           Errno = 9       /* Bad file number */
    107 	ECHILD          Errno = 10      /* No child processes */
    108 	EAGAIN          Errno = 11      /* Try again */
    109 	ENOMEM          Errno = 12      /* Out of memory */
    110 	EACCES          Errno = 13      /* Permission denied */
    111 	EFAULT          Errno = 14      /* Bad address */
    112 	EBUSY           Errno = 16      /* Device or resource busy */
    113 	EEXIST          Errno = 17      /* File exists */
    114 	EXDEV           Errno = 18      /* Cross-device link */
    115 	ENODEV          Errno = 19      /* No such device */
    116 	ENOTDIR         Errno = 20      /* Not a directory */
    117 	EISDIR          Errno = 21      /* Is a directory */
    118 	EINVAL          Errno = 22      /* Invalid argument */
    119 	ENFILE          Errno = 23      /* File table overflow */
    120 	EMFILE          Errno = 24      /* Too many open files */
    121 	ENOTTY          Errno = 25      /* Not a typewriter */
    122 	EFBIG           Errno = 27      /* File too large */
    123 	ENOSPC          Errno = 28      /* No space left on device */
    124 	ESPIPE          Errno = 29      /* Illegal seek */
    125 	EROFS           Errno = 30      /* Read-only file system */
    126 	EMLINK          Errno = 31      /* Too many links */
    127 	EPIPE           Errno = 32      /* Broken pipe */
    128 	ENAMETOOLONG    Errno = 36      /* File name too long */
    129 	ENOSYS          Errno = 38      /* Function not implemented */
    130 	EDQUOT          Errno = 122     /* Quota exceeded */
    131 	EDOM            Errno = 33      /* Math arg out of domain of func */
    132 	ERANGE          Errno = 34      /* Math result not representable */
    133 	EDEADLK         Errno = 35      /* Deadlock condition */
    134 	ENOLCK          Errno = 37      /* No record locks available */
    135 	ENOTEMPTY       Errno = 39      /* Directory not empty */
    136 	ELOOP           Errno = 40      /* Too many symbolic links */
    137 	ENOMSG          Errno = 42      /* No message of desired type */
    138 	EIDRM           Errno = 43      /* Identifier removed */
    139 	ECHRNG          Errno = 44      /* Channel number out of range */
    140 	EL2NSYNC        Errno = 45      /* Level 2 not synchronized */
    141 	EL3HLT          Errno = 46      /* Level 3 halted */
    142 	EL3RST          Errno = 47      /* Level 3 reset */
    143 	ELNRNG          Errno = 48      /* Link number out of range */
    144 	EUNATCH         Errno = 49      /* Protocol driver not attached */
    145 	ENOCSI          Errno = 50      /* No CSI structure available */
    146 	EL2HLT          Errno = 51      /* Level 2 halted */
    147 	EBADE           Errno = 52      /* Invalid exchange */
    148 	EBADR           Errno = 53      /* Invalid request descriptor */
    149 	EXFULL          Errno = 54      /* Exchange full */
    150 	ENOANO          Errno = 55      /* No anode */
    151 	EBADRQC         Errno = 56      /* Invalid request code */
    152 	EBADSLT         Errno = 57      /* Invalid slot */
    153 	EDEADLOCK       Errno = EDEADLK /* File locking deadlock error */
    154 	EBFONT          Errno = 59      /* Bad font file fmt */
    155 	ENOSTR          Errno = 60      /* Device not a stream */
    156 	ENODATA         Errno = 61      /* No data (for no delay io) */
    157 	ETIME           Errno = 62      /* Timer expired */
    158 	ENOSR           Errno = 63      /* Out of streams resources */
    159 	ENONET          Errno = 64      /* Machine is not on the network */
    160 	ENOPKG          Errno = 65      /* Package not installed */
    161 	EREMOTE         Errno = 66      /* The object is remote */
    162 	ENOLINK         Errno = 67      /* The link has been severed */
    163 	EADV            Errno = 68      /* Advertise error */
    164 	ESRMNT          Errno = 69      /* Srmount error */
    165 	ECOMM           Errno = 70      /* Communication error on send */
    166 	EPROTO          Errno = 71      /* Protocol error */
    167 	EMULTIHOP       Errno = 72      /* Multihop attempted */
    168 	EDOTDOT         Errno = 73      /* Cross mount point (not really error) */
    169 	EBADMSG         Errno = 74      /* Trying to read unreadable message */
    170 	EOVERFLOW       Errno = 75      /* Value too large for defined data type */
    171 	ENOTUNIQ        Errno = 76      /* Given log. name not unique */
    172 	EBADFD          Errno = 77      /* f.d. invalid for this operation */
    173 	EREMCHG         Errno = 78      /* Remote address changed */
    174 	ELIBACC         Errno = 79      /* Can't access a needed shared lib */
    175 	ELIBBAD         Errno = 80      /* Accessing a corrupted shared lib */
    176 	ELIBSCN         Errno = 81      /* .lib section in a.out corrupted */
    177 	ELIBMAX         Errno = 82      /* Attempting to link in too many libs */
    178 	ELIBEXEC        Errno = 83      /* Attempting to exec a shared library */
    179 	EILSEQ          Errno = 84
    180 	EUSERS          Errno = 87
    181 	ENOTSOCK        Errno = 88  /* Socket operation on non-socket */
    182 	EDESTADDRREQ    Errno = 89  /* Destination address required */
    183 	EMSGSIZE        Errno = 90  /* Message too long */
    184 	EPROTOTYPE      Errno = 91  /* Protocol wrong type for socket */
    185 	ENOPROTOOPT     Errno = 92  /* Protocol not available */
    186 	EPROTONOSUPPORT Errno = 93  /* Unknown protocol */
    187 	ESOCKTNOSUPPORT Errno = 94  /* Socket type not supported */
    188 	EOPNOTSUPP      Errno = 95  /* Operation not supported on transport endpoint */
    189 	EPFNOSUPPORT    Errno = 96  /* Protocol family not supported */
    190 	EAFNOSUPPORT    Errno = 97  /* Address family not supported by protocol family */
    191 	EADDRINUSE      Errno = 98  /* Address already in use */
    192 	EADDRNOTAVAIL   Errno = 99  /* Address not available */
    193 	ENETDOWN        Errno = 100 /* Network interface is not configured */
    194 	ENETUNREACH     Errno = 101 /* Network is unreachable */
    195 	ENETRESET       Errno = 102
    196 	ECONNABORTED    Errno = 103 /* Connection aborted */
    197 	ECONNRESET      Errno = 104 /* Connection reset by peer */
    198 	ENOBUFS         Errno = 105 /* No buffer space available */
    199 	EISCONN         Errno = 106 /* Socket is already connected */
    200 	ENOTCONN        Errno = 107 /* Socket is not connected */
    201 	ESHUTDOWN       Errno = 108 /* Can't send after socket shutdown */
    202 	ETOOMANYREFS    Errno = 109
    203 	ETIMEDOUT       Errno = 110 /* Connection timed out */
    204 	ECONNREFUSED    Errno = 111 /* Connection refused */
    205 	EHOSTDOWN       Errno = 112 /* Host is down */
    206 	EHOSTUNREACH    Errno = 113 /* Host is unreachable */
    207 	EALREADY        Errno = 114 /* Socket already connected */
    208 	EINPROGRESS     Errno = 115 /* Connection already in progress */
    209 	ESTALE          Errno = 116
    210 	ENOTSUP         Errno = EOPNOTSUPP /* Not supported */
    211 	ENOMEDIUM       Errno = 123        /* No medium (in tape drive) */
    212 	ECANCELED       Errno = 125        /* Operation canceled. */
    213 	ELBIN           Errno = 2048       /* Inode is remote (not really error) */
    214 	EFTYPE          Errno = 2049       /* Inappropriate file type or format */
    215 	ENMFILE         Errno = 2050       /* No more files */
    216 	EPROCLIM        Errno = 2051
    217 	ENOSHARE        Errno = 2052   /* No such host or network path */
    218 	ECASECLASH      Errno = 2053   /* Filename exists with different case */
    219 	EWOULDBLOCK     Errno = EAGAIN /* Operation would block */
    220 )
    221 
    222 // TODO: Auto-generate some day. (Hard-coded in binaries so not likely to change.)
    223 var errorstr = [...]string{
    224 	EPERM:           "Operation not permitted",
    225 	ENOENT:          "No such file or directory",
    226 	ESRCH:           "No such process",
    227 	EINTR:           "Interrupted system call",
    228 	EIO:             "I/O error",
    229 	ENXIO:           "No such device or address",
    230 	E2BIG:           "Argument list too long",
    231 	ENOEXEC:         "Exec format error",
    232 	EBADF:           "Bad file number",
    233 	ECHILD:          "No child processes",
    234 	EAGAIN:          "Try again",
    235 	ENOMEM:          "Out of memory",
    236 	EACCES:          "Permission denied",
    237 	EFAULT:          "Bad address",
    238 	EBUSY:           "Device or resource busy",
    239 	EEXIST:          "File exists",
    240 	EXDEV:           "Cross-device link",
    241 	ENODEV:          "No such device",
    242 	ENOTDIR:         "Not a directory",
    243 	EISDIR:          "Is a directory",
    244 	EINVAL:          "Invalid argument",
    245 	ENFILE:          "File table overflow",
    246 	EMFILE:          "Too many open files",
    247 	ENOTTY:          "Not a typewriter",
    248 	EFBIG:           "File too large",
    249 	ENOSPC:          "No space left on device",
    250 	ESPIPE:          "Illegal seek",
    251 	EROFS:           "Read-only file system",
    252 	EMLINK:          "Too many links",
    253 	EPIPE:           "Broken pipe",
    254 	ENAMETOOLONG:    "File name too long",
    255 	ENOSYS:          "not implemented on Native Client",
    256 	EDQUOT:          "Quota exceeded",
    257 	EDOM:            "Math arg out of domain of func",
    258 	ERANGE:          "Math result not representable",
    259 	EDEADLK:         "Deadlock condition",
    260 	ENOLCK:          "No record locks available",
    261 	ENOTEMPTY:       "Directory not empty",
    262 	ELOOP:           "Too many symbolic links",
    263 	ENOMSG:          "No message of desired type",
    264 	EIDRM:           "Identifier removed",
    265 	ECHRNG:          "Channel number out of range",
    266 	EL2NSYNC:        "Level 2 not synchronized",
    267 	EL3HLT:          "Level 3 halted",
    268 	EL3RST:          "Level 3 reset",
    269 	ELNRNG:          "Link number out of range",
    270 	EUNATCH:         "Protocol driver not attached",
    271 	ENOCSI:          "No CSI structure available",
    272 	EL2HLT:          "Level 2 halted",
    273 	EBADE:           "Invalid exchange",
    274 	EBADR:           "Invalid request descriptor",
    275 	EXFULL:          "Exchange full",
    276 	ENOANO:          "No anode",
    277 	EBADRQC:         "Invalid request code",
    278 	EBADSLT:         "Invalid slot",
    279 	EBFONT:          "Bad font file fmt",
    280 	ENOSTR:          "Device not a stream",
    281 	ENODATA:         "No data (for no delay io)",
    282 	ETIME:           "Timer expired",
    283 	ENOSR:           "Out of streams resources",
    284 	ENONET:          "Machine is not on the network",
    285 	ENOPKG:          "Package not installed",
    286 	EREMOTE:         "The object is remote",
    287 	ENOLINK:         "The link has been severed",
    288 	EADV:            "Advertise error",
    289 	ESRMNT:          "Srmount error",
    290 	ECOMM:           "Communication error on send",
    291 	EPROTO:          "Protocol error",
    292 	EMULTIHOP:       "Multihop attempted",
    293 	EDOTDOT:         "Cross mount point (not really error)",
    294 	EBADMSG:         "Trying to read unreadable message",
    295 	EOVERFLOW:       "Value too large for defined data type",
    296 	ENOTUNIQ:        "Given log. name not unique",
    297 	EBADFD:          "f.d. invalid for this operation",
    298 	EREMCHG:         "Remote address changed",
    299 	ELIBACC:         "Can't access a needed shared lib",
    300 	ELIBBAD:         "Accessing a corrupted shared lib",
    301 	ELIBSCN:         ".lib section in a.out corrupted",
    302 	ELIBMAX:         "Attempting to link in too many libs",
    303 	ELIBEXEC:        "Attempting to exec a shared library",
    304 	ENOTSOCK:        "Socket operation on non-socket",
    305 	EDESTADDRREQ:    "Destination address required",
    306 	EMSGSIZE:        "Message too long",
    307 	EPROTOTYPE:      "Protocol wrong type for socket",
    308 	ENOPROTOOPT:     "Protocol not available",
    309 	EPROTONOSUPPORT: "Unknown protocol",
    310 	ESOCKTNOSUPPORT: "Socket type not supported",
    311 	EOPNOTSUPP:      "Operation not supported on transport endpoint",
    312 	EPFNOSUPPORT:    "Protocol family not supported",
    313 	EAFNOSUPPORT:    "Address family not supported by protocol family",
    314 	EADDRINUSE:      "Address already in use",
    315 	EADDRNOTAVAIL:   "Address not available",
    316 	ENETDOWN:        "Network interface is not configured",
    317 	ENETUNREACH:     "Network is unreachable",
    318 	ECONNABORTED:    "Connection aborted",
    319 	ECONNRESET:      "Connection reset by peer",
    320 	ENOBUFS:         "No buffer space available",
    321 	EISCONN:         "Socket is already connected",
    322 	ENOTCONN:        "Socket is not connected",
    323 	ESHUTDOWN:       "Can't send after socket shutdown",
    324 	ETIMEDOUT:       "Connection timed out",
    325 	ECONNREFUSED:    "Connection refused",
    326 	EHOSTDOWN:       "Host is down",
    327 	EHOSTUNREACH:    "Host is unreachable",
    328 	EALREADY:        "Socket already connected",
    329 	EINPROGRESS:     "Connection already in progress",
    330 	ENOMEDIUM:       "No medium (in tape drive)",
    331 	ECANCELED:       "Operation canceled.",
    332 	ELBIN:           "Inode is remote (not really error)",
    333 	EFTYPE:          "Inappropriate file type or format",
    334 	ENMFILE:         "No more files",
    335 	ENOSHARE:        "No such host or network path",
    336 	ECASECLASH:      "Filename exists with different case",
    337 }
    338 
    339 // Do the interface allocations only once for common
    340 // Errno values.
    341 var (
    342 	errEAGAIN error = EAGAIN
    343 	errEINVAL error = EINVAL
    344 	errENOENT error = ENOENT
    345 )
    346 
    347 // errnoErr returns common boxed Errno values, to prevent
    348 // allocations at runtime.
    349 func errnoErr(e Errno) error {
    350 	switch e {
    351 	case 0:
    352 		return nil
    353 	case EAGAIN:
    354 		return errEAGAIN
    355 	case EINVAL:
    356 		return errEINVAL
    357 	case ENOENT:
    358 		return errENOENT
    359 	}
    360 	return e
    361 }
    362