Skip to content

Commit

Permalink
Merge pull request #819 from no92/iproute2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke authored Apr 5, 2023
2 parents 16ac22f + c246d73 commit 10aae9c
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 21 deletions.
14 changes: 14 additions & 0 deletions options/internal/generic/ubsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,17 @@ void __ubsan_handle_missing_return(UnreachableData *data) {
<< LOG_NAME_LOC("reached end of a value-returning function without returning a value", data->loc)
<< frg::endlog;
}

struct NonNullArgData {
SourceLocation loc;
SourceLocation attr_loc;
int arg_index;
};

extern "C" [[gnu::visibility("hidden")]]
void __ubsan_handle_nonnull_arg(NonNullArgData *data) {
mlibc::panicLogger()
<< LOG_NAME_LOC("null pointer passed to non-null argument", data->loc)
<< "argument " << data->arg_index << " is required to be non-null in "
<< data->attr_loc << frg::endlog;
}
7 changes: 5 additions & 2 deletions options/linux/include/bits/linux/linux_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#ifndef _LINUX_SCHED_H
#define _LINUX_SCHED_H

// Glibc extension
/* Glibc extension */
int sched_getcpu(void);

#if defined(_GNU_SOURCE)
int setns(int fd, int nstype);
#endif /* _GNU_SOURCE */

#endif // _LINUX_SCHED_H
#endif /* _LINUX_SCHED_H */
2 changes: 1 addition & 1 deletion options/linux/include/linux/libc-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define __UAPI_DEF_IF_IFNAMSIZ 1
#define __UAPI_DEF_IF_IFREQ 1
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1

#endif //_NET_IF_H

Expand Down
5 changes: 0 additions & 5 deletions options/posix/generic/arpa-inet-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ int inet_aton(const char *string, struct in_addr *dest) {
// ----------------------------------------------------------------------------
const char *inet_ntop(int af, const void *__restrict src, char *__restrict dst,
socklen_t size) {
if(!dst) {
errno = EINVAL;
return NULL;
}

switch (af) {
case AF_INET: {
auto source = reinterpret_cast<const struct in_addr*>(src);
Expand Down
10 changes: 0 additions & 10 deletions options/posix/generic/posix_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,6 @@ char *strcasestr(const char *s, const char *pattern) {
return nullptr;
}

char *strdupa(const char *) {
__ensure(!"Not implemented");
__builtin_unreachable();
}

char *strndupa(const char *, size_t) {
__ensure(!"Not implemented");
__builtin_unreachable();
}

void *memccpy(void *__restrict, const void *__restrict, int, size_t) {
__ensure(!"Not implemented");
__builtin_unreachable();
Expand Down
2 changes: 1 addition & 1 deletion options/posix/include/arpa/inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int inet_aton(const char *, struct in_addr *);
// Generic IP address manipulation.
// ----------------------------------------------------------------------------
const char *inet_ntop(int, const void *__restrict, char *__restrict,
socklen_t);
socklen_t) __attribute__((nonnull(3)));
int inet_pton(int, const char *__restrict, void *__restrict);

struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
Expand Down
18 changes: 16 additions & 2 deletions options/posix/include/bits/posix/posix_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef MLIBC_POSIX_STRING_H
#define MLIBC_POSIX_STRING_H

#include <alloca.h>
#include <bits/posix/locale_t.h>

#ifdef __cplusplus
Expand All @@ -21,10 +22,23 @@ void *memccpy(void *__restrict dest, const void *__restrict src, int c, size_t n
int strcoll_l(const char *s1, const char *s2, locale_t locale);

// GNU extensions.
#if defined(_GNU_SOURCE)
char *strcasestr(const char *, const char *);
char *strdupa(const char *);
char *strndupa(const char *, size_t);
#define strdupa(x) ({ \
const char *str = (x); \
size_t len = strlen(str) + 1; \
char *buf = alloca(len); \
(char *) memcpy(buf, str, len); \
})
#define strndupa(x, y) ({ \
const char *str = (x); \
size_t len = strnlen(str, (y)) + 1; \
char *buf = alloca(len); \
buf[len - 1] = '\0'; \
(char *) memcpy(buf, str, len - 1); \
})
void *memrchr(const void *, int, size_t);
#endif /* defined(_GNU_SOURCE) */

// BSD extensions
size_t strlcpy(char *d, const char *s, size_t n);
Expand Down
1 change: 1 addition & 0 deletions options/posix/include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <abi-bits/pid_t.h>
#include <bits/size_t.h>
#include <mlibc-config.h>

// MISSING: time_t, struct timespec

Expand Down
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ all_test_cases = [
'posix/if_indextoname',
'posix/readv-writev',
'posix/posix-timer',
'posix/strdupa',
'glibc/getopt',
'glibc/ffsl-ffsll',
'glibc/error_message_count',
Expand Down
3 changes: 3 additions & 0 deletions tests/posix/memrchr.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <string.h>
#include <assert.h>
Expand Down
14 changes: 14 additions & 0 deletions tests/posix/strdupa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <assert.h>
#include <string.h>

int main() {
char test[19] = "Hello mlibc World!";
char *alloca_ed = strdupa(test);
assert(!strcmp(test, alloca_ed));

char *trimmed = strndupa(test, 5);
assert(!strcmp("Hello", trimmed));
}

0 comments on commit 10aae9c

Please sign in to comment.