Skip to content

Implement shared memory (POSIX shm) for GUI #401

@pbalduino

Description

@pbalduino

Summary

Implement POSIX shared memory (shm_open, shm_unlink, mmap) to enable zero-copy window buffer sharing between GUI clients and the compositor.

Background

The compositor needs to access client window buffers without copying. Shared memory allows clients to render into a shared buffer that the compositor can directly composite to the screen.

Goals

  • Implement `shm_open()`, `shm_unlink()`
  • Extend `mmap()` to support MAP_SHARED
  • Implement shared memory object management in kernel
  • Support multiple processes mapping same memory

Implementation

Syscalls

```c
// Create/open shared memory object
int shm_open(const char *name, int oflag, mode_t mode);
int shm_unlink(const char *name);

// Map shared memory (extend existing mmap)
void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
// flags includes MAP_SHARED
```

Usage Example

```c
// Client creates window buffer
int fd = shm_open("/window_123", O_CREAT|O_RDWR, 0600);
ftruncate(fd, width * height * 4);
uint32_t pixels = mmap(NULL, widthheight*4,
PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);

// Client renders to pixels
// Compositor maps same fd and composites

// Cleanup
munmap(pixels, widthheight4);
close(fd);
shm_unlink("/window_123");
```

Timeline

Total: 2-3 weeks

Definition of Done

  • shm_open/shm_unlink implemented
  • MAP_SHARED works in mmap
  • Multiple processes can map same memory
  • Changes visible across processes
  • Memory cleanup on process exit
  • Test suite passes

Dependencies

Enables

  • Compositor (critical for window buffers)

See docs/road/road_to_gui.md for complete roadmap.

Metadata

Metadata

Assignees

Labels

GUIGraphical user interface componentsenhancementNew feature or requestkernelKernel-level implementation

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions