Подсчет системных вызовов - PullRequest
0 голосов
/ 20 сентября 2011

У меня есть этот .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 голосов
/ 20 сентября 2011

Ты не думаешь:

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...