{"id":16670344,"url":"https://github.com/ldilley/bsdmod","last_synced_at":"2026-03-10T10:32:22.346Z","repository":{"id":73152059,"uuid":"163370782","full_name":"ldilley/bsdmod","owner":"ldilley","description":":smiling_imp: Various demonstrational FreeBSD kernel modules","archived":false,"fork":false,"pushed_at":"2019-01-09T06:57:39.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-30T02:48:55.377Z","etag":null,"topics":["bsd","c","example","example-code","freebsd","freebsd-kernel","freebsd-kld","operating-system","tutorial","tutorial-code"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ldilley.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}},"created_at":"2018-12-28T05:43:27.000Z","updated_at":"2023-02-26T13:09:16.000Z","dependencies_parsed_at":"2023-05-29T14:15:29.737Z","dependency_job_id":null,"html_url":"https://github.com/ldilley/bsdmod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ldilley/bsdmod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldilley%2Fbsdmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldilley%2Fbsdmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldilley%2Fbsdmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldilley%2Fbsdmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ldilley","download_url":"https://codeload.github.com/ldilley/bsdmod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldilley%2Fbsdmod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30330582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bsd","c","example","example-code","freebsd","freebsd-kernel","freebsd-kld","operating-system","tutorial","tutorial-code"],"created_at":"2024-10-12T11:38:11.006Z","updated_at":"2026-03-10T10:32:22.318Z","avatar_url":"https://github.com/ldilley.png","language":"C","readme":"# BSDMod\nThis repo contains a variety of FreeBSD kernel modules that are for educational purposes.\n\nSee the equivalent Linux kernel module project: [LinMod](https://github.com/ldilley/linmod)\n\nThese modules demonstrate:\n\n* How device I/O works\n* How to work with sysctl keys and values\n* How to load, unload, and display loaded modules\n* How to view information on a module\n* How to build FreeBSD kernel modules\n* Module interdependence\n* Logging to dmesg\n\n### Instructions\n1. Issue `make` at the top level to build everything or in an individual directory to only build that component.\n2. To load a module: `kldload -v ./\u003cmodule_name\u003e.ko`\n3. To view loaded modules: `kldstat -v`\n4. To view module output after loading: `dmesg`\n5. To unload a module: `kldunload -v \u003cmodule_name\u003e`\n6. To view module output after unloading: `dmesg`\n\n### Examples\n##### Device\n```\nroot@fbsdev:/usr/local/devel/bsdmod_dev # kldload -v ./bsdmod_dev.ko\nLoaded ./bsdmod_dev.ko, id=5\nroot@fbsdev:/usr/local/devel/bsdmod_dev # ls -la /dev/bsdmod\ncrw-r--r--  1 root  wheel  0x65 Jan  9 01:50 /dev/bsdmod\nroot@fbsdev:/usr/local/devel/bsdmod_dev # echo \"foo bar baz\" \u003e /dev/bsdmod\nroot@fbsdev:/usr/local/devel/bsdmod_dev # cat /dev/bsdmod\nfoo bar baz\nroot@fbsdev:/usr/local/devel/bsdmod_dev # echo \"foo\" \u003e\u003e /dev/bsdmod\nroot@fbsdev:/usr/local/devel/bsdmod_dev # cat /dev/bsdmod\nfoo\nroot@fbsdev:/usr/local/devel/bsdmod_dev # kldunload -v bsdmod_dev\nUnloading bsdmod_dev.ko, id=5\nroot@fbsdev:/usr/local/devel/bsdmod_dev # cat /dev/bsdmod\ncat: /dev/bsdmod: No such file or directory\nroot@fbsdev:/usr/local/devel/bsdmod_dev # dmesg | tail -n 18\nbsdmod_dev-\u003ebsdmod_dev_handler(): Device /dev/bsdmod created.\nbsdmod_dev-\u003ebsdmod_dev_handler(): Kernel module loaded.\nbsdmod_dev-\u003edevice_open(): /dev/bsdmod opened.\nbsdmod_dev-\u003edevice_write(): uiomove() of 12 bytes completed.\nbsdmod_dev-\u003edevice_close(): /dev/bsdmod closed.\nbsdmod_dev-\u003edevice_open(): /dev/bsdmod opened.\nbsdmod_dev-\u003edevice_read(): uiomove() of 13 bytes completed.\nbsdmod_dev-\u003edevice_read(): uiomove() of 0 bytes completed.\nbsdmod_dev-\u003edevice_close(): /dev/bsdmod closed.\nbsdmod_dev-\u003edevice_open(): /dev/bsdmod opened.\nbsdmod_dev-\u003edevice_write(): uiomove() of 4 bytes completed.\nbsdmod_dev-\u003edevice_close(): /dev/bsdmod closed.\nbsdmod_dev-\u003edevice_open(): /dev/bsdmod opened.\nbsdmod_dev-\u003edevice_read(): uiomove() of 5 bytes completed.\nbsdmod_dev-\u003edevice_read(): uiomove() of 0 bytes completed.\nbsdmod_dev-\u003edevice_close(): /dev/bsdmod closed.\nbsdmod_dev-\u003ebsdmod_dev_handler(): Device /dev/bsdmod removed.\nbsdmod_dev-\u003ebsdmod_dev_handler(): Kernel module unloaded.\n```\n\n##### Module Dependency\n```\nroot@fbsdev:/usr/local/devel/bsdmod # kldload -v ./bsdmod2.ko\nLoaded ./bsdmod2.ko, id=6\nroot@fbsdev:/usr/local/devel/bsdmod # dmesg | tail -n3\nbsdmod-\u003ebsdmod_handler(): Kernel module loaded.\nbsdmod2-\u003ebsdmod2_handler(): Kernel module loaded.\nbsdmod-\u003ebsdmod_sum(2, 3): 2 + 3 = 5\nroot@fbsdev:/usr/local/devel/bsdmod # kldstat -v | sed -n '/bsdmod2.ko/,//p'\n 6    1 0xffffffff8261c000 41e      bsdmod2.ko (./bsdmod2.ko)\n        Contains modules:\n                Id Name\n                506 bsdmod2\n                505 bsdmod\n```\n\n##### Syscall\n```\nroot@fbsdev:/usr/local/devel/bsdmod_syscall # kldload -v ./bsdmod_syscall.ko\nLoaded ./bsdmod_syscall.ko, id=6\nroot@fbsdev:/usr/local/devel/bsdmod_syscall # cd ../syscall_test/\nroot@fbsdev:/usr/local/devel/syscall_test # ./syscall_test\nsys/bsdmod_syscall system call ID #: 210\nSystem call performed. Check dmesg for output of sys/bsdmod_syscall-\u003etestcall().\nroot@fbsdev:/usr/local/devel/syscall_test # dmesg | tail -n2\nbsdmod_syscall-\u003ebsdmod_syscall_handler(): Kernel module loaded.\nbsdmod_syscall-\u003etestcall() called.\n```\n\n##### Sysctl\n```\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # kldload -v ./bsdmod_sysctl.ko\nLoaded ./bsdmod_sysctl.ko, id=6\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # sysctl -a | grep bsdmod\nbsdmod.test: 0\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # sysctl bsdmod.test=1\nbsdmod.test: 0 -\u003e 1\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # sysctl -a | grep bsdmod\nbsdmod.test: 1\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # kldunload -v bsdmod_sysctl.ko\nUnloading bsdmod_sysctl.ko, id=6\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl # sysctl -a | grep bsdmod\nroot@fbsdev:/usr/local/devel/bsdmod_sysctl #\n```\n\n#### Notes:\n* The `-v` argument in the above instructions is optional and generates verbose output.\n* `make clean` can be used at the top level to remove build data for everything or in an individual directory to only remove build data for that component.\n* `make load` can be used to quickly build and load a particular component module while in its directory.\n* `make unload` can be used to unload a particular component module while in its directory.\n* The FreeBSD kernel source is required to build the modules contained in this project. It can be obtained via (replace with a closer mirror and your FreeBSD version): `svnlite checkout https://svn0.us-east.freebsd.org/base/releng/11.1 /usr/src`\n* FreeBSD 11.1 was used for the development and testing of this project.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldilley%2Fbsdmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fldilley%2Fbsdmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldilley%2Fbsdmod/lists"}