2011-09-20 56 views
-1

我有这个计算linux调用的系统调用的.c文件。这些只是主要功能。还有一些我必须做的事情,比如创建数组。计数系统调用

,然后在一些组件中的另一文件我增加与命令数组:

incl syscall_counts(,%eax,4) 

// This function is called each time the application calls read(). It starts the  process of 
// accumulating data to fill the application buffer. Return a pointer representing the current 
// item. Return NULL if there are no more items. 
// 
static void *counter_seq_start(struct seq_file *s, loff_t *record_number) 
{ 
    if (*record_number > 347) 
    return NULL; 
return (void*)s; 
} 


// This function is called to compute the next record in the sequence given a pointer to the 
// current record (in bookmark). It returns a pointer to the new record (essentially, an updated 
// bookmark) and updates *record_number appropriately. Return NULL if there are no more items. 
// 
static void *counter_seq_next(struct seq_file *s, void *bookmark, loff_t *record_number) 
{ 
    unsigned long *temp_b =(unsigned long*) bookmark; 
    (*temp_b)++; 
    if (*temp_b > 345) 
    return NULL; 
    return (void*)temp_b; 
} 


// This function is called whenever an application buffer is filled (or when start or next 
// returns NULL. It can be used to undo any special preparations done in start (such as 
// deallocating auxillary memory that was allocated in start. In simple cases, you often do not 
// need to do anything in this function. 
// 
static void counter_seq_stop(struct seq_file *s, void *bookmark) 
{ 

} 


    // This function is called after next to actually compute the output. It can use various seq_... 
// printing functions (such as seq_printf) to format the output. It returns 0 if successful or a 
// negative value if it fails. 
// 
static int counter_seq_show(struct seq_file *s, void *bookmark) 
{ 
    loff_t *bpos = (loff_t *) bookmark; 

    seq_printf(s, "value: %Ld\n", *bpos); 

    return 0; 
} 


// Define the only file handling function we need. 
static int counter_open(struct inode *inode, struct file *file) 
{ 
    return seq_open(file, &counter_seq_ops); 
} 

我的输出是很奇怪:

sample code output

任何人有任何想法,问题是?

+0

'^ @'看起来像是在打印一个值为0的字符。不过不知道它为什么这么做。 –

回答

0

你不觉得:

static int counter_seq_show(struct seq_file *s, void *bookmark) { 
    unsigned long *bpos = (unsigned long *) bookmark; 
    seq_printf(s, "value: %Ld\n", *bpos); 
    return 0; 
} 

甚至

static int counter_seq_show(struct seq_file *s, void *bookmark) { 
    seq_printf(s, "value: %lu\n", *((unsigned long *)bpos)); 
    return 0; 
} 

我没有完全理解你的计划,但我看见你施展“书签”两种不同的方式。在一个函数中,您将其设置为'unsigned long *',而其他的'loff_t *'(long int)。理想情况下,他们应该是一样的,但你是否出于某种原因这样做?

HTH