The variable BlockMap mapBlockIndex is defined in validation.cpp
I couldn't find where it is initialized.
There is only a comment here:
https://github.com/bitcoin/bitcoin/blob/86ea3c2ff247bb2ba0fb50013c8ecdbaf8a9fe8f/src/txdb.cpp
// Load mapBlockIndex
while (pcursor->Valid()) {
-- txdb.cpp
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
-- validation.cpp
CBlockIndex * InsertBlockIndex(uint256 hash)
{
if (hash.IsNull())
return NULL;
// Return existing
BlockMap::iterator mi = mapBlockIndex.find(hash);
if (mi != mapBlockIndex.end())
return (*mi).second;
// Create new
CBlockIndex* pindexNew = new CBlockIndex();
if (!pindexNew)
throw std::runtime_error(std::string(__func__) + ": new CBlockIndex failed");
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
pindexNew->phashBlock = &((*mi).first);
return pindexNew;
}