library/src/canaries/BP-Canaries.cc
// attempt to create the global map
attempt to create the global map
attempt to create the global map
BP_ERROR_T BP_CanariesInitGlobalMap(size_t max_canaries)
{
	if(canary_map_init_ok_val == canary_map_init_ok)
	{
		return ERR_FAILURE;
	}
	if(!max_canaries)
		return ERR_FAILURE;
	int fd = open("/dev/zero", O_RDWR);
	size_t canaries_size = max_canaries * (sizeof(BP_CANARY_ENTRY));
	while(canaries_size % 4096)
		canaries_size++;
	canaries_map = mmap
	(
		0,
		max_canaries * (sizeof(BP_CANARY_ENTRY)),
		PROT_READ|PROT_WRITE,
		MAP_PRIVATE,
		fd,
		0
	);
	close(fd);
	if(!canaries_map)
		return ERR_FAILURE;
	memset(canaries_map, 0x00, max_canaries * (sizeof(BP_CANARY_ENTRY)));
	BP_CANARY_TABLE_INIT_SEM(canary_map_lock);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CanariesInitGlobalMap ( size_t max_canaries ) { if ( canary_map_init_ok_val == canary_map_init_ok ) { return ERR_FAILURE ; } if ( ! max_canaries ) return ERR_FAILURE ; int fd = open ( " " , O_RDWR ) ; size_t canaries_size = max_canaries * ( sizeof ( BP_CANARY_ENTRY ) ) ; while ( canaries_size % 4096 ) canaries_size ++ ; canaries_map = mmap ( 0 , max_canaries * ( sizeof ( BP_CANARY_ENTRY ) ) , PROT_READ | PROT_WRITE , MAP_PRIVATE , fd , 0 ) ; close ( fd ) ; if ( ! canaries_map ) return ERR_FAILURE ; memset ( canaries_map , 0x00 , max_canaries * ( sizeof ( BP_CANARY_ENTRY ) ) ) ; BP_CANARY_TABLE_INIT_SEM ( canary_map_lock ) ; return ERR_SUCCESS ; }
attempt to create the global map
attempt to create the global map
// exit immediately if we're already initialized ok // ensure we have a canary creation count // open dev zero // calculate the number of canaries to create // round out the edges // map in the data // close the file descriptor // ensure we have a canaries map // zero out canary memory // init the canary lock // return indicating success