[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,31 @@
{
"ENTRY": "vSocketBind",
"ALLOW_SEND_WITHOUT_BIND":"1",
"ALLOW_ETHERNET_DRIVER_FILTER":"1",
"ALLOW_TCP":"1",
"CBMCFLAGS":
[
"--unwind 1"
],
"OBJS":
[
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
"$(ENTRY)_harness.goto"
],
"INSTFLAGS":
[
],
"DEF":
[
"ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND={ALLOW_SEND_WITHOUT_BIND}",
"ipconfigUSE_TCP={ALLOW_TCP}",
"ipconfigETHERNET_DRIVER_FILTERS_PACKETS={ALLOW_ETHERNET_DRIVER_FILTER}"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/utility"
]
}

View File

@ -0,0 +1,68 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Sockets.h"
#include "memory_assignments.c"
uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol );
uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol )
{
uint16_t usResult;
return usResult;
}
BaseType_t xIPIsNetworkTaskReady( void )
{
/* Return true saying that the task is ready. */
return pdTRUE;
}
/* Random number generator provided by the application. In our case, CBMC provides
* an indeterministic value. */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
__CPROVER_assert( pulNumber != NULL, "Argument to xApplicationGetRandomNumber cannot be NULL" );
if( nondet_bool() )
{
*pulNumber = nondet_uint32_t();
return 1;
}
else
{
*pulNumber = NULL;
return 0;
}
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
struct freertos_sockaddr * pxBindAddress = safeMalloc( sizeof( struct freertos_sockaddr ) );
/* uxAddressLength is not used in this implementation. */
size_t uxAddressLength;
BaseType_t xInternal;
/* Call to init the socket list. */
vNetworkSocketsInit();
vSocketBind( pxSocket, pxBindAddress, uxAddressLength, xInternal );
}

View File

@ -0,0 +1,28 @@
{
"ENTRY": "vSocketBind",
"ALLOW_SEND_WITHOUT_BIND":"1",
"CBMCFLAGS":
[
"--unwind 1"
],
"OBJS":
[
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
"$(ENTRY)_harness.goto"
],
"INSTFLAGS":
[
],
"DEF":
[
"ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND={ALLOW_SEND_WITHOUT_BIND}",
"ipconfigUSE_TCP=1"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/utility"
]
}

View File

@ -0,0 +1,66 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Sockets.h"
#include "memory_assignments.c"
uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol )
{
uint16_t usResult;
return usResult;
}
BaseType_t xIPIsNetworkTaskReady( void )
{
/* Return true saying that the task is ready. */
return pdTRUE;
}
/* Random number generator provided by the application. In our case, CBMC provides
* an indeterministic value. */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
__CPROVER_assert( pulNumber != NULL, "Argument to xApplicationGetRandomNumber cannot be NULL" );
if( nondet_bool() )
{
*pulNumber = nondet_uint32_t();
return 1;
}
else
{
*pulNumber = NULL;
return 0;
}
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
struct freertos_sockaddr * pxBindAddress = safeMalloc( sizeof( struct freertos_sockaddr ) );
/* uxAddressLength is not used in this implementation. */
size_t uxAddressLength;
BaseType_t xInternal;
/* Call to init the socket list. */
vNetworkSocketsInit();
vSocketBind( pxSocket, pxBindAddress, uxAddressLength, xInternal );
}

View File

@ -0,0 +1,28 @@
{
"ENTRY": "vSocketBind",
"ALLOW_SEND_WITHOUT_BIND":"0",
"CBMCFLAGS":
[
"--unwind 1"
],
"OBJS":
[
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
"$(ENTRY)_harness.goto"
],
"INSTFLAGS":
[
],
"DEF":
[
"ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND={ALLOW_SEND_WITHOUT_BIND}",
"ipconfigUSE_TCP=1"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/utility"
]
}

View File

@ -0,0 +1,70 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Sockets.h"
#include "memory_assignments.c"
uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol )
{
uint16_t usResult;
return usResult;
}
BaseType_t xIPIsNetworkTaskReady( void )
{
/* Return true saying that the task is ready. */
return pdTRUE;
}
/* Random number generator provided by the application. In our case, CBMC provides
* an indeterministic value. */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
__CPROVER_assert( pulNumber != NULL, "Argument to xApplicationGetRandomNumber cannot be NULL" );
if( nondet_bool() )
{
*pulNumber = nondet_uint32_t();
return 1;
}
else
{
*pulNumber = NULL;
return 0;
}
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
/* malloc instead of safeMalloc since we do not allow socket without binding. */
struct freertos_sockaddr * pxBindAddress = malloc( sizeof( struct freertos_sockaddr ) );
__CPROVER_assume( pxBindAddress != NULL );
/* uxAddressLength is not used in this implementation. */
size_t uxAddressLength;
BaseType_t xInternal;
/* Call to init the socket list. */
vNetworkSocketsInit();
vSocketBind( pxSocket, pxBindAddress, uxAddressLength, xInternal );
}

