示例#1
0
文件: ltp_acpi.c 项目: MohdVara/ltp
static int read_sysfs_file(const char *name, char *buf, int size)
{
	FILE *f = SAFE_FOPEN(cleanup, name, "r");
	char *res = fgets(buf, size, f);
	SAFE_FCLOSE(cleanup, f);
	return (res) ? 0 : 1;
}
示例#2
0
static int read_hugepagesize(void)
{
	FILE *fp;
	char line[BUFSIZ], buf[BUFSIZ];
	int val;

	fp = SAFE_FOPEN(cleanup, PATH_MEMINFO, "r");
	while (fgets(line, BUFSIZ, fp) != NULL) {
		if (sscanf(line, "%64s %d", buf, &val) == 2)
			if (strcmp(buf, "Hugepagesize:") == 0) {
				SAFE_FCLOSE(cleanup, fp);
				return 1024 * val;
			}
	}

	SAFE_FCLOSE(cleanup, fp);
	tst_brkm(TBROK, NULL, "can't find \"%s\" in %s",
			"Hugepagesize:", PATH_MEMINFO);
}
bool SymbolTable::parse(const char * file, bool offsets)
{
    FILE * fd = NULL;
    vaddr_t addr;
    char type;
    char name[128];
    int nr_read;
    vaddr_t text_start = 0, text_end = 0, init_start = 0, init_end = 0;

    if ( NULL == (fd = fopen(file, "r")) )
        return false;

    while ( true )
    {
        nr_read = fscanf(fd, "%" SCNx64 " %c %127s", &addr, &type, name);

        if ( nr_read != 3 )
        {
            if ( feof(fd) )
                break;
            SAFE_FCLOSE(fd);
            return false;
        }

        if ( name[0] == '+' )
        {
            if ( offsets )
            {
                insert_xensym(Abstract::xensyms::xensyms, &name[1], addr);
                insert_xensym(x86_64::xensyms::xensyms, &name[1], addr);
            }
        }
        else
        {
            if ( offsets )
            {
                insert_xensym(Abstract::xensyms::xensyms, name, addr);
                insert_xensym(x86_64::xensyms::xensyms, name, addr);
            }

            if ( ! std::strcmp(name, "_stext") )
                text_start = addr;
            else if ( ! std::strcmp(name, "_etext") )
                text_end = addr;
            else if ( ! std::strcmp(name, "_sinittext") )
                init_start = addr;
            else if ( ! std::strcmp(name, "_einittext") )
                init_end = addr;
            else if ( ! std::strcmp(name, "hypercall_page") )
                this->hypercall_page = addr;

            this->insert( new Symbol(addr, type, name) );
        }
    }

    SAFE_FCLOSE(fd);

    sort();

    if ( text_start == 0 ||
         text_end == 0 ||
         init_start == 0 ||
         init_end == 0 )
    {
        LOG_INFO("Failed to obtain text section limits\n");
        this->can_print = false;
    }
    else
    {
        add_text_region(text_start, text_end);
        add_text_region(init_start, init_end);

        LOG_DEBUG("  text section limits: 0x%016"PRIx64"->0x%016"PRIx64"\n",
                  text_start, text_end);
        LOG_DEBUG("  init section limits: 0x%016"PRIx64"->0x%016"PRIx64"\n",
                  init_start, init_end);
        this->can_print = true;
    }

    if ( this->hypercall_page == 0 )
        this->has_hypercall = false;
    else
    {
        this->has_hypercall = true;
        LOG_DEBUG("  hypercall page:      0x%016"PRIx64"->0x%016"PRIx64"\n",
                  this->hypercall_page, this->hypercall_page+4096);
    }

    return true;
}