Skip to content

Instantly share code, notes, and snippets.

View Amanieu's full-sized avatar

Amanieu d'Antras Amanieu

View GitHub Profile
.byte 253, 123, 191, 169, 253, 3, 0, 145, 246, 95, 191, 169, 243, 83, 191, 169, 244, 3, 1, 170, 243, 3, 0, 170, 150, 2, 64, 249, 151, 6, 64, 249, 129, 2, 128, 210, 0, 0, 0, 148, 64, 2, 0, 180, 22, 64, 0, 248, 150, 1, 128, 210, 23, 192, 0, 248, 1, 0, 128, 82, 1, 252, 159, 136, 224, 3, 19, 170, 0, 0, 0, 148, 148, 2, 64, 249, 225, 3, 22, 170, 224, 3, 19, 170, 0, 0, 0, 148, 192, 0, 0, 180, 20, 64, 0, 248, 33, 0, 128, 82, 1, 252, 159, 136, 224, 3, 19, 170, 0, 0, 0, 148, 243, 83, 193, 168, 246, 95, 193, 168, 253, 123, 193, 168, 192, 3, 95, 214
Disassembly of 128 bytes <u0:0>:
0: fd 7b bf a9 stp x29, x30, [sp, #-0x10]!
4: fd 03 00 91 mov x29, sp
8: f6 5f bf a9 stp x22, x23, [sp, #-0x10]!
c: f3 53 bf a9 stp x19, x20, [sp, #-0x10]!
10: f4 03 01 aa mov x20, x1
14: f3 03 00 aa mov x19, x0
18: 96 02 40 f9 ldr x22, [x20]
; ModuleID = 'test.a298ebb3-cgu.0'
source_filename = "test.a298ebb3-cgu.0"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-wasi"
@vtable.0 = private unnamed_addr constant <{ ptr, [8 x i8], ptr, ptr, ptr }> <{ ptr @"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h166e0057eb7dac29E", [8 x i8] c"\04\00\00\00\04\00\00\00", ptr @"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h1a558d8d80021a86E", ptr @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h76b0bf6ab1e8be97E", ptr @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h76b0bf6ab1e8be97E" }>, align 4
; std::sys_common::backtrace::__rust_begin_short_backtrace
; Function Attrs: noinline nounwind
define internal fastcc void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hcf2d11bbcd93b116E(ptr nocapture noundef nonnull readonly %f) unnamed_addr #0 {
// Helper macros to deal with platform-specific differences in assembly code
// between ELF, Mach-O and COFF file formats.
cfg_if::cfg_if! {
if #[cfg(windows)] {
// COFF
macro_rules! asm_function_begin {
($name:tt) => {
concat!(
".globl ", $name, "\n",
".def ", $name, "\n",

Summary

Panics which happen inside a Drop impl currently unwind as long as the drop was not itself called during unwinding (which would otherwise abort immediated due to a double-panic). This design meeting proposes to change this behavior to always abort if a panic attempts to escape a drop, even if this drop was invoked as part of normal function execution (as opposed to unwinding).

The dicussion on this issue dates back to 2014 (rust-lang/rust#14875) where the decision was made to support unwinding in drops but leave the door open to potentially reversing this decision.

Background reading

rust-lang/rust#86027

@Amanieu
Amanieu / pie_reloc.rs
Created August 25, 2021 00:53
PIE self-relocation in Rust
/// Processes all relocations in the ELF dynamic section
unsafe fn process_pie_relocations(auxv: &mut AuxVec) {
// Locate the PT_DYNAMIC segment in the program headers. If we don't have
// a .dynamic section then it means that we are a static executable and
// don't need any relocations.
let pt_dynamic = auxv
.phdr
.iter()
.filter(|p| p.p_type == linux::PT_DYNAMIC)
.next();
// Common code for interruptible syscalls
macro_rules! asm_interruptible_syscall {
($interrupted:expr, $interrupt_flag:expr, $result:expr, $nr:expr) => {
asm_snippet!(
// If a signal interrupts us between atomic_begin and atomic_end,
// the signal handler will rewind the PC back to atomic_begin so
// that the interrupt flag check is atomic.
atomic_begin:,
"ldrb {interrupted:w}, [{interrupt_flag}]",
"cbnz {interrupted}, {skip}",
/// A cursor over a `BTreeMap`.
///
/// A `Cursor` is like an iterator, except that it can freely seek back-and-forth.
///
/// Cursors always rest between two elements in the tree, and index in a logically circular way.
/// To accommodate this, there is a "ghost" non-element that yields `None` between the last and
/// first elements of the tree.
///
/// When created, cursors start at the front of the tree, or the "ghost" non-element if the tree is empty.
wget https://zombsroyale.io/asset/build/webgl.wasm.code.unityweb
clif-util wasm -T --target x86_64 --set enable_verifier=false -- webgl.wasm.code.unityweb
Old backend
======== ======== ==================================
Total Self Pass
-------- -------- ----------------------------------
5.288 0.158 Translate WASM module
5.131 5.131 Translate WASM function
23.970 0.088 Compilation passes
; std::panicking::try
; Function Attrs: nonlazybind uwtable
define void @_ZN3std9panicking3try17h2c4df7f3f9c79acfE(%"core::result::Result<proc_macro::Span, alloc::boxed::Box<core::any::Any>>"* noalias nocapture sret dereferenceable(24)) unnamed_addr #1 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality !dbg !2657 {
start:
%1 = alloca %"core::mem::maybe_uninit::MaybeUninit<imp::nightly_works::{{closure}}::{{closure}}>", align 1
%self.dbg.spill.i17 = alloca %"core::mem::manually_drop::ManuallyDrop<imp::nightly_works::{{closure}}::{{closure}}>"*, align 8
call void @llvm.dbg.declare(metadata %"core::mem::manually_drop::ManuallyDrop<imp::nightly_works::{{closure}}::{{closure}}>"** %self.dbg.spill.i17, metadata !2686, metadata !DIExpression()), !dbg !2695
%self.dbg.spill.i = alloca %"core::mem::maybe_uninit::MaybeUninit<imp::nightly_works::{{closure}}::{{closure}}>"*, align 8
call void @llvm.dbg.declare(metadata %"core::m
diff --git a/src/common/IPC/Primitives.cpp b/src/common/IPC/Primitives.cpp
index c348776e..6d48f779 100644
--- a/src/common/IPC/Primitives.cpp
+++ b/src/common/IPC/Primitives.cpp
@@ -302,13 +302,16 @@ void Socket::SendMsg(const Util::Writer& writer) const
const void* data = writer.GetData().data();
size_t len = writer.GetData().size();
+ // Use a smaller buffer size to avoid ENOBUFS errors from the kernel
+ const size_t MAX_IPC_BYTES = 4096;