muteki
Loading...
Searching...
No Matches
errno.h File Reference

Besta error code constants and functions. More...

#include <muteki/common.h>

Go to the source code of this file.

Typedefs

typedef unsigned int kerrno_t
 

Enumerations

enum  message_flags_e { FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100 , FORMAT_MESSAGE_FROM_SYSTEM = 0x1000 }
 Flags for FormatMessage() More...
 
enum  errno_ns_flag_e { ERRNO_NS_USER = 0x2 , ERRNO_NS_KERNEL = 0x4 , ERRNO_NS_EXEC = 0x8 , ERRNO_NS_APPLET_SPECIFIC = 0x2000 }
 Kernel errno namespace. More...
 
enum  errno_exec_e {
  EXEC_UNSUPPORTED = 0x0001 , EXEC_INVALID , EXEC_OPEN_FAILED , EXEC_LOADER_FAILURE ,
  EXEC_MALLOC_FAILED , EXEC_DECOMPRESSION_FAILED , EXEC_MP3_PLAYER_IS_RUNNING , EXEC_GENERIC_ERROR ,
  EXEC_MAP_FULL , EXEC_UNKNOWN_FORMAT = 0x000a , EXEC_BESTAPE_HEADER_PARSER_FAILURE = 0x000f , EXEC_BESTAPE_LD_FAILURE = 0x0010 ,
  EXEC_BESTAPE_RELOC_FAILURE = 0x0011 , EXEC_NO_SUCH_ENTRY = 0x0012 , EXEC_NOT_LOADED = 0x0016
}
 Error code for ERRNO_NS_EXEC. More...
 
enum  errno_user_e {
  THREADING_QUEUE_BUSY = 0x000a , THREADING_QUEUE_FULL = 0x001e , THREADING_QUEUE_EMPTY = 0x001f , THREADING_SLOT_IN_USE = 0x0028 ,
  THREADING_SLOT_FULL = 0x002b , THREADING_STRUCT_MALLOC_FAILED = 0x0046 , THREADING_THREAD_NOT_SLEEPING = 0x0050 , THREADING_THREAD_NOT_SUSPENDED = 0x0065 ,
  THREADING_STACK_MALLOC_FAILED = 0x0066 , THREADING_INVALID_DESCRIPTOR = 0x006e , THREADING_DESCRIPTOR_BUSY = 0x008c
}
 Error code for ERRNO_NS_USER. More...
 
enum  errno_kernel_e {
  PERIPHERAL_COMM_FAILED = 0x0003 , GENERAL_HW_ERROR , FTL_DATA_CORRUPTED = 0x0010 , FTL_ECC_FAILED ,
  FTL_ECC_TRIGGERED = 0x0018 , FTL_INVALID_LBA = 0x0021 , MEDIUM_WP_ENABLED = 0x0027 , MEDIUM_CHANGED ,
  MEDIUM_INCOMPATIBLE = 0x0030 , MEDIUM_ERROR , MEDIUM_UNLOADED = 0x003a , SYS_STORAGE_DEVICE_NOT_FOUND = 0x0060 ,
  SYS_ERASE_FAILED , SYS_OUT_OF_MEMORY , SYS_LOW_BATTERY , SYS_LOCK_SWITCH_ENABLED ,
  MKFS_PROMPT = 0x0102 , MKFS_UNSUPPORTED , MKFS_NO_SPACE_LEFT , MKFS_MODE_ERROR ,
  MKFS_IO_ERROR , FS_INVALID_DRIVE_LETTER = 0x0113 , FS_INVALID_FILENAME = 0x0140 , FS_OPERATION_ERROR ,
  FS_ENTRY_EXISTS , FS_DIR_FULL , FS_NO_SUCH_ENTRY , FS_FILE_UNAVAILABLE ,
  FS_FILE_OOB_ACCESS , FS_CONFLICTING_ATTR , FS_TOO_MANY_OPEN_FILES , FS_FILE_LOCKED ,
  FS_FILE_ATTR_ERROR , FS_NO_SPACE_LEFT , FS_NO_SUCH_ENTRY_ALT = 0x0154 , FS_READ_ONLY_FILE = 0x0158 ,
  FS_WRITE_ONLY_FILE , FS_PATH_TOO_LONG = 0x0162 , FS_GENERIC_ERROR = 0x0163 , FS_DIR_FULL_ALT1 = 0x0165 ,
  FS_DIR_FULL_ALT2 , DB_CORRUPTED = 0x0200 , DB_OPEN_FAILED , DB_INDEX_FULL_DELETE = 0x0203 ,
  DB_FULL , DB_INDEX_FULL_SYNC , DB_TOO_MANY_OPEN_FILES
}
 Error code for ERRNO_NS_KERNEL. More...
 

Functions

size_t FormatMessage (unsigned int flags, int _sbz0, int _sbz1, int _sbz2, void *outbuf, size_t outlen)
 Fetch an error message.
 
