Code Monkey home page Code Monkey logo

freebsd-lab's Introduction

Hello FreeBSD

Build the documentation

You don’t need to depend on GitHub.

For a quick and dirty build, install Asciidoctor however you like and build: pkg install asciidoc xdg-utils

make doc

install gnome

Google it!

Move to bash shell

pkg install bash
chsh -s /usr/local/bin/bash root
#logout
echo $SHELL

compile the kernel

# download the kernel
sudo svn co --trust-server-cert --non-interactive https://svn0.us-east.freebsd.org/base/stable/11/ /usr/src
# first take backup
cp -Rp /boot/kernel/ /boot/kernel.backup
# determine ur arch
uname -a
# in my case amd64
cd /usr/src/sys/amd64/conf/
# copy kenel .config
cp GENERIC NEWKERNEL
# compile!
cd /usr/src
make buildkernel KERNCONF=NEWKERNEL
# install!
make installkernel KERNCONF=NEWKERNEL

Hello world userland example

make c
.userland/hello

Kernel command!

Google: freebsd kernel module hello world

kldstat
make
make load
make unload
make clean

hello LKM

How to use it:

$cd hello
$make
$kldload ./hello.ko
$kldunload ./hello.ko

syscall LKM

How to add your own custom syscall to FreeBSD then use it from userland

$cd syscall
$make
$kldload module/syscall.ko
$./test/call
$dmesg
$kldunload module/syscall.ko

cdev LKM

Simple char dev, Reference: /usr/share/examples/kld/cdev

echo LKM

Another simple char dev, because "cdev LKM" not working now, and this works smoothly. [Reference]

Side note #1

  • /usr/src/sys/ the best reference and learning tool for a newbie FreeBSD kernel hacker

Side note #2: Debugging

mkdir hook

$cd mkdir_hook/
$make
$mkdir anything

keylogger

$cd keystroke_hook
$make
$kldload ./read_hook.ko
$dmesg

Kernel Queue Data Structures

All lists related macros here: #include <sys/queue.h>, see queue(3)


Synchronization Issues

<sys/lock.h>, <sys/mutex.h>, see mutex(9)


<sys/sx.h>, see sx(9)


proc Structure

<sys/proc.h>

ps -aux Module

Linux kernel modules act almost like $(ps aux) command.


CodeStyle

FreeBSD codestyle: `style(9) and style.Makefile(5)

The FreeBSD regression testing tools

src/tools/regression `src/tools/

Google: Micro Benchmark Checklist for FreeBSD

Chapter 8. Configuring your FreeBSD custom Kernel - FreeBSD handbook

  • 1. This chapter contains all the steps in detail. Please don’t abbreviate it.

  • 2. Don’t make that in gnome, use ttys, Please -- my laptop always sleep with gnome (I don’t mean 'that', sorry) --

  • 3. Ch 9. Building and Installing a FreeBSD Kernel - developers-handbook is complementary.

Chapter 10. Kernel Debugging - developers-handbook


Places

  • All Kernel modules exist in /boot/kernel

  • $dmesg content at boot-time === /var/run/dmesg.boot

  • Another tool for finding hardware is pciconf(8), which provides more verbose output. pciconf -lv

  • FreeBSD source code /usr/src/sys, If this place not exist, Google: get freebsd source code /usr/src/sys, that’s easy. sounds like git clone, but using svn.. I don’t try to make this page a refernce .. so google it…​

  • /var/log/messages records the kernel messages from every successful boot. While, dmesg(8) will print the kernel messages from the current boot.

  • /boot/kernel/kernel.old location of old kernel - last successful & bootable kernel :)

  • /etc configuration files

SEE ALSO

KLD(4), copyin(9), kldstat(8), ktrace(1), kdum(1),
All $man 9
#include <sys/types.h>,
#include <sys/systm.h>,
#include <sys/conf.h>,
#include <sys/protosw.h>,
FreeBSD doc: Committer's Guide

freebsd-lab's People

Contributors

smalinux avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.