编译错误 - 解析错误和不完整类型

时间:2015-10-05 11:01:45

标签: c gcc struct compilation

我正在使用gcc-3.3.4。我正在做的是伪造一些东西。 当我使用gcc -O0 -g -fomit-frame-pointer -I/usr/src/kernel-headers-2.4.26-1/include sleep.c -o sleep.exe编译文件时 我遇到以下问题:

msync-sleep.c:47: error: parse error before "wait_queue_head_t"
msync-sleep.c:47: warning: no semicolon at end of struct or union
msync-sleep.c:81: error: field `i_sem' has incomplete type
msync-sleep.c:83: error: field `i_zombie' has incomplete type
msync-sleep.c:87: error: parse error before "wait_queue_head_t"
msync-sleep.c:87: warning: no semicolon at end of struct or union
msync-sleep.c:90: error: parse error before '}' token
msync-sleep.c:93: error: parse error before "atomic_t"
msync-sleep.c:93: warning: no semicolon at end of struct or union
msync-sleep.c:96: error: parse error before '}' token
msync-sleep.c:103: error: parse error before "atomic_t"
msync-sleep.c:103: warning: no semicolon at end of struct or union
msync-sleep.c:105: error: parse error before '}' token
msync-sleep.c:149: error: field `fake_dentry' has incomplete type
msync-sleep.c:150: error: field `fake_inode' has incomplete type
msync-sleep.c:151: error: field `fake_mapping' has incomplete type
msync-sleep.c:152: error: field `fake_ops' has incomplete type
msync-sleep.c:153: error: field `dirty_page' has incomplete type

我认为问题来自我的定义部分。这是我的代码的一部分:

#include <stdio.h>      /* fprintf */
#include <stdlib.h>     /* exit */
#include <string.h>     /* memset */
#include <sys/mman.h>       /* mmap */
#include <sys/types.h>      /* pthread types */
#include <sys/stat.h>       /* fchmod */
#include <pthread.h>        /* thread primitives */
#include <fcntl.h>      /* open */
#include <unistd.h>     /* ftruncate */
#include <errno.h>      /* errno */

#include "linux/elf.h"      /* for elf struct defs */

#include "asm-i386/unistd.h"    /* uselib system call */
#include "asm-i386/page.h"      /* PAGE_SIZE */

#define LIB_ADDR   0xaabbccdd   /* memorable random address */
#define LIB_FILE   "sleepylib"
#define UNMAP_FILE "unmapfile"

/* --------------------------------------------------------
   fake struct defs
   -------------------------------------------------------- */
/* all of these only go as far as the last field we need to access */

struct list_head {
  struct list_head      *next;
  struct list_head      *prev;
};

struct wait_queue_head_t {
  volatile unsigned int lock;
  struct list_head      task_list;
};

struct semaphore {
  volatile int          count;
  int                   sleepers;
  wait_queue_head_t     wait;
};

struct rw_semaphore {
  signed long           count;
  volatile unsigned int wait_lock;
  struct list_head      wait_list;
};

struct inode {
  struct list_head      i_hash;
  struct list_head  i_list;
  struct list_head  i_dentry;

  struct list_head  i_dirty_buffers;
  struct list_head  i_dirty_data_buffers;

  unsigned long     i_ino;
  volatile int      i_count;
  unsigned short    i_dev;
  unsigned short    i_mode;
  unsigned short    i_nlink;
  unsigned short    i_uid;
  unsigned short    i_gid;
  unsigned short    i_rdev;
  long long     i_size;
  long          i_atime;
  long          i_mtime;
  long          i_ctime;
  unsigned int      i_blkbits;
  unsigned long     i_blksize;
  unsigned long     i_blocks;
  unsigned long     i_version;
  unsigned short        i_bytes;
  struct semaphore  i_sem;
  struct rw_semaphore   i_alloc_sem;
  struct semaphore  i_zombie;
  void  *i_op;
  void  *i_fop; 
  void  *i_sb;
  wait_queue_head_t i_wait;
  void  *i_flock;
  struct address_space  *i_mapping;
};

struct dentry {
  atomic_t d_count;
  unsigned int d_flags;
  struct inode *d_inode;
};

struct page {
  struct list_head list;        
  struct address_space *mapping;    
  unsigned long index;      
  struct page *next_hash;       
  atomic_t count;           
  unsigned long flags;      
};

struct fakes {
  /* dentry */
  struct dentry fake_dentry;
  struct inode fake_inode;
  struct address_space fake_mapping;
  struct address_space_operations fake_ops;
  struct page dirty_page;
};

感谢您的提前时间。

1 个答案:

答案 0 :(得分:0)

根据this page wait_queue_head_t可能是关键字,因此请尝试将其更改为其他内容。