Commit 2575d7e
committed
add fork with copy-on-write for riscv64
Unlike x86_64/aarch64, no kernel stack has to be cloned: the user-
mode dispatcher owns the complete trap context, so fork is
intercepted in user_loop (the syscall-table entry stays as an ENOSYS
fallback), the child gets a copy of the parent's UserContext with
a0 = 0, a fresh kernel stack, and re-enters user mode through its own
user_loop_resume via fork_child_entry.
The COW machinery mirrors the other targets: RSW bit 8 marks shared
frames, mark_user_pages_copy_on_write drops the write bit before
copy_current_root_page_table deep-copies the user slots (kernel slots
stay shared), and do_cow_fault clones a frame on the first write —
or re-marks it writable in place when the last reference faults.
The frame refcounting protocol is completed on riscv64: every user
mapping (code, TLS, stack, lazily faulted pages) takes a reference
and clear_user_slots only releases frames whose count drops to zero,
which also covers exec after fork. Kernel-mode stores through
sstatus.SUM to COW pages are resolved in trap_handler.
Verified in QEMU with the fork example: fork, exec with argv/envp in
the child, waitpid, and 16k fork/exec/join cycles complete cleanly.1 parent ab37371 commit 2575d7e
8 files changed
Lines changed: 467 additions & 14 deletions
File tree
- src
- arch/riscv64
- kernel
- mm
- scheduler
- syscalls
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
251 | 273 | | |
252 | 274 | | |
253 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
233 | 237 | | |
234 | 238 | | |
235 | 239 | | |
| |||
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
275 | 283 | | |
276 | 284 | | |
277 | 285 | | |
| |||
364 | 372 | | |
365 | 373 | | |
366 | 374 | | |
367 | | - | |
| 375 | + | |
368 | 376 | | |
369 | 377 | | |
370 | 378 | | |
| |||
401 | 409 | | |
402 | 410 | | |
403 | 411 | | |
| 412 | + | |
| 413 | + | |
404 | 414 | | |
405 | 415 | | |
406 | 416 | | |
| |||
489 | 499 | | |
490 | 500 | | |
491 | 501 | | |
492 | | - | |
493 | | - | |
494 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
495 | 507 | | |
496 | 508 | | |
497 | 509 | | |
| |||
500 | 512 | | |
501 | 513 | | |
502 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
503 | 524 | | |
504 | 525 | | |
505 | 526 | | |
| |||
513 | 534 | | |
514 | 535 | | |
515 | 536 | | |
516 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
517 | 551 | | |
518 | 552 | | |
519 | 553 | | |
520 | 554 | | |
521 | 555 | | |
522 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
523 | 566 | | |
524 | 567 | | |
525 | 568 | | |
| |||
565 | 608 | | |
566 | 609 | | |
567 | 610 | | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
568 | 615 | | |
569 | 616 | | |
570 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
296 | 340 | | |
297 | 341 | | |
298 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
0 commit comments