From c8d0146847fe690855dd4ba4a320135052b24766 Mon Sep 17 00:00:00 2001 From: "munkyu.im" Date: Thu, 15 Dec 2011 19:02:20 +0900 Subject: [PATCH] [Title]apply multi emulator instance (for windows) [Type]Enhancement [Module] [Priority] [CQ#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- tizen/src/emul_debug.bat | 1 + tizen/src/emul_debug.sh | 3 +-- tizen/src/emulator.c | 40 ++++++++++++++++++++++++++- tizen/src/emulsignal.c | 6 +++++ tizen/src/vtm.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 tizen/src/emul_debug.bat diff --git a/tizen/src/emul_debug.bat b/tizen/src/emul_debug.bat new file mode 100644 index 0000000..c26d461 --- /dev/null +++ b/tizen/src/emul_debug.bat @@ -0,0 +1 @@ +gdb --args emulator-x86.exe --vtm default -- -net nic,model=virtio -usb -usbdevice wacom-tablet -vga tizen -bios bios.bin -L ..\x86\data\pc-bios -kernel ..\x86\data\kernel-img\bzImage -usbdevice keyboard -rtc base=utc -net user -redir tcp:1202:10.0.2.16:22 diff --git a/tizen/src/emul_debug.sh b/tizen/src/emul_debug.sh index dee8959..6d621ef 100755 --- a/tizen/src/emul_debug.sh +++ b/tizen/src/emul_debug.sh @@ -1,5 +1,4 @@ #!/bin/sh CURDIR=`pwd` - -$CURDIR/emulator-x86 --vtm default \ +gdb --args $CURDIR/emulator-x86 --vtm default \ -- -net nic,model=virtio -usb -usbdevice wacom-tablet -vga tizen -bios bios.bin -L $CURDIR/../x86/data/pc-bios -kernel $CURDIR/../x86/data/kernel-img/bzImage -usbdevice keyboard -rtc base=utc -net user --enable-kvm -redir tcp:1202:10.0.2.16:22 diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 5d084a1..1a00e5f 100755 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -66,7 +66,9 @@ #include #ifndef _WIN32 #include -#include +#include +#else +#include #endif #include "opengl_server.h" @@ -888,6 +890,42 @@ int init_shdmem() // shmctl(shmid, IPC_RMID, 0); // shmdt(shared_memory); +#else + tizen_base_port = get_sdb_base_port(); + HANDLE hMapFile; + char* pBuf; + char* port_in_use; + char *shared_memory; + shared_memory = g_strdup_printf("%s", startup_option.vtm); + port_in_use = g_strdup_printf("%d", tizen_base_port); + hMapFile = CreateFileMapping( + INVALID_HANDLE_VALUE, // use paging file + NULL, // default security + PAGE_READWRITE, // read/write access + 0, // maximum object size (high-order DWORD) + 50, // maximum object size (low-order DWORD) + port_in_use); // name of mapping object + if (hMapFile == NULL) + { + ERR("Could not create file mapping object (%d).\n", GetLastError()); + return -1; + } + pBuf = MapViewOfFile(hMapFile, // handle to map object + FILE_MAP_ALL_ACCESS, // read/write permission + 0, + 0, + 50); + + if (pBuf == NULL) + { + ERR("Could not map view of file (%d).\n", GetLastError()); + CloseHandle(hMapFile); + return -1; + } + + CopyMemory((PVOID)pBuf, shared_memory, strlen(shared_memory)); + free(port_in_use); + free(shared_memory); #endif return 0; } diff --git a/tizen/src/emulsignal.c b/tizen/src/emulsignal.c index 3df7ab9..393cf11 100644 --- a/tizen/src/emulsignal.c +++ b/tizen/src/emulsignal.c @@ -120,6 +120,12 @@ void destroy_emulator(void) ERR( "fail to remove shared memory\n"); else INFO( "succedd to remove shared memory\n"); +#else + char *port_in_use; + port_in_use = g_strdup_printf("%d", tizen_base_port); + HANDLE hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, port_in_use); + if(hMapFile) + CloseHandle(hMapFile); #endif return; } diff --git a/tizen/src/vtm.c b/tizen/src/vtm.c index 6e83984..f5b6463 100644 --- a/tizen/src/vtm.c +++ b/tizen/src/vtm.c @@ -371,6 +371,76 @@ int check_shdmem(char *target_name, int type) } } +#else /* _WIN32*/ + u_int port; + char* base_port = NULL; + char* pBuf; + HANDLE hMapFile; + for(port=26100;port < 26200; port += 10) + { + base_port = g_strdup_printf("%d", port); + hMapFile = OpenFileMapping( + FILE_MAP_READ, + TRUE, + base_port); + if(hMapFile == NULL) + { + INFO("port %s is not used.\n", base_port); + continue; + } + else + { + pBuf = (char*)MapViewOfFile(hMapFile, + FILE_MAP_READ, + 0, + 0, + 50); + if (pBuf == NULL) + { + ERR("Could not map view of file (%d).\n", GetLastError()); + CloseHandle(hMapFile); + return -1; + } + + if(strcmp(pBuf, target_name) == 0) + { + if(check_port_bind_listen(port+1) > 0) + { + UnmapViewOfFile(pBuf); + CloseHandle(hMapFile); + continue; + } + + switch(type) + { + case CREATE_MODE: + show_message("Warning", "Can not activate this target!\nVirtual target with the same name is running now!"); + break; + case DELETE_MODE: + show_message("Warning", "Can not delete this target!\nVirtual target with the same name is running now!"); + break; + case MODIFY_MODE: + show_message("Warning", "Can not modify this target!\nVirtual target with the same name is running now!"); + break; + case RESET_MODE: + show_message("Warning", "Can not reset this target!\nVirtual target with the same name is running now!"); + break; + default: + ERR("wrong type passed\n"); + } + + UnmapViewOfFile(pBuf); + CloseHandle(hMapFile); + free(base_port); + return -1; + } + else + UnmapViewOfFile(pBuf); + } + + CloseHandle(hMapFile); + free(base_port); + } #endif return 0; -- 2.7.4