Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
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
Main
Synchronet
Commits
bc12adcb
Commit
bc12adcb
authored
12 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add xpmap()/xpunmap() functions to map a file into process memory space.
parent
0df9098f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/xpdev/xpmap.c
+166
-0
166 additions, 0 deletions
src/xpdev/xpmap.c
src/xpdev/xpmap.h
+73
-0
73 additions, 0 deletions
src/xpdev/xpmap.h
with
239 additions
and
0 deletions
src/xpdev/xpmap.c
0 → 100644
+
166
−
0
View file @
bc12adcb
/* xpmap.c */
/* mmap() style cross-platform development wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include
"xpmap.h"
#if defined(__unix__)
#include
<fcntl.h>
#include
<sys/mman.h>
#include
<sys/types.h>
#include
<sys/stat.h>
struct
xpmapping
*
xpmap
(
const
char
*
filename
,
enum
xpmap_type
type
)
{
int
fd
;
void
*
addr
=
NULL
;
int
oflags
;
int
mflags
;
int
mprot
;
struct
stat
*
sb
;
struct
xpmapping
*
ret
;
switch
(
type
)
{
case
XPMAP_READ
:
oflags
=
O_RDONLY
;
mflags
=
0
;
mprot
=
PROT_READ
;
break
;
case
XPMAP_WRITE
:
oflags
=
O_RDWR
;
mflags
=
MAP_SHARED
;
mprot
=
PROT_READ
|
PROT_WRITE
;
break
;
case
XPMAP_COPY
:
oflags
=
O_RDWR
;
mflags
=
MAP_PRIVATE
;
mprot
=
PROT_READ
|
PROT_WRITE
;
break
;
}
fd
=
open
(
filename
,
oflags
);
if
(
fd
==
-
1
)
return
NULL
;
if
(
fstat
(
fd
,
&
sb
)
==-
1
)
return
NULL
;
addr
=
mmap
(
NULL
,
sb
.
st_size
,
mprot
,
mflags
,
fd
,
0
);
if
(
addr
==
MAP_FAILED
)
return
NULL
;
ret
=
(
struct
xpmapping
*
)
malloc
(
sizeof
(
struct
xpmapping
));
if
(
ret
==
NULL
)
return
NULL
;
ret
->
addr
=
addr
;
ret
->
fd
=
fd
;
ret
->
size
=
sb
.
st_size
;
return
ret
;
}
void
xpunmap
(
struct
xpmapping
*
map
)
{
munmap
(
map
->
addr
,
map
->
size
);
close
(
map
->
fd
);
free
(
map
);
}
#elif defined(_WIN32)
struct
xpmapping
*
xpmap
(
const
char
*
filename
,
enum
xpmap_type
type
)
{
HANDLE
fd
;
HANDLE
md
;
OFSTRUCT
of
;
UINT
oflags
;
DWORD
mattrs
;
DWORD
mprot
;
DWORD
maccess
;
DWORD
size
;
void
*
addr
;
struct
xpmapping
*
ret
;
switch
(
type
)
{
case
XPMAP_READ
:
oflags
=
OF_READ
|
OF_SHARE_DENY_NONE
;
mprot
=
PAGE_READONLY
;
mattrs
=
0
;
maccess
=
FILE_MAP_READ
;
break
;
case
XPMAP_WRITE
:
oflags
=
OF_READWRITE
|
OF_SHARE_DENY_NONE
;
mprot
=
PAGE_READWRITE
;
mflags
=
0
;
maccess
=
FILE_MAP_WRITE
;
break
;
case
XPMAP_COPY
:
oflags
=
OF_READ
|
OF_SHARE_DENY_NONE
;
mprot
=
PAGE_WRITECOPY
;
mflags
=
0
;
maccess
=
FILE_MAP_COPY
;
break
;
}
fd
=
OpenFile
(
filename
,
&
of
,
oflags
);
if
(
fd
==
HFILE_ERROR
)
return
NULL
;
if
((
size
=
GetFileSize
(
fd
,
NULL
))
==
INVALID_FILE_SIZE
)
return
NULL
;
md
=
CreateFileMapping
(
fd
,
NULL
,
mprot
,
0
,
size
,
NULL
);
if
(
md
==
NULL
)
return
NULL
;
addr
=
MapViewOfFile
(
md
,
maccess
,
0
,
0
,
size
);
ret
=
(
struct
xpmapping
*
)
malloc
(
sizeof
(
struct
xpmapping
));
if
(
ret
==
NULL
)
return
NULL
;
ret
->
addr
=
addr
;
ret
->
fd
=
fd
;
ret
->
md
=
md
;
ret
->
size
=
size
;
return
ret
;
}
void
xpunmap
(
struct
xpmapping
*
map
)
{
UnmapViewOfFile
(
map
->
addr
);
CloseHandle
(
map
->
md
);
CloseHandle
(
map
->
fd
);
free
(
map
);
}
#else
#error "Need mmap wrappers."
#endif
This diff is collapsed.
Click to expand it.
src/xpdev/xpmap.h
0 → 100644
+
73
−
0
View file @
bc12adcb
/* xpmap.h */
/* mmap() style cross-platform development wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _XPMAP_H
#define _XPMAP_H
#include
"gen_defs.h"
void
*
xpmap
(
const
char
*
filename
,
int
flags
);
enum
xpmap_type
{
XPMAP_READ
,
XPMAP_WRITE
,
XPMAP_COPY
};
#if defined(__unix__)
#include
<sys/mman.h>
struct
xpmapping
{
void
*
addr
;
int
fd
;
size_t
size
;
};
#elif defined(_WIN32)
struct
xpmapping
{
void
*
addr
;
HANDLE
fd
;
HANDLE
md
;
uint64_t
size
;
};
#else
#error "Need mmap wrappers."
#endif
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