summaryrefslogtreecommitdiffstats
path: root/positioning_base_library/library/src/_pbMem.cpp
blob: 4028ae32b0082da55a22c2b50ee4ddcd66865f1b (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 File name      : _pbMem.cpp
 System name    : 05 Integration Platform
 Subsystem name : System common functions
 Title          : System API
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/

#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <vehicle_service/positioning_base_library.h>
#include "tchar.h"
#include "WPF_STD_private.h"
#include "_pbInternalProc.h"

/*
 Constants and data type definitions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define MAX_AREA_NAME_LEN        32
#define MAX_FILENAME_LEN        32
#define _CWORD64__MEM_MUTEX_NAME        __TEXT("POS_BASE_MEM_MUTEX")
#define MAX_ROMFILENAME_LEN        (32-4)        /* To the name appended with "_rom" at the time of registration */
#define PHYADDR_MAX                0x9FFFFFFF    /* Physical address of the boundary divided by 256 */
#define ROM_DATA_SIZE            0x00400000    /* Size of the virtual ROM data area(4MB) */
#define ALLOC_SIZE                0x00200000    /* 2MB (Minimum VirtualAlloc allocation of shared memory, */
/*      which is less than 2MB, is not mapped to shared memory) */
#define OFFSET_SIZE                0x00001000    /* 4KB (VirtualCopy Addressing Units) */

  /* Memory map information */
typedef struct TagMemMapItem {
    HANDLE                    h_heap;             /* Handle of heap.           */
    struct TagMemMapItem*     p_next;             /* Pointers to the next Chain memory map table    */
    struct TagMemMapItem*     p_prev;             /* Pointers to the previous Chain memory map table    */
    DWORD                     address;
    TCHAR                     name[MAX_AREA_NAME_LEN];    /* Name of shared data area(Not used when permit is processed)        */
    HANDLE                    h_shared_mem;                    /* Shared memory handle           */
} MEMMAP_ITEM;

/* Memory map information management table */
typedef struct {
    HANDLE                    h_heap;            /* Heap handle of the invoking table                */
    MEMMAP_ITEM*              p_head;            /* Pointer to the first memory map information            */
    MEMMAP_ITEM*              p_tail;            /* Pointer to the terminating memory map information            */
    DWORD                     num_of_items;        /* Chain memory map data                */
    HANDLE                    h_mutex;            /* _CWORD64__MEM_MUTEX Exclusive Mutex handles    */
} MEMMAP_LIST;

typedef struct {
    DWORD                    mem_size;
    DWORD                    reserv[3];
} _CWORD64_SHMHDR;

/* LINK ROM data top address/size storage ROM data */
typedef struct {
    u_int32                    *link_rom_addr;    /* ROM data start address                        */
    u_int32                    link_size;        /* ROM data size                                */
} LINK_ROM;

/*
 Internal function prototype declaration
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void            UnlinkFromMemMapList(MEMMAP_ITEM* p_item);
static void            LinkToMemMapList(MEMMAP_ITEM* p_item);
static MEMMAP_ITEM*        FindMemMapItemByName(TCHAR* name);

/*
 Global variable
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
MEMMAP_LIST*    g_p_mem_map_list;

/**
 * @brief
 *   Memory API initialization
 *
 * @param[in]  none
 *
 * @return RET_API    RET_NORMAL Normal completion<br>
 *                        RET_ERROR     ABENDs
 */

RET_API MemoryInit(void) {
    RET_API        ret_api = RET_NORMAL;
    TCHAR        name[] = _CWORD64__MEM_MUTEX_NAME;

    // LCOV_EXCL_BR_START 5: standard lib error
    g_p_mem_map_list = reinterpret_cast<MEMMAP_LIST *>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
    // LCOV_EXCL_BR_STOP
    if (g_p_mem_map_list == NULL) {  // LCOV_EXCL_BR_LINE 5: standard lib error
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        ret_api = RET_ERROR;  // LCOV_EXCL_LINE 5: standard lib error
    } else {
        /* Initialization of memory map information management table */
        g_p_mem_map_list->h_heap = NULL;
        g_p_mem_map_list->p_head = NULL;
        g_p_mem_map_list->p_tail = NULL;
        g_p_mem_map_list->num_of_items = 0;

        /* Create Mutex */
        g_p_mem_map_list->h_mutex = _pb_CreateMutex(NULL, TRUE, name);  // LCOV_EXCL_BR_LINE 200: no branch
        if (g_p_mem_map_list->h_mutex == NULL) {  // LCOV_EXCL_BR_LINE 200: can not be NULL
            // LCOV_EXCL_START 200:dead code
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateMutex ERROR [name:%s]", name);
            _pb_Exit();    /* System recovery processing(Exception execution) */
            // LCOV_EXCL_STOP
        }
    }

    return ret_api;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : MemoryTerm
 * ABSTRACT  : Memory API termination processing
 * NOTE      : This function frees each allocated object.
 *           : This function must be called only once by DllMain() at process termination.
 * ARGUMENT  : None
 * RETURN    : Return RET_NORMAL
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
MemoryTerm(void) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    RET_API        ret_api = RET_NORMAL;

    if (g_p_mem_map_list == NULL) {
        ret_api = RET_ERROR;
    } else {
        /* Lock Mutex */
        PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);

        while (g_p_mem_map_list->num_of_items > 0) {
            MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
            if (g_p_mem_map_list->num_of_items == 1) {
                /* Delete last one of memory map list */
                g_p_mem_map_list->p_head = NULL;
                g_p_mem_map_list->p_tail = NULL;
                g_p_mem_map_list->num_of_items = 0;
            } else {
                /* Deletes the beginning of the memory map list, with the next at the beginning. */
                g_p_mem_map_list->p_head = g_p_mem_map_list->p_head->p_next;
                g_p_mem_map_list->p_head->p_prev = NULL;
                g_p_mem_map_list->num_of_items--;
            }

            /* Releases the real memory specified in the memory map list. */
            if (p_item != NULL) {
                PbProcessHeapFree(0, p_item);
                p_item = NULL;
            }
        }

        /* Release Mutex */
        PbMutexUnlock(g_p_mem_map_list->h_mutex);

        /* Delete Mutex */
        PbDeleteMutex(g_p_mem_map_list->h_mutex);

        /* Free MEMMAP_LIST structure */
        PbProcessHeapFree(0, g_p_mem_map_list);
        g_p_mem_map_list = NULL;
    }

    return ret_api;
}
// LCOV_EXCL_STOP

