@@ -790,6 +790,19 @@ static inline int jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
790
790
return assign_eip_near (ctxt , ctxt -> _eip + rel );
791
791
}
792
792
793
+ static int linear_read_system (struct x86_emulate_ctxt * ctxt , ulong linear ,
794
+ void * data , unsigned size )
795
+ {
796
+ return ctxt -> ops -> read_std (ctxt , linear , data , size , & ctxt -> exception );
797
+ }
798
+
799
+ static int linear_write_system (struct x86_emulate_ctxt * ctxt ,
800
+ ulong linear , void * data ,
801
+ unsigned int size )
802
+ {
803
+ return ctxt -> ops -> write_std (ctxt , linear , data , size , & ctxt -> exception );
804
+ }
805
+
793
806
static int segmented_read_std (struct x86_emulate_ctxt * ctxt ,
794
807
struct segmented_address addr ,
795
808
void * data ,
@@ -1488,8 +1501,7 @@ static int read_interrupt_descriptor(struct x86_emulate_ctxt *ctxt,
1488
1501
return emulate_gp (ctxt , index << 3 | 0x2 );
1489
1502
1490
1503
addr = dt .address + index * 8 ;
1491
- return ctxt -> ops -> read_std (ctxt , addr , desc , sizeof * desc ,
1492
- & ctxt -> exception );
1504
+ return linear_read_system (ctxt , addr , desc , sizeof * desc );
1493
1505
}
1494
1506
1495
1507
static void get_descriptor_table_ptr (struct x86_emulate_ctxt * ctxt ,
@@ -1552,8 +1564,7 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
1552
1564
if (rc != X86EMUL_CONTINUE )
1553
1565
return rc ;
1554
1566
1555
- return ctxt -> ops -> read_std (ctxt , * desc_addr_p , desc , sizeof (* desc ),
1556
- & ctxt -> exception );
1567
+ return linear_read_system (ctxt , * desc_addr_p , desc , sizeof (* desc ));
1557
1568
}
1558
1569
1559
1570
/* allowed just for 8 bytes segments */
@@ -1567,8 +1578,7 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
1567
1578
if (rc != X86EMUL_CONTINUE )
1568
1579
return rc ;
1569
1580
1570
- return ctxt -> ops -> write_std (ctxt , addr , desc , sizeof * desc ,
1571
- & ctxt -> exception );
1581
+ return linear_write_system (ctxt , addr , desc , sizeof * desc );
1572
1582
}
1573
1583
1574
1584
static int __load_segment_descriptor (struct x86_emulate_ctxt * ctxt ,
@@ -1729,8 +1739,7 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
1729
1739
return ret ;
1730
1740
}
1731
1741
} else if (ctxt -> mode == X86EMUL_MODE_PROT64 ) {
1732
- ret = ctxt -> ops -> read_std (ctxt , desc_addr + 8 , & base3 ,
1733
- sizeof (base3 ), & ctxt -> exception );
1742
+ ret = linear_read_system (ctxt , desc_addr + 8 , & base3 , sizeof (base3 ));
1734
1743
if (ret != X86EMUL_CONTINUE )
1735
1744
return ret ;
1736
1745
if (is_noncanonical_address (get_desc_base (& seg_desc ) |
@@ -2043,11 +2052,11 @@ static int __emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq)
2043
2052
eip_addr = dt .address + (irq << 2 );
2044
2053
cs_addr = dt .address + (irq << 2 ) + 2 ;
2045
2054
2046
- rc = ops -> read_std (ctxt , cs_addr , & cs , 2 , & ctxt -> exception );
2055
+ rc = linear_read_system (ctxt , cs_addr , & cs , 2 );
2047
2056
if (rc != X86EMUL_CONTINUE )
2048
2057
return rc ;
2049
2058
2050
- rc = ops -> read_std (ctxt , eip_addr , & eip , 2 , & ctxt -> exception );
2059
+ rc = linear_read_system (ctxt , eip_addr , & eip , 2 );
2051
2060
if (rc != X86EMUL_CONTINUE )
2052
2061
return rc ;
2053
2062
@@ -3025,35 +3034,30 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
3025
3034
u16 tss_selector , u16 old_tss_sel ,
3026
3035
ulong old_tss_base , struct desc_struct * new_desc )
3027
3036
{
3028
- const struct x86_emulate_ops * ops = ctxt -> ops ;
3029
3037
struct tss_segment_16 tss_seg ;
3030
3038
int ret ;
3031
3039
u32 new_tss_base = get_desc_base (new_desc );
3032
3040
3033
- ret = ops -> read_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3034
- & ctxt -> exception );
3041
+ ret = linear_read_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
3035
3042
if (ret != X86EMUL_CONTINUE )
3036
3043
return ret ;
3037
3044
3038
3045
save_state_to_tss16 (ctxt , & tss_seg );
3039
3046
3040
- ret = ops -> write_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3041
- & ctxt -> exception );
3047
+ ret = linear_write_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
3042
3048
if (ret != X86EMUL_CONTINUE )
3043
3049
return ret ;
3044
3050
3045
- ret = ops -> read_std (ctxt , new_tss_base , & tss_seg , sizeof tss_seg ,
3046
- & ctxt -> exception );
3051
+ ret = linear_read_system (ctxt , new_tss_base , & tss_seg , sizeof tss_seg );
3047
3052
if (ret != X86EMUL_CONTINUE )
3048
3053
return ret ;
3049
3054
3050
3055
if (old_tss_sel != 0xffff ) {
3051
3056
tss_seg .prev_task_link = old_tss_sel ;
3052
3057
3053
- ret = ops -> write_std (ctxt , new_tss_base ,
3054
- & tss_seg .prev_task_link ,
3055
- sizeof tss_seg .prev_task_link ,
3056
- & ctxt -> exception );
3058
+ ret = linear_write_system (ctxt , new_tss_base ,
3059
+ & tss_seg .prev_task_link ,
3060
+ sizeof tss_seg .prev_task_link );
3057
3061
if (ret != X86EMUL_CONTINUE )
3058
3062
return ret ;
3059
3063
}
@@ -3169,38 +3173,34 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
3169
3173
u16 tss_selector , u16 old_tss_sel ,
3170
3174
ulong old_tss_base , struct desc_struct * new_desc )
3171
3175
{
3172
- const struct x86_emulate_ops * ops = ctxt -> ops ;
3173
3176
struct tss_segment_32 tss_seg ;
3174
3177
int ret ;
3175
3178
u32 new_tss_base = get_desc_base (new_desc );
3176
3179
u32 eip_offset = offsetof(struct tss_segment_32 , eip );
3177
3180
u32 ldt_sel_offset = offsetof(struct tss_segment_32 , ldt_selector );
3178
3181
3179
- ret = ops -> read_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3180
- & ctxt -> exception );
3182
+ ret = linear_read_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
3181
3183
if (ret != X86EMUL_CONTINUE )
3182
3184
return ret ;
3183
3185
3184
3186
save_state_to_tss32 (ctxt , & tss_seg );
3185
3187
3186
3188
/* Only GP registers and segment selectors are saved */
3187
- ret = ops -> write_std (ctxt , old_tss_base + eip_offset , & tss_seg .eip ,
3188
- ldt_sel_offset - eip_offset , & ctxt -> exception );
3189
+ ret = linear_write_system (ctxt , old_tss_base + eip_offset , & tss_seg .eip ,
3190
+ ldt_sel_offset - eip_offset );
3189
3191
if (ret != X86EMUL_CONTINUE )
3190
3192
return ret ;
3191
3193
3192
- ret = ops -> read_std (ctxt , new_tss_base , & tss_seg , sizeof tss_seg ,
3193
- & ctxt -> exception );
3194
+ ret = linear_read_system (ctxt , new_tss_base , & tss_seg , sizeof tss_seg );
3194
3195
if (ret != X86EMUL_CONTINUE )
3195
3196
return ret ;
3196
3197
3197
3198
if (old_tss_sel != 0xffff ) {
3198
3199
tss_seg .prev_task_link = old_tss_sel ;
3199
3200
3200
- ret = ops -> write_std (ctxt , new_tss_base ,
3201
- & tss_seg .prev_task_link ,
3202
- sizeof tss_seg .prev_task_link ,
3203
- & ctxt -> exception );
3201
+ ret = linear_write_system (ctxt , new_tss_base ,
3202
+ & tss_seg .prev_task_link ,
3203
+ sizeof tss_seg .prev_task_link );
3204
3204
if (ret != X86EMUL_CONTINUE )
3205
3205
return ret ;
3206
3206
}
0 commit comments