hsa_status_t MemoryRegion::AssignAgent(void* ptr, size_t size,
                                       const core::Agent& agent,
                                       hsa_access_permission_t access) const {
    if (fine_grain()) {
        return HSA_STATUS_SUCCESS;
    }

    if (std::find(agent.regions().begin(), agent.regions().end(), this) ==
            agent.regions().end()) {
        return HSA_STATUS_ERROR_INVALID_AGENT;
    }

    if (IsLocalMemory()) {
        HSAuint64 u_ptr = reinterpret_cast<HSAuint64>(ptr);
        if (u_ptr >= GetBaseAddress() &&
                u_ptr < (GetBaseAddress() + GetVirtualSize())) {
            // TODO: only support agent allocation buffer.

            // TODO: commented until API to explicitly unpin memory is available.
            // if (!MakeKfdMemoryResident(ptr, size)) {
            //  return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
            //}

            return HSA_STATUS_SUCCESS;
        } else {
            return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
        }
    }

    return HSA_STATUS_SUCCESS;
}
예제 #2
0
void FormatDisassembly::_Format(Address const& rAddress, u32 Flags)
{
  auto& rDoc = m_rCore.GetDocument();

  m_rPrintData(rAddress);

  // Header
  if (rDoc.GetStartAddress() == rAddress)
  {
    m_rPrintData(rAddress);
    _FormatHeader(rAddress, Flags);
  }

  // MemoryArea
  auto pMemArea = rDoc.GetMemoryArea(rAddress);
  if (pMemArea != nullptr && pMemArea->GetBaseAddress() == rAddress)
  {
    _FormatMemoryArea(rAddress, Flags);
    m_rPrintData.AppendNewLine();
  }

  // XRefs
  if (rDoc.HasCrossReferenceFrom(rAddress))
  {
    if (Flags & AddSpaceBeforeXref)
      m_rPrintData.AppendNewLine();

    _FormatXref(rAddress, Flags);
    m_rPrintData.AppendNewLine();
  }

  // Label
  auto rLbl = rDoc.GetLabelFromAddress(rAddress);
  if (rLbl.GetType() != Label::Unknown)
  {
    _FormatLabel(rAddress, Flags);
    m_rPrintData.AppendNewLine();
  }

  // Multicell
  if (rDoc.GetMultiCell(rAddress) != nullptr)
  {
    _FormatMultiCell(rAddress, Flags);
    m_rPrintData.AppendNewLine();
  }

  if (rDoc.GetCell(rAddress) != nullptr)
  {
    _FormatCell(rAddress, Flags);
    m_rPrintData.AppendNewLine();
  }
}
예제 #3
0
파일: Main.cpp 프로젝트: roybai/poe
//////////////////////////////////////////////////////////////////////
// WinMain
// -------------------------------------------------------------------
// The meat of the application.
//////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	DWORD check;
	DWORD PatchAddress;
	DWORD DataAddress;
	DWORD WinProcAddress;
	char message[128];
    char windowname[128];
    char dllFullName[256];
	int x;
    int mode;

	// Sets up NumWindows, and the windolist[] array of HWND's
    // See EnumWindowsProc() for deatils.....
	EnumWindows(EnumWindowsProc, 0);
	
	if(NumWindows == 0)
		MessageBox(NULL, "No D2 Windows found!", "Loader Error", MB_ICONERROR);

	// Loop through all the D2 windows found
	for(x=0; x<NumWindows; x++) {

		// Set the HWND for the current window
		hd.hwnd = windowlist[x];
		
		// Get Diablo II's Process handle
		GetWindowThreadProcessId(hd.hwnd, &hd.pid);
		hd.hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, hd.pid);
		if (!hd.hProcess) { MessageBox(NULL, "Can't get Diablo II's process handle.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// Find a good spot to put our code.  Look first for the original game.
		PatchAddress=GetBaseAddress(hd.pid, M_EXEFILE);
//		WinProcAddress =PatchAddress + 0x4262c0+11; //from spyxx
//		WinProcAddress =PatchAddress + 0x425EC0+11; //from spyxx, 1.0.5b
		WinProcAddress =PatchAddress + 0x42a2e0+11; //from spyxx, 1.0.5b
		if (!PatchAddress) { MessageBox(NULL, "Unable to find a patch location.", "Loader Error!", MB_ICONERROR); return -1;}
//		PatchAddress += 0x400;
//		PatchAddress += 0x5FBF04;
		PatchAddress += 0x1005;

		char	orig_code[10240];
		ReadProcessBYTES(hd.hProcess, PatchAddress, orig_code, 1024);
		DataAddress   = PatchAddress+DATA;

		// Get location of the game's WinProc
//		WinProcAddress = GetClassLongPtr(hd.hwnd,GCL_WNDPROC);

		if (!WinProcAddress) { MessageBox(NULL, "Unable to find WinProc entrypoint.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// Initialize our data structure
		sprintf(hd.ModuleName, "%s", "findwin");

		hd.LoaderMagic      = LOADERMAGIC;
		hd.CodeLocation     = PatchAddress;
		hd.LoaderVersion    = LOADERVERSION;
		hd.WinProcLocation  = WinProcAddress;
		hd.WinProcPatchsize = 5;

		HMODULE hModule = GetModuleHandle("Kernel32.dll");
		if (!hModule) { MessageBox(NULL, "Unable to get handle of KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// We're getting offsets to kernel functions from this userspace.
		// They will be the same inside the game, so we won't need to use
		// functions imported from the game.

		hd.pLoadLibraryA = (DWORD)GetProcAddress(hModule, "LoadLibraryA");
		if (!hd.pLoadLibraryA ) { MessageBox(NULL, "Unable to get address of LoadLibraryA in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}

		hd.pFreeLibrary = (DWORD)GetProcAddress(hModule, "FreeLibrary");
		if (!hd.pFreeLibrary ) { MessageBox(NULL, "Unable to get address of FreeLibrary in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}
		
		hd.pGetModuleHandleA = (DWORD)GetProcAddress(hModule, "GetModuleHandleA");
		if (!hd.pGetModuleHandleA ) { MessageBox(NULL, "Unable to get address of GetModuleHandleA in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}

		// Get the first DWORD from DataAddress to see if we're loading or
		// unloading.  Set up the text for the message box
		ReadProcessBYTES(hd.hProcess, DataAddress, &check, sizeof(DWORD));
		if (check != LOADERMAGIC) { 
			mode = 1;		// We are loading
			strcpy(message, "LOAD ");
		} else {
			mode = 0;		// We are unloading
			strcpy(message, "UNLOAD ");
		}

		GetWindowText(hd.hwnd, windowname, 127);
		strcat(message, windowname);
		strcat(message, "?");

		// If a single window was found, or if the user chooses to do so, 
		// run the load/unload procedure against the current window
		if((NumWindows == 1) || (MessageBox(NULL, message, "Loader Question", MB_YESNO)) == IDYES) {

			// Patch in our code
			WriteProcessBYTES(hd.hProcess, PatchAddress, &AsmCode, FUNCTLEN(AsmCode));
		
			// Patch in our data
			WriteProcessBYTES(hd.hProcess, DataAddress, &hd, sizeof(LOADERDATA));
		
			// Patch in full path+filename to server dll
			GetCurrentDirectory(255, dllFullName);
			strcat(dllFullName, "\\findwin.dll");
//			strcpy(dllFullName, "c:\\bot\\d3\\findwin.dll");
			WriteProcessBYTES(hd.hProcess, DataAddress+sizeof(LOADERDATA), dllFullName, strlen(dllFullName)+1);
		
			// Now hi-jack WinProc of the game to our code
			/*
			char buf[100];
			sprintf(buf,"handle: %x, hwnd:%x, pid:%pid",hd.hProcess,hd.hwnd,hd.pid);
	MessageBox(NULL, buf, "Loader Error!", MB_ICONERROR);*/
			Intercept(hd.hProcess, INST_CALL, WinProcAddress, PatchAddress, LEN);
		
			// Send WM_APP to toggle load/unload of the dll
			SendMessage(hd.hwnd, WM_APP,0,0);
			// Give back WinProc, we don't need it anymore
			Intercept(hd.hProcess, INST_CALL, PatchAddress, WinProcAddress, LEN);
			WriteProcessBYTES(hd.hProcess, PatchAddress, orig_code, 1024);

			// If we're unloading, then clear LOADERMAGIC from the data area
			if(mode == 0) {
				check = 0;
				WriteProcessBYTES(hd.hProcess, DataAddress, &check, sizeof(DWORD));
			}
		}
	}
	return 0;
}
예제 #4
0
 bool IsCellPresent(TOffset Offset) const
 { return GetBaseAddress().IsBetween(GetSize(), Offset); }
예제 #5
0
 bool IsCellPresent(Address const& rAddress) const
 {
   if (GetBaseAddress().GetBase() != rAddress.GetBase())
     return false;
   return IsCellPresent(rAddress.GetOffset());
 }
예제 #6
0
파일: Module.cpp 프로젝트: CaineQT/Deviare2
HRESULT CNktDvModule::ToString(__inout CNktStringW &cStrDest)
{
  if (cStrDest.Format(L"CNktDvModule [Base:%IXh / %s]", GetBaseAddress(), GetFileName()) == FALSE)
    return E_OUTOFMEMORY;
  return S_OK;
}
hsa_status_t MemoryRegion::GetInfo(hsa_region_info_t attribute,
                                   void* value) const {
    switch (attribute) {
    case HSA_REGION_INFO_SEGMENT:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((hsa_region_segment_t*)value) = HSA_REGION_SEGMENT_GLOBAL;
            break;
        case HSA_HEAPTYPE_GPU_LDS:
            *((hsa_region_segment_t*)value) = HSA_REGION_SEGMENT_GROUP;
            break;
        default:
            assert(false && "Memory region should only be global, group");
            break;
        }
        break;
    case HSA_REGION_INFO_GLOBAL_FLAGS:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
            *((uint32_t*)value) = (HSA_REGION_GLOBAL_FLAG_KERNARG |
                                   HSA_REGION_GLOBAL_FLAG_FINE_GRAINED);
            break;
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((uint32_t*)value) = HSA_REGION_GLOBAL_FLAG_COARSE_GRAINED;
            break;
        default:
            *((uint32_t*)value) = 0;
            break;
        }
        break;
    case HSA_REGION_INFO_SIZE:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            // TODO: report the actual physical size of local memory until API to
            // explicitly unpin memory is available.
            *((size_t*)value) = static_cast<size_t>(GetPhysicalSize());
            break;
        default:
            *((size_t*)value) = static_cast<size_t>(GetVirtualSize());
            break;
        }
        break;
    case HSA_REGION_INFO_ALLOC_MAX_SIZE:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
        case HSA_HEAPTYPE_SYSTEM:
            *((size_t*)value) = max_single_alloc_size_;
            break;
        default:
            *((size_t*)value) = 0;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((bool*)value) = true;
            break;
        default:
            *((bool*)value) = false;
            break;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_GRANULE:
        // TODO: remove the hardcoded value.
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((size_t*)value) = kPageSize_;
            break;
        default:
            *((size_t*)value) = 0;
            break;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_ALIGNMENT:
        // TODO: remove the hardcoded value.
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((size_t*)value) = kPageSize_;
            break;
        default:
            *((size_t*)value) = 0;
            break;
        }
        break;
    default:
        switch ((hsa_amd_region_info_t)attribute) {
        case HSA_AMD_REGION_INFO_HOST_ACCESSIBLE:
            *((bool*)value) =
                (mem_props_.HeapType == HSA_HEAPTYPE_SYSTEM) ? true : false;
            break;
        case HSA_AMD_REGION_INFO_BASE:
            *((void**)value) = reinterpret_cast<void*>(GetBaseAddress());
            break;
        default:
            return HSA_STATUS_ERROR_INVALID_ARGUMENT;
            break;
        }
        break;
    }
    return HSA_STATUS_SUCCESS;
}