DevinLeamy commented on code in PR #501:
URL: https://github.com/apache/mesos/pull/501#discussion_r1516875332
##########
src/linux/ebpf.cpp:
##########
@@ -14,4 +14,99 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "linux/ebpf.hpp"
\ No newline at end of file
+#include "linux/ebpf.hpp"
+
+#include <errno.h>
+#include <linux/bpf.h>
+#include <sys/syscall.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "stout/foreach.hpp"
+#include "stout/os.hpp"
+
+using std::ostream;
+using std::string;
+using std::vector;
+
+namespace ebpf {
+
+namespace internal {
+
+// Wrapper around the `bpf` syscall.
+Try<int> syscall_bpf(int cmd, union bpf_attr* attr, size_t size)
+{
+ int result = syscall(__NR_bpf, cmd, attr, size);
+ if (result == -1) {
+ return Error(
+ "BFP syscall failed with error '" + string(std::strerror(errno)) + "'");
+ }
+ return result;
+}
+
+
+uint64_t pointer_to_int(const void* pointer)
+{
+ return (uint64_t)(unsigned long)pointer;
+}
Review Comment:
This pointer cast `static_cast<uint64_t>(program.data())` doesn't work.
However, pointers can directly converted into integer types and back during
`reinterpret_cast` (https://stackoverflow.com/a/21250110).
```cpp
reinterpret_cast<uint64_t>(program.data())
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]