shared memory: free memory when close emulator
authormunkyu.im <munkyu.im@samsung.com>
Wed, 23 Jan 2013 11:17:24 +0000 (20:17 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Wed, 23 Jan 2013 11:17:24 +0000 (20:17 +0900)
Signed-off-by: munkyu.im <munkyu.im@samsung.com>
tizen/src/hw/maru_vga.c
tizen/src/maru_sdl.c
tizen/src/osutil-darwin.c
tizen/src/osutil-linux.c
tizen/src/skin/client/native_src/share.c

index 6007b5c..c1f2a0a 100644 (file)
@@ -61,6 +61,7 @@
 #ifdef CONFIG_USE_SHM
 void *shared_memory = (void*) 0;
 int shmid;
+int shmid_tmp;
 #endif
 
 
@@ -1873,14 +1874,14 @@ void maru_vga_common_init(VGACommonState *s)
     int mykey;
     void *temp;
 
-    shmid = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT);
-    if (shmid == -1) {
+    shmid_tmp = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT);
+    if (shmid_tmp == -1) {
         ERR("shmget failed\n");
         perror("maru_vga: ");
         exit(1);
     }
 
-    temp = shmat(shmid, (char*)0x0, 0);
+    temp = shmat(shmid_tmp, (char*)0x0, 0);
     if (temp == (void *)-1) {
         ERR("shmat failed\n");
         perror("maru_vga: ");
@@ -1889,6 +1890,7 @@ void maru_vga_common_init(VGACommonState *s)
 
     mykey = atoi(temp);
     shmdt(temp);
+    
     INFO("shared memory key: %d, vga ram_size : %d\n", mykey, s->vram_size);
 
     shmid = shmget((key_t)mykey, (size_t)s->vram_size, 0666 | IPC_CREAT);
@@ -1925,6 +1927,11 @@ void maru_vga_common_fini(void)
         ERR("shmctl failed\n");
         perror("maru_vga: ");
     }
+    
+    if (shmctl(shmid_tmp, IPC_RMID, 0) == -1) {
+        ERR("temp shmctl failed\n");
+        perror("maru_vga: ");
+    }
 }
 #endif
 
index 01c7261..fc8b33b 100644 (file)
@@ -38,6 +38,7 @@
 #include "maru_finger.h"
 #include "hw/maru_pm.h"
 #include "debug_ch.h"
+#include <sys/shm.h>
 //#include "SDL_opengl.h"
 
 MULTI_DEBUG_CHANNEL(tizen, maru_sdl);
@@ -56,6 +57,8 @@ static int current_screen_height;
 
 static int sdl_initialized;
 static int sdl_alteration;
+extern int g_shmid;
+extern char *g_shared_memory;
 
 #if 0
 static int sdl_opengl = 0; //0 : just SDL surface, 1 : using SDL with OpenGL
@@ -537,6 +540,13 @@ void maruskin_sdl_quit(void)
     sdl_alteration = -1;
 
     SDL_Quit();
+
+    if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
+            ERR("shmctl failed\n");
+            perror("maru_sdl.c: ");
+    }
+
+
 }
 
 
