Skip to content

Instantly share code, notes, and snippets.

View Amanieu's full-sized avatar

Amanieu d'Antras Amanieu

View GitHub Profile
; 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;
@Amanieu
Amanieu / expr.rs
Last active February 20, 2020 18:45
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) {
// TODO: add proper checks instead of reusing those of assign and call
let ty =
self.check_expr_with_needs(expr, if is_input { Needs::None } else { Needs::MutPlace });
self.require_type_is_sized(ty, expr.span, traits::SizedArgumentType);
if !is_input {
self.check_lhs_assignable(expr, "E0070", &expr.span);
}
if is_input {