Skip to content

Commit e6f7b92

Browse files
authored
Fix #14758 Improve cfg: Add a list of pthread functions to posix lib (#8814)
1 parent 1fda43b commit e6f7b92

2 files changed

Lines changed: 261 additions & 0 deletions

File tree

cfg/posix.cfg

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,6 +4600,142 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
46004600
<not-uninit/>
46014601
</arg>
46024602
</function>
4603+
<function name="pthread_cond_wait">
4604+
<returnValue type="int"/>
4605+
<noreturn>false</noreturn>
4606+
<leak-ignore/>
4607+
<arg nr="1">
4608+
<not-null/>
4609+
<not-uninit/>
4610+
</arg>
4611+
<arg nr="2">
4612+
<not-null/>
4613+
<not-uninit/>
4614+
</arg>
4615+
</function>
4616+
<function name="pthread_cond_timedwait">
4617+
<returnValue type="int"/>
4618+
<noreturn>false</noreturn>
4619+
<leak-ignore/>
4620+
<arg nr="1">
4621+
<not-null/>
4622+
<not-uninit/>
4623+
</arg>
4624+
<arg nr="2">
4625+
<not-null/>
4626+
<not-uninit/>
4627+
</arg>
4628+
<arg nr="3">
4629+
<not-null/>
4630+
<not-uninit/>
4631+
</arg>
4632+
</function>
4633+
<function name="pthread_cond_init">
4634+
<returnValue type="int"/>
4635+
<noreturn>false</noreturn>
4636+
<leak-ignore/>
4637+
<arg nr="1" direction="out">
4638+
<not-null/>
4639+
</arg>
4640+
<arg nr="2" direction="in">
4641+
<not-null/>
4642+
</arg>
4643+
</function>
4644+
<function name="pthread_cond_destroy">
4645+
<returnValue type="int"/>
4646+
<noreturn>false</noreturn>
4647+
<leak-ignore/>
4648+
<arg nr="1" direction="in">
4649+
<not-null/>
4650+
<not-uninit/>
4651+
</arg>
4652+
</function>
4653+
<function name="pthread_cleanup_push">
4654+
<noreturn>false</noreturn>
4655+
<leak-ignore/>
4656+
<arg nr="1">
4657+
<not-null/>
4658+
<not-uninit/>
4659+
</arg>
4660+
<arg nr="2">
4661+
<not-null/>
4662+
<not-uninit/>
4663+
</arg>
4664+
</function>
4665+
<function name="pthread_cleanup_pop">
4666+
<noreturn>false</noreturn>
4667+
<leak-ignore/>
4668+
<arg nr="1" direction="in">
4669+
<not-uninit/>
4670+
<not-bool/>
4671+
</arg>
4672+
</function>
4673+
<function name="pthread_mutexattr_init,pthread_mutexattr_destroy">
4674+
<returnValue type="int"/>
4675+
<noreturn>false</noreturn>
4676+
<leak-ignore/>
4677+
<arg nr="1" direction="inout">
4678+
<not-null/>
4679+
</arg>
4680+
</function>
4681+
<function name="pthread_mutexattr_gettype">
4682+
<returnValue type="int"/>
4683+
<noreturn>false</noreturn>
4684+
<leak-ignore/>
4685+
<arg nr="1" direction="in">
4686+
<not-null/>
4687+
<not-uninit/>
4688+
</arg>
4689+
<arg nr="2" direction="out">
4690+
<not-null/>
4691+
</arg>
4692+
</function>
4693+
<function name="pthread_mutexattr_settype">
4694+
<returnValue type="int"/>
4695+
<noreturn>false</noreturn>
4696+
<leak-ignore/>
4697+
<arg nr="1" direction="in">
4698+
<not-null/>
4699+
<not-uninit/>
4700+
</arg>
4701+
<arg nr="2" direction="in">
4702+
<not-uninit/>
4703+
<valid>0:2</valid>
4704+
</arg>
4705+
</function>
4706+
<function name="pthread_setcancelstate">
4707+
<returnValue type="int"/>
4708+
<noreturn>false</noreturn>
4709+
<leak-ignore/>
4710+
<arg nr="1" direction="in">
4711+
<not-uninit/>
4712+
<valid>0:2</valid>
4713+
</arg>
4714+
<arg nr="2" direction="out">
4715+
<not-null/>
4716+
</arg>
4717+
</function>
4718+
<function name="pthread_setcanceltype">
4719+
<returnValue type="int"/>
4720+
<noreturn>false</noreturn>
4721+
<leak-ignore/>
4722+
<arg nr="1" direction="in">
4723+
<not-uninit/>
4724+
<valid>0:2</valid>
4725+
</arg>
4726+
<arg nr="2" direction="out">
4727+
<not-null/>
4728+
</arg>
4729+
</function>
4730+
<function name="pthread_cancel">
4731+
<returnValue type="int"/>
4732+
<noreturn>false</noreturn>
4733+
<leak-ignore/>
4734+
<arg nr="1" direction="in">
4735+
<not-uninit/>
4736+
<not-bool/>
4737+
</arg>
4738+
</function>
46034739
<!-- https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html -->
46044740
<!-- int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine)(void*), void * arg); -->
46054741
<function name="pthread_create">
@@ -6437,6 +6573,32 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
64376573
<define name="R_OK" value="4"/>
64386574
<define name="W_OK" value="2"/>
64396575
<define name="X_OK" value="1"/>
6576+
<define name="PTHREAD_STACK_MIN" value="16384"/>
6577+
<define name="PTHREAD_CANCEL_ASYNCHRONOUS" value="1"/>
6578+
<define name="PTHREAD_CANCEL_ENABLE" value="0"/>
6579+
<define name="PTHREAD_CANCEL_DEFERRED" value="0"/>
6580+
<define name="PTHREAD_CANCEL_DISABLE" value="1"/>
6581+
<define name="PTHREAD_CANCELED" value="(void *)18446744073709551615U"/>
6582+
<define name="PTHREAD_COND_INITIALIZER" value="{ { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } }"/>
6583+
<define name="PTHREAD_CREATE_DETACHED" value="1"/>
6584+
<define name="PTHREAD_CREATE_JOINABLE" value="0"/>
6585+
<define name="PTHREAD_EXPLICIT_SCHED" value="1"/>
6586+
<define name="PTHREAD_INHERIT_SCHED" value="0"/>
6587+
<define name="PTHREAD_MUTEX_DEFAULT" value="0"/>
6588+
<define name="PTHREAD_MUTEX_ERRORCHECK" value="2"/>
6589+
<define name="PTHREAD_MUTEX_NORMAL" value="0"/>
6590+
<define name="PTHREAD_MUTEX_TIMED_NP" value="0"/>
6591+
<define name="PTHREAD_MUTEX_INITIALIZER" value="{ { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } }"/>
6592+
<define name="PTHREAD_MUTEX_RECURSIVE" value="1"/>
6593+
<define name="PTHREAD_ONCE_INIT" value="{0, {0}}"/>
6594+
<define name="PTHREAD_PRIO_INHERIT" value="1"/>
6595+
<define name="PTHREAD_PRIO_NONE" value="0"/>
6596+
<define name="PTHREAD_PRIO_PROTECT" value="2"/>
6597+
<define name="PTHREAD_PROCESS_SHARED" value="1"/>
6598+
<define name="PTHREAD_PROCESS_PRIVATE" value="0"/>
6599+
<define name="PTHREAD_RWLOCK_INITIALIZER" value="{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0 }, 0, 0 } }"/>
6600+
<define name="PTHREAD_SCOPE_PROCESS" value="1"/>
6601+
<define name="PTHREAD_SCOPE_SYSTEM" value="0"/>
64406602
<!-- https://man7.org/linux/man-pages/man3/lockf.3.html -->
64416603
<define name="F_LOCK" value="1"/>
64426604
<define name="F_TEST" value="3"/>

