Module kernel

Kernel module provides access to the emulated system's kernel object (read/write/...)

All kernel objects provided here are class-based.

Functions

kernel.codeseg:codeSize () Get the size of the segment's code section.
kernel.codeseg:dataSize () Get the size of the segment's data section.
kernel.codeseg:bssSize () Get the size of the segment's bss (initialised data) section.
kernel.codeseg:exportCount () Get the number of export functions (addresses) this code segment provides.
kernel.codeseg:lookup (process, ord) Search for a function with specified index (ordinal) in the library and retrieve its address.
loadCodeseg (path) Load a new code segment.
kernel.process:readByte (addr) Read the byte value (8-bit) at the specified address from this process's memory space.
kernel.process:readWord (addr) Read the word value (16-bit) at the specified address from this process's memory space.
kernel.process:readDword (addr) Read the dword value (32-bit) at the specified address from this process's memory space.
kernel.process:readQword (addr) Read the qword value (64-bit) at the specified address from this process's memory space.
kernel.process:name () Get the name of the process.
kernel.process:executablePath () Get the path to the running process's executable.
kernel.process:readMemory (addr, size) Read a certain amount of data from the process's memory.
kernel.process:writeMemory (addr, buffer) Write a byte array into the process's memory space.
getCurrentProcess () Get the current running process on the current emulated core.
kernel.thread:name () Get the name of the thread.
kernel.thread:stackBase () Get the stack base of the thread.
kernel.thread:heapBase () Get the heap base of the thread.
kernel.thread:getRegister (idx) Retrieve the value in register from R0 to R15.
kernel.thread:getPc () Retrieve the value in the PC (program counter) register.
kernel.thread:getLr () Retrieve the value in the PC (program counter) register.
kernel.thread:getSp () Retrieve the value in the SP (stack pointer) register.
kernel.thread:getCpsr () Retrieve the value in the CPSR register.
kernel.thread:exitReason () Get the reason this thread exited.
kernel.thread:currentState () Get the current scheduling state of the thread.
kernel.thread:priority () Get the scheduling priority of the thread in the process.
kernel.thread:nextInProcess () Get the thread next to the caller thread in the thread's owning process.
kernel.thread:ownProcess () Get the process that owns this thread.
kernel.process:firstThread () Get the first thread of the process.
getCurrentThread () Get the current running thread on the current emulated core.
kernel.server:name () Get the name of the server.
kernel.session:server () Get the server that this session is connected to.
sessionFromHandle (handle) Retrieve the session object from the kernel handle.
kernel.ipcMessage:func () Get the function/opcode of this message.
kernel.ipcMessage:flags () Get the argument flags of this message.
kernel.ipcMessage:arg (idx) Get the argument value of the message.
kernel.ipcMessage:sender () Get the thread sending the message.
kernel.ipcMessage:session () Get the session responsible for establishing connection to the server and sending the message.
kernel.ipcMessage:requestStatusAddress () Get the request status address in the sender process's memory space.

Fields

THREAD_STATE_CREATED Thread is created but not yet to run.
THREAD_STATE_RUN Thread is running.
THREAD_STATE_WAIT Thread is currently blocked and is waiting for a sync object.
THREAD_STATE_READY Thread is in the ready queue, waiting to be run.
THREAD_STATE_WAIT_FAST_SEMA Thread is currently waiting for a fast semaphore.
THREAD_STATE_WAIT_MUTEX Thread is currently waiting for a mutex.
THREAD_STATE_WAIT_MUTEX_SUSPEND Thread is currently waiting for a mutex and is also suspended.
THREAD_STATE_WAIT_FAST_SEMA_SUSPEND Thread is currently waiting for a fast semaphore and is also suspended.
THREAD_STATE_HOLD_MUTEX_PENDING Thread is currently in queue to own the mutex object.


Functions

kernel.codeseg:codeSize ()
Get the size of the segment's code section.

Returns:

    A 32-bit integer as the code size.
kernel.codeseg:dataSize ()
Get the size of the segment's data section.

Returns:

    A 32-bit integer as the data size.