index 542a9bc..8948496 100644 (file)
@@ -1,9 +1,9 @@
-/* 
+/*
  * Emulator
  *
  * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  * SeokYeon Hwang <syeon.hwang@samsung.com>
  * MunKyu Im <munkyu.im@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -90,16 +90,23 @@ void make_vm_lock_os(void)
     shmid = shmget((key_t)SHMKEY, MAXLEN, 0666|IPC_CREAT);
     if (shmid == -1) {
         ERR("shmget failed\n");
+        perror("osutil-darwin: ");
         return;
     }
+
     shared_memory = shmat(shmid, (char *)0x00, 0);
     if (shared_memory == (void *)-1) {
         ERR("shmat failed\n");
+        perror("osutil-darwin: ");
         return;
     }
     sprintf(shared_memory, "%d", tizen_base_port + 2);
     INFO("shared memory key: %d, value: %s\n", SHMKEY, (char *)shared_memory);
-    shmdt(shared_memory);
+    
+    if (shmdt(shared_memory) == -1) {
+        ERR("shmdt failed\n");
+        perror("osutil-darwin: ");
+    }
 }
 
 void set_bin_path_os(gchar * exec_argv)
@@ -229,7 +236,7 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy,
             ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n");
             fclose(fp_pacfile);
         }
-    } 
+    }
     else {
         ERR("fail to get pacfile fp\n");
        return -1;
@@ -250,7 +257,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     proxySettings = SCDynamicStoreCopyProxies(NULL);
 
     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPEnable);
-    if (cfnumber_to_int(isEnable)) {        
+    if (cfnumber_to_int(isEnable)) {
         // Get proxy hostname
         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPProxy);
         hostname = cfstring_to_cstring(proxyHostname);
@@ -264,9 +271,9 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     } else {
         INFO("http proxy is null\n");
     }
-    
+
     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSEnable);
-    if (cfnumber_to_int(isEnable)) {        
+    if (cfnumber_to_int(isEnable)) {
         // Get proxy hostname
         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSProxy);
         hostname = cfstring_to_cstring(proxyHostname);
@@ -280,9 +287,9 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     } else {
         INFO("https proxy is null\n");
     }
-    
+
     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPEnable);
-    if (cfnumber_to_int(isEnable)) {        
+    if (cfnumber_to_int(isEnable)) {
         // Get proxy hostname
         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPProxy);
         hostname = cfstring_to_cstring(proxyHostname);
@@ -296,9 +303,9 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     } else {
         INFO("ftp proxy is null\n");
     }
-    
+
     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSEnable);
-    if (cfnumber_to_int(isEnable)) {        
+    if (cfnumber_to_int(isEnable)) {
         // Get proxy hostname
         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSProxy);
         hostname = cfstring_to_cstring(proxyHostname);
@@ -321,10 +328,10 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
     proxySettings = SCDynamicStoreCopyProxies(NULL);
     if(proxySettings) {
         INFO("AUTO PROXY MODE\n");
-        ret = get_auto_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); 
+        ret = get_auto_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
         if(strlen(http_proxy) == 0 && ret < 0) {
             INFO("MANUAL PROXY MODE\n");
-               get_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); 
+               get_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
            }
     }
 }
index 66f9041..0de15e5 100644 (file)
@@ -57,6 +57,8 @@ MULTI_DEBUG_CHANNEL(emulator, osutil);
 
 extern char tizen_target_img_path[];
 extern int tizen_base_port;
+int g_shmid;
+char *g_shared_memory;
 
 void check_vm_lock_os(void)
 {
@@ -100,23 +102,21 @@ void check_vm_lock_os(void)
 
 void make_vm_lock_os(void)
 {
-    int shmid;
-    char *shared_memory;
 
-    shmid = shmget((key_t)tizen_base_port, MAXLEN, 0666|IPC_CREAT);
-    if (shmid == -1) {
+    g_shmid = shmget((key_t)tizen_base_port, MAXLEN, 0666|IPC_CREAT);
+    if (g_shmid == -1) {
         ERR("shmget failed\n");
         return;
     }
 
-    shared_memory = shmat(shmid, (char *)0x00, 0);
-    if (shared_memory == (void *)-1) {
+    g_shared_memory = shmat(g_shmid, (char *)0x00, 0);
+    if (g_shared_memory == (void *)-1) {
         ERR("shmat failed\n");
         return;
     }
-    g_sprintf(shared_memory, "%s", tizen_target_img_path);
+    g_sprintf(g_shared_memory, "%s", tizen_target_img_path);
     INFO("shared memory key: %d value: %s\n",
-        tizen_base_port, (char *)shared_memory);
+        tizen_base_port, (char *)g_shared_memory);
 }
 
 void set_bin_path_os(gchar * exec_argv)
index a67ea6b..6a14d76 100644 (file)
@@ -49,7 +49,7 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmget
     int keyval;
     shmid = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT);
     if (shmid == -1) {
-       fprintf(stderr, "share.c: shmget failed\n");
+           fprintf(stderr, "share.c: shmget failed\n");
         exit(1);
     }
     
@@ -59,16 +59,19 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmget
         exit(1);
     }
     keyval = atoi(temp);
+    fprintf(stdout, "share.c: shared memory key = %d\n", keyval);
     shmdt(temp);
 
     shmid = shmget((key_t)keyval, (size_t)vga_ram_size, 0666 | IPC_CREAT);
     if (shmid == -1) {
+        fprintf(stderr, "share.c: shmget failed\n");
         return 1;
     }
 
     /* We now make the shared memory accessible to the program. */
     shared_memory = shmat(shmid, (void *)0, 0);
     if (shared_memory == (void *)-1) {
+        fprintf(stderr, "share.c: shmat failed\n");
         return 2;
     }
 
@@ -80,9 +83,16 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmdt
 {
     /* Lastly, the shared memory is detached */
     if (shmdt(shared_memory) == -1) {
+        fprintf(stderr, "share.c: shmdt failed\n");
+        perror("share.c: ");
         return 1;
     }
-
+/*    
+    if (shmctl(shmid, IPC_RMID, 0) == -1) {
+        fprintf(stderr, "share.c: shmctl failed\n");
+        perror("share.c: ");
+    }
+*/
     return 0;
 }
 
@@ -92,6 +102,7 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_getPixels
     int i = 0;
     int len = (*env)->GetArrayLength(env, array);
     if (len <= 0) {
+        fprintf(stderr, "share.c: get length failed\n");
         return -1;
     }