# 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 struct
import ctypes
import logging
    import time
    import enum
from .kernel import Kernel, Uint, Int
    request_size = _IOC_SIZE(request)

    logger.info(f'ioctl(fd={fd},request={request:09_x} (type={request_type}, number={request_number}, direction={request_direction}, size={request_size}))')

    if request_type == b'T':
        if request_number == 19 and request_direction == directions._IOC_NONE:
            try:
                kernel.cpu.descriptors[fd]
            except IndexError:
                return kernel.cpu.__return(-1)

            # TAKEN FROM: http://man7.org/linux/man-pages/man4/tty_ioctl.4.html
            #
            # struct winsize
            # {
            #     unsigned short ws_row;
            #     unsigned short ws_col;
            #     unsigned short ws_xpixel; / *unused * /
            #     unsigned short ws_ypixel; / *unused * /
            # };
            struct_winsize = struct.Struct('<HHHH')

            kernel.cpu.mem.set_bytes(data_addr, struct_winsize.size, struct_winsize.pack(256, 256, 0, 0))

            return 0

    return -1


@Kernel.register(0x01)

# 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_sys.py
import struct
import ctypes
import logging
    import time
    import enum
from .kernel import Kernel, Uint, Int

    request_size = _IOC_SIZE(request)

    logger.info(f'ioctl(fd={fd},request={request:09_x} (type={request_type}, number={request_number}, direction={request_direction}, size={request_size}))')

    if request_type == b'T':
        if request_number == 19 and request_direction == directions._IOC_NONE:
            try:
                kernel.cpu.descriptors[fd]
            except IndexError:
                return kernel.cpu.__return(-1)

            # TAKEN FROM: http://man7.org/linux/man-pages/man4/tty_ioctl.4.html
            #
            # struct winsize
            # {
            #     unsigned short ws_row;
            #     unsigned short ws_col;
            #     unsigned short ws_xpixel; / *unused * /
            #     unsigned short ws_ypixel; / *unused * /
            # };
            struct_winsize = struct.Struct('<HHHH')

            kernel.cpu.mem.set_bytes(data_addr, struct_winsize.size, struct_winsize.pack(256, 256, 0, 0))

            return 0

    return -1


@Kernel.register(0x01)

def sys_exit(kernel: Kernel, code: Int):