summary refs log tree commit diff
path: root/sys_util/src/mmap.rs
Commit message (Collapse)AuthorAge
* hypervisor: add Vm user memory region functionsSteven Richman2020-06-10
| | | | | | | | | | | | | | | | | | The separate Vm functions for MemoryMappings and MemoryMappingArenas have been combined and now use a MappedRegion trait that the mappings implement. msync_memory_region replaces the get_mmap_arena function, which is used by VmMsyncRequest. Since Vm uses mutexes for cloning, it can't return mem region references. BUG=chromium:1077058 TEST=cargo test, cargo test -p sys_util, cargo test -p hypervisor Change-Id: If257b16ee34d07820ae7ebdb9a3a598a41df013c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202845 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* Make VolatileSlice ABI-compatible with iovecChirantan Ekbote2020-05-25
| | | | | | | | | | | | | | | | | | | | | | Change VolatileSlice so that it is ABI-compatible with iovec. This allows us to directly pass in a VolatileSlice for a C function that expects an iovec without having to create temporaries that convert from one to the other. Also change all the parameters from u64 to usize. It's not possible to address more memory than fits into a usize so having u64 here didn't really provide much benefit and led to a lot of tedious casting back and forth all over the place. BUG=none TEST=unit tests Cq-Depend: chromium:2206621 Change-Id: I258f9123c603d9a4c6c5e2d4d10eb4aedf74466d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2203998 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* Stop tracking sub-mappings in MemoryMappingArenaChirantan Ekbote2020-04-29
| | | | | | | | | | | | | | | | | | | | | | | | | | The kernel already takes care of tracking all our memory mappings. Doing it again ourselves doesn't provide any benefit and also adds additional restrictions (like not being able to overlap with existing mappings or partially remove mappings). Additionally, the `MemoryMappingArena` will already unmap the entire memory mapped region so there is no need to individually unmap the sub-mappings. The kernel's mmap api doesn't have these restrictions and as far as I can tell there are no safety concerns with allowing this behavior so just stop tracking the sub-mappings. Safe use of MAP_FIXED only requires that the address is part of a previously mmaped region so allow any MemoryMapping to be converted into a MemoryMappedArena. BUG=b:147341783 TEST=unit tests Change-Id: Iaf944a971b8ba9333802aab73c1d184fe388af89 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2162542 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* handle mmap of large offsets on 32 bit systemsDylan Reid2020-04-05
| | | | | | | | | | | | | | | | While only 32 bits of address can be mapped, that 32 bits can be offset by further than 32 bits in to a large file. As chirantan points out, the try_mmap call was already casting the usize to u64 on all architectures. Convert the usize offset in mmap to u64 and address users of the API as well. Change-Id: I67aed928ea521049fb51eb7aa61ea4de8b4d096c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124879 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* sys_util: Allow pre-populating mmapsDylan Reid2020-03-29
| | | | | | | | | | | | | | io_uring would like to pre-fault the ring pages as they are likely to be accessed regularly. Allow mmap users to specify the MAP_POPULATE flag through a new API. Change-Id: I5fefc13443280fe832c9601fe5a497b572127f0e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124008 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* tree-wide: Use new trait object syntaxDylan Reid2019-07-24
| | | | | | | | | | | A few places were using the old syntax without `dyn`. Nightly compilers have started warning more aggressively, so fix up the last of those. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I4df49b4a27a62acfd8c542cec903e4c5b31bedcc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715576 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: virtio-pmem deviceJakub Staron2019-06-05
| | | | | | | | | | | | | | | | | | | | Adds support for virtio-pmem device as an alternative for virtio-blk. Exposing disk image to guest as virtio-blk device results in both guest and host independently caching the disk I/O. Using virtio-pmem device allows to mount disk image as direct access (DAX) in the guest and thus bypass the guest cache. This will reduce memory foodprint of the VMs. BUG=None TEST=cargo test TEST=Boot patched termina kernel in crosvm; mount virtio-pmem device as DAX and run xfstests. Change-Id: I935fc8fc7527f79e5169f07ec7927e4ea4fa6027 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1605517 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Jakub StaroĊ„ <jstaron@google.com>
* eliminate mut from non-mut referencesZach Reizner2019-06-04
| | | | | | | | | | | | | | | | | | | | | | | This manifested itself in a couple places that were turning shared memory buffers into slices for the purposes of passing these slices to `Read` and `Write` trait methods. However, this required the removal of the methods that took `Read` and `Write` instances. This was a convenient interface but impossible to implement safely because making slices from raw pointers without enforcing safety guarantees causes undefined behaviour in Rust. It turns out lots of code in crosvm was using these interfaces indirectly, which explains why this CL touches so much. TEST=crosvm run BUG=chromium:938767 Change-Id: I4ff40c98da6ed08a4a42f4c31f0717f81b1c5863 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1636685 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* sys_util: add size to mmap InvalidRange errorDaniel Verkamp2019-04-22
| | | | | | | | | | | | | | | | The current error doesn't provide sufficient information to debug InvalidRange errors; add the size of the region so that the bounds of the comparison can be determined from the error message. BUG=None TEST=cargo test -p sys_util Change-Id: I8e7fbd750ab84c43bbf0435230b7d3cf466783da Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1574964 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* clippy: Resolve assign_op_patternDavid Tolnay2019-04-17
| | | | | | | | | | | TEST=bin/clippy Change-Id: I1cb259f399f9aff2b9b745413f9a28e130688a2b Reviewed-on: https://chromium-review.googlesource.com/1566657 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* sys_util: add MemoryMappingArenaDaniel Prilik2019-04-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | There is a hard-limit to the number of MemoryMaps that can be added to a KVM VM, a arch-dependent number defined as KVM_USER_MEM_SLOTS. e.g: on x86 this is 509 (512 - 3 internal slots). For most purposes, this isn't too much of an issue, but there are some cases where one might want to share a lot of mmaps with a Guest. e.g: virtio-fs uses a large cache region for mapping in slices of file fds directly into guest memory. If one tries to add a new KVM memory region for each mmap, the number of available slots is quickly exhausted. MemoryMappingArena is a way to work around this limitation by allocating a single KVM memory region for a large slice of memory, and then using mmap with MAP_FIXED to override slices of this "arena" hostside, thereby achieving the same effect without quickly exhausting the number of KVM memory region slots. BUG=chromium:936567 TEST=cargo test -p sys_util Change-Id: I89cc3b22cdba6756b2d76689176d7147cf238f07 Reviewed-on: https://chromium-review.googlesource.com/1546600 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* edition: Use dyn syntax for trait objectsDavid Tolnay2019-04-08
| | | | | | | | | | | | | | | | | | | | | Found by running: `cargo rustc -- -D bare_trait_objects` Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in 2018 edition and will start warning at some point. As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>` because the 'static bound is implied for boxed trait objects. TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19 Reviewed-on: https://chromium-review.googlesource.com/1513059 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Update absolute paths to 2018 styleDavid Tolnay2019-03-13
| | | | | | | | | | | | | | | | | | | | | | | | | | This is an easy step toward adopting 2018 edition eventually, and will make any future CL that sets `edition = "2018"` this much smaller. The module system changes in Rust 2018 are described here: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html Generated by running: cargo fix --edition --all in each workspace, followed by bin/fmt. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8 Reviewed-on: https://chromium-review.googlesource.com/1513054 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* data_model: ignore clippy error for mut from non-mutDylan Reid2019-03-09
| | | | | | | | | | | | | | | | A bug has been filed to fix this differently. Until then, add a TODO and a clippy disable so that clippy can be used to test for other issues without stopping on this error. BUG=928767 TEST=cargo clippy Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Ic264bc9101653c30354415c913e9ee3752985706 Reviewed-on: https://chromium-review.googlesource.com/1506308 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Allow custom protection for mmap.Lepton Wu2019-02-27
| | | | | | | | | | | BUG=b:118408510 TEST=manual - build crosvm with/without crosvm-render-node-forward USE flag and run arcvm. Change-Id: I716fbd2f5daa0f109ef839b950ec6c88dc5a9c91 Reviewed-on: https://chromium-review.googlesource.com/1487774 Commit-Ready: Lepton Wu <lepton@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* error: Print errors using Display implDavid Tolnay2019-02-20
| | | | | | | | | | | | | | | | | | | | | | | | | I have been running into Debug-printed error messages too often and needing to look up in the source code each level of nested errors to find out from the comment on the error variant what the short name of the variant means in human terms. Worse, many errors (like the one shown below) already had error strings written but were being printed from the calling code in the less helpful Debug representation anyway. Before: [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty After: [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices. TEST=cargo check --all-features TEST=FEATURES=test emerge-amd64-generic crosvm Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10 Reviewed-on: https://chromium-review.googlesource.com/1469225 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* cargo fmt all source codeZach Reizner2018-10-09
| | | | | | | | | | | | | | Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* balloon: Implement device policyChirantan Ekbote2018-07-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement a policy for the balloon device so that it starts taking memory away from the VM when the system is under low memory conditions. There are a few pieces here: * Change the madvise call in MemoryMapping::dont_need_range to use MADV_REMOVE instead of MADV_DONTNEED. The latter does nothing when the memory mapping is shared across multiple processes while the former immediately gives the pages in the specified range back to the kernel. Subsequent accesses to memory in that range returns zero pages. * Change the protocol between the balloon device process and the main crosvm process. Previously, the device process expected the main process to send it increments in the amount of memory consumed by the balloon device. Now, it instead just expects the absolute value of the memory that should be consumed. To properly implement the policy the main process needs to keep track of the total memory consumed by the balloon device so this makes it easier to handle all the policy in one place. * Add a policy for dealing with low memory situations. When the VM starts up, we determine the maximum amount of memory that the balloon device should consume: * If the VM has more than 1.5GB of memory, the balloon device max is the size of the VM memory minus 1GB. * Otherwise, if the VM has at least 500MB, the balloon device max is 50% of the size of the VM memory. * Otherwise, the max is 0. The increment used to change the size of the balloon is defined as 1/16 of the max memory that the balloon device will consume. When the crosvm main process detects that the system is low on memory, it immediately increases the balloon size by the increment (unless it has already reached the max). It then starts 2 timers: one to check for low memory conditions again in 1 seconds (+ jitter) and another to check if the system is no longer low on memory in 1 minute (+ jitter) with a subsequent interval of 30 seconds (+ jitter). Under persistent low memory conditions the balloon device will consume the maximum memory after 16 seconds. Once there is enough available memory the balloon size will shrink back down to 0 after at most 9 minutes. BUG=chromium:866193 TEST=manual Start 2 VMs and write out a large file (size > system RAM) in each. Observe /sys/kernel/mm/chromeos-low_mem/available and see that the available memory steadily decreases until it goes under the low memory margin at which point the available memory bounces back up as crosvm frees up pages. CQ-DEPEND=CL:1152214 Change-Id: I2046729683aa081c9d7ed039d902ad11737c1d52 Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1149155 Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
* sys_util: use MADV_DONTDUMP for new mmapsZach Reizner2018-03-30
| | | | | | | | | | | | | | | | The mmaps made through the sys_util API are usually for guest memory or other large shared memory chunks that will pollute the file system with huge dumps on crash. By using MADV_DONTDUMP, we save the file system from storing these useless data segments when crosvm crashes. TEST=./build_test BUG=None Change-Id: I2041523648cd7c150bbdbfceef589f42d3f9c2b9 Reviewed-on: https://chromium-review.googlesource.com/890279 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* mmap: remove unused 'use'Dylan Reid2018-02-05
| | | | | | | | | usize isn't used in this test any more. Remove compiler warning. Change-Id: I9493e22f563f2fc15532564ea57d70de593c4421 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/902778 Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
* crosvm: change GuestAddress to always be a u64Sonny Rao2018-02-01
| | | | | | | | | | | | | | | We want to be able to run 64-bit ARM kernels using a 32-bit version of crosvm, to make it more consistent use a u64 to represent GuestAddress. BUG=chromium:797868 TEST=./build_test passes on all architectures TEST=crosvm runs on caroline Change-Id: I43bf993592caf46891e3e5e05258ab70b6bf3045 Signed-off-by: Sonny Rao <sonnyrao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/896398 Reviewed-by: Dylan Reid <dgreid@chromium.org>
* mmap: Simplify offset checksDylan Reid2018-01-05
| | | | | | | | | | | Use ok_or to remove the match witch was harder to read. No functional change. Pull the check in to a function so that it only needs to be right once. Change-Id: I0e5801d9e7e82994e7f1fbda0d2692a4afd59d99 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/850850 Reviewed-by: Zach Reizner <zachr@chromium.org>
* mmap: Bounds check offset on readDylan Reid2018-01-05
| | | | | | | | | | The other functions in mmap check that the offset doesn't overflow. The kernel_loader fuzzer found that read forgot to check. Change-Id: Ifc89dbe40345c5923a5cf29c9f29e810e9e1a1e8 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/850542 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add mmap with offset supportZach Reizner2018-01-05
| | | | | | | | | | | | | | | This is needed to support the plugin process API, which may register guest memory mapped at an offset from the beginning of a file. TEST=cargo test BUG=None Change-Id: Idf1e9f0287df5510728ab2bcf4dd090f9e81a5bf Reviewed-on: https://chromium-review.googlesource.com/849495 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: check mmap return value properlyGabriel Campana2018-01-05
| | | | | | | | | | mmap returns MAP_FAILED (that is, (void *) -1) on error. Change-Id: I0dbd65e13a256840c80086e5f24359a3859759be Reviewed-on: https://chromium-review.googlesource.com/845683 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: Add ability to madvise a regionDylan Reid2017-12-08
| | | | | | | | | | | | | Add functions to let the kernel know a given range of memory isn't needed currently. This function will result in `madvise(DONTNEED)`. The ability to signal memory as not needed will be used by the balloon driver to allow system memory to be redistributed away from the VM. Change-Id: I4ca56e09010eec33989824f5738db4a4be0ec428 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/759305 Reviewed-by: Zach Reizner <zachr@chromium.org>
* Fix new warning with rust 1.21Dylan Reid2017-10-13
| | | | | | | | | | | Mutable references being declared mutable themselves is unnecessary and now generates a warning. Change-Id: I29c7652fb86e17a8eda21efc728dd09b726c304f Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/717733 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Improve guest memory error handlingDylan Reid2017-09-11
| | | | | | | | | | | | | Pass better errors from mmap and guest_memory. These modules were written before I understood errors. Now the errors passed back to block can be propagated. Change-Id: I1842808a4114a715321c555281aacc211f23511c Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/656837 Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add read_slice_at_addr to GuestMemoryStephen Barber2017-08-09
| | | | | | | | | | BUG=none TEST=cargo test Change-Id: Ifeda91de37bf83a2e5a00f5e308db786fa5d49d5 Signed-off-by: Stephen Barber <smbarber@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/604934 Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: remove accidental HTML from doc commentsZach Reizner2017-06-30
| | | | | | | | | | | | | | | | For some reason, the angle brackets in the comments confused doc-tests such that they hung everytime `cargo test` was run on sys_util on my machine. My theory is that the angle brackets triggered some strange HTML behavior in `cargo test`. BUG=None TEST=cd sys_util; cargo test Change-Id: Iceb81e64aecc4cc2a9397f2d1af2e64aeb8e2b5e Reviewed-on: https://chromium-review.googlesource.com/518444 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: implement VolatileMemory for Mmap and GuestMemoryZach Reizner2017-06-27
| | | | | | | | | | | | | | Mmap and GuestMemory are the intended targets for the VolatileMemory trait. TEST=cargo test BUG=None Change-Id: Ie228b5daef691a6dcb80841be1c3dddb4b19ffc4 Reviewed-on: https://chromium-review.googlesource.com/547335 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Limit types that can be read from guest memoryDylan Reid2017-06-27
| | | | | | | | | | | | | | | | | | | | Not all types are safe to read from guest memory. Any type with a reference or pointer will be initialized to random bits that don't refer to a valid address. This can cause dangling pointer and general unsafe behavior. To fix this, limit types that can be read with read_obj to those that implement the unsafe trait `DataInit`. Provide implementations of `DataInit` for intrinsic types that are obviously safe to initialize with random data. Implement the needed traits for bootparam types as they are read from the kernel image directly. Change-Id: I1040f5bc1b2fc4c58c87d8a2ce3f618edcf6f9b1 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540750 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: Add guest_memoryDylan Reid2017-05-25
| | | | | | | | | | | | | | Add a module for accessing guest memory. This module will replace all the slices that are used to access it currently as those slices aren't valid because the memory is volatile and a volatile slice doesn't exist in rust. Modify the existing users so they no longer depend on the deprecated slice access. Change-Id: Ic0e86dacf66f68bd88ed9cc197cb14e45ada891d Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/509919
* sys_util: add sys_util crate for misc system modulesZach Reizner2017-05-08
This initial commit includes an mmap wrapper. TEST=cargo test BUG=None Change-Id: I9625bd446fcd4801b2e16188897e84714b4e4ce0 Reviewed-on: https://chromium-review.googlesource.com/496987 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>