Skip to content

Commit 6132155

Browse files
committed
Chapter 8
1 parent 72be8e4 commit 6132155

File tree

18 files changed

+770
-287
lines changed

18 files changed

+770
-287
lines changed

.github/workflows/github-autotest.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
name: auto-test
22

3-
on:
3+
on:
44
push:
55

66
jobs:
77
base-test:
88
runs-on: ubuntu-latest
9+
outputs:
10+
points: ${{ steps.end.outputs.points}}
911
container:
1012
image: duskmoon/dev-env:ucore-ci
1113
steps:
1214
- uses: actions/checkout@v3
13-
- run: git clone https://github.com/LearningOS/uCore-Tutorial-Checker-2023S.git ucore-tutorial-ci
15+
- run: git clone https://github.com/LearningOS/uCore-Tutorial-Checker-2023S.git ucore-tutorial-ci
1416
- run: git clone https://github.com/LearningOS/uCore-Tutorial-Test-2023S.git ucore-tutorial-ci/workplace/user
15-
- run: cd ucore-tutorial-ci && make test passwd=${{ secrets.BASE_TEST_TOKEN }} CHAPTER=`echo ${GITHUB_REF##*/} | grep -oP 'ch\K[0-9]'`
16-
17+
- name: run test
18+
id: tester
19+
run: cd ucore-tutorial-ci && make test passwd=${{ secrets.BASE_TEST_TOKEN }} CHAPTER=`echo ${GITHUB_REF##*/} | grep -oP 'ch\K[0-9]'` | tee ../output.txt
20+
- name: end
21+
id: end
22+
run: cat output.txt | grep "Test passed" | grep -oP "\d{1,}/\d{1,}" | xargs -i echo "points={}" >> $GITHUB_OUTPUT
23+
deploy:
24+
if: github.repository != 'LearningOS/uCore-Tutorial-Code-2023S'
25+
name: Deploy to pages
26+
needs: base-test
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
continue-on-error: true
31+
with:
32+
ref: 'gh-pages'
33+
- name: Save Log File
34+
uses: yfblock/multi-rank-log@main
35+
with:
36+
points: ${{ needs.base-test.outputs.points }}
37+
- name: GitHub Pages
38+
uses: crazy-max/ghaction-github-pages@v3
39+
with:
40+
target_branch: gh-pages
41+
build_dir: ./public
42+
keep_history: true
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ build/kernel: $(OBJS) os/kernel.ld
9393

