SWAPCONTEXT(2)
π SWAPCONTEXT(2) π
okay bestie, welcome to the Linux 2.6 Programmer's Guide section of the man pages β today we're doing swapcontext(2) and honestly? it's giving "quiet little syscall that's lowkey carrying your whole coroutine situation." β¨
β¨ NAME β¨
swapcontext β swap out old context with new context π¦
π SYNOPSIS π
int sys_swapcontext (struct ucontext *old_ctx, struct ucontext *new_ctx,
int r5, int r6, int r7, int r8,
struct pt_regs *regs);
π DESCRIPTION π
so here's the vibe: swapcontext swaps out the context old_ctx with the new context new_ctx. that's it, that's the whole job, she's a one-trick pony and she EATS π
now about those little int parameters β r5, r6, r7, r8 β they have no place in the system call functionality. like, they're literally just there. not doing anything. main character energy with zero lines, honestly. π
and then there's regs, which indicates the current user register values from the user stack. she's the one actually holding information, periodt. β
π RETURN VALUE π
swapcontext returns 0 on success π β icon behaviour, no notes.
otherwise? she returns one of the errors listed down in the Errors section. so yeah, if you get a nonzero return, go read the next section, bestie, it's right there for you. π
π ERRORS π
-EFAULTβswapcontextcould not verify that the memory area pointed to byold_ctxornew_ctxwas accessible for the operation. basically the kernel looked at your pointer and went "girl, that's not yours." π«Ά-SIGSEGVβ a fault occurred when the context was being copied into the kernel's image of the user's registers. this should only occur in an out-of-memory situation. > β οΈ heads up: OOM territory, that's the only time this should be showing up, so if you're seeing it and you're not out of memory, that's a whole different conversation.
π¦ SEE ALSO π¦
getcontext(2)sigaction(2)sigaltstack(2)sigprocmask(2)
go read those next, they're the rest of the squad π
π AUTHOR π
Niki Rahimi β thank you for your service, legend π«‘π
and that's the whole page, bestie!! this one's from the Linux 2.6 days, dated 2004-March-12 πΈ so yeah she's an elder but she's still iconic and we respect her. mwah, go swap some contexts responsibly π β¨π
π¦ where this page comes from
- centos-stream 10: man-pages 6.06-13.el10 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-Fedora-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- centos-stream 9: man-pages 6.04-10.el9 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-Fedora-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- fedora 43: man-pages 6.13-2.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-Fedora-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- fedora 43: man-pages 6.9.1-5.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-Fedora-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- fedora 44: man-pages 6.13-3.fc44 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-Fedora-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- Copyright (C) 2004 IBM Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms