Commit Graph

664 Commits

Author SHA1 Message Date
Travis Geiselbrecht
6ed6f36fa0 [warnings] remove some redundant declarations
Discovered with -Wredundant-decls
2024-04-19 00:07:49 -07:00
Travis Geiselbrecht
f92aae9dcf [lib][libc] rework a bit of the stdio code to handle errors more closely to spec
Some of the recent refactoring may cause some of the inner error codes
to be eaten or misinterpreted. Restructure fread/fwrite to handle these
a bit more gracefully.

There's some careful use with ssize_t vs size_t here to try to deal with
negatves values properly.
2024-04-18 23:29:17 -07:00
Chieh-Min Wang
b651168fa1 [lib][stdio] wrap file io APIs with stdio APIs
Implement stdio file io APIs with LK lib/fs APIs

Signed-off-by: Chieh-Min Wang <cmwang@google.com>
2024-04-17 23:59:49 -07:00
Travis Geiselbrecht
4a97f932fd [lib][fdtwalk] restructure the fdtwalker helper routines
Instead of one large routine that takes a list of optional callbacks,
build some helper routines that do the work that a few platforms have
implemented on their own to share some code between them.

Future enhancements: move some of the helpers out of this library into
the library that implements the thing it's helping with (ie, PCI
bringup, bootstrapping arch specific cores). For now just leave them in
helper.cc which is conditionally compiled.
2024-04-16 23:11:59 -07:00
Travis Geiselbrecht
05540c992a [lib][fdtwalk] trivially convert to C++ 2024-04-16 23:01:31 -07:00
Mingjie Shen
ed2a3a754d [lib][heap] Fix array index out-of-range
argv[] should have at least 3 elements because argv[2] is accessed in line 345.
2024-03-01 15:22:36 -08:00
Travis Geiselbrecht
8176ae67c8 [libc][cdefs] add a few additional features in cdefs
This seems to only be needed for older gccs (found with 7.5.0).
2024-02-27 00:46:56 -08:00
Travis Geiselbrecht
25ff64d4fd [libc] move sys/cdefs.h out of libm and into the main include path
More code is using it, so try to build a more standardized version of
it. For now, since most of the defines that are needed are similar to
lk/compiler.h, mostly reimplement in terms of those.
2024-02-27 00:12:15 -08:00
Travis Geiselbrecht
74192acef5 [debugcommands][crash] add a variant for cortex-m
Touching around address 0 doesn't cause a cortex-m device to crash, but
branching to an aligned address absolutely will.
2024-02-26 00:58:04 -08:00
Travis Geiselbrecht
23cff5b493 [lib][debug] remove unused function 2024-02-11 00:39:53 -08:00
Travis Geiselbrecht
d9b7d070c9 [top] add header declaration for lk_boot_args
Update users of the boot args array to use the header.
2024-02-11 00:38:09 -08:00
Matt Schulte
6b16ef0da2 [console] Fix complition error when CONSOLE_OUTPUT_TO_PLATFORM_PUTC=0
Need to move `size_t i` into the correct location. Also, set the
CONSOLE_OUTPUT_TO_PLATFORM_PUTC define in the module makefile.

Change-Id: I732ebbcc43219806d5dfd3b9bdd28bf1811248dc
2023-12-16 15:52:24 -08:00
gvk51
6a33334c1e [lib][debugcommands] option to input physical address for debug commands
dw/mw and the sister commands take virtual address as input for display
or modify. Option "-p" to the command signifies the address input is
physical, and the address translation is handled by the command.

Newly added option is available with WITH_KERNEL_VM, usage as follows

] dw 0xffffffff05100000 4
0xffffffff05100000: 0000dead
] dw 0x5100000 4 -p
0xffffffff05100000: 0000dead

Signed-off-by: VAMSHI GAJJELA <vamshigajjela@google.com>
2023-12-04 01:07:26 -08:00
Matt Schulte
1ce428d305 [console] Flag to disable default console output
Introduces a flag which allows a project to disable the default output
to platform_dputc. This is useful is the project wants to maintain
`platform_dputc` for panic conditions but otherwise use a registered
callback for console io.

Change-Id: I1362529a6bb40d191ac3f7c6069985c371d9284c
2023-12-04 00:57:16 -08:00
Cody Wong
94a15119b2 [libc][string] fix strncpy potential buffer overflow
The wrong placement of the increment for index `i` causes an unexpected
behavior, which the `strncpy` writes an extra '\0'.

For example:
The `src` string is "abc". The buffer size of `dest` is 5.

