Compare commits
No commits in common. "727e227b09ed0c303e87728af531c6c3a025fd36" and "a4eed362b6c50daf95e073885bf8901ed8420a88" have entirely different histories.
727e227b09
...
a4eed362b6
@ -1,4 +1,4 @@
|
|||||||
APPS := init sym sh crash uname uptime hello ps
|
APPS := init sym sh crash uname uptime hello block
|
||||||
|
|
||||||
APPS_DIR := $(LUNA_ROOT)/apps
|
APPS_DIR := $(LUNA_ROOT)/apps
|
||||||
APPS_SRC := $(APPS_DIR)/src
|
APPS_SRC := $(APPS_DIR)/src
|
||||||
|
34
apps/src/block.c
Normal file
34
apps/src/block.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int fd = open("/dev/kbd", O_RDONLY | O_NONBLOCK);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
perror("open");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* fp = fdopen(fd, "r");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
perror("fdopen");
|
||||||
|
close(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[32];
|
||||||
|
fread(buf, sizeof(buf) - 1, 1, fp);
|
||||||
|
if (ferror(fp))
|
||||||
|
{
|
||||||
|
perror("fread");
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,44 +0,0 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <luna/pstat.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
pid_t get_current_max_threads()
|
|
||||||
{
|
|
||||||
pid_t result = pstat(-1, NULL);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
perror("pstat(-1)");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_process(struct pstat* pstatbuf)
|
|
||||||
{
|
|
||||||
printf("%ld %ld %s %s (%ld ms)\n", pstatbuf->pt_pid, pstatbuf->pt_ppid, pstatbuf->pt_name, pstname(pstatbuf),
|
|
||||||
pstatbuf->pt_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
int try_pstat(pid_t pid, struct pstat* pstatbuf)
|
|
||||||
{
|
|
||||||
pid_t result = pstat(pid, pstatbuf);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
if (errno == ESRCH) return 0;
|
|
||||||
perror("pstat");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
struct pstat pst;
|
|
||||||
pid_t max = get_current_max_threads();
|
|
||||||
for (pid_t pid = 0; pid <= max; pid++)
|
|
||||||
{
|
|
||||||
if (try_pstat(pid, &pst)) { display_process(&pst); }
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,15 +10,17 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[32];
|
char buf[4096];
|
||||||
fgets(buf, sizeof(buf), fp);
|
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
|
||||||
|
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
{
|
{
|
||||||
perror("fgets");
|
perror("fread");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf[nread] = 0; // null terminate it :)
|
||||||
|
|
||||||
long ms_uptime = atol(buf);
|
long ms_uptime = atol(buf);
|
||||||
|
|
||||||
printf("up for %ld seconds\n", ms_uptime / 1000);
|
printf("up for %ld seconds\n", ms_uptime / 1000);
|
||||||
|
@ -23,10 +23,8 @@
|
|||||||
#define SYS_waitpid 18
|
#define SYS_waitpid 18
|
||||||
#define SYS_access 19
|
#define SYS_access 19
|
||||||
#define SYS_fstat 20
|
#define SYS_fstat 20
|
||||||
#define SYS_pstat 21
|
|
||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
struct pstat;
|
|
||||||
|
|
||||||
namespace Syscall
|
namespace Syscall
|
||||||
{
|
{
|
||||||
@ -54,4 +52,3 @@ void sys_fork(Context* context);
|
|||||||
void sys_waitpid(Context* context, long pid, int* wstatus, int options);
|
void sys_waitpid(Context* context, long pid, int* wstatus, int options);
|
||||||
void sys_access(Context* context, const char* path, int amode);
|
void sys_access(Context* context, const char* path, int amode);
|
||||||
void sys_fstat(Context* context, int fd, struct stat* buf);
|
void sys_fstat(Context* context, int fd, struct stat* buf);
|
||||||
void sys_pstat(Context* context, long pid, struct pstat* buf);
|
|
||||||
|
@ -32,7 +32,6 @@ void Syscall::entry(Context* context)
|
|||||||
case SYS_waitpid: sys_waitpid(context, (long)context->rdi, (int*)context->rsi, (int)context->rdx); break;
|
case SYS_waitpid: sys_waitpid(context, (long)context->rdi, (int*)context->rsi, (int)context->rdx); break;
|
||||||
case SYS_access: sys_access(context, (const char*)context->rdi, (int)context->rsi); break;
|
case SYS_access: sys_access(context, (const char*)context->rdi, (int)context->rsi); break;
|
||||||
case SYS_fstat: sys_fstat(context, (int)context->rdi, (struct stat*)context->rsi); break;
|
case SYS_fstat: sys_fstat(context, (int)context->rdi, (struct stat*)context->rsi); break;
|
||||||
case SYS_pstat: sys_pstat(context, (long)context->rdi, (struct pstat*)context->rsi); break;
|
|
||||||
default: context->rax = -ENOSYS; break;
|
default: context->rax = -ENOSYS; break;
|
||||||
}
|
}
|
||||||
VMM::exit_syscall_context();
|
VMM::exit_syscall_context();
|
||||||
|
@ -374,10 +374,10 @@ void Scheduler::task_tick(Context* context)
|
|||||||
ASSERT(Interrupts::is_in_handler());
|
ASSERT(Interrupts::is_in_handler());
|
||||||
Interrupts::disable();
|
Interrupts::disable();
|
||||||
sched_decrement_sleep_times();
|
sched_decrement_sleep_times();
|
||||||
|
if (sched_current_task->id == 0) return task_yield(context);
|
||||||
sched_current_task->task_time -= frequency;
|
sched_current_task->task_time -= frequency;
|
||||||
sched_current_task->cpu_time += frequency;
|
sched_current_task->cpu_time += frequency;
|
||||||
if (sched_current_task->id == 0) return task_yield(context);
|
if (sched_current_task->task_time < 0)
|
||||||
if (sched_current_task->task_time <= 0)
|
|
||||||
{
|
{
|
||||||
sched_current_task->task_time = 0;
|
sched_current_task->task_time = 0;
|
||||||
task_yield(context);
|
task_yield(context);
|
||||||
@ -514,49 +514,3 @@ void sys_waitpid(Context* context, long pid, int* wstatus,
|
|||||||
child->state = child->Exited;
|
child->state = child->Exited;
|
||||||
context->rax = (long)child->id;
|
context->rax = (long)child->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pstat
|
|
||||||
{
|
|
||||||
long pt_pid;
|
|
||||||
long pt_ppid;
|
|
||||||
char pt_name[128];
|
|
||||||
int pt_state;
|
|
||||||
long pt_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
void sys_pstat(Context* context, long pid, struct pstat* buf)
|
|
||||||
{
|
|
||||||
Task* task;
|
|
||||||
if (pid == -1) task = Scheduler::find_by_pid(free_tid - 1);
|
|
||||||
else if (pid == 0)
|
|
||||||
task = &idle_task;
|
|
||||||
else
|
|
||||||
task = Scheduler::find_by_pid(pid);
|
|
||||||
if (!task)
|
|
||||||
{
|
|
||||||
context->rax = -ESRCH;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (task->state == task->Exited) // we're just waiting for the reaper to reap it
|
|
||||||
{
|
|
||||||
context->rax = -ESRCH;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (buf)
|
|
||||||
{
|
|
||||||
struct pstat* kpstat = obtain_user_ref(buf);
|
|
||||||
if (!kpstat)
|
|
||||||
{
|
|
||||||
context->rax = -EFAULT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
kpstat->pt_pid = task->id;
|
|
||||||
kpstat->pt_ppid = task->ppid;
|
|
||||||
kpstat->pt_state = (int)task->state;
|
|
||||||
kpstat->pt_time = (long)task->cpu_time;
|
|
||||||
strlcpy(kpstat->pt_name, task->name, sizeof(kpstat->pt_name));
|
|
||||||
release_user_ref(kpstat);
|
|
||||||
}
|
|
||||||
context->rax = task->id;
|
|
||||||
return;
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
#ifndef _LUNA_PSTAT_H
|
|
||||||
#define _LUNA_PSTAT_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
struct pstat
|
|
||||||
{
|
|
||||||
pid_t pt_pid;
|
|
||||||
pid_t pt_ppid;
|
|
||||||
char pt_name[128];
|
|
||||||
int pt_state;
|
|
||||||
pid_t pt_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define PT_IDLE 0
|
|
||||||
#define PT_RUNNING 1
|
|
||||||
#define PT_SLEEPING 2
|
|
||||||
#define PT_ZOMBIE 3
|
|
||||||
#define PT_WAITING 4
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Returns information about the process with PID pid in buf, if buf is non-null. Luna-specific. */
|
|
||||||
pid_t pstat(pid_t pid, struct pstat* buf);
|
|
||||||
|
|
||||||
/* Returns a string representation of the process state in buf. */
|
|
||||||
const char* pstname(struct pstat* buf);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -22,6 +22,5 @@
|
|||||||
#define SYS_waitpid 18
|
#define SYS_waitpid 18
|
||||||
#define SYS_access 19
|
#define SYS_access 19
|
||||||
#define SYS_fstat 20
|
#define SYS_fstat 20
|
||||||
#define SYS_pstat 21
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,24 +0,0 @@
|
|||||||
#include <luna/pstat.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
pid_t pstat(pid_t pid, struct pstat* buf)
|
|
||||||
{
|
|
||||||
return syscall(SYS_pstat, pid, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* pstname(struct pstat* buf)
|
|
||||||
{
|
|
||||||
switch (buf->pt_state)
|
|
||||||
{
|
|
||||||
case PT_IDLE: return "Idle";
|
|
||||||
case PT_RUNNING: return "Running";
|
|
||||||
case PT_SLEEPING: return "Sleeping";
|
|
||||||
case PT_WAITING: return "Waiting";
|
|
||||||
case PT_ZOMBIE: return "Zombie";
|
|
||||||
default: return "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ extern "C" long syscall(long number, ...)
|
|||||||
case SYS_munmap:
|
case SYS_munmap:
|
||||||
case SYS_access:
|
case SYS_access:
|
||||||
case SYS_fstat:
|
case SYS_fstat:
|
||||||
case SYS_pstat:
|
|
||||||
case SYS_open: {
|
case SYS_open: {
|
||||||
arg arg0 = va_arg(ap, arg);
|
arg arg0 = va_arg(ap, arg);
|
||||||
arg arg1 = va_arg(ap, arg);
|
arg arg1 = va_arg(ap, arg);
|
||||||
|
Loading…
Reference in New Issue
Block a user