# 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:


from .kernel import Kernel, Int, Uint
from ctypes import LittleEndianStructure, c_uint32, sizeof
        from ..Registers import SegmentDescriptor
import logging
    import enum
    logger.error('\tmmap: [ERR] unknown flags: %s', flags)

    return -1


def _munmap_fuse_memory_blocks(kernel: Kernel):
    kernel.free_memory_blocks.sort()

    did_fuse = True

    while did_fuse:
        did_fuse = False

        for i in range(len(kernel.free_memory_blocks) - 1):
            fst, snd = kernel.free_memory_blocks[i], kernel.free_memory_blocks[i + 1]

            if fst[0] <= snd[0] and snd[1] <= fst[1]:  # snd contained in fst
                kernel.free_memory_blocks[i] = None
                kernel.free_memory_blocks[i + 1] = fst
                did_fuse = True
            elif fst[0] <= snd[0] <= fst[1] < snd[1]:  # fst intersects snd
                kernel.free_memory_blocks[i] = None
                kernel.free_memory_blocks[i + 1] = fst[0], snd[1]
                did_fuse = True

        if did_fuse:
            kernel.free_blocks = sorted(filter(None, kernel.free_memory_blocks))


@Kernel.register(0x5b)

# 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_memory.py
from .kernel import Kernel, Int, Uint
from ctypes import LittleEndianStructure, c_uint32, sizeof
        from ..Registers import SegmentDescriptor
import logging
    import enum

    logger.error('\tmmap: [ERR] unknown flags: %s', flags)

    return -1


def _munmap_fuse_memory_blocks(kernel: Kernel):
    kernel.free_memory_blocks.sort()

    did_fuse = True

    while did_fuse:
        did_fuse = False

        for i in range(len(kernel.free_memory_blocks) - 1):
            fst, snd = kernel.free_memory_blocks[i], kernel.free_memory_blocks[i + 1]

            if fst[0] <= snd[0] and snd[1] <= fst[1]:  # snd contained in fst
                kernel.free_memory_blocks[i] = None
                kernel.free_memory_blocks[i + 1] = fst
                did_fuse = True
            elif fst[0] <= snd[0] <= fst[1] < snd[1]:  # fst intersects snd
                kernel.free_memory_blocks[i] = None
                kernel.free_memory_blocks[i + 1] = fst[0], snd[1]
                did_fuse = True

        if did_fuse:
            kernel.free_blocks = sorted(filter(None, kernel.free_memory_blocks))


@Kernel.register(0x5b)

def sys_munmap(kernel: Kernel, addr: Uint, length: Uint):