Skip to content

Commit

Permalink
ipc: socket initialization and limits
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 6, 2024
1 parent 1891baa commit c53991a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/include/kernel/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <kernel/sched.h>
#include <sys/types.h>

/* system-wide limit */
#define MAX_SOCKETS (1 << 20) // little over a million

/* socket family/domain - only Unix sockets will be implemented in the kernel */
#define AF_UNIX 1
#define AF_LOCAL AF_UNIX
Expand Down Expand Up @@ -45,6 +48,8 @@ typedef struct {
void **inbound, **outbound;
} SocketDescriptor;

void socketInit();

/* socket system calls */
int socket(Thread *, int, int, int);
int connect(Thread *, int, const struct sockaddr *, socklen_t);
Expand Down
22 changes: 22 additions & 0 deletions src/ipc/sockinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@

#include <errno.h>
#include <stdlib.h>
#include <kernel/logger.h>
#include <kernel/socket.h>
#include <kernel/io.h>
#include <kernel/sched.h>

/* array of system-wide open sockets */
static SocketDescriptor *sockets;
static int socketCount;

/* socketInit(): initializes the socket subsystem
* params: none
* returns: nothing
*/

void socketInit() {
sockets = calloc(sizeof(SocketDescriptor *), MAX_SOCKETS);
if(!sockets) {
KERROR("failed to allocate memory for socket subsystem\n");
while(1);
}

socketCount = 0;

KDEBUG("max %d sockets, %d per process\n", MAX_SOCKETS, MAX_IO_DESCRIPTORS);
}

/* socket(): opens a communication socket
* params: t - calling thread, NULL for kernel threads
* params: domain - socket domain/family
Expand Down
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdlib.h>
#include <kernel/logger.h>
#include <kernel/socket.h>
#include <kernel/sched.h>
#include <kernel/modules.h>
#include <platform/platform.h>
Expand Down Expand Up @@ -50,15 +51,21 @@ void *kernelThread(void *args) {
}

setLumenPID(pid);
idleThread(args);
return idleThread(args);
}

// the true kernel entry point is called after platform-specific initialization
// platform-specific code is in platform/[PLATFORM]/main.c

int main(int argc, char **argv) {
/* the platform-specific main() function must initialize some basic form of
* output for debugging, physical and virtual memory, and multiprocessing; the
* boot process will continue here in a more platform-independent fashion */

socketInit(); // sockets
schedInit(); // scheduler

// number of kernel threads = number of CPU cores
kthreadCreate(&kernelThread, NULL);

for(int i = 1; i < platformCountCPU(); i++) {
Expand Down

0 comments on commit c53991a

Please sign in to comment.