void OSSetLastError (kerrno_t err)
 Set the global errno.
 
kerrno_t OSGetLastError (void)
 Get errno value from the global errno variable.
 
void _SetLastError (kerrno_t err)
 Set errno.
 
kerrno_t _GetLastError (void)
 Get errno.
 

Detailed Description

Besta error code constants and functions.

Typedef Documentation

◆ kerrno_t

typedef unsigned int kerrno_t

Kernel error code type

Enumeration Type Documentation

◆ errno_exec_e

Error code for ERRNO_NS_EXEC.

Enumerator
EXEC_UNSUPPORTED 

Unsupported executable type.

This may be returned when attempting to execute a TLCS-900 executable or x86 EXE file on Arm systems.

Todo:
Double check.
EXEC_INVALID 

Invalid executable file.

This may be returned when attempting to execute a data-only ROM.

Todo:
Double check.
EXEC_OPEN_FAILED 

Failed to open executable file.

EXEC_LOADER_FAILURE 

Failed to parse executable file.

EXEC_MALLOC_FAILED 

Failed to allocate memory when loading executable file.

EXEC_DECOMPRESSION_FAILED 

Decompression failed.

EXEC_MP3_PLAYER_IS_RUNNING 

Refuse to load an executable file because MP3 player is running in the background.

Probably an left-over from the TLCS-900 days when MP3 can be played in the background.

EXEC_GENERIC_ERROR 

Generic error.

This is usually shown when the loader functions encountered an internal error.

EXEC_MAP_FULL 

Executable mapping table is full.

This is returned when too many executable is loaded. May be overwritten by a more generic code like EXEC_LOADER_FAILURE.

EXEC_BESTAPE_HEADER_PARSER_FAILURE 

Failed to load executable file due to an error originated from the header parser.

EXEC_BESTAPE_LD_FAILURE 

Failed to load executable file due to an error originated from the shared object loader.

EXEC_BESTAPE_RELOC_FAILURE 

Failed to load executable file due to an error originated from the relocator.

EXEC_NOT_LOADED 

Executable is not loaded.

◆ errno_kernel_e

Error code for ERRNO_NS_KERNEL.

Enumerator
PERIPHERAL_COMM_FAILED 

Peripheral communication failed.

GENERAL_HW_ERROR 

General hardware error.

FTL_DATA_CORRUPTED 

FTL: Data corruption detected.

FTL_ECC_FAILED 

FTL: Data corruption detected and error correction attempt failed.

FTL_ECC_TRIGGERED 

FTL: Data corruption detected and error correction attempt succeeded.

FTL_INVALID_LBA 

FTL: Invalid Logical Block Address.

MEDIUM_WP_ENABLED 

Medium is write protected.

MEDIUM_CHANGED 

Medium changed

MEDIUM_INCOMPATIBLE 

Medium is of an incompatible type.

MEDIUM_ERROR 

Medium I/O error.

MEDIUM_UNLOADED 

Medium is not loaded.

SYS_STORAGE_DEVICE_NOT_FOUND 

Storage device not found.

SYS_ERASE_FAILED 

Erase of storage device failed.

SYS_OUT_OF_MEMORY 

Out of memory.

SYS_LOW_BATTERY 

Low battery.

SYS_LOCK_SWITCH_ENABLED 

Lock switch is on. System is locked.

MKFS_PROMPT 

Block device format prompt.

MKFS_UNSUPPORTED 

Block device needs formatting.

MKFS_NO_SPACE_LEFT 

mkfs: No space left for device.

MKFS_MODE_ERROR 

mkfs: Mode error.

MKFS_IO_ERROR 

mkfs: I/O error.

FS_INVALID_DRIVE_LETTER 

Invalid drive letter

FS_INVALID_FILENAME 

Filename contains invalid characters.

FS_OPERATION_ERROR 

General filesystem I/O error.

FS_ENTRY_EXISTS 

File or directory exists.

FS_DIR_FULL 

Too many files in this directory.

FS_NO_SUCH_ENTRY 

No such file or directory.

FS_FILE_UNAVAILABLE 

File/directory is not available.

FS_FILE_OOB_ACCESS 

Accessing file out of bound.

FS_CONFLICTING_ATTR 

Conflicting file/directory attributes

FS_TOO_MANY_OPEN_FILES 

Too many open files.

FS_FILE_LOCKED 

File/directory is locked for exclusive access.

FS_FILE_ATTR_ERROR 

Attribute error.

FS_NO_SPACE_LEFT 

No space left for device.

FS_NO_SUCH_ENTRY_ALT 

No such file or directory (alternative).

FS_READ_ONLY_FILE 

File is read-only.

File descriptor does not support read function.

FS_WRITE_ONLY_FILE 

File is write-only.

File descriptor does not support write function.

