~ubuntu-branches/ubuntu/lucid/xenomai/lucid

« back to all changes in this revision

Viewing changes to ksrc/skins/posix/shm.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-06-24 22:17:01 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090624221701-mwnah8aj90zmp6uj
Tags: 2.4.8-2ubuntu1
* Merge from debian unstable (LP: #391918), remaining changes:
  - Add lpia to supported architectures.
  - debian/rules: Create file for debhelper to pick up, use debhelper to
    install it.
  - debian/libxenomai1.dirs: Do not create directory.
  - debian/libxenomai1.preinst: Remove symlink on upgrade, remove old udev.
    rule unless modified in which case move to new name.
  - debian/libxenomai1.postinst: Do not create symlink.
  - debian/libxenomai1.postrm: No symlink to remove.
  - Bump build-depend on debhelper to install udev rules into
    /lib/udev/rules.d, add Breaks on udev to get correct version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2005 Gilles Chanteperdrix <gilles.chanteperdrix@laposte.net>.
 
2
 * Copyright (C) 2005 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3
3
 *
4
4
 * This library is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU Lesser General Public
39
39
#include <posix/thread.h>
40
40
#include <posix/shm.h>
41
41
 
42
 
#ifdef __KERNEL__
43
 
#include <asm/semaphore.h>
44
 
#endif /* __KERNEL__ */
45
 
 
46
42
typedef struct pse51_shm {
47
43
        pse51_node_t nodebase;
48
44
 
112
108
                xnheap_free(&shm->heapbase, shm->addr);
113
109
 
114
110
#ifdef CONFIG_XENO_OPT_PERVASIVE
115
 
                xnheap_destroy_mapped(&shm->heapbase);
 
111
                xnheap_destroy_mapped(&shm->heapbase, NULL, NULL);
116
112
#else /* !CONFIG_XENO_OPT_PERVASIVE. */
117
113
                xnheap_destroy(&shm->heapbase, &pse51_free_heap_extent, NULL);
118
114
#endif /* !CONFIG_XENO_OPT_PERVASIVE. */
520
516
                size_t size = 0;
521
517
 
522
518
                if (shm->addr) {
523
 
                        size = shm->size;
 
519
                        if (len == xnheap_extentsize(&shm->heapbase)) {
 
520
                                /* Size unchanged, skip copy and reinit. */
 
521
                                err = 0;
 
522
                                goto err_up;
 
523
                        }
 
524
 
 
525
                        size = xnheap_max_contiguous(&shm->heapbase);
524
526
                        addr = xnarch_alloc_host_mem(size);
525
527
                        if (!addr) {
526
528
                                err = ENOMEM;
531
533
 
532
534
                        xnheap_free(&shm->heapbase, shm->addr);
533
535
#ifdef CONFIG_XENO_OPT_PERVASIVE
534
 
                        xnheap_destroy_mapped(&shm->heapbase);
 
536
                        xnheap_destroy_mapped(&shm->heapbase, NULL, NULL);
535
537
#else /* !CONFIG_XENO_OPT_PERVASIVE. */
536
538
                        xnheap_destroy(&shm->heapbase, &pse51_free_heap_extent,
537
539
                                       NULL);
543
545
 
544
546
                if (len) {
545
547
#ifdef CONFIG_XENO_OPT_PERVASIVE
546
 
                        int flags = len <= 128 * 1024 ? GFP_USER : 0;
 
548
                        int flags = (XNARCH_SHARED_HEAP_FLAGS ?:
 
549
                                     len <= 128 * 1024 ? GFP_USER : 0);
547
550
                        err = -xnheap_init_mapped(&shm->heapbase, len, flags);
548
551
#else /* !CONFIG_XENO_OPT_PERVASIVE. */
549
552
                        {
566
569
                        shm->addr = xnheap_alloc(&shm->heapbase, shm->size);
567
570
                        /* Required. */
568
571
                        memset(shm->addr, '\0', shm->size);
569
 
                        shm->size -= PAGE_SIZE;
570
572
 
571
573
                        /* Copy the previous contents. */
572
574
                        if (addr)
573
575
                                memcpy(shm->addr, addr,
574
576
                                       shm->size < size ? shm->size : size);
 
577
 
 
578
                        shm->size -= PAGE_SIZE;
575
579
                }
576
580
 
577
581
                if (addr)