All of lore.kernel.org
 help / color / mirror / Atom feed
* Enabling message queue in 2.6.10 kernel
@ 2006-07-07 10:03 Chinmaya Mishra
  2006-07-07 10:08 ` Arjan van de Ven
  0 siblings, 1 reply; 2+ messages in thread
From: Chinmaya Mishra @ 2006-07-07 10:03 UTC (permalink / raw)
  To: Linux Kernel

Hi All,
I am trying for message queue in linux-2.6.10 kernel.
I export sys_msgget(), sys_msgctl(), sys_msgsnd() and sys_msgrcv() in
the kernel with following EXPORT_SYMBOL(sys_msgget) and so on.
Then compile the kernel, boot with the new image.

My code is like this.
#include <linux/module.h>
#include <linux/kernel.h>

#include <linux/types.h>
#include <linux/ipc.h>
#include <linux/msg.h>
#include <linux/syscalls.h>

#include <asm/system.h>

int msqid, ret;
/* this is the thread function that we are executing */
void mymsgSend(void)
{
        struct msgbuf sbuf;
        printk("Start send message \n");
        memset(&sbuf, '\0', sizeof(sbuf));
        if((msqid = sys_msgget((key_t)1234, 0666 | IPC_CREAT )) < 0) {
                printk("Err: sys_msgget \n");
                return ;
        }
        sbuf.mtype = 1;
        //sprintf(sbuf.mtext,"a");
        ret = sys_msgsnd(msqid, &sbuf, sizeof(sbuf), IPC_NOWAIT);
        printk("Send ret = %d \n", ret);
        if (ret < 0) {
                printk("Err: sys_msgsnd \n");
                return ;
        }
        return ;
}

void mymsgRecv(void)
{
        int msqid;
        struct msgbuf rbuf;
        printk("Start recv message  \n");
        memset(&rbuf, '\0', sizeof(rbuf));
        if ((msqid = sys_msgget((key_t)1234, 0666)) < 0) {
                printk("Err: sys_msgget \n");
                return ;
        }
        rbuf.mtype = 1;
        ret = sys_msgrcv(msqid, (struct msgbuf *)&rbuf, sizeof(rbuf), 
rbuf.mtype, IPC_NOWAIT);
        printk("Recv ret = %d \n", ret);
        if (ret < 0) {
                printk("Err: sys_msgrcv \n");
                return ;
        }
        printk("Mesg Recv = %s \n", rbuf.mtext);
        return;
}

/* load the module */
int init_module(void)
{
              mymsgSend();
              msleep(1000);
              mymsgRecv();
        }
        return(0);
}

/* remove the module */
void cleanup_module(void)
{
        printk("Stop Kernel Thread \n");
        sys_msgctl(msqid, IPC_RMID, NULL);
        return;
}


But the out put messages in # dmesg <enter> is like this

Start send message
Send ret = -14
Err: sys_msgsnd
Start recv message
Recv ret = -42
Err: sys_msgrcv
Stop Kernel Thread

Is there any thing I am missing. Please help soon.


With Regards,
Chinmaya.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Enabling message queue in 2.6.10 kernel
  2006-07-07 10:03 Enabling message queue in 2.6.10 kernel Chinmaya Mishra
@ 2006-07-07 10:08 ` Arjan van de Ven
  0 siblings, 0 replies; 2+ messages in thread
From: Arjan van de Ven @ 2006-07-07 10:08 UTC (permalink / raw)
  To: chinmaya; +Cc: Linux Kernel



> 
> But the out put messages in # dmesg <enter> is like this
> 
> Start send message
> Send ret = -14
> Err: sys_msgsnd
> Start recv message
> Recv ret = -42
> Err: sys_msgrcv
> Stop Kernel Thread
> 
> Is there any thing I am missing. Please help soon.

you're missing that you're calling functions which expect a userspace
pointer, but with a kernel space pointer. You really shouldn't do that,
and in fact it doesn't work the way you did it. (you'd need to call
set_fs() and friends first, but if you're not really careful you open
security holes that way)

Can you explain why you'd want to do this from kernel space in the first
place? It's not unlikely that it's the wrong approach....

Greetings,
   Arjan van de Ven


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-07-07 10:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-07 10:03 Enabling message queue in 2.6.10 kernel Chinmaya Mishra
2006-07-07 10:08 ` Arjan van de Ven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.