File tree Expand file tree Collapse file tree 9 files changed +42
-3
lines changed Expand file tree Collapse file tree 9 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ void __0x80_init()
31
31
__0x80_add_function (__NR_3_MALLOC ,__0x80_MALLOC );
32
32
__0x80_add_function (__NR_4_FREE , __0x80_FREE );
33
33
__0x80_add_function (__NR_5_EXEC , __0x80_EXEC );
34
+ __0x80_add_function (__NR_6_EXIT , __0x80_EXIT );
34
35
}
35
36
36
37
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ enum __0x80_COMMANDS{
18
18
__NR_2_PUTCH ,
19
19
__NR_3_MALLOC ,
20
20
__NR_4_FREE ,
21
- __NR_5_EXEC
21
+ __NR_5_EXEC ,
22
+ __NR_6_EXIT
22
23
23
24
};
24
25
Original file line number Diff line number Diff line change @@ -19,9 +19,16 @@ void* __0x80_EXEC(struct interrupt_frame* iframe){
19
19
return (void * ) - ERR_PROCESS_CREATION_FAILED ;
20
20
}
21
21
22
+ process_switch (_process );
22
23
task_switch (_process -> task );
23
24
enter_task (& _process -> task -> registers );
24
25
25
26
return (void * ) SUCCESS ;
26
27
28
+ }
29
+
30
+ void * __0x80_EXIT (struct interrupt_frame * iframe ){
31
+ process_kill (process_current ());
32
+ process_back_to_gshell ();
33
+ return (void * ) SUCCESS ;
27
34
}
Original file line number Diff line number Diff line change 4
4
#include "../../idt.h"
5
5
6
6
void * __0x80_EXEC (struct interrupt_frame * iframe );
7
+ void * __0x80_EXIT (struct interrupt_frame * iframe );
7
8
8
9
9
10
#endif
Original file line number Diff line number Diff line change @@ -164,6 +164,12 @@ void process_switch(struct process* _process){
164
164
current_process = _process ;
165
165
}
166
166
167
+ void process_back_to_gshell (){
168
+ process_switch (process_list [0 ]);
169
+ task_switch (process_list [0 ]-> task );
170
+ enter_task (& process_list [0 ]-> task -> registers );
171
+ }
172
+
167
173
static int8_t process_map_memory (struct process * _process ){
168
174
169
175
// if file type is binary
@@ -312,7 +318,7 @@ int process_kill(struct process* _process){
312
318
313
319
// free all data dynamically allocated by the process.
314
320
for (int allocation = 0 ;allocation < PROCESS_MAX_PROCESS_MEM_ALLOCATIONS ; allocation ++ ){
315
- process_free (_process -> mem_allocations [allocation ]) ;
321
+ if (_process -> mem_allocations [allocation ] != 0 ) _process -> mem_allocations [ allocation ] ;
316
322
}
317
323
318
324
// mark pid as free to use
Original file line number Diff line number Diff line change 14
14
struct process * process_get (uint16_t pid );
15
15
struct process * process_new (const char * filename );
16
16
struct process * process_current ();
17
+ void process_switch (struct process * _process );
17
18
void * process_malloc (uint32_t size );
18
19
void * process_free (void * base_addr );
19
20
int process_kill (struct process * _process );
21
+ void process_back_to_gshell ();
20
22
21
23
void process_init ();
22
24
Original file line number Diff line number Diff line change 1
1
OBJ = ./build/_start.s.o ./build/stdio.s.o ./build/stdlib.s.o ./build/stdio.o ./build/stdlib.o ./build/unistd.s.o \
2
- ./build/string.o
2
+ ./build/string.o ./build/_exit.s.o
3
3
INC = -I./include
4
4
FLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-labels -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc
5
5
@@ -9,6 +9,9 @@ all: $(OBJ)
9
9
./build/_start.s.o : ./_start/_start.s
10
10
nasm -f elf ./_start/_start.s -o ./build/_start.s.o
11
11
12
+ ./build/_exit.s.o : ./_exit/_exit.s;
13
+ nasm -f elf ./_exit/_exit.s -o ./build/_exit.s.o
14
+
12
15
./build/stdio.s.o : ./stdio/stdio.s
13
16
nasm -f elf ./stdio/stdio.s -o ./build/stdio.s.o
14
17
Original file line number Diff line number Diff line change
1
+ [BITS 32]
2
+
3
+ section .asm
4
+
5
+ global _exit
6
+
7
+ _exit:
8
+
9
+ push ebp
10
+ mov ebp , esp
11
+
12
+ mov eax , 6 ; call __0x80_EXIT system call handler
13
+ int 0x80
14
+
15
+ pop ebp
16
+ ret
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ section .asm
4
4
5
5
global _start
6
6
extern main
7
+ extern _exit
7
8
8
9
_start:
9
10
10
11
call main
12
+ call _exit
11
13
ret
You can’t perform that action at this time.
0 commit comments