annotate dep/animia/src/fd/xnu.cc @ 162:61b76c7b656a

dep/animia: add os x launchservices method
author Paper <mrpapersonic@gmail.com>
date Fri, 17 Nov 2023 16:49:57 -0500
parents 900b5b530883
children 44c5e6dd9488
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 /*
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
2 ** fd/xnu.cc
153
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"
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
6 #ifdef HAVE_COREFOUNDATION
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
7 # include "animia/util/osx.h"
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
8 #endif
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include "animia.h"
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
11 #include <cassert>
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
12 #include <string>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <unordered_map>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <vector>
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
15 #include <memory>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #include <fcntl.h>
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
18 #include <libproc.h>
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 #include <sys/sysctl.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 #include <sys/types.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 #include <sys/user.h>
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
23 #include <iostream>
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
24
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 namespace animia::internal::xnu {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
27 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
28 /* 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
29 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
30 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
31
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
32 /* 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
33 size_t size;
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
34 {
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
35 int ret = sysctl((int*)mib, mib_size, nullptr, &size, nullptr, 0);
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
36 if (ret)
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
37 return false;
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
38 }
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
39
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
40 /* 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
41 std::string args;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
42 args.resize(size);
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 /* Get the contents of argc and argv */
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
45 {
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
46 int ret = sysctl((int*)mib, mib_size, &args.front(), &size, NULL, 0);
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
47 if (ret)
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
48 return false;
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
49 }
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
50
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
51 /* 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
52 if (size < sizeof(int))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
53 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
54
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
55 args.resize(size);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
56
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
57 /* Get argc using memcpy */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
58 int argc;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
59 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
60
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
61 /* Do we even have argv[0]? */
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
62 if (argc < 1)
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
63 return false;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
65 /* 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
66 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
67 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
68 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
69
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
70 /* Find the last slash */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
71 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
72 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
73 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
74
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
75 /* Return our result */
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
76 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
77 return true;
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
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
80 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
81 result.reserve(2*MAXCOMLEN);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
82 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
83 return false;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
84
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
85 result.shrink_to_fit();
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
86 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
87 }
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 static bool GetProcessName(pid_t pid, std::string& result) {
162
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
90 /* Use LaunchServices */
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
91 #ifdef HAVE_COREFOUNDATION
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
92 if (osx::util::LaunchServicesGetProcessName(pid, result))
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
93 return true;
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
94 #endif
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
95
61b76c7b656a dep/animia: add os x launchservices method
Paper <mrpapersonic@gmail.com>
parents: 160
diff changeset
96 /* Try parsing the arguments, this prevents the process name being
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
97 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
98 if (GetProcessNameFromArgs(pid, result))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
99 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
100
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
101 /* 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
102 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
103 if (GetProcessNameFromKernel(pid, result))
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
104 return true;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
105
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
106 return false;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109 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
110 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
111 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
112
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
113 int returned_size = 0;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
114 do {
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
115 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
116 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
117 if (returned_size == -1)
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
118 return false;
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
119 } 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
120
160
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
121 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
122 std::string result;
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
123 GetProcessName(pids[i], result);
900b5b530883 dep/animia: fd/xnu: use path args to get executable filename
Paper <mrpapersonic@gmail.com>
parents: 157
diff changeset
124 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
125 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 }
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
127
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
128 return true;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131 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
132 if (!open_file_proc)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 for (const auto& pid : pids) {
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 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
137 if (bufsz == -1)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 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
141 if (!info)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144 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
145
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146 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
147 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
148 struct vnode_fdinfowithpath vnodeInfo;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
150 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
151 PROC_PIDFDVNODEPATHINFO_SIZE);
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
152 if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 /* this doesn't work!
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156 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
157 continue;
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
158 */
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
159
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
160 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
161 return false;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
162 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
163 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
164 }
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 153
diff changeset
165
153
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
166 return true;
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
167 }
bd439dd6ffc5 *: make win stuff actually work, rename bsd.cc to xnu.cc
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
168
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
169 } // namespace animia::internal::xnu