Skip to content

Instantly share code, notes, and snippets.

View jeremyd2019's full-sized avatar

jeremyd2019

View GitHub Profile
@jeremyd2019
jeremyd2019 / wine-arch-detector.c
Last active June 15, 2024 18:33
exec proper wine based on arch of PE binary
/* Register with:
* echo :wine:M::MZ::/opt/wine-arch-detector:PO > /proc/sys/fs/binfmt_misc/register
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/auxv.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@jeremyd2019
jeremyd2019 / cygwin_volumes.c
Created June 4, 2024 00:19
use cygwin functions to list windows volume roots as `\0`-delimited cygwin paths
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/cygwin.h>
struct dos_drive_mappings
{
struct mapping
{
struct mapping *next;
@jeremyd2019
jeremyd2019 / cygwin.py
Created June 3, 2024 23:07
python ctypes interface to cygwin apis
import contextlib
import ctypes
import errno
import os
__all__ = ["CCP_POSIX_TO_WIN_A", "CCP_POSIX_TO_WIN_W",
"CCP_WIN_A_TO_POSIX", "CCP_WIN_W_TO_POSIX",
"CCP_ABSOLUTE", "CCP_RELATIVE", "CCP_PROC_CYGDRIVE",
"cygwin_conv_path", "cygwin_conv_path_list",
"cygwin_winpid_to_pid", "cygwin_pid_to_winpid",
@jeremyd2019
jeremyd2019 / volumes.c
Last active May 30, 2024 23:47
list windows volume roots as `\0`-delimited cygwin paths
#include <windows.h>
#include <stdio.h>
#include <wchar.h>
#include <sys/cygwin.h>
/* based on the starting point
https://learn.microsoft.com/en-us/windows/win32/fileio/displaying-volume-paths
*/
void main(void)
{
@jeremyd2019
jeremyd2019 / pacman.strace.txt
Created May 27, 2024 02:37
strace of pacman trying to unlink msys-2.0.dll
122 237566414 [main] pacman 494 unlink_nt: Trying to delete \??\D:\t\msys64\usr\bin\msys-2.0.dll, isdir = 0
252 237566666 [main] pacman 494 unlink_nt: Setting delete disposition on \??\D:\t\msys64\usr\bin\msys-2.0.dll failed, status = 0xC0000121
172 237566838 [main] pacman 494 unlink_nt: Cannot delete \??\D:\t\msys64\usr\bin\msys-2.0.dll, try delete-on-close
252 237567090 [main] pacman 494 unlink_nt: Setting delete-on-close on \??\D:\t\msys64\usr\bin\msys-2.0.dll failed, status = 0xC0000121
685 237567775 [main] pacman 494 try_to_bin: Setting delete disposition on $RECYCLE.BIN\S-1-5-21-XXX\.����60000001071944502ffdd679fdc9c66a (\??\D:\t\msys64\usr\bin\msys-2.0.dll) failed, status = 0xC0000121
522 237568297 [main] pacman 494 try_to_bin: Overwriting $RECYCLE.BIN\S-1-5-21-XXX\.����60000001071944502ffdd679fdc9c66a (\??\D:\t\msys64\usr\bin\msys-2.0.dll) with $RECYCLE.BIN\S-1-5-21-XXX\.����60000001071944502ffdd679fdc9c66aX failed, status = 0xC0000022
215 237568512 [main] pacman 494 try_to_bin: \??\D:\t
@jeremyd2019
jeremyd2019 / cleanup.sh
Last active May 26, 2024 23:06
Script to clean up files that msys2-runtime moved to recycle bin because they were in use
#!/bin/bash -e
shopt -s nullglob
root="$(cygpath -w /)"
root="$(cygpath -u "${root:0:2}")"
trash=("${root}/\$Recycle.Bin/S-1-"*/$'.\355\261\255'*)
if (( ${#trash[@]} )); then
@jeremyd2019
jeremyd2019 / testfork.c
Last active May 21, 2024 00:27
reproducer for cygwin hangs under emulation on arm64
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#ifndef BINARY
#define BINARY "/bin/true"
#endif
#ifndef ARG
#define ARG "0.1"
@jeremyd2019
jeremyd2019 / rust_beta.py
Created April 22, 2024 19:45
Script to convert msys2's mingw-w64-rust PKGBUILD to build latest beta
#!/usr/bin/env python
import fileinput
import pprint
import re
import tomli
from urllib.request import urlopen
with urlopen("https://static.rust-lang.org/dist/channel-rust-beta.toml") as f:
x = tomli.load(f)
#include <stdio.h>
#include <gmp.h>
/* due to https://github.com/msys2/MINGW-packages/issues/15715
* variables/constants are lacking dllimport annotations. But clang/lld are
* doing some magic with refptrs that results in a simple access of gmp_version
* *not* requiring a pseudo-relocation. This more contrived example results in
* a pseudo-relocation on i386, x86_64, and aarch64, with gcc/bfd and clang/lld
* (as applicable) */
@jeremyd2019
jeremyd2019 / update-llvm.sh
Last active June 8, 2023 23:34
scripts to update packages
#!/bin/bash -e
set -o pipefail
newversion="$1"
newrc=""
if [[ $newversion == *-rc* ]]; then
newrc="-${newversion#*-}"
newversion="${newversion%%-*}"