Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions .github/workflows/release_experimental.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: release latest with all library versions
name: release experimental with all library versions

on:
pull_request:
push:
branches: [ "dev/staging" ]


jobs:
build:
strategy:
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ if(NEWLIB)
)
add_dependencies(dlibc newlib)

# Additional headers / code needed to get libc to linux compatibility
set(LIBC_EXTENSION "c_extension")
add_subdirectory(libc_extension)
add_dependencies(${LIBC_EXTENSION} dlibc)

set(LLVM_C_FLAGS "-D_GNU_SOURCE=1")
string(APPEND LLVM_C_FLAGS " -D_POSIX_TIMERS")
string(APPEND LLVM_C_FLAGS " -D_POSIX_THREADS")
Expand Down Expand Up @@ -208,7 +213,6 @@ if(NEWLIB)
-DLLVM_INCLUDE_TESTS=OFF
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
-DCOMPILER_RT_BUILD_BUILTINS=ON
-DCOMPILER_RT_BAREMETAL_BUILD=ON
-DCOMPILER_RT_BUILD_XRAY=OFF
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
-DCOMPILER_RT_BUILD_MEMPROF=OFF
Expand All @@ -228,7 +232,7 @@ if(NEWLIB)
-DLIBCXX_ENABLE_RANDOM_DEVICE=OFF
-DLIBCXX_HAS_PTHREAD_API=ON
)
add_dependencies(llvmproject newlib)
add_dependencies(llvmproject newlib ${LIBC_EXTENSION})

# Create folder at configuration time to avoid issues with includes
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/include/c++/v1)
Expand Down
44 changes: 30 additions & 14 deletions file_system/file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ D_File *create_directory(Path *name, uint32_t mode) {
new_file->type = DIRECTORY;
new_file->child = NULL;
new_file->hard_links = 0;
// directory where user has full permissions
new_file->mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
new_file->mode = mode | S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
return new_file;
}

Expand All @@ -61,6 +60,13 @@ int link_file_to_folder(D_File *folder, D_File *file) {
// TODO set proper error number
return -1;
};

// Check if file already exists in this directory to prevent duplicates
D_File *existing = find_file_in_dir(folder, (Path){.path = file->name, .length = namelen(file->name, FS_NAME_LENGTH)});
if (existing != NULL) {
return -1;
}