/**
 * @brief
 *    Allocate Process Heap
 *
 *   Allocates a memory block from the process heap
 *
 * @param[in]    DWORD    dw_flags    Heap allocation scheme
 * @param[in]    SIZE_T    dw_bytes    Number of bytes to allocate
 *
 * @return    LPVOID    Except NULL    Pointer to the allocated memory block
 *                        NULL        Assignment Failed
 */
LPVOID PbProcessHeapAlloc(DWORD dw_flags, SIZE_T dw_bytes) {
    LPVOID        pv_ret = NULL;

    if ((dw_flags & HEAP_ZERO_MEMORY) == 0) {  // LCOV_EXCL_BR_LINE 200: dw_flags cannot have bit HEAP_ZERO_MEMORY
        /* Zero initialization not specified */
        pv_ret = malloc(dw_bytes);
    } else {
        /* Zero initialization specified */
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        pv_ret = calloc(dw_bytes, sizeof(char));  // LCOV_EXCL_LINE 200: dw_flags cannot have bit HEAP_ZERO_MEMORY
    }

    return pv_ret;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PrivateHeapAlloc
 * ABSTRACT  : Allocate a block of memory from the private heap
 * NOTE      : Because there is no private-heap notion in PosixBasedOS001,
 *             Allocate from the process-heap using ProcessHeapAlloc
 * ARGUMENT  : DWORD    dw_flags        Controlling Heap Allocation Methods
 *           : SIZE_T    dw_bytes        Number of bytes to allocate
 * RETURN    : LPVOID    Except NULL    Pointer to the allocated memory block
 *           :             NULL        Assignment Failed
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
LPVOID
PrivateHeapAlloc(DWORD dw_flags, SIZE_T dw_bytes) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return PbProcessHeapAlloc(dw_flags, dw_bytes);
}
// LCOV_EXCL_STOP

/**
 * @brief
 *    Free Process Heap
 *
 *   Frees memory blocks allocated from the process heap
 *
 * @param[in]    DWORD    dw_flags    Heap free method(Unused)
 * @param[in]    LPVOID    lp_mem        Pointer to the memory to be freed
 *
 * @return    BOOL            Non-zero    Normal completion
 *                               0        ABENDs
 */
