Skip to content

Commit 5b0fcbb

Browse files
authored
Merge pull request #113 from Galfurian/develop
Add Error Checks to PCI Functions and Reorganize libc Structure
2 parents 3ed113d + 98f2c48 commit 5b0fcbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1852
-988
lines changed

doc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ if (DOXYGEN_FOUND)
141141
${CMAKE_SOURCE_DIR}/libc/inc/sys/wait.h
142142
${CMAKE_SOURCE_DIR}/libc/inc/sys/list_head.h
143143
${CMAKE_SOURCE_DIR}/libc/inc/sys/kernel_levels.h
144-
${CMAKE_SOURCE_DIR}/libc/inc/sys/dirent.h
145144
${CMAKE_SOURCE_DIR}/libc/inc/sys/ioctl.h
146145
${CMAKE_SOURCE_DIR}/libc/inc/sys/mman.h
147146
${CMAKE_SOURCE_DIR}/libc/inc/sys/utsname.h
148-
${CMAKE_SOURCE_DIR}/libc/inc/sys/unistd.h
149147
${CMAKE_SOURCE_DIR}/libc/inc/sys/stat.h
150148
${CMAKE_SOURCE_DIR}/libc/inc/sys/list_head_algorithm.h
151149
${CMAKE_SOURCE_DIR}/libc/inc/grp.h
150+
${CMAKE_SOURCE_DIR}/libc/inc/unistd.h
151+
${CMAKE_SOURCE_DIR}/libc/inc/dirent.h
152152
${CMAKE_SOURCE_DIR}/libc/inc/io/ansi_colors.h
153153
${CMAKE_SOURCE_DIR}/libc/inc/io/mm_io.h
154154
${CMAKE_SOURCE_DIR}/libc/inc/io/debug.h

doc/syscall.md

Lines changed: 372 additions & 196 deletions
Large diffs are not rendered by default.

libc/inc/sys/dirent.h renamed to libc/inc/dirent.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ typedef struct dirent_t {
4848
unsigned short d_type; ///< type of the directory entry.
4949
char d_name[NAME_MAX]; ///< Filename (null-terminated)
5050
} dirent_t;
51+
52+
/// Provide access to the directory entries.
53+
/// @param fd The fd pointing to the opened directory.
54+
/// @param dirp The buffer where de data should be placed.
55+
/// @param count The size of the buffer.
56+
/// @return On success, the number of bytes read is returned. On end of
57+
/// directory, 0 is returned. On error, -1 is returned, and errno is set
58+
/// appropriately.
59+
ssize_t getdents(int fd, dirent_t *dirp, unsigned int count);

libc/inc/stdlib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ unsigned randuint(unsigned lb, unsigned ub);
9797
/// @param ub the upper-bound value.
9898
/// @return the random value.
9999
float randfloat(float lb, float ub);
100+
101+
/// @brief Wrapper for exit system call.
102+
/// @param status The exit status.
103+
void exit(int status);

libc/inc/sys/reboot.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@
3333
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
3434
/// Restart system using a previously loaded Linux kernel
3535
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
36+
37+
/// @brief Reboots the system, or enables/disables the reboot keystroke.
38+
/// @param magic1 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1.
39+
/// @param magic2 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2.
40+
/// @param cmd The command to send to the reboot.
41+
/// @param arg Argument passed with some specific commands.
42+
/// @return For the values of cmd that stop or restart the system, a
43+
/// successful call to reboot() does not return. For the other cmd
44+
/// values, zero is returned on success. In all cases, -1 is
45+
/// returned on failure, and errno is set appropriately.
46+
int reboot(int magic1, int magic2, unsigned int cmd, void *arg);

libc/inc/system/syscall_types.h

Lines changed: 222 additions & 41 deletions
Large diffs are not rendered by default.

