Skip to content

Conversation

@assembler-0
Copy link
Owner

@assembler-0 assembler-0 commented Jul 8, 2025

Suggested Fix applied, check SYSCALL_INTERRUPT_VECTOR

Summary by CodeRabbit

  • Bug Fixes

    • Improved system call handling to prevent potential errors when no current process is found.
    • Added safeguards to avoid dereferencing null pointers during system call operations.
  • Chores

    • Updated build configuration to use a specific ISO filename when running the system.
    • Replaced hardcoded values with descriptive constants for system call interrupt setup.
  • Style

    • Removed an unused commented line from the code for clarity.

@coderabbitai
Copy link

coderabbitai bot commented Jul 8, 2025

Walkthrough

This update introduces symbolic constants for syscall interrupt vector configuration, refactors the syscall handler to cache the current process pointer and improve null checks, and updates the build script to use a hardcoded ISO filename. A commented line is also removed from a kernel task function, with no other logic changes.

Changes

File(s) Change Summary
Kernel/Kernel.c Removed a single commented line ("// Test syscall") from the task3 function.
Kernel/Syscall.c Refactored syscall handler to cache current process pointer, added null checks, and replaced hardcoded interrupt vector and gate values with symbolic constants.
Kernel/Syscall.h Added macro definitions: SYSCALL_INTERRUPT_VECTOR and IDT_INTERRUPT_GATE_KERNEL.
meson.build Changed the QEMU run command to use the literal ISO filename 'VoidFrame.iso' instead of a variable.

Sequence Diagram(s)

sequenceDiagram
    participant UserApp as User Application
    participant CPU as CPU
    participant Kernel as Kernel
    participant Proc as Process Manager

    UserApp->>CPU: Triggers syscall (int SYSCALL_INTERRUPT_VECTOR)
    CPU->>Kernel: Enters syscall handler
    Kernel->>Kernel: Cache current process pointer
    alt Valid current process
        Kernel->>Proc: Handle syscall (e.g., SYS_EXIT, SYS_GETPID)
    else No current process
        Kernel->>Kernel: Return error (-1 for SYS_GETPID)
    end
    Kernel-->>CPU: Return to user mode
Loading

Possibly related PRs

  • Development #2: Introduced the initial syscall infrastructure, including the syscall handler and initialization, which are directly refined by this PR.

Poem

A hop and a skip, a syscall anew,
With constants defined and pointers in view.
The kernel now checks, with a careful glance,
To keep nulls away and give code a chance.
The ISO’s set firm, the build’s in the queue—
A rabbit’s delight in what coders do! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Kernel/Syscall.h (1)

11-12: Consider renaming the constant to reflect its actual purpose.

While using symbolic constants is excellent for maintainability, SYSCALL_INTERRUPT_VECTOR set to 0x08 is misleading since 0x08 represents the kernel code segment selector, not an interrupt vector. The actual interrupt vector is 0x80.

Consider renaming to something like KERNEL_CODE_SELECTOR or SYSCALL_CODE_SELECTOR to better reflect its purpose.

-#define SYSCALL_INTERRUPT_VECTOR 0x08
+#define KERNEL_CODE_SELECTOR 0x08
meson.build (1)

104-104: Consider the maintainability implications of hardcoding the ISO filename.

While this change simplifies the command, hardcoding 'VoidFrame.iso' instead of using the iso target variable makes the build less flexible. If the ISO target name changes in the future, this will break.

Consider keeping the variable reference for better maintainability:

-  command : ['qemu-system-x86_64', '-cdrom', 'VoidFrame.iso', '-m', '1G']
+  command : ['qemu-system-x86_64', '-cdrom', iso, '-m', '1G']
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 534b2e3 and 2c149e1.

