Muteki
EABI code execution on Besta® RTOS devices.
Loading...
Searching...
No Matches
errno.h File Reference

Besta error code constants and functions. More...

#include "common.h"

Go to the source code of this file.

Typedefs

typedef unsigned int bxc_errno_t

Enumerations

enum  bxc_message_flags_e { BXC_FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100 , BXC_FORMAT_MESSAGE_FROM_SYSTEM = 0x1000 }
 Flags for FormatMessage(). More...
enum  bxc_errno_ns_flag_e { BXC_ERRNO_NS_USER = 0x2 , BXC_ERRNO_NS_KERNEL = 0x4 , BXC_ERRNO_NS_EXEC = 0x8 , BXC_ERRNO_NS_APPLET = 0x2000 }
 Kernel errno namespace. More...
enum  bxc_errno_exec_e {
  BXC_ERR_EXEC_UNSUPPORTED = 0x0001 , BXC_ERR_EXEC_INVALID , BXC_ERR_EXEC_OPEN_FAILED , BXC_ERR_EXEC_LOADER_FAILURE ,
  BXC_ERR_EXEC_MALLOC_FAILED , BXC_ERR_EXEC_DECOMPRESSION_FAILED , BXC_ERR_EXEC_MP3_PLAYER_IS_RUNNING , BXC_ERR_EXEC_GENERIC_ERROR ,
  BXC_ERR_EXEC_MAP_FULL , BXC_ERR_EXEC_UNKNOWN_FORMAT = 0x000a , BXC_ERR_EXEC_BESTAPE_HEADER_PARSER_FAILURE = 0x000f , BXC_ERR_EXEC_BESTAPE_LD_FAILURE = 0x0010 ,
  BXC_ERR_EXEC_BESTAPE_RELOC_FAILURE = 0x0011 , BXC_ERR_EXEC_INVALID_PATH = 0x0012 , BXC_ERR_EXEC_MODULE_NOT_LOADED = 0x0013 , BXC_ERR_EXEC_NOT_LOADED = 0x0016
}
 Error code for BXC_ERRNO_NS_EXEC. More...
enum  bxc_errno_user_e {
  BXC_ERR_THREADING_QUEUE_BUSY = 0x000a , BXC_ERR_THREADING_QUEUE_FULL = 0x001e , BXC_ERR_THREADING_QUEUE_EMPTY = 0x001f , BXC_ERR_THREADING_SLOT_IN_USE = 0x0028 ,
  BXC_ERR_THREADING_SLOT_FULL = 0x002b , BXC_ERR_THREADING_STRUCT_MALLOC_FAILED = 0x0046 , BXC_ERR_THREADING_THREAD_NOT_SLEEPING = 0x0050 , BXC_ERR_THREADING_THREAD_NOT_SUSPENDED = 0x0065 ,
  BXC_ERR_THREADING_STACK_MALLOC_FAILED = 0x0066 , BXC_ERR_THREADING_INVALID_DESCRIPTOR = 0x006e , BXC_ERR_THREADING_DESCRIPTOR_BUSY = 0x008c
}
 Error code for BXC_ERRNO_NS_USER. More...
