[PATCH] sys/types.h: Avoid bit-manipulation of signed values

Nick Withers nick.withers@anu.edu.au
Thu Dec 3 09:09:00 GMT 2015


Hi all,

On Fri, 2015-11-27 at 14:04 +0100, Corinna Vinschen wrote:
> On Nov 27 19:08, Nick Withers wrote:
> > On Fri, 2015-11-27 at 09:03 +0100, Sebastian Huber wrote:
> > > 
> > > On 27/11/15 08:46, Nick Withers wrote:
> > > > On Fri, 2015-11-27 at 08:26 +0100, Sebastian Huber wrote:
> > > > > > 
> > > > > > On 26/11/15 10:17, Corinna Vinschen wrote:
> > > > > > > > > > > > Looks good. I need some time to use this in
> > > > > > > > > > > > RTEMS,
> > > > > > > > > > > > since I am
> > > > > > > > > > > > currently busy
> > > > > > > > > > > > > > > > with other stuff and this is only a
> > > > > > > > > > > > > > > > nice to
> > > > > > > > > > > > > > > > have.
> > > > > > > > > > > > 
> > > > > > > > > > > > That's ok, I'm pretty busy myself.  Can you
> > > > > > > > > > > > ping
> > > > > > > > > > > > back as soon
> > > > > > > > > > > > as you
> > > > > > > > > > > > tested this?
> > > > > > > > Did you test this in the meantime?
> > > > > > 
> > > > > > Sorry, please don't wait for me. It will be next year
> > > > > > before I
> > > > > > can
> > > > > > work
> > > > > > on this.
> 
> I'm sorry to read that.
> 
> > > > Is this the kind of thing a humble RTEMS user might be able to
> > > > figure
> > > > out?
> > > > 
> > > > It sounds like I'd have to do some hacking on / remove RTEMS'
> > > > sys/select.h at least?
> > > 
> > > The goal is to use a Newlib <sys/select.h> that is capable to
> > > replace
> > > these two files:
> > > 
> > > https://git.rtems.org/rtems/tree/cpukit/libnetworking/sys/select.
> > > h
> > > https://git.rtems.org/rtems-libbsd/tree/freebsd/sys/sys/select.h
> > > 
> > > What complicates the things a bit is that the FreeBSD file uses
> > > 
> > > https://git.rtems.org/rtems-libbsd/tree/freebsd/sys/sys/_sigset.h
> > > 
> > > which is used by other header files as well.
> > 
> > Righto, thanks Sebastian.
> > 
> > I'm heading off for the weekend, but if I don't hear anything I'll
> > have
> > a crack at it on Monday.
> 
> The first thing would be to check if sys/select.h from Cygwin is
> sufficent for RTEMS as well, provided you apply my patch from
> https://sourceware.org/ml/newlib/2015/msg00832.html and move the
> resulting winsup/cygwin/include/sys/select.h to
> newlib/libc/include/sys.
> 
> If that works fine, I apply my patch.

I haven't yet tackled the rtems-libbsd part Sebastian mentioned, but
have made some progress.

With the attached newlib-sys_select.patch* and rtems-sys_select.patch**
patches applied to Newlib and RTEMS Git masters respectively, the RTEMS
tests "syscall01" and "psxreaddir" seem to pass through PSim (psim
-syscall01.out and psxreaddir.out).


How do folk feel about this so far?


* newlib/libc/sys/arm/sys/param.h changes are untested

** I 
 - used the RSB master to build 4.12 tools
 - removed the BSD advertising clause from what's now sys/selinfo.h,
