---
title: "hv_vcpu_write_msr(_:_:_:)"
framework: hypervisor
role: symbol
role_heading: Function
path: "hypervisor/hv_vcpu_write_msr(_:_:_:)"
---

# hv_vcpu_write_msr(_:_:_:)

Sets the value of a Model-Specific Register (MSR) of a vCPU.

## Declaration

```swift
func hv_vcpu_write_msr(_ vcpu: hv_vcpuid_t, _ msr: UInt32, _ value: UInt64) -> hv_return_t
```

## Parameters

- `vcpu`: The instance of the vCPU.
- `msr`: The ID of the MSR.
- `value`: The new value for msr.

## Return Value

Return Value HV_SUCCESS if the operation was successful, otherwise an error code specified in hv_return_t.

## Discussion

Discussion This function must be called by the owning thread.

## See Also

### Model-Specific Registers

- [Extending vCPU Capabilities Using Model-Specific Registers](hypervisor/extending-vcpu-capabilities-using-model-specific-registers.md)
- [hv_vcpu_read_msr(_:_:_:)](hypervisor/hv_vcpu_read_msr(_:_:_:).md)
- [hv_vcpu_enable_native_msr(_:_:_:)](hypervisor/hv_vcpu_enable_native_msr(_:_:_:).md)
- [hv_vcpu_set_msr_access(_:_:_:)](hypervisor/hv_vcpu_set_msr_access(_:_:_:).md)
- [hv_vcpu_enable_managed_msr(_:_:_:)](hypervisor/hv_vcpu_enable_managed_msr(_:_:_:).md)
- [hv_msr_flags_t](hypervisor/hv_msr_flags_t.md)
- [Model-Specific Registers](hypervisor/3727856-model-specific-registers.md)
- [MSR Permissions](hypervisor/3567078-msr_permissions-enum.md)