enum  bxc_errno_kernel_e {
  BXC_ERR_PERIPHERAL_COMM_FAILED = 0x0003 , BXC_ERR_GENERAL_HW_ERROR , BXC_ERR_FTL_DATA_CORRUPTED = 0x0010 , BXC_ERR_FTL_ECC_FAILED ,
  BXC_ERR_FTL_ECC_TRIGGERED = 0x0018 , BXC_ERR_FTL_INVALID_LBA = 0x0021 , BXC_ERR_MEDIUM_WP_ENABLED = 0x0027 , BXC_ERR_MEDIUM_CHANGED ,
  BXC_ERR_MEDIUM_INCOMPATIBLE = 0x0030 , BXC_ERR_MEDIUM_ERROR , BXC_ERR_MEDIUM_UNLOADED = 0x003a , BXC_ERR_SYS_STORAGE_DEVICE_NOT_FOUND = 0x0060 ,
  BXC_ERR_SYS_ERASE_FAILED , BXC_ERR_SYS_OUT_OF_MEMORY , BXC_ERR_SYS_LOW_BATTERY , BXC_ERR_SYS_LOCK_SWITCH_ENABLED ,
  BXC_ERR_MKFS_PROMPT = 0x0102 , BXC_ERR_MKFS_UNSUPPORTED , BXC_ERR_MKFS_NO_SPACE_LEFT , BXC_ERR_MKFS_MODE_ERROR ,
  BXC_ERR_MKFS_IO_ERROR , BXC_ERR_FS_INVALID_DRIVE_LETTER = 0x0113 , BXC_ERR_FS_INVALID_FILENAME = 0x0140 , BXC_ERR_FS_OPERATION_ERROR ,
  BXC_ERR_FS_ENTRY_EXISTS , BXC_ERR_FS_DIR_RECORD_GROWTH , BXC_ERR_FS_NO_SUCH_ENTRY , BXC_ERR_FS_FILE_UNAVAILABLE ,
  BXC_ERR_FS_SUBFILE_OOB_SEEK , BXC_ERR_FS_CONFLICTING_ATTR , BXC_ERR_FS_TOO_MANY_OPEN_FILES , BXC_ERR_FS_FILE_LOCKED ,
  BXC_ERR_FS_FILE_ATTR_ERROR , BXC_ERR_FS_NO_SPACE_LEFT , BXC_ERR_FS_PATH_TRAVERSAL = 0x0154 , BXC_ERR_FS_READ_ONLY_FILE = 0x0158 ,
  BXC_ERR_FS_WRITE_ONLY_FILE , BXC_ERR_FS_PATH_TOO_LONG = 0x0162 , BXC_ERR_FS_GENERIC_ERROR = 0x0163 , BXC_ERR_FS_EOF_REACHED = 0x0165 ,
  BXC_ERR_FS_FAT16_DIR_ALLOC , BXC_ERR_DB_CORRUPTED = 0x0200 , BXC_ERR_DB_OPEN_FAILED , BXC_ERR_DB_INDEX_FULL_DELETE = 0x0203 ,
  BXC_ERR_DB_FULL , BXC_ERR_DB_INDEX_FULL_SYNC , BXC_ERR_DB_TOO_MANY_OPEN_FILES
}
 Error code for BXC_ERRNO_NS_KERNEL. More...

Functions

static unsigned short BXC_ERRNO_NS (bxc_errno_t kerrno)
 Get the namespace portion of raw kernel errno value.
static unsigned short BXC_ERRNO_ERR (bxc_errno_t kerrno)
 Get the error code portion of raw kernel errno value.
static bxc_errno_t BXC_ERRNO (unsigned short ns, unsigned short err)
 Helper function that builds an errno from namespace and error code.
size_t FormatMessage (unsigned int flags, int _sbz0, int _sbz1, int _sbz2, void *outbuf, size_t outlen)
 Fetch an error message.
void OSSetLastError (bxc_errno_t err)
 Set the global errno.
bxc_errno_t OSGetLastError (void)
 Get errno value from the global errno variable.
void _SetLastError (bxc_errno_t err)
 Set errno.
bxc_errno_t _GetLastError (void)
 Get errno.

Detailed Description

Besta error code constants and functions.

Typedef Documentation

◆ bxc_errno_t

typedef unsigned int bxc_errno_t

Kernel error code type

Enumeration Type Documentation

◆ bxc_errno_exec_e

Error code for BXC_ERRNO_NS_EXEC.

Enumerator
BXC_ERR_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.
BXC_ERR_EXEC_INVALID 

Invalid executable file.

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

Todo
Double check.
BXC_ERR_EXEC_OPEN_FAILED 

Failed to open executable file.

BXC_ERR_EXEC_LOADER_FAILURE 

Failed to parse executable file.

BXC_ERR_EXEC_MALLOC_FAILED 

Failed to allocate memory when loading executable file.

BXC_ERR_EXEC_DECOMPRESSION_FAILED 

Decompression failed.

BXC_ERR_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.

BXC_ERR_EXEC_GENERIC_ERROR 

Generic error.

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

BXC_ERR_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 BXC_ERR_EXEC_LOADER_FAILURE.

BXC_ERR_EXEC_BESTAPE_HEADER_PARSER_FAILURE 

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

BXC_ERR_EXEC_BESTAPE_LD_FAILURE 

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

BXC_ERR_EXEC_BESTAPE_RELOC_FAILURE 

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

BXC_ERR_EXEC_INVALID_PATH 

Invalid pathname.

BXC_ERR_EXEC_MODULE_NOT_LOADED 

Module is not loaded.

BXC_ERR_EXEC_NOT_LOADED 

Executable is not loaded.

◆ bxc_errno_kernel_e

Error code for BXC_ERRNO_NS_KERNEL.