BOOL PbProcessHeapFree(DWORD dw_flags, LPVOID lp_mem) {
    free(lp_mem);

    return TRUE;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PrivateHeapFree
 * ABSTRACT  : Free memory blocks allocated from private heap
 * NOTE      : Because there is no private-heap notion in PosixBasedOS001,
 *             Open using ProcessHeapFree
 * ARGUMENT  : DWORD    dw_flags    Heap release option(Not used by PosixBasedOS001)
 *           : LPVOID    lp_mem    Pointer to the memory to be freed
 * RETURN    : BOOL        Non-zero    Normal
 *           :             0        Abnormality
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL
PrivateHeapFree(DWORD dw_flags, LPVOID lp_mem) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return PbProcessHeapFree(dw_flags, lp_mem);
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : MemPermit
 * ABSTRACT  : Acquire access privilege to non-managed memory block of invoking process
 * NOTE      : To the data of the unmanaged memory block of invoking process
 *           : Allocate to accessible area of invoking process
 * ARGUMENT  : u_int32    mem_adr    Start address of the data area to which access privileges are granted
 *           : u_int32    size    Size of the data area to be granted access privileges
 *           : int32    perm    PERM_NONCACHE(Cache invalidation), PERM_CACHE(Cache enabled)
 *           : void**    ptr        Returns the start address of the actual data area that can be accessed
 * RETURN    : RET_API    RET_NORMAL    Normal completion
 *           :             RET_ERROR    ABENDs
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API MemPermit(u_int32 mem_adr, u_int32 size, int32 perm, void** ptr) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return RET_NORMAL;
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : MemProtect
 * ABSTRACT  : Revoking access privileges to invoking process unmanaged memory blocks
 * NOTE      : Free unmanaged memory block allocated to invoking process area
 * ARGUMENT  : u_int32    mem_adr        Start address of the data area from which the access privilege is to be revoked
 *           : u_int32    size        Size of the data area for which access privileges are to be revoked
 * RETURN    : RET_API    RET_NORMAL    Access privilege revocation successful
 *           :             RET_ERROR    Failed to revoke access privilege
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API MemProtect(u_int32 mem_adr, u_int32 size) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return RET_NORMAL;
}
// LCOV_EXCL_STOP

/**
 * @brief
 *   Create Share Data
 *
 * @param[in]    char*    area_name    Pointer to shared data area name string
 * @param[in]    u_int32 size        Size of the data portion
 * @param[out] void**    mem_ptr    Pointer to the start address of the shared data area
 *
 * @return RET_API
 *              RET_NORMAL    Normal
 *              RET_ERROR        Abnormality
 */
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
RET_API _pb_CreateShareData(char* area_name, u_int32 size, void** mem_ptr)   // NOLINT(readability/nolint) WPF_SYSAPI.h
#else
RET_API _pb_CreateShareData(TCHAR* area_name, u_int32 size, void** mem_ptr)   // NOLINT(readability/nolint) WPF_SYSAPI.h
#endif  // _CWORD64_API_DOES_NOT_USE_UNICODE
{
    RET_API            ret_api = RET_NORMAL;
    TCHAR           *p_area_name = NULL;
    TCHAR            name[MAX_AREA_NAME_LEN] = {0};
    HANDLE            h_shm = NULL;
    _CWORD64_SHMHDR       *p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(MAP_FAILED);
    MEMMAP_ITEM       *p_item = NULL;
#ifdef UNDER_CE
    TCHAR            unicode_area_name[MAX_AREA_NAME_LEN] = {0};
#endif  // UNDER_CE

    if (mem_ptr == NULL) {
        ret_api = RET_ERROR;        /* Parameter error */
    } else if (area_name == NULL) {
        ret_api = RET_ERROR;        /* Parameter error */
    } else {
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
#ifdef UNDER_CE
        if (area_name[0] == '\0') {
            ret_api = RET_ERROR;
        } else {
            /* Shared memory name character limit processing */
            if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
                ret_api = RET_ERROR;
            } else {
                mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
                p_area_name = unicode_area_name;
            }
        }
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
    }

    if (ret_api == RET_NORMAL) {
        if ((p_area_name[0] == __TEXT('\0')) || (size == 0)) {
            ret_api = RET_ERROR;    /* Parameter error */
        }
    }

    if (ret_api == RET_NORMAL) {
        _tcscpy(name, p_area_name);

        /* Lock Mutex */
        PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);  // LCOV_EXCL_BR_LINE 200: no branch

        p_item = FindMemMapItemByName(name);    /* Search memory map object by area name */
        if (p_item != NULL)              /* When there is already a generated name */ {
            *mem_ptr = NULL;
            ret_api = RET_ERROR;    /* Return in error because it has been generated */
        } else {
            /* Allocate MEMMAP_ITEM structure from heap */
            // LCOV_EXCL_BR_START 5: standard lib error
            p_item = reinterpret_cast<MEMMAP_ITEM *>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
            // LCOV_EXCL_BR_STOP
            if (p_item == NULL) {  // LCOV_EXCL_BR_LINE 5: standard lib error
                AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
                *mem_ptr = NULL;  // LCOV_EXCL_LINE 5: standard lib error
                ret_api = RET_ERROR;    /* Failed to allocate */  // LCOV_EXCL_LINE 5: standard lib error
            } else {
                p_item->h_heap = NULL;
                p_item->p_next = NULL;
                p_item->p_prev = NULL;
                p_item->address = 0;
                p_item->h_shared_mem = NULL;
                LinkToMemMapList(p_item);    /* Add to end of memory map list */    // LCOV_EXCL_BR_LINE 200: no branch

                /* Allocate shared memory */
                h_shm = CreateSharedMemory(name, size + sizeof(_CWORD64_SHMHDR));  // LCOV_EXCL_BR_LINE 200: can not be null
                if (h_shm == NULL) {  // LCOV_EXCL_BR_LINE 200: can not be null
                    // LCOV_EXCL_START 200: can not be null
                    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
                    /* Remove the target memory-mapped object from the memory-mapped list */
                    UnlinkFromMemMapList(p_item);
                    PbProcessHeapFree(0, p_item);
                    p_item = NULL;
                    *mem_ptr = NULL;
                    ret_api = RET_ERROR;
                    // LCOV_EXCL_STOP
                } else {
                    p_item->h_shared_mem = h_shm;
                     /* Get Accessible Address */
                    // LCOV_EXCL_BR_START 200: can not be null
                    p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(GetSharedMemoryPtr(p_item->h_shared_mem));
                    // LCOV_EXCL_BR_STOP
                    if (p_hdr == NULL) {  // LCOV_EXCL_BR_LINE 200: can not be null
                        // LCOV_EXCL_START 200: can not be null
                        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
                        /* Delete allocated shared memory */
                        CloseSharedMemory(h_shm);
                        DeleteSharedMemory(name);
                        /* Remove the target memory-mapped object from the memory-mapped list */
                        UnlinkFromMemMapList(p_item);
                        PbProcessHeapFree(0, p_item);
                        p_item = NULL;
                        *mem_ptr = NULL;
                        ret_api = RET_ERROR;
                        // LCOV_EXCL_STOP
                    } else {
                        p_hdr->mem_size = size;
                        *mem_ptr = reinterpret_cast<void*>(p_hdr + 1);    /* Start at the address following the header */
                        _tcscpy(p_item->name, name);    /* Name registration in the table */
                    }
                }
            }
        }

        /* Release Mutex */
        PbMutexUnlock(g_p_mem_map_list->h_mutex);  // LCOV_EXCL_BR_LINE 200: no branch
    } else {
        /* When an error occurs during parameter check */
        if (mem_ptr != NULL) {
            *mem_ptr = NULL;
        }
    }

    return ret_api;
}

