Skip to content

Commit

Permalink
fix EpollEvent memory layout (#411)
Browse files Browse the repository at this point in the history
* fix EpollEvent memory layout

on x86_64, `EpollEvent` is packed - the upstream version is correct here

* copy-paste upstream instead

* Adjust lines to be 80 characters per line.

---------

Co-authored-by: cheatfate <eugene.kabanov@status.im>
  • Loading branch information
arnetheduck and cheatfate committed Jul 6, 2023
1 parent 0a6f585 commit 3d80ea9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions chronos/osdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,22 @@ elif defined(linux):
EPOLL_CTL_DEL* = 2
EPOLL_CTL_MOD* = 3

# https://github.com/torvalds/linux/blob/ff6992735ade75aae3e35d16b17da1008d753d28/include/uapi/linux/eventpoll.h#L77
when defined(linux) and defined(amd64):
{.pragma: epollPacked, packed.}
else:
{.pragma: epollPacked.}

type
EpollData* {.importc: "union epoll_data",
header: "<sys/epoll.h>", pure, final.} = object
EpollData* {.importc: "epoll_data_t",
header: "<sys/epoll.h>", pure, final, union.} = object
`ptr`* {.importc: "ptr".}: pointer
fd* {.importc: "fd".}: cint
u32* {.importc: "u32".}: uint32
u64* {.importc: "u64".}: uint64

EpollEvent* {.importc: "struct epoll_event", header: "<sys/epoll.h>",
pure, final.} = object
EpollEvent* {.importc: "struct epoll_event",
header: "<sys/epoll.h>", pure, final, epollPacked.} = object
events*: uint32 # Epoll events
data*: EpollData # User data variable

Expand Down

0 comments on commit 3d80ea9

Please sign in to comment.