////复制父进程的地址空间 static int copy_mem(int pid,struct task_struct *p) { struct descriptor *dp = &proc_table[pid].ldts[INDEX_LDT_C]; int text_base = get_base(dp); int text_limit = get_limit(dp); int text_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1); dp = &proc_table[pid].ldts[INDEX_LDT_D]; int data_base = get_base(dp); int data_limit= get_limit(dp); int data_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1); assert((text_base == data_base) && (text_limit == data_limit) && (text_size == data_size) ); int child_base = alloc_mem(p->pid,text_size); // printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size); // memcpy((void *)child_base,(void *)(text_base),text_size); // printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size); phys_copy((char *)child_base,(char *)(text_base),text_size); return child_base; }
int do_exit(long code) { int i; free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); for (i=0 ; i<NR_TASKS ; i++) if (task[i] && task[i]->father == current->pid) task[i]->father = 0; for (i=0 ; i<NR_OPEN ; i++) if (current->filp[i]) sys_close(i); iput(current->pwd); current->pwd=NULL; iput(current->root); current->root=NULL; if (current->leader && current->tty >= 0) tty_table[current->tty].pgrp = 0; if (last_task_used_math == current) last_task_used_math = NULL; if (current->father) { current->state = TASK_ZOMBIE; do_kill(current->father,SIGCHLD,1); current->exit_code = code; } else release(current); schedule(); return (-1); /* just to suppress warnings */ }
const char *system_get_version(enum system_image_copy_t copy) { uintptr_t addr; const struct version_struct *v; /* Handle version of current image */ if (copy == system_get_image_copy() || copy == SYSTEM_IMAGE_UNKNOWN) return &RO(version_data).version[0]; addr = get_base(copy); if (addr == 0xffffffff) return ""; /* The version string is always located after the reset vectors, so * it's the same as in the current image. */ addr += ((uintptr_t)&version_data - get_base(system_get_image_copy())); /* Make sure the version struct cookies match before returning the * version string. */ v = (const struct version_struct *)addr; if (v->cookie1 == RO(version_data).cookie1 && v->cookie2 == RO(version_data).cookie2) return v->version; return ""; }
int do_exit(long code) { int i; free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); for (i=0 ; i<NR_TASKS ; i++) if (task[i] && task[i]->father == current->pid) { task[i]->father = 1; if (task[i]->state == TASK_ZOMBIE) /* assumption task[1] is always init */ (void) send_sig(SIGCHLD, task[1], 1); } for (i=0 ; i<NR_OPEN ; i++) if (current->filp[i]) sys_close(i); iput(current->pwd); current->pwd=NULL; iput(current->root); current->root=NULL; iput(current->executable); current->executable=NULL; if (current->leader && current->tty >= 0) tty_table[current->tty].pgrp = 0; if (last_task_used_math == current) last_task_used_math = NULL; if (current->leader) kill_session(); current->state = TASK_ZOMBIE; current->exit_code = code; tell_father(current->father); schedule(); return (-1); /* just to suppress warnings */ }
static void die(char * str,long esp_ptr,long nr) { long * esp = (long *) esp_ptr; int i; printk("%s: %04x\n\r",str,nr&0xffff); printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n", esp[1],esp[0],esp[2],esp[4],esp[3]); printk("fs: %04x\n",_fs()); printk("code base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17)); printk("data base: %p, limit: %p\n",get_base(current->ldt[2]),get_limit(0x17)); long line = get_base(current->ldt[1])+esp[0]; long ph0 = (*(long *)(current->tss.cr3 + ((line>>20) & 0xffc ))); long ph1 = *(long*)(((line>>10) & 0xffc)+(*(long *)(current->tss.cr3 + ((line>>20) & 0xffc )))); printk("line: %p, ph: %p %p\n",line,ph0,ph1); if (esp[4] == 0x17) { printk("Stack: "); for (i=0;i<4;i++) printk("%p ",get_seg_long(0x17,i+(long *)esp[3])); printk("\n"); } str(i); printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i); for(i=0;i<10;i++) printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0]))); printk("\n\r"); do_exit(11); /* play segment exception */ }
int do_exit(long code) { int i; // TODO 待看页表 free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); /* * 找出所有子进程,将它们的父亲设为 init 进程,将状态标记为僵尸 * 然后给 init 进程发送一个 SIGCHLD 信号,提醒 init 进程回收子进程 */ for (i=0 ; i<NR_TASKS ; i++) if (task[i] && task[i]->father == current->pid) { task[i]->father = 1; if (task[i]->state == TASK_ZOMBIE) /* assumption task[1] is always init */ // 最后一个参数 1 代表 privilege,此处为强制发送 (void) send_sig(SIGCHLD, task[1], 1); } // TODO 关闭文件? /* * NR_OPEN 是一个进程可以打开的最大文件数 * 而 NR_FILE 是系统在某时刻的限制文件总数 */ for (i=0 ; i<NR_OPEN ; i++) if (current->filp[i]) sys_close(i); // 进程的当前工作目录 inode iput(current->pwd); current->pwd=NULL; // 进程的根目录 inode iput(current->root); current->root=NULL; // 进程本身可执行文件的 inode iput(current->executable); current->executable=NULL; if (current->leader && current->tty >= 0) tty_table[current->tty].pgrp = 0; if (last_task_used_math == current) last_task_used_math = NULL; /* * 如果是 session leader 会话领头进程,则向该会话所有进程发送 SIGHUP 信号 * PID, PPID, PGID, SID * http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps * 在同一次 ssh 会话中,用户对应的 shell 最先被启动,成为 session leader, * 所有在同一次会话中产生的进程 session id 都等于这个 session leader 的 pid * 当 session leader 退出时,它会向所有同一 session 中的进程发送 SIGHUP, * 这个信号是可以被捕获的,如果进程忽略这个 SIGHUP,它则可以以一个孤儿进程继续执行 * http://www.firefoxbug.com/index.php/archives/2782/ */ if (current->leader) kill_session(); // 将自己设为僵尸,设置退出状态码,同时告诉父进程回收子进程 current->state = TASK_ZOMBIE; current->exit_code = code; tell_father(current->father); // 如果 tell_father 中找不到父进程,自己把自己释放掉了,那也不会有机会继续执行下面代码了 schedule(); return (-1); /* just to suppress warnings */ }
int con_branching() { CONSTRAINT *row0,*row1; double old_lowerb = lowerb; #ifdef STAMP std::cout << " >>>>>>>>>>>>> constraint branching " << std::endl; if(branchs==0) write_sol(fsolution); #endif if( upperb < ceil(lowerb-ZERO)+ZERO ) return(1); //// constraint_branching(nbetter,better,&row0,&row1); constraint_branching(nsupport,support,&row0,&row1); if( upperb < ceil(lowerb-ZERO)+ZERO ) return(1); if(row0==NULL && row1==NULL)return(-1); if(row0==NULL || row1==NULL)return(0); /*** to do not use the branch-cuts ***/ //// return(-1); branchs++; #ifdef STAMP std::cout << "branching " << branchs << " on constraint" << std::endl; #endif /* making the left child */ row0->stat = LP_BA; add_rows(1,&row0); lowerb = solve_lp(0); get_solution(); get_base(); write_prob(); deletelastrow(); row0->stat = FIX_LB; /* making the left child */ row1->stat = LP_BA; add_rows(1,&row1); lowerb = solve_lp(0); get_solution(); get_base(); write_prob(); deletelastrow(); row1->stat = FIX_LB; lowerb = old_lowerb; return(1); }
double ContAlign::align (const char* xseq, int xlen, const char* yseq, int ylen, bool unpack) { int x, y; char* bp = btrmx; max_reached = false; last_reached = false; accum_hor_skip = 0; to_first = false, to_last = false; //check if enough memory allocated for band alignment if (ylen > max_ylen || xlen * ylen > max_size || xlen > max_xlen) ers << "align error: attempting to align sequences longer than declared, xlen = " << xlen << ", ylen = " << ylen << Throw; bstep = ylen; xref = 0, yref = 0; // initialize homopolimer size indices fill_homo_tract_len (xseq, xlen, xhomo); fill_homo_tract_len (yseq, ylen, yhomo); //initialize left boundary //unpack Y sequence for faster processing for (y = 0; y < ylen; y++) { ap[y].w = 0; ap[y].h = low_score; ap[y].r = unpack? get_base (yseq, y) : yseq [y]; ap[y].div = yhomo [y+1]; } //find best local alignment double cur_w; max_w = last_w = - std::numeric_limits <double>::max (); max_bp = btrmx; for (x = 0; x < xlen; x++, bp += bstep) { cur_w = align_y_loop (ap, unpack ? get_base (xseq, x) : xseq [x+1], bp, x, xhomo [x], 0, ylen, true, 0.0); // remember X edge terminal scores if (last_w < cur_w) last_w = cur_w, last_bp = bp + ylen - 1, last_x = x, last_y = ylen-1, last_reached = true; } #ifdef DEBUG_TRACE if (trace_mode) trclog << std::endl; #endif if (logp_) (*logp_) << std::endl; return get_score (); }
u32 is_running_in_sdram(void) { if (get_base() > 4) return 1; /* in SDRAM */ return 0; /* running in SRAM */ }
Status conversion (Stack *S) { int inbase, outbase, number; int curr; int res; get_base(&inbase, &outbase); get_number(&number); curr = number; res = 0; if (inbase == 10 && outbase == 2) { BtoA(S, 2, number); } else if (inbase == 2 && (outbase == 8 || outbase == 16 || outbase == 10)) { BtoD(number, &res); BtoA(S, outbase, res); } else { printf("un support conversion now."); exit(ERROR); } return 0; }
int unsigned_int(va_list list, t_flags *tflags) { int cpt; int size; int size_pref; uintmax_t nbr; char *base; cpt = 0; nbr = va_arg(list, uintmax_t); if (tflags->type == 'U' || tflags->type == 'O' || tflags->type == 'p') tflags->conv = 'l'; wololo(&nbr, tflags); base = get_base(tflags); size = ucalcul_size(tflags, nbr, base); size_pref = 0; cpt += uleft_space_padding(tflags, size); cpt += prefixe_writing(tflags, nbr); cpt += uleft_zero_sign(tflags, size, nbr); if (!(tflags->prec == 0 && nbr == 0)) cpt += ft_pprint_base(nbr, base); else if (tflags->min_width > 0) buffin(' '); cpt += uright_space_padding(tflags, size); free(base); return (cpt); }
// 该子程序用来打印出错中断的名称、出错号、调用程序的EIP、EFLAGS、ESP、fs段寄存器值、 // 段的基址、段的长度、进程号PID、任务号、10字节指令码。如果堆栈在用户数据段,则还 // 打印16字节的堆栈内容。 static void die(char * str,long esp_ptr,long nr) { long * esp = (long *) esp_ptr; int i; printk("%s: %04x\n\r",str,nr&0xffff); // 下行打印语句显示当前调用进程的CS:EIP、EFLAGS和SS:ESP的值。 // EIP:\t%04x:%p\n - esp[1]是段选择符(cs),esp[0]是eip. // EFLAGS:\t%p\n - esp[2]是eflags // ESP:\t%04x:%p\n - esp[4]是源ss,esp[3]是源esp printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n", esp[1],esp[0],esp[2],esp[4],esp[3]); printk("fs: %04x\n",_fs()); printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17)); if (esp[4] == 0x17) { printk("Stack: "); for (i=0;i<4;i++) printk("%p ",get_seg_long(0x17,i+(long *)esp[3])); printk("\n"); } str(i); // 取当前运行任务的任务号 printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i); for(i=0;i<10;i++) printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0]))); printk("\n\r"); do_exit(11); /* play segment exception */ }
// 该子程序用来打印出错中断的名称、出错号、调用程序的EIP、EFLAGS、ESP、fs寄存器值、 // 段的基址、段的长度、进程号pid、任务号、10字节指令码。如果堆栈在用户数据段,则还 // 打印16字节的堆栈内容。 static void die(char * str,long esp_ptr,long nr) { long * esp = (long *) esp_ptr; int i; printk("%s: %04x\n\r",str,nr&0xffff); // 下行打印语句显示当前调用进程的CS:EIP、EFLAGS和SS:ESP的值。参照图8-4,这里esp[0]即为 // 图中的esp0位置。因此我们把这句拆分开来看为: // 1)EIP:\t%04x:%p\n -- esp[1]是段选择符(cs),esp[0]是eip // 2)EFLAGS:\t%p -- esp[2]是EFLAGS // 3)ESP:\t%04x:%p\n -- esp[4]是原ss,esp[3]是原esp printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n", esp[1],esp[0],esp[2],esp[4],esp[3]); printk("fs: %04x\n",_fs()); printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17)); if (esp[4] == 0x17) { printk("Stack: "); for (i=0;i<4;i++) printk("%p ",get_seg_long(0x17,i+(long *)esp[3])); printk("\n"); } str(i); // 取当前运行任务的任务号(include/linux/sched.h 159) printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i); for(i=0;i<10;i++) printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0]))); printk("\n\r"); do_exit(11); /* play segment exception */ }
void Ground::draw() { static const int x = 0; static const int y = 1; static const int z = 2; print_error("display ground00"); glUseProgram(program); print_error("display ground0"); Vector3f camera_position = dynamic_cast<Camera*>(parent)->position(); glUniform3fv(glGetUniformLocation(program, "camera_position"), 1, camera_position.data()); camera_position[1] = config["base_level"].as<float>(0.0); base.translation() = camera_position; // Send in additional params glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, get_projection()); glUniformMatrix4fv(glGetUniformLocation(program, "baseMatrix"), 1, GL_FALSE, get_base().data()); print_error("display ground1"); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0 print_error("display ground3"); glBindVertexArray(groundVertexArrayObjectID); // Select VAO glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0L); print_error("display ground4"); }
//// 程序退出处理程序。在系统调用的中断处理程序中被调用。 int do_exit (long code) // code 是错误码。 { int i; // 释放当前进程代码段和数据段所占的内存页(free_page_tables()在mm/memory.c,105 行)。 free_page_tables (get_base (current->ldt[1]), get_limit (0x0f)); free_page_tables (get_base (current->ldt[2]), get_limit (0x17)); // 如果当前进程有子进程,就将子进程的father 置为1(其父进程改为进程1)。如果该子进程已经 // 处于僵死(ZOMBIE)状态,则向进程1 发送子进程终止信号SIGCHLD。 for (i = 0; i < NR_TASKS; i++) if (task[i] && task[i]->father == current->pid) { task[i]->father = 1; if (task[i]->state == TASK_ZOMBIE) /* assumption task[1] is always init */ (void) send_sig (SIGCHLD, task[1], 1); } // 关闭当前进程打开着的所有文件。 for (i = 0; i < NR_OPEN; i++) if (current->filp[i]) sys_close (i); // 对当前进程工作目录pwd、根目录root 以及运行程序的i 节点进行同步操作,并分别置空。 iput (current->pwd); current->pwd = NULL; iput (current->root); current->root = NULL; iput (current->executable); current->executable = NULL; // 如果当前进程是领头(leader)进程并且其有控制的终端,则释放该终端。 if (current->leader && current->tty >= 0) tty_table[current->tty].pgrp = 0; // 如果当前进程上次使用过协处理器,则将last_task_used_math 置空。 if (last_task_used_math == current) last_task_used_math = NULL; // 如果当前进程是leader 进程,则终止所有相关进程。 if (current->leader) kill_session (); // 把当前进程置为僵死状态,并设置退出码。 current->state = TASK_ZOMBIE; current->exit_code = code; // 通知父进程,也即向父进程发送信号SIGCHLD -- 子进程将停止或终止。 tell_father (current->father); schedule (); // 重新调度进程的运行。 return (-1); /* just to suppress warnings */ }
inline object_info_ptr create_rocket_flare(kernel::system* csys, create_msg const& msg) { decart_position dpos(msg.pos,msg.orien); geo_position gp(dpos, get_base()); rocket_flare::settings_t vs; return rocket_flare::create(dynamic_cast<objects_factory*>(csys),vs,gp); }
QString isa_65c816::label_op(int offset, int size, V validator) { QByteArray little_endian = QByteArray::fromHex(QByteArray(to_hex(offset, size).toLatin1())); int address = buffer->snes_to_pc((buffer->*validator)(delta * 2 + get_base(), little_endian)); if(!in_range(address)){ return '$' + to_hex(offset, size); } return add_label(address); }
void test_typeid(Base &base) { (void)typeid(get_base(base)); #if __cplusplus <= 199711L // expected-warning@-2 {{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} #else // expected-warning@-4 {{cannot pass object of non-trivial type 'Base' through variadic function; call will abort at runtime}} #endif // expected-warning@-6 {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} (void)typeid(eat_base(base)); // okay }
const char* env_get_dir() { if (!base) get_base(); if (mkdir(base, 0700) < 0 && errno != EEXIST) { fatal("Unable to create '%s': %s\n", base, strerror(errno)); } return base; }
int *creat_matrice(int ac, char **av, int dim, int base) { int i; int *matrice; matrice = malloc(dim * sizeof(int)); i = -1; while ((++i + ac) < ((ac + dim))) matrice[i] = atoi(convert_base(av[ac + i], get_base(base), "0123456789")); return (matrice); }
static void collect_child(struct da *da, struct resolve_stat *rs, int parent, unsigned char c) { int i; int base = get_base(da, parent); rs->nr = 0; ensure_array(da, base + 256); for (i = 0; i < 256; i++) { int idx = parent + base + i; if (i == c) { push_child(rs, c, 1); } else if (get_check(da, idx) == parent) { /* escape */ /*printf("idx=%d,base=%d, parent=%d,i=%d\n", idx, base, parent, i);*/ push_child(rs, i, get_base(da, idx)); /* clear */ set_base(da, idx, 0); set_check(da, idx, 0); } } }
static struct chunk* find_chunk(size_t size) { struct chunk *prev = NULL; struct chunk *premier = get_base(); while(premier != NULL && (premier->size < size || premier->free == 0)) { prev = premier; premier = premier->next; } return prev; }
int my_atoi(char *str) { char *base; int ibase; if (match("0", str)) return (0); base = my_strdup("0123456789abcdefghijklmnopqrstuvwxyz"); ibase = get_base(&str); base[ibase] = '\0'; ibase = my_getnbr_base(str, base); xfree(base); return (ibase); }
int system_run_image_copy(enum system_image_copy_t copy) { uintptr_t base; uintptr_t init_addr; /* If system is already running the requested image, done */ if (system_get_image_copy() == copy) return EC_SUCCESS; if (system_is_locked()) { /* System is locked, so disallow jumping between images unless * this is the initial jump from RO to RW code. */ /* Must currently be running the RO image */ if (system_get_image_copy() != SYSTEM_IMAGE_RO) return EC_ERROR_ACCESS_DENIED; /* Target image must be RW image */ if (copy != SYSTEM_IMAGE_RW) return EC_ERROR_ACCESS_DENIED; /* Jumping must still be enabled */ if (disable_jump) return EC_ERROR_ACCESS_DENIED; } /* Load the appropriate reset vector */ base = get_base(copy); if (base == 0xffffffff) return EC_ERROR_INVAL; /* TODO: (ML) jump to little FW for code ram architecture */ #ifdef CONFIG_CODERAM_ARCH init_addr = system_get_lfw_address(base); #else /* Make sure the reset vector is inside the destination image */ init_addr = *(uintptr_t *)(base + 4); #ifndef EMU_BUILD if (init_addr < base || init_addr >= base + get_size(copy)) return EC_ERROR_UNKNOWN; #endif #endif CPRINTS("Jumping to image %s", system_image_copy_t_to_string(copy)); jump_to_image(init_addr); /* Should never get here */ return EC_ERROR_UNKNOWN; }
static R call(void* s, Args... args) { std::cout << "trap:" << typeid(t).name() << std::endl; try { return (get_base(s)->*t)(std::forward<Args>(args)...); } catch (...) { std::cout << "CAUGHT" << std::endl; return std::is_integral<R>::value ? static_cast<R>(-42) : static_cast<R>(-3.14); } }
double solve_child_row(CONSTRAINT *row,int sol) { int i,rmatbeg,cont; double lb,rhs; int *rmatind; double *rmatval; char sense; cont = row->card; rhs = row->rhs; sense = row->sense; rmatbeg = 0; rmatind = (int *)malloc( cont * sizeof(int) ); if( rmatind==NULL ){ std::cout << " ERROR: not enough memory for branch-constraint" << std::endl; CSPexit(EXIT_MEMO); //exit(1); } for(i=0;i<cont;i++) rmatind[i] = row->stack[i]->lp; rmatval = (double *)malloc( cont * sizeof(double) ); if( rmatval==NULL ){ std::cout << " ERROR: not enough memory for branch-constraint" << std::endl; CSPexit(EXIT_MEMO); //exit(1); } for(i=0;i<cont;i++) rmatval[i] = 1.0; if (JJaddrows(lp,0,1,cont,&rhs,&sense, &rmatbeg,rmatind,rmatval,NULL,NULL) ) { std::cout << " ERROR: it was not possible to add branch constraint" << std::endl; CSPexit(EXIT_LPSOLVER); //exit(1); } free( (void *)rmatval ); rmatval = NULL; /*PWOF*/ free( (void *)rmatind ); rmatind = NULL; /*PWOF*/ pricing_util = 0; lb = solve_lp(0); if( sol ) { get_solution(); get_base(); } integer_solution(); if( JJdelrows(lp,mar,mar) ){ std::cout << " ERROR: it was not possible to delete branch constraint" << std::endl; CSPexit(EXIT_LPSOLVER); //exit(1); } return(lb); }
void da_dump(struct da *da) { int i; printf("da dump size=%d\n", da->size); for (i = 0; i < da->size; i++) { if (get_check(da, i)) { printf("%d: base=%d,check=%d\n", i, get_base(da, i), get_check(da, i)); } } printf("da dump done\n"); }
void Flyer::draw() { glUseProgram(program); // Send in additional params glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, get_projection()); glUniformMatrix4fv(glGetUniformLocation(program, "baseMatrix"), 1, GL_FALSE, get_base().data()); float t = glutGet(GLUT_ELAPSED_TIME)/500.0; glUniform1f(glGetUniformLocation(program, "t"), t); DrawModel(object); }
int sys_munmap(unsigned long addr, size_t len) { unsigned long base, limit; base = get_base(current->ldt[2]); /* map into ds */ limit = get_limit(0x17); /* ds limit */ if ((addr & 0xfff) || addr > 0x7fffffff || addr == 0 || addr + len > limit) return -EINVAL; if (unmap_page_range(base + addr, len)) return -EAGAIN; /* should never happen */ return 0; }
int main(void) { unsigned num, i, count = 0; unsigned short digit, base; for (i = 1; i <= 1000; i++) { base = get_base(i); num = i; //count = 0; // debug while (num) { if (num < 10 || num > 19) { digit = num / base; //std::cout << "Digit: " << digit << ", num = " << num << ", base = " << base << std::endl; count += get_letter_count(digit, base); num %= base; } else { // special case switch (num) { case 10: count += 3; // ten break; case 11: case 12: count += 6; break; case 15: case 16: count += 7; break; case 13: case 14: case 18: case 19: count += 8; break; case 17: count += 9; } break; } base /= 10; } if (i > 100 && i < 1000 && i % 100) count += 3; // 'and' } std::cout << count << std::endl; return 0; }