/**
 * @brief
 *   Link Share Data
 *
 * @param[in]    char*    area_name    Pointer to shared data area name string
 * @param[out] void**    mem_ptr    Pointer to the start address of the shared data area
 * @param[out] u_int32* size        Size of the data portion
 *
 * @return RET_API
 *              RET_NORMAL    Normal
 *              RET_ERROR        Abnormality
 */
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
RET_API _pb_LinkShareData(char* area_name, void** mem_ptr, u_int32* size)   // NOLINT(readability/nolint) WPF_SYSAPI.h
#else
RET_API _pb_LinkShareData(TCHAR* area_name, void** mem_ptr, u_int32* size)   // NOLINT(readability/nolint) WPF_SYSAPI.h
#endif   // _CWORD64_API_DOES_NOT_USE_UNICODE
{
    RET_API            ret_api = RET_NORMAL;
    TCHAR           *p_area_name = NULL;
    TCHAR            name[MAX_AREA_NAME_LEN] = {0};
    _CWORD64_SHMHDR       *p_hdr = reinterpret_cast<_CWORD64_SHMHDR *>(MAP_FAILED);
    MEMMAP_ITEM       *p_item = NULL;
    HANDLE            h_shm = NULL;
    HANDLE            h_shm_temp = NULL;
    DWORD            mem_size = 0;
#ifdef UNDER_CE
    TCHAR            unicode_area_name[MAX_AREA_NAME_LEN] = {0};
#endif

    if (mem_ptr == NULL) {
        ret_api = RET_ERROR;        /* Parameter error */
    } else if ((area_name == NULL) || (size == NULL)) {
        ret_api = RET_ERROR;        /* Parameter error */
    } else {
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
#ifdef UNDER_CE
        if (area_name[0] == '\0') {
            ret_api = RET_ERROR;
        } else {
            /* Shared memory name character limit processing */
            if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
                ret_api = RET_ERROR;
            } else {
                mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
                p_area_name = unicode_area_name;
            }
        }
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
    }

    if (ret_api == RET_NORMAL) {
        if (p_area_name[0] == __TEXT('\0')) {
            ret_api = RET_ERROR;    /* Parameter error */
        }
    }

    if (ret_api == RET_NORMAL) {
        *size = 0;
        _tcscpy(name, p_area_name);
        mem_size = (u_int32) * size;

        /* Lock Mutex */
        PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);  // LCOV_EXCL_BR_LINE 200: no branch

        p_item = FindMemMapItemByName(name);            /* Search memory map object by area name */
        if (p_item != NULL) {
            /* When there is already a generated name */
            h_shm = p_item->h_shared_mem;
            // LCOV_EXCL_BR_START 200: can not be null
            p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(h_shm));    /* Get Accessible Address */
            // LCOV_EXCL_BR_STOP
            if (p_hdr == NULL) {  // LCOV_EXCL_BR_LINE 200: can not be null
                // LCOV_EXCL_START 200: can not be null
                AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
                *mem_ptr = NULL;
                ret_api = RET_ERROR;
                // LCOV_EXCL_STOP
            } else {
                /* Start at the address following the header */
                *mem_ptr = reinterpret_cast<void *>(p_hdr + 1);
                *size = static_cast<u_int32>(p_hdr->mem_size);
            }
        } else {
            /* When no memory map object has been created */
            /* Allocate MEMMAP_ITEM structure from heap */
            // LCOV_EXCL_BR_START 5: standard lib error
            p_item = reinterpret_cast<MEMMAP_ITEM*>(PbProcessHeapAlloc(0, sizeof(MEMMAP_ITEM)));
            // LCOV_EXCL_BR_STOP
            if (p_item == NULL) {  // LCOV_EXCL_BR_LINE 5: standard lib error
                AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
                *mem_ptr = NULL;  // LCOV_EXCL_LINE 5: standard lib error
                ret_api = RET_ERROR;    /* Failed to allocate */  // LCOV_EXCL_LINE 5: standard lib error
            } else {
                p_item->h_heap = NULL;
                p_item->p_next = NULL;
                p_item->p_prev = NULL;
                p_item->address = 0;
                _tcscpy(p_item->name, name);
                p_item->h_shared_mem = NULL;
                LinkToMemMapList(p_item);    /* Add to end of memory map list */  // LCOV_EXCL_BR_LINE 200: no branch

                ret_api = RET_ERROR;        /* Process result initialization */
                /* Maps the shared data area to physical memory and returns its information pointer
                 * (Check if not found by table lookup, but other processes are already reserved) */
                h_shm_temp = OpenSharedMemory(p_item->name, sizeof(_CWORD64_SHMHDR));  // LCOV_EXCL_BR_LINE 200: no branch
                if (h_shm_temp != NULL) {
                    /* Get Accessible Address */
                    p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(h_shm_temp));  // LCOV_EXCL_BR_LINE 200: can not be NULL  // NOLINT(whitespace/line_length)
                    if (p_hdr != NULL) {  // LCOV_EXCL_BR_LINE 200: can not be NULL
                        mem_size = p_hdr->mem_size;
                        ret_api = RET_NORMAL;
                    }
                    CloseSharedMemory(h_shm_temp);  // LCOV_EXCL_BR_LINE 200: no branch
                }

                if (ret_api == RET_NORMAL) {
                    ret_api = RET_ERROR;    /* Process result initialization */
                    /* Maps the shared data area to physical memory and returns its information pointer */
                    h_shm = OpenSharedMemory(p_item->name, mem_size);  // LCOV_EXCL_BR_LINE 200: no branch
                    if (h_shm != NULL) {
                        p_item->h_shared_mem = h_shm;
                        /* Get Accessible Address */
                        p_hdr = reinterpret_cast<_CWORD64_SHMHDR*>(GetSharedMemoryPtr(p_item->h_shared_mem));
                        if (p_hdr != NULL) {
                            *mem_ptr = reinterpret_cast<void*>(p_hdr + 1);    /* Start at the address following the header */
                            *size = static_cast<u_int32>(mem_size);
                            ret_api = RET_NORMAL;
                        }
                    }
                }

                if (ret_api != RET_NORMAL) {
                    UnlinkFromMemMapList(p_item);    /* Remove the target memory-mapped object from the memory-mapped list */

                    PbProcessHeapFree(0, p_item);  // LCOV_EXCL_BR_LINE 200: no branch
                    p_item = NULL;
                    *mem_ptr = NULL;
                    *size = 0;
                }
            }
        }

        /* Release Mutex */
        PbMutexUnlock(g_p_mem_map_list->h_mutex);  // LCOV_EXCL_BR_LINE 200: no branch
    } else {
        /* When an error occurs during parameter check */
        if (mem_ptr != NULL) {
            *mem_ptr = NULL;
        }
    }

    return ret_api;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PbDeleteShareData
 * ABSTRACT  : Shared data area deletion processing
 * NOTE      : Deletes (releases) the shared memory area allocated under the name of the shared data area.
 * ARGUMENT  : char*        area_name        Pointer to shared data area name string
 * RETURN    : RET_API        RET_NORMAL        Normal
 *           :                RET_ERROR        The specified shared data does not exist
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
PbDeleteShareData(char* area_name)  // LCOV_EXCL_START 8:dead code
#else
PbDeleteShareData(TCHAR* area_name)
#endif   // _CWORD64_API_DOES_NOT_USE_UNICODE
{
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    RET_API            ret_api = RET_NORMAL;
    TCHAR           *p_area_name = NULL;
    TCHAR            name[MAX_AREA_NAME_LEN] = {0};
    MEMMAP_ITEM       *p_item = NULL;
#ifdef UNDER_CE
    TCHAR            unicode_area_name[MAX_AREA_NAME_LEN] = {0};
#endif

    /* Parameter check */
    if (area_name == NULL)          /* If the name of the shared area is NULL */ {
        ret_api = RET_ERROR;
    } else {
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
#ifdef UNDER_CE
        if (strlen(area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        } else {
            mbstowcs(unicode_area_name, area_name, MAX_AREA_NAME_LEN);
            p_area_name = unicode_area_name;
        }
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
#else
        p_area_name = area_name;
        if (_tcslen(p_area_name) >= MAX_AREA_NAME_LEN) {
            ret_api = RET_ERROR;
        }
#endif
        if (ret_api == RET_NORMAL) {
            if (p_area_name[0] == __TEXT('\0')) {
                ret_api = RET_ERROR;
            }
        }
    }

    if (ret_api == RET_NORMAL) {
        /* Shared memory is allocated with the name of the shared area, or the memory map information management table is searched. */
        _tcscpy(name, p_area_name);

        /* Lock Mutex */
        PbMutexLock(g_p_mem_map_list->h_mutex, INFINITE);

        p_item = FindMemMapItemByName(name);        /* Search memory map object by area name */
        if (p_item == NULL)                          /* If the area name is not in the memory-map information management TBL */ {
            /* If the area name is not in the memory map information management TBL, it has not been created or deleted. */
            /* Release Mutex */
            PbMutexUnlock(g_p_mem_map_list->h_mutex);
            ret_api = RET_ERROR;
        } else {
            /* If the area name is in the memory map information management TBL */
            /* Removes the memory map information from the Chain of the memory map information management table. */
            UnlinkFromMemMapList(p_item);

            /* Releases the Mutex of the memory map information management table and releases the shared memory. */
            /* Release Mutex */
            PbMutexUnlock(g_p_mem_map_list->h_mutex);

            if (p_item->h_shared_mem != NULL) {
                CloseSharedMemory(p_item->h_shared_mem);
                p_item->h_shared_mem = NULL;
            }

            /* Frees memory-map information from the heap */
            PbProcessHeapFree(0, p_item);

            /* Deleting Shared Memory Objects */
            /*************************************************************/
            /* Note: Be sure to delete it, so Do not use DeleteShareData */
            /* if you want to link elsewhere.                            */
            /*************************************************************/
            DeleteSharedMemory(name);
        }
    }

    return ret_api;
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : LinkRomData
 * ABSTRACT  : ROM data link
 * NOTE      : Links data located in ROM.
 *           : Specifies the name of the file in which the data is to be stored, and points to the start address of the data.
 *           : Get pointer and data size.
 * ARGUMENT  : char        *filename    Pointer to the string of the name of the ROM data storage file
 *           : void        **mem_ptr    Pointer to the start address of the ROM data storage file
 *           : u_int32    *size        Pointer to the size of the data portion
 * RETURN    : RET_API    RET_NORMAL    Normal status
 *           :             RET_ERROR    Specified ROM data storage file does not exist
 *           :                         File name character string width error
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifdef _CWORD64_API_DOES_NOT_USE_UNICODE
RET_API LinkRomData(char* filename, void** mem_ptr, u_int32* size)  // LCOV_EXCL_START 8:dead code
#else
RET_API LinkRomData(TCHAR* filename, void** mem_ptr, u_int32* size)
#endif   // _CWORD64_API_DOES_NOT_USE_UNICODE
{
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return RET_NORMAL;    /* Coverity CID: 18772 compliant */
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PbAccessPhysicalMem
 * ABSTRACT  : Access to Physical Memory Area Allocation Data
 * NOTE      : Access data allocated in the physical memory area.
 *           : The physical memory area is mapped to the shared memory area and mapped.
 *           : The start address is returned.
 * ARGUMENT  : u_int32    addr        Start address of the physical memory area
 *           : void        **mem_ptr    Pointer to the start address of the mapped shared area
 *           : u_int32    size        Size of the data
 *           : u_int32    mode        Access mode
 *           :                             ACCESS_MODE_READONLY :Read Only
 *           :                             ACCESS_MODE_READWRITE:Reading and Writing
 * RETURN    : RET_API    RET_NORMAL        Normal status
 *           :             RET_ERRPARAM    Parameter error
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
PbAccessPhysicalMem(u_int32 addr, void **mem_ptr, u_int32 size, u_int32 mode) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return RET_NORMAL;    /* Coverity CID: 18767 compliant */
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PbFreePhysicalMem
 * ABSTRACT  : Access release processing to the physical memory area allocation data
 * NOTE      : Releases access to data allocated in a physical memory area
 *           : Releases the shared memory area Allocate by AccessPhysicalMem.
 * ARGUMENT  : u_int32    addr        Start address of the physical memory area to be released
 *           : void        *mem_ptr    Pointer to the start address of the mapped shared area
 *           : u_int32    size        Data size to be released
 * RETURN    : RET_API    RET_NORMAL        Normal status
 *           :             RET_ERRPARAM    Parameter error
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
PbFreePhysicalMem(u_int32 addr, void *mem_ptr, u_int32 size) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return RET_NORMAL;    /* Coverity CID: 18766 compliant */
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : FindMemMapItemByName
 * ABSTRACT  : Memory map information retrieval processing
 * NOTE      : Retrieves the memory map information by the specified shared data area name.
 * ARGUMENT  : TCHAR*            name        Pointer to shared data area name character string
 * RETURN    : MEMMAP_ITEM*        !NULL        Pointer to memory map information
 *           :                    NULL        Memory map information does not exist
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static MEMMAP_ITEM*
FindMemMapItemByName(TCHAR* name) {
    MEMMAP_ITEM* ret = NULL;    /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    if (g_p_mem_map_list == NULL) {  // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
        /* If the memory map information management table is not allocated, */
        /* nop */
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    } else if (g_p_mem_map_list->num_of_items == 0) {
        /* If no memory map information is allocated, */
        /* nop */
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    } else {
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
        /* Gets the pointer of the memory map Chain at the beginning of the file. */
        /* Loops until there is no memory map Chain */
        while (p_item != NULL) {
            if (_tcscmp(p_item->name, name) == 0) {
                /* If the name of the memory map information matches the name of the argument */
                /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
                /* Returns a pointer to the memory map information */
                ret = p_item;
                break;    /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
            }
            p_item = p_item->p_next;                    /* Retrieves the pointers of the memory map data Chain next time. */
        }
    }

    return(ret);   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : LinkToMemMapList
 * NOTE      : Adding a Memory Map Object to the Memory Map List
 * ARGUMENT  : MEMMAP_ITEM*    p_item    Specify a memory-mapped object
 * RETURN    : Without
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void
LinkToMemMapList(MEMMAP_ITEM* p_item) {
    BOOL    processing_complete = FALSE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    if (g_p_mem_map_list == NULL) {  // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
        // LCOV_EXCL_START 200: g_p_mem_map_list can not be NULL
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        // LCOV_EXCL_STOP
    }

    /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    if ((processing_complete == FALSE) && (g_p_mem_map_list->num_of_items == 0)) {
        g_p_mem_map_list->p_head = p_item;
        g_p_mem_map_list->p_tail = p_item;
        g_p_mem_map_list->num_of_items = 1;
        processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    }

    /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    if (processing_complete == FALSE) {
        g_p_mem_map_list->p_tail->p_next = p_item;
        p_item->p_prev = g_p_mem_map_list->p_tail;
        p_item->p_next = NULL;
        g_p_mem_map_list->p_tail = p_item;
        g_p_mem_map_list->num_of_items++;
    }
    return;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : UnlinkFromMemMapList
 * ABSTRACT  : Memory map information deletion processing
 * NOTE      : Memory map information specified by the pointer is stored in the memory map information management table.
 *           : From the Chain structures.The memory map information is not released.
 * ARGUMENT  : MEMMAP_ITEM*        p_item        Pointer to the memory map information to be deleted
 * RETURN    : None
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void
UnlinkFromMemMapList(MEMMAP_ITEM* p_item) {
    /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    BOOL    processing_complete = FALSE;
    /* Parameter check */
    if (g_p_mem_map_list == NULL) {  // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
        /* If the memory map information management table is not allocated, */
        /* nop */
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    } else if (p_item == NULL) {  // LCOV_EXCL_BR_LINE 200: p_item can not be NULL
        /* If a pointer to memory-mapped information is not specified, */
        /* nop */
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    } else if (g_p_mem_map_list->num_of_items == 0) {  // LCOV_EXCL_BR_LINE 200: num_of_items can not be 0
        /* If no memory map information is allocated, */
        /* nop */
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
    } else {
        /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        /* Chain detachment process when there is only one memory map data item */
        if (g_p_mem_map_list->num_of_items == 1) {
            if (g_p_mem_map_list->p_head == p_item) {
                /* If only one memory map is reserved */
                /* For the top memory map information of the memo map information management table */
                g_p_mem_map_list->p_head = NULL;            /* Initializes the top memory map to NULL. */
                g_p_mem_map_list->p_tail = NULL;            /* NULL initialization of the termination memory map data */
                g_p_mem_map_list->num_of_items = 0;        /* Initializes the control memory map information count to zero. */
            }
            /* Specified memory map information pointer does not exist  */
            processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        }

        /* Memory-map-information-removal process at the top of the Chain */
        if ((processing_complete == FALSE) && (p_item == g_p_mem_map_list->p_head))  {
            /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
            /* If the specified memory map information is the first memory map information, */
            /* The leading memory map information pointer is changed to the next Chain pointer. */
            g_p_mem_map_list->p_head = g_p_mem_map_list->p_head->p_next;
            /* Change the previous Chain source of the first memory map to NULL */
            g_p_mem_map_list->p_head->p_prev = NULL;
            g_p_mem_map_list->num_of_items--;        /* Decrement the number of management memory map information */
            p_item->p_next = NULL;         /* Initialize the Chain destination of the removed memory map NULL. */
            processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        }

        /* Memory-map data detachment process at the end of the Chain */
        if ((processing_complete == FALSE) && (p_item == g_p_mem_map_list->p_tail)) {
            /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
            /* If the pointed-to memory-map information is terminated, */
            /* Change the terminating memory-map info pointer to the previous Chain source */
            g_p_mem_map_list->p_tail = g_p_mem_map_list->p_tail->p_prev;
            /* Change the Chain destination of the terminated memory map to NULL. */
            g_p_mem_map_list->p_tail->p_next = NULL;
            /* Decrement the number of management memory map information */
            g_p_mem_map_list->num_of_items--;
            /* The previous Chain source of the removed memory map data is NULL initialized. */
            p_item->p_prev = NULL;
            processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        }

        /* Checking the memory map info Chain for errors */
        if ((processing_complete == FALSE) &&
                (g_p_mem_map_list->num_of_items <= 2)) {
            /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
            /* No more than two memory maps are possible except at the beginning and end. */
            processing_complete = TRUE;   /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
        }

        /* Departure process other than the start and end of the memory map data Chain */
        if (processing_complete == FALSE) {
            /* _CWORD71_:QAC++4020:Multiple exit points found. MISRA-C++ Rule 6-6-5 */
            p_item->p_prev->p_next = p_item->p_next;     /* Set the next Chain destination of the previous memory map to the next one */
            p_item->p_next->p_prev = p_item->p_prev;     /* Previous Chain of one memory map before previous */
            g_p_mem_map_list->num_of_items--;             /* Decrement the number of management memory map information */
            p_item->p_prev = NULL;                 /* The previous Chain source of the removed memory map data is NULL initialized. */
            p_item->p_next = NULL;                 /* Initialize the Chain destination of the removed memory map NULL. */
        }
    }
    return;
}

/**
 * @brief
 *   Obtain dump information
 *
 * @param[out] p_buf      Dump info
 */
void _pb_GetDebugMemoryMngTbl(void* p_buf) {    // NOLINT(readability/nolint) WPF_SYSAPI.h
    static uint8_t  buf[DEBUG_DUMP_MAX_SIZE];
    static uint8_t  buf_tmp[256];
    uint32_t        i = 0;

    if (p_buf != NULL) {
        memset(&buf[0], 0x00, sizeof(buf));
        snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf), "Memory");

        if (g_p_mem_map_list == NULL) {  // LCOV_EXCL_BR_LINE 200: g_p_mem_map_list can not be NULL
            // LCOV_EXCL_START 200: g_p_mem_map_list can not be NULL
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            strncat(reinterpret_cast<char *>(&buf[0]), "\n NULL", strlen("\n NULL"));
            // LCOV_EXCL_STOP
        } else if (g_p_mem_map_list->num_of_items == 0) {  // LCOV_EXCL_BR_LINE 200: num_of_items can not be 0
            // LCOV_EXCL_START 200: num_of_items can not be 0
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            strncat(reinterpret_cast<char *>(&buf[0]), "\n num_of_items:0", strlen("\n num_of_items:0"));
            // LCOV_EXCL_STOP
        } else {
            memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
            snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),  // LCOV_EXCL_BR_LINE 5: c lib error case
                    "\n h_heap:%p, p_head:%s, p_tail:%s, num_of_items:%lu, h_mutex:%p",
                    g_p_mem_map_list->h_heap,
                    ((g_p_mem_map_list->p_head == NULL)?"NULL":"NOT NULL"),
                    ((g_p_mem_map_list->p_tail == NULL)?"NULL":"NOT NULL"),
                    g_p_mem_map_list->num_of_items,
                    g_p_mem_map_list->h_mutex);
            strncat(reinterpret_cast<char *>(&buf[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
                strlen(reinterpret_cast<char *>(&buf_tmp[0])));
            MEMMAP_ITEM* p_item = g_p_mem_map_list->p_head;
            while (p_item != NULL) {
                memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
                snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
                        "\n [%02d]h_heap:%10p, p_next:%s, p_prev:%s, name:%40s, hShrMem:%10p, adr:%lu",
                        i,
                        p_item->h_heap,
                        ((p_item->p_next == NULL)?"NULL    ":"NOT NULL"),
                        ((p_item->p_prev == NULL)?"NULL    ":"NOT NULL"),
                        p_item->name,
                        p_item->h_shared_mem,
                        p_item->address);
                i++;
                strncat(reinterpret_cast<char *>(&buf[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
                    strlen(reinterpret_cast<char *>(&buf_tmp[0])));
                p_item = p_item->p_next;
            }
        }
        memcpy(p_buf, &buf[0], sizeof(buf));
    }
}