U-4 d Z ddlmZmZmZmZ ddlZddlmZ g dZ G d d Z G d d Z G d de ZdS ) zlModule containing a memory memory manager which provides a sliding window on a number of memory mapped files ) MapWindow MapRegion MapRegionList is_64_bit N)reduce)StaticWindowMapManagerSlidingWindowMapManagerWindowCursorc e Zd ZdZdZddZd Zd Zd Zd Z d Z d Zd Zdd Z d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )r a Pointer into the mapped region of the memory manager, keeping the map alive until it is destroyed and no other client uses it. Cursors should not be created manually, but are instead returned by the SlidingWindowMapManager **Note:**: The current implementation is suited for static and sliding window managers, but it also means that it must be suited for the somewhat quite different sliding manager. It could be improved, but I see no real need to do so._manager_rlist_region_ofs_sizeNc L || _ || _ d | _ d| _ d| _ d S )Nr r )selfmanagerregionss \/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/smmap/mman.py__init__zWindowCursor.__init__% s) c . | d S N_destroyr s r __del__zWindowCursor.__del__, r c | S r r s r __enter__zWindowCursor.__enter__/ s r c . | d S r r )r exc_type exc_value tracebacks r __exit__zWindowCursor.__exit__2 r r c | | j k t | j dk r8| j j | j dS dS # t t f$ r Y dS w xY wdS )z&Destruction code to decrement countersNr ) unuse_regionr lenr _fdictpop path_or_fd TypeErrorKeyErrorr s r r zWindowCursor._destroy5 s ;" t{##q((M(,,T[-C-C-E-EFFFFF )( x( #"s AA/ /BBc 4 |j | _ t |j |j | _ |j | _ |j | _ |j | _ | j D ]}| | j | j dS dS )z>Copy all data from rhs into this instance, handles usage countN)r typer r r r increment_client_count)r rhsregions r _copy_fromzWindowCursor._copy_fromJ s &d3:&&sz22{H Y k , ,F))++++<#L//11111 $#r c ^ t | }| | |S )zcopy module interface)r2 r6 )r cpys r __copy__zWindowCursor.__copy__Y s* d4jjllt r c X | | | dS )zAssign rhs to this instance. This is required in order to get a real copy. Alternativly, you can copy an existing instance using the copy moduleN)r r6 )r r4 s r assignzWindowCursor.assign` s) r r c d}| j }| j }t |p|| p| }| j 1| j | rd}n| ||k r| S |r<| | j |||d | _ | j || j j z | _ t || j |z | _ | S )a$ Assure we point to a window which allows access to the given offset into the file :param offset: absolute offset in bytes into the file :param size: amount of bytes to map. If 0, all available bytes will be mapped :param flags: additional flags to be given to os.open in case a file handle is initially opened for mapping. Has no effect if a region can actually be reused. :return: this instance - it should be queried for whether it points to a valid memory region. This is not the case if the mapping failed because we reached the end of the file **Note:**: The size actually mapped may be smaller than the given size. If that is the case, either the file has reached its end, or the map was created between two existing regionsTNF)r r file_sizeminwindow_sizer includes_ofsr* _obtain_regionr3 _br ofs_endr )r offsetsizeflagsneed_regionmanfsizes r use_regionzWindowCursor.use_regionf s m%%''4=5#//"3"3"