static void init_BPF_PROG_LOAD_attr4(struct bpf_attr_check *check) { struct BPF_PROG_LOAD_struct *attr = &check->data.BPF_PROG_LOAD_data; attr->insns = (uintptr_t) insns; attr->license = (uintptr_t) license; attr->log_buf = (uintptr_t) get_log_buf(); attr->prog_ifindex = ifindex_lo(); strncpy(log_buf, "log test", 9); }
static inline char * get_log_buf_tail(void) { return get_log_buf() + log_buf_size; }
////输出到控制台窗口的调试日志 void debug(const char *fmt, ...) { if(!log_ready) return; va_list arg = (va_list)((char *)(&fmt) + 4); /* 同步log */ if(!is_async_log){ char buf[512]; int len = vsprintf(buf,fmt,arg); buf[len++] = '\n'; buf[len++] = 0; int wait_count = 100000; while(debug_running && wait_count--){ //print_on_screen3("other debug is running"); //nothing } if(wait_count == 0){ panic("debug wait timeout: %s",buf); } debug_running = 1; cons_putstr0(log_win->task->cons,buf); debug_running = 0; return; } //return; static int invoke = 0; /* 为了检测debug是否已经被嵌套调用了 */ invoke++; /* 申请日志的缓冲 */ cli(); char * buf=get_log_buf(log_buf_mgr); sti(); if(buf == NULL){ print_on_screen3("no log buf"); invoke--; return; } int len = vsprintf(buf,fmt,arg); buf[len++] = '\n'; buf[len++] = 0; if(strlen(buf) + 2 > LOG_ENTRY_SIZE){ panic("log is too log: %s", buf); } if(invoke > 10){ panic("debug may invoke recursively: %s",buf); } if(is_async_log){ if(log_win != 0){ io_cli(); //print_on_screen3("utls: add log process[%d,%s]",log_fifo_buffer->task->pid,log_fifo_buffer->task->name); int retval = fifo32_put(log_fifo_buffer,(int)buf); if(retval == -1){ /* fifo已满 */ //释放日志缓冲 put_log_buf(log_buf_mgr,buf); } io_sti(); }else{ /* 释放日志缓冲 */ io_cli(); put_log_buf(log_buf_mgr,buf); io_sti(); } } invoke--; return; }