static int hello_init(void) { uint64_t a = 1048576; uint32_t b = 4096; void (* func_p)(void); /* unsigned int cpu = get_cpu(); struct module *mod; printk("this module: %p==%p\n", &__this_module, THIS_MODULE ); printk("module state: %d\n", THIS_MODULE->state ); printk("module name: %s\n", THIS_MODULE->name ); list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list ) printk(KERN_ALERT "module name: %s\n", mod->name );*/ func_p = __symbol_get("hello_func"); printk("func_p's addr is %p\n", func_p); if(!func_p){ printk("func can not find!\n"); } else{ __symbol_put("hello_func"); func_p(); printk("symbol exist. p=%p\n", func_p); } printk("a/b = %u.\n", a/b); return 0; }
void st_foreach(struct stack *stp, void (*func_p) (struct st_node *np)) { struct st_node *np; assert((stp != NULL) && (func_p != NULL) && !st_empty(stp)); np = stp->top; while (np != NULL) { func_p(np); np = np->next; } }
void sxc_debug(FILE *fp) //调试主监听程序 { char input[100],var[100]; char cmd; int para = 0; int i = 0; de_flag = 0; para = 0; while (1) { gets(input); if (strcmp(input, "\0") != 0) break; } cmd = input[0]; switch (cmd) { case 'h': runcode = 0; show_help(); break; case 'b': runcode = 0; if (input[1] != ' ') show_help(); else { i = 2; while (input[i] != '\n' && input[i++] != '\0') { if (input[i - 1] >= 48 && input[i - 1] <= 57) { para = para*10+(input[i - 1] - '0'); } else { show_help(); break; } } if (de_flag == 0) { func_b(para,0); } } break; case 'n': runcode = 1; if (input[1] != '\0') show_help(); else func_n(fp); break; case 'r': runcode = 1; if (input[1] != '\0') show_help(); else sxc(fp); break; case 'p': runcode = 0; if (input[1] != ' ' && input[1] != '\n' && input[1] != '\0') show_help(); else if (input[1] == '\0') func_p("-a"); else func_p(input + 2); break; case 'l': runcode = 0; if (input[1] != ' ' && input[1] != '\n' && input[1] != '\0') show_help(); else if (input[1] == '\0') func_l(fp, -1); else { i = 2; while (input[i] != '\n' && input[i++] != '\0') { if (input[i - 1] >= 48 && input[i - 1] <= 57) { para = para * 10 + (input[i - 1] - '0'); } else { show_help(); break; } } if (de_flag == 0) { func_l(fp, para); } } break; case 'd': runcode = 0; if (input[1] != ' ') show_help(); else { i = 2; while (input[i] != '\n' && input[i++] != '\0') { if (input[i - 1] >= 48 && input[i - 1] <= 57) { para = para * 10 + (input[i - 1] - '0'); } else { show_help(); break; } } if (de_flag == 0) { func_d(para,0); } } break; case 's': runcode = 0; if (input[1] != '\0') show_help(); else func_s(); break; case 'k':if (input[1] != '\0') show_help(); else func_k(); break; case 'q':if (input[1] != '\0') show_help(); else func_q(fp); break; default:show_help(); break; } }
test (void (*func_p) (void)) { func_p (); }
void foo (void) { if (func_p != &func || func_p () != 0xbadbeef) __builtin_abort (); }
void call_func(void (*func_p)(void)) { func_p(); }