From a0ac8bf957ed8fee99900eb572322d89e6bb0b46 Mon Sep 17 00:00:00 2001 From: Pia Date: Fri, 24 May 2024 14:51:23 +0200 Subject: [PATCH] syscall handler init --- cairo0-bootloader/os/syscall_handler.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cairo0-bootloader/os/syscall_handler.py diff --git a/cairo0-bootloader/os/syscall_handler.py b/cairo0-bootloader/os/syscall_handler.py new file mode 100644 index 0000000..6e40ee7 --- /dev/null +++ b/cairo0-bootloader/os/syscall_handler.py @@ -0,0 +1,24 @@ +from typing import Iterable +from starkware.starknet.core.os.syscall_handler import SyscallHandlerBase, OsExecutionHelper +from starkware.cairo.lang.vm.relocatable import RelocatableValue, MaybeRelocatable +from starkware.cairo.lang.vm.memory_segments import MemorySegmentManager + +class SyscallHandler(SyscallHandlerBase): + """ + A handler for system calls; used by the BusinessLogic entry point execution. + """ + + def __init__( + self, + segments: MemorySegmentManager, + ): + super().__init__(segments=segments, initial_syscall_ptr=None) + + def set_syscall_ptr(self, syscall_ptr: RelocatableValue): + assert self._syscall_ptr is None, "syscall_ptr is already set." + self._syscall_ptr = syscall_ptr + + def allocate_segment(self, data: Iterable[MaybeRelocatable]) -> RelocatableValue: + segment_start = self.segments.add() + self.segments.write_arg(ptr=segment_start, arg=data) + return segment_start \ No newline at end of file