LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-20-2007, 10:21 PM   #1
soararing
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Rep: Reputation: 0
porting linux kernel list operation to user space?


Now I have to porting some kernel space code to user space, but these code contains a lot of list operation, so is it possible to porting linux kernel list operation (/kernel src/include/linux/list.h) to user space, i did some test, but failed/

Thanks!
 
Old 11-21-2007, 03:17 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,535

Rep: Reputation: 148Reputation: 148
It should not be a very hard task, as it's mostly macro-based. You will have to remove some kernel-specific stuff, but not that much. What have you tries and what were the errors?
 
Old 11-24-2007, 06:49 AM   #3
soararing
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
I just add code in list.h:
Quote:
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)
#define prefectch(x) 1
#define smp_wmb(x) 1

#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE*)0)->MEMBER)


#define container_of(ptr, type, member)({ \
const typeof(((type*) 0)->member)*__mptr=(ptr); \
(type*)((char*)__mpt-offsetof(type, member));})
my test code is
Quote:
struct kool_list{
int to;
struct list_head list;
};


int print_string_init(void)
{
char ret[256];
struct kool_list *tmp;
struct list_head *pos, *q;
unsigned int i;
unsigned int j = 10;

struct kool_list mylist;
INIT_LIST_HEAD(&mylist.list);
for(i = 5; i!=0; --i){
tmp = (struct kool_list *)malloc(sizeof(struct kool_list));
tmp->to = j;
list_add(&(tmp->list), &(mylist.list));
j--;
}

printf("traversing the list using list_for_each().");

list_for_each(pos, &mylist.list){
tmp = list_entry(pos, struct kool_list, list);
sprintf(ret, "to = %d", tmp->to);
printf(ret);
}


I get compiler error message in line
tmp = list_entry(pos, (struct kool_list), list);

syntex error: '{'
syntex error: ')'
syntex error: ')'
syntex error: missing ':' before ')'
syntex error: missing ')' before string
'__mpt': undeclared identifier
..........

Last edited by soararing; 11-24-2007 at 08:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
notify user space application from the kernel space lordofring Linux - Software 2 06-22-2009 12:32 PM
kernel user space communication mbm Linux - Kernel 1 10-17-2007 08:21 PM
Communication between the Kernel- and User-Space Siva4Linux Linux - Kernel 3 11-30-2006 03:54 PM
How to share data b/w user space and kernel space nandac Linux - Kernel 1 11-28-2006 10:15 PM
User Space - Kernel Space basu_arani Programming 3 05-25-2004 11:46 AM


All times are GMT -5. The time now is 07:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration