📄 linux_0
字号:
//linux kernel 源代码
1 #
2 # Makefile for the linux kernel.
3 #
4 # Note! Dependencies are done automagically by 'make dep', which also
5 # removes any old dependencies. DON'T put your own dependencies here
6 # unless it's something special (ie not a .c file).
7 #
8 # Note 2! The CFLAGS definitions are now in the main makefile...
9
10 .S.s:
11 $(CPP) -traditional $< -o $*.s
12 .c.s:
13 $(CC) $(CFLAGS) -S $<
14 .s.o:
15 $(AS) -c -o $*.o $<
16 .c.o:
17 $(CC) $(CFLAGS) -c $<
18
19 OBJS = sched.o sys_call.o traps.o irq.o dma.o fork.o \
20 panic.o printk.o vsprintf.o sys.o module.o ksyms.o exit.o \
21 signal.o mktime.o ptrace.o ioport.o itimer.o \
22 info.o ldt.o time.o
23
24 all: kernel.o
25
26 kernel.o: $(OBJS)
27 $(LD) -r -o kernel.o $(OBJS)
28 sync
29
30 sys_call.s: sys_call.S
31
32 sys_call.o: sys_call.s
33
34 sched.o: sched.c
35 $(CC) $(CFLAGS) $(PROFILING) -fno-omit-frame-pointer -c $<
36
37 ksyms.lst: ksyms.S ../include/linux/autoconf.h
38 $(CPP) $(CFLAGS) $< > $@
39
40 ksyms.s: ksyms.sh ksyms.lst
41 sh $< > $@
42
43 ksyms.o: ksyms.s
44
45 dep:
46 $(CPP) -M *.c > .depend
47
48 dummy:
49
50 #
51 # include a dependency file if one exists
52 #
53 ifeq (.depend,$(wildcard .depend))
54 include .depend
55 endif
56
--------------------------
1 /* $Id: dma.c,v 1.5 1992/11/18 02:49:05 root Exp root $
2 * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c.
3 * Written by Hennus Bergman, 1992.
4 */
5
6 #include <linux/kernel.h>
7 #include <linux/errno.h>
8 #include <asm/dma.h>
9
10
11 /* A note on resource allocation:
12 *
13 * All drivers needing DMA channels, should allocate and release them
14 * through the public routines `request_dma()' and `free_dma()'.
15 *
16 * In order to avoid problems, all processes should allocate resources in
17 * the same sequence and release them in the reverse order.
18 *
19 * So, when allocating DMAs and IRQs, first allocate the IRQ, then the DMA.
20 * When releasing them, first release the DMA, then release the IRQ.
21 * If you don't, you may cause allocation requests to fail unnecessarily.
22 * This doesn't really matter now, but it will once we get real semaphores
23 * in the kernel.
24 */
25
26
27
28 /* Channel n is busy iff dma_chan_busy[n] != 0.
29 * DMA0 is reserved for DRAM refresh, I think.
30 * DMA4 is reserved for cascading (?).
31 */
32 static volatile unsigned int dma_chan_busy[MAX_DMA_CHANNELS] = {
33 1, 0, 0, 0, 1, 0, 0, 0
34 };
35
36
37
38 /* Atomically swap memory location [32 bits] with `newval'.
39 * This avoid the cli()/sti() junk and related problems.
40 * [And it's faster too :-)]
41 * Maybe this should be in include/asm/mutex.h and be used for
42 * implementing kernel-semaphores as well.
43 */
44 static __inline__ unsigned int mutex_atomic_swap(volatile unsigned int * p, unsigned int newval)
45 {
46 unsigned int semval = newval;
47
48 /* If one of the operands for the XCHG instructions is a memory ref,
49 * it makes the swap an uninterruptible RMW cycle.
50 *
51 * One operand must be in memory, the other in a register, otherwise
52 * the swap may not be atomic.
53 */
54
55 asm __volatile__ ("xchgl %2, %0\n"
56 : /* outputs: semval */ "=r" (semval)
57 : /* inputs: newval, p */ "" (semval), "m" (*p)
58 ); /* p is a var, containing an address */
59 return semval;
60 } /* mutex_atomic_swap */
61
62
63
64 int request_dma(unsigned int dmanr)
65 {
66 if (dmanr >= MAX_DMA_CHANNELS)
67 return -EINVAL;
68
69 if (mutex_atomic_swap(&dma_chan_busy[dmanr], 1) != 0)
70 return -EBUSY;
71 else
72 /* old flag was 0, now contains 1 to indicate busy */
73 return 0;
74 } /* request_dma */
75
76
77 void free_dma(unsigned int dmanr)
78 {
79 if (dmanr >= MAX_DMA_CHANNELS) {
80 printk("Trying to free DMA%d\n", dmanr);
81 return;
82 }
83
84 if (mutex_atomic_swap(&dma_chan_busy[dmanr], 0) == 0)
85 printk("Trying to free free DMA%d\n", dmanr);
86 } /* free_dma */
87
88
------------------------------
1 /*
2 * linux/kernel/exit.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7 #define DEBUG_PROC_TREE
8
9 #include <linux/wait.h>
10 #include <linux/errno.h>
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/resource.h>
15 #include <linux/mm.h>
16 #include <linux/tty.h>
17 #include <linux/malloc.h>
18
19 #include <asm/segment.h>
20 extern void shm_exit (void);
21 extern void sem_exit (void);
22
23 int getrusage(struct task_struct *, int, struct rusage *);
24
25 static int generate(unsigned long sig, struct task_struct * p)
26 {
27 unsigned long mask = 1 << (sig-1);
28 struct sigaction * sa = sig + p->sigaction - 1;
29
30 /* always generate signals for traced processes ??? */
31 if (p->flags & PF_PTRACED) {
32 p->signal |= mask;
33 return 1;
34 }
35 /* don't bother with ignored signals (but SIGCHLD is special) */
36 if (sa->sa_handler == SIG_IGN && sig != SIGCHLD)
37 return 0;
38 /* some signals are ignored by default.. (but SIGCONT already did its deed) */
39 if ((sa->sa_handler == SIG_DFL) &&
40 (sig == SIGCONT || sig == SIGCHLD || sig == SIGWINCH))
41 return 0;
42 p->signal |= mask;
43 return 1;
44 }
45
46 int send_sig(unsigned long sig,struct task_struct * p,int priv)
47 {
48 if (!p || sig > 32)
49 return -EINVAL;
50 if (!priv && ((sig != SIGCONT) || (current->session != p->session)) &&
51 (current->euid != p->euid) && (current->uid != p->uid) && !suser())
52 return -EPERM;
53 if (!sig)
54 return 0;
55 if ((sig == SIGKILL) || (sig == SIGCONT)) {
56 if (p->state == TASK_STOPPED)
57 p->state = TASK_RUNNING;
58 p->exit_code = 0;
59 p->signal &= ~( (1<<(SIGSTOP-1)) | (1<<(SIGTSTP-1)) |
60 (1<<(SIGTTIN-1)) | (1<<(SIGTTOU-1)) );
61 }
62 /* Depends on order SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU */
63 if ((sig >= SIGSTOP) && (sig <= SIGTTOU))
64 p->signal &= ~(1<<(SIGCONT-1));
65 /* Actually generate the signal */
66 generate(sig,p);
67 return 0;
68 }
69
70 void notify_parent(struct task_struct * tsk)
71 {
72 if (tsk->p_pptr == task[1])
73 tsk->exit_signal = SIGCHLD;
74 send_sig(tsk->exit_signal, tsk->p_pptr, 1);
75 wake_up_interruptible(&tsk->p_pptr->wait_chldexit);
76 }
77
78 void release(struct task_struct * p)
79 {
80 int i;
81
82 if (!p)
83 return;
84 if (p == current) {
85 printk("task releasing itself\n");
86 return;
87 }
88 for (i=1 ; i<NR_TASKS ; i++)
89 if (task[i] == p) {
90 task[i] = NULL;
91 REMOVE_LINKS(p);
92 if (STACK_MAGIC != *(unsigned long *)p->kernel_stack_page)
93 printk(KERN_ALERT "release: %s kernel stack corruption. Aiee\n", p->comm);
94 free_page(p->kernel_stack_page);
95 free_page((long) p);
96 return;
97 }
98 panic("trying to release non-existent task");
99 }
100
101 #ifdef DEBUG_PROC_TREE
102 /*
103 * Check to see if a task_struct pointer is present in the task[] array
104 * Return 0 if found, and 1 if not found.
105 */
106 int bad_task_ptr(struct task_struct *p)
107 {
108 int i;
109
110 if (!p)
111 return 0;
112 for (i=0 ; i<NR_TASKS ; i++)
113 if (task[i] == p)
114 return 0;
115 return 1;
116 }
117
118 /*
119 * This routine scans the pid tree and make sure the rep invarient still
120 * holds. Used for debugging only, since it's very slow....
121 *
122 * It looks a lot scarier than it really is.... we're doing nothing more
123 * than verifying the doubly-linked list found in p_ysptr and p_osptr,
124 * and checking it corresponds with the process tree defined by p_cptr and
125 * p_pptr;
126 */
127 void audit_ptree(void)
128 {
129 int i;
130
131 for (i=1 ; i<NR_TASKS ; i++) {
132 if (!task[i])
133 continue;
134 if (bad_task_ptr(task[i]->p_pptr))
135 printk("Warning, pid %d's parent link is bad\n",
136 task[i]->pid);
137 if (bad_task_ptr(task[i]->p_cptr))
138 printk("Warning, pid %d's child link is bad\n",
139 task[i]->pid);
140 if (bad_task_ptr(task[i]->p_ysptr))
141 printk("Warning, pid %d's ys link is bad\n",
142 task[i]->pid);
143 if (bad_task_ptr(task[i]->p_osptr))
144 printk("Warning, pid %d's os link is bad\n",
145 task[i]->pid);
146 if (task[i]->p_pptr == task[i])
147 printk("Warning, pid %d parent link points to self\n",
148 task[i]->pid);
149 if (task[i]->p_cptr == task[i])
150 printk("Warning, pid %d child link points to self\n",
151 task[i]->pid);
152 if (task[i]->p_ysptr == task[i])
153 printk("Warning, pid %d ys link points to self\n",
154 task[i]->pid);
155 if (task[i]->p_osptr == task[i])
156 printk("Warning, pid %d os link points to self\n",
157 task[i]->pid);
158 if (task[i]->p_osptr) {
159 if (task[i]->p_pptr != task[i]->p_osptr->p_pptr)
160 printk(
161 "Warning, pid %d older sibling %d parent is %d\n",
162 task[i]->pid, task[i]->p_osptr->pid,
163 task[i]->p_osptr->p_pptr->pid);
164 if (task[i]->p_osptr->p_ysptr != task[i])
165 printk(
166 "Warning, pid %d older sibling %d has mismatched ys link\n",
167 task[i]->pid, task[i]->p_osptr->pid);
168 }
169 if (task[i]->p_ysptr) {
170 if (task[i]->p_pptr != task[i]->p_ysptr->p_pptr)
171 printk(
172 "Warning, pid %d younger sibling %d parent is %d\n",
173 task[i]->pid, task[i]->p_osptr->pid,
174 task[i]->p_osptr->p_pptr->pid);
175 if (task[i]->p_ysptr->p_osptr != task[i])
176 printk(
177 "Warning, pid %d younger sibling %d has mismatched os link\n",
178 task[i]->pid, task[i]->p_ysptr->pid);
179 }
180 if (task[i]->p_cptr) {
181 if (task[i]->p_cptr->p_pptr != task[i])
182 printk(
183 "Warning, pid %d youngest child %d has mismatched parent link\n",
184 task[i]->pid, task[i]->p_cptr->pid);
185 if (task[i]->p_cptr->p_ysptr)
186 printk(
187 "Warning, pid %d youngest child %d has non-NULL ys link\n",
188 task[i]->pid, task[i]->p_cptr->pid);
189 }
190 }
191 }
192 #endif /* DEBUG_PROC_TREE */
193
194 /*
195 * This checks not only the pgrp, but falls back on the pid if no
196 * satisfactory prgp is found. I dunno - gdb doesn't work correctly
197 * without this...
198 */
199 int session_of_pgrp(int pgrp)
200 {
201 struct task_struct *p;
202 int fallback;
203
204 fallback = -1;
205 for_each_task(p) {
206 if (p->session <= 0)
207 continue;
208 if (p->pgrp == pgrp)
209 return p->session;
210 if (p->pid == pgrp)
211 fallback = p->session;
212 }
213 return fallback;
214 }
215
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -