annotate dep/animia/src/fd/xnu.cc @ 160:900b5b530883

dep/animia: fd/xnu: use path args to get executable filename
author Paper <mrpapersonic@gmail.com>
date Fri, 17 Nov 2023 12:37:31 -0500
parents 18c8eb5d1edc
children 61b76c7b656a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 /*
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 ** fd/xnu.cpp
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 ** - provides support for XNU (part of Darwin)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 */
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include "animia/fd/xnu.h"
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "animia.h"
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
8 #include <cassert>
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
9 #include <string>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <unordered_map>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <vector>
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
12 #include <memory>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <fcntl.h>
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
15 #include <libproc.h>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #include <sys/sysctl.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #include <sys/types.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 #include <sys/user.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
20 #include <iostream>
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
21
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 namespace animia::internal::xnu {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
24 static bool GetProcessNameFromArgs(pid_t pid, std::string& result) {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
25 /* sysctl shouldn't touch these, so we define them as const */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
26 const int mib[3] = {CTL_KERN, KERN_PROCARGS2, static_cast<int>(pid)};
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
27 const size_t mib_size = sizeof(mib)/sizeof(*mib);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
28
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
29 /* Get the initial size of the array */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
30 size_t size;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
31 int ret = sysctl((int*)mib, mib_size, nullptr, &size, nullptr, 0);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
32 if (ret)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
33 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
34
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
35 /* Reserve the space for it in a std::string */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
36 std::string args;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
37 args.resize(size);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
38
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
39 /* Get the contents of argc and argv */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
40 ret = sysctl((int*)mib, mib_size, &args.front(), &size, NULL, 0);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
41 if (ret)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
42 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
43
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
44 /* Is the size big enough to hold at least argc? */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
45 if (size < sizeof(int))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
46 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
47
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
48 args.resize(size);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
49
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
50 /* Get argc using memcpy */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
51 int argc;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
52 memcpy(&argc, &args.front(), sizeof(argc));
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
53
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
54 /* Check for a condition that, realistically, would never happen,
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
55 but better to be safe than sorry */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
56 if (argc < 1)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
57 return false;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
59 /* Find the first null character */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
60 size_t null_pos = args.find('\0', sizeof(argc));
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
61 if (null_pos == std::string::npos)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
62 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
63
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
64 /* Find the last slash */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
65 size_t last_slash = args.rfind('/', null_pos);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
66 if (last_slash == std::string::npos)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
67 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
68
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
69 /* Return our result */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
70 result = args.substr(last_slash + 1, null_pos - last_slash - 1);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
71 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
72 }
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
73
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
74 static bool GetProcessNameFromKernel(pid_t pid, std::string& result) {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
75 result.reserve(2*MAXCOMLEN);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
76 if (!proc_name(pid, &result.front(), result.length()))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
77 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
78
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
79 result.shrink_to_fit();
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
80 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
81 }
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
82
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
83 static bool GetProcessName(pid_t pid, std::string& result) {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
84 /* First try parsing the arguments, this prevents the process name being
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
85 cut off to 2*MAXCOMLEN (32 chars) */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
86 if (GetProcessNameFromArgs(pid, result))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
87 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
88
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
89 /* Then attempt getting it from the kernel, which results in the process name
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
90 being cut to 32 chars (16 chars if p_name is unavailable) */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
91 if (GetProcessNameFromKernel(pid, result))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
92 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
93
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
94 return false;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 bool XnuFdTools::EnumerateOpenProcesses(process_proc_t process_proc) {
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
98 size_t pids_size = 512;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
99 std::unique_ptr<pid_t[]> pids;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
101 int returned_size = 0;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
102 do {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
103 pids.reset(new pid_t[pids_size]);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
104 returned_size = proc_listpids(PROC_ALL_PIDS, 0, pids.get(), pids_size * sizeof(pid_t));
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
105 if (returned_size == -1)
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
106 return false;
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
107 } while ((pids_size * sizeof(size_t)) < returned_size);
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
109 for (int i = 0; i < pids_size; i++) {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
110 std::string result;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
111 GetProcessName(pids[i], result);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
112 if (!process_proc({pids[i], result}))
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 }
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
115
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
116 return true;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 bool XnuFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120 if (!open_file_proc)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 for (const auto& pid : pids) {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124 int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 if (bufsz == -1)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128 struct proc_fdinfo* info = (struct proc_fdinfo*)malloc(bufsz);
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 if (!info)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 proc_pidinfo(pid, PROC_PIDLISTFDS, 0, info, bufsz);
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134 for (int i = 0; i < bufsz / sizeof(info[0]); i++) {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 if (info[i].proc_fdtype == PROX_FDTYPE_VNODE) {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 struct vnode_fdinfowithpath vnodeInfo;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
138 int sz = proc_pidfdinfo(pid, info[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo,
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
139 PROC_PIDFDVNODEPATHINFO_SIZE);
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
141 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143 /* this doesn't work!
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144 if (vnodeInfo.pfi.fi_openflags & O_WRONLY || vnodeInfo.pfi.fi_openflags & O_RDWR)
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
145 continue;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146 */
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
147
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
148 if (!open_file_proc({pid, vnodeInfo.pvip.vip_path}))
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
150 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
151 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
152 }
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
153
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154 return true;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
157 } // namespace animia::internal::xnu