HAPMEM
HAP Memory Allocator
HAP_mem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2020 Qualcomm Technologies, Inc.
3  * All Rights Reserved.
4  * Confidential and Proprietary - Qualcomm Technologies, Inc
5  */
6 
7 #ifndef HAP_MEM_H
8 #define HAP_MEM_H
9 #include <stdlib.h>
10 #include "AEEStdDef.h"
11 #include "AEEStdErr.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 /*
24  * Protections are chosen from these bits, or-ed together
25  */
26 
27 
36 
41 #define HAP_PROT_NONE 0x00 /* no permissions */
42 
46 #define HAP_PROT_READ 0x01 /* pages can be read */
47 
51 #define HAP_PROT_WRITE 0x02 /* pages can be written */
52 
57 #define HAP_PROT_EXEC 0x04 /* pages can be executed */
58 
59 
61 
62 /*
63  * Cache policy or-ed with protections parameter
64  */
65 
73 
78 #define HAP_MEM_CACHE_WRITEBACK (0x10) /* cache write back */
79 
83 #define HAP_MEM_CACHE_NON_SHARED (0x20) /* normal uncached memory */
84 
89 #define HAP_MEM_CACHE_WRITETHROUGH (0x40) /* write through memory */
90 
92 
100 
106 #define HAP_MEM_FLAGS_SKIP_DSP_MAP 0
107 
112 #define HAP_MEM_FLAGS_DSP_MAP 1
113 
120 #define HAP_MEM_FLAGS_EXTENDED_MAP 2
121 
126 #define HAP_MEM_FLAGS_MAX (HAP_MEM_FLAGS_EXTENDED_MAP + 1)
127 
129 
137 static inline int HAP_malloc(uint32 bytes, void** pptr)
138 {
139  *pptr = malloc(bytes);
140  if (*pptr) {
141  return AEE_SUCCESS;
142  }
143  return AEE_ENOMEMORY;
144 }
145 
154 static inline int HAP_free(void* ptr)
155 {
156  if(ptr == NULL)
157  return AEE_EBADCLASS;
158  free(ptr);
159  return AEE_SUCCESS;
160 }
161 
166  uint64 bytes_free;
169  uint64 bytes_used;
170  uint64 seg_free;
171  uint64 seg_used;
172  uint64 min_grow_bytes;
173 };
174 
179  USAGE_STATS = 1,
180  MAX_USED
181 };
182 
186 typedef struct {
187  enum HAP_mem_stats_request req_id;
188  union {
189  struct HAP_mem_stats usage_stats;
190  unsigned long max_used; /* Peak heap usage */
191  };
193 
200 int HAP_mem_get_stats(struct HAP_mem_stats *stats);
201 
209 
226 int HAP_mem_set_grow_size(uint64 min, uint64 max);
227 
242 int HAP_mem_set_heap_thresholds(unsigned int low_largest_block_size, unsigned int high_largest_block_size);
243 
244 
261 void* HAP_mmap(void *addr, int len, int prot, int flags, int fd, long offset);
262 
277 void* HAP_mmap2(void *addr, size_t len, int prot, int flags, int fd, long offset);
278 
289 int HAP_munmap(void *addr, int len);
290 
299 int HAP_munmap2(void *addr, size_t len);
300 
311 int HAP_mmap_get(int fd, void **vaddr, uint64 *paddr);
312 
321 int HAP_mmap_put(int fd);
322 
330 uint64 HAP_mem_available_stack(void);
331 
345 int HAP_apps_mem_request(size_t len, uint32_t flags, int *fd, uint64_t *dsp_va);
346 
356 int HAP_apps_mem_release(int fd);
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 
362 #endif // HAP_MEM_H
363 
static int HAP_free(void *ptr)
Definition: HAP_mem.h:154
uint64 seg_free
Definition: HAP_mem.h:170
RequestID/Response for HAP_mem_get_heap_info.
Definition: HAP_mem.h:186
static int HAP_malloc(uint32 bytes, void **pptr)
Definition: HAP_mem.h:137
HAP_mem_stats_request
Enum for reqID for HAP_mem_get_heap_info()
Definition: HAP_mem.h:178
int HAP_mmap_put(int fd)
int HAP_munmap2(void *addr, size_t len)
uint64 seg_used
Definition: HAP_mem.h:171
Statistics of user heap memory.
Definition: HAP_mem.h:165
int HAP_munmap(void *addr, int len)
uint64 min_grow_bytes
Definition: HAP_mem.h:172
int HAP_mmap_get(int fd, void **vaddr, uint64 *paddr)
int HAP_mem_set_grow_size(uint64 min, uint64 max)
int HAP_mem_get_stats(struct HAP_mem_stats *stats)
int HAP_apps_mem_release(int fd)
int HAP_mem_set_heap_thresholds(unsigned int low_largest_block_size, unsigned int high_largest_block_size)
int HAP_apps_mem_request(size_t len, uint32_t flags, int *fd, uint64_t *dsp_va)
uint64 bytes_used
Definition: HAP_mem.h:169
void * HAP_mmap2(void *addr, size_t len, int prot, int flags, int fd, long offset)
uint64 HAP_mem_available_stack(void)
int HAP_mem_get_heap_info(HAP_mem_heap_info_t *payload)
void * HAP_mmap(void *addr, int len, int prot, int flags, int fd, long offset)