View File

@ -0,0 +1,39 @@
{
"ENTRY": "vSocketClose",
"CBMCFLAGS":
[
"--unwind 2"
],
"OBJS":
[
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
"$(ENTRY)_harness.goto"
],
"DEF":
[
{
"UDP_Only":[
"PROTOCOL=FREERTOS_IPPROTO_UDP",
"ipconfigUSE_TCP=1",
"ipconfigUSE_TCP_WIN=1",
"ipconfigHAS_DEBUG_PRINTF=0"
]
},
{
"TCP_Only":[
"PROTOCOL=FREERTOS_IPPROTO_TCP",
"ipconfigUSE_TCP=1",
"ipconfigUSE_TCP_WIN=1",
"ipconfigHAS_DEBUG_PRINTF=0"
]
}
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/utility",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs"
]
}

View File

@ -0,0 +1,125 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Sockets.h"
#include "freertos_api.c"
#include "memory_assignments.c"
/* The memory safety of vTCPWindowDestroy has already been proved in
* proofs/TCPWin/vTCPWindowDestroy. */
void vTCPWindowDestroy( TCPWindow_t const * xWindow )
{
__CPROVER_assert( xWindow != NULL, "xWindow cannot be NULL" );
/* Do nothing. */
}
void harness()
{
size_t xRequestedSizeBytes;
TickType_t xBlockTimeTicks;
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
/* Socket cannot be NULL or invalid for this proof. This is allowed since vSocketClose is called by IP task only. */
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
/* Request a random number of bytes keeping in mind the maximum bound of CBMC. */
__CPROVER_assume( xRequestedSizeBytes < ( CBMC_MAX_OBJECT_SIZE - ipBUFFER_PADDING ) );
/* Non-deterministically malloc the callback function. */
pxSocket->pxUserWakeCallback = safeMalloc( sizeof( SocketWakeupCallback_t ) );
/* Non deterministically add an event group. */
if( nondet_bool() )
{
pxSocket->xEventGroup = xEventGroupCreate();
__CPROVER_assume( pxSocket->xEventGroup != NULL );
}
else
{
pxSocket->xEventGroup = NULL;
}
/* Create and fill the socket in the bound socket list. This socket will then be
* removed by a call to the vSocketClose. */
List_t BoundSocketList;
vListInitialise( &BoundSocketList );
/* Non-deterministically add the socket to bound socket list. */
if( nondet_bool() )
{
vListInitialiseItem( &( pxSocket->xBoundSocketListItem ) );
pxSocket->xBoundSocketListItem.pxContainer = &( BoundSocketList );
vListInsertEnd( &BoundSocketList, &( pxSocket->xBoundSocketListItem ) );
}
else
{
pxSocket->xBoundSocketListItem.pxContainer = NULL;
}
/* See Configurations.json for details. Protocol can be UDP or TCP. */
pxSocket->ucProtocol = PROTOCOL;
NetworkBufferDescriptor_t * NetworkBuffer;
/* Get a network buffer descriptor with requested bytes. See the constraints
* on the number of requested bytes above. And block for random timer ticks. */
if( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP )
{
pxSocket->u.xTCP.rxStream = malloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = malloc( sizeof( StreamBuffer_t ) );
/* Non deterministically allocate/not-allocate the network buffer descriptor. */
if( nondet_bool() )
{
pxSocket->u.xTCP.pxAckMessage = pxGetNetworkBufferWithDescriptor( xRequestedSizeBytes, xBlockTimeTicks );
}
else
{
pxSocket->u.xTCP.pxAckMessage = NULL;
}
}
else if( pxSocket->ucProtocol == FREERTOS_IPPROTO_UDP )
{
/* Initialise the waiting packet list. */
vListInitialise( &( pxSocket->u.xUDP.xWaitingPacketsList ) );
/* Non-deterministically either add/not-add item to the waiting packet list. */
if( nondet_bool() )
{
NetworkBuffer = pxGetNetworkBufferWithDescriptor( xRequestedSizeBytes, xBlockTimeTicks );
/* Assume non-NULL network buffer for this case. */
__CPROVER_assume( NetworkBuffer != NULL );
/* Initialise the buffer list item. */
vListInitialiseItem( &( NetworkBuffer->xBufferListItem ) );
/*Set the item owner as the buffer itself. */
listSET_LIST_ITEM_OWNER( &( NetworkBuffer->xBufferListItem ), ( void * ) NetworkBuffer );
/* Set the container of the buffer list item as the waiting packet list. */
NetworkBuffer->xBufferListItem.pxContainer = &( pxSocket->u.xUDP.xWaitingPacketsList );
/* Insert the list-item into the waiting packet list. */
vListInsertEnd( &( pxSocket->u.xUDP.xWaitingPacketsList ), &( NetworkBuffer->xBufferListItem ) );
}
}
/* Call to init the socket list. */
vNetworkSocketsInit();
/* Call the function. */
vSocketClose( pxSocket );
/* No post checking to be done. */
}

