source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/gpl-linux/i386/ss_i386.c @ 152

Last change on this file since 152 was 16, checked in by rock, 17 years ago
File size: 5.5 KB
Line 
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/* @(#)85       1.24.1.1  src/avs/fs/mmfs/ts/kernext/gpl-linux/i386/ss_i386.c, mmfs, avs_rgpfs24, rgpfs24s007a 10/8/06 03:17:10 */
34/*
35 * Implementation of shared segment for GPFS daemon and GPFS kernel code.
36 *
37 */
38
39#include <Shark-gpl.h>
40#include <linux/config.h>
41#include <linux/types.h>
42#include <linux/version.h>
43#include <linux/kernel.h>
44#include <linux/module.h>
45#include <linux/errno.h>
46#include <linux/slab.h>
47#include <linux/smp_lock.h>
48#include <linux/proc_fs.h>
49#include <linux/mm.h>
50#include <linux/fs.h>
51#include <linux/file.h>
52#include <linux/binfmts.h>
53#include <linux/signal.h>
54#include <linux/vmalloc.h>
55
56#include <asm/pgtable.h>
57#include <asm/pgalloc.h>
58#include <asm/io.h>
59#include <asm/uaccess.h>
60#include <asm/user.h>
61#include <asm/mman.h>
62#include <asm/atomic.h>
63#include <asm/ptrace.h>
64
65#include <verdep.h>
66#include <arch-gpl.h>
67
68/*
69 * Function spec:
70 *
71 * Return a user_regs_struct <sys/user.h> for a particular thread
72 *
73 * For a particular task id, cycle thru each task via
74 *   for_each_task(task_id)
75 *
76 * Look for the requested thread
77 *   task_structP->pid
78 *
79 * A couple of the registers are found within the thread sub structure
80 * pointed to by the task structure.
81 *   task_structP->thread.fs
82 *   task_structP->thread.gs 
83 *
84 * All the other regs are found via the stack pointer thread.esp0
85 * The stack pointer points at the last element in a
86 * struct pt_regs <linux/ptrace.h>.  The elements of the pt_regs
87 * grow down from the stack pointer offset.
88 *
89 *               Thus if thread.esp0 is 0xC0000000
90 *                     pt_regs.ss       0xBFFFFFFC
91 *                     pt_regs.esp      0xBFFFFFF8
92 *                     pt_regs.eflags   0xBFFFFFF4
93 *                     pt_regs.xcs      0xBFFFFFF0
94 *                     pt_regs.eip      0xBFFFFFEC
95 *                     pt_regs.orig_eax 0xBFFFFFE8
96 *                     pt_regs.xes      0xBFFFFFE4
97 *                     pt_regs.xds      0xBFFFFFE0
98 *                     pt_regs.eax      0xBFFFFFDC
99 *                     pt_regs.ebp      0xBFFFFFD8
100 *                     pt_regs.edi      0xBFFFFFD4
101 *                     pt_regs.esi      0xBFFFFFD0
102 *                     pt_regs.edx      0xBFFFFFCC
103 *                     pt_regs.ecx      0xBFFFFFC8
104 *                     pt_regs.ebx      0xBFFFFFC4
105 */
106
107int
108kxSaveThreadInfo(int tid, void* regP)
109{
110  struct task_struct *g, *t;
111  unsigned char *stackP;
112  int rc = ENOENT;
113  union
114  {
115    struct user_regs_struct userRegs;
116    unsigned long regArray[0];
117  } u;
118
119#define STACKP(A) (*(unsigned long *)(stackP - \
120                     (unsigned char *)(sizeof(struct pt_regs) - \
121                                       (long)&((struct pt_regs *)0)->A)))
122#define REGARRAY(A)  \
123          u.regArray[(long)&(((struct user_regs_struct *)0)->A) / sizeof(long)]
124
125  // read_lock(&tasklist_lock);
126  rcu_read_lock(); 
127
128  DO_EACH_THREAD(g,t)
129  {
130    if (t->pid != tid)
131      continue;
132
133    REGARRAY(fs) = t->thread.fs;
134    REGARRAY(gs) = t->thread.gs;
135
136    stackP = (char *)t->thread.esp0;
137
138    REGARRAY(ss)       = STACKP(xss);
139    REGARRAY(esp)      = STACKP(esp);
140    REGARRAY(eflags)   = STACKP(eflags);
141    REGARRAY(cs)       = STACKP(xcs);
142    REGARRAY(eip)      = STACKP(eip);
143    REGARRAY(orig_eax) = STACKP(orig_eax);
144    REGARRAY(es)       = STACKP(xes);
145    REGARRAY(ds)       = STACKP(xds);
146    REGARRAY(eax)      = STACKP(eax);
147    REGARRAY(ebp)      = STACKP(ebp);
148    REGARRAY(edi)      = STACKP(edi);
149    REGARRAY(esi)      = STACKP(esi);
150    REGARRAY(edx)      = STACKP(edx);
151    REGARRAY(ecx)      = STACKP(ecx);
152    REGARRAY(ebx)      = STACKP(ebx);
153
154    rc = 0;
155    goto found_it;
156  } WHILE_EACH_THREAD(g,t);
157found_it:
158  // read_unlock(&tasklist_lock);
159  rcu_read_unlock();
160
161  if (rc == 0)
162    rc = copy_to_user(regP, &u.userRegs, sizeof(struct user_regs_struct));
163  return rc;
164} 
Note: See TracBrowser for help on using the repository browser.