Skip to content

Instantly share code, notes, and snippets.

View Subv's full-sized avatar

Sebastian Valle Subv

  • Barranquilla, Colombia
View GitHub Profile
@zachhilman
zachhilman / tsan2
Created August 12, 2018 22:15
tsan2
This file has been truncated, but you can view the full file.
==================
WARNING: ThreadSanitizer: data race (pid=14219)
Read of size 1 at 0x7b04000098c0 by thread T2:
#0 strlen <null> (libtsan.so.0+0x315c5)
#1 pthread_setname_np <null> (libpthread.so.0+0x1391c)
#2 <null> <null> (libglib-2.0.so.0+0x73ded)
Previous write of size 8 at 0x7b04000098c0 by main thread (mutexes: write M221):
#0 malloc <null> (libtsan.so.0+0x2afa3)
#1 g_malloc <null> (libglib-2.0.so.0+0x51858)
@Subv
Subv / install_master.sh
Last active May 31, 2018 14:21
Kubernetes Master node installer script.
#!/bin/bash
# First, install Docker.
echo "Adding Docker APT repository"
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
sudo apt-get update
#include <3ds.h>
#include <stdio.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
static s64 base_tick;
#include <3ds.h>
#include <stdio.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
static s64 base_tick;
@ds84182
ds84182 / thread-scheduling.cpp
Created November 5, 2017 00:38
Thread scheduling test. The low priority thread join is not successful, but the low priority thread has a chance to run during one of the printf calls (due to svcSendSyncRequest).
#include <3ds.h>
#include <stdio.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
static LightEvent test_event;
@Subv
Subv / 38Nodes_3.ffm
Last active May 23, 2017 22:14
NS3 Network Coding
3
31 32 33 34 35 36 37
10 12 16 29 30
6 4 3 2 7 7 1
0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Result __fastcall KResourceLimit::SetMaxLimit(KResourceLimit *resLimit, LimitableResource resType, u32 resCount)
{
signed int v3; // r10@0
KResourceLimit *v5; // r6@1
KObjectMutex *v6; // r0@1
KObjectMutex *v8; // r4@1
unsigned int v9; // r2@1
bool v10; // zf@1
unsigned int v11; // r3@2
Result result; // r0@8
@Subv
Subv / .cpp
Last active December 11, 2017 14:49
Thread starvation 3DS
#include <3ds.h>
#include <inttypes.h>
#include <cstdio>
#define NUM_THREADS 2
u32 threadA_stack[0x400];
u32 threadB_stack[0x400];
volatile bool outputs[] = { false, false };
@Subv
Subv / kernel_scheduling.md
Last active December 8, 2017 05:14
Nintendo 3DS Kernel scheduler findings

Kernel synchronization

The AppCore uses a mostly cooperative scheduler, however, it is allowed to preempt threads under some specific circumstances, see the Rescheduling section for the cases where the scheduler may preempt a lower-priority thread to let a higher-priority run.

Each core has its own KScheduler instance.

KObject waitlists

Each KObject manages a list of threads that are waiting on it. This list is iterated over each time the KObject is signalled.

KERNEL_HEAP:FFF93BB0 C0 D4 F2 FF+first_resource_limit DCD KResourceLimit_vtable; vtable
KERNEL_HEAP:FFF93BB0 01 00 00 00+ ; DATA XREF: .data:resource_limit_linko
KERNEL_HEAP:FFF93BB0 18 00 00 00+ ; KERNEL_HEAP:stru_FFF7BB40o
KERNEL_HEAP:FFF93BB0 00 00 00 04+ ; KERNEL_HEAP:resourcelimit_linked_list_firsto
KERNEL_HEAP:FFF93BB0 20 00 00 00+ DCD 1 ; refCount
KERNEL_HEAP:FFF93BB0 20 00 00 00+ DCD 0x18 ; max_thread_prio
KERNEL_HEAP:FFF93BB0 20 00 00 00+ DCD 0x4000000 ; max_commit
KERNEL_HEAP:FFF93BB0 08 00 00 00+ DCD 0x20 ; max_thread
KERNEL_HEAP:FFF93BB0 08 00 00 00+ DCD 0x20 ; max_event
KERNEL_HEAP:FFF93BB0 10 00 00 00+ DCD 0x20 ; max_mutex