// set file parent to folder
file->parent = folder;
// increase the number of hard links to the file
Expand All @@ -70,18 +76,24 @@ int link_file_to_folder(D_File *folder, D_File *file) {
file->next = NULL;
} else {
D_File *current = folder->child;
if (namecmp(file->name, FS_NAME_LENGTH, current->name, FS_NAME_LENGTH) <
0) {
int cmp_first = namecmp(file->name, FS_NAME_LENGTH, current->name, FS_NAME_LENGTH);
if (cmp_first < 0) {
file->next = current;
folder->child = file;
} else if (cmp_first == 0) {
file->hard_links -= 1;
return -1;
} else {
// Find correct position to insert
while (current->next != NULL) {
if (namecmp(file->name, FS_NAME_LENGTH, current->next->name,
FS_NAME_LENGTH) < 0) {
int cmp_next = namecmp(file->name, FS_NAME_LENGTH, current->next->name, FS_NAME_LENGTH);
if (cmp_next < 0) {
break;
} else {
current = current->next;
} else if (cmp_next == 0) {
file->hard_links -= 1;
return -1;
}
current = current->next;
}
file->next = current->next;
current->next = file;
Expand Down Expand Up @@ -163,11 +175,12 @@ D_File *create_directories(D_File *directory, Path path, char prevent_up) {
directory = candidate_dir;
continue;
}
D_File *new_dir = dandelion_alloc(sizeof(D_File), _Alignof(D_File));
new_dir->type = DIRECTORY;
memcpy(new_dir->name, current_path.path, current_path.length);
new_dir->name[current_path.length] = '\0';
new_dir->child = NULL;
uint32_t dir_mode = S_IRUSR | S_IWUSR | S_IXUSR;
D_File *new_dir = create_directory(&current_path, dir_mode);
if (new_dir == NULL) {
return NULL;
}

int error = link_file_to_folder(directory, new_dir);
if (error < 0) {
dandelion_free(new_dir);
Expand Down Expand Up @@ -416,9 +429,12 @@ int fs_initialize(int *argc, char ***argv, char ***environ) {
fs_root->parent = NULL;
fs_root->child = NULL;
fs_root->hard_links = 1;
// Set proper root directory mode
//fs_root->mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;

// create stdio folder and stdout/stderr file
D_File *stdio_folder = dandelion_alloc(sizeof(D_File), _Alignof(D_File));
Path stdio_path = path_from_string("stdio");
D_File *stdio_folder = create_directory(&stdio_path, S_IRUSR | S_IWUSR | S_IXUSR);
if (stdio_folder == NULL) {
dandelion_exit(ENOMEM);
return -1;
Expand Down
40 changes: 40 additions & 0 deletions libc_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
add_library(${LIBC_EXTENSION} STATIC)

target_sources(${LIBC_EXTENSION}
PRIVATE
dirent.c
netdb.c
socket.c
uio.c
PUBLIC FILE_SET public_headers TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include/
FILES
include/netdb.h
include/sys/cpuset.h
include/sys/dirent.h
include/sys/mman.h
include/sys/sched.h
include/sys/socket.h
include/sys/statvfs.h
include/sys/uio.h
)

if(CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_definitions(${LIBC_EXTENSION} PRIVATE DEBUG)
target_compile_options(${LIBC_EXTENSION} PRIVATE -g)
endif()

target_link_libraries(${LIBC_EXTENSION} PRIVATE dlibc)

include(GNUInstallDirs)
install(TARGETS ${LIBC_EXTENSION}
ARCHIVE FILE_SET public_headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
)

# always install after building, so the headers are available for libcxx
add_custom_command(
TARGET ${LIBC_EXTENSION}
POST_BUILD
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_CURRENT_BINARY_DIR}
)
3 changes: 3 additions & 0 deletions newlib_shim/dirent.c → libc_extension/dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ long int telldir(DIR *dir) {

extern void dandelion_seekdir(DIR *dir, long int index);
void seekdir(DIR *dir, long int index) { return dandelion_seekdir(dir, index); }
int dirfd(DIR *dirp) {
return -1;
}
75 changes: 75 additions & 0 deletions libc_extension/include/netdb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef _NETDB_H
#define _NETDB_H 1

#include <sys/types.h>
#include <inttypes.h>

/* Description of data base entry for a single host. */
struct hostent
{
char *h_name; /* Official name of host. */
char **h_aliases; /* Alias list. */
int h_addrtype; /* Host address type. */
int h_length; /* Length of address. */
char **h_addr_list; /* List of addresses from name server. */
};

/* Description of data base entry for a single network. NOTE: here a
poor assumption is made. The network number is expected to fit
into an unsigned long int variable. */
struct netent
{
char *n_name; /* Official name of network. */
char **n_aliases; /* Alias list. */
int n_addrtype; /* Net address type. */
uint32_t n_net; /* Network number. */
};

/* Description of data base entry for a single service. */
struct protoent
{
char *p_name; /* Official protocol name. */
char **p_aliases; /* Alias list. */
int p_proto; /* Protocol number. */
};

/* Description of data base entry for a single service. */
struct servent
{
char *s_name; /* Official service name. */
char **s_aliases; /* Alias list. */
int s_port; /* Port number. */
char *s_proto; /* Protocol to use. */
};

# define IPPORT_RESERVED 1024

extern int h_errno;

# define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
# define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL. */
# define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP. */
# define NO_DATA 4 /* Valid name, no data record of requested type. */

extern void endhostent (void);
extern void endnetent (void);
extern void endprotoent (void);
extern void endservent (void);
extern struct hostent *gethostbyaddr (const void *__addr, __socklen_t __len, int __type);
extern struct hostent *gethostbyname (const char *__name);
extern struct hostent *gethostent (void);
extern struct netent *getnetbyaddr (uint32_t __net, int __type);
extern struct netent *getnetbyname (const char *__name);
extern struct netent *getnetent (void);
extern struct protoent *getprotobyname (const char *__name);
extern struct protoent *getprotobynumber (int __proto);
extern struct protoent *getprotoent (void);
extern struct servent *getservbyname (const char *__name, const char *__proto);
extern struct servent *getservbyport (int __port, const char *__proto);
extern struct servent *getservent (void);
extern void sethostent (int __stay_open);
extern void setnetent (int __stay_open);
extern void setprotoent (int __stay_open);
extern void setservent (int __stay_open);

#endif // _NETDB_H
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions libc_extension/include/sys/mman.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* sys/mman.h

Copyright 1996, 1997, 1998, 2000, 2001 Red Hat, Inc.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */

#ifndef _SYS_MMAN_H_
#define _SYS_MMAN_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include <stddef.h>
#include <sys/types.h>

#define PROT_NONE 0
#define PROT_READ 1
#define PROT_WRITE 2
#define PROT_EXEC 4

#define MAP_FILE 0
#define MAP_SHARED 1
#define MAP_PRIVATE 2
#define MAP_TYPE 0xF
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
/* Non-standard flag */
#if 0 /* Not yet implemented */
#define MAP_NORESERVE 0x4000 /* Don't reserve swap space for this mapping.
Page protection must be set explicitely
to access page. */
#endif
#define MAP_AUTOGROW 0x8000 /* Grow underlying object to mapping size.
File must be opened for writing. */

#define MAP_FAILED ((void *)-1)

/*
* Flags for msync.
*/
#define MS_ASYNC 1
#define MS_SYNC 2
#define MS_INVALIDATE 4

#ifndef __INSIDE_CYGWIN__
extern void *mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, off_t __off);
#endif
extern int munmap (void *__addr, size_t __len);
extern int mprotect (void *__addr, size_t __len, int __prot);
extern int msync (void *__addr, size_t __len, int __flags);
extern int mlock (const void *__addr, size_t __len);
extern int munlock (const void *__addr, size_t __len);

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* _SYS_MMAN_H_ */
File renamed without changes.
Loading