1 // Copyright 2017 The Fuchsia Authors
2 //
3 // Use of this source code is governed by a MIT-style
4 // license that can be found in the LICENSE file or at
5 // https://opensource.org/licenses/MIT
6 
7 #pragma once
8 
9 #include <lib/user_copy/user_ptr.h>
10 #include <zircon/syscalls/object.h>
11 #include <zircon/types.h>
12 #include <fbl/ref_ptr.h>
13 
14 class ProcessDispatcher;
15 class VmAspace;
16 
17 // Walks the VmAspace and writes entries that describe it into |maps|, which
18 // must point to enough memory for |max| entries. The number of entries
19 // written is returned via |actual|, and the number entries that could have
20 // been written is returned via |available|.
21 // NOTE: Code outside of the syscall layer should not typically know about
22 // user_ptrs; do not use this pattern as an example.
23 zx_status_t GetVmAspaceMaps(fbl::RefPtr<VmAspace> aspace,
24                             user_out_ptr<zx_info_maps_t> maps, size_t max,
25                             size_t* actual, size_t* available);
26 
27 // Walks the VmAspace and writes entries that describe its mapped VMOs into
28 // |vmos|, which must point to enough memory for |max| entries. The number of
29 // entries written is returned via |actual|, and the number entries that could
30 // have been written is returned via |available|.
31 // NOTE: Code outside of the syscall layer should not typically know about
32 // user_ptrs; do not use this pattern as an example.
33 zx_status_t GetVmAspaceVmos(fbl::RefPtr<VmAspace> aspace,
34                             user_out_ptr<zx_info_vmo_t> vmos, size_t max,
35                             size_t* actual, size_t* available);
36 
37 // For every VMO in the process's handle table, writes an entry into |vmos|,
38 // which must point to enough memory for |max| entries. The number of entries
39 // written is returned via |actual|, and the number entries that could have
40 // been written is returned via |available|.
41 // NOTE: Code outside of the syscall layer should not typically know about
42 // user_ptrs; do not use this pattern as an example.
43 zx_status_t GetProcessVmosViaHandles(ProcessDispatcher* process,
44                                      user_out_ptr<zx_info_vmo_t> vmos, size_t max,
45                                      size_t* actual, size_t* available);
46 
47 // Prints (with the supplied prefix) the number of mapped, committed bytes for
48 // each process in the system whose page count > |min_pages|. Does not take
49 // sharing into account, and does not count unmapped VMOs.
50 void DumpProcessMemoryUsage(const char* prefix, size_t min_pages);
51