@@ -59,6 +59,7 @@ def is_present(self, fd):
5959 return 1
6060
6161
62+ < << << << HEAD
6263"""
6364Recursively checks each epoll instance's 'watched'
6465fds for an instance of epoll being watched.
@@ -69,6 +70,10 @@ def is_present(self, fd):
6970
7071def check_epoll_depth (ql_fd_list , epolls_list , depth ):
7172 if depth == 7 :
73+ == == == =
74+ def check_epoll_depth (ql_fd_list , epolls_list , depth ):
75+ if depth == 6 :
76+ > >> >> >> 0 aef533c (Initial commit for epoll )
7277 return 1
7378 new_epolls_list = []
7479 flag = 0
@@ -83,6 +88,7 @@ def check_epoll_depth(ql_fd_list, epolls_list, depth):
8388 return 0
8489
8590
91+ < << << << HEAD
8692"""
8793Modify an existing epoll
8894man 7 epoll for more details
@@ -92,6 +98,9 @@ def check_epoll_depth(ql_fd_list, epolls_list, depth):
9298def ql_syscall_epoll_ctl (
9399 ql : qiling .Qiling , epfd : int , op : int , fd : int , event : POINTER
94100):
101+ == == == =
102+ def ql_epoll_ctl (ql : qiling .Qiling , epfd : int , op : int , fd : int , event : POINTER ):
103+ > >> >> >> 0 aef533c (Initial commit for epoll )
95104 # Basic sanity checks first
96105 if event != 0 :
97106 ql_event = ql .unpack32 (ql .mem .read (event , 4 )) # events list is uint32_t
@@ -148,6 +157,7 @@ def ql_syscall_epoll_ctl(
148157 if epoll_obj is None or fd_obj is None :
149158 # epfd or fd is not a valid file descriptor.
150159 return EBADF
160+ < << << << HEAD
151161 if epfd == fd : # epoll can't monitor itself
152162 return EINVAL
153163 if epoll_obj .fileno () == fd :
@@ -181,17 +191,54 @@ def ql_syscall_epoll_ctl(
181191 if op & EPOLLEXCLUSIVE and fd in epoll_obj .get_fds :
182192 return EINVAL # EINVAL op was EPOLL_CTL_MOD and the EPOLLEXCLUSIVE flag has previously been applied to this epfd, fd pair.
183193 epoll_parent_obj .set_eventmask (ql_event )
194+ == == == =
195+ if epfd == fd :
196+ return EINVAL
197+ if epoll_obj .fileno () == fd :
198+ return ELOOP # ELOOP ...or a nesting depth of epoll instances greater than 5.
199+ match ql_op :
200+ case "EPOLL_CTL_ADD" :
201+ if epoll_parent_obj .is_present (
202+ fd
203+ ): # can't add an fd that's already being waited on
204+ return EEXIST # op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered with this epoll instance.
205+ epoll_parent_obj .monitor_fd (
206+ fd , ql_event
207+ ) # add to list of fds to be monitored with per-fd eventmask
208+ # register will actual epoll instance
209+ # and add eventmask accordingly
210+ case "EPOLL_CTL_DEL" :
211+ if not epoll_parent_obj .is_present (
212+ fd
213+ ): # op was EPOLL_CTL_MOD or EPOLL_CTL_DEL, and fd is not registered with this epoll instance.
214+ return ENOENT
215+ epoll_parent_obj .delist_fd (fd ) # remove from fds list and do so in the
216+ # underlying epoll instance
217+ case "EPOLL_CTL_MOD" :
218+ if not epoll_parent_obj .is_present (
219+ fd
220+ ): # ENOENT op was EPOLL_CTL_MOD or EPOLL_CTL_DEL, and fd is not registered with this epoll instance
221+ return ENOENT
222+ # EINVAL op was EPOLL_CTL_MOD and events included EPOLLEXCLUSIVE.
223+ if op & EPOLLEXCLUSIVE and fd in epoll_obj .get_fds :
224+ return EINVAL # EINVAL op was EPOLL_CTL_MOD and the EPOLLEXCLUSIVE flag has previously been applied to this epfd, fd pair.
225+ epoll_parent_obj .set_eventmask (ql_event )
226+ > >> >> >> 0 aef533c (Initial commit for epoll )
184227
185228 return 0
186229
187230
231+ < << << << HEAD
188232"""
189233Wait on an existing epoll for events specified
190234earlier. man 7 epoll_wait for more info
191235"""
192236
193237
194238def ql_syscall_epoll_wait (
239+ == == == =
240+ def ql_epoll_wait (
241+ > >> >> >> 0 aef533c (Initial commit for epoll )
195242 ql : qiling .Qiling , epfd : int , epoll_events : POINTER , maxevents : int , timeout : int
196243):
197244 if maxevents <= 0 :
@@ -244,7 +291,11 @@ def ql_syscall_epoll_wait(
244291"""
245292
246293
294+ < << << << HEAD
247295def ql_syscall_epoll_create1 (ql : qiling .Qiling , flags : int ):
296+ == == == =
297+ def ql_epoll_create1 (ql : qiling .Qiling , flags : int ):
298+ > >> >> >> 0 aef533c (Initial commit for epoll )
248299 if flags != select .EPOLL_CLOEXEC and flags != 0 :
249300 return EINVAL
250301 ret = select .epoll (sizehint = - 1 , flags = flags )
@@ -256,15 +307,28 @@ def ql_syscall_epoll_create1(ql: qiling.Qiling, flags: int):
256307
257308"""
258309Almost identical to above, but can't simply wrap
310+ <<<<<<< HEAD
259311because of the slightly different prototype
260312"""
261313
262314
263315def ql_syscall_epoll_create (ql : qiling .Qiling , size : int ):
316+ == == == =
317+ because of the slightly different args and the different
318+ syscall number
319+ """
320+
321+
322+ def ql_epoll_create (ql : qiling .Qiling , size : int ):
323+ > >> >> >> 0 aef533c (Initial commit for epoll )
264324 if size < 0 :
265325 return EINVAL
266326 ret = select .epoll (sizehint = size , flags = 0 )
267327 fd = ret .fileno ()
268328 ql_obj = QlEpollObj (ret )
269329 ql .os .fd [fd ] = ql_obj
330+ < << << << HEAD
331+ return fd
332+ == == == =
270333 return fd
334+ >> >> >> > 0 aef533c (Initial commit for epoll )
0 commit comments