# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 165
- 166
- 167
- 168
- 169
…
- 365
- 366

Memory Allocation and Access
 2012-2013 Microchip Technology Inc. DS50002071C-page 167
10.10.3 Accessing EEDATA Using Managed Access
On most device the EE Data space is part of the program address space. Therefore
EEData can be accessed automatically using one of the managed access qualifiers
__psv__ or __eds__.
EXAMPLE 10-3: EXAMPLE 6-2 USING MANAGED PSV ACCESS
#include <xc.h>
__eds__ char user_data[] __attribute__((space(eedata))) = { /* values
*/ };
int main(void) {
int value;
value = user_data[0];
if (value) ; /* do something */
}
10.10.4 Additional Sources of Information
The device Family Reference Manuals have an excellent discussion on using the Flash
program memory and EE data memory provided. These manuals also have information
on run-time programming of both program memory and EE data memory.
There are many library routines provided with the compiler. See the 16-Bit Language
Tools Libraries (DS51456) manual for more information.
10.11 DYNAMIC MEMORY ALLOCATION
The C run-time heap is an uninitialized area of data memory that is used for dynamic
memory allocation using the standard C library dynamic memory management
functions, calloc, malloc and realloc. If you do not use any of these functions,
then you do not need to allocate a heap. By default, a heap is not created.
If you do want to use dynamic memory allocation, either directly, by calling one of the
memory allocation functions, or indirectly, by using a standard C library input/output
function, then a heap must be created. A heap is created by specifying its size on the
linker command line, using the --heap linker command-line option. An example of
allocating a heap of 512 bytes using the command line is:
xc16-gcc foo.c -Wl,--heap=512
The linker allocates the heap immediately below the stack.
You can use a standard C library input/output function to create open files (fopen). If
you open files, then the heap size must include 40 bytes for each file that is simultane-
ously open. If there is insufficient heap memory, then the open function will return an
error indicator. For each file that should be buffered, 4 bytes of heap space is required.
If there is insufficient heap memory for the buffer, then the file will be opened in unbuff-
ered mode. The default buffer can be modified with setvbuf or setbuf.

- 1
- 2
…
- 165
- 166
- 167
- 168
- 169
…
- 365
- 366