5
5
*/
6
6
#include " bpftime_shm.hpp"
7
7
#include " handler/map_handler.hpp"
8
+ #include " handler/memfd_handler.hpp"
8
9
#include < ebpf-vm.h>
9
10
#include " handler/epoll_handler.hpp"
10
11
#include " handler/handler_manager.hpp"
@@ -777,6 +778,11 @@ int bpftime_shm::add_bpf_map(int fd, const char *name,
777
778
};
778
779
verifier::set_map_descriptors (helpers);
779
780
#endif
781
+ if (!std::holds_alternative<unused_handler>(manager->get_handler (fd))) {
782
+ SPDLOG_DEBUG (
783
+ " Creating map handler at {}, which must destroy the existing handler" );
784
+ manager->clear_id_at (fd, segment);
785
+ }
780
786
return manager->set_handler (
781
787
fd, bpftime::bpf_map_handler (fd, name, segment, attr), segment);
782
788
}
@@ -800,6 +806,13 @@ int bpftime_shm::dup_bpf_map(int oldfd, int newfd)
800
806
auto &handler =
801
807
std::get<bpftime::bpf_map_handler>(manager->get_handler (oldfd));
802
808
std::string new_name = std::string (" dup_" ) + handler.name .c_str ();
809
+ // Destroy old handler
810
+ auto &old_handler = manager->get_handler (newfd);
811
+ if (!std::holds_alternative<unused_handler>(old_handler)) {
812
+ SPDLOG_DEBUG (" Dup to fd {}, destroying old handler" , newfd);
813
+
814
+ manager->clear_id_at (newfd, segment);
815
+ }
803
816
// Create a new handler with the same parameters
804
817
return manager->set_handler (
805
818
newfd,
@@ -963,12 +976,22 @@ int bpftime_shm::poll_gpu_ringbuf_map(
963
976
964
977
auto impl_opt = map_handler.try_get_nv_gpu_ringbuf_map_impl ();
965
978
if (!impl_opt) {
966
- SPDLOG_ERROR (" Failed to get nv_gpu_ringbuf_map_impl for mapfd {}" , mapfd);
979
+ SPDLOG_ERROR (
980
+ " Failed to get nv_gpu_ringbuf_map_impl for mapfd {}" ,
981
+ mapfd);
967
982
return -1 ;
968
983
}
969
984
auto &impl = *impl_opt;
970
985
return impl->drain_data (fn);
971
986
}
972
987
#endif
973
-
988
+ int bpftime_shm::add_memfd_handler (const char *name, int flags)
989
+ {
990
+ int fd = open_fake_fd ();
991
+ fd = manager->set_handler (fd, memfd_handler (name, flags, segment),
992
+ segment);
993
+ SPDLOG_DEBUG (" Created memfd handler at {}, name {}, flags {}" , fd, name,
994
+ flags);
995
+ return fd;
996
+ }
974
997
} // namespace bpftime
0 commit comments