Search code examples
cmacosunixlibckqueue

Kqueue udata field changing


On mac I am using kqueue, it states that udata is unchanged. However the array returned in event_data of kevent call is being modified somewhat. What could cause this? I am passing in the pointer to string casted to void*, and when i read after kevent after the first 3 characters the rest are coming out modified.

Thanks


Solution

  • The kernel only saves and returns the value of the pointer itself, not the contents of the memory it points to. Chances are that you're passing a pointer to memory that is being overwritten later on.

    The kqueue64() system call is a little bit more explicit about this by defining the field as a uint64_t.