4 * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
7 * SeokYeon Hwang <syeon.hwang@samsung.com>
8 * MunKyu Im <munkyu.im@samsung.com>
9 * GiWoong Kim <giwoong.kim@samsung.com>
10 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 @brief Collection of utilities for win32
37 #include "maru_common.h"
41 #include "maru_err_table.h"
46 MULTI_DEBUG_CHANNEL (emulator, osutil);
48 extern char tizen_target_img_path[];
49 extern int tizen_base_port;
51 void check_vm_lock_os(void)
54 char *base_port = NULL;
57 for (port = 26100; port < 26200; port += 10) {
58 base_port = g_strdup_printf("%d", port);
59 hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, base_port);
60 if (hMapFile == NULL) {
61 INFO("port %s is not used.\n", base_port);
64 pBuf = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 50);
66 ERR("Could not map view of file (%d).\n", GetLastError());
67 CloseHandle(hMapFile);
70 if (strcmp(pBuf, tizen_target_img_path) == 0) {
71 maru_register_exit_msg(MARU_EXIT_UNKNOWN,
72 "Can not execute this VM.\n"
73 "The same name is running now.");
74 UnmapViewOfFile(pBuf);
75 CloseHandle(hMapFile);
79 UnmapViewOfFile(pBuf);
83 CloseHandle(hMapFile);
88 void make_vm_lock_os(void)
95 shared_memory = g_strdup_printf("%s", tizen_target_img_path);
96 port_in_use = g_strdup_printf("%d", tizen_base_port);
97 hMapFile = CreateFileMapping(
98 INVALID_HANDLE_VALUE, /* use paging file */
99 NULL, /* default security */
100 PAGE_READWRITE, /* read/write access */
101 0, /* maximum object size (high-order DWORD) */
102 50, /* maximum object size (low-order DWORD) */
103 port_in_use); /* name of mapping object */
104 if (hMapFile == NULL) {
105 ERR("Could not create file mapping object (%d).\n", GetLastError());
108 pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 50);
111 ERR("Could not map view of file (%d).\n", GetLastError());
112 CloseHandle(hMapFile);
116 CopyMemory((PVOID)pBuf, shared_memory, strlen(shared_memory));
121 void set_bin_path_os(gchar * exec_argv)
123 gchar link_path[PATH_MAX] = { 0, };
124 gchar *file_name = NULL;
126 if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
130 file_name = g_strrstr(link_path, "\\");
131 g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
133 g_strlcat(bin_path, "\\", PATH_MAX);
136 void print_system_info_os(void)
140 /* Retrieves information about the current os */
142 ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
143 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
145 if (GetVersionEx(&osvi)) {
146 INFO("* MajorVersion : %d, MinorVersion : %d, BuildNumber : %d, \
147 PlatformId : %d, CSDVersion : %s\n", osvi.dwMajorVersion,
148 osvi.dwMinorVersion, osvi.dwBuildNumber,
149 osvi.dwPlatformId, osvi.szCSDVersion);
152 /* Retrieves information about the current system */
154 ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
156 GetSystemInfo(&sysi);
157 INFO("* Processor type : %d, Number of processors : %d\n",
158 sysi.dwProcessorType, sysi.dwNumberOfProcessors);
160 MEMORYSTATUSEX memInfo;
161 memInfo.dwLength = sizeof(MEMORYSTATUSEX);
162 GlobalMemoryStatusEx(&memInfo);
163 INFO("* Total Ram : %llu kB, Free: %lld kB\n",
164 memInfo.ullTotalPhys / DIV, memInfo.ullAvailPhys / DIV);