but am not sure that I should have
 - made a few unrelated but minor changes to cpukit/libmisc/shell/*.c
printf()s to ensure format specifiers matched parameter types
 - disabled dltests on PSim after running out of space (in .rodata from
memory) building dl02; dl01 did build fine, though
-- 
Nick Withers

Embedded Systems Programmer
Department of Nuclear Physics, Research School of Physics and Engineering
The Australian National University (CRICOS: 00120C)

-------------- next part --------------
nick@nuc211-vm2:~/rtems/git/build/rtems$ psim-gdb powerpc-rtems4.12/c/psim/testsuites/psxtests/psxreaddir/psxreaddir.exe 
WARNING!!! RTEMS GDB Macro files not found
GNU gdb (GDB) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=powerpc-rtems4.12".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from powerpc-rtems4.12/c/psim/testsuites/psxtests/psxreaddir/psxreaddir.exe...done.
Connected to the simulator.
Breakpoint 1 at 0x47f4: file ../../../../../../../../rtems/c/src/lib/libcpu/powerpc/new-exceptions/bspsupport/ppc_exc_global_handler.c, line 24.
Breakpoint 2 at 0x13a14: file ../../../../../../../rtems/c/src/../../cpukit/score/src/interr.c, line 39.
psim-cmds:5: Error in sourced command file:
No symbol "the_source" in current context.
(gdb) run
Starting program: /home/nick/rtems/git/build/rtems/powerpc-rtems4.12/c/psim/testsuites/psxtests/psxreaddir/psxreaddir.exe 
warning: failed to reevaluate condition for breakpoint 1: No symbol "the_source" in current context.
OpenPIC Version 1.2 (2 CPUs and 17 IRQ sources) at 0x0C130000
OpenPIC Vendor 0 (Unknown), Device 0 (Unknown), Stepping 0
Overriding NumSources (17) from configuration with 16
OpenPIC timer frequency is 1 Hz


*** BEGIN OF TEST PSXREADDIR ***

chdir to the root directory
chdir() status : 0


Creating a series of directories under /
Creating directory: a      0 0    Success
Creating directory: b      0 0    Success
Creating directory: c      0 0    Success
Creating directory: d      0 0    Success
Creating directory: e      0 0    Success
Creating directory: f      0 0    Success
Creating directory: c/y      0 0    Success
Creating directory: c/z      0 0    Success
Creating directory: c/x      0 0    Success
Creating directory: c/y/a3333      0 0    Success
Creating directory: c/y/j123      0 0    Success
Create a lot of files
Create a
Create b
Create c
Create d
Create e
Create f
Create g
Create h
Create i
Create j
Create k
Create l
Create m
Create n
Create o
Create p
Create q
Create r
Create s
Create t
Create u
Create v
Create w
Create x
Create y
Create z
Create aa
Create ab
Create ac
Create ad
Create ae
Create af
Create ag
Create ah
Create ai
Create aj
Create ak
Create al
Create am
Create an
Create ao
Create ap
Create aq
Create ar
Open /many and print the directory
name                     inode   offset   reclen  type
a                      232312        0    280   0x0118
b                      232392      430    280   0x0118
c                      232472     1060    280   0x0118
d                      232552     1510    280   0x0118
e                      232632     2140    280   0x0118
f                      232712     2570    280   0x0118
g                      232792     3220    280   0x0118
h                      232872     3650    280   0x0118
i                      232952     4300    280   0x0118
j                      233032     4730    280   0x0118
k                      233112     5360    280   0x0118
l                      233192     6010    280   0x0118
m                      233272     6440    280   0x0118
n                      233352     7070    280   0x0118
o                      233432     7520    280   0x0118
p                      233512    10150    280   0x0118
q                      233592    10600    280   0x0118
r                      233672    11230    280   0x0118
s                      233752    11660    280   0x0118
t                      233832    12310    280   0x0118
u                      233912    12740    280   0x0118
v                      233992    13370    280   0x0118
w                      234072    14020    280   0x0118
x                      234152    14450    280   0x0118
y                      234232    15100    280   0x0118
z                      234312    15530    280   0x0118
aa                     234392    16160    280   0x0118
ab                     234472    16610    280   0x0118
ac                     234552    17240    280   0x0118
ad                     234632    17670    280   0x0118
ae                     234712    20320    280   0x0118
af                     234792    20750    280   0x0118
ag                     234872    21400    280   0x0118
ah                     234952    22030    280   0x0118
ai                     235032    22460    280   0x0118
aj                     235112    23110    280   0x0118
ak                     235192    23540    280   0x0118
al                     235272    24170    280   0x0118
am                     235352    24620    280   0x0118
an                     235432    25250    280   0x0118
ao                     235512    25700    280   0x0118
ap                     235592    26330    280   0x0118
aq                     235672    26760    280   0x0118
ar                     235752    27410    280   0x0118
open /b/my_file
scandir a file status: -1
Open /b/new_file
fcntl F_SETFD should return 0
fcntl F_SETFD should return 1
fcntl F_DUPFD should return a file descriptor
close duplicate should return 0
fcntl F_GETFL returns current flags
fcntl F_GETFL returned 0x200
fcntl F_SETFL to add O_APPEND and O_NONBLOCK
fcntl F_GETFL return current flags to see changes
fcntl F_GETFL returned 0x4208
fcntl F_GETLK should return -1
fcntl F_SETLK should return -1
fcntl F_SETLKW should return -1
fcntl F_SETOWN should return -1
fcntl F_GETOWN should return -1
fcntl invalid argument should return -1
Status -1
close should return 0
opendir, readdir and closedir /b/my_file
opendir, readdir and closedir
chdir to /b/my_file

Performing stat of directory /
status for stat : 0, size of directory: 4300


Open and print directory /
name                     inode   offset   reclen  type
dev                    230352        0    280   0x0118
a                      231304      430    280   0x0118
b                      231384     1060    280   0x0118
c                      231464     1510    280   0x0118
d                      231544     2140    280   0x0118
e                      231624     2570    280   0x0118
f                      231704     3220    280   0x0118
many                   232184     3650    280   0x0118

mkdir /d/my_dir
Open /d/my_dir
remove /d/my_dir.
close /d/my_dir.

Opening directory /c
name                     inode   offset   reclen  type
y                      231784        0    280   0x0118
z                      231864      430    280   0x0118
x                      231944     1060    280   0x0118

Opening directory /c/y
name                     inode   offset   reclen  type
a3333                  232024        0    280   0x0118
j123                   232104      430    280   0x0118

LSEEK to the start of the open directory
name                     inode   offset   reclen  type
dev                    230352        0    280   0x0118
a                      231304      430    280   0x0118
b                      231384     1060    280   0x0118
c                      231464     1510    280   0x0118
d                      231544     2140    280   0x0118
e                      231624     2570    280   0x0118
f                      231704     3220    280   0x0118
many                   232184     3650    280   0x0118

Rewinding directory
name                     inode   offset   reclen  type
dev                    230352        0    280   0x0118
a                      231304      430    280   0x0118
b                      231384     1060    280   0x0118
c                      231464     1510    280   0x0118
d                      231544     2140    280   0x0118
e                      231624     2570    280   0x0118
f                      231704     3220    280   0x0118
many                   232184     3650    280   0x0118

Seek directory
telldir() should report only sizeof(struct dirent) increments 
in position. Sizeof(struct dirent): 280
seeked to  0 -- currently at  1
seeked to 106 -- currently at  2
seeked to 214 -- currently at  3
Send seekdir a NULL pointer

Closing directory

SCANDIR TEST

selection rule 1
scanning for any entry under directory /c

SCANDIR SELECT1 accepts  nodename: y
SCANDIR SELECT1 accepts  nodename: z
SCANDIR SELECT1 accepts  nodename: x

scandir status: 3
Selected Node Name: y
Selected Node Name: z
Selected Node Name: x

selection rule 2
scanning for any entry under directory /c whose name = y

SCANDIR SELECT accepted nodename: y
SCANDIR SELECT rejected nodename: z
SCANDIR SELECT rejected nodename: x

scandir status: 1
Selected Node Name: y

SCANDIR with sorting

selection rule 1
scanning for any entry under directory /c
sort in ascending order

SCANDIR SELECT1 accepts  nodename: y
SCANDIR SELECT1 accepts  nodename: z
SCANDIR SELECT1 accepts  nodename: x

scandir status: 3
Selected and Sorted Node Name: x
Selected and Sorted Node Name: y
Selected and Sorted Node Name: z

SCANDIR with sorting

selection rule 1
scanning for any entry under directory /c
sort in descending order

SCANDIR SELECT1 accepts  nodename: y
SCANDIR SELECT1 accepts  nodename: z
SCANDIR SELECT1 accepts  nodename: x
scandir status: 3
Selected and Sorted Node Name: z
Selected and Sorted Node Name: y
Selected and Sorted Node Name: x
unlink /b/my_file should return 0
Validate readdir across mount point
name                     inode   offset   reclen  type
should_be_hidden       236512        0    280   0x0118
Attempting to mount IMFS file system at /imfs 
create /imfs/testdir and /imfs/testdir/testsubdir
name                     inode   offset   reclen  type
testdir                236856        0    280   0x0118
name                     inode   offset   reclen  type
testdir                236856        0    280   0x0118
name                     inode   offset   reclen  type
testdir                236856        0    280   0x0118
name                     inode   offset   reclen  type
testsubdir             236936        0    280   0x0118
name                     inode   offset   reclen  type
testdir                236856        0    280   0x0118
*** END OF TEST PSXREADDIR ***

Breakpoint 2, _Terminate (the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXIT, 
    is_internal=is_internal@entry=false, the_error=0)
    at ../../../../../../../rtems/c/src/../../cpukit/score/src/interr.c:39
39	  _ISR_Disable_without_giant( level );
-------------- next part --------------
nick@nuc211-vm2:~/rtems/git/build/rtems$ psim-gdb powerpc-rtems4.12/c/psim/testsuites/libtests/syscall01/syscall01.exe
WARNING!!! RTEMS GDB Macro files not found
GNU gdb (GDB) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=powerpc-rtems4.12".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from powerpc-rtems4.12/c/psim/testsuites/libtests/syscall01/syscall01.exe...done.
Connected to the simulator.
Breakpoint 1 at 0x438c: file ../../../../../../../../rtems/c/src/lib/libcpu/powerpc/new-exceptions/bspsupport/ppc_exc_global_handler.c, line 24.
Breakpoint 2 at 0x1fcd0: file ../../../../../../../rtems/c/src/../../cpukit/score/src/interr.c, line 39.
psim-cmds:5: Error in sourced command file:
No symbol "the_source" in current context.
(gdb) run
Starting program: /home/nick/rtems/git/build/rtems/powerpc-rtems4.12/c/psim/testsuites/libtests/syscall01/syscall01.exe 
warning: failed to reevaluate condition for breakpoint 1: No symbol "the_source" in current context.
OpenPIC Version 1.2 (2 CPUs and 17 IRQ sources) at 0x0C130000
OpenPIC Vendor 0 (Unknown), Device 0 (Unknown), Stepping 0
Overriding NumSources (17) from configuration with 16
OpenPIC timer frequency is 1 Hz


*** BEGIN OF TEST SYSCALL 1 ***
*** END OF TEST SYSCALL 1 ***

Breakpoint 2, _Terminate (the_source=the_source@entry=RTEMS_FATAL_SOURCE_EXIT, 
    is_internal=is_internal@entry=false, the_error=0)
    at ../../../../../../../rtems/c/src/../../cpukit/score/src/interr.c:39
39	  _ISR_Disable_without_giant( level );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib-sys_select.patch
Type: text/x-patch
Size: 5978 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20151203/ef77aada/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rtems-sys_select.patch
Type: text/x-patch
Size: 15113 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20151203/ef77aada/attachment-0001.bin>


More information about the Newlib mailing list