blog.farhan.codes

Farhan's Personal and Professional Blog


Debugging a running FreeBSD kernel in a VM using kgdb

Using KGDB Remote Debugging for FreeBSD VMs This guide explains how to debug a running FreeBSD kernel in a VM using kgdb. The default ddb debugger has decent functionality, but unless you somehow know dynamic memory addresses, those capabilities are effectively unusable. Conversely, kdb offers a more robust interface and set of features. While there is a handbook section on kgdb, it assumes you are running FreeBSD on bare-metal with a physical serial port connected to another serial host, not on modern virtualized infrastructure.

Read more...

Sarf Generator

I’m making available a Arabic word conjugator tool I wrote in TypeScript. It is located here https://sarf.farhan.codes. Aside from the basics, it takes into account some foundational rules of تعللات (special conjugation of certain letters) There is some stuff its missing, such as repeating letters or edge-cases, but its a good general tool that I use myself when I’m confused. It is also the first project I ever wrote in Typescript.

Read more...

Benchmarking Base32 vs Base64

This is a very rudimentary benchmark of Base32 vs Base64 performance in Golang. This should also serve as an example of Golang’s benchmarking toolchain. Conclusion: Base64 is faster. This code works by creating 1000 test strings, then performing Base32 and Base64 conversions. Timing is done by Go’s built-in benchmarking tooling, which is part of the testing framework. Here is the code: package main import "os" import "time" import "testing" import "math/rand" import "encoding/base32" import "encoding/base64" var strings = []string{} func setupStrings(n int) []string { charset := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" strings := []string{} rand.

Read more...

Let IRC Die

For the sake of progress, let IRC die! IRC was great, but its continued usage is a relic of an older internet, when storage was expensive and servers were expensive. At this stage, communities should migrate off of IRC to slack-like solutions like Mattermost or Matrix. IRC served as a workhorse for communication, but it has failed to adapt to modern demands. In particular: Offline sending and retrieval Referenceable conversations (ie, URLs to a conversation) Editing messages Formatted text (including media) True decentralization Many of these problems can be remediated at the client-level, but not without a cost.

Read more...

Simple dtrace use-case

Very small example of using dtrace, mostly for me to refernece in the future. As I port this wifi card, I am running into a situation where ifconfig is reporting an error that I do not understand. From previous reading, I know that ifconfig interfaces with the kernel through ioctl. Driver code initially handles ioctl requests by implementing the ic->ic_ioctl handler. To that end, in my handler I printed the u_long cmd variable with the intention of looking up the value.

Read more...

My FreeBSD Development Environment

I’m writing this primarily for myself, but also for others to reference and improve upon. I run FreeBSD CURRENT in a VM. I use a VM for the inevitable situation where it crashes. I prefer to use Qemu on KVM, almost exclusively because of the ease of using the graphical virt-manager over ssh, and the ease of rebooting. FreeBSD cannot do crash dumps to VT disks (vtdb0) so I make sure the Disk type is SATA.

Read more...

Rebuilt This Blog

I rebuilt this blog after a few months of having it down. Long story short, I ran the blog off of WordPress and self-hosted on my personal server for years. When I moved into a house and migrated off my personal server, I somehow lost the wp_content.sql file, and only that file, somewhere in the mix. An accidental deletion? Who knows. So all posts died. Bummer. Fortunately, I was able to rebuild the content from Wayback Machine (seriously) and Google Cache (yeah, seriously).

Read more...

Unexpected IPv6 Behavior on Linux

Linux has some strange default IPv6 behavior. Here are a few things I noticed… You can bind to a port on an IPv4 address while all of your tools will report that the port is on IPv6. For example, if your host is 198.51.100.1, you can bind to ::FFFF:198.51.100.1 and all state-checking tools like netstat, ss or lsof will report the listener as on an IPv6-port. You can do this in netcat with nc -6 -l ::FFFF:192.

Read more...

Capturing Input/Output of Another Process in C

In my travels in C programming, I periodically need to run another process and redirect its standard output back to the first process. While it is straight forward to perform, it is not always obvious. This article will explain the process of how this is done in three sections. High Level Overview Explanation of each line Code Sample High Level Overview Create a three pipe(2)s for standard input, output and error fork(2) the process The child process runs dup2(2) to over the pipes to redirect the new processes’s standard input, output and error to the pipe.

Read more...

Avoiding Redundancy with Function Pointers

I am currently writing OpenGit, a BSD-licensed re-implementation of Linus Torvald’s Git (lower-cased going forward). This frequently involves reviewing git’s source code to understand how it works under the hood. One of the things I consistently encounter is git performing similar and sizable tasks in multiple different ways and places, resulting in redundancy and a higher maintenance cost. In this brief entry, I will discuss a classic problem and how I solve it: When minor variants of a routine result in multiple implementations.

Read more...
1 of 4 Next Page