Skip to content

Commit

Permalink
Initial file
Browse files Browse the repository at this point in the history
  • Loading branch information
justinethier committed Feb 27, 2012
1 parent 9fbe92f commit 9b78014
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Makefile
@@ -0,0 +1,13 @@
# A simple makefile to drive everything
dist:
# runhaskell Setup.hs configure --prefix=$(HOME) --user && runhaskell Setup.hs build && runhaskell Setup.hs install && runhaskell Setup.hs sdist
cabal configure --prefix=$(HOME) --user && cabal build && cabal install && cabal sdist
#sipc: Sipc.chs
# c2hs Sipc.chs
# ghc Sipc.hs -lsipc
#ghci: Sipc.hs
# ghci Sipc.hs -lsipc
clean:
rm -rf *.o *.hi *.chi Sipc.chs.h C2HS.hs Sipc.hs a.out dist
find . -type f -name "*.hi" -exec rm -f {} \;
find . -type f -name "*.o" -exec rm -f {} \;
3 changes: 3 additions & 0 deletions Setup.hs
@@ -0,0 +1,3 @@
#!/usr/bin/env runhaskell
import Distribution.Simple
main = defaultMain
44 changes: 44 additions & 0 deletions bindings-sipc.cabal
@@ -0,0 +1,44 @@
Name: bindings-sipc
Version: 1.0
Synopsis: Low level bindings to SIPC.
Description: Low level bindings to the Secure Inter-Process Communications (SIPC)
library for SELinux.
License: LGPL
-- License-file: LICENSE
Author: Justin Ethier
Maintainer: Justin Ethier <github.com/justinethier>
Homepage: http://justinethier.github.com/hs-bindings-sipc
Cabal-Version: >= 1.8
Build-Tools: c2hs
Build-Type: Simple
Category: FFI
Tested-with: GHC == 6.10.3

Library
Build-Depends: base >= 2.0 && < 5
-- , array, containers, haskeline, transformers, mtl, parsec, directory, ghc, ghc-paths
-- Extensions: ExistentialQuantification CPP CPP
Hs-Source-Dirs: src
Exposed-Modules: Bindings.SELinux.SIPC
Extra-Libraries: sipc

-- Extra-Source-Files: README.markdown
-- LICENSE
-- Data-Files: stdlib.scm
--
-- Source-Repository head
-- Type: git
-- Location: git://github.com/justinethier/husk-scheme.git
--
-- Executable huski
-- Build-Depends: husk-scheme, base >= 2.0 && < 5, array, containers, haskeline, transformers, mtl, parsec, directory, ghc, ghc-paths
-- Extensions: ExistentialQuantification CPP CPP
-- Main-is: shell.hs
-- Hs-Source-Dirs: hs-src/Interpreter
--
-- Executable huskc
-- Build-Depends: husk-scheme, base >= 2.0 && < 5, array, containers, haskeline, transformers, mtl, parsec, directory, ghc, ghc-paths, process, filepath
-- Extensions: ExistentialQuantification CPP CPP
-- Main-is: huskc.hs
-- Hs-Source-Dirs: hs-src/Compiler
--
79 changes: 79 additions & 0 deletions src/Bindings/SELinux/SIPC.chs
@@ -0,0 +1,79 @@
{-# LANGUAGE ForeignFunctionInterface#-}

module Bindings.SELinux.SIPC where

import Foreign
import Foreign.C

-- The sipc header must be installed on your system
-- in order to compile this module!!
#include <sipc/sipc.h>

#c
enum SIPCRole {
Sipc_creator = SIPC_CREATOR,
Sipc_sender = SIPC_SENDER,
Sipc_receiver = SIPC_RECEIVER
};
enum SIPCType {
Sipc_sysv_shm = SIPC_SYSV_SHM,
Sipc_sysv_mqueues = SIPC_SYSV_MQUEUES,
Sipc_num_types = SIPC_NUM_TYPES
};
enum SIPCIOCtl {
Sipc_block = SIPC_BLOCK,
Sipc_noblock = SIPC_NOBLOCK
};
#endc

-- |SIPC Roles
{#enum SIPCRole {} deriving (Eq, Show)#}
-- |SIPC Types
{#enum SIPCType {} deriving (Eq, Show)#}
-- |SIPC behaviors, for sipc_ioctl()
{#enum SIPCIOCtl {} deriving (Eq, Show)#}

-- TODO: documentation for *everything* once all defs are in place

--data Sipc = Sipc
--type SipcPtr = Ptr Sipc
type SipcPtr = Ptr ()

-- TODO: should use CSize for last input arg
{#fun unsafe sipc_open {`String', cFromEnum `SIPCRole', cFromEnum `SIPCType', `Int' } -> `SipcPtr' id #}
{#fun unsafe sipc_close {id `SipcPtr'} -> `()' #}

{#fun unsafe sipc_unlink {`String', cFromEnum `SIPCType'} -> `()' #}

{#fun unsafe sipc_ioctl {id `SipcPtr', cFromEnum `SIPCIOCtl'} -> `Int' #}

-- TODO: same issue with CSize as above
--int sipc_send_data(sipc_t *sipc, size_t msg_len);
{#fun unsafe sipc_send_data {id `SipcPtr', `Int'} -> `Int' #}

-- TODO: is String really the right return type here??
-- /* Returns a pointer to the data contained within the IPC resource */
--char *sipc_get_data_ptr(sipc_t *sipc);
{#fun unsafe sipc_get_data_ptr {id `SipcPtr'} -> `String' #}

{- TODO:
-- data is allocated by C, believe this must be indicated to Haskell
-- TBD: what about len??
int sipc_recv_data(sipc_t *sipc, char **data, size_t *len);
-- TODO: are variable-length args even supported by the Haskell FFI???
/* Prints an error message, accepts printf format string */
void sipc_error(sipc_t *sipc, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
-}

{#fun unsafe sipc_shm_recv_done {id `SipcPtr'} -> `Int' #}

-- |Convert a Haskell enumeration to C.
--
-- This code is from C2HS, but it has been added
-- here since C2HS is deprecated.
cFromEnum :: (Enum e, Integral i) => e -> i
cFromEnum = fromIntegral . fromEnum

0 comments on commit 9b78014

Please sign in to comment.