Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ UPROGS=\
$U/_logstress\
$U/_forphan\
$U/_dorphan\
$U/_getcnt\


fs.img: mkfs/mkfs README $(UPROGS)
mkfs/mkfs fs.img README $(UPROGS)
Expand Down
16 changes: 16 additions & 0 deletions kernel/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,19 @@ procdump(void)
printf("\n");
}
}

extern int syscall_counts[];

uint64
sys_getcnt(void)
{
int target_sys_num;

argint(0, &target_sys_num);

if(target_sys_num <= 0 || target_sys_num >= 30) {
return -1;
}

return syscall_counts[target_sys_num];
}
6 changes: 6 additions & 0 deletions kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "syscall.h"
#include "defs.h"

int syscall_counts[30] = {0};

// Fetch the uint64 at addr from the current process.
int
fetchaddr(uint64 addr, uint64 *ip)
Expand Down Expand Up @@ -101,6 +103,7 @@ extern uint64 sys_unlink(void);
extern uint64 sys_link(void);
extern uint64 sys_mkdir(void);
extern uint64 sys_close(void);
extern uint64 sys_getcnt(void);

// An array mapping syscall numbers from syscall.h
// to the function that handles the system call.
Expand All @@ -126,6 +129,7 @@ static uint64 (*syscalls[])(void) = {
[SYS_link] sys_link,
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
[SYS_getcnt] sys_getcnt,
};

void
Expand All @@ -136,6 +140,8 @@ syscall(void)

num = p->trapframe->a7;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
syscall_counts[num]++;

// Use num to lookup the system call function for num, call it,
// and store its return value in p->trapframe->a0
p->trapframe->a0 = syscalls[num]();
Expand Down
1 change: 1 addition & 0 deletions kernel/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
#define SYS_link 19
#define SYS_mkdir 20
#define SYS_close 21
#define SYS_getcnt 22
4 changes: 3 additions & 1 deletion kernel/sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "file.h"
#include "fcntl.h"

extern int syscall_counts[];

// Fetch the nth word-sized system call argument as a file descriptor
// and return both the descriptor and the corresponding struct file.
static int
Expand Down Expand Up @@ -502,4 +504,4 @@ sys_pipe(void)
return -1;
}
return 0;
}
}
Empty file added melhorias_helena.diff
Empty file.
19 changes: 19 additions & 0 deletions user/getcnt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "kernel/types.h"
#include "user/user.h"

int
main(int argc, char *argv[])
{
if(argc != 2){
fprintf(2, "uso: getcnt <syscall_id>\n");
exit(1);
}
int id = atoi(argv[1]);
int count = getcnt(id);
if(count < 0){
fprintf(2, "getcnt: syscall id invalido: %d\n", id);
exit(1);
}
printf("syscall %d has been called %d times\n", id, count);
exit(0);
}
1 change: 1 addition & 0 deletions user/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ int getpid(void);
char* sys_sbrk(int,int);
int pause(int);
int uptime(void);
int getcnt(int);

// ulib.c
int stat(const char*, struct stat*);
Expand Down
1 change: 1 addition & 0 deletions user/usys.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ sub entry {
entry("sbrk");
entry("pause");
entry("uptime");
entry("getcnt");
87 changes: 87 additions & 0 deletions userchanges.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
diff --git a/Makefile b/Makefile
index b262c0a..7b5fb2f 100644
--- a/Makefile
+++ b/Makefile
@@ -145,6 +145,8 @@ UPROGS=\
$U/_logstress\
$U/_forphan\
$U/_dorphan\
+ $U/_getcnt\
+

fs.img: mkfs/mkfs README $(UPROGS)
mkfs/mkfs fs.img README $(UPROGS)
diff --git a/kernel/proc.c b/kernel/proc.c
index 22a5401..45a35f6 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -688,3 +688,19 @@ procdump(void)
printf("\n");
}
}
+
+extern int syscall_counts[];
+
+uint64
+sys_getcnt(void)
+{
+ int target_sys_num;
+
+ argint(0, &target_sys_num);
+
+ if(target_sys_num <= 0 || target_sys_num >= 30) {
+ return -1;
+ }
+
+ return syscall_counts[target_sys_num];
+}
\ No newline at end of file
diff --git a/kernel/sysfile.c b/kernel/sysfile.c
index a070e2d..f7762fe 100644
--- a/kernel/sysfile.c
+++ b/kernel/sysfile.c
@@ -504,21 +504,4 @@ sys_pipe(void)
return -1;
}
return 0;
-}
-
-uint64
-sys_getcnt(void)
-{
- int target_sys_num;
-
- // argint(0, ...) pega o primeiro parâmetro passado para a syscall
- argint(0, &target_sys_num);
-
- // Validação de segurança para evitar acessos fora do array
- if(target_sys_num <= 0 || target_sys_num >= 30) {
- return -1;
- }
-
- // Retorna quantas vezes a syscall foi chamada
- return syscall_counts[target_sys_num];
}
\ No newline at end of file
diff --git a/user/user.h b/user/user.h
index ac84de9..4a123f6 100644
--- a/user/user.h
+++ b/user/user.h
@@ -24,6 +24,7 @@ int getpid(void);
char* sys_sbrk(int,int);
int pause(int);
int uptime(void);
+int getcnt(int);

// ulib.c
int stat(const char*, struct stat*);
diff --git a/user/usys.pl b/user/usys.pl
index c5d4c3a..ac3d0eb 100755
--- a/user/usys.pl
+++ b/user/usys.pl
@@ -42,3 +42,4 @@ entry("getpid");
entry("sbrk");
entry("pause");
entry("uptime");
+entry("getcnt");
\ No newline at end of file