[Feature][ZXW-65]merged P49 base code

Change-Id: I3e09c0c3d47483bc645f02310380ecb7fc6f4041
diff --git a/ap/os/linux/linux-3.4.x/ipc/shm.c b/ap/os/linux/linux-3.4.x/ipc/shm.c
index 054c4e0..47d3255 100755
--- a/ap/os/linux/linux-3.4.x/ipc/shm.c
+++ b/ap/os/linux/linux-3.4.x/ipc/shm.c
@@ -43,6 +43,9 @@
 #include <asm/uaccess.h>
 
 #include "util.h"
+#ifdef CONFIG_SYSVIPC_CROSS_SHM
+#include "shm_ctrl.h"
+#endif
 
 struct shm_file_data {
 	int id;
@@ -69,6 +72,11 @@
 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
 #endif
 
+#ifdef CONFIG_SYSVIPC_CROSS_SHM
+extern int shm_remote_free_pages(struct vm_area_struct *unmap_vma);
+extern int shm_do_remote_map_vma(struct vm_area_struct *vma, key_t key);
+#endif
+
 void shm_init_ns(struct ipc_namespace *ns)
 {
 	ns->shm_ctlmax = SHMMAX;
@@ -141,6 +149,24 @@
 	return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
+#ifdef CONFIG_SYSVIPC_CROSS_SHM
+void shm_mmap_pagetable(struct vm_area_struct *vma, struct file *file)
+{
+	int ret = 0;
+	struct shm_file_data *sfd;
+	struct shmid_kernel  *shp;
+
+	sfd = shm_file_data(file);
+	shp = shm_lock(sfd->ns, sfd->id);
+
+	ret = shm_do_remote_map_vma(vma, shp->shm_perm.key);
+	if (ret < 0)
+		printk("shm_mmap_pagetable Error");
+
+	shm_unlock(shp);
+}
+#endif
+
 static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp)
 {
 	rcu_read_lock();
@@ -240,6 +266,10 @@
 	shp->shm_lprid = task_tgid_vnr(current);
 	shp->shm_dtim = get_seconds();
 	shp->shm_nattch--;
+#ifdef CONFIG_SYSVIPC_CROSS_SHM
+	if (shp->shm_perm.rpmflag == TRUE)
+		shm_remote_free_pages(shp->shm_perm.key);
+#endif
 	if (shm_may_destroy(ns, shp))
 		shm_destroy(ns, shp);
 	else
@@ -517,6 +547,12 @@
 	shp->shm_nattch = 0;
 	shp->shm_file = file;
 	shp->shm_creator = current;
+#ifdef CONFIG_SYSVIPC_CROSS_SHM
+	if((key & SHM_REMOTE_ATTR_MASK) == SHM_REMOTE_ATTR_MASK)
+		shp->shm_perm.rpmflag = TRUE;
+	else
+		shp->shm_perm.rpmflag = FALSE;
+#endif
 	/*
 	 * shmid gets reported as "inode#" in /proc/pid/maps.
 	 * proc-ps tools use this. Changing this will break them.
@@ -1049,7 +1085,10 @@
 	sfd->ns = get_ipc_ns(ns);
 	sfd->file = shp->shm_file;
 	sfd->vm_ops = NULL;
-
+#ifdef CONFIG_SYSVIPC_CROSS_SHM	
+	if(shp->shm_perm.rpmflag == TRUE)
+		file->f_flags = SHM_REMOTE_ATTR_YES;
+#endif
 	down_write(&current->mm->mmap_sem);
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;