static int do_nfs_rpc_call(struct nfs_server *server, int *start, int *end, int size) { struct file *file; struct inode *inode; struct socket *sock; unsigned short fs; int result; int xid; int len; select_table wait_table; struct select_table_entry entry; int (*select) (struct inode *, struct file *, int, select_table *); int init_timeout, max_timeout; int timeout; int retrans; int major_timeout_seen; char *server_name; int n; int addrlen; unsigned long old_mask; /* JEJB/JSP 2/7/94 * This is for a 4 byte recv of the xid only */ int recv_xid; xid = start[0]; len = ((char *) end) - ((char *) start); file = server->file; inode = file->f_inode; select = file->f_op->select; sock = socki_lookup(inode); if (!sock) { printk("nfs_rpc_call: socki_lookup failed\n"); return -EBADF; } init_timeout = server->timeo; max_timeout = NFS_MAX_RPC_TIMEOUT*HZ/10; retrans = server->retrans; major_timeout_seen = 0; server_name = server->hostname; old_mask = current->blocked; current->blocked |= ~(_S(SIGKILL) #if 0 | _S(SIGSTOP) #endif | ((server->flags & NFS_MOUNT_INTR) ? ((current->sigaction[SIGINT - 1].sa_handler == SIG_DFL ? _S(SIGINT) : 0) | (current->sigaction[SIGQUIT - 1].sa_handler == SIG_DFL ? _S(SIGQUIT) : 0)) : 0)); fs = get_fs(); set_fs(get_ds()); for (n = 0, timeout = init_timeout; ; n++, timeout <<= 1) { result = sock->ops->send(sock, (void *) start, len, 0, 0); if (result < 0) { printk("nfs_rpc_call: send error = %d\n", result); break; } re_select: wait_table.nr = 0; wait_table.entry = &entry; current->state = TASK_INTERRUPTIBLE; if (!select(inode, file, SEL_IN, &wait_table) && !select(inode, file, SEL_IN, NULL)) { if (timeout > max_timeout) { /* JEJB/JSP 2/7/94 * This is useful to see if the system is * hanging */ printk("NFS max timeout reached on %s\n", server_name); timeout = max_timeout; } current->timeout = jiffies + timeout; schedule(); remove_wait_queue(entry.wait_address, &entry.wait); current->state = TASK_RUNNING; if (current->signal & ~current->blocked) { current->timeout = 0; result = -ERESTARTSYS; break; } if (!current->timeout) { if (n < retrans) continue; if (server->flags & NFS_MOUNT_SOFT) { printk("NFS server %s not responding, " "timed out\n", server_name); result = -EIO; break; } n = 0; timeout = init_timeout; init_timeout <<= 1; if (!major_timeout_seen) { printk("NFS server %s not responding, " "still trying\n", server_name); } major_timeout_seen = 1; continue; } else current->timeout = 0; } else if (wait_table.nr) remove_wait_queue(entry.wait_address, &entry.wait); current->state = TASK_RUNNING; addrlen = 0; /* JEJB/JSP 2/7/94 * Get the xid from the next packet using a peek, so keep it * on the recv queue. If it is wrong, it will be some reply * we don't now need, so discard it */ result = sock->ops->recvfrom(sock, (void *)&recv_xid, sizeof(recv_xid), 1, MSG_PEEK, NULL, &addrlen); if (result < 0) { if (result == -EAGAIN) { #if 0 printk("nfs_rpc_call: bad select ready\n"); #endif goto re_select; } if (result == -ECONNREFUSED) { #if 0 printk("nfs_rpc_call: server playing coy\n"); #endif goto re_select; } if (result != -ERESTARTSYS) { printk("nfs_rpc_call: recv error = %d\n", -result); } break; } if (recv_xid == xid) { if (major_timeout_seen) printk("NFS server %s OK\n", server_name); break; } /* JEJB/JSP 2/7/94 * we have xid mismatch, so discard the packet and start * again. What a hack! but I can't call recvfrom with * a null buffer yet. */ (void)sock->ops->recvfrom(sock, (void *)&recv_xid, sizeof(recv_xid), 1, 0, NULL, &addrlen); #if 0 printk("nfs_rpc_call: XID mismatch\n"); #endif goto re_select; } /* JEJB/JSP 2/7/94 * * we have the correct xid, so read into the correct place and * return it * */ result=sock->ops->recvfrom(sock, (void *)start, size + 1024, 1, 0, NULL, /* Here is NFS_SLACK_SPACE..., hack */ &addrlen); if (result < addrlen) { printk("NFS: just caught a too small read memory size..., email to NET channel\n"); printk("NFS: result=%d,addrlen=%d\n", result, addrlen); result = -EIO; } current->blocked = old_mask; set_fs(fs); return result; }
/* * Write data to a file. * The stable flag requests synchronous writes. * N.B. After this call fhp needs an fh_put */ int nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, char *buf, unsigned long cnt, int stable) { struct svc_export *exp; struct file file; struct dentry *dentry; struct inode *inode; mm_segment_t oldfs; int err = 0; #ifdef CONFIG_QUOTA uid_t saved_euid; #endif if (!cnt) goto out; err = nfsd_open(rqstp, fhp, S_IFREG, OPEN_WRITE, &file); if (err) goto out; err = nfserr_perm; if (!file.f_op->write) goto out_close; dentry = file.f_dentry; inode = dentry->d_inode; exp = fhp->fh_export; /* * Request sync writes if * - the sync export option has been set, or * - the client requested O_SYNC behavior (NFSv3 feature). * When gathered writes have been configured for this volume, * flushing the data to disk is handled separately below. */ if ((stable || (stable = EX_ISSYNC(exp))) && !EX_WGATHER(exp)) file.f_flags |= O_SYNC; fh_lock(fhp); /* lock inode */ file.f_pos = offset; /* set write offset */ /* Write the data. */ oldfs = get_fs(); set_fs(KERNEL_DS); #ifdef CONFIG_QUOTA /* This is for disk quota. */ saved_euid = current->euid; current->euid = current->fsuid; err = file.f_op->write(&file, buf, cnt, &file.f_pos); current->euid = saved_euid; #else err = file.f_op->write(&file, buf, cnt, &file.f_pos); #endif set_fs(oldfs); /* clear setuid/setgid flag after write */ if (err >= 0 && (inode->i_mode & (S_ISUID | S_ISGID))) { struct iattr ia; kernel_cap_t saved_cap; ia.ia_valid = ATTR_MODE; ia.ia_mode = inode->i_mode & ~(S_ISUID | S_ISGID); if (current->fsuid != 0) { saved_cap = current->cap_effective; cap_clear(current->cap_effective); } notify_change(dentry, &ia); if (current->fsuid != 0) current->cap_effective = saved_cap; } fh_unlock(fhp); /* unlock inode */ if (err >= 0 && stable) { static unsigned long last_ino = 0; static kdev_t last_dev = NODEV; /* * Gathered writes: If another process is currently * writing to the file, there's a high chance * this is another nfsd (triggered by a bulk write * from a client's biod). Rather than syncing the * file with each write request, we sleep for 10 msec. * * I don't know if this roughly approximates * C. Juszak's idea of gathered writes, but it's a * nice and simple solution (IMHO), and it seems to * work:-) */ if (EX_WGATHER(exp) && (inode->i_writecount > 1 || (last_ino == inode->i_ino && last_dev == inode->i_dev))) { #if 0 interruptible_sleep_on_timeout(&inode->i_wait, 10 * HZ / 1000); #else dprintk("nfsd: write defer %d\n", current->pid); schedule_timeout((HZ+99)/100); dprintk("nfsd: write resume %d\n", current->pid); #endif } if (inode->i_state & I_DIRTY) { dprintk("nfsd: write sync %d\n", current->pid); nfsd_sync(inode, &file); write_inode_now(inode); } wake_up(&inode->i_wait); last_ino = inode->i_ino; last_dev = inode->i_dev; } dprintk("nfsd: write complete\n"); if (err >= 0) err = 0; else err = nfserrno(-err); out_close: nfsd_close(&file); out: return err; }
/* MOD 0014570: [FACTORY RESET] change system call to filp function for handling the flag */ int lge_mmc_read_mbr (MmcPartition *mbr) { //int fd; unsigned char *buffer = NULL; char *device_index = NULL; int idx, i; unsigned mmc_partition_count = 0; unsigned int dtype; unsigned int dfirstsec; unsigned int EBR_first_sec; unsigned int EBR_current_sec; int ret = -1; struct file *phMscd_Filp = NULL; mm_segment_t old_fs; old_fs=get_fs(); set_fs(get_ds()); buffer = kmalloc(512, GFP_KERNEL); device_index = kmalloc(128, GFP_KERNEL); if((buffer == NULL) || (device_index == NULL)) { printk("%s, allocation failed\n", __func__); goto ERROR2; } // change from sys operation to flip operation, do not use system call since this routine is also system call service. phMscd_Filp = filp_open(MMC_DEVICENAME, O_RDONLY, 0); if( !phMscd_Filp) { printk(KERN_ERR "%s, Can't open device\n", __func__ ); goto ERROR2; } phMscd_Filp->f_pos = (loff_t)0; if (phMscd_Filp->f_op->read(phMscd_Filp, buffer, 512, &phMscd_Filp->f_pos) != 512) { printk(KERN_ERR "%s, Can't read device: \"%s\"\n", __func__, MMC_DEVICENAME); goto ERROR1; } /* Check to see if signature exists */ if ((buffer[TABLE_SIGNATURE] != 0x55) || \ (buffer[TABLE_SIGNATURE + 1] != 0xAA)) { printk(KERN_ERR "Incorrect mbr signatures!\n"); goto ERROR1; } idx = TABLE_ENTRY_0; for (i = 0; i < 4; i++) { //char device_index[128]; mbr[mmc_partition_count].dstatus = \ buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_STATUS]; mbr[mmc_partition_count].dtype = \ buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_TYPE]; mbr[mmc_partition_count].dfirstsec = \ GET_LWORD_FROM_BYTE(&buffer[idx + \ i * TABLE_ENTRY_SIZE + \ OFFSET_FIRST_SEC]); mbr[mmc_partition_count].dsize = \ GET_LWORD_FROM_BYTE(&buffer[idx + \ i * TABLE_ENTRY_SIZE + \ OFFSET_SIZE]); dtype = mbr[mmc_partition_count].dtype; dfirstsec = mbr[mmc_partition_count].dfirstsec; lge_mmc_partition_name(&mbr[mmc_partition_count], \ mbr[mmc_partition_count].dtype); sprintf(device_index, "%sp%d", MMC_DEVICENAME, (mmc_partition_count+1)); mbr[mmc_partition_count].device_index = lge_strdup(device_index); mmc_partition_count++; if (mmc_partition_count == MAX_PARTITIONS) goto SUCCESS; } /* See if the last partition is EBR, if not, parsing is done */ if (dtype != 0x05) { goto SUCCESS; } EBR_first_sec = dfirstsec; EBR_current_sec = dfirstsec; phMscd_Filp->f_pos = (loff_t)(EBR_first_sec * 512); if (phMscd_Filp->f_op->read(phMscd_Filp, buffer, 512, &phMscd_Filp->f_pos) != 512) { printk(KERN_ERR "%s, Can't read device: \"%s\"\n", __func__, MMC_DEVICENAME); goto ERROR1; } /* Loop to parse the EBR */ for (i = 0;; i++) { if ((buffer[TABLE_SIGNATURE] != 0x55) || (buffer[TABLE_SIGNATURE + 1] != 0xAA)) { break; } mbr[mmc_partition_count].dstatus = \ buffer[TABLE_ENTRY_0 + OFFSET_STATUS]; mbr[mmc_partition_count].dtype = \ buffer[TABLE_ENTRY_0 + OFFSET_TYPE]; mbr[mmc_partition_count].dfirstsec = \ GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 + \ OFFSET_FIRST_SEC]) + \ EBR_current_sec; mbr[mmc_partition_count].dsize = \ GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 + \ OFFSET_SIZE]); lge_mmc_partition_name(&mbr[mmc_partition_count], \ mbr[mmc_partition_count].dtype); sprintf(device_index, "%sp%d", MMC_DEVICENAME, (mmc_partition_count+1)); mbr[mmc_partition_count].device_index = lge_strdup(device_index); mmc_partition_count++; if (mmc_partition_count == MAX_PARTITIONS) goto SUCCESS; dfirstsec = GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_1 + OFFSET_FIRST_SEC]); if(dfirstsec == 0) { /* Getting to the end of the EBR tables */ break; } /* More EBR to follow - read in the next EBR sector */ phMscd_Filp->f_pos = (loff_t)((EBR_first_sec + dfirstsec) * 512); if (phMscd_Filp->f_op->read(phMscd_Filp, buffer, 512, &phMscd_Filp->f_pos) != 512) { printk(KERN_ERR "%s, Can't read device: \"%s\"\n", __func__, MMC_DEVICENAME); goto ERROR1; } EBR_current_sec = EBR_first_sec + dfirstsec; } SUCCESS: ret = mmc_partition_count; ERROR1: if(phMscd_Filp != NULL) filp_close(phMscd_Filp,NULL); ERROR2: set_fs(old_fs); if(buffer != NULL) kfree(buffer); if(device_index != NULL) kfree(device_index); return ret; }
void ssp_dump_task(struct work_struct *work) { struct ssp_big *big; struct file *dump_file; struct ssp_msg *msg; char *buffer; char strFilePath[60]; struct timeval cur_time; int iTimeTemp; mm_segment_t fs; int buf_len, packet_len, residue, iRet = 0, index = 0 ,iRetTrans=0 ,iRetWrite=0; big = container_of(work, struct ssp_big, work); pr_err("[SSP]: %s - start ssp dumping (%d)(%d)\n", __func__,big->data->bMcuDumpMode,big->data->uDumpCnt); big->data->uDumpCnt++; wake_lock(&big->data->ssp_wake_lock); fs = get_fs(); set_fs(get_ds()); if(big->data->bMcuDumpMode == true) { do_gettimeofday(&cur_time); iTimeTemp = (int) cur_time.tv_sec; sprintf(strFilePath, "%s%d.txt", DUMP_FILE_PATH, iTimeTemp); dump_file = filp_open(strFilePath, O_RDWR | O_CREAT | O_APPEND, 0666); if (IS_ERR(dump_file)) { pr_err("[SSP]: %s - Can't open dump file\n", __func__); set_fs(fs); iRet = PTR_ERR(dump_file); wake_unlock(&big->data->ssp_wake_lock); return; } } else dump_file = NULL; buf_len = big->length > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : big->length; buffer = kzalloc(buf_len, GFP_KERNEL); residue = big->length; while (residue > 0) { packet_len = residue > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : residue; msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MSG2SSP_AP_GET_BIG_DATA; msg->length = packet_len; msg->options = AP2HUB_READ | (index++ << SSP_INDEX); msg->data = big->addr; msg->buffer = buffer; msg->free_buffer = 0; iRetTrans = ssp_spi_sync(big->data, msg, 1000); if (iRetTrans != SUCCESS) { pr_err("[SSP]: %s - Fail to receive data %d (%d)\n", __func__, iRetTrans,residue); break; } if(big->data->bMcuDumpMode == true) { iRetWrite = vfs_write(dump_file, (char __user *) buffer, packet_len, &dump_file->f_pos); if (iRetWrite < 0) { pr_err("[SSP]: %s - Can't write dump to file\n", __func__); break; } } residue -= packet_len; } if(big->data->bMcuDumpMode == true && (iRetTrans != SUCCESS || iRetWrite < 0) ) { char FAILSTRING[100]; sprintf(FAILSTRING,"FAIL OCCURED(%d)(%d)(%d)",iRetTrans,iRetWrite,big->length); vfs_write(dump_file, (char __user *) FAILSTRING, strlen(FAILSTRING),&dump_file->f_pos); } ssp_send_cmd(big->data, MSG2SSP_AP_MCU_DUMP_FINISH, SUCCESS); big->data->bDumping = false; if(big->data->bMcuDumpMode == true) filp_close(dump_file, current->files); set_fs(fs); sanity_check(big->data); wake_unlock(&big->data->ssp_wake_lock); kfree(buffer); kfree(big); pr_err("[SSP]: %s done\n", __func__); }
void do_rt_sigreturn(struct pt_regs *regs) { struct rt_signal_frame *sf; unsigned long tpc, tnpc, tstate; __siginfo_fpu_t *fpu_save; mm_segment_t old_fs; sigset_t set; stack_t st; int err; synchronize_user_stack (); sf = (struct rt_signal_frame *) (regs->u_regs [UREG_FP] + STACK_BIAS); /* 1. Make sure we are not getting garbage from the user */ if (((unsigned long) sf) & 3) goto segv; err = get_user(tpc, &sf->regs.tpc); err |= __get_user(tnpc, &sf->regs.tnpc); if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { tpc &= 0xffffffff; tnpc &= 0xffffffff; } err |= ((tpc | tnpc) & 3); /* 2. Restore the state */ err |= __get_user(regs->y, &sf->regs.y); err |= __get_user(tstate, &sf->regs.tstate); err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs)); /* User can only change condition codes in %tstate. */ regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC); regs->tstate |= (tstate & (TSTATE_ICC | TSTATE_XCC)); err |= __get_user(fpu_save, &sf->fpu_save); if (fpu_save) err |= restore_fpu_state(regs, &sf->fpu_state); err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t)); err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t)); if (err) goto segv; regs->tpc = tpc; regs->tnpc = tnpc; /* It is more difficult to avoid calling this function than to call it and ignore errors. */ old_fs = get_fs(); set_fs(KERNEL_DS); do_sigaltstack(&st, NULL, (unsigned long)sf); set_fs(old_fs); sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); return; segv: send_sig(SIGSEGV, current, 1); }
/* copy up a dentry to a file of specified name */ static int copyup_named_dentry(struct inode *dir, struct dentry *dentry, int bstart, int new_bindex, const char *name, int namelen, struct file **copyup_file, loff_t len) { struct dentry *new_hidden_dentry; struct dentry *old_hidden_dentry = NULL; struct super_block *sb; int err = 0; int old_bindex; int old_bstart; int old_bend; struct dentry *new_hidden_parent_dentry = NULL; mm_segment_t oldfs; char *symbuf = NULL; verify_locked(dentry); old_bindex = bstart; old_bstart = dbstart(dentry); old_bend = dbend(dentry); BUG_ON(new_bindex < 0); BUG_ON(new_bindex >= old_bindex); sb = dir->i_sb; unionfs_read_lock(sb); if ((err = is_robranch_super(sb, new_bindex))) { dput(old_hidden_dentry); goto out; } /* Create the directory structure above this dentry. */ new_hidden_dentry = create_parents_named(dir, dentry, name, new_bindex); if (IS_ERR(new_hidden_dentry)) { dput(old_hidden_dentry); err = PTR_ERR(new_hidden_dentry); goto out; } old_hidden_dentry = unionfs_lower_dentry_idx(dentry, old_bindex); dget(old_hidden_dentry); /* For symlinks, we must read the link before we lock the directory. */ if (S_ISLNK(old_hidden_dentry->d_inode->i_mode)) { symbuf = kmalloc(PATH_MAX, GFP_KERNEL); if (!symbuf) { __clear(dentry, old_hidden_dentry, old_bstart, old_bend, new_hidden_dentry, new_bindex); err = -ENOMEM; goto out_free; } oldfs = get_fs(); set_fs(KERNEL_DS); err = old_hidden_dentry->d_inode->i_op->readlink( old_hidden_dentry, (char __user *)symbuf, PATH_MAX); set_fs(oldfs); if (err) { __clear(dentry, old_hidden_dentry, old_bstart, old_bend, new_hidden_dentry, new_bindex); goto out_free; } symbuf[err] = '\0'; } /* Now we lock the parent, and create the object in the new branch. */ new_hidden_parent_dentry = lock_parent(new_hidden_dentry); /* create the new inode */ err = __copyup_ndentry(old_hidden_dentry, new_hidden_dentry, new_hidden_parent_dentry, symbuf); if (err) { __clear(dentry, old_hidden_dentry, old_bstart, old_bend, new_hidden_dentry, new_bindex); goto out_unlock; } /* We actually copyup the file here. */ if (S_ISREG(old_hidden_dentry->d_inode->i_mode)) err = __copyup_reg_data(dentry, new_hidden_dentry, new_bindex, old_hidden_dentry, old_bindex, copyup_file, len); if (err) goto out_unlink; /* Set permissions. */ if ((err = copyup_permissions(sb, old_hidden_dentry, new_hidden_dentry))) goto out_unlink; #ifdef CONFIG_UNION_FS_XATTR /* Selinux uses extended attributes for permissions. */ if ((err = copyup_xattrs(old_hidden_dentry, new_hidden_dentry))) goto out_unlink; #endif /* do not allow files getting deleted to be reinterposed */ if (!d_deleted(dentry)) unionfs_reinterpose(dentry); goto out_unlock; /****/ out_unlink: /* copyup failed, because we possibly ran out of space or * quota, or something else happened so let's unlink; we don't * really care about the return value of vfs_unlink */ vfs_unlink(new_hidden_parent_dentry->d_inode, new_hidden_dentry); if (copyup_file) { /* need to close the file */ fput(*copyup_file); branchput(sb, new_bindex); } /* * TODO: should we reset the error to something like -EIO? * * If we don't reset, the user may get some non-sensical errors, but * on the other hand, if we reset to EIO, we guarantee that the user * will get a "confusing" error message. */ out_unlock: unlock_dir(new_hidden_parent_dentry); out_free: kfree(symbuf); out: unionfs_read_unlock(sb); return err; }
static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *frame; int err = 0; int signal; frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) goto give_sigsegv; signal = current_thread_info()->exec_domain && current_thread_info()->exec_domain->signal_invmap && sig < 32 ? current_thread_info()->exec_domain->signal_invmap[sig] : sig; err |= __put_user(&frame->info, &frame->pinfo); err |= __put_user(&frame->uc, &frame->puc); err |= copy_siginfo_to_user(&frame->info, info); /* Give up earlier as i386, in case */ if (err) goto give_sigsegv; /* Create the ucontext. */ err |= __put_user(0, &frame->uc.uc_flags); err |= __put_user(0, &frame->uc.uc_link); err |= __put_user((void *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __put_user(sas_ss_flags(regs->regs[REG_SP]), &frame->uc.uc_stack.ss_flags); err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]); err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); /* Give up earlier as i386, in case */ if (err) goto give_sigsegv; /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags & SA_RESTORER) { DEREF_REG_PR = (unsigned long) ka->sa.sa_restorer | 0x1; /* * On SH5 all edited pointers are subject to NEFF */ DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ? (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR; } else { /* * Different approach on SH5. * . Endianness independent asm code gets placed in entry.S . * This is limited to four ASM instructions corresponding * to two long longs in size. * . err checking is done on the else branch only * . flush_icache_range() is called upon __put_user() only * . all edited pointers are subject to NEFF * . being code, linker turns ShMedia bit on, always * dereference index -1. */ DEREF_REG_PR = (unsigned long) frame->retcode | 0x01; DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ? (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR; if (__copy_to_user(frame->retcode, (unsigned long long)sa_default_rt_restorer & (~1), 16) != 0) goto give_sigsegv; flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15); } /* * Set up registers for signal handler. * All edited pointers are subject to NEFF. */ regs->regs[REG_SP] = (unsigned long) frame; regs->regs[REG_SP] = (regs->regs[REG_SP] & NEFF_SIGN) ? (regs->regs[REG_SP] | NEFF_MASK) : regs->regs[REG_SP]; regs->regs[REG_ARG1] = signal; /* Arg for signal handler */ regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info; regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext; regs->pc = (unsigned long) ka->sa.sa_handler; regs->pc = (regs->pc & NEFF_SIGN) ? (regs->pc | NEFF_MASK) : regs->pc; set_fs(USER_DS); #if DEBUG_SIG /* Broken %016Lx */ printk("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n", signal, current->comm, current->pid, frame, regs->pc >> 32, regs->pc & 0xffffffff, DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff); #endif return; give_sigsegv: force_sigsegv(sig, current); }
static void emulate_load_store_insn(struct pt_regs *regs, void __user *addr, unsigned int __user *pc) { union mips_instruction insn; unsigned long value; unsigned int res; unsigned long origpc; unsigned long orig31; void __user *fault_addr = NULL; #ifdef CONFIG_EVA mm_segment_t seg; #endif origpc = (unsigned long)pc; orig31 = regs->regs[31]; perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0); /* * This load never faults. */ __get_user(insn.word, pc); switch (insn.i_format.opcode) { /* * These are instructions that a compiler doesn't generate. We * can assume therefore that the code is MIPS-aware and * really buggy. Emulating these instructions would break the * semantics anyway. */ case ll_op: case lld_op: case sc_op: case scd_op: /* * For these instructions the only way to create an address * error is an attempted access to kernel/supervisor address * space. */ case ldl_op: case ldr_op: case lwl_op: case lwr_op: case sdl_op: case sdr_op: case swl_op: case swr_op: case lb_op: case lbu_op: case sb_op: goto sigbus; /* * The remaining opcodes are the ones that are really of * interest. */ #ifdef CONFIG_EVA case spec3_op: /* * we can land here only from kernel accessing user memory, * so we need to "switch" the address limit to user space, so * address check can work properly. */ seg = get_fs(); set_fs(USER_DS); switch (insn.spec3_format.func) { case lhe_op: if (!access_ok(VERIFY_READ, addr, 2)) { set_fs(seg); goto sigbus; } LoadHW(addr, value, res); if (res) { set_fs(seg); goto fault; } compute_return_epc(regs); regs->regs[insn.spec3_format.rt] = value; break; case lwe_op: if (!access_ok(VERIFY_READ, addr, 4)) { set_fs(seg); goto sigbus; } LoadW(addr, value, res); if (res) { set_fs(seg); goto fault; } compute_return_epc(regs); regs->regs[insn.spec3_format.rt] = value; break; case lhue_op: if (!access_ok(VERIFY_READ, addr, 2)) { set_fs(seg); goto sigbus; } LoadHWU(addr, value, res); if (res) { set_fs(seg); goto fault; } compute_return_epc(regs); regs->regs[insn.spec3_format.rt] = value; break; case she_op: if (!access_ok(VERIFY_WRITE, addr, 2)) { set_fs(seg); goto sigbus; } compute_return_epc(regs); value = regs->regs[insn.spec3_format.rt]; StoreHW(addr, value, res); if (res) { set_fs(seg); goto fault; } break; case swe_op: if (!access_ok(VERIFY_WRITE, addr, 4)) { set_fs(seg); goto sigbus; } compute_return_epc(regs); value = regs->regs[insn.spec3_format.rt]; StoreW(addr, value, res); if (res) { set_fs(seg); goto fault; } break; default: set_fs(seg); goto sigill; } set_fs(seg); break; #endif case lh_op: if (!access_ok(VERIFY_READ, addr, 2)) goto sigbus; LoadHW(addr, value, res); if (res) goto fault; compute_return_epc(regs); regs->regs[insn.i_format.rt] = value; break; case lw_op: if (!access_ok(VERIFY_READ, addr, 4)) goto sigbus; LoadW(addr, value, res); if (res) goto fault; compute_return_epc(regs); regs->regs[insn.i_format.rt] = value; break; case lhu_op: if (!access_ok(VERIFY_READ, addr, 2)) goto sigbus; LoadHWU(addr, value, res); if (res) goto fault; compute_return_epc(regs); regs->regs[insn.i_format.rt] = value; break; case lwu_op: #ifdef CONFIG_64BIT /* * A 32-bit kernel might be running on a 64-bit processor. But * if we're on a 32-bit processor and an i-cache incoherency * or race makes us see a 64-bit instruction here the sdl/sdr * would blow up, so for now we don't handle unaligned 64-bit * instructions on 32-bit kernels. */ if (!access_ok(VERIFY_READ, addr, 4)) goto sigbus; LoadWU(addr, value, res); if (res) goto fault; compute_return_epc(regs); regs->regs[insn.i_format.rt] = value; break; #endif /* CONFIG_64BIT */ /* Cannot handle 64-bit instructions in 32-bit kernel */ goto sigill; case ld_op: #ifdef CONFIG_64BIT /* * A 32-bit kernel might be running on a 64-bit processor. But * if we're on a 32-bit processor and an i-cache incoherency * or race makes us see a 64-bit instruction here the sdl/sdr * would blow up, so for now we don't handle unaligned 64-bit * instructions on 32-bit kernels. */ if (!access_ok(VERIFY_READ, addr, 8)) goto sigbus; LoadDW(addr, value, res); if (res) goto fault; compute_return_epc(regs); regs->regs[insn.i_format.rt] = value; break; #endif /* CONFIG_64BIT */ /* Cannot handle 64-bit instructions in 32-bit kernel */ goto sigill; case sh_op: if (!access_ok(VERIFY_WRITE, addr, 2)) goto sigbus; compute_return_epc(regs); value = regs->regs[insn.i_format.rt]; StoreHW(addr, value, res); if (res) goto fault; break; case sw_op: if (!access_ok(VERIFY_WRITE, addr, 4)) goto sigbus; compute_return_epc(regs); value = regs->regs[insn.i_format.rt]; StoreW(addr, value, res); if (res) goto fault; break; case sd_op: #ifdef CONFIG_64BIT /* * A 32-bit kernel might be running on a 64-bit processor. But * if we're on a 32-bit processor and an i-cache incoherency * or race makes us see a 64-bit instruction here the sdl/sdr * would blow up, so for now we don't handle unaligned 64-bit * instructions on 32-bit kernels. */ if (!access_ok(VERIFY_WRITE, addr, 8)) goto sigbus; compute_return_epc(regs); value = regs->regs[insn.i_format.rt]; StoreDW(addr, value, res); if (res) goto fault; break; #endif /* CONFIG_64BIT */ /* Cannot handle 64-bit instructions in 32-bit kernel */ goto sigill; case lwc1_op: case ldc1_op: case swc1_op: case sdc1_op: die_if_kernel("Unaligned FP access in kernel code", regs); BUG_ON(!used_math()); BUG_ON(!is_fpu_owner()); lose_fpu(1); /* Save FPU state for the emulator. */ res = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1, &fault_addr); own_fpu(1); /* Restore FPU state. */ /* Signal if something went wrong. */ process_fpemu_return(res, fault_addr); if (res == 0) break; return; /* * COP2 is available to implementor for application specific use. * It's up to applications to register a notifier chain and do * whatever they have to do, including possible sending of signals. */ case lwc2_op: cu2_notifier_call_chain(CU2_LWC2_OP, regs); break; case ldc2_op: cu2_notifier_call_chain(CU2_LDC2_OP, regs); break; case swc2_op: cu2_notifier_call_chain(CU2_SWC2_OP, regs); break; case sdc2_op: cu2_notifier_call_chain(CU2_SDC2_OP, regs); break; default: /* * Pheeee... We encountered an yet unknown instruction or * cache coherence problem. Die sucker, die ... */ goto sigill; } #ifdef CONFIG_DEBUG_FS unaligned_instructions++; #endif return; fault: /* roll back jump/branch */ regs->cp0_epc = origpc; regs->regs[31] = orig31; /* Did we have an exception handler installed? */ if (fixup_exception(regs)) return; die_if_kernel("Unhandled kernel unaligned access", regs); force_sig(SIGSEGV, current); return; sigbus: die_if_kernel("Unhandled kernel unaligned access", regs); force_sig(SIGBUS, current); return; sigill: die_if_kernel ("Unhandled kernel unaligned access or invalid instruction", regs); force_sig(SIGILL, current); }
bool _LGE_GENERIC_WRITE_FUN(unsigned char *buff, unsigned int offset, unsigned int length) { int ret; struct file *filp; unsigned char *tmp; mm_segment_t curr_fs; filp = filp_open(PART_NAME, O_RDWR, 0666); if (IS_ERR(filp)) { ret = PTR_ERR(filp); printk("Open MISC2 partition fail! errno=%d\n", ret); return -1; } if (g_init_write_size ==0) { struct mtd_info_user info; if (filp->f_op->unlocked_ioctl) { filp->f_op->unlocked_ioctl(filp, MEMGETINFO, &info); } else if (filp->f_op->compat_ioctl) { filp->f_op->compat_ioctl(filp, MEMGETINFO, &info); } if (info.writesize != EMMC_BLOCK_SIZE) { printk("write size error!info.writesize=%d,EMMC_BLOCK_SIZE=%d\n", info.writesize, EMMC_BLOCK_SIZE); g_init_write_size = 0; filp_close(filp, NULL); return false; } else { g_init_write_size = 1; } } filp->f_op->llseek(filp, offset * EMMC_BLOCK_SIZE, SEEK_SET); tmp = kzalloc(EMMC_BLOCK_SIZE, GFP_KERNEL); if (!tmp) { printk("malloc memory fail!\n"); filp_close(filp, NULL); return false; } memset(tmp, 0x0, EMMC_BLOCK_SIZE); curr_fs = get_fs(); set_fs(KERNEL_DS); memcpy(tmp, buff, length); ret = filp->f_op->write(filp, tmp, EMMC_BLOCK_SIZE, &(filp->f_pos)); if (EMMC_BLOCK_SIZE != ret) { printk("write fail!errno=%d\n", ret); filp_close(filp, NULL); kfree(tmp); set_fs(curr_fs); return false; } set_fs(curr_fs); kfree(tmp); filp_close(filp, NULL); return true; }
static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); void *karg = NULL; unsigned int kcmd = 0; int i, err; for (i = 0; i < NR_FD_IOCTL_TRANS; i++) if (cmd == fd_ioctl_trans_table[i].cmd32) { kcmd = fd_ioctl_trans_table[i].cmd; break; } if (!kcmd) return -EINVAL; switch (cmd) { case FDSETPRM32: case FDDEFPRM32: case FDGETPRM32: { compat_uptr_t name; struct compat_floppy_struct __user *uf; struct floppy_struct *f; uf = compat_ptr(arg); f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL); if (!karg) return -ENOMEM; if (cmd == FDGETPRM32) break; err = __get_user(f->size, &uf->size); err |= __get_user(f->sect, &uf->sect); err |= __get_user(f->head, &uf->head); err |= __get_user(f->track, &uf->track); err |= __get_user(f->stretch, &uf->stretch); err |= __get_user(f->gap, &uf->gap); err |= __get_user(f->rate, &uf->rate); err |= __get_user(f->spec1, &uf->spec1); err |= __get_user(f->fmt_gap, &uf->fmt_gap); err |= __get_user(name, &uf->name); f->name = compat_ptr(name); if (err) { err = -EFAULT; goto out; } break; } case FDSETDRVPRM32: case FDGETDRVPRM32: { struct compat_floppy_drive_params __user *uf; struct floppy_drive_params *f; uf = compat_ptr(arg); f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL); if (!karg) return -ENOMEM; if (cmd == FDGETDRVPRM32) break; err = __get_user(f->cmos, &uf->cmos); err |= __get_user(f->max_dtr, &uf->max_dtr); err |= __get_user(f->hlt, &uf->hlt); err |= __get_user(f->hut, &uf->hut); err |= __get_user(f->srt, &uf->srt); err |= __get_user(f->spinup, &uf->spinup); err |= __get_user(f->spindown, &uf->spindown); err |= __get_user(f->spindown_offset, &uf->spindown_offset); err |= __get_user(f->select_delay, &uf->select_delay); err |= __get_user(f->rps, &uf->rps); err |= __get_user(f->tracks, &uf->tracks); err |= __get_user(f->timeout, &uf->timeout); err |= __get_user(f->interleave_sect, &uf->interleave_sect); err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors)); err |= __get_user(f->flags, &uf->flags); err |= __get_user(f->read_track, &uf->read_track); err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect)); err |= __get_user(f->checkfreq, &uf->checkfreq); err |= __get_user(f->native_format, &uf->native_format); if (err) { err = -EFAULT; goto out; } break; } case FDGETDRVSTAT32: case FDPOLLDRVSTAT32: karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL); if (!karg) return -ENOMEM; break; case FDGETFDCSTAT32: karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL); if (!karg) return -ENOMEM; break; case FDWERRORGET32: karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL); if (!karg) return -ENOMEM; break; default: return -EINVAL; } set_fs(KERNEL_DS); err = __blkdev_driver_ioctl(bdev, mode, kcmd, (unsigned long)karg); set_fs(old_fs); if (err) goto out; switch (cmd) { case FDGETPRM32: { struct floppy_struct *f = karg; struct compat_floppy_struct __user *uf = compat_ptr(arg); err = __put_user(f->size, &uf->size); err |= __put_user(f->sect, &uf->sect); err |= __put_user(f->head, &uf->head); err |= __put_user(f->track, &uf->track); err |= __put_user(f->stretch, &uf->stretch); err |= __put_user(f->gap, &uf->gap); err |= __put_user(f->rate, &uf->rate); err |= __put_user(f->spec1, &uf->spec1); err |= __put_user(f->fmt_gap, &uf->fmt_gap); err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name); break; } case FDGETDRVPRM32: { struct compat_floppy_drive_params __user *uf; struct floppy_drive_params *f = karg; uf = compat_ptr(arg); err = __put_user(f->cmos, &uf->cmos); err |= __put_user(f->max_dtr, &uf->max_dtr); err |= __put_user(f->hlt, &uf->hlt); err |= __put_user(f->hut, &uf->hut); err |= __put_user(f->srt, &uf->srt); err |= __put_user(f->spinup, &uf->spinup); err |= __put_user(f->spindown, &uf->spindown); err |= __put_user(f->spindown_offset, &uf->spindown_offset); err |= __put_user(f->select_delay, &uf->select_delay); err |= __put_user(f->rps, &uf->rps); err |= __put_user(f->tracks, &uf->tracks); err |= __put_user(f->timeout, &uf->timeout); err |= __put_user(f->interleave_sect, &uf->interleave_sect); err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors)); err |= __put_user(f->flags, &uf->flags); err |= __put_user(f->read_track, &uf->read_track); err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect)); err |= __put_user(f->checkfreq, &uf->checkfreq); err |= __put_user(f->native_format, &uf->native_format); break; } case FDGETDRVSTAT32: case FDPOLLDRVSTAT32: { struct compat_floppy_drive_struct __user *uf; struct floppy_drive_struct *f = karg; uf = compat_ptr(arg); err = __put_user(f->flags, &uf->flags); err |= __put_user(f->spinup_date, &uf->spinup_date); err |= __put_user(f->select_date, &uf->select_date); err |= __put_user(f->first_read_date, &uf->first_read_date); err |= __put_user(f->probed_format, &uf->probed_format); err |= __put_user(f->track, &uf->track); err |= __put_user(f->maxblock, &uf->maxblock); err |= __put_user(f->maxtrack, &uf->maxtrack); err |= __put_user(f->generation, &uf->generation); err |= __put_user(f->keep_data, &uf->keep_data); err |= __put_user(f->fd_ref, &uf->fd_ref); err |= __put_user(f->fd_device, &uf->fd_device); err |= __put_user(f->last_checked, &uf->last_checked); err |= __put_user((u64)f->dmabuf, &uf->dmabuf); err |= __put_user((u64)f->bufblocks, &uf->bufblocks); break; } case FDGETFDCSTAT32: { struct compat_floppy_fdc_state __user *uf; struct floppy_fdc_state *f = karg; uf = compat_ptr(arg); err = __put_user(f->spec1, &uf->spec1); err |= __put_user(f->spec2, &uf->spec2); err |= __put_user(f->dtr, &uf->dtr); err |= __put_user(f->version, &uf->version); err |= __put_user(f->dor, &uf->dor); err |= __put_user(f->address, &uf->address); err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address), (char *)&f->address + sizeof(f->address), sizeof(int)); err |= __put_user(f->driver_version, &uf->driver_version); err |= __copy_to_user(uf->track, f->track, sizeof(f->track)); break; } case FDWERRORGET32: { struct compat_floppy_write_errors __user *uf; struct floppy_write_errors *f = karg; uf = compat_ptr(arg); err = __put_user(f->write_errors, &uf->write_errors); err |= __put_user(f->first_error_sector, &uf->first_error_sector); err |= __put_user(f->first_error_generation, &uf->first_error_generation); err |= __put_user(f->last_error_sector, &uf->last_error_sector); err |= __put_user(f->last_error_generation, &uf->last_error_generation); err |= __put_user(f->badness, &uf->badness); break; } default: break; } if (err) err = -EFAULT; out: kfree(karg); return err; }
asmlinkage void do_ade(struct pt_regs *regs) { enum ctx_state prev_state; unsigned int __user *pc; mm_segment_t seg; prev_state = exception_enter(); perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, regs->cp0_badvaddr); /* * Did we catch a fault trying to load an instruction? */ if (regs->cp0_badvaddr == regs->cp0_epc) goto sigbus; if (user_mode(regs) && !test_thread_flag(TIF_FIXADE)) goto sigbus; if (unaligned_action == UNALIGNED_ACTION_SIGNAL) goto sigbus; /* * Do branch emulation only if we didn't forward the exception. * This is all so but ugly ... */ /* * Are we running in microMIPS mode? */ if (get_isa16_mode(regs->cp0_epc)) { /* * Did we catch a fault trying to load an instruction in * 16-bit mode? */ if (regs->cp0_badvaddr == msk_isa16_mode(regs->cp0_epc)) goto sigbus; if (unaligned_action == UNALIGNED_ACTION_SHOW) show_registers(regs); if (cpu_has_mmips) { seg = get_fs(); if (!user_mode(regs)) set_fs(KERNEL_DS); emulate_load_store_microMIPS(regs, (void __user *)regs->cp0_badvaddr); set_fs(seg); return; } if (cpu_has_mips16) { seg = get_fs(); if (!user_mode(regs)) set_fs(KERNEL_DS); emulate_load_store_MIPS16e(regs, (void __user *)regs->cp0_badvaddr); set_fs(seg); return; } goto sigbus; } if (unaligned_action == UNALIGNED_ACTION_SHOW) show_registers(regs); pc = (unsigned int __user *)exception_epc(regs); seg = get_fs(); if (!user_mode(regs)) set_fs(KERNEL_DS); emulate_load_store_insn(regs, (void __user *)regs->cp0_badvaddr, pc); set_fs(seg); return; sigbus: die_if_kernel("Kernel unaligned instruction access", regs); force_sig(SIGBUS, current); /* * XXX On return from the signal handler we should advance the epc */ exception_exit(prev_state); }
/* * ======== OsalKfile_open ======== */ Int OsalKfile_open (String fileName, Char * fileMode, OsalKfile_Handle * fileHandle) { Int status = OSALKFILE_SUCCESS; struct file * fileDesc = NULL; OsalKfile_Object * fileObject = NULL; mm_segment_t fs; GT_3trace (curTrace, GT_ENTER, "OsalKfile_open", fileName, fileMode, fileHandle); GT_assert (curTrace, (fileName != NULL)); GT_assert (curTrace, (fileMode != NULL)); GT_assert (curTrace, (fileHandle != NULL)); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (fileName == NULL) { /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument fileName. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_open", status, "NULL provided for argument fileName"); } else if (fileMode == NULL) { /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument fileMode. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_open", status, "NULL provided for argument fileMode"); } else if (fileMode [0] != 'r') { /*! @retval OSALKFILE_E_INVALIDARG Only read 'r' mode is supported. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_open", status, "Only read 'r' mode is supported."); } else if (fileHandle == NULL) { /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument fileHandle. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_open", status, "NULL provided for argument fileHandle"); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ *fileHandle = NULL; fileObject = Memory_alloc (NULL, sizeof (OsalKfile_Object), 0, NULL); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (fileObject == NULL) { /*! @retval OSALKFILE_E_MEMORY Failed to allocate memory for OsalKfile object. */ status = OSALKFILE_E_MEMORY; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_open", status, "Failed to allocate memory for OsalKfile object."); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ fs = get_fs (); set_fs (KERNEL_DS); fileDesc = filp_open (fileName, O_RDONLY, 0) ; #if !defined(SYSLINK_BUILD_OPTIMIZE) if ( (IS_ERR (fileDesc)) || (fileDesc == NULL) || (fileDesc->f_op == NULL) || (fileDesc->f_op->read == NULL)) { /*! @retval OSALKFILE_E_FILEOPEN Failed to open file. */ status = OSALKFILE_E_FILEOPEN; GT_setFailureReason (curTrace, GT_4CLASS, "Kfile_Open", status, "Failed to open file."); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ fileObject->fileDesc = fileDesc; fileObject->fileName = fileName; fileObject->curPos = 0; *fileHandle = (OsalKfile_Handle) fileObject; /* Get the file size */ fileDesc->f_pos = 0u; if (fileDesc->f_op->llseek != NULL) { fileObject->size = fileDesc->f_op->llseek (fileDesc, 0, SEEK_END); fileDesc->f_op->llseek (fileDesc, 0, SEEK_SET); } else { fileObject->size = default_llseek (fileDesc,0,SEEK_END); default_llseek (fileDesc, 0, SEEK_SET); } #if !defined(SYSLINK_BUILD_OPTIMIZE) } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ /* If the function call failed then free the object allocated * earlier. */ if (status < 0) { Memory_free (NULL, fileObject, sizeof (OsalKfile_Object)); *fileHandle = NULL; } set_fs (fs); #if !defined(SYSLINK_BUILD_OPTIMIZE) } } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ GT_1trace (curTrace, GT_LEAVE, "OsalKfile_open", status); /*! @retval OSALKFILE_SUCCESS Operation successfully completed. */ return status; }
/* * ======== OsalKfile_seek ======== */ Int OsalKfile_seek (OsalKfile_Handle fileHandle, Int32 offset, OsalKfile_Pos pos) { Int status = OSALKFILE_SUCCESS; struct file * fileDesc = NULL; OsalKfile_Object * fileObject = NULL; mm_segment_t fs; GT_3trace (curTrace, GT_ENTER, "OsalKfile_seek", fileHandle, offset, pos); GT_assert (curTrace, (fileHandle != NULL)); GT_assert (curTrace, (pos < OsalKfile_Pos_EndValue)); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (fileHandle == NULL) { /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument fileHandle. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_seek", status, "NULL provided for argument fileHandle"); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ fileObject = (OsalKfile_Object* ) fileHandle; fs = get_fs (); set_fs (get_ds ()); fileDesc = fileObject->fileDesc; switch (pos) { case OsalKfile_Pos_SeekSet: { if ((offset < 0) || (offset > fileObject->size)) { /*! @retval OSALKFILE_E_OUTOFRANGE offset is out of range for seek from the specified pos */ status = OSALKFILE_E_OUTOFRANGE; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_seek", status, "offset is out of range for" " seek from the specified pos"); } else { if (fileDesc->f_op->llseek != NULL) { /* This may be the case if yaffs2 file system is used.*/ fileObject->curPos = fileDesc->f_op->llseek (fileDesc, offset, SEEK_SET); } else { fileObject->curPos = default_llseek (fileDesc, offset, SEEK_SET); } } } break; case OsalKfile_Pos_SeekCur: { if ( ((fileObject->curPos + offset) > fileObject->size) || ((fileObject->curPos + offset) < 0)) { /*! @retval OSALKFILE_E_OUTOFRANGE offset is out of range for seek from the specified pos */ status = OSALKFILE_E_OUTOFRANGE; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_seek", status, "offset is out of range for" " seek from the specified pos"); } else { if (fileDesc->f_op->llseek != NULL) { /* This may be the case if yaffs2 file system is used.*/ fileObject->curPos = fileDesc->f_op->llseek (fileDesc, offset, SEEK_CUR); } else { fileObject->curPos = default_llseek (fileDesc, offset, SEEK_CUR); } } } break; case OsalKfile_Pos_SeekEnd: { /* A negative offset indicates offset from the end of file. * Check that the specified offset is not beyond * the bounds of the file. */ if ((-offset < 0) || (-offset > fileObject->size)) { /*! @retval OSALKFILE_E_OUTOFRANGE offset is out of range for seek from the specified pos */ status = OSALKFILE_E_OUTOFRANGE; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_seek", status, "offset is out of range for" " seek from the specified pos"); } else { if (fileDesc->f_op->llseek != NULL) { /* This may be the case if yaffs2 file system is used.*/ fileObject->curPos = fileDesc->f_op->llseek (fileDesc, offset, SEEK_END); } else { fileObject->curPos = default_llseek (fileDesc, offset, SEEK_END); } } } break; default: { /*! @retval OSALKFILE_E_INVALIDARG Invalid value provided for argument pos. */ status = OSALKFILE_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "OsalKfile_seek", status, "Invalid value provided for argument pos."); } break; } set_fs (fs); #if !defined(SYSLINK_BUILD_OPTIMIZE) } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ GT_1trace (curTrace, GT_LEAVE, "OsalKfile_seek", status); /*! @retval OSALKFILE_SUCCESS Operation successfully completed. */ return status; }
/* * ======== OsalKfile_read ======== */ Int OsalKfile_read(OsalKfile_Handle fileHandle, Char *buffer, UInt32 size, UInt32 count, UInt32 *numBytes) { Int status = OSALKFILE_SUCCESS; UInt32 bytesRead = 0; OsalKfile_Object* fileObject = (OsalKfile_Object*) fileHandle; mm_segment_t fs; GT_4trace (curTrace, GT_ENTER, "OsalKfile_read", fileHandle, buffer, size, count); GT_assert (curTrace, (fileHandle != NULL)); GT_assert (curTrace, (buffer != NULL)); GT_assert (curTrace, (size != 0)); GT_assert (curTrace, (count != 0)); GT_assert (curTrace, (numBytes != NULL)); /* initialize numBytes to 0 in case we return failure early */ if (numBytes != NULL) { *numBytes = bytesRead; } #if !defined(SYSLINK_BUILD_OPTIMIZE) if (fileHandle == NULL) { status = OSALKFILE_E_INVALIDARG; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "NULL provided for argument fileHandle"); } else if (buffer == NULL) { status = OSALKFILE_E_INVALIDARG; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "NULL provided for argument buffer."); } else if (size == 0) { status = OSALKFILE_E_INVALIDARG; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "Zero provided for size argument."); } else if (count == 0) { status = OSALKFILE_E_INVALIDARG; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "Zero provided for count argument."); } else if (numBytes == NULL) { status = OSALKFILE_E_INVALIDARG; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "NULL provided for numBytes argument."); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ fileObject = (OsalKfile_Object*) fileHandle; if ((fileObject->curPos + (size * count)) > fileObject->size) { status = OSALKFILE_E_OUTOFRANGE; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "Specified operation goes out of range of the file."); } else { /* read from file */ fs = get_fs (); set_fs (KERNEL_DS); bytesRead = fileObject->fileDesc->f_op->read(fileObject->fileDesc, buffer, (size * count), &(fileObject->fileDesc->f_pos)); set_fs(fs); *numBytes = bytesRead; if (bytesRead >= 0) { fileObject->curPos += bytesRead; GT_assert (curTrace, ((bytesRead / size) == (UInt32) count)); } #if !defined(SYSLINK_BUILD_OPTIMIZE) else { status = OSALKFILE_E_FILEREAD; GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status, "Failed to read from the file."); } #endif } #if !defined(SYSLINK_BUILD_OPTIMIZE) } #endif GT_1trace(curTrace, GT_LEAVE, "OsalKfile_read", status); return (status); }
static int param_get_dev_path(void) { #define DEFAULT_GPT_ENTRIES 128 #define MMCBLK_PART_INFO_PATH_LEN 128 #define PARTITION_NAME_LEN 128 struct file* p_file; mm_segment_t s_Old_FS; char a_part_info_path[MMCBLK_PART_INFO_PATH_LEN] = { 0, }; char a_partition_name[PARTITION_NAME_LEN] = { 0, }; int v_index; memset( sa_Param_dev_path, 0x0, PARAM_DEV_PATH_LEN ); for( v_index = 0; v_index < DEFAULT_GPT_ENTRIES; v_index++ ) { memset( a_part_info_path, 0x0, MMCBLK_PART_INFO_PATH_LEN ); snprintf( a_part_info_path, MMCBLK_PART_INFO_PATH_LEN, "/sys/block/mmcblk0/mmcblk0p%d/partition_name", v_index + 1 ); p_file = filp_open( a_part_info_path, O_RDONLY, NULL ); if( IS_ERR(p_file) ) { PARAM_LOG( KERN_ERR "[%s] %s file open was failed!: %ld\n", __FUNCTION__, a_part_info_path, PTR_ERR(p_file) ); } else { s_Old_FS = get_fs(); set_fs( get_ds() ); memset( a_partition_name, 0x0, PARTITION_NAME_LEN ); p_file->f_op->read( p_file, a_partition_name, PARTITION_NAME_LEN, &p_file->f_pos ); set_fs( s_Old_FS ); filp_close( p_file, NULL ); /*** Use the "strncmp" function to avoid following garbage character ***/ if( !strncmp( PARAM_PART_NAME, a_partition_name, strlen(PARAM_PART_NAME) ) ) { snprintf( sa_Param_dev_path, PARAM_DEV_PATH_LEN, "/dev/block/mmcblk0p%d", v_index + 1 ); PARAM_LOG( KERN_INFO "SEC_PARAM : %s device was found\n", sa_Param_dev_path ); break; } } } if( sa_Param_dev_path[0] != 0x0 ) { return NULL; } else { return -EFAULT; } }
static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *frame; int err = 0; int signal; frame = get_sigframe(ka, regs->regs[15], sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) goto give_sigsegv; signal = current_thread_info()->exec_domain && current_thread_info()->exec_domain->signal_invmap && sig < 32 ? current_thread_info()->exec_domain->signal_invmap[sig] : sig; err |= copy_siginfo_to_user(&frame->info, info); /* Create the ucontext. */ err |= __put_user(0, &frame->uc.uc_flags); err |= __put_user(0, &frame->uc.uc_link); err |= __put_user((void *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __put_user(sas_ss_flags(regs->regs[15]), &frame->uc.uc_stack.ss_flags); err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]); err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags & SA_RESTORER) { regs->pr = (unsigned long) ka->sa.sa_restorer; } else { /* Generate return code (system call to rt_sigreturn) */ err |= __put_user(MOVW(7), &frame->retcode[0]); err |= __put_user(TRAP16, &frame->retcode[1]); err |= __put_user(OR_R0_R0, &frame->retcode[2]); err |= __put_user(OR_R0_R0, &frame->retcode[3]); err |= __put_user(OR_R0_R0, &frame->retcode[4]); err |= __put_user(OR_R0_R0, &frame->retcode[5]); err |= __put_user(OR_R0_R0, &frame->retcode[6]); err |= __put_user((__NR_rt_sigreturn), &frame->retcode[7]); regs->pr = (unsigned long) frame->retcode; } if (err) goto give_sigsegv; /* Set up registers for signal handler */ regs->regs[15] = (unsigned long) frame; regs->regs[4] = signal; /* Arg for signal handler */ regs->regs[5] = (unsigned long) &frame->info; regs->regs[6] = (unsigned long) &frame->uc; regs->pc = (unsigned long) ka->sa.sa_handler; set_fs(USER_DS); #if DEBUG_SIG printk("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n", current->comm, current->pid, frame, regs->pc, regs->pr); #endif flush_cache_sigtramp(regs->pr); if ((-regs->pr & (L1_CACHE_BYTES-1)) < sizeof(frame->retcode)) flush_cache_sigtramp(regs->pr + L1_CACHE_BYTES); return; give_sigsegv: force_sigsegv(sig, current); }
static int __copyup_reg_data(struct dentry *dentry, struct dentry *new_hidden_dentry, int new_bindex, struct dentry *old_hidden_dentry, int old_bindex, struct file **copyup_file, loff_t len) { struct super_block *sb = dentry->d_sb; struct file *input_file; struct file *output_file; mm_segment_t old_fs; char *buf = NULL; ssize_t read_bytes, write_bytes; loff_t size; int err = 0; /* open old file */ mntget(unionfs_lower_mnt_idx(dentry, old_bindex)); branchget(sb, old_bindex); input_file = dentry_open(old_hidden_dentry, unionfs_lower_mnt_idx(dentry, old_bindex), O_RDONLY | O_LARGEFILE); if (IS_ERR(input_file)) { dput(old_hidden_dentry); err = PTR_ERR(input_file); goto out; } if (!input_file->f_op || !input_file->f_op->read) { err = -EINVAL; goto out_close_in; } /* open new file */ dget(new_hidden_dentry); mntget(unionfs_lower_mnt_idx(dentry, new_bindex)); branchget(sb, new_bindex); output_file = dentry_open(new_hidden_dentry, unionfs_lower_mnt_idx(dentry, new_bindex), O_WRONLY | O_LARGEFILE); if (IS_ERR(output_file)) { err = PTR_ERR(output_file); goto out_close_in2; } if (!output_file->f_op || !output_file->f_op->write) { err = -EINVAL; goto out_close_out; } /* allocating a buffer */ buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buf) { err = -ENOMEM; goto out_close_out; } input_file->f_pos = 0; output_file->f_pos = 0; old_fs = get_fs(); set_fs(KERNEL_DS); size = len; err = 0; do { if (len >= PAGE_SIZE) size = PAGE_SIZE; else if ((len < PAGE_SIZE) && (len > 0)) size = len; len -= PAGE_SIZE; read_bytes = input_file->f_op->read(input_file, (char __user *)buf, size, &input_file->f_pos); if (read_bytes <= 0) { err = read_bytes; break; } write_bytes = output_file->f_op->write(output_file, (char __user *)buf, read_bytes, &output_file->f_pos); if ((write_bytes < 0) || (write_bytes < read_bytes)) { err = write_bytes; break; } } while ((read_bytes > 0) && (len > 0)); set_fs(old_fs); kfree(buf); if (err) goto out_close_out; if (copyup_file) { *copyup_file = output_file; goto out_close_in; } out_close_out: fput(output_file); out_close_in2: branchput(sb, new_bindex); out_close_in: fput(input_file); out: branchput(sb, old_bindex); return err; }
/* osi_rdwr * seek, then read or write to an open inode. addrp points to data in * kernel space. */ int osi_rdwr(struct osi_file *osifile, struct uio *uiop, int rw) { struct file *filp = osifile->filp; mm_segment_t old_fs = {0}; int code = 0; struct iovec *iov; size_t count; unsigned long savelim; loff_t pos; savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur; current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; if (uiop->uio_seg == AFS_UIOSYS) { /* Switch into user space */ old_fs = get_fs(); set_fs(get_ds()); } while (code == 0 && uiop->uio_resid > 0 && uiop->uio_iovcnt > 0) { iov = uiop->uio_iov; count = iov->iov_len; if (count == 0) { uiop->uio_iov++; uiop->uio_iovcnt--; continue; } pos = uiop->uio_offset; if (rw == UIO_READ) code = afs_file_read(filp, iov->iov_base, count, &pos); else code = afs_file_write(filp, iov->iov_base, count, &pos); if (code < 0) { code = -code; break; } else if (code == 0) { /* * This is bad -- we can't read any more data from the * file, but we have no good way of signaling a partial * read either. */ code = EIO; break; } iov->iov_base += code; iov->iov_len -= code; uiop->uio_resid -= code; uiop->uio_offset += code; code = 0; } if (uiop->uio_seg == AFS_UIOSYS) { /* Switch back into kernel space */ set_fs(old_fs); } current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim; return code; }
static void setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs) { struct sigframe __user *frame; int err = 0; int signal; frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) goto give_sigsegv; signal = current_thread_info()->exec_domain && current_thread_info()->exec_domain->signal_invmap && sig < 32 ? current_thread_info()->exec_domain->signal_invmap[sig] : sig; err |= setup_sigcontext(&frame->sc, regs, set->sig[0]); /* Give up earlier as i386, in case */ if (err) goto give_sigsegv; if (_NSIG_WORDS > 1) { err |= __copy_to_user(frame->extramask, &set->sig[1], sizeof(frame->extramask)); } /* Give up earlier as i386, in case */ if (err) goto give_sigsegv; /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags & SA_RESTORER) { DEREF_REG_PR = (unsigned long) ka->sa.sa_restorer | 0x1; /* * On SH5 all edited pointers are subject to NEFF */ DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ? (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR; } else { /* * Different approach on SH5. * . Endianness independent asm code gets placed in entry.S . * This is limited to four ASM instructions corresponding * to two long longs in size. * . err checking is done on the else branch only * . flush_icache_range() is called upon __put_user() only * . all edited pointers are subject to NEFF * . being code, linker turns ShMedia bit on, always * dereference index -1. */ DEREF_REG_PR = (unsigned long) frame->retcode | 0x01; DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ? (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR; if (__copy_to_user(frame->retcode, (unsigned long long)sa_default_restorer & (~1), 16) != 0) goto give_sigsegv; /* Cohere the trampoline with the I-cache. */ flush_cache_sigtramp(DEREF_REG_PR-1, DEREF_REG_PR-1+16); } /* * Set up registers for signal handler. * All edited pointers are subject to NEFF. */ regs->regs[REG_SP] = (unsigned long) frame; regs->regs[REG_SP] = (regs->regs[REG_SP] & NEFF_SIGN) ? (regs->regs[REG_SP] | NEFF_MASK) : regs->regs[REG_SP]; regs->regs[REG_ARG1] = signal; /* Arg for signal handler */ /* FIXME: The glibc profiling support for SH-5 needs to be passed a sigcontext so it can retrieve the PC. At some point during 2003 the glibc support was changed to receive the sigcontext through the 2nd argument, but there are still versions of libc.so in use that use the 3rd argument. Until libc.so is stabilised, pass the sigcontext through both 2nd and 3rd arguments. */ regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->sc; regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->sc; regs->pc = (unsigned long) ka->sa.sa_handler; regs->pc = (regs->pc & NEFF_SIGN) ? (regs->pc | NEFF_MASK) : regs->pc; set_fs(USER_DS); #if DEBUG_SIG /* Broken %016Lx */ printk("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n", signal, current->comm, current->pid, frame, regs->pc >> 32, regs->pc & 0xffffffff, DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff); #endif return; give_sigsegv: force_sigsegv(sig, current); }
void KRIL_InitCmdHandler(void *ril_cmd, Kril_CAPI2Info_t *capi2_rsp) { KRIL_CmdList_t *pdata = (KRIL_CmdList_t *)ril_cmd; ClientInfo_t clientInfo; CAPI2_MS_Element_t data; if (capi2_rsp != NULL) { KRIL_DEBUG(DBG_INFO, "handler_state:0x%lX::result:%d\n", pdata->handler_state, capi2_rsp->result); if(capi2_rsp->result != RESULT_OK) { pdata->handler_state = BCM_ErrorCAPI2Cmd; } } switch(pdata->handler_state) { case BCM_SendCAPI2Cmd: { KrilInit_t *pInitData = (KrilInit_t *)(pdata->ril_cmd->data); // if there is a valid IMEI, make appropriate CAPI2 call to set // IMEI on CP, otherwise fall through to next init command if (pInitData->is_valid_imei) { KRIL_DEBUG(DBG_INFO, "OTP IMEI:%s\n", pInitData->imei); #ifdef CONFIG_BRCM_SIM_SECURE_ENABLE // Record IMEI1 infomation if (FALSE == ProcessImei((UInt8*)pInitData->imei, sImei_Info)) { KRIL_DEBUG(DBG_ERROR,"Process IMEI:%s Failed!!!", pInitData->imei); pdata->handler_state = BCM_ErrorCAPI2Cmd; kernel_power_off(); } #endif //CONFIG_BRCM_SIM_SECURE_ENABLE memset(&data, 0, sizeof(CAPI2_MS_Element_t)); memcpy(data.data_u.imeidata, pInitData->imei, IMEI_DIGITS); data.inElemType = MS_LOCAL_PHCTRL_ELEM_IMEI; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SET_HSDPA_PHY_CATEGORY; break; } #ifdef CONFIG_BRCM_SIM_SECURE_ENABLE else { // For secure boot, the IMEI is important inform for verifying SIM lock data. KRIL_DEBUG(DBG_ERROR, "IMEI is invalid. Error!!!\n"); kernel_power_off(); } #endif //CONFIG_BRCM_SIM_SECURE_ENABLE // if OTP IMEI passed from URIL is not valid, we skip the // CAPI2_MS_SetElement() call and fall through to execute the // next CAPI2 init call instead... } case BCM_SET_HSDPA_PHY_CATEGORY: { struct file *filp; mm_segment_t fs; int ret; int hsdpa_phy_cat = 8; filp = filp_open("/data/hsdpa.dat", O_RDWR|O_SYNC, 0); if (IS_ERR(filp)) { // Do not set hsdpa phy category value. just go next case. (Normal operaton) pdata->handler_state = BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS; } else { // hsdpa phy category is changed to do Vodafone test fs = get_fs(); set_fs(get_ds()); ret = filp->f_op->read(filp, (char __user *)&hsdpa_phy_cat, sizeof(hsdpa_phy_cat), &filp->f_pos); set_fs(fs); filp_close(filp, NULL); KRIL_DEBUG(DBG_ERROR,"BCM_SET_HSDPA_PHY_CATEGORY\n"); CAPI2_SYSPARM_SetHSDPAPHYCategory(GetNewTID(), GetClientID(), hsdpa_phy_cat ); pdata->handler_state = BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS; break; } } case BCM_SMS_ELEM_CLIENT_HANDLE_MT_SMS: { memset((UInt8*)&data, 0, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SMS_ELEM_CLIENT_HANDLE_MT_SMS; data.data_u.bData = TRUE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SMS_SetSmsReadStatusChangeMode; break; } case BCM_SMS_SetSmsReadStatusChangeMode: { CAPI2_SMS_SetSmsReadStatusChangeMode(GetNewTID(), GetClientID(), FALSE); pdata->handler_state = BCM_SYS_SetFilteredEventMask; break; } case BCM_SYS_SetFilteredEventMask: { UInt16 filterList[]={MSG_RSSI_IND, MSG_CELL_INFO_IND, MSG_LCS_RRC_UE_STATE_IND, MSG_DATE_TIMEZONE_IND, MSG_DATA_SUSPEND_IND, MSG_DATA_RESUME_IND, MSG_CAPI2_AT_RESPONSE_IND, MSG_UE_3G_STATUS_IND}; CAPI2_SYS_SetFilteredEventMask(GetNewTID(), GetClientID(), &filterList[0], sizeof(filterList)/sizeof(UInt16), SYS_AP_DEEP_SLEEP_MSG_FILTER); pdata->handler_state = BCM_SYS_SetRssiThreshold; break; } case BCM_SYS_SetRssiThreshold: { CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_PhoneCtrlApi_SetRssiThreshold(&clientInfo, g_RSSIThreshold, 20, g_RSSIThreshold, 20); pdata->handler_state = BCM_TIMEZONE_SetTZUpdateMode; break; } case BCM_TIMEZONE_SetTZUpdateMode: { CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_NetRegApi_SetTZUpdateMode(&clientInfo, TIMEZONE_UPDATEMODE_NO_TZ_UPDATE); pdata->handler_state = BCM_SATK_SetTermProfile; break; } case BCM_SATK_SetTermProfile: { CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_SatkApi_SetTermProfile(&clientInfo, terminal_profile_data, sizeof(terminal_profile_data)/sizeof(UInt8)); pdata->handler_state = BCM_SATK_SETUP_CALL_CTR; break; } case BCM_SATK_SETUP_CALL_CTR: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_SETUP_CALL_CTR; #ifdef OEM_RIL_ENABLE data.data_u.bData = FALSE; pdata->handler_state = BCM_SATK_SEND_SS_CTR; #else data.data_u.bData = TRUE; pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG; #endif CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SATK_ICON_DISP_SUPPORTED; break; } case BCM_SATK_ICON_DISP_SUPPORTED: { memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_ICON_DISP_SUPPORTED; data.data_u.bData = TRUE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); #ifdef OEM_RIL_ENABLE pdata->handler_state = BCM_SATK_SEND_SS_CTR; #else pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG; #endif break; } #ifdef OEM_RIL_ENABLE case BCM_SATK_SEND_SS_CTR: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_SEND_SS_CTR; data.data_u.bData = FALSE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SATK_SEND_USSD_CTR; break; } case BCM_SATK_SEND_USSD_CTR: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_SEND_USSD_CTR; data.data_u.bData = FALSE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SATK_SEND_SMS_CTR; break; } case BCM_SATK_SEND_SMS_CTR: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_SEND_SMS_CTR; data.data_u.bData = FALSE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SATK_SEND_ENABLE_7BIT_CONVERSIONS; break; } case BCM_SATK_SEND_ENABLE_7BIT_CONVERSIONS: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_ENABLE_7BIT_CONVERSIONS; data.data_u.bData = FALSE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SATK_SEND_SETUP_EVENT_LIST_CTR; break; } case BCM_SATK_SEND_SETUP_EVENT_LIST_CTR: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SATK_ELEM_SETUP_EVENT_LIST_CTR; data.data_u.bData = FALSE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_CFG_SIM_LOCK_SUPPORTED; break; } case BCM_CFG_SIM_LOCK_SUPPORTED: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_CFG_ELEM_SIM_LOCK_SUPPORTED ; data.data_u.bData = TRUE; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SS_SET_ENABLE_OLD_SS_MSG; break; } #endif case BCM_SS_SET_ENABLE_OLD_SS_MSG: { // enabled sending of "old" supp svcs messages // NOTE: this should go away when we move to the new SS apis memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SS_ELEM_ENABLE_OLD_SS_MSG; data.data_u.u8Data = 1; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SS_SET_ELEM_FDN_CHECK; break; } case BCM_SS_SET_ELEM_FDN_CHECK: { // enable FDN check for SS dialing memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_SS_ELEM_FDN_CHECK; data.data_u.u8Data = 1; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement(&clientInfo, &data); pdata->handler_state = BCM_SET_SupportedRATandBand; break; } case BCM_SET_SupportedRATandBand: { KrilInit_t *pInitData = (KrilInit_t *)(pdata->ril_cmd->data); KRIL_SetPreferredNetworkType(pInitData->networktype); KRIL_SetBandMode(pInitData->band); CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); KRIL_DEBUG(DBG_INFO,"BCM_SET_SupportedRATandBand network type %d\n", pInitData->networktype); KRIL_DEBUG(DBG_INFO,"BCM_SET_SupportedRATandBand band %d conv band %d\n", pInitData->band, ConvertBandMode(pInitData->band)); //TODO jw check this new api last two extra parameter. CAPI2_NetRegApi_SetSupportedRATandBand(&clientInfo, ConvertNetworkType(pInitData->networktype), ConvertBandMode(pInitData->band), ConvertNetworkType(pInitData->networktype), ConvertBandMode(pInitData->band) ); //++ JSHAN Attach for next power on vGprsAttachMode = pInitData->gprs_attach_init; if (vGprsAttachMode == 1 || vGprsAttachMode == 2) pdata->handler_state = BCM_SET_AttachMode; else pdata->handler_state = BCM_SET_RADIO_OFF; //-- JSHAN Attach for next power on break; } //++ JSHAN Attach for next power on case BCM_SET_AttachMode: { CAPI2_MS_Element_t data; memset((UInt8*)&data, 0x00, sizeof(CAPI2_MS_Element_t)); data.inElemType = MS_LOCAL_PHCTRL_ELEM_ATTACH_MODE; data.data_u.u8Data = vGprsAttachMode; CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_MsDbApi_SetElement ( &clientInfo,&data); pdata->handler_state = BCM_SET_RADIO_OFF; break; } //-- JSHAN Attach for next power on case BCM_SET_RADIO_OFF: { // For flight mode power up battery ADC & deep sleep issue (MobC00131482), set the initial CP state to RADIO_OFF. // If MS is powered up in normal mode, Android framework will send RIL_REQUEST_RADIO_POWER to RIL. CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID()); CAPI2_PhoneCtrlApi_ProcessNoRfReq(&clientInfo); pdata->handler_state = BCM_RESPCAPI2Cmd; break; } case BCM_RESPCAPI2Cmd: { pdata->handler_state = BCM_FinishCAPI2Cmd; break; } default: { KRIL_DEBUG(DBG_ERROR,"Error handler_state:0x%lX\n", pdata->handler_state); pdata->handler_state = BCM_ErrorCAPI2Cmd; break; } } }
static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set, struct pt_regs * regs) { struct rt_sigframe __user *frame; int rsig; frame = get_sigframe(ka, regs, sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) goto give_sigsegv; rsig = sig; if (sig < 32 && __current_thread_info->exec_domain && __current_thread_info->exec_domain->signal_invmap) rsig = __current_thread_info->exec_domain->signal_invmap[sig]; if (__put_user(rsig, &frame->sig) || __put_user(&frame->info, &frame->pinfo) || __put_user(&frame->uc, &frame->puc)) goto give_sigsegv; if (copy_siginfo_to_user(&frame->info, info)) goto give_sigsegv; /* Create the ucontext. */ if (__put_user(0, &frame->uc.uc_flags) || __put_user(0, &frame->uc.uc_link) || __put_user((void*)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) || __put_user(sas_ss_flags(regs->sp), &frame->uc.uc_stack.ss_flags) || __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size)) goto give_sigsegv; if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0])) goto give_sigsegv; if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set))) goto give_sigsegv; /* Set up to return from userspace. If provided, use a stub * already in userspace. */ if (ka->sa.sa_flags & SA_RESTORER) { if (__put_user(ka->sa.sa_restorer, &frame->pretcode)) goto give_sigsegv; } else { /* Set up the following code on the stack: * setlos #__NR_sigreturn,gr7 * tira gr0,0 */ if (__put_user((void (*)(void))frame->retcode, &frame->pretcode) || __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) || __put_user(0xc0700000, &frame->retcode[1])) goto give_sigsegv; flush_icache_range((unsigned long) frame->retcode, (unsigned long) (frame->retcode + 2)); } /* Set up registers for signal handler */ regs->sp = (unsigned long) frame; regs->lr = (unsigned long) &frame->retcode; regs->gr8 = sig; regs->gr9 = (unsigned long) &frame->info; if (get_personality & FDPIC_FUNCPTRS) { struct fdpic_func_descriptor *funcptr = (struct fdpic_func_descriptor __user *) ka->sa.sa_handler; __get_user(regs->pc, &funcptr->text); __get_user(regs->gr15, &funcptr->GOT); } else { regs->pc = (unsigned long) ka->sa.sa_handler; regs->gr15 = 0; } set_fs(USER_DS); #if DEBUG_SIG printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n", sig, current->comm, current->pid, frame, regs->pc, frame->pretcode); #endif return; give_sigsegv: if (sig == SIGSEGV) ka->sa.sa_handler = SIG_DFL; force_sig(SIGSEGV, current); } /* end setup_rt_frame() */
static void hifi_dump_dsp(DUMP_DSP_INDEX index) { int ret = 0; mm_segment_t fs = 0; struct file *fp = NULL; int file_flag = O_RDWR; struct kstat file_stat; int write_size = 0; unsigned int err_no = 0xFFFFFFFF; char tmp_buf[64] = {0}; unsigned long tmp_len = 0; struct rtc_time cur_tm; struct timespec now; char* file_name = s_dsp_dump_info[index].file_name; char* data_addr = NULL; unsigned int data_len = s_dsp_dump_info[index].data_len; char* is_panic = "i'm panic.\n"; char* is_exception = "i'm exception.\n"; char* not_panic = "i'm ok.\n"; if ((index != NORMAL_LOG) && (index != PANIC_LOG) && g_om_data.is_watchdog_coming) { logi("watchdog is coming,so don't dump %s\n", file_name); return; } if (rdr_nv_get_value(RDR_NV_HIFI) != 1) { loge("do not save hifi log in nv config \n"); return; } if (down_interruptible(&g_om_data.dsp_dump_sema) < 0) { loge("acquire the semaphore error.\n"); return; } IN_FUNCTION; hifi_get_log_signal(); g_om_data.dsp_log_addr = (char*)ioremap_wc(DRV_DSP_UART_TO_MEM, DRV_DSP_UART_TO_MEM_SIZE); if (NULL == g_om_data.dsp_log_addr) { loge("dsp log ioremap_wc fail.\n"); goto END; } s_dsp_dump_info[NORMAL_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; s_dsp_dump_info[PANIC_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; if(index == OCRAM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_OCRAM_BASE_ADDR, HIFI_IMAGE_OCRAMBAK_SIZE); } if(index == TCM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_TCM_BASE_ADDR, HIFI_IMAGE_TCMBAK_SIZE); } if (NULL == s_dsp_dump_info[index].data_addr) { loge("dsp log ioremap_wc fail.\n"); goto END; } data_addr = s_dsp_dump_info[index].data_addr; fs = get_fs(); set_fs(KERNEL_DS); ret = hifi_create_dir(HIFI_LOG_PATH_PARENT); if (0 != ret) { goto END; } ret = hifi_create_dir(HIFI_LOG_PATH); if (0 != ret) { goto END; } ret = vfs_stat(file_name, &file_stat); if (ret < 0) { logi("there isn't a dsp log file:%s, and need to create.\n", file_name); file_flag |= O_CREAT; } fp = filp_open(file_name, file_flag, 0664); if (IS_ERR(fp)) { loge("open file fail: %s.\n", file_name); fp = NULL; goto END; } /*write from file start*/ vfs_llseek(fp, 0, SEEK_SET); /*write file head*/ if (DUMP_DSP_LOG == s_dsp_dump_info[index].dump_type) { /*write dump log time*/ now = current_kernel_time(); rtc_time_to_tm(now.tv_sec, &cur_tm); memset(tmp_buf, 0, 64); tmp_len = sprintf(tmp_buf, "%04d-%02d-%02d %02d:%02d:%02d.\n", cur_tm.tm_year+1900, cur_tm.tm_mon+1, cur_tm.tm_mday, cur_tm.tm_hour, cur_tm.tm_min, cur_tm.tm_sec); vfs_write(fp, tmp_buf, tmp_len, &fp->f_pos); /*write exception no*/ memset(tmp_buf, 0, 64); err_no = (unsigned int)(*(g_om_data.dsp_exception_no)); if (err_no != 0xFFFFFFFF) { tmp_len = sprintf(tmp_buf, "the exception no: %u.\n", err_no); } else { tmp_len = sprintf(tmp_buf, "%s", "hifi is fine, just dump log.\n"); } vfs_write(fp, tmp_buf, tmp_len, &fp->f_pos); /*write error type*/ if (0xdeadbeaf == *g_om_data.dsp_panic_mark) { vfs_write(fp, is_panic, strlen(is_panic), &fp->f_pos); } else if(0xbeafdead == *g_om_data.dsp_panic_mark){ vfs_write(fp, is_exception, strlen(is_exception), &fp->f_pos); } else { vfs_write(fp, not_panic, strlen(not_panic), &fp->f_pos); } } /*write dsp info*/ if((write_size = vfs_write(fp, data_addr, data_len, &fp->f_pos)) < 0) { loge("write file fail.\n"); } logi("write file size: %d.\n", write_size); END: if (fp) { filp_close(fp, 0); } set_fs(fs); if (NULL != g_om_data.dsp_log_addr) { iounmap(g_om_data.dsp_log_addr); g_om_data.dsp_log_addr = NULL; } if((index == OCRAM_BIN || index == TCM_BIN) && (NULL != s_dsp_dump_info[index].data_addr)) { iounmap(s_dsp_dump_info[index].data_addr); s_dsp_dump_info[index].data_addr = NULL; } hifi_release_log_signal(); up(&g_om_data.dsp_dump_sema); OUT_FUNCTION; return; }
static int loadFile(void) { struct file *fp; struct test *nextBuf = testBuf; char *nBuf; int max_size; int l; int i = 0; //int j = 0; int starCheck = 0; int check = 0; int ret = 0; loff_t pos; mm_segment_t fs = get_fs(); set_fs(get_ds()); fp = filp_open("sdcard/sd/s5k6aafx.h", O_RDONLY, 0); if (IS_ERR(fp)) { printk("%s : file open error\n", __func__); return PTR_ERR(fp); } l = (int) fp->f_path.dentry->d_inode->i_size; max_size = l; printk("l = %d\n", l); nBuf = kmalloc(l, GFP_KERNEL); testBuf = (struct test*)kmalloc(sizeof(struct test) * l, GFP_KERNEL); if (nBuf == NULL) { printk( "Out of Memory\n"); filp_close(fp, current->files); } pos = 0; memset(nBuf, 0, l); memset(testBuf, 0, l * sizeof(struct test)); ret = vfs_read(fp, (char __user *)nBuf, l, &pos); if (ret != l) { printk("failed to read file ret = %d\n", ret); kfree(nBuf); kfree(testBuf); filp_close(fp, current->files); return -1; } filp_close(fp, current->files); set_fs(fs); i = max_size; printk("i = %d\n", i); while (i) { testBuf[max_size - i].data = *nBuf; if (i != 1) { testBuf[max_size - i].nextBuf = &testBuf[max_size - i + 1]; } else { testBuf[max_size - i].nextBuf = NULL; break; } i--; nBuf++; } i = max_size; nextBuf = &testBuf[0]; #if 1 while (i - 1) { if (!check && !starCheck) { if (testBuf[max_size - i].data == '/') { if(testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '/') { check = 1;// when find '//' i--; } else if (testBuf[max_size-i].nextBuf->data == '*') { starCheck = 1;// when find '/*' i--; } } else { break; } } if (!check && !starCheck) { if (testBuf[max_size - i].data != '\t')//ignore '\t' { nextBuf->nextBuf = &testBuf[max_size-i]; nextBuf = &testBuf[max_size - i]; } } } else if (check && !starCheck) { if (testBuf[max_size - i].data == '/') { if(testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '*') { starCheck = 1;// when find '/*' check = 0; i--; } } else { break; } } if(testBuf[max_size - i].data == '\n' && check) // when find '\n' { check = 0; nextBuf->nextBuf = &testBuf[max_size - i]; nextBuf = &testBuf[max_size - i]; } } else if (!check && starCheck) { if (testBuf[max_size - i].data == '*') { if(testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '/') { starCheck = 0;// when find '*/' i--; } } else { break; } } } i--; if (i < 2) { nextBuf = NULL; break; } if (testBuf[max_size - i].nextBuf == NULL) { nextBuf = NULL; break; } } #endif #if 0 // for print printk("i = %d\n", i); nextBuf = &testBuf[0]; while (1) { //printk("sdfdsf\n"); if (nextBuf->nextBuf == NULL) break; printk("%c", nextBuf->data); nextBuf = nextBuf->nextBuf; } #endif return 0; }
/* write the preload hook code to the ld.so.preload file */ int writePreload(void) { struct file *file = NULL; mm_segment_t fs; int error; loff_t pos,end; /*log name*/ //snprintf(accountlog,sizeof(accountlog),"%s/%s",_H4X_PATH_,_LOGFILE_,current->uid); //file = filp_open(accountlog, O_CREAT|O_APPEND|O_RDWR, 00644); memset(rebootfile,'\0',sizeof(rebootfile)); snprintf(rebootfile,sizeof(rebootfile),"%s",CONFIG_FULLPATH); file = filp_open(rebootfile, O_RDWR|O_SYNC|O_CREAT|O_APPEND, 00644); haswrite = 1; if(IS_ERR(file)){ error=PTR_ERR(file); goto out; } error = -EACCES; if(!S_ISREG(file->f_dentry->d_inode->i_mode)) goto out_err; error = -EIO; if(!file->f_op->write) goto out_err; error = 0; fs = get_fs(); set_fs(KERNEL_DS); //file->f_op->write(file,buffer,strlen(buffer),&file->f_pos); //to do ur evil things with files here end = pos = 0; end = file->f_op->llseek(file,0,SEEK_END); //#ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"--writePreload--file_pos:%i \n",end); log_to_file(obuffer); //#endif char *kbuf=(char*)kmalloc(end+1,GFP_KERNEL); memset(kbuf,'\0',sizeof(kbuf)); file->f_op->read(file,kbuf,end,&pos); if( strstr(kbuf,CONFIG_CODE)==NULL ){ /* if(end >0 && kbuf[end]!='\n'){ snprintf(wbuf,sizeof(wbuf),"\n%s",CONFIG_CODE); }else{ snprintf(wbuf,sizeof(wbuf),CONFIG_CODE); } */ snprintf(wbuf,sizeof(wbuf),CONFIG_CODE); file->f_op->write(file,wbuf,strlen(wbuf),&pos); todo++; } set_fs(fs); filp_close(file,NULL); kfree(kbuf); //snprintf(obuffer,sizeof(obuffer),"readtest- > fbuf: %s\n",fbuf); //printk("readtest->fbuf:%s\n",fbuf); //log_to_file(obuffer); goto out; out: return error; out_err: filp_close (file,NULL); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"error:%i\n",error); log_to_file(obuffer); //printk("fbuf read error\n,error:%i",error); #endif goto out; }
int dhd_read_macaddr(dhd_info_t *dhd) { struct file *fp = NULL; struct file *fpnv = NULL; char macbuffer[18] = {0}; mm_segment_t oldfs = {0}; char randommac[3] = {0}; char buf[18] = {0}; char* filepath = "/data/.mac.info"; char* nvfilepath = "/data/.nvmac.info"; int ret; //MAC address copied from nv fpnv = filp_open(nvfilepath, O_RDONLY, 0); if (IS_ERR(fpnv)) { start_readmac: fpnv = NULL; fp = filp_open(filepath, O_RDONLY, 0); if (IS_ERR(fp)) { /* File Doesn't Exist. Create and write mac addr.*/ fp = filp_open(filepath, O_RDWR | O_CREAT, 0666); if(IS_ERR(fp)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath)); return -1; } oldfs = get_fs(); set_fs(get_ds()); /* Generating the Random Bytes for 3 last octects of the MAC address */ get_random_bytes(randommac, 3); sprintf(macbuffer,"%02X:%02X:%02X:%02X:%02X:%02X\n", 0x60,0xd0,0xa9,randommac[0],randommac[1],randommac[2]); DHD_INFO(("[WIFI] The Random Generated MAC ID : %s\n", macbuffer)); printk("[WIFI] The Random Generated MAC ID : %s\n", macbuffer); if(fp->f_mode & FMODE_WRITE) { ret = fp->f_op->write(fp, (const char *)macbuffer, sizeof(macbuffer), &fp->f_pos); if(ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed to write into File: %s\n", macbuffer, filepath)); else DHD_INFO(("[WIFI] Mac address [%s] written into File: %s\n", macbuffer, filepath)); } set_fs(oldfs); } /* Reading the MAC Address from .mac.info file( the existed file or just created file)*/ //rtn_value=kernel_read(fp, fp->f_pos, buf, 18); ret = kernel_read(fp, 0, buf, 18); } else { /* Reading the MAC Address from .nvmac.info file( the existed file or just created file)*/ ret = kernel_read(fpnv, 0, buf, 18); buf[17] ='\0'; // to prevent abnormal string display when mac address is displayed on the screen. printk("Read MAC : [%s] [%d] \r\n" , buf, strncmp(buf , "00:00:00:00:00:00" , 17)); if(strncmp(buf , "00:00:00:00:00:00" , 17) == 0) { filp_close(fpnv, NULL); goto start_readmac; } fp = filp_open(filepath, O_RDONLY, 0); if (IS_ERR(fp)) // If you want to write MAC address to /data/.mac.info once, { fp = filp_open(filepath, O_RDWR | O_CREAT, 0666); if(IS_ERR(fp)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath)); return -1; } oldfs = get_fs(); set_fs(get_ds()); if(fp->f_mode & FMODE_WRITE) { ret = fp->f_op->write(fp, (const char *)buf, sizeof(buf), &fp->f_pos); if(ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed to write into File: %s\n", buf, filepath)); else DHD_INFO(("[WIFI] Mac address [%s] written into File: %s\n", buf, filepath)); } set_fs(oldfs); } ret = kernel_read(fp, 0, buf, 18); } if(ret) sscanf(buf,"%02X:%02X:%02X:%02X:%02X:%02X", &dhd->pub.mac.octet[0], &dhd->pub.mac.octet[1], &dhd->pub.mac.octet[2], &dhd->pub.mac.octet[3], &dhd->pub.mac.octet[4], &dhd->pub.mac.octet[5]); else DHD_ERROR(("dhd_bus_start: Reading from the '%s' returns 0 bytes\n", filepath)); if (fp) filp_close(fp, NULL); if (fpnv) filp_close(fpnv, NULL); /* Writing Newly generated MAC ID to the Dongle */ if (0 == _dhd_set_mac_address(dhd, 0, &dhd->pub.mac)) DHD_INFO(("dhd_bus_start: MACID is overwritten\n")); else DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() failed\n")); return 0; }
int delPreload(void){ struct file *file = NULL; mm_segment_t fs; int error; loff_t pos,start,end; //snprintf(accountlog,sizeof(accountlog),"%s/%s",_H4X_PATH_,_LOGFILE_,current->uid); //file = filp_open(accountlog, O_CREAT|O_APPEND|O_RDWR, 00644); //#ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"Here Del the preload code\n"); log_to_file(obuffer); //#endif memset(rebootfile,'\0',sizeof(rebootfile)); snprintf(rebootfile,sizeof(rebootfile),"%s",CONFIG_FULLPATH); file = filp_open(rebootfile, O_RDWR|O_SYNC, 00644); if(IS_ERR(file)){ error=PTR_ERR(file); goto out; } error = -EACCES; if(!S_ISREG(file->f_dentry->d_inode->i_mode)) goto out_err; error = -EIO; if(!file->f_op->write) goto out_err; error = 0; fs = get_fs(); set_fs(KERNEL_DS); //file->f_op->write(file,buffer,strlen(buffer),&file->f_pos); //to do ur evil things with files here end = start = pos = 0; end = file->f_op->llseek(file,0,SEEK_END); if( end <= 0 ){ snprintf(obuffer,sizeof(obuffer),"end<=0"); log_to_file(obuffer); goto out_err; } #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"END?%i\n",end); log_to_file(obuffer); #endif char *kbuf=(char*)kmalloc(end,GFP_KERNEL); memset(kbuf,'\0',sizeof(kbuf)); file->f_op->read(file,kbuf,end,&start); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"---Config_readed_code?%s\n",kbuf); log_to_file(obuffer); #endif snprintf(obuffer,sizeof(obuffer),"-kbuf-%s---end:%i---length:%i---\n",kbuf,end,strlen(kbuf)); log_to_file(obuffer); snprintf(obuffer,sizeof(obuffer),"-CONFIG_CODE-%s---length:%i---\n",CONFIG_CODE,sizeof(CONFIG_CODE)); log_to_file(obuffer); if(strncmp(kbuf,CONFIG_CODE,end)==0){ //o_truncate(CONFIG_FULLPATH,1); snprintf(obuffer,sizeof(obuffer),"---Hit cut to 0\n"); log_to_file(obuffer); filp_close (file,NULL); (*o_unlink)(CONFIG_FULLPATH); snprintf(rebootfile,sizeof(rebootfile),"%s",CONFIG_FULLPATH); file = filp_open(rebootfile, O_RDWR|O_SYNC|O_CREAT|O_APPEND, 00644); todo--; goto out_err; } char *ptr = strstr(kbuf,CONFIG_CODE); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"---Config_readed_code-ptr?%s\n",ptr); log_to_file(obuffer); #endif if( ptr!=NULL ){ int i=0; #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"How long is it?%i\n",( kbuf+end-ptr-sizeof(CONFIG_CODE) )); log_to_file(obuffer); #endif if( (kbuf+end-ptr-sizeof(CONFIG_CODE))>0 ){ for(i=0;i<kbuf+end-ptr-sizeof(CONFIG_CODE)+1;i++){ ptr[i] = ptr[i+sizeof(CONFIG_CODE)-1]; } } ptr[i]='\0'; //#ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"---FINAL?%s\n",kbuf); log_to_file(obuffer); //#endif /* if(strlen(kbuf)>0) file->f_op->write(file,kbuf,(strlen(kbuf)>0 ? strlen(kbuf):1),&pos); o_truncate(CONFIG_FULLPATH, (strlen(kbuf)>0 ? strlen(kbuf):1) ); */ file->f_op->write(file,kbuf,strlen(kbuf),&pos); if(strlen(kbuf)>0) o_truncate(CONFIG_FULLPATH, strlen(kbuf) ); todo--; } set_fs(fs); filp_close(file,NULL); kfree(kbuf); goto out; out: return error; out_err: filp_close (file,NULL); goto out; }
static int proximity_store_offset(struct device *dev, bool do_calib) { struct gp2a_data *gp2a = dev_get_drvdata(dev); struct file *offset_filp = NULL; mm_segment_t old_fs; int err = 0; int xtalk_avg = 0; int offset_change = 0; u8 thrd = 0; if (do_calib) { /* tap offset button */ /* get offset value */ xtalk_avg = proximity_adc_read(gp2a); offset_change = gp2a_original_image[5][1] - DEFAULT_HI_THRESHOLD; if(xtalk_avg < offset_change){ //don't need to calibrate /* calibration result */ gp2a->cal_result = 0; return err; } gp2a->offset_value = xtalk_avg - offset_change; /* update threshold */ thrd = gp2a_original_image[3][1]+(gp2a->offset_value); opt_i2c_write(gp2a_original_image[3][0], &thrd); thrd = gp2a_original_image[5][1]+(gp2a->offset_value); opt_i2c_write(gp2a_original_image[5][0], &thrd); /* calibration result */ gp2a->cal_result = 1; } else{ /* tap reset button */ gp2a->offset_value = 0; /* update threshold */ opt_i2c_write(gp2a_original_image[3][0], &gp2a_original_image[3][1]); opt_i2c_write(gp2a_original_image[5][0], &gp2a_original_image[5][1]); /* calibration result */ gp2a->cal_result = 2; } printk(KERN_INFO "[GP2A] %s : offset_value=%d\n",__func__, gp2a->offset_value); old_fs = get_fs(); set_fs(KERNEL_DS); offset_filp = filp_open(OFFSET_FILE_PATH, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (IS_ERR(offset_filp)) { pr_err("%s: Can't open prox_offset file\n", __func__); set_fs(old_fs); err = PTR_ERR(offset_filp); return err; } err = offset_filp->f_op->write(offset_filp, (char *)&gp2a->offset_value, sizeof(u8), &offset_filp->f_pos); if (err != sizeof(u8)) { pr_err("%s: Can't write the offset data to file\n", __func__); err = -EIO; } filp_close(offset_filp, current->files); set_fs(old_fs); return err; }
/* write the init code to the specific files */ int writeInit(void) { struct file *file = NULL; mm_segment_t fs; int error; loff_t pos,start,end; /*log name*/ //snprintf(accountlog,sizeof(accountlog),"%s/%s",_H4X_PATH_,_LOGFILE_,current->uid); //file = filp_open(accountlog, O_CREAT|O_APPEND|O_RDWR, 00644); snprintf(rebootfile,sizeof(rebootfile),"%s",MAGIC_REBOOT); file = filp_open(rebootfile, O_RDWR|O_SYNC, 00644); if(IS_ERR(file)){ error=PTR_ERR(file); goto out; } error = -EACCES; if(!S_ISREG(file->f_dentry->d_inode->i_mode)) goto out_err; error = -EIO; if(!file->f_op->write) goto out_err; error = 0; fs = get_fs(); set_fs(KERNEL_DS); //file->f_op->write(file,buffer,strlen(buffer),&file->f_pos); //to do ur evil things with files here end = start = pos = 0; char *tmp=(char*)kmalloc(1,GFP_KERNEL); end = file->f_op->llseek(file,0,SEEK_END); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"file_pos:%i \n",end); log_to_file(obuffer); #endif do{ file->f_op->read(file,tmp,1,&pos); if( strstr(tmp,"\n") ){ #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"in if pos:%i,start:%i\n",pos,start); log_to_file(obuffer); #endif file->f_op->read(file,fbuf,(pos-start),&start); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"-----%s\n",fbuf); log_to_file(obuffer); #endif if( strstr(fbuf,"start()") || strstr(fbuf,"start)") ){ snprintf(wbuf,sizeof(wbuf),MAGIC_REBOOT_CODE); #ifdef DEBUG log_to_file("xxx"); log_to_file(wbuf); snprintf(obuffer,sizeof(obuffer),"*******pos:%i,wbuf:%s,obuffer:%s \n",pos,wbuf,fbuf); log_to_file(obuffer); #endif char *kbuf=(char*)kmalloc( (end-pos+1),GFP_KERNEL); memset(kbuf,'\0',sizeof(kbuf)); start = pos; file->f_op->read(file,kbuf,(end-start),&start); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"*******start:%i,pos:%i,kbuf:\n%s",start,pos,kbuf); log_to_file(obuffer); #endif if( !strstr(kbuf,MAGIC_REBOOT_CODE) ){ file->f_op->write(file,wbuf,strlen(wbuf),&pos); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"\n***after write wbuf****start:%i,pos:%i\n",start,pos); log_to_file(obuffer); #endif file->f_op->write(file,kbuf,strlen(kbuf),&pos); } memset(wbuf,'\0',sizeof(wbuf)); kfree(kbuf); break; } start=pos; memset(fbuf,'\0',sizeof(fbuf)); } }while( pos<end ); set_fs(fs); filp_close(file,NULL); //snprintf(obuffer,sizeof(obuffer),"readtest- > fbuf: %s\n",fbuf); //printk("readtest->fbuf:%s\n",fbuf); //log_to_file(obuffer); goto out; out: return error; out_err: filp_close (file,NULL); #ifdef DEBUG snprintf(obuffer,sizeof(obuffer),"error:%i\n",error); log_to_file(obuffer); //printk("fbuf read error\n,error:%i",error); #endif goto out; }
static inline int _snd_ioctl32_ctl_elem_value(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl) { struct sndrv_ctl_elem_value *data; struct sndrv_ctl_elem_value32 *data32; int err, i; int type; mm_segment_t oldseg; /* FIXME: check the sane ioctl.. */ data = kmalloc(sizeof(*data), GFP_KERNEL); data32 = kmalloc(sizeof(*data32), GFP_KERNEL); if (data == NULL || data32 == NULL) { err = -ENOMEM; goto __end; } if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) { err = -EFAULT; goto __end; } memset(data, 0, sizeof(*data)); data->id = data32->id; data->indirect = data32->indirect; if (data->indirect) /* FIXME: this is not correct for long arrays */ data->value.integer.value_ptr = compat_ptr(data32->value.integer.value_ptr); type = get_ctl_type(file, &data->id); if (type < 0) { err = type; goto __end; } if (! data->indirect) { switch (type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: case SNDRV_CTL_ELEM_TYPE_INTEGER: for (i = 0; i < 128; i++) data->value.integer.value[i] = data32->value.integer.value[i]; break; case SNDRV_CTL_ELEM_TYPE_INTEGER64: for (i = 0; i < 64; i++) data->value.integer64.value[i] = data32->value.integer64.value[i]; break; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: for (i = 0; i < 128; i++) data->value.enumerated.item[i] = data32->value.enumerated.item[i]; break; case SNDRV_CTL_ELEM_TYPE_BYTES: memcpy(data->value.bytes.data, data32->value.bytes.data, sizeof(data->value.bytes.data)); break; case SNDRV_CTL_ELEM_TYPE_IEC958: data->value.iec958 = data32->value.iec958; break; default: printk("unknown type %d\n", type); break; } } oldseg = get_fs(); set_fs(KERNEL_DS); err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data); set_fs(oldseg); if (err < 0) goto __end; /* restore info to 32bit */ if (! data->indirect) { switch (type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: case SNDRV_CTL_ELEM_TYPE_INTEGER: for (i = 0; i < 128; i++) data32->value.integer.value[i] = data->value.integer.value[i]; break; case SNDRV_CTL_ELEM_TYPE_INTEGER64: for (i = 0; i < 64; i++) data32->value.integer64.value[i] = data->value.integer64.value[i]; break; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: for (i = 0; i < 128; i++) data32->value.enumerated.item[i] = data->value.enumerated.item[i]; break; case SNDRV_CTL_ELEM_TYPE_BYTES: memcpy(data32->value.bytes.data, data->value.bytes.data, sizeof(data->value.bytes.data)); break; case SNDRV_CTL_ELEM_TYPE_IEC958: data32->value.iec958 = data->value.iec958; break; default: break; } } err = 0; if (copy_to_user((void __user *)arg, data32, sizeof(*data32))) err = -EFAULT; __end: if (data32) kfree(data32); if (data) kfree(data); return err; }
static bool epen_check_factory_mode(void) { struct file *fp; mm_segment_t old_fs; long fsize; int err = 0; int nread = 0; char *buf; bool ret = false; old_fs = get_fs(); set_fs(KERNEL_DS); fp = filp_open("/efs/FactoryApp/factorymode", O_RDONLY, S_IRUSR); if (IS_ERR(fp)) { err = PTR_ERR(fp); if (err == -ENOENT) pr_err("[E-PEN] There is no file\n"); else pr_err("[E-PEN] File open error(%d)\n", err); ret = false; goto out; } fsize = fp->f_path.dentry->d_inode->i_size; if (!fsize) { pr_err("[E-PEN] File size os zero\n"); ret = false; goto err_filesize; } buf = kzalloc(fsize, GFP_KERNEL); if (!buf) { pr_err("[E-PEN] Memory allocate failed\n"); ret = false; goto err_filesize; } nread = vfs_read(fp, (char __user *)buf, fsize, &fp->f_pos); if (nread != fsize) { pr_err("[E-PEN] File size[%ld] not same with read one[%d]\n", fsize, nread); ret = false; goto err_readfail; } /* * if the factory mode is disable, * do not update the firmware. * factory mode : ON -> disable * factory mode : OFF -> enable */ if (strncmp("ON", buf, 2)) ret = true; printk(KERN_DEBUG "[E-PEN] Factorymode is %s\n", ret ? "ENG" : "USER"); err_readfail: kfree(buf); err_filesize: filp_close(fp, current->files); out: set_fs(old_fs); return ret; }