When we call `strncpy(dest, src, 5)`, the first `for` loop copies the
characters, 'a', 'b', and 'c', to the `dest[0:2]`. In the 4th iteration,
however, the `for` loop breaks due to the termination of `src` whereas
the value of `i` stays 3. At the moment, it has copied 4 bytes,
including the '\0' of `src`.

In the second `for` loop, we have `i = 3` and `count = 5`, so the loop
copies two more '\0' to the `dest`. As a result, the `strncpy` copies 6
bytes to the `dest` buffer, leading to buffer overflow.

Fix the issue by increasing the index `i` before every copy.

Signed-off-by: Cody Wong <codycswong@google.com>
2023-11-04 13:16:24 -07:00
Travis Geiselbrecht
6b7d0ab627 [lib][fdtwalk] add code to skip a cpu if disabled
Some RISC-V cpus come up disabled, skip enumerating them.
2023-10-15 14:41:30 -07:00
Alex Richardson
e40ac2a883 [clang] Avoid a nested function in heap_wrapper.c
This GCC extension is not supported by clang and in this case is not
necessary. Move the function to the top level to avoid the syntax error.
2023-06-01 17:50:50 -07:00
Aaron Odell
8fc673fe4a [lib][debugcommands] Add panic command
Add a simple command to generate a test panic.
2023-04-23 17:34:57 -07:00
Aaron Odell
9ba1f165cd [libc][string] Add strcasecmp support
Add strcasecmp() for case insensitive string compares. There is no ISO
standard function for this purpose but strcasecmp() is POSIX standard.
2023-04-23 17:34:54 -07:00
Aaron Odell
9ac5708eb5 [lib][debugcommands] Add commands to display current time
Add debug commands "time" and "timeh" to display current_time() and
current_time_hires() respectively.
2023-04-23 17:34:51 -07:00
Aaron Odell
af844a2ff6 [lib][console] Add an unsigned long long to console_cmd_args
Add and populate an unsigned long long element in the console_cmd_args
struct. This enables handling of 64 bit values on 32 bit targets.
2023-04-23 17:34:49 -07:00
Alex Richardson
7c7612225a [libc] Fix -Wincompatible-library-redeclaration for strerror
Return a char * instead of a const char * to silence this Clang warning.
2023-04-23 17:23:31 -07:00
Pedro Falcato
ca633e2cb2 [ubsan] Improve printing of value in shift_out_of_bounds
Print it according to the type information we're given.
2023-02-18 23:13:23 -08:00
Pedro Falcato
36fd884faa [ubsan] Fix minor copy-paste bugs
Two handlers accidentally had the wrong prototype, called the wrong
thing and/or had the wrong name.

Should only affect divrem_overflow_abort, negate_overflow_abort.
2023-02-18 23:13:23 -08:00
Pedro Falcato
8ebbcea5ed [ubsan] Add UBSAN implementation
Add an UBSAN implementation and a new UBSAN switch to the make build.
The implementation is taken from Onyx and handles most of the cases
that should be needed for a kernel build. Floating point and fancy
C++ CFI features are not supported yet.

To build with UBSAN, pass UBSAN=1 to make such as:
PROJECT=pc-x86-64-test make -jN UBSAN=1
2023-02-18 16:47:16 -08:00
Pedro Falcato
bf2e94c2f8 [minip] Fix undefined behavior in mac_addr_copy
There was a possibly unaligned store in mac_addr_copy.
Replace it with a memcpy call that should generate equivalent,
well defined code.
2023-02-18 16:47:16 -08:00
Travis Geiselbrecht
91d0a5f7d1 [lib][fdtwalk] add routine to find and parse /reserved-memory node
Add logic to the riscv virt platform to properly mark off memory
claimed by OpenSBI.
2022-12-17 17:12:35 -08:00
gvk51
8b1335ea7e [lib][debugcommands] sanity check address is mapped before display/modify
Accessing un-mapped address/address-range results in data abort. Ensure
the address and all the pages in the requested range are mapped. Mapping
is checked at page size, also adjusts the stop address to the nearest valid
address mapped.
2022-11-03 00:04:30 -07:00
Travis Geiselbrecht
0d0568612a [lib][acpi_lite] update to use the VMM to map acpi tables in
The old method assumed that all of the tables were mapped within the
kmap area of the kernel. This basically works on 64bit machines but on a
32bit x86 its entirely likely the ACPI tables are at higher physical
addresses that can be reached, which is currently limited to 1GB.

