Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
2015-09-16 16:09 GMT+08:00 Paolo Bonzini: > > >> >> I'll modify the bionic C library to support these functions and feedback >> to google's AOSP project. But the android kernel does not support shmem, > > It doesn't support tmpfs? /dev/shm is just a tmpfs. > > Paolo Oh, you are right. The android have shmget, shmat, shmdt functions in their libc. The POSIX shm_open can built on top of these. I'll fix my libc to support posix share memory functions. -- Best regards, Houcheng Lin -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
2015-09-16 17:38 GMT+08:00 Paolo Bonzini: > > Actually it's even simpler. shm_open is basically just > > char *s; > int fd; > > asprintf(, "/dev/shm/%s", name); > fd = open(s, name | O_CLOEXEC, mode); > free(s); > return fd; > > plus some error checking. Do Android systems have /dev/shm? > > Paolo It's simple, thanks. The android have no /dev/shm. Though we can mknod it but need root prividlege to do it. -- Best regards, Houcheng Lin -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
On 16/09/2015 11:28, Houcheng Lin wrote: > 2015-09-16 16:09 GMT+08:00 Paolo Bonzini: >> >> >>> >>> I'll modify the bionic C library to support these functions and feedback >>> to google's AOSP project. But the android kernel does not support shmem, >> >> It doesn't support tmpfs? /dev/shm is just a tmpfs. >> >> Paolo > > Oh, you are right. The android have shmget, shmat, shmdt functions in > their libc. The POSIX shm_open can built on top of these. I'll fix my > libc to support posix share memory functions. Actually it's even simpler. shm_open is basically just char *s; int fd; asprintf(, "/dev/shm/%s", name); fd = open(s, name | O_CLOEXEC, mode); free(s); return fd; plus some error checking. Do Android systems have /dev/shm? Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
On 15/09/2015 19:34, Houcheng Lin wrote: > Hi Paolo, > > (Please ignore the previous mail that did not include "qemu-devel") > > Thanks for your review and suggestions. I'll fix this patch > accordingly and please see my replies below. > > best regards, > Houcheng Lin > > 2015-09-15 17:41 GMT+08:00 Paolo Bonzini: > >> This is okay and can be done unconditionally (introduce a new >> qemu_getdtablesize function that is defined in util/oslib-posix.c). > > Will fix it. >> >> >>> - sigtimewait(): call __rt_sigtimewait() instead. >>> - lockf(): not see this feature in android, directly return -1. >>> - shm_open(): not see this feature in android, directly return -1. >> >> This is not okay. Please fix your libc instead. > > I'll modify the bionic C library to support these functions and feedback > to google's AOSP project. But the android kernel does not support shmem, It doesn't support tmpfs? /dev/shm is just a tmpfs. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
On 16/09/2015 11:54, Houcheng Lin wrote: > 2015-09-16 17:38 GMT+08:00 Paolo Bonzini: >> >> Actually it's even simpler. shm_open is basically just >> >> char *s; >> int fd; >> >> asprintf(, "/dev/shm/%s", name); >> fd = open(s, name | O_CLOEXEC, mode); >> free(s); >> return fd; >> >> plus some error checking. Do Android systems have /dev/shm? >> >> Paolo > > It's simple, thanks. > The android have no /dev/shm. Though we can mknod it but need root prividlege > to > do it. Oh well. Then I think it's okay to disable ivshmem on Android. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
Hi Paolo, (Please ignore the previous mail that did not include "qemu-devel") Thanks for your review and suggestions. I'll fix this patch accordingly and please see my replies below. best regards, Houcheng Lin 2015-09-15 17:41 GMT+08:00 Paolo Bonzini: > This is okay and can be done unconditionally (introduce a new > qemu_getdtablesize function that is defined in util/oslib-posix.c). Will fix it. > > >> - sigtimewait(): call __rt_sigtimewait() instead. >> - lockf(): not see this feature in android, directly return -1. >> - shm_open(): not see this feature in android, directly return -1. > > This is not okay. Please fix your libc instead. I'll modify the bionic C library to support these functions and feedback to google's AOSP project. But the android kernel does not support shmem, so I will prevent compile the ivshmem.c when in android config. The config for ivshmem in pci.mak will be: CONFIG_IVSHMEM=$(call land, $(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM)) > For sys/io.h, we can just remove the inclusion. It is not necessary. > > scsi/sg.h should be exported by the Linux kernel, so that we can use > scripts/update-linux-headers.sh to copy it from QEMU. I've sent a Linux > kernel patch and CCed you. It's better to put headers on kernel user headers. Thanks. > > You should instead disable the guest agent on your configure command line. > Okay. > > If you have CONFIG_ANDROID, you do not need -DANDROID. > Okay. >> + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" >> + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" > > This should not be necessary, QEMU uses pkg-config. > >> +fi >> if [ "$bsd" = "yes" ] ; then >>if [ "$darwin" != "yes" ] ; then >> bsd_user="yes" >> @@ -1736,7 +1749,14 @@ fi >> # pkg-config probe >> >> if ! has "$pkg_config_exe"; then >> - error_exit "pkg-config binary '$pkg_config_exe' not found" >> + case $cross_prefix in >> +*android*) >> + pkg_config_exe=scripts/android-pkg-config > > Neither should this. Your cross-compilation environment is not > correctly set up if you do not have a pkg-config executable. If you > want to use a wrapper, you can specify it with the PKG_CONFIG > environment variable. But it need not be maintained in the QEMU > repository, because QEMU assumes a complete cross-compilation environment. I'll use wrapper in next release and specify with environment variable. Later, I may generate pkg-config data file while building library and install it into cross-compilation environment. > >> + ;; >> +*) >> + error_exit "pkg-config binary '$pkg_config_exe' not found" >> + ;; >> + esac >> fi >> >> ## >> @@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then >> fi >> >> if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ >> -"$aix" != "yes" -a "$haiku" != "yes" ; then >> +"$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then >> libs_softmmu="-lutil $libs_softmmu" >> fi >> >> @@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then >>echo "CONFIG_LINUX=y" >> $config_host_mak >> fi >> >> +if test "$android" = "yes" ; then >> + echo "CONFIG_ANDROID=y" >> $config_host_mak >> +fi >> + >> if test "$darwin" = "yes" ; then >>echo "CONFIG_DARWIN=y" >> $config_host_mak >> fi >> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h >> index ab3c876..1ba22be 100644 >> --- a/include/qemu/osdep.h >> +++ b/include/qemu/osdep.h >> @@ -59,6 +59,10 @@ >> #define WEXITSTATUS(x) (x) >> #endif >> >> +#ifdef ANDROID >> + #include "sysemu/os-android.h" >> +#endif >> + >> #ifdef _WIN32 >> #include "sysemu/os-win32.h" >> #endif >> diff --git a/include/sysemu/os-android.h b/include/sysemu/os-android.h >> new file mode 100644 >> index 000..7f73777 >> --- /dev/null >> +++ b/include/sysemu/os-android.h >> @@ -0,0 +1,35 @@ >> +#ifndef QEMU_OS_ANDROID_H >> +#define QEMU_OS_ANDROID_H >> + >> +#include >> + >> +/* >> + * For include the basename prototyping in android. >> + */ >> +#include > > These two includes can be added to sysemu/os-posix.h. > >> +extern int __rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo, \ >> + const struct timespec *uts, size_t sigsetsize); >> + >> +int getdtablesize(void); >> +int lockf(int fd, int cmd, off_t len); >> +int sigtimedwait(const sigset_t *set, siginfo_t *info, \ >> + const struct timespec *ts); >> +int shm_open(const char *name, int oflag, mode_t mode); >> +char *a_ptsname(int fd); >> + >> +#define F_TLOCK 0 >> +#define IOV_MAX 256 > > libc should really be fixed for all of these (except getdtablesize and > a_ptsname). The way you're working around it is introducing subtle > bugs, for example the pidfile is _not_ locked. Okay, I will fix it. >> +#define I_LOOK (__SID | 4) /* Retrieve the name of the module just
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
On 15/09/2015 04:11, Houcheng Lin wrote: > The OS dependent code for android that implement functions missing in bionic > C, including: > - getdtablesize(): call getrlimit() instead. This is okay and can be done unconditionally (introduce a new qemu_getdtablesize function that is defined in util/oslib-posix.c). > - a_ptsname(): call pstname_r() instead. This is not necessary, see below. > - sigtimewait(): call __rt_sigtimewait() instead. > - lockf(): not see this feature in android, directly return -1. > - shm_open(): not see this feature in android, directly return -1. This is not okay. Please fix your libc instead. > The kernel headers for android include two kernel header missing in android: > scsi/sg.h and > sys/io.h. For sys/io.h, we can just remove the inclusion. It is not necessary. scsi/sg.h should be exported by the Linux kernel, so that we can use scripts/update-linux-headers.sh to copy it from QEMU. I've sent a Linux kernel patch and CCed you. More comments follow: > diff --git a/configure b/configure > index 5c06663..3ff6ffa 100755 > --- a/configure > +++ b/configure > @@ -566,7 +566,6 @@ fi > > # host *BSD for user mode > HOST_VARIANT_DIR="" > - > case $targetos in > CYGWIN*) >mingw32="yes" > @@ -692,9 +691,23 @@ Haiku) >vhost_net="yes" >vhost_scsi="yes" >QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers > $QEMU_INCLUDES" > + case $cross_prefix in > +*android*) > + android="yes" > + guest_agent="no" You should instead disable the guest agent on your configure command line. > + QEMU_INCLUDES="-I\$(SRC_PATH)/include/android $QEMU_INCLUDES" > +;; > +*) > +;; > + esac > ;; > esac > > +if [ "$android" = "yes" ] ; then > + QEMU_CFLAGS="-DANDROID $QEMU_CFLAGS" If you have CONFIG_ANDROID, you do not need -DANDROID. > + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" > + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" This should not be necessary, QEMU uses pkg-config. > +fi > if [ "$bsd" = "yes" ] ; then >if [ "$darwin" != "yes" ] ; then > bsd_user="yes" > @@ -1736,7 +1749,14 @@ fi > # pkg-config probe > > if ! has "$pkg_config_exe"; then > - error_exit "pkg-config binary '$pkg_config_exe' not found" > + case $cross_prefix in > +*android*) > + pkg_config_exe=scripts/android-pkg-config Neither should this. Your cross-compilation environment is not correctly set up if you do not have a pkg-config executable. If you want to use a wrapper, you can specify it with the PKG_CONFIG environment variable. But it need not be maintained in the QEMU repository, because QEMU assumes a complete cross-compilation environment. > + ;; > +*) > + error_exit "pkg-config binary '$pkg_config_exe' not found" > + ;; > + esac > fi > > ## > @@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then > fi > > if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ > -"$aix" != "yes" -a "$haiku" != "yes" ; then > +"$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then > libs_softmmu="-lutil $libs_softmmu" > fi > > @@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then >echo "CONFIG_LINUX=y" >> $config_host_mak > fi > > +if test "$android" = "yes" ; then > + echo "CONFIG_ANDROID=y" >> $config_host_mak > +fi > + > if test "$darwin" = "yes" ; then >echo "CONFIG_DARWIN=y" >> $config_host_mak > fi > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index ab3c876..1ba22be 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -59,6 +59,10 @@ > #define WEXITSTATUS(x) (x) > #endif > > +#ifdef ANDROID > + #include "sysemu/os-android.h" > +#endif > + > #ifdef _WIN32 > #include "sysemu/os-win32.h" > #endif > diff --git a/include/sysemu/os-android.h b/include/sysemu/os-android.h > new file mode 100644 > index 000..7f73777 > --- /dev/null > +++ b/include/sysemu/os-android.h > @@ -0,0 +1,35 @@ > +#ifndef QEMU_OS_ANDROID_H > +#define QEMU_OS_ANDROID_H > + > +#include > + > +/* > + * For include the basename prototyping in android. > + */ > +#include These two includes can be added to sysemu/os-posix.h. > +extern int __rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo, \ > + const struct timespec *uts, size_t sigsetsize); > + > +int getdtablesize(void); > +int lockf(int fd, int cmd, off_t len); > +int sigtimedwait(const sigset_t *set, siginfo_t *info, \ > + const struct timespec *ts); > +int shm_open(const char *name, int oflag, mode_t mode); > +char *a_ptsname(int fd); > + > +#define F_TLOCK 0 > +#define IOV_MAX 256 libc should really be fixed for all of these (except getdtablesize and a_ptsname). The way you're working around it is introducing subtle bugs, for example the pidfile is _not_ locked. >
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
On Tue, 09/15 10:11, Houcheng Lin wrote: > From: HouchengThanks for sending patches! Please include qemu-de...@nongnu.org list for QEMU changes. Fam > > This patch is to build qemu in android ndk tool-chain, and has been tested in > both > x86_64 and x86 android platform with hardware virtualization enabled. This > patch is > composed of three part: > > - configure scripts for android > - OS dependent code for android > - kernel headers for android > > The configure scripts add cross-compile options for android, define compile > flags and link flags > and call android specific pkg-config. A pseudo pkg-config script is added to > report correct > compile flags for android system. > > The OS dependent code for android that implement functions missing in bionic > C, including: > - getdtablesize(): call getrlimit() instead. > - sigtimewait(): call __rt_sigtimewait() instead. > - a_ptsname(): call pstname_r() instead. > - lockf(): not see this feature in android, directly return -1. > - shm_open(): not see this feature in android, directly return -1. > > The kernel headers for android include two kernel header missing in android: > scsi/sg.h and > sys/io.h. > > How to build android version > > 1. download the ndk toolchain r10, build the following libraries and install > in your toolchain sysroot: > libiconv-1.14 > gettext-0.19 > libffi-3.0.12 > glib-2.34.3 > libpng-1.2.52 > pixman-0.30 > > 2. configure the qemu and build: > > % export SYSROOT="/opt/android-toolchain64/sysroot" > % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include > -I$SYSROOT/usr/include/pixman-1/" \ > ./configure --prefix="${SYSROOT}/usr" \ > --cross-prefix=x86_64-linux-android- \ > --enable-kvm --enable-trace-backend=nop --disable-fdt > --target-list=x86_64-softmmu \ > --disable-spice --disable-vhost-net --disable-libiscsi > --audio-drv-list="" --disable-gtk \ > --disable-gnutls --disable-libnfs --disable-glusterfs > --disable-libssh2 --disable-seccomp \ > --disable-usb-redir --disable-libusb > % make -j4 > > Or, configure qemu to static link version: > > % export SYSROOT="/opt/android-toolchain64/sysroot" > % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include > -I$SYSROOT/usr/include/pixman-1/" \ > ./configure --prefix="${SYSROOT}/usr" \ > --cross-prefix=x86_64-linux-android- \ > --enable-kvm --enable-trace-backend=nop --disable-fdt > --target-list=x86_64-softmmu \ > --disable-spice --disable-vhost-net --disable-libiscsi > --audio-drv-list="" --disable-gtk \ > --disable-gnutls --disable-libnfs --disable-glusterfs > --disable-libssh2 --disable-seccomp \ > --disable-usb-redir --disable-libusb --static > % make -j4 > > Signed-off-by: Houcheng > --- > configure | 30 - > include/android/scsi/sg.h | 307 > +++ > include/qemu/osdep.h|4 + > include/sysemu/os-android.h | 35 + > kvm-all.c |3 + > scripts/android-pkg-config | 28 > tests/Makefile |2 + > util/osdep.c| 53 > util/qemu-openpty.c | 10 +- > 9 files changed, 467 insertions(+), 5 deletions(-) > create mode 100644 include/android/scsi/sg.h > create mode 100644 include/android/sys/io.h > create mode 100644 include/sysemu/os-android.h > create mode 100755 scripts/android-pkg-config > > diff --git a/configure b/configure > index 5c06663..3ff6ffa 100755 > --- a/configure > +++ b/configure > @@ -566,7 +566,6 @@ fi > > # host *BSD for user mode > HOST_VARIANT_DIR="" > - > case $targetos in > CYGWIN*) >mingw32="yes" > @@ -692,9 +691,23 @@ Haiku) >vhost_net="yes" >vhost_scsi="yes" >QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers > $QEMU_INCLUDES" > + case $cross_prefix in > +*android*) > + android="yes" > + guest_agent="no" > + QEMU_INCLUDES="-I\$(SRC_PATH)/include/android $QEMU_INCLUDES" > +;; > +*) > +;; > + esac > ;; > esac > > +if [ "$android" = "yes" ] ; then > + QEMU_CFLAGS="-DANDROID $QEMU_CFLAGS" > + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" > + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" > +fi > if [ "$bsd" = "yes" ] ; then >if [ "$darwin" != "yes" ] ; then > bsd_user="yes" > @@ -1736,7 +1749,14 @@ fi > # pkg-config probe > > if ! has "$pkg_config_exe"; then > - error_exit "pkg-config binary '$pkg_config_exe' not found" > + case $cross_prefix in > +*android*) > + pkg_config_exe=scripts/android-pkg-config > + ;; > +*) > + error_exit "pkg-config binary '$pkg_config_exe' not found" > + ;; > + esac > fi > >
Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10
Hi Paolo, Thanks for your review and suggestions. I'll fix this patch accordingly. Please also see my replies below. best regards, Houcheng Lin 2015-09-15 17:41 GMT+08:00 Paolo Bonzini: > > This is okay and can be done unconditionally (introduce a new > qemu_getdtablesize function that is defined in util/oslib-posix.c). Will fix it. > > >> - sigtimewait(): call __rt_sigtimewait() instead. >> - lockf(): not see this feature in android, directly return -1. >> - shm_open(): not see this feature in android, directly return -1. > > This is not okay. Please fix your libc instead. I'll modify the bionic C library to support these functions and feedback to google's AOSP project. But the android kernel does not support shmem, so I will prevent compile the ivshmem.c when in android config. The config for ivshmem in pci.mak will be: CONFIG_IVSHMEM=$(call land, $(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM)) > For sys/io.h, we can just remove the inclusion. It is not necessary. > > scsi/sg.h should be exported by the Linux kernel, so that we can use > scripts/update-linux-headers.sh to copy it from QEMU. I've sent a Linux > kernel patch and CCed you. It's better to put headers on kernel user headers. Thanks. > > You should instead disable the guest agent on your configure command line. > Okay. > > If you have CONFIG_ANDROID, you do not need -DANDROID. > Okay. >> + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" >> + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" > > This should not be necessary, QEMU uses pkg-config. > >> +fi >> if [ "$bsd" = "yes" ] ; then >>if [ "$darwin" != "yes" ] ; then >> bsd_user="yes" >> @@ -1736,7 +1749,14 @@ fi >> # pkg-config probe >> >> if ! has "$pkg_config_exe"; then >> - error_exit "pkg-config binary '$pkg_config_exe' not found" >> + case $cross_prefix in >> +*android*) >> + pkg_config_exe=scripts/android-pkg-config > > Neither should this. Your cross-compilation environment is not > correctly set up if you do not have a pkg-config executable. If you > want to use a wrapper, you can specify it with the PKG_CONFIG > environment variable. But it need not be maintained in the QEMU > repository, because QEMU assumes a complete cross-compilation environment. I'll use wrapper in next release and specify with environment variable. Later, I may generate pkg-config data file while building library and install it into cross-compilation environment. > >> + ;; >> +*) >> + error_exit "pkg-config binary '$pkg_config_exe' not found" >> + ;; >> + esac >> fi >> >> ## >> @@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then >> fi >> >> if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ >> -"$aix" != "yes" -a "$haiku" != "yes" ; then >> +"$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then >> libs_softmmu="-lutil $libs_softmmu" >> fi >> >> @@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then >>echo "CONFIG_LINUX=y" >> $config_host_mak >> fi >> >> +if test "$android" = "yes" ; then >> + echo "CONFIG_ANDROID=y" >> $config_host_mak >> +fi >> + >> if test "$darwin" = "yes" ; then >>echo "CONFIG_DARWIN=y" >> $config_host_mak >> fi >> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h >> index ab3c876..1ba22be 100644 >> --- a/include/qemu/osdep.h >> +++ b/include/qemu/osdep.h >> @@ -59,6 +59,10 @@ >> #define WEXITSTATUS(x) (x) >> #endif >> >> +#ifdef ANDROID >> + #include "sysemu/os-android.h" >> +#endif >> + >> #ifdef _WIN32 >> #include "sysemu/os-win32.h" >> #endif >> diff --git a/include/sysemu/os-android.h b/include/sysemu/os-android.h >> new file mode 100644 >> index 000..7f73777 >> --- /dev/null >> +++ b/include/sysemu/os-android.h >> @@ -0,0 +1,35 @@ >> +#ifndef QEMU_OS_ANDROID_H >> +#define QEMU_OS_ANDROID_H >> + >> +#include >> + >> +/* >> + * For include the basename prototyping in android. >> + */ >> +#include > > These two includes can be added to sysemu/os-posix.h. > >> +extern int __rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo, \ >> + const struct timespec *uts, size_t sigsetsize); >> + >> +int getdtablesize(void); >> +int lockf(int fd, int cmd, off_t len); >> +int sigtimedwait(const sigset_t *set, siginfo_t *info, \ >> + const struct timespec *ts); >> +int shm_open(const char *name, int oflag, mode_t mode); >> +char *a_ptsname(int fd); >> + >> +#define F_TLOCK 0 >> +#define IOV_MAX 256 > > libc should really be fixed for all of these (except getdtablesize and > a_ptsname). The way you're working around it is introducing subtle > bugs, for example the pidfile is _not_ locked. Okay, I will fix it. >> +#define I_LOOK (__SID | 4) /* Retrieve the name of the module just >> below >> + the STREAM head
[RFC PATCH] os-android: Add support to android platform, built by ndk-r10
From: HouchengThis patch is to build qemu in android ndk tool-chain, and has been tested in both x86_64 and x86 android platform with hardware virtualization enabled. This patch is composed of three part: - configure scripts for android - OS dependent code for android - kernel headers for android The configure scripts add cross-compile options for android, define compile flags and link flags and call android specific pkg-config. A pseudo pkg-config script is added to report correct compile flags for android system. The OS dependent code for android that implement functions missing in bionic C, including: - getdtablesize(): call getrlimit() instead. - sigtimewait(): call __rt_sigtimewait() instead. - a_ptsname(): call pstname_r() instead. - lockf(): not see this feature in android, directly return -1. - shm_open(): not see this feature in android, directly return -1. The kernel headers for android include two kernel header missing in android: scsi/sg.h and sys/io.h. How to build android version 1. download the ndk toolchain r10, build the following libraries and install in your toolchain sysroot: libiconv-1.14 gettext-0.19 libffi-3.0.12 glib-2.34.3 libpng-1.2.52 pixman-0.30 2. configure the qemu and build: % export SYSROOT="/opt/android-toolchain64/sysroot" % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \ ./configure --prefix="${SYSROOT}/usr" \ --cross-prefix=x86_64-linux-android- \ --enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \ --disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \ --disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \ --disable-usb-redir --disable-libusb % make -j4 Or, configure qemu to static link version: % export SYSROOT="/opt/android-toolchain64/sysroot" % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \ ./configure --prefix="${SYSROOT}/usr" \ --cross-prefix=x86_64-linux-android- \ --enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \ --disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \ --disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \ --disable-usb-redir --disable-libusb --static % make -j4 Signed-off-by: Houcheng --- configure | 30 - include/android/scsi/sg.h | 307 +++ include/qemu/osdep.h|4 + include/sysemu/os-android.h | 35 + kvm-all.c |3 + scripts/android-pkg-config | 28 tests/Makefile |2 + util/osdep.c| 53 util/qemu-openpty.c | 10 +- 9 files changed, 467 insertions(+), 5 deletions(-) create mode 100644 include/android/scsi/sg.h create mode 100644 include/android/sys/io.h create mode 100644 include/sysemu/os-android.h create mode 100755 scripts/android-pkg-config diff --git a/configure b/configure index 5c06663..3ff6ffa 100755 --- a/configure +++ b/configure @@ -566,7 +566,6 @@ fi # host *BSD for user mode HOST_VARIANT_DIR="" - case $targetos in CYGWIN*) mingw32="yes" @@ -692,9 +691,23 @@ Haiku) vhost_net="yes" vhost_scsi="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" + case $cross_prefix in +*android*) + android="yes" + guest_agent="no" + QEMU_INCLUDES="-I\$(SRC_PATH)/include/android $QEMU_INCLUDES" +;; +*) +;; + esac ;; esac +if [ "$android" = "yes" ] ; then + QEMU_CFLAGS="-DANDROID $QEMU_CFLAGS" + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" +fi if [ "$bsd" = "yes" ] ; then if [ "$darwin" != "yes" ] ; then bsd_user="yes" @@ -1736,7 +1749,14 @@ fi # pkg-config probe if ! has "$pkg_config_exe"; then - error_exit "pkg-config binary '$pkg_config_exe' not found" + case $cross_prefix in +*android*) + pkg_config_exe=scripts/android-pkg-config + ;; +*) + error_exit "pkg-config binary '$pkg_config_exe' not found" + ;; + esac fi ## @@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then fi if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ -"$aix" != "yes" -a "$haiku" != "yes" ; then +"$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then libs_softmmu="-lutil $libs_softmmu" fi @@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then echo
[RFC PATCH] os-android: Add support to android platform, built by ndk-r10
From: HouchengThis patch is to build qemu in android ndk tool-chain, and has been tested in both x86_64 and x86 android platform with hardware virtualization enabled. This patch is composed of three part: - configure scripts for android - OS dependent code for android - kernel headers for android The configure scripts add cross-compile options for android, define compile flags and link flags and call android specific pkg-config. A pseudo pkg-config script is added to report correct compile flags for android system. The OS dependent code for android that implement functions missing in bionic C, including: - getdtablesize(): call getrlimit() instead. - sigtimewait(): call __rt_sigtimewait() instead. - a_ptsname(): call pstname_r() instead. - lockf(): not see this feature in android, directly return -1. - shm_open(): not see this feature in android, directly return -1. The kernel headers for android include two kernel header missing in android: scsi/sg.h and sys/io.h. How to build android version 1. download the ndk toolchain r10, build the following libraries and install in your toolchain sysroot: libiconv-1.14 gettext-0.19 libffi-3.0.12 glib-2.34.3 libpng-1.2.52 pixman-0.30 2. configure the qemu and build: % export SYSROOT="/opt/android-toolchain64/sysroot" % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \ ./configure --prefix="${SYSROOT}/usr" \ --cross-prefix=x86_64-linux-android- \ --enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \ --disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \ --disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \ --disable-usb-redir --disable-libusb % make -j4 Or, configure qemu to static link version: % export SYSROOT="/opt/android-toolchain64/sysroot" % CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \ ./configure --prefix="${SYSROOT}/usr" \ --cross-prefix=x86_64-linux-android- \ --enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \ --disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \ --disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \ --disable-usb-redir --disable-libusb --static % make -j4 Signed-off-by: Houcheng --- configure | 30 - include/android/scsi/sg.h | 307 +++ include/qemu/osdep.h|4 + include/sysemu/os-android.h | 35 + kvm-all.c |3 + scripts/android-pkg-config | 28 tests/Makefile |2 + util/osdep.c| 53 util/qemu-openpty.c | 10 +- 9 files changed, 467 insertions(+), 5 deletions(-) create mode 100644 include/android/scsi/sg.h create mode 100644 include/android/sys/io.h create mode 100644 include/sysemu/os-android.h create mode 100755 scripts/android-pkg-config diff --git a/configure b/configure index 5c06663..3ff6ffa 100755 --- a/configure +++ b/configure @@ -566,7 +566,6 @@ fi # host *BSD for user mode HOST_VARIANT_DIR="" - case $targetos in CYGWIN*) mingw32="yes" @@ -692,9 +691,23 @@ Haiku) vhost_net="yes" vhost_scsi="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" + case $cross_prefix in +*android*) + android="yes" + guest_agent="no" + QEMU_INCLUDES="-I\$(SRC_PATH)/include/android $QEMU_INCLUDES" +;; +*) +;; + esac ;; esac +if [ "$android" = "yes" ] ; then + QEMU_CFLAGS="-DANDROID $QEMU_CFLAGS" + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" +fi if [ "$bsd" = "yes" ] ; then if [ "$darwin" != "yes" ] ; then bsd_user="yes" @@ -1736,7 +1749,14 @@ fi # pkg-config probe if ! has "$pkg_config_exe"; then - error_exit "pkg-config binary '$pkg_config_exe' not found" + case $cross_prefix in +*android*) + pkg_config_exe=scripts/android-pkg-config + ;; +*) + error_exit "pkg-config binary '$pkg_config_exe' not found" + ;; + esac fi ## @@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then fi if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ -"$aix" != "yes" -a "$haiku" != "yes" ; then +"$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then libs_softmmu="-lutil $libs_softmmu" fi @@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then echo