Skip to content

Instantly share code, notes, and snippets.

View Subv's full-sized avatar

Sebastian Valle Subv

  • Barranquilla, Colombia
View GitHub Profile
@Subv
Subv / 1.cs
Created November 21, 2011 00:03 — forked from LordJZ/1.cs
using System;
using System.Collections;
using System.Linq;
namespace Kamilla.WorldOfWarcraft.Latest.OpcodeDatas
{
public abstract class PackedData : OpcodeData
{
protected virtual bool IsMaskSequenceSwapped { get { return true; } }
protected abstract int[] MaskSequence { get; }
@Subv
Subv / gist:1381218
Created November 21, 2011 00:03 — forked from LordJZ/gist:1193348
SMSG_PHASE_SHIFT_CHANGE 4.2.0
using System;
using System.Text;
namespace Kamilla.WorldOfWarcraft.Latest.OpcodeDatas
{
public sealed class SetPhaseShift : PackedData
{
public readonly byte[][] Data = new byte[4][];
public WowGuid Guid;
public uint Unk;
@yuriks
yuriks / ctr_resultcodes.py
Last active February 14, 2018 18:38
ctr_resultcodes.py
#!/usr/bin/python2
# Convert 3DS errors to readable format
# plutooo // yuriks
import sys
summaries = {
0: "Success",
1: "Nothing happened",
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
@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.

@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 };
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 / 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
@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;
#include <3ds.h>
#include <stdio.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
static s64 base_tick;