In assembly one can pass values via less volatile registers or volatile registers. I can for instance pass arguments to printf using edi and esi I can also instead use ebx and ecx This example is a very simple contrived one. I'm more curious to how this works with much more intricate programs calling multiple functions from libc.
For instance in Return Oriented Programming attacks, an attacker can use gadgets to use the same registers used for a previous function to pop new values from the stack into them and then return to another libc function that uses the same register(s), for instance with write and read one could use pop rsi in ROP attacks to use either function if they've leaked the global offset table. My overall question could be asked this way:
If an attacker inherits registers from a previous call to read like so:
0x00005555555552d0 <+107>: lea rcx,[rbp-0xd0] <- Memory address of buffer "msg"
0x00005555555552d7 <+114>: mov eax,DWORD PTR [rbp-0xe4] <- contains client fd 0x4
0x00005555555552dd <+120>: mov edx,0x400 <- 1024 (size of bytes to write to memory location/buffer)
0x00005555555552e2 <+125>: mov rsi,rcx
0x00005555555552e5 <+128>: mov edi,eax
0x00005555555552e7 <+130>: call 0x5555555550d0 <read@plt>
How does the processor know which arguments to supply write to if the registers passed to write are different:
0x00005555555552b1 <+76>: call 0x555555555080 <strlen@plt>
0x00005555555552b6 <+81>: mov rdx,rax <- store return value from strlen into rdx
0x00005555555552b9 <+84>: lea rcx,[rbp-0xe0] <- message to write
0x00005555555552c0 <+91>: mov eax,DWORD PTR [rbp-0xe4] <- client file descriptor
0x00005555555552c6 <+97>: mov rsi,rcx
0x00005555555552c9 <+100>: mov edi,eax
0x00005555555552cb <+102>: call 0x555555555060 <write@plt>
Clearly read does not use rdx and write does not use edx, so how does the processor know which to choose, for example if an attacker only used a gadget that pops a value into rsi?
I can't seem to understand how the processor knows which registers to chose from (rdx or edx). How do processors select values to pass to libc functions or functions/routines for that matter in general?