Debian Codegraph @

docs/porting/modscope.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Determining the Scope of the Modifications</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Porting Berkeley DB" />
10 <link rel="up" href="newbinary.html" title="Chapter 2. Creating a New Berkeley DB Binary" />
11 <link rel="prev" href="newbinary.html" title="Chapter 2. Creating a New Berkeley DB Binary" />
12 <link rel="next" href="buildtarget.html" title="Building on the Target Platform" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">
22 Determining the Scope of the Modifications
23 </th>
24 </tr>
25 <tr>
26 <td width="20%" align="left"><a accesskey="p" href="newbinary.html">Prev</a> </td>
27 <th width="60%" align="center">Chapter 2. Creating a New Berkeley DB Binary</th>
28 <td width="20%" align="right"> <a accesskey="n" href="buildtarget.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="modscope"></a>
38 Determining the Scope of the Modifications
39 </h2>
40 </div>
41 </div>
42 </div>
43 <div class="toc">
44 <dl>
45 <dt>
46 <span class="sect2">
47 <a href="modscope.html#osfunc">
48 Do Changes Need to be Made to the Operating System Functionality?
49 </a>
50 </span>
51 </dt>
52 <dt>
53 <span class="sect2">
54 <a href="modscope.html#standardfunc">Are Some Standard Functions Missing on the Target Platform?</a>
55 </span>
56 </dt>
57 <dt>
58 <span class="sect2">
59 <a href="modscope.html#sharedmem">How Will the Port Handle Shared Memory?</a>
60 </span>
61 </dt>
62 <dt>
63 <span class="sect2">
64 <a href="modscope.html#typemutex">What Type of Mutexes Will the Port Use?</a>
65 </span>
66 </dt>
67 <dt>
68 <span class="sect2">
69 <a href="modscope.html#otherchanges">Do Any Other Changes Need to be Made?</a>
70 </span>
71 </dt>
72 </dl>
73 </div>
74 <p>
75 Once you have a good build of Berkeley DB on a UNIX or UNIX-like system, look over the code to determine what type of code changes you need to make so that you can successfully build Berkeley DB on your target system. This process involves determining:
76 </p>
77 <div class="itemizedlist">
78 <ul type="disc">
79 <li>
80 <p>
81 <a class="xref" href="modscope.html#osfunc" title="Do Changes Need to be Made to the Operating System Functionality?">
82 Do Changes Need to be Made to the Operating System Functionality?
83 </a>
84 </p>
85 </li>
86 <li>
87 <p>
88 <a class="xref" href="modscope.html#standardfunc" title="Are Some Standard Functions Missing on the Target Platform?">Are Some Standard Functions Missing on the Target Platform?</a>
89 </p>
90 </li>
91 <li>
92 <p>
93 <a class="xref" href="modscope.html#sharedmem" title="How Will the Port Handle Shared Memory?">How Will the Port Handle Shared Memory?</a>
94 </p>
95 </li>
96 <li>
97 <p>
98 <a class="xref" href="modscope.html#typemutex" title="What Type of Mutexes Will the Port Use?">What Type of Mutexes Will the Port Use?</a>
99 </p>
100 </li>
101 <li>
102 <p>
103 <a class="xref" href="modscope.html#otherchanges" title="Do Any Other Changes Need to be Made?">Do Any Other Changes Need to be Made?</a>
104 </p>
105 </li>
106 </ul>
107 </div>
108 <div class="sect2" lang="en" xml:lang="en">
109 <div class="titlepage">
110 <div>
111 <div>
112 <h3 class="title"><a id="osfunc"></a>
113 Do Changes Need to be Made to the Operating System Functionality?
114 </h3>
115 </div>
116 </div>
117 </div>
118 <p>
119 Berkeley DB uses about forty operating system primitives. The Berkeley DB distribution contains files which are wrappers around these operating system primitives that act as an abstraction layer to separate the main Berkeley DB code from operating system and architecture-specific components. You <span class="emphasis"><em>must</em></span> port these files (or versions of these files) whenever you port Berkeley DB to a new platform.
120 </p>
121 <p>
122 Within a Berkeley DB distribution, typically, there is only a single
123 version of these files for all platforms that Berkeley DB supports. Those
124 versions of the files live in the <code class="literal">os</code> directory of the
125 distribution and follow the ANSI C and POSIX 1003.1 standards. Within each
126 file, there is usually one, but sometimes several functions (for example,
127 the <code class="literal">os_alloc.c</code> file contains functions such as
128 <code class="literal">malloc</code>, <code class="literal">realloc</code>,
129 <code class="literal">strdup</code>, <code class="literal">free</code>).
130 The following table describes the files in the os directory of the Berkeley DB distribution along with the POSIX functions that must be ported.
131 </p>
132 <div class="informaltable">
133 <table border="1" width="80%">
134 <colgroup>
135 <col />
136 <col />
137 <col />
138 </colgroup>
139 <thead>
140 <tr>
141 <th>
142 <p>
143 POSIX Functions
144 </p>
145 </th>
146 <th>
147 <p>
148 Internal Function Name
149 </p>
150 </th>
151 <th>
152 <p>
153 Source File
154 </p>
155 </th>
156 </tr>
157 </thead>
158 <tbody>
159 <tr>
160 <td>
161 <p>
162 abort() is required if diagnostic build is used or if snprintf is not provided by the platform
163 </p>
164 </td>
165 <td>
166 <p>
167 __os_abort()
168 </p>
169 </td>
170 <td>
171 <p>
172 os_abort.c
173 </p>
174 </td>
175 </tr>
176 <tr>
177 <td>
178 <p>
179 </p><p>
180 freeaddrinfo()
181 </p><p>
182 </p><p>getaddrinfo(), htonl(), htons(), inet_addr(), and gethostbyname() are required for Replication Manager</p><p>
183 </p>
184 </td>
185 <td>
186 <p>
187 __os_getaddrinfo(), __os_freeaddrinfo()
188 </p>
189 </td>
190 <td>
191 os_addrinfo.c
192 </td>
193 </tr>
194 <tr>
195 <td>
196 <p>
197 malloc(), realloc(), strdup(), free(), memcpy(), memset(), strlen()
198 </p>
199
200 </td>
201 <td>
202 __os_umalloc(), __os_urealloc(), __os_ufree(), __os_strdup(), __os_calloc(), __os_malloc(), __os_realloc(), __os_free(), __os_guard(), __ua_memcpy()
203 </td>
204 <td>
205 <p>
206 os_alloc.c
207 </p>
208 </td>
209 </tr>
210 <tr>
211 <td>
212
213 <p>
214 clock_gettime(), time(), gettimeofday()
215 </p>
216
217 </td>
218 <td>
219 <p>
220 __os_gettime()
221 </p>
222 </td>
223 <td>
224 <p>
225 os_clock.c
226 </p>
227 </td>
228 </tr>
229 <tr>
230 <td>
231 <p>
232 sysconf()
233 </p>
234 </td>
235 <td>
236 <p>
237 __os_cpu_count()
238 </p>
239 </td>
240 <td>
241 <p>
242 os_cpu.c
243 </p>
244 </td>
245 </tr>
246 <tr>
247 <td>
248 <p>
249 ctime(), ctime_r()
250 </p>
251 </td>
252 <td>
253 <p>
254 __os_ctime()
255 </p>
256 </td>
257 <td>
258 <p>
259 os_ctime.c
260
261 </p>
262 </td>
263 </tr>
264 <tr>
265 <td>
266 <p>
267 opendir(), closdir(), readdir(), stat()
268 </p>
269 </td>
270 <td>
271 <p>
272
273 __os_dirlist(), __os_dirfree()
274 </p>
275 </td>
276 <td>
277 <p>
278 os_dir.c
279 </p>
280 </td>
281 </tr>
282 <tr>
283 <td>
284 <p>
285 strncpy()
286 </p>
287 </td>
288 <td>
289 <p>
290 __os_get_errno_ret_zero(), __os_get_errno(), __os_get_syserr(), __os_set_errno(), __os_strerror(), __os_posix_err()
291
292 </p>
293 </td>
294 <td>
295 <p>
296 os_errno.c
297 </p>
298 </td>
299 </tr>
300 <tr>
301 <td>
302 <p>
303 fcntl() is required for DB_REGISTER
304 </p>
305 </td>
306 <td>
307 <p>
308 __os_fdlock()
309 </p>
310 </td>
311 <td>
312 <p>
313 os_flock.c
314 </p>
315 </td>
316 </tr>
317 <tr>
318 <td>
319 <p>
320 fsync(), fdatasync()
321 </p>
322 </td>
323 <td>
324 <p>
325 __vx_fsync(), __os_fsync()
326 </p>
327 </td>
328 <td>
329 <p>
330 os_fsync.c
331 </p>
332 </td>
333 </tr>
334 <tr>
335 <td>
336 <p>
337 getenv() and strcpy() are required when environment variables are used to configure the database
338 </p>
339 </td>
340 <td>
341 <p>
342 __os_getenv()
343 </p>
344 </td>
345 <td>
346 <p>
347 os_getenv.c
348 </p>
349 </td>
350 </tr>
351 <tr>
352 <td>
353 <p>
354 close(), open()
355 </p>
356 </td>
357 <td>
358 <p>
359 __os_openhandle(), __os_closehandle()
360 </p>
361 </td>
362 <td>
363 <p>
364 os_handle.c
365 </p>
366 </td>
367 </tr>
368 <tr>
369 <td>
370 <p>
371 getpid()
372 </p>
373 <p>
374 pthread_self() is required for replication and failchk functionality
375 </p>
376 </td>
377 <td>
378 <p>
379 __os_id()
380 </p>
381 </td>
382 <td>
383 <p>
384
385 os_pid.c
386 </p>
387 </td>
388 </tr>
389 <tr>
390 <td>
391 <p>
392 shmget(), shmdt(), shmctl(), and shmat() are required when envrionment uses share memory for regions
393 </p>
394 <p>munmap() is required when envrionment uses memory mapped files for regions or read-only databases
395 </p>
396 <p>munlock() is required when environment is configured with DB_LOCKDOWN
397 </p>
398
399 </td>
400 <td>
401 <p>
402 __os_attach(), __os_detach(), __os_mapfile(), __os_unmapfile(), __os_map(), __shm_mode(), __no_system_mem()
403 </p>
404 </td>
405 <td>
406 <p>
407 os_map.c
408 </p>
409 </td>
410 </tr>
411 <tr>
412 <td>
413 <p>
414 mkdir(), chmod()
415 </p>
416 </td>
417 <td>
418 <p>
419 __os_mkdir()
420 </p>
421 </td>
422 <td>
423 <p>
424 os_mkdir.c
425 </p>
426 </td>
427 </tr>
428 <tr>
429 <td>
430 <p>
431 fchmod() </p>
432 <p>directio() is required when explicitly enabling DIRECTIO_ON
433 </p>
434
435 </td>
436 <td>
437 <p>
438 __os_open()
439 </p>
440 </td>
441 <td>
442 <p>
443 os_open.c
444 </p>
445 </td>
446 </tr>
447 <tr>
448 <td>
449 <p>
450 rename()
451 </p>
452 </td>
453 <td>
454 <p>
455 __os_rename()
456 </p>
457 </td>
458 <td>
459 <p>
460 os_rename.c
461 </p>
462 </td>
463 </tr>
464 <tr>
465 <td>
466 <p>
467 getuid() is required when environment variables are used to configure the database
468 </p>
469 </td>
470 <td>
471 <p>
472 __os_isroot()
473 </p>
474 </td>
475 <td>
476 <p>
477 os_root.c
478 </p>
479 </td>
480 </tr>
481 <tr>
482 <td>
483 <p>
484 read(), write(), pread(), pwrite()
485
486 </p>
487 </td>
488 <td>
489 <p>
490 __os_io(), __os_read(), __os_write(), __os_physwrite()
491 </p>
492 </td>
493 <td>
494 <p>
495 os_rw.c
496 </p>
497 </td>
498 </tr>
499 <tr>
500 <td>
501 <p>
502 lseek()
503 </p>
504 </td>
505 <td>
506 <p>
507 __os_seek()
508 </p>
509 </td>
510 <td>
511 <p>
512 os_seek.c
513 </p>
514 </td>
515 </tr>
516 <tr>
517 <td>
518 <p>
519 stat(), fstat()
520 </p>
521 </td>
522 <td>
523 <p>
524 __os_exists(), __os_ioinfo() </p>
525 </td>
526 <td>
527 <p>
528 os_stat.c
529 </p>
530 </td>
531 </tr>
532 <tr>
533 <td>
534 <p>
535 ftruncate() is required when using truncate
536
537 </p>
538 </td>
539 <td>
540 <p>
541 __os_truncate() </p>
542 </td>
543 <td>
544 <p>
545 os_truncate.c
546 </p>
547 </td>
548 </tr>
549 <tr>
550 <td>
551 <p>
552 unlink()
553 </p>
554 </td>
555 <td>
556 <p>
557 __os_unlink()
558 </p>
559 </td>
560 <td>
561 <p>
562 os_unlink.c
563 </p>
564 </td>
565 </tr>
566 <tr>
567 <td>
568 <p>
569 yield(), sched_yield()
570 </p>
571 </td>
572 <td>
573 <p>
574 __os_yield(), __os_sleep() </p>
575 </td>
576 <td>
577 <p>
578 os.yield.c
579 </p>
580 </td>
581 </tr>
582 </tbody>
583 </table>
584 </div>
585 <p>
586 When the operating system primitives on the target platform are identical
587 or close to the POSIX semantics that Berkeley DB requires, then no code
588 changes or minimal code changes to the files in the <code class="literal">os</code> directory are required. If the operating system primitives are quite different, then some code changes may be required to bridge the gap between the requirements of Berkeley DB and what the operating system provides.
589 </p>
590 <p>
591 Where different code is required, you write an entirely different version
592 of the file and place it in an <code class="literal">os</code>_<span class="emphasis"><em>xxx</em></span> directory where <span class="emphasis"><em>xxx</em></span> represents a platform name.
593 There are <code class="literal">os</code>_<span class="emphasis"><em>xxx</em></span>
594 subdirectories in the Berkeley DB distribution for several established
595 non-POSIX platforms. For example, there is a
596 <code class="literal">os_vxworks</code> directory that contains VxWorks
597 versions of some of the files in the os directory, and Windows versions of
598 some files are in the <code class="literal">os_windows</code> directory. If
599 your target platform needs a different version of a file, you will need to
600 write that file and place it in a new <code class="literal">os</code>_<span class="emphasis"><em>xxx</em></span> directory that you create for your target platform.
601 </p>
602 </div>
603 <div class="sect2" lang="en" xml:lang="en">
604 <div class="titlepage">
605 <div>
606 <div>
607 <h3 class="title"><a id="standardfunc"></a>Are Some Standard Functions Missing on the Target Platform?</h3>
608 </div>
609 </div>
610 </div>
611 <p>
612 In some cases, the target platform may not provide the few POSIX
613 functions required by Berkeley DB or the functions provided by the
614 target platform may not operate in a standard compliant way.
615 Berkeley DB provides replacement functions in the
616 <code class="literal">clib</code> directory
617 of the Berkeley DB distribution.
618 </p>
619 <p>
620 You need to determine how your target platfrom handles these functions:
621 </p>
622 <div class="itemizedlist">
623 <ul type="disc">
624 <li>
625 <p>
626 When the target platform does <span class="emphasis"><em>not</em></span> have a POSIX
627 function required by Berkeley DB, no action is required on your
628 part. When Berekely DB cannot find one of these functions on the
629 target platform, it automatically uses the replacement functions
630 supplied in the <code class="literal">clib</code> directory of the Berkeley
631 DB distribution. For example, if the target platform does not have
632 the <code class="literal">atoi</code> or <code class="literal">strtol</code> functions,
633 Berkeley DB uses <code class="literal">clib/atoi.c</code> and
634 <code class="literal">clib/strtol.c</code>.
635 </p>
636 </li>
637 <li>
638 <p>
639 When the target platform has a function required by Berekely DB, but that
640 function operates in a non-standard compliant way, you can code to the
641 replacement functions supplied in the <code class="literal">clib</code> directory.
642 </p>
643 </li>
644 </ul>
645 </div>
646 </div>
647 <div class="sect2" lang="en" xml:lang="en">
648 <div class="titlepage">
649 <div>
650 <div>
651 <h3 class="title"><a id="sharedmem"></a>How Will the Port Handle Shared Memory?</h3>
652 </div>
653 </div>
654 </div>
655 <p>
656 In order to write
657 multiprocess database applications (not multithreaded, but threads of control running in different address spaces), Berkeley DB must be able to name pieces of shared memory and access them from multiple processes.
658 </p>
659 <p>
660 On UNIX/POSIX systems, Berkeley DB uses
661 <code class="literal">mmap</code> and <code class="literal">shmget</code> for that purpose,
662 but any interface that provides access to named shared memory is
663 sufficient. If you have a simple, flat address space, you should be able
664 to use the code in <code class="literal">os_vxworks/os_map.c</code> as a starting point for the port.
665 </p>
666 <p>
667 If you are not intending to write multiprocess database applications, then this won't be necessary, as Berkeley DB can simply allocate memory from the heap if all threads of control will live in a single address space.
668 </p>
669 </div>
670 <div class="sect2" lang="en" xml:lang="en">
671 <div class="titlepage">
672 <div>
673 <div>
674 <h3 class="title"><a id="typemutex"></a>What Type of Mutexes Will the Port Use?</h3>
675 </div>
676 </div>
677 </div>
678 <p>
679 Berkeley DB requires some form of self-blocking mutual exclusion
680 mutex. Blocking mutexes
681 are preferred as they tend to be less CPU-expensive and less likely
682 to cause thrashing. If blocking mutexes are not available, however,
683 test-and-set will work as well. The code for mutexes is in two
684 places in the system: the include file
685 <code class="literal">dbinc/mutex_int.h</code>, and the
686 distribution directory <code class="literal">mutex</code>.
687 </p>
688 </div>
689 <div class="sect2" lang="en" xml:lang="en">
690 <div class="titlepage">
691 <div>
692 <div>
693 <h3 class="title"><a id="otherchanges"></a>Do Any Other Changes Need to be Made?</h3>
694 </div>
695 </div>
696 </div>
697 <p>
698 In most cases, you do not need to make any changes to the Berkeley DB
699 source code that is not in the abstraction layer (that is, in the
700 <code class="literal">os</code> directory) as that code is designed to be platform-independent code. However, in some situations, the compiler for the target platform is non-standard and may raise errors when compiling some aspects of the Berkeley DB code (for example, additional casting may be required, or a certain type may cause a problem). In these cases, you will need to modify the generic Berkeley DB code in order to have error-free compilation.
701 </p>
702 </div>
703 </div>
704 <div class="navfooter">
705 <hr />
706 <table width="100%" summary="Navigation footer">
707 <tr>
708 <td width="40%" align="left"><a accesskey="p" href="newbinary.html">Prev</a> </td>
709 <td width="20%" align="center">
710 <a accesskey="u" href="newbinary.html">Up</a>
711 </td>
712 <td width="40%" align="right"> <a accesskey="n" href="buildtarget.html">Next</a></td>
713 </tr>
714 <tr>
715 <td width="40%" align="left" valign="top">Chapter 2. Creating a New Berkeley DB Binary </td>
716 <td width="20%" align="center">
717 <a accesskey="h" href="index.html">Home</a>
718 </td>
719 <td width="40%" align="right" valign="top">  Building on the Target Platform</td>
720 </tr>
721 </table>
722 </div>
723 </body>
724 </html>