MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / PatchAllTables

Function PatchAllTables

rEFIt_UEFI/Platform/AcpiPatcher.cpp:404–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404VOID PatchAllTables()
405{
406 UINT32 Count = XsdtTableCount();
407 UINT64* Ptr = XsdtEntryPtrFromIndex(0);
408 UINT64* EndPtr = XsdtEntryPtrFromIndex(Count);
409 for (; Ptr < EndPtr; Ptr++) {
410 BOOLEAN Patched = FALSE;
411 EFI_ACPI_DESCRIPTION_HEADER* Table = (EFI_ACPI_DESCRIPTION_HEADER*)(UINTN)ReadUnaligned64(Ptr);
412 if (!Table) {
413 // skip NULL entry
414 continue;
415 }
416 if (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE == Table->Signature) {
417 // may be also EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE?
418 continue; // will be patched elsewhere
419 }
420
421 //do new table with patched header
422 UINT32 Len = Table->Length;
423 EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;
424 EFI_STATUS Status = gBS->AllocatePages(AllocateMaxAddress,
425 EfiACPIReclaimMemory,
426 EFI_SIZE_TO_PAGES(Len + 4096),
427 &BufferPtr);
428 if(EFI_ERROR(Status)) {
429 //DBG(" ... not patched\n");
430 continue;
431 }
432 EFI_ACPI_DESCRIPTION_HEADER* NewTable = (EFI_ACPI_DESCRIPTION_HEADER*)(UINTN)BufferPtr;
433 CopyMem(NewTable, Table, Len);
434 if ((gSettings.FixDsdt & FIX_HEADERS) || gSettings.FixHeaders) {
435 // Merged tables already have the header patched, so no need to do it again
436 if (!IsXsdtEntryMerged(IndexFromXsdtEntryPtr(Ptr))) {
437 // table header NOT already patched
438 Patched = PatchTableHeader(NewTable);
439 }
440 }
441 if (NewTable->Signature == EFI_ACPI_4_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
442 if (gSettings.DSDTPatchArray.size() > 0) {
443 DBG("Patching SSDTs: %zu patches each\n", gSettings.DSDTPatchArray.size());
444
445// CHAR8 OTID[9];
446// OTID[8] = 0;
447// CopyMem(OTID, &NewTable->OemTableId, 8);
448// DBG("Patching SSDT %s Length=%d\n", OTID, (INT32)Len);
449
450 for (UINT32 i = 0; i < gSettings.DSDTPatchArray.size(); i++) {
451 if ( gSettings.DSDTPatchArray[i].PatchDsdtFind.isEmpty() ) {
452 continue;
453 }
454// DBG("%d. [%s]:", i, gSettings.PatchDsdtLabel[i]);
455 if (!gSettings.DSDTPatchArray[i].PatchDsdtMenuItem.BValue) {
456// DBG(" disabled\n");
457 continue;
458 }
459 if ( gSettings.DSDTPatchArray[i].PatchDsdtTgt.isEmpty() ) {
460 Len = FixAny((UINT8*)NewTable, Len,
461 gSettings.DSDTPatchArray[i].PatchDsdtFind,

Callers 1

PatchACPIFunction · 0.85

Calls 12

IsXsdtEntryMergedFunction · 0.85
PatchTableHeaderFunction · 0.85
FixAnyFunction · 0.85
FixRenameByBridge2Function · 0.85
RenameDevicesFunction · 0.85
GetBiosRegionsFunction · 0.85
FixChecksumFunction · 0.85
ReadUnaligned64Function · 0.50
CopyMemFunction · 0.50
WriteUnaligned64Function · 0.50
sizeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected