<moon-child>
is a desirable property, I would think
<mrvn>
Or template <typename T> class List { T *next; }; class Derived : List<Derived> { }
<moon-child>
that seems like a much more sensible arrangement
<mrvn>
Wait, that actually compiled. Since when can I use the incomplete type as template parameter?
<moon-child>
(except for that you can only be compile-time polymorphic over the type of your list elements. But I guess c++ does not have real polymorphism anyway so eh)
<mrvn>
yeah, big drawback in C++. If the compiler/linker wouldn't merge identical template instances the code size would explode.
<moon-child>
mrvn: same reason in c I can write struct list { struct list *next; ... }?
<moon-child>
since you are only declaring a pointer, incomplete type is ok
<mrvn>
<source>:2:16: error: 'List<T>::next' has incomplete type 2 | class List { T next; };
<moon-child>
I would guess. Not knowing c++; there may be additional subtleties
<mrvn>
only works for pointers
<moon-child>
well, yeah. I can't say struct list { struct list next; ... } either
<moon-child>
if I could, then 'struct list' would have infinite size
<mrvn>
calling some method on T would fail too I think.
<moon-child>
(except for the degenerate case when there is nothing else, but in that case the whole thing is useless so eh)
<mrvn>
hmm, no. calling methods works too.
<mrvn>
member pointers as template arguments doesn't work.
<mrvn>
can't calculate the offset for an incomplete type.
pretty_dumm_guy has quit [Quit: WeeChat 3.5]
jack_rabbit has joined #osdev
knusbaum has quit [Ping timeout: 255 seconds]
nyah has quit [Ping timeout: 258 seconds]
Griwes has quit [Ping timeout: 276 seconds]
Griwes has joined #osdev
Likorn has quit [Quit: WeeChat 3.4.1]
MiningMarsh has quit [Ping timeout: 276 seconds]
smeso has quit [Quit: smeso]
CryptoDavid has quit [Quit: Connection closed for inactivity]
<klys>
so I got interested in using mmap() with MAP_32BIT to allocate a chunk of ram and execute a program within that chunk. as I understand it, I may need a VDSO in order to do that.
sonny has joined #osdev
<klys>
as the program would be running within a 64bit framework, I'm not sure how to interface with the linux kernel from within there
<klys>
safe assumption is I have 32bit code to run and would like to interface with the rest of the program (outside mmap()) which uses 64bit syscalls. this question however relates to 32bit syscalls.
<bslsk05>
gist.github.com: Example of calling into the kernel vdso directly · GitHub
osmten has quit [Quit: Connection closed for inactivity]
zaquest has quit [Remote host closed the connection]
zaquest has joined #osdev
MiningMarsh has joined #osdev
<klys>
I've been reading code and the answer to my question is probably no, given that kaslr returns a 64-bit value as the vdso address to the parent process.
<klys>
so, you can't have 32-bit vdso if you just mmap() and call 32-bit code.
<geist>
word
<klys>
:)
<geist>
well, dword actually
<klys>
in related news, you can get those numbers in $ cat /proc/self/auxv | xxd -ps
<klys>
or even try $ LD_SHOW_AUXV=1 cat /proc/self/auxv | xxd
<klys>
taking a closer look at the output of the above cat|xxd command on 32bit and 64bit linux, it produces a 32bit value for .AT_SYSINFO_EHDR
<klys>
in both cases
archenoth is now known as arch
<klys>
scratch that
* AmyMalik
dies
vdamewood has joined #osdev
the_lanetly_052 has quit [Ping timeout: 240 seconds]
vinleod has joined #osdev
vdamewood has quit [Ping timeout: 255 seconds]
Likorn has joined #osdev
vinleod is now known as vdamewood
sonny has quit [Remote host closed the connection]
ketan has joined #osdev
ketan has quit [Quit: Leaving]
ketan has joined #osdev
Likorn has quit [Quit: WeeChat 3.4.1]
bauen1 has joined #osdev
GeDaMo has joined #osdev
Brnocrist has quit [Ping timeout: 240 seconds]
ketan has quit [Remote host closed the connection]
Brnocrist has joined #osdev
Brnocrist has quit [Ping timeout: 256 seconds]
Brnocrist has joined #osdev
ethrl has joined #osdev
kingoffrance has quit [Ping timeout: 265 seconds]
GeDaMo has quit [Read error: Connection reset by peer]
GeDaMo has joined #osdev
GeDaMo has quit [Client Quit]
kingoffrance has joined #osdev
GeDaMo has joined #osdev
<dostoyevsky2>
What kind of OS is AWS?
<GeDaMo>
Is AWS not based on some VM system?
<dostoyevsky2>
you mean, like lambda?
<GeDaMo>
I don't know what Lambda is in this context
<dostoyevsky2>
I guess the standard one if KVM
<GeDaMo>
Yeah, that's the sort of thing I was thinking of
<dostoyevsky2>
lambda uses an application kernel like firecracker or gvisor
<j`ey>
firecracker uses kvm
<dostoyevsky2>
But cloud providers seem like a distributed OS.. where you can allocate CPUs/hardware and store your data in distributed consensus stores for queues/object storage/databases
kingoffrance has quit [Ping timeout: 265 seconds]
jafarlihi has joined #osdev
<jafarlihi>
Hey. I've got this OS: https://github.com/jafarlihi/HikmatOS/ . The issue is when I do fork() I need to init_irq() again because interrupts stop working. Any idea why would fork cause this?
<Mutabah>
You forgot to `sti` or (or pop flags with IF set) in the new context
<jafarlihi>
Mutabah: Doesn't `sti` alter the flags? Is pop required?
<bslsk05>
github.com: HikmatOS/task.c at master · jafarlihi/HikmatOS · GitHub
pretty_dumm_guy has joined #osdev
CryptoDavid has joined #osdev
<jafarlihi>
I tracked it down to `irq_remap`, running it in forked process fixes the issue. No idea why, any ideas?
nyah has joined #osdev
jafarlihi has quit [Quit: WeeChat 3.5]
sympt has quit [Read error: Connection reset by peer]
sympt has joined #osdev
jafarlihi has joined #osdev
jafarlihi has quit [Ping timeout: 246 seconds]
rpnx-phone has quit [Ping timeout: 260 seconds]
blockhead has quit []
ketan has joined #osdev
jafarlihi has joined #osdev
<Mutabah>
j`ey: I was guessing
<Mutabah>
probably should have said that
<mrvn>
klys: Look at x86_32
theseb has joined #osdev
theseb has quit [Client Quit]
theseb has joined #osdev
<theseb>
What do people think of Fuchsia OS? If I was a budding kernel hacker it seems that would be the most promising to study. Downside....C++ instead of C. However microkernel and security primitives seem elegant
<mrvn>
upside: C++ instead of C.
<theseb>
bah humbug
xenos1984 has quit [Read error: Connection reset by peer]
<theseb>
mrvn: what about Go? Is that good for an os?
<mrvn>
never used go. Rust is popular outside of C/C++.
<mrvn>
ocaml (look up mirage) is good too
<theseb>
mrvn: yea...Rust would have likely been good....but ffs...c++? srsly?
<mrvn>
It has a safer typesystem than C, namespaces, RAII, ... Just leave out RTTI and exceptrions.
<theseb>
mrvn: yes....i've heard of that strategy...if you can somehow enforce a good *subset* of C++ you might have a decent language
<theseb>
mrvn: hopefully google is doing this for Fuchsia
<mrvn>
and that's exactly what everyone does when using C++.
<theseb>
mrvn: really? that's great to hear...i have new hopes for C++ then
<theseb>
mrvn: however, i imagine very new software shop has a *different* subset they believe in so you end of having to learn all of C++ anyways?
<mrvn>
RTTI and exceptions need extra (and a bit complex) work to setup. So when you start your kernel basically everyone just disables them.
<theseb>
every*
<mrvn>
Also you don't have the STL in freestanding mode. So that cuts down a lot too.
<theseb>
yea i have no desire in learning stl
<theseb>
mrvn: what is freestanding mode?
<sbalmos>
no userspace lib
<mrvn>
theseb: same as freestanding in C. Removes the userspace libs and only gives you the core language features.
<theseb>
interesting
<mrvn>
no memcpy(), strcat(), or in C++ no STL
<mrvn>
freestanding is the core languzage that you can expect to work everywhere, especially naked hardware.
<mrvn>
i.e. your good subset (except you reduce that even further by removing RTTI and exceptions usually)
<theseb>
mrvn: i think you just made me a C++ fan
<sbalmos>
you'll have to write some additional boilerplate ASM code to execute any static initializers before jumping into your C++ kmain, and you'll have to provide impls for new, delete, and I'm trying to remember what other?
<theseb>
err a "C++ subset" fan
<mrvn>
You probably want the initializers for C too anyway. As for new/delete. If you need them the compiler will tell you.
<jafarlihi>
How do you store the actual location (file bytes) of inode in the backing device?
<mrvn>
what's an inode?
<jafarlihi>
It stores name and other crap
<jafarlihi>
What about actual location?
<Mutabah>
inode locations are specified by the specific FS's spec.
<jafarlihi>
So in FS impl you have a map of inodes to actual locations?
Vercas9 has joined #osdev
<mrvn>
jafarlihi: or not
Vercas has quit [Quit: Ping timeout (120 seconds)]
Vercas9 is now known as Vercas
<Mutabah>
a map, or a mapping equation
<mrvn>
bttrfs just uses the address as inode number.
<Mutabah>
ext2+ have inode number be indexes into a fragmented table
<mrvn>
ext4 has inode tables and the inode number is the index in the table.
<mrvn>
tables have the problems that they might become full.
<jafarlihi>
How do you assign unique inode numbers?
<Mutabah>
FAT doesn't have "inodes", so it's up to your driver how it makes inode numbers
<mrvn>
by knowning what's free
xenos1984 has joined #osdev
<mrvn>
FYI: inode numbers aren't unique. FSes usualy also have a generation number in the inode so they can make them unique even when reused.
<sham1>
That sounds pretty unique to me
<zid>
return 7l
<zid>
s/l/;
<zid>
That's unique at *least* once
<sham1>
return 4; // Randomly selected
<jafarlihi>
For directory inode, how do you store the list of children? Just a list in inode structure?
<sham1>
Anyhow, reuse via a generation number could easily be seen as creating a unique "inode" even if that's technically not what happens
<sham1>
jafarlihi: yeah, (at least on ext2+) the directory inode points to blocks which contains a bunch of "directory entry" records
<mrvn>
jafarlihi: a directory is just a file
<mrvn>
formate specified by the FS
theseb has quit [Quit: Leaving]
<sham1>
In fact, in the Good Old Days^{TM}, you could even open(2) a directory and access its files that way
<sham1>
That's even seen in the UNIX Programming Environment-book by Kernighan and Pike
jafarlihi has quit [Ping timeout: 256 seconds]
<mrvn>
sham1: It's fun writing your own "ls" by opening the dir and interpreting the data.
<mrvn>
I think it no longer works with tree based filesystems. Since they don't exactly store directories as files anymore.
<mrvn>
all the COW filesystems
haliucinas has quit [Ping timeout: 260 seconds]
CryptoDavid has quit [Quit: Connection closed for inactivity]
vimal has quit [Quit: Leaving]
childlikempress has joined #osdev
sebonirc_ has joined #osdev
moon-child has quit [Remote host closed the connection]
sebonirc has quit [Read error: Connection reset by peer]
sebonirc_ is now known as sebonirc
jafarlihi has joined #osdev
<jafarlihi>
What data structure would you use for keeping pointers to child inodes in the parent directory inode?
<mrvn>
BTree
<mrvn>
Hashtbl
<mrvn>
depending on whether directories are files (Hashtbkl) or not (Btree)
<jafarlihi>
How do you use hashtbl? Filename as index and inode pointer as value?
<mrvn>
yes, that' how ext3 does it
<jafarlihi>
cool, thanks
<mrvn>
You also need to store the filename in the directory.
<mrvn>
so actually you have hash(name) as key and {offset of name, inode} as value.
<mrvn>
or the hash table just points to buckets and buckets have dynamic size to contain the name.
<jafarlihi>
I think I'll just use a linked list
<mrvn>
jafarlihi: decades of experience have shown that to be horribly slow. But it's what they used to do because it's so simple.
<jafarlihi>
Not worrying about speed yet
<mrvn>
s/linked list/buffer containing direntires of variable size and you have to parse through all of them to find the right entry/
<mrvn>
jafarlihi: are you talking about the in-memory representation or the on-disk format?
<jafarlihi>
in-memory
<mrvn>
don't you have a std::map<name, inode*> equivalent?
<jafarlihi>
No
<mrvn>
then maybe take a break and implement a set of standard containers. List, array, vector, hashtbl, set, map.
<sham1>
rb-trees
<sbalmos>
bah, just implement a ring buffer. unlimited capacity
<sham1>
Unlimited capacity!*
<sham1>
*: Terms and conditions apply
<mrvn>
sham1: not avl?
<mrvn>
lets give him a challenge
<sbalmos>
I haven't done an avl tree in 18 years. :/
<sham1>
RB-trees are certainly easier at least for me personally than AVL
<sham1>
Personally my biggest gripe is that there really aren't any good test cases online
<sham1>
Like for verifying that an RB-tree is implemented correctly
jafarlihi has quit [Ping timeout: 246 seconds]
<mrvn>
sham1: you want a online site that gives you a unit test to implement against and then runs it?
<sham1>
I mean, that's one way. I suppose I could also use an existing implementation to get a test vector
<mrvn>
there is leetcode and similar sites that give you coding challanges.
<mrvn>
basically the sam thing. Just change the assignments to be more generic
<mrvn>
Is there a `realloc` that fails if it has to copy the data?
<j`ey>
with objcopy -O binary.. does it keep the bss as a section full of zeros?
<mrvn>
no, but any holes you have.
<mrvn>
i.e. put .bss at the end
<j`ey>
so if it's not at the end, it will keep it then?
<mrvn>
anything NOALLOC will be skipped
<j`ey>
because my binary seems quite big, feels like the bss is in there
<mrvn>
j`ey: dump the symbol and check where _bss_start and _bss_end is.
<mrvn>
_bss_start - _start should give you the filesize.
<j`ey>
good idea
<j`ey>
hmm somehow I think that my bss is overwriting the fdt, I just cant understand how/why
<jafarlihi>
What does "opening" a file mean in VFS level (not fd)? Is it just no-op for ramfs?
<mrvn>
increment the reference counter
<jafarlihi>
Why do we even need a ref counter there?
<zid>
fd isn't just for ref counting
<zid>
it's so you can actually know what to do when read() etc happens more usually
<zid>
unless you want to completely rewalk your devices and filesystems every time someone does read() it may be wise to cache that
<zid>
plus the file position pointer
<mrvn>
j`ey: because someone can unlink() the file while you have it open.
<zid>
and you may end up doing things like needing to invalidate memory mappings for memory mapped files at close time etc, all that needs to be tracked so it can be undone
<mrvn>
I see std::for_each but no std::fold_left. Isn't there a for_each where an accumulator gets passed along?
CryptoDavid has joined #osdev
* geist
yawns
<geist>
good morning everyone
<jafarlihi>
good morning
<jafarlihi>
it's evening here
<geist>
yay time zones
floss-jas has quit [Ping timeout: 255 seconds]
<jafarlihi>
Can GitHub take down your repo if someone reports license violation (copy pasting from random projects)?
heat has joined #osdev
<sham1>
mrvn: std::transform?
ethrl has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<sham1>
Or std::reduce
<mrvn>
sham1: no, std::accumulate. But that doesn't seem to have range support
<sham1>
Although that is in <numeric>
<sham1>
Ah
<sham1>
Hm
<sham1>
Eh, doesn't seem that bad to implement
<mrvn>
wait, what's the difference between accumulate and reduce?
ethrl has joined #osdev
ketan has quit [Ping timeout: 256 seconds]
heat has quit [Remote host closed the connection]
heat has joined #osdev
<GeDaMo>
Apparently reduce can be out of order
<sham1>
According to cppreference: "in other words, reduce behaves like std::accumulate except the elements of the range may be grouped and rearranged in arbitrary order"
<sham1>
Yeah
<mrvn>
yeah, seems to just add an execution_policy
gildasio1 has quit [Quit: WeeChat 3.5]
<geist>
oh yay, finally got a smoking gun on my ryzen crash: a 3900x in the same server motherboard as the 3950x that was failing also fails
<geist>
so cpu is off the hook
<geist>
more predictably it's probably the motherboard
CaCode has joined #osdev
wootehfoot has quit [Read error: Connection reset by peer]
heat has quit [Remote host closed the connection]
heat has joined #osdev
<zid>
moar volts
<chibill>
I sort of want to try and write my own file system just for the fun of trying. (I still don't have my OS doing anything but Hello World. Since its more of a side project as I work on a homebrew computer system.
<chibill>
* computer system.)
aejsmith has quit [Remote host closed the connection]
aejsmith has joined #osdev
heat has quit [Ping timeout: 244 seconds]
jafarlihi has quit [Quit: WeeChat 3.5]
dmh has joined #osdev
<geist>
chibill: yeah i think it's pretty fun. the designing part is fun
ethrl has quit [Ping timeout: 246 seconds]
jstoker has quit [Remote host closed the connection]
jstoker has joined #osdev
blockhead has joined #osdev
CaCode has quit [Quit: Leaving]
dude12312414 has joined #osdev
<zid>
Time for my yearly emerge --sync --break-everything-now
<zid>
--python-especially
vdamewood has quit [Quit: Life beckons]
<sham1>
Call it a hunch, but I think it's due to you doing it once a year
<sham1>
Ye need to roll the release more often
<zid>
how dare you
<psykose>
it's much more fun to break everything once a year though
dude12312414 has quit [Quit: THE RAM IS TOO DAMN HIGH]
GeDaMo has quit [Quit: There is as yet insufficient data for a meaningful answer.]
psykose has quit [Remote host closed the connection]
psykose has joined #osdev
jafarlihi has joined #osdev
rpnx-phone has joined #osdev
gildasio has joined #osdev
<Ermine>
Breaking gentoo by updating once a year?
<mrvn>
Ermine: well, it takes that long to compile, doesn't it. :)
<zid>
1 of 237, it doesn't have unresolvable blockers :o
<jafarlihi>
Would you say doing OS development is harder than compiler development in general, or just about the same, or easier?
<mrvn>
yes
<geist>
probably easier
<geist>
if nothing else because there's a lot of helpful material out there
<geist>
ie, it's a very well trodden path, ad there's people like here that will talk about it and help you, etc
<geist>
but then 'os development' is a very wide field, of huge varieties of complexity
<geist>
though compiler as well
<zid>
yea it's just wide
<sham1>
I'd say that compilers is different kind of difficult
<zid>
compiler once it 'works' is about increasingly complex things
<geist>
yah
<sham1>
Although I'd say that just doing a dumb compiler isn't *that* difficult, the difficulty comes in making it good. Now of course, same could be said about OSes, although OSDev has a lot more busywork to get all the devices to work and such
<geist>
yeah, OTOH the busywork has i think in general a lot more resources available in the form of tutorials and emulators and whatnot
<sham1>
Yeah, well, compilers have LLVM
<geist>
so it's a tradeoff. but a lot of it also is how well acclimated you are or flexible abut working with low level stuff (bit twiddling, etc)
<geist>
and some folks have toruble bridging that gap
jafarlihi has quit [Quit: WeeChat 3.5]
<zid>
they'd have even more trouble with a compiler then :P
<mrvn>
Now write an OS that lets you input source and it compiles and executes it.
<zid>
"I fucked up all the memory barriers in my osdev" -> "I had to write code to programatically deduce where barriers are necessary for my compiler"
<zid>
the latter is a superset of difficulty of the former
<sham1>
mrvn: I've actually thought about doing that unironically. Some kind of a modern Lisp machine
<geist>
sure, but i mean you can generally rely on higher level language constructs you may be used to
<geist>
whereas OS work you sometimes/frequently have to fight the language itself
<geist>
or use a language you're not used to
<zid>
That just makes the compiler even harder compared to the osdev
<mrvn>
a lisp machine in lisp is realy simple.
<mrvn>
zid: how about making up the language as you write the compiler?
<sbalmos>
image-based runtime environment, like Smalltalk
<bslsk05>
github.com: lk/platform.c at master · littlekernel/lk · GitHub
<graphitemaster>
(&array[i])[1] is definitely undefined behavior
<graphitemaster>
The whole rules about array-types in general basically prevent any sort of stuff like that.
<mrvn>
geist: It's not const: declare sdb as pointer to const volatile struct rosco_system_data_block
<geist>
oh yeah. you're right, i was just thinking about that
<mrvn>
Having a volatile const doesn't make much sense.
<mrvn>
You have to read it but it must give you the same value every time?
<geist>
indeed
<geist>
anyway, it fixed the bug, otherwise if you just try to create a local pointer to something at 0x400 the compiler says it's a null pointer blahlbha
<mrvn>
declare sdb as const pointer to volatile struct rosco_system_data_block
<mrvn>
Isn't that what you want?
<geist>
yes yes i get it
<geist>
yes
<geist>
i thought that the moment i pasted it, like 'shit i think that's not the const i expected'
<mrvn>
*jipey* I fixed my first bug in LK. :)
<geist>
basically i kept adding shit until the problem went away
<geist>
somehow adding the const i think fixed it
<geist>
or the volatile
<geist>
i dunno, i was just trying to get the compiler to quit warning at me about something that shouldnt have warned me
<mrvn>
The lack of *const should fix it
joe9 has joined #osdev
Likorn has joined #osdev
<geist>
what i was really trying to get it to do was not roll a variable that it then derefed, so what was even weirder is even though that variable isn't const, it actually compiled it out in the disasm
<geist>
which is head scratching, since it should have assumed something external could mess with it
<mrvn>
Does rosco have special protextion for the first 0x400 byte like Amigas have?
<geist>
no
<geist>
its just the firmeware having had tossed down some data structures < 8K
<geist>
i was all else held equal going to treat it like a const thing since i had no intention of writing to it
<mrvn>
is the firmware/hardware going to write to it?
<mrvn>
I just realized that "const volatile" only means you can't write to it but it can still change.
<mrvn>
C/C++ really lacks an immutable qualifier.
<geist>
right. that's really my intention
<geist>
ie, please read from this it might change, but i dont want to write to it
<geist>
ow that i think about it more it's actually what i was trying to do
<geist>
and i had to run it through a non const pointer because that fooled the compiler into not assuming it's a fixed variable
<mrvn>
I really hope they fix that soon in gcc
CryptoDavid has quit [Quit: Connection closed for inactivity]
<geist>
you can of course just nerf the warning, but it *can* catch some good stuff
<geist>
it's just that it gets hoovered up into this 'also try to catch null pointer' stuff
<geist>
worse, it's optimization based. the compiler has to have sufficiently high optimization levels to try to see through the code enoguh. so -O0 wont see it
<mrvn>
-O0 should just be removed. It never ever makes sense to use.
<geist>
it's certainly not useful to me
nj0rd has quit [Quit: WeeChat 3.5]
netbsduser` has quit [Read error: Connection reset by peer]
nj0rd has joined #osdev
<mrvn>
Sometimes I want -O0 + register allocation.
xenos1984 has quit [Read error: Connection reset by peer]
<mrvn>
or even just eliminate all pairs of "store to stack, read from stack"
xenos1984 has joined #osdev
X-Scale has quit [Ping timeout: 258 seconds]
gildasio1 has joined #osdev
<mrvn>
Have you ever used a function-try-block? struct A { ~A() try { /* something */ } catch (const std::exception& e) { /* something */ if (no_terminate_on_exception) return; } };?
gildasio has quit [Ping timeout: 240 seconds]
<mrvn>
It's C11 but I've never seen it till today.
joe9 has quit [Read error: Connection reset by peer]
joe9_ has joined #osdev
X-Scale has joined #osdev
heat has joined #osdev
<heat>
mrvn, i've done that yes
<heat>
it's very nice
<mrvn>
it's odd that it re-throws the exception on it's own.
<mrvn>
(unless you return in the destructor)
<heat>
it does?
<heat>
fuck you just ruined the feature for me
<mrvn>
>
<mrvn>
Reaching the end of a catch clause for a function-try-block on a destructor also automatically rethrows the current exception as if by throw;, but a return statement is allowed.
<heat>
oh, destructor
<mrvn>
> Every catch-clause in the function-try-block for a constructor must terminate by throwing an exception. If the control reaches the end of such handler, the current exception is automatically rethrown as if by throw;. The return statement is not allowed in any catch clause of a constructor's function-try-block.
<mrvn>
In the constructor what is the compiler supposed to do otherwise? The object you created has already been destroyed. What should happen if it just returns?
gildasio1 has quit [Quit: WeeChat 3.5]
<heat>
why has it been destroyed?
<mrvn>
> Before any catch clauses of a function-try-block on a constructor are entered, all fully-constructed members and bases have already been destroyed.
<mrvn>
The construction threw an exception, you don't have a valid object. So it gets destroyed.
floss-jas has joined #osdev
<geist>
yah the rules of exceptinos in constructors/destructors i never understood
<geist>
but then, i dont think i've ever worked in a project that actually used c++ exceptions
X-Scale has quit [Ping timeout: 246 seconds]
<mrvn>
Say I have struct A { A() try : x{}, y{} { } catch (const std::exception& e) {} X x; Y y; } and y{} throws an exception and the x::~X() throws an exception will that enter the catch block twice?
X-Scale` has joined #osdev
<mrvn>
or not at all since ~X() terminates?
X-Scale` is now known as X-Scale
<mrvn>
geist: You kind of can't use inheritance then for anything with error handling.
<heat>
you can't do non-trivial work in constructors in noexcept code
joe9_ has quit [Read error: Connection reset by peer]
<heat>
that's pretty firmly banned in google C++
<mrvn>
I kind of whish that constructors would `return *this;` like operators. Then `return nullptr` would signal an error.
<heat>
that wouldn't work
<heat>
they would have to 'return this;', not *this
<mrvn>
`return this;` I mean
<heat>
more inconsistency? no ty
joe9 has joined #osdev
<geist>
there was some mention a whie back as to 'why is this a pointer and not a reference' which i thought was kinda intersting
<geist>
the main reason is references hadn't been implemented yet
<mrvn>
geist: historical, this was invented before references.
<geist>
but actually would be interesting if this was a reference
<clever>
my rough understanding is that `new` is just malloc + constructor
<mrvn>
it is
<clever>
so the memory would have already been allocated, and you would need to detect that error and then turn around and free it
<mrvn>
as it does
<clever>
what about just using exceptions?
<clever>
have the constructor throw?
<clever>
and the catch block will deal with free as it already does
<clever>
and/or finnally
<mrvn>
needs a bunch of extra runtime support
<clever>
ive not actually looked into what that involves
<clever>
does the osdev wiki say?
<mrvn>
Me neither. I just saw the missing symbols when I forgot to disable exceptions.
<geist>
not sure it needs that much else, maybe just some stuff effectively like pure virtual
<geist>
where you need the falback thing
<heat>
you need a function that allocates exception
<heat>
__cxa_allocate_exception or whatever that's called
<heat>
plus RTTI
<mrvn>
The thing is that everywhere else you can use std::optional for example. But for constructors there is no other way but exceptions to fail.
<heat>
and then the stuff that makes it walk the calling stack
<mrvn>
stack unwinder
<heat>
right
<heat>
uga booga very late here
<mrvn>
That part is probably the hardest
<heat>
std::optional is a poor return type
<heat>
I use andrei andreescu's expected<Type, ErrorType> quite a lot
<heat>
it's a fancy optional
<mrvn>
or std::variant
<heat>
std::variant is non-trivial
<FireFly>
sounds like an Either
<clever>
mrvn: would libgcc provide the stack unwinder, or is it something you have to provide yourself?
<heat>
clever, libgcc would
<clever>
i feel like its gcc's responsibility, given that gcc is what manages the stack
<mrvn>
clever: I would say gcc has to. It's winding up the stack.
<heat>
wait hrm
<heat>
that's libunwind
<heat>
does gcc put libunwind into libgcc? i think so