ppp icon indicating copy to clipboard operation
ppp copied to clipboard

Fix warning messages related to lcp_rtt_* functions

Open enaess opened this issue 1 year ago • 5 comments

Compiling the latest mainline on Solaris adds additional warning messages, we should address these. And why use the keyword "volatile" in these circumstances?

  lcp.c: In function ‘lcp_rtt_update_buffer’:
  lcp.c:2310:15: warning: passing argument 1 of ‘msync’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       if (msync(lcp_rtt_buffer, LCP_RTT_FILE_SIZE, MS_ASYNC) < 0)
                 ^~~~~~~~~~~~~~
  In file included from lcp.c:54:0:
  /usr/include/sys/mman.h:204:12: note: expected ‘void *’ but argument is of type ‘volatile u_int32_t * {aka volatile unsigned int *}’
   extern int msync(void *, size_t, int);
              ^~~~~
  lcp.c: In function ‘lcp_rtt_open_file’:
  lcp.c:2444:9: warning: passing argument 1 of ‘memset’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
    memset(lcp_rtt_buffer, 0, LCP_RTT_FILE_SIZE);
           ^~~~~~~~~~~~~~
  In file included from /usr/include/string.h:12:0,
                   from lcp.c:48:
  /usr/include/iso/string_iso.h:85:14: note: expected ‘void *’ but argument is of type ‘volatile u_int32_t * {aka volatile unsigned int *}’
   extern void *memset(void *, int, size_t);
                ^~~~~~
  lcp.c: In function ‘lcp_rtt_close_file’:
  lcp.c:2460:16: warning: passing argument 1 of ‘munmap’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       if (munmap(lcp_rtt_buffer, LCP_RTT_FILE_SIZE) < 0)
                  ^~~~~~~~~~~~~~
  In file included from lcp.c:54:0:
  /usr/include/sys/mman.h:202:12: note: expected ‘void *’ but argument is of type ‘volatile u_int32_t * {aka volatile unsigned int *}’
   extern int munmap(void *, size_t);
              ^~~~~~

enaess avatar Nov 06 '23 20:11 enaess

@rfc1036

enaess avatar Nov 06 '23 20:11 enaess

I think that the purpose is to prevent reordering by the compiler.

rfc1036 avatar Nov 06 '23 21:11 rfc1036

The buffer is volatile because other programs could potentially mmap it and access it concurrently, and so we want to limit reordering of accesses by the compiler. Volatile is not a complete fix, though, because the CPU can still reorder accesses, and to fix it properly we would need barrier instructions, which tends to get machine-dependent.

It is possible to make the accesses volatile,rather than the data, i.e. use casts to volatile where the buffer entries are read or written rather than making the data structure itself volatile.

paulusmack avatar Nov 08 '23 06:11 paulusmack

About Solaris:

  • https://github.com/ppp-project/ppp/issues/458

cc: @carlsonj, @RICCIARDI-Adrien.

Neustradamus avatar Nov 10 '23 13:11 Neustradamus

@enaess: This bug always exists?

Neustradamus avatar Jan 10 '24 14:01 Neustradamus

Fixed by fafbfdf

paulusmack avatar Apr 29 '24 06:04 paulusmack