@@ -802,6 +802,19 @@ static inline int jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
802802 return assign_eip_near (ctxt , ctxt -> _eip + rel );
803803}
804804
805+ static int linear_read_system (struct x86_emulate_ctxt * ctxt , ulong linear ,
806+ void * data , unsigned size )
807+ {
808+ return ctxt -> ops -> read_std (ctxt , linear , data , size , & ctxt -> exception );
809+ }
810+
811+ static int linear_write_system (struct x86_emulate_ctxt * ctxt ,
812+ ulong linear , void * data ,
813+ unsigned int size )
814+ {
815+ return ctxt -> ops -> write_std (ctxt , linear , data , size , & ctxt -> exception );
816+ }
817+
805818static int segmented_read_std (struct x86_emulate_ctxt * ctxt ,
806819 struct segmented_address addr ,
807820 void * data ,
@@ -1500,8 +1513,7 @@ static int read_interrupt_descriptor(struct x86_emulate_ctxt *ctxt,
15001513 return emulate_gp (ctxt , index << 3 | 0x2 );
15011514
15021515 addr = dt .address + index * 8 ;
1503- return ctxt -> ops -> read_std (ctxt , addr , desc , sizeof * desc ,
1504- & ctxt -> exception );
1516+ return linear_read_system (ctxt , addr , desc , sizeof * desc );
15051517}
15061518
15071519static void get_descriptor_table_ptr (struct x86_emulate_ctxt * ctxt ,
@@ -1564,8 +1576,7 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
15641576 if (rc != X86EMUL_CONTINUE )
15651577 return rc ;
15661578
1567- return ctxt -> ops -> read_std (ctxt , * desc_addr_p , desc , sizeof (* desc ),
1568- & ctxt -> exception );
1579+ return linear_read_system (ctxt , * desc_addr_p , desc , sizeof (* desc ));
15691580}
15701581
15711582/* allowed just for 8 bytes segments */
@@ -1579,8 +1590,7 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
15791590 if (rc != X86EMUL_CONTINUE )
15801591 return rc ;
15811592
1582- return ctxt -> ops -> write_std (ctxt , addr , desc , sizeof * desc ,
1583- & ctxt -> exception );
1593+ return linear_write_system (ctxt , addr , desc , sizeof * desc );
15841594}
15851595
15861596static int __load_segment_descriptor (struct x86_emulate_ctxt * ctxt ,
@@ -1741,8 +1751,7 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
17411751 return ret ;
17421752 }
17431753 } else if (ctxt -> mode == X86EMUL_MODE_PROT64 ) {
1744- ret = ctxt -> ops -> read_std (ctxt , desc_addr + 8 , & base3 ,
1745- sizeof (base3 ), & ctxt -> exception );
1754+ ret = linear_read_system (ctxt , desc_addr + 8 , & base3 , sizeof (base3 ));
17461755 if (ret != X86EMUL_CONTINUE )
17471756 return ret ;
17481757 if (is_noncanonical_address (get_desc_base (& seg_desc ) |
@@ -2055,11 +2064,11 @@ static int __emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq)
20552064 eip_addr = dt .address + (irq << 2 );
20562065 cs_addr = dt .address + (irq << 2 ) + 2 ;
20572066
2058- rc = ops -> read_std (ctxt , cs_addr , & cs , 2 , & ctxt -> exception );
2067+ rc = linear_read_system (ctxt , cs_addr , & cs , 2 );
20592068 if (rc != X86EMUL_CONTINUE )
20602069 return rc ;
20612070
2062- rc = ops -> read_std (ctxt , eip_addr , & eip , 2 , & ctxt -> exception );
2071+ rc = linear_read_system (ctxt , eip_addr , & eip , 2 );
20632072 if (rc != X86EMUL_CONTINUE )
20642073 return rc ;
20652074
@@ -3037,35 +3046,30 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
30373046 u16 tss_selector , u16 old_tss_sel ,
30383047 ulong old_tss_base , struct desc_struct * new_desc )
30393048{
3040- const struct x86_emulate_ops * ops = ctxt -> ops ;
30413049 struct tss_segment_16 tss_seg ;
30423050 int ret ;
30433051 u32 new_tss_base = get_desc_base (new_desc );
30443052
3045- ret = ops -> read_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3046- & ctxt -> exception );
3053+ ret = linear_read_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
30473054 if (ret != X86EMUL_CONTINUE )
30483055 return ret ;
30493056
30503057 save_state_to_tss16 (ctxt , & tss_seg );
30513058
3052- ret = ops -> write_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3053- & ctxt -> exception );
3059+ ret = linear_write_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
30543060 if (ret != X86EMUL_CONTINUE )
30553061 return ret ;
30563062
3057- ret = ops -> read_std (ctxt , new_tss_base , & tss_seg , sizeof tss_seg ,
3058- & ctxt -> exception );
3063+ ret = linear_read_system (ctxt , new_tss_base , & tss_seg , sizeof tss_seg );
30593064 if (ret != X86EMUL_CONTINUE )
30603065 return ret ;
30613066
30623067 if (old_tss_sel != 0xffff ) {
30633068 tss_seg .prev_task_link = old_tss_sel ;
30643069
3065- ret = ops -> write_std (ctxt , new_tss_base ,
3066- & tss_seg .prev_task_link ,
3067- sizeof tss_seg .prev_task_link ,
3068- & ctxt -> exception );
3070+ ret = linear_write_system (ctxt , new_tss_base ,
3071+ & tss_seg .prev_task_link ,
3072+ sizeof tss_seg .prev_task_link );
30693073 if (ret != X86EMUL_CONTINUE )
30703074 return ret ;
30713075 }
@@ -3181,38 +3185,34 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
31813185 u16 tss_selector , u16 old_tss_sel ,
31823186 ulong old_tss_base , struct desc_struct * new_desc )
31833187{
3184- const struct x86_emulate_ops * ops = ctxt -> ops ;
31853188 struct tss_segment_32 tss_seg ;
31863189 int ret ;
31873190 u32 new_tss_base = get_desc_base (new_desc );
31883191 u32 eip_offset = offsetof(struct tss_segment_32 , eip );
31893192 u32 ldt_sel_offset = offsetof(struct tss_segment_32 , ldt_selector );
31903193
3191- ret = ops -> read_std (ctxt , old_tss_base , & tss_seg , sizeof tss_seg ,
3192- & ctxt -> exception );
3194+ ret = linear_read_system (ctxt , old_tss_base , & tss_seg , sizeof tss_seg );
31933195 if (ret != X86EMUL_CONTINUE )
31943196 return ret ;
31953197
31963198 save_state_to_tss32 (ctxt , & tss_seg );
31973199
31983200 /* Only GP registers and segment selectors are saved */
3199- ret = ops -> write_std (ctxt , old_tss_base + eip_offset , & tss_seg .eip ,
3200- ldt_sel_offset - eip_offset , & ctxt -> exception );
3201+ ret = linear_write_system (ctxt , old_tss_base + eip_offset , & tss_seg .eip ,
3202+ ldt_sel_offset - eip_offset );
32013203 if (ret != X86EMUL_CONTINUE )
32023204 return ret ;
32033205
3204- ret = ops -> read_std (ctxt , new_tss_base , & tss_seg , sizeof tss_seg ,
3205- & ctxt -> exception );
3206+ ret = linear_read_system (ctxt , new_tss_base , & tss_seg , sizeof tss_seg );
32063207 if (ret != X86EMUL_CONTINUE )
32073208 return ret ;
32083209
32093210 if (old_tss_sel != 0xffff ) {
32103211 tss_seg .prev_task_link = old_tss_sel ;
32113212
3212- ret = ops -> write_std (ctxt , new_tss_base ,
3213- & tss_seg .prev_task_link ,
3214- sizeof tss_seg .prev_task_link ,
3215- & ctxt -> exception );
3213+ ret = linear_write_system (ctxt , new_tss_base ,
3214+ & tss_seg .prev_task_link ,
3215+ sizeof tss_seg .prev_task_link );
32163216 if (ret != X86EMUL_CONTINUE )
32173217 return ret ;
32183218 }
0 commit comments