//------------------------------------------------------------------------------ static void SYSRAM_UnlockUser(SYSRAM_USER_ENUM const User) { if(SYSRAM_UserIsUnlocked(User)) { return; } // Debug Log. if((1<<User) & SysramLogUserMask) { SYSRAM_USER_STRUCT*const pUserInfo = &Sysram.UserInfo[User]; MUINT32 Sec, USec; MUINT64 Time64 = 0; SYSRAM_GetTime(&Time64,&Sec,&USec); // LOG_MSG("[%s][%lu bytes]Time(%lu.%06lu - %lu.%06lu)(%lu.%06lu)", SysramUserName[User], Sysram.AllocatedSize[User], pUserInfo->TimeS, pUserInfo->TimeUS, Sec, USec, ((MUINT32)(Time64-pUserInfo->Time64))/1000, ((MUINT32)(Time64-pUserInfo->Time64))%1000); } // if(Sysram.TotalUserCount > 0) { Sysram.TotalUserCount--; } Sysram.AllocatedTbl &= (~(1 << User)); Sysram.AllocatedSize[User] = 0; SYSRAM_ResetUserTaskInfo(User); }
/* ------------------------------------------------------------------------------ */ static int SYSRAM_Release(struct inode *pInode, struct file *pFile) { MUINT32 Index = 0; MUINT32 Sec = 0, USec = 0; MUINT64 Time64 = 0; SYSRAM_PROC_STRUCT *pProc; /* */ SYSRAM_GetTime(&Time64, &Sec, &USec); /* */ LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); /* */ if (pFile->private_data != NULL) { pProc = (SYSRAM_PROC_STRUCT *) (pFile->private_data); /* */ if (pProc->Pid != 0 || pProc->Tgid != 0 || pProc->Table != 0) { /* */ LOG_WRN("Proc:Name(%s),pid(%d),tgid(%d),Table(0x%08lX),Time(%ld.%06ld)", pProc->ProcName, pProc->Pid, pProc->Tgid, pProc->Table, pProc->TimeS, pProc->TimeUS); /* */ if (pProc->Table) { LOG_WRN("Force to release"); /* LOG_WRN("Proc:Name(%s),pid(%d),tgid(%d),Table(0x%08lX),Time(%ld.%06ld)", pProc->ProcName, pProc->Pid, pProc->Tgid, pProc->Table, pProc->TimeS, pProc->TimeUS); */ SYSRAM_DumpLayout(); /* */ for (Index = 0; Index < SYSRAM_USER_AMOUNT; Index++) { if (pProc->Table & (1 << Index)) { SYSRAM_IOC_Free((SYSRAM_USER_ENUM) Index); } } } } /* */ kfree(pFile->private_data); pFile->private_data = NULL; } else { LOG_WRN("private_data is NULL"); /* LOG_WRN("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); */ } /* */ return 0; }
//------------------------------------------------------------------------------ static int SYSRAM_Open( struct inode* pInode, struct file* pFile) { int Ret = 0; MUINT32 Sec = 0,USec = 0; MUINT64 Time64 = 0; SYSRAM_PROC_STRUCT* pProc; // SYSRAM_GetTime(&Time64, &Sec, &USec); // LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); // SYSRAM_SpinLock(); // pFile->private_data = kmalloc(sizeof(SYSRAM_PROC_STRUCT) , GFP_ATOMIC); if(pFile->private_data == NULL) { Ret = -ENOMEM; } else { pProc = (SYSRAM_PROC_STRUCT*)(pFile->private_data); pProc->Pid = 0; pProc->Tgid = 0; strcpy(pProc->ProcName,SYSRAM_PROC_NAME); pProc->Table = 0; pProc->Time64 = Time64; pProc->TimeS = Sec; pProc->TimeUS = USec; } // SYSRAM_SpinUnlock(); // if(Ret == (-ENOMEM)) { LOG_ERR("No enough memory"); /* LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); */ } // return Ret; }
/* ------------------------------------------------------------------------------ */ static void SYSRAM_SetUserTaskInfo(SYSRAM_USER_ENUM const User) { if (!SYSRAM_IsBadOwner(User)) { SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User]; /* */ pUserInfo->pid = current->pid; pUserInfo->tgid = current->tgid; memcpy(pUserInfo->ProcName, current->comm, sizeof(pUserInfo->ProcName)); /* */ SYSRAM_GetTime(&(pUserInfo->Time64), &(pUserInfo->TimeS), &(pUserInfo->TimeUS)); } }
//------------------------------------------------------------------------------ static long SYSRAM_Ioctl( struct file* pFile, unsigned int Cmd, unsigned long Param) { MINT32 Ret = 0; MUINT32 Sec = 0,USec = 0; MUINT64 Time64 = 0; SYSRAM_PROC_STRUCT* pProc = (SYSRAM_PROC_STRUCT*)pFile->private_data; SYSRAM_ALLOC_STRUCT Alloc; SYSRAM_USER_ENUM User; // SYSRAM_GetTime(&Time64, &Sec, &USec); /* LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); */ if(pFile->private_data == NULL) { LOG_WRN("private_data is NULL."); Ret = -EFAULT; goto EXIT; } // switch(Cmd) { case SYSRAM_ALLOC: { if(copy_from_user(&Alloc, (void*)Param, sizeof(SYSRAM_ALLOC_STRUCT)) == 0) { if(SYSRAM_IsBadOwner(Alloc.User)) { LOG_ERR("User(%d) out of range(%d)",Alloc.User,SYSRAM_USER_AMOUNT); Ret = -EFAULT; goto EXIT; } // Alloc.Addr = SYSRAM_IOC_Alloc( Alloc.User, Alloc.Size, Alloc.Alignment, Alloc.TimeoutMS); if(Alloc.Addr != 0) { SYSRAM_SpinLock(); pProc->Table |= (1 << Alloc.User); if(pProc->Tgid == 0) { pProc->Pid = current->pid; pProc->Tgid = current->tgid; strcpy(pProc->ProcName,current->comm); SYSRAM_SpinUnlock(); } else { SYSRAM_SpinUnlock(); if(pProc->Tgid != current->tgid) { LOG_ERR("Tgid is inconsistent"); Ret = -EFAULT; } } } else { Ret = -EFAULT; } // if(copy_to_user((void*)Param, &Alloc, sizeof(SYSRAM_ALLOC_STRUCT)) ) { LOG_ERR("copy to user failed"); Ret = -EFAULT; } } else { LOG_ERR("copy_from_user fail"); Ret = -EFAULT; } break; } // case SYSRAM_FREE: { if(copy_from_user(&User, (void*)Param, sizeof(SYSRAM_USER_ENUM)) == 0) { if(SYSRAM_IsBadOwner(User)) { LOG_ERR("User(%d) out of range(%d)",User,SYSRAM_USER_AMOUNT); Ret = -EFAULT; goto EXIT; } // SYSRAM_SpinLock(); if((pProc->Table) & (1 << User)) { SYSRAM_SpinUnlock(); SYSRAM_IOC_Free(User); SYSRAM_SpinLock(); // pProc->Table &= (~(1 << User)); if(pProc->Table == 0) { pProc->Pid = 0; pProc->Tgid = 0; strcpy(pProc->ProcName,SYSRAM_PROC_NAME); } SYSRAM_SpinUnlock(); } else { SYSRAM_SpinUnlock(); LOG_WRN("Freeing unallocated buffer user(%d)",User); Ret = -EFAULT; } } else { LOG_ERR("copy_from_user fail"); Ret = -EFAULT; } break; } case SYSRAM_DUMP: { SYSRAM_DumpLayout(); break; } default: { LOG_WRN("No such command"); Ret = -EINVAL; break; } } // EXIT: if(Ret != 0) { LOG_ERR("Fail"); LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); if(pFile->private_data != NULL) { LOG_ERR("Proc:Name(%s),pid(%d),tgid(%d),Table(0x%08lX),Time(%ld.%06ld)", pProc->ProcName, pProc->Pid, pProc->Tgid, pProc->Table, Sec, USec); } } // return Ret; }
//------------------------------------------------------------------------------ static int SYSRAM_Flush( struct file* pFile, fl_owner_t Id) { MUINT32 Index = 0; MUINT32 Sec = 0,USec = 0; MUINT64 Time64 = 0; SYSRAM_PROC_STRUCT* pProc; // SYSRAM_GetTime(&Time64, &Sec, &USec); // LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); // if(pFile->private_data != NULL) { pProc = (SYSRAM_PROC_STRUCT *)pFile->private_data; // if( pProc->Pid != 0 || pProc->Tgid != 0 || pProc->Table != 0) { // LOG_WRN("Proc:Name(%s),pid(%d),tgid(%d),Table(0x%08lX),Time(%ld.%06ld)", pProc->ProcName, pProc->Pid, pProc->Tgid, pProc->Table, pProc->TimeS, pProc->TimeUS); // if( pProc->Tgid == 0 && pProc->Table != 0) { LOG_ERR("No Tgid info"); /* LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); LOG_ERR("Proc:Name(%s),pid(%d),tgid(%d),Table(0x%08lX),Time(%ld.%06ld)", pProc->ProcName, pProc->Pid, pProc->Tgid, pProc->Table, pProc->TimeS, pProc->TimeUS); */ } else if( (pProc->Tgid == current->tgid) || ((pProc->Tgid != current->tgid) && (strcmp(current->comm, "binder") == 0))) { if(pProc->Table) { LOG_WRN("Force to release"); /* LOG_WRN("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); */ SYSRAM_DumpLayout(); // for(Index = 0 ; Index < SYSRAM_USER_AMOUNT; Index++) { if(pProc->Table & (1 << Index)) { SYSRAM_IOC_Free((SYSRAM_USER_ENUM)Index); } } // pProc->Table= 0; } } } } else { LOG_WRN("private_data is NULL"); /* LOG_WRN("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)", current->comm, current->pid, current->tgid, Sec, USec); */ } // return 0; }