inux上安装vmware,启动时提示异常
提示查看日志文件
/tmp/vmware-root/vmware-19482.log
发现是编译vmnet.o模块时出错,错误信息如下

/tmp/modconfig-4UP6CG/vmnet-only/userif.c:117:43: error: passing argument 5 of ‘get_user_pages’ from incompatible pointer type [-Werror=incompatible-pointer-types]
retval = get_user_pages(addr, 1, 1, 0, &page, NULL);
^
In file included from /usr/src/linux-headers-4.9.0-deepin4-common/include/linux/highmem.h:7:0,
from /tmp/modconfig-4UP6CG/vmnet-only/userif.c:26:

查看userif.c文件
发现错误位置代码如下

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
retval = get_user_pages(addr, 1, 1, 0, &page, NULL);
#else
retval = get_user_pages(current, current->mm, addr,
1, 1, 0, &page, NULL);

/usr/src/linux-headers-4.9.0-deepin4-common/include/linux/mm.h
中找到get_user_pages的定义

long get_user_pages(unsigned long start, unsigned long nr_pages,
unsigned int gup_flags, struct page **pages,
struct vm_area_struct **vmas);

参数个数果然和userif.c里面的不一致
难道是linux内核修改了?
根据userif.c里语法的意思,下载了4.6的头文件查看mm.h
发现其定义如下

long get_user_pages(unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages,
struct vm_area_struct **vmas);

果然是改了函数定义

上github看了下变更信息,发现是在4.9中将write与force合并成一个参数了
增加了宏
#define FOLL_WRITE 0x01
#define FOLL_FORCE 0x10
来用与运算得到这两个参数
所以修改userif.c中的相关语句为
 

#if   LINUX_VERSION_CODE>= KERNEL_VERSION(4, 9, 0)
   retval = get_user_pages(addr, 1, 1, &page, NULL);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
   retval = get_user_pages(addr, 1, 1, 0, &page, NULL);
#else
   retval = get_user_pages(current, current->mm, addr,
                           1, 1, 0, &page, NULL);
#endif

再次编译后执行vmware

成功执行!

posted on 2017-05-11 22:23  mmseh  阅读(598)  评论(0编辑  收藏  举报