Some renaming for consistency, new check function added, documentation fixes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15344 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
44ccf3952d
commit
b48f8ebdaa
|
@ -83,13 +83,13 @@ extern "C" {
|
||||||
bool chMemIsStringWithinX(const memory_area_t *map,
|
bool chMemIsStringWithinX(const memory_area_t *map,
|
||||||
const char *s,
|
const char *s,
|
||||||
size_t n);
|
size_t n);
|
||||||
bool chMemIsAreaContainedX(const memory_area_t areas[],
|
bool chMemIsSpaceContainedX(const memory_area_t areas[],
|
||||||
const void *p,
|
const void *p,
|
||||||
size_t size);
|
size_t size);
|
||||||
bool chMemIsAreaWritableX(void *p,
|
bool chMemIsSpaceWritableX(void *p,
|
||||||
size_t size,
|
size_t size,
|
||||||
unsigned align);
|
unsigned align);
|
||||||
bool chMemIsAreaReadableX(const void *p,
|
bool chMemIsSpaceReadableX(const void *p,
|
||||||
size_t size,
|
size_t size,
|
||||||
unsigned align);
|
unsigned align);
|
||||||
bool chMemIsAddressExecutableX(const void *p);
|
bool chMemIsAddressExecutableX(const void *p);
|
||||||
|
@ -103,21 +103,20 @@ extern "C" {
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Memory area check.
|
* @brief Memory space inclusion check.
|
||||||
* @details Checks if specified area belongs to the specified memory area.
|
* @details Checks if specified space belongs to the specified memory area.
|
||||||
*
|
*
|
||||||
* @param[in] map pointer to a @p memory_area_t structure
|
* @param[in] map pointer to a @p memory_area_t structure
|
||||||
* @param[in] p pointer to the area to be checked
|
* @param[in] p pointer to the memory space to be checked
|
||||||
* @param[in] size size of the area to be checked, zero is considered
|
* @param[in] size size of the memory space to be checked, zero is
|
||||||
* the whole address space
|
* considered the whole address space
|
||||||
* @return The test result.
|
* @return The test result.
|
||||||
* @retval true if the area is entirely contained within one of the
|
* @retval true if the memory space is entirely contained.
|
||||||
* specified areas.
|
* @retval false if the memory space is not entirely contained.
|
||||||
* @retval false if the area check failed.
|
|
||||||
*
|
*
|
||||||
* @xclass
|
* @xclass
|
||||||
*/
|
*/
|
||||||
static inline bool chMemIsAreaWithinX(const memory_area_t *map,
|
static inline bool chMemIsSpaceWithinX(const memory_area_t *map,
|
||||||
const void *p,
|
const void *p,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
const uint8_t *mem_base = (const uint8_t *)map->base;
|
const uint8_t *mem_base = (const uint8_t *)map->base;
|
||||||
|
@ -130,6 +129,33 @@ static inline bool chMemIsAreaWithinX(const memory_area_t *map,
|
||||||
return (bool)((base <= end) && (base >= mem_base) && (end <= mem_end));
|
return (bool)((base <= end) && (base >= mem_base) && (end <= mem_end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Memory space intersection check.
|
||||||
|
* @details Checks if specified memory space intersects the specified memory
|
||||||
|
* area.
|
||||||
|
*
|
||||||
|
* @param[in] map pointer to a @p memory_area_t structure
|
||||||
|
* @param[in] p pointer to the memory space to be checked
|
||||||
|
* @param[in] size size of the memory space to be checked, zero is
|
||||||
|
* considered the whole address space
|
||||||
|
* @return The test result.
|
||||||
|
* @retval true if the memory space is intersecting.
|
||||||
|
* @retval false if the memory space is not intersecting.
|
||||||
|
*
|
||||||
|
* @xclass
|
||||||
|
*/
|
||||||
|
static inline bool chMemIsSpaceIntersectingX(const memory_area_t *map,
|
||||||
|
const void *p,
|
||||||
|
size_t size) {
|
||||||
|
const uint8_t *mem_base = (const uint8_t *)map->base;
|
||||||
|
const uint8_t *mem_end = mem_base + map->size - (size_t)1;
|
||||||
|
const uint8_t *base = (const uint8_t *)p;
|
||||||
|
const uint8_t *end = base + size - (size_t)1;
|
||||||
|
|
||||||
|
return (bool)(((base >= mem_base) && (base <= mem_end)) ||
|
||||||
|
((end >= mem_base) && (end <= mem_end)));
|
||||||
|
}
|
||||||
|
|
||||||
#if CH_CFG_USE_MEMCHECKS == FALSE
|
#if CH_CFG_USE_MEMCHECKS == FALSE
|
||||||
/* Stub implementations for when the functionality is disabled, areas are
|
/* Stub implementations for when the functionality is disabled, areas are
|
||||||
always reported as valid.*/
|
always reported as valid.*/
|
||||||
|
|
|
@ -121,22 +121,23 @@ bool chMemIsStringWithinX(const memory_area_t *map, const char *s, size_t n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Memory area check.
|
* @brief Memory space check.
|
||||||
* @details Checks if specified area belongs to one of the specified areas.
|
* @details Checks if specified memory space belongs to one of the specified
|
||||||
|
* areas.
|
||||||
*
|
*
|
||||||
* @param[in] map array of valid areas terminated with an end
|
* @param[in] map array of valid areas terminated with an end
|
||||||
* marker (base=-1)
|
* marker (base=-1)
|
||||||
* @param[in] p pointer to the area to be checked
|
* @param[in] p pointer to the memory space to be checked
|
||||||
* @param[in] size size of the area to be checked, zero is considered
|
* @param[in] size size of the memory space to be checked, zero is
|
||||||
* the whole address space
|
* considered the whole address space
|
||||||
* @return The test result.
|
* @return The test result.
|
||||||
* @retval true if the area is entirely contained within one of the
|
* @retval true if the memory space is entirely contained within one
|
||||||
* specified areas.
|
* of the specified areas.
|
||||||
* @retval false if the area check failed.
|
* @retval false if the memory space check failed.
|
||||||
*
|
*
|
||||||
* @xclass
|
* @xclass
|
||||||
*/
|
*/
|
||||||
bool chMemIsAreaContainedX(const memory_area_t areas[],
|
bool chMemIsSpaceContainedX(const memory_area_t areas[],
|
||||||
const void *p,
|
const void *p,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
const memory_area_t *map = &areas[0];
|
const memory_area_t *map = &areas[0];
|
||||||
|
@ -145,7 +146,7 @@ bool chMemIsAreaContainedX(const memory_area_t areas[],
|
||||||
|
|
||||||
/* Scanning the array of the valid areas for a mismatch.*/
|
/* Scanning the array of the valid areas for a mismatch.*/
|
||||||
while (map->base != (uint8_t *)-1) {
|
while (map->base != (uint8_t *)-1) {
|
||||||
if (chMemIsAreaWithinX(map, p, size)) {
|
if (chMemIsSpaceWithinX(map, p, size)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
map++;
|
map++;
|
||||||
|
@ -157,25 +158,25 @@ bool chMemIsAreaContainedX(const memory_area_t areas[],
|
||||||
#if (CH_CFG_USE_MEMCHECKS == TRUE) || defined(__DOXYGEN__)
|
#if (CH_CFG_USE_MEMCHECKS == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Memory writable area check.
|
* @brief Writable memory space check.
|
||||||
* @details Checks if specified pointer belongs to one of the system-defined
|
* @details Checks if the specified memory space belongs to one of the
|
||||||
* writable areas and is aligned as specified.
|
* system-defined writable areas and is aligned as specified.
|
||||||
* @note @p __ch_mem_writable_areas must be the name of a global
|
* @note @p __ch_mem_writable_areas must be the name of a global
|
||||||
* @p memory_area_t array terminated with an end marker (-1, 0).
|
* @p memory_area_t array terminated with an end marker (-1, 0).
|
||||||
*
|
*
|
||||||
* @param[in] p pointer to the area to be checked
|
* @param[in] p pointer to the memory space to be checked
|
||||||
* @param[in] size size of the area to be checked, zero is considered
|
* @param[in] size size of the memory space to be checked, zero is
|
||||||
* the whole address space
|
* considered the whole address space
|
||||||
* @param[in] align required pointer alignment to be checked, must be
|
* @param[in] align required pointer alignment to be checked, must be
|
||||||
* a power of two
|
* a power of two
|
||||||
* @return The test result.
|
* @return The test result.
|
||||||
* @retval true if the area is entirely contained within one of the
|
* @retval true if the memory space is entirely contained within one
|
||||||
* system-defined writable areas.
|
* memory space system-defined writable areas.
|
||||||
* @retval false if the area check failed.
|
* @retval false if the memory space check failed.
|
||||||
*
|
*
|
||||||
* @xclass
|
* @xclass
|
||||||
*/
|
*/
|
||||||
bool chMemIsAreaWritableX(void *p,
|
bool chMemIsSpaceWritableX(void *p,
|
||||||
size_t size,
|
size_t size,
|
||||||
unsigned align) {
|
unsigned align) {
|
||||||
|
|
||||||
|
@ -185,29 +186,29 @@ bool chMemIsAreaWritableX(void *p,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return chMemIsAreaContainedX(__ch_mem_writable_areas, p, size);
|
return chMemIsSpaceContainedX(__ch_mem_writable_areas, p, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Memory readable area check.
|
* @brief Readable memory space check.
|
||||||
* @details Checks if specified pointer belongs to one of the system-defined
|
* @details Checks if specified memory space belongs to one of the
|
||||||
* readable areas and is aligned as specified.
|
* system-defined readable areas and is aligned as specified.
|
||||||
* @note @p __ch_mem_readable_areas must be the name of a global
|
* @note @p __ch_mem_readable_areas must be the name of a global
|
||||||
* @p memory_area_t array terminated with an end marker (-1, 0).
|
* @p memory_area_t array terminated with an end marker (-1, 0).
|
||||||
*
|
*
|
||||||
* @param[in] p pointer to the area to be checked
|
* @param[in] p pointer to the memory space to be checked
|
||||||
* @param[in] size size of the area to be checked, zero is considered
|
* @param[in] size size of the memory space to be checked, zero is
|
||||||
* the whole address space
|
* considered the whole address space
|
||||||
* @param[in] align required pointer alignment to be checked, must be
|
* @param[in] align required pointer alignment to be checked, must be
|
||||||
* a power of two
|
* a power of two
|
||||||
* @return The test result.
|
* @return The test result.
|
||||||
* @retval true if the area is entirely contained within one of the
|
* @retval true if the memory space is entirely contained within one
|
||||||
* system-defined readable areas.
|
* of the system-defined readable areas.
|
||||||
* @retval false if the area check failed.
|
* @retval false if the memory space check failed.
|
||||||
*
|
*
|
||||||
* @xclass
|
* @xclass
|
||||||
*/
|
*/
|
||||||
bool chMemIsAreaReadableX(const void *p,
|
bool chMemIsSpaceReadableX(const void *p,
|
||||||
size_t size,
|
size_t size,
|
||||||
unsigned align) {
|
unsigned align) {
|
||||||
|
|
||||||
|
@ -217,7 +218,7 @@ bool chMemIsAreaReadableX(const void *p,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return chMemIsAreaContainedX(__ch_mem_readable_areas, p, size);
|
return chMemIsSpaceContainedX(__ch_mem_readable_areas, p, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,7 +244,7 @@ bool chMemIsAddressExecutableX(const void *p) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return chMemIsAreaContainedX(__ch_mem_executable_areas, p, 1);
|
return chMemIsSpaceContainedX(__ch_mem_executable_areas, p, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CH_CFG_USE_MEMCHECKS == TRUE */
|
#endif /* CH_CFG_USE_MEMCHECKS == TRUE */
|
||||||
|
|
|
@ -447,7 +447,7 @@ bool chHeapIntegrityCheck(memory_heap_t *heapp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validating the found free block.*/
|
/* Validating the found free block.*/
|
||||||
if (!chMemIsAreaWithinX(&heapp->area,
|
if (!chMemIsSpaceWithinX(&heapp->area,
|
||||||
(void *)hp,
|
(void *)hp,
|
||||||
H_FREE_FULLSIZE(hp))) {
|
H_FREE_FULLSIZE(hp))) {
|
||||||
result = true;
|
result = true;
|
||||||
|
|
|
@ -206,7 +206,7 @@ static msg_t allocate_section(elf_load_context_t *ctxp,
|
||||||
|
|
||||||
/* Checking if the section can fit into the destination memory area.*/
|
/* Checking if the section can fit into the destination memory area.*/
|
||||||
load_address = ctxp->map->base + shp->sh_addr;
|
load_address = ctxp->map->base + shp->sh_addr;
|
||||||
if (!chMemIsAreaWithinX(ctxp->map,
|
if (!chMemIsSpaceWithinX(ctxp->map,
|
||||||
(const void *)load_address,
|
(const void *)load_address,
|
||||||
(size_t)shp->sh_size)) {
|
(size_t)shp->sh_size)) {
|
||||||
return CH_RET_ENOMEM;
|
return CH_RET_ENOMEM;
|
||||||
|
@ -290,7 +290,7 @@ static msg_t reloc_entry(elf_load_context_t *ctxp,
|
||||||
relocation_address = (uint32_t)ctxp->map->base +
|
relocation_address = (uint32_t)ctxp->map->base +
|
||||||
lip->address +
|
lip->address +
|
||||||
rp->r_offset;
|
rp->r_offset;
|
||||||
if (!chMemIsAreaWithinX(ctxp->map,
|
if (!chMemIsSpaceWithinX(ctxp->map,
|
||||||
(const void *)relocation_address,
|
(const void *)relocation_address,
|
||||||
sizeof (uint32_t))) {
|
sizeof (uint32_t))) {
|
||||||
return CH_RET_ENOMEM;
|
return CH_RET_ENOMEM;
|
||||||
|
@ -372,7 +372,7 @@ static msg_t load_relocate_section(elf_load_context_t *ctxp,
|
||||||
|
|
||||||
/* Checking if the section can fit into the destination memory area.*/
|
/* Checking if the section can fit into the destination memory area.*/
|
||||||
load_address = ctxp->map->base + lip->address;
|
load_address = ctxp->map->base + lip->address;
|
||||||
if (!chMemIsAreaWithinX(ctxp->map,
|
if (!chMemIsSpaceWithinX(ctxp->map,
|
||||||
(const void *)load_address,
|
(const void *)load_address,
|
||||||
lip->bits_size)) {
|
lip->bits_size)) {
|
||||||
return CH_RET_ENOMEM;
|
return CH_RET_ENOMEM;
|
||||||
|
|
|
@ -61,7 +61,7 @@ bool sb_is_valid_read_range(sb_class_t *sbcp, const void *start, size_t size) {
|
||||||
const sb_memory_region_t *rp = &sbcp->config->regions[0];
|
const sb_memory_region_t *rp = &sbcp->config->regions[0];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (chMemIsAreaContainedX(&rp->area, start, size)) {
|
if (chMemIsSpaceWithinX(&rp->area, start, size)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
rp++;
|
rp++;
|
||||||
|
@ -74,7 +74,7 @@ bool sb_is_valid_write_range(sb_class_t *sbcp, void *start, size_t size) {
|
||||||
const sb_memory_region_t *rp = &sbcp->config->regions[0];
|
const sb_memory_region_t *rp = &sbcp->config->regions[0];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (chMemIsAreaWithinX(&rp->area, start, size)) {
|
if (chMemIsSpaceWithinX(&rp->area, start, size)) {
|
||||||
return rp->writeable;
|
return rp->writeable;
|
||||||
}
|
}
|
||||||
rp++;
|
rp++;
|
||||||
|
|
Loading…
Reference in New Issue