Skip to main content
Pranav Ram Joshi
Software Engineer — Systems & Networks
View all authors

Mach, Signal, and Threads

· 42 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

Man is born free, and everywhere he is in chains. - Jean-Jacques Rousseau; The Social Contract

Search for the truth is the noblest occupation of man; its publication is a duty. - Anne Louise Germaine de Staël; De l'Allemagne

Preamble

An operating system is a set of system software that acts as a bridge between the application software and the underlying hardware. Among the various software packaged with an operating system consists of kernel; a program which is responsible for communicating with the hardware and operating the system in its entirety. The purpose of this blog is to explore XNU implementation, understand execution primitives of Mach, and try to understand how event-driven programming takes place.

OSX API_AVAILABLE Macro

· 5 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

There are various way one could use the preprocessing macros. Learning how to properly use them will end up in some bizarre codebases. If you have ever encountered the <os/availability.h> header file on macOS, you'll find some macros that are confusing to interpret. I stumbled upon such macro that I'd like to discuss.

The macro is defined as follows:

(extended) Berkeley Packet Filter

· 31 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

Be conservative in what you do, be liberal in what you accept from others. - RFC 793

Preamble

Throughout the course of humanity, we have witnessed various forms of communication. We use language to communicate on a daily basis. Writing letters is also a form of communication, albeit a form which has slow transmission and reception time. Then came the era of telecommunication. Through the use of electronic and electrical means, we soon came to the realization that communication can be instantaneous. This, I believe, is one of the greatest achievement for mankind. This really made the world feel like a small village. The Internet is the closest to the anywhere door we know from Doraemon.

Terminal, Shell, and Portability

· 63 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

Preamble

A shell process is a program under execution that allows the user to interact with the system. When you open a terminal, you are greeted with a prompt and expects a user input. Before we even begin exploring shell in brief and talking about some portability factors, we need to understand the device that runs the shell process: the terminal. We'll slowly move into topics such as terminal line discipline, character device, shell process, and things to consider when writing portable programs.

Static Analysis

· 9 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

Introduction

Memory is a cruical topic when it comes to building a software. Programs running on historical devices referenced physical memory location which is superseded by a separate new component: Memory Management Unit (MMU). We now work with virtual memory addresses that is managed by MMU for us[0].

I recently stumbled across a video regarding the RustTM language. The intent of this post is not to look down on the RustTM language but to observe a behaviour of a trivial C program. A program fragment was shown in the video, similar to the one shown in Listing 1. After building the executable, we can notice that the program exits normally. But before that, we tried to access a region of memory that was "freed". In contrast, RustTM informs this issue during compilation.

Memory

· 35 min read
Pranav Ram Joshi
Software Engineer — Systems & Networks

Before we even step into the world of (virtual) memory, let's first learn of some tools which might come in handy when dealing with source programs (we'll describe them in lengths later):

  1. Object File Inspection. This can be done through various tools such as otool, objdump, and llvm-objdump.
  2. Debugger. Tools such as gdb and lldb can be helpful when inspecting how the program executes.
  3. Virtual Memory Information. Sometimes, we need to see how a process has arranged its virtual memory space. Tools such as vmmap, leaks, and pmap (also potentially strace) can be used for this purpose.

Other tools can come handy frequently as well. For instance, if we want to list the "files" currently owned by the process, lsof provides useful information.