Skip to content

Commit

Permalink
fix fuzzing build
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Oct 11, 2024
1 parent d997f00 commit f3b7d75
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 68 deletions.
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ repos:
types_or: [c, header]
language: system

- id: build-fuzzer
name: build-fuzzer
files: ^(src/|test/fuzz/)
language: system
types_or: [c, header]
entry: |
export CC=clang
export CXX=clang++
fuzz_harness=$(ls -d test/fuzz/device/*/)
for h in $fuzz_harness
do
make -C $h get-deps
make -C $h all
done
# - id: build-fuzzer
# name: build-fuzzer
# files: ^(src/|test/fuzz/)
# language: system
# types_or: [c, header]
# entry: |
# bash -c 'export CC=clang
# export CXX=clang++
# fuzz_harness=$(ls -d test/fuzz/device/*/)
# for h in $fuzz_harness
# do
# make -C $h get-deps
# make -C $h all
# done'
23 changes: 15 additions & 8 deletions src/device/dcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,45 @@ extern void dcd_event_handler(dcd_event_t const * event, bool in_isr);

// helper to send bus signal event
TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) {
dcd_event_t event = { .rhport = rhport, .event_id = eid };
dcd_event_t event;
event.rhport = rhport;
event.event_id = eid;
dcd_event_handler(&event, in_isr);
}

// helper to send bus reset event
TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_reset (uint8_t rhport, tusb_speed_t speed, bool in_isr) {
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_BUS_RESET };
dcd_event_t event;
event.rhport = rhport;
event.event_id = DCD_EVENT_BUS_RESET;
event.bus_reset.speed = speed;
dcd_event_handler(&event, in_isr);
}

// helper to send setup received
TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr) {
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED };
dcd_event_t event;
event.rhport = rhport;
event.event_id = DCD_EVENT_SETUP_RECEIVED;
memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t));

dcd_event_handler(&event, in_isr);
}

// helper to send transfer complete event
TU_ATTR_ALWAYS_INLINE static inline void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr) {
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_XFER_COMPLETE };

dcd_event_t event;
event.rhport = rhport;
event.event_id = DCD_EVENT_XFER_COMPLETE;
event.xfer_complete.ep_addr = ep_addr;
event.xfer_complete.len = xferred_bytes;
event.xfer_complete.result = result;

dcd_event_handler(&event, in_isr);
}

TU_ATTR_ALWAYS_INLINE static inline void dcd_event_sof(uint8_t rhport, uint32_t frame_count, bool in_isr) {
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SOF };
dcd_event_t event;
event.rhport = rhport;
event.event_id = DCD_EVENT_SOF;
event.sof.frame_count = frame_count;
dcd_event_handler(&event, in_isr);
}
Expand Down
5 changes: 2 additions & 3 deletions src/portable/microchip/samd/dcd_samd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ static void bus_reset(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init (uint8_t rhport)
{
(void) rhport;
void dcd_init(const tusb_rhport_init_t* rh_init) {
(void) rh_init;

// Reset to get in a clean state.
USB->DEVICE.CTRLA.bit.SWRST = true;
Expand Down
4 changes: 2 additions & 2 deletions src/portable/microchip/samg/dcd_samg.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ static void bus_reset(void)
}

// Initialize controller to device mode
void dcd_init (uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
dcd_connect(rhport);
}
Expand Down
4 changes: 2 additions & 2 deletions src/portable/microchip/samx7x/dcd_samx7x.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, in
//------------------------------------------------------------------

// Initialize controller to device mode
void dcd_init (uint8_t rhport)
{
void dcd_init(const tusb_rhport_init_t* rh_init) {
const uint8_t rhport = rh_init->rhport;
dcd_connect(rhport);
}

Expand Down
6 changes: 2 additions & 4 deletions src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ static usb_descriptor_buffers_t desc;
*------------------------------------------------------------------*/

// Initialize controller to device mode
void dcd_init (uint8_t rhport)
{
(void) rhport;

void dcd_init(const tusb_rhport_init_t* rh_init) {
(void) rh_init;
static pio_usb_configuration_t config = PIO_USB_DEFAULT_CONFIG;
usb_device = pio_usb_device_init(&config, &desc);
}
Expand Down
48 changes: 15 additions & 33 deletions src/portable/template/dcd_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,63 +40,52 @@
*------------------------------------------------------------------*/

// Initialize controller to device mode
void dcd_init (uint8_t rhport)
{
(void) rhport;
void dcd_init(const tusb_rhport_init_t* rh_init) {
(void) rh_init;
}

// Enable device interrupt
void dcd_int_enable (uint8_t rhport)
{
void dcd_int_enable (uint8_t rhport) {
(void) rhport;
}

// Disable device interrupt
void dcd_int_disable (uint8_t rhport)
{
void dcd_int_disable (uint8_t rhport) {
(void) rhport;
}

// Receive Set Address request, mcu port must also include status IN response
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
{
void dcd_set_address (uint8_t rhport, uint8_t dev_addr) {
(void) rhport;
(void) dev_addr;
}

// Wake up host
void dcd_remote_wakeup (uint8_t rhport)
{
void dcd_remote_wakeup (uint8_t rhport) {
(void) rhport;
}

// Connect by enabling internal pull-up resistor on D+/D-
void dcd_connect(uint8_t rhport)
{
void dcd_connect(uint8_t rhport) {
(void) rhport;
}

// Disconnect by disabling internal pull-up resistor on D+/D-
void dcd_disconnect(uint8_t rhport)
{
void dcd_disconnect(uint8_t rhport) {
(void) rhport;
}

void dcd_sof_enable(uint8_t rhport, bool en)
{
void dcd_sof_enable(uint8_t rhport, bool en) {
(void) rhport;
(void) en;

// TODO implement later
}

//--------------------------------------------------------------------+
// Endpoint API
//--------------------------------------------------------------------+

// Configure endpoint's registers according to descriptor
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
{
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc) {
(void) rhport;
(void) ep_desc;
return false;
Expand All @@ -118,14 +107,12 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep)
return false;
}

void dcd_edpt_close_all (uint8_t rhport)
{
void dcd_edpt_close_all (uint8_t rhport) {
(void) rhport;
}

// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
{
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) {
(void) rhport;
(void) ep_addr;
(void) buffer;
Expand All @@ -134,8 +121,7 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
}

// Submit a transfer where is managed by FIFO, When complete dcd_event_xfer_complete() is invoked to notify the stack - optional, however, must be listed in usbd.c
bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
{
bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes) {
(void) rhport;
(void) ep_addr;
(void) ff;
Expand All @@ -144,19 +130,15 @@ bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16
}

// Stall endpoint
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
{
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) {
(void) rhport;
(void) ep_addr;
}

// clear stall, data toggle is also reset to DATA0
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
{
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) {
(void) rhport;
(void) ep_addr;
}



#endif
4 changes: 2 additions & 2 deletions test/fuzz/dcd_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ tu_static State state = {false, 0, 0};
// All no-ops as we are fuzzing.
//--------------------------------------------------------------------+
extern "C" {
void dcd_init(uint8_t rhport) {
UNUSED(rhport);
void dcd_init(const tusb_rhport_init_t* rh_init) {
UNUSED(rh_init);
return;
}

Expand Down

0 comments on commit f3b7d75

Please sign in to comment.