diff options
author | David 'Digit' Turner <digit@google.com> | 2009-09-14 14:32:27 -0700 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2009-09-14 14:32:27 -0700 |
commit | 5d8f37ad78fc66901af50c762029a501561f3b23 (patch) | |
tree | 206790f8f21000850a98c4f9590a79e779106278 /cutils.c | |
parent | cd059b15f2c7df69f4a087bd66900eb172e41d1c (diff) | |
download | external_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.zip external_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.tar.gz external_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.tar.bz2 |
Merge upstream QEMU 10.0.50 into the Android source tree.
This change integrates many changes from the upstream QEMU sources.
Its main purpose is to enable correct ARMv6 and ARMv7 support to the
Android emulator. Due to the nature of the upstream code base, this
unfortunately also required changes to many other parts of the source.
Note that to ensure easier integrations in the future, some source files
and directories that have heavy Android-specific customization have been
renamed with an -android suffix. The original files are still there for
easier integration tracking, but *never* compiled. For example:
net.c net-android.c
qemu-char.c qemu-char-android.c
slirp/ slirp-android/
etc...
Tested on linux-x86, darwin-x86 and windows host machines.
Diffstat (limited to 'cutils.c')
-rw-r--r-- | cutils.c | 90 |
1 files changed, 67 insertions, 23 deletions
@@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu-common.h" +#include "host-utils.h" void pstrcpy(char *buf, int buf_size, const char *str) { @@ -72,7 +73,7 @@ int stristart(const char *str, const char *val, const char **ptr) p = str; q = val; while (*q != '\0') { - if (toupper(*p) != toupper(*q)) + if (qemu_toupper(*p) != qemu_toupper(*q)) return 0; p++; q++; @@ -96,42 +97,85 @@ time_t mktimegm(struct tm *tm) return t; } -void *get_mmap_addr(unsigned long size) +int qemu_fls(int i) { - return NULL; + return 32 - clz32(i); } -void qemu_free(void *ptr) +/* io vectors */ + +void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint) +{ + qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec)); + qiov->niov = 0; + qiov->nalloc = alloc_hint; + qiov->size = 0; +} + +void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov) +{ + int i; + + qiov->iov = iov; + qiov->niov = niov; + qiov->nalloc = -1; + qiov->size = 0; + for (i = 0; i < niov; i++) + qiov->size += iov[i].iov_len; +} + +void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len) { - free(ptr); + assert(qiov->nalloc != -1); + + if (qiov->niov == qiov->nalloc) { + qiov->nalloc = 2 * qiov->nalloc + 1; + qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec)); + } + qiov->iov[qiov->niov].iov_base = base; + qiov->iov[qiov->niov].iov_len = len; + qiov->size += len; + ++qiov->niov; } -void *qemu_malloc(size_t size) +void qemu_iovec_destroy(QEMUIOVector *qiov) { - return malloc(size); + assert(qiov->nalloc != -1); + + qemu_free(qiov->iov); } -void *qemu_mallocz(size_t size) +void qemu_iovec_reset(QEMUIOVector *qiov) { - void *ptr; - ptr = qemu_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; + assert(qiov->nalloc != -1); + + qiov->niov = 0; + qiov->size = 0; } -void *qemu_realloc(void* ptr, size_t size) +void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf) { - return realloc(ptr, size); + uint8_t *p = (uint8_t *)buf; + int i; + + for (i = 0; i < qiov->niov; ++i) { + memcpy(p, qiov->iov[i].iov_base, qiov->iov[i].iov_len); + p += qiov->iov[i].iov_len; + } } -char *qemu_strdup(const char *str) +void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count) { - char *ptr; - ptr = qemu_malloc(strlen(str) + 1); - if (!ptr) - return NULL; - strcpy(ptr, str); - return ptr; + const uint8_t *p = (const uint8_t *)buf; + size_t copy; + int i; + + for (i = 0; i < qiov->niov && count; ++i) { + copy = count; + if (copy > qiov->iov[i].iov_len) + copy = qiov->iov[i].iov_len; + memcpy(qiov->iov[i].iov_base, p, copy); + p += copy; + count -= copy; + } } |