Simplified thread example

This commit is contained in:
Eduard Urbach 2025-01-31 12:11:39 +01:00
parent 547e7d066b
commit 6163ba547e
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 16 additions and 14 deletions

View File

@ -1,22 +1,14 @@
import mem
import sys import sys
import thread
main() { main() {
start(thread) thread.create(work)
start(thread) thread.create(work)
start(thread) thread.create(work)
thread() work()
} }
start(func Pointer) { work() {
size := 4096
stack := mem.alloc(size)
rip := stack + size - 8
store(rip, 8, func)
sys.clone(0x100|0x200|0x400|0x800|0x8000|0x10000|0x80000000, rip)
}
thread() {
sys.write(1, "[ ] start\n", 10) sys.write(1, "[ ] start\n", 10)
sys.write(1, "[x] end\n", 8) sys.write(1, "[x] end\n", 8)
sys.exit(0) sys.exit(0)

10
lib/thread/thread.q Normal file
View File

@ -0,0 +1,10 @@
import mem
import sys
create(func Pointer) -> Int {
size := 4096
stack := mem.alloc(size)
rip := stack + size - 8
store(rip, 8, func)
return sys.clone(0x100|0x200|0x400|0x800|0x8000|0x10000|0x80000000, rip)
}