Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #433

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/arc/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct thread_info {
int preempt_count; /* 0 => preemptable, <0 => BUG */
struct task_struct *task; /* main task structure */
mm_segment_t addr_limit; /* thread address space */
__u32 cpu; /* current CPU */
__u32 cpu; /* current CPU, processִ�е�CPU */
unsigned long thr_ptr; /* TLS ptr */
};

Expand Down
73 changes: 42 additions & 31 deletions arch/x86/include/uapi/asm/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,48 @@ typedef unsigned long sigset_t;
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */


#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
/*
��������:
A ȱʡ�Ķ�������ֹ����
B ȱʡ�Ķ����Ǻ��Դ��ź�
C ȱʡ�Ķ�������ֹ���̲������ں�ӳ��ת����dump core��
D ȱʡ�Ķ�����ֹͣ����
E �źŲ��ܱ�����
F �źŲ��ܱ�����
*/
/* �ź�Ҳ�����жϣ��ǽ��̼�ͨ�ŵ�һ�ַ�ʽ, �ź�ֻ������֪ͨij���̷�
** ����ʲô�¼����������ý��̴����κ����� */

#define SIGHUP 1 /* (A) �ն˹�����߿��ƽ�����ֹ */
#define SIGINT 2 /* (A) �����жϣ���break�������£� */
#define SIGQUIT 3 /* (C) ���̵��˳��������� */
#define SIGILL 4 /* (C) �Ƿ�ָ��*/
#define SIGTRAP 5 /* () */
#define SIGABRT 6 /* (C) ��abort(3)�������˳�ָ��*/
#define SIGIOT 6 /* ()*/
#define SIGBUS 7 /* ()*/
#define SIGFPE 8 /* (C) �����쳣 */
#define SIGKILL 9 /* (AEF) Kill�ź� */
#define SIGUSR1 10 /* ()*/
#define SIGSEGV 11 /* (C) ��Ч���ڴ�����*/
#define SIGUSR2 12 /* ()*/
#define SIGPIPE 13 /* (A) �ܵ�����: дһ��û�ж��˿ڵĹܵ� */
#define SIGALRM 14 /* (A) ��alarm(2)�������ź�*/
#define SIGTERM 15 /* (A) ��ֹ�ź�*/
#define SIGSTKFLT 16 /* ()*/
#define SIGCHLD 17 /* (B) �ӽ��̽����ź� */
#define SIGCONT 18 /* ()*/
#define SIGSTOP 19 /* ()*/
#define SIGTSTP 20 /* ()*/
#define SIGTTIN 21 /* ()*/
#define SIGTTOU 22 /* ()*/
#define SIGURG 23 /* ()*/
#define SIGXCPU 24 /* ()*/
#define SIGXFSZ 25 /* ()*/
#define SIGVTALRM 26 /* ()*/
#define SIGPROF 27 /* ()*/
#define SIGWINCH 28 /* ()*/
#define SIGIO 29 /* ()*/
#define SIGPOLL SIGIO
/*
#define SIGLOST 29
Expand Down
2 changes: 1 addition & 1 deletion include/linux/fdtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static inline bool fd_is_open(unsigned int fd, const struct fdtable *fdt)
}

/*
* Open file table structure
* Open file table structure�����ܱ����process��������α����ͻ
*/
struct files_struct {
/*
Expand Down
4 changes: 3 additions & 1 deletion include/linux/mm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct mem_cgroup;
* of struct page. That is currently only used by slub but the arrangement
* allows the use of atomic double word operations on the flags/mapping
* and lru list pointers also.
*
* ����ṹ�������������ڴ汾�����������������е�����
*/
struct page {
/* First double word block */
Expand Down Expand Up @@ -100,7 +102,7 @@ struct page {
* Usage count, *USE WRAPPER FUNCTION* when manual
* accounting. See page_ref.h
*/
atomic_t _refcount;
atomic_t _refcount; /* �������ҳ�����õĴ�����������ֵΪ-1ʱ������û�����ã��·����ʱ�����ʹ���� */
};
};

Expand Down
4 changes: 2 additions & 2 deletions include/linux/nsproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct fs_struct;
struct nsproxy {
atomic_t count;
struct uts_namespace *uts_ns;
struct ipc_namespace *ipc_ns;
struct mnt_namespace *mnt_ns;
struct ipc_namespace *ipc_ns; /* ���̼�ͨ�� */
struct mnt_namespace *mnt_ns; /* �ҽӵ��ļ�ϵͳ */
struct pid_namespace *pid_ns_for_children;
struct net *net_ns;
struct cgroup_namespace *cgroup_ns;
Expand Down
11 changes: 6 additions & 5 deletions include/linux/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <linux/rculist.h>

/* ע�⣬������TGID(�߳���Id)����Ϊ���������߳��鳤ID���� */
enum pid_type
{
PIDTYPE_PID,
Expand Down Expand Up @@ -49,19 +50,19 @@ enum pid_type

struct upid {
/* Try to keep pid_chain in the same cacheline as nr for find_vpid */
int nr;
struct pid_namespace *ns;
int nr; /* ����id */
struct pid_namespace *ns; /* ����id��Ӧ��namespace */
struct hlist_node pid_chain;
};

struct pid
{
atomic_t count;
unsigned int level;
unsigned int level; /* ���Կ�����process��namespace�����ռ���Ŀ����������� */
/* lists of tasks that use this pid */
struct hlist_head tasks[PIDTYPE_MAX];
struct hlist_head tasks[PIDTYPE_MAX]; /* ���task_struct���Թ���һ��Id(����PGID)�������������� */
struct rcu_head rcu;
struct upid numbers[1];
struct upid numbers[1]; /* ÿ���������Ӧһ�������ռ� */
};

extern struct pid init_struct_pid;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/pid_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct pid_namespace {
unsigned int nr_hashed;
struct task_struct *child_reaper;
struct kmem_cache *pid_cachep;
unsigned int level;
unsigned int level; /* �̳еȼ������������м���parent */
struct pid_namespace *parent;
#ifdef CONFIG_PROC_FS
struct vfsmount *proc_mnt;
Expand Down
45 changes: 40 additions & 5 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,42 @@ struct task_struct {
#endif
/* -1 unrunnable, 0 runnable, >0 stopped: */
volatile long state;

/* �ں�ջ */
void *stack;

/* (REM)
* used by get_task_struct(). It's also set in kernel/fork.c.
* This value acts like a reference count on the task structure
* of a process. It can be used if we don't want to hold the
* tasklist_lock.
*/
atomic_t usage;
/* Per task flags (PF_*), defined further below: */

/* REM
* Per task flags (PF_*), defined further below:
* process flag can be, for example, PF_DEAD when exit_notify()
* is called. List is of possible values is in include/linux/sched.h
*/
unsigned int flags;

/* (REM)
* used by ptrace a system call that provides the ability to a
* parent process to observe and control the execution of another
* process
*/
unsigned int ptrace;

#ifdef CONFIG_SMP
struct llist_node wake_entry;
struct llist_node wake_entry; /* list�ҽӵ㣬 ���ڵ���*/

/* (REM)
* a lock when context switching and wanting to have interrupts
* enabled during a context switch in order to avoid high latency
* by having an unlocked runqueue. Basically when it's 0 then the
* task can be moved to a different cpu.��process���е�cpu������
* thread_info
*/
int on_cpu;
#ifdef CONFIG_THREAD_INFO_IN_TASK
/* Current CPU: */
Expand All @@ -511,8 +539,9 @@ struct task_struct {
#endif
int on_rq;

/* ���ȼ�*/
int prio;
int static_prio;
int static_prio; /* ��̬���ȼ��ڽ��������ķ��䣬����ͬnice��sched_setscheduler�޸� */
int normal_prio;
unsigned int rt_priority;

Expand All @@ -530,9 +559,15 @@ struct task_struct {
#endif

#ifdef CONFIG_BLK_DEV_IO_TRACE
/*
* ��blktrace�����ڿ��豸���ԣ�
*/
unsigned int btrace_seq;
#endif

/* REM
* the scheduling policy used for this process.
*/
unsigned int policy;
int nr_cpus_allowed;
cpumask_t cpus_allowed;
Expand Down Expand Up @@ -614,7 +649,7 @@ struct task_struct {
struct restart_block restart_block;

pid_t pid;
pid_t tgid;
pid_t tgid; /* �߳���id thread group id */

#ifdef CONFIG_CC_STACKPROTECTOR
/* Canary value for the -fstack-protector GCC feature: */
Expand All @@ -637,7 +672,7 @@ struct task_struct {
*/
struct list_head children;
struct list_head sibling;
struct task_struct *group_leader;
struct task_struct *group_leader; /* ָ��process group�����߳� */

/*
* 'ptraced' is the list of tasks this task is using ptrace() on.
Expand Down
2 changes: 1 addition & 1 deletion include/uapi/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
* cloning flags:
*/
#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
#define CSIGNAL 0x000000ff /* signal mask to be sent at exit�����1�ֽ����ź�ֵ */
#define CLONE_VM 0x00000100 /* set if VM shared between processes */
#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
Expand Down
25 changes: 20 additions & 5 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)

if (node == NUMA_NO_NODE)
node = tsk_fork_get_node(orig);
tsk = alloc_task_struct_node(node);
tsk = alloc_task_struct_node(node); /* ������̽ṹ�� */
if (!tsk)
return NULL;

stack = alloc_thread_stack_node(tsk, node);
stack = alloc_thread_stack_node(tsk, node); /* ����process��ջ */
if (!stack)
goto free_tsk;

Expand Down Expand Up @@ -1274,7 +1274,7 @@ static int copy_files(unsigned long clone_flags, struct task_struct *tsk)
goto out;

if (clone_flags & CLONE_FILES) {
atomic_inc(&oldf->count);
atomic_inc(&oldf->count); /* �븸���̹���file table */
goto out;
}

Expand Down Expand Up @@ -1526,15 +1526,24 @@ static __latent_entropy struct task_struct *copy_process(
int retval;
struct task_struct *p;

/*
* CLONE_NEWNS��־��ʾ�ӽ�����Ҫ�Լ��������ռ䣬��CLONE_FS������ӽ��̹�
* �������̵ĸ�Ŀ¼�͵�ǰ����Ŀ¼�����߲��ɼ��ݡ�
*/
if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
return ERR_PTR(-EINVAL);

/*
*
*/
if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS))
return ERR_PTR(-EINVAL);

/*
* Thread groups must share signals as well, and detached threads
* can only be started up within the thread group.
*
* ����ӽ��̺͸���������ͬһ���߳��飬��ô�ӽ��̱��빲�������̵��ź�
*/
if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND))
return ERR_PTR(-EINVAL);
Expand All @@ -1543,6 +1552,9 @@ static __latent_entropy struct task_struct *copy_process(
* Shared signal handlers imply shared VM. By way of the above,
* thread groups also imply shared VM. Blocking this case allows
* for various simplifications in other code.
*
* ����ӽ��̹��������̵��źţ���ô����ͬʱ���������̵��ڴ�����������
* �е�ҳ��
*/
if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
return ERR_PTR(-EINVAL);
Expand All @@ -1568,12 +1580,12 @@ static __latent_entropy struct task_struct *copy_process(
return ERR_PTR(-EINVAL);
}

retval = security_task_create(clone_flags);
retval = security_task_create(clone_flags); /* ִ�����и��ӵİ�ȫ�Լ�� */
if (retval)
goto fork_out;

retval = -ENOMEM;
p = dup_task_struct(current, node);
p = dup_task_struct(current, node); /* ���������̵ĸ��� */
if (!p)
goto fork_out;

Expand Down Expand Up @@ -1995,6 +2007,9 @@ struct task_struct *fork_idle(int cpu)
*
* It copies the process, and if successful kick-starts
* it and waits for it to finish using the VM if required.
*
* clone_flags:���1�ֽ����ӽ��̽��������������̵��źţ�������ֽ���flags���
* tls ��Thread Local Storage descriptor
*/
long _do_fork(unsigned long clone_flags,
unsigned long stack_start,
Expand Down
1 change: 1 addition & 0 deletions kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

static struct kmem_cache *nsproxy_cachep;

/* ȫ�������ռ� */
struct nsproxy init_nsproxy = {
.count = ATOMIC_INIT(1),
.uts_ns = &init_uts_ns,
Expand Down
2 changes: 1 addition & 1 deletion kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define pid_hashfn(nr, ns) \
hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
static struct hlist_head *pid_hash;
static struct hlist_head *pid_hash; /* ����ָ�������ռ��в��Ҷ�Ӧpid������struct pid */
static unsigned int pidhash_shift = 4;
struct pid init_struct_pid = INIT_STRUCT_PID;

Expand Down
23 changes: 23 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local PD = {"__KERNEL__"}
local file_path = "D:\\github\\czlc\\linux\\arch\\x86\\configs\\x86_64_defconfig"
local file_data = io.open(file_path, "r"):read("*a")

for w in string.gmatch(file_data, "[^\n\r]+") do
if (string.sub(w, 1, 1) ~= "#") then
local M,C = string.gsub(w, "(%w+)=y", "%1")
if (C == 1) then
table.insert(PD, M)
end
end
end


workspace "kernel"
configurations { "Debug" }

project "kernel"
kind "ConsoleApp"
language "C"
files { "**.*" }
includedirs { "." }
defines(PD)