#OBOS (not vibecoded)
1 messages · Page 40 of 1
500k download speed for managarm servers 🥀
im tryna see if managarm's xhci driver will work here
ok the speeds boosted
well managarm works
ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
i fucking hate reading C++ code
"ah yes let me have code implcitly call other code and make it hard to track what variables are defined where because FUCK YOU"
looking forward to having obos to read when i eventually get to usb specifically so i wont have to read c++ lmao
lmao
reading c++, linux, or bsd source code drives me insane
bsd source being the least out of the three
although reading obos source code under src/oboskrnl/arch/x86_64 makes me believe I was insane when I wrote it
I wrote like all of the x8664 thing in 2024
and had barely any idea how anything worked
so like now nothing works on a lot of real hw
because bah dumb reasons
least what?
least unreadable
ah
it's also just as bad to write
no clue how the upstream maintainers do it without wanting to rip their hair out
clang-format, duh 
man I fuckin hate this city's transit
buses are always late
but the ONE day I am late, it is early
and dont forget the next bus is in 20 minutes
@dense vigil can u get the bus to hurry up pls
this should help
ok thx
I realize it's not technically nsfw but it's supposed to put the same image in your mind
It's okay ❤️
I had my finger over that section of the gif (I'm on mobile) and legitimately thought it was just... that
Mainly the source clip context is horse riding the human like a horse and not in that connotation
😭
Take this replacement gif
time to continue trying to fix xhci because damn me i guess
why the fuck is the xhci controller putting the same trb on the event queue twice
ok better question is why is the xhci controller seeing the same trb twice
im dumb
lol
i forgot to update the dequeue pointer when sending the address device for the 2nd time (after sending a command in between)
we all are
xhci is cursed
does get descriptor request
device, nah take USB Transaction Error instead
is it possible that these usb2 ports are under control of ehci
why do i have to get all the bad errors
I wonder what Linux reports under this?
Or managarm/BSD
managarm works
perfectly fine
with passthrough enabled
tbh
i never got port reset to work on this hardware
when not doing passthrough
maybe that has something to do with something
as in, when doing a raw obos boot
today I am going to revise the entire xhci controller init sequence
sudo rm -rf ./repo
git pull https://microslopgithub.com/oberrow/OBOS
hard xhci reality
-16 celsius and its getting worse every minute 

same here in southern ontario
apparently in some places in ontario it's gonna reach -50
(not here thank god)
W H A T
yea
Dangerously cold air swept across parts of Ontario early Saturday morning, with wind chills nearing –40 degrees Celsius in northern areas.
yesterday my toe nearly froze off
i think
it still hurts
i had to shower in hot water after coming home from school
the weather is insane
i think i got a cold as well
its so cold the sun cant even be a deadly lazer anymore
real
which stuff obos have ported
(how many of those ports work? don't ask me, i wouldnt know
)
you have audio supportt ?
yes
is this hard
i want do audio stuff later for my kernel so
which api you implemented
my own™
im planning to eventually add downstream support for my audio server protocol to sdl and stuff
so shit that uses sdl for audio can work
isnt oss and pulseaudio (i have no idea can this be started with mlibc) better
(i should port SDL2, and also enable the windowing stuff in sdl)
xhci isnt real omfg
sdfkjsdfksdo
there are 10 ports on the controller
on the root hub
ZERO RESET SUCCESSFULLY
FSDOKGJSDLKFMSDOKFDMSLFKSDMF
atp it has to be the ehci ctlr trolling me
dont even need to say the unit when its -40 lol
good luck with your usb hell
i think ive been cursed by the lord himself for usb, no one can save me now
This requirement means that Root Hub port may report a device is connected
(CCS and CSC = ‘1’) before the xHC is running (i.e. HCHalted (HCH) = ‘0’), and that
when software enables the xHC and HCHalted (HCH) transitions to ‘0’, PSCEG
shall be asserted for each port with a connected device, generating a respective
Port Status Change Event. In this case
what a fucking lie
rtfdg,l;fedmdksgl;gjmdsf
It’s going near -60f for my friend
And he still has to goto school

damn that's cold
This is America too iirc
I think my API would just be pumping PCM samples into a file lmao
They are doing doctor shit or science shit idk
But like really fucking advanced shit I think
a lot of states are a further north then south eastern ontario

where like the entire country lives
i truthfully have no fucking idea what the problem is
i am literally about to give up
what do you think ive been doing 😔
You gotta bull the shit even harder
did you poke the right bits in the pci config space to toggle the ports
elaborate
do you mean in teh ehci controller thing?
void switchUsbPortsToXhci(PciDevice *dev) {
debugLogger() << " Switching USB ports to XHCI!" << frg::endlog;
auto io = dev->parentBus->io;
auto usb3PortsAvail = io->readConfigWord(dev->parentBus, dev->slot, dev->function, 0xDC);
io->writeConfigWord(dev->parentBus, dev->slot, dev->function, 0xD8, usb3PortsAvail);
auto usb2PortsAvail = io->readConfigWord(dev->parentBus, dev->slot, dev->function, 0xD4);
io->writeConfigWord(dev->parentBus, dev->slot, dev->function, 0xD0, usb2PortsAvail);
}
let me try that
on intel chipsets
with ehci
usb ports are muxed between xhci and ehci, and you can toggle it
if this works i might donate a buck to managarm
fak
it didnt work
😔
uint64_t usb3_ports_available = 0;
uint64_t usb2_ports_available = 0;
DrvS_ReadPCIRegister(dev->location, 0xdc, 4, &usb3_ports_available);
DrvS_WritePCIRegister(dev->location, 0xd8, 4, usb3_ports_available);
DrvS_ReadPCIRegister(dev->location, 0xd4, 4, &usb2_ports_available);
DrvS_WritePCIRegister(dev->location, 0xd0, 4, usb2_ports_available);
oh wait this needs to be done on an xhci controller
grepogijrd
it got further
kinda
some ports now report CCS
uh nvm
i dont have a dollar to my name
What’s a CCS btw lmfao
current connection status
That’s good I presume
yes it means a shit is connected on the port
i think the reason it got further than port reset on linux with passthrough is because the linux kernel already did this
is this a dutch word
perhaps
usb device passthrough is very far removed from actual hw
no i did xhci controller passthrough
ah
now time to figure out why the driver hangs after port reset 
could be both, even
well all i know rn is that im not getting any goddamn irqs
so now it decided it doesnt wanna work anymore
What if USB is actually implemented with quantum mechanics and the only way to be able to make a working driver is to be ordained by the gods and or to be in the proper super position at the time
You may need to do some head clips into a block to get your sub pixel correct
then i would be able to diff between now and then
Like super Mario bros style
so uh for some reason usb hotplugging stopped working everywhere
my next commit will be something to the likes of: "xhci: fix bugs on real hardware", +2000 additions, -5000 deletions
January 24th, 2026, at 1940: xhci has progressed a bit further, I am still going crazy from this
https://github.com/OBOS-dev/obos/blob/xhci-driver/src/drivers/generic/xhci/xhci.c#L463
what if the xhci pushes enough trbs to wrap around?
i told myself i would fix it
but im having problems with the first trb
also i have some new code
so let me push that
(meaning, i am aware of the bug, and i will fix it)
ah
i just pushed like 750 changes
another thing is that checking USBSTS.EINT for interrupt pending is not correct if you use MSIs, because iirc the interrupter IP is automatically cleared after the write that triggers the MSI
oh
actually hm, EINT is RW1C so it's only ever set by the controller
still i wouldn't use it and just check the specific interrupter
in managarm we check ERDP.EHB since that has to be cleared by software after it's done processing stuff from the event ring
ok ill try that
technically with MSI you don't need to check anything since you shouldn't share them and spurious ones shouldn't happen either™
im gonna share them anyway whats the worst that could happen
well the problem is that they're edge triggered
so you can lose them if multiple happen and you have them masked at the time
i see
ill fix that in a second, rn the only driver i am running is the xhci driver so other devices shouldn't be a problem™
oh well time to open managarm code
because well ig damn me, i get interrupts with xhci passthrough on this hardware
(and i also get trb completion code 0x4 because usb has damned me)
usb transaction error my beloved
managarm also gets it when trying to talk to stuff behind hubs
and i haven't figured out why yet
although i got some new equipment to try and debug it (cheap usb protocol analyzer from china based on an open source design), but i haven't had the time to do it yet
gl
i think im gonna do some polling on the event ring to see if it's an interrupter problem or something else
I wonder if there is a good way to test MSI/X seperate from the USB controller
Like a QEMU device to write to an IO port and it gives you an MSIX
AHCI

anyway this xhci controller uses MSI
and it seems to not be an interrupter problem
ok so no matter what i set the cycle bit to
it doesnt recognize my trb
msi the company 
omg
i just want an irq
is that so much to ask for, xhci controller
are you really that lazy, xhci controller
sdflkgsndflksdnfs
i have to do all OHCI, EHCI and then XCHI at some point 
Shhhh you don’t need OHCI
Nobody needs usb 1.1 as the main controller
powerpc ibook
Fuuuuckkkkk
wait until you hear about ehci companion controllers
oh no
ehci forces you to implement a UHCI or OHCI controller driver for support for older usb devices
XHCI handles USB1, USB2, and USB3 under the same thing
but intel wanted to be lazy with EHCI and decided "have the OHCI or UHCI controller do it"
USB is insane, I tell you
Who the FUCK invented this
Who the FUCK did this so I can strangle them when they sleep
dumbasses at intel and some other dumbasses at other companies
i dont care if microsoft had anything to do with this or not
Ajay V. Bhatt is an Indian-American computer architect who produced several widely used technologies, including USB (Universal Serial Bus), Platform Power Management architecture, and various other chipsets.
In January 2025, he was honored with the Padma Shri, India's fourth-highest civilian award, by the Government of India.
this idiot
fuck micro$oft
[REDACTED]
he probably didnt invent the EHCI/OHCI/UHCI interfaces
give me a song name
my ears are bored
IM NEVER GONNA DANCE AGAIN, GUILTY FEET HAV EGOT NO RHYTHM
THOUGH IT'S EASY TO PRETEND
I KNOW YOURE NO T A FOOL
no ty
crash out over toilet music is insane
[January 24th, 2026, 20:56: I have started yelling song lyrics in OBOS thread, i have been driven to absolute insanity because of USB]
wha
i cant even find the specification for any of them
@flint idol had to pirate them
Honestly honestly
I should fucking mirror the USB specs on my site
no the xhci spec was free
Copyright be damned
and ehci
oh
didnt check uhci or ohci
this is worse than openfirmware
Oh then what did you pirate
idk if the usb specs are pay walled
THATS AT LEAST INDEXED BY GOOGLE 
but I couldnt find an official spec
oh it turns out it's all free
idk why i couldnt find the usb3 spec anywhere

is xhci usb3, ehci usb2, and ohci and uhci usb1?
Can you send them to me so I can mirror them nicely
If you can find all of them
Just so people can find them 🙏
xhci is: USB3, USB2, USB1
ehci is USB2
UHCI+OHCI (mutually exclusive btw) is: USB1
how the frick do you determine whether its a uhci or an ohci
pci class codes

as you would any other device
ok honestly i think i have to implement device trees even on x86
on powerpc it was practical but x86 is literally pain
would be nice if you could also mirror benjamin lunt's usb guide 
it's paywalled
i found it on libgen

just like dont tell him
he is the guy who made fysos and its books
DMCAd tho
fine ill do it myself
real
Honestly would the fellow even care?
helping clueless people like me with USB
im not on there either
I cannot find UHCI


lets just uh ignore that
watch us get ToS banned because piracy is against discord rules
yeah im not gonna mirror that one

ehci atleast says this
there isn't even an OHCI spec 🥀
sooooo
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted herein, except that a license is hereby granted to copy and reproduce this specification for internal use only
this is "internal use" right

1.1 i think
even if its for public good
the 1.1 refers to the spec revision not usb version
i mean aside from the ben lunt book this is all publicly available
(so perhaps stop sharing it)
ill hide it on my server so no one can find it
hopefully like no one signs with ftp and finds it
because like that would be terrible
you know
this should be correct?
for ohci there is even an open source implementation in spinalhdl :^)
if you want to design your own hardware with ohci
maybe i should run dist-upgrade at this point lol
nah ill just use aptitude it's smarter
Let me get my USB
To put them on my file server
Because I forget the login

