[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: IMG_0404.jpg (1.23 MB, 1284x2238)
1.23 MB
1.23 MB JPG
previous: >>107920671

#define __NR_pwrite64            18

https://man7.org/linux/man-pages/man2/pwrite.2.html

really not much to say about this one... the man page even redirects back to pread, lol.
i guess i will take this opportunity to complain about my least favorite part of this family of syscalls:
>Note that it is not an error for a successful call to transfer fewer bytes than requested (see read(2) and write(2)).
this is pretty obnoxious, as every time you use these calls, you need to decide whether the return value should be compared against -1, or else against the expected length. luckily in most cases it should be relatively obvious which is the correct way to handle your situation, but it's still a hassle. thank you GNU for the TEMP_FAILURE_RETRY (https://elixir.bootlin.com/glibc/glibc-2.42.9000/source/posix/unistd.h#L1134) macro, though, which is pretty convenient for handling EINTR

relevant resources:
man man

man syscalls

https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
>>
>>107929895
raw syscalls return -errno instead which is much better
>>
>>107930007
yes and no
have you *seen* the return value of mmap on 32-bit systems?
>>
>>107930007
>>107930040
i guess it's always gross (https://elixir.bootlin.com/linux/v6.18.6/source/include/linux/err.h#L22), but it's just especially noticable on 32-bit systems
>>
>>107930040
no
what about it?
>>
>>107930068
you have to basically perform bitwise operations or some evil casting with the return value to check against MAX_ERRNO. it's not as easy as on 64-bit systems, where you can just cast and check if the value is negative. just a quirk of the address space
>>
>>107930068
>>107930092
https://stackoverflow.com/questions/36296130/why-does-is-err-value-cast-negative-max-errno-to-an-unsigned-long
>>
>>107929895
wops could've at least cut off the tops and bottoms of the paper
>>
>>107930092
meh
still 10x better than having to set up TLS for errno only
>>
>>107930007
Only BSDs got it right. Errors shouldn't be signalled in-band unless there's absolutely no other way
>>
>>107930115
the idea of having a global like that is honestly really gross lol
i wish it just took a pointer to an error value and set it for you if the pointer was non-null
>>107930141
agreed
>>
>>107930144
actually, i that back. the return value should always be zero, or else an error. if it wants to return other information, *that* should take a pointer
>>
>>107930188
totally agree
>>
>>107929895
Have a bump autist, survive for at least 5 more hours
>>
>>107929895
The amount of code that doesn't check if writes were partial and doesn't handle EINTR specially doesn't keep me up at night but it does make me wince sometimes
Rust has an automatic wrapper that handles this for you but flubbed by calling it "write_all" while the primitive is called "write" so of course everyone who doesn't read the docs just goes straight for "write"
>>
>>107934478
>write_all
setvbuf _IONBF+fwrite does the same thing in C
I have yet to find a way to reproducibly cut short a blocking write on Linux though
>>
>>107929895
in case any of you goys wants to learn ASM, I recommend this free book:
https://pacman128.github.io/pcasm/
sadly, it teaches 32-bit ASM and it doesn't have a section for syscalls, but it's really good as a start. here's the ToC:
>Introduction
>Basic Assembly Language
>Bit Operations
>Subprograms
>Arrays
>Floating Point
>Structures and C++
it's really cool that it even teaches calling conventions. if you know a bit of C, it might be useful for you.
>>
>>107936475
Based, thank you anon.
>>
>>107936475
I forgot to mention:
there are multiple translations (French, German, Spanish, Italian, Korean, Simplified Chinese, Traditional Chinese)
use a 32-bit system (a VM, livecd or whatever) to run the exercise/example codes.

you should be able to learn all of that in a week...

here's a much shorter tutorial that targets x86_64 and has syscalls and C calling conventions:
https://cs.lmu.edu/~ray/notes/nasmtutorial/

also, beware that nasm uses a different notation from at&t asm, and most assemblers have different notations and even, err, behaviors.

>>107936493
yw
>>
>>107936366
>_IONBF
That doesn't help if the syscall stops early as it's allowed to do, right? It just disables buffering
>>
>>107937700
yes, but fwrite retries until error
>>
>>107934478
>EINTR
do you care aboout this if oyu don't install signal handlers?
>>
>>107937845
Yeah, you can get EINTR after waking up from Ctrl-Z



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.