📒 Files selected for processing (4)
  • Kernel/Kernel.c (1 hunks)
  • Kernel/Syscall.c (3 hunks)
  • Kernel/Syscall.h (1 hunks)
  • meson.build (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: assembler-0
PR: assembler-0/VoidFrame#2
File: Kernel/Syscall.c:44-44
Timestamp: 2025-07-08T00:36:50.290Z
Learning: In IdtSetGate function calls, the parameters are: (interrupt_vector, handler_address, selector, flags). The interrupt vector (like 0x80) is the first argument, and the selector (like 0x08 for kernel code segment) is the third argument.
Kernel/Syscall.c (1)
Learnt from: assembler-0
PR: assembler-0/VoidFrame#2
File: Kernel/Syscall.c:44-44
Timestamp: 2025-07-08T00:36:50.290Z
Learning: In IdtSetGate function calls, the parameters are: (interrupt_vector, handler_address, selector, flags). The interrupt vector (like 0x80) is the first argument, and the selector (like 0x08 for kernel code segment) is the third argument.
Kernel/Syscall.h (1)
Learnt from: assembler-0
PR: assembler-0/VoidFrame#2
File: Kernel/Syscall.c:44-44
Timestamp: 2025-07-08T00:36:50.290Z
Learning: In IdtSetGate function calls, the parameters are: (interrupt_vector, handler_address, selector, flags). The interrupt vector (like 0x80) is the first argument, and the selector (like 0x08 for kernel code segment) is the third argument.
🧬 Code Graph Analysis (1)
Kernel/Syscall.c (1)
Kernel/Idt.h (1)
  • IdtSetGate (25-25)
🔇 Additional comments (4)
Kernel/Kernel.c (1)

134-134: Good cleanup.

Removing the unnecessary comment improves code cleanliness.

Kernel/Syscall.c (3)

7-7: Excellent optimization: caching the current process pointer.

This change improves performance by avoiding repeated calls to GetCurrentProcess() throughout the handler execution.


11-13: Good defensive programming with null check.

Adding the null check before accessing the current process prevents potential null pointer dereferences in the SYS_EXIT case.


38-38: Proper error handling for SYS_GETPID.

Returning -1 when no current process is found is a good error handling practice that prevents null pointer dereferences.

void SyscallInit(void) {
// Install syscall interrupt (0x80)
IdtSetGate(0x80, (uint64_t)SyscallEntry, 0x08, 0x8E);
IdtSetGate(0x80, (uint64_t)SyscallEntry, SYSCALL_INTERRUPT_VECTOR, IDT_INTERRUPT_GATE_KERNEL);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the symbolic constant usage is correct.

The use of symbolic constants is excellent for maintainability. However, there's a naming issue with SYSCALL_INTERRUPT_VECTOR - it's set to 0x08 which is actually the kernel code segment selector, not an interrupt vector.

Based on the retrieved learnings, the IdtSetGate parameters are correct:

  • 0x80 (interrupt vector)
  • SyscallEntry (handler address)
  • SYSCALL_INTERRUPT_VECTOR (0x08 - kernel code selector)
  • IDT_INTERRUPT_GATE_KERNEL (0x8E - gate flags)

The constant naming could be clearer. Please verify that the syscall setup works correctly with these constants:


🏁 Script executed:

#!/bin/bash
# Description: Verify syscall interrupt vector setup and usage
# Expected: Find consistent usage of 0x80 as interrupt vector and 0x08 as selector

echo "=== Searching for syscall interrupt vector usage ==="
rg -A 2 -B 2 "0x80|syscall.*interrupt" 

echo "=== Searching for IdtSetGate function calls ==="
rg -A 2 -B 2 "IdtSetGate"

echo "=== Searching for symbolic constants usage ==="
rg -A 2 -B 2 "SYSCALL_INTERRUPT_VECTOR|IDT_INTERRUPT_GATE_KERNEL"

Length of output: 21978


Rename SYSCALL_INTERRUPT_VECTOR to clarify its role as a segment selector

The parameters to IdtSetGate are:

  • 0x80 = interrupt vector
  • SyscallEntry = handler address
  • 0x08 = segment selector, not an interrupt vector
  • 0x8E = gate flags

Everything is wired up correctly, but the constant name is misleading. Please rename it and update its use:

  • Kernel/Syscall.h
-#define SYSCALL_INTERRUPT_VECTOR 0x08
+#define SYSCALL_SEGMENT_SELECTOR  0x08
  • Kernel/Syscall.c
-    IdtSetGate(0x80, (uint64_t)SyscallEntry, SYSCALL_INTERRUPT_VECTOR, IDT_INTERRUPT_GATE_KERNEL);
+    IdtSetGate(0x80, (uint64_t)SyscallEntry, SYSCALL_SEGMENT_SELECTOR,  IDT_INTERRUPT_GATE_KERNEL);
🤖 Prompt for AI Agents
In Kernel/Syscall.c at line 47 and Kernel/Syscall.h, rename the constant
SYSCALL_INTERRUPT_VECTOR to a name that clearly indicates it is a segment
selector, such as SYSCALL_SEGMENT_SELECTOR. Update all references to this
constant in both files accordingly to reflect its true purpose as a segment
selector rather than an interrupt vector.

@assembler-0 assembler-0 merged commit 2952332 into main Jul 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant