# Path: VM/ctypes_types.py

# 
# Path: VM/kernel/kernel.py
# class KernelMeta(type):   
# class Kernel(metaclass=KernelMeta):
#     def register(cls, syscall_number: int):
#         def actually_register(function: Callable[..., int]):
#     def __init__(self, cpu):
#     def __getitem__(self, syscall_number: int):
#     def kernel_read_string(self, address: int) -> bytes:


import os
import logging
    import enum
from io import UnsupportedOperation
from ..ctypes_types import udword, ctypes
from .kernel import Kernel, Int, Uint
    kernel.cpu.descriptors[fd] = None

    logger.info('\tsys_close: [SUCC] descriptor %u closed', fd)

    return 0


@Kernel.register(0x0a)
def sys_unlink(kernel: Kernel, pathname_addr: Uint):
    """
    int sys_unlink(const char * pathname)
    """

    pathname = kernel.kernel_read_string(pathname_addr).decode()

    logger.info('sys_unlink(const char * pathname = %r)', pathname)

    try:
        os.unlink(pathname)
    except OSError:
        ret = -1
        logger.info('\tsys_unlink: [ERR] failed to unlink %r', pathname)
    else:
        logger.info('\tsys_unlink: [SUCC] unlinked %r', pathname)
        ret = 0

    return ret


@Kernel.register(0x03)

# Path: VM/ctypes_types.py

# 
# Path: VM/kernel/kernel.py
# class KernelMeta(type):   
# class Kernel(metaclass=KernelMeta):
#     def register(cls, syscall_number: int):
#         def actually_register(function: Callable[..., int]):
#     def __init__(self, cpu):
#     def __getitem__(self, syscall_number: int):
#     def kernel_read_string(self, address: int) -> bytes:


# Path: VM/kernel/kernel_filesystem.py
import os
import logging
    import enum
from io import UnsupportedOperation
from ..ctypes_types import udword, ctypes
from .kernel import Kernel, Int, Uint

    kernel.cpu.descriptors[fd] = None

    logger.info('\tsys_close: [SUCC] descriptor %u closed', fd)

    return 0


@Kernel.register(0x0a)
def sys_unlink(kernel: Kernel, pathname_addr: Uint):
    """
    int sys_unlink(const char * pathname)
    """

    pathname = kernel.kernel_read_string(pathname_addr).decode()

    logger.info('sys_unlink(const char * pathname = %r)', pathname)

    try:
        os.unlink(pathname)
    except OSError:
        ret = -1
        logger.info('\tsys_unlink: [ERR] failed to unlink %r', pathname)
    else:
        logger.info('\tsys_unlink: [SUCC] unlinked %r', pathname)
        ret = 0

    return ret


@Kernel.register(0x03)

def sys_read(kernel: Kernel, fd: Uint, data_addr: Uint, count: Uint):