forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/x86/kernel/fpu/regset.c
....@@ -15,24 +15,19 @@
1515 */
1616 int regset_fpregs_active(struct task_struct *target, const struct user_regset *regset)
1717 {
18
- struct fpu *target_fpu = &target->thread.fpu;
19
-
20
- return target_fpu->initialized ? regset->n : 0;
18
+ return regset->n;
2119 }
2220
2321 int regset_xregset_fpregs_active(struct task_struct *target, const struct user_regset *regset)
2422 {
25
- struct fpu *target_fpu = &target->thread.fpu;
26
-
27
- if (boot_cpu_has(X86_FEATURE_FXSR) && target_fpu->initialized)
23
+ if (boot_cpu_has(X86_FEATURE_FXSR))
2824 return regset->n;
2925 else
3026 return 0;
3127 }
3228
3329 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
34
- unsigned int pos, unsigned int count,
35
- void *kbuf, void __user *ubuf)
30
+ struct membuf to)
3631 {
3732 struct fpu *fpu = &target->thread.fpu;
3833
....@@ -42,8 +37,7 @@
4237 fpu__prepare_read(fpu);
4338 fpstate_sanitize_xstate(fpu);
4439
45
- return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
46
- &fpu->state.fxsave, 0, -1);
40
+ return membuf_write(&to, &fpu->state.fxsave, sizeof(struct fxregs_state));
4741 }
4842
4943 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
....@@ -78,12 +72,10 @@
7872 }
7973
8074 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
81
- unsigned int pos, unsigned int count,
82
- void *kbuf, void __user *ubuf)
75
+ struct membuf to)
8376 {
8477 struct fpu *fpu = &target->thread.fpu;
8578 struct xregs_state *xsave;
86
- int ret;
8779
8880 if (!boot_cpu_has(X86_FEATURE_XSAVE))
8981 return -ENODEV;
....@@ -93,10 +85,8 @@
9385 fpu__prepare_read(fpu);
9486
9587 if (using_compacted_format()) {
96
- if (kbuf)
97
- ret = copy_xstate_to_kernel(kbuf, xsave, pos, count);
98
- else
99
- ret = copy_xstate_to_user(ubuf, xsave, pos, count);
88
+ copy_xstate_to_kernel(to, xsave);
89
+ return 0;
10090 } else {
10191 fpstate_sanitize_xstate(fpu);
10292 /*
....@@ -109,9 +99,8 @@
10999 /*
110100 * Copy the xstate memory layout.
111101 */
112
- ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
102
+ return membuf_write(&to, xsave, fpu_user_xstate_size);
113103 }
114
- return ret;
115104 }
116105
117106 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
....@@ -143,7 +132,7 @@
143132 } else {
144133 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
145134 if (!ret)
146
- ret = validate_xstate_header(&xsave->header);
135
+ ret = validate_user_xstate_header(&xsave->header);
147136 }
148137
149138 /*
....@@ -269,11 +258,10 @@
269258 memcpy(&to[i], &from[i], sizeof(to[0]));
270259 }
271260
272
-void convert_to_fxsr(struct task_struct *tsk,
261
+void convert_to_fxsr(struct fxregs_state *fxsave,
273262 const struct user_i387_ia32_struct *env)
274263
275264 {
276
- struct fxregs_state *fxsave = &tsk->thread.fpu.state.fxsave;
277265 struct _fpreg *from = (struct _fpreg *) &env->st_space[0];
278266 struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0];
279267 int i;
....@@ -298,8 +286,7 @@
298286 }
299287
300288 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
301
- unsigned int pos, unsigned int count,
302
- void *kbuf, void __user *ubuf)
289
+ struct membuf to)
303290 {
304291 struct fpu *fpu = &target->thread.fpu;
305292 struct user_i387_ia32_struct env;
....@@ -307,23 +294,22 @@
307294 fpu__prepare_read(fpu);
308295
309296 if (!boot_cpu_has(X86_FEATURE_FPU))
310
- return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf);
297
+ return fpregs_soft_get(target, regset, to);
311298
312
- if (!boot_cpu_has(X86_FEATURE_FXSR))
313
- return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
314
- &fpu->state.fsave, 0,
315
- -1);
299
+ if (!boot_cpu_has(X86_FEATURE_FXSR)) {
300
+ return membuf_write(&to, &fpu->state.fsave,
301
+ sizeof(struct fregs_state));
302
+ }
316303
317304 fpstate_sanitize_xstate(fpu);
318305
319
- if (kbuf && pos == 0 && count == sizeof(env)) {
320
- convert_from_fxsr(kbuf, target);
306
+ if (to.left == sizeof(env)) {
307
+ convert_from_fxsr(to.p, target);
321308 return 0;
322309 }
323310
324311 convert_from_fxsr(&env, target);
325
-
326
- return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &env, 0, -1);
312
+ return membuf_write(&to, &env, sizeof(env));
327313 }
328314
329315 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
....@@ -350,7 +336,7 @@
350336
351337 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &env, 0, -1);
352338 if (!ret)
353
- convert_to_fxsr(target, &env);
339
+ convert_to_fxsr(&target->thread.fpu.state.fxsave, &env);
354340
355341 /*
356342 * update the header bit in the xsave header, indicating the
....@@ -360,28 +346,5 @@
360346 fpu->state.xsave.header.xfeatures |= XFEATURE_MASK_FP;
361347 return ret;
362348 }
363
-
364
-/*
365
- * FPU state for core dumps.
366
- * This is only used for a.out dumps now.
367
- * It is declared generically using elf_fpregset_t (which is
368
- * struct user_i387_struct) but is in fact only used for 32-bit
369
- * dumps, so on 64-bit it is really struct user_i387_ia32_struct.
370
- */
371
-int dump_fpu(struct pt_regs *regs, struct user_i387_struct *ufpu)
372
-{
373
- struct task_struct *tsk = current;
374
- struct fpu *fpu = &tsk->thread.fpu;
375
- int fpvalid;
376
-
377
- fpvalid = fpu->initialized;
378
- if (fpvalid)
379
- fpvalid = !fpregs_get(tsk, NULL,
380
- 0, sizeof(struct user_i387_ia32_struct),
381
- ufpu, NULL);
382
-
383
- return fpvalid;
384
-}
385
-EXPORT_SYMBOL(dump_fpu);
386349
387350 #endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */