CCF
Loading...
Searching...
No Matches
mem.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include <cstring>
6#include <limits>
7#include <stdlib.h>
8#include <sys/resource.h>
9
10namespace ccf::pal
11{
21
22 static inline void* safe_memcpy(void* dest, const void* src, size_t count)
23 {
24 return ::memcpy(dest, src, count);
25 }
26
27 static inline bool get_mallinfo(MallocInfo& info)
28 {
29 {
30 rusage ru = {};
31 auto rc = getrusage(RUSAGE_SELF, &ru);
32 if (rc != 0)
33 {
34 return false;
35 }
36 const auto heap_size = ru.ru_maxrss * 1024;
37
38 info.current_allocated_heap_size = heap_size;
39 info.peak_allocated_heap_size = heap_size;
40 }
41
42 {
43 rlimit rl = {};
44 auto rc = getrlimit(RLIMIT_AS, &rl);
45 if (rc != 0)
46 {
47 return false;
48 }
49
50 info.max_total_heap_size = rl.rlim_cur;
51 }
52
53 return true;
54 }
55}
Definition attestation.h:13
Definition mem.h:16
size_t current_allocated_heap_size
Definition mem.h:18
size_t max_total_heap_size
Definition mem.h:17
size_t peak_allocated_heap_size
Definition mem.h:19