BOOLEAN ApIsValidHeader ( ACPI_TABLE_HEADER *Table) { if (!ACPI_VALIDATE_RSDP_SIG (Table->Signature)) { /* Make sure signature is all ASCII and a valid ACPI name */ if (!AcpiUtValidNameseg (Table->Signature)) { fprintf (stderr, "Table signature (0x%8.8X) is invalid\n", *(UINT32 *) Table->Signature); return (FALSE); } /* Check for minimum table length */ if (Table->Length < sizeof (ACPI_TABLE_HEADER)) { fprintf (stderr, "Table length (0x%8.8X) is invalid\n", Table->Length); return (FALSE); } } return (TRUE); }
ACPI_STATUS AcpiTbVerifyTempTable ( ACPI_TABLE_DESC *TableDesc, char *Signature) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (TbVerifyTempTable); /* Validate the table */ Status = AcpiTbValidateTempTable (TableDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (AE_NO_MEMORY); } /* If a particular signature is expected (DSDT/FACS), it must match */ if (Signature && !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature)) { ACPI_BIOS_ERROR ((AE_INFO, "Invalid signature 0x%X for ACPI table, expected [%s]", TableDesc->Signature.Integer, Signature)); Status = AE_BAD_SIGNATURE; goto InvalidateAndExit; } /* Verify the checksum */ if (AcpiGbl_VerifyTableChecksum) { Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, "%4.4s 0x%8.8X%8.8X" " Attempted table install failed", AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? TableDesc->Signature.Ascii : "????", ACPI_FORMAT_UINT64 (TableDesc->Address))); goto InvalidateAndExit; } } return_ACPI_STATUS (AE_OK); InvalidateAndExit: AcpiTbInvalidateTable (TableDesc); return_ACPI_STATUS (Status); }
static BOOLEAN AbValidateHeader ( ACPI_TABLE_HEADER *Header) { if (!AcpiUtValidNameseg (Header->Signature)) { printf ("Header signature is invalid\n"); return (FALSE); } return (TRUE); }
int ApDumpTableFromFile ( char *Pathname) { ACPI_TABLE_HEADER *Table; UINT32 FileSize = 0; int TableStatus = -1; /* Get the entire ACPI table from the file */ Table = ApGetTableFromFile (Pathname, &FileSize); if (!Table) { return (-1); } if (!AcpiUtValidNameseg (Table->Signature)) { fprintf (stderr, "No valid ACPI signature was found in input file %s\n", Pathname); } /* File must be at least as long as the table length */ if (Table->Length > FileSize) { fprintf (stderr, "Table length (0x%X) is too large for input file (0x%X) %s\n", Table->Length, FileSize, Pathname); goto Exit; } if (Gbl_VerboseMode) { fprintf (stderr, "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", Pathname, Table->Signature, FileSize, FileSize); } TableStatus = ApDumpTableBuffer (Table, 0, 0); Exit: ACPI_FREE (Table); return (TableStatus); }
ACPI_STATUS AcValidateTableHeader ( FILE *File, long TableOffset) { ACPI_TABLE_HEADER TableHeader; ACPI_SIZE Actual; long OriginalOffset; UINT32 FileSize; UINT32 i; ACPI_FUNCTION_TRACE (AcValidateTableHeader); /* Read a potential table header */ OriginalOffset = ftell (File); fseek (File, TableOffset, SEEK_SET); Actual = fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), File); fseek (File, OriginalOffset, SEEK_SET); if (Actual < sizeof (ACPI_TABLE_HEADER)) { return (AE_ERROR); } /* Validate the signature (limited ASCII chars) */ if (!AcpiUtValidNameseg (TableHeader.Signature)) { fprintf (stderr, "Invalid table signature: 0x%8.8X\n", *ACPI_CAST_PTR (UINT32, TableHeader.Signature)); return (AE_BAD_SIGNATURE); } /* Validate table length against bytes remaining in the file */ FileSize = CmGetFileSize (File); if (TableHeader.Length > (UINT32) (FileSize - TableOffset)) { fprintf (stderr, "Table [%4.4s] is too long for file - " "needs: 0x%.2X, remaining in file: 0x%.2X\n", TableHeader.Signature, TableHeader.Length, (UINT32) (FileSize - TableOffset)); return (AE_BAD_HEADER); } /* * These fields must be ASCII: OemId, OemTableId, AslCompilerId. * We allow a NULL terminator in OemId and OemTableId. */ for (i = 0; i < ACPI_NAME_SIZE; i++) { if (!ACPI_IS_ASCII ((UINT8) TableHeader.AslCompilerId[i])) { goto BadCharacters; } } for (i = 0; (i < ACPI_OEM_ID_SIZE) && (TableHeader.OemId[i]); i++) { if (!ACPI_IS_ASCII ((UINT8) TableHeader.OemId[i])) { goto BadCharacters; } } for (i = 0; (i < ACPI_OEM_TABLE_ID_SIZE) && (TableHeader.OemTableId[i]); i++) { if (!ACPI_IS_ASCII ((UINT8) TableHeader.OemTableId[i])) { goto BadCharacters; } } return (AE_OK); BadCharacters: ACPI_WARNING ((AE_INFO, "Table header for [%4.4s] has invalid ASCII character(s)", TableHeader.Signature)); return (AE_OK); }
ACPI_STATUS AcpiTbFindTable ( char *Signature, char *OemId, char *OemTableId, UINT32 *TableIndex) { ACPI_STATUS Status = AE_OK; ACPI_TABLE_HEADER Header; UINT32 i; ACPI_FUNCTION_TRACE (TbFindTable); /* Validate the input table signature */ if (!AcpiUtValidNameseg (Signature)) { return_ACPI_STATUS (AE_BAD_SIGNATURE); } /* Don't allow the OEM strings to be too long */ if ((strlen (OemId) > ACPI_OEM_ID_SIZE) || (strlen (OemTableId) > ACPI_OEM_TABLE_ID_SIZE)) { return_ACPI_STATUS (AE_AML_STRING_LIMIT); } /* Normalize the input strings */ memset (&Header, 0, sizeof (ACPI_TABLE_HEADER)); ACPI_MOVE_NAME (Header.Signature, Signature); strncpy (Header.OemId, OemId, ACPI_OEM_ID_SIZE); strncpy (Header.OemTableId, OemTableId, ACPI_OEM_TABLE_ID_SIZE); /* Search for the table */ (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) { if (memcmp (&(AcpiGbl_RootTableList.Tables[i].Signature), Header.Signature, ACPI_NAME_SIZE)) { /* Not the requested table */ continue; } /* Table with matching signature has been found */ if (!AcpiGbl_RootTableList.Tables[i].Pointer) { /* Table is not currently mapped, map it */ Status = AcpiTbValidateTable (&AcpiGbl_RootTableList.Tables[i]); if (ACPI_FAILURE (Status)) { goto UnlockAndExit; } if (!AcpiGbl_RootTableList.Tables[i].Pointer) { continue; } } /* Check for table match on all IDs */ if (!memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->Signature, Header.Signature, ACPI_NAME_SIZE) && (!OemId[0] || !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemId, Header.OemId, ACPI_OEM_ID_SIZE)) && (!OemTableId[0] || !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemTableId, Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE))) { *TableIndex = i; ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n", Header.Signature)); goto UnlockAndExit; } } Status = AE_NOT_FOUND; UnlockAndExit: (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); return_ACPI_STATUS (Status); }
int AxListTables ( char *InputPathname) { FILE *InputFile; size_t HeaderSize; unsigned char Header[48]; ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header; /* Open input in text mode, output is in binary mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open input file %s\n", InputPathname); return (-1); } if (!AxIsFileAscii (InputFile)) { fclose (InputFile); return (-1); } /* Dump the headers for all tables found in the input file */ printf ("\nSignature Length Revision OemId OemTableId" " OemRevision CompilerId CompilerRevision\n\n"); while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { /* Ignore empty lines and lines that start with a space */ if (AxIsEmptyLine (Gbl_LineBuffer) || (Gbl_LineBuffer[0] == ' ')) { continue; } /* Get the 36 byte header and display the fields */ HeaderSize = AxGetTableHeader (InputFile, Header); if (HeaderSize < 16) { continue; } /* RSDP has an oddball signature and header */ if (!strncmp (TableHeader->Signature, "RSD PTR ", 8)) { AxCheckAscii ((char *) &Header[9], 6); printf ("%7.4s \"%6.6s\"\n", "RSDP", &Header[9]); Gbl_TableCount++; continue; } /* Minimum size for table with standard header */ if (HeaderSize < sizeof (ACPI_TABLE_HEADER)) { continue; } if (!AcpiUtValidNameseg (TableHeader->Signature)) { continue; } /* Signature and Table length */ Gbl_TableCount++; printf ("%7.4s 0x%8.8X", TableHeader->Signature, TableHeader->Length); /* FACS has only signature and length */ if (ACPI_COMPARE_NAME (TableHeader->Signature, "FACS")) { printf ("\n"); continue; } /* OEM IDs and Compiler IDs */ AxCheckAscii (TableHeader->OemId, 6); AxCheckAscii (TableHeader->OemTableId, 8); AxCheckAscii (TableHeader->AslCompilerId, 4); printf ( " 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X" " \"%4.4s\" 0x%8.8X\n", TableHeader->Revision, TableHeader->OemId, TableHeader->OemTableId, TableHeader->OemRevision, TableHeader->AslCompilerId, TableHeader->AslCompilerRevision); } printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname); fclose (InputFile); return (0); }
static ACPI_STATUS AcpiDbIntegrityWalk ( ACPI_HANDLE ObjHandle, UINT32 NestingLevel, void *Context, void **ReturnValue) { ACPI_INTEGRITY_INFO *Info = (ACPI_INTEGRITY_INFO *) Context; ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; ACPI_OPERAND_OBJECT *Object; BOOLEAN Alias = TRUE; Info->Nodes++; /* Verify the NS node, and dereference aliases */ while (Alias) { if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED) { AcpiOsPrintf ( "Invalid Descriptor Type for Node %p [%s] - " "is %2.2X should be %2.2X\n", Node, AcpiUtGetDescriptorName (Node), ACPI_GET_DESCRIPTOR_TYPE (Node), ACPI_DESC_TYPE_NAMED); return (AE_OK); } if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS) || (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { Node = (ACPI_NAMESPACE_NODE *) Node->Object; } else { Alias = FALSE; } } if (Node->Type > ACPI_TYPE_LOCAL_MAX) { AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n", Node, Node->Type); return (AE_OK); } if (!AcpiUtValidNameseg (Node->Name.Ascii)) { AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node); return (AE_OK); } Object = AcpiNsGetAttachedObject (Node); if (Object) { Info->Objects++; if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND) { AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n", Object, AcpiUtGetDescriptorName (Object)); } } return (AE_OK); }
ACPI_STATUS AcpiTbVerifyTempTable ( ACPI_TABLE_DESC *TableDesc, char *Signature, UINT32 *TableIndex) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (TbVerifyTempTable); /* Validate the table */ Status = AcpiTbValidateTempTable (TableDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (AE_NO_MEMORY); } /* If a particular signature is expected (DSDT/FACS), it must match */ if (Signature && !ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature)) { ACPI_BIOS_ERROR ((AE_INFO, "Invalid signature 0x%X for ACPI table, expected [%s]", TableDesc->Signature.Integer, Signature)); Status = AE_BAD_SIGNATURE; goto InvalidateAndExit; } if (AcpiGbl_EnableTableValidation) { /* Verify the checksum */ Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, "%4.4s 0x%8.8X%8.8X" " Attempted table install failed", AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? TableDesc->Signature.Ascii : "????", ACPI_FORMAT_UINT64 (TableDesc->Address))); goto InvalidateAndExit; } /* Avoid duplications */ if (TableIndex) { Status = AcpiTbCheckDuplication (TableDesc, TableIndex); if (ACPI_FAILURE (Status)) { if (Status != AE_CTRL_TERMINATE) { ACPI_EXCEPTION ((AE_INFO, Status, "%4.4s 0x%8.8X%8.8X" " Table is already loaded", AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? TableDesc->Signature.Ascii : "????", ACPI_FORMAT_UINT64 (TableDesc->Address))); } goto InvalidateAndExit; } } TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED; } return_ACPI_STATUS (Status); InvalidateAndExit: AcpiTbInvalidateTable (TableDesc); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiTbInstallStandardTable ( ACPI_PHYSICAL_ADDRESS Address, UINT8 Flags, BOOLEAN Reload, BOOLEAN Override, UINT32 *TableIndex) { UINT32 i; ACPI_STATUS Status = AE_OK; ACPI_TABLE_DESC NewTableDesc; ACPI_FUNCTION_TRACE (TbInstallStandardTable); /* Acquire a temporary table descriptor for validation */ Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags); if (ACPI_FAILURE (Status)) { ACPI_ERROR ((AE_INFO, "Could not acquire table length at %8.8X%8.8X", ACPI_FORMAT_UINT64 (Address))); return_ACPI_STATUS (Status); } /* * Optionally do not load any SSDTs from the RSDT/XSDT. This can * be useful for debugging ACPI problems on some machines. */ if (!Reload && AcpiGbl_DisableSsdtTableInstall && ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) { ACPI_INFO (( "Ignoring installation of %4.4s at %8.8X%8.8X", NewTableDesc.Signature.Ascii, ACPI_FORMAT_UINT64 (Address))); goto ReleaseAndExit; } /* Validate and verify a table before installation */ Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL); if (ACPI_FAILURE (Status)) { goto ReleaseAndExit; } if (Reload) { /* * Validate the incoming table signature. * * 1) Originally, we checked the table signature for "SSDT" or "PSDT". * 2) We added support for OEMx tables, signature "OEM". * 3) Valid tables were encountered with a null signature, so we just * gave up on validating the signature, (05/2008). * 4) We encountered non-AML tables such as the MADT, which caused * interpreter errors and kernel faults. So now, we once again allow * only "SSDT", "OEMx", and now, also a null signature. (05/2011). */ if ((NewTableDesc.Signature.Ascii[0] != 0x00) && (!ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) && (strncmp (NewTableDesc.Signature.Ascii, "OEM", 3))) { ACPI_BIOS_ERROR ((AE_INFO, "Table has invalid signature [%4.4s] (0x%8.8X), " "must be SSDT or OEMx", AcpiUtValidNameseg (NewTableDesc.Signature.Ascii) ? NewTableDesc.Signature.Ascii : "????", NewTableDesc.Signature.Integer)); Status = AE_BAD_SIGNATURE; goto ReleaseAndExit; } /* Check if table is already registered */ for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) { /* * Check for a table match on the entire table length, * not just the header. */ if (!AcpiTbCompareTables (&NewTableDesc, i)) { continue; } /* * Note: the current mechanism does not unregister a table if it is * dynamically unloaded. The related namespace entries are deleted, * but the table remains in the root table list. * * The assumption here is that the number of different tables that * will be loaded is actually small, and there is minimal overhead * in just keeping the table in case it is needed again. * * If this assumption changes in the future (perhaps on large * machines with many table load/unload operations), tables will * need to be unregistered when they are unloaded, and slots in the * root table list should be reused when empty. */ if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED) { /* Table is still loaded, this is an error */ Status = AE_ALREADY_EXISTS; goto ReleaseAndExit; } else { /* * Table was unloaded, allow it to be reloaded. * As we are going to return AE_OK to the caller, we should * take the responsibility of freeing the input descriptor. * Refill the input descriptor to ensure * AcpiTbInstallTableWithOverride() can be called again to * indicate the re-installation. */ AcpiTbUninstallTable (&NewTableDesc); *TableIndex = i; return_ACPI_STATUS (AE_OK); } } } /* Add the table to the global root table list */ AcpiTbInstallTableWithOverride (&NewTableDesc, Override, TableIndex); ReleaseAndExit: /* Release the temporary table descriptor */ AcpiTbReleaseTempTable (&NewTableDesc); return_ACPI_STATUS (Status); }