And I CBA to change it
Because my desktop at home is logged in
i hate the cold but i love the vibe of the cold
Gparted how fucking long does it take to format a USB ext4
nvm i hate the cold
next time I have to wait for the bus in the cold im gonna listen to snowy from undertale ost
Why is my laptop overheating now 
punishment for considering pirating the book
This is just the normal spec books

Fat32 worked thank you
Unmounting it crashed plasma shell

for tomorrow: play minecraft
for monday: study for math exam
for tuesday: do math exam, stress over math exam
for wednesday: play terraria
for thursday: enjoy my break after exam season
for friday: contemplate on my exam grades
for next Saturday: work on obos?
nice
for tomorrow: fix XHCI driver
for monday: fix XHCI driver
for tuesday: fix XHCI driver
for wednesday: fix XHCI driver
for thursday: cry that XHCI driver isnt working and fix XHCI driver
for friday: fix XHCI driver
for next Saturday: fix XHCI driver
fucking hell
my pc isnt booting
well its only on the new kernel version
im gonna take a break from xhci
also after xhci i feel like adding evdev support to obos
would be le fun™, probably
ok so im tryna get fvwm3 to work
but it's faulting tryna execute 0x11
in lile the actual fvwm3 executable
(But seriously take a break you need it lmao)
lmao
but yes
I just got blinded by the sun reflecting off all this snow holy
this snow has gotta be like 3 feet deep
Arent u like from the middle east what
yes I am from there but I live in canada
Damn
yeah the canada explains why the snow is that deep lol
well delightful...
it is stack corruption occurring as soon
as waitpid() in mlibc tries to return
i think it's a bug in my signal implementation
yeah that checks out, it tries to return to 0x11, which is 17, which is SIGCHLD
um trying to fix it causes a triple fault lmfao
obos truly has the best code quality
which is probably a security vulnerability
because like anything can triple fault the kernel by passing an invalid ucontext
💀
it doesn't even set the ss/cs

