* Copyright (c) 2015-2023 Google, Inc. All rights reserved.
* **********************************************************/
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Google, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
*/
#ifndef _PHYSADDR_H_
#define _PHYSADDR_H_ 1
#include <stddef.h>
#include <stdint.h>
#include <atomic>
#include "dr_api.h"
#include "hashtable.h"
#include "trace_entry.h"
namespace dynamorio {
namespace drmemtrace {
class physaddr_t {
public:
physaddr_t();
~physaddr_t();
bool
init();
bool
virtual2physical(void *drcontext, addr_t virt, OUT addr_t *phys,
OUT bool *from_cache = nullptr);
static bool
global_init();
private:
#ifdef LINUX
inline addr_t
page_start(addr_t addr)
{
return ALIGN_BACKWARD(addr, page_size_);
}
inline uint64_t
page_offs(addr_t addr)
{
return addr & ((1 << page_bits_) - 1);
}
size_t page_size_;
int page_bits_;
static constexpr int NUM_CACHE = 8;
addr_t last_vpage_[NUM_CACHE];
addr_t last_ppage_[NUM_CACHE];
int cache_idx_;
int fd_;
void *v2p_;
void *drcontext_;
static constexpr addr_t PAGE_INVALID = (addr_t)-1;
static constexpr addr_t ZERO_ADDR_PAYLOAD = PAGE_INVALID;
unsigned int count_;
uint64_t num_hit_cache_;
uint64_t num_hit_table_;
uint64_t num_miss_;
static std::atomic<bool> has_privileges_;
#endif
};
}
}
#endif