{"id":30064929,"url":"https://github.com/bbzaffari/messaging-kernel-module","last_synced_at":"2026-05-18T02:33:24.778Z","repository":{"id":293848228,"uuid":"985304321","full_name":"bbzaffari/Messaging-Kernel-Module","owner":"bbzaffari","description":"This project implements a Messaging character device driver between user-space processes, using circular queues managed in kernel space. Includes a C client for interaction and testing. Built for OS class, exploring driver design, memory safety, and concurrent access handling.","archived":false,"fork":false,"pushed_at":"2025-07-29T21:07:30.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-29T23:49:51.062Z","etag":null,"topics":["buildroot","c","kconfig","kernel","kernel-driver","kernel-module","linux-kernel","qemu","rootfs"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbzaffari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-17T13:36:37.000Z","updated_at":"2025-07-29T21:08:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"d43bd0c4-4eca-47f8-a4ae-2098e3742b97","html_url":"https://github.com/bbzaffari/Messaging-Kernel-Module","commit_stats":null,"previous_names":["bbzaffari/kernel-driver","bbzaffari/messaging-kernel-module"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bbzaffari/Messaging-Kernel-Module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbzaffari%2FMessaging-Kernel-Module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbzaffari%2FMessaging-Kernel-Module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbzaffari%2FMessaging-Kernel-Module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbzaffari%2FMessaging-Kernel-Module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbzaffari","download_url":"https://codeload.github.com/bbzaffari/Messaging-Kernel-Module/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbzaffari%2FMessaging-Kernel-Module/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269367395,"owners_count":24405385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buildroot","c","kconfig","kernel","kernel-driver","kernel-module","linux-kernel","qemu","rootfs"],"created_at":"2025-08-08T05:24:23.977Z","updated_at":"2026-05-18T02:33:24.773Z","avatar_url":"https://github.com/bbzaffari.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Educational Purpose\n\n# Messaging Kernel Module\nThis project implements a character device driver that enables inter-process messaging via the Linux kernel. Using circular queues managed in kernel space.\n\nIt was developed as part of the Operating Systems course (Prof. Sérgio Johann Filho) and cross-compiled with **Buildroot** for use on an embedded Linux environment.\n\n## Overview\n\nThe module exposes a character device `/dev/mq` that allows user-space applications to:\n\n* **Register** and **unregister** a process under a name.\n* **Send messages** to specific registered processes.\n* **Broadcast messages** to all registered processes.\n* **Read messages** from the process's own queue.\n\nA simple C client (`client.c`) is provided to interact with the device and test its behavior.\n\n## How It Works\n\n### Data Structures\n\nIn kernel space, the module maintains:\n\n* A **control block list**, which holds:\n\n  * The process **PID**.\n  * An assigned **name** (up to 8 chars).\n  * A **message queue** (circular buffer).\n  * A spinlock for concurrent access.\n\nEach message queue holds up to `QUEUE_LEN` messages, storing:\n\n* The message **data** (dynamically allocated).\n* The **sender's name**.\n* The message **size**.\n\n### Main Operations\n\n* `/reg \u003cname\u003e`  — Registers the calling process's PID and name.\n* `/unr` — Unregisters the calling PID and cleans up its message queue.\n* `/msg \u003cdest\u003e \u003cmsg\u003e` — Sends a message to the named destination, if registered.\n* `/all \u003cmsg\u003e` — Sends the same message to all other registered processes.\n* `/read` — Reads (and removes) the next message in the calling process's queue.\n\n### Parameters\n\nThe module can be configured at load time with:\n\n* `MAX_DEVICES`: maximum number of registered processes.\n* `QUEUE_LEN`: number of messages per process queue.\n* `CMD_BUF_SIZE`: maximum command size.\n\nExample:\n\n```bash\nmodprobe mq_driver MAX_DEVICES=8 QUEUE_LEN=8 CMD_BUF_SIZE=256\n```\n\n## Notes on Implementation\n\n### Use of PID\n\n**Disclaimer:**  In a more formal or production-grade Linux driver, one would typically associate user-space interactions via file descriptors, file pointers (`struct file`), or inode references to track context.\n\nIn this project, for simplicity and as an educational abstraction, the process PID is used as the unique identifier. This avoids managing file structures and focuses on learning kernel data structures and synchronization.\n\nThis choice makes it easier to reason about process-specific state but limits interactions to one registration per PID and assumes stable PID handling.\n\n### Memory Management\n\n* Memory is dynamically allocated using `kmalloc`/`kfree`.\n* Message queues are properly cleaned up on process unregistration.\n* Circular buffer logic ensures that if a queue overflows, the oldest message is overwritten.\n* Spinlocks protect both the control block list and per-process queues against race conditions.\n\n### Build and Deployment\n\nThe system was cross-compiled using **Buildroot** to generate a minimal Linux environment for testing on embedded hardware.\n\nScripts are included to:\n\n* Build the kernel module.\n* Install and load it (`insmod`/`rmmod`).\n* Compile the client application.\n\n## Repository Structure\n\n```\n.\n├── client.c         # User-space C client for testing\n├── mq_driver.c      # Kernel module source\n├── Makefile         # Build rules\n├── README.md        # This documentation\n└── tp2.pdf         # Project description and assignment details\n```\n\n## How to build it with buildroot\n...  \n## How to run it with QEMU\n... \n\n## Final Remarks\n\nThis project is an educational exercise aimed at deepening understanding of:\n\n* Kernel-space vs user-space boundaries.\n* Character device drivers.\n* Process communication.\n* Memory and concurrency management at kernel level.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbzaffari%2Fmessaging-kernel-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbzaffari%2Fmessaging-kernel-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbzaffari%2Fmessaging-kernel-module/lists"}