Skip to content

Commit 12cc38d

Browse files
committed
Add Machine::set_fpu_registers() and Machine::run_in_usermode()
1 parent f448249 commit 12cc38d

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

lib/tinykvm/machine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ void Machine::run(float timeout)
286286
return vcpu.run(timeout * 1000.0);
287287
}
288288

289+
void Machine::run_in_usermode(float timeout)
290+
{
291+
this->enter_usermode();
292+
this->run(timeout);
293+
}
294+
289295
__attribute__((cold, noreturn))
290296
void Machine::machine_exception(const char* msg, uint64_t data)
291297
{

lib/tinykvm/machine.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct Machine
2828
void setup_linux(const std::vector<std::string>& args,
2929
const std::vector<std::string>& env = {});
3030
void run(float timeout_secs = 0.f);
31+
void run_in_usermode(float timeout_secs = 0.f);
3132

3233
/* Make a SYSV function call into the VM, with no timeout */
3334
template <typename... Args>
@@ -108,6 +109,7 @@ struct Machine
108109
const tinykvm_x86regs& registers() const;
109110
void set_registers(const tinykvm_x86regs&);
110111
tinykvm_fpuregs fpu_registers() const;
112+
void set_fpu_registers(const tinykvm_fpuregs&);
111113
const kvm_sregs& get_special_registers() const;
112114
void set_special_registers(const kvm_sregs&);
113115
std::pair<__u64, __u64> get_fsgs() const;

lib/tinykvm/machine_inline.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ inline void Machine::set_registers(const tinykvm_x86regs& regs) {
3636
inline tinykvm_fpuregs Machine::fpu_registers() const {
3737
return vcpu.fpu_registers();
3838
}
39+
inline void Machine::set_fpu_registers(const tinykvm_fpuregs& regs) {
40+
vcpu.set_fpu_registers(regs);
41+
}
3942
inline const struct kvm_sregs& Machine::get_special_registers() const {
4043
return vcpu.get_special_registers();
4144
}

lib/tinykvm/vcpu.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ tinykvm_fpuregs vCPU::fpu_registers() const
276276
}
277277
return regs;
278278
}
279+
void vCPU::set_fpu_registers(const struct tinykvm_fpuregs& regs)
280+
{
281+
if (ioctl(this->fd, KVM_SET_FPU, &regs) < 0) {
282+
Machine::machine_exception("KVM_SET_FPU failed");
283+
}
284+
}
279285
const kvm_sregs& vCPU::get_special_registers() const
280286
{
281287
#ifndef TINYKVM_USE_SYNCED_SREGS

lib/tinykvm/vcpu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace tinykvm
1515
const tinykvm_x86regs& registers() const;
1616
void set_registers(const struct tinykvm_x86regs &);
1717
tinykvm_fpuregs fpu_registers() const;
18+
void set_fpu_registers(const struct tinykvm_fpuregs &);
1819
const struct kvm_sregs& get_special_registers() const;
1920
struct kvm_sregs& get_special_registers();
2021
void set_special_registers(const struct kvm_sregs &);

0 commit comments

Comments
 (0)