View File

@ -0,0 +1,26 @@
{
"ENTRY": "vSocketWakeUpUser",
"CBMCFLAGS":
[
"--unwind 1"
],
"OBJS":
[
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
"$(ENTRY)_harness.goto"
],
"DEF":
[
"ipconfigSOCKET_HAS_USER_SEMAPHORE=1",
"ipconfigSOCKET_HAS_USER_WAKE_CALLBACK=1",
"ipconfigSUPPORT_SELECT_FUNCTION=1",
"configUSE_16_BIT_TICKS=0"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/utility"
]
}

View File

@ -0,0 +1,167 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "event_groups.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Sockets.h"
#include "memory_assignments.c"
/*********************************************************************************
*
* The below structure definitions are just copy pasted from the FreeRTOS-Kernel.
* To understand the proof, you need not understand the structures and they can
* be ignored safely.
*
********************************************************************************/
/* Define the bits used by Kernel. */
#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
typedef struct EventGroupDef_t
{
EventBits_t uxEventBits;
List_t xTasksWaitingForBits;
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxEventGroupNumber;
#endif
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
uint8_t ucStaticallyAllocated;
#endif
} EventGroup_t;
typedef struct QueuePointers
{
int8_t * pcTail;
int8_t * pcReadFrom;
} QueuePointers_t;
typedef struct SemaphoreData
{
TaskHandle_t xMutexHolder;
UBaseType_t uxRecursiveCallCount;
} SemaphoreData_t;
typedef struct QueueDefinition
{
int8_t * pcHead;
int8_t * pcWriteTo;
union
{
QueuePointers_t xQueue;
SemaphoreData_t xSemaphore;
} u;
List_t xTasksWaitingToSend;
List_t xTasksWaitingToReceive;
volatile UBaseType_t uxMessagesWaiting;
UBaseType_t uxLength;
UBaseType_t uxItemSize;
volatile int8_t cRxLock;
volatile int8_t cTxLock;
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
uint8_t ucStaticallyAllocated;
#endif
#if ( configUSE_QUEUE_SETS == 1 )
struct QueueDefinition * pxQueueSetContainer;
#endif
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxQueueNumber;
uint8_t ucQueueType;
#endif
} xQUEUE;
/********************************************************/
/********* End Kernel cut-paste section *****************/
/********************************************************/
/* The memory safety of xQueueGenericSend has been proved before.
* See github.com/FreeRTOS/FreeRTOS/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend.
*/
BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
const void * const pvItemToQueue,
TickType_t xTicksToWait,
const BaseType_t xCopyPosition )
{
BaseType_t xResult;
/* These asserts are copied over from the original function itself. */
__CPROVER_assert( xQueue != NULL, "xQueue cannot be NULL" );
__CPROVER_assert( !( ( pvItemToQueue == NULL ) && ( xQueue->uxItemSize != ( UBaseType_t ) 0U ) ),
"If itemsize is non-zero, then pvItemToQueue cannot be NULL." );
__CPROVER_assert( !( ( xCopyPosition == queueOVERWRITE ) && ( xQueue->uxLength != 1 ) ),
"If length is one, then check the copy position" );
/* Return any random value. */
return xResult;
}
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet )
{
EventBits_t uxReturnBits;
/* The below asserts are copied over from the original function itself. */
__CPROVER_assert( xEventGroup != NULL,
"The event group cannot be NULL" );
__CPROVER_assert( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0,
"Cannot set Kernel bits" );
/* Return any random value. */
return uxReturnBits;
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
pxSocket->pxUserWakeCallback = safeMalloc( sizeof( SocketWakeupCallback_t ) );
pxSocket->pxSocketSet = safeMalloc( sizeof( struct xSOCKET_SET ) );
if( pxSocket->pxSocketSet != NULL )
{
pxSocket->pxSocketSet->xSelectGroup = safeMalloc( sizeof( struct EventGroupDef_t ) );
/* The event group cannot be NULL. */
__CPROVER_assume( pxSocket->pxSocketSet->xSelectGroup != NULL );
}
pxSocket->pxUserSemaphore = safeMalloc( sizeof( xQUEUE ) );
if( pxSocket->pxUserSemaphore != NULL )
{
/* The item size must be zero since this queue will act as a semaphore. */
__CPROVER_assume( pxSocket->pxUserSemaphore->uxItemSize == 0 );
}
pxSocket->xEventGroup = safeMalloc( sizeof( struct EventGroupDef_t ) );
/* Call to init the socket list. */
vNetworkSocketsInit();
vSocketWakeUpUser( pxSocket );
}