2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19 File name : _pbMem.cpp
20 System name : 05 Integration Platform
21 Subsystem name : System common functions
23 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29 #include <vehicle_service/positioning_base_library.h>
31 #include "WPF_STD_private.h"
32 #include "_pbInternalProc.h"
35 Constants and data type definitions
36 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
37 #define MAX_AREA_NAME_LEN 32
38 #define MAX_FILENAME_LEN 32
39 #define _CWORD64__MEM_MUTEX_NAME __TEXT("POS_BASE_MEM_MUTEX")
40 #define MAX_ROMFILENAME_LEN (32-4) /* To the name appended with "_rom" at the time of registration */
41 #define PHYADDR_MAX 0x9FFFFFFF /* Physical address of the boundary divided by 256 */
42 #define ROM_DATA_SIZE 0x00400000 /* Size of the virtual ROM data area(4MB) */
43 #define ALLOC_SIZE 0x00200000 /* 2MB (Minimum VirtualAlloc allocation of shared memory, */
44 /* which is less than 2MB, is not mapped to shared memory) */
45 #define OFFSET_SIZE 0x00001000 /* 4KB (VirtualCopy Addressing Units) */
47 /* Memory map information */
48 typedef struct TagMemMapItem {
49 HANDLE h_heap; /* Handle of heap. */
50 struct TagMemMapItem* p_next; /* Pointers to the next Chain memory map table */
51 struct TagMemMapItem* p_prev; /* Pointers to the previous Chain memory map table */
53 TCHAR name[MAX_AREA_NAME_LEN]; /* Name of shared data area(Not used when permit is processed) */
54 HANDLE h_shared_mem; /* Shared memory handle */
57 /* Memory map information management table */
59 HANDLE h_heap; /* Heap handle of the invoking table */
60 MEMMAP_ITEM* p_head; /* Pointer to the first memory map information */
61 MEMMAP_ITEM* p_tail; /* Pointer to the terminating memory map information */
62 DWORD num_of_items; /* Chain memory map data */
63 HANDLE h_mutex; /* _CWORD64__MEM_MUTEX Exclusive Mutex handles */
71 /* LINK ROM data top address/size storage ROM data */
73 u_int32 *link_rom_addr; /* ROM data start address */
74 u_int32 link_size; /* ROM data size */
78 Internal function prototype declaration
79 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
80 static void UnlinkFromMemMapList(MEMMAP_ITEM* p_item);
81 static void LinkToMemMapList(MEMMAP_ITEM* p_item);
82 static MEMMAP_ITEM* FindMemMapItemByName(TCHAR* name);
86 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
87 MEMMAP_LIST* g_p_mem_map_list;
91 * Memory API initialization
95 * @return RET_API RET_NORMAL Normal completion<br>
99 RET_API MemoryInit(void) {
100 RET_API ret_api = RET_NORMAL;
101 TCHAR name[] = _CWORD64__MEM_MUTEX_NAME;
103 // LCOV_EXCL_BR_START 5: standard lib error
104 g_p_mem_map_list = reinterpret_cast<MEMMAP_LIST *>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
106 if (g_p_mem_map_list == NULL) { // LCOV_EXCL_BR_LINE 5: standard lib error
107 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
108 ret_api = RET_ERROR; // LCOV_EXCL_LINE 5: standard lib error
110 /* Initialization of memory map information management table */
111 g_p_mem_map_list->h_heap = NULL;
112 g_p_mem_map_list->p_head = NULL;
113 g_p_mem_map_list->p_tail = NULL;
114 g_p_mem_map_list->num_of_items = 0;
117 g_p_mem_map_list->h_mutex = _pb_CreateMutex(NULL, TRUE, name); // LCOV_EXCL_BR_LINE 200: no branch
118 if (g_p_mem_map_list->h_mutex == NULL) { // LCOV_EXCL_BR_LINE 200: can not be NULL
119 // LCOV_EXCL_START 200:dead code
120 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
121 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateMutex ERROR [name:%s]", name);
122 _pb_Exit(); /* System recovery processing(Exception execution) */
130 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
131 * MODULE : MemoryTerm
132 * ABSTRACT : Memory API termination processing
133 * NOTE : This function frees each allocated object.
134 * : This function must be called only once by DllMain() at process termination.
136 * RETURN : Return RET_NORMAL
137 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
139 MemoryTerm(void) { // LCOV_EXCL_START 8:dead code
140 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
141 RET_API ret_api = RET_NORMAL;
143 if (g_p_mem_map_list == NULL) {
147 PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);
149 while (g_p_mem_map_list->num_of_items > 0) {
150 MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
151 if (g_p_mem_map_list->num_of_items == 1) {
152 /* Delete last one of memory map list */
153 g_p_mem_map_list->p_head = NULL;
154 g_p_mem_map_list->p_tail = NULL;
155 g_p_mem_map_list->num_of_items = 0;
157 /* Deletes the beginning of the memory map list, with the next at the beginning. */
158 g_p_mem_map_list->p_head = g_p_mem_map_list->p_head->p_next;
159 g_p_mem_map_list->p_head->p_prev = NULL;
160 g_p_mem_map_list->num_of_items--;
163 /* Releases the real memory specified in the memory map list. */
164 if (p_item != NULL) {
165 PbProcessHeapFree(0, p_item);
171 PbMutexUnlock(g_p_mem_map_list->h_mutex);
174 PbDeleteMutex(g_p_mem_map_list->h_mutex);
176 /* Free MEMMAP_LIST structure */
177 PbProcessHeapFree(0, g_p_mem_map_list);
178 g_p_mem_map_list = NULL;
187 * Allocate Process Heap
189 * Allocates a memory block from the process heap
191 * @param[in] DWORD dw_flags Heap allocation scheme
192 * @param[in] SIZE_T dw_bytes Number of bytes to allocate
194 * @return LPVOID Except NULL Pointer to the allocated memory block
195 * NULL Assignment Failed
197 LPVOID PbProcessHeapAlloc(DWORD dw_flags, SIZE_T dw_bytes) {
198 LPVOID pv_ret = NULL;
200 if ((dw_flags & HEAP_ZERO_MEMORY) == 0) { // LCOV_EXCL_BR_LINE 200: dw_flags cannot have bit HEAP_ZERO_MEMORY
201 /* Zero initialization not specified */
202 pv_ret = malloc(dw_bytes);
204 /* Zero initialization specified */
205 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
206 pv_ret = calloc(dw_bytes, sizeof(char)); // LCOV_EXCL_LINE 200: dw_flags cannot have bit HEAP_ZERO_MEMORY
212 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
213 * MODULE : PrivateHeapAlloc
214 * ABSTRACT : Allocate a block of memory from the private heap
215 * NOTE : Because there is no private-heap notion in PosixBasedOS001,
216 * Allocate from the process-heap using ProcessHeapAlloc
217 * ARGUMENT : DWORD dw_flags Controlling Heap Allocation Methods
218 * : SIZE_T dw_bytes Number of bytes to allocate
219 * RETURN : LPVOID Except NULL Pointer to the allocated memory block
220 * : NULL Assignment Failed
221 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
223 PrivateHeapAlloc(DWORD dw_flags, SIZE_T dw_bytes) { // LCOV_EXCL_START 8:dead code
224 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
225 return PbProcessHeapAlloc(dw_flags, dw_bytes);
233 * Frees memory blocks allocated from the process heap
235 * @param[in] DWORD dw_flags Heap free method(Unused)
236 * @param[in] LPVOID lp_mem Pointer to the memory to be freed
238 * @return BOOL Non-zero Normal completion
241 BOOL PbProcessHeapFree(DWORD dw_flags, LPVOID lp_mem) {
247 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
248 * MODULE : PrivateHeapFree
249 * ABSTRACT : Free memory blocks allocated from private heap
250 * NOTE : Because there is no private-heap notion in PosixBasedOS001,
251 * Open using ProcessHeapFree
252 * ARGUMENT : DWORD dw_flags Heap release option(Not used by PosixBasedOS001)
253 * : LPVOID lp_mem Pointer to the memory to be freed
254 * RETURN : BOOL Non-zero Normal
256 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
258 PrivateHeapFree(DWORD dw_flags, LPVOID lp_mem) { // LCOV_EXCL_START 8:dead code
259 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
260 return PbProcessHeapFree(dw_flags, lp_mem);
264 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
266 * ABSTRACT : Acquire access privilege to non-managed memory block of invoking process
267 * NOTE : To the data of the unmanaged memory block of invoking process
268 * : Allocate to accessible area of invoking process
269 * ARGUMENT : u_int32 mem_adr Start address of the data area to which access privileges are granted
270 * : u_int32 size Size of the data area to be granted access privileges
271 * : int32 perm PERM_NONCACHE(Cache invalidation), PERM_CACHE(Cache enabled)
272 * : void** ptr Returns the start address of the actual data area that can be accessed
273 * RETURN : RET_API RET_NORMAL Normal completion
275 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
276 RET_API MemPermit(u_int32 mem_adr, u_int32 size, int32 perm, void** ptr) { // LCOV_EXCL_START 8:dead code
277 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
282 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
283 * MODULE : MemProtect
284 * ABSTRACT : Revoking access privileges to invoking process unmanaged memory blocks
285 * NOTE : Free unmanaged memory block allocated to invoking process area
286 * ARGUMENT : u_int32 mem_adr Start address of the data area from which the access privilege is to be revoked
287 * : u_int32 size Size of the data area for which access privileges are to be revoked
288 * RETURN : RET_API RET_NORMAL Access privilege revocation successful
289 * : RET_ERROR Failed to revoke access privilege
290 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
291 RET_API MemProtect(u_int32 mem_adr, u_int32 size) { // LCOV_EXCL_START 8:dead code
292 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
301 * @param[in] char* area_name Pointer to shared data area name string
302 * @param[in] u_int32 size Size of the data portion
303 * @param[out] void** mem_ptr Pointer to the start address of the shared data area
307 * RET_ERROR Abnormality
309 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
310 RET_API _pb_CreateShareData(char* area_name, u_int32 size, void** mem_ptr) // NOLINT(readability/nolint) WPF_SYSAPI.h
312 RET_API _pb_CreateShareData(TCHAR* area_name, u_int32 size, void** mem_ptr) // NOLINT(readability/nolint) WPF_SYSAPI.h
313 #endif // _CWORD64_API_DOES_NOT_USE_UNICODE
315 RET_API ret_api = RET_NORMAL;
316 TCHAR *p_area_name = NULL;
317 TCHAR name[MAX_AREA_NAME_LEN] = {0};
319 _CWORD64_SHMHDR *p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(MAP_FAILED);
320 MEMMAP_ITEM *p_item = NULL;
322 TCHAR unicode_area_name[MAX_AREA_NAME_LEN] = {0};
325 if (mem_ptr == NULL) {
326 ret_api = RET_ERROR; /* Parameter error */
327 } else if (area_name == NULL) {
328 ret_api = RET_ERROR; /* Parameter error */
330 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
332 if (area_name[0] == '\0') {
335 /* Shared memory name character limit processing */
336 if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
339 mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
340 p_area_name = unicode_area_name;
344 p_area_name = area_name;
345 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
350 p_area_name = area_name;
351 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
357 if (ret_api == RET_NORMAL) {
358 if ((p_area_name[0] == __TEXT('\0')) || (size == 0)) {
359 ret_api = RET_ERROR; /* Parameter error */
363 if (ret_api == RET_NORMAL) {
364 _tcscpy(name, p_area_name);
367 PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE); // LCOV_EXCL_BR_LINE 200: no branch
369 p_item = FindMemMapItemByName(name); /* Search memory map object by area name */
370 if (p_item != NULL) /* When there is already a generated name */ {
372 ret_api = RET_ERROR; /* Return in error because it has been generated */
374 /* Allocate MEMMAP_ITEM structure from heap */
375 // LCOV_EXCL_BR_START 5: standard lib error
376 p_item = reinterpret_cast<MEMMAP_ITEM *>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
378 if (p_item == NULL) { // LCOV_EXCL_BR_LINE 5: standard lib error
379 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
380 *mem_ptr = NULL; // LCOV_EXCL_LINE 5: standard lib error
381 ret_api = RET_ERROR; /* Failed to allocate */ // LCOV_EXCL_LINE 5: standard lib error
383 p_item->h_heap = NULL;
384 p_item->p_next = NULL;
385 p_item->p_prev = NULL;
387 p_item->h_shared_mem = NULL;
388 LinkToMemMapList(p_item); /* Add to end of memory map list */ // LCOV_EXCL_BR_LINE 200: no branch
390 /* Allocate shared memory */
391 h_shm = CreateSharedMemory(name, size + sizeof(_CWORD64_SHMHDR)); // LCOV_EXCL_BR_LINE 200: can not be null
392 if (h_shm == NULL) { // LCOV_EXCL_BR_LINE 200: can not be null
393 // LCOV_EXCL_START 200: can not be null
394 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
395 /* Remove the target memory-mapped object from the memory-mapped list */
396 UnlinkFromMemMapList(p_item);
397 PbProcessHeapFree(0, p_item);
403 p_item->h_shared_mem = h_shm;
404 /* Get Accessible Address */
405 // LCOV_EXCL_BR_START 200: can not be null
406 p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(GetSharedMemoryPtr(p_item->h_shared_mem));
408 if (p_hdr == NULL) { // LCOV_EXCL_BR_LINE 200: can not be null
409 // LCOV_EXCL_START 200: can not be null
410 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
411 /* Delete allocated shared memory */
412 CloseSharedMemory(h_shm);
413 DeleteSharedMemory(name);
414 /* Remove the target memory-mapped object from the memory-mapped list */
415 UnlinkFromMemMapList(p_item);
416 PbProcessHeapFree(0, p_item);
422 p_hdr->mem_size = size;
423 *mem_ptr = reinterpret_cast<void*>(p_hdr + 1); /* Start at the address following the header */
424 _tcscpy(p_item->name, name); /* Name registration in the table */
431 PbMutexUnlock(g_p_mem_map_list->h_mutex); // LCOV_EXCL_BR_LINE 200: no branch
433 /* When an error occurs during parameter check */
434 if (mem_ptr != NULL) {
446 * @param[in] char* area_name Pointer to shared data area name string
447 * @param[out] void** mem_ptr Pointer to the start address of the shared data area
448 * @param[out] u_int32* size Size of the data portion
452 * RET_ERROR Abnormality
454 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
455 RET_API _pb_LinkShareData(char* area_name, void** mem_ptr, u_int32* size) // NOLINT(readability/nolint) WPF_SYSAPI.h
457 RET_API _pb_LinkShareData(TCHAR* area_name, void** mem_ptr, u_int32* size) // NOLINT(readability/nolint) WPF_SYSAPI.h
458 #endif // _CWORD64_API_DOES_NOT_USE_UNICODE
460 RET_API ret_api = RET_NORMAL;
461 TCHAR *p_area_name = NULL;
462 TCHAR name[MAX_AREA_NAME_LEN] = {0};
463 _CWORD64_SHMHDR *p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(MAP_FAILED);
464 MEMMAP_ITEM *p_item = NULL;
466 HANDLE h_shm_temp = NULL;
469 TCHAR unicode_area_name[MAX_AREA_NAME_LEN] = {0};
472 if (mem_ptr == NULL) {
473 ret_api = RET_ERROR; /* Parameter error */
474 } else if ((area_name == NULL) || (size == NULL)) {
475 ret_api = RET_ERROR; /* Parameter error */
477 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
479 if (area_name[0] == '\0') {
482 /* Shared memory name character limit processing */
483 if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
486 mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
487 p_area_name = unicode_area_name;
491 p_area_name = area_name;
492 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
497 p_area_name = area_name;
498 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
504 if (ret_api == RET_NORMAL) {
505 if (p_area_name[0] == __TEXT('\0')) {
506 ret_api = RET_ERROR; /* Parameter error */
510 if (ret_api == RET_NORMAL) {
512 _tcscpy(name, p_area_name);
513 mem_size = (u_int32) * size;
516 PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE); // LCOV_EXCL_BR_LINE 200: no branch
518 p_item = FindMemMapItemByName(name); /* Search memory map object by area name */
519 if (p_item != NULL) {
520 /* When there is already a generated name */
521 h_shm = p_item->h_shared_mem;
522 // LCOV_EXCL_BR_START 200: can not be null
523 p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(h_shm)); /* Get Accessible Address */
525 if (p_hdr == NULL) { // LCOV_EXCL_BR_LINE 200: can not be null
526 // LCOV_EXCL_START 200: can not be null
527 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
532 /* Start at the address following the header */
533 *mem_ptr = reinterpret_cast<void *>(p_hdr + 1);
534 *size = static_cast<u_int32>(p_hdr->mem_size);
537 /* When no memory map object has been created */
538 /* Allocate MEMMAP_ITEM structure from heap */
539 // LCOV_EXCL_BR_START 5: standard lib error
540 p_item = reinterpret_cast<MEMMAP_ITEM*>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
542 if (p_item == NULL) { // LCOV_EXCL_BR_LINE 5: standard lib error
543 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
544 *mem_ptr = NULL; // LCOV_EXCL_LINE 5: standard lib error
545 ret_api = RET_ERROR; /* Failed to allocate */ // LCOV_EXCL_LINE 5: standard lib error
547 p_item->h_heap = NULL;
548 p_item->p_next = NULL;
549 p_item->p_prev = NULL;
551 _tcscpy(p_item->name, name);
552 p_item->h_shared_mem = NULL;
553 LinkToMemMapList(p_item); /* Add to end of memory map list */ // LCOV_EXCL_BR_LINE 200: no branch
555 ret_api = RET_ERROR; /* Process result initialization */
556 /* Maps the shared data area to physical memory and returns its information pointer
557 * (Check if not found by table lookup, but other processes are already reserved) */
558 h_shm_temp = OpenSharedMemory(p_item->name, sizeof(_CWORD64_SHMHDR)); // LCOV_EXCL_BR_LINE 200: no branch
559 if (h_shm_temp != NULL) {
560 /* Get Accessible Address */
561 p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(h_shm_temp)); // LCOV_EXCL_BR_LINE 200: can not be NULL // NOLINT(whitespace/line_length)
562 if (p_hdr != NULL) { // LCOV_EXCL_BR_LINE 200: can not be NULL
563 mem_size = p_hdr->mem_size;
564 ret_api = RET_NORMAL;
566 CloseSharedMemory(h_shm_temp); // LCOV_EXCL_BR_LINE 200: no branch
569 if (ret_api == RET_NORMAL) {
570 ret_api = RET_ERROR; /* Process result initialization */
571 /* Maps the shared data area to physical memory and returns its information pointer */
572 h_shm = OpenSharedMemory(p_item->name, mem_size); // LCOV_EXCL_BR_LINE 200: no branch
574 p_item->h_shared_mem = h_shm;
575 /* Get Accessible Address */
576 p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(p_item->h_shared_mem));
578 *mem_ptr = reinterpret_cast<void*>(p_hdr + 1); /* Start at the address following the header */
579 *size = static_cast<u_int32>(mem_size);
580 ret_api = RET_NORMAL;
585 if (ret_api != RET_NORMAL) {
586 UnlinkFromMemMapList(p_item); /* Remove the target memory-mapped object from the memory-mapped list */
588 PbProcessHeapFree(0, p_item); // LCOV_EXCL_BR_LINE 200: no branch
597 PbMutexUnlock(g_p_mem_map_list->h_mutex); // LCOV_EXCL_BR_LINE 200: no branch
599 /* When an error occurs during parameter check */
600 if (mem_ptr != NULL) {
608 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
609 * MODULE : PbDeleteShareData
610 * ABSTRACT : Shared data area deletion processing
611 * NOTE : Deletes (releases) the shared memory area allocated under the name of the shared data area.
612 * ARGUMENT : char* area_name Pointer to shared data area name string
613 * RETURN : RET_API RET_NORMAL Normal
614 * : RET_ERROR The specified shared data does not exist
615 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
617 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
618 PbDeleteShareData(char* area_name) // LCOV_EXCL_START 8:dead code
620 PbDeleteShareData(TCHAR* area_name)
621 #endif // _CWORD64_API_DOES_NOT_USE_UNICODE
623 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
624 RET_API ret_api = RET_NORMAL;
625 TCHAR *p_area_name = NULL;
626 TCHAR name[MAX_AREA_NAME_LEN] = {0};
627 MEMMAP_ITEM *p_item = NULL;
629 TCHAR unicode_area_name[MAX_AREA_NAME_LEN] = {0};
632 /* Parameter check */
633 if (area_name == NULL) /* If the name of the shared area is NULL */ {
636 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
638 if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
641 mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
642 p_area_name = unicode_area_name;
645 p_area_name = area_name;
646 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
651 p_area_name = area_name;
652 if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
656 if (ret_api == RET_NORMAL) {
657 if (p_area_name[0] == __TEXT('\0')) {
663 if (ret_api == RET_NORMAL) {
664 /* Shared memory is allocated with the name of the shared area, or the memory map information management table is searched. */
665 _tcscpy(name, p_area_name);
668 PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);
670 p_item = FindMemMapItemByName(name); /* Search memory map object by area name */
671 if (p_item == NULL) /* If the area name is not in the memory-map information management TBL */ {
672 /* If the area name is not in the memory map information management TBL, it has not been created or deleted. */
674 PbMutexUnlock(g_p_mem_map_list->h_mutex);
677 /* If the area name is in the memory map information management TBL */
678 /* Removes the memory map information from the Chain of the memory map information management table. */
679 UnlinkFromMemMapList(p_item);
681 /* Releases the Mutex of the memory map information management table and releases the shared memory. */
683 PbMutexUnlock(g_p_mem_map_list->h_mutex);
685 if (p_item->h_shared_mem != NULL) {
686 CloseSharedMemory(p_item->h_shared_mem);
687 p_item->h_shared_mem = NULL;
690 /* Frees memory-map information from the heap */
691 PbProcessHeapFree(0, p_item);
693 /* Deleting Shared Memory Objects */
694 /*************************************************************/
695 /* Note: Be sure to delete it, so Do not use DeleteShareData */
696 /* if you want to link elsewhere. */
697 /*************************************************************/
698 DeleteSharedMemory(name);
706 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
707 * MODULE : LinkRomData
708 * ABSTRACT : ROM data link
709 * NOTE : Links data located in ROM.
710 * : Specifies the name of the file in which the data is to be stored, and points to the start address of the data.
711 * : Get pointer and data size.
712 * ARGUMENT : char *filename Pointer to the string of the name of the ROM data storage file
713 * : void **mem_ptr Pointer to the start address of the ROM data storage file
714 * : u_int32 *size Pointer to the size of the data portion
715 * RETURN : RET_API RET_NORMAL Normal status
716 * : RET_ERROR Specified ROM data storage file does not exist
717 * : File name character string width error
718 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
719 #ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
720 RET_API LinkRomData(char* filename, void** mem_ptr, u_int32* size) // LCOV_EXCL_START 8:dead code
722 RET_API LinkRomData(TCHAR* filename, void** mem_ptr, u_int32* size)
723 #endif // _CWORD64_API_DOES_NOT_USE_UNICODE
725 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
726 return RET_NORMAL; /* Coverity CID: 18772 compliant */
730 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
731 * MODULE : PbAccessPhysicalMem
732 * ABSTRACT : Access to Physical Memory Area Allocation Data
733 * NOTE : Access data allocated in the physical memory area.
734 * : The physical memory area is mapped to the shared memory area and mapped.
735 * : The start address is returned.
736 * ARGUMENT : u_int32 addr Start address of the physical memory area
737 * : void **mem_ptr Pointer to the start address of the mapped shared area
738 * : u_int32 size Size of the data
739 * : u_int32 mode Access mode
740 * : ACCESS_MODE_READONLY :Read Only
741 * : ACCESS_MODE_READWRITE:Reading and Writing
742 * RETURN : RET_API RET_NORMAL Normal status
743 * : RET_ERRPARAM Parameter error
744 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
746 PbAccessPhysicalMem(u_int32 addr, void **mem_ptr, u_int32 size, u_int32 mode) { // LCOV_EXCL_START 8:dead code
747 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
748 return RET_NORMAL; /* Coverity CID: 18767 compliant */
752 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
753 * MODULE : PbFreePhysicalMem
754 * ABSTRACT : Access release processing to the physical memory area allocation data
755 * NOTE : Releases access to data allocated in a physical memory area
756 * : Releases the shared memory area Allocate by AccessPhysicalMem.
757 * ARGUMENT : u_int32 addr Start address of the physical memory area to be released
758 * : void *mem_ptr Pointer to the start address of the mapped shared area
759 * : u_int32 size Data size to be released
760 * RETURN : RET_API RET_NORMAL Normal status
761 * : RET_ERRPARAM Parameter error
762 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
764 PbFreePhysicalMem(u_int32 addr, void *mem_ptr, u_int32 size) { // LCOV_EXCL_START 8:dead code
765 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
766 return RET_NORMAL; /* Coverity CID: 18766 compliant */
770 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
771 * MODULE : FindMemMapItemByName
772 * ABSTRACT : Memory map information retrieval processing
773 * NOTE : Retrieves the memory map information by the specified shared data area name.
774 * ARGUMENT : TCHAR* name Pointer to shared data area name character string
775 * RETURN : MEMMAP_ITEM* !NULL Pointer to memory map information
776 * : NULL Memory map information does not exist
777 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
779 FindMemMapItemByName(TCHAR* name) {
780 MEMMAP_ITEM* ret = NULL; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
781 if (g_p_mem_map_list == NULL) { // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
782 /* If the memory map information management table is not allocated, */
784 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
785 } else if (g_p_mem_map_list->num_of_items == 0) {
786 /* If no memory map information is allocated, */
788 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
790 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
791 MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
792 /* Gets the pointer of the memory map Chain at the beginning of the file. */
793 /* Loops until there is no memory map Chain */
794 while (p_item != NULL) {
795 if (_tcscmp(p_item->name, name) == 0) {
796 /* If the name of the memory map information matches the name of the argument */
797 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
798 /* Returns a pointer to the memory map information */
800 break; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
802 p_item = p_item->p_next; /* Retrieves the pointers of the memory map data Chain next time. */
806 return(ret); /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
809 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
810 * MODULE : LinkToMemMapList
811 * NOTE : Adding a Memory Map Object to the Memory Map List
812 * ARGUMENT : MEMMAP_ITEM* p_item Specify a memory-mapped object
814 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
816 LinkToMemMapList(MEMMAP_ITEM* p_item) {
817 BOOL processing_complete = FALSE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
818 if (g_p_mem_map_list == NULL) { // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
819 // LCOV_EXCL_START 200: g_p_mem_map_list can not be NULL
820 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
821 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
825 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
826 if ((processing_complete == FALSE) && (g_p_mem_map_list->num_of_items == 0)) {
827 g_p_mem_map_list->p_head = p_item;
828 g_p_mem_map_list->p_tail = p_item;
829 g_p_mem_map_list->num_of_items = 1;
830 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
833 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
834 if (processing_complete == FALSE) {
835 g_p_mem_map_list->p_tail->p_next = p_item;
836 p_item->p_prev = g_p_mem_map_list->p_tail;
837 p_item->p_next = NULL;
838 g_p_mem_map_list->p_tail = p_item;
839 g_p_mem_map_list->num_of_items++;
844 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
845 * MODULE : UnlinkFromMemMapList
846 * ABSTRACT : Memory map information deletion processing
847 * NOTE : Memory map information specified by the pointer is stored in the memory map information management table.
848 * : From the Chain structures.The memory map information is not released.
849 * ARGUMENT : MEMMAP_ITEM* p_item Pointer to the memory map information to be deleted
851 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
853 UnlinkFromMemMapList(MEMMAP_ITEM* p_item) {
854 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
855 BOOL processing_complete = FALSE;
856 /* Parameter check */
857 if (g_p_mem_map_list == NULL) { // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
858 /* If the memory map information management table is not allocated, */
860 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
861 } else if (p_item == NULL) { // LCOV_EXCL_BR_LINE 200: p_item can not be NULL
862 /* If a pointer to memory-mapped information is not specified, */
864 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
865 } else if (g_p_mem_map_list->num_of_items == 0) { // LCOV_EXCL_BR_LINE 200: num_of_items can not be 0
866 /* If no memory map information is allocated, */
868 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
870 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
871 /* Chain detachment process when there is only one memory map data item */
872 if (g_p_mem_map_list->num_of_items == 1) {
873 if (g_p_mem_map_list->p_head == p_item) {
874 /* If only one memory map is reserved */
875 /* For the top memory map information of the memo map information management table */
876 g_p_mem_map_list->p_head = NULL; /* Initializes the top memory map to NULL. */
877 g_p_mem_map_list->p_tail = NULL; /* NULL initialization of the termination memory map data */
878 g_p_mem_map_list->num_of_items = 0; /* Initializes the control memory map information count to zero. */
880 /* Specified memory map information pointer does not exist */
881 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
884 /* Memory-map-information-removal process at the top of the Chain */
885 if ((processing_complete == FALSE) && (p_item == g_p_mem_map_list->p_head)) {
886 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
887 /* If the specified memory map information is the first memory map information, */
888 /* The leading memory map information pointer is changed to the next Chain pointer. */
889 g_p_mem_map_list->p_head = g_p_mem_map_list->p_head->p_next;
890 /* Change the previous Chain source of the first memory map to NULL */
891 g_p_mem_map_list->p_head->p_prev = NULL;
892 g_p_mem_map_list->num_of_items--; /* Decrement the number of management memory map information */
893 p_item->p_next = NULL; /* Initialize the Chain destination of the removed memory map NULL. */
894 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
897 /* Memory-map data detachment process at the end of the Chain */
898 if ((processing_complete == FALSE) && (p_item == g_p_mem_map_list->p_tail)) {
899 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
900 /* If the pointed-to memory-map information is terminated, */
901 /* Change the terminating memory-map info pointer to the previous Chain source */
902 g_p_mem_map_list->p_tail = g_p_mem_map_list->p_tail->p_prev;
903 /* Change the Chain destination of the terminated memory map to NULL. */
904 g_p_mem_map_list->p_tail->p_next = NULL;
905 /* Decrement the number of management memory map information */
906 g_p_mem_map_list->num_of_items--;
907 /* The previous Chain source of the removed memory map data is NULL initialized. */
908 p_item->p_prev = NULL;
909 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
912 /* Checking the memory map info Chain for errors */
913 if ((processing_complete == FALSE) &&
914 (g_p_mem_map_list->num_of_items <= 2)) {
915 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
916 /* No more than two memory maps are possible except at the beginning and end. */
917 processing_complete = TRUE; /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
920 /* Departure process other than the start and end of the memory map data Chain */
921 if (processing_complete == FALSE) {
922 /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
923 p_item->p_prev->p_next = p_item->p_next; /* Set the next Chain destination of the previous memory map to the next one */
924 p_item->p_next->p_prev = p_item->p_prev; /* Previous Chain of one memory map before previous */
925 g_p_mem_map_list->num_of_items--; /* Decrement the number of management memory map information */
926 p_item->p_prev = NULL; /* The previous Chain source of the removed memory map data is NULL initialized. */
927 p_item->p_next = NULL; /* Initialize the Chain destination of the removed memory map NULL. */
935 * Obtain dump information
937 * @param[out] p_buf Dump info
939 void _pb_GetDebugMemoryMngTbl(void* p_buf) { // NOLINT(readability/nolint) WPF_SYSAPI.h
940 static uint8_t buf[DEBUG_DUMP_MAX_SIZE];
941 static uint8_t buf_tmp[256];
945 memset(&buf[0], 0x00, sizeof(buf));
946 snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf), "Memory");
948 if (g_p_mem_map_list == NULL) { // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
949 // LCOV_EXCL_START 200: g_p_mem_map_list can not be NULL
950 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
951 strncat(reinterpret_cast<char *>(&buf[0]), "\n NULL", strlen("\n NULL"));
953 } else if (g_p_mem_map_list->num_of_items == 0) { // LCOV_EXCL_BR_LINE 200: num_of_items can not be 0
954 // LCOV_EXCL_START 200: num_of_items can not be 0
955 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
956 strncat(reinterpret_cast<char *>(&buf[0]), "\n num_of_items:0", strlen("\n num_of_items:0"));
959 memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
960 snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp), // LCOV_EXCL_BR_LINE 5: c lib error case
961 "\n h_heap:%p, p_head:%s, p_tail:%s, num_of_items:%lu, h_mutex:%p",
962 g_p_mem_map_list->h_heap,
963 ((g_p_mem_map_list->p_head == NULL)?"NULL":"NOT NULL"),
964 ((g_p_mem_map_list->p_tail == NULL)?"NULL":"NOT NULL"),
965 g_p_mem_map_list->num_of_items,
966 g_p_mem_map_list->h_mutex);
967 strncat(reinterpret_cast<char *>(&buf[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
968 strlen(reinterpret_cast<char *>(&buf_tmp[0])));
969 MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
970 while (p_item != NULL) {
971 memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
972 snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
973 "\n [%02d]h_heap:%10p, p_next:%s, p_prev:%s, name:%40s, hShrMem:%10p, adr:%lu",
976 ((p_item->p_next == NULL)?"NULL ":"NOT NULL"),
977 ((p_item->p_prev == NULL)?"NULL ":"NOT NULL"),
979 p_item->h_shared_mem,
982 strncat(reinterpret_cast<char *>(&buf[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
983 strlen(reinterpret_cast<char *>(&buf_tmp[0])));
984 p_item = p_item->p_next;
987 memcpy(p_buf, &buf[0], sizeof(buf));