News for hackers. Stuff that matters.
Re:Memory Safe Languages in Android 13 by steveklabnik on Friday December 02, 2022 @07:05AM (#33829455)
Rust absolutely gives you control over alignment, padding, and ordering. It’s just not the default. Ask for those things and you shall be given it.
Re:Memory Safe Languages in Android 13 by kaba0 on Friday December 02, 2022 @07:48AM (#33829801)
Could you point me to some resources on that? I only know about #[repr] options, but that isn’t absolute control (e.g. for having structs usable from rust and internal asm)
Re:Memory Safe Languages in Android 13 by steveklabnik on Friday December 02, 2022 @09:03AM (#33830505)
What is “internal assembly”? I’m not familiar with that term.

Is there anything else that the various repr options don’t give you? My team at work does OS dev in Rust, and haven’t ever run into cases where Rust can’t do what we need it to do in these cases.

Re:Memory Safe Languages in Android 13 by kaba0 on Friday December 02, 2022 @09:40AM (#33830989)
* inline assembly, just my brain stopped working for a sec :D

Well, my specific case is writing a fast interpreter in Rust, where I would like to use elements like a stackframe from both inline asm and proper Rust code. In my first iteration I chose a dynamically sized u64 array, wrapped in a safe API, because I couldn’t be more specific. But even with known size elements the best I can do - to my knowledge - is Layout? Or just a raw pointer and a wrapper with helper functions, as otherwise I can’t modify the object in question from both places.

Re:Memory Safe Languages in Android 13 by steveklabnik on Friday December 02, 2022 @02:03PM (#33835154)
Ah yeah no worries :)

It’s sort of tough because I am only familiar in passing with the patterns in that type of code, but Layout is an allocator API, so I’m not 100% sure why it would be used here. I’d guess that if I was doing something like this, I’d be casting it to and from a struct that’s defined correctly. This is one area where stuff is a little simpler than C, thanks to the lack of TBAA, though many projects do turn that off.