#Zinnia
1 messages · Page 15 of 1
i read gnu cleanup instead
that's true
that's why c++ is beautiful :^)
i mean i don't hate c++
i can just not use the features i don't need
but i don't know how it will work with modules
well really you don't need to even use them
it's a thing but you don't even use them that often
you either use make_shared/make_unique
or your way of allocating memory which hopefully has support for new-in-place
you could of course make it work with operator new/delete if you like
tf
does c++ have a stable abi across SOs? or is it like on rust
yes
yooo
well i'm not sure if it's stable stable stable
like c
but you can 100000% link a shared library
with c++ symbols
nice
as long as you use the same compiler version for both you will be fine
it will probably also work across different versions
well the idea with modules is not to compile modules standalone
but instead so you can opt out of things you never use
probably
pog

I’ll cross post it here. VC status unknown today, I give it a 25% chance. Tower is acquired tho so we are ballin the next 3 weeks
pog
Wouldn't you need some kind of external interface in rust anyway?
It's the simplest way and you can still provide a C++ interface
Just a small heads up: Those don't encode return type so be careful about changing the return type of a function exported this way.
wdym
C++ mangling encodes parameters and namespaces, but not return values.
why does that matter?
Only if you decide to change the return type
If you change the return type in a kernel function referenced by a module, but forget to recompile the module, you'll run into strange bugs.
oh that
Instead of when a param is changed, which would cause it not to dynamically link
the build signature takes care of that
only modules that fit to the loaded kernel are loadable
Sure
It's not a big thing, just something I noticed when I looked into C++ mangling and thought was odd.
wdym by custom containers?
vector
Oh custom impls of container types?
yes
Yeah C++ STL sucks IMO
because
a) allocations can fail
b) i despise the stl
TBH I should probably do something about "alloc can fail" stuff. Because even my C code doesn't handle that properly.
U not doing a rust kernel anymore?
The C++ STL is actually very well designed for most usecases. In general kernels are hard because a kernel often has very specific requirements on the implementation of various things.
yeah
it kinda takes the fun out of it because you need a workaround for almost anything
not true
flair checks out
yes
you used to need workarounds, now almost everything has a specific way of being handled with rust
@near tartan can u explain what u needed workarounds for
nah
rust still sucks
use my thing 
or frigg
i mean it's redundant information, you cannot overload on the return type alone
And thats why Linux modules hash the goddamn source file for exported functions 
.
i've gotten to userland and filesystems without needing workarounds, so what is it
just curious
well for one, you need a nightly toolchain, even though the actual version is stabilized
i needed a bunch of unstable features
well yeah
working with Arcs everywhere requires you to put locks everywhere and do like nested structures
they argue about the finalized api
why
are you needing arcs in os dev
😔
why not
like
filesystem comes to mind??
even in other langs that needs refcounting
The real issue is almost always A. someone attempting to write rust code like it's C, or B. rust being so opionated the "correct" way feels annoying to do
I don't see how that's an answer to my question
you definitely need arcs because you cannot possibly know the lifetimes
what filesystem were you trying to do
then i extra don't see why you needed arcs
vfs lifetime is just: Yes
Entire program
????
this makes 0 sense
it doesn't need a lifetime it's there the entire duration of the program
take struct inode/vnode for example
there may be multiple references to it at the same time
and you don't know how long it's going to live
mutex guard my beloved
.
which brings me to my point
it's multithreading your options are locks or some other magic
😔
oh well
just sad to see rust abandoned in corner
rust is not a bad language
just not optimal for a kernel
also yeah, dont even get me started on memory usage
well yes but linux also doesn't use alloc afaik
rust also used so much stack memory that it overflowed
like 8 functions deep
you don't have to use alloc in rust
its no different in C
needing to allocate stuff, requires you to setup allocations
and handle things
write them yourself 🔥
GASP
do explain how you achieved this
?
You certainly do need Arc<>s in a lot of cases
in osdev
You can't just make your struct File 'static, otherwise you can only have a static number of files
need is a strong word
This is not a property of Rust, the same is true for C (except that it's less ergonomic in C because you have to do the ref counting manually and it's easy to get wrong)
static_mut_fs
this makes me wonder how you implemented this
🔥
because it sounds like you just did it wrong 
Btw Marvin, i said this before but I'm pretty sure Managarm's VFS has no data structure at all that can't be literally translated to Rust
W/o running into borrowing issues
vfs = include_bytes!
yep
that still needs arcs 
@next cairn you're just trolling at this point
then explain how that's supposed to work
you can once cell mutex guard a ramfs
you can only have a finite number of objects that are 'static
sure but that's not a real VFS
that's a static archive
there can be more than one ramfs at once too
scary
you can't create files in it
and you can't take references to the files
inside the Mutex
so you have to access them by path each time
great data structure
peak
yeah
that's like saying: oh lifetimes in C are easy, i just don't use pointers and everything is global
@near tartan what part of the VFS are you struggling with?
nothing in particular, just having to have this mutex wrapper around everything
uh
I'd try to think about the VFS in terms of what traits you need
not how to implement them
make dirty cache
don't lock on writes because everything is a lie and it's queues
you got this
I'm not trolling but I'm also not 100% serious
I just know there's supposed to always be ways to avoid arcs
In Managarm, the VFS looks roughly like this:
trait Link {
fn getParent() -> Arc<dyn Node>;
fn getName() -> &str;
fn getTarget() -> Arc<dyn Node>;
}
trait Node {
fn open(flags: OpenFlags) -> Result<Arc<dyn File>>;
// Only supported on directories:
fn getLink(name: &str) -> Result<Arc<dyn Link>>;
fn mkdir(name: &str) -> Result<Arc<dyn Link>>;
// Only supported on symlinks:
fn readSymlink() -> Result<&str>;
// ...
}
trait File {
fn read(size: usize, buf: &mut [u8]) -> Result<usize>;
// ...
}
If you're not trolling with this statement: you need an Arc<> when you have shared ownership. There are not always ways to avoid shared ownership. Nor is it desirable. Arc<> is not evil
you have to
hmm
if you have two hardlinks
pointing to the same data on disk
they're pointing to the same struct in memory
the only way that works is with arc
that's not possible if you want to be posix compat, for example because posix has dup()
which is shared ownership of FDs
also for scheduling, both the runqueues and syscall handlers need a reference to the active thread
also, if you open the same file twice, you WANT to share ownership of the underlying data structure as it is otherwise a pain to keep in sync
and shared ownership is generally the best performing strategy there is in that situation
accessing an Arc<> is as fast as accessing a raw pointer
if Linux uses rc for this issue, and arc isn't slow, then why don't you want to use rust over it?
copying it is faster than locking a mutex
fwiw there are crates like arc_swap
but I don't think it's a problem that Arcs are not mutable
I only very rarely needed an atomic Arc and when I did, it was for some niche performance optimization
tooling is still trash
any other c build system
rust OS with 500 line Makefile 🔥
I think one issue of this is that your inode type is too concrete
not all FSes will have this inode structure
that's what redox does
tbh I also don't see why you don't just use cargo
you can't expect to not have a build process just bc cargo is there
makefiles are still common
i mean sure, you need scaffolding on top of cargo
but not using cargo to build the rust files seems weird
Idk why you'd choose something even more painful just because cargo didn't provide every step for you 😭
you do
wdym painful
cargo calls rustc and builds all the stuff, then you use other tools in your makefile
Last time I used C it was 100x worse than using cargo and rust
C with Meson is mostly fine
meson is sane
so idk why youd go with any other language based on "cargo sucks"
it's the whole package
but yeah, cargo is also very good except for very weird cases
like, pathing other crates with cargo is a mess

