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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/* Copyright (c) 2013, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <odp_config_internal.h>
#include <odp/api/debug.h>
#include <odp/api/std_types.h>
#include <odp/api/shared_memory.h>
#include <_ishm_internal.h>
#include <string.h>
ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS,
"ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS");
static inline uint32_t from_handle(odp_shm_t shm)
{
return _odp_typeval(shm) - 1;
}
static inline odp_shm_t to_handle(uint32_t index)
{
return _odp_cast_scalar(odp_shm_t, index + 1);
}
int odp_shm_capability(odp_shm_capability_t *capa)
{
memset(capa, 0, sizeof(odp_shm_capability_t));
capa->max_blocks = ODP_CONFIG_SHM_BLOCKS;
capa->max_size = 0;
capa->max_align = 0;
return 0;
}
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
uint32_t flags)
{
int block_index;
int flgs = 0; /* internal ishm flags */
/* set internal ishm flags according to API flags: */
flgs |= (flags & ODP_SHM_PROC) ? _ODP_ISHM_EXPORT : 0;
/* all mem reserved through this interface is requested to be locked: */
flgs |= (flags & _ODP_ISHM_LOCK);
block_index = _odp_ishm_reserve(name, size, -1, align, flgs, flags);
if (block_index >= 0)
return to_handle(block_index);
else
return ODP_SHM_INVALID;
}
int odp_shm_free(odp_shm_t shm)
{
return _odp_ishm_free_by_index(from_handle(shm));
}
odp_shm_t odp_shm_lookup(const char *name)
{
return to_handle(_odp_ishm_lookup_by_name(name));
}
void *odp_shm_addr(odp_shm_t shm)
{
return _odp_ishm_address(from_handle(shm));
}
int odp_shm_info(odp_shm_t shm, odp_shm_info_t *info)
{
_odp_ishm_info_t ishm_info;
if (_odp_ishm_info(from_handle(shm), &ishm_info))
return -1;
info->name = ishm_info.name;
info->addr = ishm_info.addr;
info->size = ishm_info.size;
info->page_size = ishm_info.page_size;
info->flags = ishm_info.user_flags;
return 0;
}
void odp_shm_print_all(void)
{
_odp_ishm_status("Memory allocation status:");
}
|