Skip to content

Instantly share code, notes, and snippets.

View avdgrinten's full-sized avatar

Alexander van der Grinten avdgrinten

  • Humboldt-Universität zu Berlin
  • Berlin
View GitHub Profile
@avdgrinten
avdgrinten / Controller.ko
Last active April 26, 2018 13:56
.kor language examples
/* This file is part of the Managarm operating system.
* Copyright (C) 2007, 2008, 2009 Alexander van der Grinten
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@avdgrinten
avdgrinten / main.cpp
Created May 1, 2018 16:32
Buddy allocator benchmark
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include <chrono>
#include <iostream>
// ----------------------------------------------------------------------------
// The new buddy allocator.
@avdgrinten
avdgrinten / linux.patch
Created August 10, 2019 06:07
Example of minimal mlibc sysdeps (Linux)
diff --git a/abis/linux/x86_64/abi.h b/abis/linux/x86_64/abi.h
new file mode 100644
index 0000000..2d970d9
--- /dev/null
+++ b/abis/linux/x86_64/abi.h
@@ -0,0 +1,27 @@
+#ifndef _ABIBITS_ABI_H
+#define _ABIBITS_ABI_H
+
+#define __MLIBC_LINUX_O_PATH 010000000

async::queue<T>: Unbounded queue with asynchronous get()

This class implements an unbounded queue by buffering all items that are put into it.

template<typename T, typename Allocator>
struct async::queue {
	void put(T object);

	/* unspecified async::sender */ async_get(); // [1]
@avdgrinten
avdgrinten / dso-load.cpp
Last active March 14, 2021 16:21
Loading ELF shared libraries as kernel modules; includes relocation and symbol lookup
void processElfDso(const char *buffer) {
auto base = reinterpret_cast<char *>(KernelVirtualMemory::global().allocate(0x10000));
// Check the EHDR file header.
Elf64_Ehdr ehdr;
memcpy(&ehdr, buffer, sizeof(Elf64_Ehdr));
assert(ehdr.e_ident[0] == 0x7F
&& ehdr.e_ident[1] == 'E'
&& ehdr.e_ident[2] == 'L'
&& ehdr.e_ident[3] == 'F');
@avdgrinten
avdgrinten / elf_x86_64.x
Created October 20, 2017 07:01
Default LD linker script (elf_x86_64 on Linux)
/* Default linker script, for normal executables */
/* Copyright (C) 2014-2017 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); SEARCH_DIR("=/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib");