Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let 32bit machines with limited memory size to use ubsan friendly #412

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/tests/v9fs_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int v9fs_tests(int argc, const console_cmd_args *argv) {

readbytes = fs_read_file(handle, buf, 0, BUF_SIZE);
if (readbytes < 0) {
LOGF("failed to read the target file: %ld\n", readbytes);
LOGF("failed to read the target file: %zd\n", readbytes);
return status;
}

Expand Down
3 changes: 1 addition & 2 deletions arch/arm/arm/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static int cmd_dcc(int argc, const console_cmd_args *argv) {
uint32_t buf[128];

ssize_t len = arm_dcc_read(buf, sizeof(buf), 1000);
printf("arm_dcc_read returns %ld\n", len);
printf("arm_dcc_read returns %zd\n", len);
if (len > 0) {
hexdump(buf, len);
}
Expand All @@ -181,4 +181,3 @@ STATIC_COMMAND_START
STATIC_COMMAND("dcc", "dcc stuff", &cmd_dcc)
#endif
STATIC_COMMAND_END(dcc);

2 changes: 2 additions & 0 deletions external/arch/arm/arm-m/CMSIS/Include/cmsis_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/* LK: include lk's compiler.h first, which has some of the same #defines */
#include <lk/compiler.h>
__BEGIN_CDECLS

/* ignore some GCC warnings */
#pragma GCC diagnostic push
Expand Down Expand Up @@ -2211,4 +2212,5 @@ __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)

#pragma GCC diagnostic pop

__END_CDECLS
#endif /* __CMSIS_GCC_H */
14 changes: 7 additions & 7 deletions lib/bio/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static int cmd_bio(int argc, const console_cmd_args *argv) {
ssize_t err_len = bio_read(dev, buf, offset, amt);

if (err_len < 0) {
dprintf(ALWAYS, "read error %s %zu@%zu (err_len %ld)\n",
dprintf(ALWAYS, "read error %s %zu@%zu (err_len %zd)\n",
argv[2].str, amt, (size_t)offset, err_len);
break;
}
Expand Down Expand Up @@ -413,7 +413,7 @@ static status_t memory_mapped_test(bdev_t *device) {
// Erase the first page of the Device.
ssize_t err = bio_erase(device, 0, device->block_size);
if (err < (ssize_t)device->block_size) {
printf("Expected to erase at least %zu bytes but only erased %ld. "
printf("Expected to erase at least %zu bytes but only erased %zd. "
"Not continuing to test memory mapped mode.\n",
device->block_size, err);
retcode = ERR_IO;
Expand All @@ -430,7 +430,7 @@ static status_t memory_mapped_test(bdev_t *device) {
err = bio_write_block(device, test_buffer, 0, 1);
if (err != (ssize_t)device->block_size) {
printf("Error while writing test pattern to device. Expected to write "
"%zu bytes but actually wrote %ld. Not continuing to test memory "
"%zu bytes but actually wrote %zd. Not continuing to test memory "
"mapped mode.\n", device->block_size, err);
retcode = ERR_IO;
goto finish;
Expand Down Expand Up @@ -474,7 +474,7 @@ static status_t memory_mapped_test(bdev_t *device) {
// what we wrote back earlier.
err = bio_read_block(device, reference_buffer, 0, 1);
if (err != (ssize_t)device->block_size) {
printf("Expected to read %zu bytes, actually read %ld. Aborting.\n",
printf("Expected to read %zu bytes, actually read %zd. Aborting.\n",
device->block_size, err);
retcode = ERR_IO;
goto finish;
Expand All @@ -501,18 +501,18 @@ static status_t memory_mapped_test(bdev_t *device) {
static int bio_test_device(bdev_t *device) {
ssize_t num_errors = erase_test(device);
if (num_errors < 0) {
printf("error %ld performing erase test\n", num_errors);
printf("error %zd performing erase test\n", num_errors);
return -1;
}
printf("discovered %ld error(s) while testing erase.\n", num_errors);
printf("discovered %zd error(s) while testing erase.\n", num_errors);
if (num_errors) {
// No point in continuing the tests if we couldn't erase the device.
printf("not continuing to test writes.\n");
return -1;
}

num_errors = write_test(device);
printf("Discovered %ld error(s) while testing write.\n", num_errors);
printf("Discovered %zd error(s) while testing write.\n", num_errors);
if (num_errors) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fs/9p/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ status_t v9fs_read_dir(dircookie *dcookie, struct dirent *ent)
}

LTRACEF(
"head (%u) tail (%u) sread (%ld) offset (%llu) name "
"head (%u) tail (%u) sread (%zd) offset (%llu) name "
"(%s)\n",
dir->head, dir->tail, sread, p9_dent.offset, p9_dent.name);

Expand Down
4 changes: 2 additions & 2 deletions lib/fs/spifs/test/spifstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ static int spifs_bench(int argc, const console_cmd_args *argv) {

if (n_bytes < 0) {
printf("SPIFS Benchmark Failed to write to file at %s. "
"Reason = %ld.\n", test_file_path, n_bytes);
"Reason = %zd.\n", test_file_path, n_bytes);
retcode = -1;
fs_close_file(handle);
goto finish;
Expand All @@ -752,7 +752,7 @@ static int spifs_bench(int argc, const console_cmd_args *argv) {

if (n_bytes < 0) {
printf("SPIFS Benchmark Failed to read from file at %s. "
"Reason = %ld.\n", test_file_path, n_bytes);
"Reason = %zd.\n", test_file_path, n_bytes);
retcode = -1;
fs_close_file(handle);
goto finish;
Expand Down
4 changes: 4 additions & 0 deletions lib/libc/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ enum handler_return {
INT_RESCHEDULE,
};

#ifdef __LP64__
typedef signed long int ssize_t;
#else
typedef signed int ssize_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this isn't really always true, it varies by architecture. For LK I've bee forcing size_t to be a long always, even if it's against the default the compiler sets it to, and it works reasonably well as long as the code is mostly using stuff built in tree.

Is there a strong need for this? If so we may be able to set it for particular architectures that its an issue with (such as linux-x86, where i know size_t is unsigned int).

#endif

typedef uint8_t u8;
typedef uint16_t u16;
Expand Down
5 changes: 2 additions & 3 deletions lib/minip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,15 +1330,15 @@ static int cmd_tcp(int argc, const console_cmd_args *argv) {
uint8_t buf[512];

ssize_t err_len = tcp_read(accepted, buf, sizeof(buf));
printf("tcp_read returns %ld\n", err_len);
printf("tcp_read returns %zd\n", err_len);
if (err_len < 0)
break;
if (err_len > 0) {
hexdump8(buf, err_len);
}

err_len = tcp_write(accepted, buf, err_len);
printf("tcp_write returns %ld\n", err_len);
printf("tcp_write returns %zd\n", err_len);
if (err_len < 0)
break;
}
Expand All @@ -1362,4 +1362,3 @@ static int cmd_tcp(int argc, const console_cmd_args *argv) {
STATIC_COMMAND_START
STATIC_COMMAND("tcp", "tcp commands", &cmd_tcp)
STATIC_COMMAND_END(tcp);

2 changes: 1 addition & 1 deletion lib/minip/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ status_t udp_send_iovec(const iovec_t *iov, uint iov_count, udp_socket_t *handle
udp->chksum = rfc768_chksum(ip, udp);
#endif

LTRACEF("packet paylod len %ld\n", len);
LTRACEF("packet paylod len %zd\n", len);

minip_tx_handler(minip_tx_arg, p);

Expand Down
14 changes: 14 additions & 0 deletions lib/test_ubsan/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LOCAL_DIR := $(GET_LOCAL_DIR)

MODULE := $(LOCAL_DIR)

MODULE_SRCS += \
$(LOCAL_DIR)/test_ubsan.c \
$(LOCAL_DIR)/test_ubsan.cpp

MODULE_DEPS += \
lib/ubsan

MODULE_COMPILEFLAGS += -fsanitize=undefined

include make/module.mk
Loading