# 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
    else:
        logger.info('sys_exit: no memory to deallocate')

    logger.info('sys_exit: closing file descriptors...')
    closed = 0
    for i, descr in enumerate(kernel.cpu.descriptors[3:], 3):
        if descr is not None:
            if not descr.closed:
                closed += 1
                kernel.cpu.descriptors[i].close()
            kernel.cpu.descriptors[i] = None
    kernel.cpu.descriptors = list(filter(None, kernel.cpu.descriptors))
    if closed > 0:
        logger.info('sys_exit: closed %d file descriptors', closed)
    else:
        logger.info('sys_exit: no file descriptors to be closed')

    code &= 0o0377
    kernel.cpu.descriptors[2].write(f'[!] Process exited with code {code}\n')
    kernel.cpu.RETCODE = code
    kernel.cpu.running = False

    return code


@Kernel.register(0xfc)
def sys_exit_group(kernel: Kernel, code: Int):
    return sys_exit(kernel, code)



# 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

    else:
        logger.info('sys_exit: no memory to deallocate')

    logger.info('sys_exit: closing file descriptors...')
    closed = 0
    for i, descr in enumerate(kernel.cpu.descriptors[3:], 3):
        if descr is not None:
            if not descr.closed:
                closed += 1
                kernel.cpu.descriptors[i].close()
            kernel.cpu.descriptors[i] = None
    kernel.cpu.descriptors = list(filter(None, kernel.cpu.descriptors))
    if closed > 0:
        logger.info('sys_exit: closed %d file descriptors', closed)
    else:
        logger.info('sys_exit: no file descriptors to be closed')

    code &= 0o0377
    kernel.cpu.descriptors[2].write(f'[!] Process exited with code {code}\n')
    kernel.cpu.RETCODE = code
    kernel.cpu.running = False

    return code


@Kernel.register(0xfc)
def sys_exit_group(kernel: Kernel, code: Int):
    return sys_exit(kernel, code)



@Kernel.register(0x7a)