计算系统调用

时间:2011-09-20 01:00:15

标签: c linux security

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

unsigned long syscall_counts [345];

然后在另一个带有一些程序集的文件中,我用命令增加了数组:

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

任何人都知道问题出在哪里?

1 个答案:

答案 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