By using the VM it means it can individually map the headers and each
individual table.
2022-11-02 21:44:15 -07:00
Travis Geiselbrecht
2367686854 [make] add a way for a module to opt into additional warnings
Move -Wmissing-declarations and -Wmissing-prototypes into this bucket.
Opt in most of the core top level modules in the system. More to follow.
2022-10-23 23:16:48 -07:00
Travis Geiselbrecht
4ce2e6a35d [libc] fix a warning squelch for some locally defined routines 2022-10-23 23:03:17 -07:00
Michael Bishop
95ac371146 [lib][gfx] fix undefined flush pointer
all places that call flush, check if its null before calling it
but its never actually written to, so it can sometimes point to garbage and just fault
2022-09-25 18:16:52 -07:00
Michael Bishop
368b5f69b8 [lib][libc] add missing BE64SWAP 2022-09-25 18:16:06 -07:00
Travis Geiselbrecht
baca46e133 [lib][libc] fix an incorrect include path in a libc file 2022-09-25 18:03:59 -07:00
mni
034a8d0ede [libc] add atof() function 2022-09-06 10:26:41 -07:00
Milis Linux
c4676e9445 [tcp] remove extra printf 2022-08-14 18:50:32 -07:00
Travis Geiselbrecht
6462cbf51c [arch][fpu] add ability to specify per file or module if code needs fpu
Have the arch define additional compiler flags to explicit support or
not support a floating point unit.

Add ability for modules to per file or for the whole module mark code
as needing floating point support.

Add default flags for arm64, riscv, and x86 toolchains.

Needed because gcc 12 is getting much more aggressive about using vector
instructions for non float code, so getting away with avoiding it was
no longer working.

Still not perfect: printf code is being compiled with float, so it's
possible to use floating point instructions inside core kernel or
interrupt handling code if a printf is used.

Possibly will have problems on architectures where mixing float and non
float code at the linker generates issues, but so far seems to be okay.
2022-07-17 16:32:24 -07:00
Travis Geiselbrecht
d80592ba7d [lib][acpi_lite] add some additional LTRACEFs
Added to try to track down an issue on a particular PC.
2022-06-05 15:57:45 -07:00
Travis Geiselbrecht
e798c47e89 [lib][debugcommands] add a workaround for gcc 12.1
GCC 12 seems to be much more aggressive about warnings about any
dereferences near 0. For this particular piece of code, which is
explicitly trying to force a fault by touching address 1, simply disable
the warning around the block of code.
2022-05-21 17:29:30 -07:00
Travis Geiselbrecht
469b0b73f6 [lib][elf] add C++ header guards 2022-05-13 01:04:05 -07:00
Travis Geiselbrecht
4a7c0ae925 [fs][fat] fix an incorrect assert 2022-05-13 01:03:15 -07:00
Travis Geiselbrecht
d525a5f7b5 [fs][fat][test] pass in the path to the test dir so files can be included correctly
Due to the way INCBIN works, the full path relative to the root of the
assembler instance must be used, so pass in the full path as a define.
2022-05-12 22:26:22 -07:00
Travis Geiselbrecht
def9bea065 [fs][fat] general fs structural improvements
Move more of the driver into a proper object oriented model.
Start to build the structure to track open file/dirs so as to
allow multiple open instances share the same underlying object.
2022-05-12 20:26:52 -07:00
Travis Geiselbrecht
89f8e62587 [fs][fat][test] add some more test code
Also create a large zero filled file and add it to the test fs, to try
to make sure there's at least one file that crosses a FAT sector.
2022-04-29 22:12:30 -07:00
Travis Geiselbrecht
144f608bce [fs][fat] add support for FAT12
The 12 bit fat parsing code is a little tricky.
2022-04-29 22:10:11 -07:00
Travis Geiselbrecht
40f516c15a [lib][unittest] tweak the command line to let you list and selectively run individual tests 2022-04-29 20:39:05 -07:00
Travis Geiselbrecht
1c9caf9f64 [fs][fat][test] start of unittests for fat file system
Requires a block device be present with a pre-formatted fs, but
should fail gracefully if its not present.
2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
f6f43edc3c [fs][tests] break some fs tests into their own module
Include the test modules if the overal virtual/test module is included.
Also set a new global build system var along with a configuration
variable.
2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
cb5ccee400 [fs][fat] fix a bug in close_dir that forgot to delete dir nodes 2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
c08d540fd6 [lib][fs] add a trace printf when unmounting 2022-04-25 23:17:45 -07:00