【问题标题】:Counting system calls计算系统调用
【发布时间】:2011-09-20 01:00:15
【问题描述】:

我有这个 .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);
 }

我的输出很奇怪:

有人知道问题出在哪里吗?

【问题讨论】:

  • ^@ 看起来像是在打印一个值为 0 的字符。不过不知道为什么会这样。

标签: c linux security


【解决方案1】:

你不觉得吗:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2020-09-01
    • 2017-06-30
    • 1970-01-01
    • 2021-05-14
    • 2020-04-03
    相关资源
    最近更新 更多