kernel.codeseg:bssSize ()
Get the size of the segment's bss (initialised data) section.

Returns:

    A 32-bit integer as the bss size.
kernel.codeseg:exportCount ()
Get the number of export functions (addresses) this code segment provides.

Returns:

    A 32-bit integer containing the export count.
kernel.codeseg:lookup (process, ord)
Search for a function with specified index (ordinal) in the library and retrieve its address.

For each process, a library may have different code address. ROM libraries are exception to this.

Parameters:

  • process A process object, where the address of the function should be retrieved on.
  • ord The ordinal identify the library function to get.

Returns:

    32-bit integer as address to the function in the process's memory space, 0 on failure.
loadCodeseg (path)
Load a new code segment.

This code segment is not attached to any process during this function.

Parameters:

  • path The emulated system's path to the codeseg to load.

Returns:

    codeseg class if the codeseg loads successfully, else nil.
kernel.process:readByte (addr)
Read the byte value (8-bit) at the specified address from this process's memory space.

Parameters:

  • addr The address to perform the read.

Returns:

    Byte value stored at the given address.
kernel.process:readWord (addr)
Read the word value (16-bit) at the specified address from this process's memory space.

Parameters:

  • addr The address to perform the read.

Returns:

    Word value stored at the given address.
kernel.process:readDword (addr)
Read the dword value (32-bit) at the specified address from this process's memory space.

Parameters:

  • addr The address to perform the read.

Returns:

    Dword value stored at the given address.
kernel.process:readQword (addr)
Read the qword value (64-bit) at the specified address from this process's memory space.

Parameters:

  • addr The address to perform the read.

Returns:

    Qword value stored at the given address.
kernel.process:name ()
Get the name of the process.

Returns:

    A string contains the process's name.
kernel.process:executablePath ()
Get the path to the running process's executable.

This path is in the emulated's virtual file system.

Returns:

    A string contains the executable path.
kernel.process:readMemory (addr, size)
Read a certain amount of data from the process's memory.

Parameters:

  • addr The address to read data from.
  • size The number of bytes to read.

Returns:

    A byte array contains the read result.
kernel.process:writeMemory (addr, buffer)
Write a byte array into the process's memory space.

This function will call error on falure.

Parameters:

  • addr The address to write the byte array to.
  • buffer Byte array to write to the memory.
getCurrentProcess ()
Get the current running process on the current emulated core.

Returns:

    Current process with type process.
kernel.thread:name ()
Get the name of the thread.

Returns:

    A string contains the thread's name.
kernel.thread:stackBase ()
Get the stack base of the thread.

This is the beginning address of the stack memory chunk, also can be called as the highest point of the stack.

Returns:

    A 32-bit integer address as the stack base value.
kernel.thread:heapBase ()
Get the heap base of the thread.

This is the beginning address of the heap memory chunk, which is created by the code in the thread and not directly managed by the kernel.

Returns:

    A 32-bit integer address as the heap base value.
kernel.thread:getRegister (idx)
Retrieve the value in register from R0 to R15.

This is the saved value from the last time this thread ran. If this is the current thread, the value will be the same as the one called from cpu module.

Parameters:

  • idx The index of the register to retrieve (0 - 15). Undefined behaviour will raise for index out of the given range.

Returns:

    The value of the target register as a 32-bit integer.
kernel.thread:getPc ()
Retrieve the value in the PC (program counter) register.

This is the saved value from the last time this thread ran. If this is the current thread, the value will be the same as the one called from cpu module.

The PC register is identical to the R15 register (PC is a different name for R15).

Returns:

    The value of the PC as a 32-bit integer.
kernel.thread:getLr ()
Retrieve the value in the PC (program counter) register.

This is the saved value from the last time this thread ran. If this is the current thread, the value will be the same as the one called from cpu module.

The PC register is identical to the R15 register (PC is a different name for R15).

Returns:

    The value of the PC as a 32-bit integer.
kernel.thread:getSp ()
Retrieve the value in the SP (stack pointer) register.

This is the saved value from the last time this thread ran. If this is the current thread, the value will be the same as the one called from cpu module.

