int acpi_table_add(const char *t)

{

    static const char *dfl_id = "QEMUQEMU";

    char buf[1024], *p, *f;

    struct acpi_table_header acpi_hdr;

    unsigned long val;

    uint32_t length;

    struct acpi_table_header *acpi_hdr_p;

    size_t off;



    memset(&acpi_hdr, 0, sizeof(acpi_hdr));

  

    if (get_param_value(buf, sizeof(buf), "sig", t)) {

        strncpy(acpi_hdr.signature, buf, 4);

    } else {

        strncpy(acpi_hdr.signature, dfl_id, 4);

    }

    if (get_param_value(buf, sizeof(buf), "rev", t)) {

        val = strtoul(buf, &p, 10);

        if (val > 255 || *p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.revision = (int8_t)val;



    if (get_param_value(buf, sizeof(buf), "oem_id", t)) {

        strncpy(acpi_hdr.oem_id, buf, 6);

    } else {

        strncpy(acpi_hdr.oem_id, dfl_id, 6);

    }



    if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {

        strncpy(acpi_hdr.oem_table_id, buf, 8);

    } else {

        strncpy(acpi_hdr.oem_table_id, dfl_id, 8);

    }



    if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {

        val = strtol(buf, &p, 10);

        if(*p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.oem_revision = cpu_to_le32(val);



    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {

        strncpy(acpi_hdr.asl_compiler_id, buf, 4);

    } else {

        strncpy(acpi_hdr.asl_compiler_id, dfl_id, 4);

    }



    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {

        val = strtol(buf, &p, 10);

        if(*p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.asl_compiler_revision = cpu_to_le32(val);

    

    if (!get_param_value(buf, sizeof(buf), "data", t)) {

         buf[0] = '\0';

    }



    length = sizeof(acpi_hdr);



    f = buf;

    while (buf[0]) {

        struct stat s;

        char *n = strchr(f, ':');

        if (n)

            *n = '\0';

        if(stat(f, &s) < 0) {

            fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno));

            goto out;

        }

        length += s.st_size;

        if (!n)

            break;

        *n = ':';

        f = n + 1;

    }



    if (!acpi_tables) {

        acpi_tables_len = sizeof(uint16_t);

        acpi_tables = qemu_mallocz(acpi_tables_len);

    }

    acpi_tables = qemu_realloc(acpi_tables,

                               acpi_tables_len + sizeof(uint16_t) + length);

    p = acpi_tables + acpi_tables_len;

    acpi_tables_len += sizeof(uint16_t) + length;



    *(uint16_t*)p = cpu_to_le32(length);

    p += sizeof(uint16_t);

    memcpy(p, &acpi_hdr, sizeof(acpi_hdr));

    off = sizeof(acpi_hdr);



    f = buf;

    while (buf[0]) {

        struct stat s;

        int fd;

        char *n = strchr(f, ':');

        if (n)

            *n = '\0';

        fd = open(f, O_RDONLY);



        if(fd < 0)

            goto out;

        if(fstat(fd, &s) < 0) {

            close(fd);

            goto out;

        }



        /* off < length is necessary because file size can be changed

           under our foot */

        while(s.st_size && off < length) {

            int r;

            r = read(fd, p + off, s.st_size);

            if (r > 0) {

                off += r;

                s.st_size -= r;

            } else if ((r < 0 && errno != EINTR) || r == 0) {

                close(fd);

                goto out;

            }

        }



        close(fd);

        if (!n)

            break;

        f = n + 1;

    }

    if (off < length) {

        /* don't pass random value in process to guest */

        memset(p + off, 0, length - off);

    }



    acpi_hdr_p = (struct acpi_table_header*)p;

    acpi_hdr_p->length = cpu_to_le32(length);

    acpi_hdr_p->checksum = acpi_checksum((uint8_t*)p, length);

    /* increase number of tables */

    (*(uint16_t*)acpi_tables) =

	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);

    return 0;

out:

    if (acpi_tables) {

        qemu_free(acpi_tables);

        acpi_tables = NULL;

    }

    return -1;

}

int acpi_table_add(const char *t)

{

    static const char *dfl_id = "QEMUQEMU";

    char buf[1024], *p, *f;

    struct acpi_table_header acpi_hdr;

    unsigned long val;

    uint32_t length;

    struct acpi_table_header *acpi_hdr_p;

    size_t off;



    memset(&acpi_hdr, 0, sizeof(acpi_hdr));

  

    if (get_param_value(buf, sizeof(buf), "sig", t)) {

        strncpy(acpi_hdr.signature, buf, 4);

    } else {

        strncpy(acpi_hdr.signature, dfl_id, 4);

    }

    if (get_param_value(buf, sizeof(buf), "rev", t)) {

        val = strtoul(buf, &p, 10);

        if (val > 255 || *p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.revision = (int8_t)val;



    if (get_param_value(buf, sizeof(buf), "oem_id", t)) {

        strncpy(acpi_hdr.oem_id, buf, 6);

    } else {

        strncpy(acpi_hdr.oem_id, dfl_id, 6);

    }



    if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {

        strncpy(acpi_hdr.oem_table_id, buf, 8);

    } else {

        strncpy(acpi_hdr.oem_table_id, dfl_id, 8);

    }



    if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {

        val = strtol(buf, &p, 10);

        if(*p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.oem_revision = cpu_to_le32(val);



    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {

        strncpy(acpi_hdr.asl_compiler_id, buf, 4);

    } else {

        strncpy(acpi_hdr.asl_compiler_id, dfl_id, 4);

    }



    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {

        val = strtol(buf, &p, 10);

        if(*p != '\0')

            goto out;

    } else {

        val = 1;

    }

    acpi_hdr.asl_compiler_revision = cpu_to_le32(val);

    

    if (!get_param_value(buf, sizeof(buf), "data", t)) {

         buf[0] = '\0';

    }



    length = sizeof(acpi_hdr);



    f = buf;

    while (buf[0]) {

        struct stat s;

        char *n = strchr(f, ':');

        if (n)

            *n = '\0';

        if(stat(f, &s) < 0) {

            fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno));

            goto out;

        }

        length += s.st_size;

        if (!n)

            break;

        *n = ':';

        f = n + 1;

    }



    if (!acpi_tables) {

        acpi_tables_len = sizeof(uint16_t);

        acpi_tables = qemu_mallocz(acpi_tables_len);

    }

    acpi_tables = qemu_realloc(acpi_tables,

                               acpi_tables_len + sizeof(uint16_t) + length);

    p = acpi_tables + acpi_tables_len;

    acpi_tables_len += sizeof(uint16_t) + length;



    *(uint16_t*)p = cpu_to_le32(length);

    p += sizeof(uint16_t);

    memcpy(p, &acpi_hdr, sizeof(acpi_hdr));

    off = sizeof(acpi_hdr);



    f = buf;

    while (buf[0]) {

        struct stat s;

        int fd;

        char *n = strchr(f, ':');

        if (n)

            *n = '\0';

        fd = open(f, O_RDONLY);



        if(fd < 0)

            goto out;

        if(fstat(fd, &s) < 0) {

            close(fd);

            goto out;

        }



        



        while(s.st_size && off < length) {

            int r;

            r = read(fd, p + off, s.st_size);

            if (r > 0) {

                off += r;

                s.st_size -= r;

            } else if ((r < 0 && errno != EINTR) || r == 0) {

                close(fd);

                goto out;

            }

        }



        close(fd);

        if (!n)

            break;

        f = n + 1;

    }

    if (off < length) {

        

        memset(p + off, 0, length - off);

    }



    acpi_hdr_p = (struct acpi_table_header*)p;

    acpi_hdr_p->length = cpu_to_le32(length);

    acpi_hdr_p->checksum = acpi_checksum((uint8_t*)p, length);

    

    (*(uint16_t*)acpi_tables) =

	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);

    return 0;

out:

    if (acpi_tables) {

        qemu_free(acpi_tables);

        acpi_tables = NULL;

    }

    return -1;

}

int FUNC_0(const char *VAR_0)

{

    static const char *VAR_1 = "QEMUQEMU";

    char VAR_2[1024], *VAR_3, *VAR_4;

    struct acpi_table_header VAR_5;

    unsigned long VAR_6;

    uint32_t length;

    struct acpi_table_header *VAR_7;

    size_t off;



    memset(&VAR_5, 0, sizeof(VAR_5));

  

    if (get_param_value(VAR_2, sizeof(VAR_2), "sig", VAR_0)) {

        strncpy(VAR_5.signature, VAR_2, 4);

    } else {

        strncpy(VAR_5.signature, VAR_1, 4);

    }

    if (get_param_value(VAR_2, sizeof(VAR_2), "rev", VAR_0)) {

        VAR_6 = strtoul(VAR_2, &VAR_3, 10);

        if (VAR_6 > 255 || *VAR_3 != '\0')

            goto out;

    } else {

        VAR_6 = 1;

    }

    VAR_5.revision = (int8_t)VAR_6;



    if (get_param_value(VAR_2, sizeof(VAR_2), "oem_id", VAR_0)) {

        strncpy(VAR_5.oem_id, VAR_2, 6);

    } else {

        strncpy(VAR_5.oem_id, VAR_1, 6);

    }



    if (get_param_value(VAR_2, sizeof(VAR_2), "oem_table_id", VAR_0)) {

        strncpy(VAR_5.oem_table_id, VAR_2, 8);

    } else {

        strncpy(VAR_5.oem_table_id, VAR_1, 8);

    }



    if (get_param_value(VAR_2, sizeof(VAR_2), "oem_rev", VAR_0)) {

        VAR_6 = strtol(VAR_2, &VAR_3, 10);

        if(*VAR_3 != '\0')

            goto out;

    } else {

        VAR_6 = 1;

    }

    VAR_5.oem_revision = cpu_to_le32(VAR_6);



    if (get_param_value(VAR_2, sizeof(VAR_2), "asl_compiler_id", VAR_0)) {

        strncpy(VAR_5.asl_compiler_id, VAR_2, 4);

    } else {

        strncpy(VAR_5.asl_compiler_id, VAR_1, 4);

    }



    if (get_param_value(VAR_2, sizeof(VAR_2), "asl_compiler_rev", VAR_0)) {

        VAR_6 = strtol(VAR_2, &VAR_3, 10);

        if(*VAR_3 != '\0')

            goto out;

    } else {

        VAR_6 = 1;

    }

    VAR_5.asl_compiler_revision = cpu_to_le32(VAR_6);

    

    if (!get_param_value(VAR_2, sizeof(VAR_2), "data", VAR_0)) {

         VAR_2[0] = '\0';

    }



    length = sizeof(VAR_5);



    VAR_4 = VAR_2;

    while (VAR_2[0]) {

        struct stat VAR_10;

        char *VAR_11 = strchr(VAR_4, ':');

        if (VAR_11)

            *VAR_11 = '\0';

        if(stat(VAR_4, &VAR_10) < 0) {

            fprintf(stderr, "Can'VAR_0 stat file '%VAR_10': %VAR_10\VAR_11", VAR_4, strerror(errno));

            goto out;

        }

        length += VAR_10.st_size;

        if (!VAR_11)

            break;

        *VAR_11 = ':';

        VAR_4 = VAR_11 + 1;

    }



    if (!acpi_tables) {

        acpi_tables_len = sizeof(uint16_t);

        acpi_tables = qemu_mallocz(acpi_tables_len);

    }

    acpi_tables = qemu_realloc(acpi_tables,

                               acpi_tables_len + sizeof(uint16_t) + length);

    VAR_3 = acpi_tables + acpi_tables_len;

    acpi_tables_len += sizeof(uint16_t) + length;



    *(uint16_t*)VAR_3 = cpu_to_le32(length);

    VAR_3 += sizeof(uint16_t);

    memcpy(VAR_3, &VAR_5, sizeof(VAR_5));

    off = sizeof(VAR_5);



    VAR_4 = VAR_2;

    while (VAR_2[0]) {

        struct stat VAR_10;

        int VAR_10;

        char *VAR_11 = strchr(VAR_4, ':');

        if (VAR_11)

            *VAR_11 = '\0';

        VAR_10 = open(VAR_4, O_RDONLY);



        if(VAR_10 < 0)

            goto out;

        if(fstat(VAR_10, &VAR_10) < 0) {

            close(VAR_10);

            goto out;

        }



        



        while(VAR_10.st_size && off < length) {

            int VAR_11;

            VAR_11 = read(VAR_10, VAR_3 + off, VAR_10.st_size);

            if (VAR_11 > 0) {

                off += VAR_11;

                VAR_10.st_size -= VAR_11;

            } else if ((VAR_11 < 0 && errno != EINTR) || VAR_11 == 0) {

                close(VAR_10);

                goto out;

            }

        }



        close(VAR_10);

        if (!VAR_11)

            break;

        VAR_4 = VAR_11 + 1;

    }

    if (off < length) {

        

        memset(VAR_3 + off, 0, length - off);

    }



    VAR_7 = (struct acpi_table_header*)VAR_3;

    VAR_7->length = cpu_to_le32(length);

    VAR_7->checksum = acpi_checksum((uint8_t*)VAR_3, length);

    

    (*(uint16_t*)acpi_tables) =

	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);

    return 0;

out:

    if (acpi_tables) {

        qemu_free(acpi_tables);

        acpi_tables = NULL;

    }

    return -1;

}

int FUNC_0(const char *VAR_0)
{ static const char *VAR_1 = "QEMUQEMU"; char VAR_2[1024], *VAR_3, *VAR_4; struct acpi_table_header VAR_5; unsigned long VAR_6; uint32_t length; struct acpi_table_header *VAR_7; size_t off; memset(&VAR_5, 0, sizeof(VAR_5)); if (get_param_value(VAR_2, sizeof(VAR_2), "sig", VAR_0)) { strncpy(VAR_5.signature, VAR_2, 4); } else { strncpy(VAR_5.signature, VAR_1, 4); } if (get_param_value(VAR_2, sizeof(VAR_2), "rev", VAR_0)) { VAR_6 = strtoul(VAR_2, &VAR_3, 10); if (VAR_6 > 255 || *VAR_3 != '\0')
goto out; } else { VAR_6 = 1; } VAR_5.revision = (int8_t)VAR_6; if (get_param_value(VAR_2, sizeof(VAR_2), "oem_id", VAR_0)) { strncpy(VAR_5.oem_id, VAR_2, 6); } else { strncpy(VAR_5.oem_id, VAR_1, 6); } if (get_param_value(VAR_2, sizeof(VAR_2), "oem_table_id", VAR_0)) { strncpy(VAR_5.oem_table_id, VAR_2, 8); } else { strncpy(VAR_5.oem_table_id, VAR_1, 8); } if (get_param_value(VAR_2, sizeof(VAR_2), "oem_rev", VAR_0)) { VAR_6 = strtol(VAR_2, &VAR_3, 10); if(*VAR_3 != '\0')
goto out; } else { VAR_6 = 1; } VAR_5.oem_revision = cpu_to_le32(VAR_6); if (get_param_value(VAR_2, sizeof(VAR_2), "asl_compiler_id", VAR_0)) { strncpy(VAR_5.asl_compiler_id, VAR_2, 4); } else { strncpy(VAR_5.asl_compiler_id, VAR_1, 4); } if (get_param_value(VAR_2, sizeof(VAR_2), "asl_compiler_rev", VAR_0)) { VAR_6 = strtol(VAR_2, &VAR_3, 10); if(*VAR_3 != '\0')
goto out; } else { VAR_6 = 1; } VAR_5.asl_compiler_revision = cpu_to_le32(VAR_6); if (!get_param_value(VAR_2, sizeof(VAR_2), "data", VAR_0)) { VAR_2[0] = '\0'; } length = sizeof(VAR_5); VAR_4 = VAR_2; while (VAR_2[0]) { struct stat VAR_10; char *VAR_11 = strchr(VAR_4, ':'); if (VAR_11)
*VAR_11 = '\0'; if(stat(VAR_4, &VAR_10) < 0) { fprintf(stderr, "Can'VAR_0 stat file '%VAR_10': %VAR_10\VAR_11", VAR_4, strerror(errno)); goto out; } length += VAR_10.st_size; if (!VAR_11)
break; *VAR_11 = ':'; VAR_4 = VAR_11 + 1; } if (!acpi_tables) { acpi_tables_len = sizeof(uint16_t); acpi_tables = qemu_mallocz(acpi_tables_len); } acpi_tables = qemu_realloc(acpi_tables,
acpi_tables_len + sizeof(uint16_t) + length); VAR_3 = acpi_tables + acpi_tables_len; acpi_tables_len += sizeof(uint16_t) + length; *(uint16_t*)VAR_3 = cpu_to_le32(length); VAR_3 += sizeof(uint16_t); memcpy(VAR_3, &VAR_5, sizeof(VAR_5)); off = sizeof(VAR_5); VAR_4 = VAR_2; while (VAR_2[0]) { struct stat VAR_10; int VAR_10; char *VAR_11 = strchr(VAR_4, ':'); if (VAR_11)
*VAR_11 = '\0'; VAR_10 = open(VAR_4, O_RDONLY); if(VAR_10 < 0)
goto out; if(fstat(VAR_10, &VAR_10) < 0) { close(VAR_10); goto out; } while(VAR_10.st_size && off < length) { int VAR_11; VAR_11 = read(VAR_10, VAR_3 + off, VAR_10.st_size); if (VAR_11 > 0) { off += VAR_11; VAR_10.st_size -= VAR_11; } else if ((VAR_11 < 0 && errno != EINTR) || VAR_11 == 0) { close(VAR_10); goto out; } } close(VAR_10); if (!VAR_11)
break; VAR_4 = VAR_11 + 1; } if (off < length) { memset(VAR_3 + off, 0, length - off); } VAR_7 = (struct acpi_table_header*)VAR_3; VAR_7->length = cpu_to_le32(length); VAR_7->checksum = acpi_checksum((uint8_t*)VAR_3, length); (*(uint16_t*)acpi_tables) =
cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1); return 0; out:
if (acpi_tables) { qemu_free(acpi_tables); acpi_tables = NULL; } return -1; }