2023-09-08 11:35:18 +02:00
|
|
|
/* Memory managment.
|
2018-06-25 17:03:09 +02:00
|
|
|
*
|
2023-01-07 17:20:15 +01:00
|
|
|
* Author: Daniel Krebs <github@daniel-krebs.net>
|
2023-09-08 11:35:18 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2023-01-07 17:20:15 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-09-08 11:35:18 +02:00
|
|
|
*/
|
2018-06-25 17:03:09 +02:00
|
|
|
|
2018-06-04 12:17:23 +02:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <villas/memory.hpp>
|
|
|
|
|
2020-06-14 22:11:15 +02:00
|
|
|
using namespace villas;
|
2018-06-04 12:17:23 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
bool HostRam::free(void *addr, size_t length) {
|
|
|
|
return munmap(addr, length) == 0;
|
2018-06-04 12:17:23 +02:00
|
|
|
}
|
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
void *HostRam::allocate(size_t length, int flags) {
|
|
|
|
const int mmap_flags = flags | MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT;
|
|
|
|
const int mmap_protection = PROT_READ | PROT_WRITE;
|
2018-06-04 12:17:23 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
return mmap(nullptr, length, mmap_protection, mmap_flags, 0, 0);
|
2018-06-04 12:17:23 +02:00
|
|
|
}
|