Codes

1. Return Process PID

Modify sys_hello to return the calling process's PID instead of returning a fixed 0

// kernel/sysproc.c
uint64
sys_hello(void)
{
  printf("Hello from kernel syscall!\n");
  return myproc()->pid; // Returns the current process ID
}

2. Repeating Message

Update the syscall hello(void) to hello(int n), where the kernel prints the message n times.

// kernel/sysproc.c
uint64
sys_hello(void)
{
  int n;
  argint(0, &n); // Fetch the first integer argument from user space
  for(int i = 0; i < n; i++){
    printf("Hello from kernel syscall!\n");
  }
  return 0;
}

3. Print Execution Core

Modify the kernel handler to print which CPU core (hart ID) is currently executing the call.

4. User-Provided Name

Create a syscall hello_user(char *name) that fetches a string from user space to print "Hello [name]".

5. Global Call Counter

Add a global counter in kernel/sysproc.c that tracks and returns the total times hello was called.

6. PID Filtering

Modify the kernel handler to print "Hello from Kernel!" only if the caller has PID 1 or 2.

7. Rate Limiting

Change the syscall to return -1 (failure) if it is called more than 3 times by the same process.

8. Kernel Arithmetic

Implement a version where hello(int a, int b) prints the sum of the two integers in the kernel log.

9. Syscall Number Logging

Modify kernel/syscall.c to log the syscall number specifically whenever SYS_hello is invoked.

10. Conditional Success Output

Update the user program hello.c to print "Syscall Successful" only if the return value is exactly 0.

Last updated