Skip to content

Instantly share code, notes, and snippets.

View ClarkThan's full-sized avatar
💤

Clark Than ClarkThan

💤
View GitHub Profile
@ClarkThan
ClarkThan / Stack.md
Created September 19, 2024 11:00 — forked from cpq/Stack.md
Why stack grows down

Why stack grows down

Any running process has several memory regions: code, read-only data, read-write data, et cetera. Some regions, such as code and read-only data, are static and do not change over time. Other regions are dynamic: they can expand and shrink. Usually there are two such regions: dynamic read-write data region, called heap, and a region called stack. Heap holds dynamic memory allocations, and stack is mostly used for keeping function frames.

Both stack and heap can grow. An OS doesn't know in advance whether stack or heap will be used predominantly. Therefore, an OS must layout these two memory regions in a way to guarantee maximum space for both. And here is the solution:

  1. Layout static memory regions at the edges of process's virtual memory
  2. Put heap and stack on edges too, and let them grow towards each other: one grows up, one grows down
@ClarkThan
ClarkThan / 1-cat-pdp7.s
Last active September 27, 2024 05:42 — forked from sinclairtarget/1-cat-pdp7.s
cat through the ages
" cat
lac 017777 i " Load accumulator (AC) with argument count
sad d4 " Skip next if we have more than 4 words of args
jmp nofiles " Otherwise, jump to nofiles
lac 017777 " Load AC with address of args
tad d1 " Increment AC by 1, past argument count
tad d4 " Increment AC by 4, now AC points to first real arg
dac name " Save arg pointer from AC into 'name'
# IDA (disassembler) and Hex-Rays (decompiler) plugin for Apple AMX
#
# WIP research. (This was edited to add more info after someone posted it to
# Hacker News. Click "Revisions" to see full changes.)
#
# Copyright (c) 2020 dougallj
# Based on Python port of VMX intrinsics plugin:
# Copyright (c) 2019 w4kfu - Synacktiv
@ClarkThan
ClarkThan / zig-postgres-todo.zig
Created January 8, 2026 04:51 — forked from rajeshpillai/zig-postgres-todo.zig
zig - postgres driver (simple example)
const std = @import("std");
const Io = std.Io;
const MessageType = enum(u8) {
BackendKeyData = 'K',
CommandComplete = 'C',
DataRow = 'D',
ErrorResponse = 'E',
ParameterStatus = 'S',
ReadyForQuery = 'Z',