Skip to content

Instantly share code, notes, and snippets.

View hasheddan's full-sized avatar
☁️
writing code that writes code

Daniel Mangum hasheddan

☁️
writing code that writes code
View GitHub Profile
@luojia65
luojia65 / 0-sbi-kernel-caller.rs
Last active November 22, 2021 14:40
sbicall calling convention
// -- 调用者(操作系统内核)
extern "sbicall" fn sbi_call(param: [usize; 6], a6: usize, a7: usize) -> (usize, usize);
// 最后两个参数必须是两个usize类型,a6: usize和a7: usize
// 除了最后两个参数,前面的参数必须是usize、[usize; N]或(usize, usize, ..)类型
// 依次会被填写到a0, a1, ..., a5寄存器中。
// 返回值可以是(usize, usize), [usize; 2]或者SbiRet(包含两个usize的结构体)
fn kernel() {
@MMI
MMI / README.md
Created March 20, 2021 15:09
Undefined behaviour: ARM gcc cross-compiler may generate illegal instructions in place of known division by zero

Division By Zero Exceptions

Setup

On an embedded project, I recently had to debug a crash where the root cause was a division by zero. The offending code in question reduced to something like function foo() presented here.

To validate that it actually was a division by zero problem, I added the if block that printed "GOTCHA". After this change, I saw that the processor status register (CFSR) had the UNDEFINST bit set instead of the exepected DIVBYZERO bit. What?

Using godbolt we can see the compiler emitting an instruction 0xdeff in main... with no other code (suggesting that the compiler realized that the code will not work and simply stopped -- without warning, I might add).

@carolynvs
carolynvs / .gitconfig
Last active October 19, 2022 14:44
git wip - Show what branches you have been working on lately
[alias]
wip = for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads
@noamtamim
noamtamim / README.md
Last active October 2, 2024 05:51
Markdown with PlantUML

How to use PlantUML with Markdown

PlantUML is a really awesome way to create diagrams by writing code instead of drawing and dragging visual elements. Markdown is a really nice documentation tool.

Here's how I combine the two, to create docs with embedded diagrams.

Step 0: Setup

Get the command-line PlantUML from the download page or your relevant package manager.

@lattner
lattner / TaskConcurrencyManifesto.md
Last active November 15, 2024 05:45
Swift Concurrency Manifesto
@negz
negz / kubedump.sh
Last active July 11, 2024 10:57
Dump Kubernetes cluster resources as YAML
#!/usr/bin/env bash
set -e
CONTEXT="$1"
if [[ -z ${CONTEXT} ]]; then
echo "Usage: $0 KUBE-CONTEXT"
exit 1
fi
@mik30s
mik30s / webcam_capture.cpp
Last active October 26, 2024 01:20
Simple C++ program to capture a webcam frame in Linux
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/v4l2-common.h>
#include <linux/v4l2-controls.h>
#include <linux/videodev2.h>
#include <fcntl.h>
#include <unistd.h>
@reterVision
reterVision / udp_client.go
Created July 12, 2014 07:50
A dummy UDP hole punching sample in Go
package main
import (
"encoding/json"
"fmt"
"log"
"net"
"os"
"time"
)
@OzTamir
OzTamir / fork.asm
Created March 26, 2014 11:37
Fork Process in x86 NASM. Each process will print a different message and then exit.
section .text
global _start
_start:
mov eax, 2 ; SYS_FORK Op Code
int 0x80
cmp eax, 0 ;If the return value is 0, we are in the child process
jz child
parent:
mov edx, len ;Move msg length to edx