aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine/stack/stack_utils.h
blob: d5d6ef9e98a4dbebc89ce70bdc832f326ad54da1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include "stack_common.h"


namespace NCoro::NStack {
    /*! Actual size of allocated memory can exceed size in pages, due to unaligned allocation.
     * @param sizeInPages : number of pages to allocate
     * @param rawPtr : pointer to unaligned memory. Should be passed to free() when is not used any more.
     * @param alignedPtr : pointer to beginning of first fully allocated page
     * @return : true on success
     */
    bool GetAlignedMemory(size_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept;

    /*! Release mapped RSS memory.
     *  @param alignedPt : page-size aligned memory on which RSS memory should be freed
     *  @param numOfPages : number of pages to free from RSS memory
     */
    void ReleaseRss(char* alignedPtr, size_t numOfPages) noexcept;

    /*! Count pages with RSS memory
     * @param alignedPtr : pointer to page-aligned memory for which calculations would be done
     * @param numOfPages : number of pages to check
     * @return : number of pages with RSS memory
     */
    size_t CountMapped(char* alignedPtr, size_t numOfPages) noexcept;
}