Move e_pid and e_pgid to libprocess, Add get_self_pid () syscall
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m13s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m13s
This commit is contained in:
6
ce/ce.c
6
ce/ce.c
@@ -3,13 +3,14 @@
|
|||||||
#include "gapbuffer.h"
|
#include "gapbuffer.h"
|
||||||
#include "interp.h"
|
#include "interp.h"
|
||||||
#include "mprintf.h"
|
#include "mprintf.h"
|
||||||
#include "self.h"
|
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include <arena.h>
|
#include <arena.h>
|
||||||
|
#include <debugconsole.h>
|
||||||
#include <kb.h>
|
#include <kb.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
|
#include <process_self.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -63,8 +64,7 @@ static void exec_line (const char* line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void app_main (void) {
|
void app_main (void) {
|
||||||
e_pid = get_exec_pid ();
|
libprocess_self_init ();
|
||||||
e_pgid = get_procgroup (e_pid);
|
|
||||||
|
|
||||||
struct edit_line edit_line;
|
struct edit_line edit_line;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "arena_alloc.h"
|
#include "arena_alloc.h"
|
||||||
#include "gapbuffer.h"
|
#include "gapbuffer.h"
|
||||||
#include "mprintf.h"
|
#include "mprintf.h"
|
||||||
#include "self.h"
|
|
||||||
#include "walloc.h"
|
#include "walloc.h"
|
||||||
#include <arena.h>
|
#include <arena.h>
|
||||||
#include <filewriter.h>
|
#include <filewriter.h>
|
||||||
@@ -11,6 +10,7 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <path.h>
|
#include <path.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
|
#include <process_self.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -231,7 +231,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
|||||||
(int)(editor.cursor.line - editor.row_offset) + 1,
|
(int)(editor.cursor.line - editor.row_offset) + 1,
|
||||||
(int)(editor.cursor.col - editor.col_offset) + 1 + (int)gutter_width);
|
(int)(editor.cursor.col - editor.col_offset) + 1 + (int)gutter_width);
|
||||||
|
|
||||||
mail_send (e_pgid, backbuffer, bbptr - backbuffer);
|
mail_send (process_get_exec_pgid (), backbuffer, bbptr - backbuffer);
|
||||||
|
|
||||||
uint8_t ch = 0;
|
uint8_t ch = 0;
|
||||||
mail_receive (&ch, 1);
|
mail_receive (&ch, 1);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "edit.h"
|
#include "edit.h"
|
||||||
#include "mprintf.h"
|
#include "mprintf.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "self.h"
|
|
||||||
#include <debugconsole.h>
|
#include <debugconsole.h>
|
||||||
#include <desc.h>
|
#include <desc.h>
|
||||||
#include <filereader.h>
|
#include <filereader.h>
|
||||||
@@ -16,6 +15,7 @@
|
|||||||
#include <path.h>
|
#include <path.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
|
#include <process_self.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <str_status.h>
|
#include <str_status.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -160,7 +160,7 @@ static void cat (struct context* context, char** file_paths, size_t files_count)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mail_send (e_pgid, buffer, chunk_size);
|
mail_send (process_get_exec_pgid (), buffer, chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rem > 0) {
|
if (rem > 0) {
|
||||||
@@ -170,7 +170,7 @@ static void cat (struct context* context, char** file_paths, size_t files_count)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mail_send (e_pgid, buffer, rem);
|
mail_send (process_get_exec_pgid (), buffer, rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
filereader_fini (&fr);
|
filereader_fini (&fr);
|
||||||
@@ -357,7 +357,7 @@ static void cmd_collect_proc (void* arg) {
|
|||||||
char recv[RECV_MAX];
|
char recv[RECV_MAX];
|
||||||
memset (recv, 0, sizeof (recv));
|
memset (recv, 0, sizeof (recv));
|
||||||
if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK) {
|
if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK) {
|
||||||
mail_send (e_pgid, recv, strlen (recv));
|
mail_send (process_get_exec_pgid (), recv, strlen (recv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "mprintf.h"
|
#include "mprintf.h"
|
||||||
#include "self.h"
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
|
#include <process_self.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
@@ -22,6 +22,6 @@ void mprintf (const char* fmt, ...) {
|
|||||||
|
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
mail_send (e_pgid, buf, len);
|
mail_send (process_get_exec_pgid (), buf, len);
|
||||||
free (buf);
|
free (buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef _SELF_H
|
|
||||||
#define _SELF_H
|
|
||||||
|
|
||||||
extern int e_pid;
|
|
||||||
extern int e_pgid;
|
|
||||||
|
|
||||||
#endif // _SELF_H
|
|
||||||
@@ -5,7 +5,6 @@ c += ce.c \
|
|||||||
parser.c \
|
parser.c \
|
||||||
interp.c \
|
interp.c \
|
||||||
mprintf.c \
|
mprintf.c \
|
||||||
self.c \
|
|
||||||
gapbuffer.c \
|
gapbuffer.c \
|
||||||
edit.c
|
edit.c
|
||||||
|
|
||||||
@@ -16,6 +15,5 @@ o += ce.o \
|
|||||||
parser.o \
|
parser.o \
|
||||||
interp.o \
|
interp.o \
|
||||||
mprintf.o \
|
mprintf.o \
|
||||||
self.o \
|
|
||||||
gapbuffer.o \
|
gapbuffer.o \
|
||||||
edit.o
|
edit.o
|
||||||
|
|||||||
@@ -35,5 +35,6 @@
|
|||||||
#define SYS_EXEC_PARTIAL 32
|
#define SYS_EXEC_PARTIAL 32
|
||||||
#define SYS_EXEC_PARTIAL_FINI 33
|
#define SYS_EXEC_PARTIAL_FINI 33
|
||||||
#define SYS_MAIL_RECEIVE_NONBLOCK 34
|
#define SYS_MAIL_RECEIVE_NONBLOCK 34
|
||||||
|
#define SYS_GET_SELF_PID 35
|
||||||
|
|
||||||
#endif // _M_SYSCALL_DEFS_H
|
#endif // _M_SYSCALL_DEFS_H
|
||||||
|
|||||||
@@ -1022,6 +1022,17 @@ DEFINE_SYSCALL (sys_env_get) {
|
|||||||
return SYSRESULT (proc_env_set (target_procgroup, key, buffer, size));
|
return SYSRESULT (proc_env_set (target_procgroup, key, buffer, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* int get_self_pid (void) */
|
||||||
|
DEFINE_SYSCALL (sys_get_self_pid) {
|
||||||
|
uint64_t fp;
|
||||||
|
|
||||||
|
spin_lock (&proc->lock, &fp);
|
||||||
|
int pid = proc->pid;
|
||||||
|
spin_unlock (&proc->lock, fp);
|
||||||
|
|
||||||
|
return SYSRESULT (pid);
|
||||||
|
}
|
||||||
|
|
||||||
static syscall_handler_func_t handler_table[] = {
|
static syscall_handler_func_t handler_table[] = {
|
||||||
[SYS_QUIT] = &sys_quit,
|
[SYS_QUIT] = &sys_quit,
|
||||||
[SYS_TEST] = &sys_test,
|
[SYS_TEST] = &sys_test,
|
||||||
@@ -1057,6 +1068,7 @@ static syscall_handler_func_t handler_table[] = {
|
|||||||
[SYS_EXEC_PARTIAL] = &sys_exec_partial,
|
[SYS_EXEC_PARTIAL] = &sys_exec_partial,
|
||||||
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
||||||
[SYS_MAIL_RECEIVE_NONBLOCK] = &sys_mail_receive_nonblock,
|
[SYS_MAIL_RECEIVE_NONBLOCK] = &sys_mail_receive_nonblock,
|
||||||
|
[SYS_GET_SELF_PID] = &sys_get_self_pid,
|
||||||
};
|
};
|
||||||
|
|
||||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||||
|
|||||||
22
libprocess/process_self.c
Normal file
22
libprocess/process_self.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <process_self.h>
|
||||||
|
#include <system.h>
|
||||||
|
|
||||||
|
static int e_pid;
|
||||||
|
static int e_pgid;
|
||||||
|
static int pid;
|
||||||
|
static int pgid;
|
||||||
|
|
||||||
|
void libprocess_self_init (void) {
|
||||||
|
e_pid = get_exec_pid ();
|
||||||
|
e_pgid = get_procgroup (e_pid);
|
||||||
|
pid = get_self_pid ();
|
||||||
|
pgid = get_procgroup (pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int process_get_exec_pid (void) { return e_pid; }
|
||||||
|
|
||||||
|
int process_get_exec_pgid (void) { return e_pgid; }
|
||||||
|
|
||||||
|
int process_get_pid (void) { return pid; }
|
||||||
|
|
||||||
|
int process_get_pgid (void) { return pgid; }
|
||||||
14
libprocess/process_self.h
Normal file
14
libprocess/process_self.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef _LIBPROCESS_PROCESS_SELF_H
|
||||||
|
#define _LIBPROCESS_PROCESS_SELF_H
|
||||||
|
|
||||||
|
void libprocess_self_init (void);
|
||||||
|
|
||||||
|
int process_get_exec_pid (void);
|
||||||
|
|
||||||
|
int process_get_exec_pgid (void);
|
||||||
|
|
||||||
|
int process_get_pid (void);
|
||||||
|
|
||||||
|
int process_get_pgid (void);
|
||||||
|
|
||||||
|
#endif // _LIBPROCESS_PROCESS_SELF_H
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
include $(platform)/src.mk
|
include $(platform)/src.mk
|
||||||
|
|
||||||
c += process.c
|
c += process.c \
|
||||||
|
process_self.c
|
||||||
|
|
||||||
o += process.o
|
o += process.o \
|
||||||
|
process_self.o
|
||||||
|
|||||||
@@ -104,3 +104,5 @@ int exec_partial (const char* volume, const char* path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int exec_partial_fini (int pid) { return (int)do_syscall (SYS_EXEC_PARTIAL_FINI, pid); }
|
int exec_partial_fini (int pid) { return (int)do_syscall (SYS_EXEC_PARTIAL_FINI, pid); }
|
||||||
|
|
||||||
|
int get_self_pid (void) { return (int)do_syscall (SYS_GET_SELF_PID, 0); }
|
||||||
|
|||||||
@@ -108,4 +108,7 @@ int exec_partial (const char* volume, const char* path);
|
|||||||
/* Finish process for execution - run it! */
|
/* Finish process for execution - run it! */
|
||||||
int exec_partial_fini (int pid);
|
int exec_partial_fini (int pid);
|
||||||
|
|
||||||
|
/* get this process' PID */
|
||||||
|
int get_self_pid (void);
|
||||||
|
|
||||||
#endif // _LIBMSL_M_SYSTEM_H
|
#endif // _LIBMSL_M_SYSTEM_H
|
||||||
|
|||||||
Reference in New Issue
Block a user