The SP register is identical to the R13 register (SP is a different name for R13).

Returns:

    The value of the SP as a 32-bit integer.
kernel.thread:getCpsr ()
Retrieve the value in the CPSR register.

This is the saved value from the last time this thread ran. If this is the current thread, the value will be the same as the one called from cpu module.

Returns:

    The value of the CPSR as a 32-bit integer.
kernel.thread:exitReason ()
Get the reason this thread exited.

The reason is a code, which will be 0 if the thread is still running.

Returns:

    32-bit integer code indicating the exit reason.
kernel.thread:currentState ()
Get the current scheduling state of the thread.

Returns:

    One of the value in THREAD_STATE_WAIT_ constant enums.
kernel.thread:priority ()
Get the scheduling priority of the thread in the process.

Returns:

    One of the value in PRIORITY_ constant enums.
kernel.thread:nextInProcess ()
Get the thread next to the caller thread in the thread's owning process.

Use this to iterate all threads in the process.

Returns:

    nil if there's no more thread in the process, else the next thread as a thread object.
kernel.thread:ownProcess ()
Get the process that owns this thread.

Returns:

    The owning process as a process object.
kernel.process:firstThread ()
Get the first thread of the process.

From the first thread you can travel to the next thread by using the kernel.thread:nextInProcess function.

Returns:

    The first thread of the process as a process object.

See also:

getCurrentThread ()
Get the current running thread on the current emulated core.

Returns:

    Current thread with type thread.
kernel.server:name ()
Get the name of the server.

Returns:

    A string object containing the server's name.
kernel.session:server ()
Get the server that this session is connected to.

The session will be responsible for sending messages/requests to the connected server.

Returns:

    The connected server object with type of server.
sessionFromHandle (handle)
Retrieve the session object from the kernel handle.

Parameters:

  • handle The kernel handle of the session.

Returns:

    The session object correspond to this kernel handle.
kernel.ipcMessage:func ()
Get the function/opcode of this message.

Returns:

    32-bit integer containing the message's function code.
kernel.ipcMessage:flags ()
Get the argument flags of this message.

This value is only relevant on IPCv2 model (appears usually on late S60v2 and further). On EKA1 this value is 0xFFFFFFFF.

Returns:

    32-bit integer containing the message's argument flags.
kernel.ipcMessage:arg (idx)
Get the argument value of the message.

Each message stores 4 integer arguments that can be considered as pointer, handle or pure integer.

Parameters:

  • idx The index of the argument to retrieve (0 - 3). Undefined behaviour if value passed is not in specified range.

Returns:

    The value of the argument.
kernel.ipcMessage:sender ()
Get the thread sending the message.

Returns:

    The thread object that sends the message.
kernel.ipcMessage:session ()
Get the session responsible for establishing connection to the server and sending the message.

Returns:

    The session object that does the message submit.
kernel.ipcMessage:requestStatusAddress ()
Get the request status address in the sender process's memory space.

It's recommended to use std.requestStatus class for exploring more about the condition of the status.

Returns:

    Address to the request status as a 32-bit integer.

Fields

THREAD_STATE_CREATED
Thread is created but not yet to run.
THREAD_STATE_RUN
Thread is running.
THREAD_STATE_WAIT
Thread is currently blocked and is waiting for a sync object. Currently unused.
THREAD_STATE_READY
Thread is in the ready queue, waiting to be run.
THREAD_STATE_WAIT_FAST_SEMA
Thread is currently waiting for a fast semaphore.
THREAD_STATE_WAIT_MUTEX
Thread is currently waiting for a mutex.
THREAD_STATE_WAIT_MUTEX_SUSPEND
Thread is currently waiting for a mutex and is also suspended.
THREAD_STATE_WAIT_FAST_SEMA_SUSPEND
Thread is currently waiting for a fast semaphore and is also suspended.
THREAD_STATE_HOLD_MUTEX_PENDING
Thread is currently in queue to own the mutex object.
generated by LDoc 1.4.6 Last updated 2021-10-30 01:56:22