quic/qbox
Loading...
Searching...
No Matches
memory_services.h
1/*
2 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _GREENSOCS_BASE_COMPONENTS_MEMORY_SERVICES_H
8#define _GREENSOCS_BASE_COMPONENTS_MEMORY_SERVICES_H
9
10#include <fstream>
11#include <memory>
12
13#include <cci_configuration>
14#include <systemc>
15
16#include <scp/report.h>
17
18#ifndef _WIN32
19#include <fcntl.h>
20#include <sys/mman.h>
21#include <sys/stat.h>
22#endif
23#include <csignal>
24#include <cstdlib>
25#include <uutils.h>
26#include <cerrno>
27#include <cstring>
28
29namespace gs {
30// Singleton class that handles memory allocation, alignment, file mapping and shared memory
31
32#define ALIGNEDBITS 12
33#define MAX_SHM_STR_LENGTH 255
34#define MAX_SHM_SEGS_NUM 1024
35
37{
38 SCP_LOGGER((), "MemoryServices");
39
40private:
42
43 void die_sys_api(int error, const char* memname, const std::string& die_msg);
44
45 struct shmem_info {
46 uint8_t* base;
47 size_t size;
48 };
49 struct shm_cleaner_info {
50 int count;
51 char name[MAX_SHM_SEGS_NUM][MAX_SHM_STR_LENGTH];
52 };
53 std::map<std::string, shmem_info> m_shmem_info_map;
54 bool finished = false;
55 bool child_cleaner_forked = false;
56 pid_t m_cpid;
57 ProcAliveHandler pahandler;
58 shm_cleaner_info* cl_info = nullptr;
59 std::string m_name;
60
61public:
63
64 const char* name() const;
65
66 size_t get_shmem_seg_num() const;
67
68 void cleanup();
69
70 static void cleanupexit();
71
72 void init();
73
74 static MemoryServices& get();
75
76 MemoryServices(MemoryServices const&) = delete;
77 void operator=(MemoryServices const&) = delete;
78
91
92 uint8_t* map_file(const char* mapfile, uint64_t size, uint64_t offset);
93
94 uint8_t* map_mem_create(const char* memname, uint64_t size, int* o_fd);
95
96 uint8_t* map_mem_join(const char* memname, size_t size);
97
98 uint8_t* alloc(uint64_t size);
99};
100} // namespace gs
101#endif
Definition target.h:160
Definition memory_services.h:37
void start_shm_cleaner_proc()
Definition memory_services.cc:61
Definition uutils.h:142
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10