↑ Back to main site.

EPOS

Experimental Protected-mode Operating System

ipc.h
/*
EPOS
http://www.atanaslaskov.com/epos/

FILE:        ipc.h
DESCRIPTION: Inter Process-Communication IPC as message passing
 
BSD LICENSE
Copyright (c) 2006, Atanas Laskov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#ifndef IPC_H
#define IPC_H

// Some defaults
//
#define PID_KERNEL MAX_PROCESS_CNT
#define IPC_MAX_LINE_CNT (MAX_PROCESS_CNT*10)
#define IPC_MSG_BUF_SIZE 64
#define IPC_INBOX_SIZ    32

#define HLINE            unsigned long

#define LINE_CLOSED      0
#define LINE_CREATING    1
#define LINE_OPEN        2

#define IPCSTATE           unsigned char
#define IPC_ST_OK          0
#define IPC_ST_OUTOFLINES  1
#define IPC_ST_INVLINE     2
#define IPC_INVPROCESS     3
#define IPC_INBOXFULL      4
#define IPC_INBOXEMPTY     5
#define IPC_ST_BAD_MEM     6

#define IPC_INBOX_WAITING     1
#define IPC_INBOX_DONT_RECIVE 2

#define MSG_KRN_IRQ           0 //data = n IRQ
#define MSG_KRN_WANT_LINE     1 //data = HLINE
#define MSG_KRN_LINE_OPENED   2 //data = HLINE
#define MSG_KRN_LINE_CLOSED   3 //data = HLINE
#define MSG_KRN_CHILD_DEATH   4 //data = PID
#define MSG_KRN_DEBUG         5 //data = TYPE(3 chars), PID

// Internal data structures
//
struct IPCMessage{
    unsigned long dwMessage;
    unsigned long dwSize;
    unsigned char arData[IPC_MSG_BUF_SIZE];

    unsigned char bMemoryTransfer;
    void* pMemory;
    unsigned long dwTransferSize;
};

struct IPCInbox{
    struct IPCMessage  arMsg[IPC_INBOX_SIZE];
    struct IPCMessage* arPMsg[IPC_INBOX_SIZE];
    unsigned long dwMsgCnt;
    PID dwOwnerPID;
    unsigned char bFlags;
    struct IPCTransfer *pUnblockingMsg;
};

struct IPCLine{
    struct IPCInbox inbox[2];
    unsigned char bState;
};

// User argument structures
//
struct IPCOpenLine{
    HLINE  hLine;
    struct PAddress padAddress;
    IPCSTATE st;
};

struct IPCPID{
    PID dwRequestorPID;
    HLINE  hLine;
    IPCSTATE st;
};

struct IPCHLine{
    HLINE  hLine;
    IPCSTATE st;
};

struct IPCTransfer{
    struct IPCMessage msg;
    HLINE  hLine;
    IPCSTATE st;
};

// Kernel internals
//
void k_ipcInit();
void k_ipcOpenLine(struct IPCOpenLine *p);
void k_ipcSend(struct IPCTransfer *p);
void k_ipcProcessDeath(PID dwPID);

// User service functions
//
void ipcOpenLine(struct IPCOpenLine *p);
void ipcGetLineInfo(struct IPCPID *p);
void ipcAcceptOpen(struct IPCHLine *p);
void ipcDenyOpen(struct IPCHLine *p);
void ipcCloseLine(struct IPCHLine *p);

void ipcSend(struct IPCTransfer *p);
void ipcRecive(struct IPCTransfer *p);
void ipcReciveB(struct IPCTransfer *p);
void ipcReciveMem(struct IPCTransfer *p);

void ipcWaitMessage();



#endif //#ifndef IPC_H