[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: 1767695845007594.png (2.78 MB, 2226x3435)
2.78 MB
2.78 MB PNG
previous: >>108058648

#define __NR_pause                34

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

simple and to the point. i love that in a syscall. honestly, this seems like a pretty handy tool. kind of like a ghetto condition variable, or a sleep, etc. just have to be particular about your signaling. with that being said, i've never actually used this syscall, and i'm not aware of anyone who has, either. what about you, anons?

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/
>>
>>108066842
she can't even tie her own shoelaces, lamao
>>
>>108066842
>simple and to the point.
>>
>>108066980
shrimple as
>>
>>108066842
i don't trust myself with such low level primitives
I'll stick to more declarative concurrency constructs
>>
>>108066842
I'm kinda new to this and started learning C recently and I have a question: is it possible to use a syscall without libc? so far the only way I know of how to do this is inline assembly, but at that point you're really writing assembly and not C, so does C have sort of keyword as sort of catch all syscaller? something like syscall(eax, ebx, ecx, edx, ...etc) that expands to appropriate inline assembly at compile time?
>>
>>108066961
Lol
>>
>>108067368
>is it possible to use a syscall without libc?
yes
>so far the only way I know of how to do this is inline assembly
that is the only way to do it
>so does C have sort of keyword as sort of catch all syscaller?
no. copy paste this into your codebase: https://elixir.bootlin.com/musl/v1.2.5/source/arch/x86_64/syscall_arch.h
>>
>>108067368
>>108067401
oh, and then of course you can use a varargs macro to call the appropriate syscall function
>>
>>108067401
Okay I guess C is only really just assembly with macros, I think I get why people call it a low level language even though I still think it's high level, but it is the lowest high level language IMO.
>https://elixir.bootlin.com/musl/v1.2.5/source/arch/x86_64/syscall_arch.h
Thanks! I was actually looking for the source code of these syscalls.
>>
>>108067368
>>108067471
C has nothing to do with syscalls. The system call is just a special instruction that jumps to a specified address and saves the state so it can return to the program that called it, and it sometimes switches CPU modes too. There is no way to use that instruction in C, so you have to use assembly which is the same thing you would do in any other language. There's nothing special about system calls at all, if you know how they work. It's just save the return address somewhere, get a new address from somewhere else, change the CPU mode to allow privileged instructions, then jump to the new address. C has no way to use any of those privileged instructions either.
>>
>>108066842
Seems sort of similar to SIGSTOP? Unless you're waiting for some kind of more general signal from a process that isn't in on the pause() shenanigans?

>>108067471
>Okay I guess C is only really just assembly with macros
Not exactly. Inline assembly is a non-standard feature, the traditional approach is to write the code in a separate assembly file and then link that into your program as a library.
Usually if you dig into a library it's C code all the way down. You only get assembly for certain funny hardware tricks like syscalls and for extreme optimization.
The main thing that sets C apart from other popular natively compiled languages is that it doesn't add (much) invisible code for cleanup and memory management and such. The only code that runs is the code that you write out explicitly.



[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.