Check that we have statfs before using it.
[wine/multimedia.git] / server / context_sparc.c
blob157f02b6d5e677101f7b4afe51eee5da332ed024
1 /*
2 * Sparc register context support
4 * Copyright (C) 2000 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #ifdef __sparc__
25 #include <assert.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_REG_H
29 # include <sys/reg.h>
30 #endif
31 #include <stdarg.h>
32 #include <unistd.h>
33 #ifdef HAVE_SYS_PTRACE_H
34 # include <sys/ptrace.h>
35 #endif
37 #include "windef.h"
38 #include "winbase.h"
40 #include "file.h"
41 #include "thread.h"
42 #include "request.h"
45 #if defined(__sun) || defined(__sun__)
47 /* retrieve a thread context */
48 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
50 int pid = get_ptrace_pid(thread);
51 if (flags & CONTEXT_FULL)
53 struct regs regs;
54 if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
55 if (flags & CONTEXT_INTEGER)
57 context->g0 = 0;
58 context->g1 = regs.r_g1;
59 context->g2 = regs.r_g2;
60 context->g3 = regs.r_g3;
61 context->g4 = regs.r_g4;
62 context->g5 = regs.r_g5;
63 context->g6 = regs.r_g6;
64 context->g7 = regs.r_g7;
66 context->o0 = regs.r_o0;
67 context->o1 = regs.r_o1;
68 context->o2 = regs.r_o2;
69 context->o3 = regs.r_o3;
70 context->o4 = regs.r_o4;
71 context->o5 = regs.r_o5;
72 context->o6 = regs.r_o6;
73 context->o7 = regs.r_o7;
75 /* FIXME: local and in registers */
77 if (flags & CONTEXT_CONTROL)
79 context->psr = regs.r_psr;
80 context->pc = regs.r_pc;
81 context->npc = regs.r_npc;
82 context->y = regs.r_y;
83 context->wim = 0; /* FIXME */
84 context->tbr = 0; /* FIXME */
87 if (flags & CONTEXT_FLOATING_POINT)
89 /* FIXME */
91 return;
92 error:
93 file_set_error();
97 /* set a thread context */
98 static void set_thread_context( struct thread *thread, unsigned int flags, const CONTEXT *context )
100 /* FIXME */
103 #else /* __sun__ */
104 #error You must implement get/set_thread_context for your platform
105 #endif /* __sun__ */
108 /* copy a context structure according to the flags */
109 static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
111 if (flags & CONTEXT_CONTROL)
113 to->psr = from->psr;
114 to->pc = from->pc;
115 to->npc = from->npc;
116 to->y = from->y;
117 to->wim = from->wim;
118 to->tbr = from->tbr;
120 if (flags & CONTEXT_INTEGER)
122 to->g0 = from->g0;
123 to->g1 = from->g1;
124 to->g2 = from->g2;
125 to->g3 = from->g3;
126 to->g4 = from->g4;
127 to->g5 = from->g5;
128 to->g6 = from->g6;
129 to->g7 = from->g7;
130 to->o0 = from->o0;
131 to->o1 = from->o1;
132 to->o2 = from->o2;
133 to->o3 = from->o3;
134 to->o4 = from->o4;
135 to->o5 = from->o5;
136 to->o6 = from->o6;
137 to->o7 = from->o7;
138 to->l0 = from->l0;
139 to->l1 = from->l1;
140 to->l2 = from->l2;
141 to->l3 = from->l3;
142 to->l4 = from->l4;
143 to->l5 = from->l5;
144 to->l6 = from->l6;
145 to->l7 = from->l7;
146 to->i0 = from->i0;
147 to->i1 = from->i1;
148 to->i2 = from->i2;
149 to->i3 = from->i3;
150 to->i4 = from->i4;
151 to->i5 = from->i5;
152 to->i6 = from->i6;
153 to->i7 = from->i7;
155 if (flags & CONTEXT_FLOATING_POINT)
157 /* FIXME */
161 /* retrieve the current instruction pointer of a thread */
162 void *get_thread_ip( struct thread *thread )
164 CONTEXT context;
165 context.pc = 0;
166 if (suspend_for_ptrace( thread ))
168 get_thread_context( thread, CONTEXT_CONTROL, &context );
169 resume_after_ptrace( thread );
171 return (void *)context.pc;
174 /* determine if we should continue the thread in single-step mode */
175 int get_thread_single_step( struct thread *thread )
177 return 0; /* FIXME */
180 /* send a signal to a specific thread */
181 int tkill( int pid, int sig )
183 /* FIXME: should do something here */
184 errno = ENOSYS;
185 return -1;
188 /* retrieve the current context of a thread */
189 DECL_HANDLER(get_thread_context)
191 struct thread *thread;
192 void *data;
193 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
195 if (get_reply_max_size() < sizeof(CONTEXT))
197 set_error( STATUS_INVALID_PARAMETER );
198 return;
200 if (!(thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT ))) return;
202 if ((data = set_reply_data_size( sizeof(CONTEXT) )))
204 if (thread->context) /* thread is inside an exception event */
206 copy_context( data, thread->context, flags );
207 flags = 0;
209 if (flags && suspend_for_ptrace( thread ))
211 get_thread_context( thread, flags, data );
212 resume_after_ptrace( thread );
215 release_object( thread );
219 /* set the current context of a thread */
220 DECL_HANDLER(set_thread_context)
222 struct thread *thread;
223 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
225 if (get_req_data_size() < sizeof(CONTEXT))
227 set_error( STATUS_INVALID_PARAMETER );
228 return;
230 if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
232 if (thread->context) /* thread is inside an exception event */
234 copy_context( thread->context, get_req_data(), flags );
235 flags = 0;
237 if (flags && suspend_for_ptrace( thread ))
239 set_thread_context( thread, flags, get_req_data() );
240 resume_after_ptrace( thread );
242 release_object( thread );
246 #endif /* __sparc__ */