FS_PATH_TOO_LONG 

Path too long.

FS_GENERIC_ERROR 

Generic error.

This is usually shown when the file and filesystem functions encountered an internal error, or that the supplied file descriptor is invalid.

FS_DIR_FULL_ALT1 

Too many files in this directory (alternative).

FS_DIR_FULL_ALT2 

Too many files in this directory (alternative).

DB_CORRUPTED 

Database is corrupted.

DB_OPEN_FAILED 

Failed to open database.

DB_INDEX_FULL_DELETE 

Database index is full. Suggesting entry cleanup.

DB_FULL 

Database is full.

DB_INDEX_FULL_SYNC 

Database index is full. Suggesting sync with PC.

DB_TOO_MANY_OPEN_FILES 

Database: too many open files.

◆ errno_ns_flag_e

Kernel errno namespace.

Enumerator
ERRNO_NS_USER 

User (errors set by OSSetLastError()).

ERRNO_NS_KERNEL 

Kernel.

ERRNO_NS_EXEC 

Executable loader.

ERRNO_NS_APPLET_SPECIFIC 

Applet specific (errors set by _SetLastError()).

◆ errno_user_e

Error code for ERRNO_NS_USER.

Enumerator
THREADING_QUEUE_BUSY 

Message queue is busy.

THREADING_QUEUE_FULL 

Message queue is full.

THREADING_QUEUE_EMPTY 

Message queue is empty.

THREADING_SLOT_IN_USE 

Thread slot is in use.

THREADING_SLOT_FULL 

Non-reserved slots are full. Cannot create thread.

THREADING_STRUCT_MALLOC_FAILED 

Failed to allocate thread struct.

THREADING_THREAD_NOT_SLEEPING 

Thread is not sleeping.

THREADING_THREAD_NOT_SUSPENDED 

Thread is not suspended.

THREADING_STACK_MALLOC_FAILED 

Failed to allocate thread stack.

THREADING_INVALID_DESCRIPTOR 

Invalid thread descriptor magic.

THREADING_DESCRIPTOR_BUSY 

Descriptor is busy. Seen on event descriptors when some threads are waiting on the event.

◆ message_flags_e

Flags for FormatMessage()

See also
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage
Enumerator
FORMAT_MESSAGE_ALLOCATE_BUFFER 

Allocate buffer for the message.

FORMAT_MESSAGE_FROM_SYSTEM 

Use system error message string table to generate the message.

Function Documentation

◆ _GetLastError()

kerrno_t _GetLastError ( void  )
extern

Get errno.

If kernel errno is set, the errno is returned with ERRNO_NS_KERNEL bit set. Otherwise it will return the result from OSSetLastError() with ERRNO_NS_USER bit set.

Requires -lkrnllib when dynamically linking with the shims.

Parameters
None.

Returns
The current errno value from either kernel or OSSetLastError().

◆ _SetLastError()

void _SetLastError ( kerrno_t  err)
extern

Set errno.

Unlike OSSetLastError(), this also clears the kernel errno before calling OSSetLastError().

If the errno namespace is unset, it will also automatically set ERRNO_NS_APPLET_SPECIFIC before passing it to OSSetLastError().

Requires -lkrnllib when dynamically linking with the shims.

Parameters
errNew errno value.

Returns
None.

◆ FormatMessage()

size_t FormatMessage ( unsigned int  flags,
int  _sbz0,
int  _sbz1,
int  _sbz2,
void *  outbuf,
size_t  outlen 
)
extern

Fetch an error message.

Fetch error descriptions (encoded in UTF16) for last set error in a similar manner to FormatMessage API in Windows.

Parameters
flagsFlags. Only FORMAT_MESSAGE_FROM_SYSTEM and FORMAT_MESSAGE_ALLOCATE_BUFFER are supported. In addition, FORMAT_MESSAGE_FROM_SYSTEM must be set.
_sbz0Reserved. Should be set to 0.
_sbz1Reserved. Should be set to 0.
_sbz2Reserved. Should be set to 0.
outbufThe output buffer. If using FORMAT_MESSAGE_ALLOCATE_BUFFER, the pointer to the allocated buffer will be placed at this location. Otherwise the message will be written directly to this location. It's caller's responsibility to free any buffer allocated by FORMAT_MESSAGE_ALLOCATE_BUFFER.
outlenWhen not using FORMAT_MESSAGE_ALLOCATE_BUFFER, this is the length of the message buffer. Otherwise this is the minimum size of the buffer allocated for the message by the function.
Returns
Length of the message written, or 0 if fails.

◆ OSGetLastError()

kerrno_t OSGetLastError ( void  )
extern

Get errno value from the global errno variable.

Parameters
None.

Returns
The current errno value.

◆ OSSetLastError()

void OSSetLastError ( kerrno_t  err)
extern

Set the global errno.

Parameters
errNew errno value.

Returns
None.