Everything

-secure_malloc [Professional Edition only]


This option generates a malloc library for security facility.

[Specification format]

-secure_malloc

 

-

Interpretation when omitted

A malloc library for normal use is generated.

[Detailed description]

-

This option generates a malloc library for security facility.

-

When using a malloc library for security facility, the __heap_chk_fail function is called when one of the following operations is performed:

-

A pointer to an area other than that allocated by calloc, malloc, or realloc is passed to free or realloc.

-

The pointer to an area released by free is passed again to free or realloc.

-

After a value is written to an address outside the area allocated by calloc, malloc, or realloc (within two bytes before and after the allocated area), the pointer to that area is passed to free or realloc.

-

The __heap_chk_fail function needs to be defined by the user. This function describes the processing to be executed when an error occurs in management of dynamic memory.

-

Note the following points when defining the __heap_chk_fail function.

-

The __heap_chk_fail function should be a far function whose return value and parameter type should be the void type.

void __far __heap_chk_fail(void);

-

Do not define the __heap_chk_fail function as static.

-

Corruption of heap memory area should not be detected recursively in the __heap_chk_fail function.

-

The calloc, malloc, and realloc functions for the security facility allocate two extra bytes each before and after an allocated area for the purpose of detecting writing to addresses outside the allocated area. This consumes more heap memory area than with the usual functions.

[Caution]

-

The default size of the heap memory area is 0x100 bytes.

-

To change the heap memory area, define the _REL_sysheap array and set the array size in the _REL_sizeof_sysheap variable.

[Example of setting the heap memory area]

#include <stddef.h>
#define SIZEOF_HEAP  0x200
int _REL_sysheap[SIZEOF_HEAP / sizeof(int)];
size_t _REL_sizeof_sysheap = SIZEOF_HEAP;

Remark

The _REL_sysheap array should be allocated to an even address.