Well I mean
It’s not really a SECURITY issue per say
Everyone data is safe
Nothing is sacked
Is more of a DoS attack
lol
ooo i should try porting it to my thing too
ye
Common astral W
btw at this point you are able to run i3
i3?
i3wm
never tried it

[ LOG ] thread 28: enter write_sync. blkCount=316, pipe->ptr=0, pipe->in_ptr=0, pipe->size=4096, pipe=ffff9000003c5808
[ LOG ] thread 28: ret from write_sync. blkCount=316, pipe->ptr=316, pipe->in_ptr=0, pipe->size=4096, pipe=ffff9000003c5808
[ LOG ] (thread 29, process 10) syscall Sys_ExecVE returned 0xb (OBOS_STATUS_NOT_FOUND)
[ LOG ] (thread 28, process 9) syscall Sys_FdSeek returned 0x2f (OBOS_STATUS_SEEK_UNALLOWED)
[ LOG ] thread 28: enter write_sync. blkCount=316, pipe->ptr=0, pipe->in_ptr=0, pipe->size=4096, pipe=ffff9000003c5808
[ LOG ] thread 28: ret from write_sync. blkCount=316, pipe->ptr=316, pipe->in_ptr=0, pipe->size=4096, pipe=ffff9000003c5808```
wtf
there should be some read log
before the pointer goes back to zero
oh
the pipe is freed
fixed it
/bin/sh didn't exist
KVM Internal Error my beloved
ts consistent too
you did some unspeakable things to kvm 🙏
acxcidentally
u have no proof of my spelling mistake 
xaccidentally
i accidentally ported x
man i hate it when that happens
What calls is it making for the time
Maybe you don’t have thoes implemented?
Could have it return the time from the BIOS RTC
a) that's not bios
b) i already have sys_clock_get implemented
it seems to get the time from clock 0x1 which i defined as the tsc/kernel time source
something does that, at least
currently implementing PTYs
TIL xterm's build system is insane
and xterm also just so happens to imagine new functions into existence
nvm
like congratz to the guy who wrote this
he managed to make a completely shit build system
what dumbass wrote this build system, seriously
bro what
config.log says it made a confdefs.h but not one is in sight
nvm that
find it then?
There is a reason why the repo has "abandon all hope, ye who enter here" in the readme
how the actual fuck did you get this to build
it's not detecting any of the installed headers correctly
or well it's detecting them but it isn't going in the config.h file thing
gcc should add this too
so it never actually realizes it has those goddamn headers
atp i might as well write my own makefile for this shit
Im just that good
i got it to build using duct tape
ffs
it's trying to use bsd PTYs
oh it doesnt build anymore
wtf
why does it think im compiling for goddamn BSD
what the fuck is wrong with this
ok i got it to build again
whoever invented the ioctls that work on goddamn file descriptors
fuck you
IO control
not FD control
well i got one half of PTYs working
it can definitely output onto the PTY
but xterm isn't recognizing it got output
like, input works
but xterm is just completely heedless to the fact it got output it needs to print
(which is probably because my PTYs are wrong)
old xterm works just fine
(from shortly after the xfree86 fork)
idk figure it out lmfao
it shouldn't be hard
...
NOOOOOO I JUST LOST ALL MY DEBUGGING PROGRESS
BECAUSE I FORGOT TO UNSET A BREAKPOINT FOR Arch_GotoUser
ok, unset it now and then continue
no because it went to a different user thread
you'll go to the next point it would've breaked at
and it's impossible for me to go back to the old one
because it's also a different process
ok i set a breakpoint on the last place i remember being at
note: charproc.c:6894
it seems like it's a bug with the PTY's IRPs

also, "no job control in background" 🥀
*only works without fvwm3 because i think xorg hates me
just use xlibre trust trust it will make eveyrthing better trust
accidentally ran cat in a no-job-control shell
what do i do
i should debug why it has no job control
hell is should debug how tf it's working
obos has absolutely no "changing controlling TTY" logic
this working should not be possible
except if like it's because on fork() nothing closes the stdio descriptors
ask claude to make a better xorg?
if you cant vibecode x12 you are ngmi
ok nvm it does work with fvwm3
i need to fix some bug with ps2
after using the mouse/keyboard long enough it kinda just starts having a stroke
to put it shrimply
also unfortunately doom does not work with X11
😔
it loads the WAD and all
but alas, it doesn't actually run
TODO: get SDL's X11 interface thing working
although that sounds like a problem for future me
im gonna stop doing osdev for the day
That’s called xlibre and they break a shit ton of things

Xlibre is X420 because they must've been high outta their god damn minds when writing it 😂
How are they even fucking doing
All I know is the creator is a biggot anti vaxor conspiracy person XD
in a bit im gonna fix job control in bash on xterm
no clue why it gets EINVAL
yay
void pty_ref(void* tty) { OBOS_SharedPtrRef(&(((struct pty*)(((struct tty*)tty)->interface.userdata))->ptr)); }
void pty_deref(void* tty) { OBOS_SharedPtrUnref(&(((struct pty*)(((struct tty*)tty)->interface.userdata))->ptr)); }

hey that's not fair why cant my fvwm3 look like that :(
no way xbps-install is almost working
faster than movistar internet
for funsies im gonna set MSS (max segment size) to 0xffff
(so much for congestion and stuff)
im tryna think of a way to increase IO performance
on the network stack
im thinking of one thing in particular and that is to eliminate as many allocations as possible
i was also thinking of delaying ACKs in the TCP implementation
reasons being:
a) sending packets takes time
b) it is better to send one big ACK as opposed to many different small ACKs
one thing i noticed in packet dumps is that obos is sending a bunch of small ACKs really slowly
i just removed a SINGLE assertion
and that boosted I/O perf 10-100 times more
still slow as shit
but
thanks for the free collection of USB specs btw yall 
https://files.evalyngoemer.com/share/manuals/
here is a good set of other specs too
I plan to get nvme on there too soon
And any others that come up that people need
nice
LMK if there is any others you need me to mirror
ok so my problem with TCP right now is that it is not seeing a lot of packets that come to it
causing a lot of retransmissions
More driver issues?
causing le slowness
no clue what's causing it to drop all these packets
Or it’s getting them too slow and it’s getting retransmitted causing a snake effect
#define RX_QUEUE_SIZE (4096)
ill just do this and see what happens 
no clue if the device actually supports that
(RX_QUEUE_SIZE was 32 before)
ok i fixed the ACK bugs
and now imn getting reasonable download speeds
in the 100s of KiB/s
but the kernel dies halfway through
the download speeds were so fast for obos that it exposed a race condition
and also it doesn't read the entire file
so i think i might've accidentally broke something
You should put on your repo that you have a blazingly fast network stack
And put tons of emojis
lol
Have you tried
Reading the entire file
yeah
And I presume DMA with the network card?
pretty much
I wonder if you can have the ISR track the packets coming in and then compare that with the actual result
so ur saying i should capture the packets for analyzing purposes
(wireshark)
nah the problem is the tcp implementation is overwriting the buffer
In the ISR just track minimal data and compare it with the result to make sure nothing is lost internally
Ahhh makes sense
Have you tried
it receives data, it gets more, it overwrites it, or so it appears
Not doing that
i always forgot how genius you are
out of curiosity, is it 3am where u are
10pm
But I am very lacking in sleep
And I just dealt with a ton of discord drama
i can tell go to sleep man
And I need to unwind a little
I can share more in DMs
But holy shit 😭
How can you tell btw
a slightly elevated level of sarcasm
aight
i do not mind at all
Thank you
i need some funny sarcasm in my life
Dosnt everyone
yes
size_t nPushed = 0;
OBOS_ENSURE(be32_to_host(hdr->seq) >= con->state.rcv.nxt);
Net_TCPPushReceivedData(
con,
segment_data, segment_length,
be32_to_host(hdr->seq) - con->state.rcv.nxt,
&nPushed);
if (con->state.rcv.furthest < con->state.rcv.nxt)
con->state.rcv.furthest = con->state.rcv.nxt;
if ((be32_to_host(hdr->seq) + nPushed) > con->state.rcv.furthest)
con->state.rcv.furthest = (be32_to_host(hdr->seq) + nPushed);
if (be32_to_host(hdr->seq) == con->state.rcv.nxt)
{
con->state.ack_pending = true;
OBOS_ASSERT(con->state.rcv.furthest >= con->state.rcv.nxt);
con->state.rcv.nxt = con->state.rcv.furthest;
}
if (!con->ack_timer.handler && con->state.ack_pending)
{
con->ack_timer.handler = ack_timer_handle;
con->ack_timer.userdata = con;
Core_TimerObjectInitialize(&con->ack_timer, TIMER_MODE_INTERVAL, 5*1000);
}
well this is the code
and apparently it causes the kernel to ACK more than it actually put in the buffer
magnificent
magnificent indeed
it was already there 
i fixed the bug, Net_TCPPushReceivedData wasn't working as i thought it would
uh how do i verify the file's contents now
sha256
yeah that's not the same file 💀
the checksums are completely different
and ig because the kernel fucking hates me
i consistently get this crash
when running curl on http
well it's reading a raw data file so id hope it's not CRLF
Try downloading a binary file that’s all 0xFF or somthing?
And then you can do a check in the hex editor
Unless you already did that
That’s how TCP works innit? You have to re order it back
yeah and that's the bug
Why don’t you put the data in order 

really should've thought of that smh
i have a better idea
while [ `sha256sum $out` != `cat sum` ]
do
curl -Lo $out $url
done```


