Skip to content

Instantly share code, notes, and snippets.

View sortie's full-sized avatar

Jonas Termansen sortie

View GitHub Profile
@sortie
sortie / which_os.c
Created October 15, 2017 23:04
Detect the operating system using UDP stack corner cases
#include <sys/socket.h>
#include <err.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
@sortie
sortie / kblayout-compiler.diff
Created November 12, 2016 13:21
kblayout-compiler.diff
diff --git a/kblayout-compiler/kblayout-compiler.c b/kblayout-compiler/kblayout-compiler.c
index f38e640..b89e83c 100644
--- a/kblayout-compiler/kblayout-compiler.c
+++ b/kblayout-compiler/kblayout-compiler.c
@@ -601,6 +601,8 @@ int main(int argc, char* argv[])
}
break;
}
+ if ( !found_key )
+ printf("%s\n", line);
@sortie
sortie / Makefile
Created October 30, 2016 12:39
ed Makefile
include ../../build-aux/platform.mak
include ../../build-aux/compiler.mak
include ../../build-aux/version.mak
include ../../build-aux/dirs.mak
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
CFLAGS?=$(OPTLEVEL)
CFLAGS:=$(CXXFLAGS) -Wall -Wextra -Wno-logical-not-parentheses -Wno-unused-parameter
CPPFLAGS:=$(CPPFLAGS) -DBACKWARDS
diff --git a/utils/Makefile b/utils/Makefile
index 53f10fe..0e0c7d0 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -72,6 +72,9 @@ BINARIES=\
$(BINARIES_EXCEPT_INSTALL) \
xinstall
+MANPAGES=\
+chkblayout.1
@sortie
sortie / test.c
Created September 28, 2016 21:06
size_t size = 0;
char* buffer = NULL;
while ( true )
{
size = size ? 2 * size : 4096;
buffer = malloc(size);
if ( !buffer )
err(1, "malloc");
ssize_t used = readlink(...);
/* error check */
@sortie
sortie / quine.c
Created September 5, 2016 20:01
quine
#include <stdio.h>
static const char code[] =
"#include <stdio.h>\n"
"\n"
"static const char code[] =\n"
" \"\0\";\n"
"\n"
"int main(void) {\n"
" for (size_t i = 0; i < sizeof(code) - 1; i++) {\n"
/* unistd.h: */
#ifndef _UNISTD_H
#define _UNISTD_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
int execv(const char*, char* const[]);
int execve(const char*, char* const[], char* const[]);
int execvp(const char*, char* const[]);
@sortie
sortie / div.c
Last active August 10, 2016 17:47
div
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// The highest bit in the uintmax_t type to avoid shift overflow.
#define UINTMAX_HIGH (UINTMAX_C(1) << (sizeof(uintmax_t) * 8 - 1))
// Attempt 1:
diff --git a/kernel/x64/boot.S b/kernel/x64/boot.S
index e541b55..da5798c 100644
--- a/kernel/x64/boot.S
+++ b/kernel/x64/boot.S
@@ -174,6 +174,15 @@ __start:
.code64
2:
+ # The upper 32 bits of the general purpose registers are *undefined* after
+ # switching into 64-bit mode (Intel Manual, Vol 1, 3.4.1.1 "General-Purpose
@sortie
sortie / bnf.bnf
Created May 2, 2016 15:36
bnf.bnf
wspace ::= '\t' | '\n' | '\v' | '\f' | '\r' | ' '.
wspaces ::= <wspace>
| <wspace> <wspaces>.
ospaces ::=
| <wspaces>.
char-constant ::= '\'' [^'] '\''
| '\'' '\\' <char> '\''.
range-char ::= [^]].
ranges ::= | <range-char> <ranges>.
range-constant ::= '[' <ranges> ']