Skip to content

Instantly share code, notes, and snippets.

View matu3ba's full-sized avatar

Jan Ph. H. matu3ba

View GitHub Profile
#if defined(__STDC__)
#define IS_MAYBE_C89
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 199409L)
#define IS_NOT_C89
#endif
#endif
#endif
#ifndef IS_MAYBE_C89
@matu3ba
matu3ba / ptrtoint_inttoptr.c
Last active June 23, 2024 21:31
clang c89 ptr to int -Weverything
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void ptrtointtoptr(void);
static void memset_16aligned(void * ptr, char byte, size_t size_bytes, uint16_t alignment) {
assert((size_bytes & (alignment-1)) == 0);
@matu3ba
matu3ba / ptrtoint_inttoptr.c
Created June 23, 2024 20:52
cerberus iso compat pointer works
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void memset_16aligned(void * ptr, char byte, size_t size_bytes, uint16_t alignment) {
assert((size_bytes & (alignment-1)) == 0); // Size aligned
assert(((uintptr_t)ptr & (alignment-1)) == 0); // Pointer aligned
memset(ptr, byte, size_bytes);
}
@matu3ba
matu3ba / error_msg
Created June 23, 2024 20:48
cerberus error ptrtoint_inttoptr.c
cerberus ptrtoint_inttoptr.c
ptrtoint_inttoptr.c:24:16: error: constraint violation: initializing 'void*' with an expression of incompatible type 'usual arithmetic conversions with type [integer promotion of [usual arithmetic conversions with type [integer promotion of [uintptr_t] and integer promotion of [unsigned short]]] and integer promotion of [integer promotion of [uintptr_t]]]'
void * ptr = ((uintptr_t)mem+align_min_1) & ~(uintptr_t)align_min_1;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
§6.7.9#11, sentence 2:
11 The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
initial value of the object is that of the expression (after conversion); the same type
constraints and conversions as for simple assignment apply, taking the type of the scalar
to be the unqualified version of its declared type.
@matu3ba
matu3ba / ansi-colors-discord.md
Created June 1, 2024 21:20 — forked from kkrypt0nn/ansi-colors-discord.md
A guide to ANSI on Discord

A guide to ANSI on Discord

Discord is now slowly rolling out the ability to send colored messages within code blocks. It uses the ANSI color codes, so if you've tried to print colored text in your terminal or console with Python or other languages then it will be easy for you.

Quick Explanation

To be able to send a colored text, you need to use the ansi language for your code block and provide a prefix of this format before writing your text:

\u001b[{format};{color}m

\u001b is the unicode escape for ESCAPE/ESC, meant to be used in the source of your bot (see ). If you wish to send colored text without using your bot you need to copy the character from the website.

@matu3ba
matu3ba / acl_min.zig
Created January 24, 2024 22:18
Minimal ACL. but ugly.
// zig run acl_min.zig
pub const DWORD = c_ulong;
pub const HANDLE = ?*anyopaque;
pub const PVOID = ?*anyopaque;
pub const PSID = PVOID;
pub const PSECURITY_DESCRIPTOR = PVOID;
pub const enum__SE_OBJECT_TYPE = c_uint;
pub const SE_OBJECT_TYPE = enum__SE_OBJECT_TYPE;
pub const wchar_t = c_ushort;
pub const SE_FILE_OBJECT: c_int = 1;
@matu3ba
matu3ba / question
Last active October 17, 2023 08:19
LLVM planned pointer semantics questions
Dear llvm folks, I have some questions on the status or plan for the LLVM memory model semantics regarding pointers and it would be nice, if you can give me pointers where to look for answers.
Context: "PNVI-ae-udi tracks (1) ambiguities in provenance and (2) provenance exposure whereas VIP
does not. On the other hand, (3) VIP tracks provenance in integers (in a limited way, for round-trip
casts) whereas PNVI-ae-udi does not, and (4) VIP relies on the copy_alloc_id primitive, which is
not available in PNVI-ae-udi.". https://iris-project.org/pdfs/2022-popl-vip.pdf
1. As far as understand, temporal (undereferenced) out of bounds pointers are also not forced to be UB in contrast to C. Is that correct and would the llvm model them to allow this use case?
2. From what I understand, the one past the end ambiguous provenance of pointers originates from pointer that were casted to integers losing their provenance. Is there some decision or discussion what llvm is doing or will do and/or if user annotation is planne
@matu3ba
matu3ba / .envrc
Last active October 15, 2023 23:19
arcan DRI driver not from this Mesa build: dont mix old + new drivers! TODO best solution
use_nix
@matu3ba
matu3ba / ANSI.md
Created September 1, 2023 22:06 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@matu3ba
matu3ba / cloneall.sh
Created August 1, 2023 23:48
Download various non-mainstream Kernels for (rip)grepping.
#!/usr/bin/env sh
git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD
git clone --depth=1 https://github.com/freebsd/freebsd-src
git clone --depth=1 https://fuchsia.googlesource.com/fuchsia
git clone --depth=1 https://github.com/haiku/haiku
git clone --depth=1 https://github.com/hermitcore/rusty-hermit
git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/
git clone --depth=1 https://github.com/NetBSD/src
git clone --depth=1 https://github.com/openbsd/src