On Tue, Aug 8, 2017 at 7:31 PM, Marcel Behlau <[email protected]> wrote: > Hi, > > i detected a problem, when a uv_cond_t isn't aligned to a valid 4Byte > boundary (?). > > I'm created the following code. Tested with libuv 1.13.1 on arch linux. > > #include <uv.h> > #include <stdio.h> > #include <string.h> // memset > > > typedef struct { > uv_mutex_t mutex; > uv_cond_t cond; > uint16_t data; > } WorkerConfig; > > > typedef struct { > WorkerConfig producer; > WorkerConfig consumer; > } GlobalConfig; > > > void checkError(int line, int val) > { > printf("%s called: Line %d: ReturnCode: %d\n", __func__, line, val); > if(val) > { > printf("File: %s Line %d failed: ReturnCode: %d\n", __FILE__, line, > val); > } > } > > > void initGlobalConfig(GlobalConfig* globalConfig) > { > printf("%s called\n", __func__); > memset(globalConfig, 0, sizeof(GlobalConfig)); > > checkError(__LINE__, uv_cond_init(&globalConfig->consumer.cond)); > checkError(__LINE__, uv_mutex_init(&globalConfig->producer.mutex)); > > checkError(__LINE__, uv_cond_init(&globalConfig->consumer.cond)); > checkError(__LINE__, uv_mutex_init(&globalConfig->producer.mutex)); > } > > > void waitForSignal(WorkerConfig* config) > { > printf("%s called\n", __func__); > uv_mutex_lock(&config->mutex); > uv_cond_wait(&config->cond, &config->mutex); > uv_mutex_unlock(&config->mutex); > } > > int main(int argc, char* argv[]) > { > setbuf(stdout, NULL); > > GlobalConfig globalConfig; > initGlobalConfig(&globalConfig); > waitForSignal(&globalConfig.consumer); > > return 0; > } > > > Compiling the code with the following is working fine: > >> > gcc test/tasktestwithoutstruct.c -luv; ./a.out >> initGlobalConfig called >> >> checkError called: Line 30: ReturnCode: 0 >> >> checkError called: Line 31: ReturnCode: 0 >> >> checkError called: Line 33: ReturnCode: 0 >> >> checkError called: Line 34: ReturnCode: 0 >> >> waitForSignal called > > > But with -fpack-struct parameter, a core dump occure. > >> > gcc test/tasktestwithoutstruct.c -luv -fpack-struct; ./a.out >> initGlobalConfig called >> >> checkError called: Line 30: ReturnCode: 0 >> >> checkError called: Line 31: ReturnCode: 0 >> >> checkError called: Line 33: ReturnCode: 0 >> >> checkError called: Line 34: ReturnCode: 0 >> >> waitForSignal called >> The futex facility returned an unexpected error code.Aborted (core dumped) > > > Is this a bug, or do i have (as user) to take care about the memory position > of the elements? At least, i would expect, that the uv_cond_init method > would check during the initialization, if the positions are valid. > > > Marcel
That's your responsibility, yes. I don't think it's reasonable to expect uv_cond_init() to check alignment. You tell the compiler that you are okay with it emitting incompatible code when you pass -fpack-struct. -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