like what?..
everything is config files
since you usually have committed lock files that don't allow you to do it
cargo is great at everything rust as far as I've seen, what is there to hate
so you need to get into your deps, patch or delete the lock files as well etc
recursively
huh
lock files keep versions
what're you on about
exactly
it doesn't do what i want to do and that pisses me off
what're you wanting it to do?..
dynamic modules
features?
e.g., when we patch something in rustix to make it managarm compatible, we have to patch all users of rustix to include our rustix version
doesn't work
that's not a property of cargo, that's just a property of monomorphization
the way you want it to work is just impossible with templates
the same would be true in C++
you have to write an extern API to make it work
that's not the issue
even if it's rust -> rust extern
._.
it's absolutely a problem with cargo
yes, but you have no real control over how they're built
meson has no issues in that regard
you can either use rust dylib or cdylibs
both should work if all your modules are rust
I don't feel like cargo not doing something it wasn't meant to do is a reason to leave a language altogether
but you do need the explicit extern API
whats the alternative
i don't think any other build system will help you here
well I'm not sure what you want dynamic modules for to begin with
that's one thing i want to have, like no compromise at all
you will need to include the parts of your deps that the module uses inside the module
no matter which build system you use
I'm assuming you want some parts compiled in depending on some flags
conditional compilation is peak in rust
they just have rust interfaces
dynamic as in dynamically linked
shared library
Oh that
like tristate in linux
not dynamic as in can be configured at compile time
so making or using dynamic modules?
both
because rust can target dynamic lib and compile into run, or load them at runtime
the primary issue iirc was how to make it so the user can choose between having a certain module statically linked (compiled in) or dynamically linked
you can either dyn or static
wat
what lmfao
and again, what i have at the moment to experiment with (with meson + c++) does work how i want it to
why don't you just always make modules dynamic?
cargo::rustc-link-search=native=/path/to/library/directory
instead of picking at compile time
you can pick tho ig
you can link shit statically in build.rs
idk why you would but you can
i guess
but you can exploit some features of shared libs if you always link dynamically
i already do
for example, you can give each lib their own symbol namespace
maybe i'm retarded
I think the hard part of Rust vs C when making modules is having a proper ABI
and that is completely independent from the build system
in C if you have a const char *foo(int a, long b), this has a well defined ABI
in Rust you need to do
unsafe extern {
fn foo(a: i32, b: i64) -> &'static str;
}
on the consumer side and
extern fn foo(a: i32, b: i64) -> &'static str {
// ...
}
and the producer side
C (by default, unless you're using attribute visibility) allows you to be sloppy with your external symbols while rust doesn't
clippy my beloved
i think this will just not work at link time if you don't do it
hm
i should try if i can get meson to work with rust
i think the main issue was build-std
if you just do fn foo without extern, rust will pull the code of foo into the consumer crate
there's even a way to make your kernel entry point public and call it from uefi-rs code through an import for whatever reason
forever being pe instead of elf
no matter if you build a dylib or an rlib
😔
and it should, there is no other way to make this work in the presence of monomorphization
since if foo was generic, the producer would have no way of knowing which specializations of foo should actually be built into itself
yes that's true, but that's a not as frequent
a simple hello world module just needs a reference to the loggers
the proper way is still to have a well-defined extern interface
i don't really need that. my modules are always supposed to be used together with the same kernel
rusts symbol mangling makes sure you can't do otherwise
sure but then all your dylibs will still have a lot of shared code
In the worse case, all your dylibs will contain the entire core kernel code
sure but it's unfeasible to wrap every single kernel function that modules may use in an extern C wrapper
i mean i would still like to use rust, but i need to find solutions for the things that are bugging me
rn it's mostly scheduler code
That's what I like so much about Ada, it's super maleable, all the issues I have can just be enabled or disabled at will
https://codeberg.org/Ironclad/Ironclad/src/branch/main/source/pragmas.adc you can have a file like this and enable and disable what you want of the language at will
Feature flags don't do as much
-fno-rtti -fno-exceptions
That's like not what I'm doing
But you wouldn't know because you wouldn't know what the pragmas mean
But things like exception propagation, secondary stack, and dispatch rules are less trivial
What problems does rust give you for the VFS that you mentioned before?
Want to bust
marvin i feel bad for u
😭
no one can understand what ur issue is
i can't articulate it either
even though they've all seen u struggle with that crap
the breaking point was the scheduler issues
i can't for the life of me figure it out
You need a healthy amount of fuck it we ball energy I feel
back to rust?
Why?
core and alloc
A syscall API essentially does that
You don't need to wrap core and alloc
Each module can have its own core and alloc
hel's syscall api also exposes all functions necessary to write drivers, so it's possible to provide such an extern API :^)
just make a storport-like interface for every driver 
all storport drivers are technically only allowed to use the storport api
which is primarily one function with 999 switch cases
but that's because it crosses priv boundary
there's no other way
What is storport?
generic windows interface for modern block devices
all block device drivers use it i think
it also allows you to use NT drivers for nvme/ahci if u implement storport in your kernel
sounds cursed (the strategy of implementing it in your own kernel)
oh well
the main issues i need to solve are memory usage (especially stack) and scheduling
keyronex does it
i'd rather add a linux driver compat layer
u cant really do it since linux doesnt have any stable api
Has any hobby OS ever ported actual accel drivers for modern graphics cards?
idr if managarm nvo actually has accel working
kinda
Managarm does not have accel for NVIDIA yet
Like you could slap a modern radeon card in there and it'd actually get used?
we need to implement fencing for that
nvidia
afterwards, it should work afaiu
I thought there'd be support for AMD before NVIDIA cards because AMD's drivers are open
nvidia drivers have sysdeps
nvidia drivers are also open
You mean you can port it by giving different sysdeps?
yes
and amd drivers are linux-specific
Ah. I see.
its like uacpi but 10 times more complex

