1 | /*************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (C) 2001 International Business Machines |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of the GPFS mmfslinux kernel module. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions |
---|
10 | * are met: |
---|
11 | * |
---|
12 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer in the |
---|
16 | * documentation and/or other materials provided with the distribution. |
---|
17 | * 3. The name of the author may not be used to endorse or promote products |
---|
18 | * derived from this software without specific prior written |
---|
19 | * permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
---|
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
---|
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
---|
27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
---|
28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
---|
30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | *************************************************************************** */ |
---|
33 | /* @(#)39 1.2 src/avs/fs/mmfs/ts/kernext/gpl-linux/x86_64/ss_x86_64.c, mmfs, avs_rgpfs24, rgpfs240610b 9/15/04 23:29:31 */ |
---|
34 | /* |
---|
35 | * Implementation of shared segment for GPFS daemon and GPFS kernel code. |
---|
36 | * |
---|
37 | */ |
---|
38 | |
---|
39 | #include <Shark-gpl.h> |
---|
40 | #include <linux/types.h> |
---|
41 | #include <linux/version.h> |
---|
42 | #include <linux/kernel.h> |
---|
43 | #include <linux/module.h> |
---|
44 | #include <linux/errno.h> |
---|
45 | #include <linux/slab.h> |
---|
46 | #include <linux/smp_lock.h> |
---|
47 | #include <linux/proc_fs.h> |
---|
48 | #include <linux/mm.h> |
---|
49 | #include <linux/fs.h> |
---|
50 | #include <linux/file.h> |
---|
51 | #include <linux/binfmts.h> |
---|
52 | #include <linux/signal.h> |
---|
53 | #include <linux/vmalloc.h> |
---|
54 | |
---|
55 | #include <asm/pgtable.h> |
---|
56 | #include <asm/pgalloc.h> |
---|
57 | #include <asm/io.h> |
---|
58 | #include <asm/uaccess.h> |
---|
59 | #include <asm/user.h> |
---|
60 | #include <asm/mman.h> |
---|
61 | #include <asm/atomic.h> |
---|
62 | #include <asm/ptrace.h> |
---|
63 | |
---|
64 | #include <verdep.h> |
---|
65 | #include <arch-gpl.h> |
---|
66 | |
---|
67 | /* |
---|
68 | * Function spec: |
---|
69 | * |
---|
70 | * Return a user_regs_struct <sys/user.h> for a particular thread |
---|
71 | * |
---|
72 | * For a particular task id, cycle thru each task via |
---|
73 | * for_each_task(task_id) |
---|
74 | * |
---|
75 | * Look for the requested thread |
---|
76 | * task_structP->pid |
---|
77 | * |
---|
78 | * Some of the registers are found within the thread_struct sub structure |
---|
79 | * pointed to by the task structure, see include/asm-x86_64/processor.h |
---|
80 | * |
---|
81 | * All the other regs are found via the stack pointer thread.rsp0 |
---|
82 | */ |
---|
83 | |
---|
84 | int |
---|
85 | kxSaveThreadInfo(int tid, void* regP) |
---|
86 | { |
---|
87 | struct task_struct *g,*t; |
---|
88 | int rc = ENOENT; |
---|
89 | struct pt_regs *kregsP; |
---|
90 | struct user_regs_struct userRegs; |
---|
91 | long data, i; |
---|
92 | |
---|
93 | read_lock(&tasklist_lock); |
---|
94 | DO_EACH_THREAD(g,t) |
---|
95 | { |
---|
96 | if (t->pid != tid) |
---|
97 | continue; |
---|
98 | |
---|
99 | userRegs.fs = t->thread.fs; |
---|
100 | userRegs.gs = t->thread.gs; |
---|
101 | userRegs.es = t->thread.es; |
---|
102 | userRegs.ds = t->thread.ds; |
---|
103 | userRegs.fs_base = t->thread.fsindex; /* ??? */ |
---|
104 | userRegs.gs_base = t->thread.gsindex; /* ??? */ |
---|
105 | |
---|
106 | /* Not really sure if this is always true, can't find any docs for this, |
---|
107 | * but it appears to work */ |
---|
108 | kregsP = (struct pt_regs*)(t->thread.rsp0 - sizeof(struct pt_regs)); |
---|
109 | |
---|
110 | /* user_regs_struct is identical to pt_regs up to the size of pt_regs */ |
---|
111 | memcpy(&userRegs, kregsP, sizeof(struct pt_regs)); |
---|
112 | |
---|
113 | /* I'm not proud of this code. I don't know why it works, |
---|
114 | * but it does. I'll have to figure out why one of these days */ |
---|
115 | userRegs.rsp = t->thread.userrsp; |
---|
116 | userRegs.r15 = kregsP->rbx; |
---|
117 | userRegs.r14 = kregsP->rbp; |
---|
118 | userRegs.r13 = kregsP->r12; |
---|
119 | userRegs.r12 = kregsP->r13; |
---|
120 | userRegs.rbp = kregsP->r14; |
---|
121 | userRegs.rbx = kregsP->r15; |
---|
122 | |
---|
123 | rc = 0; |
---|
124 | goto found_it; |
---|
125 | } WHILE_EACH_THREAD(g,t); |
---|
126 | found_it: |
---|
127 | read_unlock(&tasklist_lock); |
---|
128 | |
---|
129 | if (rc == 0) |
---|
130 | copy_to_user(regP, &userRegs, sizeof(struct user_regs_struct)); |
---|
131 | return rc; |
---|
132 | } |
---|