TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

totally_safe_transmute, Line-by-Line (2021)

80 pointsby iafisherover 1 year ago

8 comments

petsfedover 1 year ago
I appreciate that "totally_safe_transmute" carries some connotation that this is not a "safe" transmute, but rather a suspiciously specific denial.
评论 #38923093 未加载
pcfwikover 1 year ago
Also possible to do directly in the &quot;safe&quot; type system, without messing around with &#x2F;proc&#x2F;mem: <a href="https:&#x2F;&#x2F;zyedidia.github.io&#x2F;blog&#x2F;posts&#x2F;5-safe-transmute&#x2F;" rel="nofollow">https:&#x2F;&#x2F;zyedidia.github.io&#x2F;blog&#x2F;posts&#x2F;5-safe-transmute&#x2F;</a>
评论 #38921857 未加载
评论 #38921374 未加载
Pesthufover 1 year ago
Why don&#x27;t the safe file I&#x2F;O operations panic when &#x2F;proc&#x2F;self&#x2F;mem is opened for writing? I understand why they don&#x27;t want to make all of File I&#x2F;O unsafe just for edge cases like this, but shouldn&#x27;t this be handled at runtime?
评论 #38920377 未加载
评论 #38919832 未加载
评论 #38924814 未加载
评论 #38919751 未加载
jiggawattsover 1 year ago
This is cute, but I hope it never turns up in any real codebase!<p>There’s an updated version with Windows support and better performance: <a href="https:&#x2F;&#x2F;github.com&#x2F;John2143&#x2F;totally-speedy-transmute&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;John2143&#x2F;totally-speedy-transmute&#x2F;</a><p>What worries me is this macro, which “smuggles” the unsafe keyword past the forbid(unsafe_code) flag: <a href="https:&#x2F;&#x2F;github.com&#x2F;John2143&#x2F;totally-speedy-transmute&#x2F;blob&#x2F;master&#x2F;safe&#x2F;src&#x2F;lib.rs">https:&#x2F;&#x2F;github.com&#x2F;John2143&#x2F;totally-speedy-transmute&#x2F;blob&#x2F;ma...</a><p>In my mind, this kind of capability makes Rust crate safety scanning and associated metadata worthless as currently implemented.<p>Package management tools ought to store code instead of binaries, and perform safety checks to via <i>instrumented compilers</i>.
评论 #38919628 未加载
评论 #38919658 未加载
apiover 1 year ago
This is a really weird hack to say the least. More like a flex showing that the author can implement transmute without unsafe than something you’d really use.
评论 #38920536 未加载
quotemstrover 1 year ago
&#x2F;proc&#x2F;self&#x2F;mem is the moral equivalent of `unsafe`. Of course you can do arbitrary things with it. Why would anyone be surprised? You could use <a href="https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;process_vm_readv.2.html" rel="nofollow">https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;process_vm_readv.2.htm...</a>. You could fork and ptrace. You can do any number of weird things.<p>Every day that goes by is a day I think we should make a beeline to CHERI even when we have &quot;safe&quot; languages.
评论 #38923240 未加载
o11cover 1 year ago
`process_vm_writev` would be simpler.
评论 #38920376 未加载
kazinatorover 1 year ago
C doesn&#x27;t provide any reinterpretation operator, and the C++ one&#x27;s name is a misnomer.<p>Casts are <i>conversion</i>: a new value is produced based on an existing one.<p>Reinterpretation requires a value to be in memory, and to be accessed using an lvalue of a different type. Most situations of this kind are undefined behavior.
评论 #38921529 未加载
评论 #38923073 未加载