int env_setenv(const char *name,char *value,int flags) { cfe_envvar_t *env; int namelen; env = env_findenv(name); if (env) { if (!(flags & ENV_FLG_ADMIN)) { if (env->flags & ENV_FLG_READONLY) return CFE_ERR_ENVREADONLY; } q_dequeue((queue_t *) env); KFREE(env); } namelen = strlen(name); env = KMALLOC(sizeof(cfe_envvar_t) + namelen + 1 + strlen(value) + 1,0); if (!env) return CFE_ERR_NOMEM; env->name = (char *) (env+1); env->value = env->name + namelen + 1; env->flags = (flags & ENV_FLG_MASK); strcpy(env->name,name); strcpy(env->value,value); q_enqueue(&env_envvars,(queue_t *) env); return 0; }
/** * Call a Java static method on a class from native code. * * @param cname name of the class whose method is to be called * @param loader the class loader that's to be used to lookup the class * @param method_name the name of the method to be called * @param signature the signature of the method to be called * @param argptr the arguments to be passed to the method * * @throws NuSuchMethodError if method cannot be found * * @return the return value of the method */ void do_execute_java_class_method_v(jvalue *retval, const char* cname, Hjava_lang_ClassLoader* loader, const char* method_name, const char* signature, va_list argptr) { Hjava_lang_Class* clazz; errorInfo info; Method* mb = NULL; char *buf; /* Convert "." to "/" and lookup class */ buf = checkPtr(KMALLOC(strlen(cname) + 1)); classname2pathname(cname, buf); clazz = lookupClass(buf, loader, &info); KFREE(buf); /* Get method */ if (clazz != NULL) { mb = lookupClassMethod(clazz, method_name, signature, false, &info); } if (mb == NULL) { throwError(&info); } /* Method must be static to invoke it here */ if ((mb->accflags & ACC_STATIC) == 0) { throwException(NoSuchMethodError(method_name)); } /* Make the call */ KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), NULL, argptr, retval); }
static void pcconsole_probe(cfe_driver_t *drv, unsigned long probe_a, unsigned long probe_b, void *probe_ptr) { pcconsole_t *softc; char descr[80]; /* * probe_a is * probe_b is * probe_ptr is */ softc = (pcconsole_t *) KMALLOC(sizeof(pcconsole_t),0); if (softc) { memset(softc,0,sizeof(pcconsole_t)); vga_init(&(softc->vga),__ISAaddr(VGA_TEXTBUF_COLOR),outb); xsprintf(descr,"%s",drv->drv_description,probe_a,probe_b); cfe_attach(drv,softc,NULL,descr); } }
int cfe_attach_idx(cfe_driver_t *drv,int idx,void *softc, char *bootinfo,char *description) { char name[64]; cfe_device_t *dev; xsprintf(name,"%s%d",drv->drv_bootname,idx); if (bootinfo) { strcat(name,"."); strcat(name,bootinfo); } if (cfe_finddev(name) != NULL) { return 0; } dev = (cfe_device_t *) KMALLOC(sizeof(cfe_device_t),0); if (!dev) return -1; dev->dev_fullname = strdup(name); dev->dev_softc = softc; dev->dev_class = drv->drv_class; dev->dev_dispatch = drv->drv_dispatch; dev->dev_description = description ? strdup(description) : NULL; dev->dev_opencount = 0; q_enqueue(&cfe_devices,(queue_t *) dev); return 1; }
struct debug_file *createDebugFile(const char *filename) { struct debug_file *retval = 0; assert(filename != NULL); /* Allocate space for the debug_file struct and filename */ if( (retval = (struct debug_file *) KMALLOC(sizeof(struct debug_file) + strlen(filename) + 1)) ) { retval->df_filename = (char *)(retval + 1); strcpy(retval->df_filename, filename); retval->df_current_type_id = STYPE_MAX; if( (retval->df_file = fopen(retval->df_filename, "w")) ) { addDebugInfo(retval, DIA_SourceFile, "$xdb$.java", 0, DIA_Comment, debug_header, DIA_DONE); fprintf(retval->df_file, "%s", types_header); } else { KFREE(retval); retval = 0; } } return( retval ); }
static void sb1250_uart_probe(cfe_driver_t *drv, unsigned long probe_a, unsigned long probe_b, void *probe_ptr) { sb1250_uart_t *softc; char descr[80]; /* * probe_a is the DUART base address. * probe_b is the channel-number-within-duart (0 or 1) * probe_ptr is unused. */ softc = (sb1250_uart_t *) KMALLOC(sizeof(sb1250_uart_t),0); if (softc) { softc->uart_mode_reg_1 = probe_a + R_DUART_CHANREG(probe_b,R_DUART_MODE_REG_1); softc->uart_mode_reg_2 = probe_a + R_DUART_CHANREG(probe_b,R_DUART_MODE_REG_2); softc->uart_clk_sel = probe_a + R_DUART_CHANREG(probe_b,R_DUART_CLK_SEL); softc->uart_cmd = probe_a + R_DUART_CHANREG(probe_b,R_DUART_CMD); softc->uart_status = probe_a + R_DUART_CHANREG(probe_b,R_DUART_STATUS); softc->uart_tx_hold = probe_a + R_DUART_CHANREG(probe_b,R_DUART_TX_HOLD); softc->uart_rx_hold = probe_a + R_DUART_CHANREG(probe_b,R_DUART_RX_HOLD); softc->uart_imr = probe_a + R_DUART_IMRREG(probe_b); softc->uart_oprset = probe_a + R_DUART_SET_OPR; xsprintf(descr,"%s at 0x%X channel %d",drv->drv_description,probe_a,probe_b); softc->uart_speed = CFG_SERIAL_BAUD_RATE; softc->uart_flowcontrol = SERIAL_FLOW_NONE; cfe_attach(drv,softc,NULL,descr); } }
/* filename describes the location in memory in string */ static int memory_fileop_open(void **ref, void *fsctx_arg, char *filename, int mode) { memory_fsctx_t *fsctx; memory_file_t *file; if (mode != FILE_MODE_READ) return CFE_ERR_UNSUPPORTED; fsctx = (memory_fsctx_t *) fsctx_arg; file = KMALLOC(sizeof(memory_file_t), 0); if (!file) { return CFE_ERR_NOMEM; } if (filename[0] == ':') filename++; /* Skip over colon */ file->memory_start = xtoi(filename); file->memory_offset = 0; *ref = file; return 0; }
static void setupSigAltStack(void) { STACK_STRUCT newstack; void *stackp; /* * Signals has to have their own stack so we can solve * stack problems. */ newstack.ss_size = THREADSTACKSIZE; newstack.ss_flags = 0; stackp = KMALLOC(newstack.ss_size); #if defined(SIGALTSTACK_NEEDS_END) newstack.ss_sp = (void *)((uintp)stackp + newstack.ss_size); #else newstack.ss_sp = stackp; #endif if (sigaltstack(&newstack, NULL) < 0) { dprintf("Unexpected error calling sigaltstack: %s\n", SYS_ERROR(errno)); KAFFEVM_EXIT(1); } }
static LONG CDECL comm_open(FILEPTR * f) { char deb[100]; NOT_USED(f); /* Create and initialize internal file handle */ FH(f) = (LONG)KMALLOC(sizeof(FileHandle)); FH(f)->bytes_out = 0; FH(f)->selected = 0; FH(f)->queued = 0; SPRINTF(deb, "srv_comm_device: open: devinfo = 0x%lx, f = 0x%lx", f->devinfo, f); TRACE(deb); return 0; }
static int flashdrv_open(cfe_devctx_t *ctx) { flashpart_t *part = ctx->dev_softc; flashdev_t *softc = part->fp_dev; int ttlsect = softc->fd_ttlsect; /* * Calculate number of flashop instructions we'll need at most. * This will be two for each sector plus two more for the first * and last sectors, plus two extra */ ttlsect = (ttlsect * 2 * softc->fd_probe.flash_nchips) + 6; /* * Allocate memory for instructions. */ #ifdef _NEWFLASH_DEBUG_ printf("%s: allocating %d instructions\n",cfe_device_name(ctx),ttlsect); #endif softc->fd_inst = KMALLOC(ttlsect*sizeof(flashinstr_t),0); if (!softc->fd_inst) return CFE_ERR_NOMEM; return 0; }
static int raw_fileop_init(void **newfsctx,void *dev) { raw_fsctx_t *fsctx; char *devicename = (char *) dev; *newfsctx = NULL; fsctx = KMALLOC(sizeof(raw_fsctx_t),0); if (!fsctx) { return CFE_ERR_NOMEM; } if (strcmp(devicename,console_name) == 0) { fsctx->raw_dev = console_handle; fsctx->raw_isconsole = TRUE; } else { fsctx->raw_dev = cfe_open(devicename); fsctx->raw_isconsole = FALSE; } fsctx->raw_refcnt = 0; if (fsctx->raw_dev >= 0) { *newfsctx = fsctx; return 0; } KFREE(fsctx); return CFE_ERR_FILENOTFOUND; }
ui_command_t *cmd_readcommand(queue_t *head) { char *ptr; int insquote = FALSE; int indquote = FALSE; ui_command_t *cmd; int term = CMD_TERM_EOL; ui_token_t *t; cmd_eat_leading_white(head); if (q_isempty(head)) return NULL; cmd = (ui_command_t *) KMALLOC(sizeof(ui_command_t),0); q_init(&(cmd->head)); while ((t = (ui_token_t *) q_deqnext(head))) { ptr = &(t->token); if (!insquote && !indquote) { if ((*ptr == ';') || (*ptr == '\n')) { term = CMD_TERM_SEMI; break; } if ((*ptr == '&') && (*(ptr+1) == '&')) { term = CMD_TERM_AND; break; } if ((*ptr == '|') && (*(ptr+1) == '|')) { term = CMD_TERM_OR; break; } } if (*ptr == '\'') { insquote = !insquote; } if (!insquote) { if (*ptr == '"') { indquote = !indquote; } } q_enqueue(&(cmd->head),&(t->qb)); } cmd->term = term; /* If we got out by finding a command separator, eat the separator */ if (term != CMD_TERM_EOL) { KFREE(t); } return cmd; }
int env_save(void) { int size; unsigned char *buffer; unsigned char *buffer_end; unsigned char *ptr; queue_t *qb; cfe_envvar_t *env; int namelen; int valuelen; int flg; flg = nvram_open(); if (flg < 0) return flg; nvram_erase(); size = nvram_getsize(); buffer = KMALLOC(size,0); if (buffer == NULL) return CFE_ERR_NOMEM; buffer_end = buffer + size; ptr = buffer; for (qb = env_envvars.q_next; qb != &env_envvars; qb = qb->q_next) { env = (cfe_envvar_t *) qb; if (env->flags & (ENV_FLG_BUILTIN)) continue; namelen = strlen(env->name); valuelen = strlen(env->value); if ((ptr + 2 + namelen + valuelen + 1 + 1 + 1) > buffer_end) break; *ptr++ = ENV_TLV_TYPE_ENV; /* TLV record type */ *ptr++ = (namelen + valuelen + 1 + 1); /* TLV record length */ *ptr++ = (unsigned char)env->flags; memcpy(ptr,env->name,namelen); /* TLV record data */ ptr += namelen; *ptr++ = '='; memcpy(ptr,env->value,valuelen); ptr += valuelen; } *ptr++ = ENV_TLV_TYPE_END; size = nvram_write(buffer,0,ptr-buffer); KFREE(buffer); nvram_close(); return (size == (ptr-buffer)) ? 0 : CFE_ERR_IOERR; }
static ui_token_t *make_token(char *str,int len) { ui_token_t *t = (ui_token_t *) KMALLOC(sizeof(ui_token_t) + len,0); memcpy(&(t->token),str,len); (&(t->token))[len] = 0; return t; }
static int tftp_fileop_open(void **ref,void *fsctx,char *filename,int mode) { tftp_info_t *info; char *host; char *file; int res; if ((mode != FILE_MODE_READ) && (mode != FILE_MODE_WRITE)) { /* must be either read or write, not both */ return CFE_ERR_UNSUPPORTED; } /* Allocate the tftp info structure */ info = KMALLOC(sizeof(tftp_info_t),0); if (!info) { return CFE_ERR_NOMEM; } info->tftp_filename = lib_strdup(filename); if (!info->tftp_filename) { KFREE(info); return CFE_ERR_NOMEM; } lib_chop_filename(info->tftp_filename,&host,&file); /* Open the file */ if (!*host && !*file) { /* TFTP server if hostname and filename are not specified */ #ifdef RESCUE_MODE xprintf("TFTP Server.\n"); #endif res = _tftpd_open(info,host,file,mode); } else { /* TFTP client otherwise */ #ifdef RESCUE_MODE xprintf("TFTP Client.\n"); #endif res = _tftp_open(info,host,file,mode); } if (res == 0) { info->tftp_blkoffset = 0; info->tftp_fileoffset = 0; *ref = info; } else { KFREE(info->tftp_filename); KFREE(info); *ref = NULL; } return res; }
static int tftp_fileop_init(void **fsctx,void *dev) { void *ref; ref = KMALLOC(sizeof(tftp_fsctx_t),0); if (!ref) return CFE_ERR_NOMEM; *fsctx = ref; return 0; }
int tmb_alloc(tcpmodbuf_t *buf,int size) { buf->tmb_buf = KMALLOC(size,0); if (!buf->tmb_buf) return -1; buf->tmb_bufsize = size; tmb_init(buf); return 0; }
int unionfs_ioctl_rdwrbranch(struct inode *inode, unsigned int cmd, unsigned long arg) { int err; struct unionfs_rdwrbranch_args *rdwrargs = NULL; int gen; print_entry_location(); unionfs_write_lock(inode->i_sb); lock_dentry(inode->i_sb->s_root); if ((err = newputmap(inode->i_sb))) goto out; err = -ENOMEM; rdwrargs = KMALLOC(sizeof(struct unionfs_rdwrbranch_args), GFP_KERNEL); if (!rdwrargs) goto out; err = -EFAULT; if (copy_from_user (rdwrargs, (const void __user *)arg, sizeof(struct unionfs_rdwrbranch_args))) goto out; err = -EINVAL; if (rdwrargs->rwb_branch < 0 || (rdwrargs->rwb_branch > (sbend(inode->i_sb) + 1))) goto out; if (rdwrargs->rwb_perms & ~(MAY_READ | MAY_WRITE | MAY_NFSRO)) goto out; if (!(rdwrargs->rwb_perms & MAY_READ)) goto out; set_branchperms(inode->i_sb, rdwrargs->rwb_branch, rdwrargs->rwb_perms); atomic_inc(&stopd(inode->i_sb)->usi_generation); gen = atomic_read(&stopd(inode->i_sb)->usi_generation); atomic_set(&dtopd(inode->i_sb->s_root)->udi_generation, gen); atomic_set(&itopd(inode->i_sb->s_root->d_inode)->uii_generation, gen); err = 0; out: unlock_dentry(inode->i_sb->s_root); unionfs_write_unlock(inode->i_sb); KFREE(rdwrargs); print_exit_status(err); return err; }
static int cast5_setkey(u_int8_t **sched, u_int8_t *key, int len) { int err; *sched = KMALLOC(sizeof(cast_key), M_CRYPTO_DATA, M_NOWAIT|M_ZERO); if (*sched != NULL) { cast_setkey((cast_key *)*sched, key, len); err = 0; } else err = ENOMEM; return err; }
static kcontext_t* new_hcontext(CTX0) { kcontext_t *ctx; static volatile size_t ctxid_counter = 0; if(_ctx0 == NULL) { ctx = (kcontext_t*)malloc(sizeof(kcontext_t)); knh_bzero(_ctx, sizeof(kcontext_t)); } else { KNH_ASSERT_CTX0(_ctx0); ctx = (kcontext_t*)KMALLOC(_ctx0, sizeof(kcontext_t)); knh_bzero(_ctx, sizeof(kcontext_t)); } ctx->flag = 0; ctx->ctxid = ctxid_counter; ctxid_counter++; // ctx->freeObjectList = NULL; // ctx->freeMemoryList = NULL; ctx->parent = ctx; ctx->api2 = getapi2(); { uintptr_t i = 0, ch; kuint_t t = knh_rand(); ch = t % 26; ctx->trace[i] = 'A' + ch; for(i = 1; i < 9; i++) { t = t / 36; if (t == 0) t = knh_rand(); ch = t % 36; ctx->trace[i] = (ch < 10) ? '0' + ch : 'A' + (ch - 10); } } ctx->seq = 0; ctx->ctxobjNC = NULL; if(_ctx0 == NULL) { const char *ptrace = knh_getenv(K_DEOS_TRACE); if(ptrace == NULL) { ptrace = "$(setenv " K_DEOS_TRACE ")"; } KNH_NTRACE2(_ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA( LOG_s("parent", ptrace) #if defined(K_USING_POSIX_) , LOG_u("ppid", getppid()) #endif /* !defined(K_USING_POSIX_) */ )); } else { KNH_NTRACE2(_ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA(LOG_s("parent", ctx0->trace), LOG_u("seq", ctx0->seq))); } return ctx; }
static void console_save(unsigned char *buffer,int length) { msgqueue_t *msg; /* * Get a pointer to the last message in the queue. If * it's full, preprare to allocate a new one */ msg = (msgqueue_t *) console_msgq.q_prev; if (q_isempty(&(console_msgq)) || (msg->len == MSGQUEUESIZE)) { msg = NULL; } /* * Stuff characters into message chunks till we're done */ while (length) { /* * New chunk */ if (msg == NULL) { msg = (msgqueue_t *) KMALLOC(sizeof(msgqueue_t),0); if (msg == NULL) return; msg->len = 0; q_enqueue(&console_msgq,(queue_t *) msg); /* * Remove chunks to prevent chewing too much memory */ while (q_count(&console_msgq) > MSGQUEUEMAX) { msgqueue_t *dropmsg; dropmsg = (msgqueue_t *) q_deqnext(&console_msgq); if (dropmsg) KFREE(dropmsg); } } /* * Save text. If we run off the end of the buffer, prepare * to allocate a new one */ msg->data[msg->len++] = *buffer++; length--; if (msg->len == MSGQUEUESIZE) msg = NULL; } }
/** * Allocate an object and execute the constructor. * * @param cname the name of the class to be instantiated (may be 0 if cc is != 0) * @param loader the class loader that's to be used to lookup the class * @param cc the class to be instantiated (may be 0 if cname is != 0) * @param signature the signature of the constructor to be executed * @param argptr arguments to be passed to the constructor * * @throws InstantiationException if class is an interface or abstract * @throws NoSuchMethodError if the specified constructor cannot be found * * @return the newly allocated object */ Hjava_lang_Object* execute_java_constructor_v(const char* cname, Hjava_lang_ClassLoader* loader, Hjava_lang_Class* cc, const char* signature, va_list argptr) { Hjava_lang_Object* obj; Method* mb; jvalue retval; errorInfo info; Utf8Const* sig; if (cc == 0) { char *buf; /* Convert "." to "/" and lookup class */ buf = checkPtr(KMALLOC(strlen(cname) + 1)); classname2pathname(cname, buf); cc = lookupClass(buf, loader, &info); KFREE(buf); if (!cc) { throwError(&info); } } /* We cannot construct interfaces or abstract classes */ if (CLASS_IS_INTERFACE(cc) || CLASS_IS_ABSTRACT(cc)) { throwException(InstantiationException(cc->name->data)); } if (cc->state < CSTATE_USABLE) { if (processClass(cc, CSTATE_COMPLETE, &info) == false) { throwError(&info); } } sig = checkPtr(utf8ConstFromString(signature)); mb = findMethodLocal(cc, constructor_name, sig); utf8ConstRelease(sig); if (mb == 0) { throwException(NoSuchMethodError(constructor_name->data)); } obj = newObject(cc); assert(obj != 0); /* Make the call */ KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), obj, argptr, &retval); return (obj); }
/* * call d_drop so the system "forgets" about us */ if (!err) d_drop(dentry); dput(dentry); print_exit_status(err); return err; } STATIC int base0fs_mknod(inode_t *dir, struct dentry *dentry, int mode, dev_t dev) { int err; struct dentry *lower_dentry; struct dentry *lower_dir_dentry; print_entry_location(); lower_dentry = base0fs_lower_dentry(dentry); /* CPW: Moved below print_entry_location */ fist_checkinode(dir, "base0fs_mknod-dir"); lower_dir_dentry = base0fs_lock_parent(lower_dentry); err = VFS_MKNOD(lower_dir_dentry->d_inode, lower_dentry, mode, dev); if (err || !lower_dentry->d_inode) goto out; err = base0fs_interpose(lower_dentry, dentry, dir->i_sb, 0); if (err) goto out; fist_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); out: unlock_dir(lower_dir_dentry); if (!dentry->d_inode) d_drop(dentry); fist_checkinode(dir, "post base0fs_mknod-dir"); print_exit_status(err); return err; } STATIC int base0fs_rename(inode_t *old_dir, struct dentry *old_dentry, inode_t *new_dir, struct dentry *new_dentry) { int err; struct dentry *lower_old_dentry; struct dentry *lower_new_dentry; struct dentry *lower_old_dir_dentry; struct dentry *lower_new_dir_dentry; print_entry_location(); lower_old_dentry = base0fs_lower_dentry(old_dentry);/* CPW: Moved below print_entry_location */ lower_new_dentry = base0fs_lower_dentry(new_dentry); fist_checkinode(old_dir, "base0fs_rename-old_dir"); fist_checkinode(new_dir, "base0fs_rename-new_dir"); dget(lower_old_dentry); dget(lower_new_dentry); lower_old_dir_dentry = dget_parent(lower_old_dentry); lower_new_dir_dentry = dget_parent(lower_new_dentry); lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); err = VFS_RENAME(lower_old_dir_dentry->d_inode, lower_old_dentry, lower_new_dir_dentry->d_inode, lower_new_dentry); if (err) goto out_lock; fist_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); if (new_dir != old_dir) fist_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); out_lock: // unlock_rename will dput the new/old parent dentries whose refcnts // were incremented via dget_parent above. dput(lower_new_dentry); dput(lower_old_dentry); unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); fist_checkinode(new_dir, "post base0fs_rename-new_dir"); print_exit_status(err); return err; } STATIC int base0fs_readlink(struct dentry *dentry, char *buf, int bufsiz) { int err; struct dentry *lower_dentry; print_entry_location(); lower_dentry = base0fs_lower_dentry(dentry);/* CPW: Moved below print_entry_location */ fist_print_dentry("base0fs_readlink IN", dentry); if (!lower_dentry->d_inode->i_op || !lower_dentry->d_inode->i_op->readlink) { err = -EINVAL; goto out; } err = lower_dentry->d_inode->i_op->readlink(lower_dentry, buf, bufsiz); if (err > 0) fist_copy_attr_atime(dentry->d_inode, lower_dentry->d_inode); out: print_exit_status(err); return err; } #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) STATIC int base0fs_follow_link(struct dentry *dentry, struct nameidata *nd) #else /* 2.6.13 or newer */ STATIC void * base0fs_follow_link(struct dentry *dentry, struct nameidata *nd) #endif /* 2.6.13 or newer */ { char *buf; int len = PAGE_SIZE, err; mm_segment_t old_fs; struct dentry *lower_dentry; print_entry_location(); // fist_print_dentry("base0fs_follow_link dentry IN", dentry); /* buf is allocated here, and freed when VFS calls our put_link method */ err = -ENOMEM; buf = KMALLOC(len, GFP_KERNEL); if (!buf) goto out; old_fs = get_fs(); set_fs(KERNEL_DS); err = dentry->d_inode->i_op->readlink(dentry, buf, len); set_fs(old_fs); if (err < 0) goto out_free; buf[err] = 0; // terminate the buffer -- XXX still needed? err = 0; nd_set_link(nd,buf); goto out; out_free: KFREE(buf); out: #if 0 if (err < 0) { dput(nd->dentry); printk("EZK follow_link() mnt_cnt %d\n", (int) atomic_read(&nd->mnt->mnt_count)); mntput(nd->mnt); } #endif print_exit_status(err); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) return err; #else /* 2.6.13 or newer */ return ERR_PTR(err); #endif /* 2.6.13 or newer */ }
/* returns length of decoded string, or -1 if error */ int kdb3fs_decode_filename(const char *name, int length, char **decoded_name, int skip_dots, const vnode_t *this_vnode, const vfs_t *this_vfsp) { int error = 0; *decoded_name = KMALLOC(length, GFP_KERNEL); if (!*decoded_name) { printk("<0>Kernel out of memory!\n"); ASSERT(NULL); } memcpy(*decoded_name, name, length); error = length; return error; }
static int raw_fileop_open(void **ref,void *fsctx_arg,char *filename,int mode) { raw_fsctx_t *fsctx; raw_file_t *file; char temp[100]; char *len; if (mode != FILE_MODE_READ) return CFE_ERR_UNSUPPORTED; fsctx = (raw_fsctx_t *) fsctx_arg; file = KMALLOC(sizeof(raw_file_t),0); if (!file) { return CFE_ERR_NOMEM; } file->raw_fileoffset = 0; file->raw_fsctx = fsctx; /* Assume the whole device. */ file->raw_baseoffset = 0; file->raw_length = -1; /* * If a filename was specified, it will be in the form * offset,length - for example, 0x10000,0x200 * Parse this into two pieces and set up our internal * file extent information. you can use either decimal * or "0x" notation. */ if (filename) { lib_trimleading(filename); strncpy(temp,filename,sizeof(temp)); len = strchr(temp,','); if (len) *len++ = '\0'; if (temp[0]) { file->raw_baseoffset = lib_atoi(temp); } if (len) { file->raw_length = lib_atoi(len); } } fsctx->raw_refcnt++; *ref = file; return 0; }
int kdb3fs_encode_filename(const char *name, int length, char **encoded_name, int skip_dots, const vnode_t *this_vnode, const vfs_t *this_vfsp) { int encoded_length; encoded_length = length + 1; *encoded_name = KMALLOC(encoded_length, GFP_KERNEL); if (!*encoded_name) { printk("<0>Kernel out of memory!\n"); ASSERT(NULL); } memcpy(*encoded_name, name, length); (*encoded_name)[length] = '\0'; return encoded_length; }
/* ********************************************************************* * flashdrv_allocbuf(dev) * * Allocate sector buffer for flash programming. Use a global * buffer for all devices. * * Input parameters: * dev - our device * * Return value: * nothing ********************************************************************* */ static void flashdrv_allocbuf(flashdev_t *softc) { if (!flash_sector_buffer) { #if CFG_FLASH_ALLOC_SECTOR_BUFFER flash_sector_buffer = KMALLOC(CFG_FLASH_SECTOR_BUFFER_SIZE,0); if (!flash_sector_buffer) { printf("FLASH: Could not allocate sector buffer, using default\n"); flash_sector_buffer = (uint8_t *) KERNADDR(CFG_FLASH_SECTOR_BUFFER_SIZE); } #else flash_sector_buffer = (uint8_t *) KERNADDR(CFG_FLASH_SECTOR_BUFFER_ADDR); #endif } softc->fd_sectorbuffer = flash_sector_buffer; }
static int des1_setkey(u_int8_t **sched, u_int8_t *key, int len) { des_key_schedule *p; int err; p = KMALLOC(sizeof (des_key_schedule), M_CRYPTO_DATA, M_NOWAIT|M_ZERO); if (p != NULL) { des_set_key((des_cblock *) key, p[0]); err = 0; } else err = ENOMEM; *sched = (u_int8_t *) p; return err; }
static int memory_fileop_init(void **newfsctx, void *dev) { memory_fsctx_t *fsctx; *newfsctx = NULL; fsctx = KMALLOC(sizeof(memory_fsctx_t), 0); if (!fsctx) { return CFE_ERR_NOMEM; } fsctx->memory_tmp = 0; *newfsctx = fsctx; return 0; }
static int jitSectionHandler(struct file_section *fs, struct section_file *sf, int method, ...) { int retval = 1; va_list args; va_start(args, method); switch( method ) { case SFM_CREATE: { struct section_file_data **out_sfd; struct jit_section_data *jsd; char *name, *tag, *value; va_list_ptr values; /* Get the args */ out_sfd = va_arg(args, struct section_file_data **); name = va_arg(args, char *); values = va_arg(args, va_list_ptr); /* Allocate the section struct and initialize it */ if( (jsd = (struct jit_section_data *) KMALLOC(sizeof(struct jit_section_data))) ) { assert(name[0]); jsd->jsd_link.sfd_type = fs; jsd->jsd_link.sfd_flags = 0; jsd->jsd_link.sfd_name = name; jsd->jsd_flags = 0; jsd->jsd_size = 0; jsd->jsd_address = 0; /* Process the rest of the args */ tag = va_arg((*values), char *); while( tag ) { value = va_arg((*values), char *); setJITSectionValue(jsd, tag, value); tag = va_arg((*values), char *); } *out_sfd = &jsd->jsd_link; } else { retval = 0; } }