libc/inc/time.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ typedef struct timespec {
6666
/// @return The current time.
6767
time_t time(time_t *t);
6868

69+
/// @brief Converts the given time to a string representing the local time.
70+
/// @details Converts the value pointed to by timer, representing the time in
71+
/// seconds since the Unix epoch (1970-01-01 00:00:00 UTC), to a string in the
72+
/// format: Www Mmm dd hh:mm:ss yyyy.
73+
/// @param timer A pointer to a time_t object representing the time to be
74+
/// converted.
75+
/// @return A pointer to a statically allocated string containing the formatted
76+
/// date and time. The string is overwritten with each call to ctime().
77+
char *ctime(const time_t *timer);
78+
6979
/// @brief Return the difference between the two time values.
7080
/// @param time1 The first time value.
7181
/// @param time2 The second time value.

libc/inc/sys/unistd.h renamed to libc/inc/unistd.h

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "sys/types.h"
99
#include "stddef.h"
10-
#include "sys/dirent.h"
10+
#include "dirent.h"
1111

1212
#define STDIN_FILENO 0 ///< Standard input file descriptor.
1313
#define STDOUT_FILENO 1 ///< Standard output file descriptor.
@@ -71,21 +71,17 @@ int symlink(const char *linkname, const char *path);
7171
/// @return The number of read characters on success, -1 otherwise and errno is set to indicate the error.
7272
int readlink(const char *path, char *buffer, size_t bufsize);
7373

74-
/// @brief Wrapper for exit system call.
75-
/// @param status The exit status.
76-
extern void exit(int status);
77-
7874
/// @brief Returns the process ID (PID) of the calling process.
7975
/// @return pid_t process identifier.
80-
extern pid_t getpid(void);
76+
pid_t getpid(void);
8177

8278
///@brief Return session id of the given process.
8379
/// If pid == 0 return the SID of the calling process
8480
/// If pid != 0 return the SID corresponding to the process having identifier == pid
8581
///@param pid process identifier from wich we want the SID
8682
///@return On success return SID of the session
8783
/// Otherwise return -1 with errno set on: EPERM or ESRCH
88-
extern pid_t getsid(pid_t pid);
84+
pid_t getsid(pid_t pid);
8985

9086
///@brief creates a new session if the calling process is not a
9187
/// process group leader. The calling process is the leader of the
@@ -95,7 +91,7 @@ extern pid_t getsid(pid_t pid);
9591
/// is made the same as its process ID).
9692
///@return On success return SID of the session just created
9793
/// Otherwise return -1 with errno : EPERM
98-
extern pid_t setsid(void);
94+
pid_t setsid(void);
9995

10096
///@brief returns the Process Group ID (PGID) of the process specified by pid.
10197
/// If pid is zero, the process ID of the calling process is used.
@@ -112,56 +108,56 @@ int setpgid(pid_t pid, pid_t pgid);
112108

113109
///@brief returns the real group ID of the calling process.
114110
///@return GID of the current process
115-
extern gid_t getgid(void);
111+
gid_t getgid(void);
116112

117113
///@brief returns the effective group ID of the calling process.
118114
///@return GID of the current process
119-
extern gid_t getegid(void);
115+
gid_t getegid(void);
120116

121117
///@brief sets the group IDs of the calling process.
122118
///@param gid the Group ID to set
123119
///@return On success, zero is returned.
124120
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
125-
extern int setgid(gid_t gid);
121+
int setgid(gid_t gid);
126122

127123
///@brief sets the real and effective group IDs of the calling process.
128124
///@param rgid the new real Group ID.
129125
///@param egid the effective real Group ID.
130126
///@return On success, zero is returned.
131127
/// Otherwise returns -1 with errno set EPERM
132-
extern int setregid(gid_t rgid, gid_t egid);
128+
int setregid(gid_t rgid, gid_t egid);
133129

134130
///@brief Returns the real User ID of the calling process.
135131
///@return User ID of the current process.
136-
extern uid_t getuid(void);
132+
uid_t getuid(void);
137133

138134
///@brief Returns the effective User ID of the calling process.
139135
///@return User ID of the current process.
140-
extern uid_t geteuid(void);
136+
uid_t geteuid(void);
141137

142138
///@brief Sets the User IDs of the calling process.
143139
///@param uid the new User ID.
144140
///@return On success, zero is returned.
145141
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
146-
extern int setuid(uid_t uid);
142+
int setuid(uid_t uid);
147143

148144
///@brief Sets the effective and real User IDs of the calling process.
149145
///@param ruid the new real User ID.
150146
///@param euid the effective real User ID.
151147
///@return On success, zero is returned.
152148
/// Otherwise returns -1 with errno set to EPERM
153-
extern int setreuid(uid_t ruid, uid_t euid);
149+
int setreuid(uid_t ruid, uid_t euid);
154150

155151
/// @brief Returns the parent process ID (PPID) of the calling process.
156152
/// @return pid_t parent process identifier.
157-
extern pid_t getppid(void);
153+
pid_t getppid(void);
158154

159155
/// @brief Clone the calling process, but without copying the whole address space.
160156
/// The calling process is suspended until the new process exits or is
161157
/// replaced by a call to `execve'.
162158
/// @return Return -1 for errors, 0 to the new process, and the process ID of
163159
/// the new process to the old process.
164-
extern pid_t fork(void);
160+
pid_t fork(void);
165161

166162
/// @brief Replaces the current process image with a new process image (argument list).
167163
/// @param path The absolute path to the binary file to execute.
@@ -241,17 +237,6 @@ int execvpe(const char *file, char *const argv[], char *const envp[]);
241237
/// returned, and errno is set appropriately.
242238
int nice(int inc);
243239

244-
/// @brief Reboots the system, or enables/disables the reboot keystroke.
245-
/// @param magic1 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1.
246-
/// @param magic2 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2.
247-
/// @param cmd The command to send to the reboot.
248-
/// @param arg Argument passed with some specific commands.
249-
/// @return For the values of cmd that stop or restart the system, a
250-
/// successful call to reboot() does not return. For the other cmd
251-
/// values, zero is returned on success. In all cases, -1 is
252-
/// returned on failure, and errno is set appropriately.
253-
int reboot(int magic1, int magic2, unsigned int cmd, void *arg);
254-
255240
/// @brief Get current working directory.
256241
/// @param buf The array where the CWD will be copied.
257242
/// @param size The size of the array.
@@ -270,15 +255,6 @@ int chdir(char const *path);
270255
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
271256
int fchdir(int fd);
272257

273-
/// Provide access to the directory entries.
274-
/// @param fd The fd pointing to the opened directory.
275-
/// @param dirp The buffer where de data should be placed.
276-
/// @param count The size of the buffer.
277-
/// @return On success, the number of bytes read is returned. On end of
278-
/// directory, 0 is returned. On error, -1 is returned, and errno is set
279-
/// appropriately.
280-
ssize_t getdents(int fd, dirent_t *dirp, unsigned int count);
281-
282258
/// @brief Return a new file descriptor
283259
/// @param fd The fd pointing to the opened file.
284260
/// @return On success, a new file descriptor is returned.

libc/src/abort.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
44
/// See LICENSE.md for details.
55

6-
#include "sys/unistd.h"
6+
#include "unistd.h"
77
#include "signal.h"
88
#include "stdio.h"
99
#include "string.h"
10+
#include "grp.h"
11+
#include "stdlib.h"
1012

1113
/// @brief Since there could be signal handlers listening for the abort, we need
1214
/// to keep track at which stage of the abort we are.

libc/src/err.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,43 @@
22
/// @brief Contains err functions
33
/// @copyright (c) 2024 This file is distributed under the MIT License.
44
/// See LICENSE.md for details.
5+
56
#include <err.h>
67
#include <stdio.h>
78
#include <stdarg.h>
89
#include <stdio.h>
9-
#include <sys/unistd.h>
10+
#include <unistd.h>
11+
#include <stdlib.h>
1012

1113
void verr(int status, const char *fmt, va_list ap)
1214
{
13-
if (fmt) {
14-
vfprintf(STDERR_FILENO, fmt, ap);
15-
fprintf(STDERR_FILENO, ": ");
16-
}
17-
perror(0);
18-
exit(status);
15+
if (fmt) {
16+
vfprintf(STDERR_FILENO, fmt, ap);
17+
fprintf(STDERR_FILENO, ": ");
18+
}
19+
perror(0);
20+
exit(status);
1921
}
2022

2123
void verrx(int status, const char *fmt, va_list ap)
2224
{
23-
if (fmt) vfprintf(STDERR_FILENO, fmt, ap);
24-
fprintf(STDERR_FILENO, "\n");
25-
exit(status);
25+
if (fmt) vfprintf(STDERR_FILENO, fmt, ap);
26+
fprintf(STDERR_FILENO, "\n");
27+
exit(status);
2628
}
2729

2830
void err(int status, const char *fmt, ...)
2931
{
30-
va_list ap;
31-
va_start(ap, fmt);
32-
verr(status, fmt, ap);
33-
va_end(ap);
32+
va_list ap;
33+
va_start(ap, fmt);
34+
verr(status, fmt, ap);
35+
va_end(ap);
3436
}
3537

3638
void errx(int status, const char *fmt, ...)
3739
{
38-
va_list ap;
39-
va_start(ap, fmt);
40-
verrx(status, fmt, ap);
41-
va_end(ap);
40+
va_list ap;
41+
va_start(ap, fmt);
42+
verrx(status, fmt, ap);
43+
va_end(ap);
4244
}

0 commit comments

Comments
 (0)