Skip to content

Instantly share code, notes, and snippets.

#include <mach/mach_init.h>
#include <mach/thread_act.h>
#include <mach/task.h>
#include <mach/port.h>
#include <libproc.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <mach/mach_vm.h>
Process: Python [97984]
Path: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: 3.6.1 (3.6.1)
Code Type: X86-64 (Native)
Parent Process: zsh [97671]
Responsible: Python [97984]
User ID: 502
Date/Time: 2020-02-16 23:08:47.880 -0800
sophiawisdom@Sophias-MacBook-Pro tweaks % ./test_release
namesCount before is 10
namesCount after is 10
sophiawisdom@Sophias-MacBook-Pro tweaks %
namesCount before is 10
There are 2 refs for mach_thread_self and 2 refs for task_self_trap()
There are 1002 refs for mach_thread_self and 1002 refs for task_self_trap()
namesCount after is 10
new thread started
numKRefs for new thread is 2
sophiawisdom@Sophias-MacBook-Pro tweaks %
@sophiawisdom
sophiawisdom / 1: call_one_function.c
Last active April 26, 2020 16:49
thread_set_state does not set gs register
#include <mach/mach_init.h>
#include <mach/thread_act.h>
#include <mach/task.h>
#include <mach/port.h>
#include <mach-o/dyld_images.h>
#include <mach/mach_vm.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
@sophiawisdom
sophiawisdom / searches.c
Last active June 6, 2020 08:55
Linear vs binary vs interpolation search
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <limits.h>
int compar(const void *a, const void *b) {
unsigned int val_a = *(unsigned int *)a;
unsigned int val_b = *(unsigned int *)b;
if (val_a < val_b) {
return -1;
int vectorizedLinearSearch(unsigned int *array, int size, unsigned int searchNum) {
assert(((size >> 3) << 3) == size); // divisible by 8 for __m256i
__m256i searchVector = _mm256_set1_epi32(searchNum); // broadcast searchNum
for (int i = 0; i < size; i+=8) {
__m256i searchValue = _mm256_loadu_si256(&array[i]);
// Would be better if we could compare just a single 32 bit value, but just duplicating
// the 32 bit value is fine also.
__m256i eqMask = _mm256_cmpeq_epi32(searchVector, searchValue);
unsigned int intMask = _mm256_movemask_ps(eqMask);
if (_mm_popcnt_u32(intMask) != 0) {
from twisted.internet import asyncioreactor
# may need to be installed before other twisted imports?
asyncioreactor.install()
from twisted.internet import reactor
from twisted.web.resource import Resource
from twisted.internet.defer import ensureDeferred
from twisted.web.server import Site, NOT_DONE_YET
@sophiawisdom
sophiawisdom / bad file ffprobe
Created January 6, 2021 22:01
good and bad ffprobes
ffprobe version N-100563-g66deab3 Copyright (c) 2007-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.28)
configuration:
libavutil 56. 63.100 / 56. 63.100
libavcodec 58.115.102 / 58.115.102
libavformat 58. 65.101 / 58. 65.101
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 95.100 / 7. 95.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
Need a more recent version of /usr/lib/system/introspection/libdispatch.dylib -- missing suppport for the queue_item_complete hook function.
Location is /var/root/Library/Developer/Xcode/DerivedData/mods-hiqpvfikerrvwrbgoskpjqwmglif/Build/Products/Debug/daemon
Input PID to pause: 36907
Injecting into PID 36907
Magic number is -17958193
got a command of type 25
got a command of type 25
got a command of type 25
got a command of type 25