Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar-wayland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar-wayland
Commits
ff1ff0a5
Commit
ff1ff0a5
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add util to allocate shared memory
parent
527a51dd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
quasar-wayland.cabal
+4
-0
4 additions, 0 deletions
quasar-wayland.cabal
src/Quasar/Wayland/Utils/InlineC.hs
+33
-0
33 additions, 0 deletions
src/Quasar/Wayland/Utils/InlineC.hs
src/Quasar/Wayland/Utils/SharedMemory.hs
+36
-0
36 additions, 0 deletions
src/Quasar/Wayland/Utils/SharedMemory.hs
with
73 additions
and
0 deletions
quasar-wayland.cabal
+
4
−
0
View file @
ff1ff0a5
...
...
@@ -84,12 +84,16 @@ library
Quasar.Wayland.Protocol.TH
other-modules:
Quasar.Wayland.Protocol.Core
Quasar.Wayland.Utils.InlineC
Quasar.Wayland.Utils.SharedMemory
build-depends:
base >=4.7 && <5,
binary,
bytestring,
containers,
exceptions,
filepath,
inline-c,
mtl,
network,
quasar,
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Wayland/Utils/InlineC.hs
0 → 100644
+
33
−
0
View file @
ff1ff0a5
module
Quasar.Wayland.Utils.InlineC
(
ctx
)
where
import
Data.Map.Strict
as
Map
import
Language.C.Inline.Context
import
Language.C.Types
import
Language.Haskell.TH
import
Quasar.Prelude
import
System.Posix.Types
(
COff
(
..
))
ctx
::
Context
ctx
=
baseCtx
<>
extraTypesCtx
emptyCtx
::
Context
emptyCtx
=
Context
{
ctxTypesTable
=
mempty
,
ctxAntiQuoters
=
mempty
,
ctxOutput
=
mempty
,
ctxForeignSrcLang
=
Nothing
,
ctxEnableCpp
=
False
}
extraTypesCtx
::
Context
extraTypesCtx
=
emptyCtx
{
ctxTypesTable
=
Map
.
fromList
types
}
types
::
[(
TypeSpecifier
,
TypeQ
)]
types
=
[
(
TypeName
"off_t"
,
[
t
|
COff
|]
)
]
This diff is collapsed.
Click to expand it.
src/Quasar/Wayland/Utils/SharedMemory.hs
0 → 100644
+
36
−
0
View file @
ff1ff0a5
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module
Quasar.Wayland.Utils.SharedMemory
(
allocateShmFd
,
)
where
import
Foreign.C.Error
import
Language.C.Inline
qualified
as
C
import
Language.C.Inline.Unsafe
qualified
as
CU
import
Quasar.Prelude
import
Quasar.Wayland.Utils.InlineC
import
System.Posix.Types
(
COff
(
..
),
Fd
(
Fd
))
C
.
context
ctx
C
.
verbatim
"#define _GNU_SOURCE"
C
.
include
"<unistd.h>"
C
.
include
"<sys/mman.h>"
allocateShmFd
::
COff
->
IO
Fd
allocateShmFd
size
=
Fd
<$>
throwErrnoIfMinus1
"allocateShmFd"
[
CU
.
block
|
int
{
int
fd
=
memfd_create
(
"shm"
,
MFD_CLOEXEC
|
MFD_ALLOW_SEALING
);
if
(
fd
<
0
)
{
return
fd
;
}
if
(
ftruncate
(
fd
,
$
(
off_t
size
))
<
0
)
{
close
(
fd
);
return
-
1
;
}
return
fd
;
}
|
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment