开发者

Compiling a program for user mode Linux

开发者 https://www.devze.com 2023-02-01 10:19 出处:网络
I\'ve just implemented a \"pseudo\" device driver and want to test it. What can I do as a test is just:

I've just implemented a "pseudo" device driver and want to test it. What can I do as a test is just:

echo "somet开发者_如何学Pythonhing"> /dev/mydev
cat /dev/mydev

My driver supports more advanced functionality and I implemented a test program to test these functionaries. However I'm not able to run it on UML (Error: Floating point exception). I believe there is a "special" way of compiling user programs for UML?

Could you please give a starting point for this? How should I compile the test program?

p.s. Testing program is very simple and above error is not caused by the bug in the program. p.p.s. For compiling the module I had ready Makefile, so it was easy :)

Thanks in advance.

EDIT: Both host and UML kernels are of same version 2.6.35

EDIT: I believe I need to show kernel source directory, plus some compiler options, also something like ARCH=um?

EDIT: Currently I'm compiling without any options. gcc test.c. Even the "Hello world" program is not working on the UML. Maybe i've to change something on UML compilation?


The solution for the problem is found (thanks to my classmates and professor):

the glibc versions of the compile environment should match with UML. So compiling --static option solves the problem.


If you want to read/write from/to your device, you have to implement, and then use on your program, at least the system calls open(), read(), write() and close(), like any other device on you Linux. For the example you gave, your program would be something like this (syntax might contain some errors):

char* string = "something";
char* result = (char*)malloc(sizeof(char) * strlen(string) + 1);

int fd = open("/dev/mydev", O_RDWR);

write(fd, "something", strlen(string));

read(fd, result, strlen(string));
printf("result = %s\n", result);

close(fd);
0

精彩评论

暂无评论...
验证码 换一张
取 消