# 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
        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):
    logger.info('sys_read(unsigned int fd = %u, char *dest = 0x%08x, size_t count = %u)', fd, data_addr, count)

    try:
        data = os.read(kernel.cpu.descriptors[fd].fileno(), count)
    except (AttributeError, UnsupportedOperation):
        data = (kernel.cpu.descriptors[fd].read(count) + '\n').encode('ascii')
    except:
        logger.error('\tsys_read: [ERR] failed to read %u bytes from descriptor %u', count, fd)

        return -1

    logger.info('\tsys_read: [SUCC] read %r from fd %u', data, fd)

    l = len(data)
    kernel.cpu.mem.set_bytes(data_addr, l, data)

    return l



# 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

        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):
    logger.info('sys_read(unsigned int fd = %u, char *dest = 0x%08x, size_t count = %u)', fd, data_addr, count)

    try:
        data = os.read(kernel.cpu.descriptors[fd].fileno(), count)
    except (AttributeError, UnsupportedOperation):
        data = (kernel.cpu.descriptors[fd].read(count) + '\n').encode('ascii')
    except:
        logger.error('\tsys_read: [ERR] failed to read %u bytes from descriptor %u', count, fd)

        return -1

    logger.info('\tsys_read: [SUCC] read %r from fd %u', data, fd)

    l = len(data)
    kernel.cpu.mem.set_bytes(data_addr, l, data)

    return l



@Kernel.register(0x04)