Implement more security stuff

- Support deterministic stacks on OpenBSD
- Support OpenBSD system call origin verification
- Fix overrun by one in chibicc string token allocator
- Get all chibicc tests passing under Address Sanitizer
This commit is contained in:
Justine Tunney 2021-02-02 20:21:06 -08:00
parent cbfd4ccd1e
commit c843243322
56 changed files with 376 additions and 245 deletions

View file

@ -42,7 +42,6 @@
* @errors ENOENT, ENOTDIR, ENOSYS
* @asyncsignalsafe
* @see fchmod()
* @syscall
*/
int chmod(const char *pathname, uint32_t mode) {
if (!pathname) return efault();

View file

@ -50,7 +50,6 @@
* errno isn't restored to its original value, to detect prec. loss
* @see strftime(), gettimeofday()
* @asyncsignalsafe
* @syscall
*/
int clock_gettime(int clockid, struct timespec *out_ts) {
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */

View file

@ -29,7 +29,6 @@
* @param len 0 means til end of file
* @param advice can be MADV_SEQUENTIAL, MADV_RANDOM, etc.
* @return -1 on error
* @syscall
*/
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
if (!IsWindows()) {

View file

@ -38,7 +38,6 @@
* @return 0 on success, or -1 w/ errno
* @note limited availability on rhel5 and openbsd
* @see ftruncate()
* @syscall
*/
int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
int rc;

View file

@ -40,7 +40,6 @@
* @errors ENOSYS
* @asyncsignalsafe
* @see chmod()
* @syscall
*/
int fchmod(int fd, uint32_t mode) {
/* TODO(jart): Windows */

View file

@ -28,7 +28,6 @@
* @return 0 on success, or -1 w/ errno
* @see /etc/passwd for user ids
* @see /etc/group for group ids
* @syscall
*/
int fchown(int fd, uint32_t uid, uint32_t gid) {
/* TODO(jart): Windows? */

View file

@ -29,7 +29,6 @@
* @param arg can be FD_CLOEXEC, etc. depending
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
* @syscall
*/
int fcntl(int fd, int cmd, ...) {
va_list va;

View file

@ -26,7 +26,6 @@
* @return 0 on success, or -1 w/ errno
* @see fsync(), sync_file_range()
* @asyncsignalsafe
* @syscall
*/
int fdatasync(int fd) {
if (!IsWindows()) {

View file

@ -18,6 +18,7 @@
*/
#include "libc/dce.h"
#include "libc/macros.h"
.text.syscall
/ Forks process without copying page tables.
/

View file

@ -34,7 +34,7 @@ extern __msabi typeof(VirtualProtect) *const __imp_VirtualProtect;
* @return 0 on success, or -1 w/ errno
* @see mmap()
*/
int mprotect(void *addr, uint64_t len, int prot) {
textsyscall int mprotect(void *addr, uint64_t len, int prot) {
bool cf;
int64_t rc;
uint32_t oldprot;