9494
clean:
9595
rm -rf $(BUILDDIR) os/initproc.S
96-
rm -f $(F)/*.img
96+
rm $(F)/*.img
9797

9898
# BOARD
9999
BOARD ?= qemu

os/const.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define TRAPFRAME (TRAMPOLINE - PGSIZE)
2525

2626
#define MAX_APP_NUM (32)
27-
#define MAX_STR_LEN (200)
27+
#define MAX_STR_LEN (300)
2828
#define IDLE_PID (0)
2929
#define MAX_ARG_NUM (32) // max exec arguments
3030

os/file.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ int show_all_files()
6666
}
6767

6868
//Create a new empty file based on path and type and return its inode;
69-
7069
//if the file under the path exists, return its inode;
71-
7270
//returns 0 if the type of file to be created is not T_file
7371
static struct inode *create(char *path, short type)
7472
{
7573
struct inode *ip, *dp;
76-
dp = root_dir(); //Remember that the root_inode is open in this step,so it needs closing then.
74+
//Remember that the root_inode is open in this step,so it needs closing then.
75+
dp = root_dir();
7776
ivalid(dp);
7877
if ((ip = dirlookup(dp, path, 0)) != 0) {
7978
warnf("create a exist file\n");
@@ -99,9 +98,7 @@ static struct inode *create(char *path, short type)
9998
}
10099

101100
//A process creates or opens a file according to its path, returning the file descriptor of the created or opened file.
102-
103101
//If omode is O_CREATE, create a new file
104-
105102
//if omode if the others,open a created file.
106103
int fileopen(char *path, uint64 omode)
107104
{
@@ -122,6 +119,8 @@ int fileopen(char *path, uint64 omode)
122119
if (ip->type != T_FILE)
123120
panic("unsupported file inode type\n");
124121
if ((f = filealloc()) == 0 || (fd = fdalloc(f)) < 0) {
122+
//Assign a system-level table entry to a newly created or opened file
123+
//and then create a file descriptor that points to it
125124
if (f)
126125
fileclose(f);
127126
iput(ip);

os/fs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ int dirlink(struct inode *dp, char *name, uint inum)
428428
return 0;
429429
}
430430

431+
// LAB4: You may want to add dirunlink here
432+
431433
//Return the inode of the root directory
432434
struct inode *root_dir()
433435
{

os/loader.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,14 @@ int bin_loader(struct inode *ip, struct proc *p)
2727
PTE_U | PTE_R | PTE_W | PTE_X) != 0)
2828
panic("...");
2929
}
30-
// map ustack
31-
p->ustack = va_end + PAGE_SIZE;
32-
for (uint64 va = p->ustack; va < p->ustack + USTACK_SIZE;
33-
va += PGSIZE) {
34-
page = kalloc();
35-
if (page == 0) {
36-
panic("...");
37-
}
38-
memset(page, 0, PGSIZE);
39-
if (mappages(p->pagetable, va, PGSIZE, (uint64)page,
40-
PTE_U | PTE_R | PTE_W) != 0)
41-
panic("...");
30+
31+
p->max_page = va_end / PAGE_SIZE;
32+
p->ustack_base = va_end + PAGE_SIZE;
33+
// alloc main thread
34+
if (allocthread(p, va_start, 1) != 0) {
35+
panic("proc %d alloc main thread failed!", p->pid);
4236
}
43-
p->trapframe->sp = p->ustack + USTACK_SIZE;
44-
p->trapframe->epc = va_start;
45-
p->max_page = PGROUNDUP(p->ustack + USTACK_SIZE - 1) / PAGE_SIZE;
46-
p->program_brk = p->ustack + USTACK_SIZE;
47-
p->heap_bottom = p->ustack + USTACK_SIZE;
48-
p->state = RUNNABLE;
37+
debugf("bin loader fin");
4938
return 0;
5039
}
5140

@@ -65,7 +54,9 @@ int load_init_app()
6554
char *argv[2];
6655
argv[0] = INIT_PROC;
6756
argv[1] = NULL;
68-
p->trapframe->a0 = push_argv(p, argv);
69-
add_task(p);
57+
struct thread *t = &p->threads[0];
58+
t->trapframe->a0 = push_argv(p, argv);
59+
t->state = RUNNABLE;
60+
add_task(t);
7061
return 0;
71-
}
62+
}

os/log.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LOG_H
33

44
extern void printf(char *, ...);
5+
extern int procid();
56
extern int threadid();
67
extern void dummy(int, ...);
78
extern void shutdown();
@@ -57,9 +58,9 @@ enum LOG_COLOR {
5758
#if defined(USE_LOG_ERROR)
5859
#define errorf(fmt, ...) \
5960
do { \
60-
int tid = threadid(); \
61-
printf("\x1b[%dm[%s %d]" fmt "\x1b[0m\n", RED, "ERROR", tid, \
62-
##__VA_ARGS__); \
61+
int pid = procid(), tid = threadid(); \
62+
printf("\x1b[%dm[%s %d-%d]" fmt "\x1b[0m\n", RED, "ERROR", \
63+
pid, tid, ##__VA_ARGS__); \
6364
} while (0)
6465
#else
6566
#define errorf(fmt, ...) dummy(0, ##__VA_ARGS__)
@@ -68,9 +69,9 @@ enum LOG_COLOR {
6869
#if defined(USE_LOG_WARN)
6970
#define warnf(fmt, ...) \
7071
do { \
71-
int tid = threadid(); \
72-
printf("\x1b[%dm[%s %d]" fmt "\x1b[0m\n", YELLOW, "WARN", tid, \
73-
##__VA_ARGS__); \
72+
int pid = procid(), tid = threadid(); \
73+
printf("\x1b[%dm[%s %d-%d]" fmt "\x1b[0m\n", YELLOW, "WARN", \
74+
pid, tid, ##__VA_ARGS__); \
7475
} while (0)
7576
#else
7677
#define warnf(fmt, ...) dummy(0, ##__VA_ARGS__)
@@ -79,9 +80,9 @@ enum LOG_COLOR {
7980
#if defined(USE_LOG_INFO)
8081
#define infof(fmt, ...) \
8182
do { \
82-
int tid = threadid(); \
83-
printf("\x1b[%dm[%s %d]" fmt "\x1b[0m\n", BLUE, "INFO", tid, \
84-
##__VA_ARGS__); \
83+
int pid = procid(), tid = threadid(); \
84+
printf("\x1b[%dm[%s %d-%d]" fmt "\x1b[0m\n", BLUE, "INFO", \
85+
pid, tid, ##__VA_ARGS__); \
8586
} while (0)
8687
#else
8788
#define infof(fmt, ...) dummy(0, ##__VA_ARGS__)
@@ -90,9 +91,9 @@ enum LOG_COLOR {
9091
#if defined(USE_LOG_DEBUG)
9192
#define debugf(fmt, ...) \
9293
do { \
93-
int tid = threadid(); \
94-
printf("\x1b[%dm[%s %d]" fmt "\x1b[0m\n", GREEN, "DEBUG", tid, \
95-
##__VA_ARGS__); \
94+
int pid = procid(), tid = threadid(); \
95+
printf("\x1b[%dm[%s %d-%d]" fmt "\x1b[0m\n", GREEN, "DEBUG", \
96+
pid, tid, ##__VA_ARGS__); \
9697
} while (0)
9798
#else
9899
#define debugf(fmt, ...) dummy(0, ##__VA_ARGS__)
@@ -101,19 +102,19 @@ enum LOG_COLOR {
101102
#if defined(USE_LOG_TRACE)
102103
#define tracef(fmt, ...) \
103104
do { \
104-
int tid = threadid(); \
105-
printf("\x1b[%dm[%s %d]" fmt "\x1b[0m\n", GRAY, "TRACE", tid, \
106-
##__VA_ARGS__); \
105+
int pid = procid(), tid = threadid(); \
106+
printf("\x1b[%dm[%s %d-%d]" fmt "\x1b[0m\n", GRAY, "TRACE", \
107+
pid, tid, ##__VA_ARGS__); \
107108
} while (0)
108109
#else
109110
#define tracef(fmt, ...) dummy(0, ##__VA_ARGS__)
110111
#endif // USE_LOG_TRACE
111112

112113
#define panic(fmt, ...) \
113114
do { \
114-
int tid = threadid(); \
115-
printf("\x1b[%dm[%s %d] %s:%d: " fmt "\x1b[0m\n", RED, \
116-
"PANIC", tid, __FILE__, __LINE__, ##__VA_ARGS__); \
115+
int pid = procid(), tid = threadid(); \
116+
printf("\x1b[%dm[%s %d-%d] %s:%d: " fmt "\x1b[0m\n", RED, \
117+
"PANIC", pid, tid, __FILE__, __LINE__, ##__VA_ARGS__); \
117118
shutdown(); \
118119
__builtin_unreachable(); \
119120
} while (0)

0 commit comments

Comments
 (0)