Commit Graph

202 Commits

Author SHA1 Message Date
Guillaume Chatelet 436c8f4420 [reland][libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 10:07:04 +00:00
Guillaume Chatelet c5fe7eb216 Revert D138994 "[libc] Add bcopy"
Broke build bot

This reverts commit 186a15f7a9.
2022-12-01 09:55:36 +00:00
Guillaume Chatelet 186a15f7a9 [libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 09:52:10 +00:00
Michael Jones 36991d8342 [libc] add scanf entrypoints
This patch adds scanf, sscanf, and fscanf entrypoints. It also adds unit
tests for sscanf and a basic test to fscanf. The scanf function is
basically impossible to test in an automated fashion due to it recieving
user input.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D138076
2022-11-17 15:37:52 -08:00
Raman Tenneti dbd31935ed [libc] cleanup changes to gettimeofday.
+ Deleted duplicate definitions of StructTimeVal and StructTimeValPtr.
+ Caled syscall  clock_gettime to get timespec data.
+ Added tests to test for sleeping 200 and 1000 microseconds.
+ Fixed comments from https://reviews.llvm.org/D137881

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D138064
2022-11-15 15:06:35 -08:00
Michael Jones 7ffa52dfd1 [libc] re-enable assert
The assert functions were disabled while the signal functions were being
fixed. This patch re-enables them.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D138056
2022-11-15 13:39:34 -08:00
Raman Tenneti 35155ee7d3 Removed tabs. 2022-11-11 18:11:06 -08:00
Raman Tenneti 78f172e45a [libc] Implement gettimeofday
Implement gettimeofday per
.../onlinepubs/9699919799/functions/gettimeofday.html.
This call clock_gettime to implement gettimeofday function.

Tested:
Limited unit test: This makes a call and checks that no error was
returned. Used nanosleep for 100 microseconds and verfified it
returns a value that elapses more than 100 microseconds and less
than 300 microseconds.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

Differential Revision: https://reviews.llvm.org/D137881
2022-11-11 18:02:33 -08:00
Siva Chandra Reddy 6a6101958a [libc] Add implementation of getc, getc_unlocked and fgetc_unlocked.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137507
2022-11-07 21:47:29 +00:00
Siva Chandra Reddy 43e52ad553 [libc] Add implementations of ftell.
Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D137395
2022-11-07 21:38:53 +00:00
Siva Chandra Reddy 4eea884959 [libc] Add implementation of setbuf and setvbuf.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137356
2022-11-04 07:15:13 +00:00
Siva Chandra Reddy 1ceafe5e0f [libc] Add implementation of ungetc.
A bug in the file read logic has also been fixed along the way. Parts
of the ungetc tests will fail without that bug fixed.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137286
2022-11-02 22:45:57 +00:00
Siva Chandra Reddy 15ae08c1a1 [libc] Add definitions of a few missing macros and types. 2022-11-02 07:17:33 +00:00
Siva Chandra Reddy 3b82b4fbd5 [libc] Add x86_64 implementation of setjmp and longjmp.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137147
2022-11-01 22:58:35 +00:00
Tue Ly 45233cc1ca [libc][math] Add place-holder implementation for pow function.
Add place-holder implementation for pow function to unblock libc demo
examples.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137109
2022-10-31 17:23:33 -04:00
Tue Ly 97b4cc83e1 [libc][math] Add place-holder implementation for asin to unblock demo examples.
Add a place-holder implementation for asin to unblock libc demo
examples.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137105
2022-10-31 17:22:12 -04:00
Alex Brachet 5fd03c8176 [libc] Implement getopt
Differential Revision: https://reviews.llvm.org/D133487
2022-10-31 16:55:53 +00:00
Michael Jones 2d52283391 [libc] add fgets
This adds the fgets function and its unit tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136785
2022-10-27 10:27:24 -07:00
Alex Brachet d6ac84bce8 Revert "[libc] Implement getopt"
This reverts commit a678f86351.
2022-10-27 06:47:24 +00:00
Alex Brachet a678f86351 [libc] Implement getopt
Differential Revision: https://reviews.llvm.org/D133487
2022-10-27 06:23:33 +00:00
Siva Chandra Reddy 22ea0e5d9b [libc] Add Linux implementations of time and clock functions.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136666
2022-10-25 18:06:05 +00:00
Siva Chandra Reddy 6faf40bb75 [libc] Add the header sys/types.h.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136642
2022-10-25 00:24:49 +00:00
Raman Tenneti cec276ac91 [libc] Build fix.
Build fix.

Reviewed By: rtenneti

Differential Revision: https://reviews.llvm.org/D136647
2022-10-24 16:18:52 -07:00
Siva Chandra Reddy 0480b45e9e [libc] Add implementation of fgetc.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136421
2022-10-22 03:34:44 +00:00
Siva Chandra Reddy 2a038f9138 [libc] Add stdin definition.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136398
2022-10-22 03:27:31 +00:00
Siva Chandra Reddy be4e425758 [libc] Add select.h and the implementation of the select function for Linux.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136375
2022-10-22 03:17:48 +00:00
Siva Chandra Reddy 9ec0ad75f5 [libc][Obvious] Fix incomplete spec definition of sys/random.h. 2022-10-20 06:57:00 +00:00
Siva Chandra Reddy 67957368ae [libc] Add implementation of sigaltstack for linux.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135949
2022-10-18 22:04:30 +00:00
Siva Chandra Reddy b2a294bcf8 [libc] Add termios.h and the implementation of functions declared in it.
Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D136143
2022-10-18 20:53:00 +00:00
Michael Jones 40b494396b [libc] add putc, fputc, and putchar
These three functions are simple, but needed for libc build testing.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D135990
2022-10-17 16:29:04 -07:00
Siva Chandra Reddy 8b0e84a6f6 [libc] Add implementation of the POSIX getcwd function.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135905
2022-10-14 16:20:59 +00:00
Siva Chandra Reddy 02a543db66 [libc] Add a simple implementation of the posix_spawn function.
The implementation currently ignores all spawn attributes. Support for
them will be added in future changes.

A simple allocator for integration tests has been added so that the
integration test for posix_spawn can use the
posix_spawn_file_actions_add* functions.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135752
2022-10-13 18:47:47 +00:00
Michael Jones 35a4fe4c0b [libc] add headers sys/auxv sys/prctl and sys/time
These headers are uncommonly used, and from extensions, but some basic
support is needed. Macros have been added where available.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135731
2022-10-12 13:19:50 -07:00
Siva Chandra Reddy 28943d617a [libc] Add POSIX functions posix_spawn_file_actions_*.
Namely, posix_spawn_file_actions_addclose,
posix_spawn_file_actions_adddup2, posix_spawn_file_actions_addopen,
posix_spawn_file_actions_destroy, posix_spawn_file_actions_init have
been added.

Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D135603
2022-10-11 04:54:44 +00:00
Michael Jones 7639ba6906 [libc] add isatty
The isatty function uses the side effects of an ioctl call to determine
if a specific file descriptor is a terminal. I chose TIOCGETD (get line
discipline of terminal) because it didn't require any new structs.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D135618
2022-10-10 15:20:46 -07:00
Michael Jones 1ac525b28b [libc] add sysconf with pagesize
The sysconf function has many options, this patch adds the basic funtion
and the pagesize option. More options will be added in future patches.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135409
2022-10-10 14:51:45 -07:00
Siva Chandra Reddy 438e59182b [libc] Add implementation of pthread_atfork.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135432
2022-10-10 18:28:43 +00:00
Schrodinger ZHU Yifan 9eb11856cf Implement `getrandom` function for linux targets.
Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D134665
2022-10-10 11:00:35 -07:00
Michael Jones 07793f95c4 [libc] add strsignal and refactor message mapping
The logic for strsignal and strerror is very similar, so I've moved them
both to use a shared utility (MessageMapper) for the basic
functionality.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135322
2022-10-07 11:11:53 -07:00
Michael Jones a9f95b769e [libc] add strerror_r function
I've implemente the gnu variant of strerror_r since that seems to be the
one more relevant to what we're trying to do.

Differential Revision: https://reviews.llvm.org/D135227
2022-10-07 11:07:06 -07:00
Michael Jones 9015810648 [libc] add kill
Add the kill syscall wrapper and tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135406
2022-10-06 15:25:56 -07:00
Siva Chandra Reddy 3f965818b6 [libc] Add POSIX execv and execve functions.
The POSIX global variable environ has also been added.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135351
2022-10-06 19:50:23 +00:00
Siva Chandra Reddy 3e1986682f [libc][Obvious] Add "__" prefix to sched_getcpucount in the spec and elsewhere.
Without this fix, the declaration in sched.h will not have the "__" prefix and
will cause a compile failure.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D135286
2022-10-05 18:01:13 +00:00
Siva Chandra Reddy 995105de1b [libc] Add the POSIX waitpid function and the BSD wait4 function.
Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D135225
2022-10-05 07:38:55 +00:00
Michael Jones 0b790afb06 [libc] add CPU_COUNT macro and backing function
Add the macro CPU_COUNT as well as a backing function to implement the
functionality.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135179
2022-10-04 15:22:55 -07:00
Michael Jones 38b6f58e33 [libc] implement basic rand and srand
This provides the reference implementation of rand and srand. In future
this will likely be upgraded to something that supports full ints.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135187
2022-10-04 13:31:26 -07:00
Siva Chandra Reddy e3638e83db [libc] Add a minimal implementation of the POSIX fork function.
A very simple and minimal implementation of fork is added. Future
changes will add more functionality to satisfy POSIX and Linux
requirements.

An implementation of wait and a few support macros in sys/wait.h
have also been added to help with testing the fork function.

Reviewed By: lntue, michaelrj

Differential Revision: https://reviews.llvm.org/D135131
2022-10-04 19:12:08 +00:00
Michael Jones 1801c356f6 [libc] add syscall function
Add the syscall wrapper function and tests. It's implemented using a
macro to guarantee the minimum number of arguments.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D134919
2022-09-30 15:46:28 -07:00
Siva Chandra Reddy 215c9fa4de [libc] Re-enable functions from signal.h and re-enable abort.
They were disabled because we were including linux/signal.h from our
signal.h. Linux's signal.h is not designed to be included from user
programs as it causes a lot of non-standard name pollution. Also, it is
not self-contained. This change defines types and macros relevant for
signal related syscalls within libc's headers and removes inclusion of
Linux headers.

This patch enables the funtions only for x86_64. They will be enabled
for aarch64 also in a follow up patch after testing.

Reviewed By: abrachet, lntue

Differential Revision: https://reviews.llvm.org/D134567
2022-09-30 07:31:50 +00:00
Siva Chandra Reddy 545b954251 [libc] Add GNU extension functions sched_getaffinity and sched_setaffinity.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D134858
2022-09-29 20:31:46 +00:00