Enumerator
BXC_ERR_PERIPHERAL_COMM_FAILED 

Peripheral communication failed.

BXC_ERR_GENERAL_HW_ERROR 

General hardware error.

BXC_ERR_FTL_DATA_CORRUPTED 

FTL: Data corruption detected.

BXC_ERR_FTL_ECC_FAILED 

FTL: Data corruption detected and error correction attempt failed.

BXC_ERR_FTL_ECC_TRIGGERED 

FTL: Data corruption detected and error correction attempt succeeded.

BXC_ERR_FTL_INVALID_LBA 

FTL: Invalid Logical Block Address.

BXC_ERR_MEDIUM_WP_ENABLED 

Medium is write protected.

BXC_ERR_MEDIUM_CHANGED 

Medium changed

BXC_ERR_MEDIUM_INCOMPATIBLE 

Medium is of an incompatible type.

BXC_ERR_MEDIUM_ERROR 

Medium I/O error.

BXC_ERR_MEDIUM_UNLOADED 

Medium is not loaded.

BXC_ERR_SYS_STORAGE_DEVICE_NOT_FOUND 

Storage device not found.

BXC_ERR_SYS_ERASE_FAILED 

Erase of storage device failed.

BXC_ERR_SYS_OUT_OF_MEMORY 

Out of memory.

BXC_ERR_SYS_LOW_BATTERY 

Low battery.

BXC_ERR_SYS_LOCK_SWITCH_ENABLED 

Lock switch is on. System is locked.

BXC_ERR_MKFS_PROMPT 

Block device format prompt.

BXC_ERR_MKFS_UNSUPPORTED 

Block device needs formatting.

BXC_ERR_MKFS_NO_SPACE_LEFT 

mkfs: No space left for device.

BXC_ERR_MKFS_MODE_ERROR 

mkfs: Mode error.

BXC_ERR_MKFS_IO_ERROR 

mkfs: I/O error.

BXC_ERR_FS_INVALID_DRIVE_LETTER 

Invalid drive letter

BXC_ERR_FS_INVALID_FILENAME 

Filename contains invalid characters.

BXC_ERR_FS_OPERATION_ERROR 

General filesystem I/O error.

BXC_ERR_FS_ENTRY_EXISTS 

File or directory exists.

BXC_ERR_FS_DIR_RECORD_GROWTH 

Directory/mount record cannot grow.

BXC_ERR_FS_NO_SUCH_ENTRY 

No such file or directory.

This is raised when a file/directory cannot be found, or attempting to access an unmounted drive.

See also
BXC_ERR_FS_PATH_TRAVERSAL Raised when entries cannot be found due to directory traversal failures.
BXC_ERR_FS_FILE_UNAVAILABLE 

File/directory is not available.

BXC_ERR_FS_SUBFILE_OOB_SEEK 

Seeking a subfile out-of-bound.

Only seems to be used by the loader's subfile API.

BXC_ERR_FS_CONFLICTING_ATTR 

Conflicting file/directory attributes

BXC_ERR_FS_TOO_MANY_OPEN_FILES 

Too many open files.

BXC_ERR_FS_FILE_LOCKED 

File/directory is locked for exclusive access.

BXC_ERR_FS_FILE_ATTR_ERROR 

Attribute error.

BXC_ERR_FS_NO_SPACE_LEFT 

No space left for device.

BXC_ERR_FS_PATH_TRAVERSAL 

Path traversal failure.

This is raised when attempting to access a file but the path traversal fails at a directory, or wrong type of node is found during path traversal (i.e. expecting a directory but a file is found, and vice-versa).

See also
BXC_ERR_FS_NO_SUCH_ENTRY Raised when no entry can be found, but not caused by a traversal failure.
BXC_ERR_FS_READ_ONLY_FILE 

File is read-only.

File descriptor does not support read function.

BXC_ERR_FS_WRITE_ONLY_FILE 

File is write-only.

File descriptor does not support write function.

BXC_ERR_FS_PATH_TOO_LONG 

Path too long.

BXC_ERR_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.

BXC_ERR_FS_EOF_REACHED 

EOF reached when accessing (R/W) a file.

Note
This is usually handled internally by either truncating the result or allocating more space. This could explain why the strerror message of this errno seems to indicate that it is a "record overflow" condition, since this errno may be visible by the top caller when automatic file growth fails.
BXC_ERR_FS_FAT16_DIR_ALLOC 