keep on redownloading the file until the checksum is right
Bogosort ahh algorithm
(actually this is technically how tcp works)
Do packets not have an order ID?
if the receiver got a mismatching checksum, the packet is retransmitted
so technically
it is
but it doesn't really work like that at all
i lied
the lion does not concern himself with data accuracy
if only i knew how i could make this buffer work
i need the consumer of the buffer to be able to read from it like a stream
but i need the producer to be able to write to it at any arbitrary offset, with the user only being signaled when there is some complete data (i.e., data at offset zero has been written)
what if i used a bitmap to indicate which regions of the buffer have not been written and which haven't been read 
so ig the data structure i am looking for is a: string
the writer needs to be able to write at any arbitrary offset into the future
a read() reads the currently available bytes
so like if the buffer has bytes 15-20 received, then a read would block until offsets 0-15 are filled
But it can’t overwrite data no?
no
the writer is also able to write bytes 20-30 for example if it gets those
Why not use a freelist of unwritten blocks or some shit
seems pretty not right
idk ill figure it out im wording what i want terribly
maybe instead of writing stuff out of order
Do you know how many packets you get ahead of time?
what i need to do is reorder segments so that they are in the right order, then process them in order
Why not make a sparse array you allocate lazily
definitely not
Damn 
all i know is that i will get at most rcv.wnd bytes ahead of time
but that says absolutely nothing
yeah im not a fan of this solution
What if when you get a block you sort them automatically and if it can’t be put in sorted put them in a linked list elsewhere or some other thing
And then as needed go through it and sort it and put onto the main set
idk
maybe a bitmap of "received bytes" could the solution
once there are enough contiguous received bytes from the start of the buffer, signal the reader
but of course a bitmap might not be the best
Yeah I don’t think a bitmap is the best
Like an RB tree?
no rb-trees are only self-balanced
also wouldn't fit this, i don't need O(log n) search
i need fast iteration, so a list is likely best suited
but at the same time, a list will need allocation, and allocation might not be the best idea in a critical part of the tcp stack (but that is probably a problem for later)
struct received_segment {
intptr_t offset;
size_t len;
// list info
}```
when a received_segment is found with offset=0, it signals the reader, and the reader will read from offset to len of that segment
if i knew how much data im getting in advance this could be easier
like if i knew for a fact i would get receive_buffer.length bytes, then i could simply have the reader block until that many bytes have been written
but alas, i dont have that information
actually wait
i do have that information
not exactly
that information
but what ill do is keep my current approach
but only signal the buffer when the kernel sends an ACK to the data
because ik for a fact that the tcp implementation ACKs when it knows it's emplaced all data
and i did that
and the data is still completely wrong
i just figured out
that's wrong
yeah it's probably in my best interest to have the packets be sorted in order of SEQuence, then processed in that order
which sounds pretty complicated for my brain rn
so im gonna sleep
TODO for tomorrow: process packets in the right goddamn order
maybe even TODO for tomrrow: implement TCP SACK (selective ACK)
Why not pre allocate some
You could say keep X blocks pre allocated so when new shit comes in they fill up first
if i process packets in the right order to begin with this problem doesnt exist
What happens to out of order packets? I presume you keep those non processed elsewhere
more amusing than xhci 
throw em in a sorted list
and process them once there are no more holes
on my phone there is an audio file named weird.wav that was created at 1:30 am...
i do wonder what this could be
You should use miracle sort btw
just did
I prefer the quantum immortality sort
where you randomize it and if it is not sorted, you destroy the universe
its just some music I wrote during the winter break cuz I was bored
by the theory of quantum immortality, it will be sorted
and thus, I will not be sending it
Do you have such an implementation made?
yeah but I don't want to share it in fear of someone abusing the destruction of the universe for nefarious means
works pretty well, seeing as we are still here
time to listen to 647 instupendo with the lights off starting at the ceiling
nvm i think ill get possessed if I do that
I wonder what would happen with an HTTP server
Like your OS hosting it
And seeings how scrambled it is
probably not at all
because the problem is not on transmission but instead on reception
true 
It’s better than microslop

Actually though
When you finish this
Host an HTTP(S) server for your kernel
On your kernel
And have it though NAT to catch most attacks on a buggy stock
Stack
And also use it for people to pen test your stack

I’d probaly slap it on a hetzner box inside a VM so you can control it a lot better if it did get PWNed and the person wasn’t so kind
I was also thinking it might be possible to host a site on obos as long as I implement some sort of watchdog timer that resets the system if it detects a hang
If any attacker got in there you have no idea
With a VM you can heavily restrict the traffic and sniff it to make sure it’s not doing stupid ahh shit to be able to kill it
how exactly would an attacker get through there if only ssh and http are open
its not like sshd would be any less capable on obos than it is linux
Just incase there is any bugs in the networking stack with crafted packets and overflows or other shit
I’d just be slightly concerned with a brand new networking stack etc?
Not like a hetzner box is that expensive for a cheaper one?
who even need to attack obos server

But I mean you never know on the Internet
I paid attention to overflows while writing the network stack
With people fucking hammering every ssh and http server to find vulns and shit
and crafted packets
is network stack not hard
the kernel drops any packets that lied about their length
and worst case scenario if it overflows and crashes, the watchdog timer takes over and resets the kernel
I’m just saying take some precautions so you don’t have to fucking explain to your VPS provider if it got pwned lmfao
yeah im not actually gonna do it anytime soon

What if you did a dynamic array / vector?
And then you get a packet with order 7, and you put it into slot 7 and if you then get order 27 you expand it more etc
And then if it’s lower than the max they can go into the proper spot
cuz that's not really how sequence numbers work
I would need rcv.wnd amount of slots (0xffff)
for that to work
And that’s expensive
indeed
uh so ive managed to make the receive speeds and accuracy bad
scraped that idea
instead i will go back to what i originally did
i feel like an rb tree for the reassembly queue is not ideal
since the reassembly queue should not have many segments on it in most cases
true...
im thinking that instead of having a reassembly queue, i will insert packets into the rx buffer as soon as they're available
send an ACK (and signal the rx buffer) everytime rcv.nxt is advanced
and ill have some specific conditions for advancing rcv.nxt
that i will explain once i know what they are
this will also probably aid me when/if i implement the SACK extension
Oberrow quick question
What’s your block layer interface
How does a file system ask for a block
Because I wana make sure I’m not missing anything obvious
the ext2 driver (only existing file system driver) either uses the page cache
or submits an IRP
to the block device
So like it would get a pointer to the page cache entry or would it copy to a buffer?
it would get a pointer to a page cache entry
and then do whatever it needed with the block
How do you deal with the page cache entry being invalidated while in use? Would the FS free it back after?
The kernel is to shit itself if that happens.
but uh as long as it isn't on a standby list, the pagecache entry, it should be good
yeah this is actually like really fucked up
Like the pfndb may say BLOCK_CACHE_FREE
Or
BLOCK_CACHE_USED
some of the pagecache entries are stored for long-term storage (i.e., for the lifetime of an inode)
And it will only reclaim free ones
if the pagecache entry gets reclaimed then the driver can call it quits
I may do a seperate buddy allocator for the cached blocks to allocate from?
uh to fix this i will use the PHYS_PAGE_LOCKED
in struct page
just set that bit until the driver is done with the entry, it should be good™
How should one make the allocator linked list skip over blocks like that l?
It wouldn’t be much overhead though
if (page->flags & PHYS_PAGE_LOCKED) continue;
Because it won’t need to lock it for long
?
Yeah
anway if u will excuse me i have a reassembly queue to fix
well im getting consistent download speeds and accuracy i believe
(that doesn't mean shit)
literally exactly 143 bytes a second
because for some reason the window isn't growing properly
hey not bad, you could use a BBS just fine 
The is blazing fast
Rust only gets 142
so to fix the whole "data isn't right" thing
im gonna double buffer this shit
you read that right
ill have the kernel intermediate receive buffer
that will be flushed to a user "ready buffer"
whenever the kernel sends an ACK
(and of course this buffer will be dynamic)
is it insane? yes
will it work? idk
/*
* We manage rcv_wnd like this: it stays constant until we can't
* putnext() any further data and have to queue it; then, we
* reduce rcv_wnd by as much as we receive. this continues until
* we are free to putnext() again, at which point we reopen the
* window to its full extent.
*/
so i push the data up through STREAMS but if STREAMS says it can't take any more, then i queue it within the TCP driver
it seems to be a fine solution
hm
i found it interesting we both ended up with a 'double buffer' solution there
note the reopening to full extent
streams is full: data is queued up in the tcp driver in the meantime; streams doesn't allow messages to be sent up anymore until the streams queue reaches a low watermark; when that low watermark is reached, potentially a lot of data queued in tcp can go up at once, and then readers naturally coalesce their reads of this data
the double-buffering solution gets me the right data
however it seems to fail to return the right amount of data in cases where the amount of data received in total is < rx window size
yeah it's failing to push the full extent of data to userspace for some reason
huh it seems like it's not ACKing everything properly

im having fun running sudo ss -K dst 192.168.3.2 while sshing into the host from obos
sudo
after I come back home today im gonna commit my working changes and implement selective ack
Btw how does OBOS handle MMAPing files from block devices?
I heard how managarm does it. Pretty complex but possibly manageable but I wonder how USB person does it
I would assume so seeing as it has a page cache

Page cache is gonna be hard. Wanting to see how others do it
It’s coming up soonerish on the list
pagecache
it refs the page in the pagecache
and then maps the physical address
possibly mapping as CoW if it is a private mapping
and possibly creating new entries if prefaulting is requested
if a pagecache entry does not exist and prefaulting is not requested then on fault, it is created and mapped
How do you handle invalidation of MMAPd files or other things so you can update the needed PTEs
if any page is reclaimed then the kernel will remap the pte with an ID that the MM uses to know that it needs to fetch this file from disk or this anon memory from swap
and this ID is also used to identify the page in the swap
I mean like if say multible processes have this mapped and you need to edit the pages to fault, how do you keep track of that and to clean them all up?
I forgor let me check
Thank you
uh iirc I always map pages that are swapped out with a swap allocation id so the kernel never has to keep track of what pages are using a virtual page
I also think that if a pagecache entry has mappedPageCount >0 the kernel will not invalidate it
(not same as refcount btw)
So a swap allocation in of its self keeps track of the PIDs and the mappings they have for swap/MMAP stuff?
// TODO(oberrow): Reclamation of file cache pages.```
So then the kernel sees oh this is part of this to send it over here to nuke mappings
the swap allocation simply holds track of the swapped out page
// represents a swap allocation, as well as the physical page that it uses, if it was already read.
typedef struct swap_allocation
{
LIST_NODE(swap_allocation_list, struct swap_allocation) node;
uintptr_t id; // the key
size_t refs;
page* phys; // if !phys, this page must be read from swap.
struct swap_device* provider;
} swap_allocation;
OBOS_NODISCARD swap_allocation* MmH_LookupSwapAllocation(uintptr_t id);
swap_allocation* MmH_AddSwapAllocation(uintptr_t id);
void MmH_RefSwapAllocation(swap_allocation* alloc);
void MmH_DerefSwapAllocation(swap_allocation* alloc);```
and then when the kernel swaps smth out, if there is already a swap allocation it will use that as the id otherwise it'll create a new one
So there currently isn’t a way to reclaim a MMAPd file from a process because it isn’t tracked?
Because many virtual address spaces could refer to such a page

yeah
I also dont like the idea of keeping track of virtual pages in a physical mapping






