1 // AreaSupport.cpp 2 3 #include "AreaSupport.h" 4 5 // get_area_for_address 6 status_t 7 UserlandFSUtil::get_area_for_address(void* address, int32 size, area_id* area, 8 int32* offset, void** areaBaseAddress) 9 { 10 // check parameters 11 if (!area || !offset || size < 0) 12 return B_BAD_VALUE; 13 // catch NULL address case 14 if (!address) { 15 *area = -1; 16 *offset = 0; 17 return B_OK; 18 } 19 // get area and in-area offset 20 *area = area_for(address); 21 if (*area < 0) 22 return *area; 23 area_info areaInfo; 24 status_t error = get_area_info(*area, &areaInfo); 25 if (error != B_OK) 26 return error; 27 // check the size 28 *offset = (uint8*)address - (uint8*)areaInfo.address; 29 if (*offset + size > (int32)areaInfo.size) 30 return B_BAD_VALUE; 31 if (areaBaseAddress) 32 *areaBaseAddress = areaInfo.address; 33 return B_OK; 34 } 35