I am now actually making the list that contains all the system calls. I'm planning on making a new source code file that contains all the list and some functions related to it. I will implement these Three Function :
void init_sys_call_table_list(void);
void register_sys_call_tables(void);
void add_sys_call_table(linux_binfmt *bin_handler , sys_call_ptr *tbl_ptr);
init_sys_call_table_list() function initializes the list that maintains all the system call tables. register_sys_call_tables() function is the crucial part. This function is architecture-dependent, which means this function should be implemented with consideration of architecture... The function should be implemented in different way for each architecture. For example, x86_64 architecture will have to make this function add x86_64 system call table of linux and windows. arm architecture will have to make this function add arm system call tables. blah blah. Finally, add_system_call_table() function actually adds the table into list.
I made very tiny progress on implementing these functions. I just created new base files for establishing my system. Here's some snippet of it..
dynamic_sys_call_table.h at include/linux/
#ifndef _DYNAMIC_SYS_CALL_TABLE_H_
#define _DYNAMIC_SYS_CALL_TABLE_H_
#include <linux/linkage.h>
#include <linux/sys.h>
#include <linux/cache.h>
#include <asm/syscall.h>
#include <linux/binfmts.h>
#include <linux/list.h>
struct sys_call_array_container {
// binary handler
struct linux_binfmt *bin_handler;
// system call table
sys_call_ptr_t *tbl_ptr;
struct list_head lst;
};
// Add system call table to list
void init_sys_call_table_list(void);
void register_sys_call_tables(void);
void add_sys_call_tables(struct linux_binfmt *bin_handler , sys_call_ptr_t *tbl_ptr);
#endif
dynamic_sys_call_table.c at kernel/
#include <linux/dynamic_sys_call_table.h>
// Declare list here!
static LIST_HEAD(sys_call_list);
EXPORT_SYMBOL(init_sys_call_table_list);
void init_sys_call_table_list(void) {
INIT_LIST_HEAD(&sys_call_list);
register_sys_call_tables();
}
void add_sys_call_tables(struct linux_binfmt *bin_handler , sys_call_ptr_t *tbl_ptr) {
struct sys_call_array_container new_container = {
.bin_handler = bin_handler ,
.tbl_ptr = tbl_ptr ,
};
list_add(&new_container.lst , &sys_call_list);
}
sys_call_ptr_t *search_by_binfmt(struct linux_binfmt *bin_handler) {
struct sys_call_array_container *cur;
sys_call_ptr_t *tbl_ptr = 0x00;
list_for_each_entry(cur , &sys_call_list , lst) {
if(cur->bin_handler == bin_handler) {
tbl_ptr = cur->tbl_ptr;
}
}
return tbl_ptr;
}
While I was trying to figure out where the sys_call_table exists, I stumbled upon this source file...
sys_call_table_x64.c at arch/x86/um/
// SPDX-License-Identifier: GPL-2.0
/*
* System call table for UML/x86-64, copied from arch/x86/kernel/syscall_*.c
* with some changes for UML.
*/
#include <linux/linkage.h>
#include <linux/sys.h>
#include <linux/cache.h>
#include <asm/syscall.h>
/*
* Below you can see, in terms of #define's, the differences between the x86-64
* and the UML syscall table.
*/
/* Not going to be implemented by UML, since we have no hardware. */
#define sys_iopl sys_ni_syscall
#define sys_ioperm sys_ni_syscall
#define __SYSCALL(nr, sym) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
#include <asm/syscalls_64.h>
#undef __SYSCALL
#define __SYSCALL(nr, sym) sym,
extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = {
#include <asm/syscalls_64.h>
};
int syscall_table_size = sizeof(sys_call_table);
This source contained the sys_call_table array, so I just modified some codes and implemented the register_sys_call_tables() function there... Surprisingly nothing worked. It was as if this source was completely excluded from compile process. I tried cleaning and rebuilding. Didn't work. I tried intentionally making error so that compiler will catch the error. Didn't work.
....
(This is me 5 days after this.) Turns out, those files in "um" folder was not in part of compiling process, which means I did nothing but wasting my time trying to make something work THAT WOULD NEVER WORK. At least I know now.
(To be continued in next journal.)