Example #1
0
int read_hypervisor_dmi(void)
{
	int rc = HYPER_NONE;
	uint8_t *buf = NULL;
	size_t fp = 0;

	if (sizeof(uint8_t) != 1
	    || sizeof(uint16_t) != 2
	    || sizeof(uint32_t) != 4
	    || '\0' != 0)
		return rc;

	rc = hypervisor_decode_sysfw();
	if (rc >= 0)
		return rc;

	/* First try EFI (ia64, Intel-based Mac) */
	switch (address_from_efi(&fp)) {
		case EFI_NOT_FOUND:
			goto memory_scan;
		case EFI_NO_SMBIOS:
			goto done;
	}

	buf = get_mem_chunk(fp, 0x20, _PATH_DEV_MEM);
	if (!buf)
		goto done;

	rc = hypervisor_decode_smbios(buf, _PATH_DEV_MEM);
	if (rc)
		goto done;
	free(buf);
	buf = NULL;
memory_scan:
#if defined(__x86_64__) || defined(__i386__)
	/* Fallback to memory scan (x86, x86_64) */
	buf = get_mem_chunk(0xF0000, 0x10000, _PATH_DEV_MEM);
	if (!buf)
		goto done;

	for (fp = 0; fp <= 0xFFF0; fp += 16) {
		if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
			rc = hypervisor_decode_smbios(buf + fp, _PATH_DEV_MEM);
			if (rc == -1)
				fp += 16;

		} else if (memcmp(buf + fp, "_DMI_", 5) == 0)
			rc = hypervisor_decode_legacy(buf + fp, _PATH_DEV_MEM);

		if (rc >= 0)
			break;
	}
#endif
done:
	free(buf);
	return rc;
}
Example #2
0
/*
 *  Function:
 *     InitSMBIOS
 *
 *  Description:
 *     Initializes the SMBIOS tables by reading physical memory.  All records
 *     are read in at once, and parsed later.
 *
 *  Return:
 *     1 if inited correctly; 0 otherwise
 */
int InitSMBIOS() {
    u_char * pBuf = NULL;
    size_t fp, count;
    u_char* p;
    int efi;

    SMBIOSEntryPoint *pEPS = NULL;

    if ((pBuf = malloc(SMBIOS_EPS_SCAN_SIZE)) == NULL)
        return fSMBiosInited;

    /* First try EFI (ia64, Intel-based Mac) */
    if ((efi = address_from_efi("SMBIOS", &fp)) >= 0) {
        count = 0x20;
    } else {
        if (efi == EFI_NO_SECTION) {
            free(pBuf);
            return 0;
        }

        count = SMBIOS_EPS_SCAN_SIZE;
        fp = SMBIOS_EPS_ADDR_START;
    }


    if (ReadPhysMem(fp, count, pBuf)) {

        /* scan 0xF0000 through 0xFFFFF for an EPS (Entry Point Structure) */
        for (p = pBuf; p < pBuf + SMBIOS_EPS_SCAN_SIZE;
                p += SMBIOS_EPS_BOUNDRY) {
            /* check for a possible EPS.
             * we look for a valid signature and checksum */
            pEPS = (SMBIOSEntryPoint *) p;
            if ((strncmp((const char *)pEPS->sAnchorString,
                         SMBIOS_ANCHOR_STRING,
                         sizeof(pEPS->sAnchorString))) ||
                    (SmbChecksum((u_char*) pEPS, pEPS->byEPSLength)) ||
                    (((pEPS->byMajorVer << 8) + pEPS->byMinorVer) < 0x0201))
                continue;

            /* we have found a valid EPS (entry point structure) */
            memcpy(&EPS, pEPS, sizeof(EPS));
            if ((pSMBTables = malloc(EPS.wSTLength)) != NULL) {
                if (ReadPhysMem(EPS.dwSTAddr, EPS.wSTLength, pSMBTables))
                    fSMBiosInited = 1;
            }
            break;
        }
    }
    free(pBuf);
    return fSMBiosInited;
}
Example #3
0
int read_hypervisor_dmi(void)
{
	int ret = HYPER_NONE;
	uint8_t *buf = NULL;
	size_t fp = 0;

	if (sizeof(uint8_t) != 1
	    || sizeof(uint16_t) != 2
	    || sizeof(uint32_t) != 4
	    || '\0' != 0)
		return ret;

	/* First try EFI (ia64, Intel-based Mac) */
	switch (address_from_efi(&fp)) {
		case EFI_NOT_FOUND:
			goto memory_scan;
		case EFI_NO_SMBIOS:
			goto exit_free;
	}

	buf = get_mem_chunk(fp, 0x20, _PATH_DEV_MEM);
	if (!buf)
		goto exit_free;

	if (hypervisor_decode_smbios(buf, _PATH_DEV_MEM))
		goto done;

memory_scan:
	/* Fallback to memory scan (x86, x86_64) */
	buf = get_mem_chunk(0xF0000, 0x10000, _PATH_DEV_MEM);
	if (!buf)
		goto exit_free;

	for (fp = 0; fp <= 0xFFF0; fp += 16) {
		if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
			if ((ret = hypervisor_decode_smbios(buf + fp,
						 _PATH_DEV_MEM)) == -1)
				fp += 16;

		} else if (memcmp(buf + fp, "_DMI_", 5) == 0)
			ret = hypervisor_decode_legacy(buf + fp, _PATH_DEV_MEM);
	}

done:
	free(buf);
exit_free:
	return ret;
}
Example #4
0
int dump(const char *memdev, const char *dumpfile)
{
        /* On success, return found, otherwise return -1 */
        int ret = 0;
        int found = 0;
        size_t fp;
        int efi;
        u8 *buf;

        /* First try EFI (ia64, Intel-based Mac) */
        efi = address_from_efi(NULL, &fp);
        if(efi == EFI_NOT_FOUND) {
                /* Fallback to memory scan (x86, x86_64) */
                if((buf = mem_chunk(NULL, 0xF0000, 0x10000, memdev)) != NULL) {
                        for(fp = 0; fp <= 0xFFF0; fp += 16) {
                                if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
                                        if(dumpling(buf + fp, dumpfile, NON_LEGACY))
                                                found++;
                                        fp += 16;
                                } else if(memcmp(buf + fp, "_DMI_", 5) == 0) {
                                        if(dumpling(buf + fp, dumpfile, LEGACY))
                                                found++;
                                }
                        }
                } else
                        ret = -1;
        } else if(efi == EFI_NO_SMBIOS) {
                ret = -1;
        } else {
                if((buf = mem_chunk(NULL, fp, 0x20, memdev)) == NULL)
                        ret = -1;
                else if(dumpling(buf, dumpfile, NON_LEGACY))
                        found++;
        }

        if(ret == 0) {
                free(buf);
                if(!found) {
                        ret = -1;
                }
        }

        return ret == 0 ? found : ret;
}