0

I'm trying to create a "mailbox" system call where processes can send messages to each other. I wanted to use some sort of shared memory so I can refer to a "mailbox" by its ID, but I can't call system calls from another system call right? Is there another way where I can "refer" to a particular "mailbox" by its ID? I was thinking of just using kmalloc and creating an array of structs. Not looking for code, just general pointers as to how I should do this. Thank you!

EDIT: Don't think I clarified but the mailboxes have to be in kernel space

somtingwong
  • 361
  • 1
  • 6
  • 19

1 Answers1

1

You certainly can't call kmalloc from userspace.

What you're looking for is actually called POSIX "shared memory".

In general, you call shm_open to open a shared memory object. Then you mmap it, so you can access it via a pointer, just like normal memory.

See also:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Sorry I forgot to mention that the "mailboxes" have to be in kernel space – somtingwong May 01 '14 at 22:31
  • @user1813076 I don't really understand what you're trying to accomplish, that you can't with features that already exist. You have lots of IPC mechanisms at your disposal: UNIX sockets (including file-based), pipes, shared memory. What features do these mailboxes possess that aren't satisfied by those means? Note that the actual memory where a UNIX socket's buffers live is in kernel space. – Jonathon Reinhart May 01 '14 at 23:33
  • It's just for a project in my operating systems class. We have to create something similar to shared memory segments – somtingwong May 01 '14 at 23:56
  • So you're planning on modifying the Linux kernel? I think adding a system call to create or use these mailboxes would make sense then. – Jonathon Reinhart May 02 '14 at 02:29