github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/syscall/tables_nonhosted.go (about)

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