Damn. I run a modern RADEON card in my desktop.
Not that I'm close to graphics stuff in BadgerOS but...
gop 
i think the situation for radeon is even worse atm
because it doesnt have a portable driver
it also doesn't have a gsp
on modern nvidia the driver doesnt really do all that much, its just a shim for doing RPC stuff on the card
as it should be
Yeah most of the NVIDIA driver stack was actually userspace right?
Only NVIDIA card I have is a 960 lol
I'll wait until I actually get to a point I need accel before I buy shit
i do it the other way around
i buy funny hardware then force myself into writing drivers cuz sunken cost fallacy
lolol
thats why i got a 5090 
I already had RISC-V booting (as the only one at the time) when I bought that HiFive Unmatched
you do?
yea
crazy
i was just upgrading my pc recently, not really osdev releated tbh lol
back to this i guess
i do need to figure this one out though
if i have a ton of built-in drivers, will this not slow down the compilation process a lot?
because afaict every crate is its own TU
@next cairn this is your time to shine
Whoever told you this is stupid and has no clue about kernel dev
Uhh no. VFS is actually a really good example of you being forced to have something equivalent to an Arc (at least if you want POSIX semantics).
Saying you dont need refcounting because tmpfs exists always is fundumentally misunderstanding how anything works tbh
Also, if you want to avoid getting banned again, don't double down on shit you're not sure about yourself
what the fuck
read above
but I like my brain 
💀 i did too
I really don't see confusion as a banable offense, especially in one of the most confusing topics of programming
Tmpfs was what I thought they were asking about, and me mixing it up doesn't mean "oh my god he's trolling ban him"
good lord
i mean i quite clearly said vfs
yea vfs is absolutely not the same
but what u said is wrong for tmpfs also?
okay
shouldn't it only compile what's changed
unrelated
it still can't parallelize it
afaict
it can compile multiple crates at once
parallelize the compilation?
yes
it can to a point
cargo uses multiple threads by default
yes, but only one crate per cpu
not sure if that's true
just do what I do
make everything its own crate
if i have everything in one crate I'm basically limiting myself
💀
I CANT 
yes
but even if it's all one thing, it shouldn't be recompiling things that haven't changed
never said anything about recompiling
well the initial compilation will always be slow idk what else you could do about that
hm
as most rust issues are
sometimes mold helps, but mold isn't os dev friendly at all so
mold has issues with ld scripts i think
yes that's what I mean
it doesn't support a lot of keywords for them
Well last time I checked, this was on by default for the number of cargo jobs, but you could try setting it yourself and see if it helps
cargo +nightly build -Z threads=8
RUSTFLAGS="-Z threads=8" cargo build --release
"It may be surprising that single-threaded mode is the default. Why parallelize the front-end and then run it in single-threaded mode? The answer is simple: caution. This is a big change! The parallel front-end has a lot of new code. Single-threaded mode exercises most of the new code, but excludes the possibility of threading bugs such as deadlocks that can affect multi-threaded mode. Even in Rust, parallel programs are harder to write correctly than serial programs. For this reason the parallel front-end also won't be shipped in beta or stable releases for some time."
interesting
now I want to try the faster mode myself
it's not like using nightly will be an issue, it's already the only option for os dev 💀
lol
how much is that
I want an EPYC :(
ebay
I actually want to have a threadripper
thery're not really expensive
they're cool
they continued them
and you cant run them in dual cpu mode
yeah but if you're compiling llvm for example you want a ton of cores
because c/c++ is highly parallelizable
this would be like the one machine I could tolerate gentoo on
i'm compiling llvm for my target
tbh i should port rustc too
rn i'm using the debian rust
it would be great if I could stop being in pain and work on my os
you can also make menix PRs
I win
💀
what the hell is that
you couldn't pay me to work on that
I don't
I was working on a decent Thinkpad x1
but I had to sell it
now I'm using some cheaply made but decent spec gaming laptop
yeah no it only uses one core
where's the repo
that doesn't sound healthy
prob not
explains a lot tho
scary
gib star
wtf is the make doing that installs 10k packages
why is make installing any packages
blame for what
fucking stupid fork from a billion years ago
one of the two xorriso implementations is absolute shit
this build system pmo
500 line makefile
it's not even that big
or am i mixing up mkisofs and mkisofs
no i want the 500 line makefile
all I know is that libburnia is ass cancer
Wtf is make doing on bootstrap
i use jinx to build packages
yeah for jinx that is fair
like why is it rebuilding linux-headers
rebuilding?
i just watched something mentioning linux headers 6.11 fly by
yes
because you need linux-headers to compile mlibc
and no you can't use /usr/include
it's not the same
duh
better use the damned cores, you paid for them
i dont think i could contribute to menix if i wanted to 🥀
why
every build is gonna take this pos an hour
PEBKAC
well, in your own words, it should be faster after the first compile 
what
not how it works
you need to explicitly tell it what package to rebuild
like, it can't detect if something changes
Atp 100% serious, start distributing this shit 💀
have your server host ready to use ones
jesus
use axum
just one more build system
I've done that but for a linux distro 🥀
then do it for jinx 
yes but then users and contributors will have the binaries
no
lol
imma have to ask god himself for a pc just to continue os dev
let me guess, no job?
anyway while this is building
fair enough
cargo workspace my beloved
did you put the gdt into its own crate?
yeah
that was supposed to be the goal
"no more os dev boilerplate because 800k crates for the tasks you can't avoid"
so you just end up with crateOS
my goal is mostly NIH
I've already made MakefileOS
i'm not writing a kernel because i think it's linux 2
the best linux distro
i'm writing one because i want to write it once
im wanting one because using anyone elses work feels like i did nothing, until the point of needing to write my own os to feel good
💀
Holy shit
I hate python vs code extensions
Why the hell is the python extension slowing down my computer on a rust project
turn it off?
I do
Then the one time I run into a python project, i turn it on and forget
Every other language pack only activates when the language is actually in use, python just does whatever tf it wants
just stop using python then 
okay TTY time i guess
@near tartan can I get some advice
I never do
it's always someone else's thing
like 10k features in you had to start getting mixed up surely
how do you keep up with what features you're done with and what you want to add
todo!() or // TODO
i usually stub out everything and gradually implment things
also there's usually just one thing i'm doing at a time
also there's a nice TODO Tree extension for vscode that scans your codebase for todo comments

also yea you can see the vast amount of todos in the code
it's a lot
i wonder what linux opens for fd 0-2 for init
how do you get that in rust
it's just an extension
ah
I dunno. Also don't have an easy way to check unfortunately.
same thing
so, no 800 page notion account
todo tree
💔
Actually, yes I can check. Lemme make a Limine entry that sets init=/bin/bash and report back what happens.
the only thing I like about coda/notion is the ability to check blocking tasks to see what's needed first
@near tartan /dev/console (deleted) is what I get
my issue is
With init as bash
"I'm gonna make the next linux" level decision
where I compare what I'm doing to something as daily drivable and useful as Linux
then I overwhelm myself
feature creep
yeah
real
that shit's broken for me 
ragebait lore
/proc/1/fd lore
okay one issue i have at the moment
because everything is basically demand paged, how am i supposed to satisfy a page fault that happens during a syscall, while the current process is being locked
because if it's locked, i can't access its address space
Also that's 100% because your kernel doesn't do anything interesting
rust just requires extra thinking and workarounds for basic things and it's annoying
And its memory model can't model everything a kernel may work with
Mutex for global variables to be extra safe 🤓
either
- more fine-grained locking, e.g. only take the read lock on the mm struct during page faults.
- move accesses to a process' address space outside such critical sections.
- back off from the critical section, fault-in the page, and then try again.
these are IMO all good options.
context is, i have a UserSlice<T> structure, which takes in an address and length. now, to access such a pointer, i pass an address space to it
looks something like this
hm i guess i could map it in as_mut_slice without going through a fault first
ah, so the slice is basically an iterator over userspace addresses
i dunno how i should do this
do i write to the address directly, or do i copy a buffer that's allocated in the kernel?
IIUC file.read(slice) happens without the process lock being held.
yep
and all faults happen during the file.read, don't they?
Possibly slightly orthogonal to what you're asking, but if you're satisfying a read from the page cache, you can grab and hold a strong reference to a page cache page when copying from it into the userspace slice. Then you do the actual copying without holding any lock, then you decrement the mlock count of the page cache page, and thus there is no problem. (This is all internal to the implementation of file.read.)
i'm dumb
read works
openat is causing issues now
because i don't free the lock
hm
what's an ideal way to copy a c string from userspace
make userspace pass the length
good point
if you don't want to do that you need a user_strnlen
and you pass either the max you want to copy or top_of_user_memory-ptr for the limit
linux statically limits it to 4096
nobody was asking you
I'm glad to hear Linux doesn't do anything interesting also, pretty nice
Are you saying your toy kernel is at the same level of capabilities as Linux
No
Linux has rust code infected into it already
Multiple operating systems thatre well known have rust in them
I'm tired of the rust denial cycle 😔
Rust bindings that call into C core is very different from a full rust kernel
It just has memory-model=kernel as a joke also
that's... not the same "memory model"
It can do whatever you want it to now, all the complaints are usually older editions before all the updates
actually not really
there's plenty of examples working fine, hell you're literally in a thread for one
peripherals dont necessarily have coherent caches for example
claiming that Rust can model every possible data structure in safe code is just wrong
and dma can violate &mut invariants unless you are suuuuper careful
its not afaik
it's up to you to make it safe
it can model a vm
same for C
and thus any ds within it too
no there are data structures that can't be made safe in rust
That's not what the safety is supposed to mean
afaik thats not true
you make it safe
btw @next cairn you seem to have the impression that people hate or dislike rust here
they cant be made without crazy perf overhead
if whatever defaults aren't safe and it requires unsafe code
which is not true
you make it safe
I do like rust and i also do rust coding as part of my job
you should see reactions in #lounge-0
for some things, you cannot do so
but it does have limitations
Like what?
mmio?
it's no different than making it safe in C, you have to do it correctly 😭
intrusive data structures?
like a struct Foo that is alive as long as an AtomicU32 in it is nonzero
this is a perfectly safe concept
but it's not expressible in safe rust
this is what i meant originally with inner structs
we're at the point of being able to tell borrow checking to fuck off entirely just to create things
like having Process and InnerProcess
huh
💀

having limitations is also kinda the point of Rust: they ensure that you can't violate Rust's invariants
wat
you can definitely violate them
only in unsafe code
it's just
struct Process {
inner: Mutex<InnerProcess>,
}
struct InnerProcess {...
this just reminded me of the issue where two structs reference each other and are never dropped
(except for unsoundness bugs ofc)
and its very easy to write incorrect unsafe code
yes
writing unsafe rust is way harder than writing C
that's the point
because there are a lot more invariants that you need to care about
like, making a shared memory region is already quite a challenge
because you can at no point in time keep a ref to it
You keep saying this, but what do u mean by safe C exactly?
the same safety rusts unsafe exists for
you still need to ensure thread and memory safety in C
Just because it doesn't force you to write explicitly unsafe code doesn't make it inherently safe
Rust is only worth it if you can contain the unsafety at the module level though
a lot of the time safe wrappers exists
But you can segfault safe rust also
but still a lot of the time, they can't exist
huh
no, you can't
Well I've seen tons of snippets that do
those are compiler bugs
those are bugs
every language has them at some point
yeah they are compiler bugs, no different from llvm miscompiling C code
yeah that's like a shared_ptr cycle in C++ (where you have object A and object B pointing to eachother with shared_ptr<MyClass>s)
compiler bugs 💔
but that's like an entirely different thing
Oh ok
There was even one compiler bug where you could use lifetimes to leak your entire program
🔥
you can leak memory in safe Rust under a good compiler
really?
memory leaks != memory safety
it's supposed to be guranteeing you that it won't leak
well you can also leak on purpose
I guess?
that's usually what they're talking about though
UB and memory leaks
yeah ofcourse you don't want memory leaks in your programs...
there's some shit called BoxLeak iirc
you can leak on purpose in the rare case you need it
is a Box<T> Rust's equivalent to shared_ptr<T>?
if there is a memory leak it shouldn't be an accident tho
you're supposed to know it exists
im not sure
memory leak 'safety' is explicitly not a thing that Rust enforces
Box is just a heap pointer
ah, ok.
unique_ptr iirc
no
you can std::mem::forget a box
or an Arc or Rc
Takes ownership and “forgets” about the value without running its destructor.
it's not the funnest or easiest topic of rust but people have done it a lot
https://github.com/Amanieu/intrusive-rs
forget is not marked as unsafe, because Rust’s safety guarantees do not include a guarantee that destructors will always run. For example, a program can create a reference cycle using Rc, or call process::exit to exit without running destructors. Thus, allowing mem::forget from safe code does not fundamentally change Rust’s safety guarantees.
That said, leaking resources such as memory or I/O objects is usually undesirable. The need comes up in some specialized use cases for FFI or unsafe code, but even then, ManuallyDrop is typically preferred.
Because forgetting a value is allowed, any unsafe code you write must allow for this possibility. You cannot return a value and expect that the caller will necessarily run the value’s destructor.
... so if I have something like:
struct Foo {
Arc<Foo> ptr;
};
and I create some Foos pointing to each other, that's the very same thing as a C++ shared_ptr cycle.
yes
and that does leak memory
kinda
and you're not explicitly writing forget or leak
it even leaks memory if you have only weak refs to it
yeah, weak refs keep the allocation alive
so there's weak reference wrappers for that
they just don't prevent drop from running
Weak is a version of Rc that holds a non-owning reference to the managed allocation.
yes there are weak reference types, but my point is this.
Weak<> keeps the memory allocation alive
e.g., if you store a Weak in something 'static, that keeps the allocation alive
Source of the Rust file library/alloc/src/rc.rs.
both Rc and Weak point to RcInner which is the acutal allocation
Linux only uses rust for some drivers
Also didn't they remove rust or something?
marcan removed themselves
still there in 6.16
big drama because linux maintainers are children
Yea I remember there was drama recently but idk how that ended
basically, marcan left kernel development altogether
so no more upstream work
because they wouldn't merge some changes and acted like kids
static mut files is silly 🤪
RUSTFLAGS="-Z threads=$(nproc) -C relocation-model=static" cargo build 12.75s user 2.14s system 494% cpu 3.012 total
RUSTFLAGS="-C relocation-model=static" cargo build --target 10.83s user 1.39s system 415% cpu 2.938 total
bruh
multithreaded used more cpu and was slower?..
wow no way, if you try to parallelize small tasks it gets slower?
🤯
that's not how it works
that's what you'd like to think