FAT16 directory entry allocation failure.

Seems to be raised when the FAT16 driver cannot find an empty slot to put a new directory entry in.

BXC_ERR_DB_CORRUPTED 

Database is corrupted.

BXC_ERR_DB_OPEN_FAILED 

Failed to open database.

BXC_ERR_DB_INDEX_FULL_DELETE 

Database index is full. Suggesting entry cleanup.

BXC_ERR_DB_FULL 

Database is full.

BXC_ERR_DB_INDEX_FULL_SYNC 

Database index is full. Suggesting sync with PC.

BXC_ERR_DB_TOO_MANY_OPEN_FILES 

Database: too many open files.

◆ bxc_errno_ns_flag_e

Kernel errno namespace.

Enumerator
BXC_ERRNO_NS_USER 

User (errors set by OSSetLastError()).

BXC_ERRNO_NS_KERNEL 

Kernel.

BXC_ERRNO_NS_EXEC 

Executable loader.

BXC_ERRNO_NS_APPLET 

Applet specific (errors set by _SetLastError()).

◆ bxc_errno_user_e

Error code for BXC_ERRNO_NS_USER.

Enumerator
BXC_ERR_THREADING_QUEUE_BUSY 

Message queue is busy.

BXC_ERR_THREADING_QUEUE_FULL 

Message queue is full.

BXC_ERR_THREADING_QUEUE_EMPTY 

Message queue is empty.

BXC_ERR_THREADING_SLOT_IN_USE 

Thread slot is in use.

BXC_ERR_THREADING_SLOT_FULL 

Non-reserved slots are full. Cannot create thread.

BXC_ERR_THREADING_STRUCT_MALLOC_FAILED 

Failed to allocate thread struct.

BXC_ERR_THREADING_THREAD_NOT_SLEEPING 

Thread is not sleeping.

BXC_ERR_THREADING_THREAD_NOT_SUSPENDED 

Thread is not suspended.

BXC_ERR_THREADING_STACK_MALLOC_FAILED 

Failed to allocate thread stack.

BXC_ERR_THREADING_INVALID_DESCRIPTOR 

Invalid thread/synch. primitive descriptor magic.

BXC_ERR_THREADING_DESCRIPTOR_BUSY 

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

◆ bxc_message_flags_e

Flags for FormatMessage().

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

Allocate buffer for the message.

BXC_FORMAT_MESSAGE_FROM_SYSTEM 

Use system error message string table to generate the message.

Function Documentation

◆ _GetLastError()

bxc_errno_t _GetLastError ( void )
extern

Get errno.

If kernel errno is set, the errno is returned with BXC_ERRNO_NS_KERNEL bit set. Otherwise it will return the result from OSSetLastError() with BXC_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 ( bxc_errno_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 BXC_ERRNO_NS_APPLET before passing it to OSSetLastError().

Requires -lkrnllib when dynamically linking with the shims.

Parameters
errNew errno value.
Returns
None.

◆ BXC_ERRNO()

bxc_errno_t BXC_ERRNO ( unsigned short ns,
unsigned short err )
inlinestatic

Helper function that builds an errno from namespace and error code.

Parameters
nsNamespace.
errError code.
Returns
The errno.

◆ BXC_ERRNO_ERR()

unsigned short BXC_ERRNO_ERR ( bxc_errno_t kerrno)
inlinestatic

Get the error code portion of raw kernel errno value.

Parameters
kerrnoKernel errno value.
Returns
The error code.
See also
bxc_errno_exec_e
bxc_errno_kernel_e

◆ BXC_ERRNO_NS()

unsigned short BXC_ERRNO_NS ( bxc_errno_t kerrno)
inlinestatic

Get the namespace portion of raw kernel errno value.

Parameters
kerrnoKernel errno value.
Returns
The namespace.
See also
bxc_errno_ns_flag_e

◆ 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 BXC_FORMAT_MESSAGE_FROM_SYSTEM and BXC_FORMAT_MESSAGE_ALLOCATE_BUFFER are supported. In addition, BXC_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 BXC_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 BXC_FORMAT_MESSAGE_ALLOCATE_BUFFER.
outlenWhen not using BXC_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()

bxc_errno_t OSGetLastError ( void )
extern

Get errno value from the global errno variable.

Parameters
None.
Returns
The current errno value.

◆ OSSetLastError()

void OSSetLastError ( bxc_errno_t err)
extern

Set the global errno.

Parameters
errNew errno value.
Returns
None.