test/cfg/posix.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <strings.h>
3838
#if defined(__APPLE__)
3939
#include <xlocale.h>
40+
#include <limits.h>
4041
#endif
4142
#if !defined(__APPLE__)
4243
#include <mqueue.h>
@@ -1508,3 +1509,101 @@ void invalidFunctionArg_nice(int inc)
15081509
// cppcheck-suppress invalidFunctionArg
15091510
nice(+20);
15101511
}
1512+
1513+
void pthread_cond_wait_test(pthread_cond_t *cond, pthread_mutex_t *mutex)
1514+
{
1515+
(void)pthread_cond_wait(cond, mutex);
1516+
}
1517+
1518+
void pthread_cond_timedwait_test(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
1519+
{
1520+
// cppcheck-suppress nullPointer
1521+
(void)pthread_cond_timedwait(cond, mutex, NULL);
1522+
(void)pthread_cond_timedwait(cond, mutex, abstime);
1523+
}
1524+
1525+
void pthread_cond_init_test(pthread_cond_t *cond, const pthread_condattr_t *attr)
1526+
{
1527+
// cppcheck-suppress nullPointer
1528+
(void)pthread_cond_init(cond, NULL);
1529+
(void)pthread_cond_init(cond, attr);
1530+
}
1531+
1532+
void pthread_cond_destroy_test(const pthread_cond_t *cond)
1533+
{
1534+
(void)pthread_cond_destroy(cond);
1535+
}
1536+
1537+
void pthread_cleanup_push_test(void (*routine)(void *), void *arg)
1538+
{
1539+
pthread_cleanup_push(routine, arg);
1540+
pthread_cleanup_pop(0);
1541+
}
1542+
1543+
void pthread_mutexattr_init_test(pthread_mutexattr_t *attr)
1544+
{
1545+
(void)pthread_mutexattr_init(attr);
1546+
}
1547+
1548+
void pthread_mutexattr_destroy_test(pthread_mutexattr_t *attr)
1549+
{
1550+
(void)pthread_mutexattr_destroy(attr);
1551+
}
1552+
1553+
void pthread_mutexattr_settype_test(const pthread_mutexattr_t *attr, int type)
1554+
{
1555+
(void)pthread_mutexattr_settype(attr, type);
1556+
}
1557+
1558+
void pthread_mutexattr_gettype_test(const pthread_mutexattr_t *attr, int *type)
1559+
{
1560+
(void)pthread_mutexattr_gettype(attr, type);
1561+
}
1562+
1563+
void pthread_setcancelstate_test(int state, int *oldstate)
1564+
{
1565+
(void)pthread_setcancelstate(state, oldstate);
1566+
}
1567+
1568+
void pthread_setcanceltype_test(int type, int *oldtype)
1569+
{
1570+
(void)pthread_setcanceltype(type, oldtype);
1571+
}
1572+
1573+
void pthread_cancel_test(pthread_t thread)
1574+
{
1575+
(void)pthread_cancel(thread);
1576+
}
1577+
1578+
void pthread_define_test()
1579+
{
1580+
PTHREAD_STACK_MIN;
1581+
PTHREAD_CANCEL_ASYNCHRONOUS;
1582+
PTHREAD_CANCEL_ENABLE;
1583+
PTHREAD_CANCEL_DEFERRED;
1584+
PTHREAD_CANCEL_DISABLE;
1585+
PTHREAD_CANCELED;
1586+
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
1587+
(void)cond;
1588+
PTHREAD_CREATE_DETACHED;
1589+
PTHREAD_CREATE_JOINABLE;
1590+
PTHREAD_EXPLICIT_SCHED;
1591+
PTHREAD_INHERIT_SCHED;
1592+
PTHREAD_MUTEX_DEFAULT;
1593+
PTHREAD_MUTEX_ERRORCHECK;
1594+
PTHREAD_MUTEX_NORMAL;
1595+
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1596+
(void)mutex;
1597+
PTHREAD_MUTEX_RECURSIVE;
1598+
pthread_once_t once_block = PTHREAD_ONCE_INIT;
1599+
(void)once_block;
1600+
PTHREAD_PRIO_INHERIT;
1601+
PTHREAD_PRIO_NONE;
1602+
PTHREAD_PRIO_PROTECT;
1603+
PTHREAD_PROCESS_SHARED;
1604+
PTHREAD_PROCESS_PRIVATE;
1605+
pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
1606+
(void)rwlock;
1607+
PTHREAD_SCOPE_PROCESS;
1608+
PTHREAD_SCOPE_SYSTEM;
1609+
}

0 commit comments

Comments
 (0)