mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
reading from/writing to non-existant MSRs via /dev/msr no longer crashes the system
This commit is contained in:
parent
eee8fc8f2a
commit
03d71535ec
4 changed files with 36 additions and 3 deletions
|
@ -397,7 +397,8 @@ archread(Chan *c, void *a, long n, vlong offset)
|
|||
error(Ebadarg);
|
||||
vp = a;
|
||||
for(port = offset; port < offset+n; port += 8)
|
||||
rdmsr(port, vp++);
|
||||
if(tryrdmsr(port, vp++) < 0)
|
||||
error(Ebadarg);
|
||||
return n;
|
||||
|
||||
case Qioalloc:
|
||||
|
@ -475,7 +476,8 @@ archwrite(Chan *c, void *a, long n, vlong offset)
|
|||
error(Ebadarg);
|
||||
vp = a;
|
||||
for(port = offset; port < offset+n; port += 8)
|
||||
wrmsr(port, *vp++);
|
||||
if(trywrmsr(port, *vp++) < 0)
|
||||
error(Ebadarg);
|
||||
return n;
|
||||
|
||||
default:
|
||||
|
|
|
@ -167,6 +167,10 @@ void trapenable(int, void (*)(Ureg*, void*), void*, char*);
|
|||
void trapinit(void);
|
||||
void trapinit0(void);
|
||||
int tas(void*);
|
||||
int tryrdmsr(int, vlong*);
|
||||
void tryrdmsrbody(void);
|
||||
int trywrmsr(int, vlong);
|
||||
void trywrmsrbody(void);
|
||||
uvlong tscticks(uvlong*);
|
||||
ulong umbmalloc(ulong, int, int);
|
||||
void umbfree(ulong, int);
|
||||
|
|
|
@ -691,6 +691,17 @@ TEXT rdmsr(SB), $0 /* model-specific register */
|
|||
MOVL AX, 0(CX) /* lo */
|
||||
MOVL DX, 4(CX) /* hi */
|
||||
RET
|
||||
|
||||
TEXT tryrdmsr(SB), $0 /* model-specific register */
|
||||
MOVL $0, BP
|
||||
MOVL index+0(FP), CX
|
||||
TEXT tryrdmsrbody(SB), $0
|
||||
RDMSR
|
||||
MOVL vlong+4(FP), CX /* &vlong */
|
||||
MOVL AX, 0(CX) /* lo */
|
||||
MOVL DX, 4(CX) /* hi */
|
||||
MOVL BP, AX
|
||||
RET
|
||||
|
||||
TEXT wrmsr(SB), $0
|
||||
MOVL index+0(FP), CX
|
||||
|
@ -699,6 +710,16 @@ TEXT wrmsr(SB), $0
|
|||
WRMSR
|
||||
RET
|
||||
|
||||
TEXT trywrmsr(SB), $0
|
||||
MOVL $0, BP
|
||||
MOVL index+0(FP), CX
|
||||
MOVL lo+4(FP), AX
|
||||
MOVL hi+8(FP), DX
|
||||
TEXT trywrmsrbody(SB), $0
|
||||
WRMSR
|
||||
MOVL BP, AX
|
||||
RET
|
||||
|
||||
/*
|
||||
* Try to determine the CPU type which requires fiddling with EFLAGS.
|
||||
* If the Id bit can be toggled then the CPUID instruction can be used
|
||||
|
|
|
@ -463,7 +463,13 @@ trap(Ureg* ureg)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(vno == VectorGPF && !user &&
|
||||
(ureg->pc == (ulong)(void*)tryrdmsrbody ||
|
||||
ureg->pc == (ulong)(void*)trywrmsrbody)){
|
||||
ureg->bp = -1;
|
||||
ureg->pc += 2;
|
||||
return;
|
||||
}
|
||||
dumpregs(ureg);
|
||||
if(!user){
|
||||
ureg->sp = (ulong)&ureg->sp;
|
||||
|
|
Loading…
Reference in a new issue